Search code examples
arduinonfcmifare

NFC MIFARE Ultralight C authentication failure


I recently got the NFC shield v1.0 for my arduino Uno board. I tried some of the starter code provided from seed's studio wiki http://www.seeedstudio.com/wiki/index.php?title=NFC_Shield. After multiple attempt at reading or writing a set of Mifare Ultralight C's, I set to try line by line to see what the issue was. I narrowed it down to more or less this line:

nfc.authenticateBlock( 1 /*1 or 2*/,
                 id /*Card NUID*/,
                 10/*0 to 63*/,
                 KEY_A /*Either KEY_A or KEY_B */,
                 keys)) 

The id for the card is correct, so i'm assuming another of the argument must be tripping things up. I'm using keys[]= {0xff, 0xff, 0xff, 0xff, 0xff, 0xff} for the key. Anything else that might be the issue? I included my entire code below. Please let me know if you need additional details.

Thank you!

#include "PN532.h"

#define SCK 13
#define MOSI 11
#define SS 10
#define MISO 12

PN532 nfc(SCK, MISO, MOSI, SS);

void setup(void) {
    Serial.begin(9600);
    Serial.println("Hello!");

    nfc.begin();

    uint32_t versiondata = nfc.getFirmwareVersion();
    if (! versiondata) {
        Serial.print("Didn't find PN53x board");
        while (1); // halt
    }
    // Got ok data, print it out!
    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);
    Serial.print("Supports "); Serial.println(versiondata & 0xFF, HEX);

    // configure board to read RFID tags and cards
    nfc.SAMConfig();
}


void loop(void) {
    uint32_t id;
    // look for MiFare type cards
    id = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A);

    if (id != 0)
    {
        Serial.print("Read card #");
        Serial.println(id);
        Serial.println();
        uint8_t keys[]= {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};  // default key of a fresh card


        if(nfc.authenticateBlock( 1 /*1 or 2*/,
                 id /*Card NUID*/,
                 0x08 /*0 to 63*/,
                 KEY_A /*Either KEY_A or KEY_B */,
                 keys)) 
        {
            Serial.println("authenticated!");
        }
        else {
            Serial.println("failed to authenticate");
        }
    }
    delay(2000);
}

Solution

  • You are using the MIFARE Classic authentication function for authenticatication with a MIFARE Ultralight C chip. As the two kinds of chips use entirely different methods of authentication, this will not work.