Skip to content

Commit 14d8abc

Browse files
committed
bluetooth: host: CS support for various HCI commands
Adds HCI support for: - LE CS Security Enable - LE CS Procedure Enable - LE CS Set Procedure Parameters - LE CS Set Channel Classification - LE CS Read Local Supported Capabilities - LE CS Write Cached Remote Supported Capabilities - LE CS Write Cached Remote FAE Table Signed-off-by: Adam Cavender <[email protected]>
1 parent 0fb63c0 commit 14d8abc

File tree

9 files changed

+1127
-81
lines changed

9 files changed

+1127
-81
lines changed

include/zephyr/bluetooth/conn.h

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1518,6 +1518,86 @@ enum bt_security_err {
15181518
BT_SECURITY_ERR_UNSPECIFIED,
15191519
};
15201520

1521+
enum bt_conn_le_cs_procedure_enable_state {
1522+
BT_CONN_LE_CS_PROCEDURES_DISABLED = BT_HCI_OP_LE_CS_PROCEDURES_DISABLED,
1523+
BT_CONN_LE_CS_PROCEDURES_ENABLED = BT_HCI_OP_LE_CS_PROCEDURES_ENABLED,
1524+
};
1525+
1526+
/** CS Test Tone Antennna Config Selection.
1527+
*
1528+
* These enum values are indices in the following table, where N_AP is the maximum
1529+
* number of antenna paths (in the range [1, 4]).
1530+
*
1531+
* +--------------+-------------+-------------------+-------------------+--------+
1532+
* | Config Index | Total Paths | Dev A: # Antennas | Dev B: # Antennas | Config |
1533+
* +--------------+-------------+-------------------+-------------------+--------+
1534+
* | 0 | 1 | 1 | 1 | 1:1 |
1535+
* | 1 | 2 | 2 | 1 | N_AP:1 |
1536+
* | 2 | 3 | 3 | 1 | N_AP:1 |
1537+
* | 3 | 4 | 4 | 1 | N_AP:1 |
1538+
* | 4 | 2 | 1 | 2 | 1:N_AP |
1539+
* | 5 | 3 | 1 | 3 | 1:N_AP |
1540+
* | 6 | 4 | 1 | 4 | 1:N_AP |
1541+
* | 7 | 4 | 2 | 2 | 2:2 |
1542+
* +--------------+-------------+-------------------+-------------------+--------+
1543+
*
1544+
* There are therefore four groups of possible antenna configurations:
1545+
*
1546+
* - 1:1 configuration, where both A and B support 1 antenna each
1547+
* - 1:N_AP configuration, where A supports 1 antenna, B supports N_AP antennas, and
1548+
* N_AP is a value in the range [2, 4]
1549+
* - N_AP:1 configuration, where A supports N_AP antennas, B supports 1 antenna, and
1550+
* N_AP is a value in the range [2, 4]
1551+
* - 2:2 configuration, where both A and B support 2 antennas and N_AP = 4
1552+
*/
1553+
enum bt_conn_le_cs_tone_antenna_config_selection {
1554+
BT_LE_CS_TONE_ANTENNA_CONFIGURATION_INDEX_ONE = BT_HCI_OP_LE_CS_ACI_0,
1555+
BT_LE_CS_TONE_ANTENNA_CONFIGURATION_INDEX_TWO = BT_HCI_OP_LE_CS_ACI_1,
1556+
BT_LE_CS_TONE_ANTENNA_CONFIGURATION_INDEX_THREE = BT_HCI_OP_LE_CS_ACI_2,
1557+
BT_LE_CS_TONE_ANTENNA_CONFIGURATION_INDEX_FOUR = BT_HCI_OP_LE_CS_ACI_3,
1558+
BT_LE_CS_TONE_ANTENNA_CONFIGURATION_INDEX_FIVE = BT_HCI_OP_LE_CS_ACI_4,
1559+
BT_LE_CS_TONE_ANTENNA_CONFIGURATION_INDEX_SIX = BT_HCI_OP_LE_CS_ACI_5,
1560+
BT_LE_CS_TONE_ANTENNA_CONFIGURATION_INDEX_SEVEN = BT_HCI_OP_LE_CS_ACI_6,
1561+
BT_LE_CS_TONE_ANTENNA_CONFIGURATION_INDEX_EIGHT = BT_HCI_OP_LE_CS_ACI_7,
1562+
};
1563+
1564+
struct bt_conn_le_cs_procedure_enable_complete {
1565+
/* The ID associated with the desired configuration (0 to 3) */
1566+
uint8_t config_id;
1567+
1568+
/* State of the CS procedure */
1569+
enum bt_conn_le_cs_procedure_enable_state state;
1570+
1571+
/* Antenna configuration index */
1572+
enum bt_conn_le_cs_tone_antenna_config_selection tone_antenna_config_selection;
1573+
1574+
/* Transmit power level used for CS procedures (-127 to 20 dB; 0x7F if unavailable) */
1575+
int8_t selected_tx_power;
1576+
1577+
/* Duration of each CS subevent in microseconds (1250 us to 4 s) */
1578+
uint32_t subevent_len;
1579+
1580+
/* Number of CS subevents anchored off the same ACL connection event (0x01 to 0x20) */
1581+
uint8_t subevents_per_event;
1582+
1583+
/* Time between consecutive CS subevents anchored off the same ACL connection event in
1584+
* units of 0.625 ms
1585+
*/
1586+
uint16_t subevent_interval;
1587+
1588+
/* Number of ACL connection events between consecutive CS event anchor points */
1589+
uint16_t event_interval;
1590+
1591+
/* Number of ACL connection events between consecutive CS procedure anchor points */
1592+
uint16_t procedure_interval;
1593+
1594+
/* Number of CS procedures to be scheduled (0 if procedures to continue until disabled) */
1595+
uint16_t procedure_count;
1596+
1597+
/* Maximum duration for each procedure in units of 0.625 ms (0x0001 to 0xFFFF) */
1598+
uint16_t max_procedure_len;
1599+
};
1600+
15211601
/** @brief Connection callback structure.
15221602
*
15231603
* This structure is used for tracking the state of a connection.
@@ -1810,6 +1890,27 @@ struct bt_conn_cb {
18101890
*/
18111891
void (*le_cs_subevent_data_available)(struct bt_conn *conn,
18121892
struct bt_conn_le_cs_subevent_result *result);
1893+
1894+
/** @brief LE CS Security Enabled.
1895+
*
1896+
* This callback notifies the application that a Channel Sounding
1897+
* Security Enable procedure has completed
1898+
*
1899+
* @param conn Connection object.
1900+
*/
1901+
void (*le_cs_security_enabled)(struct bt_conn *conn);
1902+
1903+
/** @brief LE CS Procedure Enabled.
1904+
*
1905+
* This callback notifies the application that a Channel Sounding
1906+
* Procedure Enable procedure has completed
1907+
*
1908+
* @param conn Connection object.
1909+
* @param params CS Procedure Enable parameters
1910+
*/
1911+
void (*le_cs_procedure_enabled)(
1912+
struct bt_conn *conn, struct bt_conn_le_cs_procedure_enable_complete *params);
1913+
18131914
#endif
18141915

18151916
/** @internal Internally used field for list handling */

include/zephyr/bluetooth/cs.h

Lines changed: 189 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -88,62 +88,24 @@ enum bt_le_cs_test_cs_sync_antenna_selection {
8888
BT_LE_CS_TEST_CS_SYNC_ANTENNA_SELECTION_FOUR = BT_HCI_OP_LE_CS_ANTENNA_SEL_FOUR,
8989
};
9090

91-
/** CS Test Tone Antennna Config Selection.
92-
*
93-
* These enum values are indices in the following table, where N_AP is the maximum
94-
* number of antenna paths (in the range [1, 4]).
95-
*
96-
* +--------------+-------------+-------------------+-------------------+--------+
97-
* | Config Index | Total Paths | Dev A: # Antennas | Dev B: # Antennas | Config |
98-
* +--------------+-------------+-------------------+-------------------+--------+
99-
* | 0 | 1 | 1 | 1 | 1:1 |
100-
* | 1 | 2 | 2 | 1 | N_AP:1 |
101-
* | 2 | 3 | 3 | 1 | N_AP:1 |
102-
* | 3 | 4 | 4 | 1 | N_AP:1 |
103-
* | 4 | 2 | 1 | 2 | 1:N_AP |
104-
* | 5 | 3 | 1 | 3 | 1:N_AP |
105-
* | 6 | 4 | 1 | 4 | 1:N_AP |
106-
* | 7 | 4 | 2 | 2 | 2:2 |
107-
* +--------------+-------------+-------------------+-------------------+--------+
108-
*
109-
* There are therefore four groups of possible antenna configurations:
110-
*
111-
* - 1:1 configuration, where both A and B support 1 antenna each
112-
* - 1:N_AP configuration, where A supports 1 antenna, B supports N_AP antennas, and
113-
* N_AP is a value in the range [2, 4]
114-
* - N_AP:1 configuration, where A supports N_AP antennas, B supports 1 antenna, and
115-
* N_AP is a value in the range [2, 4]
116-
* - 2:2 configuration, where both A and B support 2 antennas and N_AP = 4
117-
*/
118-
enum bt_le_cs_test_tone_antenna_config_selection {
119-
BT_LE_CS_TEST_TONE_ANTENNA_CONFIGURATION_INDEX_ONE = BT_HCI_OP_LE_CS_TEST_ACI_0,
120-
BT_LE_CS_TEST_TONE_ANTENNA_CONFIGURATION_INDEX_TWO = BT_HCI_OP_LE_CS_TEST_ACI_1,
121-
BT_LE_CS_TEST_TONE_ANTENNA_CONFIGURATION_INDEX_THREE = BT_HCI_OP_LE_CS_TEST_ACI_2,
122-
BT_LE_CS_TEST_TONE_ANTENNA_CONFIGURATION_INDEX_FOUR = BT_HCI_OP_LE_CS_TEST_ACI_3,
123-
BT_LE_CS_TEST_TONE_ANTENNA_CONFIGURATION_INDEX_FIVE = BT_HCI_OP_LE_CS_TEST_ACI_4,
124-
BT_LE_CS_TEST_TONE_ANTENNA_CONFIGURATION_INDEX_SIX = BT_HCI_OP_LE_CS_TEST_ACI_5,
125-
BT_LE_CS_TEST_TONE_ANTENNA_CONFIGURATION_INDEX_SEVEN = BT_HCI_OP_LE_CS_TEST_ACI_6,
126-
BT_LE_CS_TEST_TONE_ANTENNA_CONFIGURATION_INDEX_EIGHT = BT_HCI_OP_LE_CS_TEST_ACI_7,
127-
};
128-
12991
/** CS Test Initiator SNR control options */
130-
enum bt_le_cs_test_initiator_snr_control {
131-
BT_LE_CS_TEST_INITIATOR_SNR_CONTROL_18dB = BT_HCI_OP_LE_CS_TEST_INITIATOR_SNR_18,
132-
BT_LE_CS_TEST_INITIATOR_SNR_CONTROL_21dB = BT_HCI_OP_LE_CS_TEST_INITIATOR_SNR_21,
133-
BT_LE_CS_TEST_INITIATOR_SNR_CONTROL_24dB = BT_HCI_OP_LE_CS_TEST_INITIATOR_SNR_24,
134-
BT_LE_CS_TEST_INITIATOR_SNR_CONTROL_27dB = BT_HCI_OP_LE_CS_TEST_INITIATOR_SNR_27,
135-
BT_LE_CS_TEST_INITIATOR_SNR_CONTROL_30dB = BT_HCI_OP_LE_CS_TEST_INITIATOR_SNR_30,
136-
BT_LE_CS_TEST_INITIATOR_SNR_CONTROL_NOT_USED = BT_HCI_OP_LE_CS_TEST_INITIATOR_SNR_NOT_USED,
92+
enum bt_le_cs_initiator_snr_control {
93+
BT_LE_CS_INITIATOR_SNR_CONTROL_18dB = BT_HCI_OP_LE_CS_INITIATOR_SNR_18,
94+
BT_LE_CS_INITIATOR_SNR_CONTROL_21dB = BT_HCI_OP_LE_CS_INITIATOR_SNR_21,
95+
BT_LE_CS_INITIATOR_SNR_CONTROL_24dB = BT_HCI_OP_LE_CS_INITIATOR_SNR_24,
96+
BT_LE_CS_INITIATOR_SNR_CONTROL_27dB = BT_HCI_OP_LE_CS_INITIATOR_SNR_27,
97+
BT_LE_CS_INITIATOR_SNR_CONTROL_30dB = BT_HCI_OP_LE_CS_INITIATOR_SNR_30,
98+
BT_LE_CS_INITIATOR_SNR_CONTROL_NOT_USED = BT_HCI_OP_LE_CS_INITIATOR_SNR_NOT_USED,
13799
};
138100

139101
/** CS Test Reflector SNR control options */
140-
enum bt_le_cs_test_reflector_snr_control {
141-
BT_LE_CS_TEST_REFLECTOR_SNR_CONTROL_18dB = BT_HCI_OP_LE_CS_TEST_REFLECTOR_SNR_18,
142-
BT_LE_CS_TEST_REFLECTOR_SNR_CONTROL_21dB = BT_HCI_OP_LE_CS_TEST_REFLECTOR_SNR_21,
143-
BT_LE_CS_TEST_REFLECTOR_SNR_CONTROL_24dB = BT_HCI_OP_LE_CS_TEST_REFLECTOR_SNR_24,
144-
BT_LE_CS_TEST_REFLECTOR_SNR_CONTROL_27dB = BT_HCI_OP_LE_CS_TEST_REFLECTOR_SNR_27,
145-
BT_LE_CS_TEST_REFLECTOR_SNR_CONTROL_30dB = BT_HCI_OP_LE_CS_TEST_REFLECTOR_SNR_30,
146-
BT_LE_CS_TEST_REFLECTOR_SNR_CONTROL_NOT_USED = BT_HCI_OP_LE_CS_TEST_REFLECTOR_SNR_NOT_USED,
102+
enum bt_le_cs_reflector_snr_control {
103+
BT_LE_CS_REFLECTOR_SNR_CONTROL_18dB = BT_HCI_OP_LE_CS_REFLECTOR_SNR_18,
104+
BT_LE_CS_REFLECTOR_SNR_CONTROL_21dB = BT_HCI_OP_LE_CS_REFLECTOR_SNR_21,
105+
BT_LE_CS_REFLECTOR_SNR_CONTROL_24dB = BT_HCI_OP_LE_CS_REFLECTOR_SNR_24,
106+
BT_LE_CS_REFLECTOR_SNR_CONTROL_27dB = BT_HCI_OP_LE_CS_REFLECTOR_SNR_27,
107+
BT_LE_CS_REFLECTOR_SNR_CONTROL_30dB = BT_HCI_OP_LE_CS_REFLECTOR_SNR_30,
108+
BT_LE_CS_REFLECTOR_SNR_CONTROL_NOT_USED = BT_HCI_OP_LE_CS_REFLECTOR_SNR_NOT_USED,
147109
};
148110

149111
/** CS Test Override 3 T_PM Tone Extension */
@@ -351,11 +313,11 @@ struct bt_le_cs_test_param {
351313
/** Antenna Configuration Index used during antenna switching during
352314
* the tone phases of CS steps.
353315
*/
354-
enum bt_le_cs_test_tone_antenna_config_selection tone_antenna_config_selection;
316+
enum bt_conn_le_cs_tone_antenna_config_selection tone_antenna_config_selection;
355317
/** Initiator SNR control options */
356-
enum bt_le_cs_test_initiator_snr_control initiator_snr_control;
318+
enum bt_le_cs_initiator_snr_control initiator_snr_control;
357319
/** Reflector SNR control options */
358-
enum bt_le_cs_test_reflector_snr_control reflector_snr_control;
320+
enum bt_le_cs_reflector_snr_control reflector_snr_control;
359321
/** Determines octets 14 and 15 of the initial value of the DRBG nonce. */
360322
uint16_t drbg_nonce;
361323

@@ -687,6 +649,178 @@ void bt_le_cs_step_data_parse(struct net_buf_simple *step_data_buf,
687649
bool (*func)(struct bt_le_cs_subevent_step *step, void *user_data),
688650
void *user_data);
689651

652+
/** @brief CS Security Enable
653+
*
654+
* This commmand is used to start or restart the Channel Sounding Security
655+
* Start procedure in the local Controller for the ACL connection identified
656+
* in the conn parameter.
657+
*
658+
* @note To use this API @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
659+
*
660+
* @param conn Connection Object.
661+
*
662+
* @return Zero on success or (negative) error code on failure.
663+
*/
664+
int bt_le_cs_security_enable(struct bt_conn *conn);
665+
666+
struct bt_le_cs_procedure_enable_param {
667+
uint8_t config_id;
668+
enum bt_conn_le_cs_procedure_enable_state enable;
669+
};
670+
671+
/** @brief CS Procedure Enable
672+
*
673+
* This command is used to enable or disable the scheduling of CS procedures
674+
* by the local Controller, with the remote device identified in the conn
675+
* parameter.
676+
*
677+
* @note To use this API @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
678+
*
679+
* @param conn Connection Object.
680+
* @param params Parameters for the CS Procedure Enable command.
681+
*
682+
* @return Zero on success or (negative) error code on failure.
683+
*/
684+
int bt_le_cs_procedure_enable(struct bt_conn *conn,
685+
const struct bt_le_cs_procedure_enable_param *params);
686+
687+
enum bt_le_cs_procedure_phy {
688+
BT_LE_CS_PROCEDURE_PHY_1M = BT_HCI_OP_LE_CS_PROCEDURE_PHY_1M,
689+
BT_LE_CS_PROCEUDRE_PHY_2M = BT_HCI_OP_LE_CS_PROCEDURE_PHY_2M,
690+
BT_LE_CS_PROCEDURE_PHY_CODED_S8 = BT_HCI_OP_LE_CS_PROCEDURE_PHY_CODED_S8,
691+
BT_LE_CS_PROCEDURE_PHY_CODED_S2 = BT_HCI_OP_LE_CS_PROCEDURE_PHY_CODED_S2,
692+
};
693+
694+
#define BT_LE_CS_PROCEDURE_PREFERRED_PEER_ANTENNA_1 BIT(0)
695+
#define BT_LE_CS_PROCEDURE_PREFERRED_PEER_ANTENNA_2 BIT(1)
696+
#define BT_LE_CS_PROCEDURE_PREFERRED_PEER_ANTENNA_3 BIT(2)
697+
#define BT_LE_CS_PROCEDURE_PREFERRED_PEER_ANTENNA_4 BIT(3)
698+
699+
struct bt_le_cs_set_procedure_parameters_param {
700+
/* The ID associated with the desired configuration (0 to 3) */
701+
uint8_t config_id;
702+
703+
/* Max. duration for each CS procedure, where T = N * 0.625 ms (0x0001 to 0xFFFF) */
704+
uint16_t max_procedure_len;
705+
706+
/* Min. number of connection events between consecutive CS procedures (0x0001 to 0xFFFF) */
707+
uint16_t min_procedure_interval;
708+
709+
/* Max. number of connection events between consecutive CS procedures (0x0001 to 0xFFFF) */
710+
uint16_t max_procedure_interval;
711+
712+
/* Max. number of procedures to be scheduled (0x0000 for no limit; otherwise 0x0001
713+
* to 0xFFFF)
714+
*/
715+
uint16_t max_procedure_count;
716+
717+
/* Min. suggested duration for each CS subevent in microseconds (1250 us to 4 s) */
718+
uint32_t min_subevent_len;
719+
720+
/* Max. suggested duration for each CS subevent in microseconds (1250 us to 4 s) */
721+
uint32_t max_subevent_len;
722+
723+
/* Antenna configuration index */
724+
enum bt_conn_le_cs_tone_antenna_config_selection tone_antenna_config_selection;
725+
726+
/* Phy */
727+
enum bt_le_cs_procedure_phy phy;
728+
729+
/* Transmit power delta, in signed dB, to indicate the recommended difference between the
730+
* remote device's power level for the CS tones and RTT packets and the existing power
731+
* level for the Phy indicated by the Phy parameter (0x80 for no recommendation)
732+
*/
733+
int8_t tx_power_delta;
734+
735+
/* Preferred peer antenna (Bitmask of BT_LE_CS_PROCEDURE_PREFERRED_PEER_ANTENNA_*) */
736+
uint8_t preferred_peer_antenna;
737+
738+
/* Initiator SNR control adjustment */
739+
enum bt_le_cs_initiator_snr_control snr_control_initiator;
740+
741+
/* Reflector SNR control adjustment */
742+
enum bt_le_cs_reflector_snr_control snr_control_reflector;
743+
};
744+
745+
/** @brief CS Set Procedure Parameters
746+
*
747+
* This command is used to set the parameters for the scheduling of one
748+
* or more CS procedures by the local controller.
749+
*
750+
* @note To use this API @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
751+
*
752+
* @param conn Connection Object.
753+
* @param params Parameters for the CS Set Procedure Parameters command.
754+
*
755+
* @return Zero on success or (negative) error code on failure.
756+
*/
757+
int bt_le_cs_set_procedure_parameters(struct bt_conn *conn,
758+
const struct bt_le_cs_set_procedure_parameters_param *params);
759+
760+
/** @brief CS Set Channel Classification
761+
*
762+
* This command is used to update the channel classification based on
763+
* its local information.
764+
*
765+
* The nth bitfield (in the range 0 to 78) contains the value for the CS
766+
* channel index n. Channel Enabled = 1; Channel Disabled = 0.
767+
*
768+
* Channels n = 0, 1, 23, 24, 25, 77, and 78 shall be reserved for future
769+
* use and shall be set to zero. At least 15 channels shall be enabled.
770+
*
771+
* The most significant bit (bit 79) is reserved for future use.
772+
*
773+
* @note To use this API, @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
774+
*
775+
* @param channel_classification Bit fields
776+
*
777+
* @return Zero on success or (negative) error code on failure.
778+
*/
779+
int bt_le_cs_set_channel_classification(uint8_t channel_classification[10]);
780+
781+
/** @brief CS Read Local Supported Capabilities
782+
*
783+
* This command is used to read the CS capabilities that are supported
784+
* by the local Controller.
785+
*
786+
* @note To use this API @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
787+
*
788+
* @param ret Return values for the CS Procedure Enable command.
789+
*
790+
* @return Zero on success or (negative) error code on failure.
791+
*/
792+
int bt_le_cs_read_local_supported_capabilities(struct bt_conn_le_cs_capabilities *ret);
793+
794+
/** @brief CS Write Cached Remote Supported Capabilities
795+
*
796+
* This command is used to write the cached copy of the CS capabilities
797+
* that are supported by the remote Controller for the connection
798+
* identified.
799+
*
800+
* @note To use this API @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
801+
*
802+
* @param conn Connection Object.
803+
* @param params Parameters for the CS Write Cached Remote Supported Capabilities command.
804+
*
805+
* @return Zero on success or (negative) error code on failure.
806+
*/
807+
int bt_le_cs_write_cached_remote_supported_capabilities(
808+
struct bt_conn *conn, const struct bt_conn_le_cs_capabilities *params);
809+
810+
/** @brief CS Write Cached Remote FAE Table
811+
*
812+
* This command is used to write a cached copy of the per-channel mode-0
813+
* Frequency Actuation Error table of the remote device in the local Controller.
814+
*
815+
* @note To use this API @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
816+
*
817+
* @param conn Connection Object.
818+
* @param remote_fae_table Per-channel mode-0 FAE table of the local Controller
819+
*
820+
* @return Zero on success or (negative) error code on failure.
821+
*/
822+
int bt_le_cs_write_cached_remote_fae_table(struct bt_conn *conn, uint8_t remote_fae_table[72]);
823+
690824
#ifdef __cplusplus
691825
}
692826
#endif

0 commit comments

Comments
 (0)