0

Several questions about this wonderful duo btmgmt/bluetoothctl on a peripheral device with bluez 5.55.

Is it normal that the return code from btmgmt is almost always 0 even if there is an error? I check the code and it seems to be the expected behaviour. But I don't understand why...

# btmgmt bredr off
Set BR/EDR for hci0 failed with status 0x0b (Rejected)
# echo $?
0

Indeed when I check the btmgmt code. Even if the status is not equal to 0. We use the done label which returns an EXIT_SUCCESS code... How can I check properly the result of my command?

static void setting_rsp(uint16_t op, uint16_t id, uint8_t status, uint16_t len,
                            const void *param)
{
    const uint32_t *rp = param;

    if (status != 0) {
        error("%s for hci%u failed with status 0x%02x (%s)",
            mgmt_opstr(op), id, status, mgmt_errstr(status));
        goto done;
    }

    if (len < sizeof(*rp)) {
        error("Too small %s response (%u bytes)",
                            mgmt_opstr(op), len);
        goto done;
    }

    print("hci%u %s complete, settings: %s", id, mgmt_opstr(op),
                        settings2str(get_le32(rp)));

done:
    bt_shell_noninteractive_quit(EXIT_SUCCESS);
}

I have a lot of issue with btmgmt... I have a lot of random failure result when I run the command. And the only way for me to check the result is to use btmgmt info | grep current | grep XXX to check the current settings on hci0. Is it better to use bluetoothctl instead? I can see also some code in mgmt-tester.c. Do I have to used this c api instead ? My current way to enable/disable bluetooth :

// Enable
system ("/usr/bin/btmgmt -i hci0 power off");
system ("/usr/bin/btmgmt -i hci0 le on"); // BLE enable
system ("/usr/bin/btmgmt -i hci0 bredr on"); // BTC enable
system ("/usr/bin/btmgmt -i hci0 connectable on");
system ("/usr/bin/btmgmt -i hci0 bondable on");
system ("/usr/bin/btmgmt -i hci0 discov on");
system ("/usr/bin/btmgmt -i hci0 name XXXXX");
system ("/usr/bin/btmgmt -i hci0 advertising on");
system ("/usr/bin/btmgmt -i hci0 power on");

// Disable
system ("/usr/bin/btmgmt -i hci0 discov off");
system ("/usr/bin/btmgmt -i hci0 advertising off");
system ("/usr/bin/btmgmt -i hci0 connectable off");
system ("/usr/bin/btmgmt -i hci0 power off");

I try to implement the same with bluetoothctl. Problem is that I cannot find a way to enable bonding with bluetoothctl. No way also to enable the duo mode le/btc with bluetoothctl.

My last point concerns advertising. I would like to send a custom advertising data in manufacter data field. I try something like this on my peripheral device:

# bluetoothctl
Agent registered
[bluetooth]# menu advertise

Use "help" for a list of available commands in a menu.
Use "menu <submenu>" if you want to enter any submenu.
Use "back" if you want to return to menu main.
[bluetooth]# manufacturer 0xffff 0x12 0x34 0x56 0x78
[bluetooth]# name coucou
[bluetooth]# back

[CHG] Controller AC:64:CF:ZZ:YY:XX SupportedInstances: 0x04 (4)
[CHG] Controller AC:64:CF:ZZ:YY:XX ActiveInstances: 0x01 (1)
Advertising object registered
Manufacturer: 65535
  12 34 56 78                                      .4Vx            
Tx Power: off
LocalName: coucou
Appearance: off
Discoverable: on
[bluetooth]# 

On another device, I sniff bluetooth packet with btmon or bluetoothctl scan on but I cannot see any manufacturer data match my data.

ArthurLambert
  • 749
  • 1
  • 7
  • 30
  • I developed a piece of code to drive hci device in c code using mgmt protocol because dbus one does not integrate all the command I need : https://github.com/Evanok/mgmt_example. Problem is that sometimes the mgmt socket return busy forever.. I have the bondable setting which is disable by magic sometimes. I have a kind of watchdog which check current settings every 5 minutes. Sometimes even if everything is ok, I cannot connect to the device without reason. Only solution is to disable/enable the hci device. – ArthurLambert Dec 08 '20 at 09:21
  • According to this post, to disable BR/EDR you first need to shutdown the controller then enable LE (`btmgmt le on`) and then disable BR/EDR (`btmgmt bredr off`): https://www.spinics.net/lists/linux-bluetooth/msg63087.html – Pierz Dec 10 '21 at 15:44

0 Answers0