Created
August 15, 2018 22:03
-
-
Save valkheim/ef87d4b582232de599e89aec92e87853 to your computer and use it in GitHub Desktop.
Révision du dump exemple fourni avec la lib Adafruit pour le pn532
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Adafruit_PN532.h> | |
#define PN532_IRQ (2) | |
#define PN532_RESET (3) // Not connected by default on the NFC Shield | |
// Shield with an I2C connection: | |
Adafruit_PN532 nfc(PN532_IRQ, PN532_RESET); | |
void setup(void) { | |
Serial.begin(115200); | |
Serial.println("################################"); | |
Serial.println("## Mifare Classic Memory Dump ##"); | |
Serial.println("################################"); | |
nfc.begin(); | |
uint32_t versiondata; | |
versiondata = nfc.getFirmwareVersion(); | |
if (versiondata) { | |
Serial.print("Found chip PN5"); Serial.println((versiondata>>24) & 0xFF, HEX); | |
Serial.print("Firmware ver. "); Serial.print((versiondata>>16) & 0xFF, DEC); | |
Serial.print('.'); Serial.println((versiondata>>8) & 0xFF, DEC); | |
} else { | |
Serial.print("Didn't find PN53x board"); | |
while (1); // halt | |
} | |
// configure board to read RFID tags | |
nfc.SAMConfig(); | |
Serial.println("Waiting for an ISO14443A Card ..."); | |
} | |
void loop(void) { | |
uint8_t card; | |
uint8_t uid[7]; | |
uint8_t uidLen; | |
uint8_t block; | |
bool authentication; | |
uint8_t data[16]; | |
uint8_t key[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; | |
card = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLen); | |
if (card) { | |
Serial.println("ISO14443A found"); | |
if (uidLen == 4) { | |
Serial.print("Mifare classic card - 4 byte UID : "); | |
nfc.PrintHex(uid, uidLen); | |
block = -1; | |
authentication = false; | |
while (++block < 64) { | |
if (nfc.mifareclassic_IsFirstBlock(block)) | |
authentication = false; | |
if (!authentication) { | |
if (nfc.mifareclassic_AuthenticateBlock(uid, uidLen, block, 1, key)) { | |
authentication = true; | |
} else { | |
Serial.print("[ERROR] Authentication on block "); | |
Serial.println(block, DEC); | |
} | |
} else { | |
if (nfc.mifareclassic_ReadDataBlock(block, data)) { | |
Serial.print("Block "); | |
Serial.print(block, DEC); | |
Serial.print(" "); | |
nfc.PrintHexChar(data, 16); | |
} else { | |
Serial.print("Block "); | |
Serial.print(block, DEC); | |
Serial.println(" unable to read this block"); | |
} | |
} | |
} | |
} | |
else { | |
Serial.println("[ERROR] Card isn't a Mifare classic"); | |
} | |
} | |
Serial.print("\n\nWait for a sec\n"); | |
delay(1000); | |
Serial.print("Ok\n"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment