32
32
#include "settings.h"
33
33
34
34
#include <zephyr/bluetooth/hci.h>
35
+ #include <zephyr/sys/util_macro.h>
35
36
#include <zephyr/toolchain.h>
36
37
37
38
#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)
1750
1751
if (err ) {
1751
1752
return err ;
1752
1753
}
1753
- }
1754
1754
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
+ }
1756
1762
}
1757
1763
1758
1764
return 0 ;
@@ -1805,8 +1811,6 @@ int bt_id_set_scan_own_addr(bool active_scan, uint8_t *own_addr_type)
1805
1811
return err ;
1806
1812
}
1807
1813
} else {
1808
- * own_addr_type = bt_dev .id_addr [0 ].type ;
1809
-
1810
1814
/* Use NRPA unless identity has been explicitly requested
1811
1815
* (through Kconfig).
1812
1816
* 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)
1824
1828
}
1825
1829
1826
1830
* 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 ;
1837
1846
}
1838
- } else {
1839
- LOG_DBG ("Not changing the address" );
1840
1847
}
1841
1848
}
1842
1849
@@ -1904,9 +1911,11 @@ int bt_id_set_adv_own_addr(struct bt_le_ext_adv *adv, uint32_t options,
1904
1911
if (err ) {
1905
1912
return err ;
1906
1913
}
1907
- }
1908
1914
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
+ }
1910
1919
1911
1920
if (dir_adv && (options & BT_LE_ADV_OPT_DIR_ADDR_RPA )) {
1912
1921
* 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,
1916
1925
if (options & BT_LE_ADV_OPT_USE_IDENTITY ) {
1917
1926
if (id_addr -> type == BT_ADDR_LE_RANDOM ) {
1918
1927
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 ;
1919
1935
}
1920
1936
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
+ }
1922
1940
} else if (!(IS_ENABLED (CONFIG_BT_EXT_ADV ) &&
1923
1941
BT_DEV_FEAT_LE_EXT_ADV (bt_dev .le .features ))) {
1924
1942
/* In case advertising set random address is not
0 commit comments