This is an automated email from the ASF dual-hosted git repository. andk pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-nimble.git
commit 6f514eefd398aa5cd3cd6d415ea7f3940c16aa14 Author: Andrzej Kaczmarek <[email protected]> AuthorDate: Thu Jan 2 09:29:39 2020 +0100 nimble/ll: Add API to retrieve address subtype This adds convenience function to retrieve address (sub)type, that means whether address is an indentity (public/static random), RPA or NRPA. This allows to use single call instead of using multiple helpers in a row to determine address (sub)type using pretty much the same check. --- nimble/controller/include/controller/ble_ll.h | 6 ++++++ nimble/controller/src/ble_ll.c | 17 +++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/nimble/controller/include/controller/ble_ll.h b/nimble/controller/include/controller/ble_ll.h index b748e10..9d8c801 100644 --- a/nimble/controller/include/controller/ble_ll.h +++ b/nimble/controller/include/controller/ble_ll.h @@ -401,6 +401,10 @@ struct ble_dev_addr #define BLE_SCAN_RSP_MAX_LEN (37) #define BLE_SCAN_RSP_MAX_EXT_LEN (251) +#define BLE_LL_ADDR_SUBTYPE_IDENTITY (0) +#define BLE_LL_ADDR_SUBTYPE_RPA (1) +#define BLE_LL_ADDR_SUBTYPE_NRPA (2) + /*--- External API ---*/ /* Initialize the Link Layer */ void ble_ll_init(void); @@ -431,6 +435,8 @@ uint16_t ble_ll_pdu_max_tx_octets_get(uint32_t usecs, int phy_mode); /* Is this address a resolvable private address? */ int ble_ll_is_rpa(const uint8_t *addr, uint8_t addr_type); +int ble_ll_addr_subtype(const uint8_t *addr, uint8_t addr_type); + /* Is this address an identity address? */ int ble_ll_addr_is_id(uint8_t *addr, uint8_t addr_type); diff --git a/nimble/controller/src/ble_ll.c b/nimble/controller/src/ble_ll.c index fb430ea..9b3fd22 100644 --- a/nimble/controller/src/ble_ll.c +++ b/nimble/controller/src/ble_ll.c @@ -444,6 +444,23 @@ ble_ll_addr_is_id(uint8_t *addr, uint8_t addr_type) } int +ble_ll_addr_subtype(const uint8_t *addr, uint8_t addr_type) +{ + if (!addr_type) { + return BLE_LL_ADDR_SUBTYPE_IDENTITY; + } + + switch (addr[5] >> 6) { + case 0: + return BLE_LL_ADDR_SUBTYPE_NRPA; /* NRPA */ + case 1: + return BLE_LL_ADDR_SUBTYPE_RPA; /* RPA */ + default: + return BLE_LL_ADDR_SUBTYPE_IDENTITY; /* static random */ + } +} + +int ble_ll_is_valid_public_addr(const uint8_t *addr) { int i;
