Commit a9a01d4c authored by Vinayak Kariappa Chettimada's avatar Vinayak Kariappa Chettimada Committed by Carles Cufi
Browse files

Bluetooth: Controller: Fix missing reset of Periodic Sync Create



Fix missing reset of Periodic Sync Create when HCI Reset is
performed.

Signed-off-by: default avatarVinayak Kariappa Chettimada <vich@nordicsemi.no>
parent 29ae143a
Loading
Loading
Loading
Loading
+20 −5
Original line number Diff line number Diff line
/*
 * Copyright (c) 2020 Nordic Semiconductor ASA
 * Copyright (c) 2020-2021 Nordic Semiconductor ASA
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr.h>
#include <soc.h>
#include <sys/byteorder.h>
#include <bluetooth/hci.h>

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

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

	/* Check for race condition where in sync is established when sync
	 * context was set to NULL.
	 *
	 * Setting `scan->per_scan.sync` to NULL represents cancellation
	 * requested in the thread context. Checking `sync->timeout_reload`
	 * confirms if synchronization was established before
	 * `scan->per_scan.sync` was set to NULL.
	 */
	sync = scan->per_scan.sync;
	if (!sync || sync->timeout_reload) {
		return BT_HCI_ERR_CMD_DISALLOWED;
	}

	scan->per_scan.sync = NULL;
	if (IS_ENABLED(CONFIG_BT_CTLR_PHY_CODED)) {
		scan_coded->per_scan.sync = NULL;
	}
	cpu_dmb();
	if (!sync || sync->timeout_reload) {
		return BT_HCI_ERR_CMD_DISALLOWED;
	}

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

int ull_sync_reset(void)
{
	uint16_t handle;
	void *rx;
	int err;

	(void)ll_sync_create_cancel(&rx);

	for (handle = 0U; handle < CONFIG_BT_PER_ADV_SYNC_MAX; handle++) {
		(void)ll_sync_terminate(handle);
	}

	err = init_reset();
	if (err) {
		return err;