public inbox for linux-bluetooth@vger.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 v1] monitor: Fix not loading local GATT DB from cache
Date: Mon,  6 Apr 2026 16:00:43 -0400	[thread overview]
Message-ID: <20260406200043.3447321-1-luiz.dentz@gmail.com> (raw)

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

The local GATT DB maybe discover in previous connection and therefore
should be cached as well to be able to decode follow-up connections
where the discovery may not be visible.
---
 monitor/att.c | 23 +++++++++++++++++++----
 1 file changed, 19 insertions(+), 4 deletions(-)

diff --git a/monitor/att.c b/monitor/att.c
index e76cb44d28f5..e8e0d499a826 100644
--- a/monitor/att.c
+++ b/monitor/att.c
@@ -412,12 +412,24 @@ static bool match_cache_id(const void *data, const void *match_data)
 	return !bacmp(&cache->id, id);
 }
 
-static void gatt_cache_add(struct packet_conn_data *conn, struct gatt_db *db)
+static void gatt_cache_add(struct packet_conn_data *conn, struct gatt_db *ldb,
+							struct gatt_db *rdb)
 {
 	struct gatt_cache *cache;
 	bdaddr_t id;
 	uint8_t id_type;
 
+	/* Attempt to cache local db if not empty */
+	if (!gatt_db_isempty(ldb)) {
+		cache = new0(struct gatt_cache, 1);
+		bacpy(&cache->id, (bdaddr_t *)conn->src);
+		cache->db = gatt_db_ref(ldb);
+		queue_push_tail(cache_list, cache);
+	}
+
+	if (gatt_db_isempty(rdb))
+		return;
+
 	if (!keys_resolve_identity(conn->dst, id.b, &id_type))
 		bacpy(&id, (bdaddr_t *)conn->dst);
 
@@ -429,7 +441,7 @@ static void gatt_cache_add(struct packet_conn_data *conn, struct gatt_db *db)
 
 	cache = new0(struct gatt_cache, 1);
 	bacpy(&cache->id, &id);
-	cache->db = gatt_db_ref(db);
+	cache->db = gatt_db_ref(rdb);
 	queue_push_tail(cache_list, cache);
 }
 
@@ -437,8 +449,7 @@ static void att_conn_data_free(struct packet_conn_data *conn, void *data)
 {
 	struct att_conn_data *att_data = data;
 
-	if (!gatt_db_isempty(att_data->rdb))
-		gatt_cache_add(conn, att_data->rdb);
+	gatt_cache_add(conn, att_data->ldb, att_data->rdb);
 
 	gatt_db_unref(att_data->rdb);
 	gatt_db_unref(att_data->ldb);
@@ -520,6 +531,10 @@ static void load_gatt_db(struct packet_conn_data *conn)
 		cache = queue_find(cache_list, match_cache_id, &id);
 		if (cache)
 			data->rdb = gatt_db_ref(cache->db);
+
+		cache = queue_find(cache_list, match_cache_id, &conn->src);
+		if (cache)
+			data->ldb = gatt_db_ref(cache->db);
 	}
 }
 
-- 
2.53.0


             reply	other threads:[~2026-04-06 20:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-06 20:00 Luiz Augusto von Dentz [this message]
2026-04-06 20:55 ` [BlueZ,v1] monitor: Fix not loading local GATT DB from cache bluez.test.bot
2026-04-07 13:30 ` [PATCH BlueZ v1] " patchwork-bot+bluetooth

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=20260406200043.3447321-1-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