bluetoothd(BlueZ 5)不会与任何设备连接

解决了。 编辑: 见下文。

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

似乎有很多方法,但我不清楚结束的地方和另一个的开始:

方法1:

a) $ sudo bluetoothd -d -n verdo bluetoothd $ sudo bluetoothd -d -n #runs bluetoothd在详细模式下

b) $ hciconfig hci1 up #turns设备开启

$ hciconfig -a hciconfig $ hciconfig -a #see设备属性

  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或密钥不正确,无法与Adapter-1配对。

根据上面的主演回复,我调查了为什么没有代理人。 什么是经纪人? 谁知道,但我推断它是我的设备和蓝牙守护进程之间的中间人。

d) $ ../bluey-5.15/test/simple-agent #I也尝试使用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设备上打了一对,它说配对,但简单代理挂起。 我使用过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的一些脚本(如测试设备)可以看到BT设备的某些命令,但不能看到其他命令。 例如,测试设备将“信任”该设备,但当我尝试“删除”它时,它不存在。

方法2:

DBUS直接使用dbus-send –system命令。 在我可以配对和连接设备之前,我认为这些命令中的任何一个都不会对我有任何帮助。

方法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 simple-agent没有给我任何有用的错误,我编写了自己的配对代理。 一旦我做了,我能够配对但不能连接。 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 

这篇文章指出,也许我的LOCAL蓝牙适配器不支持我的音频源的a2dp配置文件。 (不像水槽那样)然后我看到许多人从BlueZ4升级到BlueZ5时遇到了同样的问题。 该问题也发布在BlueZ邮件列表中 。

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

解:

在发现配置文件(a2dp)未连接并且看到其他人遇到相同问题后,我查看了此配置文件是否已在BlueZ5中实现。 我想我没有仔细阅读移植指南,因为它解释了a2dp被移出BlueZ堆栈并进入GStreamer。 我从未听说过GStreamer,但我也从这篇文章中看到PulseAudio和JACK也会实现这个配置文件。 我尝试过PulseAudio,但它不会为适配器加载正确的UUID。 然后我终于在ArchLinux维基上发了一篇文章。 我一定要去过这个页面一百万次,但可能是我还在使用BlueZ4时。

最重要的是:

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

-compiling有很多依赖项(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插件了。

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

请阅读http://www.bluez.org/bluez-5-api-introduction-and-porting-guide/中的 设备发现部分。

我有类似的问题,但它已配对并连接。 要配对和连接设备,必须在最近3分钟内发现它。 simple-agent和bluetoothctl都可以正常工作。