Skip to contentSkip to conversation

Bluetooth: fix autoconnect for pending connect attempt

PATCH In review Jakub Pawlowski 2 participants 2 messages Oct 7, 2015

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Bluetooth: fix autoconnect for pending connect attempt

When adding device to auto connect whitelist when there is pending connect attempt, there is no need to update scan, or to add it to pend_le_conns list.

When trying to connect to le device, it is added to pend_le_conns and background scan is updated. There's no need to repeat this operation when adding device to auto connect list. Only update of params->auto_connect value is required.

If both operations try to update background scan, and are quickly queued together when scan was disabled, second operation might improperly try to start, instead of restarting scan. This means that adding device to connect whitelist would report failure, even though it succeeded.

In order to reproduce this bug type in bluetoothctl:
connect D9:00:00:00:00
disconnect D9:00:00:00:00
connect D9:00:00:00:00

and observe bluetoothd logs (error happens during second connect attempt):
src/device.c:device_connect_le() Connection attempt to: D0:5F:B8:52:22:9F Failed to add device D0:5F:B8:52:22:9F (1): Busy (0x0a)

---
 net/bluetooth/mgmt.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
net/bluetooth/mgmt.c +6 -1
index ccaf5a4..1108281 100644
@@ -6122,7 +6122,12 @@ static int hci_conn_params_set(struct hci_request *req, bdaddr_t *addr,
 		break;
 	case HCI_AUTO_CONN_DIRECT:
 	case HCI_AUTO_CONN_ALWAYS:
-		if (!is_connected(hdev, addr, addr_type)) {
+		/* If we are connected, don't add to whitelist. If we are
+		 * connecting, we're already added to pend_le_conns and
+		 * scanning.
+		 */
+		if (!is_connected(hdev, addr, addr_type) &&
+		    !params->auto_connect == HCI_AUTO_CONN_EXPLICIT) {
 			list_add(&params->action, &hdev->pend_le_conns);
 			__hci_update_background_scan(req);
 		}
Signature · 1 line
2.6.0.rc2.230.g3dd15c0
maintainer
#1 lore raw

Hi Jakub,

Quoted 31 lines

When adding device to auto connect whitelist when there is pending connect attempt, there is no need to update scan, or to add it to pend_le_conns list.

When trying to connect to le device, it is added to pend_le_conns and background scan is updated. There's no need to repeat this operation when adding device to auto connect list. Only update of params->auto_connect value is required.

If both operations try to update background scan, and are quickly queued together when scan was disabled, second operation might improperly try to start, instead of restarting scan. This means that adding device to connect whitelist would report failure, even though it succeeded.

In order to reproduce this bug type in bluetoothctl:
connect D9:00:00:00:00
disconnect D9:00:00:00:00
connect D9:00:00:00:00

and observe bluetoothd logs (error happens during second connect attempt):
src/device.c:device_connect_le() Connection attempt to: D0:5F:B8:52:22:9F Failed to add device D0:5F:B8:52:22:9F (1): Busy (0x0a)
---
net/bluetooth/mgmt.c | 7 ++++++-

1 file changed, 6 insertions(+), 1 deletion(-)
net/bluetooth/mgmt.c +0 -0
index ccaf5a4..1108281 100644

net/bluetooth/mgmt.c static int hci_conn_params_set(struct hci_request *req, bdaddr_t *addr, · line 6130

Quoted 10 lines
net/bluetooth/mgmt.c +6 -1
@@ -6122,7 +6122,12 @@ static int hci_conn_params_set(struct hci_request *req, bdaddr_t *addr,
 		break;
 	case HCI_AUTO_CONN_DIRECT:
 	case HCI_AUTO_CONN_ALWAYS:
-		if (!is_connected(hdev, addr, addr_type)) {
+		/* If we are connected, don't add to whitelist. If we are
+		 * connecting, we're already added to pend_le_conns and
+		 * scanning.
+		 */
+		if (!is_connected(hdev, addr, addr_type) &&
+		    !params->auto_connect == HCI_AUTO_CONN_EXPLICIT) {

we are not doing it like this. I think you are looking for != here.

Regards

Marcel