diff --git a/go.sum b/go.sum index 4053cbb..5d741c4 100644 --- a/go.sum +++ b/go.sum @@ -125,6 +125,7 @@ github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFB github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI= github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ= @@ -148,6 +149,7 @@ github.com/muka/go-bluetooth v0.0.0-20200619025933-f6113f7141c5/go.mod h1:yV39+E github.com/muka/go-bluetooth v0.0.0-20201211051136-07f31c601d33 h1:p3srutpE8TpQmOUQ5Qw94jYFUdoG2jBbILeYLroQNoI= github.com/muka/go-bluetooth v0.0.0-20201211051136-07f31c601d33/go.mod h1:dMCjicU6vRBk34dqOmIZm0aod6gUwZXOXzBROqGous0= github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U= +github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e h1:fD57ERR4JtEqsWbfPhv4DMiApHyliiK5xCTNVSPiaAs= github.com/niemeyer/pretty v0.0.0-20200227124842-a10e7caefd8e/go.mod h1:zD1mROLANZcx1PVRCS0qkT7pwLkGfwJo4zjcN/Tysno= github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn4U= github.com/pascaldekloe/goe v0.0.0-20180627143212-57f6aae5913c/go.mod h1:lzWF7FIEvWOWxwDKqyGYQf6ZUaNfKdP144TG7ZOy1lc= @@ -216,7 +218,6 @@ github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoH github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA= -github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0= github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= @@ -381,6 +382,7 @@ google.golang.org/grpc v1.21.1/go.mod h1:oYelfM1adQP15Ek0mdvEgi9Df8B9CZIaU1084ij gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f h1:BLraFXnmrev5lT+xlilqcH8XK9/i0At2xKjWk4p6zsU= gopkg.in/check.v1 v1.0.0-20200227125254-8fa46927fb4f/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI= gopkg.in/ini.v1 v1.51.0/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k= @@ -392,7 +394,6 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= -gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo= gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/src/scanStuff/scanStuff.go b/src/scanStuff/scanStuff.go index 2e7c3a7..ac2245d 100644 --- a/src/scanStuff/scanStuff.go +++ b/src/scanStuff/scanStuff.go @@ -8,10 +8,9 @@ import ( "github.com/rs/zerolog" "github.com/rs/zerolog/log" + "tinygo.org/x/bluetooth" "time" - - "tinygo.org/x/bluetooth" ) type Meta struct { diff --git a/vendor/tinygo.org/x/bluetooth/adapter_linux.go b/vendor/tinygo.org/x/bluetooth/adapter_linux.go index 15aa354..b225348 100644 --- a/vendor/tinygo.org/x/bluetooth/adapter_linux.go +++ b/vendor/tinygo.org/x/bluetooth/adapter_linux.go @@ -12,7 +12,7 @@ import ( type Adapter struct { adapter *adapter.Adapter1 - id string + ID string cancelChan chan struct{} defaultAdvertisement *Advertisement @@ -32,12 +32,12 @@ var DefaultAdapter = &Adapter{ // Enable configures the BLE stack. It must be called before any // Bluetooth-related calls (unless otherwise indicated). func (a *Adapter) Enable() (err error) { - if a.id == "" { + if a.ID == "" { a.adapter, err = api.GetDefaultAdapter() if err != nil { return } - a.id, err = a.adapter.GetAdapterID() + a.ID, err = a.adapter.GetAdapterID() } return nil } diff --git a/vendor/tinygo.org/x/bluetooth/gap.go b/vendor/tinygo.org/x/bluetooth/gap.go index 63998f4..ccea884 100644 --- a/vendor/tinygo.org/x/bluetooth/gap.go +++ b/vendor/tinygo.org/x/bluetooth/gap.go @@ -123,6 +123,9 @@ type AdvertisementPayload interface { // UUIDs and 128-bit UUIDs. HasServiceUUID(UUID) bool + //Optputs what i think is the raw data packet + ServiceUUIDOut() []UUID + // Bytes returns the raw advertisement packet, if available. It returns nil // if this data is not available. Bytes() []byte @@ -164,6 +167,16 @@ func (p *advertisementFields) HasServiceUUID(uuid UUID) bool { return false } +func (p *advertisementFields) ServiceUUIDOut() []UUID { + return p.AdvertisementFields.ServiceUUIDs +} + +/* +func (p *advertisementFields) ServiceUUIDOut() []UUID { + return p.AdvertisementFields.ServiceUUIDs +} +*/ + // Bytes returns nil, as structured advertisement data does not have the // original raw advertisement data available. func (p *advertisementFields) Bytes() []byte { @@ -174,13 +187,13 @@ func (p *advertisementFields) Bytes() []byte { // get the data (such as LocalName()) will parse just the needed field. Scanning // the data should be fast as most advertisement packets only have a very small // (3 or so) amount of fields. -type rawAdvertisementPayload struct { +type RawAdvertisementPayload struct { data [31]byte len uint8 } // Bytes returns the raw advertisement packet as a byte slice. -func (buf *rawAdvertisementPayload) Bytes() []byte { +func (buf *RawAdvertisementPayload) Bytes() []byte { return buf.data[:buf.len] } @@ -188,7 +201,7 @@ func (buf *rawAdvertisementPayload) Bytes() []byte { // // See this list of field types: // https://www.bluetooth.com/specifications/assigned-numbers/generic-access-profile/ -func (buf *rawAdvertisementPayload) findField(fieldType byte) []byte { +func (buf *RawAdvertisementPayload) FindField(fieldType byte) []byte { data := buf.Bytes() for len(data) >= 2 { fieldLength := data[0] @@ -206,12 +219,12 @@ func (buf *rawAdvertisementPayload) findField(fieldType byte) []byte { // LocalName returns the local name (complete or shortened) in the advertisement // payload. -func (buf *rawAdvertisementPayload) LocalName() string { - b := buf.findField(9) // Complete Local Name +func (buf *RawAdvertisementPayload) LocalName() string { + b := buf.FindField(9) // Complete Local Name if len(b) != 0 { return string(b) } - b = buf.findField(8) // Shortened Local Name + b = buf.FindField(8) // Shortened Local Name if len(b) != 0 { return string(b) } @@ -221,11 +234,11 @@ func (buf *rawAdvertisementPayload) LocalName() string { // HasServiceUUID returns true whether the given UUID is present in the // advertisement payload as a Service Class UUID. It checks both 16-bit UUIDs // and 128-bit UUIDs. -func (buf *rawAdvertisementPayload) HasServiceUUID(uuid UUID) bool { +func (buf *RawAdvertisementPayload) HasServiceUUID(uuid UUID) bool { if uuid.Is16Bit() { - b := buf.findField(0x03) // Complete List of 16-bit Service Class UUIDs + b := buf.FindField(0x03) // Complete List of 16-bit Service Class UUIDs if len(b) == 0 { - b = buf.findField(0x02) // Incomplete List of 16-bit Service Class UUIDs + b = buf.FindField(0x02) // Incomplete List of 16-bit Service Class UUIDs } uuid := uuid.Get16Bit() for i := 0; i < len(b)/2; i++ { @@ -236,9 +249,9 @@ func (buf *rawAdvertisementPayload) HasServiceUUID(uuid UUID) bool { } return false } else { - b := buf.findField(0x07) // Complete List of 128-bit Service Class UUIDs + b := buf.FindField(0x07) // Complete List of 128-bit Service Class UUIDs if len(b) == 0 { - b = buf.findField(0x06) // Incomplete List of 128-bit Service Class UUIDs + b = buf.FindField(0x06) // Incomplete List of 128-bit Service Class UUIDs } uuidBuf1 := uuid.Bytes() for i := 0; i < len(b)/16; i++ { @@ -258,8 +271,27 @@ func (buf *rawAdvertisementPayload) HasServiceUUID(uuid UUID) bool { } } +/// Very dumb attempts at reworking this code ************************************************ +var FUUID uint16 + +func (buf *RawAdvertisementPayload) FindServiceUUIDInfo(uuid UUID) uint16 { + if uuid.Is16Bit() { + b := buf.FindField(0x03) // Complete List of 16-bit Service Class UUIDs + if len(b) == 0 { + b = buf.FindField(0x02) // Incomplete List of 16-bit Service Class UUIDs + } + for i := 0; i < len(b)/2; i++ { + foundUUID := uint16(b[i*2]) | (uint16(b[i*2+1]) << 8) + + FUUID = foundUUID + } + + } + return FUUID +} + // reset restores this buffer to the original state. -func (buf *rawAdvertisementPayload) reset() { +func (buf *RawAdvertisementPayload) reset() { // The data is not reset (only the length), because with a zero length the // data is undefined. buf.len = 0 @@ -268,7 +300,7 @@ func (buf *rawAdvertisementPayload) reset() { // addFromOptions constructs a new advertisement payload (assumed to be empty // before the call) from the advertisement options. It returns true if it fits, // false otherwise. -func (buf *rawAdvertisementPayload) addFromOptions(options AdvertisementOptions) (ok bool) { +func (buf *RawAdvertisementPayload) addFromOptions(options AdvertisementOptions) (ok bool) { buf.addFlags(0x06) if options.LocalName != "" { if !buf.addCompleteLocalName(options.LocalName) { @@ -290,7 +322,7 @@ func (buf *rawAdvertisementPayload) addFromOptions(options AdvertisementOptions) // addFlags adds a flags field to the advertisement buffer. It returns true on // success (the flags can be added) and false on failure. -func (buf *rawAdvertisementPayload) addFlags(flags byte) (ok bool) { +func (buf *RawAdvertisementPayload) addFlags(flags byte) (ok bool) { if int(buf.len)+3 > len(buf.data) { return false // flags don't fit } @@ -304,7 +336,7 @@ func (buf *rawAdvertisementPayload) addFlags(flags byte) (ok bool) { // addCompleteLocalName adds the Complete Local Name field to the advertisement // buffer. It returns true on success (the name fits) and false on failure. -func (buf *rawAdvertisementPayload) addCompleteLocalName(name string) (ok bool) { +func (buf *RawAdvertisementPayload) addCompleteLocalName(name string) (ok bool) { if int(buf.len)+len(name)+2 > len(buf.data) { return false // name doesn't fit } @@ -319,7 +351,7 @@ func (buf *rawAdvertisementPayload) addCompleteLocalName(name string) (ok bool) // addServiceUUID adds a Service Class UUID (16-bit or 128-bit). It has // currently only been designed for adding single UUIDs: multiple UUIDs are // stored in separate fields without joining them together in one field. -func (buf *rawAdvertisementPayload) addServiceUUID(uuid UUID) (ok bool) { +func (buf *RawAdvertisementPayload) addServiceUUID(uuid UUID) (ok bool) { // Don't bother with 32-bit UUID support, it doesn't seem to be used in // practice. if uuid.Is16Bit() { diff --git a/vendor/tinygo.org/x/bluetooth/gap_linux.go b/vendor/tinygo.org/x/bluetooth/gap_linux.go index 9d3fd14..1a23e14 100644 --- a/vendor/tinygo.org/x/bluetooth/gap_linux.go +++ b/vendor/tinygo.org/x/bluetooth/gap_linux.go @@ -59,7 +59,7 @@ func (a *Advertisement) Start() error { if a.advertisement != nil { panic("todo: start advertisement a second time") } - _, err := api.ExposeAdvertisement(a.adapter.id, a.properties, uint32(a.properties.Timeout)) + _, err := api.ExposeAdvertisement(a.adapter.ID, a.properties, uint32(a.properties.Timeout)) if err != nil { return err } @@ -219,6 +219,8 @@ func makeScanResult(props *device.Device1Properties) ScanResult { serviceUUIDs = append(serviceUUIDs, parsedUUID) } + //var ManufactuerData UUID + a := Address{MACAddress{MAC: addr}} a.SetRandom(props.AddressType == "random") diff --git a/vendor/tinygo.org/x/bluetooth/gattc_linux.go b/vendor/tinygo.org/x/bluetooth/gattc_linux.go index 57b875e..2a7113f 100644 --- a/vendor/tinygo.org/x/bluetooth/gattc_linux.go +++ b/vendor/tinygo.org/x/bluetooth/gattc_linux.go @@ -39,6 +39,7 @@ func (s *DeviceService) UUID() UUID { // services haven't been resolved yet) and uses this list of cached services. func (d *Device) DiscoverServices(uuids []UUID) ([]DeviceService, error) { for { + resolved, err := d.device.GetServicesResolved() if err != nil { return nil, err @@ -47,7 +48,6 @@ func (d *Device) DiscoverServices(uuids []UUID) ([]DeviceService, error) { break } // This is a terrible hack, but I couldn't find another way. - time.Sleep(50 * time.Millisecond) } @@ -245,3 +245,4 @@ func (c *DeviceCharacteristic) Read(data []byte) (int, error) { copy(data, result) return len(result), nil } + diff --git a/vendor/tinygo.org/x/bluetooth/gatts_linux.go b/vendor/tinygo.org/x/bluetooth/gatts_linux.go index 0422c44..5e1d3ef 100644 --- a/vendor/tinygo.org/x/bluetooth/gatts_linux.go +++ b/vendor/tinygo.org/x/bluetooth/gatts_linux.go @@ -18,7 +18,7 @@ type Characteristic struct { // Service struct. func (a *Adapter) AddService(s *Service) error { app, err := service.NewApp(service.AppOptions{ - AdapterID: a.id, + AdapterID: a.ID, }) if err != nil { return err