Exemple #1
0
phStatus_t phalI15693_Sw_GetSystemInformation(
    phalI15693_Sw_DataParams_t * pDataParams,
    uint8_t ** ppRxBuffer,
    uint16_t * pRxLength
    )
{
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM bCommand[1];
    uint8_t     PH_MEMLOC_REM bExpLength;

    /* Build command */
    bCommand[0] = PHAL_I15693_SW_CMD_GET_SYSTEM_INFO;

    /* Clear Option bit */
    PH_CHECK_SUCCESS_FCT(statusTmp, phalI15693_Sw_Int_SetOptionBit(pDataParams, PHAL_I15693_OPTION_OFF));

    /* Set short timeout. */
    PH_CHECK_SUCCESS_FCT(statusTmp, phpalSli15693_SetConfig(
        pDataParams->pPalSli15693DataParams,
        PHPAL_SLI15693_CONFIG_TIMEOUT_US,
        PHPAL_SLI15693_TIMEOUT_SHORT_US));

    /* Proceed with the command in lower layers */
    PH_CHECK_SUCCESS_FCT(statusTmp, phpalSli15693_Exchange(
        pDataParams->pPalSli15693DataParams,
        PH_EXCHANGE_DEFAULT,
        bCommand,
        1,
        ppRxBuffer,
        pRxLength));

    /* Check number of data received */
    if (*pRxLength == 0)
    {
        return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_AL_I15693);
    }

    /* Expected length is 9 by default */
    bExpLength = 9;

    /* Check for DSFID byte */
    if ((*ppRxBuffer[0]) & PHAL_I15693_INFO_FLAGS_DSFID)
    {
        ++bExpLength;
    }

    /* Check for AFI byte */
    if ((*ppRxBuffer[0]) & PHAL_I15693_INFO_FLAGS_AFI)
    {
        ++bExpLength;
    }

    /* Check for MEMSIZE bytes */
    if ((*ppRxBuffer[0]) & PHAL_I15693_INFO_FLAGS_MEMSIZE)
    {
        bExpLength += 2;
    }

    /* Check for ICREF byte */
    if ((*ppRxBuffer[0]) & PHAL_I15693_INFO_FLAGS_ICREF)
    {
        ++bExpLength;
    }

    /* Check response length */
    if (*pRxLength < bExpLength)
    {
        return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_AL_I15693);
    }

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_I15693);
}
Exemple #2
0
phStatus_t phalMfdf_Int_ComputeErrorResponse(
    void * pDataParams,
    uint16_t wStatus
    )
{
    phStatus_t  PH_MEMLOC_REM status = PH_ERR_SUCCESS;
    phStatus_t  PH_MEMLOC_REM statusTmp;

    switch (wStatus)
    {
    case PHAL_MFDF_RESP_OPERATION_OK:
    case PHAL_MFDF_ISO7816_SUCCESS:
        status = PH_ERR_SUCCESS;
        break;

    case PHAL_MFDF_RESP_NO_CHANGES:
        status = PHAL_MFDF_NO_CHANGES;
        break;

    case PHAL_MFDF_RESP_ERR_OUT_OF_EEPROM_ERROR:
        status = PHAL_MFDF_ERR_OUT_OF_EEPROM_ERROR;
        break;

    case PHAL_MFDF_RESP_ERR_INTEGRITY_ERROR:
        status = PHAL_MFDF_ERR_PICC_CRYPTO;
        break;

    case PHAL_MFDF_RESP_ERR_PARAMETER_ERROR:
        status = PHAL_MFDF_ERR_PARAMETER_ERROR;
        break;

    case PHAL_MFDF_RESP_NO_SUCH_KEY:
        status = PHAL_MFDF_ERR_NO_SUCH_KEY;
        break;

    case PHAL_MFDF_RESP_ERR_LENGTH_ERROR:
        status = PH_ERR_LENGTH_ERROR;
        break;

    case PHAL_MFDF_RESP_PERMISSION_DENIED:
        status = PHAL_MFDF_ERR_PERMISSION_DENIED;
        break;

    case PHAL_MFDF_RESP_APPLICATION_NOT_FOUND:
        status = PHAL_MFDF_ERR_APPLICATION_NOT_FOUND;
        break;

    case PHAL_MFDF_RESP_ERR_AUTHENTICATION_ERROR:
        status = PH_ERR_AUTH_ERROR;
        break;

    case PHAL_MFDF_RESP_ADDITIONAL_FRAME:
        status = PH_ERR_SUCCESS_CHAINING;
        break;

    case PHAL_MFDF_RESP_ERR_BOUNDARY_ERROR:
        status = PHAL_MFDF_ERR_BOUNDARY_ERROR;
        break;

    case PHAL_MFDF_RESP_ERR_COMMAND_ABORTED:
        status = PHAL_MFDF_ERR_COMMAND_ABORTED;
        break;

    case PHAL_MFDF_RESP_ERR_COUNT:
        status = PHAL_MFDF_ERR_COUNT;
        break;

    case PHAL_MFDF_RESP_ERR_DUPLICATE:
        status = PHAL_MFDF_ERR_DUPLICATE;
        break;

    case PHAL_MFDF_RESP_ERR_FILE_NOT_FOUND:
        status = PHAL_MFDF_ERR_FILE_NOT_FOUND;
        break;

    case PHAL_MFDF_RESP_ERR_APPL_INTEGRITY_ERROR:
    case PHAL_MFDF_RESP_ERR_PICC_INTEGRITY:
    case PHAL_MFDF_RESP_ERR_EEPROM:
    case PHAL_MFDF_RESP_ERR_FILE_INTEGRITY:
    case PHAL_MFDF_RESP_ERR_PIC_DISABLED:
    case PHAL_MFDF_RESP_ILLEGAL_COMMAND_CODE:
        status = PHAL_MFDF_ERR_DF_GEN_ERROR;
        PH_CHECK_SUCCESS_FCT(statusTmp, phalMfdf_SetConfig(
            pDataParams,
            PHAL_MFDF_ADDITIONAL_INFO,
            wStatus));
        break;

    case PHAL_MFDF_ISO7816_ERR_WRONG_LENGTH:
    case PHAL_MFDF_ISO7816_ERR_WRONG_LE:
    case PHAL_MFDF_ISO7816_ERR_FILE_NOT_FOUND:
    case PHAL_MFDF_ISO7816_ERR_WRONG_PARAMS:
    case PHAL_MFDF_ISO7816_ERR_WRONG_LC:
    case PHAL_MFDF_ISO7816_ERR_NO_PRECISE_DIAGNOSTICS:
    case PHAL_MFDF_ISO7816_ERR_EOF_REACHED:
    case PHAL_MFDF_ISO7816_ERR_FILE_ACCESS:
    case PHAL_MFDF_ISO7816_ERR_FILE_EMPTY:
    case PHAL_MFDF_ISO7816_ERR_MEMORY_FAILURE:
    case PHAL_MFDF_ISO7816_ERR_INCORRECT_PARAMS:
    case PHAL_MFDF_ISO7816_ERR_WRONG_CLA:
    case PHAL_MFDF_ISO7816_ERR_UNSUPPORTED_INS:
        status = PHAL_MFDF_ERR_DF_7816_GEN_ERROR;
        PH_CHECK_SUCCESS_FCT(statusTmp, phalMfdf_SetConfig(
            pDataParams,
            PHAL_MFDF_ADDITIONAL_INFO,
            wStatus));
        break;

    default:
        status = PH_ERR_PROTOCOL_ERROR;
    }
    return PH_ADD_COMPCODE(status, PH_COMP_AL_MFDF);
}
Exemple #3
0
/* SNEP Client Initialization API */
phStatus_t phnpSnep_Client_Init( void                           *pDataParams,
                                phnpSnep_Fri_Config_t           *pConfigInfo,
                                ph_NfcHandle                     hRemDevHandle,
                                pphnpSnep_Fri_ConnectCB_t        pConnClientCb,
                                phnpSnep_Fri_ClientSession_t    *pClient,
                                void                            *pContext)
{
    phStatus_t status = PH_ERR_SUCCESS;

    PH_LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "phnpSnep_Client_Init");
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pConfigInfo);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pConnClientCb);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pClientSession);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pContext);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(status);
    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_ENTER);
    PH_ASSERT_NULL (pDataParams);
    PH_ASSERT_NULL (pConfigInfo);
    PH_ASSERT_NULL (pConnClientCb);
    PH_ASSERT_NULL (pClient);
    PH_ASSERT_NULL (pContext);


    /* Check data parameters */
    if (PH_GET_COMPCODE(pDataParams) != PH_COMP_NP_SNEP)
    {
        status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_NP_SNEP);

        PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
        PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
        PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);
        return status;
    }

    /* perform operation on active layer */
    switch (PH_GET_COMPID(pDataParams))
    {
#ifdef NXPBUILD__PHNP_SNEP_FRI
    case PHNP_SNEP_FRI_ID:
    status = phnpSnep_Fri_Client_Init( pDataParams,
                                       pConfigInfo,
                                       hRemDevHandle,
                                       pConnClientCb,
                                       pClient,
                                       pContext
                                      );
        break;
#endif /* NXPBUILD__PHNP_SNEP_FRI */

    default:
        status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_NP_SNEP);
        break;
    }

    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);


    return status;

}
Exemple #4
0
phStatus_t phbalReg_GetPortList(
                                void * pDataParams,
                                uint16_t wPortBufSize,
                                uint8_t * pPortNames,
                                uint16_t * pNumOfPorts
                                )
{
    phStatus_t PH_MEMLOC_REM status;
#ifdef NXPBUILD__PH_LOG
    uint16_t PH_MEMLOC_REM wCnt;
    uint16_t PH_MEMLOC_REM wLen;
#endif /* NXPBUILD__PH_LOG */

    PH_LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "phbalReg_GetPortList");
    /*PH_LOG_HELPER_ALLOCATE_PARAMNAME(pDataParams);*/
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(wPortBufSize);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pPortNames);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pNumOfPorts);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(status);
    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_DEBUG, wPortBufSize_log, &wPortBufSize);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_ENTER);
    PH_ASSERT_NULL (pDataParams);
    PH_ASSERT_NULL (pPortNames);
    PH_ASSERT_NULL (pNumOfPorts);

    /* Check data parameters */
    if (PH_GET_COMPCODE(pDataParams) != PH_COMP_BAL)
    {
		status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_BAL);

        PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
        PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
        PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

        return status; 
    }

    /* perform operation on active layer */
    switch (PH_GET_COMPID(pDataParams))
    {
#ifdef NXPBUILD__PHBAL_REG_STUB
    case PHBAL_REG_STUB_ID:
        status = phbalReg_Stub_GetPortList((phbalReg_Stub_DataParams_t*)pDataParams, wPortBufSize, pPortNames, pNumOfPorts);
        break;
#endif /* NXPBUILD__PHBAL_REG_STUB */

#ifdef NXPBUILD__PHBAL_REG_LPC1768SPI
    case PHBAL_REG_LPC1768SPI_ID:
        status = phbalReg_Lpc1768Spi_GetPortList((phbalReg_Lpc1768Spi_DataParams_t *)pDataParams, wPortBufSize, pPortNames, pNumOfPorts);
        break;
#endif /* NXPBUILD__PHBAL_REG_LPC1768SPI */

#ifdef NXPBUILD__PHBAL_REG_LPC1768I2C
    case PHBAL_REG_LPC1768I2C_ID:
        status = phbalReg_Lpc1768I2c_GetPortList((phbalReg_Lpc1768I2c_DataParams_t *)pDataParams, wPortBufSize, pPortNames, pNumOfPorts);
        break;
#endif /* NXPBUILD__PHBAL_REG_LPC1768SPI */

    default:
        status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_BAL);
        break;
    }

    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
#ifdef NXPBUILD__PH_LOG
    if ((status & PH_ERR_MASK) == PH_ERR_SUCCESS)
    {
        for (wCnt = 0; wCnt < *pNumOfPorts; wCnt++)
        {
            wLen = (uint16_t)strlen((char*)pPortNames);
            PH_LOG_HELPER_ADDPARAM_BUFFER(PH_LOG_LOGTYPE_DEBUG, pPortNames_log, pPortNames, wLen);
            pPortNames += wLen;
        }
    }
#endif /* NXPBUILD__PH_LOG */
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_DEBUG, pNumOfPorts_log, pNumOfPorts);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

    return status;
}
Exemple #5
0
/*
*
* Should take care of wrapping and unwrapping if ISO 7816 Wrapped mode
* Does not handle any chaining or CMAC generation/verification or encryption/decryption
*/
phStatus_t phalMfdf_ExchangeCmd(
                                void * pDataParams, 
                                void * pPalMifareDataParams,
                                uint8_t bWrappedMode,
                                uint8_t * pSendBuff,
                                uint16_t wCmdLen,
                                uint8_t * pResponse,
                                uint16_t * pRxlen
                                )
{
    uint16_t    PH_MEMLOC_REM wFrameLen;
    uint8_t     PH_MEMLOC_REM * pRecv;
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM bStatusByte = 0xFF;
    uint8_t     PH_MEMLOC_REM pApdu[5] = { PHAL_MFDF_WRAPPEDAPDU_CLA, 0x00, PHAL_MFDF_WRAPPEDAPDU_P1, PHAL_MFDF_WRAPPEDAPDU_P2, 0x00 };

    if (bWrappedMode)
    {
        wFrameLen = PHAL_MFDF_MAXWRAPPEDAPDU_SIZE;
    }
    else
    {
        wFrameLen = PHAL_MFDF_MAXDFAPDU_SIZE;
    }

    if (wCmdLen > wFrameLen)
    {
        return PH_ADD_COMPCODE(PH_ERR_BUFFER_OVERFLOW, PH_COMP_AL_MFDF);
    }

    /* Send the data to PICC */
    if (bWrappedMode)
    {
        pApdu[1] = pSendBuff[0]; /* Desfire cmd code in INS */
        pApdu[4] = (uint8_t)(wCmdLen) - 0x01u;

        PH_CHECK_SUCCESS_FCT(statusTmp, phpalMifare_ExchangeL4(
            pPalMifareDataParams,
            pApdu[4] == 0x00 ? PH_EXCHANGE_DEFAULT : PH_EXCHANGE_BUFFER_FIRST,
            pApdu,
            PHAL_MFDF_WRAP_HDR_LEN,
            &pRecv,
            pRxlen));

        if (pApdu[4] != 0x00)
        {
            PH_CHECK_SUCCESS_FCT(statusTmp,  phpalMifare_ExchangeL4(
                pPalMifareDataParams,
                PH_EXCHANGE_BUFFER_CONT,
                &pSendBuff[1],
                wCmdLen - 1,
                &pRecv,
                pRxlen));

            /* Le byte */
            PH_CHECK_SUCCESS_FCT(statusTmp, phpalMifare_ExchangeL4(
                pPalMifareDataParams,
                PH_EXCHANGE_BUFFER_LAST,
                &pApdu[2], /* Le is always zero in wrapped mode. */
                0x01,
                &pRecv,
                pRxlen));
        }
    }
    else
    {
        PH_CHECK_SUCCESS_FCT(statusTmp, phpalMifare_ExchangeL4(
            pPalMifareDataParams,
            PH_EXCHANGE_DEFAULT,
            pSendBuff,
            wCmdLen,
            &pRecv,
            pRxlen));
    }
    if (bWrappedMode)
    {
        memcpy(pResponse, pRecv, (*pRxlen) - 2); /* PRQA S 3200 */
        bStatusByte = pRecv[(*pRxlen) - 1];
        (*pRxlen) -= 2;
    } 
    else 
    {
        memcpy(pResponse, &pRecv[1], (*pRxlen) - 1); /* PRQA S 3200 */
        bStatusByte = pRecv[0];
        (*pRxlen) -= 1;
    }
    return phalMfdf_Int_ComputeErrorResponse(pDataParams, bStatusByte);
}
phStatus_t phalTop_Sw_Int_T4T_CheckNdef(
                                        phalTop_T4T_t * pT4T,
                                        uint8_t * pNdefPresence
                                        )
{
    uint16_t PH_MEMLOC_REM status;
    uint16_t PH_MEMLOC_REM pBytesRead;
    uint8_t  PH_MEMLOC_REM *ppRxBuffer;
    uint8_t  PH_MEMLOC_REM aFid_MApp[2] = {0x00, 0x3F}; /* Master Application ISO File ID */
    uint8_t  PH_MEMLOC_REM aFid_CC[2] = {0x03, 0xE1};
    uint8_t  PH_MEMLOC_REM aNdefApp_Name[7] = {0xD2, 0x76, 0x00,        /**< DF Name buffer */
                                               0x00, 0x85, 0x01, 0x01};
    uint8_t  PH_MEMLOC_REM aNdefApp_Len = 0X07;
    uint8_t  PH_MEMLOC_REM *pFCI;
    uint16_t PH_MEMLOC_REM *pwFCILen = 0;
    uint16_t PH_MEMLOC_REM wNdef_Fid;
    uint16_t PH_MEMLOC_REM wErrorCode;
    phalMfdf_Sw_DataParams_t PH_MEMLOC_REM *pMfdf;
    pMfdf = (phalMfdf_Sw_DataParams_t *)(pT4T->phalT4TDataParams);

    pMfdf->bWrappedMode = 1;
    pT4T->bNdefSupport = PH_UNSUPPORTED;
    pT4T->bNdefFormatted = PH_UNSUPPORTED;
    pT4T->bNdefPresence = false;
    *pNdefPresence = PH_OFF;

    /* Select the NDEF Tag Application with ISO File id of the Application */
    status = phalMfdf_IsoSelectFile(
        pT4T->phalT4TDataParams,
        PH_EXCHANGE_DEFAULT,
        0x04,
        0,                                          /* Look for File ID of 0xE105 */
        aNdefApp_Name,
        aNdefApp_Len,
        &pFCI,
        pwFCILen
        );
    if((status & PH_ERR_MASK) == PH_ERR_IO_TIMEOUT)
    {
        return status;
    }

    /* If No Valid Application is found then Format to make Tag as NDEF */
    wErrorCode = pMfdf->wAdditionalInfo;
    if(wErrorCode == 0x6A82)                             /* PHAL_MFDF_ISO7816_ERR_FILE_NOT_FOUND = 0x6A82*/
    {
        PH_CHECK_SUCCESS_FCT(status, phalTop_Sw_Int_T4T_FormatNdef(pT4T));
        PH_CHECK_SUCCESS_FCT(status, phalMfdf_IsoSelectFile(
            pT4T->phalT4TDataParams,
            PH_EXCHANGE_DEFAULT,
            0x04,
            0,
            aNdefApp_Name,
            aNdefApp_Len,
            &pFCI,
            pwFCILen
            ));
    }

    if((status & PH_ERR_MASK) == PH_ERR_SUCCESS)
    {
    	pT4T->bNdefFormatted = PH_SUPPORTED;

        /* Select the Capability Container (CC) file once NDEF Tag Application is selected */
        PH_CHECK_SUCCESS_FCT(status, phalMfdf_IsoSelectFile(
            pT4T->phalT4TDataParams,
            0x0C,                              /* If bOption == 00 FCI(file control info) is returned. If 0x0C no FCI returned */
            0x00,
            aFid_CC,                                          /* Look for File ID of 0xE103 */
            NULL,
            0x00,
            &pFCI,
            pwFCILen
            ));

        /* Read the CC file and select the NDEF file */
        PH_CHECK_SUCCESS_FCT(status, phalMfdf_IsoReadBinary(
            pT4T->phalT4TDataParams,
            PH_EXCHANGE_DEFAULT,
            0x00,                                             /* File offset where to start reading data */
            0x00,
            0x0F,                                             /* number of bytes to read. If 0, then entire file to be read */
            &ppRxBuffer,
            &pBytesRead
            ));

        pT4T->wCCLEN = ((uint16_t)ppRxBuffer[PHAL_TOP_T4T_CCLEN_OFFSET] << 8) | ppRxBuffer[PHAL_TOP_T4T_CCLEN_OFFSET + 1];
        if(pT4T->wCCLEN < 0x000F)
        {
            return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_AL_TOP);
        }

        if(ppRxBuffer[PHAL_TOP_T4T_NDEFTLV_OFFSET] == PHAL_TOP_T4T_NDEF_TLV)
        {
            pT4T->bRa = ppRxBuffer[PHAL_TOP_T4T_NDEFTLV_OFFSET + 6];

            if(pT4T->bRa == PHAL_TOP_T4T_NDEF_FILE_READ)
            {
                pT4T->bWa = ppRxBuffer[PHAL_TOP_T4T_NDEFTLV_OFFSET + 7];
                pT4T->bVno = ppRxBuffer[PHAL_TOP_T4T_VERSION_OFFSET];
                /* Read NDEF File ID from CC */
                pT4T->bNdef_FileID[0] = ppRxBuffer[PHAL_TOP_T4T_NDEFTLV_OFFSET + 3];    /* MSB of bNdef_FileID */
                pT4T->bNdef_FileID[1] = ppRxBuffer[PHAL_TOP_T4T_NDEFTLV_OFFSET + 2];    /* LSB of bNdef_FileID */
                pT4T->bMaxFileSize = ((uint16_t)ppRxBuffer[PHAL_TOP_T4T_NDEFTLV_OFFSET + 4] << 8) | ppRxBuffer[PHAL_TOP_T4T_NDEFTLV_OFFSET + 5];

                wNdef_Fid = ((uint16_t)pT4T->bNdef_FileID[1] << 8) | pT4T->bNdef_FileID[0];

                if(!((wNdef_Fid == 0x0000) ||
                    (wNdef_Fid == 0xE102) ||
                    (wNdef_Fid == 0xE103) ||
                    (wNdef_Fid == 0x3F00) ||
                    (wNdef_Fid == 0x3FFF)))
                {
                    /* select the NDEF file  */
                    PH_CHECK_SUCCESS_FCT(status, phalMfdf_IsoSelectFile(
                        pT4T->phalT4TDataParams,
                        0x0C,
                        0x00,
                        pT4T->bNdef_FileID,
                        NULL,
                        0x00,
                        &pFCI,
                        pwFCILen
                        ));

                    /* Read the NDEF file */
                    PH_CHECK_SUCCESS_FCT(status, phalMfdf_IsoReadBinary(
                        pT4T->phalT4TDataParams,
                        PH_EXCHANGE_DEFAULT,
                        0x00,                                 /* File offset where to start reading data */
                        0x00,
                        0x02,                                 /* number of bytes to read. If 0, then entire file to be read */
                        &ppRxBuffer,
                        &pBytesRead
                        ));

                    pT4T->bNdefSupport = PH_SUPPORTED;
                    pT4T->wNLEN = ((uint16_t)ppRxBuffer[0] << 8) | ppRxBuffer[1];

                    if((pT4T->wNLEN > 0x0000) && (pT4T->wNLEN <= (pT4T->bMaxFileSize - 2)))
                    {
                        pT4T->bNdefPresence = true;
                        *pNdefPresence = PH_ON;

                        if(pT4T->bWa == PHAL_TOP_T4T_NDEF_FILE_NO_WRITE_ACCESS)
                        {
                            pT4T->bTagState = PHAL_TOP_T4T_STATE_READONLY;
                        }
                        else if(pT4T->bWa == PHAL_TOP_T4T_NDEF_FILE_WRITE_ACCESS)
                        {
                            pT4T->bTagState = PHAL_TOP_T4T_STATE_READWRITE;
                        }
                        else
                        {
                            pT4T->bTagState = PHAL_TOP_T4T_STATE_UNKNOWN;
                        }
                    }
                    else if((pT4T->wNLEN == 0x0000) || (pT4T->wNLEN > (pT4T->bMaxFileSize - 2)))
                    {
                        pT4T->bNdefSupport = PH_SUPPORTED;
                        pT4T->bTagState = PHAL_TOP_T4T_STATE_INITIALIZED;
                    }
                    else
                    {
                        /* Do Nothing */
                    }
                }
                else
                {
                    return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_AL_TOP);
                }
            }
            else
            {
                return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_AL_TOP);
            }
        }
        else
        {
            return PH_ADD_COMPCODE(PHAL_TOP_T4T_ERR_NO_NDEF_TLV, PH_COMP_AL_TOP);
        }

        /* Select the Master Tag Application with ISO File ID (0x3F00) of the Application */
        PH_CHECK_SUCCESS_FCT(status, phalMfdf_IsoSelectFile(
            pT4T->phalT4TDataParams,
            0x0C,
            0x00,
            aFid_MApp,
            NULL,
            0x00,
            &pFCI,
            pwFCILen
            ));
    }
    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_TOP);
}
Exemple #7
0
phStatus_t phbalReg_SetPort(
                            void * pDataParams,
                            uint8_t * pPortName
                            )
{
    phStatus_t PH_MEMLOC_REM status;

    PH_LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "phbalReg_SetPort");
    /*PH_LOG_HELPER_ALLOCATE_PARAMNAME(pDataParams);*/
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pPortName);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(status);
    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_BUFFER(PH_LOG_LOGTYPE_DEBUG, pPortName_log, pPortName, (uint16_t)strlen((char*)pPortName));
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_ENTER);
    PH_ASSERT_NULL (pDataParams);
    PH_ASSERT_NULL (pPortName);

    /* Check data parameters */
    if (PH_GET_COMPCODE(pDataParams) != PH_COMP_BAL)
    {
		status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_BAL);

        PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
        PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
        PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

        return status;
    }

    /* perform operation on active layer */
    switch (PH_GET_COMPID(pDataParams))
    {
#ifdef NXPBUILD__PHBAL_REG_STUB
    case PHBAL_REG_STUB_ID:
        status = phbalReg_Stub_SetPort((phbalReg_Stub_DataParams_t*)pDataParams, pPortName);
        break;
#endif /* NXPBUILD__PHBAL_REG_STUB */

#ifdef NXPBUILD__PHBAL_REG_LPC1768SPI
    case PHBAL_REG_LPC1768SPI_ID:
        status = phbalReg_Lpc1768Spi_SetPort((phbalReg_Lpc1768Spi_DataParams_t *)pDataParams, pPortName);
        break;
#endif /* NXPBUILD__PHBAL_REG_LPC1768SPI */

#ifdef NXPBUILD__PHBAL_REG_LPC1768I2C
    case PHBAL_REG_LPC1768I2C_ID:
        status = phbalReg_Lpc1768I2c_SetPort((phbalReg_Lpc1768I2c_DataParams_t *)pDataParams, pPortName);
        break;
#endif /* NXPBUILD__PHBAL_REG_LPC1768SPI */

    default:
        status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_BAL);
        break;
    }

    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

    return status;
}
Exemple #8
0
phStatus_t phalTop_Sw_Int_T3T_CheckNdef(
                                        phalTop_T3T_t * pT3T,
                                        uint8_t * pNdefPresence
                                        )
{
    phStatus_t PH_MEMLOC_REM status;
    uint8_t    PH_MEMLOC_REM wLength;
    uint8_t    PH_MEMLOC_REM bNDEFSystemCode[2] = { 0x12, 0xFC};
    uint8_t    PH_MEMLOC_REM bSystemCode[2] = { 0x88, 0xB4};
    uint8_t    PH_MEMLOC_REM wMoreCardsAvailable;
    uint8_t    PH_MEMLOC_REM bBlockList[2] = { 0x80, 0x00};   /* Read Zero Block to get Attribute Block */
    uint8_t    PH_MEMLOC_REM bMCBlockList[2] = { 0x80, 0x88}; /* Memory Configuration(MC) Block is 88h */
    uint8_t    PH_MEMLOC_REM bReadServiceList[2] = { 0x0B, 0x00};
    uint8_t    PH_MEMLOC_REM bRxNumBlocks = 0;
    uint8_t    PH_MEMLOC_REM bBlockData[16];

    *pNdefPresence = PH_OFF;
    pT3T->bNdefPresence = PH_OFF;
    pT3T->bNdefSupport = PH_UNSUPPORTED;
    pT3T->bNdefFormatted = PH_UNSUPPORTED;

    status = phalFelica_ActivateCard(
        pT3T->phalT3TDataParams,
        bNDEFSystemCode,
        0X00,
        pT3T->bUid,
        &wLength,
        &wMoreCardsAvailable);

    if ((status & PH_ERR_MASK) == PH_ERR_SUCCESS)
    {
        pT3T->bNdefSupport = PH_SUPPORTED;
        pT3T->bNdefFormatted = PH_SUPPORTED;

        PH_CHECK_SUCCESS_FCT(status, phalFelica_Read(
            pT3T->phalT3TDataParams,
            0x01,
            bReadServiceList,
            0x01,
            bBlockList,
            0x02,
            &bRxNumBlocks,
            bBlockData));

        pT3T->bVno = bBlockData[0];
        pT3T->bNbr = bBlockData[1];
        pT3T->bNbw = bBlockData[2];
        pT3T->bNmaxb = (uint16_t)(((uint16_t)bBlockData[3] << 8) | bBlockData[4]);
        pT3T->bRwa = bBlockData[10];
        pT3T->wNdefLength = (uint16_t)(((uint32_t)bBlockData[11] << 16) | (((uint16_t)bBlockData[12] << 8) | bBlockData[13]));

        if((pT3T->wNdefLength != 0) && ((pT3T->bVno == PHAL_TOP_T3T_NDEF_SUPPORTED_VNO1)
            || (pT3T->bVno == PHAL_TOP_T3T_NDEF_SUPPORTED_VNO2)))
        {
            pT3T->bNdefPresence = PH_ON;
            *pNdefPresence = PH_ON;

            if(pT3T->bRwa == PHAL_TOP_T3T_AIB_RWA_RW)
            {
                pT3T->bTagState = PHAL_TOP_T3T_STATE_READWRITE;
            }
            else if(pT3T->bRwa == PHAL_TOP_T3T_AIB_RWA_RO)
            {
                pT3T->bTagState = PHAL_TOP_T3T_STATE_READONLY;
            }
            else
            {
                /* Do Nothing */
            }
        }
        else if(pT3T->wNdefLength == 0)
        {
            pT3T->bTagState = PHAL_TOP_T3T_STATE_INITIALIZED;
        }
        else
        {
            /* Do Nothing */
        }
    }
    else
    {
        /* Check if the Tag is Formattable or not and update NdefSupport flag */
        status = phalFelica_ActivateCard(
            pT3T->phalT3TDataParams,
            bSystemCode,
            0,                                                    /* Time Slot */
            pT3T->bUid,
            &wLength,
            &wMoreCardsAvailable);
        if ((status & PH_ERR_MASK) != PH_ERR_SUCCESS)
        {
        	/* This is not a valid T3T TAG. */
        	return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_TOP);
    }

        /* Read MC(Memory Configuration) Block to get SYS_OP Value */
        PH_CHECK_SUCCESS_FCT(status, phalFelica_Read(
            pT3T->phalT3TDataParams,
            0x01,
            bReadServiceList,
            0x01,
            bMCBlockList,
            0x02,
            &bRxNumBlocks,
            bBlockData));

        if((bBlockData[0] == 0xFF) && (bBlockData[1] == 0xFF) && (bBlockData[2] == 0xFF)
            && (bBlockData[3] == 0x00) && (bBlockData[4] == 0xFF))
        {
        	pT3T->bNdefFormatted = PH_SUPPORTED;
        }
        else if((bBlockData[0] == 0xFF) && (bBlockData[1] == 0xFF) && (bBlockData[2] == 0xFF)
            && (bBlockData[3] == 0x01) && (bBlockData[4] == 0xFF))
        {
        	pT3T->bNdefFormatted = PH_SUPPORTED;
        }
        else
        {
        	pT3T->bNdefFormatted = PH_UNSUPPORTED;
        }
    }
    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_TOP);
}
Exemple #9
0
phStatus_t phalTop_Sw_Int_T3T_WriteNdef(
                                        phalTop_T3T_t * pT3T,
                                        uint8_t * pData,
                                        uint16_t wLength
                                        )
{
    phStatus_t PH_MEMLOC_REM status;
    uint16_t   PH_MEMLOC_REM wTempIndex;
    uint16_t   PH_MEMLOC_REM wIndex;
    uint16_t   PH_MEMLOC_REM wCheckSum;
    uint8_t    PH_MEMLOC_REM bBlockData[16];
    uint8_t    PH_MEMLOC_REM bAttBlock[2] = { 0x80, 0x00};   /* Read Zero Block to get Attribute Block */
    uint8_t    PH_MEMLOC_REM bBlockList[2] = { 0x80, 0x01};  /* First Block to Write Ndef Data */
    uint8_t    PH_MEMLOC_REM bReadServiceList[2] = { 0x0B, 0x00};
    uint8_t    PH_MEMLOC_REM bWriteServiceList[2] = { 0x09, 0x00};
    uint8_t    PH_MEMLOC_REM bRxNumBlocks = 0;


    if(!((pT3T->bNdefFormatted == PH_SUPPORTED) || (pT3T->bNdefSupport == PH_SUPPORTED)))
    {
        return PH_ADD_COMPCODE(PHAL_TOP_ERR_NOT_FORMATTED, PH_COMP_AL_TOP);
    }

    /* Check NDEF length */
    if((wLength > (pT3T->bNmaxb * PHAL_TOP_T3T_BLOCK_SIZE)) || (wLength == 0))
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_AL_TOP);
    }

    /* Read and Update Attribute Block before Writing NDEF */
    PH_CHECK_SUCCESS_FCT(status, phalFelica_Read(
        pT3T->phalT3TDataParams,
        0x01,
        bReadServiceList,
        0x01,                                                /* wNoBlocks */
        bAttBlock,
        0x02,
        &bRxNumBlocks,
        bBlockData));

    if(bBlockData[0x0A] != PHAL_TOP_T3T_AIB_RWA_RW)
    {
        return PH_ADD_COMPCODE(PHAL_TOP_ERR_READONLY_TAG, PH_COMP_AL_TOP);
    }

    bBlockData[PHAL_TOP_T3T_WRITE_FLAG_ADDRESS] = PHAL_TOP_T3T_WRITE_FLAG_SET;
    bBlockData[11] = 0x00U;
    bBlockData[12] = 0x00U;
    bBlockData[13] = 0x00U;

    /* Calculate CheckSum */
    for(wIndex = 0, wCheckSum = 0; wIndex < 14; wIndex++)
    {
        wCheckSum += bBlockData[wIndex];
    }
    bBlockData[14] = (uint8_t)(wCheckSum >> 8);
    bBlockData[15] = (uint8_t)(wCheckSum & 0x00FF);

    PH_CHECK_SUCCESS_FCT(status, phalFelica_Write(
        pT3T->phalT3TDataParams,
        0x01,
        bWriteServiceList,
        0x01,
        bAttBlock,
        0x02,
        bBlockData));

    /* Write NDEF Data */
    for(wIndex = 0, wTempIndex = 0;
        wIndex < (wLength / PHAL_TOP_T3T_BLOCK_SIZE);
        wIndex++)
    {
        memcpy(&bBlockData[0], &pData[wTempIndex], PHAL_TOP_T3T_BLOCK_SIZE);    /* PRQA S 3200 */

        PH_CHECK_SUCCESS_FCT(status, phalFelica_Write(
            pT3T->phalT3TDataParams,
            0x01,
            bWriteServiceList,
            0x01,
            bBlockList,
            0x02,
            bBlockData));

        wTempIndex += 16;
        if(bBlockList[1] == 0xFF)
        {
            bBlockList[0] += 1;
        }
        else
        {
            bBlockList[1] += 1;
        }
    }

    /* Write the remaining NDEF bytes in the Last Block after adding padding bytes */
    wIndex = wLength % PHAL_TOP_T3T_BLOCK_SIZE;
    if (wIndex != 0)
    {
        memcpy(&bBlockData[0], &pData[wTempIndex], wIndex);     /* PRQA S 3200 */
        memset(&bBlockData[wIndex], 0x00, PHAL_TOP_T3T_BLOCK_SIZE - wIndex);    /* PRQA S 3200 */
        wTempIndex = wTempIndex + wIndex;

        PH_CHECK_SUCCESS_FCT(status, phalFelica_Write(
            pT3T->phalT3TDataParams,
            0x01,
            bWriteServiceList,
            0x01,
            bBlockList,
            0x02,
            bBlockData));
    }

    /* User NDEF Lenght should be equal to Written NDEF Lenght */
    if(wLength != wTempIndex)
    {
        return PH_ADD_COMPCODE(PH_ERR_READ_WRITE_ERROR, PH_COMP_AL_TOP);
    }

    /* Read and Update Attribute Block after Writing NDEF */
    PH_CHECK_SUCCESS_FCT(status, phalFelica_Read(
        pT3T->phalT3TDataParams,
        0x01,
        bReadServiceList,
        0x01,
        bAttBlock,
        0x02,
        &bRxNumBlocks,
        bBlockData));

    bBlockData[PHAL_TOP_T3T_WRITE_FLAG_ADDRESS] = PHAL_TOP_T3T_WRITE_FLAG_RESET;
    bBlockData[11] = 0x00U;                          /* As the User is able to input 16bit Lenght Upper byte of Ln is 0x00. */
    bBlockData[12] = (uint8_t)(wTempIndex >> 8);
    bBlockData[13] = (uint8_t)(wTempIndex & 0x00FF);

    /* Calculate CheckSum */
    for(wIndex = 0, wCheckSum = 0; wIndex < 14; wIndex++)
    {
        wCheckSum += bBlockData[wIndex];
    }
    bBlockData[14] = (uint8_t)(wCheckSum >> 8);
    bBlockData[15] = (uint8_t)(wCheckSum & 0x00FF);

    PH_CHECK_SUCCESS_FCT(status, phalFelica_Write(
        pT3T->phalT3TDataParams,
        0x01,
        bWriteServiceList,
        0x01,
        bAttBlock,
        0x02,
        bBlockData));

    pT3T->bTagState = PHAL_TOP_T3T_STATE_READWRITE;
    pT3T->wNdefLength = wLength;
    pT3T->bNdefPresence = PH_ON;

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_TOP);
}
Exemple #10
0
phStatus_t phalTop_Sw_Int_T3T_FormatNdef(
    phalTop_T3T_t * pT3T
    )
{
    phStatus_t PH_MEMLOC_REM status;
    uint16_t   PH_MEMLOC_REM wIndex;
    uint16_t   PH_MEMLOC_REM wCheckSum;
    uint8_t    PH_MEMLOC_REM bBlockData[16];
    uint8_t    PH_MEMLOC_REM bBlockList[2] = { 0x80, 0x00};   /* Read Zero Block to get Attribute Block */
    uint8_t    PH_MEMLOC_REM bSystemCode[2] = { 0x88, 0xB4};
    uint8_t    PH_MEMLOC_REM bReadServiceList[2] = { 0x0B, 0x00};
    uint8_t    PH_MEMLOC_REM bWriteServiceList[2] = { 0x09, 0x00};
    uint8_t    PH_MEMLOC_REM bRxNumBlocks = 0;
    uint8_t    PH_MEMLOC_REM bMCBlockList[2] = { 0x80, 0x88}; /* Memory Configuration(MC) Block is 88h */
    uint8_t    PH_MEMLOC_REM wLength;
    uint8_t    PH_MEMLOC_REM wMoreCardsAvailable;

    if(pT3T->bNdefSupport != PH_SUPPORTED)
    {
        /* Write MC Block to change Tag to NDEF Complaiant as CheckNDEF falied to activate Tag as NDEF. */
        PH_CHECK_SUCCESS_FCT(status, phalFelica_ActivateCard(
            pT3T->phalT3TDataParams,
            bSystemCode,
            0,                                                    /* Time Slot */
            pT3T->bUid,
            &wLength,
            &wMoreCardsAvailable));

        /* Read MC(Memory Configuration) Block to get SYS_OP Value */
        PH_CHECK_SUCCESS_FCT(status, phalFelica_Read(
            pT3T->phalT3TDataParams,
            0x01,
            bReadServiceList,
            0x01,
            bMCBlockList,
            0x02,
            &bRxNumBlocks,
            bBlockData));

        if((bBlockData[0] == 0xFF) && (bBlockData[1] == 0xFF) && (bBlockData[2] == 0xFF)
            && (bBlockData[3] == 0x00) && (bBlockData[4] == 0xFF))
        {
            bBlockData[3] = 0x01;

            PH_CHECK_SUCCESS_FCT(status, phalFelica_Write(
                pT3T->phalT3TDataParams,
                0x01,
                bWriteServiceList,
                0x01,
                bMCBlockList,
                0x02,
                bBlockData));
        }
        else if((bBlockData[0] == 0xFF) && (bBlockData[1] == 0xFF) && (bBlockData[2] == 0xFF)
            && (bBlockData[3] == 0x01) && (bBlockData[4] == 0xFF))
        {
            /* Proceed with write of Attribute Information block */
        }
        else
        {
            return PH_ADD_COMPCODE(PHAL_TOP_ERR_INVALID_TAG, PH_COMP_AL_TOP);
        }
    }

    /* Write Attribute Information Block(AIB) with some Nbr and Nbw values */
    if((pT3T->bVno == PHAL_TOP_T3T_NDEF_SUPPORTED_VNO1) ||
        (pT3T->bVno == PHAL_TOP_T3T_NDEF_SUPPORTED_VNO2))
    {
        bBlockData[0] = pT3T->bVno;
    }
    else
    {
        bBlockData[0] = 0x11;
    }
    bBlockData[1] = 0x01;                                 /* Value of Nbr for Felica Lite is 1 */
    bBlockData[2] = 0x01;                                 /* Value of Nbw for Felica Lite is 1 */
    if(pT3T->bNmaxb < 0x000D)
    {
        bBlockData[3] = 0x00;                             /* MSB Value of Nmaxb */
        bBlockData[4] = 0x0D;                             /* LSB Value of Nmaxb */
    }
    else
    {
        bBlockData[3] = (uint8_t)((uint16_t)(pT3T->bNmaxb & 0xFF00) >> 8);
        bBlockData[4] = (uint8_t)(pT3T->bNmaxb & 0x00FF);
    }
    bBlockData[5] = 0x00;
    bBlockData[6] = 0x00;
    bBlockData[7] = 0x00;
    bBlockData[8] = 0x00;
    bBlockData[PHAL_TOP_T3T_WRITE_FLAG_ADDRESS] = 0x00U;
    bBlockData[10] = PHAL_TOP_T3T_AIB_RWA_RW;
    bBlockData[11] = 0x00U;
    bBlockData[12] = 0x00U;
    bBlockData[13] = 0x00U;

    for(wIndex = 0, wCheckSum = 0; wIndex < 14; wIndex++)
    {
        wCheckSum += bBlockData[wIndex];
    }
    bBlockData[14] = (uint8_t)(wCheckSum >> 8);
    bBlockData[15] = (uint8_t)(wCheckSum & 0x00FF);

    PH_CHECK_SUCCESS_FCT(status, phalFelica_Write(
        pT3T->phalT3TDataParams,
        0x01,
        bWriteServiceList,
        0x01,
        bBlockList,
        0x02,
        bBlockData));

    pT3T->bVno = bBlockData[0];
    pT3T->bNmaxb = (uint16_t)(((uint16_t)bBlockData[3] << 8) | bBlockData[4]);
    pT3T->bNdefFormatted = PH_SUPPORTED;
    pT3T->bNdefPresence = PH_OFF;
    pT3T->wNdefLength = 0x00;
    pT3T->bTagState = PHAL_TOP_T3T_STATE_INITIALIZED;
    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_TOP);
}
Exemple #11
0
phStatus_t phalTop_Sw_Int_T3T_ReadNdef(
                                       phalTop_T3T_t * pT3T,
                                       uint8_t * pData,
                                       uint16_t * pLength
                                       )
{
    phStatus_t PH_MEMLOC_REM status;
    uint16_t   PH_MEMLOC_REM wIndex;                             /* Block Index */
    uint16_t   PH_MEMLOC_REM wTempIndex;
    uint8_t    PH_MEMLOC_REM bBlockData[240];
    uint8_t    PH_MEMLOC_REM bReadBlocks;
    uint8_t    PH_MEMLOC_REM bReadNo;
    uint8_t    PH_MEMLOC_REM bCount = 0;
    uint32_t    PH_MEMLOC_REM bNdefLength;
    uint8_t    PH_MEMLOC_REM bWriteServiceList[2] = { 0x09, 0x00};
    uint8_t    PH_MEMLOC_REM bBlockList[0x1E] = { 0x80, 0x01, 0x80, 0x02, 0x80, 0x03, 0x80, 0x04, 0x80, 0x05,
        0x80, 0x06, 0x80, 0x07, 0x80, 0x08, 0x80, 0x09, 0x80, 0x0A,
        0x80, 0x0B, 0x80, 0x0C, 0x80, 0x0D, 0x80, 0x0E, 0x80, 0x0F};
    uint8_t    PH_MEMLOC_REM bRxNumBlocks = 0;

    if(pT3T->bNdefPresence != PH_ON)
    {
        return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_AL_TOP);
    }
    if(!((pT3T->bTagState == PHAL_TOP_T3T_STATE_READWRITE) || (pT3T->bTagState == PHAL_TOP_T3T_STATE_READONLY)))
    {
        return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_AL_TOP);
    }

    bReadBlocks = pT3T->bNbr;
    if(bReadBlocks == 0x00)
    {
        bReadBlocks = 0x01;
    }
    else if(bReadBlocks > 0x0F)
    {
        /* Assumed Max Nbr value is 0x0F */
        bReadBlocks = 0x0F;
    }
    else
    {
        /* Do Nothing */
    }

    bNdefLength = pT3T->wNdefLength;
    bReadNo = (uint8_t)(bNdefLength / (bReadBlocks * PHAL_TOP_T3T_BLOCK_SIZE));
    if(bNdefLength % (bReadBlocks * PHAL_TOP_T3T_BLOCK_SIZE))
    {
        bReadNo += 1;
    }

    for(wIndex = 0x01, wTempIndex = 0;
        wIndex <= bReadNo;
        wIndex++)
    {
        PH_CHECK_SUCCESS_FCT(status, phalFelica_Read(
            pT3T->phalT3TDataParams,
            0x01,
            bWriteServiceList,
            bReadBlocks,
            bBlockList,
            (bReadBlocks * 2),
            &bRxNumBlocks,
            bBlockData));

        if(bNdefLength <= (bReadBlocks * PHAL_TOP_T3T_BLOCK_SIZE))
        {
            /* Copy the remaining bytes in the Block excluding the padding bytes */
            memcpy(&pData[wTempIndex], &bBlockData[0], bNdefLength);    /* PRQA S 3200 */
        }
        else
        {
            bNdefLength = bNdefLength - (bReadBlocks * PHAL_TOP_T3T_BLOCK_SIZE);
            memcpy(&pData[wTempIndex], &bBlockData[0], (bReadBlocks * PHAL_TOP_T3T_BLOCK_SIZE));    /* PRQA S 3200 */
            wTempIndex = wTempIndex + (bReadBlocks * PHAL_TOP_T3T_BLOCK_SIZE);
            for(bCount = 0; bCount < bReadBlocks; bCount++)
            {
                bBlockList[(bCount * 2)+ 1] += bReadBlocks;
            }
        }
    }
    *pLength = (uint16_t) pT3T->wNdefLength;
    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_TOP);
}
Exemple #12
0
phStatus_t phpalEpcUid_Sw_ActivateCard(
                                       phpalEpcUid_Sw_DataParams_t * pDataParams,
                                       uint8_t bTagType,
                                       uint8_t bNumSlots,
                                       uint8_t * pMask,
                                       uint8_t bMaskBitLength,
                                       uint8_t bHash,
                                       uint8_t * pRxBuffer,
                                       uint8_t * pRxLength,
                                       uint8_t * pMoreCardsAvailable
                                       )
{
    phStatus_t  PH_MEMLOC_REM status;
    phStatus_t  PH_MEMLOC_REM statusTmp;
    phStatus_t  PH_MEMLOC_REM statusReturned;
    uint8_t     PH_MEMLOC_REM bNumSlotsTmp;
    uint16_t    PH_MEMLOC_REM wNumSlotsDec;
    uint8_t     PH_MEMLOC_REM bCardsPresent;

    /* reset pMoreCardsAvailable flag */
    *pMoreCardsAvailable = PH_OFF;

    /* init. return status */
    statusReturned = PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL);

    do
    {
        /* Reset card present state */
        bCardsPresent = PH_OFF;
        
        /* Start a new Response Round and scan slot 0 */
        status = phpalEpcUid_Sw_BeginRound(
            pDataParams,
            bTagType,
            bNumSlots,
            pMask,
            bMaskBitLength,
            bHash,
            pRxBuffer,
            pRxLength);

        /* Return on parameter error */
        if ((status & PH_ERR_MASK) == PH_ERR_INVALID_PARAMETER)
        {
            return status;
        }

        /* Calculate number of slots in decimal */
		wNumSlotsDec = 0x01;
        if (bNumSlots > PHPAL_EPCUID_NUMSLOTS_1)
        {
            bNumSlotsTmp = bNumSlots;
            do 
            {
                bNumSlotsTmp >>= 1;
                wNumSlotsDec <<= 1;
            } while (bNumSlotsTmp);

            wNumSlotsDec <<= 1;
        }
        bNumSlotsTmp = bNumSlots;

		/* Do for all further requested slots */
		while (wNumSlotsDec--)
		{
			/* Multiple labels found in current slot */
            if (((status & PH_ERR_MASK) == PH_ERR_COLLISION_ERROR) ||
                ((status & PH_ERR_MASK) == PH_ERR_INTEGRITY_ERROR))
			{
				bCardsPresent = PH_ON;
				*pMoreCardsAvailable = PH_ON;

                /* Store collision error in case it can't be resolved */
                if ((statusReturned & PH_ERR_MASK) == PH_ERR_SUCCESS)
                {
                    statusReturned = status;
                }
			}
            else
            {
                /* Store timeout error if integrity / collision error has not happened */
                if ((status & PH_ERR_MASK) == PH_ERR_IO_TIMEOUT)
                {
                    if ((statusReturned & PH_ERR_MASK) == PH_ERR_SUCCESS)
                    {
                        statusReturned = status;
                    }
                }
                /* Return on success or other errors */
                else
				{
					return status;
				}
			}

            /* Last slot -> send CloseSlotLast */
            if (wNumSlotsDec == 0)
            {
                /* Send CloseSlot command */
                PH_CHECK_SUCCESS_FCT(statusTmp, phpalEpcUid_Sw_CloseSlot(
                    pDataParams,
                    PHPAL_EPCUID_CLOSESLOT_LAST,
                    pRxBuffer,
                    pRxLength));
            }
            else
            {
                /* Send CloseSlot command */
                status = phpalEpcUid_Sw_CloseSlot(
                    pDataParams,
                    PHPAL_EPCUID_CLOSESLOT_NONLAST,
                    pRxBuffer,
                    pRxLength);
            }
        }

        /* Increment number of slots */
        bNumSlots = (bNumSlots << 1) | 0x01;
    }
Exemple #13
0
phStatus_t phpalMifare_MfcAuthenticate(
                                       void * pDataParams,
                                       uint8_t bBlockNo,
                                       uint8_t bKeyType,
                                       uint8_t * pKey,
                                       uint8_t * pUid
                                       )
{
    phStatus_t PH_MEMLOC_REM status;

    PH_LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "phpalMifare_MfcAuthenticate");
    /*PH_LOG_HELPER_ALLOCATE_PARAMNAME(pDataParams);*/
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(bBlockNo);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(bKeyType);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pKey);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pUid);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(status);
    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_UINT8(PH_LOG_LOGTYPE_DEBUG, bBlockNo_log, &bBlockNo);
    PH_LOG_HELPER_ADDPARAM_UINT8(PH_LOG_LOGTYPE_DEBUG, bKeyType_log, &bKeyType);
    PH_LOG_HELPER_ADDPARAM_BUFFER(PH_LOG_LOGTYPE_DEBUG, pKey_log, pKey, 6);
    PH_LOG_HELPER_ADDPARAM_BUFFER(PH_LOG_LOGTYPE_DEBUG, pUid_log, pUid, 4);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_ENTER);
	PH_ASSERT_NULL (pDataParams);
	PH_ASSERT_NULL (pKey);
	PH_ASSERT_NULL (pUid);

    /* Check data parameters */
    if (PH_GET_COMPCODE(pDataParams) != PH_COMP_PAL_MIFARE)
    {
        PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
        PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
        PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

        return PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_PAL_MIFARE);
    }

    /* perform operation on active layer */
    switch (PH_GET_COMPID(pDataParams))
    {
#ifdef NXPBUILD__PHPAL_MIFARE_STUB
    case PHPAL_MIFARE_STUB_ID:
        status = phpalMifare_Stub_MfcAuthenticate(
            (phpalMifare_Stub_DataParams_t *)pDataParams,
            bBlockNo,
            bKeyType,
            pKey,
            pUid);
        break;
#endif /* NXPBUILD__PHPAL_MIFARE_STUB */

#ifdef NXPBUILD__PHPAL_MIFARE_SW
    case PHPAL_MIFARE_SW_ID:
        status = phpalMifare_Sw_MfcAuthenticate(
            (phpalMifare_Sw_DataParams_t *)pDataParams,
            bBlockNo,
            bKeyType,
            pKey,
            pUid);
        break;
#endif /* NXPBUILD__PHPAL_MIFARE_SW */

#ifdef NXPBUILD__PHPAL_MIFARE_SAMAV2_X
    case PHPAL_MIFARE_SAMAV2_X_ID:
        status = phpalMifare_SamAV2_X_MfcAuthenticate(
            (phpalMifare_SamAV2_X_DataParams_t *)pDataParams,
            bBlockNo,
            bKeyType,
            pKey,
            pUid);
        break;
#endif /* NXPBUILD__PHPAL_MIFARE_SAMAV2_X */

#ifdef NXPBUILD__PHPAL_MIFARE_RD710
    case PHPAL_MIFARE_RD710_ID:
        status = phpalMifare_Rd710_MfcAuthenticate(
            (phpalMifare_Rd710_DataParams_t *)pDataParams,
            bBlockNo,
            bKeyType,
            pKey,
            pUid);
        break;
#endif /* NXPBUILD__PHPAL_MIFARE_RD710 */

    default:
        status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_PAL_MIFARE);
        break;
    }

    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

    return status;
}
Exemple #14
0
phStatus_t phpalMifare_ExchangeL3(
                                  void * pDataParams,
                                  uint16_t wOption,
                                  uint8_t * pTxBuffer,
                                  uint16_t wTxLength,
                                  uint8_t ** ppRxBuffer,
                                  uint16_t * pRxLength
                                  )
{
    phStatus_t PH_MEMLOC_REM status;

    PH_LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "phpalMifare_ExchangeL3");
    /*PH_LOG_HELPER_ALLOCATE_PARAMNAME(pDataParams);*/
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(wOption);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pTxBuffer);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(ppRxBuffer);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(status);
    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_DEBUG, wOption_log, &wOption);
    PH_LOG_HELPER_ADDPARAM_BUFFER(PH_LOG_LOGTYPE_DEBUG, pTxBuffer_log, pTxBuffer, wTxLength);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_ENTER);
	PH_ASSERT_NULL (pDataParams);
	if (wTxLength) PH_ASSERT_NULL (pTxBuffer);

    /* Check data parameters */
    if (PH_GET_COMPCODE(pDataParams) != PH_COMP_PAL_MIFARE)
    {
        PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
        PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
        PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

        return PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_PAL_MIFARE);
    }

    /* perform operation on active layer */
    switch (PH_GET_COMPID(pDataParams))
    {
#ifdef NXPBUILD__PHPAL_MIFARE_STUB
    case PHPAL_MIFARE_STUB_ID:
        status = phpalMifare_Stub_ExchangeL3(
            (phpalMifare_Stub_DataParams_t *)pDataParams,
            wOption,
            pTxBuffer,
            wTxLength,
            ppRxBuffer,
            pRxLength);
        break;
#endif /* NXPBUILD__PHPAL_MIFARE_STUB */

#ifdef NXPBUILD__PHPAL_MIFARE_SW
    case PHPAL_MIFARE_SW_ID:
        status = phpalMifare_Sw_ExchangeL3(
            (phpalMifare_Sw_DataParams_t *)pDataParams,
            wOption,
            pTxBuffer,
            wTxLength,
            ppRxBuffer,
            pRxLength);
        break;
#endif /* NXPBUILD__PHPAL_MIFARE_SW */

#ifdef NXPBUILD__PHPAL_MIFARE_SAMAV2_X
    case PHPAL_MIFARE_SAMAV2_X_ID:
        status = phpalMifare_SamAV2_X_ExchangeL3(
            (phpalMifare_SamAV2_X_DataParams_t *)pDataParams,
            wOption,
            pTxBuffer,
            wTxLength,
            ppRxBuffer,
            pRxLength);
        break;
#endif /* NXPBUILD__PHPAL_MIFARE_SAMAV2_X */

#ifdef NXPBUILD__PHPAL_MIFARE_RD710
    case PHPAL_MIFARE_RD710_ID:
        status = phpalMifare_Rd710_ExchangeL3(
            (phpalMifare_Rd710_DataParams_t *)pDataParams,
            wOption,
            pTxBuffer,
            wTxLength,
            ppRxBuffer,
            pRxLength);
        break;
#endif /* NXPBUILD__PHPAL_MIFARE_RD710 */

    default:
        status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_PAL_MIFARE);
        break;
    }

    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
#ifdef NXPBUILD__PH_LOG
    if ((((status & PH_ERR_MASK) == PH_ERR_SUCCESS) ||
        ((status & PH_ERR_MASK) == PH_ERR_SUCCESS_CHAINING) ||
        ((status & PH_ERR_MASK) == PH_ERR_SUCCESS_INCOMPLETE_BYTE)) &&
        !(wOption & PH_EXCHANGE_BUFFERED_BIT) &&
        (ppRxBuffer != NULL))
    {
        PH_LOG_HELPER_ADDPARAM_BUFFER(PH_LOG_LOGTYPE_DEBUG, ppRxBuffer_log, *ppRxBuffer, *pRxLength);
    }
#endif
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

    return status;
}
Exemple #15
0
phStatus_t phpalI14443p4a_Sw_Rats(
                                  phpalI14443p4a_Sw_DataParams_t * pDataParams,
                                  uint8_t bFsdi,
                                  uint8_t bCid,
                                  uint8_t * pAts
                                  )
{
    phStatus_t  PH_MEMLOC_REM status;
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM cmd[2];
    uint8_t     PH_MEMLOC_REM bAtsIndex;
    uint8_t     PH_MEMLOC_REM bSfgi;
    uint32_t    PH_MEMLOC_REM dwSfgt;
    uint32_t    PH_MEMLOC_REM dwFwt;
    uint8_t *   PH_MEMLOC_REM pResp;
    uint16_t    PH_MEMLOC_REM wRespLength;

    /* Parameter check */
    if ((bFsdi > 8) || (bCid > 14))
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_PAL_ISO14443P4A);
    }

    /* Set Activation timeout */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(
        pDataParams->pHalDataParams,
        PHHAL_HW_CONFIG_TIMEOUT_VALUE_US,
        PHPAL_I14443P4A_SW_FWT_ACTIVATION_US + PHPAL_I14443P4A_SW_EXT_TIME_US));

    /* Send Rats command */
    cmd[0] = PHPAL_I14443P4A_SW_RATS;
    cmd[1] = (uint8_t)(((bFsdi << 4) & 0xF0) | (bCid & 0x0F));
    status = phhalHw_Exchange(
        pDataParams->pHalDataParams,
        PH_EXCHANGE_DEFAULT,
        cmd,
        2,
        &pResp,
        &wRespLength);

    if ((status & PH_ERR_MASK) == PH_ERR_SUCCESS)
    {
        /* Check for protocol error */
        if (((uint8_t)wRespLength != pResp[0]) || (wRespLength < 1))
        {
            return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_PAL_ISO14443P4A);
        }

        /* Copy ATS buffer */
        memcpy(pAts, pResp, wRespLength);  /* PRQA S 3200 */

        /* Set default values */
        /* */
        pDataParams->bCidSupported  = PH_OFF;
        pDataParams->bCid           = 0x00;
        pDataParams->bNadSupported  = PH_OFF;
        pDataParams->bBitRateCaps   = 0x00;
        pDataParams->bFwi           = PHPAL_I14443P4A_SW_FWI_DEFAULT;
        pDataParams->bFsdi          = bFsdi;
        pDataParams->bFsci          = PHPAL_I14443P4A_SW_FSCI_DEFAULT;
        pDataParams->bDri           = 0x00;
        pDataParams->bDsi           = 0x00;
        bSfgi                       = PHPAL_I14443P4A_SW_SFGI_DEFAULT;

        /* Retrieve ATS information */
        /* Start parsing with T0 byte */
        bAtsIndex = PHPAL_I14443P4A_SW_ATS_T0;

        /* Parse T0/TA/TB/TC */
        if (wRespLength > 1)
        {
            /* Parse T0 */
            pDataParams->bFsci = pAts[bAtsIndex] & 0x0F;
            if (pDataParams->bFsci > 8)
            {
                pDataParams->bFsci = 8;
            }
            bAtsIndex++;

            /* Parse TA(1) */
            if (pAts[PHPAL_I14443P4A_SW_ATS_T0] & PHPAL_I14443P4A_SW_ATS_TA1_PRESENT)
            {
                /* Check for protocol error */
                if (wRespLength <= bAtsIndex)
                {
                    return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_PAL_ISO14443P4A);
                }
                else
                {
                    /* Store Bitrate capabilities */
                    pDataParams->bBitRateCaps = pAts[bAtsIndex];

                    bAtsIndex++;
                }
            }

            /* Parse TB(1) */
            if (pAts[PHPAL_I14443P4A_SW_ATS_T0] & PHPAL_I14443P4A_SW_ATS_TB1_PRESENT)
            {
                /* Check for protocol error */
                if (wRespLength <= bAtsIndex)
                {
                    return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_PAL_ISO14443P4A);
                }
                else
                {
                    /* Store Sfgi */
                    bSfgi = pAts[bAtsIndex] & 0x0F;
                    if (bSfgi == 0x0F)
                    {
                        bSfgi = PHPAL_I14443P4A_SW_SFGI_DEFAULT;
                    }

                    /* Store Fwi */
                    pDataParams->bFwi = (pAts[bAtsIndex] >> 4) & 0x0F;
                    if (pDataParams->bFwi == 0x0F)
                    {
                        pDataParams->bFwi = PHPAL_I14443P4A_SW_FWI_DEFAULT;
                    }

                    bAtsIndex++;
                }
            }

            /* Parse TC(1) */
            if (pAts[PHPAL_I14443P4A_SW_ATS_T0] & PHPAL_I14443P4A_SW_ATS_TC1_PRESENT)
            {
                /* Check for protocol error */
                if (wRespLength <= bAtsIndex)
                {
                    return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_PAL_ISO14443P4A);
                }
                else
                {
                    /* Check NAD Support */
                    if (pAts[bAtsIndex] & PHPAL_I14443P4A_SW_ATS_TC1_NAD_SUPPORT)
                    {
                        pDataParams->bNadSupported = 1;
                    }

                    /* Check CID Support */
                    if (pAts[bAtsIndex] & PHPAL_I14443P4A_SW_ATS_TC1_CID_SUPPORT)
                    {
                        pDataParams->bCidSupported = 1;
                        pDataParams->bCid = bCid;
                    }
                }
            }
        }

        /* Calculate SFGT in Microseconds */
        dwSfgt = (uint32_t)(PHPAL_I14443P4A_SW_FWT_MIN_US * (1 << bSfgi));

        /* Perform SFGT Wait */
        if (dwSfgt > 0xFFFF)
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Wait(
                pDataParams->pHalDataParams,
                PHHAL_HW_TIME_MILLISECONDS,
                (uint16_t)(dwSfgt / 1000)));
        }
        else
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Wait(
                pDataParams->pHalDataParams,
                PHHAL_HW_TIME_MICROSECONDS,
                (uint16_t)dwSfgt));
        }

        /* Calculate FWT timeout */
        dwFwt = (uint32_t)(PHPAL_I14443P4A_SW_FWT_MIN_US * (1 << pDataParams->bFwi));

        /* Add extension time */
        dwFwt = dwFwt + PHPAL_I14443P4A_SW_EXT_TIME_US;

        /* Set FWT timeout */
        if (dwFwt > 0xFFFF)
        {
            /* +1 is added to the timeout in millisecond to compensate the
             * fractional microseconds lost in division by 1000 */
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(
                pDataParams->pHalDataParams,
                PHHAL_HW_CONFIG_TIMEOUT_VALUE_MS,
                (uint16_t)((dwFwt / 1000) + 1)));
        }
        else
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(
                pDataParams->pHalDataParams,
                PHHAL_HW_CONFIG_TIMEOUT_VALUE_US,
                (uint16_t)dwFwt));
        }
    }
Exemple #16
0
phStatus_t phalTop_Sw_Int_T3T_EraseNdef(
                                        phalTop_T3T_t * pT3T
                                        )
{
    phStatus_t PH_MEMLOC_REM status;
    uint16_t   PH_MEMLOC_REM wLength;
    uint16_t   PH_MEMLOC_REM wIndex;
    uint16_t   PH_MEMLOC_REM wTempIndex;
    uint16_t   PH_MEMLOC_REM wCheckSum;
    uint8_t    PH_MEMLOC_REM bBlockData[16];
    uint8_t    PH_MEMLOC_REM bAttBlock[2] = { 0x80, 0x00};  /* Read Zero Block to get Attribute Block */
    uint8_t    PH_MEMLOC_REM bBlockList[2] = { 0x80, 0x01}; /* First Block to Write Ndef Data */
    uint8_t    PH_MEMLOC_REM bReadServiceList[2] = { 0x0B, 0x00};
    uint8_t    PH_MEMLOC_REM bWriteServiceList[2] = { 0x09, 0x00};
    uint8_t    PH_MEMLOC_REM bRxNumBlocks = 0;

    /* Read and Update Attribute Block before Writing NDEF */
    PH_CHECK_SUCCESS_FCT(status, phalFelica_Read(
        pT3T->phalT3TDataParams,
        0x01,
        bReadServiceList,
        0x01,
        bAttBlock,
        0x02,
        &bRxNumBlocks,
        bBlockData));

    bBlockData[PHAL_TOP_T3T_WRITE_FLAG_ADDRESS] = PHAL_TOP_T3T_WRITE_FLAG_SET;
    wLength = (uint16_t)(((uint16_t)bBlockData[12] << 8) | bBlockData[13]);
    bBlockData[11] = 0x00U;
    bBlockData[12] = 0x00U;
    bBlockData[13] = 0x00U;

    /* Calculate CheckSum */
    for(wIndex = 0, wCheckSum = 0; wIndex < 14; wIndex++)
    {
        wCheckSum += bBlockData[wIndex];
    }
    bBlockData[14] = (uint8_t)(wCheckSum >> 8);
    bBlockData[15] = (uint8_t)(wCheckSum & 0x00FF);

    PH_CHECK_SUCCESS_FCT(status, phalFelica_Write(
        pT3T->phalT3TDataParams,
        0x01,
        bWriteServiceList,
        0x01,
        bAttBlock,
        0x02,
        bBlockData));

    if(wLength % PHAL_TOP_T3T_BLOCK_SIZE)
    {
        wLength = (wLength / PHAL_TOP_T3T_BLOCK_SIZE) + 1;
    }
    else
    {
        wLength = wLength / PHAL_TOP_T3T_BLOCK_SIZE;
    }
    /* Write 0s in NDEF Block area */
    for(wIndex = 0, wTempIndex = 0;
        wIndex < wLength + 1;
        wIndex++)
    {
        memset(&bBlockData[0], 0x00, PHAL_TOP_T3T_BLOCK_SIZE);  /* PRQA S 3200 */

        PH_CHECK_SUCCESS_FCT(status, phalFelica_Write(
            pT3T->phalT3TDataParams,
            0x01,
            bWriteServiceList,
            0x01,
            bBlockList,
            0x02,
            bBlockData));

        wTempIndex += 16;
        if(bBlockList[1] == 0xFF)
        {
            bBlockList[0] += 1;
        }
        else
        {
            bBlockList[1] += 1;
        }
    }

    /* Read and Update Attribute Block after Writing 0s in NDEF area */
    PH_CHECK_SUCCESS_FCT(status, phalFelica_Read(
        pT3T->phalT3TDataParams,
        0x01,
        bReadServiceList,
        0x01,
        bAttBlock,
        0x02,
        &bRxNumBlocks,
        bBlockData));

    bBlockData[PHAL_TOP_T3T_WRITE_FLAG_ADDRESS] = PHAL_TOP_T3T_WRITE_FLAG_RESET;
    bBlockData[11] = 0x00U;
    bBlockData[12] = 0x00U;
    bBlockData[13] = 0x00U;

    /* Calculate CheckSum */
    for(wIndex = 0, wCheckSum = 0; wIndex < 14; wIndex++)
    {
        wCheckSum += bBlockData[wIndex];
    }
    bBlockData[14] = (uint8_t)(wCheckSum >> 8);
    bBlockData[15] = (uint8_t)(wCheckSum & 0x00FF);

    PH_CHECK_SUCCESS_FCT(status, phalFelica_Write(
        pT3T->phalT3TDataParams,
        0x01,
        bWriteServiceList,
        0x01,
        bAttBlock,
        0x02,
        bBlockData));

    pT3T->bNdefPresence = PH_OFF;

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_TOP);
}
Exemple #17
0
phStatus_t phalTop_Sw_Int_T4T_FormatNdef(
    phalTop_T4T_t * pT4T
    )
{
    phStatus_t PH_MEMLOC_REM status;
    uint8_t PH_MEMLOC_REM aNDEF_msg[2] = {0x00, 0x00};
    uint8_t PH_MEMLOC_REM aFileSize[3] = {0x0F, 0x00, 0x00};        /**< File size specifier */
    uint8_t PH_MEMLOC_REM aNdefFileLen[3] = {0x04, 0x00, 0x00};     /**< Valid data buffer length */
    uint8_t PH_MEMLOC_REM aOffset[3] = {0x00, 0x00, 0x00};          /**< Offset for write data */
    uint8_t PH_MEMLOC_REM aAccessRights[2] = {0xEE, 0xEE};          /**< Access Rights */
    uint8_t PH_MEMLOC_REM aAid[3] = {0x01, 0x00, 0x00};
    uint8_t PH_MEMLOC_REM aFid_App[2] = {0x05, 0xE1};
    uint8_t PH_MEMLOC_REM aFid_MApp[2] = {0x00, 0x3F};              /**< Master Application ISO File ID */
    uint8_t PH_MEMLOC_REM aFid_CC[2] = {0x03, 0xE1};
    uint8_t  PH_MEMLOC_REM *pFCI;
    uint16_t PH_MEMLOC_REM *pwFCILen = 0;
    /* Default CC File contents with 0xE104 as NDEF FileID
    *  and with 1KBytes as Max NDEF File Size */
    uint8_t PH_MEMLOC_REM aData[15] = {0x00, 0x0F, 0x20, 0x00,
        0x3B, 0x00, 0x34, 0x04,
        0x06, 0xE1, 0x04, 0x04,
        0x00, 0x00, 0x00};
    uint8_t PH_MEMLOC_REM aNdefApp_Name[7] = {0xD2, 0x76, 0x00,        /**< DF Name buffer */
                                              0x00, 0x85, 0x01, 0x01};
    uint8_t  PH_MEMLOC_REM aNdefApp_Len = 0X07;
    uint16_t PH_MEMLOC_REM wNdef_Fid;
    phalMfdf_Sw_DataParams_t PH_MEMLOC_REM *pMfdf;
    pMfdf = (phalMfdf_Sw_DataParams_t *)(pT4T->phalT4TDataParams);

    pMfdf->bWrappedMode = 1;
    if(pT4T->bNdefSupport == PH_SUPPORTED)
    {
        /* CheckNDEF returned with Valid Card State. Erase the contents of Tag. */
        PH_CHECK_SUCCESS_FCT(status, phalTop_Sw_Int_T4T_EraseNdef(pT4T));
        pT4T->bNdefFormatted = true;
        return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_TOP);
    }

    /* Check for valid NDEF File ID provided by user or default NDEF ID = 0xE104*/
    wNdef_Fid = ((uint16_t)pT4T->bNdef_FileID[1] << 8) | pT4T->bNdef_FileID[0];

    if(!((wNdef_Fid == 0x0000) ||
        (wNdef_Fid == 0xE102) ||
        (wNdef_Fid == 0xE103) ||
        (wNdef_Fid == 0x3F00) ||
        (wNdef_Fid == 0x3FFF)))
    {
        aData[0x0A] = pT4T->bNdef_FileID[0];
        aData[0x09] = pT4T->bNdef_FileID[1];
    }
    else
    {
        pT4T->bNdef_FileID[0] = aData[0x0A];
        pT4T->bNdef_FileID[1] = aData[0x09];
    }

    if(!((pT4T->bMaxFileSize < 0x0005) ||
        (pT4T->bMaxFileSize > 0x80FE)))
    {
        aData[0x0B] = (uint8_t)((uint16_t)(pT4T->bMaxFileSize & 0xFF00) >> 8);
        aData[0x0C] = (uint8_t)(pT4T->bMaxFileSize & 0x00FF);
    }
Exemple #18
0
phStatus_t phOsal_GLib_Init( phOsal_GLib_DataParams_t  *pDataParams )
{
    pDataParams->wId = PH_COMP_OSAL | PH_OSAL_GLIB_ID;

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_OSAL);
}
Exemple #19
0
phStatus_t phKeyStore_Sw_SetFullKeyEntry(
    phKeyStore_Sw_DataParams_t * pDataParams,
    uint16_t wNoOfKeys,
    uint16_t wKeyNo,
    uint16_t wNewRefNoKUC,
    uint16_t wNewKeyType,
    uint8_t * pNewKeys,
    uint16_t * pNewKeyVersionList
    )
{
    phStatus_t statusTmp;
    uint8_t    i;
    uint8_t bKeyLength;
    phKeyStore_Sw_KeyVersionPair_t * pKeyVersion;

    /* Overflow checks */
    if (wKeyNo >= pDataParams->wNoOfKeyEntries)
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_KEYSTORE);
    }
    /* Check for a valid KUC entry */
    if (wNewRefNoKUC >= pDataParams->wNoOfKUCEntries)
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_KEYSTORE);
    }
    /* Overflow checks */
    if (wNoOfKeys > pDataParams->wNoOfVersions)
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_KEYSTORE);
    }

    switch(wNewKeyType)
    {
		case PH_KEYSTORE_KEY_TYPE_AES128:
		case PH_KEYSTORE_KEY_TYPE_2K3DES:
		case PH_KEYSTORE_KEY_TYPE_AES192:
		case PH_KEYSTORE_KEY_TYPE_3K3DES:
		case PH_KEYSTORE_KEY_TYPE_AES256:
		case PH_KEYSTORE_KEY_TYPE_DES:
		case PH_KEYSTORE_KEY_TYPE_MIFARE:
			bKeyLength = (uint8_t)phKeyStore_GetKeySize(wNewKeyType);
			break;

		default:
			return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_KEYSTORE);
    }

    pDataParams->pKeyEntries[wKeyNo].wKeyType = wNewKeyType;

    /* Reset KUC to master Key */
    pDataParams->pKeyEntries[wKeyNo].wRefNoKUC = wNewRefNoKUC;

    /* Reset all keys to 0x00*/
    for (i=0; i < wNoOfKeys ; i++)
    {
        PH_CHECK_SUCCESS_FCT(statusTmp, phKeyStore_Sw_GetKeyValuePtrPos(pDataParams,wKeyNo,i,&pKeyVersion));
        pKeyVersion->wVersion = pNewKeyVersionList[i];
        memcpy(pKeyVersion->pKey, &pNewKeys[i*bKeyLength], bKeyLength); /* PRQA S 3200 */
    }

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_KEYSTORE);
}
Exemple #20
0
phStatus_t phOsal_GLib_FreeMemory( phOsal_GLib_DataParams_t   *pDataParams,
                                   void                       *ptr
                                 )
{
    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_OSAL);
}
Exemple #21
0
phStatus_t phbalReg_Exchange(
                             void * pDataParams,
                             uint16_t wOption,
                             uint8_t * pTxBuffer,
                             uint16_t wTxLength,
                             uint16_t wRxBufSize,
                             uint8_t * pRxBuffer,
                             uint16_t * pRxLength
                             )
{
    phStatus_t PH_MEMLOC_REM status;

    PH_LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "phbalReg_Exchange");
    /*PH_LOG_HELPER_ALLOCATE_PARAMNAME(pDataParams);*/
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(wOption);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pTxBuffer);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(wRxBufSize);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pRxBuffer);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(status);
    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_DEBUG, wOption_log, &wOption);
    PH_LOG_HELPER_ADDPARAM_BUFFER(PH_LOG_LOGTYPE_DEBUG, pTxBuffer_log, pTxBuffer, wTxLength);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_DEBUG, wRxBufSize_log, &wRxBufSize);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_ENTER);
    PH_ASSERT_NULL (pDataParams);
    if (wTxLength) PH_ASSERT_NULL (pTxBuffer);

    /* Check data parameters */
    if (PH_GET_COMPCODE(pDataParams) != PH_COMP_BAL)
    {
		status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_BAL);

        PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
        PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
        PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

        return status;
    }

    /* perform operation on active layer */
    switch (PH_GET_COMPID(pDataParams))
    {
#ifdef NXPBUILD__PHBAL_REG_STUB
    case PHBAL_REG_STUB_ID:
        status = phbalReg_Stub_Exchange((phbalReg_Stub_DataParams_t*)pDataParams, wOption, pTxBuffer, wTxLength, wRxBufSize, pRxBuffer, pRxLength);
        break;
#endif /* NXPBUILD__PHBAL_REG_STUB */

#ifdef NXPBUILD__PHBAL_REG_LPC1768SPI
    case PHBAL_REG_LPC1768SPI_ID:
        status = phbalReg_Lpc1768Spi_Exchange((phbalReg_Lpc1768Spi_DataParams_t *)pDataParams, pTxBuffer, wTxLength, wRxBufSize, pRxBuffer, pRxLength);
        break;
#endif /* NXPBUILD__PHBAL_REG_LPC1768SPI */

#ifdef NXPBUILD__PHBAL_REG_LPC1768I2C
    case PHBAL_REG_LPC1768I2C_ID:
        status = phbalReg_Lpc1768I2c_Exchange((phbalReg_Lpc1768I2c_DataParams_t *)pDataParams, pTxBuffer, wTxLength, wRxBufSize, pRxBuffer, pRxLength);
        break;
#endif /* NXPBUILD__PHBAL_REG_LPC1768SPI */

    default:
        status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_BAL);
        break;
    }

    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
#ifdef NXPBUILD__PH_LOG
    if ((((status & PH_ERR_MASK) == PH_ERR_SUCCESS) ||
        ((status & PH_ERR_MASK) == PH_ERR_SUCCESS_CHAINING) ||
        ((status & PH_ERR_MASK) == PH_ERR_SUCCESS_INCOMPLETE_BYTE))
        &&
        (pRxBuffer != NULL) &&
        (pRxLength != NULL))
    {
        PH_LOG_HELPER_ADDPARAM_BUFFER(PH_LOG_LOGTYPE_DEBUG, pRxBuffer_log, pRxBuffer, *pRxLength);
    }
#endif
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

    return status;
}
Exemple #22
0
phStatus_t phOsal_GLib_Timer_Start( phOsal_GLib_DataParams_t  *pDataParams,
                                    uint32_t                   dwTimerId,
                                    uint32_t                   dwRegTimeCnt,
                                    uint16_t                   wOption,
                                    ppCallBck_t                pApplicationCallback,
                                    void                      *pContext
                                  )
{
   //g_debug("Starting timer %d...\r\n", dwTimerId);
   if( (dwTimerId > OSAL_GLIB_MAX_TIMERS) || (pDataParams->gTimers[dwTimerId].bTimerFree == TIMER_FREE) )
   {
	   /* Can't use a non existent timer */
	   /* Can't start a free timer, first create the timer */

	   return PH_ADD_COMPCODE(PH_ERR_INTERNAL_ERROR, PH_COMP_OSAL);
   }

   if( pDataParams->gTimers[dwTimerId].pGTimeoutSource != NULL )
   {
	   //Cannot start at timer which is already running
	   g_error("Timer %d already running\n", dwTimerId);
	   return PH_ADD_COMPCODE(PH_ERR_INTERNAL_ERROR, PH_COMP_OSAL);
   }

   //Convert usecs to millisecs if needed
   if( wOption ==  0 ) //
   {
	   //g_debug("%d us", dwRegTimeCnt);
	   //We're running in user-mode on a (probably) non realtime kernel, so even millisecs are very approximate
	   if( dwRegTimeCnt < 1000 )
	   {
		   pDataParams->gTimers[dwTimerId].dwMillisecs = 1;
	   }
	   else
	   {
		   pDataParams->gTimers[dwTimerId].dwMillisecs = dwRegTimeCnt / 1000;
	   }
   }
   else //These are already millisecs
   {
	   //g_debug("%d ms", dwRegTimeCnt);
	   pDataParams->gTimers[dwTimerId].dwMillisecs = dwRegTimeCnt;
   }

   //Remember callback
   pDataParams->gTimers[dwTimerId].pApplicationCallback = pApplicationCallback;
   pDataParams->gTimers[dwTimerId].pContext = pContext;

   //Create source
   pDataParams->gTimers[dwTimerId].pGTimeoutSource = g_timeout_source_new(pDataParams->gTimers[dwTimerId].dwMillisecs);
   if( pDataParams->gTimers[dwTimerId].pGTimeoutSource == NULL)
   {
	   return PH_ADD_COMPCODE(PH_ERR_INSUFFICIENT_RESOURCES, PH_COMP_OSAL);
   }

   //Set callback
   g_source_set_callback(pDataParams->gTimers[dwTimerId].pGTimeoutSource, phOsal_Int_Timer_Callback, &pDataParams->gTimers[dwTimerId], NULL);

   //Attach source to context
   g_source_attach(pDataParams->gTimers[dwTimerId].pGTimeoutSource, pDataParams->pgGLibMainContext);

   return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_OSAL);
}
Exemple #23
0
phStatus_t phbalReg_GetConfig(
                              void * pDataParams,
                              uint16_t wConfig,
                              uint16_t * pValue
                              )
{
    phStatus_t PH_MEMLOC_REM status;

    PH_LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "phbalReg_GetConfig");
    /*PH_LOG_HELPER_ALLOCATE_PARAMNAME(pDataParams);*/
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(wConfig);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pValue);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(status);
    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_DEBUG, wConfig_log, &wConfig);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_ENTER);
    PH_ASSERT_NULL (pDataParams);
    PH_ASSERT_NULL (pValue);

    /* Check data parameters */
    if (PH_GET_COMPCODE(pDataParams) != PH_COMP_BAL)
    {
		status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_BAL);

        PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
        PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
        PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

        return status;
    }

    switch (PH_GET_COMPID(pDataParams))
    {
#ifdef NXPBUILD__PHBAL_REG_STUB
        case PHBAL_REG_STUB_ID:
            status = phbalReg_Stub_GetConfig((phbalReg_Stub_DataParams_t*)pDataParams, wConfig, pValue);
            break;
#endif /* NXPBUILD__PHBAL_REG_STUB */

#ifdef NXPBUILD__PHBAL_REG_LPC1768SPI
    case PHBAL_REG_LPC1768SPI_ID:
        status = phbalReg_Lpc1768Spi_GetConfig((phbalReg_Lpc1768Spi_DataParams_t *)pDataParams, wConfig, pValue);
        break;
#endif /* NXPBUILD__PHBAL_REG_LPC1768SPI */

#ifdef NXPBUILD__PHBAL_REG_LPC1768I2C
    case PHBAL_REG_LPC1768I2C_ID:
        status = phbalReg_Lpc1768I2c_GetConfig((phbalReg_Lpc1768I2c_DataParams_t *)pDataParams, wConfig, pValue);
        break;
#endif /* NXPBUILD__PHBAL_REG_LPC1768SPI */

        default:
            status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_BAL);
            break;
    }

    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_DEBUG, pValue_log, pValue);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

    return PH_ADD_COMPCODE(status, PH_COMP_BAL);
}
Exemple #24
0
phStatus_t phpalMifare_Sw_ExchangePc(
                                     phpalMifare_Sw_DataParams_t * pDataParams,
                                     uint16_t wOption,
                                     uint8_t * pTxBuffer,
                                     uint16_t wTxLength,
                                     uint8_t ** ppRxBuffer,
                                     uint16_t * pRxLength
                                     )
{
#ifdef NXPBUILD__PHPAL_I14443P4
    phStatus_t  PH_MEMLOC_REM status;
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM bIsoFrame[3];
    uint16_t    PH_MEMLOC_REM wIsoFrameLen;
    uint16_t    PH_MEMLOC_REM wBlockNo;
    uint16_t    PH_MEMLOC_REM wCidConfig;
    uint16_t    PH_MEMLOC_REM wNadConfig;
    uint16_t    PH_MEMLOC_REM wCrcIn;
    uint16_t    PH_MEMLOC_REM wCrcCalc;
	uint16_t	PH_MEMLOC_REM RxLength;
	uint8_t *	PH_MEMLOC_REM pRxBuffer;

    /* Not available if no Layer4 has been set */
    if (pDataParams->pPalI14443p4DataParams == NULL)
    {
        return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_COMMAND, PH_COMP_PAL_MIFARE);
    }

    /* Ignore wOption byte */
    wOption = PH_EXCHANGE_DEFAULT;

	/* Check if caller has provided valid RxBuffer */
	if (ppRxBuffer == NULL)
	{
		ppRxBuffer = &pRxBuffer;
	}
	if (pRxLength == NULL)
	{
		pRxLength = &RxLength;
	}

    /* Retrieve ISO 14443-4 Protocol Parameters */
    PH_CHECK_SUCCESS_FCT(statusTmp, phpalI14443p4_GetConfig(pDataParams->pPalI14443p4DataParams, PHPAL_I14443P4_CONFIG_BLOCKNO, &wBlockNo));
    PH_CHECK_SUCCESS_FCT(statusTmp, phpalI14443p4_GetConfig(pDataParams->pPalI14443p4DataParams, PHPAL_I14443P4_CONFIG_CID, &wCidConfig));
    PH_CHECK_SUCCESS_FCT(statusTmp, phpalI14443p4_GetConfig(pDataParams->pPalI14443p4DataParams, PHPAL_I14443P4_CONFIG_NAD, &wNadConfig));

    /* Build ISO 14443-4 I-Block Frame */
    bIsoFrame[0] = (uint8_t)(0x02 | wBlockNo);
    wIsoFrameLen = 1;

    /* Append CID if needed */
    if (wCidConfig & 0xFF00)
    {
        bIsoFrame[0] |= 0x08;
        bIsoFrame[wIsoFrameLen++] = (uint8_t)(wCidConfig & 0x00FF);
    }

    /* Append NAD if needed */
    if (wNadConfig & 0xFF00)
    {
        bIsoFrame[0] |= 0x04;
        bIsoFrame[wIsoFrameLen++] = (uint8_t)(wNadConfig & 0x00FF);
    }

    /* Calculate CRC over the frame */
    PH_CHECK_SUCCESS_FCT(statusTmp, phTools_CalculateCrc16(
        PH_TOOLS_CRC_OPTION_DEFAULT,
        PH_TOOLS_CRC16_PRESET_ISO14443A,
        PH_TOOLS_CRC16_POLY_ISO14443,
        bIsoFrame, 
        wIsoFrameLen, 
        &wCrcCalc));

    /* Calculate CRC over the data to send */
    PH_CHECK_SUCCESS_FCT(statusTmp, phTools_CalculateCrc16(
        PH_TOOLS_CRC_OPTION_DEFAULT,
        wCrcCalc,
        PH_TOOLS_CRC16_POLY_ISO14443,
        pTxBuffer, 
        wTxLength, 
        &wCrcCalc));

    /* Preload the frame */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Exchange(
        pDataParams->pHalDataParams,
        PH_EXCHANGE_BUFFER_FIRST,
        bIsoFrame,
        wIsoFrameLen,
        NULL,
        NULL));

    /* Disable Tx-/RxCRC */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_TXCRC, PH_OFF));
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_RXCRC, PH_OFF));

    /* Perform Exchange */
    status = phhalHw_Exchange(
        pDataParams->pHalDataParams,
        PH_EXCHANGE_BUFFER_LAST,
        pTxBuffer,
        wTxLength,
        ppRxBuffer,
        pRxLength);

    /* Enable Tx-/RxCRC again */
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_TXCRC, PH_ON));
    PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_RXCRC, PH_ON));

    /* Check for Exchange Error */
    PH_CHECK_SUCCESS(status);

    /* Response length check */
    if (*pRxLength < 2)
    {
        return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_PAL_MIFARE);
    }

    /* Retrieve CRC */
    wCrcIn  = (uint16_t)(((uint16_t)(*ppRxBuffer)[(*pRxLength) - 1]) << 8);
    wCrcIn |= (uint16_t)((*ppRxBuffer)[(*pRxLength) - 2]);

    /* Remove CRC from input data */
    *pRxLength -= 2;

    /* Calculate CRC over the received data */
    PH_CHECK_SUCCESS_FCT(statusTmp, phTools_CalculateCrc16(
        PH_TOOLS_CRC_OPTION_DEFAULT,
        wCrcCalc,
        PH_TOOLS_CRC16_POLY_ISO14443,
        *ppRxBuffer, 
        *pRxLength, 
        &wCrcCalc));

    /* CRC Check -> Compare input and calculated crc */
    if (wCrcIn != wCrcCalc)
    {
        return PH_ADD_COMPCODE(PH_ERR_INTEGRITY_ERROR, PH_COMP_PAL_MIFARE);
    }

    /* Update ISO14443-4 Block Number */
    PH_CHECK_SUCCESS_FCT(statusTmp, phpalI14443p4_SetConfig(pDataParams->pPalI14443p4DataParams, PHPAL_I14443P4_CONFIG_BLOCKNO, (uint16_t)(wBlockNo ^ 0x01)));

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_PAL_MIFARE);
#else
    /* satisfy compiler */
    if (pDataParams || wOption || pTxBuffer || wTxLength || ppRxBuffer || pRxLength);
    return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_COMMAND, PH_COMP_PAL_MIFARE);
#endif
}
Exemple #25
0
/*
* Should return SW1+SW2
*/
phStatus_t phalMfdf_Int_Send7816Apdu(
                                     void * pDataParams,
                                     void * pPalMifareDataParams,
                                     uint8_t bOption,
                                     uint8_t bIns,
                                     uint8_t bP1,
                                     uint8_t bP2,
                                     uint8_t bLc,
                                     uint8_t * pDataIn,
                                     uint8_t bLe,
                                     uint8_t ** ppDataOut,
                                     uint16_t *pDataLen
                                     )
{
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint8_t     PH_MEMLOC_REM bCmdBuff[20];
    uint16_t    PH_MEMLOC_REM wRxlen;
    uint16_t    PH_MEMLOC_REM wCmdLen = 0;
    uint8_t     PH_MEMLOC_REM *pRecv;

    bCmdBuff[wCmdLen++] = 0x00; /* Class is always 0x00 */
    bCmdBuff[wCmdLen++] = bIns;
    bCmdBuff[wCmdLen++] = bP1;
    bCmdBuff[wCmdLen++] = bP2;

    if (bOption & 0x01)
    {
        bCmdBuff[wCmdLen++] = bLc;
    }

    PH_CHECK_SUCCESS_FCT(statusTmp, phpalMifare_ExchangeL4(
        pPalMifareDataParams,
        PH_EXCHANGE_BUFFER_FIRST,
        bCmdBuff,
        wCmdLen,
        &pRecv,
        &wRxlen
        ));

    if ((bOption & 0x01) && (bLc > 0))
    {
        PH_CHECK_SUCCESS_FCT(statusTmp, phpalMifare_ExchangeL4(
            pPalMifareDataParams,
            PH_EXCHANGE_BUFFER_CONT,
            pDataIn,
            bLc,
            &pRecv,
            &wRxlen
            ));
    }

    wCmdLen = 0;
    if (bOption & 0x02)
    {
        bCmdBuff[wCmdLen++] = bLe;
    }

    PH_CHECK_SUCCESS_FCT(statusTmp, phpalMifare_ExchangeL4(
        pPalMifareDataParams,
        PH_EXCHANGE_BUFFER_LAST,
        bCmdBuff,
        wCmdLen,
        &pRecv,
        &wRxlen
        ));

    statusTmp = pRecv[wRxlen - 2];
    statusTmp <<= 8;
    statusTmp |= pRecv[wRxlen - 1];

    PH_CHECK_SUCCESS_FCT(statusTmp, phalMfdf_Int_ComputeErrorResponse(pDataParams, statusTmp));

    if (pDataLen != NULL)
    {
        *pDataLen = wRxlen -2;
    }

    if (ppDataOut != NULL)
    {
        *ppDataOut = pRecv;
    }

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_MFDF);
}
Exemple #26
0
phStatus_t phpalMifare_Sw_ExchangeRaw(
                                      phpalMifare_Sw_DataParams_t * pDataParams,
                                      uint16_t wOption,
                                      uint8_t * pTxBuffer,
                                      uint16_t wTxLength,
                                      uint8_t bTxLastBits,
                                      uint8_t ** ppRxBuffer,
                                      uint16_t * pRxLength,
                                      uint8_t * pRxLastBits
                                      )
{
    phStatus_t  PH_MEMLOC_REM status;
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint16_t    PH_MEMLOC_REM wValue = 0;

    /* Do not switch Parity / CRC modes if no real exchange is done */
    if (!(wOption & PH_EXCHANGE_BUFFERED_BIT))
    {
        /* TxLastBits > 7 is invalid  */
        if (bTxLastBits > 7)
        {
            return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_PAL_MIFARE);
        }

        /* Retrieve Parity-setting */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_GetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_PARITY, &wValue));

        /* Disable Parity */
        if (wValue == PH_ON)
        {
            PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_PARITY, PH_OFF));
        }

        /* Disable TxCrc */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_TXCRC, PH_OFF));

        /* Disable RxCrc */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_RXCRC, PH_OFF));

        /* Set TxLastBits */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_TXLASTBITS, bTxLastBits));
    }
    else
    {
        /* TxLastBits != 0 is invalid for buffered operation */
        if (bTxLastBits != 0)
        {
            return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_PAL_MIFARE);
        }
    }

    /* Perform Exchange */
    status = phhalHw_Exchange(
        pDataParams->pHalDataParams,
        wOption,
        pTxBuffer,
        wTxLength,
        ppRxBuffer,
        pRxLength);
	printf("phpalMifare_Sw_ExchangeRaw phhalHw_Exchange %02x\n", status);

    /* Return if no real exchange is done */
    if (wOption & PH_EXCHANGE_BUFFERED_BIT)
    {
        return status;
    }

    /* Restore Parity-setting again since many PAL layers expect it */
    if (wValue == PH_ON)
    {
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_PARITY, wValue));
    }

    /* Retrieve RxLastBits */
    if ((status & PH_ERR_MASK) == PH_ERR_SUCCESS_INCOMPLETE_BYTE)
    {
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_GetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_RXLASTBITS, &wValue));
        *pRxLastBits = (uint8_t)wValue;
    }
    else
    {
        PH_CHECK_SUCCESS(status);
    }

    return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_PAL_MIFARE);
}
Exemple #27
0
/* SNEP Server Accept Connection API */
phStatus_t phnpSnep_Server_Accept( void                             *pDataParams,
                                  phNfc_sData_t                     *pDataInbox,
                                  phlnLlcp_Fri_Transport_sSocketOptions_t   *pSockOps,
                                  ph_NfcHandle                       ServerHandle,
                                  ph_NfcHandle                       ConnHandle,
                                  pphnpSnep_Fri_Put_ntf_t            pPutNtfCb,
                                  pphnpSnep_Fri_Get_ntf_t            pGetNtfCb,
                                  void                              *pContext )
{
    phStatus_t    status;

    PH_LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "phnpSnep_Server_Accept");
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pDataInbox);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pSockOps);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(ServerHandle);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pPutNtfCb);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pGetNtfCb);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pContext);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(status);
    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_ENTER);
    PH_ASSERT_NULL (pDataParams);
    PH_ASSERT_NULL (pDataInbox);
    PH_ASSERT_NULL (pSockOps);
    PH_ASSERT_NULL (ServerHandle);
    PH_ASSERT_NULL (pPutNtfCb);
    PH_ASSERT_NULL (pGetNtfCb);
    PH_ASSERT_NULL (pContext);

    /* Check data parameters */
    if (PH_GET_COMPCODE(pDataParams) != PH_COMP_NP_SNEP)
    {
        status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_NP_SNEP);

        PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
        PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
        PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);
        return status;
    }

    /* perform operation on active layer */
    switch (PH_GET_COMPID(pDataParams))
    {
#ifdef NXPBUILD__PHNP_SNEP_FRI
    case PHNP_SNEP_FRI_ID:

    status = phnpSnep_Fri_Server_Accept( pDataParams,
                                         pDataInbox,
                                         pSockOps,
                                         ServerHandle,
                                         ConnHandle,
                                         pPutNtfCb,
                                         pGetNtfCb,
                                         pContext );
        break;
#endif /* NXPBUILD__PHNP_SNEP_FRI */

    default:
        status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_NP_SNEP);
        break;
    }

    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);


    return status;
}
Exemple #28
0
phStatus_t phpalMifare_Sw_ExchangeL3(
                                     phpalMifare_Sw_DataParams_t * pDataParams,
                                     uint16_t wOption,
                                     uint8_t * pTxBuffer,
                                     uint16_t wTxLength,
                                     uint8_t ** ppRxBuffer,
                                     uint16_t * pRxLength
                                     )
{
    phStatus_t  PH_MEMLOC_REM status;
    phStatus_t  PH_MEMLOC_REM statusTmp;
    uint16_t    PH_MEMLOC_REM wValidBits;
    uint16_t    PH_MEMLOC_REM wCrcIn;
    uint16_t    PH_MEMLOC_REM wCrcCalc;
	uint16_t	PH_MEMLOC_REM RxLength;
	uint8_t *	PH_MEMLOC_REM pRxBuffer;
	int debug = 0;

	/* Check if caller has provided valid RxBuffer */
	if (ppRxBuffer == NULL)
	{
		ppRxBuffer = &pRxBuffer;
	}
	if (pRxLength == NULL)
	{
		pRxLength = &RxLength;
	}

    /* Switch CRC modes in case of first part of exchange. */
    if (!(wOption & PH_EXCHANGE_BUFFERED_BIT))
    {
        /* Enable TxCrc */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_TXCRC, PH_ON));

        /* Disable RxCrc */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_RXCRC, PH_OFF));
    }
    /* Perform Exchange */
    status = phhalHw_Exchange(
        pDataParams->pHalDataParams,
        wOption,
        pTxBuffer,
        wTxLength,
        ppRxBuffer,
        pRxLength);

    /* Return if no real exchange is done */
    if (wOption & PH_EXCHANGE_BUFFERED_BIT)
    {
        return status;
    }

    /* ACK/NAK Handling */
    if ((status & PH_ERR_MASK) == PH_ERR_SUCCESS_INCOMPLETE_BYTE)
    {
		if(debug) puts("ACKNAK");
        /* Check for protocol error */
        if (*pRxLength != 1)
        {
            return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_PAL_MIFARE);
        }

        /* Retrieve bitcount */
        PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_GetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_RXLASTBITS, &wValidBits));

        /* Check for protocol error */
        if (wValidBits != 4)
        {
            return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_PAL_MIFARE);
        }
        /* ACK/NAK Mapping */
		if(debug) printf("(*ppRxBuffer)[0] %02x\n", (*ppRxBuffer)[0]);
        switch ((*ppRxBuffer)[0])
        {
            /* ACK -> everything OK */
        case PHPAL_MIFARE_RESP_ACK:
            status = PH_ERR_SUCCESS;
            break;
		case PHPAL_MIFARE_RESP_AUTH:
            status = PH_ERR_SUCCESS;
            break;			
            /* Mapping of NAK codes: */
        case PHPAL_MIFARE_RESP_NAK0:
            status = PHPAL_MIFARE_ERR_NAK0;
            break;
        case PHPAL_MIFARE_RESP_NAK1:
            status = PHPAL_MIFARE_ERR_NAK1;
            break;
        case PHPAL_MIFARE_RESP_NAK4:
            status = PHPAL_MIFARE_ERR_NAK4;
            break;
        case PHPAL_MIFARE_RESP_NAK5:
            status = PHPAL_MIFARE_ERR_NAK5;
            break;
        case PHPAL_MIFARE_RESP_NAK6:
            status = PHPAL_MIFARE_ERR_NAK6;
            break;
        case PHPAL_MIFARE_RESP_NAK7:
            status = PHPAL_MIFARE_ERR_NAK7;
            break;
        case PHPAL_MIFARE_RESP_NAK9:
            status = PHPAL_MIFARE_ERR_NAK9;
            break;
        default:
            status = PH_ERR_PROTOCOL_ERROR;
            break;
        }
		if(debug) printf("statusACK %02x\n", status);
    }
    /* Normal data stream with CRC */
    else
    {
        /* Check status */
        PH_CHECK_SUCCESS(status);

        /* Check length (min. 1 byte + 2 byte CRC) */
        if (*pRxLength < 3)
        {
            return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_PAL_MIFARE);
        }

        /* Retrieve CRC */
        wCrcIn  = (uint16_t)(((uint16_t)(*ppRxBuffer)[(*pRxLength) - 1]) << 8);
        wCrcIn |= (uint16_t)((*ppRxBuffer)[(*pRxLength) - 2]);

        /* Remove CRC from input data */
        *pRxLength -= 2;

        /* Calculate CRC */
        PH_CHECK_SUCCESS_FCT(statusTmp, phTools_CalculateCrc16(
            PH_TOOLS_CRC_OPTION_DEFAULT,
            PH_TOOLS_CRC16_PRESET_ISO14443A,
            PH_TOOLS_CRC16_POLY_ISO14443,
            *ppRxBuffer, 
            *pRxLength, 
            &wCrcCalc));

        /* CRC Check -> Compare input and calculated crc */
        if (wCrcIn == wCrcCalc)
        {
            status = PH_ERR_SUCCESS;
        }
        else
        {
            status = PH_ERR_INTEGRITY_ERROR;
        }
    }

    return PH_ADD_COMPCODE(status, PH_COMP_PAL_MIFARE);
}
Exemple #29
0
/* SNEP Server Server Send Response API */
phStatus_t phnpSnep_ServerSendResponse( void            *pDataParams,
                                        ph_NfcHandle     ConnHandle,
                                        phNfc_sData_t   *pResponseData,
                                        phStatus_t       responseStatus,
                                        ph_NfcHandle     fSendCompleteCb,
                                        void            *cbContext
                                      )
{
    phStatus_t status;

    PH_LOG_HELPER_ALLOCATE_TEXT(bFunctionName, "phnpSnep_ServerSendResponse");
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(pResponseData);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(responseStatus);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(fSendCompleteCb);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(cbContext);
    PH_LOG_HELPER_ALLOCATE_PARAMNAME(status);
    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_ENTER);
    PH_ASSERT_NULL (pDataParams);
    PH_ASSERT_NULL (pResponseData);
    //PH_ASSERT_NULL (responseStatus); DG: If successful, this is == 0
    PH_ASSERT_NULL (fSendCompleteCb);
    PH_ASSERT_NULL (cbContext);

    /* Check data parameters */
    if (PH_GET_COMPCODE(pDataParams) != PH_COMP_NP_SNEP)
    {
        status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_NP_SNEP);

        PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
        PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
        PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);
        return status;
    }

    /* perform operation on active layer */
    switch (PH_GET_COMPID(pDataParams))
    {
#ifdef NXPBUILD__PHNP_SNEP_FRI
    case PHNP_SNEP_FRI_ID:

    status = phnpSnep_Fri_ServerSendResponse( (phnpSnep_Fri_DataParams_t *) pDataParams,
                                               ConnHandle,
                                              (phNfc_sData_t *) pResponseData,
                                               responseStatus,
                                              (pphnpSnep_Fri_Protocol_SendRspCb_t) fSendCompleteCb,
                                              (void *) cbContext
                                             );

        break;
#endif /* NXPBUILD__PHNP_SNEP_FRI */

    default:
        status = PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_NP_SNEP);
        break;
    }

    PH_LOG_HELPER_ADDSTRING(PH_LOG_LOGTYPE_INFO, bFunctionName);
    PH_LOG_HELPER_ADDPARAM_UINT16(PH_LOG_LOGTYPE_INFO, status_log, &status);
    PH_LOG_HELPER_EXECUTE(PH_LOG_OPTION_CATEGORY_LEAVE);

    return status;
}
Exemple #30
0
phStatus_t phalI15693_Sw_WriteMultipleBlocks(
    phalI15693_Sw_DataParams_t * pDataParams,
    uint8_t bOption,
    uint8_t bBlockNo,
    uint16_t wNumBlocks,
    uint8_t * pTxBuffer,
    uint16_t wTxLength
    )
{
    phStatus_t  PH_MEMLOC_REM statusTmp;
    phStatus_t  PH_MEMLOC_REM status;
    uint8_t     PH_MEMLOC_REM bCommand[3];
    uint8_t *   PH_MEMLOC_REM pRxBuffer;
    uint16_t    PH_MEMLOC_REM bRxLength;

    /* Number of wNumBlocks can't be zero */
    if (wNumBlocks == 0)
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_AL_I15693);
    }

    /* adjust number of blocks. */
    --wNumBlocks;

    /* Check number of blocks doesn't exceed 256 */
    if (((uint16_t)bBlockNo + wNumBlocks) >= 0x100)
    {
        return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_AL_I15693);
    }

    /* Build command */
    bCommand[0] = PHAL_I15693_SW_CMD_WRITE_MULTIPLE_BLOCKS;
    bCommand[1] = bBlockNo;
    bCommand[2] =(uint8_t)wNumBlocks;

    /* Set or clear the flags option bit indicated by bOption. */
    PH_CHECK_SUCCESS_FCT(statusTmp, phalI15693_Sw_Int_SetOptionBit(pDataParams, bOption));

    /* Set long timeout. */
    PH_CHECK_SUCCESS_FCT(statusTmp, phpalSli15693_SetConfig(
        pDataParams->pPalSli15693DataParams,
        PHPAL_SLI15693_CONFIG_TIMEOUT_US,
        PHPAL_SLI15693_TIMEOUT_LONG_US));

    /* Proceed with the command in lower layers */
    PH_CHECK_SUCCESS_FCT(statusTmp, phpalSli15693_Exchange(
        pDataParams->pPalSli15693DataParams,
        PH_EXCHANGE_BUFFER_FIRST,
        bCommand,
        3,
        NULL,
        NULL));

    status = phpalSli15693_Exchange(
        pDataParams->pPalSli15693DataParams,
        PH_EXCHANGE_BUFFER_LAST,
        pTxBuffer,
        wTxLength,
        &pRxBuffer,
        &bRxLength);

    /* Write-alike handling */
    if (bOption != PHAL_I15693_OPTION_OFF)
    {
        return phalI15693_Sw_WriteAlikeHandling(pDataParams, status);
    }

    return status;
}