monitor: Cache IRK being parsed
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Fri, 24 Mar 2023 23:38:56 +0000 (16:38 -0700)
committerAyush Garg <ayush.garg@samsung.com>
Fri, 5 Jan 2024 10:41:34 +0000 (16:11 +0530)
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
monitor/keys.h
monitor/packet.c

index d2fa3b2..c1eebae 100755 (executable)
@@ -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;
+}
index e40c90f..f44d332 100755 (executable)
@@ -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]);
index 4f4f7d0..0d310ca 100755 (executable)
@@ -12866,6 +12866,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)