I am running BlueZ 5.56 on a custom embedded Linux 5.15 board. The board has the Atmel wilc3000 wifi/bluetooth radio onboard. I have implemented a python GATT server, based on the BlueZ example, that works fine on the raspberry pi. However, the advertising portion of that example does not work with the wilc3000. Therefore I am using hcitool manually to start advertisments. These advertisements work - however I can not figure out how to combine the Manufacturing data with a Service UUID.
I am using LightBlue on my Macbook to test and debug. If I setup both the following commands, the advertisements seem to fight each other, sometimes I get one or the other, and sometimes I get empty advertisments with nothing received.
How can I combine the 2 so that I can receive both manufacturing and service uuid advertisements at the same time?
# Custom Manufacturing Advertisement
hcitool -i hci0 cmd 0x08 0x0008 11 02 01 06 07 09 61 62 63 64 65 66 05 ff fe 01 00 31 00 00 00 00 00 00 00 00 00 00 00 00 00 00
# Custom Service UUID Advertisement
hcitool -i hci0 cmd 0x08 0x0008 12 11 07 30 44 5a 3e 35 50 0f ab 01 48 fd 25 11 63 a7 f5 00 00 00 00 00 00 00 00 00 00 00 00 00
I think the main problem is that you are setting the advert report twice, and what's most likely happening is that the second advert report is overwriting the first one. You need to call the hcitool cmd only once as follows:-
hcitool -i hci0 cmd 0x08 0x0008 12 02 01 06 05 02 FF 01 FF 02 08 FF 00 11 22 33 44 55 66
BLE data in adverts is decoded as follows (based on the Assigned Numbers Document):-
So the data above is decoded as:
12 - 18 (length of full advert report)
02 - Length of next advert report entry (2 bytes)
01 - Type: Flags
06 - 02 && 04 LE General Discoverable && BR/EDR Not supported
05 - Length of the next advert report entry (5 bytes)
02 - Type: Complete list of 16-bit UUIDs
FF 01 FF 02 - The UUIDs 0xFF01 and 0xFF02 will be included in the advert report
08 - Length of the next advert report entry
FF - Type: Manufacturer data
00 11 22 33 44 55 66 - The actual manufacturer data
That being said, I would recommend that you avoid using the hcitool command as it is deprecated and has many limitations compared to the newer bluez commands. Instead, you can use the btmgmt tool (if it is available on your system) to send out adverts that contain both the UUID and the manufacturer data. To do this, you can use the following command:-
sudo btmgmt add-adv -u FF01 -u FF02 -d 02010608FF00112233445566 1
The line above adds UUIDs 0xFF01, 0xFF02, and the manufacturer data 00112233445566 to the advertising report. The full list of btmgmt add-adv options are:-
Usage: add-adv [options] <instance_id>
Options:
-u, --uuid <uuid> Service UUID
-d, --adv-data <data> Advertising Data bytes
-s, --scan-rsp <data> Scan Response Data bytes
-t, --timeout <timeout> Timeout in seconds
-D, --duration <duration> Duration in seconds
-P, --phy <phy> Phy type, Specify 1M/2M/CODED
-c, --connectable "connectable" flag
-g, --general-discov "general-discoverable" flag
-l, --limited-discov "limited-discoverable" flag
-n, --scan-rsp-local-name "local-name" flag
-a, --scan-rsp-appearance "appearance" flag
-m, --managed-flags "managed-flags" flag
-p, --tx-power "tx-power" flag
e.g.:
add-adv -u 180d -u 180f -d 080954657374204C45 1
BLE data in adverts is decoded as follows (based on the Assigned Numbers Document):-
So the meaning of the advert data I added:-
02 - Length (2 bytes)
01 - Type: Flags
06 - Flag - 02 && 04 LE General Discoverable && BR/EDR Not supported
08 - Length (8 bytes)
FF - Type: Manufacturer data
00112233445566 - Actual manufacturer data
Some other useful links:-