diff --git a/include/bluetooth/direction.h b/include/bluetooth/direction.h new file mode 100644 index 00000000000..cf1e0cbaf0f --- /dev/null +++ b/include/bluetooth/direction.h @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 Nordic Semiconductor ASA + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#ifndef ZEPHYR_INCLUDE_BLUETOOTH_DF_H_ +#define ZEPHYR_INCLUDE_BLUETOOTH_DF_H_ + +/** @brief Constant Tone Extension parameters for connectionless + * transmission. + * + * The structure holds information required to setup CTE transmission + * in periodic advertising. + */ +struct bt_df_adv_cte_tx_param { + /** Length of CTE in 8us units */ + uint8_t cte_len; + /** CTE Type: AoA, AoD 1us slots, AoD 2us slots */ + uint8_t cte_type; + /** Number of CTE to transmit in each periodic adv interval */ + uint8_t cte_count; + /** Number of Antenna IDs in the switch pattern */ + uint8_t num_ant_ids; + /** List of antenna IDs in the pattern */ + uint8_t *ant_ids; +}; + +/** @brief Set or update the Constant Tone Extension parameters for periodic + * advertising set. + * + * @param[in] adv Advertising set object. + * @param[in] params Constant Tone Extension parameters. + * + * @return Zero on success or (negative) error code otherwise. + */ +int bt_df_set_adv_cte_tx_param(struct bt_le_ext_adv *adv, + const struct bt_df_adv_cte_tx_param *params); + +#endif /* ZEPHYR_INCLUDE_BLUETOOTH_DF_H_ */ diff --git a/subsys/bluetooth/host/direction.c b/subsys/bluetooth/host/direction.c index ae3884abbb4..6724b78114a 100644 --- a/subsys/bluetooth/host/direction.c +++ b/subsys/bluetooth/host/direction.c @@ -9,11 +9,11 @@ #include #include #include +#include #include #include "hci_core.h" #include "conn_internal.h" -#include "direction.h" #include "direction_internal.h" #define BT_DBG_ENABLED IS_ENABLED(CONFIG_BT_DEBUG_DF) @@ -44,7 +44,7 @@ static struct bt_le_df_ant_info df_ant_info; BT_HCI_LE_1US_AOA_RX)) static int hci_df_set_cl_cte_tx_params(const struct bt_le_ext_adv *adv, - const struct bt_le_df_adv_cte_tx_params *params) + const struct bt_df_adv_cte_tx_param *params) { struct bt_hci_cp_le_set_cl_cte_tx_params *cp; struct net_buf *buf; @@ -250,3 +250,30 @@ int le_df_init(void) BT_DBG("DF initialized."); return 0; } + +int bt_df_set_adv_cte_tx_param(struct bt_le_ext_adv *adv, + const struct bt_df_adv_cte_tx_param *params) +{ + __ASSERT_NO_MSG(adv); + __ASSERT_NO_MSG(params); + + int err; + + if (!BT_FEAT_LE_CONNECTIONLESS_CTE_TX(bt_dev.le.features)) { + return -ENOTSUP; + } + + /* Check if BT_ADV_PARAMS_SET is set, because it implies the set + * has already been created. + */ + if (!atomic_test_bit(adv->flags, BT_ADV_PARAMS_SET)) { + return -EINVAL; + } + + err = hci_df_set_cl_cte_tx_params(adv, params); + if (err) { + return err; + } + + return 0; +} diff --git a/subsys/bluetooth/host/direction.h b/subsys/bluetooth/host/direction.h deleted file mode 100644 index 9637c417178..00000000000 --- a/subsys/bluetooth/host/direction.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2020 Nordic Semiconductor ASA - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef ZEPHYR_SUBSYS_BLUETOOTH_HOST_DF_H_ -#define ZEPHYR_SUBSYS_BLUETOOTH_HOST_DF_H_ - -/* @brief Optional switching and sampling rates for Angle of Departure - * and Angle or Arrival modes. - */ -enum bt_df_opt_swich_sample_rates { - /* Support Angle of Departure 1us switching TX */ - DF_AOD_1US_SWITCH_TX_SUPP = BIT(0), - /* Support Angle of departure 1us sampling RX */ - DF_AOD_1US_SAMPL_RX_SUPP = BIT(1), - /* Support Angle of Arrival 1us switching and sampling RX */ - DF_AOA_1US_SWITCH_SAMPL_RX_SUPP = BIT(2), -}; - -/* @brief Constant Tone Extension parameters for connectionless - * transmission. - * - * The structure holds information required to setup CTE transmission - * in periodic advertising. - */ -struct bt_le_df_adv_cte_tx_params { - /* Length of CTE in 8us units */ - uint8_t cte_len; - /* CTE Type: AoA, AoD 1us slots, AoD 2us slots */ - uint8_t cte_type; - /* Number of CTE to transmit in each periodic adv interval */ - uint8_t cte_count; - /* Number of Antenna IDs in the switch pattern */ - uint8_t num_ant_ids; - /* List of antenna IDs in the pattern */ - uint8_t *ant_ids; -}; -#endif /* ZEPHYR_SUBSYS_BLUETOOTH_HOST_DF_H_ */