解决了。 编辑: 见下文。
我想我已经为这个问题在互联网上搜索了足够长的时间。已经被问过很多次了,但没有一个解决方案适合我。我升级到 BlueZ 5 是因为我希望最终能够使用它的低能耗功能。但是现在,我什至无法配对我的设备。我不能使用 GUI,因为这最终将用于嵌入式 linux 系统。因此,我想我也不能使用bluetoothctl,因为它需要一个交互式会话。(我可能错了。)所以我希望一切都按照这个顺序通过 BASH、C 或 python。此外,因为它需要自动化,配对和连接必须从蓝牙设备启动,而不是从 linux box。最后,所有设备都需要使用 a2dp 配置文件。
似乎有很多方法,但我不清楚一个在哪里结束,另一个从哪里开始:
方法 1:
a) $ sudo bluetoothd -d -n #以详细模式运行蓝牙
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)
Run Code Online (Sandbox Code Playgroud)
c) 尝试从设备配对。
结果:从蓝牙:
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()
Run Code Online (Sandbox Code Playgroud)
设备显示无法与 Adapter-1 配对,因为 PIN 或密码不正确。
根据上面加星标的回复,我调查了为什么没有代理。什么是代理?谁知道呢,但我推断它是我的设备和蓝牙守护进程之间的中间人。
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
Run Code Online (Sandbox Code Playgroud)
我在 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()
Run Code Online (Sandbox Code Playgroud)
所以这会有所作为。
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
Run Code Online (Sandbox Code Playgroud)
我什至尝试过 bluetoothctl,但结果相同。有趣的是,来自 BlueZ 的一些脚本(如 test-device)可以看到某些命令的 BT 设备,但不能看到其他命令。例如, test-device 将“信任”该设备,但是当我尝试“删除”它时,它不存在。
方法 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
Run Code Online (Sandbox Code Playgroud)
蓝牙输出:
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()
Run Code Online (Sandbox Code Playgroud)
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
Run Code Online (Sandbox Code Playgroud)
有什么建议?我是:
忘记一些非常明显的事情?
工具使用不当?
忘记设置配置文件?
编辑:
由于 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
Run Code Online (Sandbox Code Playgroud)
这篇文章指出,也许我的本地蓝牙适配器不支持我的音频源的 a2dp 配置文件。(不像水槽)然后我看到很多人从BlueZ4升级到BlueZ5都遇到过同样的问题。该问题也已发布在 BlueZ 邮件列表上。
到目前为止,我还没有找到将这个协议添加到我的适配器的方法。
解决方案:
在发现配置文件(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 插件。
| 归档时间: |
|
| 查看次数: |
33018 次 |
| 最近记录: |