Skip to content

Commit a9a01d4

Browse files
cvinayakcarlescufi
authored andcommitted
Bluetooth: Controller: Fix missing reset of Periodic Sync Create
Fix missing reset of Periodic Sync Create when HCI Reset is performed. Signed-off-by: Vinayak Kariappa Chettimada <[email protected]>
1 parent 29ae143 commit a9a01d4

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

subsys/bluetooth/controller/ll_sw/ull_sync.c

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
/*
2-
* Copyright (c) 2020 Nordic Semiconductor ASA
2+
* Copyright (c) 2020-2021 Nordic Semiconductor ASA
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

77
#include <zephyr.h>
8+
#include <soc.h>
89
#include <sys/byteorder.h>
910
#include <bluetooth/hci.h>
1011

@@ -13,6 +14,7 @@
1314
#include "util/memq.h"
1415
#include "util/mayfly.h"
1516

17+
#include "hal/cpu.h"
1618
#include "hal/ccm.h"
1719
#include "hal/radio.h"
1820
#include "hal/ticker.h"
@@ -217,16 +219,21 @@ uint8_t ll_sync_create_cancel(void **rx)
217219

218220
/* Check for race condition where in sync is established when sync
219221
* context was set to NULL.
222+
*
223+
* Setting `scan->per_scan.sync` to NULL represents cancellation
224+
* requested in the thread context. Checking `sync->timeout_reload`
225+
* confirms if synchronization was established before
226+
* `scan->per_scan.sync` was set to NULL.
220227
*/
221228
sync = scan->per_scan.sync;
222-
if (!sync || sync->timeout_reload) {
223-
return BT_HCI_ERR_CMD_DISALLOWED;
224-
}
225-
226229
scan->per_scan.sync = NULL;
227230
if (IS_ENABLED(CONFIG_BT_CTLR_PHY_CODED)) {
228231
scan_coded->per_scan.sync = NULL;
229232
}
233+
cpu_dmb();
234+
if (!sync || sync->timeout_reload) {
235+
return BT_HCI_ERR_CMD_DISALLOWED;
236+
}
230237

231238
node_rx = (void *)scan->per_scan.node_rx_estab;
232239
link_sync_estab = node_rx->hdr.link;
@@ -302,8 +309,16 @@ int ull_sync_init(void)
302309

303310
int ull_sync_reset(void)
304311
{
312+
uint16_t handle;
313+
void *rx;
305314
int err;
306315

316+
(void)ll_sync_create_cancel(&rx);
317+
318+
for (handle = 0U; handle < CONFIG_BT_PER_ADV_SYNC_MAX; handle++) {
319+
(void)ll_sync_terminate(handle);
320+
}
321+
307322
err = init_reset();
308323
if (err) {
309324
return err;

0 commit comments

Comments
 (0)