Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH] adapter: Fix Discovering staying true after a rejected stop
@ 2026-10-27 16:08 Kevin Dewald
  2026-10-27 17:42 ` Kevin Dewald
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Kevin Dewald @ 2026-10-27 16:08 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Luiz Augusto von Dentz, Kevin Dewald

The kernel rejects Stop Discovery when no discovery is active by the
time it processes the command, because the discovery ended or another
mgmt client stopped it just before. stop_discovery_complete() then
removes the client but keeps the discovery state, so Discovering stays
true with no client left, and the next StartDiscovery with the same
filter returns without starting a discovery. The client that called
StopDiscovery also gets an InProgress error, and "No discovery started"
if it tries again.

Treat MGMT_STATUS_REJECTED as the discovery being stopped, as
stop_passive_scanning_complete() already does.

Closes: https://github.com/bluez/bluez/issues/2547
Link: https://github.com/bluez/bluez/issues/807
Fixes: c1226f79ec97 ("adapter: Fix not checking status of stop discovery command")
Assisted-by: Claude:claude-opus-5.5
---
Reproduced with a functional test that holds the emulated controller
while a second mgmt client stops the discovery, so the kernel rejects
the Stop Discovery bluetoothd sends for StopDiscovery: on master the
call fails with InProgress and Discovering stays true (3 of 3 runs);
with this patch it succeeds and Discovering goes false (5 of 5). I can
send the test as well if you want it.

 src/adapter.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index 1561ea3bf..4d753028a 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2194,6 +2194,14 @@ static void stop_discovery_complete(uint8_t status, uint16_t length,
 
 	DBG("status 0x%02x", status);
 
+	/*
+	 * MGMT_STATUS_REJECTED is returned from kernel when no discovery is
+	 * active, e.g. because it ended or another mgmt client stopped it
+	 * just before this command, so treat it as stopped as well.
+	 */
+	if (status == MGMT_STATUS_REJECTED)
+		status = MGMT_STATUS_SUCCESS;
+
 	client = discovery_complete(adapter, status);
 	if (client)
 		discovery_remove(client);

base-commit: b0bf49270d445da0852851f393cd67a0a1e5f05e
-- 
2.54.0 (Apple Git-157)


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2026-10-28 19:50 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-27 16:08 [PATCH] adapter: Fix Discovering staying true after a rejected stop Kevin Dewald
2026-10-27 17:42 ` Kevin Dewald
2026-10-27 20:30 ` bluez.test.bot
2026-10-28 19:50 ` [PATCH] " patchwork-bot+bluetooth

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox