bt:1.FIX some bt crash and bt block
authorLongjian Lin <llj@rock-chips.com>
Fri, 12 Jan 2018 01:04:30 +0000 (20:04 -0500)
committerLongjian Lin <llj@rock-chips.com>
Fri, 12 Jan 2018 01:04:30 +0000 (20:04 -0500)
Change-Id: I800c04e840b736045dbe8c6bd8dcb5030720fb15

rtkbt/code/libbt-vendor/src/hci_h5.c
rtkbt/code/libbt-vendor/src/userial_vendor.c

index 80a3273efe6324cb74bf783dec9eaa7d79f21e77..c4cb422bf3b50ccaf9a51db1fd0b5b0d1718f2ec 100644 (file)
@@ -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);
 
index 72323533c49a3b4bf64163448c66e727a52794d7..9b62d2f71cce0d5a3769bb7c0aacdd78605b6e81 100644 (file)
@@ -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();
+
+    }
 }
 
 /*******************************************************************************