1

I am writing a custom service over BLE to transmit custom characteristics. It has it's own UUID such as '8E400001-B5A3-F393-E0A9-E50E24DCCA9E'.

I have found that a particular android app (BLE client) I wish to support requires that a custom service UUID is included in the advertising packet.

However our peripheral is running via bluez 5.43 on debian and I cannot figure out how to put this UUID in the advertising packet.

I think it will be something like:

hcitool -i hci0 cmd 0x08 0x0008 .... ?

pstanton
  • 35,033
  • 24
  • 126
  • 168
  • The HCI command that you are try to send is the "LE Set Advertising Data Command" which is documented in the Bluetooth Core specification Vol. 2 Part E section 7.8.7. After 0x0008 come Advertising_Data_Length and Advertising_Data. The latter is documented [here](https://www.bluetooth.org/DocMan/handlers/DownloadDoc.ashx?doc_id=421047&_ga=2.220103193.1266709538.1511469879-1085787902.1511469879). Sorry but I have no time to try it our now and give you the full command. – Šatov Nov 23 '17 at 20:51
  • A quick search found this: https://stackoverflow.com/questions/35872097/advertise-bluetooth-le-service-using-hcitool – Tim Tisdall Nov 24 '17 at 14:10
  • So the full command should be `hcitool -i hci0 cmd 0x08 0x0008 12 11 07 8E 40 00 01 B5 A3 F3 93 E0 A9 E5 0E 24 DC CA 9E 00 00 00 00 00 00 00 00 00 00 00 00 00` – Šatov Nov 24 '17 at 20:49

1 Answers1

1

I verified the following commands to be working (BlueZ ver 5.43, Linux 4.9.0-2-amd64 (x86_64)):

hcitool -i hci0 cmd 0x08 0x0008 12 11 07 9E CA DC 24 0E E5 A9 E0 93 F3 A3 B5 01 00 40 8E 00 00 00 00 00 00 00 00 00 00 00 00 00

Explanation:

I assume everything until 0x0008 is clear, if not let me know or look at the description of the LE Set Advertising Data Command in the spec. 0x12 is Advertising_Data_Length, i.e., the number of useful bytes that comes after (until the padding bytes). Now you have to insert the Advertising_Data, which is formatted as in Vol 3 Part C, Section 11, Fig. 11.1 of the spec. So, 0x11 is the length of the AD Structure. Then, 0x07 is the AD Type "Complete List of 128-bit Service Class UUIDs" (see here). Finally comes the UUID. Notice that everything is little endian.

Then send the LE Set Advertising Parameters Commands, for example:

hcitool -i hci0 cmd 0x08 0x0006 00 08 00 08 00 00 00 00 00 00 00 00 00 07 00

Then enable advertising by sending the LE Advertising Enable command:

hcitool -i hci0 cmd 0x08 0x000A 01

See btmon output here.

Šatov
  • 323
  • 3
  • 9
  • sorry it took so long for me to verify, but this works great. any chance you can explain how the service uuid is encoded into the hcitool command syntax? thanks. – pstanton Dec 11 '17 at 08:24
  • ah, i can now see that the uuid is reversed (little endian). great explanation. thanks again. – pstanton Dec 12 '17 at 04:16