User manual
NXP Semiconductors
UM10663
NXP Reader Library User Manual
UM10663
All information provided in this document is subject to legal disclaimers.
© NXP B.V. 2013. All rights reserved.
User Manual
COMPANY PUBLIC
Rev. 1.2 — 24 July 2013
257412
41 of 47
From this point nearly to the end is branch for MIFARE Classic card detected.
242
else if (0x08 == (*bSak & 0x08))
243
{
244
debug_printf_msg("Mifare Classic card detected");
Memory of MIFARE Classic is divided into 16 sectors and each sector contains 4 blocks
of 16 byte length. Firstly we need to get access to sector by authentication with key. The
key must agree with key stored in the card for particular sector.
Before authentication we must store the key into key storage area in the EEPROM of the
reader chip. The key is defined array Key[6] – we use a new card here so the key is 6
bytes of 0xFF.
260
PH_CHECK_SUCCESS_FCT(status, phKeyStore_SetKey(&Rc663keyStore, 0, 0,
261
PH_KEYSTORE_KEY_TYPE_MIFARE, &Key[0], 0));
Now the 6 byte key is in key buffer of the crypto unit and retains until next key is buffered
by
phKeyStore_SetKey()
.
Performing authentication function loads from the key storage EEPROM area according
blocknumber passed as parameter to authentication function. See section 2.4.2 to
understand parameters of this function.
265
status = phalMfc_Authenticate(&alMfc, 0, PHHAL_HW_MFC_KEYA, 0, 0,
bUid, bLength);
Successful authentication to block 0 gives access to all the other blocks of sector 0.
Although we already have captured UID since Authentication, here is an alternative way:
UID of the card is read from block 0 in sector 0 by Read MIFARE native command. But
this assumes sector 0 has already been authenticated.
280
PH_CHECK_SUCCESS_FCT(status, phalMfc_Read(&alMfc, 0,
281
&bBufferReader[0]));
Now let’s authenticate through block 6 to entire sector 1 – block 4, 5, 6, 7.
313
PH_CHECK_SUCCESS_FCT(status, phalMfc_Authenticate(&alMfc, 6,
314
PHHAL_HW_MFC_KEYA, 0, 0, bUid, bLength));
Block 4 is accessible, so we can write data into. To be correct, 4 bytes should be written
to card EEPROM via
phhalMfc_ WriteValue()
, which ensures correct form of data to be
written. That function is described in section 2.4.4.
320
PH_CHECK_SUCCESS_FCT(status, phalMfc_Write(&alMfc, 4, bBufferReader));
Clear the read buffer to forget written data and later read data can be load buffer and
verified.
324
memset(bBufferReader, '\0', 0x60);