На карте DESFire Mifare у меня проблемы с аутинтификацией (функцией
phalMfdf_AuthenticateISO() ).
Кто работал с этой картой подскажите, пожалуйста, что не так.
CODE
uint8_t bLength; /**< Length */
uint8_t aSak[1]; /**< Select Acknowledge; uint8_t. */
uint8_t aUid[10]; /**< complete Uid; uint8_t[4/7/10]. */
uint8_t bMoreCardsAvaliable; /**< more card available */
#define NUMBER_OF_KEYVERSIONPAIRS 1 //! for Classic
/* Initialize the keystore component */
status = phKeyStore_Sw_Init(
&pKeyStore,
sizeof(phKeyStore_Sw_DataParams_t),
&sKeyEntries[0],
0xFF,
&sKeyVersionPairs[0],
NUMBER_OF_KEYVERSIONPAIRS,
&sKUCEntries[0],
0xFF);
CHECK_SUCCESS(status);
/* Default PICC key */
static uint8_t bDefaultPICCKey[16] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
#define PICCKEY_ADDRESS 0x15 /* PICC Key entry number in key store. */
#define SL_3_AES_KEY_VERSION 0x00 /**< SL2 key version in keystore */
phalMfdf_Sw_DataParams_t alMfdf;
phCryptoSym_Sw_DataParams_t CryptoEnc;
phCryptoSym_Sw_DataParams_t CryptoMac;
phCryptoSym_Sw_DataParams_t CryptoDiv;
phCryptoSym_Sw_DataParams_t CryptoRngCrypto;
phCryptoRng_Sw_DataParams_t CryptoRng;
/* initialise Crypto components */
status = phCryptoSym_Sw_Init(&CryptoEnc, sizeof(CryptoEnc), &pKeyStore);
CHECK_SUCCESS(status);
status = phCryptoSym_Sw_Init(&CryptoMac, sizeof(CryptoMac), &pKeyStore);
CHECK_SUCCESS(status);
status = phCryptoSym_Sw_Init(&CryptoDiv, sizeof(CryptoDiv), &pKeyStore);
CHECK_SUCCESS(status);
status = phCryptoSym_Sw_Init(&CryptoRngCrypto, sizeof(CryptoRngCrypto), &pKeyStore);
CHECK_SUCCESS(status);
/* initialise Crypto Rng component */
status = phCryptoRng_Sw_Init(&CryptoRng, sizeof(CryptoRng), &CryptoRngCrypto);
CHECK_SUCCESS(status);
/*Intialize the crypto components */
status = phCryptoSym_Sw_Init(&CryptoEnc, /**< [In] Pointer to this layer's parameter structure. */
sizeof(phCryptoSym_Sw_DataParams_t), /**< [In] Specifies the size of the data parameter structure */
&pKeyStore); /**< [In] Pointer to a key store structure (can be null).*/
CHECK_SUCCESS(status);
status = phCryptoSym_Sw_Init(&CryptoRngCrypto, /**< [In] Pointer to this layer's parameter structure. */
sizeof(phCryptoSym_Sw_DataParams_t), /**< [In] Specifies the size of the data parameter structure */
&pKeyStore); /**< [In] Pointer to a key store structure (can be null).*/
CHECK_SUCCESS(status);
status = phCryptoRng_Sw_Init(&CryptoRng, /**< [In] Pointer to this layer's parameter structure. */
sizeof(phCryptoRng_Sw_DataParams_t), /**< [In] Specifies the size of the data parameter structure */
&CryptoRngCrypto); /**< [In] Pointer to the parameter structure of the symmetric crypto layer. */
CHECK_SUCCESS(status);
status = phhalHw_FieldReset(&sHal_Nfc_Ic.sHal); /**< [In] Pointer to the parameter structure of the underlying HAL layer. */
CHECK_SUCCESS(status);
/* Activate Layer 3 card. In loop till a card is detected. */
status = phpalI14443p3a_ActivateCard(&spalI14443p3a, /**< [In] PAL-ISO14443P3A parameter structure */
NULL, /**< [In] Known Uid */
0x00, /**< [In] Known Uid length */
aUid, /**< [Out] Complete Uid */
&bLength, /**< [Out] Lenght Uid **/
&aSak, /**< [out] SAK */
&bMoreCardsAvaliable); /**< [Out] Whether there are more cards in the field or not */
CHECK_SUCCESS(status);
/* Send RATS */
status = phpalI14443p4a_Rats(&spalI14443p4, /**< [In] PAL-ISO14443P4A parameter structure */
0x08, /**< [In] Frame size integer */
0x01, /**< [In] Card Identifier */
pAts); /**< [Out] Answer to select */
CHECK_SUCCESS(status);
/* Send PPS */
status = phpalI14443p4a_Pps(&spalI14443p4, /**< [In] PAL-ISO14443P4A parameter structure */
0x00, /**< [In] Divisor Receive (PCD to PICC) Integer */
0x00); /**< [In] Divisor Send (PICC to PCD) Integer */
CHECK_SUCCESS(status);
// status = StoreKeysInKeyStore_desfire(&pKeyStore);
/* Set the default PICC Master key in the key store */
status = phKeyStore_FormatKeyEntry(&pKeyStore, PICCKEY_ADDRESS, PH_CRYPTOSYM_KEY_TYPE_2K3DES);
CHECK_SUCCESS(status);
status = phKeyStore_SetKeyAtPos(&pKeyStore,
PICCKEY_ADDRESS,
0x00,
PH_CRYPTOSYM_KEY_TYPE_2K3DES,
bDefaultPICCKey,
0x00);
CHECK_SUCCESS(status);
// /* Authenticating the Desfire Ev1 with PICC Master key stored above */
// status = phalMfdf_AuthenticateAES(&alMfdf, /* [In] Pointer to parameters data structure */
// PHAL_MFDF_NO_DIVERSIFICATION, /* [In] Diversification option */
// PICCKEY_ADDRESS, /* [In]KEY number in key store */
// 0x00, /* [In] Key version in key store */
// 0x00, /* [In] Key number on Card */
// NULL, /* [In] Diversification input */
// 0); /* [In] Diversification input length */
// CHECK_SUCCESS(status);
//status = phhalHw_FieldReset(&sHal_Nfc_Ic.sHal); /**< [In] Pointer to the parameter structure of the underlying HAL layer. */
//CHECK_SUCCESS(status);
status = phalMfdf_AuthenticateISO(&alMfdf, /* [In] Pointer to parameters data structure */
PHAL_MFDF_NO_DIVERSIFICATION, /* [In] Diversification option */
PICCKEY_ADDRESS, /* [In]KEY number in key store */
0x00, /* [In] Key version in key store */
0x00, /* [In] Key number on Card */
NULL, /* [In] Diversification input */
0); /* [In] Diversification input length */
CHECK_SUCCESS(status);
/* Pre personalization */
//status = PrePersonalization_AFCApp(&alMfdf, bCardUid);
CHECK_SUCCESS(status);
/* Authenticate with the PICC Master key */
status = phalMfdf_AuthenticateISO(&alMfdf, /* [In] Pointer to parameters data structure */
PHAL_MFDF_NO_DIVERSIFICATION, /* [In] Diversification option */
PICCKEY_ADDRESS, /* [In]KEY number in key store */
0x00, /* [In] Key version in key store */
0x00, /* [In] Key number on Card */
NULL, /* [In] Diversification input */
0); /* [In] Diversification input length */
CHECK_SUCCESS(status);