Bluetooth: host: direction: Add public API to set CTE TX enable for adv
Add public function to set Constant Tone Extension transmission enabled or disabled for periodic advertising. Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
This commit is contained in:
parent
0a09441e47
commit
472febfe69
3 changed files with 99 additions and 0 deletions
|
@ -37,4 +37,26 @@ struct bt_df_adv_cte_tx_param {
|
|||
int bt_df_set_adv_cte_tx_param(struct bt_le_ext_adv *adv,
|
||||
const struct bt_df_adv_cte_tx_param *params);
|
||||
|
||||
/** @brief Enable transmission of Constant Tone Extension for the given
|
||||
* advertising set.
|
||||
*
|
||||
* Transmission of Constant Tone Extension may be enabled only after setting
|
||||
* periodic advertising parameters (@ref bt_le_per_adv_set_param) and Constant
|
||||
* Tone Extension parameters (@ref bt_df_set_adv_cte_tx_param).
|
||||
*
|
||||
* @param[in] adv Advertising set object.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_df_adv_cte_tx_enable(struct bt_le_ext_adv *adv);
|
||||
|
||||
/** @brief Disable transmission of Constant Tone Extension for the given
|
||||
* advertising set.
|
||||
*
|
||||
* @param[in] adv Advertising set object.
|
||||
*
|
||||
* @return Zero on success or (negative) error code otherwise.
|
||||
*/
|
||||
int bt_df_adv_cte_tx_disable(struct bt_le_ext_adv *adv);
|
||||
|
||||
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_DF_H_ */
|
||||
|
|
|
@ -156,6 +156,40 @@ static int hci_df_read_ant_info(uint8_t *switch_sample_rates,
|
|||
return 0;
|
||||
}
|
||||
|
||||
/* @brief Function handles send of HCI commnad to enable or disables CTE
|
||||
* transmission for given advertising set.
|
||||
*
|
||||
* @param[in] adv Pointer to advertising set
|
||||
* @param[in] enable Enable or disable CTE TX
|
||||
*
|
||||
* @return Zero in case of success, other value in case of failure.
|
||||
*/
|
||||
static int hci_df_set_adv_cte_tx_enable(struct bt_le_ext_adv *adv,
|
||||
bool enable)
|
||||
{
|
||||
struct bt_hci_cp_le_set_cl_cte_tx_enable *cp;
|
||||
struct bt_hci_cmd_state_set state;
|
||||
struct net_buf *buf;
|
||||
|
||||
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_CL_CTE_TX_ENABLE, sizeof(*cp));
|
||||
if (!buf) {
|
||||
return -ENOBUFS;
|
||||
}
|
||||
|
||||
cp = net_buf_add(buf, sizeof(*cp));
|
||||
(void)memset(cp, 0, sizeof(*cp));
|
||||
|
||||
cp->handle = adv->handle;
|
||||
cp->cte_enable = enable ? 1 : 0;
|
||||
|
||||
bt_hci_cmd_state_set_init(&state, adv->flags, BT_PER_ADV_CTE_ENABLED,
|
||||
enable);
|
||||
bt_hci_cmd_data_state_set(buf, &state);
|
||||
|
||||
return bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_CL_CTE_TX_ENABLE,
|
||||
buf, NULL);
|
||||
}
|
||||
|
||||
/* @brief Function sets CTE parameters for connection object
|
||||
*
|
||||
* @param[in] cte_types Allowed response CTE types
|
||||
|
@ -271,10 +305,45 @@ int bt_df_set_adv_cte_tx_param(struct bt_le_ext_adv *adv,
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (atomic_test_bit(adv->flags, BT_PER_ADV_CTE_ENABLED)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
err = hci_df_set_cl_cte_tx_params(adv, params);
|
||||
if (err) {
|
||||
return err;
|
||||
}
|
||||
|
||||
atomic_set_bit(adv->flags, BT_PER_ADV_CTE_PARAMS_SET);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bt_df_set_adv_cte_tx_enabled(struct bt_le_ext_adv *adv, bool enable)
|
||||
{
|
||||
if (!atomic_test_bit(adv->flags, BT_PER_ADV_PARAMS_SET)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (!atomic_test_bit(adv->flags, BT_PER_ADV_CTE_PARAMS_SET)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (enable == atomic_test_bit(adv->flags, BT_PER_ADV_CTE_ENABLED)) {
|
||||
return -EALREADY;
|
||||
}
|
||||
|
||||
return hci_df_set_adv_cte_tx_enable(adv, enable);
|
||||
}
|
||||
|
||||
int bt_df_adv_cte_tx_enable(struct bt_le_ext_adv *adv)
|
||||
{
|
||||
__ASSERT_NO_MSG(adv);
|
||||
return bt_df_set_adv_cte_tx_enabled(adv, true);
|
||||
}
|
||||
|
||||
int bt_df_adv_cte_tx_disable(struct bt_le_ext_adv *adv)
|
||||
{
|
||||
__ASSERT_NO_MSG(adv);
|
||||
return bt_df_set_adv_cte_tx_enabled(adv, false);
|
||||
}
|
||||
|
|
|
@ -105,6 +105,14 @@ enum {
|
|||
BT_PER_ADV_ENABLED,
|
||||
/* Periodic Advertising parameters has been set in the controller. */
|
||||
BT_PER_ADV_PARAMS_SET,
|
||||
/* Constant Tone Extension parameters for Periodic Advertising
|
||||
* has been set in the controller.
|
||||
*/
|
||||
BT_PER_ADV_CTE_PARAMS_SET,
|
||||
/* Constant Tone Extension for Periodic Advertising has been enabled
|
||||
* in the controller.
|
||||
*/
|
||||
BT_PER_ADV_CTE_ENABLED,
|
||||
|
||||
BT_ADV_NUM_FLAGS,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue