static bt_status_t btsock_listen(btsock_type_t type, const char* service_name, const uint8_t* service_uuid, int channel, int* sock_fd, int flags) { if((service_uuid == NULL && channel <= 0) || sock_fd == NULL) { BTIF_TRACE_ERROR3("invalid parameters, uuid:%p, channel:%d, sock_fd:%p", service_uuid, channel, sock_fd); return BT_STATUS_PARM_INVALID; } *sock_fd = -1; bt_status_t status = BT_STATUS_FAIL; switch(type) { case BTSOCK_RFCOMM: status = btsock_rfc_listen(service_name, service_uuid, channel, sock_fd, flags); break; case BTSOCK_L2CAP: BTIF_TRACE_ERROR1("bt l2cap socket type not supported, type:%d", type); status = BT_STATUS_UNSUPPORTED; break; case BTSOCK_SCO: BTIF_TRACE_ERROR1("bt sco socket not supported, type:%d", type); status = BT_STATUS_UNSUPPORTED; break; default: BTIF_TRACE_ERROR1("unknown bt socket type:%d", type); status = BT_STATUS_UNSUPPORTED; break; } return status; }
static bt_status_t btsock_connect(const bt_bdaddr_t *bd_addr, btsock_type_t type, const uint8_t* uuid, int channel, int* sock_fd, int flags) { if((uuid == NULL && channel <= 0) || bd_addr == NULL || sock_fd == NULL) { BTIF_TRACE_ERROR4("invalid parameters, bd_addr:%p, uuid:%p, channel:%d, sock_fd:%p", bd_addr, uuid, channel, sock_fd); return BT_STATUS_PARM_INVALID; } *sock_fd = -1; bt_status_t status = BT_STATUS_FAIL; switch(type) { case BTSOCK_RFCOMM: status = btsock_rfc_connect(bd_addr, uuid, channel, sock_fd, flags); break; case BTSOCK_L2CAP: BTIF_TRACE_ERROR1("bt l2cap socket type not supported, type:%d", type); status = BT_STATUS_UNSUPPORTED; break; case BTSOCK_SCO: BTIF_TRACE_ERROR1("bt sco socket not supported, type:%d", type); status = BT_STATUS_UNSUPPORTED; break; default: BTIF_TRACE_ERROR1("unknown bt socket type:%d", type); status = BT_STATUS_UNSUPPORTED; break; } return status; }
int uinput_create(char *name) { struct uinput_dev dev; int fd, err, x = 0; for(x=0; x < MAX_UINPUT_PATHS; x++) { fd = open(uinput_dev_path[x], O_RDWR); if (fd < 0) continue; break; } if (x == MAX_UINPUT_PATHS) { BTIF_TRACE_ERROR1("%s ERROR: uinput device open failed", __FUNCTION__); return -1; } memset(&dev, 0, sizeof(dev)); if (name) strncpy(dev.name, name, UINPUT_MAX_NAME_SIZE); dev.id.bustype = BUS_BLUETOOTH; dev.id.vendor = 0x0000; dev.id.product = 0x0000; dev.id.version = 0x0000; if (write(fd, &dev, sizeof(dev)) < 0) { BTIF_TRACE_ERROR1("%s Unable to write device information", __FUNCTION__); close(fd); return -1; } ioctl(fd, UI_SET_EVBIT, EV_KEY); ioctl(fd, UI_SET_EVBIT, EV_REL); ioctl(fd, UI_SET_EVBIT, EV_SYN); for (x = 0; key_map[x].name != NULL; x++) ioctl(fd, UI_SET_KEYBIT, key_map[x].mapped_id); for(x = 0; x < KEY_MAX; x++) ioctl(fd, UI_SET_KEYBIT, x); if (ioctl(fd, UI_DEV_CREATE, NULL) < 0) { BTIF_TRACE_ERROR1("%s Unable to create uinput device", __FUNCTION__); close(fd); return -1; } return fd; }
static void btpan_tap_fd_signaled(int fd, int type, int flags, uint32_t user_id) { char packet[MAX_PACKET_SIZE]; tETH_HDR eth_hdr; if(flags & SOCK_THREAD_FD_EXCEPTION) { BTIF_TRACE_ERROR1("pan tap fd:%d exception", fd); } else if(flags & SOCK_THREAD_FD_RD) { /* debug("tab fd read trigged, data"); */ int size = read(fd, packet, MAX_PACKET_SIZE); /* debug("tap fd read trigged, read size:%d", size); */ memcpy(ð_hdr, &packet, sizeof(tETH_HDR)); /* debug("eth src = %02x:%02x:%02x:%02x:%02x:%02x", */ /* eth_hdr.h_src[0], eth_hdr.h_src[1], eth_hdr.h_src[2], eth_hdr.h_src[3], */ /* eth_hdr.h_src[4], eth_hdr.h_src[5]); */ /* debug("eth dest = %02x:%02x:%02x:%02x:%02x:%02x", */ /* eth_hdr.h_dest[0], eth_hdr.h_dest[1], eth_hdr.h_dest[2], eth_hdr.h_dest[3], */ /* eth_hdr.h_dest[4], eth_hdr.h_dest[5]); */ //dump_bin("eth packet received", packet, size); if(should_forward(ð_hdr)) { forward_bnep(ð_hdr, packet + sizeof(tETH_HDR), size - sizeof(tETH_HDR)); } btsock_thread_add_fd(pth, fd, 0, SOCK_THREAD_FD_RD | SOCK_THREAD_ADD_FD_SYNC, 0); } }
/******************************************************************************* ** ** Function bta_hl_co_put_echo_data ** ** Description Put the received loopback echo data ** ** Parameters app_id - HDP application ID ** mcl_handle - MCL handle ** data_size - the size of the data ** p_data - the data pointer ** evt - the evt to be passed back to the HL in the ** bta_hl_ci_put_echo_data call-in function ** ** Returns Void ** *******************************************************************************/ void bta_hl_co_put_echo_data (UINT8 app_id, tBTA_HL_MCL_HANDLE mcl_handle, UINT16 data_size, UINT8 *p_data, UINT16 evt) { tBTA_HL_STATUS status = BTA_HL_STATUS_FAIL; BTIF_TRACE_ERROR1("%s not supported",__FUNCTION__); bta_hl_ci_put_echo_data(mcl_handle, status, evt); }
/************** uinput related functions **************/ int uinput_driver_check() { uint32_t i; for (i=0; i < MAX_UINPUT_PATHS; i++) { if (access(uinput_dev_path[i], O_RDWR) == 0) { return 0; } } BTIF_TRACE_ERROR1("%s ERROR: uinput device is not in the system", __FUNCTION__); return -1; }
void BTM_VendorSpecificCommand(UINT16 opcode, UINT8 param_len, UINT8 *p_param_buf) { void *p_buf; /* Allocate a buffer to hold HCI command plus the callback function */ if ((p_buf = GKI_getbuf((UINT16)(sizeof(BT_HDR) + sizeof (void *) + param_len + HCIC_PREAMBLE_SIZE))) != NULL) { btsnd_hcic_mp_test_cmd (p_buf, opcode, param_len, p_param_buf, (void *)NULL); } else { BTIF_TRACE_ERROR1("%s", __FUNCTION__); } }
int btpan_tap_open() { struct ifreq ifr; int fd, err; const char *clonedev = "/dev/tun"; /* open the clone device */ //system("insmod /system/lib/modules/tun.ko"); if( (fd = open(clonedev, O_RDWR)) < 0 ) { BTIF_TRACE_DEBUG2("could not open %s, err:%d", clonedev, errno); return fd; } memset(&ifr, 0, sizeof(ifr)); ifr.ifr_flags = IFF_TAP | IFF_NO_PI; strncpy(ifr.ifr_name, TAP_IF_NAME, IFNAMSIZ); /* try to create the device */ if( (err = ioctl(fd, TUNSETIFF, (void *) &ifr)) < 0 )//|| tap_setup_ip(TAP_IF_NAME) == FALSE) { BTIF_TRACE_DEBUG2("ioctl error:%d, errno:%s", err, strerror(errno)); close(fd); return err; } BTM_GetLocalDeviceAddr (local_addr); if(tap_if_up(TAP_IF_NAME, local_addr) == 0) { return fd; } BTIF_TRACE_ERROR1("can not bring up tap interface:%s", TAP_IF_NAME); close(fd); return -1; }
static void bta_pan_callback_transfer(UINT16 event, char *p_param) { tBTA_PAN *p_data = (tBTA_PAN *)p_param; switch(event) { case BTA_PAN_ENABLE_EVT: BTIF_TRACE_DEBUG0("BTA_PAN_ENABLE_EVT"); break; case BTA_PAN_SET_ROLE_EVT: { int btpan_role = bta_role_to_btpan(p_data->set_role.role); bt_status_t status = p_data->set_role.status == BTA_PAN_SUCCESS ? BT_STATUS_SUCCESS : BT_STATUS_FAIL; btpan_control_state_t state = btpan_role == 0 ? BTPAN_STATE_DISABLED : BTPAN_STATE_ENABLED; callback.control_state_cb(state, btpan_role, status, TAP_IF_NAME); break; } case BTA_PAN_OPENING_EVT: { btpan_conn_t* conn; bdstr_t bds; bd2str((bt_bdaddr_t*)p_data->opening.bd_addr, &bds); BTIF_TRACE_DEBUG2("BTA_PAN_OPENING_EVT handle %d, addr: %s", p_data->opening.handle, bds); conn = btpan_find_conn_addr(p_data->opening.bd_addr); asrt(conn != NULL); if (conn) { conn->handle = p_data->opening.handle; int btpan_conn_local_role = bta_role_to_btpan(conn->local_role); int btpan_remote_role = bta_role_to_btpan(conn->remote_role); callback.connection_state_cb(BTPAN_STATE_CONNECTING, BT_STATUS_SUCCESS, (const bt_bdaddr_t*)p_data->opening.bd_addr, btpan_conn_local_role, btpan_remote_role); } else BTIF_TRACE_ERROR0("connection not found"); break; } case BTA_PAN_OPEN_EVT: { /* debug("BTA_PAN_OPEN_EVT, open status:%d, bd_addr = [%02X:%02X:%02X:%02X:%02X:%02X]", */ /* p_data->open.status, */ /* p_data->open.bd_addr[0], p_data->open.bd_addr[1], p_data->open.bd_addr[2], */ /* p_data->open.bd_addr[3], p_data->open.bd_addr[4], p_data->open.bd_addr[5]); */ btpan_connection_state_t state; bt_status_t status; btpan_conn_t* conn = btpan_find_conn_handle(p_data->open.handle); ALOGI("%s: event = BTA_PAN_OPEN_EVT p_data->open.status %d", __FUNCTION__, p_data->open.status); if(p_data->open.status == BTA_PAN_SUCCESS) { state = BTPAN_STATE_CONNECTED; status = BT_STATUS_SUCCESS; } else { state = BTPAN_STATE_DISCONNECTED; status = BT_STATUS_FAIL; btpan_cleanup_conn(conn); } /* debug("BTA_PAN_OPEN_EVT handle:%d, conn:%p", p_data->open.handle, conn); */ /* debug("conn bta local_role:%d, bta remote role:%d", conn->local_role, conn->remote_role); */ int btpan_conn_local_role = bta_role_to_btpan(p_data->open.local_role); /* debug("bta local_role:%d, bta remote role:%d", p_data->open.local_role, p_data->open.peer_role); */ int btpan_remote_role = bta_role_to_btpan(p_data->open.peer_role); callback.connection_state_cb(state, status, (const bt_bdaddr_t*)p_data->open.bd_addr, btpan_conn_local_role, btpan_remote_role); break; } case BTA_PAN_CLOSE_EVT: { btpan_conn_t* conn = btpan_find_conn_handle(p_data->close.handle); ALOGI("%s: event = BTA_PAN_CLOSE_EVT handle %d", __FUNCTION__, p_data->close.handle); btpan_close_conn(conn); if(conn && conn->handle >= 0) { /* debug("BTA_PAN_CLOSE_EVT, conn local_role:%d, remote_role:%d", conn->local_role, conn->remote_role); */ int btpan_conn_local_role = bta_role_to_btpan(conn->local_role); int btpan_remote_role = bta_role_to_btpan(conn->remote_role); callback.connection_state_cb(BTPAN_STATE_DISCONNECTED, 0, (const bt_bdaddr_t*)conn->peer, btpan_conn_local_role, btpan_remote_role); btpan_cleanup_conn(conn); } else BTIF_TRACE_ERROR1("pan handle not found (%d)", p_data->close.handle); break; } default: BTIF_TRACE_WARNING1("Unknown pan event %d", event); break; } }
int RTKBT_AUTOPAIR_CheckMSD(UINT8 * p, UINT8 len, UINT32 * p_rcuid, UINT8 * p_classic_supported,bt_bdaddr_t * p_classic_addr) //MSD: Manufacturer Specific Data { UINT32 cmd,vendor,rcu_id,classic_supported; UINT8 val,type,left; left = len; STREAM_TO_UINT16(vendor,p); BTIF_TRACE_ERROR1("AutoPairing:ITEM:vendor %04x\n",vendor); left -= 2; if((vendor == 0x7966)||(vendor == 0x6679)) { *p_rcuid = 2; *p_classic_supported = 0; BTIF_TRACE_ERROR2("AutoPairing: IflyTek Vendor %04x ==> RcuID:%d\n",vendor,*p_rcuid); return 0; } if(vendor == BLUETOOTH_RTK_AUTOPAIR_VENDOR) { if(left<2) return -4; STREAM_TO_UINT16(cmd, p); BTIF_TRACE_ERROR1("AutoPairing:ITEM:cmd %04x\n",cmd); left -= 2; if(cmd == BLUETOOTH_RTK_AUTOPAIR_CMDID) { *p_rcuid = 2; *p_classic_supported = 0; BTIF_TRACE_ERROR2("AutoPairing: IflyTek Vendor %04x ==> RcuID:%d\n",vendor,*p_rcuid); return 0; if(left<1) return -5; STREAM_TO_UINT8(val, p); left--; rcu_id = val<<8; if(left<1) return -6; STREAM_TO_UINT8(val, p); left--; rcu_id |= val; /* if(rcu_id&0x8000) { rcu_id = rcu_id<<8; if(left<1) return -7; STREAM_TO_UINT8(val, p); left--; rcu_id |= val; } */ BTIF_TRACE_ERROR1("AutoPairing:ITEM:rcu_id %08x\n",rcu_id); if(left>=6) { STREAM_TO_BDADDR(p_classic_addr->address, p); BTIF_TRACE_ERROR6("AutoPairing:ITEM:addr %02x:%02x:%02x:%02x:%02x:%02x\n", \ p_classic_addr->address[0], p_classic_addr->address[1], p_classic_addr->address[2], p_classic_addr->address[3], p_classic_addr->address[4], p_classic_addr->address[5]); #ifdef DUMMY_CLASSIC_INQUIRY_RESULT bluetooth_rtk_AutoPair_SendClassicInquiryResults(p_classic_addr); #endif classic_supported = 1; left -= 6; }else{ classic_supported = 0; memset(p_classic_addr, 0 , sizeof(bt_bdaddr_t)); } if(remote_controller_id == rcu_id){ *p_rcuid = rcu_id; } else *p_rcuid = 0; *p_classic_supported = classic_supported; return 0; } } return 0; }
static void btif_task(UINT32 params) { UINT16 event; BT_HDR *p_msg; BTIF_TRACE_DEBUG0("btif task starting"); btif_associate_evt(); for(;;) { /* wait for specified events */ event = GKI_wait(0xFFFF, 0); /* * Wait for the trigger to init chip and stack. This trigger will * be received by btu_task once the UART is opened and ready */ if (event == BT_EVT_TRIGGER_STACK_INIT) { BTIF_TRACE_DEBUG0("btif_task: received trigger stack init event"); btif_enable_bluetooth_evt(BT_STATE_ON); } /* * Failed to initialize controller hardware, reset state and bring * down all threads */ if (event == BT_EVT_HARDWARE_INIT_FAIL) { BTIF_TRACE_DEBUG0("btif_task: hardware init failed"); bte_main_disable(); GKI_task_self_cleanup(BTIF_TASK); bte_main_shutdown(); btif_dut_mode = 0; btif_core_state = BTIF_CORE_STATE_DISABLED; HAL_CBACK(bt_hal_cbacks,adapter_state_changed_cb,BT_STATE_OFF); break; } if (event & EVENT_MASK(GKI_SHUTDOWN_EVT)) break; if(event & TASK_MBOX_1_EVT_MASK) { while((p_msg = GKI_read_mbox(BTU_BTIF_MBOX)) != NULL) { BTIF_TRACE_VERBOSE1("btif task fetched event %x", p_msg->event); switch (p_msg->event) { case BT_EVT_CONTEXT_SWITCH_EVT: btif_context_switched(p_msg); break; case BT_EVT_RX: btif_mp_test_evt(p_msg); break; case BT_EVT_MP_NOTIFY_BTIF: btif_mp_notify_evt(p_msg); break; default: BTIF_TRACE_ERROR1("unhandled btif event (%d)", p_msg->event & BT_EVT_MASK); break; } GKI_freebuf(p_msg); } } } btif_disassociate_evt(); BTIF_TRACE_DEBUG0("btif task exiting"); }
static bt_status_t phone_state_change(int num_active, int num_held, bthf_call_state_t call_setup_state, const char *number, bthf_call_addrtype_t type) { tBTA_AG_RES res = 0xff; tBTA_AG_RES_DATA ag_res; bt_status_t status = BT_STATUS_SUCCESS; BOOLEAN activeCallUpdated = FALSE; CHECK_BTHF_SLC_CONNECTED(); BTIF_TRACE_DEBUG6("phone_state_change: num_active=%d [prev: %d] num_held=%d[prev: %d]"\ " call_setup=%s [prev: %s]", num_active, btif_hf_cb.num_active, num_held, btif_hf_cb.num_held, dump_hf_call_state(call_setup_state), dump_hf_call_state(btif_hf_cb.call_setup_state)); /* if all indicators are 0, send end call and return */ if (num_active == 0 && num_held == 0 && call_setup_state == BTHF_CALL_STATE_IDLE) { BTIF_TRACE_DEBUG1("%s: Phone on hook", __FUNCTION__); /* record call termination timestamp if there was an active/held call or callsetup state > BTHF_CALL_STATE_IDLE */ if ((btif_hf_cb.call_setup_state != BTHF_CALL_STATE_IDLE ) || (btif_hf_cb.num_active) ||(btif_hf_cb.num_held)) { BTIF_TRACE_DEBUG1("%s: Record call termination timestamp", __FUNCTION__); clock_gettime(CLOCK_MONOTONIC, &btif_hf_cb.call_end_timestamp); } BTA_AgResult (BTA_AG_HANDLE_ALL, BTA_AG_END_CALL_RES, NULL); /* if held call was present, reset that as well */ if (btif_hf_cb.num_held) send_indicator_update(BTA_AG_IND_CALLHELD, 0); goto update_call_states; } /* active state can change when: ** 1. an outgoing/incoming call was answered ** 2. an held was resumed ** 3. without callsetup notifications, call became active ** (3) can happen if call is active and a headset connects to us ** ** In the case of (3), we will have to notify the stack of an active ** call, instead of sending an indicator update. This will also ** force the SCO to be setup. Handle this special case here prior to ** call setup handling */ if ( (num_active == 1) && (btif_hf_cb.num_active == 0) && (btif_hf_cb.num_held == 0) && (btif_hf_cb.call_setup_state == BTHF_CALL_STATE_IDLE) ) { BTIF_TRACE_DEBUG1("%s: Active call notification received without call setup update", __FUNCTION__); memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA)); ag_res.audio_handle = btif_hf_cb.handle; res = BTA_AG_OUT_CALL_CONN_RES; BTA_AgResult(BTA_AG_HANDLE_ALL, res, &ag_res); activeCallUpdated = TRUE; } /* Ringing call changed? */ if (call_setup_state != btif_hf_cb.call_setup_state) { BTIF_TRACE_DEBUG3("%s: Call setup states changed. old: %s new: %s", __FUNCTION__, dump_hf_call_state(btif_hf_cb.call_setup_state), dump_hf_call_state(call_setup_state)); memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA)); switch (call_setup_state) { case BTHF_CALL_STATE_IDLE: { switch (btif_hf_cb.call_setup_state) { case BTHF_CALL_STATE_INCOMING: if (num_active > btif_hf_cb.num_active) { res = BTA_AG_IN_CALL_CONN_RES; ag_res.audio_handle = btif_hf_cb.handle; } else if (num_held > btif_hf_cb.num_held) res = BTA_AG_IN_CALL_HELD_RES; else res = BTA_AG_CALL_CANCEL_RES; break; case BTHF_CALL_STATE_DIALING: case BTHF_CALL_STATE_ALERTING: if (num_active > btif_hf_cb.num_active) { ag_res.audio_handle = BTA_AG_HANDLE_SCO_NO_CHANGE; res = BTA_AG_OUT_CALL_CONN_RES; } else res = BTA_AG_CALL_CANCEL_RES; break; default: BTIF_TRACE_ERROR1("%s: Incorrect Call setup state transition", __FUNCTION__); status = BT_STATUS_PARM_INVALID; break; } } break; case BTHF_CALL_STATE_INCOMING: if (num_active || num_held) res = BTA_AG_CALL_WAIT_RES; else res = BTA_AG_IN_CALL_RES; if (number) { int xx = 0; if ((type == BTHF_CALL_ADDRTYPE_INTERNATIONAL) && (*number != '+')) xx = sprintf (ag_res.str, "\"+%s\"", number); else xx = sprintf (ag_res.str, "\"%s\"", number); ag_res.num = type; if (res == BTA_AG_CALL_WAIT_RES) sprintf(&ag_res.str[xx], ",%d", type); } break; case BTHF_CALL_STATE_DIALING: ag_res.audio_handle = btif_hf_cb.handle; res = BTA_AG_OUT_CALL_ORIG_RES; break; case BTHF_CALL_STATE_ALERTING: /* if we went from idle->alert, force SCO setup here. dialing usually triggers it */ if (btif_hf_cb.call_setup_state == BTHF_CALL_STATE_IDLE) ag_res.audio_handle = btif_hf_cb.handle; res = BTA_AG_OUT_CALL_ALERT_RES; break; default: BTIF_TRACE_ERROR1("%s: Incorrect new ringing call state", __FUNCTION__); status = BT_STATUS_PARM_INVALID; break; } BTIF_TRACE_DEBUG3("%s: Call setup state changed. res=%d, audio_handle=%d", __FUNCTION__, res, ag_res.audio_handle); if (res) BTA_AgResult(BTA_AG_HANDLE_ALL, res, &ag_res); /* if call setup is idle, we have already updated call indicator, jump out */ if (call_setup_state == BTHF_CALL_STATE_IDLE) { /* check & update callheld */ if ((num_held > 0) && (num_active > 0)) send_indicator_update(BTA_AG_IND_CALLHELD, 1); goto update_call_states; } } memset(&ag_res, 0, sizeof(tBTA_AG_RES_DATA)); /* per the errata 2043, call=1 implies atleast one call is in progress (active/held) ** https://www.bluetooth.org/errata/errata_view.cfm?errata_id=2043 ** Handle call indicator change **/ if (!activeCallUpdated && ((num_active + num_held) != (btif_hf_cb.num_active + btif_hf_cb.num_held)) ) { BTIF_TRACE_DEBUG3("%s: Active call states changed. old: %d new: %d", __FUNCTION__, btif_hf_cb.num_active, num_active); send_indicator_update(BTA_AG_IND_CALL, ((num_active + num_held) > 0) ? 1 : 0); } /* Held Changed? */ if (num_held != btif_hf_cb.num_held) { BTIF_TRACE_DEBUG3("%s: Held call states changed. old: %d new: %d", __FUNCTION__, btif_hf_cb.num_held, num_held); send_indicator_update(BTA_AG_IND_CALLHELD, ((num_held == 0) ? 0 : ((num_active == 0) ? 2 : 1))); } /* Calls Swapped? */ if ( (call_setup_state == btif_hf_cb.call_setup_state) && (num_active && num_held) && (num_active == btif_hf_cb.num_active) && (num_held == btif_hf_cb.num_held) ) { BTIF_TRACE_DEBUG1("%s: Calls swapped", __FUNCTION__); send_indicator_update(BTA_AG_IND_CALLHELD, 1); } update_call_states: btif_hf_cb.num_active = num_active; btif_hf_cb.num_held = num_held; btif_hf_cb.call_setup_state = call_setup_state; return status; }