0

关于这个美妙的二人组btmgmt/bluetoothctl在带有 bluez 5.55 的外围设备上的几个问题。

即使出现错误, btmgmt的返回码几乎总是 0 是否正常?我检查了代码,这似乎是预期的行为。但我不明白为什么...

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

事实上,当我检查btmgmt代码时。即使状态不等于 0。我们使用 done 标签返回EXIT_SUCCESS代码...如何正确检查命令的结果?

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);
}

我对btmgmt有很多问题......当我运行命令时,我有很多随机失败的结果。我检查结果的唯一方法是使用 btmgmt info | grep 当前 | grep XXX 检查 hci0 上的当前设置。改用bluetoothctl会更好吗?我还可以在 mgmt-tester.c 中看到一些代码。我必须改用这个c api吗?我目前启用/禁用蓝牙的方法:

// 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");

我尝试用bluetoothctl实现相同的功能。问题是我找不到启用与bluetoothctl绑定的方法。也无法使用 bluetoothctl 启用双模式 le/btc。

我的最后一点是关于广告的。我想在制造商数据字段中发送自定义广告数据。我在外围设备上尝试这样的事情:

# 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]# 

在另一台设备上,我使用btmonbluetoothctl scan嗅探蓝牙数据包,但我看不到任何制造商数据与我的数据匹配。

4

0 回答 0