2025-02-12 09:19 AM
We are using an ST25R3916B to read and write to both ST25TV512C tags and Mifare Classic 1K cards. While we have successfully communicated with ST25 tags, we are encountering issues at the authentication stage with Mifare Classic.
Steps We Are Following:
Before sending authentication commands, we ensure the reader is in the RFAL_NFC_STATE_ACTIVATED state.
Mifare Classic authentication follows a challenge-response mechanism. To begin, we must send the authentication command and obtain a 4-byte random challenge from the card.
The command consists of:
uint8_t authCmd[12];
authCmd[0] = 0x60; // Authenticate using Key A
authCmd[1] = block; // Block number
memcpy(&authCmd[2], keyA, 6); // Copy the 6-byte key
memcpy(&authCmd[8], device.nfcid, device.nfcidLen); // Copy the UID
We then transmit this using rfalTransceiveBlockingTxRx():
status = driver.rfalTransceiveBlockingTxRx(
authCmd, // Transmit buffer
sizeof(authCmd), // Transmit length
response, // Receive buffer
sizeof(response), // Max receive length
&responseLen, // Actual response length
RFAL_TXRX_FLAGS_DEFAULT,
RFAL_FWT_NONE
);
Current Issue
In the code below, I attempt to send only 4 bytes for authentication, which includes CRC values (D1 and 3D) for 0x60 and 0x04:
uint8_t authCmd[4];
authCmd[0] = 0x60; // Authentication command (Key A)
authCmd[1] = 0x04; // Block number
authCmd[2] = 0xD1; // CRC for 60 and 04
authCmd[3] = 0x3D; // CRC
status = driver.rfalTransceiveBlockingTxRx(
authCmd, // Transmit buffer
sizeof(authCmd), // Transmit length
response, // Receive buffer
sizeof(response), // Max receive length
&responseLen, // Actual response length
RFAL_TXRX_FLAGS_DEFAULT,
RFAL_FWT_NONE
);
What I Need Help With
Any help would be greatly appreciated.
Thanks in advance.
2025-02-13 12:58 AM
Hi AMCI,
you can find some hints here: nfc0541-read-mifare-classic-1k .
Concerning the ERR_IO: No idea really, please debug through and isolate the code line. There should only be very few ERR_IO and in normal operation this error code shouldn't appear.
Regards, Ulysses