From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 09/10] adapter: Don't cancel requests of a new link on stale disconnection
Date: Fri, 30 Oct 2026 17:29:38 -0400 [thread overview]
Message-ID: <20261030212940.753771-10-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261030212940.753771-1-luiz.dentz@gmail.com>
From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
When the remote reconnects before the disconnection of the previous
link is processed, e.g. if bluetoothd was slow, processing it cancels
the pending service authorizations and authentication of the device,
which then belong to the new link, refusing e.g. its AVDTP connection.
Check with the kernel whether a BR/EDR link to the device exists again,
and if so don't cancel them.
Fixes: 5b6ffe0381e8 ("adapter: Cancel the service authorization when remote is disconnected")
Assisted-by: Claude:claude-opus-5-5
---
src/adapter.c | 42 ++++++++++++++++++++++++++++++++++++++++--
1 file changed, 40 insertions(+), 2 deletions(-)
diff --git a/src/adapter.c b/src/adapter.c
index 3c0895d1e241..fd6746258f70 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -7985,6 +7985,36 @@ struct agent *adapter_get_agent(struct btd_adapter *adapter)
return agent_get(NULL);
}
+/* Whether the kernel has a BR/EDR link to the device: its disconnection
+ * may be processed after the device connected again, e.g. when bluetoothd
+ * was slow to process events.
+ */
+static bool link_connected(struct btd_adapter *adapter,
+ struct btd_device *device, uint8_t bdaddr_type)
+{
+ struct hci_conn_info_req *cr;
+ bool connected;
+ int dd;
+
+ if (bdaddr_type != BDADDR_BREDR)
+ return false;
+
+ dd = hci_open_dev(adapter->dev_id);
+ if (dd < 0)
+ return false;
+
+ cr = g_malloc0(sizeof(*cr) + sizeof(struct hci_conn_info));
+ bacpy(&cr->bdaddr, device_get_address(device));
+ cr->type = ACL_LINK;
+
+ connected = !ioctl(dd, HCIGETCONNINFO, cr);
+
+ g_free(cr);
+ hci_close_dev(dd);
+
+ return connected;
+}
+
static void adapter_remove_connection(struct btd_adapter *adapter,
struct btd_device *device,
uint8_t bdaddr_type,
@@ -8005,7 +8035,9 @@ static void adapter_remove_connection(struct btd_adapter *adapter,
device_remove_connection(device, bdaddr_type, &remove_device, reason);
- device_cancel_authentication(device, TRUE);
+ /* Requests of a link that connected meanwhile are not cancelled */
+ if (!link_connected(adapter, device, bdaddr_type))
+ device_cancel_authentication(device, TRUE);
/* If another bearer is still connected */
if (btd_device_bearer_is_connected(device))
@@ -9013,6 +9045,7 @@ static void dev_disconnected(struct btd_adapter *adapter,
uint8_t reason)
{
struct btd_device *device;
+ bool reconnected = false;
char dst[18];
ba2str(&addr->bdaddr, dst);
@@ -9023,6 +9056,11 @@ static void dev_disconnected(struct btd_adapter *adapter,
if (device) {
bool removed;
+ /* The device connected again before this was processed: its
+ * pending requests belong to the new link.
+ */
+ reconnected = link_connected(adapter, device, addr->type);
+
adapter_remove_connection(adapter, device, addr->type, reason,
&removed);
/* No need to continue if device was removed from the adapter,
@@ -9036,7 +9074,7 @@ static void dev_disconnected(struct btd_adapter *adapter,
}
/* device could be still connected to different bearer */
- if (!device || !btd_device_is_connected(device))
+ if (!reconnected && (!device || !btd_device_is_connected(device)))
bonding_attempt_complete(adapter, &addr->bdaddr, addr->type,
MGMT_STATUS_DISCONNECTED);
}
--
2.56.0
next prev parent reply other threads:[~2026-10-30 21:29 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-30 21:29 [PATCH BlueZ v1 00/10] Run test-functional under User Mode Linux Luiz Augusto von Dentz
2026-10-30 21:29 ` [PATCH BlueZ v1 01/10] tools/test-runner: Default to time travel with " Luiz Augusto von Dentz
2026-10-30 23:58 ` Run test-functional under " bluez.test.bot
2026-10-30 21:29 ` [PATCH BlueZ v1 02/10] tools/test-runner: Unbind virtio devices before powering off UML Luiz Augusto von Dentz
2026-10-30 21:29 ` [PATCH BlueZ v1 03/10] emulator: Answer the time of a guest with a skew Luiz Augusto von Dentz
2026-10-30 21:29 ` [PATCH BlueZ v1 04/10] adapter: Don't return Busy when a pending change sets the same value Luiz Augusto von Dentz
2026-10-30 21:34 ` Luiz Augusto von Dentz
2026-10-30 21:29 ` [PATCH BlueZ v1 05/10] test: functional: wait for BAP transports to be configured Luiz Augusto von Dentz
2026-10-30 21:29 ` [PATCH BlueZ v1 06/10] shared/mcp: Don't drop commands before supported opcodes are read Luiz Augusto von Dentz
2026-10-30 21:29 ` [PATCH BlueZ v1 07/10] doc/test-functional: Document User Mode Linux VM hosts Luiz Augusto von Dentz
2026-10-30 21:29 ` [PATCH BlueZ v1 08/10] a2dp: Fix refusing the AVDTP connection of a new link Luiz Augusto von Dentz
2026-10-30 21:29 ` Luiz Augusto von Dentz [this message]
2026-10-30 21:29 ` [PATCH BlueZ v1 10/10] test: Cover A2DP reconnection with a pending disconnection Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261030212940.753771-10-luiz.dentz@gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox