@@ -4083,6 +4083,21 @@ static void hci_cmd_status(struct net_buf *buf)
40834083}
40844084
40854085#if defined(CONFIG_BT_OBSERVER )
4086+ static bool is_adv_using_rand_addr (void )
4087+ {
4088+ struct bt_le_ext_adv * adv = bt_adv_lookup_legacy ();
4089+
4090+ if (IS_ENABLED (CONFIG_BT_EXT_ADV ) &&
4091+ BT_FEAT_LE_EXT_ADV (bt_dev .le .features )) {
4092+ /* When advertising using extended advertising HCI commands
4093+ * then the advertiser has it's own random address command.
4094+ */
4095+ return false;
4096+ }
4097+
4098+ return adv && atomic_test_bit (adv -> flags , BT_ADV_ENABLED );
4099+ }
4100+
40864101static int le_scan_set_random_addr (bool active_scan , uint8_t * own_addr_type )
40874102{
40884103 int err ;
@@ -4099,18 +4114,14 @@ static int le_scan_set_random_addr(bool active_scan, uint8_t *own_addr_type)
40994114 * own_addr_type = BT_ADDR_LE_RANDOM ;
41004115 }
41014116 } else {
4102- struct bt_le_ext_adv * adv = bt_adv_lookup_legacy ();
4103-
41044117 * own_addr_type = bt_dev .id_addr [0 ].type ;
41054118
41064119 /* Use NRPA unless identity has been explicitly requested
41074120 * (through Kconfig).
41084121 * Use same RPA as legacy advertiser if advertising.
41094122 */
41104123 if (!IS_ENABLED (CONFIG_BT_SCAN_WITH_IDENTITY ) &&
4111- !(IS_ENABLED (CONFIG_BT_EXT_ADV ) &&
4112- BT_FEAT_LE_EXT_ADV (bt_dev .le .features )) &&
4113- adv && !atomic_test_bit (adv -> flags , BT_ADV_ENABLED )) {
4124+ !is_adv_using_rand_addr ()) {
41144125 err = le_set_private_addr (BT_ID_DEFAULT );
41154126 if (err ) {
41164127 return err ;
0 commit comments