Skip to content

Commit 2125a64

Browse files
ppryga-nordiccarlescufi
authored andcommitted
Bluetooth: Host: add missing de-init of periodic sync pool
While execution of bt_disable there is missing de-initialization of per_adv_sync_pool. If there was a sync in progress, (flags set to BT_PER_ADV_SYNC_SYNCING) before bt_disable, then when the stack is re-enabled by bt_enable new sync create fails. The commit fixes the issue by new function that clears flags for all per_adv_sync_pool entries. The function is executed by bt_disable. Signed-off-by: Piotr Pryga <[email protected]>
1 parent 8be0999 commit 2125a64

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

subsys/bluetooth/host/hci_core.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3736,7 +3736,13 @@ int bt_disable(void)
37363736

37373737
bt_monitor_send(BT_MONITOR_CLOSE_INDEX, NULL, 0);
37383738

3739-
/* Clear BT_DEV_ENABLE here to prevent early bt_enable() calls */
3739+
#if defined(CONFIG_BT_PER_ADV_SYNC)
3740+
bt_periodic_sync_disable();
3741+
#endif /* CONFIG_BT_PER_ADV_SYNC */
3742+
3743+
/* Clear BT_DEV_ENABLE here to prevent early bt_enable() calls, before disable is
3744+
* completed.
3745+
*/
37403746
atomic_clear_bit(bt_dev.flags, BT_DEV_ENABLE);
37413747

37423748
return 0;

subsys/bluetooth/host/scan.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,13 @@ static struct bt_le_per_adv_sync *get_pending_per_adv_sync(void)
723723
return NULL;
724724
}
725725

726+
void bt_periodic_sync_disable(void)
727+
{
728+
for (size_t i = 0; i < ARRAY_SIZE(per_adv_sync_pool); i++) {
729+
per_adv_sync_delete(&per_adv_sync_pool[i]);
730+
}
731+
}
732+
726733
struct bt_le_per_adv_sync *bt_hci_get_per_adv_sync(uint16_t handle)
727734
{
728735
for (int i = 0; i < ARRAY_SIZE(per_adv_sync_pool); i++) {

subsys/bluetooth/host/scan.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,5 @@ bool bt_id_scan_random_addr_check(void);
1212
int bt_le_scan_set_enable(uint8_t enable);
1313

1414
struct bt_le_per_adv_sync *bt_hci_get_per_adv_sync(uint16_t handle);
15+
16+
void bt_periodic_sync_disable(void);

0 commit comments

Comments
 (0)