Skip to content

Commit

Permalink
[nrf fromtree] bluetooth: host: CS support for remote capabilities an…
Browse files Browse the repository at this point in the history
…d FAE table

Adds HCI support for:
- LE CS Read Remote Supported Capabilities
- LE CS Read Remote FAE Table

Callbacks have been added to the conn object to allow upper layers to
make use of the cache commands, with which it will be possible to store
this information and provide it again in the case of a disconnect
and reconnect to the same device.

Upstream PR: zephyrproject-rtos/zephyr#78455

Signed-off-by: Olivier Lesage <olivier.lesage@nordicsemi.no>
  • Loading branch information
olivier-le-sage authored and bjarki-andreasen committed Sep 27, 2024
1 parent 76105ee commit f398ec0
Show file tree
Hide file tree
Showing 10 changed files with 680 additions and 0 deletions.
175 changes: 175 additions & 0 deletions include/zephyr/bluetooth/conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,157 @@ enum __packed bt_conn_type {
BT_CONN_TYPE_SCO | BT_CONN_TYPE_ISO,
};

/** Supported AA-Only RTT precision. */
enum bt_conn_le_cs_capability_rtt_aa_only {
/** AA-Only RTT variant is not supported. */
BT_CONN_LE_CS_RTT_AA_ONLY_NOT_SUPP = 0,
/** 10ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_AA_ONLY_10NS,
/** 150ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_AA_ONLY_150NS,
};

/** Supported Sounding Sequence RTT precision. */
enum bt_conn_le_cs_capability_rtt_sounding {
/** Sounding Sequence RTT variant is not supported. */
BT_CONN_LE_CS_RTT_SOUNDING_NOT_SUPP = 0,
/** 10ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_SOUNDING_10NS,
/** 150ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_SOUNDING_150NS,
};

/** Supported Random Payload RTT precision. */
enum bt_conn_le_cs_capability_rtt_random_payload {
/** Random Payload RTT variant is not supported. */
BT_CONN_LE_CS_RTT_RANDOM_PAYLOAD_NOT_SUPP = 0,
/** 10ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_RANDOM_PAYLOAD_10NS,
/** 150ns time-of-flight accuracy. */
BT_CONN_LE_CS_RTT_RANDOM_PAYLOAD_150NS,
};

/** Remote channel sounding capabilities for LE connections supporting CS */
struct bt_conn_le_cs_capabilities {
/** Number of CS configurations */
uint8_t num_config_supported;
/** Maximum number of consecutive CS procedures.
*
* When set to zero, indicates support for both fixed and indefinite
* numbers of CS procedures before termination.
*/
uint16_t max_consecutive_procedures_supported;
/** Number of antennas. */
uint8_t num_antennas_supported;
/** Maximum number of antenna paths. */
uint8_t max_antenna_paths_supported;
/** Initiator role. */
bool initiator_supported;
/** Reflector role. */
bool reflector_supported;
/** Mode-3 */
bool mode_3_supported;
/** RTT AA-Only */
enum bt_conn_le_cs_capability_rtt_aa_only rtt_aa_only_precision;
/** RTT Sounding */
enum bt_conn_le_cs_capability_rtt_sounding rtt_sounding_precision;
/** RTT Random Payload */
enum bt_conn_le_cs_capability_rtt_random_payload rtt_random_payload_precision;
/** Number of CS steps needed to achieve the
* accuracy requirements for RTT AA Only.
*
* Set to 0 if RTT AA Only isn't supported.
*/
uint8_t rtt_aa_only_n;
/** Number of CS steps needed to achieve the
* accuracy requirements for RTT Sounding.
*
* Set to 0 if RTT Sounding isn't supported
*/
uint8_t rtt_sounding_n;
/** Number of CS steps needed to achieve the
* accuracy requirements for RTT Random Payload.
*
* Set to 0 if RTT Random Payload isn't supported.
*/
uint8_t rtt_random_payload_n;
/** Phase-based normalized attack detector metric
* when a CS_SYNC with sounding sequence is received.
*/
bool phase_based_nadm_sounding_supported;
/** Phase-based normalized attack detector metric
* when a CS_SYNC with random sequence is received.
*/
bool phase_based_nadm_random_supported;
/** CS_SYNC LE 2M PHY. */
bool cs_sync_2m_phy_supported;
/** CS_SYNC LE 2M 2BT PHY. */
bool cs_sync_2m_2bt_phy_supported;
/** Subfeature: CS with no Frequency Actuation Error. */
bool cs_without_fae_supported;
/** Subfeature: Channel Selection Algorithm #3c */
bool chsel_alg_3c_supported;
/** Subfeature: Phase-based Ranging from RTT sounding sequence. */
bool pbr_from_rtt_sounding_seq_supported;
/** Optional T_IP1 time durations during CS steps.
*
* - Bit 0: 10 us
* - Bit 1: 20 us
* - Bit 2: 30 us
* - Bit 3: 40 us
* - Bit 4: 50 us
* - Bit 5: 60 us
* - Bit 6: 80 us
*/
uint16_t t_ip1_times_supported;
/** Optional T_IP2 time durations during CS steps.
*
* - Bit 0: 10 us
* - Bit 1: 20 us
* - Bit 2: 30 us
* - Bit 3: 40 us
* - Bit 4: 50 us
* - Bit 5: 60 us
* - Bit 6: 80 us
*/
uint16_t t_ip2_times_supported;
/** Optional T_FCS time durations during CS steps.
*
* - Bit 0: 15 us
* - Bit 1: 20 us
* - Bit 2: 30 us
* - Bit 3: 40 us
* - Bit 4: 50 us
* - Bit 5: 60 us
* - Bit 6: 80 us
* - Bit 7: 100 us
* - Bit 8: 120 us
*/
uint16_t t_fcs_times_supported;
/** Optional T_PM time durations during CS steps.
*
* - Bit 0: 10 us
* - Bit 1: 20 us
*/
uint16_t t_pm_times_supported;
/** Time in microseconds for the antenna switch period of the CS tones. */
uint8_t t_sw_time;
/** Supported SNR levels used in RTT packets.
*
* - Bit 0: 18dB
* - Bit 1: 21dB
* - Bit 2: 24dB
* - Bit 3: 27dB
* - Bit 4: 30dB
*/
uint8_t tx_snr_capability;
};

/** Remote FAE Table for LE connections supporting CS */
struct bt_conn_le_cs_fae_table {
uint8_t *remote_fae_table;
};

/** @brief Increment a connection's reference count.
*
* Increment the reference count of a connection object.
Expand Down Expand Up @@ -1359,6 +1510,30 @@ struct bt_conn_cb {
const struct bt_conn_le_subrate_changed *params);
#endif /* CONFIG_BT_SUBRATING */

#if defined(CONFIG_BT_CHANNEL_SOUNDING)
/** @brief LE CS Read Remote Supported Capabilities Complete event.
*
* This callback notifies the application that the remote channel
* sounding capabilities have been received from the peer.
*
* @param conn Connection object.
* @param remote_cs_capabilities Remote Channel Sounding Capabilities.
*/
void (*remote_cs_capabilities_available)(struct bt_conn *conn,
struct bt_conn_le_cs_capabilities *params);

/** @brief LE CS Read Remote FAE Table Complete event.
*
* This callback notifies the application that the remote mode-0
* FAE Table has been received from the peer.
*
* @param conn Connection object.
* @param params FAE Table.
*/
void (*remote_cs_fae_table_available)(struct bt_conn *conn,
struct bt_conn_le_cs_fae_table *params);
#endif

/** @internal Internally used field for list handling */
sys_snode_t _node;
};
Expand Down
27 changes: 27 additions & 0 deletions include/zephyr/bluetooth/cs.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ struct bt_cs_set_default_settings_param {
int8_t max_tx_power;
};


/** @brief Read Remote Supported Capabilities
*
* This command is used to query the CS capabilities that are supported
* by the remote controller.
*
* @note To use this API @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
*
* @param conn Connection Object.
*
* @return Zero on success or (negative) error code on failure.
*/
int bt_cs_read_remote_supported_capabilities(struct bt_conn *conn);

/** @brief Set Channel Sounding default settings.
*
* This command is used to set default Channel Sounding settings for this
Expand All @@ -75,6 +89,19 @@ struct bt_cs_set_default_settings_param {
int bt_cs_set_default_settings(struct bt_conn *conn,
const struct bt_cs_set_default_settings_param *params);

/** @brief Read Remote FAE Table
*
* This command is used to read the per-channel mode-0 Frequency Actuation Error
* table of the remote Controller.
*
* @note To use this API @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
*
* @param conn Connection Object.
*
* @return Zero on success or (negative) error code on failure.
*/
int bt_cs_read_remote_fae_table(struct bt_conn *conn);

#ifdef __cplusplus
}
#endif
Expand Down
109 changes: 109 additions & 0 deletions include/zephyr/bluetooth/hci_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,9 @@ struct bt_hci_cmd_hdr {
#define BT_LE_FEAT_BIT_PAWR_ADVERTISER 43
#define BT_LE_FEAT_BIT_PAWR_SCANNER 44

#define BT_LE_FEAT_BIT_CHANNEL_SOUNDING 46
#define BT_LE_FEAT_BIT_CHANNEL_SOUNDING_HOST 47

#define BT_LE_FEAT_TEST(feat, n) (feat[(n) >> 3] & \
BIT((n) & 7))

Expand Down Expand Up @@ -268,6 +271,10 @@ struct bt_hci_cmd_hdr {
BT_LE_FEAT_BIT_PAWR_ADVERTISER)
#define BT_FEAT_LE_PAWR_SCANNER(feat) BT_LE_FEAT_TEST(feat, \
BT_LE_FEAT_BIT_PAWR_SCANNER)
#define BT_FEAT_LE_CHANNEL_SOUNDING(feat) BT_LE_FEAT_TEST(feat, \
BT_LE_FEAT_BIT_CHANNEL_SOUNDING)
#define BT_FEAT_LE_CHANNEL_SOUNDING_HOST(feat) BT_LE_FEAT_TEST(feat, \
BT_LE_FEAT_BIT_CHANNEL_SOUNDING_HOST)

#define BT_FEAT_LE_CIS(feat) (BT_FEAT_LE_CIS_CENTRAL(feat) | \
BT_FEAT_LE_CIS_PERIPHERAL(feat))
Expand Down Expand Up @@ -2395,6 +2402,12 @@ struct bt_hci_cp_le_tx_test_v4_tx_power {
int8_t tx_power;
} __packed;

#define BT_HCI_OP_LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES BT_OP(BT_OGF_LE, 0x008A) /* 0x208A */

struct bt_hci_cp_le_read_remote_supported_capabilities {
uint16_t handle;
} __packed;

#define BT_HCI_OP_LE_CS_SET_DEFAULT_SETTINGS BT_OP(BT_OGF_LE, 0x008D) /* 0x208D */

#define BT_HCI_OP_LE_CS_INITIATOR_ROLE_MASK BIT(0)
Expand All @@ -2417,6 +2430,12 @@ struct bt_hci_cp_le_cs_set_default_settings {
int8_t max_tx_power;
} __packed;

#define BT_HCI_OP_LE_CS_READ_REMOTE_FAE_TABLE BT_OP(BT_OGF_LE, 0x008E) /* 0x208E */

struct bt_hci_cp_le_read_remote_fae_table {
uint16_t handle;
} __packed;

/* Event definitions */

#define BT_HCI_EVT_UNKNOWN 0x00
Expand Down Expand Up @@ -3151,6 +3170,93 @@ struct bt_hci_evt_le_subrate_change {
uint16_t supervision_timeout;
} __packed;

#define BT_HCI_LE_CS_INITIATOR_ROLE_MASK BIT(0)
#define BT_HCI_LE_CS_REFLECTOR_ROLE_MASK BIT(1)

#define BT_HCI_LE_CS_MODES_SUPPORTED_MODE_3_MASK BIT(0)

#define BT_HCI_LE_CS_RTT_AA_ONLY_N_10NS_MASK BIT(0)
#define BT_HCI_LE_CS_RTT_SOUNDING_N_10NS_MASK BIT(1)
#define BT_HCI_LE_CS_RTT_RANDOM_PAYLOAD_N_10NS_MASK BIT(2)

#define BT_HCI_LE_CS_NADM_SOUNDING_CAPABILITY_PHASE_BASED_MASK BIT(0)
#define BT_HCI_LE_CS_NADM_RANDOM_CAPABILITY_PHASE_BASED_MASK BIT(0)

#define BT_HCI_LE_CS_SYNC_PHYS_2M_MASK BIT(1)
#define BT_HCI_LE_CS_SYNC_PHYS_2M_2BT_MASK BIT(2)

#define BT_HCI_LE_CS_SUBFEATURE_NO_TX_FAE_MASK BIT(1)
#define BT_HCI_LE_CS_SUBFEATURE_CHSEL_ALG_3C_MASK BIT(2)
#define BT_HCI_LE_CS_SUBFEATURE_PBR_FROM_RTT_SOUNDING_SEQ_MASK BIT(3)

#define BT_HCI_LE_CS_T_IP1_TIME_10US_MASK BIT(0)
#define BT_HCI_LE_CS_T_IP1_TIME_20US_MASK BIT(1)
#define BT_HCI_LE_CS_T_IP1_TIME_30US_MASK BIT(2)
#define BT_HCI_LE_CS_T_IP1_TIME_40US_MASK BIT(3)
#define BT_HCI_LE_CS_T_IP1_TIME_50US_MASK BIT(4)
#define BT_HCI_LE_CS_T_IP1_TIME_60US_MASK BIT(5)
#define BT_HCI_LE_CS_T_IP1_TIME_80US_MASK BIT(6)

#define BT_HCI_LE_CS_T_IP2_TIME_10US_MASK BIT(0)
#define BT_HCI_LE_CS_T_IP2_TIME_20US_MASK BIT(1)
#define BT_HCI_LE_CS_T_IP2_TIME_30US_MASK BIT(2)
#define BT_HCI_LE_CS_T_IP2_TIME_40US_MASK BIT(3)
#define BT_HCI_LE_CS_T_IP2_TIME_50US_MASK BIT(4)
#define BT_HCI_LE_CS_T_IP2_TIME_60US_MASK BIT(5)
#define BT_HCI_LE_CS_T_IP2_TIME_80US_MASK BIT(6)

#define BT_HCI_LE_CS_T_FCS_TIME_15US_MASK BIT(0)
#define BT_HCI_LE_CS_T_FCS_TIME_20US_MASK BIT(1)
#define BT_HCI_LE_CS_T_FCS_TIME_30US_MASK BIT(2)
#define BT_HCI_LE_CS_T_FCS_TIME_40US_MASK BIT(3)
#define BT_HCI_LE_CS_T_FCS_TIME_50US_MASK BIT(4)
#define BT_HCI_LE_CS_T_FCS_TIME_60US_MASK BIT(5)
#define BT_HCI_LE_CS_T_FCS_TIME_80US_MASK BIT(6)
#define BT_HCI_LE_CS_T_FCS_TIME_100US_MASK BIT(7)
#define BT_HCI_LE_CS_T_FCS_TIME_1200US_MASK BIT(8)

#define BT_HCI_LE_CS_T_PM_TIME_10US_MASK BIT(0)
#define BT_HCI_LE_CS_T_PM_TIME_20US_MASK BIT(1)

#define BT_HCI_LE_CS_TX_SNR_CAPABILITY_18DB_MASK BIT(0)
#define BT_HCI_LE_CS_TX_SNR_CAPABILITY_21DB_MASK BIT(1)
#define BT_HCI_LE_CS_TX_SNR_CAPABILITY_24DB_MASK BIT(2)
#define BT_HCI_LE_CS_TX_SNR_CAPABILITY_27DB_MASK BIT(3)
#define BT_HCI_LE_CS_TX_SNR_CAPABILITY_30DB_MASK BIT(4)

#define BT_HCI_EVT_LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES_COMPLETE 0x2C
struct bt_hci_evt_le_cs_read_remote_supported_capabilities_complete {
uint8_t status;
uint16_t conn_handle;
uint8_t num_config_supported;
uint16_t max_consecutive_procedures_supported;
uint8_t num_antennas_supported;
uint8_t max_antenna_paths_supported;
uint8_t roles_supported;
uint8_t modes_supported;
uint8_t rtt_capability;
uint8_t rtt_aa_only_n;
uint8_t rtt_sounding_n;
uint8_t rtt_random_payload_n;
uint16_t nadm_sounding_capability;
uint16_t nadm_random_capability;
uint8_t cs_sync_phys_supported;
uint16_t subfeatures_supported;
uint16_t t_ip1_times_supported;
uint16_t t_ip2_times_supported;
uint16_t t_fcs_times_supported;
uint16_t t_pm_times_supported;
uint8_t t_sw_time_supported;
uint8_t tx_snr_capability;
} __packed;

#define BT_HCI_EVT_LE_CS_READ_REMOTE_FAE_TABLE_COMPLETE 0x2D
struct bt_hci_evt_le_cs_read_remote_fae_table_complete {
uint8_t status;
uint16_t conn_handle;
uint8_t remote_fae_table[72];
} __packed;

/* Event mask bits */

#define BT_EVT_BIT(n) (1ULL << (n))
Expand Down Expand Up @@ -3240,6 +3346,9 @@ struct bt_hci_evt_le_subrate_change {
#define BT_EVT_MASK_LE_PER_ADV_RESPONSE_REPORT BT_EVT_BIT(39)
#define BT_EVT_MASK_LE_ENH_CONN_COMPLETE_V2 BT_EVT_BIT(40)

#define BT_EVT_MASK_LE_CS_READ_REMOTE_SUPPORTED_CAPABILITIES_COMPLETE BT_EVT_BIT(43)
#define BT_EVT_MASK_LE_CS_READ_REMOTE_FAE_TABLE_COMPLETE BT_EVT_BIT(44)

/** HCI Error Codes, BT Core Spec v5.4 [Vol 1, Part F]. */
#define BT_HCI_ERR_SUCCESS 0x00
#define BT_HCI_ERR_UNKNOWN_CMD 0x01
Expand Down
Loading

0 comments on commit f398ec0

Please sign in to comment.