From aa4b75b58ca548fea3f543c502e7e30fd5e55bbc Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 28 Sep 2021 06:09:13 +0530 Subject: [PATCH] Bluetooth: Controller: Separate address get and read functions Have separate Bluetooth Device address get and read functions, remove use of function just to return Extended Advertising Random address and replace with simple assignment statement. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/hci/hci.c | 2 +- subsys/bluetooth/controller/include/ll.h | 3 +- subsys/bluetooth/controller/ll_sw/ll_addr.c | 46 ++++++++++--------- subsys/bluetooth/controller/ll_sw/ull_adv.c | 4 +- .../bluetooth/controller/ll_sw/ull_adv_aux.c | 10 ---- .../controller/ll_sw/ull_adv_internal.h | 4 -- .../bluetooth/controller/ll_sw/ull_central.c | 2 +- subsys/bluetooth/controller/ll_sw/ull_scan.c | 4 +- subsys/bluetooth/shell/ll.c | 4 +- subsys/bluetooth/shell/ll.h | 2 +- 10 files changed, 36 insertions(+), 45 deletions(-) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 55ede5d577c..dad1632606f 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -852,7 +852,7 @@ static void read_bd_addr(struct net_buf *buf, struct net_buf **evt) rp->status = 0x00; - ll_addr_get(0, &rp->bdaddr.val[0]); + (void)ll_addr_read(0, &rp->bdaddr.val[0]); } #if defined(CONFIG_BT_CTLR_HCI_CODEC_AND_DELAY_INFO) diff --git a/subsys/bluetooth/controller/include/ll.h b/subsys/bluetooth/controller/include/ll.h index b4adebf4e87..1b74b503de1 100644 --- a/subsys/bluetooth/controller/include/ll.h +++ b/subsys/bluetooth/controller/include/ll.h @@ -15,8 +15,9 @@ void ll_reset(void); uint8_t ll_set_host_feature(uint8_t bit_number, uint8_t bit_value); uint64_t ll_feat_get(void); -uint8_t *ll_addr_get(uint8_t addr_type, uint8_t *p_bdaddr); uint8_t ll_addr_set(uint8_t addr_type, uint8_t const *const p_bdaddr); +uint8_t *ll_addr_get(uint8_t addr_type); +uint8_t *ll_addr_read(uint8_t addr_type, uint8_t *const bdaddr); #if defined(CONFIG_BT_CTLR_HCI_ADV_HANDLE_MAPPING) uint8_t ll_adv_set_by_hci_handle_get(uint8_t hci_handle, uint8_t *handle); diff --git a/subsys/bluetooth/controller/ll_sw/ll_addr.c b/subsys/bluetooth/controller/ll_sw/ll_addr.c index 9fc10982f2c..207339485e2 100644 --- a/subsys/bluetooth/controller/ll_sw/ll_addr.c +++ b/subsys/bluetooth/controller/ll_sw/ll_addr.c @@ -34,27 +34,6 @@ static uint8_t pub_addr[BDADDR_SIZE]; static uint8_t rnd_addr[BDADDR_SIZE]; -uint8_t *ll_addr_get(uint8_t addr_type, uint8_t *bdaddr) -{ - if (addr_type > 1) { - return NULL; - } - - if (addr_type) { - if (bdaddr) { - memcpy(bdaddr, rnd_addr, BDADDR_SIZE); - } - - return rnd_addr; - } - - if (bdaddr) { - memcpy(bdaddr, pub_addr, BDADDR_SIZE); - } - - return pub_addr; -} - uint8_t ll_addr_set(uint8_t addr_type, uint8_t const *const bdaddr) { if (IS_ENABLED(CONFIG_BT_BROADCASTER)) { @@ -81,6 +60,31 @@ uint8_t ll_addr_set(uint8_t addr_type, uint8_t const *const bdaddr) return 0; } +uint8_t *ll_addr_get(uint8_t addr_type) +{ + if (addr_type > BT_ADDR_LE_RANDOM) { + return NULL; + } + + if (addr_type) { + return rnd_addr; + } + + return pub_addr; +} + +uint8_t *ll_addr_read(uint8_t addr_type, uint8_t *const bdaddr) +{ + uint8_t *addr; + + addr = ll_addr_get(addr_type); + if (addr) { + memcpy(bdaddr, addr, BDADDR_SIZE); + } + + return addr; +} + void bt_ctlr_set_public_addr(const uint8_t *addr) { (void)memcpy(pub_addr, addr, sizeof(pub_addr)); diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv.c b/subsys/bluetooth/controller/ll_sw/ull_adv.c index 384c27c00ce..4ac7087d614 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv.c @@ -2709,10 +2709,10 @@ static const uint8_t *adva_update(struct ll_adv_set *adv, struct pdu_adv *pdu) if (0) { #if defined(CONFIG_BT_CTLR_ADV_EXT) } else if (ll_adv_cmds_is_ext() && pdu->tx_addr) { - own_id_addr = ull_adv_aux_random_addr_get(adv, NULL); + own_id_addr = adv->rnd_addr; #endif } else { - own_id_addr = ll_addr_get(pdu->tx_addr, NULL); + own_id_addr = ll_addr_get(pdu->tx_addr); } } diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c index 3f367bbf305..42080304509 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_aux.c @@ -441,16 +441,6 @@ int ull_adv_aux_reset_finalize(void) return 0; } -uint8_t const *ull_adv_aux_random_addr_get(struct ll_adv_set const *const adv, - uint8_t *const addr) -{ - if (addr) { - (void)memcpy(addr, adv->rnd_addr, BDADDR_SIZE); - } - - return adv->rnd_addr; -} - uint8_t ull_adv_aux_chm_update(void) { /* For each created extended advertising set */ diff --git a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h index 20cd5309e81..dbd8ed75a30 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h +++ b/subsys/bluetooth/controller/ll_sw/ull_adv_internal.h @@ -72,10 +72,6 @@ int ull_adv_aux_reset_finalize(void); /* Return the aux set handle given the aux set instance */ uint8_t ull_adv_aux_handle_get(struct ll_adv_aux_set *aux); -/* Helper to read back random address */ -uint8_t const *ull_adv_aux_random_addr_get(struct ll_adv_set const *const adv, - uint8_t *const addr); - /* Helper function to apply Channel Map Update for auxiliary PDUs */ uint8_t ull_adv_aux_chm_update(void); diff --git a/subsys/bluetooth/controller/ll_sw/ull_central.c b/subsys/bluetooth/controller/ll_sw/ull_central.c index 43ab9e81a83..89839338121 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_central.c +++ b/subsys/bluetooth/controller/ll_sw/ull_central.c @@ -98,7 +98,7 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window, const uint8_t *own_id_addr; /* Do not connect twice to the same peer */ - own_id_addr = ll_addr_get(own_id_addr_type, NULL); + own_id_addr = ll_addr_get(own_id_addr_type); if (ull_conn_peer_connected(own_id_addr_type, own_id_addr, peer_addr_type, peer_addr)) { return BT_HCI_ERR_CONN_ALREADY_EXISTS; diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan.c b/subsys/bluetooth/controller/ll_sw/ull_scan.c index c1e5b0eaeb3..d8c724f6232 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_scan.c +++ b/subsys/bluetooth/controller/ll_sw/ull_scan.c @@ -188,7 +188,7 @@ uint8_t ll_scan_enable(uint8_t enable) if ((is_coded_phy && (own_addr_type & 0x1)) || (!is_coded_phy && (scan->own_addr_type & 0x1))) { - if (!mem_nz(ll_addr_get(1, NULL), BDADDR_SIZE)) { + if (!mem_nz(ll_addr_get(BT_ADDR_LE_RANDOM), BDADDR_SIZE)) { return BT_HCI_ERR_INVALID_PARAM; } } @@ -362,7 +362,7 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan) uint32_t ret; lll->init_addr_type = scan->own_addr_type; - ll_addr_get(lll->init_addr_type, lll->init_addr); + (void)ll_addr_read(lll->init_addr_type, lll->init_addr); lll->chan = 0U; lll->is_stop = 0U; diff --git a/subsys/bluetooth/shell/ll.c b/subsys/bluetooth/shell/ll.c index b44528ccd19..4acdfb511cd 100644 --- a/subsys/bluetooth/shell/ll.c +++ b/subsys/bluetooth/shell/ll.c @@ -24,7 +24,7 @@ #include "bt.h" -int cmd_ll_addr_get(const struct shell *sh, size_t argc, char *argv[]) +int cmd_ll_addr_read(const struct shell *sh, size_t argc, char *argv[]) { uint8_t addr_type; const char *str_type; @@ -44,7 +44,7 @@ int cmd_ll_addr_get(const struct shell *sh, size_t argc, char *argv[]) return -EINVAL; } - (void)ll_addr_get(addr_type, addr.val); + (void)ll_addr_read(addr_type, addr.val); bt_addr_to_str(&addr, str_addr, sizeof(str_addr)); shell_print(sh, "Current %s address: %s", str_type, str_addr); diff --git a/subsys/bluetooth/shell/ll.h b/subsys/bluetooth/shell/ll.h index db6da4d72c0..bafc1f74485 100644 --- a/subsys/bluetooth/shell/ll.h +++ b/subsys/bluetooth/shell/ll.h @@ -13,7 +13,7 @@ #ifndef __LL_H #define __LL_H -int cmd_ll_addr_get(const struct shell *sh, size_t argc, char *argv[]); +int cmd_ll_addr_read(const struct shell *sh, size_t argc, char *argv[]); int cmd_advx(const struct shell *sh, size_t argc, char *argv[]); int cmd_scanx(const struct shell *sh, size_t argc, char *argv[]);