/******************************************************************************* ** ** 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; }
/******************************************************************************* ** ** 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_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 (); } }
INT32 nativeNfcLlcp_ConnLessReceiveMessage(UINT8* msg, UINT32 *length) { NXPLOG_API_D ("%s: enter\n", __FUNCTION__); if(msg == NULL || length == NULL){ NXPLOG_API_E ("%s: Invalid buffer or length", __FUNCTION__); return NFA_STATUS_FAILED; } NXPLOG_API_D("nfaLlcpServerCallBack: remote sap ID 0x%04x\n ", bDestSap); if( (bServerReadState == FALSE) && (bClientReadState == FALSE) ) { sNfaLlcpConnLessReadEvent.wait(); } if(NFA_STATUS_OK != NFA_P2pReadUI ((size_t)sLlcpConnLessHandle, LLCP_MAX_DATA_SIZE, &bDestSap, &dwLlcpReadLength, &bLlcpReadData[0], &blMoreDataRemaining)) { NXPLOG_API_D ("%s: send response failed.", __FUNCTION__); return NFA_STATUS_FAILED; } else { memcpy(msg,bLlcpReadData, dwLlcpReadLength); *length = dwLlcpReadLength; NXPLOG_API_D ("%s: exit\n", __FUNCTION__); bServerReadState = FALSE; bClientReadState = FALSE; return NFA_STATUS_OK; } }
static void nativeNfcLlcp_doClientReadCompleted (tNFA_STATUS status) { NXPLOG_API_D ("%s: status=0x%X", __FUNCTION__, status); SyncEventGuard g (sNfaLlcpConnLessReadEvent); bClientReadState = TRUE; sNfaLlcpConnLessReadEvent.notifyOne (); }
static void nativeNfcSnep_doPutCompleted (tNFA_STATUS status) { NXPLOG_API_D ("%s: status=0x%X", __FUNCTION__, status); sSnepClientPutState = status; SyncEventGuard g (sNfaSnepClientPutMsgEvent); sNfaSnepClientPutMsgEvent.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__); }
void nativeNfcTag_notifyRfTimeout () { SyncEventGuard g (sTransceiveEvent); ALOGD ("%s: waiting for transceive: %d", __FUNCTION__, sWaitingForTransceive); if (!sWaitingForTransceive) return; sTransceiveRfTimeout = true; sTransceiveEvent.notifyOne (); }
/******************************************************************************* ** ** 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(); } }
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 (); }
/******************************************************************************* ** ** Function: nativeNfcTag_doRead ** ** Description: Read the NDEF message on the tag. ** e: JVM environment. ** o: Java object. ** ** Returns: NDEF message. ** *******************************************************************************/ static jbyteArray nativeNfcTag_doRead (JNIEnv* e, jobject) { ALOGD ("%s: enter", __FUNCTION__); tNFA_STATUS status = NFA_STATUS_FAILED; jbyteArray buf = NULL; sReadDataLen = 0; if (sReadData != NULL) { free (sReadData); sReadData = NULL; } if (sCheckNdefCurrentSize > 0) { { SyncEventGuard g (sReadEvent); sIsReadingNdefMessage = true; status = NFA_RwReadNDef (); sReadEvent.wait (); //wait for NFA_READ_CPLT_EVT } sIsReadingNdefMessage = false; if (sReadDataLen > 0) //if stack actually read data from the tag { ALOGD ("%s: read %u bytes", __FUNCTION__, sReadDataLen); buf = e->NewByteArray (sReadDataLen); e->SetByteArrayRegion (buf, 0, sReadDataLen, (jbyte*) sReadData); } } else { ALOGD ("%s: create empty buffer", __FUNCTION__); sReadDataLen = 0; sReadData = (uint8_t*) malloc (1); buf = e->NewByteArray (sReadDataLen); e->SetByteArrayRegion (buf, 0, sReadDataLen, (jbyte*) sReadData); } if (sReadData) { free (sReadData); sReadData = NULL; } sReadDataLen = 0; ALOGD ("%s: exit", __FUNCTION__); return buf; }
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 (); }
INT32 nativeNfcLlcp_ConnLessRegisterClientCallback(nfcllcpConnlessClientCallback_t *clientCallback) { tNFA_STATUS status = NFA_STATUS_FAILED; pthread_t llcpCleintRespThread; int ret = 1; NXPLOG_API_D ("%s:", __FUNCTION__); gSyncMutex.lock(); if (!nativeNfcManager_isNfcActive()) { NXPLOG_API_E ("%s: Nfc not initialized.", __FUNCTION__); gSyncMutex.unlock(); return NFA_STATUS_FAILED; } sRfEnabled = isDiscoveryStarted(); if (sRfEnabled) { /* Stop RF Discovery if we were polling */ startRfDiscovery (FALSE); } { SyncEventGuard g (sNfaLlcpClientRegEvent); bClientReadState = FALSE; if(NFA_STATUS_OK != (status = NFA_P2pRegisterClient(NFA_P2P_LLINK_TYPE, nfaLlcpClientCallback))) { NXPLOG_API_E ("%s: fail to register client callback for LLCP", __FUNCTION__); if (sRfEnabled) { /* Rollback to default */ startRfDiscovery (TRUE); gSyncMutex.unlock(); return status; } } sNfaLlcpClientRegEvent.wait(); } sClientCallback = clientCallback; status = NFA_STATUS_OK; gSyncMutex.unlock(); return status; }
static void *snepServerThread(void *arg) { (void)arg; SyncEventGuard guard (sNfaSnepServerPutRspEvent); NXPLOG_API_D ("%s: enter\n", __FUNCTION__); while(sSnepServerState == SNEP_SERVER_STARTED) { sNfaSnepServerPutRspEvent.wait(); if (sSnepServerConnectionHandle == 0) break; if(NFA_STATUS_OK != NFA_SnepPutResponse(sSnepServerConnectionHandle, sNfaSnepRespCode)) { NXPLOG_API_D ("%s: send response failed.", __FUNCTION__); } } NXPLOG_API_D ("%s: exit\n", __FUNCTION__); pthread_exit(NULL); return NULL; }
INT32 nativeNfcSnep_registerClientCallback(nfcSnepClientCallback_t *clientCallback) { tNFA_STATUS status = NFA_STATUS_FAILED; NXPLOG_API_D ("%s:", __FUNCTION__); gSyncMutex.lock(); if (!nativeNfcManager_isNfcActive()) { NXPLOG_API_E ("%s: Nfc not initialized.", __FUNCTION__); gSyncMutex.unlock(); return NFA_STATUS_FAILED; } sRfEnabled = isDiscoveryStarted(); if (sRfEnabled) { // Stop RF Discovery if we were polling startRfDiscovery (FALSE); } { SyncEventGuard g (sNfaSnepClientRegEvent); if(NFA_STATUS_OK != (status = NFA_SnepRegisterClient(nfaSnepClientCallback))) { NXPLOG_API_E ("%s: fail to register client callback for SNEP", __FUNCTION__); goto clean_and_return; } sNfaSnepClientRegEvent.wait(); } sClientCallback = clientCallback; status = NFA_STATUS_OK; clean_and_return: if (sRfEnabled) { // Stop RF Discovery if we were polling startRfDiscovery (TRUE); } gSyncMutex.unlock(); return status; }
void syncError(SyncEvent& event) { CPPUNIT_ASSERT(strcmp(TEST_ERROR_MSG, event.getMessage()) == 0); counter++; };
void syncBegin(SyncEvent& event) { CPPUNIT_ASSERT_EQUAL(event.getType(), SYNC_BEGIN); counter++; };
void sendModifications(SyncEvent& event) { CPPUNIT_ASSERT_EQUAL(event.getType(), SEND_MODIFICATION); counter++; };
void sendFinalization(SyncEvent& event) { CPPUNIT_ASSERT_EQUAL(event.getType(), SEND_FINALIZATION); counter++; };
void syncError (SyncEvent& event) { printf("\nSynchronization error: %s\n", event.getMessage()); }
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; } }
INT32 nativeNfcSnep_putMessage(UINT8* msg, UINT32 length) { tNFA_STATUS status = NFA_STATUS_FAILED; NXPLOG_API_D ("%s: data length = %d", __FUNCTION__, length); if (!sSnepClientHandle) { NXPLOG_API_E ("%s: no connection", __FUNCTION__); return NFA_STATUS_FAILED; } if (!msg || length == 0) { NXPLOG_API_E ("%s: wrong param", __FUNCTION__); return NFA_STATUS_FAILED; } if(NFA_STATUS_OK != NDEF_MsgValidate(msg, length, FALSE)) { NXPLOG_API_E ("%s: not NDEF message", __FUNCTION__); return NFA_STATUS_FAILED; } gSyncMutex.lock(); if (!nativeNfcManager_isNfcActive()) { NXPLOG_API_E ("%s: Nfc not initialized.", __FUNCTION__); status = NFA_STATUS_FAILED; goto clean_and_return; } if (sSnepClientHandle){ SyncEventGuard guard (sNfaSnepClientConnEvent); if(NFA_STATUS_OK != NFA_SnepConnect(sSnepClientHandle, SNEP_SERVER_NAME)) { status = NFA_STATUS_FAILED; goto clean_and_return; } sNfaSnepClientConnEvent.wait(); } /* Send Put Request */ if (sSnepClientConnectionHandle != 0) { SyncEventGuard guard (sNfaSnepClientPutMsgEvent); if(NFA_STATUS_OK != NFA_SnepPut (sSnepClientConnectionHandle, length, msg)) { status = NFA_STATUS_FAILED; goto clean_and_return; } sNfaSnepClientPutMsgEvent.wait(); if (sSnepClientPutState != NFA_STATUS_OK) { status = NFA_STATUS_FAILED; } else { status = NFA_STATUS_OK; sSnepClientPutState = NFA_STATUS_FAILED; } } /* Disconnect from Snep Server */ if (sSnepClientConnectionHandle != 0) { SyncEventGuard guard (sNfaSnepClientDisconnEvent); if(NFA_STATUS_OK != NFA_SnepDisconnect (sSnepClientConnectionHandle, 0x01)) { status = NFA_STATUS_FAILED; goto clean_and_return; } sNfaSnepClientDisconnEvent.wait(); } clean_and_return: NXPLOG_API_D ("%s: return = %d", __FUNCTION__, status); gSyncMutex.unlock(); return status; }
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; } }
void syncEnd(SyncEvent& event) { CPPUNIT_ASSERT_EQUAL(event.getType(), SYNC_END); counter++; };
void sendInitialization(SyncEvent& event) { CPPUNIT_ASSERT_EQUAL(event.getType(), SEND_INITIALIZATION); counter++; };
INT32 nativeNfcSnep_startServer(nfcSnepServerCallback_t *serverCallback) { tNFA_STATUS status = NFA_STATUS_OK; int ret; pthread_t snepRespThread; NXPLOG_API_D ("%s:", __FUNCTION__); if (serverCallback == NULL) { NXPLOG_API_E ("%s: callback is NULL!", __FUNCTION__); return NFA_STATUS_FAILED; } gSyncMutex.lock(); if (!nativeNfcManager_isNfcActive()) { NXPLOG_API_E ("%s: Nfc not initialized.", __FUNCTION__); gSyncMutex.unlock(); return NFA_STATUS_FAILED; } if (sSnepServerState == SNEP_SERVER_STARTED && serverCallback == sServerCallback) { NXPLOG_API_D ("%s: alread started!", __FUNCTION__); gSyncMutex.unlock(); return NFA_STATUS_OK; } if (sSnepServerState != SNEP_SERVER_IDLE) { NXPLOG_API_E ("%s: Server is started or busy. State = 0x%X", __FUNCTION__, sSnepServerState); gSyncMutex.unlock(); return NFA_STATUS_FAILED; } sServerCallback = serverCallback; sSnepServerState = SNEP_SERVER_STARTING; sRfEnabled = isDiscoveryStarted(); if (sRfEnabled) { // Stop RF Discovery if we were polling startRfDiscovery (FALSE); } { SyncEventGuard guard (sNfaSnepServerRegEvent); if(NFA_STATUS_OK != NFA_SnepRegisterServer(0x04, SNEP_SERVER_NAME, nfaSnepServerCallback)) { status = NFA_STATUS_FAILED; sSnepServerState = SNEP_SERVER_IDLE; sServerCallback = NULL; goto clean_and_return; } sNfaSnepServerRegEvent.wait(); } ret = pthread_create(&snepRespThread, NULL, snepServerThread, NULL); if(ret != 0) { NXPLOG_API_E("Unable to create snep server thread"); sSnepServerState = SNEP_SERVER_IDLE; NFA_SnepDeregister(sSnepServerHandle); sServerCallback = NULL; status = NFA_STATUS_FAILED; goto clean_and_return; } sSnepServerState = SNEP_SERVER_STARTED; clean_and_return: if (sRfEnabled) { startRfDiscovery (TRUE); } gSyncMutex.unlock(); return status; }