From 3e3445811afca8c0c003baae50aa0b6b61979496 Mon Sep 17 00:00:00 2001 From: weitianhua Date: Thu, 3 Dec 2020 17:18:19 +0800 Subject: [PATCH] Correct some debug log for BT Stack & Add protection for rfcomm close API in SPP --- components/bt/bluedroid/api/esp_bt_main.c | 16 ++++++++++---- components/bt/bluedroid/bta/jv/bta_jv_api.c | 5 ++++- .../bt/bluedroid/bta/sys/bta_sys_main.c | 1 - .../bluedroid/stack/include/stack/a2d_api.h | 21 +++++++++++++++---- .../bluedroid/stack/include/stack/sdp_api.h | 2 +- .../bt/bluedroid/stack/l2cap/l2c_utils.c | 4 ++-- .../bt/bluedroid/stack/rfcomm/port_utils.c | 10 +++++++++ components/bt/bluedroid/stack/sdp/sdp_api.c | 6 +++--- components/bt/common/btc/core/btc_task.c | 4 ++-- .../bt/common/btc/include/btc/btc_task.h | 2 +- 10 files changed, 52 insertions(+), 19 deletions(-) diff --git a/components/bt/bluedroid/api/esp_bt_main.c b/components/bt/bluedroid/api/esp_bt_main.c index 8aff98e8b9..f3d3fe1c6e 100644 --- a/components/bt/bluedroid/api/esp_bt_main.c +++ b/components/bt/bluedroid/api/esp_bt_main.c @@ -117,6 +117,7 @@ esp_err_t esp_bluedroid_init(void) { btc_msg_t msg; future_t **future_p; + bt_status_t ret; if (esp_bt_controller_get_status() != ESP_BT_CONTROLLER_STATUS_ENABLED) { LOG_ERROR("Controller not initialised\n"); @@ -135,23 +136,30 @@ esp_err_t esp_bluedroid_init(void) future_p = btc_main_get_future_p(BTC_MAIN_INIT_FUTURE); *future_p = future_new(); if (*future_p == NULL) { - LOG_ERROR("Bluedroid initialise failed\n"); + LOG_ERROR("Bluedroid Initialize Fail!"); return ESP_ERR_NO_MEM; } - btc_init(); + /* + * BTC Init + */ + ret = btc_init(); + if (ret != BT_STATUS_SUCCESS) { + LOG_ERROR("Bluedroid Initialize Fail"); + return ESP_FAIL; + } msg.sig = BTC_SIG_API_CALL; msg.pid = BTC_PID_MAIN_INIT; msg.act = BTC_MAIN_ACT_INIT; if (btc_transfer_context(&msg, NULL, 0, NULL) != BT_STATUS_SUCCESS) { - LOG_ERROR("Bluedroid initialise failed\n"); + LOG_ERROR("Bluedroid Initialize Fail!"); return ESP_FAIL; } if (future_await(*future_p) == FUTURE_FAIL) { - LOG_ERROR("Bluedroid initialise failed\n"); + LOG_ERROR("Bluedroid Initialize Fail!"); return ESP_FAIL; } diff --git a/components/bt/bluedroid/bta/jv/bta_jv_api.c b/components/bt/bluedroid/bta/jv/bta_jv_api.c index ccbdadcb06..94fca7d1b5 100644 --- a/components/bt/bluedroid/bta/jv/bta_jv_api.c +++ b/components/bt/bluedroid/bta/jv/bta_jv_api.c @@ -95,8 +95,11 @@ tBTA_JV_STATUS BTA_JvEnable(tBTA_JV_DM_CBACK *p_cback) bta_sys_sendmsg(p_buf); status = BTA_JV_SUCCESS; } + } else if (p_cback == NULL) { + APPL_TRACE_ERROR("No p_cback."); } else { - APPL_TRACE_ERROR("JVenable fails"); + APPL_TRACE_WARNING("No need to Init again."); + // status = BTA_JV_SUCCESS; } return (status); } diff --git a/components/bt/bluedroid/bta/sys/bta_sys_main.c b/components/bt/bluedroid/bta/sys/bta_sys_main.c index e3b8c77fa9..82eade94a7 100644 --- a/components/bt/bluedroid/bta/sys/bta_sys_main.c +++ b/components/bt/bluedroid/bta/sys/bta_sys_main.c @@ -501,7 +501,6 @@ void bta_sys_event(BT_HDR *p_msg) if (freebuf) { osi_free(p_msg); } - } /******************************************************************************* diff --git a/components/bt/bluedroid/stack/include/stack/a2d_api.h b/components/bt/bluedroid/stack/include/stack/a2d_api.h index 7509544fb5..238d3af805 100644 --- a/components/bt/bluedroid/stack/include/stack/a2d_api.h +++ b/components/bt/bluedroid/stack/include/stack/a2d_api.h @@ -235,10 +235,6 @@ extern UINT8 A2D_SetTraceLevel (UINT8 new_level); ******************************************************************************/ extern UINT8 A2D_BitsSet(UINT8 num); -#ifdef __cplusplus -} -#endif - /******************************************************************************* ** ** Function A2D_Init @@ -251,6 +247,23 @@ extern UINT8 A2D_BitsSet(UINT8 num); ** *******************************************************************************/ extern void A2D_Init(void); + +/******************************************************************************* +** +** Function A2D_Deinit +** +** Description This function is called at stack startup to free the +** control block (if using dynamic memory), and free the +** control block and tracing level. +** +** Returns void +** +*******************************************************************************/ extern void A2D_Deinit(void); + +#ifdef __cplusplus +} +#endif + #endif ///A2D_INCLUDED #endif /* A2D_API_H */ diff --git a/components/bt/bluedroid/stack/include/stack/sdp_api.h b/components/bt/bluedroid/stack/include/stack/sdp_api.h index a64e5f2604..70da3182a5 100644 --- a/components/bt/bluedroid/stack/include/stack/sdp_api.h +++ b/components/bt/bluedroid/stack/include/stack/sdp_api.h @@ -222,7 +222,7 @@ extern BOOLEAN SDP_ServiceSearchRequest (UINT8 *p_bd_addr, ** Description This function queries an SDP server for information. ** ** The difference between this API function and the function -** SDP_ServiceSearchRequest is that this one does a +** SDP_ServiceSearchRequest2 is that this one does a ** combined ServiceSearchAttributeRequest SDP function. ** ** Returns TRUE if discovery started, FALSE if failed. diff --git a/components/bt/bluedroid/stack/l2cap/l2c_utils.c b/components/bt/bluedroid/stack/l2cap/l2c_utils.c index e6389413b9..22443faecd 100644 --- a/components/bt/bluedroid/stack/l2cap/l2c_utils.c +++ b/components/bt/bluedroid/stack/l2cap/l2c_utils.c @@ -2202,7 +2202,7 @@ void l2cu_device_reset (void) ** ** Description This function initiates an acl connection via HCI ** -** Returns TRUE if successful, FALSE if gki get buffer fails. +** Returns TRUE if successful, FALSE if osi get buffer fails. ** *******************************************************************************/ BOOLEAN l2cu_create_conn (tL2C_LCB *p_lcb, tBT_TRANSPORT transport) @@ -2309,7 +2309,7 @@ UINT8 l2cu_get_num_hi_priority (void) ** Description This function initiates an acl connection via HCI ** If switch required to create connection it is already done. ** -** Returns TRUE if successful, FALSE if gki get buffer fails. +** Returns TRUE if successful, FALSE if osi get buffer fails. ** *******************************************************************************/ diff --git a/components/bt/bluedroid/stack/rfcomm/port_utils.c b/components/bt/bluedroid/stack/rfcomm/port_utils.c index 0da8b3d76b..b7b8162edd 100644 --- a/components/bt/bluedroid/stack/rfcomm/port_utils.c +++ b/components/bt/bluedroid/stack/rfcomm/port_utils.c @@ -212,12 +212,22 @@ void port_release_port (tPORT *p_port) RFCOMM_TRACE_DEBUG("port_release_port, p_port:%p", p_port); while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->rx.queue)) != NULL) { osi_free (p_buf); + if (p_port->rx.queue) { + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_port->rx.queue)) != NULL) { + osi_free (p_buf); + } + } } p_port->rx.queue_size = 0; while ((p_buf = (BT_HDR *)fixed_queue_try_dequeue(p_port->tx.queue)) != NULL) { osi_free (p_buf); + if (p_port->tx.queue) { + while ((p_buf = (BT_HDR *)fixed_queue_dequeue(p_port->tx.queue)) != NULL) { + osi_free (p_buf); + } + } } p_port->tx.queue_size = 0; diff --git a/components/bt/bluedroid/stack/sdp/sdp_api.c b/components/bt/bluedroid/stack/sdp/sdp_api.c index 5a2e4f8ba4..60e3cd18ee 100644 --- a/components/bt/bluedroid/stack/sdp/sdp_api.c +++ b/components/bt/bluedroid/stack/sdp/sdp_api.c @@ -169,9 +169,9 @@ BOOLEAN SDP_ServiceSearchRequest (UINT8 *p_bd_addr, tSDP_DISCOVERY_DB *p_db, ** Description This function queries an SDP server for information. ** ** The difference between this API function and the function -** SDP_ServiceSearchRequest is that this one does a -** combined ServiceSearchAttributeRequest SDP function. -** (This is for Unplug Testing) +** SDP_ServiceSearchRequest2 is that this one does a +** combined ServiceSearchAttributeRequest SDP function with the +** user data piggyback. ** ** Returns TRUE if discovery started, FALSE if failed. ** diff --git a/components/bt/common/btc/core/btc_task.c b/components/bt/common/btc/core/btc_task.c index af60227f9a..71a91d4fe4 100644 --- a/components/bt/common/btc/core/btc_task.c +++ b/components/bt/common/btc/core/btc_task.c @@ -250,10 +250,10 @@ bt_status_t btc_inter_profile_call(btc_msg_t *msg, void *arg) return BT_STATUS_SUCCESS; } -int btc_init(void) +bt_status_t btc_init(void) { xBtcQueue = xQueueCreate(BTC_TASK_QUEUE_LEN, sizeof(btc_msg_t)); - xTaskCreatePinnedToCore(btc_task, "Btc_task", BTC_TASK_STACK_SIZE, NULL, BTC_TASK_PRIO, &xBtcTaskHandle, BTC_TASK_PINNED_TO_CORE); + xTaskCreatePinnedToCore(btc_task, "BTC_TASK", BTC_TASK_STACK_SIZE, NULL, BTC_TASK_PRIO, &xBtcTaskHandle, BTC_TASK_PINNED_TO_CORE); if (xBtcTaskHandle == NULL || xBtcQueue == 0){ return BT_STATUS_NOMEM; } diff --git a/components/bt/common/btc/include/btc/btc_task.h b/components/bt/common/btc/include/btc/btc_task.h index 8e6cb6a673..846d3bc7bf 100644 --- a/components/bt/common/btc/include/btc/btc_task.h +++ b/components/bt/common/btc/include/btc/btc_task.h @@ -112,7 +112,7 @@ bt_status_t btc_transfer_context(btc_msg_t *msg, void *arg, int arg_len, btc_arg */ bt_status_t btc_inter_profile_call(btc_msg_t *msg, void *arg); -int btc_init(void); +bt_status_t btc_init(void); void btc_deinit(void); bool btc_check_queue_is_congest(void);