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 <piotr.pryga@nordicsemi.no>
This commit is contained in:
parent
fac2c22824
commit
61872da64e
4 changed files with 123 additions and 3 deletions
|
@ -142,6 +142,7 @@ struct bt_df_conn_iq_samples_report {
|
||||||
/** Pinter to IQ samples data. */
|
/** Pinter to IQ samples data. */
|
||||||
struct bt_hci_le_iq_sample const *sample;
|
struct bt_hci_le_iq_sample const *sample;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set or update the Constant Tone Extension parameters for periodic advertising set.
|
* @brief Set or update the Constant Tone Extension parameters for periodic advertising set.
|
||||||
*
|
*
|
||||||
|
@ -217,4 +218,26 @@ int bt_df_conn_cte_rx_enable(struct bt_conn *conn, const struct bt_df_conn_cte_r
|
||||||
*/
|
*/
|
||||||
int bt_df_conn_cte_rx_disable(struct bt_conn *conn);
|
int bt_df_conn_cte_rx_disable(struct bt_conn *conn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Enable Constant Tone Extension response procedure for a connection.
|
||||||
|
*
|
||||||
|
* The function is available if @kconfig{CONFIG_BT_DF_CONNECTION_CTE_RSP} is enabled.
|
||||||
|
*
|
||||||
|
* @param conn Connection object.
|
||||||
|
*
|
||||||
|
* @return Zero in case of success, other value in case of failure.
|
||||||
|
*/
|
||||||
|
int bt_df_conn_cte_rsp_enable(struct bt_conn *conn);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief Disable Constant Tone Extension response procedure for a connection.
|
||||||
|
*
|
||||||
|
* The function is available if @kconfig{CONFIG_BT_DF_CONNECTION_CTE_RSP} is enabled.
|
||||||
|
*
|
||||||
|
* @param conn Connection object.
|
||||||
|
*
|
||||||
|
* @return Zero in case of success, other value in case of failure.
|
||||||
|
*/
|
||||||
|
int bt_df_conn_cte_rsp_disable(struct bt_conn *conn);
|
||||||
|
|
||||||
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_DF_H_ */
|
#endif /* ZEPHYR_INCLUDE_BLUETOOTH_DF_H_ */
|
||||||
|
|
|
@ -546,26 +546,39 @@ config BT_DF
|
||||||
It will allow to: get information about antennae, configure
|
It will allow to: get information about antennae, configure
|
||||||
Constant Tone Extension, transmit CTE and sample incoming CTE.
|
Constant Tone Extension, transmit CTE and sample incoming CTE.
|
||||||
|
|
||||||
|
if BT_DF
|
||||||
|
|
||||||
config BT_DF_CONNECTIONLESS_CTE_RX
|
config BT_DF_CONNECTIONLESS_CTE_RX
|
||||||
bool "Enable support for receive of CTE in connectionless mode"
|
bool "Enable support for receive of CTE in connectionless mode"
|
||||||
depends on BT_DF
|
|
||||||
help
|
help
|
||||||
Enable support for reception and sampling of Constant Tone Extension
|
Enable support for reception and sampling of Constant Tone Extension
|
||||||
in connectionless mode.
|
in connectionless mode.
|
||||||
|
|
||||||
config BT_DF_CONNECTION_CTE_RX
|
config BT_DF_CONNECTION_CTE_RX
|
||||||
bool "Enable support for receive of CTE in connection mode"
|
bool "Enable support for receive of CTE in connection mode"
|
||||||
depends on BT_DF
|
|
||||||
help
|
help
|
||||||
Enable support for reception and sampling of Constant Tone Extension
|
Enable support for reception and sampling of Constant Tone Extension
|
||||||
in connection mode.
|
in connection mode.
|
||||||
|
|
||||||
|
config BT_DF_CONNECTION_CTE_TX
|
||||||
|
bool "Enable support for transmission of CTE in connection mode"
|
||||||
|
help
|
||||||
|
Enable support for transmission of Constant Tone Extension in
|
||||||
|
connection mode.
|
||||||
|
|
||||||
|
config BT_DF_CONNECTION_CTE_RSP
|
||||||
|
bool "Enable support for CTE request procedure in connection mode"
|
||||||
|
depends on BT_DF_CONNECTION_CTE_TX
|
||||||
|
help
|
||||||
|
Enable support for request of Constant Tone Extension in connection
|
||||||
|
mode.
|
||||||
|
|
||||||
config BT_DEBUG_DF
|
config BT_DEBUG_DF
|
||||||
bool "Bluetooth Direction Finding debug"
|
bool "Bluetooth Direction Finding debug"
|
||||||
depends on BT_DF
|
|
||||||
help
|
help
|
||||||
This option enables debug support for Bluetooth Direction Finding
|
This option enables debug support for Bluetooth Direction Finding
|
||||||
|
|
||||||
|
endif # BT_DF
|
||||||
endif # BT_HCI_HOST
|
endif # BT_HCI_HOST
|
||||||
|
|
||||||
config BT_ECC
|
config BT_ECC
|
||||||
|
|
|
@ -44,6 +44,8 @@ enum {
|
||||||
BT_CONN_AUTO_DATA_LEN_COMPLETE,
|
BT_CONN_AUTO_DATA_LEN_COMPLETE,
|
||||||
|
|
||||||
BT_CONN_CTE_RX_ENABLED, /* CTE receive and sampling is enabled */
|
BT_CONN_CTE_RX_ENABLED, /* CTE receive and sampling is enabled */
|
||||||
|
BT_CONN_CTE_TX_PARAMS_SET, /* CTE transmission parameters are set */
|
||||||
|
BT_CONN_CTE_RSP_ENABLED, /* CTE response procedure is enabled */
|
||||||
|
|
||||||
/* Total number of flags - must be at the end of the enum */
|
/* Total number of flags - must be at the end of the enum */
|
||||||
BT_CONN_NUM_FLAGS,
|
BT_CONN_NUM_FLAGS,
|
||||||
|
|
|
@ -593,6 +593,52 @@ int hci_df_prepare_connection_iq_report(struct net_buf *buf,
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
|
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
|
||||||
|
|
||||||
|
#if defined(CONFIG_BT_DF_CONNECTION_CTE_RSP)
|
||||||
|
static void prepare_conn_cte_rsp_enable_cmd_params(struct net_buf *buf, const struct bt_conn *conn,
|
||||||
|
bool enable)
|
||||||
|
{
|
||||||
|
struct bt_hci_cp_le_conn_cte_rsp_enable *cp;
|
||||||
|
|
||||||
|
cp = net_buf_add(buf, sizeof(*cp));
|
||||||
|
(void)memset(cp, 0, sizeof(*cp));
|
||||||
|
|
||||||
|
cp->handle = sys_cpu_to_le16(conn->handle);
|
||||||
|
cp->enable = enable ? 1U : 0U;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int hci_df_set_conn_cte_rsp_enable(struct bt_conn *conn, bool enable)
|
||||||
|
{
|
||||||
|
struct bt_hci_rp_le_conn_cte_rsp_enable *rp;
|
||||||
|
struct bt_hci_cmd_state_set state;
|
||||||
|
struct net_buf *buf, *rsp;
|
||||||
|
int err;
|
||||||
|
|
||||||
|
buf = bt_hci_cmd_create(BT_HCI_OP_LE_CONN_CTE_RSP_ENABLE,
|
||||||
|
sizeof(struct bt_hci_cp_le_conn_cte_rsp_enable));
|
||||||
|
if (!buf) {
|
||||||
|
return -ENOBUFS;
|
||||||
|
}
|
||||||
|
|
||||||
|
prepare_conn_cte_rsp_enable_cmd_params(buf, conn, enable);
|
||||||
|
|
||||||
|
bt_hci_cmd_state_set_init(buf, &state, conn->flags, BT_CONN_CTE_RSP_ENABLED, enable);
|
||||||
|
|
||||||
|
err = bt_hci_cmd_send_sync(BT_HCI_OP_LE_CONN_CTE_RSP_ENABLE, buf, &rsp);
|
||||||
|
if (err) {
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
rp = (void *)rsp->data;
|
||||||
|
if (conn->handle != sys_le16_to_cpu(rp->handle)) {
|
||||||
|
err = -EIO;
|
||||||
|
}
|
||||||
|
|
||||||
|
net_buf_unref(rsp);
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RSP */
|
||||||
|
|
||||||
/* @brief Function initializes Direction Finding in Host
|
/* @brief Function initializes Direction Finding in Host
|
||||||
*
|
*
|
||||||
* @return Zero in case of success, other value in case of failure.
|
* @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)
|
||||||
return bt_df_set_conn_cte_rx_enable(conn, false, NULL);
|
return bt_df_set_conn_cte_rx_enable(conn, false, NULL);
|
||||||
}
|
}
|
||||||
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
|
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
|
||||||
|
|
||||||
|
#if defined(CONFIG_BT_DF_CONNECTION_CTE_RSP)
|
||||||
|
static int bt_df_set_conn_cte_rsp_enable(struct bt_conn *conn, bool enable)
|
||||||
|
{
|
||||||
|
CHECKIF(!conn) {
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!BT_FEAT_LE_CONNECTION_CTE_RESP(bt_dev.le.features)) {
|
||||||
|
BT_WARN("CTE response procedure is not supported");
|
||||||
|
return -ENOTSUP;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (conn->state != BT_CONN_CONNECTED) {
|
||||||
|
BT_ERR("not connected");
|
||||||
|
return -ENOTCONN;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!atomic_test_bit(conn->flags, BT_CONN_CTE_TX_PARAMS_SET)) {
|
||||||
|
BT_ERR("Can't start CTE response procedure before CTE TX params setup");
|
||||||
|
return -EINVAL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hci_df_set_conn_cte_rsp_enable(conn, enable);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bt_df_conn_cte_rsp_enable(struct bt_conn *conn)
|
||||||
|
{
|
||||||
|
return bt_df_set_conn_cte_rsp_enable(conn, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
int bt_df_conn_cte_rsp_disable(struct bt_conn *conn)
|
||||||
|
{
|
||||||
|
return bt_df_set_conn_cte_rsp_enable(conn, false);
|
||||||
|
}
|
||||||
|
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RSP */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue