From b24239843b6d5430089ce85dfd9d2bb60e0f2b98 Mon Sep 17 00:00:00 2001 From: zhiweijian Date: Tue, 10 Jun 2025 16:56:56 +0800 Subject: [PATCH] feat(ble/bluedroid): support bluedroid host channel sounding feature --- components/bt/host/bluedroid/Kconfig.in | 7 + .../bt/host/bluedroid/api/esp_gap_ble_api.c | 332 +++++++ .../api/include/api/esp_gap_ble_api.h | 890 ++++++++++++++++++ .../bt/host/bluedroid/bta/dm/bta_dm_act.c | 81 ++ .../bt/host/bluedroid/bta/dm/bta_dm_api.c | 161 ++++ .../bt/host/bluedroid/bta/dm/bta_dm_main.c | 14 + .../bluedroid/bta/dm/include/bta_dm_int.h | 158 ++++ .../host/bluedroid/bta/include/bta/bta_api.h | 96 ++ .../btc/profile/std/gap/btc_gap_ble.c | 274 ++++++ .../btc/profile/std/include/btc_gap_ble.h | 116 +++ .../include/common/bluedroid_user_config.h | 6 + .../common/include/common/bt_target.h | 6 + .../host/bluedroid/stack/btm/btm_ble_5_gap.c | 285 ++++++ .../bluedroid/stack/btm/include/btm_ble_int.h | 11 + .../bluedroid/stack/btm/include/btm_int.h | 8 + .../bt/host/bluedroid/stack/btu/btu_hcif.c | 278 +++++- .../bt/host/bluedroid/stack/hcic/hciblecmds.c | 321 +++++++ .../stack/include/stack/btm_ble_api.h | 217 ++++- .../bluedroid/stack/include/stack/hcidefs.h | 25 + .../bluedroid/stack/include/stack/hcimsgs.h | 45 + 20 files changed, 3329 insertions(+), 2 deletions(-) diff --git a/components/bt/host/bluedroid/Kconfig.in b/components/bt/host/bluedroid/Kconfig.in index 6e7a21b5c6b..ffca30ca95f 100644 --- a/components/bt/host/bluedroid/Kconfig.in +++ b/components/bt/host/bluedroid/Kconfig.in @@ -1487,6 +1487,13 @@ config BT_BLE_FEAT_ADV_CODING_SELECTION help Enable Advertising Coding Selection +config BT_BLE_FEAT_CHANNEL_SOUNDING + bool "Enable BLE channel sounding" + depends on (BT_BLE_50_FEATURES_SUPPORTED && ((BT_CONTROLLER_ENABLED && SOC_BLE_CHANNEL_SOUNDING_SUPPORTED) || BT_CONTROLLER_DISABLED)) # NOERROR + default n + help + Enable BLE channel sounding + menuconfig BT_BLE_42_FEATURES_SUPPORTED bool "Enable BLE 4.2 features(please disable BLE 5.0 if enable BLE 4.2)" depends on BT_BLE_ENABLED diff --git a/components/bt/host/bluedroid/api/esp_gap_ble_api.c b/components/bt/host/bluedroid/api/esp_gap_ble_api.c index 5582ab03688..0880d669536 100644 --- a/components/bt/host/bluedroid/api/esp_gap_ble_api.c +++ b/components/bt/host/bluedroid/api/esp_gap_ble_api.c @@ -2125,3 +2125,335 @@ esp_err_t esp_ble_gap_set_periodic_sync_subevent(esp_ble_per_sync_subevent_param == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); } #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) + +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +esp_err_t esp_ble_cs_read_local_supported_capabilities(void) +{ + btc_msg_t msg = {0}; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_READ_LOCAL_SUPPORTED_CAPS; + + return (btc_transfer_context(&msg, NULL, 0, NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_cs_read_remote_supported_capabilities(uint16_t conn_handle) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_READ_REMOTE_SUPPORTED_CAPS; + + arg.cs_read_remote_supp_caps.conn_handle = conn_handle; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_cs_write_cached_remote_supported_capabilities(esp_ble_cs_write_cached_remote_supp_caps_params *cached_remote_supp_caps_params) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg = {0}; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + if (!cached_remote_supp_caps_params) { + return ESP_ERR_NOT_ALLOWED; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPS; + + arg.cs_write_cached_remote_supp_caps.conn_handle = cached_remote_supp_caps_params->conn_handle; + arg.cs_write_cached_remote_supp_caps.num_config_supported = cached_remote_supp_caps_params->num_config_supported; + arg.cs_write_cached_remote_supp_caps.max_consecutive_proc_supported = cached_remote_supp_caps_params->max_consecutive_proc_supported; + arg.cs_write_cached_remote_supp_caps.num_ant_supported = cached_remote_supp_caps_params->num_ant_supported; + arg.cs_write_cached_remote_supp_caps.max_ant_paths_supported = cached_remote_supp_caps_params->max_ant_paths_supported; + arg.cs_write_cached_remote_supp_caps.modes_supported = cached_remote_supp_caps_params->modes_supported; + arg.cs_write_cached_remote_supp_caps.rtt_capability = cached_remote_supp_caps_params->rtt_capability; + arg.cs_write_cached_remote_supp_caps.rtt_aa_only_n = cached_remote_supp_caps_params->rtt_aa_only_n; + arg.cs_write_cached_remote_supp_caps.rtt_sounding_n = cached_remote_supp_caps_params->rtt_sounding_n; + arg.cs_write_cached_remote_supp_caps.rtt_random_payload_n = cached_remote_supp_caps_params->rtt_random_payload_n; + arg.cs_write_cached_remote_supp_caps.NADM_sounding_capability = cached_remote_supp_caps_params->NADM_sounding_capability; + arg.cs_write_cached_remote_supp_caps.NADM_random_capability = cached_remote_supp_caps_params->NADM_random_capability; + arg.cs_write_cached_remote_supp_caps.subfeatures_supported = cached_remote_supp_caps_params->subfeatures_supported; + arg.cs_write_cached_remote_supp_caps.T_IP1_times_supported = cached_remote_supp_caps_params->T_IP1_times_supported; + arg.cs_write_cached_remote_supp_caps.T_IP2_times_supported = cached_remote_supp_caps_params->T_IP2_times_supported; + arg.cs_write_cached_remote_supp_caps.T_FCS_times_supported = cached_remote_supp_caps_params->T_FCS_times_supported; + arg.cs_write_cached_remote_supp_caps.T_PM_times_supported = cached_remote_supp_caps_params->T_PM_times_supported; + arg.cs_write_cached_remote_supp_caps.T_SW_times_supported = cached_remote_supp_caps_params->T_SW_times_supported; + arg.cs_write_cached_remote_supp_caps.TX_SNR_capability = cached_remote_supp_caps_params->TX_SNR_capability; + if (cached_remote_supp_caps_params->initiator_role_supported) { + arg.cs_write_cached_remote_supp_caps.roles_supported |= ESP_BLE_CS_INITIATOR_ROLE_SUPPORTED; + } + if (cached_remote_supp_caps_params->reflector_role_supported) { + arg.cs_write_cached_remote_supp_caps.roles_supported |= ESP_BLE_CS_REFLECTOR_ROLE_SUPPORTED; + } + if (cached_remote_supp_caps_params->cs_sync_2m_phy_supported) { + arg.cs_write_cached_remote_supp_caps.cs_sync_phys_supported |= ESP_BLE_CS_SYNC_PHYS_2M_SUPPORTED; + } + if (cached_remote_supp_caps_params->cs_sync_2m_2bt_phy_supported) { + arg.cs_write_cached_remote_supp_caps.cs_sync_phys_supported |= ESP_BLE_CS_SYNC_PHYS_2M_2BT_SUPPORTED; + } + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_cs_security_enable(uint16_t conn_handle) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_SECURITY_ENABLE; + + arg.cs_security_enable.conn_handle = conn_handle; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_cs_set_default_settings(esp_ble_cs_set_default_settings_params *default_setting_params) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg = {0}; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + if (!default_setting_params) { + return ESP_ERR_NOT_ALLOWED; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_SET_DEFAULT_SETTINGS; + + arg.cs_set_default_settings_params.conn_handle = default_setting_params->conn_handle; + arg.cs_set_default_settings_params.cs_sync_ant_selection = default_setting_params->cs_sync_ant_selection; + arg.cs_set_default_settings_params.max_tx_power = default_setting_params->max_tx_power; + if (default_setting_params->initiator_role_enable) { + arg.cs_set_default_settings_params.role_enable |= ESP_BLE_CS_INITIATOR_ROLE_ENABLED; + } + if (default_setting_params->reflector_role_enable) { + arg.cs_set_default_settings_params.role_enable |= ESP_BLE_CS_REFLECTOR_ROLE_ENABLED; + } + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_cs_read_remote_fae_table(uint16_t conn_handle) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_READ_REMOTE_FAE_TABLE; + + arg.cs_read_remote_tab.conn_handle = conn_handle; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_cs_write_cached_remote_fae_table(esp_ble_cs_write_cached_remote_fae_table_params *write_cached_remote_fae_tab_params) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg = {0}; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + if (!write_cached_remote_fae_tab_params) { + return ESP_ERR_NOT_ALLOWED; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_WRITE_CACHED_REMOTE_FAE_TABLE; + + arg.cs_write_cached_remote_fae_table_params.conn_handle = write_cached_remote_fae_tab_params->conn_handle; + memcpy(arg.cs_write_cached_remote_fae_table_params.remote_fae_table, write_cached_remote_fae_tab_params->remote_fae_table, sizeof(arg.cs_write_cached_remote_fae_table_params.remote_fae_table)); + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_cs_create_config(esp_ble_cs_create_config_params *create_config_params) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg = {0}; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + if (!create_config_params) { + return ESP_ERR_NOT_ALLOWED; + } + + arg.cs_create_config_params.conn_handle = create_config_params->conn_handle; + arg.cs_create_config_params.config_id = create_config_params->config_id; + arg.cs_create_config_params.create_context = create_config_params->create_context; + arg.cs_create_config_params.main_mode_type = create_config_params->main_mode_type; + arg.cs_create_config_params.sub_mode_type = create_config_params->sub_mode_type; + arg.cs_create_config_params.min_main_mode_steps = create_config_params->min_main_mode_steps; + arg.cs_create_config_params.max_main_mode_steps = create_config_params->max_main_mode_steps; + arg.cs_create_config_params.main_mode_repetition = create_config_params->main_mode_repetition; + arg.cs_create_config_params.mode_0_steps = create_config_params->mode_0_steps; + arg.cs_create_config_params.role = create_config_params->role; + arg.cs_create_config_params.rtt_type = create_config_params->rtt_type; + arg.cs_create_config_params.cs_sync_phy = create_config_params->cs_sync_phy; + memcpy(arg.cs_create_config_params.channel_map, create_config_params->channel_map, sizeof(arg.cs_create_config_params.channel_map)); + arg.cs_create_config_params.channel_map_repetition = create_config_params->channel_map_repetition; + arg.cs_create_config_params.channel_selection_type = create_config_params->channel_selection_type; + arg.cs_create_config_params.ch3c_shape = create_config_params->ch3c_shape; + arg.cs_create_config_params.ch3c_jump = create_config_params->ch3c_jump; + arg.cs_create_config_params.reserved = create_config_params->reserved; + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_CREATE_CONFIG; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_cs_remove_config(esp_ble_cs_remove_config_params *remove_config_params) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + if (!remove_config_params) { + return ESP_ERR_NOT_ALLOWED; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_REMOVE_CONFIG; + + arg.cs_remove_config_params.conn_handle = remove_config_params->conn_handle; + arg.cs_remove_config_params.config_id = remove_config_params->config_id; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_cs_set_channel_classification(esp_ble_cs_set_channel_class_params *channel_class_params) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + if (!channel_class_params) { + return ESP_ERR_NOT_ALLOWED; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_SET_CAHNNEL_CLASSIFICATION; + + memcpy(arg.cs_set_channel_class_params.channel_class, channel_class_params->channel_class, sizeof(arg.cs_set_channel_class_params)); + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_cs_set_procedure_params(esp_ble_cs_set_proc_params *procedure_params) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + if (!procedure_params) { + return ESP_ERR_NOT_ALLOWED; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_SET_PROCEDURE_PARAMS; + + arg.cs_set_procedure_params.conn_handle = procedure_params->conn_handle; + arg.cs_set_procedure_params.config_id = procedure_params->config_id; + arg.cs_set_procedure_params.max_procedure_len = procedure_params->max_procedure_len; + arg.cs_set_procedure_params.min_procedure_interval = procedure_params->min_procedure_interval; + arg.cs_set_procedure_params.max_procedure_interval = procedure_params->max_procedure_interval; + arg.cs_set_procedure_params.max_procedure_count = procedure_params->max_procedure_count; + arg.cs_set_procedure_params.min_subevent_len = (procedure_params->min_subevent_len & 0x00FFFFFF); + arg.cs_set_procedure_params.max_subevent_len = (procedure_params->max_subevent_len & 0x00FFFFFF); + arg.cs_set_procedure_params.tone_ant_config_selection = procedure_params->tone_ant_config_selection; + arg.cs_set_procedure_params.phy = procedure_params->phy; + arg.cs_set_procedure_params.tx_power_delta = procedure_params->tx_power_delta; + arg.cs_set_procedure_params.preferred_peer_antenna = procedure_params->preferred_peer_antenna; + arg.cs_set_procedure_params.SNR_control_initiator = procedure_params->SNR_control_initiator; + arg.cs_set_procedure_params.SNR_control_reflector = procedure_params->SNR_control_reflector; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +esp_err_t esp_ble_cs_procedure_enable(esp_ble_cs_procedure_enable_params *procedure_enable_params) +{ + btc_msg_t msg = {0}; + btc_ble_5_gap_args_t arg; + + if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) { + return ESP_ERR_INVALID_STATE; + } + + if (!procedure_enable_params) { + return ESP_ERR_NOT_ALLOWED; + } + + msg.sig = BTC_SIG_API_CALL; + msg.pid = BTC_PID_GAP_BLE; + msg.act = BTC_GAP_BLE_CS_PROCEDURE_ENABLE; + + arg.cs_procedure_enable_params.conn_handle = procedure_enable_params->conn_handle; + arg.cs_procedure_enable_params.config_id = procedure_enable_params->config_id; + arg.cs_procedure_enable_params.enable = procedure_enable_params->enable; + + return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_5_gap_args_t), NULL, NULL) + == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL); +} + +#endif diff --git a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h index df0f8629f23..02adac20411 100644 --- a/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h +++ b/components/bt/host/bluedroid/api/include/api/esp_gap_ble_api.h @@ -254,6 +254,19 @@ typedef enum { ESP_GAP_BLE_SET_PERIODIC_SYNC_SUBEVT_EVT, /*!< When BLE update periodic sync subevent complete, the event comes */ ESP_GAP_BLE_PERIODIC_ADV_SUBEVT_DATA_REQUEST_EVT, /*!< When Controller is ready to transmit one or more subevents and is requesting the advertising data for these subevents, the event comes*/ ESP_GAP_BLE_PERIODIC_ADV_RESPONSE_REPORT_EVT, /*!< When one or more devices have responded to a periodic advertising subevent during a PAwR train, the event comes */ + ESP_GAP_BLE_CS_READ_LOCAL_SUPP_CAPS_EVT, /*!< When CS read local supported capabilities complete, the event comes */ + ESP_GAP_BLE_CS_WRITE_CACHED_REMOTE_SUPP_CAPS_EVT, /*!< When CS write cached remote supported capabilities complete, the event comes */ + ESP_GAP_BLE_CS_SET_DEFAULT_SETTINGS_EVT, /*!< When CS set default settings complete, the event comes */ + ESP_GAP_BLE_CS_WRITE_CACHED_REMOTE_FAE_TABLE_EVT, /*!< When CS write cached remote FAE table complete, the event comes */ + ESP_GAP_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT, /*!< When CS read remote supported capabilities complete, the event comes */ + ESP_GAP_BLE_CS_SET_CHANNEL_CLASS_CMPL_EVT, /*!< When CS set channel classification complete, the event comes */ + ESP_GAP_BLE_CS_SET_PROC_PARAMS_CMPL_EVT, /*!< When CS set procedure parameters complete, the event comes */ + ESP_GAP_BLE_CS_PROC_ENABLE_CMPL_EVT, /*!< When CS procedure enable complete, the event comes */ + ESP_GAP_BLE_CS_READ_REMOTE_FAE_TABLE_CMPL_EVT, /*!< When CS read remote FAE table complete, the event comes */ + ESP_GAP_BLE_CS_SECURITY_ENABLE_CMPL_EVT, /*!< When CS security enable complete, the event comes */ + ESP_GAP_BLE_CS_CONFIG_CMPL_EVT, /*!< When CS has completed the Channel Sounding Configuration procedure, the event comes */ + ESP_GAP_BLE_CS_SUBEVENT_RESULT_EVT, /*!< When CS has results to report for a CS subevent during the CS procedure, the event comes */ + ESP_GAP_BLE_CS_SUBEVENT_RESULT_CONTINUE_EVT, /*!< When CS has completed a new CS subevent measurement, the event comes */ ESP_GAP_BLE_EVT_MAX, /*!< when maximum advertising event complete, the event comes */ } esp_gap_ble_cb_event_t; @@ -1368,6 +1381,349 @@ typedef struct { uint8_t *data; /*!< Periodic advertising response data formatted as defined in [Vol 3] Part C, Section 11*/ } esp_ble_pa_rsp_info; +/** Initiator role that are supported by the remote Controller */ +#define ESP_BLE_CS_INITIATOR_ROLE_SUPPORTED (1 << 0) +/** Reflector role that are supported by the remote Controller */ +#define ESP_BLE_CS_REFLECTOR_ROLE_SUPPORTED (1 << 1) + +/** The RTT_AA_Only_N field refers to the 150 ns time-of-flight precision requirement */ +#define ESP_BLE_CS_RTT_CAPABILITY_RTT_AA_ONLY_N_150NS (0 << 0) +/** The RTT_AA_Only_N field refers to the 10 ns time-of-flight precision requirement */ +#define ESP_BLE_CS_RTT_CAPABILITY_RTT_AA_ONLY_N_10NS (1 << 0) +/** The RTT_Sounding_N field refers to the 150 ns time-of-flight precision requirement */ +#define ESP_BLE_CS_RTT_CAPABILITY_RTT_SOUNDING_N_150NS (0 << 1) +/** The RTT_Sounding_N field refers to the 10 ns time-of-flight precision requirement */ +#define ESP_BLE_CS_RTT_CAPABILITY_RTT_SOUNDING_N_10NS (1 << 1) +/** The RTT_Random_Payload_N field refers to the 150 ns time-of-flight precision requirement */ +#define ESP_BLE_CS_RTT_CAPABILITY_RTT_RANDOM_PAYLOAD_N_150NS (0 << 2) +/** The RTT_Random_Payload_N field refers to the 10 ns time-of-flight precision requirement */ +#define ESP_BLE_CS_RTT_CAPABILITY_RTT_RANDOM_PAYLOAD_N_10NS (1 << 2) +typedef uint8_t esp_ble_cs_rtt_caps_opt_t; + +/** CS_SYNC 2M phy supported */ +#define ESP_BLE_CS_SYNC_PHYS_2M_SUPPORTED (1 << 1) +/** CS_SYNC 2M 2BT phy supported */ +#define ESP_BLE_CS_SYNC_PHYS_2M_2BT_SUPPORTED (1 << 2) + +/** +* @brief CS write cached remote supported capabilities parameters +*/ +typedef struct { + uint16_t conn_handle; /*!< Connection_Handle */ + uint8_t num_config_supported; /*!< The number of CS configurations that are supported by the remote Controller. Range: 0x01 to 0x04 */ + uint16_t max_consecutive_proc_supported;/*!< 0x0000: Support for both a fixed number of consecutive CS procedures and for an indefinite number of CS procedures until termination + 0x0001 to 0xFFFF: The Maximum number of consecutive CS procedures supported */ + uint8_t num_ant_supported; /*!< Number of antennas supported. Range: 0x01 to 0x04 */ + uint8_t max_ant_paths_supported; /*!< Maximum number of antenna paths supported. Range: 0x01 to 0x04 */ + bool initiator_role_supported; /*!< Initiator role that are supported by the remote Controller */ + bool reflector_role_supported; /*!< Reflector role that are supported by the remote Controller */ + uint8_t modes_supported; /*!< The optional CS modes that are supported by the remote Controller + bit 0: Mode-3 */ + esp_ble_cs_rtt_caps_opt_t rtt_capability; /*!< time-of-flight precision requirement */ + uint8_t rtt_aa_only_n; /*!< 0x00: RTT AA-only not supported. + 0x01 to 0xff: Number of CS_SYNC exchanges needed to satisfy the precision requirements */ + uint8_t rtt_sounding_n; /*!< 0x00: RTT Sounding not supported + 0x01 to 0xFF: Number of CS_SYNC exchanges needed to satisfy the precision requirements */ + uint8_t rtt_random_payload_n; /*!< 0x00: RTT Random Payload not supported + 0x01 to 0xff: Number of CS_SYNC exchanges needed to satisfy the time-of-flight precision requirements */ + uint16_t NADM_sounding_capability; /*!< Support for Phase-based Normalized Attack Detector Metric when a CS_SYNC with sounding sequence is received */ + uint16_t NADM_random_capability; /*!< Support for Phase-based Normalized Attack Detector Metric when a CS_SYNC with random sequence is received */ + bool cs_sync_2m_phy_supported; /*!< CS_SYNC 2M phy supported */ + bool cs_sync_2m_2bt_phy_supported; /*!< CS_SYNC 2M 2BT phy supported */ + uint16_t subfeatures_supported; /*!< bit 1: CS with a Frequency Actuation Error of zero relative to mode-0 transmissions in the reflector role + bit 2: CS Channel Selection Algorithm #3c + bit 3: CS phase-based ranging from an RTT sounding sequence */ + uint16_t T_IP1_times_supported; /*!< bit 0: 10 μs supported + bit 1: 20 μs supported + bit 2: 30 μs supported + bit 3: 40 μs supported + bit 4: 50 μs supported + bit 5: 60 μs supported + bit 6: 80 μs supported + */ + uint16_t T_IP2_times_supported; /*!< bit 0: 10 μs supported + bit 1: 20 μs supported + bit 2: 30 μs supported + bit 3: 40 μs supported + bit 4: 50 μs supported + bit 5: 60 μs supported + bit 6: 80 μs supported + */ + uint16_t T_FCS_times_supported; /*!< bit 0: 15 μs supported + bit 1: 20 μs supported + bit 2: 30 μs supported + bit 3: 40 μs supported + bit 4: 50 μs supported + bit 5: 60 μs supported + bit 6: 80 μs supported + bit 7: 100 μs supported + bit 8: 120 μs supported + */ + uint16_t T_PM_times_supported; /*!< bit 0: 10 μs supported + bit 1: 20 μs supported + */ + uint8_t T_SW_times_supported; /*!< Time in microseconds for the antenna switch period of the CS tones. Range: 0x00 to 0x04 or 0x0A */ + uint8_t TX_SNR_capability; /*!< bit 0: 18 dB supported + bit 1: 21 dB supported + bit 2: 24 dB supported + bit 3: 27 dB supported + bit 4: 30 dB supported + */ +} esp_ble_cs_write_cached_remote_supp_caps_params; + +/** +* @brief CS sync antenna selection options +*/ +typedef enum { + /** Use antenna identifier 1 for CS_SYNC packets by the local Controller */ + ESP_BLE_CS_ANT_SELECTION_OPT_ONE = 0x01, + /** Use antenna identifier 2 for CS_SYNC packets by the local Controller */ + ESP_BLE_CS_ANT_SELECTION_OPT_TWO = 0x02, + /** Use antenna identifier 3 for CS_SYNC packets by the local Controller */ + ESP_BLE_CS_ANT_SELECTION_OPT_THREE = 0x03, + /** Use antenna identifier 4 for CS_SYNC packets by the local Controller */ + ESP_BLE_CS_ANT_SELECTION_OPT_FOUR = 0x04, + /** Use antennas in repetitive order from 1 to 4 for CS_SYNC packets by the local Controller */ + ESP_BLE_CS_ANT_SELECTION_OPT_REPETITIVE = 0xFE, + /** No recommendation for local controller antenna selection by the local Controller */ + ESP_BLE_CS_ANT_SELECTION_OPT_NO_RECOMMENDATION = 0xFF, +} esp_ble_cs_sync_ant_selection_opt_t; + +/** Initiator role is enabled */ +#define ESP_BLE_CS_INITIATOR_ROLE_ENABLED (1 << 0) +/** Reflector role is enabled */ +#define ESP_BLE_CS_REFLECTOR_ROLE_ENABLED (1 << 1) + +/** +* @brief CS set default settings parameters +*/ +typedef struct { + uint16_t conn_handle; /*!< Connection_Handle */ + bool initiator_role_enable; /*!< Initiator role is enabled */ + bool reflector_role_enable; /*!< Reflector role is enabled */ + esp_ble_cs_sync_ant_selection_opt_t cs_sync_ant_selection; /*!< 0x01 to 0x04: Antenna identifier to be used for CS_SYNC packets by the local Controller + 0xFE: Antennas to be used, in repetitive order from 0x01 to 0x04, for CS_SYNC packets by the local Controller + 0xFF: Host does not have a recommendation + */ + int8_t max_tx_power; /*!< The maximum transmit power level to be used for all CS transmissions. Range: -127 to 20. Units: dBm */ +} esp_ble_cs_set_default_settings_params; + +/** +* @brief CS write cached remote Frequency Actuation Error table parameters +*/ +typedef struct { + uint16_t conn_handle; /*!< Connection_Handle */ + uint8_t remote_fae_table[72]; /*!< Per-channel mode-0 Frequency Actuation Error table of the local Controller */ +} esp_ble_cs_write_cached_remote_fae_table_params; + +#define ESP_BLE_CS_SYNC_PHY_1M (0x01) +#define ESP_BLE_CS_SYNC_PHY_2M (0x02) +#define ESP_BLE_CS_SYNC_PHY_2M_2BT (0x03) +typedef uint8_t esp_ble_cs_sync_phy_opt_t; + +#define ESP_BLE_CS_RTT_TYPE_RTT_AA_ONLY (0X00) +#define ESP_BLE_CS_RTT_TYPE_RTT_WITH_32BIT_SOUNDING_SEQUENCE (0X01) +#define ESP_BLE_CS_RTT_TYPE_RTT_WITH_96BIT_SOUNDING_SEQUENCE (0X02) +#define ESP_BLE_CS_RTT_TYPE_RTT_WITH_32BIT_RANDOM_SEQUENCE (0X03) +#define ESP_BLE_CS_RTT_TYPE_RTT_WITH_64BIT_RANDOM_SEQUENCE (0X04) +#define ESP_BLE_CS_RTT_TYPE_RTT_WITH_96BIT_RANDOM_SEQUENCE (0X05) +#define ESP_BLE_CS_RTT_TYPE_RTT_WITH_128BIT_RANDOM_SEQUENCE (0X06) +typedef uint8_t esp_ble_cs_rtt_type_opt_t; + +#define ESP_BLE_CS_ROLE_INITIATOR (0x00) +#define ESP_BLE_CS_ROLE_REFLECTOR (0x01) +typedef uint8_t esp_ble_cs_role_opt_t; + +#define ESP_BLE_CS_MAIN_MODE_TYPE_MODE_1 (0x01) +#define ESP_BLE_CS_MAIN_MODE_TYPE_MODE_2 (0x02) +#define ESP_BLE_CS_MAIN_MODE_TYPE_MODE_3 (0x03) +typedef uint8_t esp_ble_cs_main_mode_opt_t; + +#define ESP_BLE_CS_SUB_MODE_TYPE_MODE_1 (0x01) +#define ESP_BLE_CS_SUB_MODE_TYPE_MODE_2 (0x02) +#define ESP_BLE_CS_SUB_MODE_TYPE_MODE_3 (0x03) +#define ESP_BLE_CS_SUB_MODE_TYPE_UNUSED (0xFF) +typedef uint8_t esp_ble_cs_sub_mode_opt_t; + +#define ESP_BLE_CS_CREAT_CONTEXT_IN_LOCAL_CONTROLLER (0x00) +#define ESP_BLE_CS_CREAT_CONTEXT_IN_LOCAL_AND_REMOTE_CONTROLLER (0x01) +typedef uint8_t esp_ble_cs_create_context_opt_t; + +#define ESP_BLE_CS_CAHNNEL_SELECT_TYPE_ALGORITHM_3b (0x00) +#define ESP_BLE_CS_CAHNNEL_SELECT_TYPE_ALGORITHM_3C (0x01) +typedef uint8_t esp_ble_cs_channel_select_type_opt_t; + +#define ESP_BLE_CS_CH3C_USE_HAT_SHAPE (0x00) +#define ESP_BLE_CS_CH3C_USE_X_SHAPE (0x01) +typedef uint8_t esp_ble_cs_ch3c_shape_opt_t; + +/** +* @brief CS create configuration parameters +*/ +typedef struct { + uint16_t conn_handle; /*!< Connection_Handle */ + uint8_t config_id; /*!< CS configuration identifier. Range: 0 to 3 */ + esp_ble_cs_create_context_opt_t create_context; /*!< 0x00: Write CS configuration in local Controller only + 0x01: Write CS configuration in both local and remote Controller using Channel Sounding Configuration procedure + */ + esp_ble_cs_main_mode_opt_t main_mode_type; /*!< 0x01: Mode-1 + 0x02: Mode-2 + 0x03: Mode-3 + */ + esp_ble_cs_sub_mode_opt_t sub_mode_type; /*!< 0x01: Mode-1 + 0x02: Mode-2 + 0x03: Mode-3 + 0xFF: Unused + */ + uint8_t min_main_mode_steps; /*!< Minimum number of CS main mode steps to be executed before a submode step is executed. Range: 0x02 to 0xFF */ + uint8_t max_main_mode_steps; /*!< Maximum number of CS main mode steps to be executed before a submode step is executed. Range: 0x02 to 0xFF */ + uint8_t main_mode_repetition; /*!< The number of main mode steps taken from the end of the last CS subevent to be repeated at the beginning of + the current CS subevent directly after the last mode-0 step of that event. Range: 0x00 to 0x03 */ + uint8_t mode_0_steps; /*!< Number of CS mode-0 steps to be included at the beginning of each CS subevent. Range: 0x01 to 0x03 */ + esp_ble_cs_role_opt_t role; /*!< 0x00: Initiator + 0x01: Reflector + */ + esp_ble_cs_rtt_type_opt_t rtt_type; /*!< 0x00: RTT AA-only + 0x01: RTT with 32-bit sounding sequence + 0x02: RTT with 96-bit sounding sequence + 0x03: RTT with 32-bit random sequence + 0x04: RTT with 64-bit random sequence + 0x05: RTT with 96-bit random sequence + 0x06: RTT with 128-bit random sequence + */ + esp_ble_cs_sync_phy_opt_t cs_sync_phy; /*!< 0x01: LE 1M PHY + 0x02: LE 2M PHY + 0x03: LE 2M 2BT PHY + */ + uint8_t channel_map[10]; /*!< This parameter contains 80 1-bit fields. + The nth such field (in the range 0 to 78) contains the value for the CS channel index n. + Channel n is enabled for CS procedure = 1 + Channel n is disabled for CS procedure = 0 + Channels n = 0, 1, 23, 24, 25, 77, and 78 shall be ignored and shall be set to zero. At least 15 channels shall be enabled. + The most significant bit (bit 79) is reserved for future use + */ + uint8_t channel_map_repetition; /*!< The number of times the map represented by the Channel_Map field is to be cycled through for non-mode-0 steps within a CS procedure. Range: 0x01 to 0xFF */ + esp_ble_cs_channel_select_type_opt_t channel_selection_type;/*!< 0x00: Use Channel Selection Algorithm #3b for non-mode-0 CS steps + 0x01: Use Channel Selection Algorithm #3c for non-mode-0 CS steps + */ + esp_ble_cs_ch3c_shape_opt_t ch3c_shape; /*!< 0x00: Use Hat shape for user-specified channel sequence + 0x01: Use X shape for user-specified channel sequence + */ + uint8_t ch3c_jump; /*!< Number of channels skipped in each rising and falling sequence. Range: 0x02 to 0x08 */ + uint8_t reserved; /*!< Reserved, shall be set to 0x00 */ +} esp_ble_cs_create_config_params; + +/** +* @brief CS remove configuration parameters +*/ +typedef struct { + uint16_t conn_handle; /*!< Connection_Handle */ + uint8_t config_id; /*!< CS configuration identifier. Range: 0 to 3 */ +} esp_ble_cs_remove_config_params; + +/** +* @brief CS set channel class parameters +*/ +typedef struct { + uint8_t channel_class[10]; /*!< This parameter contains 80 1-bit fields. + The nth such field (in the range 0 to 78) contains the value for the CS channel index n. + Channel n is enabled for CS procedure = 1 + Channel n is disabled for CS procedure = 0 + Channels n = 0, 1, 23, 24, 25, 77, and 78 shall be reserved for future use and shall be set to zero. At least 15 channels shall be enabled. + The most significant bit (bit 79) is reserved for future use. + */ +} esp_ble_cs_set_channel_class_params; + +#define ESP_BLE_CS_PHY_1M (0x01) +#define ESP_BLE_CS_PHY_2M (0x02) +#define ESP_BLE_CS_PHY_S8 (0x03) +#define ESP_BLE_CS_PHY_S2 (0x04) +typedef uint8_t esp_ble_cs_phy_opt_t; + +#define ESP_BLE_CS_PREFERRED_FIRST_ORDER_ANT (1 << 0) +#define ESP_BLE_CS_PREFERRED_SECOND_ORDER_ANT (1 << 1) +#define ESP_BLE_CS_PREFERRED_THIRD_ORDER_ANT (1 << 2) +#define ESP_BLE_CS_PREFERRED_FOURTH_ORDER_ANT (1 << 3) +typedef uint8_t esp_ble_cs_preferred_peer_ant_t; + +#define ESP_BLE_CS_SNR_CONTROL_ADIJUSTMENT_18DB (0x00) +#define ESP_BLE_CS_SNR_CONTROL_ADIJUSTMENT_21DB (0x01) +#define ESP_BLE_CS_SNR_CONTROL_ADIJUSTMENT_24DB (0x02) +#define ESP_BLE_CS_SNR_CONTROL_ADIJUSTMENT_27DB (0x03) +#define ESP_BLE_CS_SNR_CONTROL_ADIJUSTMENT_30DB (0x04) +#define ESP_BLE_CS_SNR_CONTROL_NOT_APPLIED (0xFF) +typedef uint8_t esp_ble_cs_snr_control_adjustment_t; + +/** +* @brief CS set procedure parameters +*/ +typedef struct { + uint16_t conn_handle; /*!< Connection_Handle */ + uint8_t config_id; /*!< CS configuration identifier. Range: 0 to 3 */ + uint16_t max_procedure_len; /*!< Maximum duration for each CS procedure. Range: 0x0001 to 0xFFFF. Time = N × 0.625 ms */ + uint16_t min_procedure_interval; /*!< Minimum number of connection events between consecutive CS procedures. Range: 0x0001 to 0xFFFF */ + uint16_t max_procedure_interval; /*!< Maximum number of connection events between consecutive CS procedures. Range: 0x0001 to 0xFFFF */ + uint16_t max_procedure_count; /*!< 0x0000:CS procedures to continue until disabled + 0xxxxx: Maximum number of CS procedures to be scheduled + */ + uint32_t min_subevent_len; /*!< Minimum suggested duration for each CS subevent in microseconds. Range: 1250 μs to 4 s */ + uint32_t max_subevent_len; /*!< Maximum suggested duration for each CS subevent in microseconds. Range: 1250 μs to 4 s */ + uint8_t tone_ant_config_selection; /*!< Antenna Configuration Index. Range: 0x00 to 0x07 */ + esp_ble_cs_phy_opt_t phy; /*!< 0x01: LE 1M PHY + 0x02: LE 2M PHY + 0x03: LE Coded PHY with S=8 data coding + 0x04: LE Coded PHY with S=2 data coding + */ + uint8_t tx_power_delta; /*!< 0xxx: Transmit power delta, in signed dB, to indicate the recommended difference between the remote device’s power level + for the CS tones and RTT packets and the existing power level for the PHY indicated by the PHY parameter + 0x80: Host does not have a recommendation for transmit power delta + */ + esp_ble_cs_preferred_peer_ant_t preferred_peer_antenna; /*!< bit 0: Use first ordered antenna element + bit 1: Use second ordered antenna element + bit 2: Use third ordered antenna element + bit 3: Use fourth ordered antenna element + */ + esp_ble_cs_snr_control_adjustment_t SNR_control_initiator; /*!< 0x00: SNR control adjustment of 18 dB. + 0x01: SNR control adjustment of 21 dB. + 0x02: SNR control adjustment of 24 dB. + 0x03: SNR control adjustment of 27 dB. + 0x04: SNR control adjustment of 30 dB. + 0xFF: SNR control is not to be applied + */ + esp_ble_cs_snr_control_adjustment_t SNR_control_reflector; /*!< 0x00: SNR control adjustment of 18 dB. + 0x01: SNR control adjustment of 21 dB. + 0x02: SNR control adjustment of 24 dB. + 0x03: SNR control adjustment of 27 dB. + 0x04: SNR control adjustment of 30 dB. + 0xFF: SNR control is not to be applied. + */ +} esp_ble_cs_set_proc_params; + +#define ESP_BLE_CS_PROCEDURES_DISABLE (0x00) +#define ESP_BLE_CS_PROCEDURES_ENABLE (0x01) +typedef uint8_t esp_ble_cs_procedures_action_t; + +/** +* @brief CS procedure enable parameters +*/ +typedef struct { + uint16_t conn_handle; /*!< Connection_Handle */ + uint8_t config_id; /*!< CS configuration identifier. Range: 0 to 3 */ + esp_ble_cs_procedures_action_t enable; /*!< 0x00: CS procedures are to be disabled + 0x01: CS procedures are to be enabled + */ +} esp_ble_cs_procedure_enable_params; + +/** +* @brief CS step information +*/ +typedef struct { + uint8_t step_mode; /*!< 0x00 to 0x03: Mode type */ + uint8_t step_channel; /*!< 0x00 to 0x4E: CS channel index */ + uint8_t step_data_len; /*!< 0x00 to 0xFF: Length of mode- and role-specific information being reported */ + uint8_t *data; /*!< Mode- and role-specific information being reported as Mode_Role_Specific_Info object */ +} esp_ble_cs_step_info; + /** * @brief Gap callback parameters union */ @@ -2074,6 +2430,376 @@ typedef union { esp_ble_pa_rsp_info *pa_rsp_info; /*!< response information */ } pa_rsp_rpt_evt; /*!< Event parameter of ESP_GAP_BLE_PERIODIC_ADV_RESPONSE_REPORT_EVT */ #endif // #if (CONFIG_BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + /** + * @brief ESP_GAP_BLE_CS_READ_LOCAL_SUPP_CAPS_EVT + */ + struct ble_cs_read_local_supp_caps_evt { + uint8_t status; /*!< Indicate channel sounding read local supported capabilities command successfully completed */ + uint16_t conn_handle; /*!< Connection Handle */ + uint8_t num_config_supported; /*!< Number of CS configurations supported per connection */ + uint16_t max_consecutive_proc_supported; /*!< 0x0000: Support for both a fixed number of consecutive CS procedures and for an indefinite number of CS procedures until termination + 0x0001 to 0xFFFF: Maximum number of consecutive CS procedures supported */ + uint8_t num_ant_supported; /*!< Number of antennas supported */ + uint8_t max_ant_paths_supported; /*!< Maximum number of antenna paths supported */ + uint8_t roles_supported; /*!< bit 0: Initiator + bit 1: Reflector + */ + uint8_t modes_supported; /*!< bit 0: Mode-3*/ + uint8_t rtt_capability; /*!< time-of-flight precision requirement */ + uint8_t rtt_aa_only_n; /*!< 0x00: RTT AA Only not supported + 0x01 to 0xFF: Number of CS steps of single packet exchanges needed to satisfy the precision requirements */ + uint8_t rtt_sounding_n; /*!< 0x00: RTT Sounding not supported + 0x01 to 0xFF: Number of CS steps of single packet exchanges needed to satisfy the precision requirements */ + uint8_t rtt_random_payload_n; /*!< 0x00: RTT Random Payload not supported + 0x01 to 0xFF: Number of CS steps of single packet exchanges needed to satisfy the precision requirements */ + uint16_t NADM_sounding_capability; /*!< bit 0: Support for Phase-based Normalized Attack Detector Metric when a CS_SYNC with sounding sequence is received */ + uint16_t NADM_random_capability; /*!< bit 0: Support for Phase-based Normalized Attack Detector Metric when a CS_SYNC with random sequence is received */ + uint8_t cs_sync_phys_supported; /*!< bit 1: LE 2M PHY + bit 2: LE 2M 2BT PHY + */ + uint16_t subfeatures_supported; /*!< bit 1: CS with no transmitter Frequency Actuation Error + bit 2: CS Channel Selection Algorithm #3c + bit 3: CS phase-based ranging from RTT sounding sequence + */ + uint16_t T_IP1_times_supported; /*!< bit 0: 10 μs supported + bit 1: 20 μs supported + bit 2: 30 μs supported + bit 3: 40 μs supported + bit 4: 50 μs supported + bit 5: 60 μs supported + bit 6: 80 μs supported + */ + uint16_t T_IP2_times_supported; /*!< bit 0: 10 μs supported + bit 1: 20 μs supported + bit 2: 30 μs supported + bit 3: 40 μs supported + bit 4: 50 μs supported + bit 5: 60 μs supported + bit 6: 80 μs supported + */ + uint16_t T_FCS_times_supported; /*!< bit 0: 15 μs supported + bit 1: 20 μs supported + bit 2: 30 μs supported + bit 3: 40 μs supported + bit 4: 50 μs supported + bit 5: 60 μs supported + bit 6: 80 μs supported + bit 7: 100 μs supported + bit 8: 120 μs supported */ + uint16_t T_PM_times_supported; /*!< bit 0: 10 μs supported + bit 1: 20 μs supported + */ + uint8_t T_SW_times_supported; /*!< 0x00, 0x01, 0x02, 0x04, or 0x0A: Time in microseconds for the antenna switch period of the CS tones */ + uint8_t TX_SNR_capability; /*!< bit 0: 18 dB supported + bit 1: 21 dB supported + bit 2: 24 dB supported + bit 3: 27 dB supported + bit 4: 30 dB supported + */ + } cs_read_local_supp_caps; /*!< Event parameter of ESP_GAP_BLE_CS_READ_LOCAL_SUPP_CAPS_EVT */ + /** + * @brief ESP_GAP_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT + */ + struct ble_cs_read_remote_supp_caps { + uint8_t status; /*!< 0x00: Channel sounding read remote supported capabilities command successfully completed + other: Channel sounding read remote supported capabilities command failed */ + uint16_t conn_handle; /*!< Connection Handle */ + uint8_t num_config_supported; /*!< Number of CS configurations supported per connection */ + uint16_t max_consecutive_proc_supported; /*!< Maximum number of consecutive CS procedures supported */ + uint8_t num_ant_supported; /*!< Number of antennas supported */ + uint8_t max_ant_paths_supported; /*!< Maximum number of antenna paths supported */ + uint8_t roles_supported; /*!< bit 0: Initiator + bit 1: Reflector */ + uint8_t modes_supported; /*!< bit 0: Mode-3 */ + uint8_t rtt_capability; /*!< Time-of-flight precision requirement */ + uint8_t rtt_aa_only_n; /*!< Number of CS steps of single packet exchanges needed to satisfy the precision requirements */ + uint8_t rtt_sounding_n; /*!< Number of CS steps of single packet exchanges needed to satisfy the precision requirements */ + uint8_t rtt_random_payload_n; /*!< Number of CS steps of single packet exchanges needed to satisfy the precision requirements */ + uint16_t NADM_sounding_capability; /*!< bit 0: Support for Phase-based Normalized Attack Detector Metric when a CS_SYNC with sounding sequence is received */ + uint16_t NADM_random_capability; /*!< bit 0: Support for Phase-based Normalized Attack Detector Metric when a CS_SYNC with random sequence is received*/ + uint8_t cs_sync_phys_supported; /*!< bit 1: LE 2M PHY + bit 2: LE 2M 2BT PHY */ + uint16_t subfeatures_supported; /*!< bit 1: CS with no transmitter Frequency Actuation Error + bit 2: CS Channel Selection Algorithm #3c + bit 3: CS phase-based ranging from RTT sounding sequence + */ + uint16_t T_IP1_times_supported; /*!< bit 0: 10 μs supported + bit 1: 20 μs supported + bit 2: 30 μs supported + bit 3: 40 μs supported + bit 4: 50 μs supported + bit 5: 60 μs supported + bit 6: 80 μs supported + */ + uint16_t T_IP2_times_supported; /*!< bit 0: 10 μs supported + bit 1: 20 μs supported + bit 2: 30 μs supported + bit 3: 40 μs supported + bit 4: 50 μs supported + bit 5: 60 μs supported + bit 6: 80 μs supported + */ + uint16_t T_FCS_times_supported; /*!< bit 0: 15 μs supported + bit 1: 20 μs supported + bit 2: 30 μs supported + bit 3: 40 μs supported + bit 4: 50 μs supported + bit 5: 60 μs supported + bit 6: 80 μs supported + bit 7: 100 μs supported + bit 8: 120 μs supported + */ + uint16_t T_PM_times_supported; /*!< bit 0: 10 μs supported + bit 1: 20 μs supported + */ + uint8_t T_SW_times_supported; /*!< 0x00, 0x01, 0x02, 0x04, or 0x0A: Time in microseconds for the antenna switch period of the CS tones */ + uint8_t TX_SNR_capability; /*!< bit 0: 18 dB supported + bit 1: 21 dB supported + bit 2: 24 dB supported + bit 3: 27 dB supported + bit 4: 30 dB supported + */ + } cs_read_remote_supp_caps; /*!< Event parameter of ESP_GAP_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT */ + /** + * @brief ESP_GAP_BLE_CS_WRITE_CACHED_REMOTE_SUPP_CAPS_EVT + */ + struct ble_cs_write_cached_remote_supp_caps { + uint8_t status; /*!< 0x00: Channel sounding write cached remote FAE table command succeeded + 0x01: Channel sounding write cached remote FAE table command failed */ + uint16_t conn_handle; /*!< Connection Handle */ + } cs_write_cached_remote_supp_caps; /*!< Event parameter of ESP_GAP_BLE_CS_WRITE_CACHED_REMOTE_SUPP_CAPS_EVT */ + /** + * @brief ESP_GAP_BLE_CS_SECURITY_ENABLE_CMPL_EVT + */ + struct ble_cs_security_enable { + uint8_t status; /*!< 0x00: Channel sounding security parameters successfully exchanged + other: Channel sounding CS security parameter exchange failed */ + uint16_t conn_handle; /*!< Connection Handle */ + } cs_security_enable; /*!< Event parameter of ESP_GAP_BLE_CS_SECURITY_ENABLE_CMPL_EVT */ + /** + * @brief ESP_GAP_BLE_CS_SET_DEFAULT_SETTINGS_EVT + */ + struct ble_cs_set_default_settings { + uint8_t status; /*!< 0x00: Channel sounding set default settings command successfully completed + other: Channel sounding set default settings command failed*/ + uint16_t conn_handle; /*!< Connection Handle */ + } cs_set_default_settings; /*!< Event parameter of ESP_GAP_BLE_CS_SET_DEFAULT_SETTINGS_EVT */ + /** + * @brief ESP_GAP_BLE_CS_READ_REMOTE_FAE_TABLE_CMPL_EVT + */ + struct ble_cs_read_remote_fae_tab { + uint8_t status; /*!< 0x00: Channel sounding read remote FAE Table command successfully completed + other: Channel sounding read remote FAE Table command failed*/ + uint16_t conn_handle; /*!< Connection Handle */ + uint8_t remote_fae_table[72]; /*!< Per-channel mode-0 Frequency Actuation Error table of the remote Controller */ + } cs_read_remote_fae_tab; /*!< Event parameter of ESP_GAP_BLE_CS_READ_REMOTE_FAE_TABLE_CMPL_EVT */ + /** + * @brief ESP_GAP_BLE_CS_WRITE_CACHED_REMOTE_FAE_TABLE_EVT + */ + struct ble_cs_write_cached_remote_fae_tab { + uint8_t status; /*!< 0x00: Channel sounding write cached remote FAE table command succeeded + other: Channel sounding write cached remote FAE table command failed */ + uint16_t conn_handle; /*!< Connection Handle */ + } cs_write_cached_remote_fae_tab; /*!< Event parameter of ESP_GAP_BLE_CS_WRITE_CACHED_REMOTE_FAE_TABLE_EVT */ + /** + * @brief ESP_GAP_BLE_CS_CONFIG_CMPL_EVT + */ + struct ble_cs_config_udpate { + uint8_t status; /*!< 0x00: Channel Sounding Configuration procedure succeeded + other: Channel Sounding Configuration procedure failed */ + uint16_t conn_handle; /*!< Connection Handle */ + uint8_t config_id; /*!< CS configuration identifier */ + uint8_t action; /*!< 0x00: CS configuration is removed + 0x01: CS configuration is created */ + uint8_t main_mode_type; /*!< 0x01: Mode-1 + 0x02: Mode-2 + 0x03: Mode-3 + */ + uint8_t sub_mode_type; /*!< 0x01: Mode-1 + 0x02: Mode-2 + 0x03: Mode-3 + 0xFF: Unused + */ + uint8_t min_main_mode_steps; /*!< Minimum number of CS main mode steps to be executed before a submode step is executed */ + uint8_t max_main_mode_steps; /*!< Maximum number of CS main mode steps to be executed before a submode step is executed */ + uint8_t main_mode_repetition; /*!< Number of main mode steps taken from the end of the last CS subevent to be repeated at + the beginning of the current CS subevent directly after the last mode-0 step of that event + */ + uint8_t mode_0_steps; /*!< Number of CS mode-0 steps to be included at the beginning of each CS subevent */ + uint8_t role; /*!< 0x00: Initiator + 0x01: Reflector + */ + uint8_t rtt_type; /*!< 0x00: RTT AA Only + 0x01: RTT with 32-bit sounding sequence + 0x02: RTT with 96-bit sounding sequence + 0x03: RTT with 32-bit random sequence + 0x04: RTT with 64-bit random sequence + 0x05: RTT with 96-bit random sequence + 0x06: RTT with 128-bit random sequence + */ + uint8_t cs_sync_phy; /*!< 0x01: LE 1M PHY + 0x02: LE 2M PHY + 0x03: LE 2M 2BT PHY + */ + uint8_t channel_map[10]; /*!< This parameter contains 80 1-bit fields. + The nth such field (in the range 0 to 78) contains the value for the CS channel index n. + Channel n is enabled for CS procedure = 1 + Channel n is disabled for CS procedure = 0 + Channels n = 0, 1, 23, 24, 25, 77, and 78 shall be ignored and shall be set to zero. At least 15 channels shall be enabled. + The most significant bit (bit 79) is reserved for future use. + */ + uint8_t channel_map_repetition; /*!< The number of times the Channel_Map field will be cycled through for non-mode-0 steps within a CS procedure*/ + uint8_t channel_selection_type; /*!< 0x00: Use Channel Selection Algorithm #3b for non-mode-0 CS steps + 0x01: Use Channel Selection Algorithm #3c for non-mode-0 CS steps + */ + uint8_t ch3c_shape; /*!< 0x00: Use Hat shape for user-specified channel sequence + 0x01: Use X shape for user-specified channel sequence + */ + uint8_t ch3c_jump; /*!< Number of channels skipped in each rising and falling sequence */ + uint8_t reserved; /*!< Reserved, shall be set to 0x00 */ + uint8_t t_ip1_time; /*!< 0x0A, 0x14, 0x1E, 0x28, 0x32, 0x3C, 0x50, or 0x91: Interlude time in microseconds between the RTT packets */ + uint8_t t_ip2_time; /*!< 0x0A, 0x14, 0x1E, 0x28, 0x32, 0x3C, 0x50, or 0x91: nterlude time in microseconds between the CS tones */ + uint8_t t_fcs_time; /*!< 0x0F, 0x14, 0x1E, 0x28, 0x32, 0x3C, 0x50, 0x64, 0x78, or 0x96: Time in microseconds for frequency changes */ + uint8_t t_pm_time; /*!< 0x0A, 0x14, or 0x28: Time in microseconds for the phase measurement period of the CS tones */ + } cs_config_update; /*!< Event parameter of ESP_GAP_BLE_CS_CONFIG_CMPL_EVT */ + /** + * @brief ESP_GAP_BLE_CS_SET_PROC_PARAMS_CMPL_EVT + */ + struct ble_cs_set_proc_params { + uint8_t status; /*!< 0x00: Channel sounding set procedure_Parameters command successful + other: Channel sounding set procedure_Parameters command failed */ + uint16_t conn_handle; /*!< Connection Handle */ + } cs_set_proc_params; /*!< Event parameter of ESP_GAP_BLE_CS_SET_PROC_PARAMS_CMPL_EVT */ + /** + * @brief ESP_GAP_BLE_CS_SET_CHANNEL_CLASS_CMPL_EVT + */ + struct ble_cs_set_channel_class { + uint8_t status; /*!< 0x00: Channel sounding set channel classification command successful + other: Channel sounding set channel classification command failed */ + } cs_set_channel_class; /*!< Event parameter of ESP_GAP_BLE_CS_SET_CHANNEL_CLASS_CMPL_EVT */ + /** + * @brief ESP_GAP_BLE_CS_PROC_ENABLE_CMPL_EVT + */ + struct ble_cs_proc_enable { + uint8_t status; /*!< 0x00: Channel sounding procedure enable command successful + other: Channel sounding procedure enable command failed */ + uint16_t conn_handle; /*!< Connection Handle */ + uint8_t config_id; /*!< CS configuration identifier */ + uint8_t state; /*!< 0x00: CS procedures are disabled + 0x01: CS procedures are enabled + */ + uint8_t tone_Ant_config_select; /*!< Antenna Configuration Index. Range:0x00 to 0x07*/ + int8_t select_tx_power; /*!< Transmit power level used for CS procedure. Range: -127 to 20. Units: dBm */ + uint32_t subevent_Len; /*!< Duration for each CS subevent in microseconds. Range: 1250 μs to 4 s */ + uint8_t subevents_per_event; /*!< Number of CS subevents anchored off the same ACL connection event. Range: 0x01 to 0x20 */ + uint16_t subevent_interval; /*!< Time between consecutive CS subevents anchored off the same ACL connection event. Units: 0.625 ms */ + uint16_t event_interval; /*!< Number of ACL connection events between consecutive CS event anchor points */ + uint16_t procedure_interval; /*!< Number of ACL connection events between consecutive CS procedure anchor points */ + uint16_t procedure_count; /*!< 0x0000: CS procedures to continue until disabled + other: Number of CS procedures to be scheduled */ + uint16_t max_procedure_len; /*!< Maximum duration for each CS procedure. Range: 0x0001 to 0xFFFF. Time = N × 0.625 ms. Time range: 0.625 ms to 40.959375 s */ + } cs_proc_enable; /*!< Event parameter of ESP_GAP_BLE_CS_PROC_ENABLE_CMPL_EVT */ + /** + * @brief ESP_GAP_BLE_CS_SUBEVENT_RESULT_EVT + */ + struct ble_cs_subevt_result { + uint16_t conn_handle; /*!< 0x0000 to 0x0EFF: Connection Handle + 0x0FFF: CS test + */ + uint8_t config_id; /*!< CS configuration identifier. Range: 0 to 3 */ + uint16_t start_acl_conn_event_counter; /*!< Starting ACL connection event counter for the results reported in the event */ + uint16_t procedure_counter; /*!< CS procedure count since completion of the Channel Sounding Security Start procedure. Range: 0x0000 to 0xFFFF */ + int16_t frequency_compensation; /*!< 0xC000: Frequency compensation value is not available, or the role is not initiator + other: Frequency compensation value in units of 0.01 ppm (15-bit signed integer). Range: -100 ppm (0x58F0) to +100 ppm (0x2710). Units: 0.01 ppm */ + int8_t reference_power_level; /*!< 0x7F: Reference power level is not applicable + other: Reference power level. Range: -127 to 20. Units: dBm */ + uint8_t procedure_done_status; /*!< bit 0 to 3: + 0x0 = All results complete for the CS procedure + 0x1 = Partial results with more to follow for the CS procedure + 0xF = All subsequent CS procedures aborted + All other values = Reserved for future use + bit 4 to 7: + Reserved for future use + */ + uint8_t subevent_done_status; /*!< bit 0 to 3: + 0x0 = All results complete for the CS subevent + 0x1 = Partial results with more to follow for the CS subevent + 0xF = Current CS subevent aborted + All other values = Reserved for future use + bit 4 to 7: + Reserved for future use + */ + uint8_t abort_reason; /*!< bit 0 to 3: + Indicates the abort reason when Procedure_Done_Status is set to 0xF, otherwise the default value is set to zero. + 0x0 = Report with no abort + 0x1 = Abort because of local Host or remote request + 0x2 = Abort because filtered channel map has less than 15 channels + 0x3 = Abort because the channel map update instant has passed + 0xF = Abort because of unspecified reasons + All other values = Reserved for future use + bit 4 to 7: + Indicates the abort reason when Subevent_Done_Status is set to 0xF, otherwise the default value is set to zero. + 0x0 = Report with no abort + 0x1 = Abort because of local Host or remote request + 0x2 = Abort because no CS_SYNC (mode-0) received + 0x3 = Abort because of scheduling conflicts or limited resources + 0xF = Abort because of unspecified reasons + All other values = Reserved for future use + */ + uint8_t num_ant_paths; /*!< 0x00: Ignored because phase measurement does not occur during the CS step + 0x01 to 0x04: Number of antenna paths used during the phase measurement stage of the CS step */ + uint8_t num_steps_reported; /*!< 0x00 to 0xA0: Number of steps in the CS subevent for which results are reported */ + esp_ble_cs_step_info *step_info; /*!< steps information in the CS subevent */ + } cs_subevt_result; /*!< Event parameter of ESP_GAP_BLE_CS_SUBEVENT_RESULT_EVT */ + /** + * @brief ESP_GAP_BLE_CS_SUBEVENT_RESULT_CONTINUE_EVT + */ + struct ble_cs_subevt_result_continue { + uint16_t conn_handle; /*!< 0x0000 to 0x0EFF: Connection Handle + 0x0FFF: CS test + */ + uint8_t config_id; /*!< CS configuration identifier. Range: 0 to 3 */ + uint8_t proc_done_status; /*!< bit 0 to 3: + 0x0 = All results complete for the CS procedure + 0x1 = Partial results with more to follow for the CS procedure + 0xF = All subsequent CS procedures aborted + All other values = Reserved for future use + bit 4 to 7: + Reserved for future use + */ + uint8_t subevt_done_status; /*!< bit 0 to 3: + 0x0 = All results complete for the CS subevent + 0x1 = Partial results with more to follow for the CS subevent + 0xF = Current CS subevent aborted + All other values = Reserved for future use + bit 4 to 7: + Reserved for future use + */ + uint8_t abort_reason; /*!< bit 0 to 3: + Indicates the abort reason when Procedure_Done_Status is set to 0xF, otherwise the default value is set to zero. + 0x0 = Report with no abort + 0x1 = Abort because of local Host or remote request + 0x2 = Abort because filtered channel map has less than 15 channels + 0x3 = Abort because the channel map update instant has passed + 0xF = Abort because of unspecified reasons + All other values = Reserved for future use + bit 4 to 7: + Indicates the abort reason when Subevent_Done_Status is set to 0xF, otherwise the default value is set to zero. + 0x0 = Report with no abort + 0x1 = Abort because of local Host or remote request + 0x2 = Abort because no CS_SYNC (mode-0) received + 0x3 = Abort because of scheduling conflicts or limited resources + 0xF = Abort because of unspecified reasons + All other values = Reserved for future use + */ + uint8_t num_ant_paths; /*!< 0x00: Ignored because phase measurement does not occur during the CS step + 0x01 to 0x04: Number of antenna paths used during the phase measurement stage of the CS step + */ + uint8_t num_steps_reported; /*!< Number of steps in the CS subevent for which results are reported, Range: 0x00 to 0xA0 */ + esp_ble_cs_step_info *step_info; /*!< steps information in the CS subevent */ + } cs_subevt_result_continue; /*!< Event parameter of ESP_GAP_BLE_CS_SUBEVENT_RESULT_CONTINUE_EVT */ +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) } esp_ble_gap_cb_param_t; /** @@ -3555,6 +4281,170 @@ esp_err_t esp_ble_gap_set_periodic_adv_response_data(esp_ble_per_adv_response_da */ esp_err_t esp_ble_gap_set_periodic_sync_subevent(esp_ble_per_sync_subevent_params *sync_subevent_params); +/** + * @brief This function is used to read the CS capabilities that are supported by the local Controller + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_read_local_supported_capabilities(void); + +/** + * @brief This function is used to query the CS capabilities that are supported by the remote Controller + * + * + * + * @param[in] conn_handle: connection handle. + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_read_remote_supported_capabilities(uint16_t conn_handle); + +/** + * @brief This function is used to write the cached copy of the CS capabilities that are supported by the remote Controller + * + * + * + * @param[in] cached_remote_supp_caps_params: CS write cached remote supported capabilities parameters + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_write_cached_remote_supported_capabilities(esp_ble_cs_write_cached_remote_supp_caps_params *cached_remote_supp_caps_params); + +/** + * @brief This function is used to start or restart the Channel Sounding Security Start procedure in the local Controller + * + * + * + * @param[in] conn_handle: the ACL connection identified + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_security_enable(uint16_t conn_handle); + +/** + * @brief This function is used to set default CS settings in the local Controller + * + * + * + * @param[in] default_setting_params: CS set default settings parameters + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_set_default_settings(esp_ble_cs_set_default_settings_params *default_setting_params); + +/** + * @brief This function is used to read the per-channel mode-0 Frequency Actuation Error table of the remote Controller + * + * + * + * @param[in] conn_handle: the ACL connection identified + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_read_remote_fae_table(uint16_t conn_handle); + +/** + * @brief This function is used to write a cached copy of the per-channel mode-0 Frequency Actuation Error table of the remote device in the local Controller + * + * + * + * @param[in] write_cached_remote_fae_tab_params: CS write cached remote FAE table parameters + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_write_cached_remote_fae_table(esp_ble_cs_write_cached_remote_fae_table_params *write_cached_remote_fae_tab_params); + +/** + * @brief This function is used to create a new CS configuration or update an existing CS configuration in the local and/or the remote Controller + * + * + * + * @param[in] create_config_params: CS create config parameters + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_create_config(esp_ble_cs_create_config_params *create_config_params); + +/** + * @brief This function is used to remove a CS configuration from the local Controller + * + * + * + * @param[in] remove_config_params: CS remove config parameters + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_remove_config(esp_ble_cs_remove_config_params *remove_config_params); + +/** + * @brief This function is used to update the channel classification based on its local information + * + * + * + * @param[in] channel_class_params: CS set channel classification parameters + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_set_channel_classification(esp_ble_cs_set_channel_class_params *channel_class_params); + +/** + * @brief This function is used to set the parameters for the scheduling of one or more CS procedures by the local Controller + * + * + * + * @param[in] procedure_params: CS set channel procedure parameters + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_set_procedure_params(esp_ble_cs_set_proc_params *procedure_params); + +/** + * @brief This function is used to enable or disable the scheduling of CS procedures by the local Controller + * + * + * + * @param[in] procedure_enable_params: CS procedure enable parameters + * + * + * @return + * - ESP_OK : success + * - other : failed + */ +esp_err_t esp_ble_cs_procedure_enable(esp_ble_cs_procedure_enable_params *procedure_enable_params); + #ifdef __cplusplus } #endif diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c index ab17a88b128..1c95371afa3 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_act.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_act.c @@ -6366,6 +6366,87 @@ void bta_dm_api_set_periodic_sync_subevt(tBTA_DM_MSG *p_data) } #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +void bta_dm_api_cs_read_local_supported_caps(tBTA_DM_MSG *p_data) +{ + BTM_BleCSReadLocalSuppCaps(); +} + +void bta_dm_api_cs_read_remote_supported_caps(tBTA_DM_MSG *p_data) +{ + BTM_BleCSReadRemoteSuppCaps(p_data->read_remote_supp_caps.conn_handle); +} + +void bta_dm_api_cs_write_cached_remote_supported_caps(tBTA_DM_MSG *p_data) +{ + tBTA_DM_API_CS_WRITE_CACHED_REMOTE_SUPP_CAPS *p = &p_data->write_cached_remote_caps; + BTM_BleGapWriteCachedRemoteSupportedCaps(p->conn_handle, p->num_config_supported, p->max_consecutive_proc_supported, + p->num_ant_supported, p->max_ant_paths_supported, p->roles_supported, + p->modes_supported, p->rtt_capability, p->rtt_aa_only_n, + p->rtt_sounding_n, p->rtt_random_payload_n, p->NADM_sounding_capability, + p->NADM_random_capability, p->cs_sync_phys_supported, p->subfeatures_supported, + p->T_IP1_times_supported, p->T_IP2_times_supported, p->T_FCS_times_supported, + p->T_PM_times_supported, p->T_SW_times_supported, p->TX_SNR_capability); +} + +void bta_dm_api_cs_security_enable(tBTA_DM_MSG *p_data) +{ + BTM_BleGapCsSecurityEnable(p_data->security_enable.conn_handle); +} + +void bta_dm_api_cs_set_default_settings(tBTA_DM_MSG *p_data) +{ + BTM_BleGapCsSetDefaultSetting(p_data->set_default_setting_params.conn_handle, p_data->set_default_setting_params.role_enable, + p_data->set_default_setting_params.cs_sync_ant_selection, p_data->set_default_setting_params.max_tx_power); +} + +void bta_dm_api_cs_read_remote_fae_table(tBTA_DM_MSG *p_data) +{ + BTM_BleGapCsReadRemoteFaeTable(p_data->read_remote_tab.conn_handle); +} + +void bta_dm_api_cs_write_cached_remote_fae_table(tBTA_DM_MSG *p_data) +{ + BTM_BleGapWriteCachedRemoteFaeTable(p_data->write_cached_remote_fae_tab_params.conn_handle, p_data->write_cached_remote_fae_tab_params.remote_fae_table); +} + +void bta_dm_api_cs_create_config(tBTA_DM_MSG *p_data) +{ + tBTA_DM_API_CS_CREATE_CONFIG_PARAMS *p = &p_data->create_config_params; + BTM_BleGapCsCreateConfig(p->conn_handle, p->config_id, p->create_context, + p->main_mode_type, p->sub_mode_type, p->min_main_mode_steps, + p->max_main_mode_steps, p->main_mode_repetition, p->mode_0_steps, + p->role, p->rtt_type, p->cs_sync_phy, &p->channel_map[0], + p->channel_map_repetition, p->channel_selection_type, p->ch3c_shape, + p->ch3c_jump, p->reserved); +} + +void bta_dm_api_cs_remove_config(tBTA_DM_MSG *p_data) +{ + BTM_BleGapCsRemoveConfig(p_data->remove_config_params.conn_handle, p_data->remove_config_params.config_id); +} + +void bta_dm_api_cs_set_channel_classification(tBTA_DM_MSG *p_data) +{ + BTM_BleGapCsSetChannelClass(p_data->set_channel_class_params.channel_class); +} +void bta_dm_api_cs_set_procedure_params(tBTA_DM_MSG *p_data) +{ + tBTA_DM_API_CS_SET_PROC_PARAMS *p = &p_data->set_proc_params; + BTM_BleGapCsSetProcPatams(p->conn_handle, p->config_id, p->max_procedure_len, + p->min_procedure_interval, p->max_procedure_interval, + p->max_procedure_count, p->min_subevent_len, + p->max_subevent_len, p->tone_ant_config_selection, + p->phy, p->tx_power_delta, p->preferred_peer_antenna, + p->SNR_control_initiator, p->SNR_control_reflector); +} + +void bta_dm_api_cs_procedure_enable(tBTA_DM_MSG *p_data) +{ + BTM_BleGapCsProcEnable(p_data->proc_enable_params.conn_handle, p_data->proc_enable_params.config_id, p_data->proc_enable_params.enable); +} +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + #if (BLE_HOST_SETUP_STORAGE_EN == TRUE) /******************************************************************************* ** diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c index 65f564ac08a..7ffdabfa82f 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_api.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_api.c @@ -3240,6 +3240,167 @@ void BTA_DmBleGapSetPeriodicSyncSubevt(uint16_t sync_handle, uint16_t periodic_a #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +void BTA_DmBleGapReadLocalSupportedCaps(void) +{ + tBTA_DM_API_CS_READ_LOCAL_SUPP_CAPS *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_READ_LOCAL_SUPP_CAPS *)osi_malloc(sizeof(tBTA_DM_API_CS_READ_LOCAL_SUPP_CAPS))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_READ_LOCAL_SUPPORTED_CAPS; + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapReadRemoteSupportedCaps(uint16_t conn_handle) +{ + tBTA_DM_API_CS_READ_REMOTE_SUPP_CAPS *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_READ_REMOTE_SUPP_CAPS *)osi_malloc(sizeof(tBTA_DM_API_CS_READ_REMOTE_SUPP_CAPS))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_READ_REMOTE_SUPPORTED_CAPS; + p_msg->conn_handle = conn_handle; + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapWriteCachedRemoteSupportedCaps(tBTA_DM_CS_WRITE_CACHED_REMOTE_SUPP_CAPS *write_cachedremote_supp_caps) +{ + tBTA_DM_API_CS_WRITE_CACHED_REMOTE_SUPP_CAPS *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_WRITE_CACHED_REMOTE_SUPP_CAPS *)osi_malloc(sizeof(tBTA_DM_API_CS_WRITE_CACHED_REMOTE_SUPP_CAPS))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPS; + memcpy(&p_msg->conn_handle, &write_cachedremote_supp_caps->conn_handle, sizeof(tBTA_DM_CS_WRITE_CACHED_REMOTE_SUPP_CAPS)); + // p_msg->conn_handle = write_cachedremote_supp_caps->conn_handle; + // p_msg->num_config_supported = write_cachedremote_supp_caps->num_config_supported; + // p_msg->max_consecutive_proc_supported = write_cachedremote_supp_caps->max_consecutive_proc_supported; + // p_msg->num_ant_supported = write_cachedremote_supp_caps->num_ant_supported; + // p_msg->max_ant_paths_supported = write_cachedremote_supp_caps->max_ant_paths_supported; + // p_msg->roles_supported = write_cachedremote_supp_caps->roles_supported; + // p_msg->modes_supported = write_cachedremote_supp_caps->modes_supported; + // p_msg->rtt_capability = write_cachedremote_supp_caps->rtt_capability; + // p_msg->rtt_aa_only_n = write_cachedremote_supp_caps->rtt_aa_only_n; + // p_msg->rtt_sounding_n = write_cachedremote_supp_caps->rtt_sounding_n; + // p_msg->rtt_random_payload_n = write_cachedremote_supp_caps->rtt_random_payload_n; + // p_msg->NADM_sounding_capability = write_cachedremote_supp_caps->NADM_sounding_capability; + // p_msg->NADM_random_capability = write_cachedremote_supp_caps->NADM_random_capability; + // p_msg->cs_sync_phys_supported = write_cachedremote_supp_caps->cs_sync_phys_supported; + // p_msg->subfeatures_supported = write_cachedremote_supp_caps->subfeatures_supported; + // p_msg->T_IP1_times_supported = write_cachedremote_supp_caps->T_IP1_times_supported; + // p_msg->T_IP2_times_supported = write_cachedremote_supp_caps->T_IP2_times_supported; + // p_msg->T_FCS_times_supported = write_cachedremote_supp_caps->T_FCS_times_supported; + // p_msg->T_PM_times_supported = write_cachedremote_supp_caps->T_PM_times_supported; + // p_msg->T_SW_times_supported = write_cachedremote_supp_caps->T_SW_times_supported; + // p_msg->TX_SNR_capability = write_cachedremote_supp_caps->TX_SNR_capability; + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapCsSecurityEnable(uint16_t conn_handle) +{ + tBTA_DM_API_CS_SECURITY_ENABLE *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_SECURITY_ENABLE *)osi_malloc(sizeof(tBTA_DM_API_CS_SECURITY_ENABLE))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_SECURITY_ENABLE; + p_msg->conn_handle = conn_handle; + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapCsSetDefaultSetting(uint16_t conn_handle, uint8_t role_enable, uint8_t cs_sync_ant_selection, int8_t max_tx_power) +{ + tBTA_DM_API_CS_SET_DEFAULT_SETTING_PARAMS *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_SET_DEFAULT_SETTING_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_CS_SET_DEFAULT_SETTING_PARAMS))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_SET_DEFAULT_SETTINGS; + p_msg->conn_handle = conn_handle; + p_msg->role_enable = role_enable; + p_msg->cs_sync_ant_selection = cs_sync_ant_selection; + p_msg->max_tx_power = max_tx_power; + bta_sys_sendmsg(p_msg); + } +} +void BTA_DmBleGapCsReadRemoteFaeTable(uint16_t conn_handle) +{ + tBTA_DM_API_CS_READ_REMOTE_TAB *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_READ_REMOTE_TAB *)osi_malloc(sizeof(tBTA_DM_API_CS_READ_REMOTE_TAB))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_READ_REMOTE_FAE_TABLE; + p_msg->conn_handle = conn_handle; + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapWriteCachedRemoteFaeTable(uint16_t conn_handle, uint8_t *remote_fae_table, uint8_t table_len) +{ + tBTA_DM_API_CS_WRITE_CACHED_REMOTE_FAE_TAB_PARAMS *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_WRITE_CACHED_REMOTE_FAE_TAB_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_CS_WRITE_CACHED_REMOTE_FAE_TAB_PARAMS))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_WRITE_CACHED_REMOTE_FAE_TABLE; + p_msg->conn_handle = conn_handle; + memcpy(&p_msg->remote_fae_table[0], remote_fae_table, table_len); + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapCsCreateConfig(tBTA_DM_CS_CREATE_CONFIG_PARAMS *create_config_params) +{ + tBTA_DM_API_CS_CREATE_CONFIG_PARAMS *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_CREATE_CONFIG_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_CS_CREATE_CONFIG_PARAMS))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_CREATE_CONFIG; + memcpy(&p_msg->conn_handle, &create_config_params->conn_handle, sizeof(tBTA_DM_CS_CREATE_CONFIG_PARAMS)); + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapCsRemoveConfig(uint16_t conn_handle, uint8_t config_id) +{ + tBTA_DM_API_CS_REMOVE_CONFIG_PARAMS *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_REMOVE_CONFIG_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_CS_REMOVE_CONFIG_PARAMS))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_REMOVE_CONFIG; + p_msg->conn_handle = conn_handle; + p_msg->config_id = config_id; + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapCsSetChannelClass(uint8_t *channel_class, uint8_t channl_len) +{ + tBTA_DM_API_CS_SET_CHANNEL_CLASS_PARAMS *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_SET_CHANNEL_CLASS_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_CS_SET_CHANNEL_CLASS_PARAMS))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_SET_CAHNNEL_CLASSIFICATION; + memcpy(&p_msg->channel_class[0], channel_class, channl_len); + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapCsSetProcPatams(tBTA_DM_CS_SET_PROC_PARAMS *set_proc_params) +{ + tBTA_DM_API_CS_SET_PROC_PARAMS *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_SET_PROC_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_CS_SET_PROC_PARAMS))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_SET_PROCEDURE_PARAMS; + memcpy(&p_msg->conn_handle, &set_proc_params->conn_handle, sizeof(tBTA_DM_CS_SET_PROC_PARAMS)); + bta_sys_sendmsg(p_msg); + } +} + +void BTA_DmBleGapCsProcEnable(uint16_t conn_handle, uint8_t config_id, uint8_t enable) +{ + tBTA_DM_API_CS_PROC_ENABLE_PARAMS *p_msg; + + if ((p_msg = (tBTA_DM_API_CS_PROC_ENABLE_PARAMS *)osi_malloc(sizeof(tBTA_DM_API_CS_PROC_ENABLE_PARAMS))) != NULL) { + p_msg->hdr.event = BTA_DM_API_CS_PROCEDURE_ENABLE; + p_msg->conn_handle = conn_handle; + p_msg->config_id = config_id; + p_msg->enable = enable; + bta_sys_sendmsg(p_msg); + } +} + +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + /******************************************************************************* ** ** Function BTA_VendorInit diff --git a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c index 362795cd32c..77bc60a7f2f 100644 --- a/components/bt/host/bluedroid/bta/dm/bta_dm_main.c +++ b/components/bt/host/bluedroid/bta/dm/bta_dm_main.c @@ -349,6 +349,20 @@ const tBTA_DM_ACTION bta_dm_action[BTA_DM_MAX_EVT] = { bta_dm_api_set_periodic_adv_response_data, /* BTA_DM_API_SET_PA_RSP_DATA */ bta_dm_api_set_periodic_sync_subevt, /* BTA_DM_API_SET_PA_SYNC_SUBEVT */ #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + bta_dm_api_cs_read_local_supported_caps, /* BTA_DM_API_CS_READ_LOCAL_SUPPORTED_CAPS */ + bta_dm_api_cs_read_remote_supported_caps, /* BTA_DM_API_CS_READ_REMOTE_SUPPORTED_CAPS */ + bta_dm_api_cs_write_cached_remote_supported_caps, /* BTA_DM_API_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPS */ + bta_dm_api_cs_security_enable, /* BTA_DM_API_CS_SECURITY_ENABLE */ + bta_dm_api_cs_set_default_settings, /* BTA_DM_API_CS_SET_DEFAULT_SETTINGS */ + bta_dm_api_cs_read_remote_fae_table, /* BTA_DM_API_CS_READ_REMOTE_FAE_TABLE */ + bta_dm_api_cs_write_cached_remote_fae_table, /* BTA_DM_API_CS_WRITE_CACHED_REMOTE_FAE_TABLE */ + bta_dm_api_cs_create_config, /* BTA_DM_API_CS_CREATE_CONFIG */ + bta_dm_api_cs_remove_config, /* BTA_DM_API_CS_REMOVE_CONFIG */ + bta_dm_api_cs_set_channel_classification, /* BTA_DM_API_CS_SET_CAHNNEL_CLASSIFICATION */ + bta_dm_api_cs_set_procedure_params, /* BTA_DM_API_CS_SET_PROCEDURE_PARAMS */ + bta_dm_api_cs_procedure_enable, /* BTA_DM_API_CS_PROCEDURE_ENABLE */ +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) }; diff --git a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h index 32b7e40a61e..9ef189a26f6 100644 --- a/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h +++ b/components/bt/host/bluedroid/bta/dm/include/bta_dm_int.h @@ -340,6 +340,20 @@ enum { BTA_DM_API_SET_PA_RSP_DATA, BTA_DM_API_SET_PA_SYNC_SUBEVT, #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + BTA_DM_API_CS_READ_LOCAL_SUPPORTED_CAPS, + BTA_DM_API_CS_READ_REMOTE_SUPPORTED_CAPS, + BTA_DM_API_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPS, + BTA_DM_API_CS_SECURITY_ENABLE, + BTA_DM_API_CS_SET_DEFAULT_SETTINGS, + BTA_DM_API_CS_READ_REMOTE_FAE_TABLE, + BTA_DM_API_CS_WRITE_CACHED_REMOTE_FAE_TABLE, + BTA_DM_API_CS_CREATE_CONFIG, + BTA_DM_API_CS_REMOVE_CONFIG, + BTA_DM_API_CS_SET_CAHNNEL_CLASSIFICATION, + BTA_DM_API_CS_SET_PROCEDURE_PARAMS, + BTA_DM_API_CS_PROCEDURE_ENABLE, +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) BTA_DM_MAX_EVT }; @@ -1206,6 +1220,122 @@ typedef struct { } tBTA_DM_API_BLE_PA_SYNC_SUBEVT; #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +typedef struct { + BT_HDR hdr; +} tBTA_DM_API_CS_READ_LOCAL_SUPP_CAPS; +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; +} tBTA_DM_API_CS_READ_REMOTE_SUPP_CAPS; +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 num_config_supported; + UINT16 max_consecutive_proc_supported; + UINT8 num_ant_supported; + UINT8 max_ant_paths_supported; + UINT8 roles_supported; + UINT8 modes_supported; + UINT8 rtt_capability; + UINT8 rtt_aa_only_n; + UINT8 rtt_sounding_n; + UINT8 rtt_random_payload_n; + UINT16 NADM_sounding_capability; + UINT16 NADM_random_capability; + UINT8 cs_sync_phys_supported; + UINT16 subfeatures_supported; + UINT16 T_IP1_times_supported; + UINT16 T_IP2_times_supported; + UINT16 T_FCS_times_supported; + UINT16 T_PM_times_supported; + UINT8 T_SW_times_supported; + UINT8 TX_SNR_capability; +} tBTA_DM_API_CS_WRITE_CACHED_REMOTE_SUPP_CAPS; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; +} tBTA_DM_API_CS_SECURITY_ENABLE; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 role_enable; + UINT8 cs_sync_ant_selection; + INT8 max_tx_power; +} tBTA_DM_API_CS_SET_DEFAULT_SETTING_PARAMS; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; +} tBTA_DM_API_CS_READ_REMOTE_TAB; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 remote_fae_table[72]; +} tBTA_DM_API_CS_WRITE_CACHED_REMOTE_FAE_TAB_PARAMS; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 config_id; + UINT8 create_context; + UINT8 main_mode_type; + UINT8 sub_mode_type; + UINT8 min_main_mode_steps; + UINT8 max_main_mode_steps; + UINT8 main_mode_repetition; + UINT8 mode_0_steps; + UINT8 role; + UINT8 rtt_type; + UINT8 cs_sync_phy; + UINT8 channel_map[10]; + UINT8 channel_map_repetition; + UINT8 channel_selection_type; + UINT8 ch3c_shape; + UINT8 ch3c_jump; + UINT8 reserved; +} tBTA_DM_API_CS_CREATE_CONFIG_PARAMS; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 config_id; +} tBTA_DM_API_CS_REMOVE_CONFIG_PARAMS; + +typedef struct { + BT_HDR hdr; + UINT8 channel_class[10]; +} tBTA_DM_API_CS_SET_CHANNEL_CLASS_PARAMS; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 config_id; + UINT16 max_procedure_len; + UINT16 min_procedure_interval; + UINT16 max_procedure_interval; + UINT16 max_procedure_count; + UINT32 min_subevent_len; + UINT32 max_subevent_len; + UINT8 tone_ant_config_selection; + UINT8 phy; + UINT8 tx_power_delta; + UINT8 preferred_peer_antenna; + UINT8 SNR_control_initiator; + UINT8 SNR_control_reflector; +} tBTA_DM_API_CS_SET_PROC_PARAMS; + +typedef struct { + BT_HDR hdr; + UINT16 conn_handle; + UINT8 config_id; + UINT8 enable; +} tBTA_DM_API_CS_PROC_ENABLE_PARAMS; +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + #endif /* BLE_INCLUDED */ #if (BLE_HOST_REMOVE_AN_ACL_EN == TRUE) @@ -1931,6 +2061,20 @@ typedef union { tBTA_DM_API_BLE_PA_RSP_DATA pa_rsp_data; tBTA_DM_API_BLE_PA_SYNC_SUBEVT pa_sync_subevt; #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + tBTA_DM_API_CS_READ_LOCAL_SUPP_CAPS read_local_supp_caps; + tBTA_DM_API_CS_READ_REMOTE_SUPP_CAPS read_remote_supp_caps; + tBTA_DM_API_CS_WRITE_CACHED_REMOTE_SUPP_CAPS write_cached_remote_caps; + tBTA_DM_API_CS_SECURITY_ENABLE security_enable; + tBTA_DM_API_CS_SET_DEFAULT_SETTING_PARAMS set_default_setting_params; + tBTA_DM_API_CS_READ_REMOTE_TAB read_remote_tab; + tBTA_DM_API_CS_WRITE_CACHED_REMOTE_FAE_TAB_PARAMS write_cached_remote_fae_tab_params; + tBTA_DM_API_CS_CREATE_CONFIG_PARAMS create_config_params; + tBTA_DM_API_CS_REMOVE_CONFIG_PARAMS remove_config_params; + tBTA_DM_API_CS_SET_CHANNEL_CLASS_PARAMS set_channel_class_params; + tBTA_DM_API_CS_SET_PROC_PARAMS set_proc_params; + tBTA_DM_API_CS_PROC_ENABLE_PARAMS proc_enable_params; +#endif } tBTA_DM_MSG; @@ -2603,4 +2747,18 @@ void bta_dm_api_set_periodic_adv_subevt_data(tBTA_DM_MSG *p_data); void bta_dm_api_set_periodic_adv_response_data(tBTA_DM_MSG *p_data); void bta_dm_api_set_periodic_sync_subevt(tBTA_DM_MSG *p_data); #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +void bta_dm_api_cs_read_local_supported_caps(tBTA_DM_MSG *p_data); +void bta_dm_api_cs_read_remote_supported_caps(tBTA_DM_MSG *p_data); +void bta_dm_api_cs_write_cached_remote_supported_caps(tBTA_DM_MSG *p_data); +void bta_dm_api_cs_security_enable(tBTA_DM_MSG *p_data); +void bta_dm_api_cs_set_default_settings(tBTA_DM_MSG *p_data); +void bta_dm_api_cs_read_remote_fae_table(tBTA_DM_MSG *p_data); +void bta_dm_api_cs_write_cached_remote_fae_table(tBTA_DM_MSG *p_data); +void bta_dm_api_cs_create_config(tBTA_DM_MSG *p_data); +void bta_dm_api_cs_remove_config(tBTA_DM_MSG *p_data); +void bta_dm_api_cs_set_channel_classification(tBTA_DM_MSG *p_data); +void bta_dm_api_cs_set_procedure_params(tBTA_DM_MSG *p_data); +void bta_dm_api_cs_procedure_enable(tBTA_DM_MSG *p_data); +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) #endif /* BTA_DM_INT_H */ diff --git a/components/bt/host/bluedroid/bta/include/bta/bta_api.h b/components/bt/host/bluedroid/bta/include/bta/bta_api.h index 17e439c2ad0..23bf8915d9b 100644 --- a/components/bt/host/bluedroid/bta/include/bta/bta_api.h +++ b/components/bt/host/bluedroid/bta/include/bta/bta_api.h @@ -1228,6 +1228,71 @@ typedef struct { tBTA_DM_SEARCH *p_data; /* Union of all search callback structures */ } tBTA_DM_SEARCH_PARAM; +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +typedef struct { + UINT16 conn_handle; + UINT8 num_config_supported; + UINT16 max_consecutive_proc_supported; + UINT8 num_ant_supported; + UINT8 max_ant_paths_supported; + UINT8 roles_supported; + UINT8 modes_supported; + UINT8 rtt_capability; + UINT8 rtt_aa_only_n; + UINT8 rtt_sounding_n; + UINT8 rtt_random_payload_n; + UINT16 NADM_sounding_capability; + UINT16 NADM_random_capability; + UINT8 cs_sync_phys_supported; + UINT16 subfeatures_supported; + UINT16 T_IP1_times_supported; + UINT16 T_IP2_times_supported; + UINT16 T_FCS_times_supported; + UINT16 T_PM_times_supported; + UINT8 T_SW_times_supported; + UINT8 TX_SNR_capability; +} tBTA_DM_CS_WRITE_CACHED_REMOTE_SUPP_CAPS; + +typedef struct { + UINT16 conn_handle; + UINT8 config_id; + UINT8 create_context; + UINT8 main_mode_type; + UINT8 sub_mode_type; + UINT8 min_main_mode_steps; + UINT8 max_main_mode_steps; + UINT8 main_mode_repetition; + UINT8 mode_0_steps; + UINT8 role; + UINT8 rtt_type; + UINT8 cs_sync_phy; + UINT8 channel_map[10]; + UINT8 channel_map_repetition; + UINT8 channel_selection_type; + UINT8 ch3c_shape; + UINT8 ch3c_jump; + UINT8 reserved; +} tBTA_DM_CS_CREATE_CONFIG_PARAMS; + +typedef struct { + UINT16 conn_handle; + UINT8 config_id; + UINT16 max_procedure_len; + UINT16 min_procedure_interval; + UINT16 max_procedure_interval; + UINT16 max_procedure_count; + uint32_t min_subevent_len; + uint32_t max_subevent_len; + UINT8 tone_ant_config_selection; + UINT8 phy; + UINT8 tx_power_delta; + UINT8 preferred_peer_antenna; + UINT8 SNR_control_initiator; + UINT8 SNR_control_reflector; +} tBTA_DM_CS_SET_PROC_PARAMS; + +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + /* Search callback */ typedef void (tBTA_DM_SEARCH_CBACK)(tBTA_DM_SEARCH_EVT event, tBTA_DM_SEARCH *p_data); @@ -1720,6 +1785,22 @@ typedef struct { #define BTA_BLE_GAP_PERIODIC_ADV_RESPONSE_REPORT_EVT BTM_BLE_GAP_PERIODIC_ADV_RESPONSE_REPORT_EVT #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +#define BTA_BLE_GAP_CS_READ_LOCAL_SUPP_CAPS_EVT BTM_BLE_GAP_CS_READ_LOCAL_SUPP_CAPS_EVT +#define BTA_BLE_GAP_CS_WRITE_CACHED_REMOTE_SUPP_CAPS_EVT BTM_BLE_GAP_CS_WRITE_CACHED_REMOTE_SUPP_CAPS_EVT +#define BTA_BLE_GAP_CS_SET_DEFAULT_SETTINGS_EVT BTM_BLE_GAP_CS_SET_DEFAULT_SETTINGS_EVT +#define BTA_BLE_GAP_CS_WRITE_CACHED_REMOTE_FAE_TAB_EVT BTM_BLE_GAP_CS_WRITE_CACHED_REMOTE_FAE_TAB_EVT +#define BTA_BLE_GAP_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT BTM_BLE_GAP_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT +#define BTA_BLE_GAP_CS_SET_CHANNEL_CLASS_CMPL_EVT BTM_BLE_GAP_CS_SET_CHANNEL_CLASS_CMPL_EVT +#define BTA_BLE_GAP_CS_PROC_PARAMS_CMPL_EVT BTM_BLE_GAP_CS_PROC_PARAMS_CMPL_EVT +#define BTA_BLE_GAP_CS_PROC_ENABLE_CMPL_EVT BTM_BLE_GAP_CS_PROC_ENABLE_CMPL_EVT +#define BTA_BLE_GAP_CS_READ_REMOTE_FAE_TABLE_CMPL_EVT BTM_BLE_GAP_CS_READ_REMOTE_FAE_TABLE_CMPL_EVT +#define BTA_BLE_GAP_CS_SECURITY_ENABLE_CMPL_EVT BTM_BLE_GAP_CS_SECURITY_ENABLE_CMPL_EVT +#define BTA_BLE_GAP_CS_CONFIG_CMPL_EVT BTM_BLE_GAP_CS_CONFIG_CMPL_EVT +#define BTA_BLE_GAP_CS_SUBEVENT_RESULT_EVT BTM_BLE_GAP_CS_SUBEVENT_RESULT_EVT +#define BTA_BLE_GAP_CS_SUBEVENT_RESULT_CONTINUE_EVT BTM_BLE_GAP_CS_SUBEVENT_RESULT_CONTINUE_EVT +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + #define BTA_DM_BLE_5_GAP_UNKNOWN_EVT BTM_BLE_5_GAP_UNKNOWN_EVT typedef tBTM_BLE_5_GAP_EVENT tBTA_DM_BLE_5_GAP_EVENT; @@ -3120,6 +3201,21 @@ void BTA_DmBleGapSetPeriodicAdvRspData(uint16_t sync_handle, uint16_t request_ev void BTA_DmBleGapSetPeriodicSyncSubevt(uint16_t sync_handle, uint16_t periodic_adv_properties, uint8_t num_subevents_to_sync, uint8_t *subevent); #endif// (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +void BTA_DmBleGapReadLocalSupportedCaps(void); +void BTA_DmBleGapReadRemoteSupportedCaps(uint16_t conn_handle); +void BTA_DmBleGapWriteCachedRemoteSupportedCaps(tBTA_DM_CS_WRITE_CACHED_REMOTE_SUPP_CAPS *write_cachedremote_supp_caps); +void BTA_DmBleGapCsSecurityEnable(uint16_t conn_handle); +void BTA_DmBleGapCsSetDefaultSetting(uint16_t conn_handle, uint8_t role_enable, uint8_t cs_sync_ant_selection, int8_t max_tx_power); +void BTA_DmBleGapCsReadRemoteFaeTable(uint16_t conn_handle); +void BTA_DmBleGapWriteCachedRemoteFaeTable(uint16_t conn_handle, uint8_t *remote_fae_table, uint8_t table_len); +void BTA_DmBleGapCsCreateConfig(tBTA_DM_CS_CREATE_CONFIG_PARAMS *create_config_params); +void BTA_DmBleGapCsRemoveConfig(uint16_t conn_handle, uint8_t config_id); +void BTA_DmBleGapCsSetChannelClass(uint8_t *channel_class, uint8_t channl_len); +void BTA_DmBleGapCsSetProcPatams(tBTA_DM_CS_SET_PROC_PARAMS *set_proc_params); +void BTA_DmBleGapCsProcEnable(uint16_t conn_handle, uint8_t config_id, uint8_t enable); +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + /******************************************************************************* ** ** Function BTA_DmBleSetStorageParams diff --git a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c index f42ab484a9c..7a22f2fa5a1 100644 --- a/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c +++ b/components/bt/host/bluedroid/btc/profile/std/gap/btc_gap_ble.c @@ -1328,6 +1328,161 @@ void btc_ble_5_gap_callback(tBTA_DM_BLE_5_GAP_EVENT event, param.pa_rsp_rpt_evt.pa_rsp_info = (esp_ble_pa_rsp_info *)params->pa_rsp_rpt_evt.rsp_data_info; break; #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + case BTA_BLE_GAP_CS_READ_LOCAL_SUPP_CAPS_EVT: + msg.act = ESP_GAP_BLE_CS_READ_LOCAL_SUPP_CAPS_EVT; + param.cs_read_local_supp_caps.status = params->cs_read_local_supp_caps.status; + param.cs_read_local_supp_caps.conn_handle = params->cs_read_local_supp_caps.conn_handle; + param.cs_read_local_supp_caps.num_config_supported = params->cs_read_local_supp_caps.num_config_supported; + param.cs_read_local_supp_caps.max_consecutive_proc_supported = params->cs_read_local_supp_caps.max_consecutive_proc_supported; + param.cs_read_local_supp_caps.num_ant_supported = params->cs_read_local_supp_caps.num_ant_supported; + param.cs_read_local_supp_caps.max_ant_paths_supported= params->cs_read_local_supp_caps.max_ant_paths_supported; + param.cs_read_local_supp_caps.roles_supported = params->cs_read_local_supp_caps.roles_supported; + param.cs_read_local_supp_caps.modes_supported = params->cs_read_local_supp_caps.modes_supported; + param.cs_read_local_supp_caps.rtt_capability = params->cs_read_local_supp_caps.rtt_capability; + param.cs_read_local_supp_caps.rtt_aa_only_n = params->cs_read_local_supp_caps.rtt_aa_only_n; + param.cs_read_local_supp_caps.rtt_sounding_n = params->cs_read_local_supp_caps.rtt_sounding_n; + param.cs_read_local_supp_caps.rtt_random_payload_n = params->cs_read_local_supp_caps.rtt_random_payload_n; + param.cs_read_local_supp_caps.NADM_sounding_capability = params->cs_read_local_supp_caps.NADM_sounding_capability; + param.cs_read_local_supp_caps.NADM_random_capability = params->cs_read_local_supp_caps.NADM_random_capability; + param.cs_read_local_supp_caps.cs_sync_phys_supported = params->cs_read_local_supp_caps.cs_sync_phys_supported; + param.cs_read_local_supp_caps.subfeatures_supported = params->cs_read_local_supp_caps.subfeatures_supported; + param.cs_read_local_supp_caps.T_IP1_times_supported = params->cs_read_local_supp_caps.T_IP1_times_supported; + param.cs_read_local_supp_caps.T_IP2_times_supported = params->cs_read_local_supp_caps.T_IP2_times_supported; + param.cs_read_local_supp_caps.T_FCS_times_supported = params->cs_read_local_supp_caps.T_FCS_times_supported; + param.cs_read_local_supp_caps.T_PM_times_supported = params->cs_read_local_supp_caps.T_PM_times_supported; + param.cs_read_local_supp_caps.T_SW_times_supported = params->cs_read_local_supp_caps.T_SW_times_supported; + param.cs_read_local_supp_caps.TX_SNR_capability = params->cs_read_local_supp_caps.TX_SNR_capability; + break; + case BTA_BLE_GAP_CS_WRITE_CACHED_REMOTE_SUPP_CAPS_EVT: + msg.act = ESP_GAP_BLE_CS_WRITE_CACHED_REMOTE_SUPP_CAPS_EVT; + param.cs_write_cached_remote_supp_caps.status = params->cs_write_cached_remote_supp_caps.status; + param.cs_write_cached_remote_supp_caps.conn_handle = params->cs_write_cached_remote_supp_caps.conn_handle; + break; + case BTA_BLE_GAP_CS_SET_DEFAULT_SETTINGS_EVT: + msg.act = ESP_GAP_BLE_CS_SET_DEFAULT_SETTINGS_EVT; + param.cs_set_default_settings.status = params->cs_set_default_settings.status; + param.cs_set_default_settings.conn_handle = params->cs_set_default_settings.conn_handle; + break; + case BTA_BLE_GAP_CS_WRITE_CACHED_REMOTE_FAE_TAB_EVT: + msg.act = ESP_GAP_BLE_CS_WRITE_CACHED_REMOTE_FAE_TABLE_EVT; + param.cs_write_cached_remote_fae_tab.status = params->cs_write_cached_remote_fae_tab.status; + param.cs_write_cached_remote_fae_tab.conn_handle = params->cs_write_cached_remote_fae_tab.conn_handle; + break; + case BTA_BLE_GAP_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT: + msg.act = ESP_GAP_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT; + param.cs_read_remote_supp_caps.status = params->cs_read_remote_supp_caps.status; + param.cs_read_remote_supp_caps.conn_handle = params->cs_read_remote_supp_caps.conn_handle; + param.cs_read_remote_supp_caps.num_config_supported = params->cs_read_remote_supp_caps.num_config_supported; + param.cs_read_remote_supp_caps.max_consecutive_proc_supported = params->cs_read_remote_supp_caps.max_consecutive_proc_supported; + param.cs_read_remote_supp_caps.num_ant_supported = params->cs_read_remote_supp_caps.num_ant_supported; + param.cs_read_remote_supp_caps.max_ant_paths_supported = params->cs_read_remote_supp_caps.max_ant_paths_supported; + param.cs_read_remote_supp_caps.roles_supported = params->cs_read_remote_supp_caps.roles_supported; + param.cs_read_remote_supp_caps.modes_supported = params->cs_read_remote_supp_caps.modes_supported; + param.cs_read_remote_supp_caps.rtt_capability = params->cs_read_remote_supp_caps.rtt_capability; + param.cs_read_remote_supp_caps.rtt_aa_only_n = params->cs_read_remote_supp_caps.rtt_aa_only_n; + param.cs_read_remote_supp_caps.rtt_sounding_n = params->cs_read_remote_supp_caps.rtt_sounding_n; + param.cs_read_remote_supp_caps.rtt_random_payload_n = params->cs_read_remote_supp_caps.rtt_random_payload_n; + param.cs_read_remote_supp_caps.NADM_sounding_capability = params->cs_read_remote_supp_caps.NADM_sounding_capability; + param.cs_read_remote_supp_caps.NADM_random_capability = params->cs_read_remote_supp_caps.NADM_random_capability; + param.cs_read_remote_supp_caps.cs_sync_phys_supported = params->cs_read_remote_supp_caps.cs_sync_phys_supported; + param.cs_read_remote_supp_caps.subfeatures_supported = params->cs_read_remote_supp_caps.subfeatures_supported; + param.cs_read_remote_supp_caps.T_IP1_times_supported = params->cs_read_remote_supp_caps.T_IP1_times_supported; + param.cs_read_remote_supp_caps.T_IP2_times_supported = params->cs_read_remote_supp_caps.T_IP2_times_supported; + param.cs_read_remote_supp_caps.T_FCS_times_supported = params->cs_read_remote_supp_caps.T_FCS_times_supported; + param.cs_read_remote_supp_caps.T_PM_times_supported = params->cs_read_remote_supp_caps.T_PM_times_supported; + param.cs_read_remote_supp_caps.T_SW_times_supported = params->cs_read_remote_supp_caps.T_SW_times_supported; + param.cs_read_remote_supp_caps.TX_SNR_capability = params->cs_read_remote_supp_caps.TX_SNR_capability; + break; + case BTA_BLE_GAP_CS_SET_CHANNEL_CLASS_CMPL_EVT: + msg.act = ESP_GAP_BLE_CS_SET_CHANNEL_CLASS_CMPL_EVT; + param.cs_set_channel_class.status = params->status; + break; + case BTA_BLE_GAP_CS_PROC_PARAMS_CMPL_EVT: + msg.act = ESP_GAP_BLE_CS_SET_PROC_PARAMS_CMPL_EVT; + param.cs_set_proc_params.status = params->cs_set_proc_params.status; + param.cs_set_proc_params.conn_handle = params->cs_set_proc_params.conn_handle; + break; + case BTA_BLE_GAP_CS_PROC_ENABLE_CMPL_EVT: + msg.act = ESP_GAP_BLE_CS_PROC_ENABLE_CMPL_EVT; + param.cs_proc_enable.status = params->cs_proc_en.status; + param.cs_proc_enable.conn_handle = params->cs_proc_en.conn_handle; + param.cs_proc_enable.config_id = params->cs_proc_en.config_id; + param.cs_proc_enable.state = params->cs_proc_en.state; + param.cs_proc_enable.tone_Ant_config_select = params->cs_proc_en.tone_Ant_config_select; + param.cs_proc_enable.select_tx_power = params->cs_proc_en.select_tx_power; + param.cs_proc_enable.subevent_Len = params->cs_proc_en.subevent_Len; + param.cs_proc_enable.subevents_per_event = params->cs_proc_en.subevents_per_event; + param.cs_proc_enable.subevent_interval = params->cs_proc_en.subevent_interval; + param.cs_proc_enable.event_interval = params->cs_proc_en.event_interval; + param.cs_proc_enable.procedure_interval = params->cs_proc_en.procedure_interval; + param.cs_proc_enable.procedure_count = params->cs_proc_en.procedure_count; + param.cs_proc_enable.max_procedure_len = params->cs_proc_en.max_procedure_len; + break; + case BTA_BLE_GAP_CS_READ_REMOTE_FAE_TABLE_CMPL_EVT: + msg.act = ESP_GAP_BLE_CS_READ_REMOTE_FAE_TABLE_CMPL_EVT; + param.cs_read_remote_fae_tab.status = params->cs_read_remote_fae_tab.status; + param.cs_read_remote_fae_tab.conn_handle = params->cs_read_remote_fae_tab.conn_handle; + memcpy(param.cs_read_remote_fae_tab.remote_fae_table, params->cs_read_remote_fae_tab.remote_fae_table, 72); + break; + case BTA_BLE_GAP_CS_SECURITY_ENABLE_CMPL_EVT: + msg.act = ESP_GAP_BLE_CS_SECURITY_ENABLE_CMPL_EVT; + param.cs_security_enable.status = params->cs_security_enable.status; + param.cs_security_enable.conn_handle = params->cs_security_enable.conn_handle; + break; + case BTA_BLE_GAP_CS_CONFIG_CMPL_EVT: + msg.act = ESP_GAP_BLE_CS_CONFIG_CMPL_EVT; + param.cs_config_update.status = params->cs_config_update.status; + param.cs_config_update.conn_handle = params->cs_config_update.conn_handle; + param.cs_config_update.config_id = params->cs_config_update.config_id; + param.cs_config_update.action = params->cs_config_update.action; + param.cs_config_update.main_mode_type = params->cs_config_update.main_mode_type; + param.cs_config_update.sub_mode_type = params->cs_config_update.sub_mode_type; + param.cs_config_update.min_main_mode_steps = params->cs_config_update.min_main_mode_steps; + param.cs_config_update.max_main_mode_steps = params->cs_config_update.max_main_mode_steps; + param.cs_config_update.main_mode_repetition = params->cs_config_update.main_mode_repetition; + param.cs_config_update.mode_0_steps = params->cs_config_update.mode_0_steps; + param.cs_config_update.role = params->cs_config_update.role; + param.cs_config_update.rtt_type = params->cs_config_update.rtt_type; + param.cs_config_update.cs_sync_phy = params->cs_config_update.cs_sync_phy; + memcpy(param.cs_config_update.channel_map, params->cs_config_update.channel_map, 10); + param.cs_config_update.channel_map_repetition = params->cs_config_update.channel_map_repetition; + param.cs_config_update.channel_selection_type = params->cs_config_update.channel_selection_type; + param.cs_config_update.ch3c_shape = params->cs_config_update.ch3c_shape; + param.cs_config_update.ch3c_jump = params->cs_config_update.ch3c_jump; + param.cs_config_update.reserved = params->cs_config_update.reserved; + param.cs_config_update.t_ip1_time = params->cs_config_update.t_ip1_time; + param.cs_config_update.t_ip2_time = params->cs_config_update.t_ip2_time; + param.cs_config_update.t_fcs_time = params->cs_config_update.t_fcs_time; + param.cs_config_update.t_pm_time = params->cs_config_update.t_pm_time; + break; + case BTA_BLE_GAP_CS_SUBEVENT_RESULT_EVT: + msg.act = ESP_GAP_BLE_CS_SUBEVENT_RESULT_EVT; + param.cs_subevt_result.conn_handle = params->cs_subevt_result.conn_handle; + param.cs_subevt_result.config_id = params->cs_subevt_result.config_id; + param.cs_subevt_result.start_acl_conn_event_counter = params->cs_subevt_result.start_acl_conn_event_counter; + param.cs_subevt_result.procedure_counter = params->cs_subevt_result.procedure_counter; + param.cs_subevt_result.frequency_compensation = params->cs_subevt_result.frequency_compensation; + param.cs_subevt_result.reference_power_level = params->cs_subevt_result.reference_power_level; + param.cs_subevt_result.procedure_done_status = params->cs_subevt_result.procedure_done_status; + param.cs_subevt_result.subevent_done_status = params->cs_subevt_result.subevent_done_status; + param.cs_subevt_result.abort_reason = params->cs_subevt_result.abort_reason; + param.cs_subevt_result.num_ant_paths = params->cs_subevt_result.num_ant_paths; + param.cs_subevt_result.num_steps_reported = params->cs_subevt_result.num_steps_reported; + param.cs_subevt_result.step_info = (esp_ble_cs_step_info *)params->cs_subevt_result.step_info; + break; + case BTA_BLE_GAP_CS_SUBEVENT_RESULT_CONTINUE_EVT: + msg.act = ESP_GAP_BLE_CS_SUBEVENT_RESULT_CONTINUE_EVT; + param.cs_subevt_result_continue.conn_handle = params->cs_subevt_result_continue.conn_handle; + param.cs_subevt_result_continue.config_id = params->cs_subevt_result_continue.config_id; + param.cs_subevt_result_continue.proc_done_status = params->cs_subevt_result_continue.proc_done_status; + param.cs_subevt_result_continue.subevt_done_status = params->cs_subevt_result_continue.subevt_done_status; + param.cs_subevt_result_continue.abort_reason = params->cs_subevt_result_continue.abort_reason; + param.cs_subevt_result_continue.num_ant_paths = params->cs_subevt_result_continue.num_ant_paths; + param.cs_subevt_result_continue.num_steps_reported = params->cs_subevt_result_continue.num_steps_reported; + param.cs_subevt_result_continue.step_info = (esp_ble_cs_step_info *)params->cs_subevt_result_continue.step_info; + break; +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) default: break; } @@ -2137,6 +2292,54 @@ void btc_gap_ble_cb_deep_copy(btc_msg_t *msg, void *p_dest, void *p_src) } break; #endif // (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + case BTA_BLE_GAP_CS_SUBEVENT_RESULT_EVT: + if (src->cs_subevt_result.step_info) { + dst->cs_subevt_result.step_info = osi_malloc(src->cs_subevt_result.num_steps_reported * sizeof(esp_ble_cs_step_info)); + if (dst->cs_subevt_result.step_info) { + for (UINT8 i = 0; i < src->cs_subevt_result.num_steps_reported; i++) + { + dst->cs_subevt_result.step_info[i].step_mode = src->cs_subevt_result.step_info[i].step_mode; + dst->cs_subevt_result.step_info[i].step_channel = src->cs_subevt_result.step_info[i].step_channel; + dst->cs_subevt_result.step_info[i].step_data_len = src->cs_subevt_result.step_info[i].step_data_len; + if (src->cs_subevt_result.step_info[i].step_data_len) { + dst->cs_subevt_result.step_info[i].data = osi_malloc(src->cs_subevt_result.step_info[i].step_data_len); + if (dst->cs_subevt_result.step_info[i].data) { + memcpy(dst->cs_subevt_result.step_info[i].data, src->cs_subevt_result.step_info[i].data, src->cs_subevt_result.step_info[i].step_data_len); + } else { + BTC_TRACE_ERROR("%s, data, no enough memory.", __func__); + } + } + } + } else { + BTC_TRACE_ERROR("%s, pa_rsp_info, no enough memory.", __func__); + } + } + break; + case BTA_BLE_GAP_CS_SUBEVENT_RESULT_CONTINUE_EVT: + if (src->cs_subevt_result_continue.step_info) { + dst->cs_subevt_result_continue.step_info = osi_malloc(src->cs_subevt_result_continue.num_steps_reported * sizeof(esp_ble_cs_step_info)); + if (dst->cs_subevt_result_continue.step_info) { + for (UINT8 i = 0; i < src->cs_subevt_result_continue.num_steps_reported; i++) + { + dst->cs_subevt_result_continue.step_info[i].step_mode = src->cs_subevt_result_continue.step_info[i].step_mode; + dst->cs_subevt_result_continue.step_info[i].step_channel = src->cs_subevt_result_continue.step_info[i].step_channel; + dst->cs_subevt_result_continue.step_info[i].step_data_len = src->cs_subevt_result_continue.step_info[i].step_data_len; + if (src->cs_subevt_result_continue.step_info[i].step_data_len) { + dst->cs_subevt_result_continue.step_info[i].data = osi_malloc(src->cs_subevt_result_continue.step_info[i].step_data_len); + if (dst->cs_subevt_result_continue.step_info[i].data) { + memcpy(dst->cs_subevt_result_continue.step_info[i].data, src->cs_subevt_result_continue.step_info[i].data, src->cs_subevt_result.step_info[i].step_data_len); + } else { + BTC_TRACE_ERROR("%s, data, no enough memory.", __func__); + } + } + } + } else { + BTC_TRACE_ERROR("%s, pa_rsp_info, no enough memory.", __func__); + } + } + break; +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) default: // BTC_TRACE_ERROR("%s, Unhandled deep copy %d\n", __func__, msg->act); break; @@ -2333,6 +2536,38 @@ void btc_gap_ble_cb_deep_free(btc_msg_t *msg) } break; #endif // (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + case BTA_BLE_GAP_CS_SUBEVENT_RESULT_EVT: + { + esp_ble_cs_step_info *step_info = ((esp_ble_gap_cb_param_t *)msg->arg)->cs_subevt_result.step_info; + if (step_info) { + uint8_t num_step = ((esp_ble_gap_cb_param_t *)msg->arg)->cs_subevt_result.num_steps_reported; + for (uint8_t i = 0; i < num_step; i++) + { + if (step_info[i].data) { + osi_free(step_info[i].data); + } + } + osi_free(step_info); + } + } + break; + case BTA_BLE_GAP_CS_SUBEVENT_RESULT_CONTINUE_EVT: + { + esp_ble_cs_step_info *step_info = ((esp_ble_gap_cb_param_t *)msg->arg)->cs_subevt_result_continue.step_info; + if (step_info) { + uint8_t num_step = ((esp_ble_gap_cb_param_t *)msg->arg)->cs_subevt_result_continue.num_steps_reported; + for (uint8_t i = 0; i < num_step; i++) + { + if (step_info[i].data) { + osi_free(step_info[i].data); + } + } + osi_free(step_info); + } + } + break; +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) default: BTC_TRACE_DEBUG("Unhandled deep free %d", msg->act); break; @@ -2913,6 +3148,45 @@ void btc_gap_ble_call_handler(btc_msg_t *msg) BTA_DmBleGapSetPeriodicSyncSubevt(arg_5->per_sync_subevent_params.sync_handle, arg_5->per_sync_subevent_params.periodic_adv_properties, arg_5->per_sync_subevent_params.num_subevents_to_sync, arg_5->per_sync_subevent_params.subevent); break; #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + case BTC_GAP_BLE_CS_READ_LOCAL_SUPPORTED_CAPS: + BTA_DmBleGapReadLocalSupportedCaps(); + break; + case BTC_GAP_BLE_CS_READ_REMOTE_SUPPORTED_CAPS: + BTA_DmBleGapReadRemoteSupportedCaps(arg_5->cs_read_remote_supp_caps.conn_handle); + break; + case BTC_GAP_BLE_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPS: + BTA_DmBleGapWriteCachedRemoteSupportedCaps((tBTA_DM_CS_WRITE_CACHED_REMOTE_SUPP_CAPS *)&arg_5->cs_write_cached_remote_supp_caps); + break; + case BTC_GAP_BLE_CS_SECURITY_ENABLE: + BTA_DmBleGapCsSecurityEnable(arg_5->cs_security_enable.conn_handle); + break; + case BTC_GAP_BLE_CS_SET_DEFAULT_SETTINGS: + BTA_DmBleGapCsSetDefaultSetting(arg_5->cs_set_default_settings_params.conn_handle, arg_5->cs_set_default_settings_params.role_enable, + arg_5->cs_set_default_settings_params.cs_sync_ant_selection, arg_5->cs_set_default_settings_params.max_tx_power); + break; + case BTC_GAP_BLE_CS_READ_REMOTE_FAE_TABLE: + BTA_DmBleGapCsReadRemoteFaeTable(arg_5->cs_read_remote_tab.conn_handle); + break; + case BTC_GAP_BLE_CS_WRITE_CACHED_REMOTE_FAE_TABLE: + BTA_DmBleGapWriteCachedRemoteFaeTable(arg_5->cs_write_cached_remote_fae_table_params.conn_handle, &arg_5->cs_write_cached_remote_fae_table_params.remote_fae_table[0], 72); + break; + case BTC_GAP_BLE_CS_CREATE_CONFIG: + BTA_DmBleGapCsCreateConfig((tBTA_DM_CS_CREATE_CONFIG_PARAMS*)&arg_5->cs_create_config_params); + break; + case BTC_GAP_BLE_CS_REMOVE_CONFIG: + BTA_DmBleGapCsRemoveConfig(arg_5->cs_remove_config_params.conn_handle, arg_5->cs_remove_config_params.config_id); + break; + case BTC_GAP_BLE_CS_SET_CAHNNEL_CLASSIFICATION: + BTA_DmBleGapCsSetChannelClass(&arg_5->cs_set_channel_class_params.channel_class[0], 10); + break; + case BTC_GAP_BLE_CS_SET_PROCEDURE_PARAMS: + BTA_DmBleGapCsSetProcPatams((tBTA_DM_CS_SET_PROC_PARAMS *)&arg_5->cs_set_procedure_params); + break; + case BTC_GAP_BLE_CS_PROCEDURE_ENABLE: + BTA_DmBleGapCsProcEnable(arg_5->cs_procedure_enable_params.conn_handle, arg_5->cs_procedure_enable_params.config_id, arg_5->cs_procedure_enable_params.enable); + break; +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) default: break; } diff --git a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h index ae1b974f665..8f844a50b87 100644 --- a/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h +++ b/components/bt/host/bluedroid/btc/profile/std/include/btc_gap_ble.h @@ -146,6 +146,20 @@ typedef enum { BTC_GAP_BLE_SET_PA_RSP_DATA, BTC_GAP_BLE_SET_PA_SYNC_SUBEVT, #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + BTC_GAP_BLE_CS_READ_LOCAL_SUPPORTED_CAPS, + BTC_GAP_BLE_CS_READ_REMOTE_SUPPORTED_CAPS, + BTC_GAP_BLE_CS_WRITE_CACHED_REMOTE_SUPPORTED_CAPS, + BTC_GAP_BLE_CS_SECURITY_ENABLE, + BTC_GAP_BLE_CS_SET_DEFAULT_SETTINGS, + BTC_GAP_BLE_CS_READ_REMOTE_FAE_TABLE, + BTC_GAP_BLE_CS_WRITE_CACHED_REMOTE_FAE_TABLE, + BTC_GAP_BLE_CS_CREATE_CONFIG, + BTC_GAP_BLE_CS_REMOVE_CONFIG, + BTC_GAP_BLE_CS_SET_CAHNNEL_CLASSIFICATION, + BTC_GAP_BLE_CS_SET_PROCEDURE_PARAMS, + BTC_GAP_BLE_CS_PROCEDURE_ENABLE, +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) } btc_gap_ble_act_t; /* btc_ble_gap_args_t */ @@ -564,6 +578,108 @@ typedef union { uint8_t *subevent; } per_sync_subevent_params; #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + struct cs_read_remote_supp_caps_args { + uint16_t conn_handle; + } cs_read_remote_supp_caps; + + struct cs_write_cached_remote_supp_caps_args { + uint16_t conn_handle; + uint8_t num_config_supported; + uint16_t max_consecutive_proc_supported; + uint8_t num_ant_supported; + uint8_t max_ant_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_times_supported; + uint8_t TX_SNR_capability; + } cs_write_cached_remote_supp_caps; + + struct cs_security_enable_args { + uint16_t conn_handle; + } cs_security_enable; + + struct cs_set_default_settings_params_args { + uint16_t conn_handle; + uint8_t role_enable; + uint8_t cs_sync_ant_selection; + int8_t max_tx_power; + } cs_set_default_settings_params; + + struct cs_read_remote_tab_args { + uint16_t conn_handle; + } cs_read_remote_tab; + + struct cs_write_cached_remote_fae_table_params_args { + uint16_t conn_handle; + uint8_t remote_fae_table[72]; + } cs_write_cached_remote_fae_table_params; + + struct cs_create_config_params_args { + uint16_t conn_handle; + uint8_t config_id; + uint8_t create_context; + uint8_t main_mode_type; + uint8_t sub_mode_type; + uint8_t min_main_mode_steps; + uint8_t max_main_mode_steps; + uint8_t main_mode_repetition; + uint8_t mode_0_steps; + uint8_t role; + uint8_t rtt_type; + uint8_t cs_sync_phy; + uint8_t channel_map[10]; + uint8_t channel_map_repetition; + uint8_t channel_selection_type; + uint8_t ch3c_shape; + uint8_t ch3c_jump; + uint8_t reserved; + } cs_create_config_params; + + struct cs_remove_config_params_args { + uint16_t conn_handle; + uint8_t config_id; + } cs_remove_config_params; + + struct cs_set_channel_class_params_args { + uint8_t channel_class[10]; + } cs_set_channel_class_params; + + struct cs_set_procedure_params_args { + uint16_t conn_handle; + uint8_t config_id; + uint16_t max_procedure_len; + uint16_t min_procedure_interval; + uint16_t max_procedure_interval; + uint16_t max_procedure_count; + uint32_t min_subevent_len; + uint32_t max_subevent_len; + uint8_t tone_ant_config_selection; + uint8_t phy; + uint8_t tx_power_delta; + uint8_t preferred_peer_antenna; + uint8_t SNR_control_initiator; + uint8_t SNR_control_reflector; + } cs_set_procedure_params; + + struct cs_procedure_enable_params_args { + uint16_t conn_handle; + uint8_t config_id; + uint8_t enable; + } cs_procedure_enable_params; +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) } btc_ble_5_gap_args_t; #endif // #if (BLE_50_FEATURE_SUPPORT == TRUE) diff --git a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h index 48d06fba6b0..70e967b44bb 100644 --- a/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h +++ b/components/bt/host/bluedroid/common/include/common/bluedroid_user_config.h @@ -376,6 +376,12 @@ #define UC_BT_BLE_FEAT_ADV_CODING_SELECTION FALSE #endif +#ifdef CONFIG_BT_BLE_FEAT_CHANNEL_SOUNDING +#define UC_BT_BLE_FEAT_CHANNEL_SOUNDING CONFIG_BT_BLE_FEAT_CHANNEL_SOUNDING +#else +#define UC_BT_BLE_FEAT_CHANNEL_SOUNDING FALSE +#endif + #ifdef CONFIG_BT_BLE_VENDOR_HCI_EN #define UC_BT_BLE_VENDOR_HCI_EN CONFIG_BT_BLE_VENDOR_HCI_EN #else diff --git a/components/bt/host/bluedroid/common/include/common/bt_target.h b/components/bt/host/bluedroid/common/include/common/bt_target.h index 35485cbbff0..0f7fdb773cb 100644 --- a/components/bt/host/bluedroid/common/include/common/bt_target.h +++ b/components/bt/host/bluedroid/common/include/common/bt_target.h @@ -427,6 +427,12 @@ #define BT_BLE_FEAT_ADV_CODING_SELECTION FALSE #endif +#if (UC_BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +#define BT_BLE_FEAT_CHANNEL_SOUNDING TRUE +#else +#define BT_BLE_FEAT_CHANNEL_SOUNDING FALSE +#endif + #if (UC_BT_BLE_VENDOR_HCI_EN == TRUE) #define BLE_VENDOR_HCI_EN TRUE #else diff --git a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c index b25b98b81c2..f55939923a0 100644 --- a/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c +++ b/components/bt/host/bluedroid/stack/btm/btm_ble_5_gap.c @@ -1819,3 +1819,288 @@ void btm_ble_pa_rsp_rpt_evt(tBTM_BLE_PA_RSP_REPORT_EVT *params) } #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) + +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +void BTM_BleCSReadLocalSuppCaps(void) +{ + btsnd_hcic_ble_cs_read_local_supported_caps(); +} + +void btm_ble_cs_read_local_supp_caps_cmpl_evt(uint8_t *p) +{ + tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.status, p); + if (cb_params.cs_read_local_supp_caps.status != HCI_SUCCESS) { + BTM_TRACE_ERROR("%s cmd err = 0x%x", __func__, cb_params.cs_read_local_supp_caps.status); + cb_params.cs_read_local_supp_caps.status |= BTM_HCI_ERROR; + goto _error; + } + + STREAM_TO_UINT16(cb_params.cs_read_local_supp_caps.conn_handle, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.num_config_supported, p); + STREAM_TO_UINT16(cb_params.cs_read_local_supp_caps.max_consecutive_proc_supported, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.num_ant_supported, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.max_ant_paths_supported, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.roles_supported, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.modes_supported, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.rtt_capability, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.rtt_aa_only_n, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.rtt_sounding_n, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.rtt_random_payload_n, p); + STREAM_TO_UINT16(cb_params.cs_read_local_supp_caps.NADM_sounding_capability, p); + STREAM_TO_UINT16(cb_params.cs_read_local_supp_caps.NADM_random_capability, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.cs_sync_phys_supported, p); + STREAM_TO_UINT16(cb_params.cs_read_local_supp_caps.subfeatures_supported, p); + STREAM_TO_UINT16(cb_params.cs_read_local_supp_caps.T_IP1_times_supported, p); + STREAM_TO_UINT16(cb_params.cs_read_local_supp_caps.T_IP2_times_supported, p); + STREAM_TO_UINT16(cb_params.cs_read_local_supp_caps.T_FCS_times_supported, p); + STREAM_TO_UINT16(cb_params.cs_read_local_supp_caps.T_PM_times_supported, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.T_SW_times_supported, p); + STREAM_TO_UINT8(cb_params.cs_read_local_supp_caps.TX_SNR_capability, p); + +_error: + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_READ_LOCAL_SUPP_CAPS_EVT, &cb_params); +} + +void BTM_BleCSReadRemoteSuppCaps(UINT16 conn_handle) +{ + btsnd_hcic_ble_cs_read_remote_supported_capabilities(conn_handle); +} + +void btm_ble_cs_read_remote_supp_caps_cmd_status(UINT8 status) +{ + if (status != HCI_SUCCESS) { + tBTM_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT cs_read_remote_supp_caps = {0}; + cs_read_remote_supp_caps.status = (status | BTM_HCI_ERROR); + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)&cs_read_remote_supp_caps); + } +} + +void BTM_BleGapWriteCachedRemoteSupportedCaps(UINT16 conn_handle, UINT8 num_config_supported, UINT16 max_consecutive_proc_supported, + UINT8 num_ant_supported, UINT8 max_ant_paths_supported, UINT8 roles_supported, + UINT8 modes_supported, UINT8 rtt_capability, UINT8 rtt_aa_only_n, + UINT8 rtt_sounding_n, UINT8 rtt_random_payload_n, UINT16 NADM_sounding_capability, + UINT16 NADM_random_capability, UINT8 cs_sync_phys_supported, UINT16 subfeatures_supported, + UINT16 T_IP1_times_supported, UINT16 T_IP2_times_supported, UINT16 T_FCS_times_supported, + UINT16 T_PM_times_supported, UINT8 T_SW_times_supported, UINT8 TX_SNR_capability) +{ + tBTM_STATUS status = BTM_SUCCESS; + tHCI_STATUS err = HCI_SUCCESS; + tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + + if ((err = btsnd_hcic_ble_cs_write_cached_remote_supported_capabilities(conn_handle, num_config_supported, max_consecutive_proc_supported, + num_ant_supported, max_ant_paths_supported, roles_supported, + modes_supported, rtt_capability, rtt_aa_only_n, + rtt_sounding_n, rtt_random_payload_n, NADM_sounding_capability, + NADM_random_capability, cs_sync_phys_supported, subfeatures_supported, + T_IP1_times_supported, T_IP2_times_supported, T_FCS_times_supported, + T_PM_times_supported, T_SW_times_supported, TX_SNR_capability)) != HCI_SUCCESS) { + BTM_TRACE_ERROR("cs write cached remote support caps, cmd err=0x%x", err); + status = BTM_HCI_ERROR | err; + } + + cb_params.cs_write_cached_remote_supp_caps.status = status; + cb_params.cs_write_cached_remote_supp_caps.conn_handle = conn_handle; + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_WRITE_CACHED_REMOTE_SUPP_CAPS_EVT, &cb_params); +} + +void BTM_BleGapCsSecurityEnable(UINT16 conn_handle) +{ + btsnd_hcic_ble_cs_security_enable(conn_handle); +} + +void btm_ble_cs_security_enable_cmd_status(UINT8 status) +{ + tBTM_BLE_CS_SEC_ENABLE_CMPL_EVT cs_security_enable = {0}; + if (status != HCI_SUCCESS) { + cs_security_enable.status = (status | BTM_HCI_ERROR); + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_SECURITY_ENABLE_CMPL_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)&cs_security_enable); + } +} + +void BTM_BleGapCsSetDefaultSetting(UINT16 conn_handle, UINT8 role_enable, UINT8 cs_sync_ant_selection, INT8 max_tx_power) +{ + tBTM_STATUS status = BTM_SUCCESS; + tHCI_STATUS err = HCI_SUCCESS; + tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + + if ((err = btsnd_hcic_ble_cs_set_default_settings(conn_handle, role_enable, cs_sync_ant_selection, max_tx_power)) != HCI_SUCCESS) { + BTM_TRACE_ERROR("cs set default setting, cmd err=0x%x", err); + status = BTM_HCI_ERROR | err; + } + + cb_params.cs_set_default_settings.status = status; + cb_params.cs_set_default_settings.conn_handle = conn_handle; + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_SET_DEFAULT_SETTINGS_EVT, &cb_params); +} + +void BTM_BleGapCsReadRemoteFaeTable(UINT16 conn_handle) +{ + btsnd_hcic_ble_cs_read_remote_fae_table(conn_handle); +} + +void btm_ble_cs_read_remote_fae_table_cmd_status(UINT8 status) +{ + tBTM_BLE_CS_READ_REMOTE_FAE_TAB_CMPL_EVT cs_read_remote_fae_tab = {0}; + if (status != HCI_SUCCESS) { + cs_read_remote_fae_tab.status = (status | BTM_HCI_ERROR); + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_READ_REMOTE_FAE_TABLE_CMPL_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)&cs_read_remote_fae_tab); + } +} + +void BTM_BleGapWriteCachedRemoteFaeTable(UINT16 conn_handle, UINT8 *remote_fae_table) +{ + tBTM_STATUS status = BTM_SUCCESS; + tHCI_STATUS err = HCI_SUCCESS; + tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + + if ((err = btsnd_hcic_ble_cs_write_cached_remote_fae_table(conn_handle, remote_fae_table)) != HCI_SUCCESS) { + BTM_TRACE_ERROR("cs write cached remote fae tab, cmd err=0x%x", err); + status = BTM_HCI_ERROR | err; + } + + cb_params.cs_write_cached_remote_fae_tab.status = status; + cb_params.cs_write_cached_remote_fae_tab.conn_handle = conn_handle; + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_WRITE_CACHED_REMOTE_FAE_TAB_EVT, &cb_params); +} + +void BTM_BleGapCsCreateConfig(UINT16 conn_handle, UINT8 config_id, UINT8 create_context, + UINT8 main_mode_type, UINT8 sub_mode_type, UINT8 min_main_mode_steps, + UINT8 max_main_mode_steps, UINT8 main_mode_repetition, UINT8 mode_0_steps, + UINT8 role, UINT8 rtt_type, UINT8 cs_sync_phy, UINT8 *channel_map, + UINT8 channel_map_repetition, UINT8 channel_selection_type, UINT8 ch3c_shape, + UINT8 ch3c_jump,UINT8 reserved) +{ + btsnd_hcic_ble_cs_create_config(conn_handle, config_id, create_context, + main_mode_type, sub_mode_type, min_main_mode_steps, + max_main_mode_steps, main_mode_repetition, mode_0_steps, + role, rtt_type, cs_sync_phy, channel_map, + channel_map_repetition, channel_selection_type, ch3c_shape, + ch3c_jump, reserved); +} + +void BTM_BleGapCsRemoveConfig(UINT16 conn_handle, UINT8 config_id) +{ + btsnd_hcic_ble_cs_remove_config(conn_handle, config_id); +} + +void btm_ble_cs_update_config_cmd_status(UINT8 status, BOOLEAN create) +{ + tBTM_BLE_CS_CONFIG_CMPL_EVT config_cmpl = {0}; + if (status != HCI_SUCCESS) { + config_cmpl.status = (status | BTM_HCI_ERROR); + config_cmpl.action = (create? 0x01:0x00); + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_CONFIG_CMPL_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)&config_cmpl); + } +} + +void BTM_BleGapCsSetChannelClass(UINT8 *channel_class) +{ + tBTM_STATUS status = BTM_SUCCESS; + tHCI_STATUS err = HCI_SUCCESS; + tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + + if ((err = btsnd_hcic_ble_cs_set_channel_classification(channel_class)) != HCI_SUCCESS) { + BTM_TRACE_ERROR("cs set channel class, cmd err=0x%x", err); + status = BTM_HCI_ERROR | err; + } + + cb_params.status = status; + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_SET_CHANNEL_CLASS_CMPL_EVT, &cb_params); +} + +void BTM_BleGapCsSetProcPatams(UINT16 conn_handle, UINT8 config_id, UINT16 max_procedure_len, + UINT16 min_procedure_interval, UINT16 max_procedure_interval, + UINT16 max_procedure_count, UINT32 min_subevent_len, + UINT32 max_subevent_len, UINT8 tone_ant_config_selection, + UINT8 phy, UINT8 tx_power_delta, UINT8 preferred_peer_antenna, + UINT8 SNR_control_initiator, UINT8 SNR_control_reflector) +{ + tBTM_STATUS status = BTM_SUCCESS; + tHCI_STATUS err = HCI_SUCCESS; + tBTM_BLE_5_GAP_CB_PARAMS cb_params = {0}; + + if ((err = btsnd_hcic_ble_cs_set_procedure_params(conn_handle, config_id, max_procedure_len, + min_procedure_interval, max_procedure_interval, + max_procedure_count, min_subevent_len, + max_subevent_len, tone_ant_config_selection, + phy, tx_power_delta, preferred_peer_antenna, + SNR_control_initiator, SNR_control_reflector)) != HCI_SUCCESS) { + BTM_TRACE_ERROR("cs set procedure params, cmd err=0x%x", err); + status = BTM_HCI_ERROR | err; + } + + cb_params.cs_set_proc_params.status = status; + cb_params.cs_set_proc_params.conn_handle = conn_handle; + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_PROC_PARAMS_CMPL_EVT, &cb_params); +} + +void BTM_BleGapCsProcEnable(UINT16 conn_handle, UINT8 config_id, UINT8 enable) +{ + btsnd_hcic_ble_cs_procedure_enable(conn_handle, config_id, enable); +} + +void btm_ble_cs_read_remote_supp_caps_cmpl_evt(tBTM_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT *cs_read_remote_supp_caps) +{ + if (cs_read_remote_supp_caps->status != HCI_SUCCESS) { + BTM_TRACE_ERROR("%s cmd err = 0x%x", __func__, cs_read_remote_supp_caps->status); + cs_read_remote_supp_caps->status |= BTM_HCI_ERROR; + } + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)cs_read_remote_supp_caps); +} + +void btm_ble_cs_read_remote_fae_tab_cmpl_evt(tBTM_BLE_CS_READ_REMOTE_FAE_TAB_CMPL_EVT *cs_read_remote_fae_tab) +{ + if (cs_read_remote_fae_tab->status != HCI_SUCCESS) { + BTM_TRACE_ERROR("%s cmd err = 0x%x", __func__, cs_read_remote_fae_tab->status); + cs_read_remote_fae_tab->status |= BTM_HCI_ERROR; + } + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_READ_REMOTE_FAE_TABLE_CMPL_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)cs_read_remote_fae_tab); +} + +void btm_ble_cs_securuty_enable_cmpl_evt(tBTM_BLE_CS_SEC_ENABLE_CMPL_EVT *cs_security_enable) +{ + if (cs_security_enable->status != HCI_SUCCESS) { + BTM_TRACE_ERROR("%s cmd err = 0x%x", __func__, cs_security_enable->status); + cs_security_enable->status |= BTM_HCI_ERROR; + } + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_SECURITY_ENABLE_CMPL_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)cs_security_enable); +} + +void btm_ble_cs_config_cmpl_evt(tBTM_BLE_CS_CONFIG_CMPL_EVT *config_cmpl) +{ + if (config_cmpl->status != HCI_SUCCESS) { + BTM_TRACE_ERROR("%s cmd err = 0x%x", __func__, config_cmpl->status); + config_cmpl->status |= BTM_HCI_ERROR; + } + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_CONFIG_CMPL_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)config_cmpl); +} + +void btm_ble_cs_proc_enable_cmpl_evt(tBTM_BLE_CS_PROC_ENABLE_CMPL_EVT *proc_en) +{ + if (proc_en->status != HCI_SUCCESS) { + BTM_TRACE_ERROR("%s cmd err = 0x%x", __func__, proc_en->status); + proc_en->status |= BTM_HCI_ERROR; + } + + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_PROC_ENABLE_CMPL_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)proc_en); +} + +void btm_ble_cs_subevt_result_evt(tBTM_BLE_CS_SUBEVT_RESULT_CMPL_EVT *subevt_result) +{ + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_SUBEVENT_RESULT_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)subevt_result); +} + +void btm_ble_cs_subevt_continue_result_evt(tBTM_BLE_CS_SUBEVT_RESULT_CONTINUE_EVT *subevt_result_continue) +{ + BTM_ExtBleCallbackTrigger(BTM_BLE_GAP_CS_SUBEVENT_RESULT_CONTINUE_EVT, (tBTM_BLE_5_GAP_CB_PARAMS *)subevt_result_continue); +} + +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h index e7fe12925d2..c8181086f72 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_ble_int.h @@ -611,6 +611,17 @@ void btm_ble_pa_subevt_data_req_evt(tBTM_BLE_PA_SUBEVT_DATA_REQ_EVT *params); void btm_ble_pa_rsp_rpt_evt(tBTM_BLE_PA_RSP_REPORT_EVT *params); #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +void btm_ble_cs_read_remote_supp_caps_cmpl_evt(tBTM_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT *cs_read_remote_supp_caps); +void btm_ble_cs_read_remote_fae_tab_cmpl_evt(tBTM_BLE_CS_READ_REMOTE_FAE_TAB_CMPL_EVT *cs_read_remote_fae_tab); +void btm_ble_cs_securuty_enable_cmpl_evt(tBTM_BLE_CS_SEC_ENABLE_CMPL_EVT *cs_security_enable); +void btm_ble_cs_config_cmpl_evt(tBTM_BLE_CS_CONFIG_CMPL_EVT *config_cmpl); +void btm_ble_cs_proc_enable_cmpl_evt(tBTM_BLE_CS_PROC_ENABLE_CMPL_EVT *proc_en); +void btm_ble_cs_subevt_result_evt(tBTM_BLE_CS_SUBEVT_RESULT_CMPL_EVT *subevt_result); +void btm_ble_cs_subevt_continue_result_evt(tBTM_BLE_CS_SUBEVT_RESULT_CONTINUE_EVT *subevt_continue_result); +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + + /* #ifdef __cplusplus } diff --git a/components/bt/host/bluedroid/stack/btm/include/btm_int.h b/components/bt/host/bluedroid/stack/btm/include/btm_int.h index e23b086368b..930edc236db 100644 --- a/components/bt/host/bluedroid/stack/btm/include/btm_int.h +++ b/components/bt/host/bluedroid/stack/btm/include/btm_int.h @@ -1137,6 +1137,14 @@ void btm_read_remote_trans_pwr_level_cmpl(UINT8 status); void btm_subrate_req_cmd_status(UINT8 status); #endif // #if (BLE_FEAT_CONN_SUBRATING == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +void btm_ble_cs_read_local_supp_caps_cmpl_evt(UINT8 *p); +void btm_ble_cs_read_remote_supp_caps_cmd_status(UINT8 status); +void btm_ble_cs_security_enable_cmd_status(UINT8 status); +void btm_ble_cs_read_remote_fae_table_cmd_status(UINT8 status); +void btm_ble_cs_update_config_cmd_status(UINT8 status, BOOLEAN create); +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + /* Internal functions provided by btm_sco.c ******************************************** */ diff --git a/components/bt/host/bluedroid/stack/btu/btu_hcif.c b/components/bt/host/bluedroid/stack/btu/btu_hcif.c index 7c88845d8cb..b1c3d9bf9b1 100644 --- a/components/bt/host/bluedroid/stack/btu/btu_hcif.c +++ b/components/bt/host/bluedroid/stack/btu/btu_hcif.c @@ -233,6 +233,16 @@ static void btu_ble_pa_subevt_data_request_evt(UINT8 *p); static void btu_ble_pa_response_report_evt(UINT8 *p); #endif // (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +static void btu_ble_cs_read_remote_supp_caps_evt(UINT8 *p); +static void btu_ble_cs_read_remote_fae_tab_evt(UINT8 *p); +static void btu_ble_cs_security_enable_cmpl_evt(UINT8 *p); +static void btu_ble_cs_config_cmpl_evt(UINT8 *p); +static void btu_ble_cs_proc_enable_cmpl_evt(UINT8 *p); +static void btu_ble_cs_subevt_result_evt(UINT8 *p); +static void btu_ble_cs_subevt_result_continue_evt(UINT8 *p); +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + #if (BLE_42_ADV_EN == TRUE) extern osi_sem_t adv_enable_sem; extern osi_sem_t adv_data_sem; @@ -607,6 +617,29 @@ void btu_hcif_process_event (UNUSED_ATTR UINT8 controller_id, BT_HDR *p_msg) btu_ble_pa_response_report_evt(p); break; #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + case HCI_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT: + btu_ble_cs_read_remote_supp_caps_evt(p); + break; + case HCI_BLE_CS_READ_REMOTE_FAE_TAB_CMPL_EVT: + btu_ble_cs_read_remote_fae_tab_evt(p); + break; + case HCI_BLE_CS_SECURITY_ENABLE_CMPL_EVT: + btu_ble_cs_security_enable_cmpl_evt(p); + break; + case HCI_BLE_CS_CONFIG_CMPL_EVT: + btu_ble_cs_config_cmpl_evt(p); + break; + case HCI_BLE_CS_PROC_ENABLE_CMPL_EVT: + btu_ble_cs_proc_enable_cmpl_evt(p); + break; + case HCI_BLE_CS_SUBEVENT_RESULT_EVT: + btu_ble_cs_subevt_result_evt(p); + break; + case HCI_BLE_CS_SUBEVENT_RESULT_CONTINUE_EVT: + btu_ble_cs_subevt_result_continue_evt(p); + break; +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) } break; #endif /* BLE_INCLUDED */ @@ -1411,7 +1444,11 @@ static void btu_hcif_hdl_command_complete (UINT16 opcode, UINT8 *p, UINT16 evt_l btm_enh_read_trans_pwr_level_cmpl_evt(p); break; #endif //#if (BLE_FEAT_POWER_CONTROL_EN == TRUE) - +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + case HCI_BLE_CS_READ_LOCAL_SUPP_CAPS: + btm_ble_cs_read_local_supp_caps_cmpl_evt(p); + break; +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) #endif /* (BLE_INCLUDED == TRUE) */ default: { @@ -1619,6 +1656,23 @@ static void btu_hcif_hdl_command_status (UINT16 opcode, UINT8 status, UINT8 *p_c btm_subrate_req_cmd_status(status); break; #endif // #if (BLE_FEAT_CONN_SUBRATING == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + case HCI_BLE_CS_READ_REMOTE_SUPP_CAPS: + btm_ble_cs_read_remote_supp_caps_cmd_status(status); + break; + case HCI_BLE_CS_SECURITY_ENABLE: + btm_ble_cs_security_enable_cmd_status(status); + break; + case HCI_BLE_CS_READ_REMOTE_FAE_TABLE: + btm_ble_cs_read_remote_fae_table_cmd_status(status); + break; + case HCI_BLE_CS_CREATE_CONFIG: + btm_ble_cs_update_config_cmd_status(status, true); + break; + case HCI_BLE_CS_REMOVE_CONFIG: + btm_ble_cs_update_config_cmd_status(status, false); + break; +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) default: /* If command failed to start, we may need to tell BTM */ if (status != HCI_SUCCESS) { @@ -3192,6 +3246,228 @@ static void btu_ble_pa_response_report_evt(UINT8 *p) } #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +static void btu_ble_cs_read_remote_supp_caps_evt(UINT8 *p) +{ + tBTM_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT cs_read_remote_supp_caps = {0}; + if (!p) { + HCI_TRACE_ERROR("%s, Invalid params.", __func__); + return; + } + + STREAM_TO_UINT8(cs_read_remote_supp_caps.status, p); + STREAM_TO_UINT16(cs_read_remote_supp_caps.conn_handle, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.num_config_supported, p); + STREAM_TO_UINT16(cs_read_remote_supp_caps.max_consecutive_proc_supported, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.num_ant_supported, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.max_ant_paths_supported, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.roles_supported, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.modes_supported, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.rtt_capability, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.rtt_aa_only_n, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.rtt_sounding_n, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.rtt_random_payload_n, p); + STREAM_TO_UINT16(cs_read_remote_supp_caps.NADM_sounding_capability, p); + STREAM_TO_UINT16(cs_read_remote_supp_caps.NADM_random_capability, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.cs_sync_phys_supported, p); + STREAM_TO_UINT16(cs_read_remote_supp_caps.subfeatures_supported, p); + STREAM_TO_UINT16(cs_read_remote_supp_caps.T_IP1_times_supported, p); + STREAM_TO_UINT16(cs_read_remote_supp_caps.T_IP2_times_supported, p); + STREAM_TO_UINT16(cs_read_remote_supp_caps.T_FCS_times_supported, p); + STREAM_TO_UINT16(cs_read_remote_supp_caps.T_PM_times_supported, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.T_SW_times_supported, p); + STREAM_TO_UINT8(cs_read_remote_supp_caps.TX_SNR_capability, p); + + btm_ble_cs_read_remote_supp_caps_cmpl_evt(&cs_read_remote_supp_caps); +} + +static void btu_ble_cs_read_remote_fae_tab_evt(UINT8 *p) +{ + tBTM_BLE_CS_READ_REMOTE_FAE_TAB_CMPL_EVT cs_read_remote_fae_tab = {0}; + + if (!p) { + HCI_TRACE_ERROR("%s, Invalid params.", __func__); + return; + } + + STREAM_TO_UINT8(cs_read_remote_fae_tab.status, p); + STREAM_TO_UINT16(cs_read_remote_fae_tab.conn_handle, p); + STREAM_TO_ARRAY(cs_read_remote_fae_tab.remote_fae_table, p, 72); + + btm_ble_cs_read_remote_fae_tab_cmpl_evt(&cs_read_remote_fae_tab); +} + +static void btu_ble_cs_security_enable_cmpl_evt(UINT8 *p) +{ + tBTM_BLE_CS_SEC_ENABLE_CMPL_EVT cs_security_enable = {0}; + if (!p) { + HCI_TRACE_ERROR("%s, Invalid params.", __func__); + return; + } + STREAM_TO_UINT8(cs_security_enable.status, p); + STREAM_TO_UINT16(cs_security_enable.conn_handle, p); + + btm_ble_cs_securuty_enable_cmpl_evt(&cs_security_enable); +} + +static void btu_ble_cs_config_cmpl_evt(UINT8 *p) +{ + tBTM_BLE_CS_CONFIG_CMPL_EVT config_cmpl = {0}; + if (!p) { + HCI_TRACE_ERROR("%s, Invalid params.", __func__); + return; + } + STREAM_TO_UINT8(config_cmpl.status, p); + STREAM_TO_UINT16(config_cmpl.conn_handle, p); + STREAM_TO_UINT8(config_cmpl.config_id, p); + STREAM_TO_UINT8(config_cmpl.action, p);; + STREAM_TO_UINT8(config_cmpl.main_mode_type, p); + STREAM_TO_UINT8(config_cmpl.sub_mode_type, p); + STREAM_TO_UINT8(config_cmpl.min_main_mode_steps, p); + STREAM_TO_UINT8(config_cmpl.max_main_mode_steps, p); + STREAM_TO_UINT8(config_cmpl.main_mode_repetition, p); + STREAM_TO_UINT8(config_cmpl.mode_0_steps, p); + STREAM_TO_UINT8(config_cmpl.role, p); + STREAM_TO_UINT8(config_cmpl.rtt_type, p); + STREAM_TO_UINT8(config_cmpl.cs_sync_phy, p); + STREAM_TO_ARRAY(config_cmpl.channel_map, p, 10); + STREAM_TO_UINT8(config_cmpl.channel_map_repetition, p); + STREAM_TO_UINT8(config_cmpl.channel_selection_type, p); + STREAM_TO_UINT8(config_cmpl.ch3c_shape, p); + STREAM_TO_UINT8(config_cmpl.ch3c_jump, p); + STREAM_TO_UINT8(config_cmpl.reserved, p); + STREAM_TO_UINT8(config_cmpl.t_ip1_time, p); + STREAM_TO_UINT8(config_cmpl.t_ip2_time, p); + STREAM_TO_UINT8(config_cmpl.t_fcs_time, p); + STREAM_TO_UINT8(config_cmpl.t_pm_time, p); + + btm_ble_cs_config_cmpl_evt(&config_cmpl); +} + +static void btu_ble_cs_proc_enable_cmpl_evt(UINT8 *p) +{ + tBTM_BLE_CS_PROC_ENABLE_CMPL_EVT proc_en = {0}; + + if (!p) { + HCI_TRACE_ERROR("%s, Invalid params.", __func__); + return; + } + + STREAM_TO_UINT8(proc_en.status, p); + STREAM_TO_UINT16(proc_en.conn_handle, p); + STREAM_TO_UINT8(proc_en.config_id, p); + STREAM_TO_UINT8(proc_en.state, p); + STREAM_TO_UINT8(proc_en.tone_Ant_config_select, p); + STREAM_TO_UINT8(proc_en.select_tx_power, p); + STREAM_TO_UINT24(proc_en.subevent_Len, p); + STREAM_TO_UINT8(proc_en.subevents_per_event, p); + STREAM_TO_UINT16(proc_en.subevent_interval, p); + STREAM_TO_UINT16(proc_en.event_interval, p); + STREAM_TO_UINT16(proc_en.procedure_interval, p); + STREAM_TO_UINT16(proc_en.procedure_count, p); + STREAM_TO_UINT16(proc_en.max_procedure_len, p); + + btm_ble_cs_proc_enable_cmpl_evt(&proc_en); +} + +static void btu_ble_cs_subevt_result_evt(UINT8 *p) +{ + tBTM_BLE_CS_SUBEVT_RESULT_CMPL_EVT subevt_result = {0}; + if (!p) { + HCI_TRACE_ERROR("%s, Invalid params.", __func__); + return; + } + STREAM_TO_UINT16(subevt_result.conn_handle, p); + STREAM_TO_UINT8(subevt_result.config_id, p); + STREAM_TO_UINT16(subevt_result.start_acl_conn_event_counter, p); + STREAM_TO_UINT16(subevt_result.procedure_counter, p); + STREAM_TO_UINT16(subevt_result.frequency_compensation, p); + STREAM_TO_UINT8(subevt_result.reference_power_level, p); + STREAM_TO_UINT8(subevt_result.procedure_done_status, p); + STREAM_TO_UINT8(subevt_result.subevent_done_status, p); + STREAM_TO_UINT8(subevt_result.abort_reason, p); + STREAM_TO_UINT8(subevt_result.num_ant_paths, p); + STREAM_TO_UINT8(subevt_result.num_steps_reported, p); + + subevt_result.step_info = osi_malloc(subevt_result.num_steps_reported * sizeof(tBTM_BLE_CS_STEP_INFO)); + if (subevt_result.step_info) { + for (uint8_t i = 0; i < subevt_result.num_steps_reported; i++) + { + STREAM_TO_UINT8(subevt_result.step_info[i].step_mode, p); + STREAM_TO_UINT8(subevt_result.step_info[i].step_channel, p); + STREAM_TO_UINT8(subevt_result.step_info[i].step_data_len, p); + subevt_result.step_info[i].data = osi_malloc(subevt_result.step_info[i].step_data_len); + if (subevt_result.step_info[i].data) { + STREAM_TO_ARRAY(subevt_result.step_info[i].data, p, subevt_result.step_info[i].step_data_len); + } else if (subevt_result.step_info[i].step_data_len) { + HCI_TRACE_ERROR("%s, no memory.", __func__); + } + } + } + + btm_ble_cs_subevt_result_evt(&subevt_result); + + if (subevt_result.step_info) + { + for (UINT8 i = 0; i < subevt_result.num_steps_reported; i++) + { + if (subevt_result.step_info[i].data) { + osi_free(subevt_result.step_info[i].data); + } + } + osi_free(subevt_result.step_info); + } + +} + +static void btu_ble_cs_subevt_result_continue_evt(UINT8 *p) +{ + tBTM_BLE_CS_SUBEVT_RESULT_CONTINUE_EVT subevt_continue_result = {0}; + + if (!p) { + HCI_TRACE_ERROR("%s, Invalid params.", __func__); + return; + } + + STREAM_TO_UINT16(subevt_continue_result.conn_handle, p); + STREAM_TO_UINT8(subevt_continue_result.config_id, p); + STREAM_TO_UINT8(subevt_continue_result.proc_done_status, p); + STREAM_TO_UINT8(subevt_continue_result.subevt_done_status, p); + STREAM_TO_UINT8(subevt_continue_result.abort_reason, p); + STREAM_TO_UINT8(subevt_continue_result.num_ant_paths, p); + STREAM_TO_UINT8(subevt_continue_result.num_steps_reported, p); + + subevt_continue_result.step_info = osi_malloc(subevt_continue_result.num_steps_reported * sizeof(tBTM_BLE_CS_STEP_INFO)); + if (subevt_continue_result.step_info) { + for (uint8_t i = 0; i < subevt_continue_result.num_steps_reported; i++) { + STREAM_TO_UINT8(subevt_continue_result.step_info[i].step_mode, p); + STREAM_TO_UINT8(subevt_continue_result.step_info[i].step_channel, p); + STREAM_TO_UINT8(subevt_continue_result.step_info[i].step_data_len, p); + subevt_continue_result.step_info[i].data = osi_malloc(subevt_continue_result.step_info[i].step_data_len); + if (subevt_continue_result.step_info[i].data) { + STREAM_TO_ARRAY(subevt_continue_result.step_info[i].data, p, subevt_continue_result.step_info[i].step_data_len); + } else if (subevt_continue_result.step_info[i].step_data_len) { + HCI_TRACE_ERROR("%s, no memory.", __func__); + } + } + } + + btm_ble_cs_subevt_continue_result_evt(&subevt_continue_result); + + if (subevt_continue_result.step_info) + { + for (UINT8 i = 0; i < subevt_continue_result.num_steps_reported; i++) + { + if (subevt_continue_result.step_info[i].data) { + osi_free(subevt_continue_result.step_info[i].data); + } + } + osi_free(subevt_continue_result.step_info); + } + +} +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + /********************************************** ** End of BLE Events Handler ***********************************************/ diff --git a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c index 81214a9bc42..af75e6ac5a4 100644 --- a/components/bt/host/bluedroid/stack/hcic/hciblecmds.c +++ b/components/bt/host/bluedroid/stack/hcic/hciblecmds.c @@ -3074,3 +3074,324 @@ UINT8 btsnd_hcic_ble_set_periodic_sync_subevt(UINT16 sync_handle, UINT16 periodi return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); } #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) + +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +UINT8 btsnd_hcic_ble_cs_read_local_supported_caps(void) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("cs read local supported caps"); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_READ_LOCAL_SUPP_CAPS_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_READ_LOCAL_SUPP_CAPS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_LOCAL_SUPP_CAPS_PARAMS_LEN); + + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); + return (TRUE); +} + +UINT8 btsnd_hcic_ble_cs_read_remote_supported_capabilities(UINT16 conn_handle) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_ERROR("cs read remote supported caps, conn_handle %d", conn_handle); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_READ_REMOTE_SUPP_CAPS_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_READ_REMOTE_SUPP_CAPS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_REMOTE_SUPP_CAPS_PARAMS_LEN); + UINT16_TO_STREAM(pp, conn_handle); + + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); + return (TRUE); +} + +UINT8 btsnd_hcic_ble_cs_write_cached_remote_supported_capabilities(UINT16 conn_handle, UINT8 num_config_supported, UINT16 max_consecutive_proc_supported, + UINT8 num_ant_supported, UINT8 max_ant_paths_supported, UINT8 roles_supported, + UINT8 modes_supported, UINT8 rtt_capability, UINT8 rtt_aa_only_n, + UINT8 rtt_sounding_n, UINT8 rtt_random_payload_n, UINT16 NADM_sounding_capability, + UINT16 NADM_random_capability, UINT8 cs_sync_phys_supported, UINT16 subfeatures_supported, + UINT16 T_IP1_times_supported, UINT16 T_IP2_times_supported, UINT16 T_FCS_times_supported, + UINT16 T_PM_times_supported, UINT8 T_SW_times_supported, UINT8 TX_SNR_capability) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("cs write cached remote supported caps"); + HCI_TRACE_DEBUG("conn_handle %d num_config_supported %d max_consecutive_proc_supported %d, num_ant_supported %d max_ant_paths_supported %d roles_supported %d,\ + modes_supported %d, rtt_capability %d, rtt_aa_only_n %d, rtt_sounding_n %d, rtt_random_payload_n %d, NADM_sounding_capability %d, NADM_random_capability %d\ + ,cs_sync_phys_supported %d, subfeatures_supported %d, T_IP1_times_supported %d, T_IP2_times_supported %d, T_FCS_times_supported %d, T_PM_times_supported %d\ + ,T_SW_times_supported %d, TX_SNR_capability %d", + conn_handle, num_config_supported, max_consecutive_proc_supported, num_ant_supported, max_ant_paths_supported, roles_supported, + modes_supported, rtt_capability, rtt_aa_only_n, rtt_sounding_n, rtt_random_payload_n, NADM_sounding_capability, + NADM_random_capability, cs_sync_phys_supported, subfeatures_supported, T_IP1_times_supported, T_IP2_times_supported, T_FCS_times_supported, + T_PM_times_supported, T_SW_times_supported, TX_SNR_capability); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_WRITE_CACHE_REMOTE_SUPP_CAPS_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_WRITE_CACHED_REMOTE_SUPP_CAPS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_CACHE_REMOTE_SUPP_CAPS_PARAMS_LEN); + UINT16_TO_STREAM(pp, conn_handle); + UINT8_TO_STREAM(pp, num_config_supported); + UINT16_TO_STREAM(pp, max_consecutive_proc_supported); + UINT8_TO_STREAM(pp, num_ant_supported); + UINT8_TO_STREAM(pp, max_ant_paths_supported); + UINT8_TO_STREAM(pp, roles_supported); + UINT8_TO_STREAM(pp, modes_supported); + UINT8_TO_STREAM(pp, rtt_capability); + UINT8_TO_STREAM(pp, rtt_aa_only_n); + UINT8_TO_STREAM(pp, rtt_sounding_n); + UINT8_TO_STREAM(pp, rtt_random_payload_n); + UINT16_TO_STREAM(pp, NADM_sounding_capability); + UINT16_TO_STREAM(pp, NADM_random_capability); + UINT8_TO_STREAM(pp, cs_sync_phys_supported); + UINT16_TO_STREAM(pp, subfeatures_supported); + UINT16_TO_STREAM(pp, T_IP1_times_supported); + UINT16_TO_STREAM(pp, T_IP2_times_supported); + UINT16_TO_STREAM(pp, T_FCS_times_supported); + UINT16_TO_STREAM(pp, T_PM_times_supported); + UINT8_TO_STREAM(pp, T_SW_times_supported); + UINT8_TO_STREAM(pp, TX_SNR_capability); + + return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); + +} + +UINT8 btsnd_hcic_ble_cs_security_enable(UINT16 conn_handle) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("cs security enable conn_handle %d", conn_handle); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SECURITY_ENABLE_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_SECURITY_ENABLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SECURITY_ENABLE_PARAMS_LEN); + UINT16_TO_STREAM(pp, conn_handle); + + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); + return (TRUE); +} + +UINT8 btsnd_hcic_ble_cs_set_default_settings(UINT16 conn_handle, UINT8 role_enable, UINT8 cs_sync_ant_selection, INT8 max_tx_power) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("cs set default settings, conn_handle %d role_enable %d cs_sync_ant_selection %d max_tx_power %d", conn_handle, role_enable, cs_sync_ant_selection, max_tx_power); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_DEFAULT_SETTINGS_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_SET_DEFAULT_SETTINGS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_DEFAULT_SETTINGS_PARAMS_LEN); + UINT16_TO_STREAM(pp, conn_handle); + UINT8_TO_STREAM(pp, role_enable); + UINT8_TO_STREAM(pp, cs_sync_ant_selection); + INT8_TO_STREAM(pp, max_tx_power); + + return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); +} + +UINT8 btsnd_hcic_ble_cs_read_remote_fae_table(UINT16 conn_handle) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("cs read remote fae table, conn_handle %d", conn_handle); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_READ_REMOTE_FAE_TAB_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_READ_REMOTE_FAE_TABLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_READ_REMOTE_FAE_TAB_PARAMS_LEN); + UINT16_TO_STREAM(pp, conn_handle); + + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); + return (TRUE); +} + +UINT8 btsnd_hcic_ble_cs_write_cached_remote_fae_table(UINT16 conn_handle, UINT8 *remote_fae_table) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("cs write cached remote fae table, conn_handle %d", conn_handle); + esp_log_buffer_hex_internal("remote_fae_table", remote_fae_table, 72, ESP_LOG_DEBUG); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_WRITE_CACHED_REMOTE_FAE_TAB_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_WRITE_CACHED_REMOTE_FAE_TABLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_WRITE_CACHED_REMOTE_FAE_TAB_PARAMS_LEN); + UINT16_TO_STREAM(pp, conn_handle); + ARRAY_TO_STREAM(pp, remote_fae_table, 72); + + return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); +} + +UINT8 btsnd_hcic_ble_cs_create_config(UINT16 conn_handle, UINT8 config_id, UINT8 create_context, + UINT8 main_mode_type, UINT8 sub_mode_type, UINT8 min_main_mode_steps, + UINT8 max_main_mode_steps, UINT8 main_mode_repetition, UINT8 mode_0_steps, + UINT8 role, UINT8 rtt_type, UINT8 cs_sync_phy, UINT8 *channel_map, + UINT8 channel_map_repetition, UINT8 channel_selection_type, UINT8 ch3c_shape, + UINT8 ch3c_jump,UINT8 reserved) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("cs create config"); + HCI_TRACE_DEBUG("conn_handle %d config_id %d create_context %d main_mode_type %d sub_mode_type %d min_main_mode_steps %d max_main_mode_steps\ + %d main_mode_repetition %d mode_0_steps %d role %d rtt_type %d cs_sync_phy %d, channel_map_repetition %d, channel_selection_type %d\ + ch3c_shape %d ch3c_jump %d,reserved %d", conn_handle, config_id, create_context, main_mode_type, sub_mode_type, min_main_mode_steps, max_main_mode_steps,\ + main_mode_repetition, mode_0_steps, role, rtt_type, cs_sync_phy, channel_map_repetition, channel_selection_type\ + ,ch3c_shape, ch3c_jump, reserved); + esp_log_buffer_hex_internal("channel_map", channel_map, 10, ESP_LOG_DEBUG); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_CREATE_CONFIG_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_CREATE_CONFIG); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_CREATE_CONFIG_PARAMS_LEN); + UINT16_TO_STREAM(pp, conn_handle); + UINT8_TO_STREAM(pp, config_id); + UINT8_TO_STREAM(pp, create_context); + UINT8_TO_STREAM(pp, main_mode_type); + UINT8_TO_STREAM(pp, sub_mode_type); + UINT8_TO_STREAM(pp, min_main_mode_steps); + UINT8_TO_STREAM(pp, max_main_mode_steps); + UINT8_TO_STREAM(pp, main_mode_repetition); + UINT8_TO_STREAM(pp, mode_0_steps); + UINT8_TO_STREAM(pp, role); + UINT8_TO_STREAM(pp, rtt_type); + UINT8_TO_STREAM(pp, cs_sync_phy); + ARRAY_TO_STREAM(pp, channel_map, 10); + UINT8_TO_STREAM(pp, channel_map_repetition); + UINT8_TO_STREAM(pp, channel_selection_type); + UINT8_TO_STREAM(pp, ch3c_shape); + UINT8_TO_STREAM(pp, ch3c_jump); + UINT8_TO_STREAM(pp, reserved); + + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); + return (TRUE); +} + +UINT8 btsnd_hcic_ble_cs_remove_config(UINT16 conn_handle, UINT8 config_id) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_ERROR("cs remove config, conn_handle %d config_id %d", conn_handle, config_id); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_REMOVE_CONFIG_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_REMOVE_CONFIG); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_REMOVE_CONFIG_PARAMS_LEN); + UINT16_TO_STREAM(pp, conn_handle); + UINT8_TO_STREAM(pp, config_id); + + btu_hcif_send_cmd(LOCAL_BR_EDR_CONTROLLER_ID, p); + + return TRUE; +} + +UINT8 btsnd_hcic_ble_cs_set_channel_classification(UINT8 *channel_class) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("cs set channel class"); + esp_log_buffer_hex_internal("channel", channel_class, 10, ESP_LOG_DEBUG); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_CHANNEL_CLASS_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_SET_CAHNNEL_CLASS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_CHANNEL_CLASS_PARAMS_LEN); + ARRAY_TO_STREAM(pp, channel_class, 10); + + return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); +} + +UINT8 btsnd_hcic_ble_cs_set_procedure_params(UINT16 conn_handle, UINT8 config_id, UINT16 max_procedure_len, + UINT16 min_procedure_interval, UINT16 max_procedure_interval, + UINT16 max_procedure_count, UINT32 min_subevent_len, + UINT32 max_subevent_len, UINT8 tone_ant_config_selection, + UINT8 phy, UINT8 tx_power_delta, UINT8 preferred_peer_antenna, + UINT8 SNR_control_initiator, UINT8 SNR_control_reflector) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("cs set procedure params"); + HCI_TRACE_DEBUG("conn_handle %d config_id %d max_procedure_len %d min_procedure_interval %d max_procedure_interval %d\ + max_procedure_count %d min_subevent_len %d max_subevent_len %d tone_ant_config_selection %d phy %d tx_power_delta %d,\ + preferred_peer_antenna %d SNR_control_initiator %d SNR_control_reflector %d\n", + conn_handle, config_id, max_procedure_len, min_procedure_interval, max_procedure_interval, max_procedure_count, min_subevent_len, max_subevent_len, + tone_ant_config_selection, phy, tx_power_delta, preferred_peer_antenna, SNR_control_initiator, SNR_control_reflector); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_PROCEDURE_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_SET_PROCEDURE_PARAMS); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_PROCEDURE_PARAMS_LEN); + UINT16_TO_STREAM(pp, conn_handle); + UINT8_TO_STREAM(pp, config_id); + UINT16_TO_STREAM(pp, max_procedure_len); + UINT16_TO_STREAM(pp, min_procedure_interval); + UINT16_TO_STREAM(pp, max_procedure_interval); + UINT16_TO_STREAM(pp, max_procedure_count); + UINT24_TO_STREAM(pp, min_subevent_len); + UINT24_TO_STREAM(pp, max_subevent_len); + UINT8_TO_STREAM(pp, tone_ant_config_selection); + UINT8_TO_STREAM(pp, phy); + UINT8_TO_STREAM(pp, tx_power_delta); + UINT8_TO_STREAM(pp, preferred_peer_antenna); + UINT8_TO_STREAM(pp, SNR_control_initiator); + UINT8_TO_STREAM(pp, SNR_control_reflector); + + return btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); +} + +UINT8 btsnd_hcic_ble_cs_procedure_enable(UINT16 conn_handle, UINT8 config_id, UINT8 enable) +{ + BT_HDR *p; + UINT8 *pp; + + HCI_TRACE_DEBUG("cs set procedure enable, conn_handle %d config_id %d enable %d", conn_handle, config_id, enable); + + HCIC_BLE_CMD_CREATED(p, pp, HCIC_PARAM_SIZE_SET_PROCEDURE_ENABLE_PARAMS_LEN); + + pp = (UINT8 *)(p + 1); + + UINT16_TO_STREAM(pp, HCI_BLE_CS_SET_PROCEDURE_ENABLE); + UINT8_TO_STREAM(pp, HCIC_PARAM_SIZE_SET_PROCEDURE_ENABLE_PARAMS_LEN); + UINT16_TO_STREAM(pp, conn_handle); + UINT8_TO_STREAM(pp, config_id); + UINT8_TO_STREAM(pp, enable); + + btu_hcif_send_cmd_sync(LOCAL_BR_EDR_CONTROLLER_ID, p); + + return TRUE; +} +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) diff --git a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h index 8c0460c457a..22de09f434b 100644 --- a/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h +++ b/components/bt/host/bluedroid/stack/include/stack/btm_ble_api.h @@ -1108,7 +1108,22 @@ typedef void (tBTM_SET_VENDOR_EVT_MASK_CBACK) (tBTM_STATUS status); #define BTM_BLE_GAP_PERIODIC_ADV_SUBEVT_DATA_REQUEST_EVT 55 #define BTM_BLE_GAP_PERIODIC_ADV_RESPONSE_REPORT_EVT 56 #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) -#define BTM_BLE_5_GAP_UNKNOWN_EVT 57 +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +#define BTM_BLE_GAP_CS_READ_LOCAL_SUPP_CAPS_EVT 57 +#define BTM_BLE_GAP_CS_WRITE_CACHED_REMOTE_SUPP_CAPS_EVT 58 +#define BTM_BLE_GAP_CS_SET_DEFAULT_SETTINGS_EVT 59 +#define BTM_BLE_GAP_CS_WRITE_CACHED_REMOTE_FAE_TAB_EVT 60 +#define BTM_BLE_GAP_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT 61 +#define BTM_BLE_GAP_CS_SET_CHANNEL_CLASS_CMPL_EVT 62 +#define BTM_BLE_GAP_CS_PROC_PARAMS_CMPL_EVT 63 +#define BTM_BLE_GAP_CS_PROC_ENABLE_CMPL_EVT 64 +#define BTM_BLE_GAP_CS_READ_REMOTE_FAE_TABLE_CMPL_EVT 65 +#define BTM_BLE_GAP_CS_SECURITY_ENABLE_CMPL_EVT 66 +#define BTM_BLE_GAP_CS_CONFIG_CMPL_EVT 67 +#define BTM_BLE_GAP_CS_SUBEVENT_RESULT_EVT 68 +#define BTM_BLE_GAP_CS_SUBEVENT_RESULT_CONTINUE_EVT 69 +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +#define BTM_BLE_5_GAP_UNKNOWN_EVT 70 typedef UINT8 tBTM_BLE_5_GAP_EVENT; #if (BLE_FEAT_ISO_EN == TRUE) @@ -1519,6 +1534,161 @@ typedef struct { } __attribute__((packed)) tBTM_BLE_PA_RSP_REPORT_EVT; #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +typedef struct { + UINT8 status; + UINT16 conn_handle; +} __attribute__((packed)) tBTM_BLE_CS_WRITE_CACHED_SUPPORT_CAPS_EVT; +typedef struct { + UINT8 status; + UINT16 conn_handle; +} __attribute__((packed)) tBTM_BLE_CS_SET_DEFAULT_SETTINGS_EVT; +typedef struct { + UINT8 status; + UINT16 conn_handle; +} __attribute__((packed)) tBTM_BLE_CS_WRITE_CACHED_REMOTE_FAE_TAB_EVT; +typedef struct { + UINT8 status; + UINT16 conn_handle; +} __attribute__((packed)) tBTM_BLE_CS_SET_PAROC_PARAMS_EVT; +typedef struct { + UINT8 status; + UINT16 conn_handle; + UINT8 num_config_supported; + UINT16 max_consecutive_proc_supported; + UINT8 num_ant_supported; + UINT8 max_ant_paths_supported; + UINT8 roles_supported; + UINT8 modes_supported; + UINT8 rtt_capability; + UINT8 rtt_aa_only_n; + UINT8 rtt_sounding_n; + UINT8 rtt_random_payload_n; + UINT16 NADM_sounding_capability; + UINT16 NADM_random_capability; + UINT8 cs_sync_phys_supported; + UINT16 subfeatures_supported; + UINT16 T_IP1_times_supported; + UINT16 T_IP2_times_supported; + UINT16 T_FCS_times_supported; + UINT16 T_PM_times_supported; + UINT8 T_SW_times_supported; + UINT8 TX_SNR_capability; +} __attribute__((packed)) tBTM_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT; + +typedef struct { + UINT8 status; + UINT16 conn_handle; + UINT8 remote_fae_table[72]; +} __attribute__((packed)) tBTM_BLE_CS_READ_REMOTE_FAE_TAB_CMPL_EVT; + +typedef struct { + UINT8 status; + UINT16 conn_handle; +} __attribute__((packed)) tBTM_BLE_CS_SEC_ENABLE_CMPL_EVT; + +typedef struct { + UINT8 status; + UINT16 conn_handle; + UINT8 config_id; + UINT8 action; + UINT8 main_mode_type; + UINT8 sub_mode_type; + UINT8 min_main_mode_steps; + UINT8 max_main_mode_steps; + UINT8 main_mode_repetition; + UINT8 mode_0_steps; + UINT8 role; + UINT8 rtt_type; + UINT8 cs_sync_phy; + UINT8 channel_map[10]; + UINT8 channel_map_repetition; + UINT8 channel_selection_type; + UINT8 ch3c_shape; + UINT8 ch3c_jump; + UINT8 reserved; + UINT8 t_ip1_time; + UINT8 t_ip2_time; + UINT8 t_fcs_time; + UINT8 t_pm_time; +}__attribute__((packed)) tBTM_BLE_CS_CONFIG_CMPL_EVT; + +typedef struct { + UINT8 status; + UINT16 conn_handle; + UINT8 config_id; + UINT8 state; + UINT8 tone_Ant_config_select; + INT8 select_tx_power; + UINT32 subevent_Len; + UINT8 subevents_per_event; + UINT16 subevent_interval; + UINT16 event_interval; + UINT16 procedure_interval; + UINT16 procedure_count; + UINT16 max_procedure_len; +}__attribute__((packed)) tBTM_BLE_CS_PROC_ENABLE_CMPL_EVT; + +typedef struct { + UINT8 step_mode; + UINT8 step_channel; + UINT8 step_data_len; + UINT8 *data; +} __attribute__((packed)) tBTM_BLE_CS_STEP_INFO; + +typedef struct { + UINT16 conn_handle; + UINT8 config_id; + UINT16 start_acl_conn_event_counter; + UINT16 procedure_counter; + INT16 frequency_compensation; + INT8 reference_power_level; + UINT8 procedure_done_status; + UINT8 subevent_done_status; + UINT8 abort_reason; + UINT8 num_ant_paths; + UINT8 num_steps_reported; + tBTM_BLE_CS_STEP_INFO *step_info; +}__attribute__((packed)) tBTM_BLE_CS_SUBEVT_RESULT_CMPL_EVT; + +typedef struct { + UINT16 conn_handle; + UINT8 config_id; + UINT8 proc_done_status; + UINT8 subevt_done_status; + UINT8 abort_reason; + UINT8 num_ant_paths; + UINT8 num_steps_reported; + tBTM_BLE_CS_STEP_INFO *step_info; +}__attribute__((packed)) tBTM_BLE_CS_SUBEVT_RESULT_CONTINUE_EVT; + +typedef struct { + UINT8 status; + UINT16 conn_handle; + UINT8 num_config_supported; + UINT16 max_consecutive_proc_supported; + UINT8 num_ant_supported; + UINT8 max_ant_paths_supported; + UINT8 roles_supported; + UINT8 modes_supported; + UINT8 rtt_capability; + UINT8 rtt_aa_only_n; + UINT8 rtt_sounding_n; + UINT8 rtt_random_payload_n; + UINT16 NADM_sounding_capability; + UINT16 NADM_random_capability; + UINT8 cs_sync_phys_supported; + UINT16 subfeatures_supported; + UINT16 T_IP1_times_supported; + UINT16 T_IP2_times_supported; + UINT16 T_FCS_times_supported; + UINT16 T_PM_times_supported; + UINT8 T_SW_times_supported; + UINT8 TX_SNR_capability; +} __attribute__((packed)) tBTM_BLE_CS_READ_LOCAL_SUPP_CAPS_CMPL_EVT; + +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + #if (BLE_FEAT_ISO_EN == TRUE) #if (BLE_FEAT_ISO_BIG_BROCASTER_EN == TRUE) typedef struct { @@ -1892,6 +2062,20 @@ typedef union { tBTM_BLE_PA_SUBEVT_DATA_REQ_EVT pa_subevent_data_req_evt; tBTM_BLE_PA_RSP_REPORT_EVT pa_rsp_rpt_evt; #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + tBTM_BLE_CS_WRITE_CACHED_SUPPORT_CAPS_EVT cs_write_cached_remote_supp_caps; + tBTM_BLE_CS_SET_DEFAULT_SETTINGS_EVT cs_set_default_settings; + tBTM_BLE_CS_WRITE_CACHED_REMOTE_FAE_TAB_EVT cs_write_cached_remote_fae_tab; + tBTM_BLE_CS_SET_PAROC_PARAMS_EVT cs_set_proc_params; + tBTM_BLE_CS_READ_LOCAL_SUPP_CAPS_CMPL_EVT cs_read_local_supp_caps; + tBTM_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT cs_read_remote_supp_caps; + tBTM_BLE_CS_READ_REMOTE_FAE_TAB_CMPL_EVT cs_read_remote_fae_tab; + tBTM_BLE_CS_SEC_ENABLE_CMPL_EVT cs_security_enable; + tBTM_BLE_CS_PROC_ENABLE_CMPL_EVT cs_proc_en; + tBTM_BLE_CS_CONFIG_CMPL_EVT cs_config_update; + tBTM_BLE_CS_SUBEVT_RESULT_CMPL_EVT cs_subevt_result; + tBTM_BLE_CS_SUBEVT_RESULT_CONTINUE_EVT cs_subevt_result_continue; +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) } tBTM_BLE_5_GAP_CB_PARAMS; typedef struct { @@ -3455,4 +3639,35 @@ void BTM_BleSetPaResponseData(UINT16 sync_handle, UINT16 req_evt, UINT8 req_sube void BTM_BleSetPaSyncSubevt(UINT16 sync_handle, UINT16 periodic_adv_properties, UINT8 num_subevents_to_sync, UINT8 *subevt); #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +void BTM_BleCSReadLocalSuppCaps(void); +void BTM_BleCSReadRemoteSuppCaps(UINT16 conn_handle); +void BTM_BleGapWriteCachedRemoteSupportedCaps(UINT16 conn_handle, UINT8 num_config_supported, UINT16 max_consecutive_proc_supported, + UINT8 num_ant_supported, UINT8 max_ant_paths_supported, UINT8 roles_supported, + UINT8 modes_supported, UINT8 rtt_capability, UINT8 rtt_aa_only_n, + UINT8 rtt_sounding_n, UINT8 rtt_random_payload_n, UINT16 NADM_sounding_capability, + UINT16 NADM_random_capability, UINT8 cs_sync_phys_supported, UINT16 subfeatures_supported, + UINT16 T_IP1_times_supported, UINT16 T_IP2_times_supported, UINT16 T_FCS_times_supported, + UINT16 T_PM_times_supported, UINT8 T_SW_times_supported, UINT8 TX_SNR_capability); +void BTM_BleGapCsSecurityEnable(UINT16 conn_handle); +void BTM_BleGapCsSetDefaultSetting(UINT16 conn_handle, UINT8 role_enable, UINT8 cs_sync_ant_selection, INT8 max_tx_power); +void BTM_BleGapCsReadRemoteFaeTable(UINT16 conn_handle); +void BTM_BleGapWriteCachedRemoteFaeTable(UINT16 conn_handle, UINT8 *remote_fae_table); +void BTM_BleGapCsCreateConfig(UINT16 conn_handle, UINT8 config_id, UINT8 create_context, + UINT8 main_mode_type, UINT8 sub_mode_type, UINT8 min_main_mode_steps, + UINT8 max_main_mode_steps, UINT8 main_mode_repetition, UINT8 mode_0_steps, + UINT8 role, UINT8 rtt_type, UINT8 cs_sync_phy, UINT8 *channel_map, + UINT8 channel_map_repetition, UINT8 channel_selection_type, UINT8 ch3c_shape, + UINT8 ch3c_jump,UINT8 reserved); +void BTM_BleGapCsRemoveConfig(UINT16 conn_handle, UINT8 config_id); +void BTM_BleGapCsSetChannelClass(UINT8 *channel_class); +void BTM_BleGapCsSetProcPatams(UINT16 conn_handle, UINT8 config_id, UINT16 max_procedure_len, + UINT16 min_procedure_interval, UINT16 max_procedure_interval, + UINT16 max_procedure_count, UINT32 min_subevent_len, + UINT32 max_subevent_len, UINT8 tone_ant_config_selection, + UINT8 phy, UINT8 tx_power_delta, UINT8 preferred_peer_antenna, + UINT8 SNR_control_initiator, UINT8 SNR_control_reflector); +void BTM_BleGapCsProcEnable(UINT16 conn_handle, UINT8 config_id, UINT8 enable); +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + #endif diff --git a/components/bt/host/bluedroid/stack/include/stack/hcidefs.h b/components/bt/host/bluedroid/stack/include/stack/hcidefs.h index 8621b67458e..9365de9d54f 100644 --- a/components/bt/host/bluedroid/stack/include/stack/hcidefs.h +++ b/components/bt/host/bluedroid/stack/include/stack/hcidefs.h @@ -455,6 +455,21 @@ #define HCI_BLE_SET_PERIOD_ADV_PARAMS_V2 (0x0086 | HCI_GRP_BLE_CMDS) #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +#define HCI_BLE_CS_READ_LOCAL_SUPP_CAPS (0x0089 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CS_READ_REMOTE_SUPP_CAPS (0x008A | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CS_WRITE_CACHED_REMOTE_SUPP_CAPS (0x008B | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CS_SECURITY_ENABLE (0x008C | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CS_SET_DEFAULT_SETTINGS (0x008D | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CS_READ_REMOTE_FAE_TABLE (0x008E | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CS_WRITE_CACHED_REMOTE_FAE_TABLE (0x008F | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CS_CREATE_CONFIG (0x0090 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CS_REMOVE_CONFIG (0x0091 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CS_SET_CAHNNEL_CLASS (0x0092 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CS_SET_PROCEDURE_PARAMS (0x0093 | HCI_GRP_BLE_CMDS) +#define HCI_BLE_CS_SET_PROCEDURE_ENABLE (0x0094 | HCI_GRP_BLE_CMDS) +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + // Vendor OGF define #define HCI_VENDOR_OGF 0x3F @@ -938,6 +953,16 @@ #define HCI_BLE_PA_RESPONSE_REPORT_EVT 0x28 #endif // #if (BT_BLE_FEAT_PAWR_EN == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +#define HCI_BLE_CS_READ_REMOTE_SUPP_CAPS_CMPL_EVT 0x2C +#define HCI_BLE_CS_READ_REMOTE_FAE_TAB_CMPL_EVT 0x2D +#define HCI_BLE_CS_SECURITY_ENABLE_CMPL_EVT 0x2E +#define HCI_BLE_CS_CONFIG_CMPL_EVT 0x2F +#define HCI_BLE_CS_PROC_ENABLE_CMPL_EVT 0x30 +#define HCI_BLE_CS_SUBEVENT_RESULT_EVT 0x31 +#define HCI_BLE_CS_SUBEVENT_RESULT_CONTINUE_EVT 0x32 +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + /* Definitions for LE Channel Map */ #define HCI_BLE_CHNL_MAP_SIZE 5 diff --git a/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h b/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h index d0f8e205291..c4da454d0fa 100644 --- a/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h +++ b/components/bt/host/bluedroid/stack/include/stack/hcimsgs.h @@ -1284,4 +1284,49 @@ UINT8 btsnd_hcic_ble_set_ext_adv_params_v2(UINT8 adv_handle, UINT16 properties, UINT8 primary_adv_phy_options, UINT8 secondary_adv_phy_options); #endif // (BT_BLE_FEAT_ADV_CODING_SELECTION == TRUE) +#if (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) +#define HCIC_PARAM_SIZE_READ_LOCAL_SUPP_CAPS_PARAMS_LEN 0 +#define HCIC_PARAM_SIZE_READ_REMOTE_SUPP_CAPS_PARAMS_LEN 2 +#define HCIC_PARAM_SIZE_WRITE_CACHE_REMOTE_SUPP_CAPS_PARAMS_LEN 30 +#define HCIC_PARAM_SIZE_SECURITY_ENABLE_PARAMS_LEN 2 +#define HCIC_PARAM_SIZE_SET_DEFAULT_SETTINGS_PARAMS_LEN 5 +#define HCIC_PARAM_SIZE_READ_REMOTE_FAE_TAB_PARAMS_LEN 2 +#define HCIC_PARAM_SIZE_WRITE_CACHED_REMOTE_FAE_TAB_PARAMS_LEN 74 +#define HCIC_PARAM_SIZE_CREATE_CONFIG_PARAMS_LEN 28 +#define HCIC_PARAM_SIZE_REMOVE_CONFIG_PARAMS_LEN 3 +#define HCIC_PARAM_SIZE_SET_CHANNEL_CLASS_PARAMS_LEN 10 +#define HCIC_PARAM_SIZE_SET_PROCEDURE_PARAMS_LEN 21 +#define HCIC_PARAM_SIZE_SET_PROCEDURE_ENABLE_PARAMS_LEN 4 + +UINT8 btsnd_hcic_ble_cs_read_local_supported_caps(void); +UINT8 btsnd_hcic_ble_cs_read_remote_supported_capabilities(UINT16 conn_handle); +UINT8 btsnd_hcic_ble_cs_write_cached_remote_supported_capabilities(UINT16 conn_handle, UINT8 num_config_supported, UINT16 max_consecutive_proc_supported, + UINT8 num_ant_supported, UINT8 max_ant_paths_supported, UINT8 roles_supported, + UINT8 modes_supported, UINT8 rtt_capability, UINT8 rtt_aa_only_n, + UINT8 rtt_sounding_n, UINT8 rtt_random_payload_n, UINT16 NADM_sounding_capability, + UINT16 NADM_random_capability, UINT8 cs_sync_phys_supported, UINT16 subfeatures_supported, + UINT16 T_IP1_times_supported, UINT16 T_IP2_times_supported, UINT16 T_FCS_times_supported, + UINT16 T_PM_times_supported, UINT8 T_SW_times_supported, UINT8 TX_SNR_capability); + +UINT8 btsnd_hcic_ble_cs_security_enable(UINT16 conn_handle); +UINT8 btsnd_hcic_ble_cs_set_default_settings(UINT16 conn_handle, UINT8 role_enable, UINT8 cs_sync_ant_selection, INT8 max_tx_power); +UINT8 btsnd_hcic_ble_cs_read_remote_fae_table(UINT16 conn_handle); +UINT8 btsnd_hcic_ble_cs_write_cached_remote_fae_table(UINT16 conn_handle, UINT8 *remote_fae_table); +UINT8 btsnd_hcic_ble_cs_create_config(UINT16 conn_handle, UINT8 config_id, UINT8 create_context, + UINT8 main_mode_type, UINT8 sub_mode_type, UINT8 min_main_mode_steps, + UINT8 max_main_mode_steps, UINT8 main_mode_repetition, UINT8 mode_0_steps, + UINT8 role, UINT8 rtt_type, UINT8 cs_sync_phy, UINT8 *channel_map, + UINT8 channel_map_repetition, UINT8 channel_selection_type, UINT8 ch3c_shape, + UINT8 ch3c_jump,UINT8 reserved); +UINT8 btsnd_hcic_ble_cs_remove_config(UINT16 conn_handle, UINT8 config_id); +UINT8 btsnd_hcic_ble_cs_set_channel_classification(UINT8 *channel_class); +UINT8 btsnd_hcic_ble_cs_set_procedure_params(UINT16 conn_handle, UINT8 config_id, UINT16 max_procedure_len, + UINT16 min_procedure_interval, UINT16 max_procedure_interval, + UINT16 max_procedure_count, UINT32 min_subevent_len, + UINT32 max_subevent_len, UINT8 tone_ant_config_selection, + UINT8 phy, UINT8 tx_power_delta, UINT8 preferred_peer_antenna, + UINT8 SNR_control_initiator, UINT8 SNR_control_reflector); +UINT8 btsnd_hcic_ble_cs_procedure_enable(UINT16 conn_handle, UINT8 config_id, UINT8 enable); +#endif // (BT_BLE_FEAT_CHANNEL_SOUNDING == TRUE) + #endif