static void btif_in_pan_generic_evt(UINT16 event, char *p_param) { BTIF_TRACE_EVENT2("%s: event=%d", __FUNCTION__, event); switch (event) { case BTIF_PAN_CB_DISCONNECTING: { bt_bdaddr_t *bd_addr = (bt_bdaddr_t*)p_param; btpan_conn_t* conn = btpan_find_conn_addr(bd_addr->address); int btpan_conn_local_role; int btpan_remote_role; asrt(conn != NULL); if (conn) { btpan_conn_local_role = bta_role_to_btpan(conn->local_role); btpan_remote_role = bta_role_to_btpan(conn->remote_role); callback.connection_state_cb(BTPAN_STATE_DISCONNECTING, BT_STATUS_SUCCESS, (const bt_bdaddr_t*)conn->peer, btpan_conn_local_role, btpan_remote_role); } } break; default: { BTIF_TRACE_WARNING2("%s : Unknown event 0x%x", __FUNCTION__, event); } break; } }
/******************************************************************************* ** ** Function btif_in_hf_generic_evt ** ** Description Processes generic events to be sent to JNI that are not triggered from the BTA. ** Always runs in BTIF context ** ** Returns void ** *******************************************************************************/ static void btif_in_hf_generic_evt(UINT16 event, char *p_param) { BTIF_TRACE_EVENT2("%s: event=%d", __FUNCTION__, event); switch (event) { case BTIF_HFP_CB_AUDIO_CONNECTING: { HAL_CBACK(bt_hf_callbacks, audio_state_cb, BTHF_AUDIO_STATE_CONNECTING, &btif_hf_cb.connected_bda); } break; default: { BTIF_TRACE_WARNING2("%s : Unknown event 0x%x", __FUNCTION__, event); } break; } }
/*************************************************************************** * Function send_metamsg_rsp * * - Argument: * rc_handle RC handle corresponding to the connected RC * label Label of the RC response * code Response type * pmetamsg_resp Vendor response * * - Description: Remote control metamsg response handler (AVRCP 1.3) * ***************************************************************************/ static void send_metamsg_rsp (UINT8 rc_handle, UINT8 label, tBTA_AV_CODE code, tAVRC_RESPONSE *pmetamsg_resp) { UINT8 ctype; tAVRC_STS status; if (!pmetamsg_resp) { BTIF_TRACE_WARNING1("%s: Invalid response received from application", __FUNCTION__); return; } BTIF_TRACE_EVENT5("+%s: rc_handle: %d, label: %d, code: 0x%02x, pdu: %s", __FUNCTION__, rc_handle, label, code, dump_rc_pdu(pmetamsg_resp->rsp.pdu)); if (pmetamsg_resp->rsp.status != AVRC_STS_NO_ERROR) { ctype = AVRC_RSP_REJ; } else { if ( code < AVRC_RSP_NOT_IMPL) { if (code == AVRC_CMD_NOTIF) { ctype = AVRC_RSP_INTERIM; } else if (code == AVRC_CMD_STATUS) { ctype = AVRC_RSP_IMPL_STBL; } else { ctype = AVRC_RSP_ACCEPT; } } else { ctype = code; } } /* if response is for register_notification, make sure the rc has actually registered for this */ if((pmetamsg_resp->rsp.pdu == AVRC_PDU_REGISTER_NOTIFICATION) && (code == AVRC_RSP_CHANGED)) { BOOLEAN bSent = FALSE; UINT8 event_id = pmetamsg_resp->reg_notif.event_id; BOOLEAN bNotify = (btif_rc_cb.rc_connected) && (btif_rc_cb.rc_notif[event_id-1].bNotify); /* de-register this notification for a CHANGED response */ btif_rc_cb.rc_notif[event_id-1].bNotify = FALSE; BTIF_TRACE_DEBUG4("%s rc_handle: %d. event_id: 0x%02d bNotify:%u", __FUNCTION__, btif_rc_cb.rc_handle, event_id, bNotify); if (bNotify) { BT_HDR *p_msg = NULL; tAVRC_STS status; if (AVRC_STS_NO_ERROR == (status = AVRC_BldResponse(btif_rc_cb.rc_handle, pmetamsg_resp, &p_msg)) ) { BTIF_TRACE_DEBUG3("%s Sending notification to rc_handle: %d. event_id: 0x%02d", __FUNCTION__, btif_rc_cb.rc_handle, event_id); bSent = TRUE; BTA_AvMetaRsp(btif_rc_cb.rc_handle, btif_rc_cb.rc_notif[event_id-1].label, ctype, p_msg); } else { BTIF_TRACE_WARNING2("%s failed to build metamsg response. status: 0x%02x", __FUNCTION__, status); } } if (!bSent) { BTIF_TRACE_DEBUG2("%s: Notification not sent, as there are no RC connections or the \ CT has not subscribed for event_id: %s", __FUNCTION__, dump_rc_notification_event_id(event_id)); }
/*************************************************************************** * Function handle_rc_metamsg_cmd * * - Argument: tBTA_AV_VENDOR Structure containing the received * metamsg command * * - Description: Remote control metamsg command handler (AVRCP 1.3) * ***************************************************************************/ void handle_rc_metamsg_cmd (tBTA_AV_META_MSG *pmeta_msg) { /* Parse the metamsg command and pass it on to BTL-IFS */ UINT8 scratch_buf[512] = {0}; tAVRC_COMMAND avrc_command = {0}; tAVRC_STS status; int param_len; BTIF_TRACE_EVENT1("+ %s", __FUNCTION__); if (pmeta_msg->p_msg->hdr.opcode != AVRC_OP_VENDOR) { BTIF_TRACE_WARNING1("Invalid opcode: %x", pmeta_msg->p_msg->hdr.opcode); return; } if (pmeta_msg->len < 3) { BTIF_TRACE_WARNING2("Invalid length.Opcode: 0x%x, len: 0x%x", pmeta_msg->p_msg->hdr.opcode, pmeta_msg->len); return; } if (pmeta_msg->code >= AVRC_RSP_NOT_IMPL) { BTIF_TRACE_DEBUG3("%s:Received vendor dependent rsp. code: %d len: %d. Not processing it.", __FUNCTION__, pmeta_msg->code, pmeta_msg->len); return; } status = AVRC_ParsCommand(pmeta_msg->p_msg, &avrc_command, scratch_buf, sizeof(scratch_buf)); if (status != AVRC_STS_NO_ERROR) { /* return error */ BTIF_TRACE_WARNING2("%s: Error in parsing received metamsg command. status: 0x%02x", __FUNCTION__, status); send_reject_response(pmeta_msg->rc_handle, pmeta_msg->label, avrc_command.pdu, status); } else { /* if RegisterNotification, add it to our registered queue */ if (avrc_command.cmd.pdu == AVRC_PDU_REGISTER_NOTIFICATION) { UINT8 event_id = avrc_command.reg_notif.event_id; param_len = sizeof(tAVRC_REG_NOTIF_CMD); BTIF_TRACE_EVENT3("%s: New register notification received. event_id:%s, label:0x%x", __FUNCTION__, dump_rc_notification_event_id(event_id), pmeta_msg->label); btif_rc_cb.rc_notif[event_id-1].bNotify = TRUE; btif_rc_cb.rc_notif[event_id-1].label = pmeta_msg->label; if(event_id == AVRC_EVT_UIDS_CHANGE) { handle_uid_changed_notification(pmeta_msg, &avrc_command); return; } } BTIF_TRACE_EVENT2("%s: Passing received metamsg command to app. pdu: %s", __FUNCTION__, dump_rc_pdu(avrc_command.cmd.pdu)); /* Since handle_rc_metamsg_cmd() itself is called from *btif context, no context switching is required. Invoke * btif_rc_upstreams_evt directly from here. */ btif_rc_upstreams_evt((uint16_t)avrc_command.cmd.pdu, &avrc_command, pmeta_msg->code, pmeta_msg->label); } }
/******************************************************************************* ** ** Function btif_hf_upstreams_evt ** ** Description Executes HF UPSTREAMS events in btif context ** ** Returns void ** *******************************************************************************/ static void btif_hf_upstreams_evt(UINT16 event, char* p_param) { tBTA_AG *p_data = (tBTA_AG *)p_param; bdstr_t bdstr; BTIF_TRACE_DEBUG2("%s: event=%s", __FUNCTION__, dump_hf_event(event)); switch (event) { case BTA_AG_ENABLE_EVT: case BTA_AG_DISABLE_EVT: break; case BTA_AG_REGISTER_EVT: btif_hf_cb.handle = p_data->reg.hdr.handle; break; case BTA_AG_OPEN_EVT: if (p_data->open.status == BTA_AG_SUCCESS) { bdcpy(btif_hf_cb.connected_bda.address, p_data->open.bd_addr); btif_hf_cb.state = BTHF_CONNECTION_STATE_CONNECTED; btif_hf_cb.peer_feat = 0; clear_phone_state(); } else if (btif_hf_cb.state == BTHF_CONNECTION_STATE_CONNECTING) { btif_hf_cb.state = BTHF_CONNECTION_STATE_DISCONNECTED; } else { BTIF_TRACE_WARNING4("%s: AG open failed, but another device connected. status=%d state=%d connected device=%s", __FUNCTION__, p_data->open.status, btif_hf_cb.state, bd2str(&btif_hf_cb.connected_bda, &bdstr)); break; } HAL_CBACK(bt_hf_callbacks, connection_state_cb, btif_hf_cb.state, &btif_hf_cb.connected_bda); if (btif_hf_cb.state == BTHF_CONNECTION_STATE_DISCONNECTED) bdsetany(btif_hf_cb.connected_bda.address); if (p_data->open.status != BTA_AG_SUCCESS) btif_queue_advance(); break; case BTA_AG_CLOSE_EVT: btif_hf_cb.state = BTHF_CONNECTION_STATE_DISCONNECTED; HAL_CBACK(bt_hf_callbacks, connection_state_cb, btif_hf_cb.state, &btif_hf_cb.connected_bda); bdsetany(btif_hf_cb.connected_bda.address); btif_hf_cb.peer_feat = 0; clear_phone_state(); /* If AG_OPEN was received but SLC was not setup in a specified time (10 seconds), ** then AG_CLOSE may be received. We need to advance the queue here */ btif_queue_advance(); break; case BTA_AG_CONN_EVT: btif_hf_cb.peer_feat = p_data->conn.peer_feat; btif_hf_cb.state = BTHF_CONNECTION_STATE_SLC_CONNECTED; HAL_CBACK(bt_hf_callbacks, connection_state_cb, btif_hf_cb.state, &btif_hf_cb.connected_bda); btif_queue_advance(); break; case BTA_AG_AUDIO_OPEN_EVT: HAL_CBACK(bt_hf_callbacks, audio_state_cb, BTHF_AUDIO_STATE_CONNECTED, &btif_hf_cb.connected_bda); break; case BTA_AG_AUDIO_CLOSE_EVT: HAL_CBACK(bt_hf_callbacks, audio_state_cb, BTHF_AUDIO_STATE_DISCONNECTED, &btif_hf_cb.connected_bda); break; /* BTA auto-responds, silently discard */ case BTA_AG_SPK_EVT: case BTA_AG_MIC_EVT: HAL_CBACK(bt_hf_callbacks, volume_cmd_cb, (event == BTA_AG_SPK_EVT) ? BTHF_VOLUME_TYPE_SPK : BTHF_VOLUME_TYPE_MIC, p_data->val.num); break; case BTA_AG_AT_A_EVT: HAL_CBACK(bt_hf_callbacks, answer_call_cmd_cb); break; /* Java needs to send OK/ERROR for these commands */ case BTA_AG_AT_BLDN_EVT: case BTA_AG_AT_D_EVT: HAL_CBACK(bt_hf_callbacks, dial_call_cmd_cb, (event == BTA_AG_AT_D_EVT) ? p_data->val.str : NULL); break; case BTA_AG_AT_CHUP_EVT: HAL_CBACK(bt_hf_callbacks, hangup_call_cmd_cb); break; case BTA_AG_AT_CIND_EVT: HAL_CBACK(bt_hf_callbacks, cind_cmd_cb); break; case BTA_AG_AT_VTS_EVT: HAL_CBACK(bt_hf_callbacks, dtmf_cmd_cb, p_data->val.str[0]); break; case BTA_AG_AT_BVRA_EVT: HAL_CBACK(bt_hf_callbacks, vr_cmd_cb, (p_data->val.num == 1) ? BTHF_VR_STATE_STARTED : BTHF_VR_STATE_STOPPED); break; case BTA_AG_AT_NREC_EVT: HAL_CBACK(bt_hf_callbacks, nrec_cmd_cb, (p_data->val.num == 1) ? BTHF_NREC_START : BTHF_NREC_STOP); break; /* TODO: Add a callback for CBC */ case BTA_AG_AT_CBC_EVT: break; case BTA_AG_AT_CKPD_EVT: HAL_CBACK(bt_hf_callbacks, key_pressed_cmd_cb); break; /* Java needs to send OK/ERROR for these commands */ case BTA_AG_AT_CHLD_EVT: HAL_CBACK(bt_hf_callbacks, chld_cmd_cb, atoi(p_data->val.str)); break; case BTA_AG_AT_CLCC_EVT: HAL_CBACK(bt_hf_callbacks, clcc_cmd_cb, p_data->val.num); break; case BTA_AG_AT_COPS_EVT: HAL_CBACK(bt_hf_callbacks, cops_cmd_cb); break; case BTA_AG_AT_UNAT_EVT: HAL_CBACK(bt_hf_callbacks, unknown_at_cmd_cb, p_data->val.str); break; case BTA_AG_AT_CNUM_EVT: HAL_CBACK(bt_hf_callbacks, cnum_cmd_cb); break; /* TODO: Some of these commands may need to be sent to app. For now respond with error */ case BTA_AG_AT_BINP_EVT: case BTA_AG_AT_BTRH_EVT: send_at_result(BTA_AG_OK_ERROR, BTA_AG_ERR_OP_NOT_SUPPORTED); break; default: BTIF_TRACE_WARNING2("%s: Unhandled event: %d", __FUNCTION__, event); break; } }