diff options
author | Michael Janssen <jamuraa@chromium.org> | 2014-12-15 17:03:35 -0800 |
---|---|---|
committer | Luiz Augusto von Dentz <luiz.von.dentz@intel.com> | 2014-12-16 10:54:32 -0200 |
commit | db72587787c58408526da0bf92f27cdf32525592 (patch) | |
tree | 5bcf4cc375f6004072cea5d4c51ad1c27e4598d1 /monitor/keys.c | |
parent | 87a75236a7934582b1189efc08237a471d78b8d7 (diff) | |
download | bluez-db72587787c58408526da0bf92f27cdf32525592.tar.gz |
monitor/keys: use queue_find over queue_foreach
Use queue_find instead of visiting all queue items.
Diffstat (limited to 'monitor/keys.c')
-rw-r--r-- | monitor/keys.c | 37 |
1 files changed, 10 insertions, 27 deletions
diff --git a/monitor/keys.c b/monitor/keys.c index 4ccef22c7..e60aa9386 100644 --- a/monitor/keys.c +++ b/monitor/keys.c @@ -99,44 +99,27 @@ void keys_update_identity_addr(const uint8_t addr[6], uint8_t addr_type) } } -struct resolve_data { - bool found; - uint8_t addr[6]; - uint8_t ident[6]; - uint8_t ident_type; -}; - -static void try_resolve_irk(void *data, void *user_data) +static bool match_resolve_irk(const void *data, const void *match_data) { - struct irk_data *irk = data; - struct resolve_data *result = user_data; + const struct irk_data *irk = data; + const uint8_t *addr = match_data; uint8_t local_hash[3]; - if (result->found) - return; - - bt_crypto_ah(crypto, irk->key, result->addr + 3, local_hash); + bt_crypto_ah(crypto, irk->key, addr + 3, local_hash); - if (!memcmp(result->addr, local_hash, 3)) { - result->found = true; - memcpy(result->ident, irk->addr, 6); - result->ident_type = irk->addr_type; - } + return !memcmp(addr, local_hash, 3); } bool keys_resolve_identity(const uint8_t addr[6], uint8_t ident[6], uint8_t *ident_type) { - struct resolve_data result; - - result.found = false; - memcpy(result.addr, addr, 6); + struct irk_data *irk; - queue_foreach(irk_list, try_resolve_irk, &result); + irk = queue_find(irk_list, match_resolve_irk, addr); - if (result.found) { - memcpy(ident, result.ident, 6); - *ident_type = result.ident_type; + if (irk) { + memcpy(ident, irk->addr, 6); + *ident_type = irk->addr_type; return true; } |