/******************************************************************************* ** ** Function: nativeNfcTag_abortWaits ** ** Description: Unblock all thread synchronization objects. ** ** Returns: None ** *******************************************************************************/ void nativeNfcTag_abortWaits () { ALOGD ("%s", __FUNCTION__); { SyncEventGuard g (sReadEvent); sReadEvent.notifyOne (); } sem_post (&sWriteSem); sem_post (&sFormatSem); { SyncEventGuard g (sTransceiveEvent); sTransceiveEvent.notifyOne (); } { SyncEventGuard g (sReconnectEvent); sReconnectEvent.notifyOne (); } sem_post (&sCheckNdefSem); { SyncEventGuard guard (sPresenceCheckEvent); sPresenceCheckEvent.notifyOne (); } sem_post (&sMakeReadonlySem); sCurrentRfInterface = NFA_INTERFACE_ISO_DEP; sCurrentConnectedTargetType = TARGET_TYPE_UNKNOWN; }
static void nativeNfcSnep_doPutReceived (tNFA_HANDLE handle, UINT8 *data, UINT32 length) { NXPLOG_API_D ("%s: handle=0x%X, msg length =%d", __FUNCTION__, handle, length); if (!nativeNfcManager_isNfcActive()) { return; } if((sSnepServerConnectionHandle == handle) && NULL != data && 0x00 != length) { if (sServerCallback&& (NULL != sServerCallback->onMessageReceived)) { sServerCallback->onMessageReceived(data, length); } sNfaSnepRespCode = NFA_SNEP_RESP_CODE_SUCCESS; } else { sNfaSnepRespCode = NFA_SNEP_RESP_CODE_REJECT; } { SyncEventGuard guard (sNfaSnepServerPutRspEvent); sNfaSnepServerPutRspEvent.notifyOne (); } }
/******************************************************************************* ** ** Function: nativeNfcTag_doDeactivateStatus ** ** Description: Receive the completion status of deactivate operation. ** ** Returns: None ** *******************************************************************************/ void nativeNfcTag_doDeactivateStatus (int status) { sGotDeactivate = (status == 0); SyncEventGuard g (sReconnectEvent); sReconnectEvent.notifyOne (); }
static void nativeNfcSnep_doPutCompleted (tNFA_STATUS status) { NXPLOG_API_D ("%s: status=0x%X", __FUNCTION__, status); sSnepClientPutState = status; SyncEventGuard g (sNfaSnepClientPutMsgEvent); sNfaSnepClientPutMsgEvent.notifyOne (); }
static void nativeNfcLlcp_doClientReadCompleted (tNFA_STATUS status) { NXPLOG_API_D ("%s: status=0x%X", __FUNCTION__, status); SyncEventGuard g (sNfaLlcpConnLessReadEvent); bClientReadState = TRUE; sNfaLlcpConnLessReadEvent.notifyOne (); }
void nativeNfcSnep_abortClientWaits() { NXPLOG_API_D ("%s", __FUNCTION__); sSnepClientConnectionHandle = 0; { SyncEventGuard g (sNfaSnepClientPutMsgEvent); sNfaSnepClientPutMsgEvent.notifyOne (); } { SyncEventGuard g (sNfaSnepClientConnEvent); sNfaSnepClientConnEvent.notifyOne (); } { SyncEventGuard g (sNfaSnepClientDisconnEvent); sNfaSnepClientDisconnEvent.notifyOne (); } NXPLOG_API_D ("%s exit", __FUNCTION__); }
/******************************************************************************* ** ** Function: nativeNfcTag_doConnectStatus ** ** Description: Receive the completion status of connect operation. ** isConnectOk: Status of the operation. ** ** Returns: None ** *******************************************************************************/ void nativeNfcTag_doConnectStatus (jboolean isConnectOk) { if (sConnectWaitingForComplete != JNI_FALSE) { sConnectWaitingForComplete = JNI_FALSE; sConnectOk = isConnectOk; SyncEventGuard g (sReconnectEvent); sReconnectEvent.notifyOne (); } }
void nativeNfcLlcp_abortClientWaits() { NXPLOG_API_D ("%s", __FUNCTION__); sLlcpConnLessClientHandle = 0; { SyncEventGuard g (sNfaLlcpClientRegEvent); sNfaLlcpClientRegEvent.notifyOne (); } NXPLOG_API_D ("%s exit", __FUNCTION__); }
/******************************************************************************* ** ** Function: nativeNfcTag_abortWaits ** ** Description: Unblock all thread synchronization objects. ** ** Returns: None ** *******************************************************************************/ void nativeNfcSnep_abortServerWaits () { NXPLOG_API_D ("%s", __FUNCTION__); if (sSnepServerState == SNEP_SERVER_STARTED) { SyncEventGuard g (sNfaSnepServerPutRspEvent); sSnepServerState = SNEP_SERVER_IDLE; sSnepServerConnectionHandle = 0; sNfaSnepServerPutRspEvent.notifyOne(); } }
void nativeNfcTag_notifyRfTimeout () { SyncEventGuard g (sTransceiveEvent); ALOGD ("%s: waiting for transceive: %d", __FUNCTION__, sWaitingForTransceive); if (!sWaitingForTransceive) return; sTransceiveRfTimeout = true; sTransceiveEvent.notifyOne (); }
static void nativeNfcLlcp_doServerReadCompleted (tNFA_STATUS status) { NXPLOG_API_D ("%s: status=0x%X", __FUNCTION__, status); if(nativeNfcManager_isNfcActive()) { if(sServerCallback&& (NULL != sServerCallback->onMessageReceived)) { sServerCallback->onMessageReceived(); } } SyncEventGuard g (sNfaLlcpConnLessReadEvent); bServerReadState = TRUE; sNfaLlcpConnLessReadEvent.notifyOne (); }
void RoutingManager::stackCallback (UINT8 event, tNFA_CONN_EVT_DATA* eventData) { static const char fn [] = "RoutingManager::stackCallback"; ALOGD("%s: event=0x%X", fn, event); RoutingManager& routingManager = RoutingManager::getInstance(); switch (event) { case NFA_CE_REGISTERED_EVT: { tNFA_CE_REGISTERED& ce_registered = eventData->ce_registered; ALOGD("%s: NFA_CE_REGISTERED_EVT; status=0x%X; h=0x%X", fn, ce_registered.status, ce_registered.handle); } break; case NFA_CE_DEREGISTERED_EVT: { tNFA_CE_DEREGISTERED& ce_deregistered = eventData->ce_deregistered; ALOGD("%s: NFA_CE_DEREGISTERED_EVT; h=0x%X", fn, ce_deregistered.handle); } break; case NFA_CE_ACTIVATED_EVT: { routingManager.notifyActivated(); } break; case NFA_DEACTIVATED_EVT: case NFA_CE_DEACTIVATED_EVT: { ALOGD("%s: NFA_DEACTIVATED_EVT, NFA_CE_DEACTIVATED_EVT", fn); routingManager.notifyDeactivated(); SyncEventGuard g (gDeactivatedEvent); gActivated = false; //guard this variable from multi-threaded access gDeactivatedEvent.notifyOne (); } break; case NFA_CE_DATA_EVT: { tNFA_CE_DATA& ce_data = eventData->ce_data; ALOGD("%s: NFA_CE_DATA_EVT; stat=0x%X; h=0x%X; data len=%u", fn, ce_data.status, ce_data.handle, ce_data.len); getInstance().handleData(ce_data.p_data, ce_data.len, ce_data.status); } break; } }
/******************************************************************************* ** ** Function: nativeNfcTag_doTransceiveStatus ** ** Description: Receive the completion status of transceive operation. ** status: operation status. ** buf: Contains tag's response. ** bufLen: Length of buffer. ** ** Returns: None ** *******************************************************************************/ void nativeNfcTag_doTransceiveStatus (tNFA_STATUS status, uint8_t* buf, uint32_t bufLen) { SyncEventGuard g (sTransceiveEvent); ALOGD ("%s: data len=%d", __FUNCTION__, bufLen); if (!sWaitingForTransceive) { ALOGE ("%s: drop data", __FUNCTION__); return; } sRxDataStatus = status; if (sRxDataStatus == NFA_STATUS_OK || sRxDataStatus == NFA_STATUS_CONTINUE) sRxDataBuffer.append (buf, bufLen); if (sRxDataStatus == NFA_STATUS_OK) sTransceiveEvent.notifyOne (); }
/******************************************************************************* ** ** Function: nativeNfcTag_doReadCompleted ** ** Description: Receive the completion status of read operation. Called by ** NFA_READ_CPLT_EVT. ** status: Status of operation. ** ** Returns: None ** *******************************************************************************/ void nativeNfcTag_doReadCompleted (tNFA_STATUS status) { ALOGD ("%s: status=0x%X; is reading=%u", __FUNCTION__, status, sIsReadingNdefMessage); if (sIsReadingNdefMessage == false) return; //not reading NDEF message right now, so just return if (status != NFA_STATUS_OK) { sReadDataLen = 0; if (sReadData) free (sReadData); sReadData = NULL; } SyncEventGuard g (sReadEvent); sReadEvent.notifyOne (); }
static void nfaSnepServerCallback (tNFA_SNEP_EVT snepEvent, tNFA_SNEP_EVT_DATA *eventData) { NXPLOG_API_D("%s: Function Entry snepEvent: 0x%X\n",__FUNCTION__, snepEvent); switch (snepEvent) { case NFA_SNEP_REG_EVT: NXPLOG_API_D ("%s: NFA_SNEP_REG_EVT; Status: 0x%04x\n", __FUNCTION__, eventData->reg.status); NXPLOG_API_D ("%s: NFA_SNEP_REG_EVT; Server Register Handle: 0x%04x\n", __FUNCTION__, eventData->reg.reg_handle); sSnepServerHandle = eventData->reg.reg_handle; { SyncEventGuard guard (sNfaSnepServerRegEvent); sNfaSnepServerRegEvent.notifyOne (); } break; case NFA_SNEP_DEFAULT_SERVER_STARTED_EVT: NXPLOG_API_D ("%s: NFA_SNEP_DEFAULT_SERVER_STARTED_EVT\n", __FUNCTION__); break; case NFA_SNEP_DEFAULT_SERVER_STOPPED_EVT: NXPLOG_API_D ("%s: NFA_SNEP_DEFAULT_SERVER_STOPPED_EVT\n", __FUNCTION__); break; case NFA_SNEP_ACTIVATED_EVT: NXPLOG_API_D ("%s: NFA_SNEP_ACTIVATED_EVT: Server Activated\n", __FUNCTION__); break; case NFA_SNEP_DEACTIVATED_EVT: NXPLOG_API_D ("%s: NFA_SNEP_DEACTIVATED_EVT: Server Deactivated\n", __FUNCTION__); break; case NFA_SNEP_CONNECTED_EVT: NXPLOG_API_D ("%s: NFA_SNEP_CONNECTED_EVT: Server Register Handle: 0x%04x\n", __FUNCTION__, eventData->connect.reg_handle); NXPLOG_API_D ("%s: NFA_SNEP_CONNECTED_EVT: Server Connection handle: 0x%04x\n", __FUNCTION__, eventData->connect.conn_handle); if((eventData->connect.reg_handle) && (eventData->connect.conn_handle)) { sSnepServerConnectionHandle = eventData->connect.conn_handle; nativeNfcSnep_notifyServerActivated(); } break; case NFA_SNEP_DISC_EVT: NXPLOG_API_D ("%s: NFA_SNEP_DISC_EVT: Server Connection/Register Handle: 0x%04x\n", __FUNCTION__, eventData->disc.conn_handle); if(sSnepServerConnectionHandle == eventData->disc.conn_handle) { nativeNfcSnep_notifyServerDeactivated(); } break; case NFA_SNEP_PUT_REQ_EVT: NXPLOG_API_D ("%s: NFA_SNEP_PUT_REQ_EVT: Server Connection Handle: 0x%04x\n", __FUNCTION__, eventData->put_req.conn_handle); NXPLOG_API_D ("%s: NFA_SNEP_PUT_REQ_EVT: NDEF Message Length: 0x%04x\n", __FUNCTION__, eventData->put_req.ndef_length); nativeNfcSnep_doPutReceived(eventData->put_req.conn_handle, eventData->put_req.p_ndef, eventData->put_req.ndef_length); break; case NFA_SNEP_ALLOC_BUFF_EVT: NXPLOG_API_D ("%s: NFA_SNEP_ALLOC_BUFF_EVT: Server Connection Handle: 0x%04x\n", __FUNCTION__, eventData->alloc.conn_handle); NXPLOG_API_D ("%s: NFA_SNEP_ALLOC_BUFF_EVT: Request Code: 0x%04x\n", __FUNCTION__, eventData->alloc.req_code); NXPLOG_API_D ("%s: NFA_SNEP_ALLOC_BUFF_EVT: NDEF Message Length: 0x%04x\n", __FUNCTION__, eventData->alloc.ndef_length); NXPLOG_API_D ("%s: NFA_SNEP_ALLOC_BUFF_EVT: Response Code: 0x%04x\n", __FUNCTION__, eventData->alloc.resp_code); if(0x00 != eventData->alloc.ndef_length) { eventData->alloc.p_buff = (UINT8*)malloc(eventData->alloc.ndef_length); if(NULL == eventData->alloc.p_buff) { NXPLOG_API_D("Memory Allocation Failed !!!\n"); } } break; case NFA_SNEP_FREE_BUFF_EVT: NXPLOG_API_D ("%s: NFA_SNEP_FREE_BUFF_EVT: Server Connection Handle: 0x%04x\n",__FUNCTION__, eventData->free.conn_handle); NXPLOG_API_D ("%s: NFA_SNEP_FREE_BUFF_EVT: Buffer to Free: 0x%04x\n",__FUNCTION__, eventData->free.p_buff); if(eventData->free.p_buff) { free(eventData->free.p_buff); eventData->free.p_buff = NULL; } break; default: NXPLOG_API_D ("%s: unknown event 0x%X ?\n", __FUNCTION__, snepEvent); break; } }
/** * LLCP Server callback from middleware */ void nfaLlcpServerCallBack(tNFA_P2P_EVT eP2pEvent,tNFA_P2P_EVT_DATA *psP2pEventData) { NXPLOG_API_D("MwIf>%s:Enter: Event = 0x%x",__FUNCTION__,eP2pEvent); if(psP2pEventData != NULL) { switch (eP2pEvent) { case NFA_P2P_REG_SERVER_EVT: { sLlcpConnLessServerHandle = psP2pEventData->reg_server.server_handle; { SyncEventGuard guard (sNfaLlcpServerRegEvent); sNfaLlcpServerRegEvent.notifyOne (); } } break; case NFA_P2P_ACTIVATED_EVT: { NXPLOG_API_D("nfaLlcpServerCallBack: P2P Activated !! \n"); if((psP2pEventData->activated.handle) && (sLlcpConnLessServerHandle == psP2pEventData->activated.handle)) { sLlcpConnLessHandle = psP2pEventData->activated.handle; sLlcpConnLessConnectedHandle = psP2pEventData->connected.conn_handle; NXPLOG_API_D("nfaLlcpServerCallBack: remote sap ID 0x%04x\n ", bDestSap); nativeNfcLlcp_notifyServerActivated(); } } break; case NFA_P2P_DEACTIVATED_EVT: { NXPLOG_API_D("nfaLlcpServerCallBack P2P Deactivated !! \n"); nativeNfcLlcp_notifyServerDeactivated(); } break; case NFA_P2P_CONNECTED_EVT: { NXPLOG_API_D("nfaLlcpServerCallBack: P2P Connected Event \n "); } break; case NFA_P2P_DISC_EVT: { NXPLOG_API_D("nfaLlcpServerCallBack: P2P Discovery Event \n "); } break; case NFA_P2P_DATA_EVT: { NXPLOG_API_D("nfaLlcpServerCallBack: P2P Data Event "); bDestSap = psP2pEventData->data.remote_sap; sLlcpConnLessHandle = psP2pEventData->data.handle; NXPLOG_API_D("nfaLlcpServerCallBack: remote sap ID 0x%04x\n ", bDestSap); nativeNfcLlcp_doServerReadCompleted(NFA_STATUS_OK); } break; case NFA_P2P_CONGEST_EVT: { NXPLOG_API_D("nfaLlcpServerCallBack: P2P Link Congestion Event \n"); } break; case NFA_P2P_SDP_EVT: bDestSap = psP2pEventData->sdp.remote_sap; sNfaLlcpSdpEvt.notifyOne(); NXPLOG_API_D ("nfaLlcpServerCallBack: 0x%04x\n", bDestSap); break; default: NXPLOG_API_D("P2P Unknown Event"); break; } } NXPLOG_API_D("MwIf>%s:Exit",__FUNCTION__); return; }
static void nfaLlcpClientCallback (tNFA_P2P_EVT LlcpEvent, tNFA_P2P_EVT_DATA *eventData) { NXPLOG_API_D("%s: snepEvent= %u", __FUNCTION__, LlcpEvent); if(eventData != NULL) { switch (LlcpEvent) { case NFA_P2P_REG_CLIENT_EVT: NXPLOG_API_D ("%s: NFA_P2P_REG_CLIENT_EVT; Client Register Handle: 0x%04x\n", __FUNCTION__, eventData->reg_client.client_handle); sLlcpConnLessClientHandle = eventData->reg_client.client_handle; { SyncEventGuard guard (sNfaLlcpClientRegEvent); sNfaLlcpClientRegEvent.notifyOne (); } break; case NFA_P2P_ACTIVATED_EVT: NXPLOG_API_D ("%s: NFA_P2P_ACTIVATED_EVT; Client Activated Handle: 0x%04x\n", __FUNCTION__, eventData->activated.handle); nativeNfcTag_deregisterNdefTypeHandler (); if((eventData->activated.handle) && (sLlcpConnLessClientHandle == eventData->activated.handle)) { bDestSap = LLCP_CL_SAP_ID_DEFAULT; sLlcpConnLessHandle = eventData->activated.handle; sLlcpConnLessConnectedHandle = eventData->connected.conn_handle; NXPLOG_API_D("nfaLlcpServerCallBack: remote sap ID 0x%04x\n ", bDestSap); nativeNfcLlcp_notifyClientActivated(); } break; case NFA_P2P_DEACTIVATED_EVT: NXPLOG_API_D ("%s: NFA_P2P_DEACTIVATED_EVT: Client Deactivated Handle: 0x%04x\n", __FUNCTION__, eventData->deactivated.handle); if((eventData->deactivated.handle) && (sLlcpConnLessClientHandle == eventData->deactivated.handle)) { nativeNfcLlcp_notifyClientDeactivated(); } nativeNfcLlcp_abortClientWaits(); nativeNfcTag_registerNdefTypeHandler(); break; case NFA_P2P_DISC_EVT: NXPLOG_API_D ("%s: NFA_SNEP_DISC_EVT: Client Connection/Register Handle: 0x%04x\n", __FUNCTION__, eventData->disc.handle); { nativeNfcLlcp_abortClientWaits(); } break; case NFA_P2P_DATA_EVT: NXPLOG_API_D ("%s: NFA_P2P_DATA_EVT: Handle: 0x%04x Remote SAP: 0x%04x\n", __FUNCTION__, eventData->data.handle, eventData->data.remote_sap); bDestSap = eventData->data.remote_sap; sLlcpConnLessHandle = eventData->data.handle; NXPLOG_API_D("nfaLlcpServerCallBack: remote sap ID 0x%04x\n ", bDestSap); /* Chekthe Data event */ nativeNfcLlcp_doClientReadCompleted(NFA_STATUS_OK); break; case NFA_P2P_CONGEST_EVT: NXPLOG_API_D ("%s: NFA_SNEP_ALLOC_BUFF_EVT: Handle: 0x%04x\n", __FUNCTION__, eventData->congest.handle); break; case NFA_P2P_SDP_EVT: bDestSap = eventData->sdp.remote_sap; sNfaLlcpSdpEvt.notifyOne(); NXPLOG_API_D ("nfaLlcpServerCallBack: 0x%04x\n", bDestSap); break; default: NXPLOG_API_D ("%s: unknown event 0x%X\n", LlcpEvent); break; } } }
static void nfaSnepClientCallback (tNFA_SNEP_EVT snepEvent, tNFA_SNEP_EVT_DATA *eventData) { NXPLOG_API_D("%s: snepEvent= %u", __FUNCTION__, snepEvent); switch (snepEvent) { case NFA_SNEP_REG_EVT: NXPLOG_API_D ("%s: NFA_SNEP_REG_EVT; Status: 0x%04x\n", __FUNCTION__, eventData->reg.status); NXPLOG_API_D ("%s: NFA_SNEP_REG_EVT; Client Register Handle: 0x%04x\n", __FUNCTION__, eventData->reg.reg_handle); sSnepClientHandle = eventData->reg.reg_handle; { SyncEventGuard guard (sNfaSnepClientRegEvent); sNfaSnepClientRegEvent.notifyOne (); } break; case NFA_SNEP_ACTIVATED_EVT: NXPLOG_API_D ("%s: NFA_SNEP_ACTIVATED_EVT; Client Activated Handle: 0x%04x\n", __FUNCTION__, eventData->activated.client_handle); nativeNfcTag_deregisterNdefTypeHandler (); if((eventData->activated.client_handle) && (sSnepClientHandle == eventData->activated.client_handle)) { nativeNfcSnep_notifyClientActivated(); } break; case NFA_SNEP_DEACTIVATED_EVT: NXPLOG_API_D ("%s: NFA_SNEP_DEACTIVATED_EVT: Client Deactivated Handle: 0x%04x\n", __FUNCTION__, eventData->deactivated.client_handle); if((eventData->deactivated.client_handle) && (sSnepClientHandle == eventData->deactivated.client_handle)) { nativeNfcSnep_notifyClientDeactivated(); } nativeNfcSnep_abortClientWaits(); nativeNfcTag_registerNdefTypeHandler(); break; case NFA_SNEP_CONNECTED_EVT: if((eventData->connect.reg_handle) && (eventData->connect.conn_handle) && (sSnepClientHandle == eventData->connect.reg_handle)) { SyncEventGuard guard (sNfaSnepClientConnEvent); NXPLOG_API_D ("%s: NFA_SNEP_CONNECTED_EVT: Client Register Handle: 0x%04x\n", __FUNCTION__, eventData->connect.reg_handle); sSnepClientConnectionHandle = eventData->connect.conn_handle; sNfaSnepClientConnEvent.notifyOne (); } break; case NFA_SNEP_DISC_EVT: NXPLOG_API_D ("%s: NFA_SNEP_DISC_EVT: Client Connection/Register Handle: 0x%04x\n", __FUNCTION__, eventData->disc.conn_handle); { nativeNfcSnep_abortClientWaits(); } break; case NFA_SNEP_PUT_RESP_EVT: NXPLOG_API_D ("%s: NFA_SNEP_PUT_RESP_EVT: Server Response Code: 0x%04x\n", __FUNCTION__, eventData->put_resp.resp_code); if((sSnepClientConnectionHandle == eventData->put_resp.conn_handle) && (NFA_SNEP_RESP_CODE_SUCCESS == eventData->put_resp.resp_code)) { nativeNfcSnep_doPutCompleted (NFA_STATUS_OK); } else { nativeNfcSnep_doPutCompleted (NFA_STATUS_FAILED); } break; case NFA_SNEP_ALLOC_BUFF_EVT: NXPLOG_API_D ("%s: NFA_SNEP_ALLOC_BUFF_EVT: Handle: 0x%04x\n", __FUNCTION__, eventData->alloc.conn_handle); break; case NFA_SNEP_FREE_BUFF_EVT: NXPLOG_API_D ("%s: NFA_SNEP_FREE_BUFF_EVT: \n", __FUNCTION__); break; default: NXPLOG_API_D ("%s: unknown event 0x%X\n", snepEvent); break; } }
/******************************************************************************* ** ** Function: nativeNfcTag_doPresenceCheckResult ** ** Description: Receive the result of presence-check. ** status: Result of presence-check. ** ** Returns: None ** *******************************************************************************/ void nativeNfcTag_doPresenceCheckResult (tNFA_STATUS status) { SyncEventGuard guard (sPresenceCheckEvent); sIsTagPresent = status == NFA_STATUS_OK; sPresenceCheckEvent.notifyOne (); }