Skip to content

Commit 61872da

Browse files
ppryga-nordicjhedberg
authored andcommitted
Bluetooth: host: Add API to run conn CTE response HCI command
Add host API to allow execution of HCI_LE_Connection_CTE_Response_- Enable HCI command. Signed-off-by: Piotr Pryga <[email protected]>
1 parent fac2c22 commit 61872da

File tree

4 files changed

+123
-3
lines changed

4 files changed

+123
-3
lines changed

include/bluetooth/direction.h

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ struct bt_df_conn_iq_samples_report {
142142
/** Pinter to IQ samples data. */
143143
struct bt_hci_le_iq_sample const *sample;
144144
};
145+
145146
/**
146147
* @brief Set or update the Constant Tone Extension parameters for periodic advertising set.
147148
*
@@ -217,4 +218,26 @@ int bt_df_conn_cte_rx_enable(struct bt_conn *conn, const struct bt_df_conn_cte_r
217218
*/
218219
int bt_df_conn_cte_rx_disable(struct bt_conn *conn);
219220

221+
/**
222+
* @brief Enable Constant Tone Extension response procedure for a connection.
223+
*
224+
* The function is available if @kconfig{CONFIG_BT_DF_CONNECTION_CTE_RSP} is enabled.
225+
*
226+
* @param conn Connection object.
227+
*
228+
* @return Zero in case of success, other value in case of failure.
229+
*/
230+
int bt_df_conn_cte_rsp_enable(struct bt_conn *conn);
231+
232+
/**
233+
* @brief Disable Constant Tone Extension response procedure for a connection.
234+
*
235+
* The function is available if @kconfig{CONFIG_BT_DF_CONNECTION_CTE_RSP} is enabled.
236+
*
237+
* @param conn Connection object.
238+
*
239+
* @return Zero in case of success, other value in case of failure.
240+
*/
241+
int bt_df_conn_cte_rsp_disable(struct bt_conn *conn);
242+
220243
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_DF_H_ */

subsys/bluetooth/host/Kconfig

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -546,26 +546,39 @@ config BT_DF
546546
It will allow to: get information about antennae, configure
547547
Constant Tone Extension, transmit CTE and sample incoming CTE.
548548

549+
if BT_DF
550+
549551
config BT_DF_CONNECTIONLESS_CTE_RX
550552
bool "Enable support for receive of CTE in connectionless mode"
551-
depends on BT_DF
552553
help
553554
Enable support for reception and sampling of Constant Tone Extension
554555
in connectionless mode.
555556

556557
config BT_DF_CONNECTION_CTE_RX
557558
bool "Enable support for receive of CTE in connection mode"
558-
depends on BT_DF
559559
help
560560
Enable support for reception and sampling of Constant Tone Extension
561561
in connection mode.
562562

563+
config BT_DF_CONNECTION_CTE_TX
564+
bool "Enable support for transmission of CTE in connection mode"
565+
help
566+
Enable support for transmission of Constant Tone Extension in
567+
connection mode.
568+
569+
config BT_DF_CONNECTION_CTE_RSP
570+
bool "Enable support for CTE request procedure in connection mode"
571+
depends on BT_DF_CONNECTION_CTE_TX
572+
help
573+
Enable support for request of Constant Tone Extension in connection
574+
mode.
575+
563576
config BT_DEBUG_DF
564577
bool "Bluetooth Direction Finding debug"
565-
depends on BT_DF
566578
help
567579
This option enables debug support for Bluetooth Direction Finding
568580

581+
endif # BT_DF
569582
endif # BT_HCI_HOST
570583

571584
config BT_ECC

subsys/bluetooth/host/conn_internal.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ enum {
4444
BT_CONN_AUTO_DATA_LEN_COMPLETE,
4545

4646
BT_CONN_CTE_RX_ENABLED, /* CTE receive and sampling is enabled */
47+
BT_CONN_CTE_TX_PARAMS_SET, /* CTE transmission parameters are set */
48+
BT_CONN_CTE_RSP_ENABLED, /* CTE response procedure is enabled */
4749

4850
/* Total number of flags - must be at the end of the enum */
4951
BT_CONN_NUM_FLAGS,

subsys/bluetooth/host/direction.c

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -593,6 +593,52 @@ int hci_df_prepare_connection_iq_report(struct net_buf *buf,
593593
}
594594
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
595595

596+
#if defined(CONFIG_BT_DF_CONNECTION_CTE_RSP)
597+
static void prepare_conn_cte_rsp_enable_cmd_params(struct net_buf *buf, const struct bt_conn *conn,
598+
bool enable)
599+
{
600+
struct bt_hci_cp_le_conn_cte_rsp_enable *cp;
601+
602+
cp = net_buf_add(buf, sizeof(*cp));
603+
(void)memset(cp, 0, sizeof(*cp));
604+
605+
cp->handle = sys_cpu_to_le16(conn->handle);
606+
cp->enable = enable ? 1U : 0U;
607+
}
608+
609+
static int hci_df_set_conn_cte_rsp_enable(struct bt_conn *conn, bool enable)
610+
{
611+
struct bt_hci_rp_le_conn_cte_rsp_enable *rp;
612+
struct bt_hci_cmd_state_set state;
613+
struct net_buf *buf, *rsp;
614+
int err;
615+
616+
buf = bt_hci_cmd_create(BT_HCI_OP_LE_CONN_CTE_RSP_ENABLE,
617+
sizeof(struct bt_hci_cp_le_conn_cte_rsp_enable));
618+
if (!buf) {
619+
return -ENOBUFS;
620+
}
621+
622+
prepare_conn_cte_rsp_enable_cmd_params(buf, conn, enable);
623+
624+
bt_hci_cmd_state_set_init(buf, &state, conn->flags, BT_CONN_CTE_RSP_ENABLED, enable);
625+
626+
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_CONN_CTE_RSP_ENABLE, buf, &rsp);
627+
if (err) {
628+
return err;
629+
}
630+
631+
rp = (void *)rsp->data;
632+
if (conn->handle != sys_le16_to_cpu(rp->handle)) {
633+
err = -EIO;
634+
}
635+
636+
net_buf_unref(rsp);
637+
638+
return err;
639+
}
640+
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RSP */
641+
596642
/* @brief Function initializes Direction Finding in Host
597643
*
598644
* @return Zero in case of success, other value in case of failure.
@@ -767,3 +813,39 @@ int bt_df_conn_cte_rx_disable(struct bt_conn *conn)
767813
return bt_df_set_conn_cte_rx_enable(conn, false, NULL);
768814
}
769815
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
816+
817+
#if defined(CONFIG_BT_DF_CONNECTION_CTE_RSP)
818+
static int bt_df_set_conn_cte_rsp_enable(struct bt_conn *conn, bool enable)
819+
{
820+
CHECKIF(!conn) {
821+
return -EINVAL;
822+
}
823+
824+
if (!BT_FEAT_LE_CONNECTION_CTE_RESP(bt_dev.le.features)) {
825+
BT_WARN("CTE response procedure is not supported");
826+
return -ENOTSUP;
827+
}
828+
829+
if (conn->state != BT_CONN_CONNECTED) {
830+
BT_ERR("not connected");
831+
return -ENOTCONN;
832+
}
833+
834+
if (!atomic_test_bit(conn->flags, BT_CONN_CTE_TX_PARAMS_SET)) {
835+
BT_ERR("Can't start CTE response procedure before CTE TX params setup");
836+
return -EINVAL;
837+
}
838+
839+
return hci_df_set_conn_cte_rsp_enable(conn, enable);
840+
}
841+
842+
int bt_df_conn_cte_rsp_enable(struct bt_conn *conn)
843+
{
844+
return bt_df_set_conn_cte_rsp_enable(conn, true);
845+
}
846+
847+
int bt_df_conn_cte_rsp_disable(struct bt_conn *conn)
848+
{
849+
return bt_df_set_conn_cte_rsp_enable(conn, false);
850+
}
851+
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RSP */

0 commit comments

Comments
 (0)