author | Tellen Yu <tellen.yu@amlogic.com> | 2018-10-09 15:18:56 (GMT) |
---|---|---|
committer | Gerrit Code Review <gituser@droid04> | 2018-10-09 15:18:56 (GMT) |
commit | 984603a82920146f7d3ec4ba3d65c07f1f84078e (patch) | |
tree | 8b7da52742e1b4881627c489a5288d08d052598a | |
parent | ce0e951be57bf12fc2313125ff8996b2684cdbe2 (diff) | |
parent | 27bf09c6fbc4c84c40d0c78540824d9997dc1fa8 (diff) | |
download | amlogic-p-amlogic.zip amlogic-p-amlogic.tar.gz amlogic-p-amlogic.tar.bz2 |
Merge "BT: fix native bt crashes" into p-amlogic
9 files changed, 126 insertions, 60 deletions
diff --git a/bluetooth/realtek/rtkbt/code/libbt-vendor/include/bt_vendor_rtk.h b/bluetooth/realtek/rtkbt/code/libbt-vendor/include/bt_vendor_rtk.h index 18f551a..713eabe 100755 --- a/bluetooth/realtek/rtkbt/code/libbt-vendor/include/bt_vendor_rtk.h +++ b/bluetooth/realtek/rtkbt/code/libbt-vendor/include/bt_vendor_rtk.h @@ -60,7 +60,6 @@ #define RTKBT_TRANS_UART 0x01 #define RTKBT_TRANS_USB 0x20 - #ifndef FALSE #define FALSE 0 #endif diff --git a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hardware_uart.c b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hardware_uart.c index 2622c6c..344f4ad 100755 --- a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hardware_uart.c +++ b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hardware_uart.c @@ -1,5 +1,5 @@ #define LOG_TAG "bt_hwcfg_uart" -#define RTKBT_RELEASE_NAME "Test-2" +#define RTKBT_RELEASE_NAME "Test-3" #include <utils/Log.h> #include <sys/types.h> diff --git a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hardware_usb.c b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hardware_usb.c index 74957a7..ce67647 100755 --- a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hardware_usb.c +++ b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hardware_usb.c @@ -201,10 +201,10 @@ static void rtk_usb_update_altsettings(usb_patch_info *patch_entry, unsigned cha struct rtk_bt_vendor_config_entry* entry = config->entry; size_t config_len = *config_len_ptr; unsigned int i = 0; - int count = 0,temp = 0, j; + int count = 0,temp = 0, j; ALOGI("ORG Config len=%08zx:\n", config_len); - for(i=0;i<=config_len;i+=0x10) + for(i = 0; i <= config_len; i+= 0x10) { ALOGI("%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, \ config_buf_ptr[i], config_buf_ptr[i+1], config_buf_ptr[i+2], config_buf_ptr[i+3], config_buf_ptr[i+4], config_buf_ptr[i+5], config_buf_ptr[i+6], config_buf_ptr[i+7], \ @@ -229,7 +229,7 @@ static void rtk_usb_update_altsettings(usb_patch_info *patch_entry, unsigned cha return; } - for (i=0; i<data_len;) + for (i = 0; i < data_len;) { for(j = 0; j < count;j++) { @@ -244,6 +244,7 @@ static void rtk_usb_update_altsettings(usb_patch_info *patch_entry, unsigned cha i += temp; entry = (struct rtk_bt_vendor_config_entry*)((uint8_t*)entry + temp); } + for(j = 0; j < count;j++){ if(offset[j] == 0) continue; @@ -258,10 +259,10 @@ static void rtk_usb_update_altsettings(usb_patch_info *patch_entry, unsigned cha entry = (struct rtk_bt_vendor_config_entry*)((uint8_t*)entry + temp); } config->data_len = cpu_to_le16(i); - *config_len_ptr = i+sizeof(struct rtk_bt_vendor_config); + *config_len_ptr = i + sizeof(struct rtk_bt_vendor_config); ALOGI("NEW Config len=%08zx:\n", *config_len_ptr); - for(i=0;i<=(*config_len_ptr);i+=0x10) + for(i = 0; i<= (*config_len_ptr); i+= 0x10) { ALOGI("%08x: %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", i, \ config_buf_ptr[i], config_buf_ptr[i+1], config_buf_ptr[i+2], config_buf_ptr[i+3], config_buf_ptr[i+4], config_buf_ptr[i+5], config_buf_ptr[i+6], config_buf_ptr[i+7], \ @@ -295,7 +296,7 @@ static void rtk_usb_parse_config_file(unsigned char** config_buf, size_t* filele } hw_cfg_cb.heartbeat = 0; - for (i=0; i<config_len;) + for (i = 0; i < config_len;) { switch(le16_to_cpu(entry->offset)) { @@ -633,7 +634,7 @@ void hw_usb_config_cback(void *p_mem) STREAM_TO_UINT16(hw_cfg_cb.hci_revision, p); p = (uint8_t *)(p_evt_buf + 1) + HCI_EVT_CMD_CMPL_OP1001_LMP_SUBVERSION_OFFSET; STREAM_TO_UINT16(hw_cfg_cb.lmp_subversion, p); - + prtk_usb_patch_file_info = rtk_usb_get_fw_table_entry(hw_cfg_cb.vid, hw_cfg_cb.pid); if((prtk_usb_patch_file_info == NULL) || (prtk_usb_patch_file_info->lmp_sub_default == 0)) { @@ -677,7 +678,7 @@ void hw_usb_config_cback(void *p_mem) hw_cfg_cb.state = 0; is_proceeding = TRUE; } - + /* if(hw_cfg_cb.lmp_subversion == LMPSUBVERSION_8723a) { hw_cfg_cb.state = HW_CFG_START; diff --git a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hci_h5.c b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hci_h5.c index 1de5a18..67d8af0 100755 --- a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hci_h5.c +++ b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/hci_h5.c @@ -2222,7 +2222,7 @@ uint16_t hci_h5_send_cmd(serial_data_type_t type, uint8_t *data, uint16_t length *******************************************************************************/ uint16_t hci_h5_send_acl_data(serial_data_type_t type, uint8_t *data, uint16_t length) { - uint16_t bytes_to_send;//, lay_spec; + uint16_t bytes_to_send; sk_buff * skb = NULL; skb = skb_alloc_and_init(type, data, length); @@ -2250,7 +2250,7 @@ uint16_t hci_h5_send_acl_data(serial_data_type_t type, uint8_t *data, uint16_t l uint16_t hci_h5_send_sco_data(serial_data_type_t type, uint8_t *data, uint16_t length) { sk_buff * skb = NULL; - uint16_t bytes_to_send;//, lay_spec; + uint16_t bytes_to_send; skb = skb_alloc_and_init(type, data, length); if(!skb) { diff --git a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_btservice.c b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_btservice.c index 3ecd314..762108c 100755 --- a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_btservice.c +++ b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_btservice.c @@ -83,6 +83,7 @@ typedef void (*tTIMER_HANDLE_CBACK)(union sigval sigval_value); typedef struct Rtk_Btservice_Info { int socketfd; + int sig_fd[2]; pthread_t cmdreadythd; pthread_t epollthd; int current_client_sock; @@ -127,7 +128,7 @@ typedef struct Rtk_Queue_Data void (*complete_cback)(void *); }Rtkqueuedata; -static Rtk_Btservice_Info *rtk_btservice = NULL; +static Rtk_Btservice_Info *rtk_btservice; static void Rtk_Service_Send_Hwerror_Event(); //extern void userial_recv_rawdata_hook(unsigned char *, unsigned int); static timer_t OsAllocateTimer(tTIMER_HANDLE_CBACK timer_callback) @@ -293,7 +294,7 @@ void Rtk_Service_Vendorcmd_Hook(Rtk_Service_Data *RtkData, int client_sock) { Rtkqueuedata* rtkqueue_data = NULL; if(!rtk_btservice) { - ALOGE("rtkbt service is NULL"); + ALOGE("rtkbt service is null"); return; } @@ -571,7 +572,7 @@ static int socket_accept(socketfd) { struct sockaddr_un un; socklen_t len; - int client_sock=0; + int client_sock = 0; len = sizeof(un); struct epoll_event event; @@ -583,10 +584,10 @@ static int socket_accept(socketfd) } //pthread_create(&connectthread,NULL,(void *)accept_request_thread,&client_sock); - event.data.fd=client_sock; - event.events=EPOLLIN | EPOLLHUP | EPOLLRDHUP | EPOLLERR; + event.data.fd = client_sock; + event.events = EPOLLIN | EPOLLHUP | EPOLLRDHUP | EPOLLERR; //list_add(client_sock); - if(epoll_ctl(rtk_btservice->epoll_fd,EPOLL_CTL_ADD,client_sock,&event)==-1) + if(epoll_ctl(rtk_btservice->epoll_fd, EPOLL_CTL_ADD, client_sock, &event)==-1) { ALOGE("%s unable to register fd %d to epoll set: %s", __func__, client_sock, strerror(errno)); close(client_sock); @@ -603,21 +604,26 @@ static void *epoll_thread() while(rtk_btservice->epoll_thread_running) { - nfds=epoll_wait(rtk_btservice->epoll_fd,events,32,500); + nfds = epoll_wait(rtk_btservice->epoll_fd,events, 32, 500); if(rtk_btservice->epoll_thread_running != 0) { - if(nfds>0) + if(nfds > 0) { - for(i=0;i<nfds;i++) + for(i = 0; i < nfds; i++) { - if(events[i].data.fd == rtk_btservice->socketfd && events[i].events&EPOLLIN) + if(events[i].data.fd == rtk_btservice->sig_fd[1]) { + ALOGE("epoll_thread , receive exit signal"); + continue; + } + + if(events[i].data.fd == rtk_btservice->socketfd && events[i].events & EPOLLIN) { - if(socket_accept(events[i].data.fd)<0) + if(socket_accept(events[i].data.fd) < 0) { pthread_exit(0); } } - else if(events[i].events&(EPOLLIN | EPOLLHUP | EPOLLRDHUP | EPOLLERR)) + else if(events[i].events & (EPOLLIN | EPOLLHUP | EPOLLRDHUP | EPOLLERR)) { ALOGD("%s events[i].data.fd = %d ", __func__, events[i].data.fd); Getpacket(events[i].data.fd); @@ -664,17 +670,31 @@ static int unix_socket_start(const char *servername) ALOGE("%s chmod failed"); } */ - event.data.fd=rtk_btservice->socketfd; - event.events=EPOLLIN; - if(epoll_ctl(rtk_btservice->epoll_fd,EPOLL_CTL_ADD,rtk_btservice->socketfd,&event)==-1) + event.data.fd = rtk_btservice->socketfd; + event.events = EPOLLIN; + if(epoll_ctl(rtk_btservice->epoll_fd, EPOLL_CTL_ADD, rtk_btservice->socketfd,&event) == -1) { ALOGE("%s unable to register fd %d to epoll set: %s", __func__, rtk_btservice->socketfd, strerror(errno)); return -1; } + event.data.fd = rtk_btservice->sig_fd[1]; + event.events = EPOLLIN; + if(epoll_ctl(rtk_btservice->epoll_fd, EPOLL_CTL_ADD, rtk_btservice->sig_fd[1], &event) == -1) + { + ALOGE("%s unable to register signal fd %d to epoll set: %s", __func__, rtk_btservice->sig_fd[1], strerror(errno)); + return -1; + } return 0; } +void RTK_btservice_send_close_signal(void) +{ + unsigned char close_signal = 1; + ssize_t ret; + RTK_NO_INTR(ret = write(rtk_btservice->sig_fd[0], &close_signal, 1)); +} + int RTK_btservice_thread_start() { rtk_btservice->epoll_thread_running=1; @@ -684,7 +704,7 @@ int RTK_btservice_thread_start() return -1; } - rtk_btservice->cmdqueue_thread_running=1; + rtk_btservice->cmdqueue_thread_running = 1; if (pthread_create(&rtk_btservice->cmdreadythd, NULL, cmdready_thread, NULL)!=0) { ALOGE("pthread_create cmdready_thread: %s", strerror(errno)); @@ -696,9 +716,9 @@ int RTK_btservice_thread_start() void RTK_btservice_thread_stop() { - ALOGD("%s !", __func__); rtk_btservice->epoll_thread_running=0; rtk_btservice->cmdqueue_thread_running=0; + RTK_btservice_send_close_signal(); sem_post(&rtk_btservice->cmdqueue_sem); sem_post(&rtk_btservice->cmdsend_sem); pthread_join(rtk_btservice->cmdreadythd, NULL); @@ -710,12 +730,11 @@ void RTK_btservice_thread_stop() int RTK_btservice_init() { int ret; - rtk_btservice=(Rtk_Btservice_Info *)malloc(sizeof(Rtk_Btservice_Info)); + rtk_btservice = (Rtk_Btservice_Info *)malloc(sizeof(Rtk_Btservice_Info)); rtk_btservice->current_client_sock = -1; rtk_btservice->current_complete_cback = NULL; rtk_btservice->autopair_fd = -1; - ALOGD("%s init start!", __func__); hcicmd_alloc_reply_timer(); sem_init(&rtk_btservice->cmdqueue_sem, 0, 0); @@ -729,6 +748,11 @@ int RTK_btservice_init() return -1; } + if((ret = socketpair(AF_UNIX, SOCK_STREAM, 0, rtk_btservice->sig_fd)) < 0) { + ALOGE("%s, errno : %s", __func__, strerror(errno)); + return ret; + } + rtk_btservice->epoll_fd = epoll_create(64); if (rtk_btservice->epoll_fd == -1) { ALOGE("%s unable to create epoll instance: %s", __func__, strerror(errno)); @@ -742,7 +766,7 @@ int RTK_btservice_init() } ret = RTK_btservice_thread_start(); - if(ret<0) + if(ret < 0) { ALOGE("%s RTK_btservice_thread_start fail!", __func__); return -1; @@ -756,6 +780,8 @@ void RTK_btservice_destroyed() RTK_btservice_thread_stop(); close(rtk_btservice->socketfd); rtk_btservice->socketfd = -1; + close(rtk_btservice->sig_fd[0]); + close(rtk_btservice->sig_fd[1]); sem_destroy(&rtk_btservice->cmdqueue_sem); sem_destroy(&rtk_btservice->cmdsend_sem); flush_cmdqueue_hash(rtk_btservice); diff --git a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_heartbeat.c b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_heartbeat.c index ccd59cb..79c0d03 100755 --- a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_heartbeat.c +++ b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_heartbeat.c @@ -26,7 +26,7 @@ #include <semaphore.h> #include <endian.h> #include <byteswap.h> -#include <sys/un.h> +#include <sys/un.h> #include <stddef.h> #include <sys/socket.h> #include <sys/types.h> @@ -138,7 +138,7 @@ static void rtkbt_heartbeat_cmpl_cback (void *p_params) status = p_evt_buf->data[HCI_EVT_HEARTBEAT_STATUS_OFFSET]; seqnum = p_evt_buf->data[HCI_EVT_HEARTBEAT_SEQNUM_OFFSET_H]<<8 | p_evt_buf->data[HCI_EVT_HEARTBEAT_SEQNUM_OFFSET_L]; } - + if(status == 0 && seqnum == nextSeqNum) { nextSeqNum = (seqnum+1); @@ -151,14 +151,14 @@ static void rtkbt_heartbeat_cmpl_cback (void *p_params) usleep(1000); rtkbt_heartbeat_send_hw_error(); } - + } static void heartbeat_timed_out()//(union sigval arg) { Rtk_Service_Data *p_buf; - + heartbeatCount++; if(heartbeatCount >= 3) { @@ -218,7 +218,7 @@ static void rtkbt_heartbeat_beginTimer_func(void) p_buf->parameter = NULL; p_buf->parameter_len = 0; p_buf->complete_cback = rtkbt_heartbeat_cmpl_cback; - + Rtk_Service_Vendorcmd_Hook(p_buf,-1); free(p_buf); diff --git a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_parse.c b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_parse.c index bdd69f0..661d86e 100755 --- a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_parse.c +++ b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/rtk_parse.c @@ -1848,7 +1848,7 @@ void rtk_handle_event_from_wifi(uint8_t* msg) { uint8_t *p = msg; uint8_t event_code = *p++; - uint8_t total_length = 0; + uint8_t total_length = 0; if(memcmp(msg, invite_rsp, sizeof(invite_rsp)) == 0) { #if 0 @@ -2058,14 +2058,14 @@ int stop_btwifi_coex_receive_thread() ALOGE( "data thread pthread_join() failed result:%d", result); } - if(rtk_prof.udpsocket) { + if(rtk_prof.udpsocket > 0) { RtkLogMsg("close socket %d", rtk_prof.udpsocket); if((result = close(rtk_prof.udpsocket)) != 0) { ALOGE("close socket error!"); } } - else if(rtk_prof.btcoex_chr) { + else if(rtk_prof.btcoex_chr > 0) { RtkLogMsg("close char device %d", rtk_prof.btcoex_chr); if((result = close(rtk_prof.btcoex_chr)) != 0) { diff --git a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/upio.c b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/upio.c index b0011c3..ec29649 100755 --- a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/upio.c +++ b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/upio.c @@ -172,7 +172,7 @@ static int init_rfkill() break; } } - + asprintf(&rfkill_state_path, "/sys/class/rfkill/rfkill%d/state", rfkill_id); return 0; } diff --git a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/userial_vendor.c b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/userial_vendor.c index 5ef8880..a6259b5 100755 --- a/bluetooth/realtek/rtkbt/code/libbt-vendor/src/userial_vendor.c +++ b/bluetooth/realtek/rtkbt/code/libbt-vendor/src/userial_vendor.c @@ -89,6 +89,7 @@ typedef struct { int fd; /* fd to Bluetooth device */ int uart_fd[2]; + int signal_fd[2]; int epoll_fd; int cpoll_fd; int event_fd; @@ -439,14 +440,25 @@ static void userial_socket_close(void) if (epoll_ctl(vnd_userial.epoll_fd, EPOLL_CTL_DEL, vnd_userial.uart_fd[1], NULL) == -1) ALOGE("%s unable to unregister fd %d from epoll set: %s", __func__, vnd_userial.uart_fd[1], strerror(errno)); + if (epoll_ctl(vnd_userial.epoll_fd, EPOLL_CTL_DEL, vnd_userial.signal_fd[1], NULL) == -1) + ALOGE("%s unable to unregister signal fd %d from epoll set: %s", __func__, vnd_userial.signal_fd[1], strerror(errno)); + if ((result = close(vnd_userial.uart_fd[1])) < 0) ALOGE( "%s (fd:%d) FAILED result:%d", __func__, vnd_userial.uart_fd[1], result); pthread_join(vnd_userial.thread_socket_id, NULL); close(vnd_userial.epoll_fd); + + if ((result = close(vnd_userial.signal_fd[0])) < 0) + ALOGE( "%s (signal fd[0]:%d) FAILED result:%d", __func__, vnd_userial.signal_fd[0], result); + if ((result = close(vnd_userial.signal_fd[1])) < 0) + ALOGE( "%s (signal fd[1]:%d) FAILED result:%d", __func__, vnd_userial.signal_fd[1], result); + vnd_userial.epoll_fd = -1; vnd_userial.uart_fd[0] = -1; vnd_userial.uart_fd[1] = -1; + vnd_userial.signal_fd[0] = -1; + vnd_userial.signal_fd[1] = -1; } static void userial_uart_close(void) @@ -462,7 +474,10 @@ static void userial_coex_close(void) int result; if (epoll_ctl(vnd_userial.cpoll_fd, EPOLL_CTL_DEL, vnd_userial.event_fd, NULL) == -1) - ALOGE("%s unable to unregister fd %d from epoll set: %s", __func__, vnd_userial.event_fd, strerror(errno)); + ALOGE("%s unable to unregister fd %d from cpoll set: %s", __func__, vnd_userial.event_fd, strerror(errno)); + + if (epoll_ctl(vnd_userial.cpoll_fd, EPOLL_CTL_DEL, vnd_userial.signal_fd[1], NULL) == -1) + ALOGE("%s unable to unregister fd %d from cpoll set: %s", __func__, vnd_userial.signal_fd[1], strerror(errno)); if ((result = close(vnd_userial.event_fd)) < 0) ALOGE( "%s (fd:%d) FAILED result:%d", __func__, vnd_userial.event_fd, result); @@ -473,6 +488,12 @@ static void userial_coex_close(void) vnd_userial.event_fd = -1; } +void userial_send_close_signal(void) +{ + unsigned char close_signal = 1; + ssize_t ret; + RTK_NO_INTR(ret = write(vnd_userial.signal_fd[0], &close_signal, 1)); +} /******************************************************************************* ** @@ -498,13 +519,13 @@ void userial_vendor_close(void) } vnd_userial.thread_running = false; - Heartbeat_cleanup(); RTK_btservice_destroyed(); - userial_socket_close(); + userial_send_close_signal(); userial_uart_close(); userial_coex_close(); + userial_socket_close(); if((rtkbt_transtype & RTKBT_TRANS_UART) && (rtkbt_transtype & RTKBT_TRANS_H5)) { h5_int_interface->h5_int_cleanup(); @@ -1050,7 +1071,7 @@ static void* userial_send_sco_thread(void *arg) continue; */ for(i = 0; i < 4; i++) { - if(sbc_encode(&sco_cb.sbc_enc, &pcm_data[240*i], 240, &enc_data[i*60 +2], 58, &writen) <= 0) { + if(sbc_encode(&sco_cb.sbc_enc, &pcm_data[240*i], 240, &enc_data[i*60 +2], 58, (ssize_t *)&writen) <= 0) { ALOGE("sbc encode error!"); } else { @@ -1267,15 +1288,6 @@ static void userial_handle_cmd(unsigned char * recv_buffer, int total_length) } break; - case HCI_LE_SET_EXTENDED_SCAN_PARAMETERS: - scan_int = *(uint16_t*)&recv_buffer[7]; - scan_win = *(uint16_t*)&recv_buffer[9]; - //if(scan_win > 20){ - // *(uint16_t*)&recv_buffer[4] = (scan_int * 20) / scan_win; - // *(uint16_t*)&recv_buffer[6] = 20; - //} - break; - case HCI_WRITE_VOICE_SETTINGS : voice_settings = *(uint16_t*)&recv_buffer[3]; @@ -1716,6 +1728,7 @@ static int userial_handle_recv_data(unsigned char * recv_buffer, int total_lengt case RTKBT_PACKET_CONTENT: if(recv_packet_current_type == DATA_TYPE_EVENT) { event = received_resvered_header[0]; + if(event == HCI_COMMAND_COMPLETE_EVT) { if(received_resvered_length == 2) { if(length >= 1) { @@ -1909,6 +1922,7 @@ static void* userial_recv_socket_thread(void *arg) do{ ret = epoll_wait(vnd_userial.epoll_fd, events, 32, 500); }while(vnd_userial.thread_running && ret == -1 && errno == EINTR); + if (ret == -1) { ALOGE("%s error in epoll_wait: %s", __func__, strerror(errno)); } @@ -1931,18 +1945,26 @@ static void* userial_recv_socket_thread(void *arg) static void* userial_recv_uart_thread(void *arg) { RTK_UNUSED(arg); - struct pollfd pfd; - pfd.events = POLLIN|POLLHUP|POLLERR|POLLRDHUP; - pfd.fd = vnd_userial.fd; + struct pollfd pfd[2]; + pfd[0].events = POLLIN|POLLHUP|POLLERR|POLLRDHUP; + pfd[0].fd = vnd_userial.signal_fd[1]; + pfd[1].events = POLLIN|POLLHUP|POLLERR|POLLRDHUP; + pfd[1].fd = vnd_userial.fd; int ret; unsigned char read_buffer[2056] = {0}; ssize_t bytes_read; while(vnd_userial.thread_running) { do{ - ret = poll(&pfd, 1, 50); + ret = poll(pfd, 2, 500); }while(ret == -1 && errno == EINTR && vnd_userial.thread_running); - if (pfd.revents & POLLIN) { + //exit signal is always at first index + if(pfd[0].revents && !vnd_userial.thread_running) { + ALOGE("receive exit signal and stop thread "); + return NULL; + } + + if (pfd[1].revents & POLLIN) { RTK_NO_INTR(bytes_read = read(vnd_userial.fd, read_buffer, sizeof(read_buffer))); if(!bytes_read) continue; @@ -1955,7 +1977,7 @@ static void* userial_recv_uart_thread(void *arg) } } - if (pfd.revents & (POLLERR|POLLHUP)) { + if (pfd[1].revents & (POLLERR|POLLHUP)) { ALOGE("%s poll error, fd : %d", __func__, vnd_userial.fd); vnd_userial.btdriver_state = false; close(vnd_userial.fd); @@ -2009,6 +2031,11 @@ int userial_socket_open() return ret; } + if((ret = socketpair(AF_UNIX, SOCK_STREAM, 0, vnd_userial.signal_fd)) < 0) { + ALOGE("%s, errno : %s", __func__, strerror(errno)); + return ret; + } + vnd_userial.epoll_fd = epoll_create(64); if (vnd_userial.epoll_fd == -1) { ALOGE("%s unable to create epoll instance: %s", __func__, strerror(errno)); @@ -2026,6 +2053,12 @@ int userial_socket_open() return -1; } + event.data.ptr = NULL; + if (epoll_ctl(vnd_userial.epoll_fd, EPOLL_CTL_ADD, vnd_userial.signal_fd[1], &event) == -1) { + ALOGE("%s unable to register signal fd %d to epoll set: %s", __func__, vnd_userial.signal_fd[1], strerror(errno)); + close(vnd_userial.epoll_fd); + return -1; + } pthread_attr_t thread_attr; pthread_attr_init(&thread_attr); pthread_attr_setdetachstate(&thread_attr, PTHREAD_CREATE_JOINABLE); @@ -2063,12 +2096,19 @@ int userial_socket_open() assert(false); } + event.data.ptr = NULL; + if (epoll_ctl(vnd_userial.cpoll_fd, EPOLL_CTL_ADD, vnd_userial.signal_fd[1], &event) == -1) { + ALOGE("%s unable to register fd %d to cpoll set: %s", __func__, vnd_userial.signal_fd[1], strerror(errno)); + assert(false); + } + if (pthread_create(&vnd_userial.thread_coex_id, &thread_attr, userial_coex_thread, NULL) !=0 ) { ALOGE("pthread create coex : %s", strerror(errno)); assert(false); } } + ret = vnd_userial.uart_fd[0]; return ret; } |