Bluetooth: host: Align usage of cte_type in DF host implementation

The CTE type is used in two ways by HCI layer:
1) single value representing particular CTE type: AoA, AoD 1 us,
  AoD 2 us
2) bit-filed where bits 0-2 represent particular CTE types AoA
  AoD 1 us, AoD 2 us

The bit-field is used to inform Controller about allowed types
of CTE, hence single value carries more than one value.
To avoid confusion between these use cases in code that refers
to case 1) all named cte_type (singular form). For case 2)
cte_types (plural form) is used.

There is an enumeration that is used for both cases:
bt_df_cte_type. For cte_type only single value from the
enumeration may be assigned to variable except
BT_DF_CTE_TYPE_NONE and BT_DF_CTE_TYPE_ALL.
For cte_types all enum members may be used. Ocasionally
BT_DF_CTE_TYPE_NONE may be excluded. If that is true,
it is described in code documentation.

Thanks to that applications are released from requirement
to include hci.h header file.

Signed-off-by: Piotr Pryga <piotr.pryga@nordicsemi.no>
This commit is contained in:
Piotr Pryga 2021-12-28 22:17:20 +01:00 committed by Carles Cufí
parent b76b5750ee
commit 3b5c1efc16
6 changed files with 53 additions and 35 deletions

View file

@ -61,7 +61,12 @@ enum bt_df_packet_status {
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. */
/**
* @brief CTE type.
*
* Allowed values are defined by @ref bt_df_cte_type, except BT_DF_CTE_TYPE_NONE and
* BT_DF_CTE_TYPE_ALL.
*/
uint8_t cte_type;
/** Number of CTE to transmit in each periodic adv interval. */
uint8_t cte_count;
@ -80,8 +85,12 @@ struct bt_df_adv_cte_tx_param {
* for correctness.
*/
struct bt_df_per_adv_sync_cte_rx_param {
/* Bitmap with allowed CTE types (@ref bt_df_cte_type). */
uint8_t cte_type;
/**
* @brief Bitfield with allowed CTE types.
*
* Allowed values are defined by @ref bt_df_cte_type, except BT_DF_CTE_TYPE_NONE.
*/
uint8_t cte_types;
/** Antenna switching slots (@ref bt_df_antenna_switching_slot). */
uint8_t slot_durations;
/** Max number of CTEs to receive. Min is 1, max is 10, 0 means receive continuously. */
@ -114,8 +123,12 @@ struct bt_df_per_adv_sync_iq_samples_report {
};
struct bt_df_conn_cte_rx_param {
/* Bitmap with allowed CTE types (@ref bt_df_cte_type). */
uint8_t cte_type;
/**
* @brief Bitfield with allowed CTE types.
*
* Allowed values are defined by @ref bt_df_cte_type, except BT_DF_CTE_TYPE_NONE.
*/
uint8_t cte_types;
/** Antenna switching slots (@ref bt_df_antenna_switching_slot). */
uint8_t slot_durations;
/** Length of antenna switch pattern. */

View file

@ -13,7 +13,6 @@
#include <sys/util.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/direction.h>
#define DEVICE_NAME CONFIG_BT_DEVICE_NAME
@ -244,12 +243,12 @@ static void enable_cte_rx(void)
const struct bt_df_per_adv_sync_cte_rx_param cte_rx_params = {
.max_cte_count = 5,
#if defined(CONFIG_BT_CTLR_DF_ANT_SWITCH_RX)
.cte_type = BT_DF_CTE_TYPE_ALL,
.cte_types = BT_DF_CTE_TYPE_ALL,
.slot_durations = 0x2,
.num_ant_ids = ARRAY_SIZE(ant_patterns),
.ant_ids = ant_patterns,
#else
.cte_type = BT_DF_CTE_TYPE_AOD_1US | BT_DF_CTE_TYPE_AOD_2US,
.cte_types = BT_DF_CTE_TYPE_AOD_1US | BT_DF_CTE_TYPE_AOD_2US,
#endif /* CONFIG_BT_CTLR_DF_ANT_SWITCH_RX */
};

View file

@ -11,7 +11,6 @@
#include <sys/printk.h>
#include <bluetooth/bluetooth.h>
#include <bluetooth/hci.h>
#include <bluetooth/direction.h>
#include <sys/byteorder.h>
#include <sys/util.h>
@ -55,11 +54,11 @@ static uint8_t ant_patterns[] = {0x1, 0x2, 0x3, 0x4, 0x5, 0x6, 0x7, 0x8, 0x9, 0x
struct bt_df_adv_cte_tx_param cte_params = { .cte_len = CTE_LEN,
.cte_count = PER_ADV_EVENT_CTE_COUNT,
#if defined(CONFIG_BT_CTLR_DF_ANT_SWITCH_TX)
.cte_type = BT_HCI_LE_AOD_CTE_2US,
.cte_type = BT_DF_CTE_TYPE_AOD_2US,
.num_ant_ids = ARRAY_SIZE(ant_patterns),
.ant_ids = ant_patterns
#else
.cte_type = BT_HCI_LE_AOA_CTE,
.cte_type = BT_DF_CTE_TYPE_AOA,
.num_ant_ids = 0,
.ant_ids = NULL
#endif /* CONFIG_BT_CTLR_DF_ANT_SWITCH_TX */

View file

@ -169,8 +169,12 @@ struct bt_conn {
#endif /* CONFIG_BT_SMP || CONFIG_BT_BREDR */
#if defined(CONFIG_BT_DF_CONNECTION_CTE_RX)
/** Accepted CTE type */
uint8_t cte_type;
/**
* @brief Bitfield with allowed CTE types.
*
* Allowed values are defined by @ref bt_df_cte_type, except BT_DF_CTE_TYPE_NONE.
*/
uint8_t cte_types;
#endif /* CONFIG_BT_DF_CONNECTION_CTE_RX */
/* Connection error or reason for disconnect */

View file

@ -47,7 +47,7 @@ const static uint8_t df_dummy_switch_pattern[BT_HCI_LE_SWITCH_PATTERN_LEN_MIN] =
#define DF_SAMPLING_ANTENNA_NUMBER_MIN 0x2
#if defined(CONFIG_BT_DF_CONNECTIONLESS_CTE_RX) || defined(CONFIG_BT_DF_CONNECTION_CTE_RX)
static bool validate_cte_rx_common_params(uint8_t cte_type, uint8_t slot_durations,
static bool validate_cte_rx_common_params(uint8_t cte_types, uint8_t slot_durations,
uint8_t num_ant_ids, const uint8_t *ant_ids);
#endif /* CONFIG_BT_DF_CONNECTIONLESS_CTE_RX || CONFIG_BT_DF_CONNECTION_CTE_RX */
@ -93,14 +93,13 @@ static int hci_df_set_cl_cte_tx_params(const struct bt_le_ext_adv *adv,
/* If AoD is not enabled, ant_ids are ignored by controller:
* BT Core spec 5.2 Vol 4, Part E sec. 7.8.80.
*/
if (params->cte_type == BT_HCI_LE_AOD_CTE_1US ||
params->cte_type == BT_HCI_LE_AOD_CTE_2US) {
if (params->cte_type == BT_DF_CTE_TYPE_AOD_1US ||
params->cte_type == BT_DF_CTE_TYPE_AOD_2US) {
if (!BT_FEAT_LE_ANT_SWITCH_TX_AOD(bt_dev.le.features)) {
return -EINVAL;
}
if (params->cte_type == BT_HCI_LE_AOD_CTE_1US &&
if (params->cte_type == BT_DF_CTE_TYPE_AOD_1US &&
!DF_AOD_TX_1US_SUPPORT(df_ant_info.switch_sample_rates)) {
return -EINVAL;
}
@ -110,7 +109,7 @@ static int hci_df_set_cl_cte_tx_params(const struct bt_le_ext_adv *adv,
!params->ant_ids) {
return -EINVAL;
}
} else if (params->cte_type != BT_HCI_LE_AOA_CTE) {
} else if (params->cte_type != BT_DF_CTE_TYPE_AOA) {
return -EINVAL;
}
@ -133,7 +132,7 @@ static int hci_df_set_cl_cte_tx_params(const struct bt_le_ext_adv *adv,
cp = net_buf_add(buf, sizeof(*cp));
cp->handle = adv->handle;
cp->cte_len = params->cte_len;
cp->cte_type = params->cte_type;
cp->cte_type = get_hci_cte_type(params->cte_type);
cp->cte_count = params->cte_count;
if (params->num_ant_ids) {
@ -230,14 +229,14 @@ static int hci_df_set_adv_cte_tx_enable(struct bt_le_ext_adv *adv,
}
#if defined(CONFIG_BT_DF_CONNECTIONLESS_CTE_RX) || defined(CONFIG_BT_DF_CONNECTION_CTE_RX)
static bool validate_cte_rx_common_params(uint8_t cte_type, uint8_t slot_durations,
static bool validate_cte_rx_common_params(uint8_t cte_types, uint8_t slot_durations,
uint8_t num_ant_ids, const uint8_t *ant_ids)
{
if (!(cte_type & (BT_DF_CTE_TYPE_AOA | BT_DF_CTE_TYPE_AOD_1US | BT_DF_CTE_TYPE_AOD_2US))) {
if (!(cte_types & BT_DF_CTE_TYPE_ALL)) {
return false;
}
if (cte_type & BT_DF_CTE_TYPE_AOA) {
if (cte_types & BT_DF_CTE_TYPE_AOA) {
if (df_ant_info.num_ant < DF_SAMPLING_ANTENNA_NUMBER_MIN ||
!BT_FEAT_LE_ANT_SWITCH_RX_AOA(bt_dev.le.features)) {
return false;
@ -266,8 +265,8 @@ static bool validate_cl_cte_rx_params(const struct bt_df_per_adv_sync_cte_rx_par
return false;
}
if (params->cte_type & BT_DF_CTE_TYPE_AOA) {
return validate_cte_rx_common_params(params->cte_type, params->slot_durations,
if (params->cte_types & BT_DF_CTE_TYPE_AOA) {
return validate_cte_rx_common_params(params->cte_types, params->slot_durations,
params->num_ant_ids, params->ant_ids);
}
@ -293,7 +292,7 @@ prepare_cl_cte_rx_enable_cmd_params(struct net_buf *buf, struct bt_le_per_adv_sy
cp->max_sampled_cte = params->max_cte_count;
if (params->cte_type & BT_DF_CTE_TYPE_AOA) {
if (params->cte_types & BT_DF_CTE_TYPE_AOA) {
cp->slot_durations = params->slot_durations;
cp->switch_pattern_len = params->num_ant_ids;
ant_ids = params->ant_ids;
@ -350,7 +349,7 @@ static int hci_df_set_cl_cte_rx_enable(struct bt_le_per_adv_sync *sync, bool ena
if (sync->handle != sys_le16_to_cpu(rp->sync_handle)) {
err = -EIO;
} else {
sync->cte_type = (enable ? params->cte_type : 0);
sync->cte_types = (enable ? params->cte_types : 0);
}
net_buf_unref(rsp);
@ -385,7 +384,7 @@ void hci_df_prepare_connectionless_iq_report(struct net_buf *buf,
return;
}
if (!(per_adv_sync->cte_type & BIT(evt->cte_type))) {
if (!(per_adv_sync->cte_types & BIT(evt->cte_type))) {
BT_DBG("CTE filtered out by cte_type: %u", evt->cte_type);
return;
}
@ -520,7 +519,7 @@ static void prepare_conn_cte_rx_enable_cmd_params(struct net_buf *buf, struct bt
if (enable) {
uint8_t *dest_ant_ids;
if (params->cte_type & BT_DF_CTE_TYPE_AOA) {
if (params->cte_types & BT_DF_CTE_TYPE_AOA) {
cp->slot_durations = params->slot_durations;
cp->switch_pattern_len = params->num_ant_ids;
ant_ids = params->ant_ids;
@ -549,7 +548,7 @@ static int hci_df_set_conn_cte_rx_enable(struct bt_conn *conn, bool enable,
int err;
if (enable) {
if (!validate_cte_rx_common_params(params->cte_type, params->slot_durations,
if (!validate_cte_rx_common_params(params->cte_types, params->slot_durations,
params->num_ant_ids, params->ant_ids)) {
return -EINVAL;
}
@ -578,7 +577,7 @@ static int hci_df_set_conn_cte_rx_enable(struct bt_conn *conn, bool enable,
if (conn->handle != sys_le16_to_cpu(rp->handle)) {
err = -EIO;
} else {
conn->cte_type = (enable ? params->cte_type : 0);
conn->cte_types = (enable ? params->cte_types : 0);
/* This flag is set once for connection object. It is never cleared because CTE RX
* params must be set at least once for connection object to successfully execute
* CTE REQ procedure.
@ -618,7 +617,7 @@ int hci_df_prepare_connection_iq_report(struct net_buf *buf,
return -EINVAL;
}
if (!(conn->cte_type & BIT(evt->cte_type))) {
if (!(conn->cte_types & BIT(evt->cte_type))) {
BT_DBG("CTE filtered out by cte_type: %u", evt->cte_type);
return -EINVAL;
}
@ -645,7 +644,7 @@ int hci_df_prepare_connection_iq_report(struct net_buf *buf,
static bool valid_cte_req_params(const struct bt_conn *conn, uint8_t cte_type,
uint8_t cte_length)
{
if (!(conn->cte_type & cte_type)) {
if (!(conn->cte_types & cte_type)) {
return false;
}

View file

@ -198,8 +198,12 @@ struct bt_le_per_adv_sync {
uint8_t phy;
#if defined(CONFIG_BT_DF_CONNECTIONLESS_CTE_RX)
/** Accepted CTE type */
uint8_t cte_type;
/**
* @brief Bitfield with allowed CTE types.
*
* Allowed values are defined by @ref bt_df_cte_type, except BT_DF_CTE_TYPE_NONE.
*/
uint8_t cte_types;
#endif /* CONFIG_BT_DF_CONNECTIONLESS_CTE_RX */
#if CONFIG_BT_PER_ADV_SYNC_BUF_SIZE > 0