Qt BLE advertising gives "advertising error", "HCI command disallowed"

255 views Asked by At

I wanted to use Qt and Qt creator to advertise on my laptop with BLE. When I start the application example "heart-rate server", it gives the error "advertising error". Btmon shows the error "HCI command disallowed". (https://i.stack.imgur.com/433yc.png) (https://i.stack.imgur.com/LJzqQ.png)

I am running as root. https://i.stack.imgur.com/36kN1.png

I’m using Qt version 5.15.2. Trying it on a linux laptop with ubuntu version 22.04.2

When I tried to advertise with bluetoothctl "advertise on" in the terminal. It did work and all commands are allowed in btmon.

How can I solve this?

2

There are 2 answers

0
David Netherwood On

It may be your app does not have the right capabilities. Try:

sudo setcap 'cap_net_raw+ep' <path to your app>

If that does not work:

sudo setcap 'cap_net_admin+ep cap_sys_rawio+ep  cap_net_raw+ep'  <path to your app>
3
ArthurZheng On

Bluetooth spec "3.1.1 Legacy and extended advertising":

If, since the last power-on or reset, the Host has ever issued a legacy advertising command and then issues an extended advertising command, or has ever issued an extended advertising command and then issues a legacy advertising command, the Controller shall return the error code Command Disallowed (0x0C).

This problem occurs because the system automatically runs some extended advertising commands when starting the Bluetooth device. Start btmod and then run hcitool hci0 up and hcitool hci0 down commands, we can confirm this in the monitoring information.

To solve this problem, we can reset the controller by running the command: hcitool cmd 0x03 0x0003 so that the controller can receive the legacy advertising command. After running this command, we can verify the effect by running hcitool lescan. Before resetting, this command will report an error: 'Set scan parameters failed: Input/output error'.