From 1e0b0948c3aa542adb925a663b0eec501bd0bf64 Mon Sep 17 00:00:00 2001 From: Szymon Janc Date: Thu, 7 Nov 2019 15:29:16 +0100 Subject: [PATCH] nimble/ll: Add api for resolving peer RPA to any IRK on list This is needed to properly report periodic sync transfers received since address in LL_SYNC_TRANSFER_IND is always RPA. --- .../include/controller/ble_ll_resolv.h | 5 ++++- nimble/controller/src/ble_ll_resolv.c | 20 ++++++++++++++++--- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/nimble/controller/include/controller/ble_ll_resolv.h b/nimble/controller/include/controller/ble_ll_resolv.h index 17228d657..f9dc3973a 100644 --- a/nimble/controller/include/controller/ble_ll_resolv.h +++ b/nimble/controller/include/controller/ble_ll_resolv.h @@ -98,7 +98,10 @@ int ble_ll_resolve_set_priv_mode(const uint8_t *cmdbuf, uint8_t len); uint32_t ble_ll_resolv_get_rpa_tmo(void); /* Resolve a resolvable private address */ -int ble_ll_resolv_rpa(uint8_t *rpa, uint8_t *irk); +int ble_ll_resolv_rpa(const uint8_t *rpa, const uint8_t *irk); + +/* Try to resolve peer RPA and return index on RL if matched */ +int ble_ll_resolv_peer_rpa_any(const uint8_t *rpa); /* Initialize resolv*/ void ble_ll_resolv_init(void); diff --git a/nimble/controller/src/ble_ll_resolv.c b/nimble/controller/src/ble_ll_resolv.c index abf398636..c35cc3393 100644 --- a/nimble/controller/src/ble_ll_resolv.c +++ b/nimble/controller/src/ble_ll_resolv.c @@ -641,15 +641,15 @@ ble_ll_resolv_gen_rpa(uint8_t *addr, uint8_t addr_type, uint8_t *rpa, int local) * @return int */ int -ble_ll_resolv_rpa(uint8_t *rpa, uint8_t *irk) +ble_ll_resolv_rpa(const uint8_t *rpa, const uint8_t *irk) { int rc; - uint32_t *irk32; + const uint32_t *irk32; uint32_t *key32; uint32_t *pt32; struct ble_encryption_block ecb; - irk32 = (uint32_t *)irk; + irk32 = (const uint32_t *)irk; key32 = (uint32_t *)&ecb.key[0]; key32[0] = irk32[0]; @@ -678,6 +678,20 @@ ble_ll_resolv_rpa(uint8_t *rpa, uint8_t *irk) return rc; } +int +ble_ll_resolv_peer_rpa_any(const uint8_t *rpa) +{ + int i; + + for (i = 0; i < g_ble_ll_resolv_data.rl_cnt_hw; i++) { + if (ble_ll_resolv_rpa(rpa, g_ble_ll_resolv_list[i].rl_peer_irk)) { + return i; + } + } + + return -1; +} + /** * Returns whether or not address resolution is enabled. *