Bluetooth (Linux/BlueZ) pair timeout or something?

949 Views Asked by At

At first I can pair and connect to device, it's works as expected. But I can't understand some peculiarities of pairing process.

In case of where is no pause between this operations pair,trust,connect bluetoothctl log look like this:

[bluetooth]#pair FC:58:FA:XX:XX:XX
Attempting to pair with FC:58:FA:XX:XX:XX
[bluetooth]# trust  FC:58:FA:XX:XX:XX
[bluetooth]#                               [CHG] Device FC:58:FA:XX:XX:XX Trusted: yes
[bluetooth]#                               Changing FC:58:FA:XX:XX:XX trust succeeded
[bluetooth]#connect  FC:58:FA:XX:XX:XX
Attempting to connect to FC:58:FA:XX:XX:XX
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX Connected: yes
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX ServicesResolved: yes
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX Paired: yes
[ERGO BTS-520]#                            Connection successful
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000111e-0000-1000-8000-00805f9b34fb

Such behavior can be observed with Ubuntu Bluetooth connection manager.

But in my own implementation of BT manager I have some delay between pair and connect operation(above of 2-3 seconds), and in this case log of bluetoothctl absolutely different:

[bluetooth]# pair FC:58:FA:XX:XX:XX
Attempting to pair with FC:58:FA:XX:XX:XX
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX Connected: yes
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX ServicesResolved: yes
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX Paired: yes
[ERGO BTS-520]#                            Pairing successful
[ERGO BTS-520]# trust FC:58:FA:XX:XX:XX
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX Trusted: yes
[ERGO BTS-520]#                            Changing FC:58:FA:XX:XX:XX trust succeeded
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX ServicesResolved: no
[bluetooth]#                         [CHG] Device FC:58:FA:XX:XX:XX Connected: no
[bluetooth]# connect FC:58:FA:XX:XX:XX
Attempting to connect to FC:58:FA:XX:XX:XX
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX Connected: yes
[ERGO BTS-520]#                            Connection successful
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 00001101-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 00001108-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000110b-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000110c-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000110e-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX UUIDs: 0000111e-0000-1000-8000-00805f9b34fb
[ERGO BTS-520]#                            [CHG] Device FC:58:FA:XX:XX:XX ServicesResolved: yes

If no connection to device within 2-3 seconds after paired, device status changed to "Disconnected".

Because of rely on order of device property changes (ServicesResolved, Connected, etc) my logic of BT manager is broken.

Does this behavior is described somehow by BlueZ or linux HCI subsystem ?

Will be grateful for any help, thank you.

PS: I know about this kernel headers parameters, and even tried to play around with it by increasing values.

HCI_DISCONN_TIMEOUT     msecs_to_jiffies(2000)  /* 2 seconds */
HCI_CMD_TIMEOUT     msecs_to_jiffies(2000)  /* 2 seconds */
HCI_LE_AUTOCONN_TIMEOUT msecs_to_jiffies(2000)  /* 2 seconds */

But it seems like this not works for me.

1

There are 1 best solutions below

2
On

Not sure I understand your question. Pairing is normally a one-off provisioning step where keys are exchanged and a device is established as trusted. I would expect the device to disconnect once this setup has happened.

Subsequent connections don't need to have the pairing step happen first. You would do connection and service discovery because the two devices are already paired and trusted.

The pairing process discussed in a series of blogs on the Bluetooth SIG site: https://www.bluetooth.com/blog/bluetooth-pairing-part-1-pairing-feature-exchange/