diff mbox series

[BlueZ,4/4] monitor: Cache IRK being parsed

Message ID 20230324233856.3693370-4-luiz.dentz@gmail.com (mailing list archive)
State Accepted
Commit 011e562a98a8b8c278391bc64d9dc2c8df0a5585
Headers show
Series [BlueZ,1/4] shared/gatt-db: Make gatt_db_attribute_get_value public | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
tedd_an/CheckPatch success CheckPatch PASS
tedd_an/GitLint success Gitlint PASS
tedd_an/IncrementalBuild success Incremental Build PASS

Commit Message

Luiz Augusto von Dentz March 24, 2023, 11:38 p.m. UTC
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 mbox series

Patch

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)