【发布时间】:2019-02-08 06:38:01
【问题描述】:
在 Linux/Bluez 上通过 RFCOMM 与蓝牙设备的连接失败,连接被拒绝
connect(s, (struct sockaddr *)&addr, sizeof(addr));。
设备已成功配对。可以成功建立从 Android 或 Windows 到该设备的 RFCOMM 连接,因此问题似乎与 Bluez 潜水员和/或蓝牙设备有关。
在 Linux/Bluez 中,bluetoothctl 和 Wireshark 跟踪显示它首先连接,然后大约 2 秒后断开连接。断线原因不清楚。
同样的问题发生在不同的 Linux 版本上,在带有 USB 蓝牙的 PC 上(Linux ubuntu 4.15.0-33-generic #36~16.04.1-Ubuntu SMP Wed Aug 15 17:21:05 UTC 2018 x86_64 x86_64 x86_64 GNU /Linux) 或 Raspberry Pi 3 (Jessie, Stretch)。
我检查了许多其他具有相同/相似问题的线程。大多数人没有或没有明确的答案。
Wireshark trace screenshot 显示 2.2 秒后断开连接。
对应的bluetoothd syslog输出:
Aug 31 16:43:54 ubuntu bluetoothd[926]: src/adapter.c:connected_callback() hci0 device F6:65:0A:E5:DE:E1 connected eir_len 22
Aug 31 16:43:54 ubuntu bluetoothd[926]: src/device.c:device_create() dst F6:65:0A:E5:DE:E1
Aug 31 16:43:54 ubuntu bluetoothd[926]: src/device.c:device_new() address F6:65:0A:E5:DE:E1
Aug 31 16:43:55 ubuntu bluetoothd[926]: src/device.c:device_new() Creating device /org/bluez/hci0/dev_F6_65_0A_E5_DE_E1
Aug 31 16:43:57 ubuntu bluetoothd[926]: src/adapter.c:dev_disconnected() Device F6:65:0A:E5:DE:E1 disconnected, reason 3
Aug 31 16:43:57 ubuntu bluetoothd[926]: src/adapter.c:adapter_remove_connection()
Aug 31 16:43:57 ubuntu bluetoothd[926]: src/adapter.c:adapter_remove_connection() Removing temporary device /org/bluez/hci0/dev_F6_65_0A_E5_DE_E1
Aug 31 16:43:57 ubuntu bluetoothd[926]: src/device.c:device_remove() Removing device /org/bluez/hci0/dev_F6_65_0A_E5_DE_E1
Aug 31 16:43:57 ubuntu bluetoothd[926]: src/device.c:btd_device_unref() Freeing device /org/bluez/hci0/dev_F6_65_0A_E5_DE_E1
Aug 31 16:43:57 ubuntu bluetoothd[926]: src/device.c:device_free() 0x563aa2a270a0
Aug 31 16:43:57 ubuntu bluetoothd[926]: plugins/policy.c:disconnect_cb() reason 3
Aug 31 16:43:57 ubuntu bluetoothd[926]: src/adapter.c:bonding_attempt_complete() hci0 bdaddr F6:65:0A:E5:DE:E1 type 0 status 0xe
Aug 31 16:43:57 ubuntu bluetoothd[926]: src/adapter.c:resume_discovery()
reason 3 points 到内核源代码的 include/net/bluetooth/mgmt.h 中的 MGMT_DEV_DISCONN_REMOTE。这意味着启动断开连接的是设备。但是 Wireshark 跟踪中突出显示的行表明是主机发起了断开连接。
非常感谢您提前提供的任何帮助。
【问题讨论】:
-
当 bluez 没有设备所需的所有强制配置文件时,通常会发生这种情况。我不确定基于 libbluetooth 的操作,但您仍然可以尝试使用“ConnectProfile”方法连接到特定配置文件,请参见此处:git.kernel.org/pub/scm/bluetooth/bluez.git/tree/doc/… 默认情况下,“连接”将尝试解析并连接设备支持的所有配置文件。未能与所有配置文件连接会退出连接并使设备处于配对状态。
-
感谢您的提示。设置配置文件可能会自动选择正确的 RFCOMM 通道。但对我来说,如何设置配置文件似乎并不明显。
标签: linux bluetooth raspberry-pi3 bluez rfcomm