yonran
yonran

Reputation: 19134

How to tell whether bluetooth adapter supports bluetooth LE (4.0)?

I have two Bluetooth adapters, an old internal adapter and a new Bluetooth 4.0 adapter.

I am writing an application that uses a socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_L2CAP) to connect to a Bluetooth LE device on Linux. When I call connect() with a sockaddr_l2 {.l2_family = AF_BLUETOOTH, .l2_bdaddr = {...}, .l2_cid = L2CAP_CID_ATT, .l2_bdaddr_type = BRADDR_LE_PUBLIC}, connect fails with errno=0x38000000=939524096 Unknown error, because Linux arbitrarily chooses the old adapter that only supports Bluetooth 2.1, not Bluetooth 4.0. The solution is to bind the socket to the bd_addr of the adapter that supports Bluetooth 4.0.

Question: How to tell which adapter is the Bluetooth 4.0 adapter? hciconfig does not tell which one is the one to use; they both say BR/EDR and not 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

Upvotes: 6

Views: 8980

Answers (2)

kaylum
kaylum

Reputation: 14046

Try: hciconfig hci[0|1] version

Upvotes: 7

lumostor
lumostor

Reputation: 141

To answer your question there is btmgmt info which will list the HCI version (on the same line as addr), you will have to look into Host Controller Interface Assigned numbers for the meaning of the numbers, version 6 below mean 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 

If you need to know if the adapter support LE, you will have to look for le in Supported settings: because LE is not mandatory in bluetooth 4.0/4.1.

Upvotes: 14

Related Questions