Reputation: 690
I can't get the btmgmt add-adv command to work. I've tried the suggested example and that doesn't work either. My goal is to set up the advertising and scan response payloads with my own custom payloads using the BlueZ 5.x stack (I'm using v. 5.31).
I've got le, connectable, advertising, and power enabled. I've tried various combinations (power off, advertising off, etc.) and it still doesn't work. Here's the example command (with response):
sudo btmgmt add-adv -u 180d -u 180f -d 080954657374204C45 1
Add Advertising failed with status 0x01 (Unknown Command)
Can anyone help me?
Thanks
Upvotes: 2
Views: 4709
Reputation: 690
Arrgh!! It took me way too much time to figure this one out. If there was some documentation, this would have been avoided. Instead, I feel like I'm poking around in the dark. Fortunately, I poked the right place, but only after a week of fumbling around in the dark. Here's what was required to get this working properly:
The Add Advertising failed with status 0x01 (Unknown Command) response was due to the fact that my Linux kernel did not support this feature. I was using v. 3.19. Once I upgraded to v. 4.1.1 (I think 4.0 is probably sufficient), I no longer got that response.
Even after the kernel upgrade, I still did not have control over the advertisement payload or the scan response payload. After some more fumbling, I found that I misunderstood the meaning of the advertisement flag in the btmgmt command, i.e. do not activate the advertising flag if you want to customize your ad or scan response payloads:
sudo btmgmt advertising on
This causes a default/predetermined advertisement payload to be used instead of your custom payload (not very intuitive). The scan response will contain the device name. Instead, turn that flag off like so:
sudo btmgmt advertising off
Then use your own custom ad and scan payload like so:
sudo btmgmt add-adv -d 02010606094142434400 -s 05061805051206000a00020a00 1
This will turn on advertising with your custom payload once you've powered up the adapter. The example above sets up the complete name in the advertisement payload. The scan response payload is also set with the following: 16-bit UUID, connection interval range, and TX power level:
Complete name: "ABCD"
UUID: 1805
Connection interval range: 7.5 ms to 12.5 ms
TX power level: 0 dBm
If you want to understand the meaning of the header bytes in the payloads I've posted, I suggest you read the Bluetooth Core Specification documents. Another place to look is in the BlueZ source code (eir.h in the src directory).
I hope this helps the next person going down this path save some time.
Upvotes: 9