NXP Reader Library  v17.1.0.2535
SAM AV3 HAL Initialization for Pegoda 2 (RD710) Reader in S (NonX) Mode

Example code to configure HAL and BAL for Pegoda 2 (RD710) reader with SAM AV3 in S (NonX) mode. More...

Collaboration diagram for SAM AV3 HAL Initialization for Pegoda 2 (RD710) Reader in S (NonX) Mode:

Modules

 RD710 Initialization
 Example code to configure PAL 3A, 4A, 4, MIFARE and SLI15693 to work in RD710 mode. This is valid for RD710 / CM1 reader only.
 
 Software Initialization
 Example code to configure PAL 3A, 4A, 4, MIFARE and SLI15693 to work in software mode.
 

Detailed Description

Example code to configure HAL and BAL for Pegoda 2 (RD710) reader with SAM AV3 in S (NonX) mode.

#define CHECK_SUCCESS(x) \
if ( (x) != PH_ERR_SUCCESS ) \
{ \
printf ( "\n\n" ); \
printf ( "An error occurred: (0x%04X)\n", (x) ); \
printf ( "Pressing any key will exit the demo.\n" ); \
_getch (); \
return 0; \
}
/* Variables */
phStatus_t wStatus = 0;
phCryptoSym_Sw_DataParams_t stCryptoSym_Enc_PLUpload;
phCryptoSym_Sw_DataParams_t stCryptoSym_Mac_PLUpload;
phKeyStore_Sw_KeyEntry_t aKeyEntry[0xFF];
phKeyStore_Sw_KeyVersionPair_t aKeyVersionPair[0xFF];
phKeyStore_Sw_KUCEntry_t aKeyUsageCounter[0xFF];
uint8_t aAtr_ContactLess[256];
uint8_t aAtr_Contact[256];
uint8_t aTx_BalBuffer[512];
uint8_t aRx_BalBuffer[512];
uint8_t aTx_HalBuffer[512];
uint8_t aRx_HalBuffer[512];
uint8_t aTx_SamBuffer[512];
uint8_t aRx_SamBuffer[512];
uint8_t aPLUploadBuffer[512];
uint8_t aSeed[8];
uint8_t aHostAuthKey[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
void* pBal_Generic = NULL;
void* pHal_Generic = NULL;
/* Initialize software KeyStore component. */
wStatus = phKeyStore_Sw_Init ( &stKeyStore, sizeof ( phKeyStore_Sw_DataParams_t ), aKeyEntry, 0xFF, aKeyVersionPair, 0x03,
aKeyUsageCounter, 0xFF );
CHECK_SUCCESS ( wStatus );
/* Initialize software Crypto component. */
wStatus = phCryptoSym_Sw_Init ( &stCryptoSym_Enc, sizeof ( phCryptoSym_Sw_DataParams_t ), &stKeyStore )
CHECK_SUCCESS ( wStatus );
wStatus = phCryptoSym_Sw_Init ( &stCryptoSym_Mac, sizeof ( phCryptoSym_Sw_DataParams_t ), &stKeyStore )
CHECK_SUCCESS ( wStatus );
wStatus = phCryptoSym_Sw_Init ( &stCryptoSym_Enc_PLUpload, sizeof ( phCryptoSym_Sw_DataParams_t ), &stKeyStore )
CHECK_SUCCESS ( wStatus );
wStatus = phCryptoSym_Sw_Init ( &stCryptoSym_Mac_PLUpload, sizeof ( phCryptoSym_Sw_DataParams_t ), &stKeyStore )
CHECK_SUCCESS ( wStatus );
wStatus = phCryptoSym_Sw_Init ( &stCryptoSym_Rnd, sizeof ( phCryptoSym_Sw_DataParams_t ), &stKeyStore )
CHECK_SUCCESS ( wStatus );
wStatus = phCryptoRng_Sw_Init ( &stCryptoRng_Rnd, sizeof ( phCryptoRng_Sw_DataParams_t ), &stKeyStore )
CHECK_SUCCESS ( wStatus );
/* Seed the random number generator with the given seed. */
memset ( aSeed, 0x00, 0x08 );
wStatus = phCryptoRng_Seed ( &stCryptoRng_Rnd, aSeed, sizeof ( aSeed ) );
/* Initialization for Contactless reader ------------------------------------------------------------------------------------------------------ */
/* Initialize the reader BAL component */
wStatus = phbalReg_PcscWin_Init ( &stBal_Rd710, sizeof ( phbalReg_PcscWin_DataParams_t ), aAtr_ContactLess, 256 );
CHECK_SUCCESS ( wStatus );
/* Set the BAL Communication Configuration values */
CHECK_SUCCESS ( wStatus );
CHECK_SUCCESS ( wStatus );
/* Connect to the first reader out of the list. */
wStatus = phbalReg_SetPort ( &stBal_Rd710, ( uint8_t * ) "NXP Pegoda S CL 0 0" );
CHECK_SUCCESS ( wStatus );
/* Open the reader port. */
wStatus = phbalReg_OpenPort ( &stBal_Rd710 );
CHECK_SUCCESS ( wStatus );
/* Initialize the reader HAL component. */
wStatus = phhalHw_Rd710_Init ( &stHal_Rd710, sizeof ( phhalHw_Rd710_DataParams_t ), &stBal_Rd710, 0, aTx_HalBuffer,
sizeof ( aTx_HalBuffer ), aRx_HalBuffer, sizeof ( aRx_HalBuffer ) );
CHECK_SUCCESS ( wStatus );
/* Standard Rd710 Cmd Init. */
wStatus = ( phStatus_t ) phhalHw_Rd710_Cmd_InitReader ( &stHal_Rd710 );
CHECK_SUCCESS ( wStatus );
/* Initialization for Contact reader ---------------------------------------------------------------------------------------------------------- */
/* Initialize the reader BAL component */
wStatus = phbalReg_Sam_Init ( &stBal_Sam, sizeof ( phbalReg_Sam_DataParams_t ), &stBal_Rd710, aAtr_Contact, 256, aTx_BalBuffer,
sizeof ( aTx_BalBuffer ), aRx_BalBuffer, sizeof ( aRx_BalBuffer ) ) );
CHECK_SUCCESS ( wStatus );
/* Open the reader port. */
wStatus = phbalReg_OpenPort ( &stBal_Sam );
CHECK_SUCCESS ( wStatus );
/* Initialize the reader HAL component */
wStatus = phhalHw_SamAV3_Init ( &stHal_SamAv3, sizeof ( phhalHw_SamAV3_DataParams_t ), &stBal_Sam, &stHal_Rd710, &stKeyStore,
&stCryptoSym_Enc, &stCryptoSym_MAC, &stCryptoRng_Rng, &stCryptoSym_Enc_PLUpload, &stCryptoSym_Mac_PLUpload,
PHHAL_HW_SAMAV3_OPMODE_NON_X, 0x00, aTx_SamBuffer, sizeof ( aTx_SamBuffer ), aRx_SamBuffer,
sizeof ( aRx_SamBuffer ), aPLUploadBuffer );
CHECK_SUCCESS ( wStatus );
/* Update the generic components. */
pBal_Generic = &stBal_Sam;
pHal_Generic = &stHal_SamAv3;
/* Initialize SAM Keystore component. */
wStatus = phKeyStore_SamAV3_Init ( &stKeyStoreSAM, sizeof ( phKeyStore_SamAV3_DataParams_t ), &stHal_SamAv3 );
CHECK_SUCCESS ( wStatus );
/* Detect SAM settings. This will update the Host version internally. MUST to be CALLED. */
wStatus = phhalHw_SamAV3_DetectMode ( &stHal_SamAv3 );
CHECK_SUCCESS ( wStatus );
/* Load a the key to software keystore for SAM HOST Authentication. */
wStatus = phKeyStore_FormatKeyEntry ( &stKeyStore, 0x00, PH_KEYSTORE_KEY_TYPE_AES128 );
CHECK_SUCCESS ( wStatus );
wStatus = phKeyStore_SetKeyAtPos ( &stKeyStore, 0x00, 0x00, PH_KEYSTORE_KEY_TYPE_AES128, aHostAuthKey, 0x00 );
CHECK_SUCCESS ( wStatus );
/* Perform HOST AUTHENTICATION in PLAIN mode. */
0x00, 0x00, 0x00 );
CHECK_SUCCESS ( wStatus );
phbalReg_PcscWin_DataParams_t
PCSC (Windows) BAL parameter structure.
Definition: phbalReg.h:600
phKeyStore_Sw_Init
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)
Initializes the KeyStore component as software component.
phCryptoSym_Sw_Init
phStatus_t phCryptoSym_Sw_Init(phCryptoSym_Sw_DataParams_t *pDataParams, uint16_t wSizeOfDataParams, void *pKeyStoreDataParams)
Initialize the CryptoSym with Software as sub-component.
phKeyStore_Sw_KeyEntry_t
Software KeyEntry structure.
Definition: phKeyStore.h:66
phKeyStore_Sw_DataParams_t
Software parameter structure.
Definition: phKeyStore.h:82
phKeyStore_SetKeyAtPos
phStatus_t phKeyStore_SetKeyAtPos(void *pDataParams, uint16_t wKeyNo, uint16_t wPos, uint16_t wKeyType, uint8_t *pNewKey, uint16_t wNewKeyVersion)
Change a symmetric key entry at the specified position.
phhalHw_Rd710_Init
phStatus_t phhalHw_Rd710_Init(phhalHw_Rd710_DataParams_t *pDataParams, uint16_t wSizeOfDataParams, void *pBalDataParams, uint8_t bSlotNumber, uint8_t *pTxBuffer, uint16_t wTxBufSize, uint8_t *pRxBuffer, uint16_t wRxBufSize)
Initialise the HAL component.
phhalHw_Rd710_Cmd_InitReader
phStatus_t phhalHw_Rd710_Cmd_InitReader(phhalHw_Rd710_DataParams_t *pDataParams)
The function starts the reader in direct PCSC mode and initializes the following stack components: HA...
phKeyStore_Sw_KeyVersionPair_t
Software KeyVersionPair structure for Symmetric and ASymmetric keys.
Definition: phKeyStore.h:51
PHHAL_HW_SAMAV3_CMD_SAM_AUTHENTICATE_HOST_MODE_PLAIN
#define PHHAL_HW_SAMAV3_CMD_SAM_AUTHENTICATE_HOST_MODE_PLAIN
Option mask for protection mode as plain.
Definition: phhalHw_SamAV3_Cmd.h:295
phStatus_t
uint16_t phStatus_t
phcsBfl_Status_t is a signed short value, using the positive range.
Definition: ph_TypeDefs.h:158
PHBAL_REG_PCSCWIN_VALUE_PROTOCOL_UNDEFINED
#define PHBAL_REG_PCSCWIN_VALUE_PROTOCOL_UNDEFINED
UNDEFINED protocol.
Definition: phbalReg.h:641
phbalReg_Sam_DataParams_t
Sam BAL parameter structure.
Definition: phbalReg.h:1031
phhalHw_SamAV3_Init
phStatus_t phhalHw_SamAV3_Init(phhalHw_SamAV3_DataParams_t *pDataParams, uint16_t wSizeOfDataParams, void *pBalDataParams, void *pReaderHalDataParams, void *pKeyStoreDataParams, void *pCryptoENCDataParams, void *pCryptoMACDataParams, void *pCryptoRngDataParams, void *pPLUpload_CryptoENCDataParams, void *pPLUpload_CryptoMACDataParams, uint8_t bOpMode, uint8_t bLogicalChannel, uint8_t *pTxBuffer, uint16_t wTxBufSize, uint8_t *pRxBuffer, uint16_t wRxBufSize, uint8_t *pPLUploadBuf)
Initialise the HAL component.
PH_KEYSTORE_KEY_TYPE_AES128
#define PH_KEYSTORE_KEY_TYPE_AES128
AES 128 Key [16].
Definition: phKeyStore.h:1067
phhalHw_Rd710_DataParams_t
Rd710 HAL parameter structure.
Definition: phhalHw.h:1484
phCryptoRng_Sw_Init
phStatus_t phCryptoRng_Sw_Init(phCryptoRng_Sw_DataParams_t *pDataParams, uint16_t wSizeOfDataParams, void *pCryptoDataParams)
Initialize the CryptoRng with software as sub-component.
phhalHw_SamAV3_DetectMode
phStatus_t phhalHw_SamAV3_DetectMode(phhalHw_SamAV3_DataParams_t *pDataParams)
Detect UID, AV2/AV3 mode and HostAuth settings.
phCryptoSym_Sw_DataParams_t
Data structure for Symmetric Crypto Software layer implementation.
Definition: phCryptoSym.h:435
phbalReg_SetPort
phStatus_t phbalReg_SetPort(void *pDataParams, uint8_t *pPortName)
Select Port to be used.
phKeyStore_SamAV3_Init
phStatus_t phKeyStore_SamAV3_Init(phKeyStore_SamAV3_DataParams_t *pDataParams, uint16_t wSizeOfDataParams, phhalHw_SamAV3_DataParams_t *pHalDataParams)
Initializes the KeyStore component as SAM AV3 component.
phKeyStore_Sw_KUCEntry_t
Software KeyUsageCounter structure.
Definition: phKeyStore.h:75
PHBAL_REG_PCSCWIN_VALUE_SHARE_DIRECT
#define PHBAL_REG_PCSCWIN_VALUE_SHARE_DIRECT
DIRECT access.
Definition: phbalReg.h:644
phbalReg_Sam_Init
phStatus_t phbalReg_Sam_Init(phbalReg_Sam_DataParams_t *pDataParams, uint16_t wSizeOfDataParams, void *pLowerBalDataParams, uint8_t *pAtrBuffer, uint16_t wAtrBufSize, uint8_t *pTxBuffer, uint16_t wTxBufSize, uint8_t *pRxBuffer, uint16_t wRxBufSize)
Initialize the SAM BAL component.
phbalReg_SetConfig
phStatus_t phbalReg_SetConfig(void *pDataParams, uint16_t wConfig, uint16_t wValue)
Set configuration parameter.
PHHAL_HW_SAMAV3_OPMODE_NON_X
#define PHHAL_HW_SAMAV3_OPMODE_NON_X
Non-X operation mode.
Definition: phhalHw.h:418
phCryptoRng_Sw_DataParams_t
Data structure for Random Number's Software layer implementation.
Definition: phCryptoRng.h:52
PHBAL_REG_PCSCWIN_CONFIG_SHARE
#define PHBAL_REG_PCSCWIN_CONFIG_SHARE
Used Access mode; e.g.
Definition: phbalReg.h:628
phCryptoRng_Seed
phStatus_t phCryptoRng_Seed(void *pDataParams, uint8_t *pSeed, uint8_t bSeedLength)
Seeds the random number generator with the given seed.
phhalHw_SamAV3_Cmd_SAM_AuthenticateHost
phStatus_t phhalHw_SamAV3_Cmd_SAM_AuthenticateHost(phhalHw_SamAV3_DataParams_t *pDataParams, uint8_t bHostMode, uint16_t wRdKeyNo, uint16_t wRdKeyV, uint8_t bSamKeyNo, uint8_t bSamKeyV)
Mutual 3-pass-AV2 or 3-Pass AV3 authentication between Host and SAM.
phbalReg_OpenPort
phStatus_t phbalReg_OpenPort(void *pDataParams)
Open communication port.
phbalReg_PcscWin_Init
phStatus_t phbalReg_PcscWin_Init(phbalReg_PcscWin_DataParams_t *pDataParams, uint16_t wSizeOfDataParams, uint8_t *pAtrBuffer, uint16_t wAtrBufSize)
Initialise the PCSC BAL component.
phKeyStore_SamAV3_DataParams_t
Sam parameter structure.
Definition: phKeyStore.h:421
PHBAL_REG_PCSCWIN_CONFIG_PROTOCOL
#define PHBAL_REG_PCSCWIN_CONFIG_PROTOCOL
Used Protocol; e.g.
Definition: phbalReg.h:627
uint8_t
unsigned char uint8_t
8 bit unsigned integer
Definition: ph_TypeDefs.h:56
phKeyStore_FormatKeyEntry
phStatus_t phKeyStore_FormatKeyEntry(void *pDataParams, uint16_t wKeyNo, uint16_t wNewKeyType)
Format a key entry to a new KeyType.
phhalHw_SamAV3_DataParams_t
SamAV3 HAL parameter structure.
Definition: phhalHw.h:445