Bluetooth: HCI: Fix updating RPA too early

Checking work pending flag does not account the delay before the work is
submitted so this make use a flag to track when the RPA is valid.

Change-Id: I2d858e5163455ce90eb6273c6a8824c5c6d44ae1
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
This commit is contained in:
Luiz Augusto von Dentz 2016-09-13 13:49:53 +03:00 committed by Johan Hedberg
parent d17a803dc9
commit eeccdaca05
2 changed files with 12 additions and 8 deletions

View file

@ -424,15 +424,17 @@ static int le_set_rpa(void)
bt_addr_t rpa;
int err;
/* work is not idle so current RPA is valid */
if (!atomic_test_bit(bt_dev.rpa_update.work.flags,
NANO_WORK_STATE_IDLE)) {
/* check if RPA is valid */
if (atomic_test_bit(bt_dev.flags, BT_DEV_RPA_VALID)) {
return 0;
}
err = bt_smp_create_rpa(bt_dev.irk, &rpa);
if (!err) {
err = set_random_address(&rpa);
if (!err) {
atomic_set_bit(bt_dev.flags, BT_DEV_RPA_VALID);
}
}
/* restart timer even if failed to set new RPA */
@ -445,6 +447,9 @@ static void rpa_timeout(struct nano_work *work)
{
BT_DBG("");
/* Invalidate RPA */
atomic_clear_bit(bt_dev.flags, BT_DEV_RPA_VALID);
/*
* we need to update rpa only if advertising is ongoing, with
* BT_DEV_KEEP_ADVERTISING flag is handled in disconnected event
@ -4240,11 +4245,8 @@ int bt_le_oob_get_local(struct bt_le_oob *oob)
#if defined(CONFIG_BLUETOOTH_PRIVACY)
int err;
/* TODO better handle submitted but not run case */
err = nano_delayed_work_cancel(&bt_dev.rpa_update);
if (err && err == -EINPROGRESS) {
return err;
}
/* Invalidate RPA so a new one is generated */
atomic_clear_bit(bt_dev.flags, BT_DEV_RPA_VALID);
err = le_set_rpa();
if (err) {

View file

@ -40,6 +40,8 @@ enum {
BT_DEV_EXPLICIT_SCAN,
BT_DEV_ACTIVE_SCAN,
BT_DEV_RPA_VALID,
#if defined(CONFIG_BLUETOOTH_BREDR)
BT_DEV_ISCAN,
BT_DEV_PSCAN,