-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Bluetooth: hci_usb fails to connect to two devices with slow advertising interval #23280
Comments
I get the same behavior on a Raspberry Pi 3 running |
@ChristianHirsch can you please reproduce the issue while running |
@carlescufi see logs attached. |
It seems that when the problem occurs, it repeatedly requests the data from the remote device.. |
At btmon_hci_usb.log line 428 I restarted the bluetooth service. |
With the internal controller, the connections do not overlap, seems the controller you are using does not support simultaneous connections and scanning to connect until the previous connection is being disconnected by the gatttool. The LE Create Connection is only issued after the previous connection is disconnected. Also, this way it reuses the same connection handle 3585.
In the Zephyr controller, I am "assuming" the host is made aware that simultaneous connection and scanning to initiate is supported, and hence second connection is initiated while the previous is still connected.
I do not see anything wrong in the HCI logs, before you restarted at line 428, the second connection is up and alive receiving the notifications.
|
@jhedberg do you know if Bluez/gatttool would behave differently? Does the host use the local supported features? |
@cvinayak The person is using Zephyr's hci_usb sample on a nRF52840 board :-) |
That's also strange, @cvinayak, I did not enable notifications, so why am I receiving them? |
@jfischer-phytec-iot Reporter is using PC's controller
|
@ ChristianHirsch something in the host does the following... not sure if this is the CCCD handle (0x0013) being written to enable notifications.
|
@ChristianHirsch also, the handle you wanted to read has been read in the second connection.
|
a)
b)
To be clear, this |
Both (a) and (b) are the same comment text you have quote, and is for the internal PC's controller.
This is for the Zephyr controller. |
@cvinayak, there are some things that bother me:
This is not true. I can connect to two devices simultaneously with the internal adapter. I did the following and it works perfectly with the internal adapter: $ gatttool -t random -b AA:BB:CC:DD:EE:FF --char-read --handle=0x0012 --listen & (sleep 5; echo "Executing gatttool"; gatttool -t random -b FF:EE:DD:CC:BB:AA --char-read --handle=0x0012)
Characteristic value/descriptor: 41
Executing gatttool
Characteristic value/descriptor: 4e Here is the log btmon_internal_2sim.log. You also see that no CCCD is written to device
|
@ChristianHirsch any reason why you are using a 5 seconds sleep with your internal controller when connecting to devices? I am not able to reproduce the issue reported with vanilla peripheral sample or slow advertising peripheral sample. My commandline and btmon logs atttached.
|
@cvinayak thanks for trying.
This is just to guarantee, that gatttool connects to device 1 first and keep the connection alive, before connecting to device 2. If I don't use the sleep, it might happen, that device 2 is connected first. This was to show that the internal adapter can handle two connections simultaneously. Did you execute the commands on the Could you please try to execute this script? The sleep in the script makes sure that the PC disconnects from the devices. #!/bin/bash
while true ; do
gatttool -t random -b AA:BB:CC:DD:EE:FF --char-read --handle=0x0012
if [ $? -eq 1 ]; then
break
fi
gatttool -t random -b FF:EE:DD:CC:BB:AA --char-read --handle=0x0012
if [ $? -eq 1 ]; then
break
fi
sleep 5
done This script runs successfully the first couple of times. But after some attempts, it fails. Then, I need to restart the bluetooth service and from that point on it almost fails every time in the first attempt to connect to the second device.. |
@ChristianHirsch Yes, I have tried connections many times (and with upto 3 peripherals). What I find different from your logs is, your host is doing more than just reading the characteristics (like ATT MTU request, which does not get num complete and no more ATT transaction there after). That is not what is done when using internal controller. If this happens it looks like gatttool is out-of-sync with the connection, and with notifications enabled. I am suspecting gatttool and something inherent to bluetoothd interfere. gatttool is deprecated in the latest BlueZ releases (and had to use --enable-deprecated to build it), @Vudentz which tool should we be using instead? |
@ChristianHirsch Any updates? Please use latest BlueZ and compatible tools, also latest Zephyr upstream master and revert back (I have been using hci_usb on my virtual machine for the last one week, scanning and making simultaneous connections using bluetoothctl, and not encountered any issues) Alternatively, you could build hci_usb with CONFIG_BT_LL_SW_LEGACY=y in the latest upstream master branch, which is the controller in Zephyr v1.14 but with fixes. |
@cvinayak Unfortunately not. I'm already running the Do you have a script for bluetoothctl that you use for connecting and reading characteristics? Unfortunately, I'm a little bit lost with bluetoothctl.. It does not show me all the available services and characteristics of the |
@cvinayak I wrote a python script, that reproduces the error by using the bluez d-bus api. I have a similar behavior: it runs without any problems with the internal adapter, but I get errors with the org.freedesktop.DBus.Error.NoReply: Did not receive a reply. Possible causes include: the remote application did not send a reply, the message bus security policy blocked the reply, the reply timeout expired, or the network connection was broken. The script is available here. You can execute it as follows: ./ble_dbus.py -i hci1 00002a19-0000-1000-8000-00805f9b34fb AA:BB:CC:DD:EE:FF FF:EE:DD:CC:BB:AA |
@cvinayak could you take a look please? |
@carlescufi yes, placed on the top in my backlog, hope to start on this 19/03. |
@ChristianHirsch I am able to reproduce the DBus error when running your script. In the btmon logs, it is the same behavior as before, the host stack performs service discovery and enables notifications. I dont see any issue in the hci_usb sample, it is merely doing what the host is telling the controller to do using HCI commands/data. I tried with hci_usb build with no PHY update, data length and privacy support (to emulate your internal device based on the feature exchange I read), and got different results. But in this case too, host does service discovery but disconnections happen before enabling notifications. |
Thanks @cvinayak for trying, but your console out does not look like what I was expecting. It seems that you did not receive any succefful value, right? I will create a more robust script. |
@ChristianHirsch Sorry for the late reply. No, its weird that something in the host automatically performs service discovery and notification enable, and the request to read may have been missed or delayed. |
@ChristianHirsch can you check with the BlueZ folks to see if they have an idea of what the issue might be? |
Yes, I will check with them @carlescufi. |
Thank you. I will close this in the meantime, feel free to reopen if you find out that this is indeed a Zephyr issue. |
Describe the bug
Connecting to two devices one after another and reading data with the
samples/bluetooth/hci_usb
sample fails on a PC. First the PC connects to device 1 (AA:BB:CC:DD:EE:FF
) and reads the data. Then, it tries to connect to device 2 (FF:EE:DD:CC:BB:AA
) and read the data, but establishing a connection (or channel?) fails, although, the PC (or bluetooth service) seems to be connected to the device (the panel icon shows an established connection to the device and the device can't be found if the PC scans for devices). The PC does not terminate the connection until manually restarting the blueetooth service.To Reproduce
Steps to reproduce the behavior:
samples/bluetooth/hci_usb
on one board withCONFIG_BT_MAX_CONN
increased to8
(e.g., on a nRF52840 board).samples/bluetooth/peripheral_hr
on two other boards (e.g.,particle_xenon
) and changeBT_GAP_ADV_FAST_INT_MIN_2
andBT_GAP_ADV_FAST_INT_MAX_2
toBT_GAP_ADV_SLOW_INT_MIN
andBT_GAP_ADV_SLOW_INT_MAX
, by, e.g.gatttool
to theperipheral_hr
devices one after another and read some data:gatttool -t random -b AA:BB:CC:DD:EE:FF --char-read --handle=0x0012 ; gatttool -t random -b FF:EE:DD:CC:BB:AA --char-read --handle=0x0012
Expected behavior
Connecting to both devices, one after another, should not fail, and both connections terminate after reading some data. Expected output:
Impact
Showstopper
Screenshots or console output
See above.
Environment (please complete the following information):
Additional context
I don't know if this is a problem of Zephyr or the PC's bluetooth driver or bluez, however, it only happens with the
hci_usb
sample (running on a nRF52840 board). It does not happen with the PC's internal bluetooth adapter.Sometimes connecting to both devices, one after another, with the
hci_usb
sample works. But most of the time it does not.The text was updated successfully, but these errors were encountered: