From 99916bead0195b98aaa50979d9f5583f54904bd2 Mon Sep 17 00:00:00 2001 From: Vinayak Kariappa Chettimada Date: Tue, 11 Aug 2020 09:48:29 +0530 Subject: [PATCH] Bluetooth: controller: Refactor to use ull_sync naming Refactored to use ull_sync naming instead of ull_scan_sync. Signed-off-by: Vinayak Kariappa Chettimada --- subsys/bluetooth/controller/CMakeLists.txt | 2 +- subsys/bluetooth/controller/hci/hci.c | 12 +- subsys/bluetooth/controller/include/ll.h | 12 +- .../bluetooth/controller/ll_sw/ull_scan_aux.c | 1 + .../controller/ll_sw/ull_scan_sync.c | 35 ---- subsys/bluetooth/controller/ll_sw/ull_sync.c | 158 ++++++++++++++++++ .../controller/ll_sw/ull_sync_types.h | 27 +++ 7 files changed, 199 insertions(+), 48 deletions(-) delete mode 100644 subsys/bluetooth/controller/ll_sw/ull_scan_sync.c create mode 100644 subsys/bluetooth/controller/ll_sw/ull_sync.c create mode 100644 subsys/bluetooth/controller/ll_sw/ull_sync_types.h diff --git a/subsys/bluetooth/controller/CMakeLists.txt b/subsys/bluetooth/controller/CMakeLists.txt index f4ae6c044c5..e68b30ba26a 100644 --- a/subsys/bluetooth/controller/CMakeLists.txt +++ b/subsys/bluetooth/controller/CMakeLists.txt @@ -45,7 +45,7 @@ if(CONFIG_BT_LL_SW_SPLIT) ) zephyr_library_sources_ifdef( CONFIG_BT_CTLR_SCAN_PERIODIC - ll_sw/ull_scan_sync.c + ll_sw/ull_sync.c ) endif() if(CONFIG_BT_CONN) diff --git a/subsys/bluetooth/controller/hci/hci.c b/subsys/bluetooth/controller/hci/hci.c index 75a3df69f78..4600c37ffdc 100644 --- a/subsys/bluetooth/controller/hci/hci.c +++ b/subsys/bluetooth/controller/hci/hci.c @@ -2065,9 +2065,9 @@ static void le_per_adv_create_sync(struct net_buf *buf, struct net_buf **evt) skip = sys_le16_to_cpu(cmd->skip); sync_timeout = sys_le16_to_cpu(cmd->sync_timeout); - status = ll_scan_sync_create(cmd->options, cmd->sid, cmd->addr.type, - cmd->addr.a.val, skip, sync_timeout, - cmd->cte_type); + status = ll_sync_create(cmd->options, cmd->sid, cmd->addr.type, + cmd->addr.a.val, skip, sync_timeout, + cmd->cte_type); *evt = cmd_status(status); } @@ -2078,7 +2078,7 @@ static void le_per_adv_create_sync_cancel(struct net_buf *buf, struct bt_hci_evt_cc_status *ccst; uint8_t status; - status = ll_scan_sync_create_cancel(); + status = ll_sync_create_cancel(); ccst = hci_cmd_complete(evt, sizeof(*ccst)); ccst->status = status; @@ -2093,7 +2093,7 @@ static void le_per_adv_terminate_sync(struct net_buf *buf, struct net_buf **evt) handle = sys_le16_to_cpu(cmd->handle); - status = ll_scan_sync_terminate(handle); + status = ll_sync_terminate(handle); ccst = hci_cmd_complete(evt, sizeof(*ccst)); ccst->status = status; @@ -2108,7 +2108,7 @@ static void le_per_adv_recv_enable(struct net_buf *buf, struct net_buf **evt) handle = sys_le16_to_cpu(cmd->handle); - status = ll_scan_sync_recv_enable(handle, cmd->enable); + status = ll_sync_recv_enable(handle, cmd->enable); ccst = hci_cmd_complete(evt, sizeof(*ccst)); ccst->status = status; diff --git a/subsys/bluetooth/controller/include/ll.h b/subsys/bluetooth/controller/include/ll.h index 40a8a24fed2..3cf2098035d 100644 --- a/subsys/bluetooth/controller/include/ll.h +++ b/subsys/bluetooth/controller/include/ll.h @@ -98,12 +98,12 @@ uint8_t ll_adv_enable(uint8_t enable); uint8_t ll_scan_params_set(uint8_t type, uint16_t interval, uint16_t window, uint8_t own_addr_type, uint8_t filter_policy); uint8_t ll_scan_enable(uint8_t enable); -uint8_t ll_scan_sync_create(uint8_t options, uint8_t sid, uint8_t adv_addr_type, - uint8_t *adv_addr, uint16_t skip, - uint16_t sync_timeout, uint8_t sync_cte_type); -uint8_t ll_scan_sync_create_cancel(void); -uint8_t ll_scan_sync_terminate(uint16_t handle); -uint8_t ll_scan_sync_recv_enable(uint16_t handle, uint8_t enable); +uint8_t ll_sync_create(uint8_t options, uint8_t sid, uint8_t adv_addr_type, + uint8_t *adv_addr, uint16_t skip, + uint16_t sync_timeout, uint8_t sync_cte_type); +uint8_t ll_sync_create_cancel(void); +uint8_t ll_sync_terminate(uint16_t handle); +uint8_t ll_sync_recv_enable(uint16_t handle, uint8_t enable); #else /* !CONFIG_BT_CTLR_ADV_EXT */ uint8_t ll_scan_params_set(uint8_t type, uint16_t interval, uint16_t window, uint8_t own_addr_type, uint8_t filter_policy); diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c b/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c index 818ff046df7..eb321bc580c 100644 --- a/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c +++ b/subsys/bluetooth/controller/ll_sw/ull_scan_aux.c @@ -23,6 +23,7 @@ #include "lll_scan_aux.h" #include "ull_scan_types.h" +#include "ull_sync_types.h" #include "ull_internal.h" #include "ull_scan_internal.h" diff --git a/subsys/bluetooth/controller/ll_sw/ull_scan_sync.c b/subsys/bluetooth/controller/ll_sw/ull_scan_sync.c deleted file mode 100644 index ca55a35305b..00000000000 --- a/subsys/bluetooth/controller/ll_sw/ull_scan_sync.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * Copyright (c) 2020 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include - -#include - -uint8_t ll_scan_sync_create(uint8_t options, uint8_t sid, uint8_t adv_addr_type, - uint8_t *adv_addr, uint16_t skip, - uint16_t sync_timeout, uint8_t sync_cte_type) -{ - /* TODO: */ - return BT_HCI_ERR_CMD_DISALLOWED; -} - -uint8_t ll_scan_sync_create_cancel(void) -{ - /* TODO: */ - return BT_HCI_ERR_CMD_DISALLOWED; -} - -uint8_t ll_scan_sync_terminate(uint16_t handle) -{ - /* TODO: */ - return BT_HCI_ERR_CMD_DISALLOWED; -} - -uint8_t ll_scan_sync_recv_enable(uint16_t handle, uint8_t enable) -{ - /* TODO: */ - return BT_HCI_ERR_CMD_DISALLOWED; -} diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync.c b/subsys/bluetooth/controller/ll_sw/ull_sync.c new file mode 100644 index 00000000000..3003cea278c --- /dev/null +++ b/subsys/bluetooth/controller/ll_sw/ull_sync.c @@ -0,0 +1,158 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include +#include + +#include "hal/ccm.h" +#include "hal/radio.h" + +#include "util/util.h" +#include "util/mem.h" +#include "util/memq.h" + +#include "pdu.h" +#include "ll.h" + +#include "lll.h" +#include "lll_scan.h" +#include "lll_sync.h" + +#include "ull_scan_types.h" +#include "ull_sync_types.h" + +#include "ull_scan_internal.h" + +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_DRIVER) +#define LOG_MODULE_NAME bt_ctlr_ull_sync +#include "common/log.h" +#include +#include "hal/debug.h" + +static int init_reset(void); +static inline struct ll_sync_set *sync_acquire(void); + +static struct ll_sync_set ll_sync_pool[CONFIG_BT_CTLR_SCAN_SYNC_SET]; +static void *sync_free; + +uint8_t ll_sync_create(uint8_t options, uint8_t sid, uint8_t adv_addr_type, + uint8_t *adv_addr, uint16_t skip, + uint16_t sync_timeout, uint8_t sync_cte_type) +{ + struct ll_scan_set *scan_coded = NULL; + struct ll_scan_set *scan = NULL; + struct ll_sync_set *sync; + + scan = ull_scan_set_get(SCAN_HANDLE_1M); + if (!scan || scan->sync) { + return BT_HCI_ERR_CMD_DISALLOWED; + } + + if (IS_ENABLED(CONFIG_BT_CTLR_PHY_CODED)) { + scan_coded = ull_scan_set_get(SCAN_HANDLE_PHY_CODED); + if (!scan_coded || scan_coded->sync) { + return BT_HCI_ERR_CMD_DISALLOWED; + } + } + + sync = sync_acquire(); + if (!sync) { + return BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; + } + + sync->filter_policy = options & BIT(0); + if (!sync->filter_policy) { + sync->sid = sid; + sync->adv_addr_type = adv_addr_type; + memcpy(sync->adv_addr, adv_addr, BDADDR_SIZE); + } + + sync->skip = skip; + sync->skip_countdown = skip; + + sync->timeout = sync_timeout; + + /* TODO: Support for CTE type */ + + /* Reporting initially enabled/disabled */ + sync->lll.is_enabled = options & BIT(1); + + /* Enable scanner to create sync */ + scan->sync = sync; + if (IS_ENABLED(CONFIG_BT_CTLR_PHY_CODED)) { + scan_coded->sync = sync; + } + + return 0; +} + +uint8_t ll_sync_create_cancel(void) +{ + /* TODO: */ + return BT_HCI_ERR_CMD_DISALLOWED; +} + +uint8_t ll_sync_terminate(uint16_t handle) +{ + /* TODO: */ + return BT_HCI_ERR_CMD_DISALLOWED; +} + +uint8_t ll_sync_recv_enable(uint16_t handle, uint8_t enable) +{ + /* TODO: */ + return BT_HCI_ERR_CMD_DISALLOWED; +} + +int ull_sync_init(void) +{ + int err; + + err = init_reset(); + if (err) { + return err; + } + + return 0; +} + +int ull_sync_reset(void) +{ + int err; + + err = init_reset(); + if (err) { + return err; + } + + return 0; +} + +static int init_reset(void) +{ + /* Initialize sync pool. */ + mem_init(ll_sync_pool, sizeof(struct ll_sync_set), + sizeof(ll_sync_pool) / sizeof(struct ll_sync_set), + &sync_free); + + return 0; +} + +static inline struct ll_sync_set *sync_acquire(void) +{ + return mem_acquire(&sync_free); +} + +static inline void sync_release(struct ll_sync_set *sync) +{ + mem_release(sync, &sync_free); +} + +static inline uint8_t sync_handle_get(struct ll_sync_set *sync) +{ + return mem_index_get(sync, ll_sync_pool, sizeof(struct ll_sync_set)); +} + diff --git a/subsys/bluetooth/controller/ll_sw/ull_sync_types.h b/subsys/bluetooth/controller/ll_sw/ull_sync_types.h new file mode 100644 index 00000000000..66ea3cbeff9 --- /dev/null +++ b/subsys/bluetooth/controller/ll_sw/ull_sync_types.h @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#define LL_SYNC_STATE_IDLE 0x00 +#define LL_SYNC_STATE_ADDR_MATCH 0x01 +#define LL_SYNC_STATE_CREATED 0x02 + +struct ll_sync_set { + struct evt_hdr evt; + struct ull_hdr ull; + struct lll_sync lll; + + uint8_t sid; + uint8_t adv_addr_type:1; + uint8_t filter_policy:1; + uint8_t state:2; + + uint8_t adv_addr[BDADDR_SIZE]; + uint16_t skip; + uint16_t skip_countdown; + uint16_t timeout; + + /* TODO: handling of sync CTE type */ +};