All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v4 01/18] gatt-database: Drop stale device state for removed bonds
Date: Fri, 20 Nov 2026 11:54:51 -0500	[thread overview]
Message-ID: <20261120165510.1858959-2-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20261120165510.1858959-1-luiz.dentz@gmail.com>

From: Cheng Jiang <cheng.jiang@oss.qualcomm.com>

When a device is removed while disconnected, its cached CCC state
stays in the GATT database and is restored on the next connection.
Drop that state from device_remove() so a re-paired device starts
clean.

Assisted-by: Claude:claude-haiku-5-5
---
 src/device.c        |  3 +++
 src/gatt-database.c | 34 ++++++++++++++++++++++++++++++++++
 src/gatt-database.h |  2 ++
 3 files changed, 39 insertions(+)

diff --git a/src/device.c b/src/device.c
index 36a980d1ea66..b4dd52e4f34e 100644
--- a/src/device.c
+++ b/src/device.c
@@ -5637,6 +5637,9 @@ void device_remove(struct btd_device *device, gboolean remove_stored)
 {
 	DBG("Removing device %s", device->path);
 
+	btd_gatt_database_remove_device(
+			btd_adapter_get_database(device->adapter), device);
+
 	if (device->auth_retry_id) {
 		device->auth_retry_id = 0;
 		timeout_remove(device->auth_retry_id);
diff --git a/src/gatt-database.c b/src/gatt-database.c
index cbee49d59f55..81a52492002d 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -4277,6 +4277,40 @@ void btd_gatt_database_att_disconnected(struct btd_gatt_database *database,
 	att_disconnected(0, state);
 }
 
+static void remove_device_state(struct btd_gatt_database *database,
+				const bdaddr_t *addr, uint8_t type)
+{
+	struct device_state *state;
+
+	state = find_device_state(database, addr, type);
+	if (!state)
+		return;
+
+	/* While connected, gatt_server_cleanup() still reaches the state
+	 * through the disconnect callback, so leave it alone here.
+	 */
+	if (state->disc_id)
+		return;
+
+	queue_foreach(state->ccc_states, clear_ccc_state, state->db);
+	queue_remove(database->device_states, state);
+	device_state_free(state);
+}
+
+void btd_gatt_database_remove_device(struct btd_gatt_database *database,
+						struct btd_device *device)
+{
+	const bdaddr_t *addr = device_get_address(device);
+
+	/* Adapters without LE support have no GATT database */
+	if (!database)
+		return;
+
+	/* A dual-mode device can have a state for each bearer */
+	remove_device_state(database, addr, device_get_le_address_type(device));
+	remove_device_state(database, addr, BDADDR_BREDR);
+}
+
 static void restore_ccc(struct btd_gatt_database *database,
 			const bdaddr_t *addr, uint8_t addr_type, uint16_t value)
 {
diff --git a/src/gatt-database.h b/src/gatt-database.h
index 998e3c452b16..94469a707184 100644
--- a/src/gatt-database.h
+++ b/src/gatt-database.h
@@ -20,6 +20,8 @@ btd_gatt_database_get_adapter(struct btd_gatt_database *database);
 
 void btd_gatt_database_att_disconnected(struct btd_gatt_database *database,
 						struct btd_device *device);
+void btd_gatt_database_remove_device(struct btd_gatt_database *database,
+						struct btd_device *device);
 void btd_gatt_database_server_connected(struct btd_gatt_database *database,
 						struct bt_gatt_server *server);
 
-- 
2.56.0


  reply	other threads:[~2026-11-20 16:55 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-20 16:54 [PATCH BlueZ v4 00/18] Channel Sounding and RAP fixes Luiz Augusto von Dentz
2026-11-20 16:54 ` Luiz Augusto von Dentz [this message]
2026-11-20 22:32   ` bluez.test.bot
2026-11-20 16:54 ` [PATCH BlueZ v4 02/18] shared/rap: Reset the readable Ranging Counters per connection Luiz Augusto von Dentz
2026-11-20 16:54 ` [PATCH BlueZ v4 03/18] shared/rap: Subscribe on-demand data with the requested transport Luiz Augusto von Dentz
2026-11-20 16:54 ` [PATCH BlueZ v4 04/18] shared/rap: Subscribe to Ranging Data when a measurement starts Luiz Augusto von Dentz
2026-11-20 16:54 ` [PATCH BlueZ v4 05/18] client/cs: Fix use-after-free in stop_measurement_reply Luiz Augusto von Dentz
2026-11-20 16:54 ` [PATCH BlueZ v4 06/18] shared/hci: Look up the connection handle on the right link Luiz Augusto von Dentz
2026-11-20 16:54 ` [PATCH BlueZ v4 07/18] profiles/ranging: Let the Reflector run the CS setup phase Luiz Augusto von Dentz
2026-11-20 16:54 ` [PATCH BlueZ v4 08/18] profiles/ranging: Let StartMeasurement() pick the Initiator for Both Luiz Augusto von Dentz
2026-11-20 16:54 ` [PATCH BlueZ v4 09/18] profiles/ranging: Take the CS role from Config Complete Luiz Augusto von Dentz
2026-11-20 16:55 ` [PATCH BlueZ v4 10/18] profiles/ranging: Act on a CS configuration created by the peer Luiz Augusto von Dentz
2026-11-20 16:55 ` [PATCH BlueZ v4 11/18] profiles/ranging: Keep a peer-driven setup from being rewound Luiz Augusto von Dentz
2026-11-20 16:55 ` [PATCH BlueZ v4 12/18] profiles/ranging: Defer CS Security Enable until the link is encrypted Luiz Augusto von Dentz
2026-11-20 16:55 ` [PATCH BlueZ v4 13/18] profiles/ranging: Choose the CS antenna configuration from both ends Luiz Augusto von Dentz
2026-11-20 16:55 ` [PATCH BlueZ v4 14/18] profiles/ranging: Do not start a procedure after StopMeasurement() Luiz Augusto von Dentz
2026-11-20 16:55 ` [PATCH BlueZ v4 15/18] profiles/ranging: Keep CS sessions apart from stale and unrelated events Luiz Augusto von Dentz
2026-11-20 16:55 ` [PATCH BlueZ v4 16/18] shared/rap: Start the Real-time timeout when the procedure starts Luiz Augusto von Dentz
2026-11-20 16:55 ` [PATCH BlueZ v4 17/18] unit/test-rap: Add tests for Ranging Data subscription and counters Luiz Augusto von Dentz
2026-11-20 16:55 ` [PATCH BlueZ v4 18/18] shared/rap: Defer Ranging Data mode selection until Features is read 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=20261120165510.1858959-2-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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.