5

I have a Linux C application which requires making multiple connections to BLE devices. The application uses a library stripped from gatttool. The BLE devices have a very slow advertising rate, so it takes a long time for a to connect to be established. As a result I need to be able to make multiple gatt_connect requests at the same time.

gatt_connect uses the standard socket/connect to set up a L2CAP connection to the devices. Although this method allows you to have multiple active connections, it only allows you to be establishing one connection at a time. Using the HCI interface you can can be establishing multiple interface at the same time (i.e. hcitool lecc --whitelist), however I can't figure a way to get this to work with the gatttool library L2CAP socket/connect.

Can anyone suggest a way to integrate the gatttool L2CAP socket/connect with the hci interface (hci_open_dev/hci_le_create_conn) handles used by "hcitool lecc --whitelist", or an alernative method to establish multiple connections simultaneously?

mw.
  • 357
  • 3
  • 18
  • 1
    Any reason why you don't use the DBUS interface? That is the offically supported interface and it's easy to establish multiple connections simultaneously (once you get past the DBUS learning curve). – kaylum Nov 02 '15 at 19:36
  • Unfortunately I have to run the code on both standard ubuntu 14.04.03 LTS (bluez 4.101) and the Intel Edison (bluez 5.x). The ubuntu bluez version is 4.101 which to my understanding does not properly support dbus for bluez (or at least does not support it the same way as 5.x). I also understand the bluez dbus GATT is still experimental and frequently changing. – mw. Nov 02 '15 at 20:39
  • @mw. : I am also trying something similar. I would like to know status of your project. – abhiarora Jan 09 '17 at 17:07
  • I had something working for for bluez 4.101 and some early 5.x using the method described in the comment below. Unfortunately newer versions move a bunch of the Bluetooth of functionality down into the kernel. This broke my code. Fixing this gets real ugly handling all the anomalies created by the kernel interfering with my code or re-writing things to use HCI_CHANNEL_USER to disable bluez/kernel access and write my own ATT/L2CAP routines. – mw. Jan 10 '17 at 18:13

1 Answers1

7

I think the whitelist method is the only way to handle establishing multiple connections at once. HCI is only able to handle establishing one connection at a time as (if I remember correctly) you don't have any connection handle until the connection is established.

The L2CAP socket is a kernel abstraction that utilizes the HCI method. If you try to start another connection while one is pending I think you get an error.

I suspect even the DBUS method mention is just an abstraction over the HCI method and it's still a process of making connections in sequence.

Even if you used the whitelist method, though, I'm not sure how much faster it'd actually be as the issue is the connection interval along with the advertising interval. The whitelist works by listening for advertising packets and establishing connections as they're detected. I've also never used the whitelist method, but you'd probably have to use an HCI socket and handle multiplexing the different devices over that one socket yourself.

Most hardware will allow you to establish connections while still scanning, so you can be collecting new ad packets while waiting for the current connection to establish. When a connection is finished establishing you can move to the next. As long as connection can be established relatively quickly, there's no benefit over using a whitelist. (the actual underlying implementation may be the same any way)

Tim Tisdall
  • 9,914
  • 3
  • 52
  • 82
  • 1
    For reference, what I ended up doing was writing a connection routine that managed the white list entries using hci_le_rm_white_list and hci_le_add_white_list. I call le_create_conn (whitelisted) when I want to establish an connection, then establish a L2CAP socket with this connection. If I need to add more connection requests, I stop the current connection request with hci_le_create_conn_cancel add it to the white list, then resume with le_create_conn. – mw. Mar 07 '16 at 17:41