Topic: Need help with Mifare Hello World

Hi all,

I am trying to learn more about NFC and Mifare. I copied and edited some example code that interfaces with libnfc. My goal is to write a program that reads the UID from the card, and later extend it to read some data from a card.
However, I am already having trouble just retrieving the UID from the card. I am using an Arygon reader and some Mifare Classic 1K cards.
The call to nfc_initiator_select_tag(...) gives me a nfc_device_t* with the correct UID in, but when I try to send to APDU command for the UID (0xFF, 0xCA, 0x00, 0x00, 0x00) myself, the reader fails to return a respond.

I am running the following code: https://gist.github.com/ace72d39209070516ed9

[~/Desktop] $ gcc -lnfc nfc.c -o nfc &&  ./nfc
./nfc use libnfc 1.3.4 (r338)
Connected to NFC reader: ARYGON - PN532 v2.103 (0x6e)
The following (NFC) ISO14443A tag was found:
    ATQA (SENS_RES): 04  00  
       UID (NFCID1): 93  72  ae  ed  
      SAK (SEL_RES): 08  
Error sending UID request
Sent UID request
Error receiving UID request

Am I missing something?

Re: Need help with Mifare Hello World

Just found out about the function 'nfc_initiator_mifare_cmd', and tried the MC_AUTH_A and MC_READ commands with success! I am able to read several blocks from my Mifare card.
I will take a peek in the implementation of nfc_initiator_mifare_cmd to see what's going on behind the curtains ;-). I mean in the end there still has to be a call to nfc_initiator_transceive_bytes, right?
Exciting stuff!

Re: Need help with Mifare Hello World

Hey mlangenberg

Bad news, nfc_initiator_mifare_cmd() is likely to be removed from the libnfc API…  Good news, there is another project that focusses on accessing Mifare targets using the libnfc: libfreefare [1].   You can look at the code to learn how it perfom the communication, and if you plan to do some developments involving Mifare targets, I strongly advice you to use that library: the API is somewhat stable while we are planing major refactoring in the libnfc code [2] which may lead to API breakages.  If you depend on the libfreefare, the transition should me smoother since we develop both libraries side by side.

References:
  1. http://code.google.com/p/nfc-tools/wiki/libfreefare
  2. http://code.google.com/p/libnfc/wiki/Roadmap