NFCSTATUS phNciNfc_SetConnCredentials(void *psNciContext) { NFCSTATUS wStatus = NFCSTATUS_SUCCESS; pphNciNfc_Context_t psNciCtxt = (pphNciNfc_Context_t )psNciContext; PH_LOG_NCI_FUNC_ENTRY(); if(NULL == psNciCtxt) { wStatus = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_CRIT_STR(" Invalid Context Param.."); } else { /* Update Static conn info with conn details & device handle */ wStatus = phNciNfc_UpdateConnDestInfo(psNciCtxt->tActvDevIf.pDevInfo->bRfDiscId, phNciNfc_e_REMOTE_NFC_ENDPOINT, psNciCtxt->tActvDevIf.pDevInfo); if(NFCSTATUS_SUCCESS == wStatus) { PH_LOG_NCI_INFO_STR("Conn Credentials updated successfully.."); } else { PH_LOG_NCI_CRIT_STR("Conn Credentials update failed!!.."); } } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
NFCSTATUS phNciNfc_UpdateConnDestInfo( uint8_t bDestId, phNciNfc_DestType_t tDestType, void *pHandle ) { NFCSTATUS wStatus = NFCSTATUS_SUCCESS; uint8_t bConnIdx; uint8_t bConnId; PH_LOG_NCI_FUNC_ENTRY(); if(NULL == pHandle) { wStatus = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_CRIT_STR(" Invalid Params supplied!!"); } else { if( (phNciNfc_e_NFCEE == tDestType) ||\ (phNciNfc_e_NFCC_LOOPBACK == tDestType) ) { wStatus = phNciNfc_GetConnInfo(bDestId,tDestType,&bConnId); if( (NFCSTATUS_SUCCESS != wStatus) || (NFCSTATUS_SUCCESS != phNciNfc_GetConnIndex(bConnId,&bConnIdx) ) ) { wStatus = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_FAILED); } else { gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnIdx].pActvDevHandle = pHandle; } } else if(phNciNfc_e_REMOTE_NFC_ENDPOINT == tDestType) { pphNciNfc_RemoteDevInformation_t pActvDev = (pphNciNfc_RemoteDevInformation_t)pHandle; gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[CONNTYPE_STATIC].bDestId = pActvDev->bRfDiscId; gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[CONNTYPE_STATIC].bDestType = tDestType; gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[CONNTYPE_STATIC].tConn.bMaxDpldSize = pActvDev->bMaxPayLoadSize; gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[CONNTYPE_STATIC].tConn.bNumCredits = pActvDev->bInitialCredit; gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[CONNTYPE_STATIC].bIfActive = TRUE; gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[CONNTYPE_STATIC].pActvDevHandle = pActvDev; } else { wStatus = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_CRIT_STR(" Unsupported Destination Type!!"); } } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
static NFCSTATUS phNciNfc_SendCb(void* pContext, void *pInfo, NFCSTATUS wStatus) { NFCSTATUS wStat = wStatus; pphNciNfc_Context_t pNciContext = pContext; UNUSED(pInfo); PH_LOG_NCI_FUNC_ENTRY(); if(NULL != pNciContext) { /* Opening a dummy read request inorder not to loose data sent from remote device */ (void )phNciNfc_DummyReadReq((void *)pNciContext); if(NULL != pNciContext->IfNtf) { pNciContext->IfNtf(pNciContext->IfNtfCtx,wStat,NULL); } if(NULL != pNciContext->tTranscvCtxt.tSendPld.pBuff) { PH_LOG_NCI_INFO_STR("De-allocating Send Request Payload Buffer..."); phOsalNfc_FreeMemory(pNciContext->tTranscvCtxt.tSendPld.pBuff); pNciContext->tTranscvCtxt.tSendPld.pBuff = NULL; pNciContext->tTranscvCtxt.tSendPld.wLen = 0; } } else { PH_LOG_NCI_CRIT_STR("Invalid context received from RecvMgrHdlr!"); } PH_LOG_NCI_FUNC_EXIT(); return wStat; }
static NFCSTATUS phNciNfc_SeSendCb(void* pContext, void *pInfo, NFCSTATUS wStatus) { NFCSTATUS wStat = wStatus; pphNciNfc_Context_t pNciContext = pContext; UNUSED(pInfo); PH_LOG_NCI_FUNC_ENTRY(); if(NULL != pNciContext) { if(NULL != pNciContext->tTranscvCtxt.tSendPld.pBuff) { PH_LOG_NCI_INFO_STR("De-allocating Send Request Payload Buffer..."); phOsalNfc_FreeMemory(pNciContext->tTranscvCtxt.tSendPld.pBuff); pNciContext->tTranscvCtxt.tSendPld.pBuff = NULL; pNciContext->tTranscvCtxt.tSendPld.wLen = 0; } phNciNfc_Notify(pNciContext, wStatus, NULL); } else { PH_LOG_NCI_CRIT_STR("Invalid context received from RecvMgrHdlr!"); } PH_LOG_NCI_FUNC_EXIT(); return wStat; }
static NFCSTATUS phNciNfc_CoreRegister(void *pRegList, pphNciNfc_CoreRegInfo_t pRegInfo, phNciNfc_NciCoreMsgType_t eMsgType) { uint8_t bIndex = 0; uint8_t bGetEmptySlot = 1; NFCSTATUS wStatus = NFCSTATUS_FAILED; pphNciNfc_CoreRegRspNtfInfo_t pRegRspNtfList = NULL; pphNciNfc_CoreRegDataInfo_t pRegDataList = NULL; PH_LOG_NCI_FUNC_ENTRY(); if(phNciNfc_e_NciCoreMsgTypeCntrlRsp == eMsgType) { /* Force registration (over-write resposnse/data call back entry if any exist) */ bIndex = 0; wStatus = NFCSTATUS_SUCCESS; } else { /* Get a free slot in the list */ wStatus = phNciNfc_CoreGetIndex(bGetEmptySlot,pRegList,pRegInfo,eMsgType,&bIndex); } if(NFCSTATUS_SUCCESS == wStatus) { switch(eMsgType) { case phNciNfc_e_NciCoreMsgTypeCntrlRsp: case phNciNfc_e_NciCoreMsgTypeCntrlNtf: pRegRspNtfList = (pphNciNfc_CoreRegRspNtfInfo_t)pRegList; pRegRspNtfList[bIndex].bEnabled = pRegInfo->bEnabled; pRegRspNtfList[bIndex].bGid = pRegInfo->bGid; pRegRspNtfList[bIndex].bOid = pRegInfo->bOid; pRegRspNtfList[bIndex].pContext = pRegInfo->pContext; pRegRspNtfList[bIndex].pNotifyCb = pRegInfo->pNotifyCb; break; case phNciNfc_e_NciCoreMsgTypeData: pRegDataList = (pphNciNfc_CoreRegDataInfo_t)pRegList; pRegDataList[bIndex].bEnabled = pRegInfo->bEnabled; pRegDataList[bIndex].bConnId = pRegInfo->bConnId; pRegDataList[bIndex].pContext = pRegInfo->pContext; pRegDataList[bIndex].pNotifyCb = pRegInfo->pNotifyCb; break; default: break; } PH_LOG_NCI_INFO_STR("Registration success"); } else { PH_LOG_NCI_CRIT_STR("No free slots available, registraiton failed!"); } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
NFCSTATUS phNciNfc_NfcIsoLstnRdrInit( pphNciNfc_RemoteDevInformation_t pRemDevInf, uint8_t *pBuff, uint16_t wLen ) { NFCSTATUS wStatus = NFCSTATUS_SUCCESS; uint8_t *pRfNtfBuff = NULL; uint8_t RfTechSpecParamsLen = 0; uint8_t bUidLength = 0; uint8_t bSelResRespLen = 0; uint8_t bSelRespVal = 0; PH_LOG_NCI_FUNC_ENTRY(); if((NULL == pRemDevInf) || (NULL == pBuff) || (0 == wLen)) { wStatus = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_CRIT_STR(" Invalid Param(s).."); } else { pRemDevInf->bRfDiscId = pBuff[0]; pRemDevInf->eRfIf = (phNciNfc_RfInterfaces_t)pBuff[1]; pRemDevInf->eRFProtocol = (phNciNfc_RfProtocols_t)pBuff[2]; pRemDevInf->eRFTechMode = (phNciNfc_RfTechMode_t)pBuff[3]; pRemDevInf->bMaxPayLoadSize = pBuff[4]; pRemDevInf->bInitialCredit = pBuff[5]; /* Obtain the len of RF tech specific parameters from Resp buff */ RfTechSpecParamsLen = pBuff[6]; pRemDevInf->bTechSpecificParamLen = RfTechSpecParamsLen; pRfNtfBuff = &(pBuff[7+RfTechSpecParamsLen]); pRemDevInf->eDataXchgRFTechMode = (phNciNfc_RfTechMode_t)*(pRfNtfBuff+0); pRemDevInf->bTransBitRate = *(pRfNtfBuff+1); pRemDevInf->bRecvBitRate = *(pRfNtfBuff+2); /* Length of NFCID1 */ bUidLength = *(pRfNtfBuff+2); /* Length of SEL_RES response */ bSelResRespLen = *(pRfNtfBuff + 3 + bUidLength); if(1 == bSelResRespLen) { /* Length of SEL_RES shall be '0' incase of Nfc Forum Type 1 Tag */ bSelRespVal = *(pRfNtfBuff + 3 + bUidLength + 1); } else { bSelRespVal = 0; } /* Length of SEL_RES shall be '0' incase of Nfc Forum Type 1 Tag */ } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
static NFCSTATUS phNciNfc_UpdateNfcIRemDevInfo(pphNciNfc_RemoteDevInformation_t pRemDevInf, uint8_t *pBuff, uint16_t wLen ) { NFCSTATUS wStatus = NFCSTATUS_SUCCESS; uint8_t *pRfNtfBuff = NULL; uint8_t RfTechSpecParamsLen = 0; PH_LOG_NCI_FUNC_ENTRY(); if((NULL == pRemDevInf) || (NULL == pBuff) || (0 == wLen)) { wStatus = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_CRIT_STR(" Invalid Param(s).."); } else { pRemDevInf->bRfDiscId = pBuff[0]; pRemDevInf->eRfIf = (phNciNfc_RfInterfaces_t)pBuff[1]; if(phNciNfc_e_RfInterfacesNfceeDirect_RF != (pRemDevInf->eRfIf)) { pRemDevInf->eRFProtocol = (phNciNfc_RfProtocols_t)pBuff[2]; pRemDevInf->eRFTechMode = (phNciNfc_RfTechMode_t)pBuff[3]; pRemDevInf->bMaxPayLoadSize = pBuff[4]; pRemDevInf->bInitialCredit = pBuff[5]; /* Obtain the len of RF tech specific parameters from Resp buff */ RfTechSpecParamsLen = pBuff[6]; pRemDevInf->bTechSpecificParamLen = RfTechSpecParamsLen; pRfNtfBuff = &(pBuff[7+RfTechSpecParamsLen]); pRemDevInf->eDataXchgRFTechMode = (phNciNfc_RfTechMode_t)*(pRfNtfBuff+0); pRemDevInf->bTransBitRate = *(pRfNtfBuff+1); pRemDevInf->bRecvBitRate = *(pRfNtfBuff+2); } else { PH_LOG_NCI_WARN_STR("Interface is NFCEE Direct RF,subsequent payload contents ignored.."); } } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
NFCSTATUS phNciNfc_GetConnCredits( uint8_t bConnId, uint8_t *pCredits ) { NFCSTATUS wStatus = NFCSTATUS_FAILED; uint8_t bConnListIdx; PH_LOG_NCI_FUNC_ENTRY(); if(NULL == pCredits) { wStatus = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_INFO_STR(" Invalid Params.."); } else { for(bConnListIdx = 0; bConnListIdx < (MAX_LOGICAL_CONNS+1) ; bConnListIdx++) { if(bConnId == (gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bConnId) ) { if((TRUE == (gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].bIfActive)) || (CONNTYPE_STATIC == (gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bConnId))) { *pCredits = (gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bNumCredits); wStatus = NFCSTATUS_SUCCESS; } else { PH_LOG_NCI_CRIT_STR("Interface not active for this connection"); } break; } } } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
NFCSTATUS phNciNfc_ReceiveCb(void* pContext, void *pInfo, NFCSTATUS wStatus) { pphNciNfc_Context_t pNciContext = pContext; NFCSTATUS wStat; PH_LOG_NCI_FUNC_ENTRY(); wStat = wStatus; if(NULL != pNciContext) { if(NULL != pNciContext->IfNtf) { pNciContext->IfNtf(pNciContext->IfNtfCtx,wStat,pInfo); } } else { PH_LOG_NCI_CRIT_STR("Invalid context received from RecvMgrHdlr!"); } PH_LOG_NCI_FUNC_EXIT(); return wStat; }
NFCSTATUS phNciNfc_DecrConnCredit( uint8_t bConnId ) { NFCSTATUS wStatus = NFCSTATUS_FAILED; uint8_t bConnListIdx; PH_LOG_NCI_FUNC_ENTRY(); for(bConnListIdx = 0; bConnListIdx < (MAX_LOGICAL_CONNS+1) ; bConnListIdx++) { if(bConnId == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bConnId) { if((TRUE == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].bIfActive) || (CONNTYPE_STATIC == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bConnId)) { if(gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bNumCredits > 0) { gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bNumCredits -= 1; wStatus = NFCSTATUS_SUCCESS; } else { PH_LOG_NCI_WARN_STR("No Credits available for this connId!!"); } } else { PH_LOG_NCI_CRIT_STR(" Interface not active for this connection"); } break; } } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
NFCSTATUS phNciNfc_IncrConnCredits( uint8_t bConnId, uint8_t bVal ) { NFCSTATUS wStatus = NFCSTATUS_FAILED; uint8_t bConnListIdx; PH_LOG_NCI_FUNC_ENTRY(); for(bConnListIdx = 0; bConnListIdx < (MAX_LOGICAL_CONNS+1) ; bConnListIdx++) { if(bConnId == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bConnId) { if((TRUE == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].bIfActive) || (CONNTYPE_STATIC == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bConnId)) { gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bNumCredits += bVal; if(gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bNumCredits > MAX_CREDITS_LIMIT) { gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bNumCredits = MAX_CREDITS_LIMIT; PH_LOG_NCI_WARN_STR(" Credit Limit xceeded for this Conn,Rounding to max value .."); } wStatus = NFCSTATUS_SUCCESS; } else { PH_LOG_NCI_CRIT_STR(" Interface not active for this connection"); } break; } } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
static void phNciNfc_WaitCreditTimerCb(uint32_t TimerId, void *pContext) { NFCSTATUS wStatus = NFCSTATUS_RF_TIMEOUT; phNciNfc_LogConnMgmt_Int_t *pConnMgmtCtxt = (phNciNfc_LogConnMgmt_Int_t *)pContext; PH_LOG_NCI_FUNC_ENTRY(); if(NULL != pConnMgmtCtxt) { if(TimerId == pConnMgmtCtxt->tCWTimerIf.dwTimerId) { pConnMgmtCtxt->tCWTimerIf.TimerStatus = 0; /* Reset timer status flag */ (void)phOsalNfc_Timer_Stop(pConnMgmtCtxt->tCWTimerIf.dwTimerId); (void)phOsalNfc_Timer_Delete(pConnMgmtCtxt->tCWTimerIf.dwTimerId); pConnMgmtCtxt->tCWTimerIf.dwTimerId = 0; } else { PH_LOG_NCI_CRIT_STR("Invalid wait credit timer ID"); phOsalNfc_RaiseException(phOsalNfc_e_InternalErr, 1); } if(TRUE == pConnMgmtCtxt->bCreditsAwaited) { pConnMgmtCtxt->bCreditsAwaited = FALSE; } if (NULL != pConnMgmtCtxt->pCrdtsNotify) { (void)(pConnMgmtCtxt->pCrdtsNotify)(pConnMgmtCtxt->pContext,0,wStatus); } } PH_LOG_NCI_FUNC_EXIT(); return; }
NFCSTATUS phNciNfc_RdrAInit( pphNciNfc_RemoteDevInformation_t pRemDevInf, uint8_t *pBuff, uint16_t wLen ) { NFCSTATUS status = NFCSTATUS_SUCCESS; uint8_t *pRfNtfBuff = NULL; uint8_t RfTechSpecParamsLen = 0; uint8_t ActvnParamsLen = 0; uint8_t bSelResRespLen = 0; uint8_t bUidLength = 0; uint8_t bSelRespVal = 0; phNciNfc_RFDevType_t eDevType = phNciNfc_eInvalid_DevType; PH_LOG_NCI_FUNC_ENTRY(); if((0 != (wLen)) && (NULL != pBuff) && (NULL != pRemDevInf)) { PH_LOG_NCI_INFO_STR(" NFC-A Passive Poll Mode Info being captured.."); /* Length of technology specific parameters */ RfTechSpecParamsLen = pBuff[6]; /* Shift the buffer pointer points to first parameter of technology specific parameters */ pRfNtfBuff = &pBuff[7]; /* Get technology specific parameters incase of Nfc-A poll mode */ if (phNciNfc_NFCA_Kovio_Poll == pRemDevInf->eRFTechMode) { if (RfTechSpecParamsLen > PH_NCINFCTYPES_KOVIO_TAG_ID_LENGTH) { status = NFCSTATUS_FAILED; } } else if(phNciNfc_NFCA_Listen != pRemDevInf->eRFTechMode) { /* Length of NFCID1 */ bUidLength = *(pRfNtfBuff+2); if((0 != bUidLength) && (NFCID1_LEN4 != bUidLength) && (NFCID1_LEN7 != bUidLength) && (NFCID1_LEN10 != bUidLength)) { PH_LOG_NCI_CRIT_STR("Invalid Nfc-A UID length"); status = NFCSTATUS_FAILED; } if(NFCSTATUS_SUCCESS == status) { /* Length of SEL_RES response */ bSelResRespLen = *(pRfNtfBuff + 3 + bUidLength); if(1 == bSelResRespLen) { /* Length of SEL_RES shall be '0' incase of Nfc Forum Type 1 Tag */ bSelRespVal = *(pRfNtfBuff + 3 + bUidLength + 1); } else if(0 == bSelResRespLen) { bSelRespVal = 0; } else { PH_LOG_NCI_CRIT_STR("Invalid Nfc-A SEL_RES length"); status = NFCSTATUS_FAILED; } } } if(NFCSTATUS_SUCCESS == status) { phNciNfc_GetRfDevType(bSelRespVal,bSelResRespLen,pRemDevInf,&eDevType); (pRemDevInf->RemDevType) = eDevType; } else { pRemDevInf->RemDevType = phNciNfc_eInvalid_DevType; } /*Update technology specific parameters (these parameters are specific to the remote device type detected)*/ switch((pRemDevInf->RemDevType)) { case phNciNfc_eISO14443_4A_PICC: case phNciNfc_eMifareUL_PICC: case phNciNfc_eMifare1k_PICC: case phNciNfc_eMifare4k_PICC: case phNciNfc_eMifareMini_PICC: { if(0 != bUidLength) { (pRemDevInf->tRemoteDevInfo.Iso14443A_Info.UidLength) = bUidLength; (pRemDevInf->tRemoteDevInfo.Iso14443A_Info.bSelResRespLen) = bSelResRespLen; (pRemDevInf->tRemoteDevInfo.Iso14443A_Info.Sak) = bSelRespVal; phOsalNfc_MemCopy(&(pRemDevInf->tRemoteDevInfo.Iso14443A_Info.bSensResResp),pRfNtfBuff,2); phOsalNfc_SetMemory((pRemDevInf->tRemoteDevInfo.Iso14443A_Info.Uid),0,PH_NCINFCTYPES_MAX_UID_LENGTH); phOsalNfc_MemCopy(&(pRemDevInf->tRemoteDevInfo.Iso14443A_Info.Uid), (pRfNtfBuff+3),(pRemDevInf->tRemoteDevInfo.Iso14443A_Info.UidLength)); } else { status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_INFO_STR(" Invalid UID Length received"); } } break; case phNciNfc_eJewel_PICC: { if((0 == bUidLength) || (NFCID1_LEN4 == bUidLength)) { phOsalNfc_MemCopy(&(pRemDevInf->tRemoteDevInfo.Jewel_Info.bSensResResp),pRfNtfBuff,2); } else { status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_INFO_STR(" Invalid UID Length received"); } } break; case phNciNfc_eKovio_PICC: { // The tag ID is all we get if(RfTechSpecParamsLen > 0) { pRemDevInf->tRemoteDevInfo.Kovio_Info.TagIdLength = RfTechSpecParamsLen; phOsalNfc_MemCopy(&(pRemDevInf->tRemoteDevInfo.Kovio_Info.TagId), pRfNtfBuff, RfTechSpecParamsLen); } } break; default: { break; } } /* Update gpphNciNfc_RdrDataXchgSequence with the appropriate functions to be called by sequence handler on invocation during data exchange */ switch(pRemDevInf->RemDevType) { case phNciNfc_eISO14443_A_PICC: { break; } case phNciNfc_eKovio_PICC: { break; } case phNciNfc_eISO14443_4A_PICC: { if(NFCSTATUS_SUCCESS == status) { if(phNciNfc_e_RfInterfacesISODEP_RF == (pRemDevInf->eRfIf)) { /* Obtain the length of Activation parameters from pBuff */ ActvnParamsLen = pBuff[7+RfTechSpecParamsLen+PH_NCINFCTYPES_DATA_XCHG_PARAMS_LEN]; if(0 != ActvnParamsLen) { pRfNtfBuff = &(pBuff[7+RfTechSpecParamsLen+PH_NCINFCTYPES_DATA_XCHG_PARAMS_LEN+1]); pRemDevInf->tRemoteDevInfo.Iso14443A_Info.bRatsRespLen = *pRfNtfBuff; if(0 != pRemDevInf->tRemoteDevInfo.Iso14443A_Info.bRatsRespLen) { if(((ActvnParamsLen - 1) >= pRemDevInf->tRemoteDevInfo.Iso14443A_Info.bRatsRespLen) && (sizeof(phNciNfc_RATSResp_t) >= pRemDevInf->tRemoteDevInfo.Iso14443A_Info.bRatsRespLen)) { phOsalNfc_MemCopy(&(pRemDevInf->tRemoteDevInfo.Iso14443A_Info. tRatsResp),(pRfNtfBuff+1),(pRemDevInf->tRemoteDevInfo. Iso14443A_Info.bRatsRespLen)); } else { PH_LOG_NCI_CRIT_STR("Invalid RATS Resp Recvd!!, ActvnParamsLen %d, RatsRespLen %d", ActvnParamsLen, pRemDevInf->tRemoteDevInfo.Iso14443A_Info.bRatsRespLen); status = NFCSTATUS_FAILED; } } } } else { /* TODO:- RF Frame interface case,no activation parameters available for 4A Tag */ } gpphNciNfc_RdrDataXchgSequence[0].SequnceInitiate = &phNciNfc_Send4AData; gpphNciNfc_RdrDataXchgSequence[0].SequenceProcess = &phNciNfc_Recv4AResp; } break; } case phNciNfc_eMifareUL_PICC: case phNciNfc_eMifare1k_PICC: case phNciNfc_eMifare4k_PICC: case phNciNfc_eMifareMini_PICC: { if(NFCSTATUS_SUCCESS == status) { gpphNciNfc_RdrDataXchgSequence[0].SequnceInitiate = &phNciNfc_SendMfReq; gpphNciNfc_RdrDataXchgSequence[0].SequenceProcess = &phNciNfc_RecvMfResp; } break; } case phNciNfc_eJewel_PICC: { if(NFCSTATUS_SUCCESS == status) { /* Validate Technology specific parameters */ status = phNciNfc_JewelInit(pRemDevInf->tRemoteDevInfo.Jewel_Info.bSensResResp); gpphNciNfc_RdrDataXchgSequence[0].SequnceInitiate = &phNciNfc_SendJewelReq; gpphNciNfc_RdrDataXchgSequence[0].SequenceProcess = &phNciNfc_RecvJewelResp; } break; } default: { break; } } gpphNciNfc_RdrDataXchgSequence[1].SequnceInitiate = NULL; gpphNciNfc_RdrDataXchgSequence[1].SequenceProcess = &phNciNfc_CompleteDataXchgSequence; } else { status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_INFO_STR(" Invalid Params.."); } PH_LOG_NCI_FUNC_EXIT(); #pragma prefast(suppress: __WARNING_POTENTIAL_RANGE_POSTCONDITION_VIOLATION, "ESP:1220 PreFast Bug") return status; }
NFCSTATUS phNciNfc_NfcDepLstnRdrFInit( pphNciNfc_RemoteDevInformation_t pRemDevInf, uint8_t *pBuff, uint16_t wLen) { NFCSTATUS status = NFCSTATUS_SUCCESS; uint8_t *pRfNtfBuff; uint8_t RfTechSpecParamsLen; uint8_t bNfcId2Len; uint8_t ActvnParamsLen = 0; PH_LOG_NCI_FUNC_ENTRY(); if( (0 != (wLen)) && (NULL != pBuff) && (NULL != pRemDevInf)) { /* Remote devuce is a P2P Initiator */ pRemDevInf->RemDevType = phNciNfc_eNfcIP1_Initiator; /* Obtain the len of RF tech specific parameters from Resp buff */ RfTechSpecParamsLen = pBuff[6]; /*TODO: Check should added for this*/ pRfNtfBuff = &pBuff[7]; bNfcId2Len = *(pRfNtfBuff); pRemDevInf->tRemoteDevInfo.NfcIP_Info.NFCID_Length = 0; if(0 != RfTechSpecParamsLen) { pRemDevInf->tRemoteDevInfo.NfcIP_Info.NFCID_Length = bNfcId2Len; phOsalNfc_SetMemory(pRemDevInf->tRemoteDevInfo.NfcIP_Info.NFCID,0,PH_NCINFCTYPES_MAX_NFCID3_SIZE); if(0 == bNfcId2Len) { PH_LOG_NCI_CRIT_STR("No NFCID2 received"); } else if(PH_NCINFCTYPES_NFCID2_LEN == bNfcId2Len) { phOsalNfc_SetMemory(pRemDevInf->tRemoteDevInfo.NfcIP_Info.NFCID,0,PH_NCINFCTYPES_MAX_NFCID3_SIZE); phOsalNfc_MemCopy(pRemDevInf->tRemoteDevInfo.NfcIP_Info.NFCID,(pRfNtfBuff+1),bNfcId2Len); } else { status = NFCSTATUS_FAILED; PH_LOG_NCI_CRIT_STR("Invalid NFCID2 received"); } } if(NFCSTATUS_SUCCESS == status) { /* Initiator speed (Initiator to target speed) */ pRemDevInf->tRemoteDevInfo.NfcIP_Info.Nfcip_Datarate = (phNciNfc_BitRates_t)pRemDevInf->bTransBitRate; switch(pRemDevInf->eRFTechMode) { case phNciNfc_NFCA_Active_Listen: case phNciNfc_NFCF_Active_Listen: pRemDevInf->tRemoteDevInfo.NfcIP_Info.Nfcip_Active = 1; /* Active communciation */ break; default: pRemDevInf->tRemoteDevInfo.NfcIP_Info.Nfcip_Active = 0; /* Passive communciation */ break; } /* Obtain the length of Activation parameters from pBuff */ ActvnParamsLen = pBuff[7+RfTechSpecParamsLen+PH_NCINFCTYPES_DATA_XCHG_PARAMS_LEN]; if(0 != ActvnParamsLen) { pRemDevInf->tRemoteDevInfo.NfcIP_Info.bATRInfo_Length = (ActvnParamsLen-1); pRfNtfBuff = &(pBuff[7+RfTechSpecParamsLen+PH_NCINFCTYPES_DATA_XCHG_PARAMS_LEN+2]); phOsalNfc_SetMemory(pRemDevInf->tRemoteDevInfo.NfcIP_Info.aAtrInfo,0, PH_NCINFCTYPES_ATR_MAX_LEN); if(pRemDevInf->tRemoteDevInfo.NfcIP_Info.bATRInfo_Length <= PH_NCINFCTYPES_ATR_MAX_LEN) { phOsalNfc_MemCopy(pRemDevInf->tRemoteDevInfo.NfcIP_Info.aAtrInfo, pRfNtfBuff,pRemDevInf->tRemoteDevInfo.NfcIP_Info.bATRInfo_Length); } else { pRemDevInf->tRemoteDevInfo.NfcIP_Info.bATRInfo_Length = 0; PH_LOG_NCI_CRIT_STR("Invalid ATR_INFO length"); status = NFCSTATUS_FAILED; } } /* The Activated device is a P2P Initiator. The P2P 'Send' and 'Receive' functions shall be active. The P2P Target (i.e., us) is expected to receive data from remote P2P initiator and expected to send data to Remote P2P target in response */ } } else { status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_INFO_STR(" Invalid Params.."); } PH_LOG_NCI_FUNC_EXIT(); return status; }
NFCSTATUS phNciNfc_NfcDepLstnRdrAInit( pphNciNfc_RemoteDevInformation_t pRemDevInf, uint8_t *pBuff, uint16_t wLen ) { NFCSTATUS status = NFCSTATUS_SUCCESS; uint8_t *pRfNtfBuff = NULL; uint8_t RfTechSpecParamsLen = 0; uint8_t ActvnParamsLen = 0; PH_LOG_NCI_FUNC_ENTRY(); if((0 != (wLen)) && (NULL != pBuff) && (NULL != pRemDevInf)) { /* No Technology specific parameters incase of Listen A as per NCI Spec */ RfTechSpecParamsLen = pBuff[6]; /* Shift the buffer pointer points to first parameter of technology specific parameters */ pRfNtfBuff = &pBuff[7]; /* The activated remote device is a P2P Initiator */ (pRemDevInf->RemDevType) = phNciNfc_eNfcIP1_Initiator; /* NOTE: NO TECHNOLOGY SPECIFIC PARAMETERS ARE DEFINED FOR LISTEN NFC-A TECHN (as per Nci Spec Rev.21) */ /* Initiator speed (Initiator to target speed) */ pRemDevInf->tRemoteDevInfo.NfcIP_Info.Nfcip_Datarate = (phNciNfc_BitRates_t)pRemDevInf->bTransBitRate; switch(pRemDevInf->eRFTechMode) { case phNciNfc_NFCA_Active_Listen: case phNciNfc_NFCF_Active_Listen: pRemDevInf->tRemoteDevInfo.NfcIP_Info.Nfcip_Active = 1; /* Active communciation */ break; default: pRemDevInf->tRemoteDevInfo.NfcIP_Info.Nfcip_Active = 0; /* Passive communciation */ break; } /* Obtain the length of Activation parameters from pBuff */ ActvnParamsLen = pBuff[7+RfTechSpecParamsLen+PH_NCINFCTYPES_DATA_XCHG_PARAMS_LEN]; /* Holds ATR_RES if remote device is a P2P target and ATR_REQ if remote device is a P2P initiator */ if(0 != ActvnParamsLen) { pRemDevInf->tRemoteDevInfo.NfcIP_Info.bATRInfo_Length = (ActvnParamsLen-1); pRfNtfBuff = &(pBuff[7+RfTechSpecParamsLen+PH_NCINFCTYPES_DATA_XCHG_PARAMS_LEN+2]); phOsalNfc_SetMemory(pRemDevInf->tRemoteDevInfo.NfcIP_Info.aAtrInfo,0, PH_NCINFCTYPES_ATR_MAX_LEN); if(pRemDevInf->tRemoteDevInfo.NfcIP_Info.bATRInfo_Length <= PH_NCINFCTYPES_ATR_MAX_LEN) { phOsalNfc_MemCopy(pRemDevInf->tRemoteDevInfo.NfcIP_Info.aAtrInfo, pRfNtfBuff,pRemDevInf->tRemoteDevInfo.NfcIP_Info.bATRInfo_Length); } else { pRemDevInf->tRemoteDevInfo.NfcIP_Info.bATRInfo_Length = 0; PH_LOG_NCI_CRIT_STR("Invalid ATR_INFO length"); status = NFCSTATUS_FAILED; } } /* The Activated device is a P2P Initiator. The P2P 'Send' and 'Receive' functions shall be active. The P2P Target (i.e., us) is expected to receive data from remote P2P initiator and expected to send data to Remote P2P target in response */ } else { status = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_INFO_STR(" Invalid Params.."); } PH_LOG_NCI_FUNC_EXIT(); return status; }
static NFCSTATUS phNciNfc_ProcessInitRsp(void *pContext, NFCSTATUS Status) { NFCSTATUS wStatus = Status; phNciNfc_sInitRspParams_t *pInitRsp = NULL; pphNciNfc_Context_t pNciContext = pContext; uint8_t Offset = 0; uint16_t wTemp = 0; PH_LOG_NCI_FUNC_ENTRY(); if(NULL != pNciContext) { pInitRsp = &(pNciContext->InitRspParams); if (pNciContext->RspBuffInfo.wLen >= 19) { if (pNciContext->RspBuffInfo.pBuff[Offset++] == PH_NCINFC_STATUS_OK) { wStatus = NFCSTATUS_SUCCESS; /*NFCC Features*/ pInitRsp->NfccFeatures.DiscConfSuprt = pNciContext->RspBuffInfo.pBuff[Offset++]; pInitRsp->NfccFeatures.RoutingType = pNciContext->RspBuffInfo.pBuff[Offset++]; pInitRsp->NfccFeatures.PwrOffState = pNciContext->RspBuffInfo.pBuff[Offset++]; pInitRsp->NfccFeatures.Byte3 = pNciContext->RspBuffInfo.pBuff[Offset++]; /*number of supported RF interfaces*/ pInitRsp->NoOfRfIfSuprt = pNciContext->RspBuffInfo.pBuff[Offset++]; if(pInitRsp->NoOfRfIfSuprt <= PH_NCINFC_CORE_MAX_SUP_RF_INTFS) { /*Supported RF Interfaces */ phOsalNfc_MemCopy(pInitRsp->RfInterfaces, &(pNciContext->RspBuffInfo.pBuff[Offset]), pInitRsp->NoOfRfIfSuprt); Offset += pInitRsp->NoOfRfIfSuprt; /*Max No of Logical Connection supported*/ pInitRsp->MaxLogicalCon = pNciContext->RspBuffInfo.pBuff[Offset++]; /*Routing Table Size*/ pInitRsp->RoutingTableSize = pNciContext->RspBuffInfo.pBuff[Offset++]; /*LSB*/ wTemp = pNciContext->RspBuffInfo.pBuff[Offset++]; pInitRsp->RoutingTableSize = (pInitRsp->RoutingTableSize) | (wTemp << 8); /*Control Packet Payload Length*/ pInitRsp->CntrlPktPayloadLen = pNciContext->RspBuffInfo.pBuff[Offset++]; /*Max Size For Large parameter*/ pInitRsp->MaxSizeLarge = pNciContext->RspBuffInfo.pBuff[Offset++]; /*LSB*/ wTemp = (uint16_t)pNciContext->RspBuffInfo.pBuff[Offset++]; pInitRsp->MaxSizeLarge = (pInitRsp->MaxSizeLarge) | (wTemp << 8); /*Manufacturer ID*/ pInitRsp->ManufacturerId = pNciContext->RspBuffInfo.pBuff[Offset++]; if(pInitRsp->ManufacturerId != 0x00) { /*Decided by Manufacturer*/ pInitRsp->ManufacturerInfo.Byte0 = pNciContext->RspBuffInfo.pBuff[Offset++]; pInitRsp->ManufacturerInfo.Byte1 = pNciContext->RspBuffInfo.pBuff[Offset++]; pInitRsp->ManufacturerInfo.Byte2 = pNciContext->RspBuffInfo.pBuff[Offset++]; pInitRsp->ManufacturerInfo.Byte3 = pNciContext->RspBuffInfo.pBuff[Offset++]; } wStatus = phNciNfc_CoreIfSetMaxCtrlPacketSize(&(pNciContext->NciCoreContext), pInitRsp->CntrlPktPayloadLen); } else { PH_LOG_NCI_CRIT_STR("Invalid number of supported Rf interfaces"); wStatus = NFCSTATUS_FAILED; } } else { wStatus = NFCSTATUS_FAILED; } } else { wStatus = NFCSTATUS_FAILED; } if((NFCSTATUS_SUCCESS == wStatus) && (0 == pNciContext->tInitInfo.bSkipRegisterAllNtfs)) { wStatus = phNciNfc_RegAllNtfs(pNciContext); if(NFCSTATUS_SUCCESS == wStatus) { pNciContext->dwNtfTimerId = phOsalNfc_Timer_Create(); if(PH_OSALNFC_TIMER_ID_INVALID == pNciContext->dwNtfTimerId) { PH_LOG_NCI_CRIT_STR("Notification Timer Create failed!!"); wStatus = NFCSTATUS_INSUFFICIENT_RESOURCES; } else { PH_LOG_NCI_INFO_STR("Notification Timer Created Successfully"); } } } } else { wStatus = NFCSTATUS_INVALID_PARAMETER; } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
NFCSTATUS phNciNfc_RegForConnCredits( uint8_t bConnId, pphNciNfc_ConnCreditsNtf_t pNotify, void *pContext, uint32_t CreditTo ) { NFCSTATUS wStatus = NFCSTATUS_SUCCESS; uint8_t bConnListIdx; uint32_t TimerId; PH_LOG_NCI_FUNC_ENTRY(); if((NULL == pNotify) || (NULL == pContext)) { wStatus = PHNFCSTVAL(CID_NFC_NCI, NFCSTATUS_INVALID_PARAMETER); PH_LOG_NCI_INFO_STR(" Invalid Caller Layer Param(s) received .."); } else { for(bConnListIdx = 0; bConnListIdx < (MAX_LOGICAL_CONNS+1) ; bConnListIdx++) { if(bConnId == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bConnId) { if((TRUE == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].bIfActive) || (CONNTYPE_STATIC == gphNciNfc_ConnMgmtInt.tConnInfo.tConnList[bConnListIdx].tConn.bConnId)) { wStatus = NFCSTATUS_SUCCESS; } else { PH_LOG_NCI_CRIT_STR(" Interface not active for this connection"); wStatus = NFCSTATUS_FAILED; } break; } } if(NFCSTATUS_SUCCESS == wStatus) { gphNciNfc_ConnMgmtInt.bConnId = bConnId; gphNciNfc_ConnMgmtInt.pCrdtsNotify = pNotify; gphNciNfc_ConnMgmtInt.pContext = pContext; TimerId = phOsalNfc_Timer_Create(); if (0 == TimerId) { PH_LOG_NCI_WARN_STR("Credit wait Timer Create failed!!"); wStatus = NFCSTATUS_INSUFFICIENT_RESOURCES; } else { PH_LOG_NCI_INFO_STR("Credit wait Timer Created Successfully"); gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId = TimerId; gphNciNfc_ConnMgmtInt.tCWTimerIf.TimerStatus = 0; PH_LOG_NCI_INFO_STR("Credit timeout set to %d, for ConnId 0x%x",CreditTo, bConnId); wStatus = phOsalNfc_Timer_Start(gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId, CreditTo, &phNciNfc_WaitCreditTimerCb, &gphNciNfc_ConnMgmtInt); if (NFCSTATUS_SUCCESS == wStatus) { PH_LOG_NCI_INFO_STR("Credit wait timer started.."); gphNciNfc_ConnMgmtInt.tCWTimerIf.TimerStatus = 1; /* Set the CreditsAwaited flag to indicate credit notif function to call the registered CB */ gphNciNfc_ConnMgmtInt.bCreditsAwaited = TRUE; } else { PH_LOG_NCI_WARN_STR("Failed to start credit ntf wait timer!"); (void )phOsalNfc_Timer_Delete(gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId); gphNciNfc_ConnMgmtInt.tCWTimerIf.dwTimerId = 0; wStatus = NFCSTATUS_FAILED; } } } } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
static NFCSTATUS phNciNfc_CoreUtilsValidateNtfPktOID(uint8_t bGID, uint8_t bOID) { NFCSTATUS bRetNfcStat = NFCSTATUS_FAILED; PH_LOG_NCI_FUNC_ENTRY(); /* Check whether the OID of the received packet is within the * allowed range w.r.t GID of the notification packet */ if(bGID == phNciNfc_e_CoreNciCoreGid) { switch(bOID) { case phNciNfc_e_NciCoreResetNtfOid: case phNciNfc_e_NciCoreConnCreditNtfOid: case phNciNfc_e_NciCoreGenericErrNtfOid: case phNciNfc_e_NciCoreInterfaceErrNtfOid: bRetNfcStat = NFCSTATUS_SUCCESS; break; default: PH_LOG_NCI_CRIT_STR("Unknown OID received"); break; } } else if(bGID == phNciNfc_e_CoreRfMgtGid) { switch(bOID) { case phNciNfc_e_RfMgtRfGetListenModeRoutingNtfOid: case phNciNfc_e_RfMgtRfDiscoverNtfOid: case phNciNfc_e_RfMgtRfIntfActivatedNtfOid: case phNciNfc_e_RfMgtRfDeactivateNtfOid: case phNciNfc_e_RfMgtRfFieldInfoNtfOid: case phNciNfc_e_RfMgtRfT3tPollingNtfOid: case phNciNfc_e_RfMgtRfNfceeActionNtfOid: case phNciNfc_e_RfMgtRfNfceeDiscoveryReqNtfOid: case phNciNfc_e_RfMgtRfIsoDepPresChkNtfOid: bRetNfcStat = NFCSTATUS_SUCCESS; break; default: PH_LOG_NCI_CRIT_STR("Unknown OID received"); break; } } else if(bGID == phNciNfc_e_CoreNfceeMgtGid) { switch(bOID) { case phNciNfc_e_NfceeMgtNfceeDiscNtfOid: case phNciNfc_e_NfceeMgtModeSetNtfOid: case phNciNfc_e_NfceeMgtStatusNtfOid: bRetNfcStat = NFCSTATUS_SUCCESS; break; default: PH_LOG_NCI_CRIT_STR("Unknown OID received"); break; } } else if(bGID == phNciNfc_e_CorePropGid) { switch(bOID) { case phNciNfc_e_CorePropIsoDepPrsnChkNtfOid: case phNciNfc_e_CorePropTestSwpNtfOid: case phNciNfc_e_CorePropTagDetectorNtfOid: bRetNfcStat = NFCSTATUS_SUCCESS; break; default: PH_LOG_NCI_CRIT_STR("Unknown OID received"); break; } } else { /* (Proprietary - yet to be implemented) */ } PH_LOG_NCI_FUNC_EXIT(); return bRetNfcStat; }
static NFCSTATUS phNciNfc_ValidateIfActParams(uint8_t *pNtfBuff, uint16_t wSize) { NFCSTATUS wStatus = NFCSTATUS_SUCCESS; uint8_t bRfDiscId; phNciNfc_RfInterfaces_t eRfIf; phNciNfc_RfProtocols_t eRFProtocol; phNciNfc_RfTechMode_t eActvdRFTechMode; uint8_t bMaxDataPayLoadSize; uint8_t bInitialCredit; uint8_t bTechSpecificParamLen; phNciNfc_RfTechMode_t eDataXchgRFTechMode; uint8_t bTransBitRate; uint8_t bRecvBitRate; uint16_t wOffset = 0; PH_LOG_NCI_FUNC_ENTRY(); if((NULL != pNtfBuff) && (0 != wSize)) { bRfDiscId = pNtfBuff[wOffset++]; eRfIf = (phNciNfc_RfInterfaces_t) pNtfBuff[wOffset++]; eRFProtocol = (phNciNfc_RfProtocols_t) pNtfBuff[wOffset++]; eActvdRFTechMode = (phNciNfc_RfTechMode_t) pNtfBuff[wOffset++]; bMaxDataPayLoadSize = pNtfBuff[wOffset++]; bInitialCredit = pNtfBuff[wOffset++]; UNREFERENCED_PARAMETER(bInitialCredit); bTechSpecificParamLen = pNtfBuff[wOffset++]; wOffset += bTechSpecificParamLen; eDataXchgRFTechMode = (phNciNfc_RfTechMode_t) pNtfBuff[wOffset++]; bTransBitRate = pNtfBuff[wOffset++]; bRecvBitRate = pNtfBuff[wOffset]; if((bRfDiscId < 1) || (bRfDiscId > PHNCINFC_RF_DISCOVERY_ID_MAX)) { PH_LOG_NCI_CRIT_STR("Invalid RfDiscId!"); wStatus = NFCSTATUS_INVALID_PARAMETER; } else if(phNciNfc_ValidateRfInterface(eRfIf)) { wStatus = NFCSTATUS_INVALID_PARAMETER; PH_LOG_NCI_CRIT_STR("Invalid RfInterface!"); } else if(phNciNfc_ValidateRfProtocol(eRFProtocol)) { PH_LOG_NCI_CRIT_STR("Invalid RfProtocol!"); wStatus = NFCSTATUS_INVALID_PARAMETER; } else if(phNciNfc_ValidateRfTechMode(eActvdRFTechMode)) { PH_LOG_NCI_CRIT_STR("Invalid Actv Rf Tech and mode received!"); wStatus = NFCSTATUS_INVALID_PARAMETER; } else if(phNciNfc_ValidateRfTechMode(eDataXchgRFTechMode)) { PH_LOG_NCI_CRIT_STR("Invalid DataXchg Actv Rf Tech and mode received!"); wStatus = NFCSTATUS_INVALID_PARAMETER; } if((NFCSTATUS_SUCCESS == wStatus) && (bMaxDataPayLoadSize < PHNCINFC_MIN_DATA_PKT_PAYLOAD_SIZE)) { PH_LOG_NCI_CRIT_STR("Invalid Max Data packet Payload!"); wStatus = NFCSTATUS_INVALID_PARAMETER; } if(NFCSTATUS_SUCCESS == wStatus) { if(phNciNfc_ValidateBitRate(bTransBitRate) || phNciNfc_ValidateBitRate(bRecvBitRate)) { PH_LOG_NCI_CRIT_STR("Invalid BitRate!"); wStatus = NFCSTATUS_INVALID_PARAMETER; } else { /* Interface to Protocol mapping check */ if((phNciNfc_e_RfInterfacesISODEP_RF == eRfIf) && (phNciNfc_e_RfProtocolsIsoDepProtocol != eRFProtocol)) { PH_LOG_NCI_CRIT_STR("ISO DEP interface mapped to wrong protocol!"); wStatus = NFCSTATUS_INVALID_PARAMETER; } else if( (phNciNfc_e_RfInterfacesTagCmd_RF == eRfIf) &&\ (phNciNfc_e_RfProtocolsMifCProtocol != eRFProtocol) ) { PH_LOG_NCI_CRIT_STR("TagCmd interface mapped to wrong protocol!"); wStatus = NFCSTATUS_INVALID_PARAMETER; } else if((phNciNfc_e_RfInterfacesFrame_RF == eRfIf) &&\ (eActvdRFTechMode != phNciNfc_NFCISO15693_Poll)) { if((phNciNfc_e_RfProtocolsT1tProtocol == eRFProtocol) || (phNciNfc_e_RfProtocolsT2tProtocol == eRFProtocol) || (phNciNfc_e_RfProtocolsT3tProtocol == eRFProtocol) || (phNciNfc_e_RfProtocolsIsoDepProtocol == eRFProtocol)) { PH_LOG_NCI_INFO_STR("Valid Frame-RF interface to protocol mapping!"); } else { PH_LOG_NCI_CRIT_STR("Frame-RF interface mapped to wrong protocol!"); wStatus = NFCSTATUS_INVALID_PARAMETER; } } else if((phNciNfc_e_RfInterfacesNFCDEP_RF == eRfIf) && (phNciNfc_e_RfProtocolsNfcDepProtocol != eRFProtocol)) { wStatus = NFCSTATUS_INVALID_PARAMETER; PH_LOG_NCI_CRIT_STR("NFC DEP interface mapped to wrong protocol!"); } else { PH_LOG_NCI_INFO_STR("Interface activated ntf parameter validation success"); } } } } else { wStatus = NFCSTATUS_INVALID_PARAMETER; } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
NFCSTATUS phNciNfc_SeSendData(void* pNciCtx, void* pSeHandle, pphNciNfc_IfNotificationCb_t pSendCb, void* pContext, phNfc_sData_t *pSendData) { NFCSTATUS wStatus = NFCSTATUS_SUCCESS; phNciNfc_CoreTxInfo_t TxInfo; uint16_t wPldDataSize; phNciNfc_Context_t* pNciContext = (phNciNfc_Context_t *)pNciCtx; PH_LOG_NCI_FUNC_ENTRY(); if((NULL == pNciContext) || (pNciContext != phNciNfc_GetContext())) { PH_LOG_NCI_CRIT_STR("Stack not initialized"); wStatus = NFCSTATUS_NOT_INITIALISED; } else if((NULL == pSendData) || (NULL == pSendCb)) { wStatus = NFCSTATUS_INVALID_PARAMETER; PH_LOG_NCI_CRIT_STR("Invalid input parameter!"); } else { if((0 == pSendData->length) || (NULL == pSendData->buffer)) { PH_LOG_NCI_CRIT_STR("Invalid Send buffer!"); wStatus = NFCSTATUS_FAILED; } else { /* Fill the data packet details into TxInfo */ TxInfo.tHeaderInfo.eMsgType = phNciNfc_e_NciCoreMsgTypeData; if (!phNciNfc_IsVersion1x(pNciContext)) { TxInfo.tHeaderInfo.bConn_ID = CONNHCITYPE_STATIC; } else { wStatus = phNciNfc_GetConnId(pSeHandle, &(TxInfo.tHeaderInfo.bConn_ID)); } if(NFCSTATUS_SUCCESS == wStatus) { wPldDataSize = (uint16_t)pSendData->length; (pNciContext->tTranscvCtxt.tSendPld.wLen) = 0; (pNciContext->tTranscvCtxt.tSendPld.pBuff) = (uint8_t *)phOsalNfc_GetMemory(wPldDataSize); if(NULL != (pNciContext->tTranscvCtxt.tSendPld.pBuff)) { (pNciContext->tTranscvCtxt.tSendPld.wLen) = (wPldDataSize); phOsalNfc_SetMemory((pNciContext->tTranscvCtxt.tSendPld.pBuff),0, (pNciContext->tTranscvCtxt.tSendPld.wLen)); /* Copy data to be sent to the local buffer */ phOsalNfc_MemCopy((pNciContext->tTranscvCtxt.tSendPld.pBuff), (pSendData->buffer),wPldDataSize); TxInfo.Buff = (pNciContext->tTranscvCtxt.tSendPld.pBuff); TxInfo.wLen = (pNciContext->tTranscvCtxt.tSendPld.wLen); /* Send data */ wStatus = phNciNfc_CoreIfTxOnly(&(pNciContext->NciCoreContext), &TxInfo, (pphNciNfc_CoreIfNtf_t)&phNciNfc_SeSendCb, pNciContext); if(NFCSTATUS_PENDING == wStatus) { /* Store upper layer call back function and upper layer context */ phNciNfc_SetUpperLayerCallback(pNciContext, pSendCb, pContext); } else { /* Deallocate memory allcoated for send buffer */ phOsalNfc_FreeMemory(pNciContext->tTranscvCtxt.tSendPld.pBuff); pNciContext->tTranscvCtxt.tSendPld.pBuff = NULL; pNciContext->tTranscvCtxt.tSendPld.wLen = 0; } } else { wStatus = NFCSTATUS_INSUFFICIENT_RESOURCES; PH_LOG_NCI_CRIT_STR("Payload MemAlloc for Send request Failed!"); } } else { wStatus = NFCSTATUS_FAILED; PH_LOG_NCI_CRIT_STR(" Couldn't Get ConnId!"); } } } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
static NFCSTATUS phNciNfc_CoreInvokeCb(pphNciNfc_CoreRegInfo_t pRegList, NFCSTATUS wStatus, pphNciNfc_CoreRegInfo_t pRegInfo, phNciNfc_NciCoreMsgType_t eMsgType, phNciNfc_TransactInfo_t *pTransInfo) { uint8_t bIndex = 0; uint8_t bCount = 0; uint8_t bRegExist = 0; uint8_t bGetEmptySlot = 0; NFCSTATUS wStat = NFCSTATUS_FAILED; pphNciNfc_CoreRegRspNtfInfo_t pRegRspNtfList = NULL; pphNciNfc_CoreRegDataInfo_t pRegDataList = NULL; pphNciNfc_CoreIfNtf_t IfNtfCb = NULL; void *pIfNtfCtx = NULL; PH_LOG_NCI_FUNC_ENTRY(); if((phNciNfc_e_NciCoreMsgTypeCntrlRsp == eMsgType) || (phNciNfc_e_NciCoreMsgTypeData == eMsgType)) { /* Only one entry shall exist per GID and OID or ConnID */ wStat = phNciNfc_CoreGetIndex(bGetEmptySlot,pRegList,pRegInfo,eMsgType,&bIndex); if(NFCSTATUS_SUCCESS == wStat) { if(phNciNfc_e_NciCoreMsgTypeCntrlRsp == eMsgType) { pRegRspNtfList = (pphNciNfc_CoreRegRspNtfInfo_t) pRegList; if(NULL != pRegRspNtfList[bIndex].pNotifyCb) { IfNtfCb = pRegRspNtfList[bIndex].pNotifyCb; pIfNtfCtx = pRegRspNtfList[bIndex].pContext; bRegExist = 1; PH_LOG_NCI_INFO_STR("Registered Rsp call back function invoked"); } else { PH_LOG_NCI_CRIT_STR("Registered Rsp call back function invoke failed-Invalid fnc pointer!"); } /* Check if auto de-registration is enabled */ if((0 != bRegExist) && (pRegRspNtfList[bIndex].bEnabled == PHNCINFC_ENABLE_AUTO_DEREG)) { pRegRspNtfList[bIndex].bEnabled = PHNCINFC_CORE_DISABLE_REG_ENTRY; pRegRspNtfList[bIndex].bGid = phNciNfc_e_CoreInvalidGid; pRegRspNtfList[bIndex].bOid = phNciNfc_e_NciCoreInvalidOid; pRegRspNtfList[bIndex].pContext = NULL; pRegRspNtfList[bIndex].pNotifyCb = NULL; PH_LOG_NCI_INFO_STR("Response call back de-registered as auto de-register is enabled"); } } else { pRegDataList = (pphNciNfc_CoreRegDataInfo_t) pRegList; if(NULL != pRegDataList[bIndex].pNotifyCb) { IfNtfCb = pRegDataList[bIndex].pNotifyCb; pIfNtfCtx = pRegDataList[bIndex].pContext; bRegExist = 1; PH_LOG_NCI_INFO_STR("Registered Data call back function invoked"); } else { PH_LOG_NCI_CRIT_STR("Registered Data call back function invoke failed-Invalid fnc pointer!"); } /* Check if auto de-registration is enabled */ if((0 != bRegExist) && (pRegDataList[bIndex].bEnabled == PHNCINFC_ENABLE_AUTO_DEREG)) { pRegDataList[bIndex].bEnabled = PHNCINFC_CORE_DISABLE_REG_ENTRY; pRegDataList[bIndex].bConnId = 0; pRegDataList[bIndex].pContext = NULL; pRegDataList[bIndex].pNotifyCb = NULL; PH_LOG_NCI_INFO_STR("Data call back de-registered as auto de-register is enabled"); } } if(NULL != IfNtfCb) { IfNtfCb(pIfNtfCtx, pTransInfo, wStatus); } } else { PH_LOG_NCI_INFO_STR("Response/Data call back not registered"); } } else /* phNciNfc_e_NciCoreMsgTypeCntrlNtf == eMsgType */ { pRegRspNtfList = (pphNciNfc_CoreRegRspNtfInfo_t) pRegList; /* Invoke registered call back functions as multiple registrations can exist */ for(bCount = 0; bCount < PHNCINFC_CORE_MAX_NTF_REGS; bCount++) { wStat = phNciNfc_CoreGetIndex(bGetEmptySlot,pRegList,pRegInfo,eMsgType,&bIndex); if(NFCSTATUS_SUCCESS == wStat) { if(NULL != pRegRspNtfList[bIndex].pNotifyCb) { pRegRspNtfList[bIndex].pNotifyCb(pRegRspNtfList[bIndex].pContext,pTransInfo,wStatus); bRegExist = 1; PH_LOG_NCI_INFO_STR("Registered Ntf call back function invoked"); } else { bRegExist = 0; PH_LOG_NCI_INFO_STR("Registered Ntf call back function invok failed-Invalid fnc pointer"); } /* Check if auto de-registration is enabled */ if((0 != bRegExist) && (pRegRspNtfList[bIndex].bEnabled == PHNCINFC_ENABLE_AUTO_DEREG)) { pRegRspNtfList[bIndex].bEnabled = PHNCINFC_CORE_DISABLE_REG_ENTRY; pRegRspNtfList[bIndex].bGid = phNciNfc_e_CoreInvalidGid; pRegRspNtfList[bIndex].bOid = phNciNfc_e_NciCoreInvalidOid; pRegRspNtfList[bIndex].pContext = NULL; pRegRspNtfList[bIndex].pNotifyCb = NULL; PH_LOG_NCI_INFO_STR("Notification call back de-registered as auto de-register is enabled"); } bIndex++; if(bIndex == PHNCINFC_CORE_MAX_NTF_REGS) { break; } } else { PH_LOG_NCI_INFO_STR("End of list reached"); break; } } } if(1 == bRegExist) { wStat = NFCSTATUS_SUCCESS; } else { wStat = NFCSTATUS_FAILED; } PH_LOG_NCI_FUNC_EXIT(); return wStat; }
NFCSTATUS phNciNfc_CoreRecvManager(void *pCtx, NFCSTATUS wStatus, pphNciNfc_sCoreHeaderInfo_t pHdrInfo, phNciNfc_NciCoreMsgType_t eMsgType) { NFCSTATUS wStat = NFCSTATUS_INVALID_PARAMETER; phNciNfc_TransactInfo_t tTransInfo; void *pRegList = NULL; phNciNfc_CoreRegInfo_t tRegInfo; uint16_t wDataLen = 0; uint16_t wNumOfNode = 0; pphNciNfc_CoreContext_t pCoreCtx = (pphNciNfc_CoreContext_t) pCtx; PH_LOG_NCI_FUNC_ENTRY(); if((NULL != pCoreCtx) && (NULL != pHdrInfo)) { wStat = NFCSTATUS_SUCCESS; if((phNciNfc_e_NciCoreMsgTypeCntrlRsp == eMsgType) || (phNciNfc_e_NciCoreMsgTypeCntrlNtf == eMsgType)) { tRegInfo.bGid = (uint8_t)pHdrInfo->Group_ID; tRegInfo.bOid = (uint8_t)pHdrInfo->Opcode_ID.Val; if((phNciNfc_e_NciCoreMsgTypeCntrlRsp == eMsgType)) { PH_LOG_NCI_INFO_STR("Invoke response call back func if registered"); pRegList = (void *)pCoreCtx->tRspCtx.aRspRegList; } else { PH_LOG_NCI_INFO_STR("Invoke notification call back func if registered"); pRegList = (void *)pCoreCtx->tNtfCtx.aNtfRegList; } } else if(phNciNfc_e_NciCoreMsgTypeData == eMsgType) { PH_LOG_NCI_INFO_STR("Invoke data call back func if registered"); pRegList = (void *)pCoreCtx->tDataCtx.aDataRegList; tRegInfo.bConnId = pHdrInfo->bConn_ID; } else { wStat = NFCSTATUS_INVALID_PARAMETER; PH_LOG_NCI_CRIT_STR("Invalid message type!"); } if(NFCSTATUS_SUCCESS == wStat) { /* NOTE: For time being the following operations are being done at this location 1. Allocation of buffer for storing the extracted data from linked list 2. Extraction of received payload from linked list 3. Copy of extracted data to the allocated buffer #These operation shall be performed at the Nci module level call back in later point of time */ if(NFCSTATUS_SUCCESS != wStatus) { /* Response time out has happened */ tTransInfo.pbuffer = NULL; tTransInfo.wLength = 0; wStat = NFCSTATUS_SUCCESS; } else { tTransInfo.pbuffer = NULL; tTransInfo.wLength = 0; /* Get size of payload present in linked list */ wStat = phNciNfc_CoreGetDataLength(pCoreCtx,&wDataLen, &wNumOfNode); if(NFCSTATUS_SUCCESS == wStat) { PH_LOG_NCI_INFO_U32MSG("Message size received: ",wDataLen); if(wNumOfNode == 1) { /*May need seperate function for getting the pointer value*/ tTransInfo.pbuffer = &(pCoreCtx->tReceiveInfo.ListHead.tMem.aBuffer[PHNCINFC_CORE_PKT_HEADER_LEN]); tTransInfo.wLength = wDataLen; }else { /* Allocate memory for storing the payload */ tTransInfo.pbuffer = phOsalNfc_GetMemory(wDataLen); } if(NULL != tTransInfo.pbuffer) { tTransInfo.wLength = wDataLen; /* Extract the data from linked list and copy it to the allocated buffer */ wStat = phNciNfc_CoreGetData(pCoreCtx,tTransInfo.pbuffer,wDataLen); } } } if(NFCSTATUS_SUCCESS == wStat) { phNciNfc_PrintPacketDescription(pHdrInfo, tTransInfo.pbuffer, tTransInfo.wLength, pCoreCtx->bLogDataMessages); wStat = phNciNfc_CoreInvokeCb(pRegList,wStatus,&tRegInfo,eMsgType,&tTransInfo); } /* Free memory that had been allocated */ if((NULL != tTransInfo.pbuffer) && (wNumOfNode > 1)) { phOsalNfc_FreeMemory(tTransInfo.pbuffer); tTransInfo.pbuffer = NULL; tTransInfo.wLength = 0; } /* Delete linked list */ phNciNfc_CoreDeleteList(pCoreCtx); } } PH_LOG_NCI_FUNC_EXIT(); return wStat; }
static NFCSTATUS phNciNfc_CoreUtilsValidateRspPktOID(uint8_t bGID, uint8_t bOID) { NFCSTATUS bRetNfcStat = NFCSTATUS_FAILED; PH_LOG_NCI_FUNC_ENTRY(); /* Check whether the OID of the received packet is within the * allowed range w.r.t GID of the response packet */ if(bGID == phNciNfc_e_CoreNciCoreGid) { switch(bOID) { case phNciNfc_e_NciCoreResetRspOid: case phNciNfc_e_NciCoreInitRspOid: case phNciNfc_e_NciCoreSetConfigRspOid: case phNciNfc_e_NciCoreGetConfigRspOid: case phNciNfc_e_NciCoreDhConnRspOid: case phNciNfc_e_NciCoreConnCloseRspOid: case phNciNfc_e_NciCoreSetPowerSubStateRspOid: bRetNfcStat = NFCSTATUS_SUCCESS; break; default: PH_LOG_NCI_CRIT_STR("Unknown OID received"); break; } } else if(phNciNfc_e_CoreRfMgtGid == bGID) { switch(bOID) { case phNciNfc_e_RfMgtRfDiscoverMapRspOid: case phNciNfc_e_RfMgtRfSetRoutingRspOid: case phNciNfc_e_RfMgtRfGetRoutingRspOid: case phNciNfc_e_RfMgtRfDiscoverRspOid: case phNciNfc_e_RfMgtRfDiscSelectRspOid: case phNciNfc_e_RfMgtRfDeactivateRspOid: case phNciNfc_e_RfMgtRfT3tPollingRspOid: case phNciNfc_e_RfMgtRfParamUpdateRspOid: case phNciNfc_e_RfMgtRfIsoDepPresChkRspOid: bRetNfcStat = NFCSTATUS_SUCCESS; break; default: PH_LOG_NCI_CRIT_STR("Unknown OID received"); break; } } else if(phNciNfc_e_CoreNfceeMgtGid == bGID) { switch(bOID) { case phNciNfc_e_NfceeMgtNfceeDiscRspOid: case phNciNfc_e_NfceeMgtModeSetRspOid: case phNciNfc_e_NfceeMgtPowerAndLinkCtrlRspOid: bRetNfcStat = NFCSTATUS_SUCCESS; break; default: PH_LOG_NCI_CRIT_STR("Unknown OID received"); break; } } else if (phNciNfc_e_CorePropGid == bGID) { switch(bOID) { case phNciNfc_e_CorePropSetPwrModeRspOid: case phNciNfc_e_CorePropEnableExtnRspOid: case phNciNfc_e_CorePropIsoDepChkPresRspOid: case phNciNfc_e_CorePropDhListenFilterRspOid: case phNciNfc_e_CorePropTestSwpRspOid: case phNciNfc_e_CorePropTestPrbsRspOid: case phNciNfc_e_CorePropTestAntennaRspOid: bRetNfcStat = NFCSTATUS_SUCCESS; break; default: PH_LOG_NCI_CRIT_STR("Unknown OID received"); break; } } else { /* do nothing */ } PH_LOG_NCI_FUNC_EXIT(); return bRetNfcStat; }
NFCSTATUS phNciNfc_CoreUtilsUpdatePktInfo(pphNciNfc_CoreContext_t pContext, uint8_t *pBuff, uint16_t wLength) { uint8_t bMsgType = 0; uint8_t bGid = 0; uint8_t bOid = 0; uint8_t bConn_ID = 0; uint8_t bPayloadLen = 0; NFCSTATUS wStatus = NFCSTATUS_INVALID_PARAMETER; PH_LOG_NCI_FUNC_ENTRY(); if((NULL != pContext) && (NULL != pBuff)) { /* Verify payload length */ bPayloadLen = PHNCINFC_CORE_GET_LENBYTE(pBuff); if((PHNCINFC_CORE_PKT_HEADER_LEN + bPayloadLen) != wLength) { PH_LOG_NCI_CRIT_STR("Incorrect payload length"); wStatus = PH_NCINFC_STATUS_INVALID_PKT_LEN; } else { wStatus = NFCSTATUS_SUCCESS; } if(NFCSTATUS_SUCCESS == wStatus) { /* Get the Message Type from the received packet */ bMsgType = PHNCINFC_CORE_GET_MT(pBuff); switch(bMsgType) { case phNciNfc_e_NciCoreMsgTypeData: { bConn_ID = (uint8_t) PHNCINFC_CORE_GET_CONNID(pBuff); /* Update packet info with connection id */ pContext->tReceiveInfo.HeaderInfo.bConn_ID = bConn_ID; pContext->tReceiveInfo.HeaderInfo.Group_ID = phNciNfc_e_CoreNciCoreGid; pContext->tReceiveInfo.HeaderInfo.Opcode_ID.Val = 0; wStatus = PH_NCINFC_STATUS_OK; } break; case phNciNfc_e_NciCoreMsgTypeCntrlRsp: case phNciNfc_e_NciCoreMsgTypeCntrlNtf: { /* Get GID and OID of the received packet */ bGid = PHNCINFC_CORE_GET_GID(pBuff); bOid = PHNCINFC_CORE_GET_OID(pBuff); /* Validate GID */ wStatus = phNciNfc_CoreUtilsValidateGID(bGid); if(NFCSTATUS_SUCCESS == wStatus) { /* Validate for Oid */ wStatus = phNciNfc_CoreUtilsValidateCtrlPktOID(bMsgType, bGid, bOid); } else { PH_LOG_NCI_CRIT_STR("Unknown GID received"); } if(NFCSTATUS_SUCCESS == wStatus) { /* Update GID and OID values in packet info structure */ pContext->tReceiveInfo.HeaderInfo.Group_ID = (phNciNfc_CoreGid_t)bGid; pContext->tReceiveInfo.HeaderInfo.Opcode_ID.Val = bOid; pContext->tReceiveInfo.HeaderInfo.bConn_ID = 0; } } break; default: { PH_LOG_NCI_CRIT_STR("Invalid message type"); wStatus = PH_NCINFC_STATUS_INVALID_MT; } break; } } /* Update packet information */ if(PH_NCINFC_STATUS_OK == wStatus) { /*Update message type*/ pContext->tReceiveInfo.HeaderInfo.eMsgType = (phNciNfc_NciCoreMsgType_t)bMsgType; } } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
NFCSTATUS phNciNfc_ReceiveData(void *pNciCtx, pphNciNfc_IfNotificationCb_t pReceiveCb, void* pContext) { NFCSTATUS wStatus = NFCSTATUS_NOT_INITIALISED; phNciNfc_Context_t *pNciContext = (phNciNfc_Context_t *)pNciCtx; pphNciNfc_ActiveDeviceInfo_t pActivDev = NULL; phNciNfc_sCoreHeaderInfo_t tRegInfo; uint8_t bConnId; uint8_t bFreeTempBuff = 0; PH_LOG_NCI_FUNC_ENTRY(); if((NULL == pNciContext) || (pNciContext != phNciNfc_GetContext())) { PH_LOG_NCI_CRIT_STR("Stack not initialized"); } else if(NULL == pReceiveCb) { wStatus = NFCSTATUS_INVALID_PARAMETER; PH_LOG_NCI_CRIT_STR("Invalid input parameter (Nci Context)!"); } else { /* Store upper layer call back function and upper layer context */ phNciNfc_SetUpperLayerCallback(pNciContext, pReceiveCb, pContext); /* Check whether data has been received from remote device already */ if(1 == pNciContext->tLstnModeRecvInfo.bDataBuffEnable) { /* Data has already been received and stored in temporary buffer. Instead of registering for the data message which has already been received, queue a deferred callback */ wStatus = phOsalNfc_QueueDeferredCallback(phNciNfc_TempReceiveCb, pNciContext); if(NFCSTATUS_SUCCESS == wStatus) { wStatus = NFCSTATUS_PENDING; } else { bFreeTempBuff = 1; } pNciContext->tLstnModeRecvInfo.bDataBuffEnable = 0; if(1 == bFreeTempBuff) { pNciContext->IfNtf = NULL; pNciContext->IfNtfCtx = NULL; if(NULL != pNciContext->tLstnModeRecvInfo.pBuff) { phOsalNfc_FreeMemory(pNciContext->tLstnModeRecvInfo.pBuff); pNciContext->tLstnModeRecvInfo.pBuff = NULL; } pNciContext->tLstnModeRecvInfo.wBuffSize = 0; pNciContext->tLstnModeRecvInfo.wLstnCbStatus = NFCSTATUS_FAILED; } } else { pActivDev = (pphNciNfc_ActiveDeviceInfo_t)&pNciContext->tActvDevIf; wStatus = phNciNfc_GetConnId(pActivDev->pDevInfo,&bConnId); /* If dummy data receive call back function is still registered, unregister the same first*/ if(NFCSTATUS_SUCCESS == wStatus) { tRegInfo.bConn_ID = bConnId; tRegInfo.eMsgType = phNciNfc_e_NciCoreMsgTypeData; /* UnRegister for Data message (with auto de-register enabled) */ (void)phNciNfc_CoreIfUnRegRspNtf(&(pNciContext->NciCoreContext), &(tRegInfo),&phNciNfc_ReceiveDataBufferCb); } /*Now register for the data message */ if(NFCSTATUS_SUCCESS == wStatus) { tRegInfo.bEnabled = (uint8_t)PHNCINFC_ENABLE_AUTO_DEREG; tRegInfo.eMsgType = phNciNfc_e_NciCoreMsgTypeData; tRegInfo.bConn_ID= bConnId; /* Register for Data message (with auto de-register enabled) */ wStatus = phNciNfc_CoreIfRegRspNtf((void *)&pNciContext->NciCoreContext, &tRegInfo, &phNciNfc_ReceiveCb, pNciContext); if(NFCSTATUS_SUCCESS == wStatus) { /* Data message call back registered successfully, send pending status to upper layer */ wStatus = NFCSTATUS_PENDING; } else { pNciContext->IfNtf = NULL; pNciContext->IfNtfCtx = NULL; PH_LOG_NCI_CRIT_STR("Data message call back registration failed!"); wStatus = NFCSTATUS_FAILED; } } else { pNciContext->IfNtf = NULL; pNciContext->IfNtfCtx = NULL; PH_LOG_NCI_CRIT_STR("Couldn't Get ConnId!"); wStatus = NFCSTATUS_FAILED; } } } PH_LOG_NCI_FUNC_EXIT(); return wStatus; }
void phNciNfc_GetRfDevType(uint8_t bRespVal, uint8_t bRespLen, pphNciNfc_RemoteDevInformation_t pRemDevInf, phNciNfc_RFDevType_t *pDevType) { PH_LOG_NCI_FUNC_ENTRY(); if((NULL != pRemDevInf) && (NULL != pDevType)) { /* Technology and mode of local device (NFCC) */ if(phNciNfc_NFCA_Poll == pRemDevInf->eRFTechMode) { /* If length of select response is '0', remote device is of 'Jewel' type */ if(0 != bRespLen) { if((phNciNfc_e_RfInterfacesNFCDEP_RF == pRemDevInf->eRfIf) && (phNciNfc_e_RfProtocolsNfcDepProtocol == pRemDevInf->eRFProtocol)) { /* Remote device is a P2P Target */ *pDevType = phNciNfc_eNfcIP1_Target; } else { PH_LOG_NCI_INFO_X32MSG("SAK Received",(SEL_RESP_CONFIG_MASK & bRespVal)); switch(bRespVal & SEL_RESP_CONFIG_MASK) { /* Ref: section 4.8.2 of [DIGITAL] */ case 0: /* Configured for Type 2 Tag Platform */ { *pDevType = phNciNfc_eMifareUL_PICC; PH_LOG_NCI_INFO_STR(" MifareUL tag detected.."); break; } case MIFARE_1K_SAK: case MIFARE_1K_SAK88: case MIFARE_1K_SAK28: case MIFARE_1K_CLASSIC_SAK: { if((phNciNfc_e_RfInterfacesISODEP_RF == pRemDevInf->eRfIf) && (phNciNfc_e_RfProtocolsIsoDepProtocol == pRemDevInf->eRFProtocol)) { /* Remote device is a phNciNfc_eISO14443_4A_PICC*/ *pDevType = phNciNfc_eISO14443_4A_PICC; PH_LOG_NCI_INFO_STR("4A tag detected.."); } else { *pDevType = phNciNfc_eMifare1k_PICC; PH_LOG_NCI_INFO_STR(" Mifare1k tag detected.."); } } break; case MIFARE_4K_SAK: case MIFARE_4K_SAK38: case MIFARE_4K_SAK98: case MIFARE_4K_SAKB8: { *pDevType = phNciNfc_eMifare4k_PICC; PH_LOG_NCI_INFO_STR(" Mifare4k tag detected.."); } break; case MIFARE_MINI_SAK: { *pDevType = phNciNfc_eMifareMini_PICC; PH_LOG_NCI_INFO_STR(" Mifare Mini tag detected.."); } break; case 0x24: case 0x20: /* Configured for Type 4A Tag Platform */ case 0x60: /* FIXME: Workaround to enable CE when ISODEP & NFCDEP is enabled */ case 0x68: { *pDevType = phNciNfc_eISO14443_4A_PICC; PH_LOG_NCI_INFO_STR(" 4A tag detected.."); break; } default: { *pDevType = phNciNfc_eUnknown_DevType; PH_LOG_NCI_INFO_STR(" Unknown tag detected.."); break; } } } } else { /* Type 1 Tag type [TODO?] Temporary type assigned below */ *pDevType = phNciNfc_eJewel_PICC; PH_LOG_NCI_INFO_STR(" Type 1 Tag detected.."); } } else if((phNciNfc_NFCA_Active_Listen == pRemDevInf->eRFTechMode) || (phNciNfc_NFCF_Active_Listen == pRemDevInf->eRFTechMode) || (phNciNfc_NFCA_Listen == pRemDevInf->eRFTechMode)) { if((phNciNfc_e_RfInterfacesNFCDEP_RF == pRemDevInf->eRfIf) && (phNciNfc_e_RfProtocolsNfcDepProtocol == pRemDevInf->eRFProtocol)) { /* Remote device is a P2P Initiator */ *pDevType = phNciNfc_eNfcIP1_Initiator; } else { PH_LOG_NCI_CRIT_STR("Nfc-A Listen mode notification - unknown"); } } else if(phNciNfc_NFCB_Poll == pRemDevInf->eRFTechMode) { if(bRespVal & 0x01) { PH_LOG_NCI_INFO_STR(" 4B tag detected.."); *pDevType = phNciNfc_eISO14443_4B_PICC; } else { /* Todo:- Non ISO14443 B card detected,exact name to be updated */ *pDevType = phNciNfc_eUnknown_DevType; } } else if((phNciNfc_NFCF_Poll == pRemDevInf->eRFTechMode) || (phNciNfc_NFCF_Active_Poll == pRemDevInf->eRFTechMode)) { if(phNciNfc_e_RfProtocolsNfcDepProtocol == pRemDevInf->eRFProtocol) { /* Remote device is a P2P Target */ *pDevType = phNciNfc_eNfcIP1_Target; } } else if((phNciNfc_NFCA_Active_Poll == pRemDevInf->eRFTechMode) ) { if(phNciNfc_e_RfProtocolsNfcDepProtocol == pRemDevInf->eRFProtocol) { /* Remote device is a P2P Target */ *pDevType = phNciNfc_eNfcIP1_Target; } } else { /* Other types */ } } else { PH_LOG_NCI_CRIT_STR("Invalid Input Parameter"); } PH_LOG_NCI_FUNC_EXIT(); }