【问题标题】:Disable "Filter duplicates" setting for LE Set Scan Enable command禁用 LE Set Scan Enable 命令的“过滤重复项”设置
【发布时间】:2019-08-15 14:08:15
【问题描述】:

我想使用 bluetoothd 的 D-Bus 接口通过 HCI 命令“LE Set Scan Enable”禁用蓝牙控制器级别的“过滤重复”设置。

我已经尝试从 SetDiscoveryFilter(org.bluez.Adapter1) 设置“DuplicateData”参数,但根据 btmon,这不会更改 LE Set Scan Enable 的“Filter duplicates”的值。 我还阅读了“bluetoothd”和“main.conf”的手册页,但没有成功。

相比之下,我发现“hcitool lescan --duplicates”可以解决问题。

任何指针将不胜感激!

【问题讨论】:

    标签: bluetooth-lowenergy bluez


    【解决方案1】:

    使用 bluez 进行扫描的一个问题是当前的 Linux 内核支持总是打开广告的重复数据删除。请参阅 linux-bluetooth 邮件列表中的this thread- GitHub 上的dhalbert's comment

    即使你表现出色

    sudo bluetoothctl
    menu scan
    duplicate-data on
    

    或将{"DuplicateData": true} 传递给D-Bus API SetDiscoveryFilter(),内核驱动程序将在扫描开始时始终发送以下HCI 命令:

    < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
            Scanning: Enabled (0x01)
            Filter duplicates: Enabled (0x01)
    

    使用hcitool lescan --duplicates 绕过BT MGMT 命令的内核解释并发送正确的HCI 命令(过滤重复:禁用(0x00))。

    comment on GitHub 中所述,我的解决方法如下(hci_le_set_scan_enable 命令的来源):

    # This is executed every time after 'scan on' is executed in bluetoothctl.
    # First, disable ongoing scan enabled by bluetoothctl - if this is not executed
    # then next command to enable scanning will result in Command Disallowed (0x0c)
    # status. Fortunatelly, bluetoothctl seems not to be bothered by execution of
    # this commands.
    hcitool cmd 0x08 0x000C 0x00 0x00
    # This results in
    # < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    #         Scanning: Disabled (0x00)
    #         Filter duplicates: Disabled (0x00)
    # > HCI Event: Command Complete (0x0e) plen 4
    #       LE Set Scan Enable (0x08|0x000c) ncmd 1
    #         Status: Success (0x00)
    # Now, enable scanning with duplicate filtering disabled
    hcitool cmd 0x08 0x000C 0x01 0x00
    # This results in
    # < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2
    #         Scanning: Enabled (0x01)
    #         Filter duplicates: Disabled (0x00)
    # > HCI Event: Command Complete (0x0e) plen 4
    #       LE Set Scan Enable (0x08|0x000c) ncmd 1
    #         Status: Success (0x00)
    # and bluetoothctl now reports all packets, as if the 'duplicate-data on'
    # actually works as expected. Note: 'duplicate-data on' shall still be 
    # executed to prevent additional layer of filtering in bluetoothd itself.
    

    对于使用hcitool lescan --duplicates + hciump 的其他解决方法,请查看Adafruit_Blinka_bleio

    但是请注意,这两种解决方法都需要提升权限。

    【讨论】:

      【解决方案2】:

      非常感谢您的回答。我尝试了 bluetoothctl 命令 bluez 5.48 和 5.50 并获得与我的 D-Bus 应用程序相同的结果。 无论“重复数据”设置(开/关)如何,btmon/HCI 始终 在“扫描”上显示“过滤重复项:已启用”

      < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2      #5 [hci0] 10.895438
              Scanning: Enabled (0x01)
              Filter duplicates: Enabled (0x01)
      > HCI Event: Command Complete (0x0e) plen 4                 #6 [hci0] 10.898311
            LE Set Scan Enable (0x08|0x000c) ncmd 2
              Status: Success (0x00)
      

      真正让我感到困惑的是,禁用 LE 扫描(“扫描关闭”)也会禁用 过滤重复... :-(

      < HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2     #21 [hci0] 14.969999
              Scanning: Disabled (0x00)
              Filter duplicates: Disabled (0x00)
      > HCI Event: Command Complete (0x0e) plen 4                #22 [hci0] 14.973667
            LE Set Scan Enable (0x08|0x000c) ncmd 2
              Status: Success (0x00)
      

      在多次阅读 doc/adapter-api.txt 之后,我认为“DuplicateData” filter 旨在应用于 bluez 本身而不是蓝牙硬件, 但我可能错了

      【讨论】:

      • 是的,当然。数据重复过滤器是更高级别的功能,而不是 HCI 或基带级别的功能。这就是为什么如果您使用 btmon,您将始终看到数据。这是因为基带仍在接收来自远程设备的广告数据包,而 HCI 层仍在查看事件。过滤重复功能是在应用层(即 bluetoothctl)中,当您看到来自同一设备的广告时,您会抑制额外的广告,以便您只看到广告设备一次。
      • 感谢您的澄清!您是否知道使用“bluetoothd”更改 HCI/基带的“过滤重复”值的任何方法,就像使用“hcitool”一样?
      • 实际上我收回了它,我仔细检查了规范,并且在版本 5.1 Vol 2 Part E 第 7.8.11 节中表明您应该能够将过滤器副本应用于 HCI 层。我会再看看这个,并尝试用 bluetoothctl 自己测试一下。
      • @YoussifSaeed 很抱歉打扰您,但您有时间查看此问题或有关如何继续操作的任何提示吗?
      • 使用 BlueZ 5.55 版时,同样的问题仍然存在。在 Raspberry Pi (RPi OS Buster) 上使用 Filter duplicates: Enabled (0x01),尽管 duplicate-data on 并且未报告数据包 - 但 hcitool lescan --duplicates 正常工作并显示所有数据包。有趣的是,在我的 ThinkPad 笔记本电脑上并非如此(BlueZ 要么从 apt 安装,要么从存储库编译,标记为 5.55)。
      【解决方案3】:

      欢迎来到 StackOverflow。发布问题时,发布所使用的软件和硬件的版本非常有用,因为这可以帮助您获得更好的答案。

      关于您的问题,这取决于您使用的 BlueZ 版本。假设这是当前的最新版本(v5.50),那么有一个低能量扫描选项可以禁用重复过滤器。请在此处查看文档:-

      https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/adapter-api.txt#n107

      您还可以在 bluetoothctl 命令中查看它的使用情况。请看看这个:-

      https://git.kernel.org/pub/scm/bluetooth/bluez.git/tree/client/main.c#n1390

      如果你想试试这个,可以使用bluetoothctl命令如下:-

      #bluetoothctl
      [bluetoothctl] menu scan
      [bluetoothctl] duplicate-data on
      [bluetoothctl] back
      [bluetoothctl] scan on
      

      这将只返回一次广告,重复的广告将被禁止。

      我希望这会有所帮助。

      【讨论】:

      • duplicate-data on 在后台设置SetDiscoveryFilter({"DuplicateData": true})。即使在 5.55 版上,设置 duplicate-data on 也不会改变行为并且仍然会发送 &lt; HCI Command: LE Set Scan Enable (0x08|0x000c) plen 2; Filter duplicates: Enabled (0x01)
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-09-09
      • 1970-01-01
      • 1970-01-01
      • 2021-09-27
      • 2012-05-26
      • 2012-08-10
      • 1970-01-01
      相关资源
      最近更新 更多