我有两个蓝牙适配器,一个旧的内部适配器和一个新的蓝牙 4.0 适配器。
我正在编写一个应用程序,它使用 socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)
连接到 Linux 上的蓝牙 LE 设备。当我使用 sockaddr_l2 {.l2_family = AF_BLUETOOTH, .l2_bdaddr = {...}, .l2_cid = L2CAP_CID_ATT, .l2_bdaddr_type = BRADDR_LE_PUBLIC}
调用 connect()
时,连接失败并显示 errno=0x38000000=939524096 未知错误,因为 Linux 任意选择仅支持蓝牙 2.1 的旧适配器,而不支持蓝牙 4.0。解决方法是将socket绑定(bind)到支持蓝牙4.0的adapter的bd_addr上。
问:如何判断哪个适配器是蓝牙4.0适配器? hciconfig 不会告诉使用哪一个;他们都说 BR/EDR 而不是 LE。
$ hciconfig
hci1: Type: BR/EDR Bus: USB
BD Address: 00:25:00:F6:97:F0 ACL MTU: 1021:5 SCO MTU: 64:1
UP RUNNING PSCAN
RX bytes:1074 acl:0 sco:0 events:56 errors:0
TX bytes:1462 acl:0 sco:0 commands:56 errors:0
hci0: Type: BR/EDR Bus: USB
BD Address: 00:02:72:D6:A0:BF ACL MTU: 1021:8 SCO MTU: 64:1
UP RUNNING PSCAN
RX bytes:146505 acl:328 sco:0 events:4189 errors:0
TX bytes:6213 acl:215 sco:0 commands:83 errors:0
$ modinfo bluetooth | grep ^version:
version: 2.17
$ modinfo btusb | grep ^version:
version: 0.6
$ lsb_release --description
Description: Ubuntu 14.04.1 LTS
$ uname --kernel-release
3.13.0-40-generic
最佳答案
要回答您的问题,btmgmt info
将列出 HCI 版本(与 addr
在同一行),您必须查看 Host Controller Interface Assigned numbers对于数字的含义,以下版本6表示蓝牙4.0。
# btmgmt info
hci0: Primary controller
addr 5C:F3:70:XX:XX:XX version 6 manufacturer 15 class 0x1c010c
supported settings: powered connectable fast-connectable discoverable bondable link-security ssp br/edr hs le advertising secure-conn debug-keys privacy configuration static-addr
current settings: powered bondable ssp br/edr le secure-conn
name BlueZ 5.47
short name
如果您需要知道适配器是否支持 LE,则必须在 Supported settings:
中查找 le
,因为 LE 在蓝牙 4.0/4.1 中不是强制性的。
关于linux - 如何判断蓝牙适配器是否支持蓝牙 LE (4.0)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27368085/