|
1 | 1 | /*
|
2 |
| - * Copyright (c) 2020 Nordic Semiconductor ASA |
| 2 | + * Copyright (c) 2020-2021 Nordic Semiconductor ASA |
3 | 3 | *
|
4 | 4 | * SPDX-License-Identifier: Apache-2.0
|
5 | 5 | */
|
6 | 6 |
|
7 | 7 | #include <zephyr.h>
|
| 8 | +#include <soc.h> |
8 | 9 | #include <sys/byteorder.h>
|
9 | 10 | #include <bluetooth/hci.h>
|
10 | 11 |
|
|
13 | 14 | #include "util/memq.h"
|
14 | 15 | #include "util/mayfly.h"
|
15 | 16 |
|
| 17 | +#include "hal/cpu.h" |
16 | 18 | #include "hal/ccm.h"
|
17 | 19 | #include "hal/radio.h"
|
18 | 20 | #include "hal/ticker.h"
|
@@ -217,16 +219,21 @@ uint8_t ll_sync_create_cancel(void **rx)
|
217 | 219 |
|
218 | 220 | /* Check for race condition where in sync is established when sync
|
219 | 221 | * 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. |
220 | 227 | */
|
221 | 228 | sync = scan->per_scan.sync;
|
222 |
| - if (!sync || sync->timeout_reload) { |
223 |
| - return BT_HCI_ERR_CMD_DISALLOWED; |
224 |
| - } |
225 |
| - |
226 | 229 | scan->per_scan.sync = NULL;
|
227 | 230 | if (IS_ENABLED(CONFIG_BT_CTLR_PHY_CODED)) {
|
228 | 231 | scan_coded->per_scan.sync = NULL;
|
229 | 232 | }
|
| 233 | + cpu_dmb(); |
| 234 | + if (!sync || sync->timeout_reload) { |
| 235 | + return BT_HCI_ERR_CMD_DISALLOWED; |
| 236 | + } |
230 | 237 |
|
231 | 238 | node_rx = (void *)scan->per_scan.node_rx_estab;
|
232 | 239 | link_sync_estab = node_rx->hdr.link;
|
@@ -302,8 +309,16 @@ int ull_sync_init(void)
|
302 | 309 |
|
303 | 310 | int ull_sync_reset(void)
|
304 | 311 | {
|
| 312 | + uint16_t handle; |
| 313 | + void *rx; |
305 | 314 | int err;
|
306 | 315 |
|
| 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 | + |
307 | 322 | err = init_reset();
|
308 | 323 | if (err) {
|
309 | 324 | return err;
|
|
0 commit comments