From 25dc0c5026442edee1ef0b987aca723ea3b593fb Mon Sep 17 00:00:00 2001 From: Johan Hedberg Date: Mon, 3 Nov 2014 22:02:53 +0200 Subject: [PATCH] core: Remove unnecessary LE connect for kernels that don't need it From mgmt version 1.4 onward the ATT server socket gets appropriate notifications also for outgoing connections triggered by mgmt_pair_device. This patch adds a check for the mgmt version to not unnecessarily create the LE client socket first. For now this also fixes a potential race condition in the kernel where the socket connect LE scan disabling will fail because of a preceding mgmt_stop_discovery trying to do the same thing. Since mgmt commands (unlike the socket connect) are serialized the race cannot happen with the mgmt_stop_discover + mgmt_pair_device combination. --- src/adapter.c | 13 +++++++++++++ src/adapter.h | 2 ++ src/device.c | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/adapter.c b/src/adapter.c index 21c1bb6ff..606affdfe 100644 --- a/src/adapter.c +++ b/src/adapter.c @@ -7450,3 +7450,16 @@ void adapter_shutdown(void) if (!adapter_remaining) btd_exit(); } + +/* + * Check if workaround for broken ATT server socket behavior is needed + * where we need to connect an ATT client socket before pairing to get + * early access to the ATT channel. + */ +bool btd_le_connect_before_pairing(void) +{ + if (MGMT_VERSION(mgmt_version, mgmt_revision) < MGMT_VERSION(1, 4)) + return true; + + return false; +} diff --git a/src/adapter.h b/src/adapter.h index 8f4098a50..737479f14 100644 --- a/src/adapter.h +++ b/src/adapter.h @@ -225,3 +225,5 @@ gboolean btd_adapter_check_oob_handler(struct btd_adapter *adapter); void btd_adapter_for_each_device(struct btd_adapter *adapter, void (*cb)(struct btd_device *device, void *data), void *data); + +bool btd_le_connect_before_pairing(void); diff --git a/src/device.c b/src/device.c index 1499d1b15..025743fc9 100644 --- a/src/device.c +++ b/src/device.c @@ -1815,7 +1815,7 @@ static DBusMessage *pair_device(DBusConnection *conn, DBusMessage *msg, * this in the ATT connect callback) */ if (bdaddr_type != BDADDR_BREDR) { - if (!state->connected) + if (!state->connected && btd_le_connect_before_pairing()) err = device_connect_le(device); else err = adapter_create_bonding(adapter, &device->bdaddr, -- 2.47.3