Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如何判断蓝牙适配器是否支持蓝牙LE(4.0)?_Linux_Sockets_Bluetooth - Fatal编程技术网

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

Linux 如何判断蓝牙适配器是否支持蓝牙LE(4.0)?,linux,sockets,bluetooth,Linux,Sockets,Bluetooth,我有两个蓝牙适配器,一个旧的内部适配器和一个新的蓝牙4.0适配器 我正在编写一个应用程序,它使用套接字(PF_BLUETOOTH,SOCK_SEQPACKET,BTPROTO_L2CAP)连接到Linux上的蓝牙LE设备。当我使用sockaddr\u l2{.l2\u family=AF\u BLUETOOTH、.l2\u bdaddr={…}、.l2\u cid=L2CAP\u cid\u ATT、.l2\u bdaddr\u type=BRADDR\u LE\u PUBLIC}调用时,连接失

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

我正在编写一个应用程序,它使用
套接字(PF_BLUETOOTH,SOCK_SEQPACKET,BTPROTO_L2CAP)
连接到Linux上的蓝牙LE设备。当我使用
sockaddr\u l2{.l2\u family=AF\u BLUETOOTH、.l2\u bdaddr={…}、.l2\u cid=L2CAP\u cid\u ATT、.l2\u bdaddr\u type=BRADDR\u LE\u PUBLIC}
调用
时,连接失败,错误为errno=0x38000000=939524096未知错误,因为Linux任意选择了只支持BLUETOOTH 2.1而不支持BLUETOOTH 4.0的旧适配器。解决方案是将套接字绑定到支持Bluetooth 4.0的适配器的bd_addr

# 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 
问题:如何辨别哪个适配器是蓝牙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

请尝试:
hciconfig hci[0 | 1]version
要回答您的问题,有
btmgmt info
将列出hci版本(与
addr
在同一行),您必须查看数字的含义,下面的版本6表示Bluetooth 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,您必须在
支持的设置中查找
LE
,因为LE在bluetooth 4.0/4.1中不是强制性的。

对于那些对此答案中的语法感到困惑的人:
hciconfig hci0 version
hciconfig hci1 version
。但是如果您阅读
manhciconfig
您将看到:
如果没有给出hciX,hciconfig将打印系统中安装的所有蓝牙设备的名称和基本信息。
换句话说:
hciconfig
就可以了;仅列出实际设备。超级有用答案+1。不知道为什么没有这方面的
手册页
?x-cool将是一款将
btmgmt
信息翻译成直接可读的应用程序。感谢您让我们知道,在Bluetooth 4.0+中,LE不是强制性的。这是在bluez>=5.44上实现此功能的唯一方法,因为默认情况下,他们从该版本中删除了
hcitool
(尽管我注意到Ubuntu为了向后兼容而继续使用它)。