/******************************************************************************* ** ** Function NFA_P2pFlushData ** ** Description This function is called to flush data on connection-oriented ** transport. ** ** Returns NFA_STATUS_OK if successfully initiated ** NFA_STATUS_BAD_HANDLE if handle is not valid ** *******************************************************************************/ tNFA_STATUS NFA_P2pFlushData (tNFA_HANDLE handle, UINT32 *p_length) { tNFA_STATUS ret_status; tNFA_HANDLE xx; P2P_TRACE_API1 ("NFA_P2pFlushData (): handle:0x%X", handle); GKI_sched_lock (); xx = handle & NFA_HANDLE_MASK; xx &= ~NFA_P2P_HANDLE_FLAG_CONN; if ( (!(handle & NFA_P2P_HANDLE_FLAG_CONN)) ||(xx >= LLCP_MAX_DATA_LINK) ||(nfa_p2p_cb.conn_cb[xx].flags == 0) ) { P2P_TRACE_ERROR1 ("NFA_P2pFlushData (): Handle(0x%X) is not valid", handle); ret_status = NFA_STATUS_BAD_HANDLE; } else { *p_length = LLCP_FlushDataLinkRxData (nfa_p2p_cb.conn_cb[xx].local_sap, nfa_p2p_cb.conn_cb[xx].remote_sap); ret_status = NFA_STATUS_OK; } GKI_sched_unlock (); return (ret_status); }
/******************************************************************************* ** ** Function NFA_P2pFlushUI ** ** Description This function is called to flush data on connectionless ** transport. ** ** Returns NFA_STATUS_OK if successfully initiated ** NFA_STATUS_BAD_HANDLE if handle is not valid ** *******************************************************************************/ tNFA_STATUS NFA_P2pFlushUI (tNFA_HANDLE handle, UINT32 *p_length) { tNFA_STATUS ret_status; tNFA_HANDLE xx; P2P_TRACE_API1 ("NFA_P2pReadUI (): handle:0x%X", handle); GKI_sched_lock (); xx = handle & NFA_HANDLE_MASK; if ( (xx >= NFA_P2P_NUM_SAP) ||(nfa_p2p_cb.sap_cb[xx].p_cback == NULL) ) { P2P_TRACE_ERROR1 ("NFA_P2pFlushUI (): Handle (0x%X) is not valid", handle); ret_status = NFA_STATUS_BAD_HANDLE; *p_length = 0; } else { *p_length = LLCP_FlushLogicalLinkRxData ((UINT8)xx); ret_status = NFA_STATUS_OK; } GKI_sched_unlock (); return (ret_status); }
/******************************************************************************* ** ** Function bta_ag_api_disable ** ** Description Handle an API disable event. ** ** ** Returns void ** *******************************************************************************/ static void bta_ag_api_disable(tBTA_AG_DATA *p_data) { /* deregister all scbs in use */ tBTA_AG_SCB *p_scb = &bta_ag_cb.scb[0]; BOOLEAN do_dereg = FALSE; int i; if (!bta_sys_is_register (BTA_ID_AG)) { APPL_TRACE_ERROR0("BTA AG is already disabled, ignoring ..."); return; } /* De-register with BTA system manager */ GKI_sched_lock(); bta_sys_deregister(BTA_ID_AG); GKI_sched_unlock(); for (i = 0; i < BTA_AG_NUM_SCB; i++, p_scb++) { if (p_scb->in_use) { bta_ag_sm_execute(p_scb, BTA_AG_API_DEREGISTER_EVT, p_data); do_dereg = TRUE; } } if (!do_dereg) { /* Done, send callback evt to app */ (*bta_ag_cb.p_cback)(BTA_AG_DISABLE_EVT, NULL); } bta_sys_collision_register (BTA_ID_AG, NULL); }
/******************************************************************************* ** ** Function BTA_HfClientEnable ** ** Description Enable the HF CLient service. When the enable ** operation is complete the callback function will be ** called with a BTA_HF_CLIENT_ENABLE_EVT. This function must ** be called before other function in the HF CLient API are ** called. ** ** Returns BTA_SUCCESS if OK, BTA_FAILURE otherwise. ** *******************************************************************************/ BTA_API tBTA_STATUS BTA_HfClientEnable(tBTA_HF_CLIENT_CBACK *p_cback) { tBTA_HF_CLIENT_API_ENABLE *p_buf; UINT8 idx; if (bta_sys_is_register (BTA_ID_HS)) { APPL_TRACE_ERROR0("BTA HF Client is already enabled, ignoring ..."); return BTA_FAILURE; } /* register with BTA system manager */ GKI_sched_lock(); bta_sys_register(BTA_ID_HS, &bta_hf_client_reg); GKI_sched_unlock(); if ((p_buf = (tBTA_HF_CLIENT_API_ENABLE *) GKI_getbuf(sizeof(tBTA_HF_CLIENT_API_ENABLE))) != NULL) { p_buf->hdr.event = BTA_HF_CLIENT_API_ENABLE_EVT; p_buf->p_cback = p_cback; bta_sys_sendmsg(p_buf); } return BTA_SUCCESS; }
/******************************************************************************* ** ** Function BTA_AgEnable ** ** Description Enable the audio gateway service. When the enable ** operation is complete the callback function will be ** called with a BTA_AG_ENABLE_EVT. This function must ** be called before other function in the AG API are ** called. ** ** Returns BTA_SUCCESS if OK, BTA_FAILURE otherwise. ** *******************************************************************************/ tBTA_STATUS BTA_AgEnable(tBTA_AG_PARSE_MODE parse_mode, tBTA_AG_CBACK *p_cback) { tBTA_AG_API_ENABLE *p_buf; UINT8 idx; /* Error if AG is already enabled, or AG is in the middle of disabling. */ for (idx = 0; idx < BTA_AG_NUM_SCB; idx++) { if (bta_ag_cb.scb[idx].in_use) { APPL_TRACE_ERROR0 ("BTA_AgEnable: FAILED, AG already enabled."); return BTA_FAILURE; } } /* register with BTA system manager */ GKI_sched_lock(); bta_sys_register(BTA_ID_AG, &bta_ag_reg); GKI_sched_unlock(); if ((p_buf = (tBTA_AG_API_ENABLE *) GKI_getbuf(sizeof(tBTA_AG_API_ENABLE))) != NULL) { p_buf->hdr.event = BTA_AG_API_ENABLE_EVT; p_buf->parse_mode = parse_mode; p_buf->p_cback = p_cback; bta_sys_sendmsg(p_buf); } return BTA_SUCCESS; }
/******************************************************************************* ** ** Function BTA_AvEnable ** ** Description Enable the advanced audio/video service. When the enable ** operation is complete the callback function will be ** called with a BTA_AV_ENABLE_EVT. This function must ** be called before other function in the AV API are ** called. ** ** Returns void ** *******************************************************************************/ void BTA_AvEnable(tBTA_SEC sec_mask, tBTA_AV_FEAT features, tBTA_AV_CBACK *p_cback) { tBTA_AV_API_ENABLE *p_buf; /* register with BTA system manager */ GKI_sched_lock(); bta_sys_register(BTA_ID_AV, &bta_av_reg); GKI_sched_unlock(); if ((p_buf = (tBTA_AV_API_ENABLE *) GKI_getbuf(sizeof(tBTA_AV_API_ENABLE))) != NULL) { p_buf->hdr.event = BTA_AV_API_ENABLE_EVT; p_buf->p_cback = p_cback; p_buf->features = features; p_buf->sec_mask = sec_mask; bta_sys_sendmsg(p_buf); } }
/******************************************************************************* ** ** Function BTA_HhEnable ** ** Description Enable the HID host. This function must be called before ** any other functions in the HID host API are called. When the ** enable operation is complete the callback function will be ** called with BTA_HH_ENABLE_EVT. ** ** ** Returns void ** *******************************************************************************/ void BTA_HhEnable(tBTA_SEC sec_mask, tBTA_HH_CBACK *p_cback) { tBTA_HH_API_ENABLE *p_buf; /* register with BTA system manager */ GKI_sched_lock(); bta_sys_register(BTA_ID_HH, &bta_hh_reg); GKI_sched_unlock(); APPL_TRACE_ERROR0("Calling BTA_HhEnable"); p_buf = (tBTA_HH_API_ENABLE *)GKI_getbuf((UINT16)sizeof(tBTA_HH_API_ENABLE)); if (p_buf != NULL) { memset(p_buf, 0, sizeof(tBTA_HH_API_ENABLE)); p_buf->hdr.event = BTA_HH_API_ENABLE_EVT; p_buf->p_cback = p_cback; p_buf->sec_mask = sec_mask; bta_sys_sendmsg(p_buf); } }
/******************************************************************************* ** ** Function NFA_P2pReadUI ** ** Description This function is called to read data on connectionless ** transport when receiving NFA_P2P_DATA_EVT with NFA_P2P_LLINK_TYPE. ** ** - Remote SAP who sent UI PDU is returned. ** - Information of UI PDU up to max_data_len is copied into p_data. ** - If more information of UI PDU or more UI PDU in queue then more ** is returned to TRUE. ** - Information of next UI PDU is not concatenated. ** ** Returns NFA_STATUS_OK if successfully initiated ** NFA_STATUS_BAD_HANDLE if handle is not valid ** *******************************************************************************/ tNFA_STATUS NFA_P2pReadUI (tNFA_HANDLE handle, UINT32 max_data_len, UINT8 *p_remote_sap, UINT32 *p_data_len, UINT8 *p_data, BOOLEAN *p_more) { tNFA_STATUS ret_status; tNFA_HANDLE xx; P2P_TRACE_API1 ("NFA_P2pReadUI (): handle:0x%X", handle); GKI_sched_lock (); xx = handle & NFA_HANDLE_MASK; if ( (xx >= NFA_P2P_NUM_SAP) ||(nfa_p2p_cb.sap_cb[xx].p_cback == NULL) ) { P2P_TRACE_ERROR1 ("NFA_P2pReadUI (): Handle (0x%X) is not valid", handle); ret_status = NFA_STATUS_BAD_HANDLE; } else { *p_more = LLCP_ReadLogicalLinkData ((UINT8)xx, max_data_len, p_remote_sap, p_data_len, p_data); ret_status = NFA_STATUS_OK; } GKI_sched_unlock (); return (ret_status); }
/******************************************************************************* ** ** Function BTA_GATTS_AppRegister ** ** Description This function is called to register application callbacks ** with BTA GATTS module. ** ** Parameters p_app_uuid - applicaiton UUID ** p_cback - pointer to the application callback function. ** ** Returns None ** *******************************************************************************/ void BTA_GATTS_AppRegister(tBT_UUID *p_app_uuid, tBTA_GATTS_CBACK *p_cback) { tBTA_GATTS_API_REG *p_buf; /* register with BTA system manager */ if (bta_sys_is_register(BTA_ID_GATTS) == FALSE) { GKI_sched_lock(); bta_sys_register(BTA_ID_GATTS, &bta_gatts_reg); GKI_sched_unlock(); } if ((p_buf = (tBTA_GATTS_API_REG *) GKI_getbuf(sizeof(tBTA_GATTS_API_REG))) != NULL) { p_buf->hdr.event = BTA_GATTS_API_REG_EVT; if (p_app_uuid != NULL) memcpy(&p_buf->app_uuid, p_app_uuid, sizeof(tBT_UUID)); p_buf->p_cback = p_cback; bta_sys_sendmsg(p_buf); } return; }
/******************************************************************************* ** ** Function NFA_P2pSendData ** ** Description This function is called to send data on connection-oriented ** transport. ** ** Returns NFA_STATUS_OK if successfully initiated ** NFA_STATUS_BAD_HANDLE if handle is not valid ** NFA_STATUS_BAD_LENGTH if data length is more than remote MIU ** NFA_STATUS_CONGESTED if congested ** NFA_STATUS_FAILED otherwise ** *******************************************************************************/ tNFA_STATUS NFA_P2pSendData (tNFA_HANDLE handle, UINT16 length, UINT8 *p_data) { tNFA_P2P_API_SEND_DATA *p_msg; tNFA_STATUS ret_status = NFA_STATUS_FAILED; tNFA_HANDLE xx; P2P_TRACE_API2 ("NFA_P2pSendData (): handle:0x%X, length:%d", handle, length); GKI_sched_lock (); xx = handle & NFA_HANDLE_MASK; xx &= ~NFA_P2P_HANDLE_FLAG_CONN; if ( (!(handle & NFA_P2P_HANDLE_FLAG_CONN)) ||(xx >= LLCP_MAX_DATA_LINK) ||(nfa_p2p_cb.conn_cb[xx].flags == 0) ) { P2P_TRACE_ERROR1 ("NFA_P2pSendData (): Handle(0x%X) is not valid", handle); ret_status = NFA_STATUS_BAD_HANDLE; } else if (nfa_p2p_cb.conn_cb[xx].flags & NFA_P2P_CONN_FLAG_REMOTE_RW_ZERO) { P2P_TRACE_ERROR1 ("NFA_P2pSendData (): handle:0x%X, Remote set RW to 0 (flow off)", handle); ret_status = NFA_STATUS_FAILED; } else if (nfa_p2p_cb.conn_cb[xx].remote_miu < length) { P2P_TRACE_ERROR2 ("NFA_P2pSendData (): handle:0x%X, Data more than remote MIU(%d)", handle, nfa_p2p_cb.conn_cb[xx].remote_miu); ret_status = NFA_STATUS_BAD_LENGTH; } else if (nfa_p2p_cb.conn_cb[xx].flags & NFA_P2P_CONN_FLAG_CONGESTED) { P2P_TRACE_WARNING1 ("NFA_P2pSendData (): handle:0x%X, data link connection is already congested", handle); ret_status = NFA_STATUS_CONGESTED; } else if (LLCP_IsDataLinkCongested (nfa_p2p_cb.conn_cb[xx].local_sap, nfa_p2p_cb.conn_cb[xx].remote_sap, nfa_p2p_cb.conn_cb[xx].num_pending_i_pdu, nfa_p2p_cb.total_pending_ui_pdu, nfa_p2p_cb.total_pending_i_pdu)) { nfa_p2p_cb.conn_cb[xx].flags |= NFA_P2P_CONN_FLAG_CONGESTED; P2P_TRACE_WARNING1 ("NFA_P2pSendData (): handle:0x%X, data link connection is congested", handle); ret_status = NFA_STATUS_CONGESTED; } else if ((p_msg = (tNFA_P2P_API_SEND_DATA *) GKI_getbuf (sizeof(tNFA_P2P_API_SEND_DATA))) != NULL) { p_msg->hdr.event = NFA_P2P_API_SEND_DATA_EVT; p_msg->conn_handle = handle; if ((p_msg->p_msg = (BT_HDR *) GKI_getpoolbuf (LLCP_POOL_ID)) != NULL) { p_msg->p_msg->len = length; p_msg->p_msg->offset = LLCP_MIN_OFFSET; memcpy (((UINT8*) (p_msg->p_msg + 1) + p_msg->p_msg->offset), p_data, length); /* increase number of tx I PDU which is not processed by NFA for congestion control */ nfa_p2p_cb.conn_cb[xx].num_pending_i_pdu++; nfa_p2p_cb.total_pending_i_pdu++; nfa_sys_sendmsg (p_msg); ret_status = NFA_STATUS_OK; } else { GKI_freebuf (p_msg); nfa_p2p_cb.conn_cb[xx].flags |= NFA_P2P_CONN_FLAG_CONGESTED; ret_status = NFA_STATUS_CONGESTED; } } GKI_sched_unlock (); return (ret_status); }
/******************************************************************************* ** ** Function NFA_P2pSendUI ** ** Description This function is called to send data on connectionless ** transport. ** ** Returns NFA_STATUS_OK if successfully initiated ** NFA_STATUS_BAD_HANDLE if handle is not valid ** NFA_STATUS_BAD_LENGTH if data length is more than remote link MIU ** NFA_STATUS_CONGESTED if congested ** NFA_STATUS_FAILED otherwise ** *******************************************************************************/ tNFA_STATUS NFA_P2pSendUI (tNFA_HANDLE handle, UINT8 dsap, UINT16 length, UINT8 *p_data) { tNFA_P2P_API_SEND_UI *p_msg; tNFA_STATUS ret_status = NFA_STATUS_FAILED; tNFA_HANDLE xx; P2P_TRACE_API3 ("NFA_P2pSendUI (): handle:0x%X, DSAP:0x%02X, length:%d", handle, dsap, length); GKI_sched_lock (); xx = handle & NFA_HANDLE_MASK; if ( (xx >= NFA_P2P_NUM_SAP) ||(nfa_p2p_cb.sap_cb[xx].p_cback == NULL)) { P2P_TRACE_ERROR1 ("NFA_P2pSendUI (): Handle (0x%X) is not valid", handle); ret_status = NFA_STATUS_BAD_HANDLE; } else if (length > nfa_p2p_cb.remote_link_miu) { P2P_TRACE_ERROR3 ("NFA_P2pSendUI (): handle:0x%X, length(%d) must be less than remote link MIU(%d)", handle, length, nfa_p2p_cb.remote_link_miu); ret_status = NFA_STATUS_BAD_LENGTH; } else if (nfa_p2p_cb.sap_cb[xx].flags & NFA_P2P_SAP_FLAG_LLINK_CONGESTED) { P2P_TRACE_WARNING1 ("NFA_P2pSendUI (): handle:0x%X, logical data link is already congested", handle); ret_status = NFA_STATUS_CONGESTED; } else if (LLCP_IsLogicalLinkCongested ((UINT8)xx, nfa_p2p_cb.sap_cb[xx].num_pending_ui_pdu, nfa_p2p_cb.total_pending_ui_pdu, nfa_p2p_cb.total_pending_i_pdu)) { nfa_p2p_cb.sap_cb[xx].flags |= NFA_P2P_SAP_FLAG_LLINK_CONGESTED; P2P_TRACE_WARNING1 ("NFA_P2pSendUI(): handle:0x%X, logical data link is congested", handle); ret_status = NFA_STATUS_CONGESTED; } else if ((p_msg = (tNFA_P2P_API_SEND_UI *) GKI_getbuf (sizeof(tNFA_P2P_API_SEND_UI))) != NULL) { p_msg->hdr.event = NFA_P2P_API_SEND_UI_EVT; p_msg->handle = handle; p_msg->dsap = dsap; if ((p_msg->p_msg = (BT_HDR *) GKI_getpoolbuf (LLCP_POOL_ID)) != NULL) { p_msg->p_msg->len = length; p_msg->p_msg->offset = LLCP_MIN_OFFSET; memcpy (((UINT8*) (p_msg->p_msg + 1) + p_msg->p_msg->offset), p_data, length); /* increase number of tx UI PDU which is not processed by NFA for congestion control */ nfa_p2p_cb.sap_cb[xx].num_pending_ui_pdu++; nfa_p2p_cb.total_pending_ui_pdu++; nfa_sys_sendmsg (p_msg); ret_status = NFA_STATUS_OK; } else { GKI_freebuf (p_msg); nfa_p2p_cb.sap_cb[xx].flags |= NFA_P2P_SAP_FLAG_LLINK_CONGESTED; ret_status = NFA_STATUS_CONGESTED; } } GKI_sched_unlock (); return (ret_status); }