Skip to content

Commit 8bdf363

Browse files
kapi-nofabiobaltieri
authored andcommitted
bluetooth: adv: add rpa timeout callback to extended advertising api
Added a new callback to the Bluetooth Extended Advertising callback structure. It notifies the application that the RPA validity of the advertising set has timed out. The user can use this callback to synchronize the advertising payload update with the RPA rotation. Signed-off-by: Kamil Piszczek <[email protected]>
1 parent 4e924b6 commit 8bdf363

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

include/zephyr/bluetooth/bluetooth.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,22 @@ struct bt_le_ext_adv_cb {
114114
*/
115115
void (*scanned)(struct bt_le_ext_adv *adv,
116116
struct bt_le_ext_adv_scanned_info *info);
117+
118+
#if defined(CONFIG_BT_PRIVACY)
119+
/**
120+
* @brief The RPA validity of the advertising set has expired.
121+
*
122+
* This callback notifies the application that the RPA validity of
123+
* the advertising set has expired. The user can use this callback
124+
* to synchronize the advertising payload update with the RPA rotation.
125+
*
126+
* @param adv The advertising set object.
127+
*
128+
* @return true to rotate the current RPA, or false to use it for the
129+
* next rotation period.
130+
*/
131+
bool (*rpa_expired)(struct bt_le_ext_adv *adv);
132+
#endif /* defined(CONFIG_BT_PRIVACY) */
117133
};
118134

119135
/**

subsys/bluetooth/host/id.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ static void adv_disable_rpa(struct bt_le_ext_adv *adv, void *data)
350350
{
351351
uint8_t adv_index = bt_le_ext_adv_get_index(adv);
352352
bool *adv_disabled = data;
353+
bool rpa_invalid = true;
353354

354355
adv_disabled[adv_index] = false;
355356

@@ -366,7 +367,14 @@ static void adv_disable_rpa(struct bt_le_ext_adv *adv, void *data)
366367
adv_disabled[adv_index] = true;
367368
}
368369

369-
atomic_clear_bit(adv->flags, BT_ADV_RPA_VALID);
370+
/* Notify the user about the RPA timeout and set the RPA validity. */
371+
if (adv->cb && adv->cb->rpa_expired) {
372+
rpa_invalid = adv->cb->rpa_expired(adv);
373+
}
374+
375+
if (rpa_invalid) {
376+
atomic_clear_bit(adv->flags, BT_ADV_RPA_VALID);
377+
}
370378
}
371379

372380
static void adv_enable_rpa(struct bt_le_ext_adv *adv, void *data)
@@ -394,6 +402,12 @@ static void adv_update_rpa_foreach(void)
394402
bool adv_disabled[CONFIG_BT_EXT_ADV_MAX_ADV_SET];
395403

396404
bt_le_ext_adv_foreach(adv_disable_rpa, adv_disabled);
405+
406+
/* Submit the timeout in case all sets use the same
407+
* RPA for the next rotation period.
408+
*/
409+
le_rpa_timeout_submit();
410+
397411
bt_le_ext_adv_foreach(adv_enable_rpa, adv_disabled);
398412
#endif
399413
}

0 commit comments

Comments
 (0)