mirror of
https://github.com/espressif/esp-idf.git
synced 2026-06-04 20:26:38 +03:00
fix(ble/bluedroid): fix parameter validation and cleanup in ISO and CTE APIs
- Add parameter validation in esp_ble_iso_api and esp_ble_cte_api - Delete unused ISO functions and incorrect parameter checks - Add host status check in esp_ble_iso_get_callback() - Fix CTE parameter handling when enable value is 0
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2025-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -15,6 +15,9 @@
|
||||
|
||||
esp_err_t esp_ble_cte_register_callback(esp_ble_cte_cb_t callback)
|
||||
{
|
||||
if (callback == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_BLE_CTE, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
@@ -22,6 +25,9 @@ esp_err_t esp_ble_cte_register_callback(esp_ble_cte_cb_t callback)
|
||||
|
||||
esp_ble_cte_cb_t esp_ble_cte_get_callback(void)
|
||||
{
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return NULL;
|
||||
}
|
||||
return (esp_ble_cte_cb_t) btc_profile_cb_get(BTC_PID_BLE_CTE);
|
||||
}
|
||||
|
||||
@@ -30,6 +36,7 @@ esp_err_t esp_ble_cte_set_connectionless_trans_params(esp_ble_cte_connless_trans
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_cte_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@@ -38,6 +45,21 @@ esp_err_t esp_ble_cte_set_connectionless_trans_params(esp_ble_cte_connless_trans
|
||||
if ((cte_trans_params == NULL) || (cte_trans_params->antenna_ids == NULL)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((cte_trans_params->switching_pattern_len < ESP_BLE_CTE_MIN_SWITCHING_PATTERN_LENGTH) ||
|
||||
(cte_trans_params->switching_pattern_len > ESP_BLE_CTE_MAX_SWITCHING_PATTERN_LENGTH)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((cte_trans_params->cte_len < ESP_BLE_CTE_MIN_CTE_LENGTH) ||
|
||||
(cte_trans_params->cte_len > ESP_BLE_CTE_MAX_CTE_LENGTH)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cte_trans_params->cte_type > ESP_BLE_CTE_TYPE_AOD_WITH_2US) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((cte_trans_params->cte_count < ESP_BLE_CTE_MIN_CTE_COUNT) ||
|
||||
(cte_trans_params->cte_count > ESP_BLE_CTE_MAX_CTE_COUNT)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_BLE_CTE;
|
||||
@@ -57,6 +79,7 @@ esp_err_t esp_ble_cte_set_connectionless_trans_enable(esp_ble_cte_trans_enable_p
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_cte_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@@ -65,6 +88,10 @@ esp_err_t esp_ble_cte_set_connectionless_trans_enable(esp_ble_cte_trans_enable_p
|
||||
if (cte_trans_enable == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((cte_trans_enable->cte_enable != ESP_BLE_CTE_ADV_WITH_CTE_DISABLE) &&
|
||||
(cte_trans_enable->cte_enable != ESP_BLE_CTE_ADV_WITH_CTE_ENABLE)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_BLE_CTE;
|
||||
@@ -80,14 +107,39 @@ esp_err_t esp_ble_cte_set_connectionless_iq_sampling_enable(esp_ble_cte_iq_sampl
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_cte_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if ((iq_sampling_en == NULL) || (iq_sampling_en->antenna_ids == NULL)) {
|
||||
// iq_sampling_en must not be NULL
|
||||
if (iq_sampling_en == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
// Sampling enable must be either disable or enable
|
||||
if ((iq_sampling_en->sampling_en != ESP_BLE_CTE_SAMPLING_DISABLE) &&
|
||||
(iq_sampling_en->sampling_en != ESP_BLE_CTE_SAMPLING_ENABLE)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
/* When sampling is enabled, antenna_ids and switching_pattern_len are required; when disabled they are ignored by the controller */
|
||||
if (iq_sampling_en->sampling_en == ESP_BLE_CTE_SAMPLING_ENABLE) {
|
||||
// Slot duration must be either 1us or 2us
|
||||
if ((iq_sampling_en->slot_dur != ESP_BLE_CTE_SLOT_DURATION_1US) &&
|
||||
(iq_sampling_en->slot_dur != ESP_BLE_CTE_SLOT_DURATION_2US)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
// Max sampled Ctes must be between 0 and 16
|
||||
if (iq_sampling_en->max_sampled_ctes > ESP_BLE_CTE_MAX_SAMPLED_CTES) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (iq_sampling_en->antenna_ids == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((iq_sampling_en->switching_pattern_len < ESP_BLE_CTE_MIN_SWITCHING_PATTERN_LENGTH) ||
|
||||
(iq_sampling_en->switching_pattern_len > ESP_BLE_CTE_MAX_SWITCHING_PATTERN_LENGTH)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_BLE_CTE;
|
||||
@@ -97,9 +149,13 @@ esp_err_t esp_ble_cte_set_connectionless_iq_sampling_enable(esp_ble_cte_iq_sampl
|
||||
arg.cte_iq_sampling_en.sampling_en = iq_sampling_en->sampling_en;
|
||||
arg.cte_iq_sampling_en.slot_dur = iq_sampling_en->slot_dur;
|
||||
arg.cte_iq_sampling_en.max_sampled_ctes = iq_sampling_en->max_sampled_ctes;
|
||||
arg.cte_iq_sampling_en.switching_pattern_len = iq_sampling_en->switching_pattern_len;
|
||||
arg.cte_iq_sampling_en.antenna_ids = iq_sampling_en->antenna_ids;
|
||||
|
||||
if (iq_sampling_en->sampling_en == ESP_BLE_CTE_SAMPLING_ENABLE) {
|
||||
arg.cte_iq_sampling_en.switching_pattern_len = iq_sampling_en->switching_pattern_len;
|
||||
arg.cte_iq_sampling_en.antenna_ids = iq_sampling_en->antenna_ids;
|
||||
} else {
|
||||
arg.cte_iq_sampling_en.switching_pattern_len = 0;
|
||||
arg.cte_iq_sampling_en.antenna_ids = NULL;
|
||||
}
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_cte_args_t), btc_ble_cte_arg_deep_copy, btc_ble_cte_arg_deep_free) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif // #if (BLE_FEAT_CTE_CONNECTIONLESS_EN == TRUE)
|
||||
@@ -109,14 +165,33 @@ esp_err_t esp_ble_cte_set_connection_receive_params(esp_ble_cte_recv_params_para
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_cte_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if ((cte_recv_params == NULL) || (cte_recv_params->antenna_ids == NULL)) {
|
||||
if (cte_recv_params == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((cte_recv_params->sampling_en != ESP_BLE_CTE_SAMPLING_DISABLE) &&
|
||||
(cte_recv_params->sampling_en != ESP_BLE_CTE_SAMPLING_ENABLE)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
/* When sampling is enabled, antenna_ids and switching_pattern_len are required; when disabled they are ignored by the controller */
|
||||
if (cte_recv_params->sampling_en == ESP_BLE_CTE_SAMPLING_ENABLE) {
|
||||
if ((cte_recv_params->slot_dur != ESP_BLE_CTE_SLOT_DURATION_1US) &&
|
||||
(cte_recv_params->slot_dur != ESP_BLE_CTE_SLOT_DURATION_2US)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cte_recv_params->antenna_ids == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((cte_recv_params->switching_pattern_len < ESP_BLE_CTE_MIN_SWITCHING_PATTERN_LENGTH) ||
|
||||
(cte_recv_params->switching_pattern_len > ESP_BLE_CTE_MAX_SWITCHING_PATTERN_LENGTH)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_BLE_CTE;
|
||||
@@ -125,8 +200,13 @@ esp_err_t esp_ble_cte_set_connection_receive_params(esp_ble_cte_recv_params_para
|
||||
arg.cte_recv_params.conn_handle = cte_recv_params->conn_handle;
|
||||
arg.cte_recv_params.sampling_en = cte_recv_params->sampling_en;
|
||||
arg.cte_recv_params.slot_dur = cte_recv_params->slot_dur;
|
||||
arg.cte_recv_params.switching_pattern_len = cte_recv_params->switching_pattern_len;
|
||||
arg.cte_recv_params.antenna_ids = cte_recv_params->antenna_ids;
|
||||
if (cte_recv_params->sampling_en == ESP_BLE_CTE_SAMPLING_ENABLE) {
|
||||
arg.cte_recv_params.switching_pattern_len = cte_recv_params->switching_pattern_len;
|
||||
arg.cte_recv_params.antenna_ids = cte_recv_params->antenna_ids;
|
||||
} else {
|
||||
arg.cte_recv_params.switching_pattern_len = 0;
|
||||
arg.cte_recv_params.antenna_ids = NULL;
|
||||
}
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_cte_args_t), btc_ble_cte_arg_deep_copy, btc_ble_cte_arg_deep_free) == BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
@@ -135,6 +215,7 @@ esp_err_t esp_ble_cte_set_connection_transmit_params(esp_ble_cte_conn_trans_para
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_cte_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@@ -143,6 +224,15 @@ esp_err_t esp_ble_cte_set_connection_transmit_params(esp_ble_cte_conn_trans_para
|
||||
if ((cte_conn_trans_params == NULL) || (cte_conn_trans_params->antenna_ids == NULL)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((cte_conn_trans_params->switching_pattern_len < ESP_BLE_CTE_MIN_SWITCHING_PATTERN_LENGTH) ||
|
||||
(cte_conn_trans_params->switching_pattern_len > ESP_BLE_CTE_MAX_SWITCHING_PATTERN_LENGTH)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
/* cte_types must be non-zero and only allowed bits (AOA, AoD 1us, AoD 2us) */
|
||||
if ((cte_conn_trans_params->cte_types == 0) ||
|
||||
(cte_conn_trans_params->cte_types & ~ESP_BLE_CTE_TYPES_ALL)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_BLE_CTE;
|
||||
@@ -160,6 +250,7 @@ esp_err_t esp_ble_cte_connection_cte_request_enable(esp_ble_cte_req_en_params_t
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_cte_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@@ -168,6 +259,19 @@ esp_err_t esp_ble_cte_connection_cte_request_enable(esp_ble_cte_req_en_params_t
|
||||
if (cte_conn_req_en == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((cte_conn_req_en->enable != ESP_BLE_CTE_REQUEST_FOR_CONNECTION_DISABLE) &&
|
||||
(cte_conn_req_en->enable != ESP_BLE_CTE_REQUEST_FOR_CONNECTION_ENABLE)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cte_conn_req_en->enable == ESP_BLE_CTE_REQUEST_FOR_CONNECTION_ENABLE) {
|
||||
if ((cte_conn_req_en->req_cte_len < ESP_BLE_CTE_MIN_REQUESTED_CTE_LENGTH) ||
|
||||
(cte_conn_req_en->req_cte_len > ESP_BLE_CTE_MAX_REQUESTED_CTE_LENGTH)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cte_conn_req_en->req_cte_Type > ESP_BLE_CTE_TYPE_AOD_WITH_2US) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_BLE_CTE;
|
||||
@@ -186,6 +290,7 @@ esp_err_t esp_ble_cte_connection_cte_response_enable(esp_ble_cte_rsp_en_params_t
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_ble_cte_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@@ -194,6 +299,10 @@ esp_err_t esp_ble_cte_connection_cte_response_enable(esp_ble_cte_rsp_en_params_t
|
||||
if (cte_conn_rsp_en == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((cte_conn_rsp_en->enable != ESP_BLE_CTE_RESPONSE_FOR_CONNECTION_DISABLE) &&
|
||||
(cte_conn_rsp_en->enable != ESP_BLE_CTE_RESPONSE_FOR_CONNECTION_ENABLE)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_BLE_CTE;
|
||||
|
||||
@@ -14,6 +14,9 @@
|
||||
|
||||
esp_err_t esp_ble_iso_register_callback(esp_ble_iso_cb_t callback)
|
||||
{
|
||||
if (callback == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
|
||||
return (btc_profile_cb_set(BTC_PID_ISO_BLE, callback) == 0 ? ESP_OK : ESP_FAIL);
|
||||
@@ -21,23 +24,55 @@ esp_err_t esp_ble_iso_register_callback(esp_ble_iso_cb_t callback)
|
||||
|
||||
esp_ble_iso_cb_t esp_ble_iso_get_callback(void)
|
||||
{
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return (esp_ble_iso_cb_t) btc_profile_cb_get(BTC_PID_ISO_BLE);
|
||||
}
|
||||
|
||||
#if (BLE_FEAT_ISO_BIG_BROCASTER_EN == TRUE)
|
||||
#if (BLE_FEAT_ISO_BIG_BROADCASTER_EN == TRUE)
|
||||
esp_err_t esp_ble_iso_create_big(esp_ble_iso_big_creat_params_t *big_creat_param)
|
||||
{
|
||||
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
|
||||
if (big_creat_param == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (big_creat_param->num_bis > BLE_ISO_BIS_MAX_COUNT) {
|
||||
if (big_creat_param->num_bis == 0 || big_creat_param->num_bis > BLE_ISO_BIS_MAX_COUNT) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_param->num_bis > ESP_BLE_MAX_BIS_NUM) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_param->sdu_interval < BLE_ISO_SDU_INT_MIN || big_creat_param->sdu_interval > BLE_ISO_SDU_INT_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_param->max_sdu < 0x0001 || big_creat_param->max_sdu > 0x0FFF) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_param->max_transport_latency < BLE_ISO_MAX_TRANSPORT_LATENCY_MIN ||
|
||||
big_creat_param->max_transport_latency > BLE_ISO_MAX_TRANSPORT_LATENCY_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_param->rtn > 0x1E) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((big_creat_param->phy != 0x01) && (big_creat_param->phy != 0x02) && (big_creat_param->phy != 0x04)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_param->packing > 0x01) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_param->framing > BLE_ISO_FRAMING_FRAMED_PDU_UNSEGMENTABLE_MODE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_param->encryption > 0x01) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@@ -53,18 +88,58 @@ esp_err_t esp_ble_iso_create_big(esp_ble_iso_big_creat_params_t *big_creat_param
|
||||
|
||||
esp_err_t esp_ble_iso_create_big_test(esp_ble_iso_big_creat_test_params_t *big_creat_test_param)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
|
||||
if (big_creat_test_param == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (big_creat_test_param->num_bis > BLE_ISO_BIS_MAX_COUNT) {
|
||||
if (big_creat_test_param->num_bis == 0 || big_creat_test_param->num_bis > BLE_ISO_BIS_MAX_COUNT) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->num_bis > ESP_BLE_MAX_BIS_NUM) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->sdu_interval < BLE_ISO_SDU_INT_MIN || big_creat_test_param->sdu_interval > BLE_ISO_SDU_INT_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->iso_interval < 0x0004 || big_creat_test_param->iso_interval > 0x0C80) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->nse == 0 || big_creat_test_param->nse > 0x1F) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->max_sdu < 0x0001 || big_creat_test_param->max_sdu > 0x0FFF) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->max_pdu < 0x0001 || big_creat_test_param->max_pdu > 0x00FB) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if ((big_creat_test_param->phy != 0x01) && (big_creat_test_param->phy != 0x02) && (big_creat_test_param->phy != 0x04)) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->framing > BLE_ISO_FRAMING_FRAMED_PDU_UNSEGMENTABLE_MODE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->bn == 0 || big_creat_test_param->bn > 0x07) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->irc == 0 || big_creat_test_param->irc > 0x0F) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->encryption > 0x01) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->packing > 0x01) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_creat_test_param->pto > 0x0F) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_ISO_BLE;
|
||||
@@ -78,11 +153,17 @@ esp_err_t esp_ble_iso_create_big_test(esp_ble_iso_big_creat_test_params_t *big_c
|
||||
|
||||
esp_err_t esp_ble_iso_terminate_big(uint8_t big_handle, uint8_t reason)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
|
||||
/* big_handle: 0x00 to 0xEF */
|
||||
if (big_handle > 0xEF) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_ISO_BLE;
|
||||
msg.act = BTC_ISO_ACT_BIG_TERMINATE;
|
||||
@@ -93,23 +174,51 @@ esp_err_t esp_ble_iso_terminate_big(uint8_t big_handle, uint8_t reason)
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_iso_args_t), NULL, NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
#endif // #if (BLE_FEAT_ISO_BIG_BROCASTER_EN == TRUE)
|
||||
#endif // #if (BLE_FEAT_ISO_BIG_BROADCASTER_EN == TRUE)
|
||||
|
||||
#if (BLE_FEAT_ISO_BIG_SYNCER_EN == TRUE)
|
||||
esp_err_t esp_ble_iso_big_create_sync(esp_ble_iso_big_sync_creat_params_t *big_sync_create_param)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
|
||||
if (big_sync_create_param == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
if (big_sync_create_param->num_bis > BLE_ISO_BIS_MAX_COUNT) {
|
||||
/* num_bis: 0x01 to 0x1F, and not more than BLE_ISO_BIS_MAX_COUNT */
|
||||
if (big_sync_create_param->num_bis == 0 || big_sync_create_param->num_bis > BLE_ISO_BIS_MAX_COUNT) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_sync_create_param->num_bis > ESP_BLE_MAX_BIS_NUM) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_sync_create_param->big_handle > 0xEF) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
/* sync_handle: 0x0000 to 0x0EFF */
|
||||
if (big_sync_create_param->sync_handle > 0x0EFF) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (big_sync_create_param->encryption > 0x01) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
/* mse: 0x00 to 0x1F */
|
||||
if (big_sync_create_param->mse > 0x1F) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
/* big_sync_timeout: 0x000A to 0x4000 */
|
||||
if (big_sync_create_param->big_sync_timeout < 0x000A || big_sync_create_param->big_sync_timeout > 0x4000) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
for (uint8_t k = 0; k < big_sync_create_param->num_bis; k++) {
|
||||
/* BIS index: 0x01 to 0x1F */
|
||||
if (big_sync_create_param->bis[k] == 0 || big_sync_create_param->bis[k] > 0x1F) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_ISO_BLE;
|
||||
@@ -127,19 +236,23 @@ esp_err_t esp_ble_iso_big_create_sync(esp_ble_iso_big_sync_creat_params_t *big_s
|
||||
arg.iso_big_sync_creat_params.bis[i] = big_sync_create_param->bis[i];
|
||||
}
|
||||
|
||||
// memcpy(&arg.iso_big_sync_creat_params, big_sync_create_param, sizeof(esp_ble_iso_big_sync_creat_params_t));
|
||||
|
||||
return (btc_transfer_context(&msg, &arg, sizeof(btc_ble_iso_args_t), NULL, NULL)
|
||||
== BT_STATUS_SUCCESS ? ESP_OK : ESP_FAIL);
|
||||
}
|
||||
|
||||
esp_err_t esp_ble_iso_big_terminate_sync(uint8_t big_handle)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
ESP_BLUEDROID_STATUS_CHECK(ESP_BLUEDROID_STATUS_ENABLED);
|
||||
|
||||
/* big_handle: 0x00 to 0xEF */
|
||||
if (big_handle > 0xEF) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_ISO_BLE;
|
||||
msg.act = BTC_ISO_ACT_BIG_SYNC_TERMINATE;
|
||||
@@ -155,6 +268,7 @@ esp_err_t esp_ble_iso_set_iso_data_path(esp_ble_iso_set_data_path_params_t *data
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@@ -175,6 +289,10 @@ esp_err_t esp_ble_iso_set_iso_data_path(esp_ble_iso_set_data_path_params_t *data
|
||||
if (data_path_params->data_path_dir > ESP_BLE_ISO_DATA_PATH_DIR_OUTPUT) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
/* controller_delay: 0x000000 to 0x3D0900 (0 to 4 s in microseconds) */
|
||||
if (data_path_params->controller_delay > 0x3D0900) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_ISO_BLE;
|
||||
@@ -198,6 +316,7 @@ esp_err_t esp_ble_iso_remove_iso_data_path(esp_ble_iso_remove_data_path_params_t
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@@ -226,6 +345,7 @@ esp_err_t esp_ble_iso_read_iso_tx_sync(uint16_t iso_handle)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@@ -244,6 +364,7 @@ esp_err_t esp_ble_iso_read_link_quality(uint16_t iso_handle)
|
||||
{
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
@@ -261,14 +382,36 @@ esp_err_t esp_ble_iso_read_link_quality(uint16_t iso_handle)
|
||||
#if (BLE_FEAT_ISO_CIG_CENTRAL_EN == TRUE)
|
||||
esp_err_t esp_ble_iso_set_cig_parameters(struct esp_ble_iso_set_cig_params *cig_params)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if ((cig_params == NULL) || (cig_params->cis_cnt > BLE_ISO_CIS_MAX_COUNT)) {
|
||||
if (cig_params == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params->cis_cnt == 0 || cig_params->cis_cnt > BLE_ISO_CIS_MAX_COUNT) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params->sdu_int_c_to_p < BLE_ISO_SDU_INT_MIN || cig_params->sdu_int_c_to_p > BLE_ISO_SDU_INT_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params->sdu_int_p_to_c < BLE_ISO_SDU_INT_MIN || cig_params->sdu_int_p_to_c > BLE_ISO_SDU_INT_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params->worse_case_SCA > BLE_ISO_WORST_CASE_SCA_LEVEL_20_PPM) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params->framing > BLE_ISO_FRAMING_FRAMED_PDU_UNSEGMENTABLE_MODE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params->mtl_c_to_p < BLE_ISO_MAX_TRANSPORT_LATENCY_MIN || cig_params->mtl_c_to_p > BLE_ISO_MAX_TRANSPORT_LATENCY_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params->mtl_p_to_c < BLE_ISO_MAX_TRANSPORT_LATENCY_MIN || cig_params->mtl_p_to_c > BLE_ISO_MAX_TRANSPORT_LATENCY_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@@ -293,14 +436,33 @@ esp_err_t esp_ble_iso_set_cig_parameters(struct esp_ble_iso_set_cig_params *cig_
|
||||
|
||||
esp_err_t esp_ble_iso_set_cig_parameters_test(struct esp_ble_iso_set_cig_params_test *cig_params_test)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if ((cig_params_test == NULL) || (cig_params_test->cis_cnt > BLE_ISO_CIS_MAX_COUNT)) {
|
||||
if (cig_params_test == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params_test->cis_cnt == 0 || cig_params_test->cis_cnt > BLE_ISO_CIS_MAX_COUNT) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params_test->sdu_int_c_to_p < BLE_ISO_SDU_INT_MIN || cig_params_test->sdu_int_c_to_p > BLE_ISO_SDU_INT_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params_test->sdu_int_p_to_c < BLE_ISO_SDU_INT_MIN || cig_params_test->sdu_int_p_to_c > BLE_ISO_SDU_INT_MAX) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params_test->iso_interval < 0x0004 || cig_params_test->iso_interval > 0x0C80) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params_test->worse_case_SCA > BLE_ISO_WORST_CASE_SCA_LEVEL_20_PPM) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (cig_params_test->framing > BLE_ISO_FRAMING_FRAMED_PDU_UNSEGMENTABLE_MODE) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@@ -326,14 +488,18 @@ esp_err_t esp_ble_iso_set_cig_parameters_test(struct esp_ble_iso_set_cig_params_
|
||||
|
||||
esp_err_t esp_ble_iso_create_cis(struct esp_ble_iso_create_cis_params *creat_cis_params)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if ((creat_cis_params == NULL) || (creat_cis_params->cis_count > BLE_ISO_CIS_MAX_COUNT)) {
|
||||
if (creat_cis_params == NULL) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
if (creat_cis_params->cis_count == 0 || creat_cis_params->cis_count > BLE_ISO_CIS_MAX_COUNT) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
@@ -355,13 +521,19 @@ esp_err_t esp_ble_iso_create_cis(struct esp_ble_iso_create_cis_params *creat_cis
|
||||
|
||||
esp_err_t esp_ble_iso_remove_cig(uint8_t cig_id)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
|
||||
/* cig_id: 0x00 to 0xEF */
|
||||
if (cig_id > 0xEF) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_ISO_BLE;
|
||||
msg.act = BTC_ISO_ACT_REMOVE_CIG;
|
||||
@@ -375,12 +547,17 @@ esp_err_t esp_ble_iso_remove_cig(uint8_t cig_id)
|
||||
#if (BLE_FEAT_ISO_CIG_PERIPHERAL_EN == TRUE)
|
||||
esp_err_t esp_ble_iso_accept_cis_request(uint16_t cis_handle)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
/* Connection handle range: 0x0000 to 0x0EFF */
|
||||
if (cis_handle > 0x0EFF) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_ISO_BLE;
|
||||
@@ -393,12 +570,16 @@ esp_err_t esp_ble_iso_accept_cis_request(uint16_t cis_handle)
|
||||
|
||||
esp_err_t esp_ble_iso_reject_cis_request(uint16_t cis_handle, uint8_t reason)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (cis_handle > 0x0EFF) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_ISO_BLE;
|
||||
@@ -414,12 +595,16 @@ esp_err_t esp_ble_iso_reject_cis_request(uint16_t cis_handle, uint8_t reason)
|
||||
#if (BLE_FEAT_ISO_CIG_EN == TRUE)
|
||||
esp_err_t esp_ble_iso_disconnect_cis(uint16_t cis_handle, uint8_t reason)
|
||||
{
|
||||
btc_msg_t msg;
|
||||
btc_msg_t msg = {0};
|
||||
btc_ble_iso_args_t arg;
|
||||
memset(&arg, 0, sizeof(arg));
|
||||
|
||||
if (esp_bluedroid_get_status() != ESP_BLUEDROID_STATUS_ENABLED) {
|
||||
return ESP_ERR_INVALID_STATE;
|
||||
}
|
||||
if (cis_handle > 0x0EFF) {
|
||||
return ESP_ERR_INVALID_ARG;
|
||||
}
|
||||
|
||||
msg.sig = BTC_SIG_API_CALL;
|
||||
msg.pid = BTC_PID_ISO_BLE;
|
||||
|
||||
@@ -78,7 +78,7 @@ typedef enum {
|
||||
#define BLE_ISO_MAX_TRANSPORT_LATENCY_MIN (0x0005)
|
||||
#define BLE_ISO_MAX_TRANSPORT_LATENCY_MAX (0x0FA0)
|
||||
|
||||
#if (BLE_FEAT_ISO_BIG_BROCASTER_EN == TRUE)
|
||||
#if (BLE_FEAT_ISO_BIG_BROADCASTER_EN == TRUE)
|
||||
typedef struct {
|
||||
uint8_t big_handle; /*!< Used to identify the BIG, value 0x00 to 0xEF */
|
||||
uint8_t adv_handle; /*!< Used to identify the periodic advertising train, value 0x00 to 0xEF */
|
||||
@@ -113,7 +113,7 @@ typedef struct {
|
||||
uint8_t broadcast_code[16]; /*!< The code used to derive the session key that is used to encrypt and decrypt BIS payloads */
|
||||
} esp_ble_iso_big_creat_test_params_t;
|
||||
|
||||
#endif //#if (BLE_FEAT_ISO_BIG_BROCASTER_EN == TRUE)
|
||||
#endif //#if (BLE_FEAT_ISO_BIG_BROADCASTER_EN == TRUE)
|
||||
|
||||
#if (BLE_FEAT_ISO_BIG_SYNCER_EN == TRUE)
|
||||
typedef struct {
|
||||
@@ -431,7 +431,7 @@ esp_ble_iso_cb_t esp_ble_iso_get_callback(void);
|
||||
|
||||
|
||||
|
||||
#if (BLE_FEAT_ISO_BIG_BROCASTER_EN == TRUE)
|
||||
#if (BLE_FEAT_ISO_BIG_BROADCASTER_EN == TRUE)
|
||||
|
||||
/**
|
||||
* @brief This function is called to create BIG.
|
||||
@@ -469,7 +469,7 @@ esp_err_t esp_ble_iso_create_big_test(esp_ble_iso_big_creat_test_params_t *big_c
|
||||
*
|
||||
*/
|
||||
esp_err_t esp_ble_iso_terminate_big(uint8_t big_handle, uint8_t reason);
|
||||
#endif // #if (BLE_FEAT_ISO_BIG_BROCASTER_EN == TRUE)
|
||||
#endif // #if (BLE_FEAT_ISO_BIG_BROADCASTER_EN == TRUE)
|
||||
|
||||
#if (BLE_FEAT_ISO_BIG_SYNCER_EN == TRUE)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user