Milan Jovanovic
/
readMifareORG
Test example
Fork of readMifare by
Diff: main.cpp
- Revision:
- 10:1773f3d5bdda
- Parent:
- 9:be80c24599b5
- Child:
- 11:5e52e43e2977
diff -r be80c24599b5 -r 1773f3d5bdda main.cpp --- a/main.cpp Thu Mar 17 10:19:02 2016 +0000 +++ b/main.cpp Thu Mar 17 10:37:02 2016 +0000 @@ -51,25 +51,33 @@ pc.printf("Seems to be a Mifare Classic card (4 byte UID)\r\n"); pc.printf("Trying to authenticate sector %d with default KEYA value\r\n", sector); uint8_t keya[6] = { 0xA0, 0xA1, 0xA2, 0xA3, 0xA4, 0xA5 }; - int blockNumber = sectorToBlock(sector); - - if (nfc.mifareclassic_AuthenticateBlock(uid, uidLength, blockNumber, 0, keya)) { - uint8_t data; - - if (nfc.mifareclassic_ReadDataBlock(blockNumber, &data)) { - // Data seems to have been read ... spit it out - pc.printf("Reading Block %d:\r\n\t", blockNumber); - nfc.PrintHexChar(&data, 16); - pc.printf("\r\n"); - - // Wait a bit before reading the card again - wait(1); + int firstBlockInSectorNumber = sectorToBlock(sector); + + uint8_t buffer[16 * 4]; + for(int blockOffset = 0; blockOffset < 4; blockOffset++){ + int blockNumber = firstBlockInSectorNumber + blockOffset; + int bufferLoc = 16 * blockOffset; + + if (nfc.mifareclassic_AuthenticateBlock(uid, uidLength, blockNumber, 0, keya)) { + uint8_t data[16]; + + if (nfc.mifareclassic_ReadDataBlock(blockNumber, data)) { + // Data seems to have been read ... spit it out + pc.printf("Reading Block %d:\r\n\t", blockNumber); + memcpy(buffer + bufferLoc, data, 16); + + // Wait a bit before reading the card again + wait(1); + } else { + pc.printf("Ooops ... unable to read the requested block. Try another key?\r\n"); + } } else { - pc.printf("Ooops ... unable to read the requested block. Try another key?\r\n"); + pc.printf("Ooops ... authentication failed: Try another key?\r\n"); } - } else { - pc.printf("Ooops ... authentication failed: Try another key?\r\n"); } + printf("<FullRead>\r\n"); + Adafruit_PN532::PrintHexChar(buffer, 16 * 4); + printf("</FullRead>\r\n"); } } }