Bluetooth: Host: Fix PA sync cancel scan update

When the application cancels the PA sync, it would update
the scan before clearing the BT_PER_ADV_SYNC_SYNCING flag
which cause the scan to always start again.

Signed-off-by: Emil Gydesen <emil.gydesen@nordicsemi.no>
This commit is contained in:
Emil Gydesen 2020-09-21 20:44:21 +02:00 committed by Johan Hedberg
commit b78245db60

View file

@ -4647,10 +4647,43 @@ static void le_per_adv_sync_established(struct net_buf *buf)
struct bt_le_per_adv_sync *pending_per_adv_sync;
int err;
err = bt_le_scan_update(false);
pending_per_adv_sync = get_pending_per_adv_sync();
if (err) {
BT_ERR("Could not stop scan (%d)", err);
if (pending_per_adv_sync) {
atomic_clear_bit(pending_per_adv_sync->flags,
BT_PER_ADV_SYNC_SYNCING);
err = bt_le_scan_update(false);
if (err) {
BT_ERR("Could not update scan (%d)", err);
}
}
if (!pending_per_adv_sync ||
pending_per_adv_sync->sid != evt->sid ||
bt_addr_le_cmp(&pending_per_adv_sync->addr, &evt->adv_addr)) {
struct bt_le_per_adv_sync_term_info term_info;
BT_ERR("Unexpected per adv sync established event");
per_adv_sync_terminate(sys_le16_to_cpu(evt->handle));
if (pending_per_adv_sync) {
/* Terminate the pending PA sync and notify app */
term_info.addr = &pending_per_adv_sync->addr;
term_info.sid = pending_per_adv_sync->sid;
/* Deleting before callback, so the caller will be able
* to restart sync in the callback.
*/
per_adv_sync_delete(pending_per_adv_sync);
if (pending_per_adv_sync->cb &&
pending_per_adv_sync->cb->term) {
pending_per_adv_sync->cb->term(
pending_per_adv_sync, &term_info);
}
}
return;
}
if (evt->status == BT_HCI_ERR_OP_CANCELLED_BY_HOST) {
@ -4658,18 +4691,6 @@ static void le_per_adv_sync_established(struct net_buf *buf)
return;
}
pending_per_adv_sync = get_pending_per_adv_sync();
if (!pending_per_adv_sync ||
pending_per_adv_sync->sid != evt->sid ||
bt_addr_le_cmp(&pending_per_adv_sync->addr, &evt->adv_addr)) {
BT_ERR("Unexpected per adv sync established event");
per_adv_sync_terminate(sys_le16_to_cpu(evt->handle));
return;
}
atomic_clear_bit(pending_per_adv_sync->flags, BT_PER_ADV_SYNC_SYNCING);
atomic_set_bit(pending_per_adv_sync->flags, BT_PER_ADV_SYNC_SYNCED);
pending_per_adv_sync->handle = sys_le16_to_cpu(evt->handle);