static BOOLEAN send_app_connect_signal(int fd, const bt_bdaddr_t* addr, int channel, int status, int send_fd) { /* typedef struct { short size; bt_bdaddr_t bd_addr; int channel; int status; } __attribute__((packed)) sock_connect_signal_t; */ sock_connect_signal_t cs; cs.size = sizeof(cs); cs.bd_addr = *addr; cs.channel = channel; cs.status = status; if(send_fd != -1) { if(sock_send_fd(fd, (const uint8_t*)&cs, sizeof(cs), send_fd) == sizeof(cs)) return TRUE; else APPL_TRACE_ERROR2("sock_send_fd failed, fd:%d, send_fd:%d", fd, send_fd); } else if(sock_send_all(fd, (const uint8_t*)&cs, sizeof(cs)) == sizeof(cs)) { return TRUE; } return FALSE; }
static inline void set_poll(poll_slot_t* ps, int fd, int type, int flags, uint32_t user_id) { ps->pfd.fd = fd; ps->user_id = user_id; if(ps->type != 0 && ps->type != type) APPL_TRACE_ERROR2("poll socket type should not changed! type was:%d, type now:%d", ps->type, type); ps->type = type; ps->flags = flags; ps->pfd.events = flags2pevents(flags); ps->pfd.revents = 0; }
static void *rfcomm_cback(tBTA_JV_EVT event, tBTA_JV *p_data, void *user_data) { int rc; void* new_user_data = NULL; APPL_TRACE_DEBUG1("event=%s", jv_evt[event]); switch (event) { case BTA_JV_RFCOMM_START_EVT: on_srv_rfc_listen_started(&p_data->rfc_start, (uint32_t)user_data); break; case BTA_JV_RFCOMM_CL_INIT_EVT: on_cl_rfc_init(&p_data->rfc_cl_init, (uint32_t)user_data); break; case BTA_JV_RFCOMM_OPEN_EVT: BTA_JvSetPmProfile(p_data->rfc_open.handle,BTA_JV_PM_ID_1,BTA_JV_CONN_OPEN); on_cli_rfc_connect(&p_data->rfc_open, (uint32_t)user_data); break; case BTA_JV_RFCOMM_SRV_OPEN_EVT: BTA_JvSetPmProfile(p_data->rfc_srv_open.handle,BTA_JV_PM_ALL,BTA_JV_CONN_OPEN); new_user_data = (void*)on_srv_rfc_connect(&p_data->rfc_srv_open, (uint32_t)user_data); break; case BTA_JV_RFCOMM_CLOSE_EVT: APPL_TRACE_DEBUG1("BTA_JV_RFCOMM_CLOSE_EVT: user_data:%d", (uint32_t)user_data); on_rfc_close(&p_data->rfc_close, (uint32_t)user_data); break; case BTA_JV_RFCOMM_READ_EVT: APPL_TRACE_DEBUG0("BTA_JV_RFCOMM_READ_EVT not used"); break; case BTA_JV_RFCOMM_WRITE_EVT: on_rfc_write_done(&p_data->rfc_write, (uint32_t)user_data); break; case BTA_JV_RFCOMM_DATA_IND_EVT: APPL_TRACE_DEBUG0("BTA_JV_RFCOMM_DATA_IND_EVT not used"); break; case BTA_JV_RFCOMM_CONG_EVT: //on_rfc_cong(&p_data->rfc_cong); on_rfc_outgoing_congest(&p_data->rfc_cong, (uint32_t)user_data); break; default: APPL_TRACE_ERROR2("unhandled event %d, slot id:%d", event, (uint32_t)user_data); break; } return new_user_data; }
/******************************************************************************* ** ** Function preload_wait_timeout ** ** Description Timeout thread of preload watchdog timer ** ** Returns None ** *******************************************************************************/ static void preload_wait_timeout(union sigval arg) { APPL_TRACE_ERROR2("...preload_wait_timeout (retried:%d/max-retry:%d)...", preload_retry_cb.retry_counts, PRELOAD_MAX_RETRY_ATTEMPTS); if (preload_retry_cb.retry_counts++ < PRELOAD_MAX_RETRY_ATTEMPTS) { bte_hci_disable(); GKI_delay(100); bte_hci_enable(); } else { /* Notify BTIF_TASK that the init procedure had failed*/ GKI_send_event(BTIF_TASK, BT_EVT_HARDWARE_INIT_FAIL); } }
static void *sock_poll_thread(void *arg) { struct pollfd pfds[MAX_POLL]; memset(pfds, 0, sizeof(pfds)); int h = (int)arg; for(;;) { prepare_poll_fds(h, pfds); int ret = poll(pfds, ts[h].poll_count, -1); if(ret == -1) { APPL_TRACE_ERROR2("poll ret -1, exit the thread, errno:%d, err:%s", errno, strerror(errno)); break; } if(ret != 0) { int need_process_data_fd = TRUE; if(pfds[0].revents) //cmd fd always is the first one { asrt(pfds[0].fd == ts[h].cmd_fdr); if(!process_cmd_sock(h)) { APPL_TRACE_DEBUG1("h:%d, process_cmd_sock return false, exit...", h); break; } if(ret == 1) need_process_data_fd = FALSE; else ret--; //exclude the cmd fd } if(need_process_data_fd) process_data_sock(h, pfds, ret); } else {APPL_TRACE_DEBUG1("no data, select ret: %d", ret)}; } ts[h].thread_id = -1; APPL_TRACE_DEBUG1("socket poll thread exiting, h:%d", h); return 0; }
int bta_ma_co_open(const char *p_path, int oflags) { struct stat file_stat; int fd; /* Convert BTA oflags into MFS */ oflags = bta_fs_convert_bta_oflags(oflags); if ((fd = open (p_path, oflags | O_NONBLOCK, 0666)) < 0) { APPL_TRACE_ERROR2("%s: Error opening file: error code %d", __FUNCTION__, fd); return BTA_FS_INVALID_FD; } else { if(fstat(fd, &file_stat) == 0) { if (oflags & O_CREAT) { fchown(fd, BT_UID, BT_GID); APPL_TRACE_DEBUG0("\n ******CHANGED OWNERSHIP SUCCESSFULLY**********"); } } return fd; } }
/******************************************************************************* ** ** Function bta_av_co_audio_delay ** ** Description This function is called by AV when the audio stream connection ** needs to send the initial delay report to the connected SRC. ** ** ** Returns void ** *******************************************************************************/ void bta_av_co_audio_delay(tBTA_AV_HNDL hndl, UINT16 delay) { FUNC_TRACE(); APPL_TRACE_ERROR2("bta_av_co_audio_delay handle: x%x, delay:0x%x", hndl, delay); }
/******************************************************************************* ** ** Function bta_hh_sm_execute ** ** Description State machine event handling function for HID Host ** ** ** Returns void ** *******************************************************************************/ void bta_hh_sm_execute(tBTA_HH_DEV_CB *p_cb, UINT16 event, tBTA_HH_DATA * p_data) { tBTA_HH_ST_TBL state_table; UINT8 action; tBTA_HH cback_data; tBTA_HH_EVT cback_event = 0; #if BTA_HH_DEBUG == TRUE tBTA_HH_STATE in_state ; UINT16 debug_event = event; #endif memset(&cback_data, 0, sizeof(tBTA_HH)); /* handle exception, no valid control block was found */ if (!p_cb) { /* BTA HH enabled already? otherwise ignore the event although it's bad*/ if (bta_hh_cb.p_cback != NULL) { switch (event) { /* no control block available for new connection */ case BTA_HH_API_OPEN_EVT: cback_event = BTA_HH_OPEN_EVT; /* build cback data */ bdcpy(cback_data.conn.bda, ((tBTA_HH_API_CONN *)p_data)->bd_addr); cback_data.conn.status = BTA_HH_ERR_DB_FULL; cback_data.conn.handle = BTA_HH_INVALID_HANDLE; break; /* DB full, BTA_HhAddDev */ case BTA_HH_API_MAINT_DEV_EVT: cback_event = p_data->api_maintdev.sub_event; if (p_data->api_maintdev.sub_event == BTA_HH_ADD_DEV_EVT) { bdcpy(cback_data.dev_info.bda, p_data->api_maintdev.bda); cback_data.dev_info.status = BTA_HH_ERR_DB_FULL; cback_data.dev_info.handle = BTA_HH_INVALID_HANDLE; } else { cback_data.dev_info.status = BTA_HH_ERR_HDL; cback_data.dev_info.handle = (UINT8)p_data->api_maintdev.hdr.layer_specific; } break; case BTA_HH_API_WRITE_DEV_EVT: cback_event = (p_data->api_sndcmd.t_type - BTA_HH_FST_BTE_TRANS_EVT) + BTA_HH_FST_TRANS_CB_EVT; if (p_data->api_sndcmd.p_data != NULL) { GKI_freebuf(p_data->api_sndcmd.p_data); } if (p_data->api_sndcmd.t_type == HID_TRANS_SET_PROTOCOL || p_data->api_sndcmd.t_type == HID_TRANS_SET_REPORT || p_data->api_sndcmd.t_type == HID_TRANS_SET_IDLE) { cback_data.dev_status.status = BTA_HH_ERR_HDL; cback_data.dev_status.handle = (UINT8)p_data->api_sndcmd.hdr.layer_specific; } else if (p_data->api_sndcmd.t_type != HID_TRANS_DATA && p_data->api_sndcmd.t_type != HID_TRANS_CONTROL) { cback_data.hs_data.handle = (UINT8)p_data->api_sndcmd.hdr.layer_specific; cback_data.hs_data.status = BTA_HH_ERR_HDL; /* hs_data.rsp_data will be all zero, which is not valid value */ } else if (p_data->api_sndcmd.t_type == HID_TRANS_CONTROL && p_data->api_sndcmd.param == BTA_HH_CTRL_VIRTUAL_CABLE_UNPLUG) { cback_data.status = BTA_HH_ERR_HDL; cback_event = BTA_HH_VC_UNPLUG_EVT; } else cback_event = 0; break; case BTA_HH_API_CLOSE_EVT: cback_event = BTA_HH_CLOSE_EVT; cback_data.dev_status.status = BTA_HH_ERR_HDL; cback_data.dev_status.handle = (UINT8)p_data->api_sndcmd.hdr.layer_specific; break; default: /* invalid handle, call bad API event */ APPL_TRACE_ERROR1("wrong device handle: [%d]", p_data->hdr.layer_specific); break; } if (cback_event) (* bta_hh_cb.p_cback)(cback_event, &cback_data); } } /* corresponding CB is found, go to state machine */ else { #if BTA_HH_DEBUG == TRUE in_state = p_cb->state; APPL_TRACE_EVENT3("bta_hh_sm_execute: State 0x%02x [%s], Event [%s]", in_state, bta_hh_state_code(in_state), bta_hh_evt_code(debug_event)); #endif if ((p_cb->state == BTA_HH_NULL_ST) || (p_cb->state >= BTA_HH_INVALID_ST)) { APPL_TRACE_ERROR2("bta_hh_sm_execute: Invalid state State = 0x%x, Event = %d", p_cb->state,event); return; } state_table = bta_hh_st_tbl[p_cb->state - 1]; event &= 0xff; p_cb->state = state_table[event][BTA_HH_NEXT_STATE] ; if ((action = state_table[event][BTA_HH_ACTION]) != BTA_HH_IGNORE) { (*bta_hh_action[action])(p_cb, p_data); } #if BTA_HH_DEBUG == TRUE if (in_state != p_cb->state) { APPL_TRACE_DEBUG3("HH State Change: [%s] -> [%s] after Event [%s]", bta_hh_state_code(in_state), bta_hh_state_code(p_cb->state), bta_hh_evt_code(debug_event)); } #endif } return; }