Skip to content

Commit a12b869

Browse files
olivier-le-sagefabiobaltieri
authored andcommitted
bluetooth: host: Add support for processing CS subevent results
Adds support for: - LE CS Subevent Result event - LE CS Test End Complete event For now, recombination of subevent results with more steps than could fit within a single HCI event is not supported, and such events are discarded. Signed-off-by: Olivier Lesage <[email protected]>
1 parent 6fc8563 commit a12b869

File tree

9 files changed

+607
-4
lines changed

9 files changed

+607
-4
lines changed

include/zephyr/bluetooth/conn.h

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,112 @@ struct bt_conn_le_cs_config {
538538
uint8_t channel_map[10];
539539
};
540540

541+
/** Procedure done status */
542+
enum bt_conn_le_cs_procedure_done_status {
543+
BT_CONN_LE_CS_PROCEDURE_COMPLETE = BT_HCI_LE_CS_PROCEDURE_DONE_STATUS_COMPLETE,
544+
BT_CONN_LE_CS_PROCEDURE_INCOMPLETE = BT_HCI_LE_CS_PROCEDURE_DONE_STATUS_PARTIAL,
545+
BT_CONN_LE_CS_PROCEDURE_ABORTED = BT_HCI_LE_CS_PROCEDURE_DONE_STATUS_ABORTED,
546+
};
547+
548+
/** Subevent done status */
549+
enum bt_conn_le_cs_subevent_done_status {
550+
BT_CONN_LE_CS_SUBEVENT_COMPLETE = BT_HCI_LE_CS_SUBEVENT_DONE_STATUS_COMPLETE,
551+
BT_CONN_LE_CS_SUBEVENT_INCOMPLETE = BT_HCI_LE_CS_SUBEVENT_DONE_STATUS_PARTIAL,
552+
BT_CONN_LE_CS_SUBEVENT_ABORTED = BT_HCI_LE_CS_SUBEVENT_DONE_STATUS_ABORTED,
553+
};
554+
555+
/** Procedure abort reason */
556+
enum bt_conn_le_cs_procedure_abort_reason {
557+
BT_CONN_LE_CS_PROCEDURE_NOT_ABORTED = BT_HCI_LE_CS_PROCEDURE_ABORT_REASON_NO_ABORT,
558+
BT_CONN_LE_CS_PROCEDURE_ABORT_REQUESTED =
559+
BT_HCI_LE_CS_PROCEDURE_ABORT_REASON_LOCAL_HOST_OR_REMOTE_REQUEST,
560+
BT_CONN_LE_CS_PROCEDURE_ABORT_TOO_FEW_CHANNELS =
561+
BT_HCI_LE_CS_PROCEDURE_ABORT_REASON_TOO_FEW_CHANNELS,
562+
BT_CONN_LE_CS_PROCEDURE_ABORT_CHMAP_INSTANT_PASSED =
563+
BT_HCI_LE_CS_PROCEDURE_ABORT_REASON_CHMAP_INSTANT_PASSED,
564+
BT_CONN_LE_CS_PROCEDURE_ABORT_UNSPECIFIED = BT_HCI_LE_CS_PROCEDURE_ABORT_REASON_UNSPECIFIED,
565+
};
566+
567+
/** Subevent abort reason */
568+
enum bt_conn_le_cs_subevent_abort_reason {
569+
BT_CONN_LE_CS_SUBEVENT_NOT_ABORTED = BT_HCI_LE_CS_SUBEVENT_ABORT_REASON_NO_ABORT,
570+
BT_CONN_LE_CS_SUBEVENT_ABORT_REQUESTED =
571+
BT_HCI_LE_CS_SUBEVENT_ABORT_REASON_LOCAL_HOST_OR_REMOTE_REQUEST,
572+
BT_CONN_LE_CS_SUBEVENT_ABORT_NO_CS_SYNC =
573+
BT_HCI_LE_CS_SUBEVENT_ABORT_REASON_NO_CS_SYNC_RECEIVED,
574+
BT_CONN_LE_CS_SUBEVENT_ABORT_SCHED_CONFLICT =
575+
BT_HCI_LE_CS_SUBEVENT_ABORT_REASON_SCHED_CONFLICT,
576+
BT_CONN_LE_CS_SUBEVENT_ABORT_UNSPECIFIED = BT_HCI_LE_CS_SUBEVENT_ABORT_REASON_UNSPECIFIED,
577+
};
578+
579+
/** Subevent data for LE connections supporting CS */
580+
struct bt_conn_le_cs_subevent_result {
581+
struct {
582+
/** CS configuration identifier.
583+
*
584+
* Range: 0 to 3
585+
*
586+
* If these results were generated by a CS Test,
587+
* this value will be set to 0 and has no meaning.
588+
*/
589+
uint8_t config_id;
590+
/** Starting ACL connection event counter.
591+
*
592+
* If these results were generated by a CS Test,
593+
* this value will be set to 0 and has no meaning.
594+
*/
595+
uint16_t start_acl_conn_event;
596+
/** CS procedure count associated with these results.
597+
*
598+
* This is the CS procedure count since the completion of
599+
* the Channel Sounding Security Start procedure.
600+
*/
601+
uint16_t procedure_counter;
602+
/** Frequency compensation value in units of 0.01 ppm.
603+
*
604+
* This is a 15-bit signed integer in the range [-100, 100] ppm.
605+
*
606+
* A value of @ref BT_HCI_LE_CS_SUBEVENT_RESULT_FREQ_COMPENSATION_NOT_AVAILABLE
607+
* indicates that the role is not the initiator, or that the
608+
* frequency compensation value is unavailable.
609+
*/
610+
uint16_t frequency_compensation;
611+
/** Reference power level in dBm.
612+
*
613+
* Range: -127 to 20
614+
*
615+
* A value of @ref BT_HCI_LE_CS_REF_POWER_LEVEL_UNAVAILABLE indicates
616+
* that the reference power level was not available during a subevent.
617+
*/
618+
int8_t reference_power_level;
619+
/** Procedure status. */
620+
enum bt_conn_le_cs_procedure_done_status procedure_done_status;
621+
/** Subevent status. */
622+
enum bt_conn_le_cs_subevent_done_status subevent_done_status;
623+
/** Abort reason.
624+
*
625+
* If the procedure status is
626+
* @ref BT_CONN_LE_CS_PROCEDURE_ABORTED, this field will
627+
* specify the reason for the abortion.
628+
*/
629+
enum bt_conn_le_cs_procedure_abort_reason procedure_abort_reason;
630+
/** Abort reason.
631+
*
632+
* If the subevent status is
633+
* @ref BT_CONN_LE_CS_SUBEVENT_ABORTED, this field will
634+
* specify the reason for the abortion.
635+
*/
636+
enum bt_conn_le_cs_subevent_abort_reason subevent_abort_reason;
637+
/** Number of antenna paths used during the phase measurement stage.
638+
*/
639+
uint8_t num_antenna_paths;
640+
/** Number of CS steps in the subevent.
641+
*/
642+
uint8_t num_steps_reported;
643+
} header;
644+
struct net_buf_simple *step_data_buf;
645+
};
646+
541647
/** @brief Increment a connection's reference count.
542648
*
543649
* Increment the reference count of a connection object.
@@ -1677,6 +1783,17 @@ struct bt_conn_cb {
16771783
* @param config_id ID of the CS configuration that was removed.
16781784
*/
16791785
void (*le_cs_config_removed)(struct bt_conn *conn, uint8_t config_id);
1786+
1787+
/** @brief Subevent Results from a CS procedure are available.
1788+
*
1789+
* This callback notifies the user that CS subevent results are
1790+
* available for the given connection object.
1791+
*
1792+
* @param conn Connection objects.
1793+
* @param result Subevent results
1794+
*/
1795+
void (*le_cs_subevent_data_available)(struct bt_conn *conn,
1796+
struct bt_conn_le_cs_subevent_result *result);
16801797
#endif
16811798

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

include/zephyr/bluetooth/cs.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,29 @@ struct bt_le_cs_create_config_params {
517517
uint8_t channel_map[10];
518518
};
519519

520+
/** Callbacks for CS Test */
521+
struct bt_le_cs_test_cb {
522+
/**@brief CS Test Subevent data.
523+
*
524+
* @param[in] Subevent results.
525+
*/
526+
void (*le_cs_test_subevent_data_available)(struct bt_conn_le_cs_subevent_result *data);
527+
/**@brief CS Test End Complete. */
528+
void (*le_cs_test_end_complete)(void);
529+
};
530+
531+
/** Subevent result step */
532+
struct bt_le_cs_subevent_step {
533+
/** CS step mode. */
534+
uint8_t mode;
535+
/** CS step channel index. */
536+
uint8_t channel;
537+
/** Length of role- and mode-specific information being reported. */
538+
uint8_t data_len;
539+
/** Pointer to role- and mode-specific information. */
540+
const uint8_t *data;
541+
};
542+
520543
/** @brief Set all valid channel map bits
521544
*
522545
* This command is used to enable all valid channels in a
@@ -567,6 +590,17 @@ int bt_le_cs_set_default_settings(struct bt_conn *conn,
567590
*/
568591
int bt_le_cs_read_remote_fae_table(struct bt_conn *conn);
569592

593+
/** @brief Register callbacks for the CS Test mode.
594+
*
595+
* Existing callbacks can be unregistered by providing NULL function
596+
* pointers.
597+
*
598+
* @param cs_test_cb Set of callbacks to be used with CS Test
599+
*
600+
* @return Zero on success or (negative) error code on failure.
601+
*/
602+
int bt_le_cs_test_cb_register(struct bt_le_cs_test_cb cs_test_cb);
603+
570604
/** @brief Start a CS test
571605
*
572606
* This command is used to start a CS test where the IUT is placed in the role
@@ -620,6 +654,37 @@ int bt_le_cs_create_config(struct bt_conn *conn, struct bt_le_cs_create_config_p
620654
*/
621655
int bt_le_cs_remove_config(struct bt_conn *conn, uint8_t config_id);
622656

657+
/** @brief Stop ongoing CS Test
658+
*
659+
* This command is used to stop any CS test that is in progress.
660+
*
661+
* The controller is expected to finish reporting any subevent results
662+
* before completing this termination.
663+
*
664+
* @note To use this API @kconfig{CONFIG_BT_CHANNEL_SOUNDING} must be set.
665+
*
666+
* @return Zero on success or (negative) error code on failure.
667+
*/
668+
int bt_le_cs_stop_test(void);
669+
670+
/** @brief Parse CS Test Subevent Results
671+
*
672+
* A helper for parsing HCI-formatted step data found in channel sounding subevent results.
673+
*
674+
* A typical use-case is filtering out data which does not meet certain packet quality or NADM
675+
* requirements.
676+
*
677+
* @warning This function will consume the data when parsing.
678+
*
679+
* @param step_data_buf Pointer to a buffer containing the step data.
680+
* @param func Callback function which will be called for each step data found.
681+
* The callback should return true to continue parsing, or false to stop.
682+
* @param user_data User data to be passed to the callback.
683+
*/
684+
void bt_le_cs_step_data_parse(struct net_buf_simple *step_data_buf,
685+
bool (*func)(struct bt_le_cs_subevent_step *step, void *user_data),
686+
void *user_data);
687+
623688
#ifdef __cplusplus
624689
}
625690
#endif

0 commit comments

Comments
 (0)