hcitool 无法设置扫描响应数据

问题描述 投票:0回答:1

该问题类似于使用 hcitool 设置广告数据包,但我不只是发送 AD 数据,还尝试使用 OCF 0x0009 设置扫描响应数据(也在答案之一中暗示)。

问题是我可以只发送 AD 数据,也可以什么也不发送,没有任何扫描响应数据。我可以使用 ESP32 发送相同的广告 + 扫描,但不能使用 hci。

这是完整的命令列表(Apple id 目前只是一个占位符):

hciconfig hci0 up
hciconfig hci0 piscan
hciconfig hci0 leadv 0
hcitool -i hci0 cmd 0x08 0x0008 1F 02 01 06 1B FF 4C 00 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01
hcitool -i hci0 cmd 0x08 0x0009 1F 1E FF 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02

我使用 Raspberry Pi 4 的内置蓝牙发送数据包,并使用手机上的 BLE 扫描仪应用程序读取数据包。

我仅将

leadv 3
用于 AD 数据,并且工作正常,但扫描响应需要可连接设备,所以我将其更改为
leadv 0

我在这里缺少什么?

编辑这里是运行上述命令时 sudo btmon 的结果:https://pastebin.com/B8GG91Wr

bluetooth bluetooth-lowenergy bluez bluetooth-hci
1个回答
1
投票

我的建议是根本不要使用 hcitool,因为它是一个“已弃用”命令,不再受支持,并将在将来逐步淘汰。相反,您应该使用 btmon 命令,该命令允许您除了广告响应之外还添加扫描响应。 您可以通过 btmgmt 命令设置扫描响应,如下所示:-

sudo btmgmt add-adv -d 02010606084142434400 -s 080954657374204C45

其中-d选项用于设置广告数据,-s用于设置扫描响应数据。 btmgmt add-adv 选项的完整列表是:-

Usage: add-adv [options] <instance_id> Options: -u, --uuid <uuid> Service UUID -d, --adv-data <data> Advertising Data bytes -s, --scan-rsp <data> Scan Response Data bytes -t, --timeout <timeout> Timeout in seconds -D, --duration <duration> Duration in seconds -P, --phy <phy> Phy type, Specify 1M/2M/CODED -c, --connectable "connectable" flag -g, --general-discov "general-discoverable" flag -l, --limited-discov "limited-discoverable" flag -n, --scan-rsp-local-name "local-name" flag -a, --scan-rsp-appearance "appearance" flag -m, --managed-flags "managed-flags" flag -p, --tx-power "tx-power" flag e.g.: add-adv -u 180d -u 180f -d 080954657374204C45 1

广告中的 BLE 数据解码如下(基于
分配的号码文档

):- 第一个字节 = 长度(n 个字节) 第二个字节 = 类型 n-1 字节 = 实际数据

所以我添加的广告数据的含义:-

02 长度(2 字节)
  • 01 类型(标志)
  • 06 标志 - 02 && 04 LE 一般可发现 && BR/EDR 不支持
  • 06 长度(6 字节)
  • 08 类型(本地缩写名称)
  • 4142434400(ABCD)
  • 而扫描响应数据的含义是:-

08 长度(8 字节)
  • 09 类型(完整的本地名称)
  • 54657374204C45(测试LE)
  • 一些相关链接:-

    hcitool 广告命令不起作用
  • btmgmt 添加广告不起作用
  • 解码 BLE 原始广告数据
© www.soinside.com 2019 - 2024. All rights reserved.