Skip to content

Commit 9482530

Browse files
committed
fix: correct parsing of ServiceData and ManufacturerData and add some helpful constants
Signed-off-by: deadprogram <[email protected]>
1 parent c6dfccb commit 9482530

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

gap.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,17 @@ var (
1212
errNotYetImplmented = errors.New("bluetooth: not implemented")
1313
)
1414

15+
const (
16+
// Public address
17+
GAPAddressTypePublic = 0x00
18+
// Random Static address
19+
GAPAddressTypeRandomStatic = 0x01
20+
// Private Resolvable address
21+
GAPAddressTypeRandomPrivateResolvable = 0x02
22+
// Private Non-Resolvable address
23+
GAPAddressTypeRandomPrivateNonResolvable = 0x03
24+
)
25+
1526
// MACAddress contains a Bluetooth address which is a MAC address.
1627
type MACAddress struct {
1728
// MAC address of the Bluetooth device.
@@ -313,7 +324,7 @@ func (buf *rawAdvertisementPayload) HasServiceUUID(uuid UUID) bool {
313324
// ManufacturerData returns the manufacturer data in the advertisement payload.
314325
func (buf *rawAdvertisementPayload) ManufacturerData() []ManufacturerDataElement {
315326
var manufacturerData []ManufacturerDataElement
316-
for index := 0; index < int(buf.len)+4; index += int(buf.data[index]) + 1 {
327+
for index := 0; index < int(buf.len); index += int(buf.data[index]) + 1 {
317328
fieldLength := int(buf.data[index+0])
318329
if fieldLength < 3 {
319330
continue
@@ -334,7 +345,7 @@ func (buf *rawAdvertisementPayload) ManufacturerData() []ManufacturerDataElement
334345
// ServiceData returns the service data in the advertisment payload
335346
func (buf *rawAdvertisementPayload) ServiceData() []ServiceDataElement {
336347
var serviceData []ServiceDataElement
337-
for index := 0; index < int(buf.len)+4; index += int(buf.data[index]) + 1 {
348+
for index := 0; index < int(buf.len); index += int(buf.data[index]) + 1 {
338349
fieldLength := int(buf.data[index+0])
339350
if fieldLength < 3 { // field has only length and type and no data
340351
continue

0 commit comments

Comments
 (0)