Hey,
Thank you for your reply, I did some testing and used Packet Logger to get more info and here's what I got:
This is how I create ASDiscoveryDescriptor
, nothing fancy, declaring the service UUID I am interested in.
let descriptor = ASDiscoveryDescriptor()
descriptor.bluetoothServiceUUID = CBUUID(string: device.serviceUUID)
descriptor.supportedOptions = [.bluetoothPairingLE]
Info.plist
contains all the required data as well (the same service uuid and Bluetooth for supporred modes).
I'll be using code above to discover the peripheral.
**Case 1 - working scenario: **
In this case peripheral advertises only service uuid in it's advertisment data and it's local name is "Periph-1234". Using packet logger I can see two HCI events: ADV_IN followed by SCAN_RSP
Jun 17 17:19:43.268 HCI Event 0x0000 2C:CF:67:02:8A:4B LE - Advertising Report - 1 Report - Normal - Public - 2C:CF:67:02:8A:4B - ADV_IND -31 dBm - Channel 37
Parameter Length: 33 (0x21)
Num Reports: 0X01
Report 0
Event Type: Connectable Undirected Advertising (ADV_IND)
Address Type: Public
Peer Address: 2C:CF:67:02:8A:4B
Data Length: 21
Flags: 0x6
LE Limited General Discoverable Mode
BR/EDR Not Supported
128 Bit UUIDs: 9727905B-EC88-AB8F-A041-F77A8D48343D
Data: 02 01 06 11 07 97 27 90 5B EC 88 AB 8F A0 41 F7 7A 8D 48 34 3D
RSSI: -31 dBm
Jun 17 17:19:43.268 HCI Event 0x0000 00:00:00:00:00:00 00000000: 3E21 0201 1000 4B8A 0267 CF2C 1502 0106 >!....K..g.,....
00000000: 3E21 0201 1000 4B8A 0267 CF2C 1502 0106 >!....K..g.,....
00000010: 1107 9727 905B EC88 AB8F A041 F77A 8D48 ...'.[.....A.z.H
00000020: 343D E1 4=.
Jun 17 17:19:43.269 HCI Event 0x0000 2C:CF:67:02:8A:4B LE - Advertising Report - 1 Report - Normal - Public - 2C:CF:67:02:8A:4B - SCAN_RSP -31 dBm - Periph-1234 - Channel 37
Parameter Length: 25 (0x19)
Num Reports: 0X01
Report 0
Event Type: Scan Response (SCAN_RSP)
Address Type: Public
Peer Address: 2C:CF:67:02:8A:4B
Data Length: 13
Local Name: Periph-1234
Data: 0C 09 50 65 72 69 70 68 2D 31 32 33 34
RSSI: -31 dBm
Jun 17 17:19:43.269 HCI Event 0x0000 00:00:00:00:00:00 00000000: 3E19 0201 1400 4B8A 0267 CF2C 0D0C 0950 >.....K..g.,...P
00000000: 3E19 0201 1400 4B8A 0267 CF2C 0D0C 0950 >.....K..g.,...P
00000010: 6572 6970 682D 3132 3334 E1 eriph-1234.
In this case, using descriptor code above, I have no issues discovering the peripheral.
Case 2 - not working
In this case, peripheral includes manufacturer data in in's advertisment packet. it's sets its company identifier and arbitrary data (in this case - a short id with value "1234" for simplicity). Again, using packet logger, I see ADV_IND and SCAN_RSP as follow:
Jun 17 17:22:17.289 HCI Event 0x0000 2C:CF:67:02:8A:4B LE - Advertising Report - 1 Report - Normal - Public - 2C:CF:67:02:8A:4B - ADV_IND -32 dBm - Manufacturer Specific Data - Channel 37
Parameter Length: 41 (0x29)
Num Reports: 0X01
Report 0
Event Type: Connectable Undirected Advertising (ADV_IND)
Address Type: Public
Peer Address: 2C:CF:67:02:8A:4B
Data Length: 29
Flags: 0x6
LE Limited General Discoverable Mode
BR/EDR Not Supported
128 Bit UUIDs: 9727905B-EC88-AB8F-A041-F77A8D48343D
Data: 02 01 06 11 07 97 27 90 5B EC 88 AB 8F A0 41 F7 7A 8D 48 34 3D 07 FF FF FF 31 32 33 34
RSSI: -32 dBm
Jun 17 17:22:17.289 HCI Event 0x0000 00:00:00:00:00:00 00000000: 3E29 0201 0000 4B8A 0267 CF2C 1D02 0106 >)....K..g.,....
00000000: 3E29 0201 0000 4B8A 0267 CF2C 1D02 0106 >)....K..g.,....
00000010: 1107 9727 905B EC88 AB8F A041 F77A 8D48 ...'.[.....A.z.H
00000020: 343D 07FF FFFF 3132 3334 E0 4=....1234.
Jun 17 17:22:17.289 HCI Event 0x0000 2C:CF:67:02:8A:4B LE - Advertising Report - 1 Report - Normal - Public - 2C:CF:67:02:8A:4B - SCAN_RSP -32 dBm - Periph-1234 - Channel 37
Parameter Length: 25 (0x19)
Num Reports: 0X01
Report 0
Event Type: Scan Response (SCAN_RSP)
Address Type: Public
Peer Address: 2C:CF:67:02:8A:4B
Data Length: 13
Local Name: Periph-1234
Data: 0C 09 50 65 72 69 70 68 2D 31 32 33 34
RSSI: -32 dBm
Jun 17 17:22:17.289 HCI Event 0x0000 00:00:00:00:00:00 00000000: 3E19 0201 0400 4B8A 0267 CF2C 0D0C 0950 >.....K..g.,...P
00000000: 3E19 0201 0400 4B8A 0267 CF2C 0D0C 0950 >.....K..g.,...P
00000010: 6572 6970 682D 3132 3334 E0 eriph-1234.
SCAN_RSP is the same in both cases.
the only difference I see is in ADV_IND where its few bytes longer
I played around a little bit with configuration of ASDiscoveryDescriptor
and found that setting bluetoothCompanyIdentifier
allows me to discover the peripheral regardless if its contains manufacturer data in advertisment packet or not as below (Info.plist needs update as well to include NSAccessorySetupBluetoothCompanyIdentifiers
):
let descriptor = ASDiscoveryDescriptor()
descriptor.bluetoothServiceUUID = CBUUID(string: device.serviceUUID)
descriptor.bluetoothCompanyIdentifier = .init(rawValue: 0xffff)
descriptor.supportedOptions = [.bluetoothPairingLE]
I'd expect AccessorySetupKit to discover the peripheral regardless of manufacturer's data when configured to look for service uuid. This behavior is not documented anywhere and documentation is misleading as it explicity states that descriptor requires bluetoothServiceUUID
OR bluetoothCompanyIdentifier
- not both.
Such situation and undocumented behavior can lead to unexpected behavior with firmware updates.
Can you please confirm if what I observe is a unintentional behavior or an expected one?