解决了。 编辑: 请参见下文。
我想我已经在互联网上搜寻了足够长的时间来解决此问题。已经问了很多遍,但是没有一种解决方案对我有用。我升级到BlueZ 5是因为我希望最终能够使用它的低能耗功能。但是现在,我什至无法配对设备。我不能使用GUI,因为它最终将用于嵌入式Linux系统。因此,我认为我也不能使用bluetoothctl,因为它需要交互式会话。(对此我可能是错的。)因此,我希望一切都以该顺序通过BASH,C或python进行。另外,由于需要自动进行,因此配对和连接必须从蓝牙设备而不是从Linux盒启动。最后,所有设备都需要使用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)
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()
设备说,由于PIN或密码不正确,无法与Adapter-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设备上打了对,说成对了,但是简单代理挂起了。我已经使用过BlueZ 4,而且我很确定它应该说类似“ New Device 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简单代理没有给我任何有用的错误,因此我编写了自己的配对代理。一旦完成操作,我就可以配对但无法连接。蓝牙给了我这个新的错误:
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邮件列表中。
到目前为止,我还没有找到将这个协议添加到我的适配器的方法。