From 14890c8eb60f7f6b302030a417a911d6b9571b9b Mon Sep 17 00:00:00 2001 From: Piotr Pryga Date: Wed, 14 Oct 2020 00:50:47 -0700 Subject: [PATCH] Bluetooth: host: Add read antenna information HCI command Add Bluetooth 5.1 Direction Finding HCI command: HCI_LE_Read_Antenna_Information handling to Host. Add wrapper function to handle send the command and receive response from Controller. Signed-off-by: Piotr Pryga --- include/bluetooth/hci.h | 22 ++++++++++ subsys/bluetooth/host/CMakeLists.txt | 6 +++ subsys/bluetooth/host/Kconfig | 7 ++++ subsys/bluetooth/host/direction.c | 61 ++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+) create mode 100644 subsys/bluetooth/host/direction.c diff --git a/include/bluetooth/hci.h b/include/bluetooth/hci.h index 6e4a86224a1..7ee90d31ed4 100644 --- a/include/bluetooth/hci.h +++ b/include/bluetooth/hci.h @@ -1351,6 +1351,28 @@ struct bt_hci_cp_le_set_privacy_mode { uint8_t mode; } __packed; +#define BT_HCI_LE_1US_AOD_TX BIT(0) +#define BT_HCI_LE_1US_AOD_RX BIT(1) +#define BT_HCI_LE_1US_AOA_RX BIT(2) + +#define BT_HCI_LE_NUM_ANT_MIN 0x1 +#define BT_HCI_LE_NUM_ANT_MAX 0x4B + +#define BT_HCI_LE_MAX_SWITCH_PATTERN_LEN_MIN 0x2 +#define BT_HCI_LE_MAX_SWITCH_PATTERN_LEN_MAX 0x4B + +#define BT_HCI_LE_MAX_CTE_LEN_MIN 0x2 +#define BT_HCI_LE_MAX_CTE_LEN_MAX 0x14 + +#define BT_HCI_OP_LE_READ_ANT_INFO BT_OP(BT_OGF_LE, 0x0058) +struct bt_hci_rp_le_read_ant_info { + uint8_t status; + uint8_t switch_sample_rates; + uint8_t num_ant; + uint8_t max_switch_pattern_len; + uint8_t max_cte_len; +}; + #define BT_HCI_OP_LE_SET_PER_ADV_RECV_ENABLE BT_OP(BT_OGF_LE, 0x0059) struct bt_hci_cp_le_set_per_adv_recv_enable { uint16_t handle; diff --git a/subsys/bluetooth/host/CMakeLists.txt b/subsys/bluetooth/host/CMakeLists.txt index 8e46a36382f..ba44c5c4fee 100644 --- a/subsys/bluetooth/host/CMakeLists.txt +++ b/subsys/bluetooth/host/CMakeLists.txt @@ -57,6 +57,12 @@ if(CONFIG_BT_HCI_HOST) ) endif() endif() + + if(CONFIG_BT_DF) + zephyr_library_sources( + direction.c + ) + endif() endif() if(CONFIG_BT_DEBUG_SMP OR CONFIG_BT_DEBUG_KEYS) diff --git a/subsys/bluetooth/host/Kconfig b/subsys/bluetooth/host/Kconfig index c03146791b7..2be3f46e7ca 100644 --- a/subsys/bluetooth/host/Kconfig +++ b/subsys/bluetooth/host/Kconfig @@ -601,6 +601,13 @@ config BT_ID_MAX Maximum number of supported local identity addresses. For most products this is safe to leave as the default value (1). +config BT_DF + bool "Enable Direction Finding support [EXPERIMENTAL]" + help + Enable support for Bluetooth 5.1 Direction Finding. + It will allow to: get information about antennae, configure + Constant Tone Extension, transmit CTE and sample incoming CTE. + endif # BT_HCI_HOST config BT_ECC diff --git a/subsys/bluetooth/host/direction.c b/subsys/bluetooth/host/direction.c new file mode 100644 index 00000000000..a6b591a6771 --- /dev/null +++ b/subsys/bluetooth/host/direction.c @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ +#include +#include + +#include +#include + +#define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_HCI_CORE) +#define LOG_MODULE_NAME bt_df +#include "common/log.h" + +/* @brief Function provides information about DF antennae numer and + * controller capabilities related with Constant Tone Extension. + * + * @param[out] switch_sample_rates Optional switching and sampling rates. + * @param[out] num_ant Antennae number. + * @param[out] max_switch_pattern_len Maximum supported antennae switching + * paterns length. + * @param[out] max_CTE_len Maximum length of CTE in 8[us] units. + * + * @return Zero in case of success, other value in case of failure. + */ +static int hci_df_read_ant_info(uint8_t *switch_sample_rates, + uint8_t *num_ant, + uint8_t *max_switch_pattern_len, + uint8_t *max_cte_len) +{ + __ASSERT_NO_MSG(switch_sample_rates); + __ASSERT_NO_MSG(num_ant); + __ASSERT_NO_MSG(max_switch_pattern_len); + __ASSERT_NO_MSG(max_cte_len); + + struct bt_hci_rp_le_read_ant_info *rp; + struct net_buf *rsp; + int err; + + err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_READ_ANT_INFO, NULL, &rsp); + if (err) { + BT_ERR("Failed to read antenna information"); + return err; + } + + rp = (void *)rsp->data; + + BT_DBG("DF: sw. sampl rates: %x ant num: %u , max sw. pattern len: %u," + "max CTE len %d", rp->switch_sample_rates, rp->num_ant, + rp->max_switch_pattern_len, rp->max_cte_len); + + *switch_sample_rates = rp->switch_sample_rates; + *num_ant = rp->num_ant; + *max_switch_pattern_len = rp->max_switch_pattern_len; + *max_cte_len = rp->max_cte_len; + + net_buf_unref(rsp); + + return 0; +}