bluetoothbluetooth-lowenergybluezhcibtle

How to check if BLE advertisement is already enabled (HCI)


BLE advertising can be enabled using HCI_LE_Set_Advertising_Enable[1] command which returns status 0x00 if HCI_LE_Set_Advertising_Enable command succeeded or status code 0x01 to 0xFF[2] if the command failed.

If the advertisement is already enabled (e.g. calling this command for the second time with Advertising_Enable parameter set to 0x01) then this or HCI_LE_Set_Advertising_Data commands will return status 0x0C (Command Disallowed).

There are (at least) two problems with this:

How to check if the LE advertisement is already enabled to be able to perform safe/strict error handling? I cannot find any command for Get Advertising Status in the BT Core Specs. I cannot rely on something like

if ((rc == -1) && (errno == EIO)) {
    /* Actually OK, advertising is already enabled */
    return 0;
}

Thank you.

References:


Solution

  • The idea is that the Bluetooth stack on the host side should know if it has started advertising or not. That's how it should work. If you manually bypass the Bluetooth stack on the host side (which you shouldn't do unless you are debugging or something), sending your own hci command, then you can't know.