如何判断蓝牙适配器是否支持蓝牙LE(4.0)?

yon*_*ran 3 sockets linux bluetooth

我有两个蓝牙适配器,一个旧的内部适配器和一个新的蓝牙4.0适配器.

我正在编写一个应用程序,用于socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP)连接Linux上的蓝牙LE设备.当我connect()用a 调用时sockaddr_l2 {.l2_family = AF_BLUETOOTH, .l2_bdaddr = {...}, .l2_cid = L2CAP_CID_ATT, .l2_bdaddr_type = BRADDR_LE_PUBLIC},连接失败并且errno = 0x38000000 = 939524096未知错误,因为Linux任意选择仅支持蓝牙2.1的旧适配器,而不是蓝牙4.0.解决方案是将套接字绑定到支持蓝牙4.0的适配器的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
Run Code Online (Sandbox Code Playgroud)

小智 9

要回答您的问题btmgmt info,将列出HCI版本(与相同addr),您必须查看“ 主机控制器接口分配的数字”以了解数字的含义,以下版本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 
Run Code Online (Sandbox Code Playgroud)

如果您需要知道适配器是否支持LE,则必须寻找适配器leSupported settings:因为LE在蓝牙4.0 / 4.1中不是必需的。


kay*_*lum 5

尝试: hciconfig hci[0|1] version