phStatus_t phalMfp_SamAV2_X_WritePerso( phalMfp_SamAV2_X_DataParams_t * pDataParams, uint8_t bLayer4Comm, uint16_t wBlockNr, uint8_t * pValue ) { phStatus_t PH_MEMLOC_REM status; phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_REM pEntryPair[2 + PHAL_MFP_MIFARE_BLOCK_SIZE]; uint8_t PH_MEMLOC_REM bResponseCode; /* Sam natively only supprots L4 WRITE Perso writing*/ if (bLayer4Comm) { pEntryPair[0] = (uint8_t)(wBlockNr); pEntryPair[1] = (uint8_t)(wBlockNr >> 8); memcpy(&pEntryPair[2], pValue, PHAL_MFP_MIFARE_BLOCK_SIZE); /* PRQA S 3200 */ status = phhalHw_SamAV2_Cmd_MfpWritePerso( pDataParams->pHalDataParams, pEntryPair, 2 + PHAL_MFP_MIFARE_BLOCK_SIZE, &bResponseCode); /* Convert HAL status codes to palMifare status codes */ PH_CHECK_SUCCESS_FCT(statusTmp, phalMfp_SamAV2_X_ConvertNak(status)); /* Check Card response*/ PH_CHECK_SUCCESS_FCT(statusTmp, phalMfp_Int_ComputeErrorResponse(1, bResponseCode, bLayer4Comm)); } else {
phStatus_t phalVca_SamAV2_DeselectVc( phalVca_SamAV2_DataParams_t * pDataParams ) { /* local variables */ phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_REM aCommand[1 /* command code */]; uint8_t * PH_MEMLOC_REM pResponse; uint16_t PH_MEMLOC_REM wRxLength; /* command code */ aCommand[0] = PHAL_VCA_CMD_DVC; /* command exchange */ PH_CHECK_SUCCESS_FCT(statusTmp, phpalMifare_ExchangeL4( pDataParams->pPalMifareDataParams, PH_EXCHANGE_DEFAULT, aCommand, 1, &pResponse, &wRxLength)); /* check response */ PH_CHECK_SUCCESS_FCT(statusTmp, phalVca_Int_ComputeErrorResponse(wRxLength, pResponse[0])); /* check response length */ if (wRxLength != 1 /* STATUS */) { return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_AL_VCA); } return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_VCA); }
phStatus_t phalVca_SamAV2_SelectVc( phalVca_SamAV2_DataParams_t * pDataParams, uint16_t wValidIidIndex, uint16_t wKeyNumber, uint16_t wKeyVersion ) { /* local variables */ phStatus_t PH_MEMLOC_REM status; phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_REM aCommand[9]; uint8_t * PH_MEMLOC_REM pResponse; uint16_t PH_MEMLOC_REM wRxLength; status = phalVca_SamAV2_Int_ResolveValidIndex( pDataParams, wValidIidIndex, &wValidIidIndex); /* for the case of an overflow we always send the first random number to the SAM */ if ((status & PH_ERR_MASK) == PH_ERR_INVALID_PARAMETER) { wValidIidIndex = 0; } else { PH_CHECK_SUCCESS(status); } aCommand[0] = PHAL_VCA_CMD_SVC; /* Prepare Buffer */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SamAV2_Cmd_SAM_SelectVirtualCardMfp( pDataParams->pSamHal, (uint8_t)wKeyNumber, (uint8_t)wKeyVersion, &pDataParams->pRndq[wValidIidIndex * 12], NULL, 0, &aCommand[1])); /* command exchange */ PH_CHECK_SUCCESS_FCT(statusTmp, phpalMifare_ExchangeL4( pDataParams->pPalMifareDataParams, PH_EXCHANGE_DEFAULT, aCommand, 9, &pResponse, &wRxLength)); PH_CHECK_SUCCESS_FCT(statusTmp, phalVca_Int_ComputeErrorResponse(wRxLength, pResponse[0])); /* check response length */ if (wRxLength != 1 /* STATUS */) { return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_AL_VCA); } return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_VCA); }
phStatus_t phalVca_SamAV2_StartCardSelection ( phalVca_SamAV2_DataParams_t * pDataParams ) { phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_REM wIndex; /* Obtain Random Numbers */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SamAV2_Cmd_SAM_GetChallenge(pDataParams->pSamHal, (uint8_t)(12 * pDataParams->wNumCardTableEntries), pDataParams->pRndq)); /* Send the complete stream to the SAM */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SamAV2_Cmd_SAM_VirtualCardSupportMfp( pDataParams->pSamHal, PH_EXCHANGE_BUFFER_FIRST, NULL, 0, NULL, 0, NULL, NULL)); pDataParams->wCurrentCardTablePos = 0; for (wIndex = 0; wIndex < pDataParams->wNumCardTableEntries; ++wIndex) { pDataParams->pCardTable[wIndex].bNumKeyDuos = 0; pDataParams->pCardTable[wIndex].wIidIndex = 0xFF; } return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_VCA); }
phStatus_t phKeyStore_Sw_GetKey( phKeyStore_Sw_DataParams_t * pDataParams, uint16_t wKeyNo, uint16_t wKeyVersion, uint8_t bKeyBufSize, uint8_t * pKey, uint16_t * pKeyType ) { phStatus_t statusTmp; uint16_t wKeySize; phKeyStore_Sw_KeyVersionPair_t * pKeyVersion; PH_CHECK_SUCCESS_FCT(statusTmp, phKeyStore_Sw_GetKeyValuePtrVersion(pDataParams,wKeyNo,wKeyVersion,&pKeyVersion)); /* Check for Counter overflow */ PH_CHECK_SUCCESS_FCT(statusTmp, phKeyStore_Sw_CheckUpdateKUC(pDataParams,pDataParams->pKeyEntries[wKeyNo].wRefNoKUC)); /* check buffer size */ wKeySize = phKeyStore_GetKeySize(pDataParams->pKeyEntries[wKeyNo].wKeyType); if (bKeyBufSize < wKeySize) { return PH_ADD_COMPCODE(PH_ERR_BUFFER_OVERFLOW, PH_COMP_KEYSTORE); } /* copy the key */ memcpy(pKey, pKeyVersion->pKey, wKeySize); /* PRQA S 3200 */ *pKeyType = pDataParams->pKeyEntries[wKeyNo].wKeyType; return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_KEYSTORE); }
phStatus_t readSector(uint8_t sector_id, uint8_t * key, uint8_t key_type, uint8_t * bUid, uint8_t * data) { uint8_t block = sector_id << 2; PH_CHECK_SUCCESS_FCT(status, phhalHw_MfcAuthenticate(&hal, block, key_type, key, bUid)); PH_CHECK_SUCCESS_FCT(status, phalMfc_Read(&alMfc, block + 0, &data[0 * 16])); PH_CHECK_SUCCESS_FCT(status, phalMfc_Read(&alMfc, block + 1, &data[1 * 16])); PH_CHECK_SUCCESS_FCT(status, phalMfc_Read(&alMfc, block + 2, &data[2 * 16])); PH_CHECK_SUCCESS_FCT(status, phalMfc_Read(&alMfc, block + 3, &data[3 * 16])); return PH_ERR_SUCCESS; }
phStatus_t search_card(uint8_t * pUid, uint8_t * pLength, uint8_t * pSak, uint8_t * pNbCards) { PH_CHECK_SUCCESS_FCT(status, phhalHw_FieldReset(&hal)); PH_CHECK_SUCCESS_FCT(status, phhalHw_ApplyProtocolSettings(&hal, PHHAL_HW_CARDTYPE_ISO14443A)); PH_CHECK_SUCCESS_FCT(status, phpalI14443p3a_ActivateCard(&palI14443p3a, NULL, 0x00, pUid, pLength, pSak, pNbCards)); return PH_ERR_SUCCESS; }
phStatus_t phalMfc_Sw_RestoreTransfer( phalMfc_Sw_DataParams_t * pDataParams, uint8_t bSrcBlockNo, uint8_t bDstBlockNo ) { phStatus_t PH_MEMLOC_REM statusTmp; PH_CHECK_SUCCESS_FCT(statusTmp, phalMfc_Sw_Restore(pDataParams, bSrcBlockNo)); PH_CHECK_SUCCESS_FCT(statusTmp, phalMfc_Sw_Transfer(pDataParams, bDstBlockNo)); return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_MFC); }
phStatus_t phalI15693_Sw_WriteSingleBlock( phalI15693_Sw_DataParams_t * pDataParams, uint8_t bOption, uint8_t bBlockNo, uint8_t * pTxBuffer, uint16_t wTxLength ) { phStatus_t PH_MEMLOC_REM statusTmp; phStatus_t PH_MEMLOC_REM status; uint8_t PH_MEMLOC_REM bCommand[2]; uint8_t * PH_MEMLOC_REM pRxBuffer; uint16_t PH_MEMLOC_REM bRxLength; /* Build command */ bCommand[0] = PHAL_I15693_SW_CMD_WRITE_SINGLE_BLOCK; bCommand[1] = bBlockNo; /* 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, 2, NULL, NULL)); /* Append given data */ 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; }
phStatus_t phalI15693_Sw_ReadSingleBlock( phalI15693_Sw_DataParams_t * pDataParams, uint8_t bOption, uint8_t bBlockNo, uint8_t ** ppRxBuffer, uint16_t * pRxLength ) { phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_REM bCommand[2]; /* Build command */ bCommand[0] = PHAL_I15693_SW_CMD_READ_SINGLE_BLOCK; bCommand[1] = bBlockNo; /* Set or clear the flags option bit indicated by bOption. */ PH_CHECK_SUCCESS_FCT(statusTmp, phalI15693_Sw_Int_SetOptionBit(pDataParams, bOption)); /* 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, 2, ppRxBuffer, pRxLength)); /* Length check */ if (bOption != PHAL_I15693_OPTION_OFF) { if (*pRxLength < 2) { return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_AL_I15693); } } else { if (*pRxLength == 0) { return PH_ADD_COMPCODE(PH_ERR_PROTOCOL_ERROR, PH_COMP_AL_I15693); } } return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_I15693); }
phStatus_t phalI15693_Sw_GetMultipleBlockSecurityStatus( phalI15693_Sw_DataParams_t * pDataParams, uint8_t bBlockNo, uint16_t wNumBlocks, uint8_t ** ppRxBuffer, uint16_t * pRxLength ) { phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_REM bCommand[3]; /* 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); } /* Clear Option bit */ PH_CHECK_SUCCESS_FCT(statusTmp, phalI15693_Sw_Int_SetOptionBit(pDataParams, PHAL_I15693_OPTION_OFF)); /* Build command */ bCommand[0] = PHAL_I15693_SW_CMD_GET_MULTIPLE_BLOCK_SEC; bCommand[1] = bBlockNo; bCommand[2] = (uint8_t)wNumBlocks; /* 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, 3, ppRxBuffer, pRxLength)); return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_I15693); }
phStatus_t phCryptoRng_Sw_Reseed( phCryptoRng_Sw_DataParams_t * pDataParams, uint8_t * pEntropyInput, uint16_t wEntropyInputLength, uint8_t * pAdditionalInput, uint8_t bAdditionalInputLength ) { phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_REM aSeedMaterial[PHCRYPTORNG_SW_SEEDLEN]; /* Check for operational state */ if (pDataParams->bState != PHCRYPTORNG_SW_STATE_WORKING) { return PH_ADD_COMPCODE(PH_ERR_USE_CONDITION, PH_COMP_CRYPTORNG); } /* Comment: Ensure that the length of the seed_material is exactly seedlen bits. */ if (PHCRYPTORNG_SW_SEEDLEN != (wEntropyInputLength + bAdditionalInputLength)) { return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_CRYPTORNG); } /* Prepare seed Material */ /* 1. seed_material = entropy_input || additional_input. */ memcpy(aSeedMaterial, pEntropyInput, wEntropyInputLength); /* PRQA S 3200 */ memcpy(&aSeedMaterial[wEntropyInputLength], pAdditionalInput, bAdditionalInputLength); /* PRQA S 3200 */ /* Encrypt the seed value */ /* 2. seed_material = Block_Cipher_df (seed_material, seedlen). */ PH_CHECK_SUCCESS_FCT(statusTmp, phCryptoRng_Sw_BlockCipherDf( pDataParams, aSeedMaterial)); /* Update using aSeedMaterial as the personalization string. */ /* 3. (Key, V) = Update (seed_material, Key, V). */ PH_CHECK_SUCCESS_FCT(statusTmp, phCryptoRng_Sw_Update(pDataParams, aSeedMaterial)); /* Set the counter again to 1. */ /* 4. reseed_counter = 1. */ pDataParams->dwRequestCounter = 1; /* 5. Return V, Key, and reseed_counter as the new_working_state. */ /* Clear seed material for security reasons */ memset(aSeedMaterial, 0x00, sizeof(aSeedMaterial)); /* PRQA S 3200 */ return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_CRYPTORNG); }
phStatus_t phKeyStore_Rc632_SetFullKeyEntry( phKeyStore_Rc632_DataParams_t * pDataParams, uint16_t wNoOfKeys, uint16_t wKeyNo, uint16_t wNewRefNoKUC, uint16_t wNewKeyType, uint8_t * pNewKeys, uint16_t * pNewKeyVersionList ) { phStatus_t PH_MEMLOC_REM statusTmp; uint16_t PH_MEMLOC_REM wKeyVersion = 0; uint16_t PH_MEMLOC_COUNT i; /* satisfy compiler */ if (pNewKeyVersionList || wNewRefNoKUC); /* check wNoOfKeys */ if (wNoOfKeys > PH_KEYSTORE_RC632_NUM_VERSIONS) { return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_KEYSTORE); } /* set keys */ for (i = 0; i < wNoOfKeys; ++i) { PH_CHECK_SUCCESS_FCT(statusTmp, phKeyStore_Rc632_SetKeyAtPos(pDataParams, wKeyNo, i, wNewKeyType, &pNewKeys[i*PH_KEYSTORE_KEY_TYPE_MIFARE_SIZE], wKeyVersion)); } return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_KEYSTORE); }
phStatus_t phalVca_SamAV2_GetIidInfo( phalVca_SamAV2_DataParams_t * pDataParams, uint16_t wValidIidIndex, uint16_t * pIidIndex, uint8_t * pVcUidSize, uint8_t * pVcUid, uint8_t * pInfo, uint8_t * pPdCapabilities ) { phStatus_t PH_MEMLOC_REM statusTmp; PH_CHECK_SUCCESS_FCT(statusTmp, phalVca_SamAV2_Int_ResolveValidIndex( pDataParams, wValidIidIndex, &wValidIidIndex)); *pIidIndex = pDataParams->pCardTable[wValidIidIndex].wIidIndex; *pInfo = pDataParams->pCardTable[wValidIidIndex].pCardData[0]; pPdCapabilities[0] = pDataParams->pCardTable[wValidIidIndex].pCardData[1]; pPdCapabilities[1] = pDataParams->pCardTable[wValidIidIndex].pCardData[2]; if (*pInfo & 0x80) { *pVcUidSize = 4; memcpy(pVcUid, &pDataParams->pCardTable[wValidIidIndex].pCardData[3], 4); /* PRQA S 3200 */ } else { *pVcUidSize = 7; memcpy(pVcUid, &pDataParams->pCardTable[wValidIidIndex].pCardData[3], 7); /* PRQA S 3200 */ } return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_VCA); }
phStatus_t phKeyStore_Sw_GetKeyEntry( phKeyStore_Sw_DataParams_t * pDataParams, uint16_t wKeyNo, uint16_t wKeyVersionBufSize, uint16_t * wKeyVersion, uint16_t * wKeyVersionLength, uint16_t * pKeyType ) { phStatus_t statusTmp; uint16_t i; phKeyStore_Sw_KeyVersionPair_t * pKeyVersion; /* Check for overflow */ if (wKeyVersionBufSize < (sizeof(uint16_t) * pDataParams->wNoOfVersions)) { return PH_ADD_COMPCODE(PH_ERR_BUFFER_OVERFLOW, PH_COMP_KEYSTORE); } for (i = 0; i < pDataParams->wNoOfVersions; i++) { PH_CHECK_SUCCESS_FCT(statusTmp, phKeyStore_Sw_GetKeyValuePtrPos(pDataParams,wKeyNo,i,&pKeyVersion)); wKeyVersion[i] = pKeyVersion->wVersion; } *wKeyVersionLength = pDataParams->wNoOfVersions; *pKeyType = pDataParams->pKeyEntries[wKeyNo].wKeyType; return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_KEYSTORE); }
phStatus_t phKeyStore_Sw_SetKeyAtPos( phKeyStore_Sw_DataParams_t * pDataParams, uint16_t wKeyNo, uint16_t wPos, uint16_t wKeyType, uint8_t * pNewKey, uint16_t wNewKeyVersion ) { phStatus_t statusTmp; phKeyStore_Sw_KeyVersionPair_t * pKeyVersion; PH_CHECK_SUCCESS_FCT(statusTmp, phKeyStore_Sw_GetKeyValuePtrPos(pDataParams,wKeyNo,wPos,&pKeyVersion)); /* Check that Key type matches with current Key Type format */ if (pDataParams->pKeyEntries[wKeyNo].wKeyType != wKeyType) { return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_KEYSTORE); } /* copy the key and version */ memcpy(pKeyVersion->pKey, pNewKey, phKeyStore_GetKeySize(wKeyType)); /* PRQA S 3200 */ pKeyVersion->wVersion = wNewKeyVersion; return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_KEYSTORE); }
phStatus_t forceReadSector(uint8_t sector_id, uint8_t ** keys, uint16_t nbKeys, uint8_t * data) { uint8_t bSak[1]; uint8_t bUid[10]; uint8_t bNbCards; uint8_t bLength; uint16_t i; PH_CHECK_SUCCESS_FCT(status, search_card(bUid, &bLength, bSak, &bNbCards)); for (i = 0; i < nbKeys; i++) { if (readSector(sector_id, keys[i], PHAL_MFC_KEYA, bUid, data) == PH_ERR_SUCCESS) return PH_ERR_SUCCESS; PH_CHECK_SUCCESS_FCT(status, search_card(bUid, &bLength, bSak, &bNbCards)); if (readSector(sector_id, keys[i], PHAL_MFC_KEYB, bUid, data) == PH_ERR_SUCCESS) return PH_ERR_SUCCESS; PH_CHECK_SUCCESS_FCT(status, search_card(bUid, &bLength, bSak, &bNbCards)); } return PH_ERR_AUTH_ERROR; }
phStatus_t phalI15693_Sw_Int_SetOptionBit( phalI15693_Sw_DataParams_t * pDataParams, uint8_t bOption ) { phStatus_t PH_MEMLOC_REM statusTmp; uint16_t PH_MEMLOC_REM wFlagsCurrent; uint16_t PH_MEMLOC_REM wFlagsNew; /* Next check if the Option Byte has a valid value */ if ((bOption != PHAL_I15693_OPTION_OFF) &&(bOption != PHAL_I15693_OPTION_ON)) { return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_AL_I15693); } /* retrieve the flags byte */ PH_CHECK_SUCCESS_FCT(statusTmp, phpalSli15693_GetConfig( pDataParams->pPalSli15693DataParams, PHPAL_SLI15693_CONFIG_FLAGS, &wFlagsCurrent)); /* Set Option bit */ if (bOption != PHAL_I15693_OPTION_OFF) { wFlagsNew = wFlagsCurrent | PHPAL_SLI15693_FLAG_OPTION; } /* Clear option bit */ else { wFlagsNew = wFlagsCurrent &(uint8_t)~(uint8_t)PHPAL_SLI15693_FLAG_OPTION; } /* update the flags byte */ if (wFlagsNew != wFlagsCurrent) { PH_CHECK_SUCCESS_FCT(statusTmp, phpalSli15693_SetConfig( pDataParams->pPalSli15693DataParams, PHPAL_SLI15693_CONFIG_FLAGS, wFlagsNew)); } return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_I15693); }
phStatus_t phalVca_Sw_ProximityCheck( phalVca_Sw_DataParams_t * pDataParams, uint8_t bGenerateRndC, uint8_t* pRndC, uint8_t bPps1, uint8_t bNumSteps, uint16_t wKeyNumber, uint16_t wKeyVersion, uint8_t * pUsedRndRC ) { phStatus_t PH_MEMLOC_REM statusTmp; PH_CHECK_SUCCESS_FCT(statusTmp, phalVca_Sw_Cmd_PrepareProximityCheck(pDataParams)); PH_CHECK_SUCCESS_FCT(statusTmp, phalVca_Sw_Cmd_ProximityCheck(pDataParams, bGenerateRndC, pRndC, bNumSteps, pUsedRndRC)); return (phalVca_Sw_Cmd_VerifyProximityCheck(pDataParams, pUsedRndRC, bPps1, wKeyNumber, wKeyVersion)); }
phStatus_t phhalHw_Pn512_Cmd_GenerateRandomId( phhalHw_Pn512_DataParams_t * pDataParams ) { phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_REM bIrq0WaitFor = 0x0; uint8_t PH_MEMLOC_REM bIrq1WaitFor = 0x0; uint8_t PH_MEMLOC_REM bIrq0Rq; uint8_t PH_MEMLOC_REM bIrq1Rq; /* start the command */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_WriteRegister(pDataParams, PHHAL_HW_PN512_REG_COMMAND, PHHAL_HW_PN512_CMD_RANDOMIDS)); /* wait until the command is finished */ bIrq0WaitFor = PHHAL_HW_PN512_BIT_IDLEI; PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Pn512_WaitIrq(pDataParams, bIrq0WaitFor,bIrq1WaitFor,&bIrq0Rq,&bIrq1Rq)); return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL); }
phStatus_t phalI15693_Sw_WriteDSFID( phalI15693_Sw_DataParams_t * pDataParams, uint8_t bOption, uint8_t bDsfid ) { phStatus_t PH_MEMLOC_REM statusTmp; phStatus_t PH_MEMLOC_REM status; uint8_t PH_MEMLOC_REM bCommand[2]; uint8_t * PH_MEMLOC_REM pRxBuffer; uint16_t PH_MEMLOC_REM bRxLength; /* Build command */ bCommand[0] = PHAL_I15693_SW_CMD_WRITE_DSFID; bCommand[1] = bDsfid; /* 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 */ status = phpalSli15693_Exchange( pDataParams->pPalSli15693DataParams, PH_EXCHANGE_DEFAULT, bCommand, 2, &pRxBuffer, &bRxLength); /* Write-alike handling */ if (bOption != PHAL_I15693_OPTION_OFF) { return phalI15693_Sw_WriteAlikeHandling(pDataParams, status); } return status; }
phStatus_t phhalHw_Rd70x_ReadFifo( phhalHw_Rd70x_DataParams_t * pDataParams, uint16_t wBufSize, uint8_t * pData, uint16_t * pLength ) { phStatus_t PH_MEMLOC_REM status; phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_COUNT bIndex; uint8_t PH_MEMLOC_COUNT bFifoLen; /* read out the FiFo Length register */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister(pDataParams, PHHAL_HW_RD70X_REG_FIFO_LENGTH, &bFifoLen)); /* check for buffer overflow */ if (bFifoLen > (uint8_t)wBufSize) { /* read maximum possible number of bytes */ bFifoLen = (uint8_t)wBufSize; /* return buffer overflow status */ status = PH_ERR_BUFFER_OVERFLOW; } else { /* Buffer is big enough */ status = PH_ERR_SUCCESS; } /* Read each single data byte */ for (bIndex = 0; bIndex < bFifoLen; ++bIndex) { PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_Rd70x_ReadRegister( pDataParams, PHHAL_HW_RD70X_REG_FIFO_DATA, &pData[bIndex])); } *pLength = (uint16_t)bFifoLen; return PH_ADD_COMPCODE(status, PH_COMP_HAL); }
phStatus_t phKeyStore_Sw_Init( phKeyStore_Sw_DataParams_t * pDataParams, uint16_t wSizeOfDataParams, phKeyStore_Sw_KeyEntry_t * pKeyEntries, uint16_t wNoOfKeyEntries, phKeyStore_Sw_KeyVersionPair_t * pKeyVersionPairs, uint16_t wNoOfVersionPairs, phKeyStore_Sw_KUCEntry_t * pKUCEntries, uint16_t wNoOfKUCEntries ) { uint16_t i; uint16_t j; phStatus_t statusTmp; phKeyStore_Sw_KeyVersionPair_t * pKeyVersion; if (sizeof(phKeyStore_Sw_DataParams_t) != wSizeOfDataParams) { return PH_ADD_COMPCODE(PH_ERR_INVALID_DATA_PARAMS, PH_COMP_KEYSTORE); } PH_ASSERT_NULL (pDataParams); PH_ASSERT_NULL (pKeyEntries); PH_ASSERT_NULL (pKeyVersionPairs); PH_ASSERT_NULL (pKUCEntries); /* Init private data */ pDataParams->wId = PH_COMP_KEYSTORE | PH_KEYSTORE_SW_ID; pDataParams->pKeyEntries = pKeyEntries; pDataParams->pKeyVersionPairs = pKeyVersionPairs; pDataParams->wNoOfKeyEntries = wNoOfKeyEntries; pDataParams->wNoOfVersions = wNoOfVersionPairs; pDataParams->pKUCEntries = pKUCEntries; pDataParams->wNoOfKUCEntries = wNoOfKUCEntries; for (i = 0; i < pDataParams->wNoOfKeyEntries; i++) { pDataParams->pKeyEntries[i].wKeyType = PH_KEYSTORE_INVALID_ID; pDataParams->pKeyEntries[i].wRefNoKUC = PH_KEYSTORE_INVALID_ID; for (j = 0; j < pDataParams->wNoOfVersions; j++) { PH_CHECK_SUCCESS_FCT(statusTmp, phKeyStore_Sw_GetKeyValuePtrPos(pDataParams, i, j, &pKeyVersion)); pKeyVersion->wVersion = PH_KEYSTORE_DEFAULT_ID; } } for (i = 0; i < pDataParams->wNoOfKUCEntries; i++) { pDataParams->pKUCEntries[i].dwLimit = 0xFFFFFFFF; pDataParams->pKUCEntries[i].dwCurVal = 0; } return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_KEYSTORE); }
phStatus_t phalTop_Sw_Int_T1T_Read( phalTop_T1T_t * pT1T, uint16_t wAddress, uint8_t * pData, uint8_t bFreshRead ) { phStatus_t PH_MEMLOC_REM status; uint16_t PH_MEMLOC_REM wLength; if(pT1T->bTagMemoryType != PHAL_TOP_T1T_TAG_MEMORY_TYPE_STATIC) { if((pT1T->sSegment.bBlockAddress != (wAddress / 8)) || (pT1T->sSegment.bValidity == PH_OFF) || (bFreshRead == PH_ON)) { pT1T->sSegment.bBlockAddress = (uint8_t)(wAddress / 8); pT1T->sSegment.bAddress = (uint8_t)(wAddress / PHAL_TOP_T1T_SEGMENT_SIZE); PH_CHECK_SUCCESS_FCT(status, phalT1T_ReadBlock( pT1T->phalT1TDataParams, pT1T->bUid, pT1T->sSegment.bBlockAddress, pData, &wLength)); pT1T->sSegment.bValidity = PH_ON; } pData[0] = pData[1 + (wAddress % 8)]; } else { PH_CHECK_SUCCESS_FCT(status, phalT1T_ReadByte( pT1T->phalT1TDataParams, pT1T->bUid, (uint8_t)wAddress, pData, &wLength)); pData[0] = pData[1]; } return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_TOP); }
phStatus_t phpalMifare_Sw_SetMinFdtPc( phpalMifare_Sw_DataParams_t * pDataParams, uint16_t wValue ) { phStatus_t PH_MEMLOC_REM status; /* Execute HAL Setconfig function */ PH_CHECK_SUCCESS_FCT( status, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_SETMINFDT, wValue)); return status; }
phStatus_t phpalMifare_Sw_ExchangeL4( 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 statusTmp; /* Not available if no Layer4 has been set */ if (pDataParams->pPalI14443p4DataParams == NULL) { return PH_ADD_COMPCODE(PH_ERR_UNSUPPORTED_COMMAND, PH_COMP_PAL_MIFARE); } /* Enable TxCrc */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_TXCRC, PH_ON)); /* Enable RxCrc */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_SetConfig(pDataParams->pHalDataParams, PHHAL_HW_CONFIG_RXCRC, PH_ON)); /* Perform Exchange */ PH_CHECK_SUCCESS_FCT(statusTmp, phpalI14443p4_Exchange( pDataParams->pPalI14443p4DataParams, wOption, pTxBuffer, wTxLength, ppRxBuffer, pRxLength)); 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 }
phStatus_t phhalHw_SamAV2_Rc523_GetFdt( phhalHw_SamAV2_DataParams_t * pDataParams, uint32_t * pTime ) { phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_REM bRegister; uint16_t PH_MEMLOC_REM wDataRate; uint16_t PH_MEMLOC_REM wPsReload; uint16_t PH_MEMLOC_REM wTReload; uint16_t PH_MEMLOC_REM wTValue; float32_t PH_MEMLOC_REM fTimeout; /* Retrieve RxDataRate */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_GetConfig(pDataParams, PHHAL_HW_CONFIG_RXDATARATE, &wDataRate)); wDataRate++; /* Get prescaler value */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_ReadRegister(pDataParams, PHHAL_HW_SAMAV2_RC523_REG_TMODE, &bRegister)); wPsReload = (uint16_t)(bRegister & PHHAL_HW_SAMAV2_RC523_MASK_TPRESCALER_HI) << 8; PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_ReadRegister(pDataParams, PHHAL_HW_SAMAV2_RC523_REG_TPRESCALER, &bRegister)); wPsReload |= (uint16_t)bRegister; /* Get reload value */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_ReadRegister(pDataParams, PHHAL_HW_SAMAV2_RC523_REG_TRELOADHI, &bRegister)); wTReload = (uint16_t)bRegister << 8; PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_ReadRegister(pDataParams, PHHAL_HW_SAMAV2_RC523_REG_TRELOADLO, &bRegister)); wTReload |= (uint16_t)bRegister; /* Get counter value */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_ReadRegister(pDataParams, PHHAL_HW_SAMAV2_RC523_REG_TCOUNTERVALHI, &bRegister)); wTValue = (uint16_t)bRegister << 8; PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_ReadRegister(pDataParams, PHHAL_HW_SAMAV2_RC523_REG_TCOUNTERVALLO, &bRegister)); wTValue |= (uint16_t)bRegister; /* Subtract reload- and counter values */ wTValue = wTReload - wTValue; /* Calculate the timeout value */ fTimeout = ((float32_t)wTValue * (1.0f + (2.0f * (float32_t)wPsReload))) / PHHAL_HW_SAMAV2_TIMER_FREQ; /* Subtract timershift from timeout value */ fTimeout = fTimeout - (PHHAL_HW_SAMAV2_RC523_TIMER_SHIFT * (PHHAL_HW_SAMAV2_ETU_106 / (float32_t)wDataRate)); /* Return the value */ *pTime = (uint32_t)fTimeout; /* Round the value if neccessary */ if ((fTimeout - (float32_t)*pTime) >= 0.5) { ++(*pTime); } return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL); }
phStatus_t phhalHw_Pn512_Cmd_SoftReset( phhalHw_Pn512_DataParams_t * pDataParams ) { phStatus_t PH_MEMLOC_REM statusTmp; /* Terminate a probably running command */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_WriteRegister(pDataParams, PHHAL_HW_PN512_REG_COMMAND, PHHAL_HW_PN512_CMD_IDLE)); /* clear all IRQ flags */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_WriteRegister( pDataParams, PHHAL_HW_PN512_REG_COMMIRQ, (uint8_t)~(uint8_t)PHHAL_HW_PN512_BIT_IRQINV)); /* start the command */ PH_CHECK_SUCCESS_FCT(statusTmp, phhalHw_WriteRegister(pDataParams, PHHAL_HW_PN512_REG_COMMAND, PHHAL_HW_PN512_CMD_SOFTRESET)); return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_HAL); }
phStatus_t phalMfc_Sw_ReadValue( phalMfc_Sw_DataParams_t * pDataParams, uint8_t bBlockNo, uint8_t * pValue, uint8_t * pAddrData ) { phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_REM bBuffer[PHAL_MFC_DATA_BLOCK_LENGTH]; /* perform read operation */ PH_CHECK_SUCCESS_FCT(statusTmp, phalMfc_Sw_Read(pDataParams, bBlockNo, bBuffer)); /* check format of value block */ PH_CHECK_SUCCESS_FCT(statusTmp, phalMfc_Int_CheckValueBlockFormat(bBuffer)); /* return received contents */ *pAddrData = bBuffer[12]; memcpy(pValue, bBuffer, PHAL_MFC_VALUE_BLOCK_LENGTH); /* PRQA S 3200 */ return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_MFC); }
phStatus_t phalVca_Sw_Cmd_ProximityCheck( phalVca_Sw_DataParams_t * pDataParams, uint8_t bGenerateRndC, uint8_t * pRndC, uint8_t bNumSteps, uint8_t * pUsedRndRC ) { phStatus_t PH_MEMLOC_REM statusTmp; uint8_t PH_MEMLOC_REM bRndC[PHAL_VCA_PC_RND_LEN]; /* parameter checking */ if (((bGenerateRndC == 0) && (pRndC == NULL)) || (pUsedRndRC == NULL)) { return PH_ADD_COMPCODE(PH_ERR_INVALID_PARAMETER, PH_COMP_AL_VCA); } /* check whether to generate RndC or not */ if (bGenerateRndC) { pRndC = bRndC; PH_CHECK_SUCCESS_FCT(statusTmp, phCryptoRng_Rnd( pDataParams->pCryptoRngDataParams, PHAL_VCA_PC_RND_LEN, pRndC )); } /* send "Proximity Check" command */ PH_CHECK_SUCCESS_FCT(statusTmp, phalVca_Int_ProximityCheck( pDataParams->pPalMifareDataParams, bNumSteps, pRndC, pUsedRndRC)); return PH_ADD_COMPCODE(PH_ERR_SUCCESS, PH_COMP_AL_VCA); }