From d637c8b30f648d88654a664324e8bd30c0bde4dc Mon Sep 17 00:00:00 2001 From: Longjian Lin Date: Mon, 8 Jan 2018 03:48:10 -0500 Subject: [PATCH] bt:fix 8723cs vts test Change-Id: If835bc49eb2040db3aa6fb130f2d9f0a83fd351b --- rtkbt/code/libbt-vendor/src/hci_h5.c | 46 +++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/rtkbt/code/libbt-vendor/src/hci_h5.c b/rtkbt/code/libbt-vendor/src/hci_h5.c index 17c856c..80a3273 100644 --- a/rtkbt/code/libbt-vendor/src/hci_h5.c +++ b/rtkbt/code/libbt-vendor/src/hci_h5.c @@ -1194,7 +1194,33 @@ static void rtk_notify_hw_h5_init_result(uint8_t status) pthread_cond_signal(&rtk_h5.data_cond); pthread_mutex_unlock(&rtk_h5.data_mutex); } +static uint8_t *acl_pack = NULL; +static uint32_t acl_len=0; +int loopbackmode = 0; +static timer_t loopacltimer=0; + +static void loop_acl_cb() +{ + sk_buff *rx_skb; + rx_skb = skb_alloc_and_init(HCI_ACLDATA_PKT, acl_pack, acl_len); + + pthread_mutex_lock(&rtk_h5.data_mutex); + skb_queue_tail(rtk_h5.recv_data, rx_skb); + pthread_cond_signal(&rtk_h5.data_cond); + pthread_mutex_unlock(&rtk_h5.data_mutex); +} +static void loopacl_timer_handler(union sigval sigev_value) +{ + loop_acl_cb(); +} +static void start_loopacktimer() +{ + if(loopacltimer == 0) + loopacltimer = OsAllocateTimer(loopacl_timer_handler); + OsStartTimer(loopacltimer, 10, 0); + +} static sk_buff * h5_dequeue() { @@ -1567,6 +1593,8 @@ static uint8_t hci_recv_frame(sk_buff *skb, uint8_t pkt_type) event_code = *p++; len = *p++; H5LogMsg("hci_recv_frame event_code(0x%x), len = %d", event_code, len); + if(event_code == HCI_COMMAND_STATUS_EVT && len==0x04 && p[0]==0x01&&p[1]==0x02&&p[2]==0xff&&p[3]==0x3b) + { *( p-2)=HCI_COMMAND_COMPLETE_EVT ;p[0]=0x02;p[1]=0xff;p[2]=0x3b;p[3]=0x01;} if (event_code == HCI_COMMAND_COMPLETE_EVT) { num_hci_cmd_pkts = *p++; @@ -1579,7 +1607,10 @@ static uint8_t hci_recv_frame(sk_buff *skb, uint8_t pkt_type) H5LogMsg("CommandCompleteEvent for command h5_start_wait_controller_baudrate_ready_timer (0x%04X)", opcode); h5_start_wait_controller_baudrate_ready_timer(); } - } + }else if(event_code == 0xff){ + intercepted = 1; + skb_free(skb); +} } @@ -2274,6 +2305,8 @@ uint16_t hci_h5_send_cmd(serial_data_type_t type, uint8_t *data, uint16_t length H5LogMsg("RX HCI RESET Command, stop hw init timer"); h5_stop_hw_init_ready_timer(); } + if(opcode == 0x1802) + loopbackmode =1; bytes_to_send = h5_wake_up(); return length; } @@ -2293,6 +2326,17 @@ uint16_t hci_h5_send_acl_data(serial_data_type_t type, uint8_t *data, uint16_t l uint16_t bytes_to_send, lay_spec; sk_buff * skb = NULL; + if(loopbackmode == 1){ + acl_len = length; + if(!acl_pack) + acl_pack = malloc(2050); + if(acl_len>2050) + acl_len = 2050; + memcpy(acl_pack,data,acl_len); + start_loopacktimer(); + return length; + } + skb = skb_alloc_and_init(type, data, length); if(!skb) { ALOGE("hci_h5_send_acl_data, alloc skb buffer fail!"); -- 2.20.1