Skip to content

Commit aa4b75b

Browse files
cvinayakcfriedt
authored andcommitted
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 <[email protected]>
1 parent d7cfb54 commit aa4b75b

File tree

10 files changed

+36
-45
lines changed

10 files changed

+36
-45
lines changed

subsys/bluetooth/controller/hci/hci.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -852,7 +852,7 @@ static void read_bd_addr(struct net_buf *buf, struct net_buf **evt)
852852

853853
rp->status = 0x00;
854854

855-
ll_addr_get(0, &rp->bdaddr.val[0]);
855+
(void)ll_addr_read(0, &rp->bdaddr.val[0]);
856856
}
857857

858858
#if defined(CONFIG_BT_CTLR_HCI_CODEC_AND_DELAY_INFO)

subsys/bluetooth/controller/include/ll.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,9 @@ void ll_reset(void);
1515
uint8_t ll_set_host_feature(uint8_t bit_number, uint8_t bit_value);
1616
uint64_t ll_feat_get(void);
1717

18-
uint8_t *ll_addr_get(uint8_t addr_type, uint8_t *p_bdaddr);
1918
uint8_t ll_addr_set(uint8_t addr_type, uint8_t const *const p_bdaddr);
19+
uint8_t *ll_addr_get(uint8_t addr_type);
20+
uint8_t *ll_addr_read(uint8_t addr_type, uint8_t *const bdaddr);
2021

2122
#if defined(CONFIG_BT_CTLR_HCI_ADV_HANDLE_MAPPING)
2223
uint8_t ll_adv_set_by_hci_handle_get(uint8_t hci_handle, uint8_t *handle);

subsys/bluetooth/controller/ll_sw/ll_addr.c

Lines changed: 25 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -34,27 +34,6 @@
3434
static uint8_t pub_addr[BDADDR_SIZE];
3535
static uint8_t rnd_addr[BDADDR_SIZE];
3636

37-
uint8_t *ll_addr_get(uint8_t addr_type, uint8_t *bdaddr)
38-
{
39-
if (addr_type > 1) {
40-
return NULL;
41-
}
42-
43-
if (addr_type) {
44-
if (bdaddr) {
45-
memcpy(bdaddr, rnd_addr, BDADDR_SIZE);
46-
}
47-
48-
return rnd_addr;
49-
}
50-
51-
if (bdaddr) {
52-
memcpy(bdaddr, pub_addr, BDADDR_SIZE);
53-
}
54-
55-
return pub_addr;
56-
}
57-
5837
uint8_t ll_addr_set(uint8_t addr_type, uint8_t const *const bdaddr)
5938
{
6039
if (IS_ENABLED(CONFIG_BT_BROADCASTER)) {
@@ -81,6 +60,31 @@ uint8_t ll_addr_set(uint8_t addr_type, uint8_t const *const bdaddr)
8160
return 0;
8261
}
8362

63+
uint8_t *ll_addr_get(uint8_t addr_type)
64+
{
65+
if (addr_type > BT_ADDR_LE_RANDOM) {
66+
return NULL;
67+
}
68+
69+
if (addr_type) {
70+
return rnd_addr;
71+
}
72+
73+
return pub_addr;
74+
}
75+
76+
uint8_t *ll_addr_read(uint8_t addr_type, uint8_t *const bdaddr)
77+
{
78+
uint8_t *addr;
79+
80+
addr = ll_addr_get(addr_type);
81+
if (addr) {
82+
memcpy(bdaddr, addr, BDADDR_SIZE);
83+
}
84+
85+
return addr;
86+
}
87+
8488
void bt_ctlr_set_public_addr(const uint8_t *addr)
8589
{
8690
(void)memcpy(pub_addr, addr, sizeof(pub_addr));

subsys/bluetooth/controller/ll_sw/ull_adv.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,10 +2709,10 @@ static const uint8_t *adva_update(struct ll_adv_set *adv, struct pdu_adv *pdu)
27092709
if (0) {
27102710
#if defined(CONFIG_BT_CTLR_ADV_EXT)
27112711
} else if (ll_adv_cmds_is_ext() && pdu->tx_addr) {
2712-
own_id_addr = ull_adv_aux_random_addr_get(adv, NULL);
2712+
own_id_addr = adv->rnd_addr;
27132713
#endif
27142714
} else {
2715-
own_id_addr = ll_addr_get(pdu->tx_addr, NULL);
2715+
own_id_addr = ll_addr_get(pdu->tx_addr);
27162716
}
27172717
}
27182718

subsys/bluetooth/controller/ll_sw/ull_adv_aux.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -441,16 +441,6 @@ int ull_adv_aux_reset_finalize(void)
441441
return 0;
442442
}
443443

444-
uint8_t const *ull_adv_aux_random_addr_get(struct ll_adv_set const *const adv,
445-
uint8_t *const addr)
446-
{
447-
if (addr) {
448-
(void)memcpy(addr, adv->rnd_addr, BDADDR_SIZE);
449-
}
450-
451-
return adv->rnd_addr;
452-
}
453-
454444
uint8_t ull_adv_aux_chm_update(void)
455445
{
456446
/* For each created extended advertising set */

subsys/bluetooth/controller/ll_sw/ull_adv_internal.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,6 @@ int ull_adv_aux_reset_finalize(void);
7272
/* Return the aux set handle given the aux set instance */
7373
uint8_t ull_adv_aux_handle_get(struct ll_adv_aux_set *aux);
7474

75-
/* Helper to read back random address */
76-
uint8_t const *ull_adv_aux_random_addr_get(struct ll_adv_set const *const adv,
77-
uint8_t *const addr);
78-
7975
/* Helper function to apply Channel Map Update for auxiliary PDUs */
8076
uint8_t ull_adv_aux_chm_update(void);
8177

subsys/bluetooth/controller/ll_sw/ull_central.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ uint8_t ll_create_connection(uint16_t scan_interval, uint16_t scan_window,
9898
const uint8_t *own_id_addr;
9999

100100
/* Do not connect twice to the same peer */
101-
own_id_addr = ll_addr_get(own_id_addr_type, NULL);
101+
own_id_addr = ll_addr_get(own_id_addr_type);
102102
if (ull_conn_peer_connected(own_id_addr_type, own_id_addr,
103103
peer_addr_type, peer_addr)) {
104104
return BT_HCI_ERR_CONN_ALREADY_EXISTS;

subsys/bluetooth/controller/ll_sw/ull_scan.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ uint8_t ll_scan_enable(uint8_t enable)
188188

189189
if ((is_coded_phy && (own_addr_type & 0x1)) ||
190190
(!is_coded_phy && (scan->own_addr_type & 0x1))) {
191-
if (!mem_nz(ll_addr_get(1, NULL), BDADDR_SIZE)) {
191+
if (!mem_nz(ll_addr_get(BT_ADDR_LE_RANDOM), BDADDR_SIZE)) {
192192
return BT_HCI_ERR_INVALID_PARAM;
193193
}
194194
}
@@ -362,7 +362,7 @@ uint8_t ull_scan_enable(struct ll_scan_set *scan)
362362
uint32_t ret;
363363

364364
lll->init_addr_type = scan->own_addr_type;
365-
ll_addr_get(lll->init_addr_type, lll->init_addr);
365+
(void)ll_addr_read(lll->init_addr_type, lll->init_addr);
366366
lll->chan = 0U;
367367
lll->is_stop = 0U;
368368

subsys/bluetooth/shell/ll.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
#include "bt.h"
2626

27-
int cmd_ll_addr_get(const struct shell *sh, size_t argc, char *argv[])
27+
int cmd_ll_addr_read(const struct shell *sh, size_t argc, char *argv[])
2828
{
2929
uint8_t addr_type;
3030
const char *str_type;
@@ -44,7 +44,7 @@ int cmd_ll_addr_get(const struct shell *sh, size_t argc, char *argv[])
4444
return -EINVAL;
4545
}
4646

47-
(void)ll_addr_get(addr_type, addr.val);
47+
(void)ll_addr_read(addr_type, addr.val);
4848
bt_addr_to_str(&addr, str_addr, sizeof(str_addr));
4949

5050
shell_print(sh, "Current %s address: %s", str_type, str_addr);

subsys/bluetooth/shell/ll.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#ifndef __LL_H
1414
#define __LL_H
1515

16-
int cmd_ll_addr_get(const struct shell *sh, size_t argc, char *argv[]);
16+
int cmd_ll_addr_read(const struct shell *sh, size_t argc, char *argv[]);
1717

1818
int cmd_advx(const struct shell *sh, size_t argc, char *argv[]);
1919
int cmd_scanx(const struct shell *sh, size_t argc, char *argv[]);

0 commit comments

Comments
 (0)