From 85653ed7a8d853b17aa1f92357b282fe1c3198a7 Mon Sep 17 00:00:00 2001 From: Longjian Lin Date: Thu, 11 Jan 2018 20:04:30 -0500 Subject: [PATCH] bt:1.FIX some bt crash and bt block Change-Id: I800c04e840b736045dbe8c6bd8dcb5030720fb15 --- rtkbt/code/libbt-vendor/src/hci_h5.c | 31 ++++++++++++++++---- rtkbt/code/libbt-vendor/src/userial_vendor.c | 17 ++++++----- 2 files changed, 36 insertions(+), 12 deletions(-) diff --git a/rtkbt/code/libbt-vendor/src/hci_h5.c b/rtkbt/code/libbt-vendor/src/hci_h5.c index 80a3273..c4cb422 100644 --- a/rtkbt/code/libbt-vendor/src/hci_h5.c +++ b/rtkbt/code/libbt-vendor/src/hci_h5.c @@ -1609,7 +1609,7 @@ static uint8_t hci_recv_frame(sk_buff *skb, uint8_t pkt_type) } }else if(event_code == 0xff){ intercepted = 1; - skb_free(skb); + skb_free(&skb); } } @@ -1918,6 +1918,15 @@ static bool h5_recv(tHCI_H5_CB *h5, uint8_t *data, int count) /****************************************************************************** ** Static functions ******************************************************************************/ +static void h5_data_ready_cb_signal_exit() +{ + + pthread_mutex_lock(&rtk_h5.data_mutex); + pthread_cond_signal(&rtk_h5.data_cond); + pthread_mutex_unlock(&rtk_h5.data_mutex); +} + + static void data_ready_cb_thread(void *arg) { sk_buff *skb; @@ -1931,12 +1940,15 @@ static void data_ready_cb_thread(void *arg) while (h5_data_ready_running) { pthread_mutex_lock(&rtk_h5.data_mutex); - while ((skb_queue_get_length(rtk_h5.recv_data) == 0)) + while ((skb_queue_get_length(rtk_h5.recv_data) == 0) && h5_retransfer_running) { pthread_cond_wait(&rtk_h5.data_cond, &rtk_h5.data_mutex); } pthread_mutex_unlock(&rtk_h5.data_mutex); + if(!h5_retransfer_running) + break; + if((skb = skb_dequeue_head(rtk_h5.recv_data)) != NULL) { rtk_h5.data_skb = skb; } @@ -1946,7 +1958,7 @@ static void data_ready_cb_thread(void *arg) h5_int_hal_callbacks->h5_data_ready_cb(pkt_type, total_length); } - H5LogMsg("data_ready_cb_thread exiting"); + ALOGE("data_ready_cb_thread exiting"); pthread_exit(NULL); } @@ -2012,7 +2024,7 @@ static void data_retransfer_thread(void *arg) } - H5LogMsg("data_retransfer_thread exiting"); + ALOGE("data_retransfer_thread exiting"); pthread_exit(NULL); } @@ -2165,11 +2177,12 @@ void hci_h5_int_init(hci_h5_callbacks_t* h5_callbacks) *******************************************************************************/ void hci_h5_cleanup(void) { - H5LogMsg("hci_h5_cleanup"); + ALOGE("hci_h5_cleanup"); uint8_t try_cnt=10; int result; rtk_h5.cleanuping = 1; + ms_delay(200); //btsnoop_cleanup(); @@ -2184,6 +2197,10 @@ void hci_h5_cleanup(void) if (h5_retransfer_running) { h5_retransfer_running = 0; + h5_data_ready_cb_signal_exit(); + if ((result = pthread_join(rtk_h5.thread_data_ready_cb, NULL)) < 0) + ALOGE("H5 thread_data_ready_cb pthread_join() FAILED result:%d", result); + h5_retransfer_signal_event(H5_EVENT_EXIT); if ((result = pthread_join(rtk_h5.thread_data_retrans, NULL)) < 0) ALOGE("H5 pthread_join() FAILED result:%d", result); @@ -2191,6 +2208,10 @@ void hci_h5_cleanup(void) ms_delay(200); + + pthread_mutex_destroy(&rtk_h5.data_mutex); + pthread_cond_destroy(&rtk_h5.data_cond); + pthread_mutex_destroy(&rtk_h5.mutex); pthread_cond_destroy(&rtk_h5.cond); diff --git a/rtkbt/code/libbt-vendor/src/userial_vendor.c b/rtkbt/code/libbt-vendor/src/userial_vendor.c index 7232353..9b62d2f 100644 --- a/rtkbt/code/libbt-vendor/src/userial_vendor.c +++ b/rtkbt/code/libbt-vendor/src/userial_vendor.c @@ -423,14 +423,7 @@ void userial_vendor_close(void) if (vnd_userial.fd == -1) return; - if((rtkbt_transtype & RTKBT_TRANS_UART) && (rtkbt_transtype & RTKBT_TRANS_H5)) { -#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE) - /* de-assert bt_wake BEFORE closing port */ - ioctl(vnd_userial.fd, USERIAL_IOCTL_BT_WAKE_DEASSERT, NULL); -#endif - h5_int_interface->h5_int_cleanup(); - } vnd_userial.thread_running = false; @@ -443,6 +436,16 @@ void userial_vendor_close(void) rtk_parse_manager->rtk_parse_cleanup(); } rtk_parse_manager = NULL; + + + if((rtkbt_transtype & RTKBT_TRANS_UART) && (rtkbt_transtype & RTKBT_TRANS_H5)) { +#if (BT_WAKE_VIA_USERIAL_IOCTL==TRUE) + /* de-assert bt_wake BEFORE closing port */ + ioctl(vnd_userial.fd, USERIAL_IOCTL_BT_WAKE_DEASSERT, NULL); +#endif + h5_int_interface->h5_int_cleanup(); + + } } /******************************************************************************* -- 2.20.1