@@ -71,7 +71,6 @@ static void adv_id_check_func(struct bt_le_ext_adv *adv, void *data)
71
71
}
72
72
}
73
73
74
- #if defined(CONFIG_BT_PRIVACY )
75
74
static void adv_is_private_enabled (struct bt_le_ext_adv * adv , void * data )
76
75
{
77
76
bool * adv_enabled = data ;
@@ -81,7 +80,6 @@ static void adv_is_private_enabled(struct bt_le_ext_adv *adv, void *data)
81
80
* adv_enabled = true;
82
81
}
83
82
}
84
- #endif /* defined(CONFIG_BT_PRIVACY) */
85
83
86
84
#if defined(CONFIG_BT_SMP )
87
85
static void adv_is_limited_enabled (struct bt_le_ext_adv * adv , void * data )
@@ -184,14 +182,33 @@ int bt_id_set_adv_random_addr(struct bt_le_ext_adv *adv,
184
182
return 0 ;
185
183
}
186
184
187
- static void adv_disabled_rpa_invalidate (struct bt_le_ext_adv * adv , void * data )
185
+ static void adv_rpa_expired (struct bt_le_ext_adv * adv )
188
186
{
189
- /* Don't invalidate RPA of enabled advertising set. */
190
- if (!atomic_test_bit (adv -> flags , BT_ADV_ENABLED )) {
187
+ bool rpa_invalid = true;
188
+
189
+ #if defined(CONFIG_BT_EXT_ADV ) && defined(CONFIG_BT_PRIVACY )
190
+ /* Notify the user about the RPA timeout and set the RPA validity. */
191
+ if (atomic_test_bit (adv -> flags , BT_ADV_RPA_VALID ) &&
192
+ adv -> cb && adv -> cb -> rpa_expired ) {
193
+ rpa_invalid = adv -> cb -> rpa_expired (adv );
194
+ }
195
+ #endif
196
+ if (rpa_invalid ) {
191
197
atomic_clear_bit (adv -> flags , BT_ADV_RPA_VALID );
192
198
}
193
199
}
194
200
201
+ static void adv_rpa_invalidate (struct bt_le_ext_adv * adv , void * data )
202
+ {
203
+ /* RPA of Advertisers limited by timeot or number of packets only expire
204
+ * when they are stopped.
205
+ */
206
+ if (!atomic_test_bit (adv -> flags , BT_ADV_LIMITED ) &&
207
+ !atomic_test_bit (adv -> flags , BT_ADV_USE_IDENTITY )) {
208
+ adv_rpa_expired (adv );
209
+ }
210
+ }
211
+
195
212
static void le_rpa_invalidate (void )
196
213
{
197
214
/* Invalidate RPA */
@@ -200,13 +217,8 @@ static void le_rpa_invalidate(void)
200
217
atomic_clear_bit (bt_dev .flags , BT_DEV_RPA_VALID );
201
218
}
202
219
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
- */
208
220
if (IS_ENABLED (CONFIG_BT_BROADCASTER )) {
209
- bt_le_ext_adv_foreach (adv_disabled_rpa_invalidate , NULL );
221
+ bt_le_ext_adv_foreach (adv_rpa_invalidate , NULL );
210
222
}
211
223
}
212
224
@@ -298,6 +310,13 @@ int bt_id_set_adv_private_addr(struct bt_le_ext_adv *adv)
298
310
299
311
/* check if RPA is valid */
300
312
if (atomic_test_bit (adv -> flags , BT_ADV_RPA_VALID )) {
313
+ /* Schedule the RPA timer if it is not running.
314
+ * The RPA may be valid without the timer running.
315
+ */
316
+ if (!atomic_test_bit (adv -> flags , BT_ADV_LIMITED )) {
317
+ le_rpa_timeout_submit ();
318
+ }
319
+
301
320
return 0 ;
302
321
}
303
322
@@ -390,10 +409,9 @@ int bt_id_set_adv_private_addr(struct bt_le_ext_adv *adv)
390
409
}
391
410
#endif /* defined(CONFIG_BT_PRIVACY) */
392
411
393
- #if defined(CONFIG_BT_EXT_ADV ) && defined(CONFIG_BT_PRIVACY )
394
- static void adv_disable_rpa (struct bt_le_ext_adv * adv , void * data )
412
+ static void adv_pause_rpa (struct bt_le_ext_adv * adv , void * data )
395
413
{
396
- bool rpa_invalid = true ;
414
+ bool * adv_enabled = data ;
397
415
398
416
/* Disable advertising sets to prepare them for RPA update. */
399
417
if (atomic_test_bit (adv -> flags , BT_ADV_ENABLED ) &&
@@ -402,21 +420,26 @@ static void adv_disable_rpa(struct bt_le_ext_adv *adv, void *data)
402
420
bt_le_adv_set_enable_ext (adv , false, NULL );
403
421
404
422
atomic_set_bit (adv -> flags , BT_ADV_RPA_UPDATE );
423
+ * adv_enabled = true;
424
+ }
425
+ }
405
426
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
- }
427
+ static bool le_adv_rpa_timeout (void )
428
+ {
429
+ bool adv_enabled = false;
410
430
411
- if (rpa_invalid ) {
412
- atomic_clear_bit (adv -> flags , BT_ADV_RPA_VALID );
431
+ if (IS_ENABLED (CONFIG_BT_BROADCASTER )) {
432
+ if (IS_ENABLED (CONFIG_BT_EXT_ADV ) &&
433
+ BT_DEV_FEAT_LE_EXT_ADV (bt_dev .le .features )) {
434
+ /* Pause all advertising sets using RPAs */
435
+ bt_le_ext_adv_foreach (adv_pause_rpa , & adv_enabled );
413
436
} 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 ();
437
+ /* Check if advertising set is enabled */
438
+ bt_le_ext_adv_foreach (adv_is_private_enabled , & adv_enabled );
418
439
}
419
440
}
441
+
442
+ return adv_enabled ;
420
443
}
421
444
422
445
static void adv_enable_rpa (struct bt_le_ext_adv * adv , void * data )
@@ -433,16 +456,6 @@ static void adv_enable_rpa(struct bt_le_ext_adv *adv, void *data)
433
456
bt_le_adv_set_enable_ext (adv , true, NULL );
434
457
}
435
458
}
436
- #endif /* defined(CONFIG_BT_EXT_ADV) && defined(CONFIG_BT_PRIVACY) */
437
-
438
- static void adv_update_rpa_foreach (void )
439
- {
440
- #if defined(CONFIG_BT_EXT_ADV ) && defined(CONFIG_BT_PRIVACY )
441
- bt_le_ext_adv_foreach (adv_disable_rpa , NULL );
442
-
443
- bt_le_ext_adv_foreach (adv_enable_rpa , NULL );
444
- #endif
445
- }
446
459
447
460
static void le_update_private_addr (void )
448
461
{
@@ -451,12 +464,6 @@ static void le_update_private_addr(void)
451
464
uint8_t id = BT_ID_DEFAULT ;
452
465
int err ;
453
466
454
- if (IS_ENABLED (CONFIG_BT_BROADCASTER ) &&
455
- IS_ENABLED (CONFIG_BT_EXT_ADV ) &&
456
- BT_DEV_FEAT_LE_EXT_ADV (bt_dev .le .features )) {
457
- adv_update_rpa_foreach ();
458
- }
459
-
460
467
#if defined(CONFIG_BT_OBSERVER )
461
468
bool scan_enabled = false;
462
469
@@ -500,6 +507,12 @@ static void le_update_private_addr(void)
500
507
return ;
501
508
}
502
509
510
+ if (IS_ENABLED (CONFIG_BT_BROADCASTER ) &&
511
+ IS_ENABLED (CONFIG_BT_EXT_ADV ) &&
512
+ BT_DEV_FEAT_LE_EXT_ADV (bt_dev .le .features )) {
513
+ bt_le_ext_adv_foreach (adv_enable_rpa , NULL );
514
+ }
515
+
503
516
if (IS_ENABLED (CONFIG_BT_BROADCASTER ) &&
504
517
adv && adv_enabled ) {
505
518
bt_le_adv_set_enable_legacy (adv , true);
@@ -519,14 +532,15 @@ static void le_force_rpa_timeout(void)
519
532
520
533
k_work_cancel_delayable_sync (& bt_dev .rpa_update , & sync );
521
534
#endif
535
+ (void )le_adv_rpa_timeout ();
522
536
le_rpa_invalidate ();
523
537
le_update_private_addr ();
524
538
}
525
539
526
540
#if defined(CONFIG_BT_PRIVACY )
527
541
static void rpa_timeout (struct k_work * work )
528
542
{
529
- bool adv_enabled = false ;
543
+ bool adv_enabled ;
530
544
531
545
BT_DBG ("" );
532
546
@@ -541,12 +555,9 @@ static void rpa_timeout(struct k_work *work)
541
555
}
542
556
}
543
557
558
+ adv_enabled = le_adv_rpa_timeout ();
544
559
le_rpa_invalidate ();
545
560
546
- if (IS_ENABLED (CONFIG_BT_BROADCASTER )) {
547
- bt_le_ext_adv_foreach (adv_is_private_enabled , & adv_enabled );
548
- }
549
-
550
561
/* IF no roles using the RPA is running we can stop the RPA timer */
551
562
if (!(adv_enabled ||
552
563
atomic_test_bit (bt_dev .flags , BT_DEV_INITIATING ) ||
@@ -669,6 +680,11 @@ bool bt_id_adv_random_addr_check(const struct bt_le_adv_param *param)
669
680
return true;
670
681
}
671
682
683
+ void bt_id_adv_limited_stopped (struct bt_le_ext_adv * adv )
684
+ {
685
+ adv_rpa_expired (adv );
686
+ }
687
+
672
688
#if defined(CONFIG_BT_SMP )
673
689
static int le_set_privacy_mode (const bt_addr_le_t * addr , uint8_t mode )
674
690
{
0 commit comments