@@ -73,35 +73,59 @@ func (a *Adapter) Scan(callback func(*Adapter, ScanResult)) error {
73
73
continue
74
74
}
75
75
76
- for i := 0 ; i < int (a .hci .advData .eirLength ); {
77
- l , t := int (a .hci .advData .eirData [i ]), a .hci .advData .eirData [i + 1 ]
78
- if l < 1 {
79
- break
76
+ rp := rawAdvertisementPayload {len : a .hci .advData .eirLength }
77
+ copy (rp .data [:], a .hci .advData .eirData [:a .hci .advData .eirLength ])
78
+ if rp .LocalName () != "" {
79
+ println ("LocalName:" , rp .LocalName ())
80
+ adf .LocalName = rp .LocalName ()
81
+ }
82
+
83
+ // Complete List of 16-bit Service Class UUIDs
84
+ if b := rp .findField (0x03 ); len (b ) > 0 {
85
+ for i := 0 ; i < len (b )/ 2 ; i ++ {
86
+ uuid := uint16 (b [i * 2 ]) | (uint16 (b [i * 2 + 1 ]) << 8 )
87
+ adf .ServiceUUIDs = append (adf .ServiceUUIDs , New16BitUUID (uuid ))
88
+ }
89
+ }
90
+ // Incomplete List of 16-bit Service Class UUIDs
91
+ if b := rp .findField (0x02 ); len (b ) > 0 {
92
+ for i := 0 ; i < len (b )/ 2 ; i ++ {
93
+ uuid := uint16 (b [i * 2 ]) | (uint16 (b [i * 2 + 1 ]) << 8 )
94
+ adf .ServiceUUIDs = append (adf .ServiceUUIDs , New16BitUUID (uuid ))
95
+ }
96
+ }
97
+
98
+ // Complete List of 128-bit Service Class UUIDs
99
+ if b := rp .findField (0x07 ); len (b ) > 0 {
100
+ for i := 0 ; i < len (b )/ 16 ; i ++ {
101
+ var uuid [16 ]byte
102
+ copy (uuid [:], b [i * 16 :i * 16 + 16 ])
103
+ adf .ServiceUUIDs = append (adf .ServiceUUIDs , NewUUID (uuid ))
80
104
}
105
+ }
81
106
82
- switch t {
83
- case ADIncompleteAdvertisedService16 , ADCompleteAdvertisedService16 :
84
- adf .ServiceUUIDs = append (adf .ServiceUUIDs , New16BitUUID (binary .LittleEndian .Uint16 (a .hci .advData .eirData [i + 2 :i + 4 ])))
85
- case ADIncompleteAdvertisedService128 , ADCompleteAdvertisedService128 :
107
+ // Incomplete List of 128-bit Service Class UUIDs
108
+ if b := rp .findField (0x06 ); len (b ) > 0 {
109
+ for i := 0 ; i < len (b )/ 16 ; i ++ {
86
110
var uuid [16 ]byte
87
- copy (uuid [:], a . hci . advData . eirData [ i + 2 : i + 18 ])
111
+ copy (uuid [:], b [ i * 16 : i * 16 + 16 ])
88
112
adf .ServiceUUIDs = append (adf .ServiceUUIDs , NewUUID (uuid ))
89
- case ADShortLocalName , ADCompleteLocalName :
90
- if debug {
91
- println ("local name" , string (a .hci .advData .eirData [i + 2 :i + 1 + l ]))
92
- }
93
-
94
- adf .LocalName = string (a .hci .advData .eirData [i + 2 : i + 1 + l ])
95
- case ADServiceData :
96
- // TODO: handle service data
97
- case ADManufacturerData :
98
- // TODO: handle manufacturer data
99
113
}
114
+ }
100
115
101
- i += l + 1
116
+ // service data
117
+ sd := rp .ServiceData ()
118
+ if len (sd ) > 0 {
119
+ adf .ServiceData = append (adf .ServiceData , sd ... )
102
120
}
103
121
104
- random := a .hci .advData .peerBdaddrType == 0x01
122
+ // manufacturer data
123
+ md := rp .ManufacturerData ()
124
+ if len (md ) > 0 {
125
+ adf .ManufacturerData = append (adf .ManufacturerData , md ... )
126
+ }
127
+
128
+ random := a .hci .advData .peerBdaddrType == GAPAddressTypeRandomStatic
105
129
106
130
callback (a , ScanResult {
107
131
Address : Address {
@@ -163,11 +187,11 @@ func (a *Adapter) Connect(address Address, params ConnectionParams) (Device, err
163
187
164
188
peerRandom := uint8 (0 )
165
189
if address .isRandom {
166
- peerRandom = 1
190
+ peerRandom = GAPAddressTypeRandomStatic
167
191
}
168
192
localRandom := uint8 (0 )
169
193
if a .hci .address .isRandom {
170
- localRandom = 1
194
+ localRandom = GAPAddressTypeRandomStatic
171
195
}
172
196
if err := a .hci .leCreateConn (0x0060 , // interval
173
197
0x0030 , // window
@@ -334,11 +358,8 @@ func (a *Adapter) DefaultAdvertisement() *Advertisement {
334
358
func (a * Advertisement ) Configure (options AdvertisementOptions ) error {
335
359
a .advertisementType = options .AdvertisementType
336
360
337
- switch {
338
- case options .LocalName != "" :
361
+ if options .LocalName != "" {
339
362
a .localName = []byte (options .LocalName )
340
- default :
341
- a .localName = []byte ("TinyGo" )
342
363
}
343
364
344
365
a .serviceUUIDs = append ([]UUID {}, options .ServiceUUIDs ... )
@@ -369,7 +390,7 @@ func (a *Advertisement) Start() error {
369
390
370
391
localRandom := uint8 (0 )
371
392
if a .adapter .hci .address .isRandom {
372
- localRandom = 1
393
+ localRandom = GAPAddressTypeRandomStatic
373
394
}
374
395
375
396
if err := a .adapter .hci .leSetAdvertisingParameters (a .interval , a .interval ,
0 commit comments