mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 11:10:54 +03:00
fix(bt/example): fix critical issues of classic_bt examples reported by AI review
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021-2022 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@@ -21,7 +21,8 @@ static void bt_app_work_dispatched(bt_app_msg_t *msg);
|
||||
static QueueHandle_t bt_app_task_queue = NULL;
|
||||
static TaskHandle_t bt_app_task_handle = NULL;
|
||||
|
||||
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback)
|
||||
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len,
|
||||
bt_app_copy_cb_t p_copy_cback, bt_app_free_cb_t p_free_cback)
|
||||
{
|
||||
ESP_LOGD(BT_APP_CORE_TAG, "%s event 0x%x, param len %d", __func__, event, param_len);
|
||||
|
||||
@@ -31,6 +32,7 @@ bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, i
|
||||
msg.sig = BT_APP_SIG_WORK_DISPATCH;
|
||||
msg.event = event;
|
||||
msg.cb = p_cback;
|
||||
msg.free_cb = p_free_cback;
|
||||
|
||||
if (param_len == 0) {
|
||||
return bt_app_send_msg(&msg);
|
||||
@@ -41,7 +43,14 @@ bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, i
|
||||
if (p_copy_cback) {
|
||||
p_copy_cback(&msg, msg.param, p_params);
|
||||
}
|
||||
return bt_app_send_msg(&msg);
|
||||
if (!bt_app_send_msg(&msg)) {
|
||||
if (p_free_cback) {
|
||||
p_free_cback(msg.param);
|
||||
}
|
||||
free(msg.param);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,7 +59,7 @@ bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, i
|
||||
|
||||
static bool bt_app_send_msg(bt_app_msg_t *msg)
|
||||
{
|
||||
if (msg == NULL) {
|
||||
if (msg == NULL || bt_app_task_queue == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -87,6 +96,9 @@ static void bt_app_task_handler(void *arg)
|
||||
} // switch (msg.sig)
|
||||
|
||||
if (msg.param) {
|
||||
if (msg.free_cb) {
|
||||
msg.free_cb(msg.param);
|
||||
}
|
||||
free(msg.param);
|
||||
}
|
||||
}
|
||||
@@ -107,6 +119,15 @@ void bt_app_task_shut_down(void)
|
||||
bt_app_task_handle = NULL;
|
||||
}
|
||||
if (bt_app_task_queue) {
|
||||
bt_app_msg_t msg;
|
||||
while (xQueueReceive(bt_app_task_queue, &msg, 0) == pdTRUE) {
|
||||
if (msg.param) {
|
||||
if (msg.free_cb) {
|
||||
msg.free_cb(msg.param);
|
||||
}
|
||||
free(msg.param);
|
||||
}
|
||||
}
|
||||
vQueueDelete(bt_app_task_queue);
|
||||
bt_app_task_queue = NULL;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2021-2026 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Unlicense OR CC0-1.0
|
||||
*/
|
||||
@@ -20,11 +20,17 @@
|
||||
*/
|
||||
typedef void (* bt_app_cb_t) (uint16_t event, void *param);
|
||||
|
||||
/**
|
||||
* @brief parameter deep-free function
|
||||
*/
|
||||
typedef void (* bt_app_free_cb_t) (void *p_param);
|
||||
|
||||
/* message to be sent */
|
||||
typedef struct {
|
||||
uint16_t sig; /*!< signal to bt_app_task */
|
||||
uint16_t event; /*!< message event id */
|
||||
bt_app_cb_t cb; /*!< context switch callback */
|
||||
bt_app_free_cb_t free_cb; /*!< parameter deep-free function */
|
||||
void *param; /*!< parameter area needs to be the last */
|
||||
} bt_app_msg_t;
|
||||
|
||||
@@ -36,7 +42,8 @@ typedef void (* bt_app_copy_cb_t) (bt_app_msg_t *msg, void *p_dest, void *p_src)
|
||||
/**
|
||||
* @brief work dispatcher for the application task
|
||||
*/
|
||||
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len, bt_app_copy_cb_t p_copy_cback);
|
||||
bool bt_app_work_dispatch(bt_app_cb_t p_cback, uint16_t event, void *p_params, int param_len,
|
||||
bt_app_copy_cb_t p_copy_cback, bt_app_free_cb_t p_free_cback);
|
||||
|
||||
void bt_app_task_start_up(void);
|
||||
|
||||
|
||||
@@ -160,9 +160,9 @@ const char *c_at_response_code_str[] = {
|
||||
|
||||
// esp_hf_subscriber_service_type_t
|
||||
const char *c_subscriber_service_type_str[] = {
|
||||
"unknown",
|
||||
"voice",
|
||||
"fax",
|
||||
[ESP_HF_SUBSCRIBER_SERVICE_TYPE_UNKNOWN] = "unknown",
|
||||
[ESP_HF_SUBSCRIBER_SERVICE_TYPE_VOICE] = "voice",
|
||||
[ESP_HF_SUBSCRIBER_SERVICE_TYPE_FAX] = "fax",
|
||||
};
|
||||
|
||||
// esp_hf_client_in_band_ring_state_t
|
||||
@@ -242,6 +242,7 @@ static void bt_app_hf_client_audio_close(void)
|
||||
}
|
||||
|
||||
vRingbufferDelete(m_rb);
|
||||
m_rb = NULL;
|
||||
}
|
||||
|
||||
static uint32_t bt_app_hf_client_outgoing_cb(uint8_t *p_buf, uint32_t sz)
|
||||
@@ -329,11 +330,14 @@ void bt_app_hf_client_cb(esp_hf_client_cb_event_t event, esp_hf_client_cb_param_
|
||||
} else if (param->audio_stat.state == ESP_HF_CLIENT_AUDIO_STATE_DISCONNECTED) {
|
||||
s_sync_conn_hdl = 0;
|
||||
s_msbc_air_mode = false;
|
||||
esp_hf_audio_buff_t *buff_to_free = NULL;
|
||||
while (xQueueReceive(s_audio_buff_queue, &buff_to_free, 0)) {
|
||||
esp_hf_client_audio_buff_free(buff_to_free);
|
||||
if (s_audio_buff_queue) {
|
||||
esp_hf_audio_buff_t *buff_to_free = NULL;
|
||||
while (xQueueReceive(s_audio_buff_queue, &buff_to_free, 0)) {
|
||||
esp_hf_client_audio_buff_free(buff_to_free);
|
||||
}
|
||||
vQueueDelete(s_audio_buff_queue);
|
||||
s_audio_buff_queue = NULL;
|
||||
}
|
||||
vQueueDelete(s_audio_buff_queue);
|
||||
s_audio_buff_cnt = 0;
|
||||
}
|
||||
#else
|
||||
|
||||
@@ -207,7 +207,7 @@ void app_main(void)
|
||||
bt_app_task_start_up();
|
||||
|
||||
/* Bluetooth device name, connection mode and profile set up */
|
||||
bt_app_work_dispatch(bt_hf_client_hdl_stack_evt, BT_APP_EVT_STACK_UP, NULL, 0, NULL);
|
||||
bt_app_work_dispatch(bt_hf_client_hdl_stack_evt, BT_APP_EVT_STACK_UP, NULL, 0, NULL, NULL);
|
||||
|
||||
#if CONFIG_BT_HFP_AUDIO_DATA_PATH_PCM
|
||||
/* configure the PCM interface and PINs used */
|
||||
|
||||
Reference in New Issue
Block a user