Skip to content

Commit 472febf

Browse files
ppryga-nordiccarlescufi
authored andcommitted
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 <[email protected]>
1 parent 0a09441 commit 472febf

File tree

3 files changed

+99
-0
lines changed

3 files changed

+99
-0
lines changed

include/bluetooth/direction.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,26 @@ struct bt_df_adv_cte_tx_param {
3737
int bt_df_set_adv_cte_tx_param(struct bt_le_ext_adv *adv,
3838
const struct bt_df_adv_cte_tx_param *params);
3939

40+
/** @brief Enable transmission of Constant Tone Extension for the given
41+
* advertising set.
42+
*
43+
* Transmission of Constant Tone Extension may be enabled only after setting
44+
* periodic advertising parameters (@ref bt_le_per_adv_set_param) and Constant
45+
* Tone Extension parameters (@ref bt_df_set_adv_cte_tx_param).
46+
*
47+
* @param[in] adv Advertising set object.
48+
*
49+
* @return Zero on success or (negative) error code otherwise.
50+
*/
51+
int bt_df_adv_cte_tx_enable(struct bt_le_ext_adv *adv);
52+
53+
/** @brief Disable transmission of Constant Tone Extension for the given
54+
* advertising set.
55+
*
56+
* @param[in] adv Advertising set object.
57+
*
58+
* @return Zero on success or (negative) error code otherwise.
59+
*/
60+
int bt_df_adv_cte_tx_disable(struct bt_le_ext_adv *adv);
61+
4062
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_DF_H_ */

subsys/bluetooth/host/direction.c

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,40 @@ static int hci_df_read_ant_info(uint8_t *switch_sample_rates,
156156
return 0;
157157
}
158158

159+
/* @brief Function handles send of HCI commnad to enable or disables CTE
160+
* transmission for given advertising set.
161+
*
162+
* @param[in] adv Pointer to advertising set
163+
* @param[in] enable Enable or disable CTE TX
164+
*
165+
* @return Zero in case of success, other value in case of failure.
166+
*/
167+
static int hci_df_set_adv_cte_tx_enable(struct bt_le_ext_adv *adv,
168+
bool enable)
169+
{
170+
struct bt_hci_cp_le_set_cl_cte_tx_enable *cp;
171+
struct bt_hci_cmd_state_set state;
172+
struct net_buf *buf;
173+
174+
buf = bt_hci_cmd_create(BT_HCI_OP_LE_SET_CL_CTE_TX_ENABLE, sizeof(*cp));
175+
if (!buf) {
176+
return -ENOBUFS;
177+
}
178+
179+
cp = net_buf_add(buf, sizeof(*cp));
180+
(void)memset(cp, 0, sizeof(*cp));
181+
182+
cp->handle = adv->handle;
183+
cp->cte_enable = enable ? 1 : 0;
184+
185+
bt_hci_cmd_state_set_init(&state, adv->flags, BT_PER_ADV_CTE_ENABLED,
186+
enable);
187+
bt_hci_cmd_data_state_set(buf, &state);
188+
189+
return bt_hci_cmd_send_sync(BT_HCI_OP_LE_SET_CL_CTE_TX_ENABLE,
190+
buf, NULL);
191+
}
192+
159193
/* @brief Function sets CTE parameters for connection object
160194
*
161195
* @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,
271305
return -EINVAL;
272306
}
273307

308+
if (atomic_test_bit(adv->flags, BT_PER_ADV_CTE_ENABLED)) {
309+
return -EINVAL;
310+
}
311+
274312
err = hci_df_set_cl_cte_tx_params(adv, params);
275313
if (err) {
276314
return err;
277315
}
278316

317+
atomic_set_bit(adv->flags, BT_PER_ADV_CTE_PARAMS_SET);
318+
279319
return 0;
280320
}
321+
322+
static int bt_df_set_adv_cte_tx_enabled(struct bt_le_ext_adv *adv, bool enable)
323+
{
324+
if (!atomic_test_bit(adv->flags, BT_PER_ADV_PARAMS_SET)) {
325+
return -EINVAL;
326+
}
327+
328+
if (!atomic_test_bit(adv->flags, BT_PER_ADV_CTE_PARAMS_SET)) {
329+
return -EINVAL;
330+
}
331+
332+
if (enable == atomic_test_bit(adv->flags, BT_PER_ADV_CTE_ENABLED)) {
333+
return -EALREADY;
334+
}
335+
336+
return hci_df_set_adv_cte_tx_enable(adv, enable);
337+
}
338+
339+
int bt_df_adv_cte_tx_enable(struct bt_le_ext_adv *adv)
340+
{
341+
__ASSERT_NO_MSG(adv);
342+
return bt_df_set_adv_cte_tx_enabled(adv, true);
343+
}
344+
345+
int bt_df_adv_cte_tx_disable(struct bt_le_ext_adv *adv)
346+
{
347+
__ASSERT_NO_MSG(adv);
348+
return bt_df_set_adv_cte_tx_enabled(adv, false);
349+
}

subsys/bluetooth/host/hci_core.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,14 @@ enum {
105105
BT_PER_ADV_ENABLED,
106106
/* Periodic Advertising parameters has been set in the controller. */
107107
BT_PER_ADV_PARAMS_SET,
108+
/* Constant Tone Extension parameters for Periodic Advertising
109+
* has been set in the controller.
110+
*/
111+
BT_PER_ADV_CTE_PARAMS_SET,
112+
/* Constant Tone Extension for Periodic Advertising has been enabled
113+
* in the controller.
114+
*/
115+
BT_PER_ADV_CTE_ENABLED,
108116

109117
BT_ADV_NUM_FLAGS,
110118
};

0 commit comments

Comments
 (0)