3

I'm trying to simply read an ISO 14443-2B ST SRx card content using ACR122 card reader.

I've set up my environment with Libnfc and the proper reader driver.

Right now I've managed to write a code that simply read the card UID and prints that out. There's no documentation at all, and I totally don't know where to start for reading card content. Any clue or code snippet?

This is what I've done:

    // To compile this simple example:
// $ gcc -o quick_start_example1 quick_start_example1.c -lnfc
// ./quick_start_example1

#include <stdlib.h>
#include <nfc/nfc.h>

void print_nfc_target(const nfc_target *pnt, bool verbose)
{
  char *s;
  str_nfc_target(&s, pnt, verbose);
  printf("%s", s);
  nfc_free(s);
}

int main(int argc, const char *argv[])
{
    nfc_device *pnd;
    nfc_target nt;

    // Allocate only a pointer to nfc_context
    nfc_context *context;

    // Initialize libnfc and set the nfc_context
    nfc_init(&context);
    if (context == NULL) {
      printf("Unable to init libnfc (malloc)\n");
      exit(EXIT_FAILURE);
    }

    // Display libnfc version
    const char *acLibnfcVersion = nfc_version();
    (void)argc;
    printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);

    // Open, using the first available NFC device
    pnd = nfc_open(context, NULL);

    if (pnd == NULL) {
      printf("ERROR: %s\n", "Unable to open NFC device.");
      exit(EXIT_FAILURE);
    }
    // Set opened NFC device to initiator mode
    if (nfc_initiator_init(pnd) < 0) {
      nfc_perror(pnd, "nfc_initiator_init");
      exit(EXIT_FAILURE);
    }

    printf("NFC reader: %s opened\n", nfc_device_get_name(pnd));

    nfc_target ant[1];
    nfc_modulation nm;
    nm.nmt = NMT_ISO14443B;
    nm.nbr = NBR_106;

    nfc_initiator_list_passive_targets(pnd,nm,ant,1);
    printf("%s\n",nfc_strerror(pnd)); // print Success

    nfc_target ant2[1];
    nfc_modulation nm2;
    nm2.nmt = NMT_ISO14443B2SR;
    nm2.nbr = NBR_106;

    int res = 0;
    int n = 0;
    res = nfc_initiator_list_passive_targets(pnd, nm2, ant2, 1);
    printf("%s\n",nfc_strerror(pnd)); // print Success

    // printf("Cart identifier: %s\n", nt.nti.nsi.abtUID);
    for (n = 0; n < res; n++) {
      print_nfc_target(&ant2[n], true);
      printf("\n");
    }

    // Close NFC device
    nfc_close(pnd);
    // Release the context
    nfc_exit(context);
    exit(EXIT_SUCCESS);
}

PS: I'm listing 2 times the targets because of a known bug ( http://www.libnfc.org/community/topic/1044/problem-with-init-of-iso14443b/ )

d.lime
  • 393
  • 4
  • 15

2 Answers2

0

I wrote a small helper program to read ST SRx tags using LibNFC:

https://github.com/Depau/nfc-st-srx/

It still needs some changes to write them but it does read them successfully.

depau
  • 443
  • 4
  • 17
-3

For a start (this is how I began), get EMV book 3 and read on the commands for card transactions, including the command APDUs and how they are written, response APDUs and how they are processed, response codes, status byte codes e.t.c. Then get books 1 - 5 to accompany the above book. Also get the book Implementing Electronic Card Payment Systems by Cristian Radu which will guide you through every step needed to learn how to develop EMV card applications. Hope that helps.

Peter
  • 648
  • 7
  • 26
  • Maybe I missed something but ST's SR contactless memory ("*ISO 14443-2B ST SRx*", as specifically asked in the question) are completely unrelated to APDUs and EMV payment cards. – Michael Roland Dec 22 '14 at 08:25
  • Didn't know of that, I will check it out. But the code being used above is part of the code am using in my applications for reading nfc cards, and that's also where I began learning about reading nfc cards, that's why I asked @user1118094 to check those tutorials out. – Peter Dec 22 '14 at 08:39