Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bluetooth: id: fix adv sets with same id use different RPA #68885

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 37 additions & 13 deletions subsys/bluetooth/host/id.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,24 +198,29 @@ int bt_id_set_adv_random_addr(struct bt_le_ext_adv *adv,
return 0;
}

static void adv_rpa_expired(struct bt_le_ext_adv *adv)
static void adv_rpa_expired(struct bt_le_ext_adv *adv, void *data))
{
bool rpa_invalid = true;

#if defined(CONFIG_BT_EXT_ADV) && defined(CONFIG_BT_PRIVACY)
/* Notify the user about the RPA timeout and set the RPA validity. */
if (atomic_test_bit(adv->flags, BT_ADV_RPA_VALID) &&
adv->cb && adv->cb->rpa_expired) {
rpa_invalid = adv->cb->rpa_expired(adv);
}
#endif
if (rpa_invalid) {
atomic_clear_bit(adv->flags, BT_ADV_RPA_VALID);

#if defined(CONFIG_BT_RPA_SHARING)
bt_addr_copy(&bt_dev.rpa[adv->id], BT_ADDR_NONE);
#endif
}
if (IS_ENABLED(CONFIG_BT_RPA_SHARING)) {
bool *rpa_invalid_ptr = data;

if (!rpa_invalid) {
*rpa_invalid_ptr = false;
}
}
else {
if (rpa_invalid) {
atomic_clear_bit(adv->flags, BT_ADV_RPA_VALID);
}
}
}

static void adv_rpa_invalidate(struct bt_le_ext_adv *adv, void *data)
Expand All @@ -225,10 +230,18 @@ static void adv_rpa_invalidate(struct bt_le_ext_adv *adv, void *data)
*/
if (!atomic_test_bit(adv->flags, BT_ADV_LIMITED) &&
!atomic_test_bit(adv->flags, BT_ADV_USE_IDENTITY)) {
adv_rpa_expired(adv);
adv_rpa_expired(adv, data);
}
}

#if defined(CONFIG_BT_RPA_SHARING)
static void adv_rpa_clear_data(struct bt_le_ext_adv *adv, void *data)
{
atomic_clear_bit(adv->flags, BT_ADV_RPA_VALID);
bt_addr_copy(&bt_dev.rpa[adv->id], BT_ADDR_NONE);
}
#endif

static void le_rpa_invalidate(void)
{
/* Invalidate RPA */
Expand All @@ -237,9 +250,20 @@ static void le_rpa_invalidate(void)
atomic_clear_bit(bt_dev.flags, BT_DEV_RPA_VALID);
}

if (IS_ENABLED(CONFIG_BT_BROADCASTER)) {
bt_le_ext_adv_foreach(adv_rpa_invalidate, NULL);
}
if (IS_ENABLED(CONFIG_BT_BROADCASTER)) {
bool is_rpa_expired_for_adv_sets = true;

bt_le_ext_adv_foreach(adv_rpa_invalidate, &is_rpa_expired_for_adv_sets);
if (IS_ENABLED(CONFIG_BT_RPA_SHARING)) {
/* If rpa is expired for all adv sets, then clear the data. */
if (is_rpa_expired_for_adv_sets) {
bt_le_ext_adv_foreach(adv_rpa_clear_data, NULL);
}
else {
LOG_WRN("Either one of the adv set's rpa expired cb not regd or returns false!");
}
}
}
}

#if defined(CONFIG_BT_PRIVACY)
Expand Down Expand Up @@ -769,7 +793,7 @@ bool bt_id_adv_random_addr_check(const struct bt_le_adv_param *param)

void bt_id_adv_limited_stopped(struct bt_le_ext_adv *adv)
{
adv_rpa_expired(adv);
adv_rpa_expired(adv, NULL);
}

#if defined(CONFIG_BT_SMP)
Expand Down
Loading