bluetoothd(BlueZ 5)无法连接任何设备

bluetoothd(BlueZ 5)无法连接任何设备

解决了。 編輯: 见下文。

我认为我已经在互联网上搜索了很长时间来解决这个问题。这个问题已经被问过很多次了,但没有一个解决方案对我有用。我升级到了 BlueZ 5,因为我希望最终能够使用它的低能耗功能。但是现在,我甚至无法配对我的设备。我不能使用 GUI,因为这最终将用于嵌入式 Linux 系统。因此,我想我也不能使用 bluetoothctl,因为它需要交互式会话。(我可能错了。)所以我希望一切都按顺序通过 BASH、C 或 python。此外,由于它需要自动化,因此配对和连接必须从蓝牙设备启动,而不是从 Linux 机器启动。最后,所有设备都需要使用 a2dp 配置文件。

似乎有很多方法,但我不清楚一种方法在哪里结束,另一种方法在哪里开始:

方法一:

a) $ sudo bluetoothd -d -n #以详细模式运行 bluetoothd

b) $ hciconfig hci1 up#打开设备

$ hciconfig -a #查看设备属性

    Type: BR/EDR  Bus: USB
    BD Address: 00:02:72:C5:D8:E0  ACL MTU: 1021:8  SCO MTU: 64:1
    UP RUNNING PSCAN ISCAN 
    RX bytes:32875 acl:761 sco:0 events:1037 errors:0
    TX bytes:20178 acl:780 sco:0 commands:329 errors:0
    Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
    Packet type: DM1 DM3 DM5 DH1 DH3 DH5 HV1 HV2 HV3 
    Link policy: RSWITCH SNIFF 
    Link mode: SLAVE ACCEPT 
    Name: 'Adapter-1'
    Class: 0x00010c
    Service Classes: Unspecified
    Device Class: Computer, Laptop
    HCI Version: 4.0 (0x6)  Revision: 0x1000
    LMP Version: 4.0 (0x6)  Subversion: 0x220e
    Manufacturer: Broadcom Corporation (15)

c) 尝试从设备配对。

结果:来自 bluetoothd:

bluetoothd[5359]: src/adapter.c:connected_callback() hci1 device 70:72:3C:62:49:7F connected eir_len 15
bluetoothd[5359]: src/adapter.c:user_confirm_request_callback() hci1 70:72:3C:62:49:7F confirm_hint 1
bluetoothd[5359]: src/device.c:new_auth() Requesting agent authentication for 70:72:3C:62:49:7F
** bluetoothd[5359]: No agent available for request type 2
** bluetoothd[5359]: device_confirm_passkey: Operation not permitted 
bluetoothd[5359]: src/adapter.c:btd_adapter_confirm_reply() hci1 addr 70:72:3C:62:49:7F success 0
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0x5
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x05
bluetoothd[5359]: src/device.c:device_bonding_failed() status 5
bluetoothd[5359]: src/adapter.c:resume_discovery() 
bluetoothd[5359]: src/adapter.c:dev_disconnected() Device 70:72:3C:62:49:7F disconnected, reason 3
bluetoothd[5359]: src/adapter.c:adapter_remove_connection() 
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0xe
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
bluetoothd[5359]: src/device.c:device_bonding_failed() status 14
bluetoothd[5359]: src/adapter.c:resume_discovery()

设备说由于 PIN 或密钥不正确,无法与适配器 1 配对。

根据上面带星号的回复,我研究了为什么没有代理。什么是代理?谁知道呢,但我推断它是我的设备和蓝牙守护进程之间的中间人。

d)$ ../bluey-5.15/test/simple-agent #我也尝试使用 sudo 执行这些命令

或者$ ../bluey-5.15/test/simple-agent hci1

这是一个处理传入配对请求的 Python 脚本。如果成功,它还会尝试“信任”和“连接”

输出:Agent registered

e) 然后我再次尝试从设备配对。

简单代理输出:

RequestConfirmation (/org/bluez/hci1/dev_70_72_3C_62_49_7F, 110643)
Confirm passkey (yes/no): yes 

我在 BT 设备上点击配对,它显示已配对,但 simple-agent 挂起了。我使用过 BlueZ 4,我很确定它应该显示类似“新设备 XX_XX_XX_XX_XX_XX”的内容

蓝牙输出:

** bluetoothd[5359]: src/agent.c:set_default_agent() Default agent set to :1.126 /test/agent
bluetoothd[5359]: src/adapter.c:connected_callback() hci1 device 70:72:3C:62:49:7F connected eir_len 15
bluetoothd[5359]: src/adapter.c:user_confirm_request_callback() hci1 70:72:3C:62:49:7F confirm_hint 0
bluetoothd[5359]: src/device.c:new_auth() Requesting agent authentication for 70:72:3C:62:49:7F
bluetoothd[5359]: src/agent.c:agent_ref() 0xa59290: ref=2
bluetoothd[5359]: src/agent.c:agent_request_confirmation() Calling Agent.RequestConfirmation: name=:1.126, path=/test/agent, passkey=110643
bluetoothd[5359]: src/agent.c:agent_ref() 0xa59290: ref=3
bluetoothd[5359]: src/adapter.c:btd_adapter_confirm_reply() hci1 addr 70:72:3C:62:49:7F success 1
bluetoothd[5359]: src/agent.c:agent_unref() 0xa59290: ref=2
bluetoothd[5359]: src/agent.c:agent_unref() 0xa59290: ref=1
bluetoothd[5359]: src/adapter.c:new_link_key_callback() hci1 new key for 70:72:3C:62:49:7F type 5 pin_len 0
bluetoothd[5359]: src/device.c:device_set_bonded() 
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x00
bluetoothd[5359]: src/adapter.c:resume_discovery() 
bluetoothd[5359]: src/adapter.c:dev_disconnected() Device 70:72:3C:62:49:7F disconnected, reason 3
bluetoothd[5359]: src/adapter.c:adapter_remove_connection() 
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0xe
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
bluetoothd[5359]: src/device.c:device_bonding_failed() status 14
bluetoothd[5359]: src/adapter.c:resume_discovery()

因此,这会产生一些作用。

hcidump 输出:

$ hcidump -i hci1

HCI sniffer - Bluetooth packet analyzer ver 5.15
device: hci1 snap_len: 1500 filter: 0xffffffffffffffff
> HCI Event: Connect Request (0x04) plen 10
    bdaddr 70:72:3C:62:49:7F class 0x5a020c type ACL
> HCI Event: Command Status (0x0f) plen 4
    Accept Connection Request (0x01|0x0009) status 0x00 ncmd 1
> HCI Event: Connect Complete (0x03) plen 11
    status 0x00 handle 11 bdaddr 70:72:3C:62:49:7F type ACL encrypt 0x00
> HCI Event: Command Status (0x0f) plen 4
    Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 1
> HCI Event: Read Remote Supported Features (0x0b) plen 11
    status 0x00 handle 11
    Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
> HCI Event: Command Status (0x0f) plen 4
    Read Remote Extended Features (0x01|0x001c) status 0x00 ncmd 1
> HCI Event: Command Complete (0x0e) plen 10
    IO Capability Request Reply (0x01|0x002b) ncmd 1
    status 0x00 bdaddr 70:72:3C:62:49:7F
> HCI Event: Read Remote Extended Features (0x23) plen 13
    status 0x00 handle 11 page 1 max 1
    Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> HCI Event: Command Status (0x0f) plen 4
    Remote Name Request (0x01|0x0019) status 0x00 ncmd 1
> HCI Event: Remote Name Req Complete (0x07) plen 255
    status 0x00 bdaddr 70:72:3C:62:49:7F name 'Prism II'
> HCI Event: Command Complete (0x0e) plen 10
    User Confirmation Request Reply (0x01|0x002c) ncmd 1
    status 0x00 bdaddr 70:72:3C:62:49:7F
> HCI Event: Disconn Complete (0x05) plen 4
    status 0x00 handle 11 reason 0x13
    Reason: Remote User Terminated Connection

我甚至尝试了 bluetoothctl,但结果相同。有趣的是,BlueZ 中的一些脚本(如 test-device)可以查看某些命令的 BT 设备,但看不到其他命令。例如,test-device 将“信任”该设备,但当我尝试“删除”它时,它不存在。

方法 2:

直接使用 dbus-send --system 命令访问 DBUS。我认为,在能够配对和连接设备之前,这些命令对我都没有任何用处。

方法 3:

我尝试了所有关于此的建议邮政。BlueZ 5 中没有 /etc/bluetooth/hcid.conf。我需要创建一个吗?rfcomm 命令将连接,但随后会立即断开连接。

$ sudo rfcomm connect /dev/rfcomm0 70:72:3C:62:49:7F 1
Connected /dev/rfcomm0 to 70:72:3C:62:49:7F on channel 1
Press CTRL-C for hangup
Disconnected

蓝牙输出:

bluetoothd[5359]: src/adapter.c:connected_callback() hci1 device 70:72:3C:62:49:7F connected eir_len 10
bluetoothd[5359]: src/adapter.c:dev_disconnected() Device 70:72:3C:62:49:7F disconnected, reason 3
bluetoothd[5359]: src/adapter.c:adapter_remove_connection() 
bluetoothd[5359]: src/adapter.c:bonding_attempt_complete() hci1 bdaddr 70:72:3C:62:49:7F type 0 status 0xe
bluetoothd[5359]: src/device.c:device_bonding_complete() bonding (nil) status 0x0e
bluetoothd[5359]: src/device.c:device_bonding_failed() status 14
bluetoothd[5359]: src/adapter.c:resume_discovery()

hcidump 输出:

$ hcidump -i hci1
HCI sniffer - Bluetooth packet analyzer ver 5.15
device: hci1 snap_len: 1500 filter: 0xffffffffffffffff
> HCI Event: Command Status (0x0f) plen 4
    Create Connection (0x01|0x0005) status 0x00 ncmd 1
> HCI Event: Connect Complete (0x03) plen 11
    status 0x00 handle 11 bdaddr 70:72:3C:62:49:7F type ACL encrypt 0x00
> HCI Event: Command Status (0x0f) plen 4
    Read Remote Supported Features (0x01|0x001b) status 0x00 ncmd 1
> HCI Event: Read Remote Supported Features (0x0b) plen 11
    status 0x00 handle 11
    Features: 0xbf 0xfe 0xcf 0xfe 0xdb 0xff 0x7b 0x87
> HCI Event: Command Status (0x0f) plen 4
    Read Remote Extended Features (0x01|0x001c) status 0x00 ncmd 1
> HCI Event: Read Remote Extended Features (0x23) plen 13
    status 0x00 handle 11 page 1 max 1
    Features: 0x01 0x00 0x00 0x00 0x00 0x00 0x00 0x00
> HCI Event: Command Status (0x0f) plen 4
    Remote Name Request (0x01|0x0019) status 0x00 ncmd 1
> HCI Event: Remote Name Req Complete (0x07) plen 255
    status 0x00 bdaddr 70:72:3C:62:49:7F name 'Prism II'
> HCI Event: Command Status (0x0f) plen 4
    Authentication Requested (0x01|0x0011) status 0x00 ncmd 1
> HCI Event: Command Complete (0x0e) plen 10
    Link Key Request Reply (0x01|0x000b) ncmd 1
    status 0x00 bdaddr 70:72:3C:62:49:7F
> HCI Event: Auth Complete (0x06) plen 3
    status 0x00 handle 11
> HCI Event: Command Status (0x0f) plen 4
    Set Connection Encryption (0x01|0x0013) status 0x00 ncmd 1
> HCI Event: Encrypt Change (0x08) plen 4
    status 0x00 handle 11 encrypt 0x01
> HCI Event: Command Status (0x0f) plen 4
    Exit Sniff Mode (0x02|0x0004) status 0x0c ncmd 1
    Error: Command Disallowed
> HCI Event: Disconn Complete (0x05) plen 4
    status 0x00 handle 11 reason 0x13
    Reason: Remote User Terminated Connection

有什么建议吗?我是:

  • 忘记了一些非常明显的事情?

  • 工具使用不当?

  • 忘记设置配置文件?

编辑:

由于 bluez 简单代理没有给我任何有用的错误,我编写了自己的配对代理。一旦我这样做了,我就可以配对但无法连接。bluetoothd 给了我这个新错误:

bluetoothd[3078]: profiles/audio/a2dp.c:a2dp_source_connect() path /org/bluez/hci0/dev_70_72_3C_62_49_7F
bluetoothd[3078]: a2dp-source profile connect failed for 70:72:3C:62:49:7F: Protocol not available

这个帖子指出我的本地蓝牙适配器可能不支持我的音频源的 a2dp 配置文件。(不像接收器一样)然后我看到许多人从 BlueZ4 升级到 BlueZ5 时都遇到了同样的问题。这个问题也是发布在 BlueZ 邮件列表上

到目前为止,我还没有找到将该协议添加到我的适配器的方法。

答案1

解决方案:

在发现配置文件 (a2dp) 未连接并看到其他人遇到同样的问题后,我查看了此配置文件是否已在 BlueZ5 中实现。我猜我没有仔细阅读移植指南,因为它解释说a2dp 已从 BlueZ 堆栈移出并移入 GStreamer。 我以前从未听说过 GStreamer,但我也看到过这个帖子PulseAudio 和 JACK 也会实现此配置文件。我尝试了 PulseAudio,但它无法为适配器加载正确的 UUID。后来我终于找到了一个在 ArchLinux wiki 上发布。 我肯定已经访问过这个页面一百万次了,但那可能是在我仍在使用 BlueZ4 的时候。

最重要的是:

-下载支持 BlueZ5 的新 PulseAudio 5 源代码并进行编译。(它不是 apt 存储库中的最新版本。)

-编译需要很多依赖项(JSON、libsndfile、libcap 等)

-请记住 PA5 的路径是 /usr/local 而不是 /usr/(这很重要,因为我必须将其放在 $LD_LIBRARY_PATH 中,以便 PA 可以在启动时找到 libpulsecore-5.0)

-正如 ArchLinux wiki 所述,终止启动时运行的 pulseaudio 服务器并启动一个新的。它不会在启动时加载配置文件。还要确保守护进程重新启动。(在 /usr/local//etc/pulse/client.conf 中设置)

之后,常用的 pactl 命令就可以正常工作了。我能够让 a2dp BT 源(即 iPod)流式传输到 PA5,然后使用环回模块流式传输到 a2dp BT 接收器!

我无法让它与 ALSA 一起运行,但我读到某处说 BlueZ5 可能不再支持 ALSA pcm 插件。

答案2

上述问题的关键是这句话:“一旦发现停止,未连接或配对的设备将在三分钟内被蓝牙自动移除。”

请阅读设备发现节选自http://www.bluez.org/bluez-5-api-introduction-and-porting-guide/

我遇到了类似的问题,但已将其配对并连接。要配对并连接设备,必须在过去 3 分钟内发现该设备。simple-agent 和 bluetoothctl 均可正常工作。

相关内容