@@ -184,9 +184,10 @@ int bt_id_set_adv_random_addr(struct bt_le_ext_adv *adv,
184
184
return 0 ;
185
185
}
186
186
187
- static void adv_rpa_invalidate (struct bt_le_ext_adv * adv , void * data )
187
+ static void adv_disabled_rpa_invalidate (struct bt_le_ext_adv * adv , void * data )
188
188
{
189
- if (!atomic_test_bit (adv -> flags , BT_ADV_LIMITED )) {
189
+ /* Don't invalidate RPA of enabled advertising set. */
190
+ if (!atomic_test_bit (adv -> flags , BT_ADV_ENABLED )) {
190
191
atomic_clear_bit (adv -> flags , BT_ADV_RPA_VALID );
191
192
}
192
193
}
@@ -199,8 +200,13 @@ static void le_rpa_invalidate(void)
199
200
atomic_clear_bit (bt_dev .flags , BT_DEV_RPA_VALID );
200
201
}
201
202
203
+ /* Invalidate RPA of advertising sets that are disabled.
204
+ *
205
+ * Enabled advertising set have to call rpa_expired callback first to
206
+ * determine if the RPA of the advertising set should be rotated.
207
+ */
202
208
if (IS_ENABLED (CONFIG_BT_BROADCASTER )) {
203
- bt_le_ext_adv_foreach (adv_rpa_invalidate , NULL );
209
+ bt_le_ext_adv_foreach (adv_disabled_rpa_invalidate , NULL );
204
210
}
205
211
}
206
212
@@ -387,41 +393,35 @@ int bt_id_set_adv_private_addr(struct bt_le_ext_adv *adv)
387
393
#if defined(CONFIG_BT_EXT_ADV ) && defined(CONFIG_BT_PRIVACY )
388
394
static void adv_disable_rpa (struct bt_le_ext_adv * adv , void * data )
389
395
{
390
- uint8_t adv_index = bt_le_ext_adv_get_index (adv );
391
- bool * adv_disabled = data ;
392
396
bool rpa_invalid = true;
393
397
394
- adv_disabled [adv_index ] = false;
395
-
396
- /* Invalidate RPA only for non-limited advertising sets. */
397
- if (atomic_test_bit (adv -> flags , BT_ADV_LIMITED )) {
398
- return ;
399
- }
400
-
401
398
/* Disable advertising sets to prepare them for RPA update. */
402
399
if (atomic_test_bit (adv -> flags , BT_ADV_ENABLED ) &&
400
+ !atomic_test_bit (adv -> flags , BT_ADV_LIMITED ) &&
403
401
!atomic_test_bit (adv -> flags , BT_ADV_USE_IDENTITY )) {
404
402
bt_le_adv_set_enable_ext (adv , false, NULL );
405
403
406
- adv_disabled [adv_index ] = true;
407
- }
404
+ atomic_set_bit (adv -> flags , BT_ADV_RPA_UPDATE );
408
405
409
- /* Notify the user about the RPA timeout and set the RPA validity. */
410
- if (adv -> cb && adv -> cb -> rpa_expired ) {
411
- rpa_invalid = adv -> cb -> rpa_expired (adv );
412
- }
406
+ /* Notify the user about the RPA timeout and set the RPA validity. */
407
+ if (adv -> cb && adv -> cb -> rpa_expired ) {
408
+ rpa_invalid = adv -> cb -> rpa_expired (adv );
409
+ }
413
410
414
- if (rpa_invalid ) {
415
- atomic_clear_bit (adv -> flags , BT_ADV_RPA_VALID );
411
+ if (rpa_invalid ) {
412
+ atomic_clear_bit (adv -> flags , BT_ADV_RPA_VALID );
413
+ } else {
414
+ /* Submit the timeout in case no advertising set updates their RPA
415
+ * in the current period. This makes sure that the RPA timer is running.
416
+ */
417
+ le_rpa_timeout_submit ();
418
+ }
416
419
}
417
420
}
418
421
419
422
static void adv_enable_rpa (struct bt_le_ext_adv * adv , void * data )
420
423
{
421
- uint8_t adv_index = bt_le_ext_adv_get_index (adv );
422
- bool * adv_disabled = data ;
423
-
424
- if (adv_disabled [adv_index ]) {
424
+ if (atomic_test_and_clear_bit (adv -> flags , BT_ADV_RPA_UPDATE )) {
425
425
int err ;
426
426
427
427
err = bt_id_set_adv_private_addr (adv );
@@ -438,16 +438,9 @@ static void adv_enable_rpa(struct bt_le_ext_adv *adv, void *data)
438
438
static void adv_update_rpa_foreach (void )
439
439
{
440
440
#if defined(CONFIG_BT_EXT_ADV ) && defined(CONFIG_BT_PRIVACY )
441
- bool adv_disabled [CONFIG_BT_EXT_ADV_MAX_ADV_SET ];
442
-
443
- bt_le_ext_adv_foreach (adv_disable_rpa , adv_disabled );
441
+ bt_le_ext_adv_foreach (adv_disable_rpa , NULL );
444
442
445
- /* Submit the timeout in case all sets use the same
446
- * RPA for the next rotation period.
447
- */
448
- le_rpa_timeout_submit ();
449
-
450
- bt_le_ext_adv_foreach (adv_enable_rpa , adv_disabled );
443
+ bt_le_ext_adv_foreach (adv_enable_rpa , NULL );
451
444
#endif
452
445
}
453
446
@@ -462,8 +455,6 @@ static void le_update_private_addr(void)
462
455
IS_ENABLED (CONFIG_BT_EXT_ADV ) &&
463
456
BT_DEV_FEAT_LE_EXT_ADV (bt_dev .le .features )) {
464
457
adv_update_rpa_foreach ();
465
- } else {
466
- le_rpa_invalidate ();
467
458
}
468
459
469
460
#if defined(CONFIG_BT_OBSERVER )
@@ -528,6 +519,7 @@ static void le_force_rpa_timeout(void)
528
519
529
520
k_work_cancel_delayable_sync (& bt_dev .rpa_update , & sync );
530
521
#endif
522
+ le_rpa_invalidate ();
531
523
le_update_private_addr ();
532
524
}
533
525
@@ -549,6 +541,8 @@ static void rpa_timeout(struct k_work *work)
549
541
}
550
542
}
551
543
544
+ le_rpa_invalidate ();
545
+
552
546
if (IS_ENABLED (CONFIG_BT_BROADCASTER )) {
553
547
bt_le_ext_adv_foreach (adv_is_private_enabled , & adv_enabled );
554
548
}
@@ -558,7 +552,6 @@ static void rpa_timeout(struct k_work *work)
558
552
atomic_test_bit (bt_dev .flags , BT_DEV_INITIATING ) ||
559
553
(atomic_test_bit (bt_dev .flags , BT_DEV_SCANNING ) &&
560
554
atomic_test_bit (bt_dev .flags , BT_DEV_ACTIVE_SCAN )))) {
561
- le_rpa_invalidate ();
562
555
return ;
563
556
}
564
557
0 commit comments