Skip to content

Commit 25c993e

Browse files
Thalleycarlescufi
authored andcommitted
Bluetooth: Host: Remove implicit conversions of own_addr_type
Remove implicit conversions and assignment to the own_addr_type variables. Signed-off-by: Emil Gydesen <[email protected]>
1 parent da2e8c3 commit 25c993e

File tree

1 file changed

+37
-19
lines changed
  • subsys/bluetooth/host

1 file changed

+37
-19
lines changed

subsys/bluetooth/host/id.c

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "settings.h"
3333

3434
#include <zephyr/bluetooth/hci.h>
35+
#include <zephyr/sys/util_macro.h>
3536
#include <zephyr/toolchain.h>
3637

3738
#include "common/bt_str.h"
@@ -1750,9 +1751,14 @@ int bt_id_set_create_conn_own_addr(bool use_filter, uint8_t *own_addr_type)
17501751
if (err) {
17511752
return err;
17521753
}
1753-
}
17541754

1755-
*own_addr_type = addr->type;
1755+
*own_addr_type = BT_HCI_OWN_ADDR_RANDOM;
1756+
} else {
1757+
/* If address type is not random, it's public. If it's public then we assume
1758+
* it's the Controller's public address.
1759+
*/
1760+
*own_addr_type = BT_HCI_OWN_ADDR_PUBLIC;
1761+
}
17561762
}
17571763

17581764
return 0;
@@ -1805,8 +1811,6 @@ int bt_id_set_scan_own_addr(bool active_scan, uint8_t *own_addr_type)
18051811
return err;
18061812
}
18071813
} else {
1808-
*own_addr_type = bt_dev.id_addr[0].type;
1809-
18101814
/* Use NRPA unless identity has been explicitly requested
18111815
* (through Kconfig).
18121816
* Use same RPA as legacy advertiser if advertising.
@@ -1824,19 +1828,22 @@ int bt_id_set_scan_own_addr(bool active_scan, uint8_t *own_addr_type)
18241828
}
18251829

18261830
*own_addr_type = BT_HCI_OWN_ADDR_RANDOM;
1827-
} else if (IS_ENABLED(CONFIG_BT_SCAN_WITH_IDENTITY) &&
1828-
*own_addr_type == BT_HCI_OWN_ADDR_RANDOM) {
1829-
/* If scanning with Identity Address we must set the
1830-
* random identity address for both active and passive
1831-
* scanner in order to receive adv reports that are
1832-
* directed towards this identity.
1833-
*/
1834-
err = set_random_address(&bt_dev.id_addr[0].a);
1835-
if (err) {
1836-
return err;
1831+
} else if (IS_ENABLED(CONFIG_BT_SCAN_WITH_IDENTITY)) {
1832+
if (bt_dev.id_addr[BT_ID_DEFAULT].type == BT_ADDR_LE_RANDOM) {
1833+
/* If scanning with Identity Address we must set the
1834+
* random identity address for both active and passive
1835+
* scanner in order to receive adv reports that are
1836+
* directed towards this identity.
1837+
*/
1838+
err = set_random_address(&bt_dev.id_addr[BT_ID_DEFAULT].a);
1839+
if (err) {
1840+
return err;
1841+
}
1842+
1843+
*own_addr_type = BT_HCI_OWN_ADDR_RANDOM;
1844+
} else if (bt_dev.id_addr[BT_ID_DEFAULT].type == BT_ADDR_LE_PUBLIC) {
1845+
*own_addr_type = BT_HCI_OWN_ADDR_PUBLIC;
18371846
}
1838-
} else {
1839-
LOG_DBG("Not changing the address");
18401847
}
18411848
}
18421849

@@ -1904,9 +1911,11 @@ int bt_id_set_adv_own_addr(struct bt_le_ext_adv *adv, uint32_t options,
19041911
if (err) {
19051912
return err;
19061913
}
1907-
}
19081914

1909-
*own_addr_type = id_addr->type;
1915+
*own_addr_type = BT_HCI_OWN_ADDR_RANDOM;
1916+
} else if (id_addr->type == BT_ADDR_LE_PUBLIC) {
1917+
*own_addr_type = BT_HCI_OWN_ADDR_PUBLIC;
1918+
}
19101919

19111920
if (dir_adv && (options & BT_LE_ADV_OPT_DIR_ADDR_RPA)) {
19121921
*own_addr_type |= BT_HCI_OWN_ADDR_RPA_MASK;
@@ -1916,9 +1925,18 @@ int bt_id_set_adv_own_addr(struct bt_le_ext_adv *adv, uint32_t options,
19161925
if (options & BT_LE_ADV_OPT_USE_IDENTITY) {
19171926
if (id_addr->type == BT_ADDR_LE_RANDOM) {
19181927
err = bt_id_set_adv_random_addr(adv, &id_addr->a);
1928+
if (err) {
1929+
return err;
1930+
}
1931+
1932+
*own_addr_type = BT_HCI_OWN_ADDR_RANDOM;
1933+
} else if (id_addr->type == BT_ADDR_LE_PUBLIC) {
1934+
*own_addr_type = BT_HCI_OWN_ADDR_PUBLIC;
19191935
}
19201936

1921-
*own_addr_type = id_addr->type;
1937+
if (options & BT_LE_ADV_OPT_DIR_ADDR_RPA) {
1938+
*own_addr_type |= BT_HCI_OWN_ADDR_RPA_MASK;
1939+
}
19221940
} else if (!(IS_ENABLED(CONFIG_BT_EXT_ADV) &&
19231941
BT_DEV_FEAT_LE_EXT_ADV(bt_dev.le.features))) {
19241942
/* In case advertising set random address is not

0 commit comments

Comments
 (0)