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 4/4] monitor: Cache IRK being parsed
Date: Fri, 24 Mar 2023 16:38:56 -0700	[thread overview]
Message-ID: <20230324233856.3693370-4-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20230324233856.3693370-1-luiz.dentz@gmail.com>

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

This caches any IRK being parsed so they can be used to resolve
addresses later which fixes the problem of only being able to resolve
addresses if the monitor happens to be active while SMP exchange the
keys.
---
 monitor/keys.c   | 26 ++++++++++++++++++++++++++
 monitor/keys.h   |  2 ++
 monitor/packet.c |  1 +
 3 files changed, 29 insertions(+)

diff --git a/monitor/keys.c b/monitor/keys.c
index d2fa3b23ffec..c1eebae82ac2 100644
--- a/monitor/keys.c
+++ b/monitor/keys.c
@@ -112,3 +112,29 @@ bool keys_resolve_identity(const uint8_t addr[6], uint8_t ident[6],
 
 	return false;
 }
+
+static bool match_key(const void *data, const void *match_data)
+{
+	const struct irk_data *irk = data;
+	const uint8_t *key = match_data;
+
+	return !memcmp(irk->key, key, 16);
+}
+
+bool keys_add_identity(const uint8_t addr[6], uint8_t addr_type,
+					const uint8_t key[16])
+{
+	struct irk_data *irk;
+
+	irk = queue_find(irk_list, match_key, key);
+	if (!irk) {
+		irk = new0(struct irk_data, 1);
+		memcpy(irk->key, key, 16);
+		queue_push_tail(irk_list, irk);
+	}
+
+	memcpy(irk->addr, addr, 6);
+	irk->addr_type = addr_type;
+
+	return true;
+}
diff --git a/monitor/keys.h b/monitor/keys.h
index e40c90fa9c72..f44d33295269 100644
--- a/monitor/keys.h
+++ b/monitor/keys.h
@@ -20,3 +20,5 @@ void keys_update_identity_addr(const uint8_t addr[6], uint8_t addr_type);
 
 bool keys_resolve_identity(const uint8_t addr[6], uint8_t ident[6],
 							uint8_t *ident_type);
+bool keys_add_identity(const uint8_t addr[6], uint8_t addr_type,
+					const uint8_t key[16]);
diff --git a/monitor/packet.c b/monitor/packet.c
index d9e8abf41fed..c6ff16eda9cf 100644
--- a/monitor/packet.c
+++ b/monitor/packet.c
@@ -12870,6 +12870,7 @@ static void mgmt_print_identity_resolving_key(const void *data)
 
 	mgmt_print_address(data, address_type);
 	print_hex_field("Key", data + 7, 16);
+	keys_add_identity(data, address_type, data + 7);
 }
 
 static void mgmt_print_signature_resolving_key(const void *data)
-- 
2.39.2


  parent reply	other threads:[~2023-03-24 23:39 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-24 23:38 [PATCH BlueZ 1/4] shared/gatt-db: Make gatt_db_attribute_get_value public Luiz Augusto von Dentz
2023-03-24 23:38 ` [PATCH BlueZ 2/4] monitor/att: Print value when printing descriptors Luiz Augusto von Dentz
2023-03-24 23:38 ` [PATCH BlueZ 3/4] monitor/att: Fix not loading gatt_db for devices using RPA Luiz Augusto von Dentz
2023-03-24 23:38 ` Luiz Augusto von Dentz [this message]
2023-03-25  2:27 ` [BlueZ,1/4] shared/gatt-db: Make gatt_db_attribute_get_value public bluez.test.bot
2023-03-27 21:20 ` [PATCH BlueZ 1/4] " 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=20230324233856.3693370-4-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