Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android NFC read from tag type: IsoDep and NfcB

I am very new to Android development and NFC in general.

I am trying to build an application to read the content of an NFC card where I don't know anything about this card (bus card), I want to see for example how many tickets I have left.

I have scanned the card with variety of NFC applications and know that this card is of type: IsoDep AND NfcB.

Right now I am trying to read its content using IsoDep with no success (errors 6A82, 91AE, 6E00 and so on).

I have an app that waiting for new intent of type ACTION_NDEF_DISCOVERED || ACTION_TECH_DISCOVERED || ACTION_TAG_DISCOVERED opens a new thread (since it is not possible to read and connect on UI's thread) and I am trying to read the content of the card.

I guess my problem is with the bytes I am passing to isoDep.transceive(NATIVE_SELECT_APP_COMMAND).

Should I keep trying on the IsoDep or should I move to try on the NfcB? Do you guys have any tips?

here is my code sample:

 final byte[] SELECT = {
            (byte) 0x00, // CLA Class
            (byte) 0xA4, // INS Instruction
            (byte) 0x04, // P1  Parameter 1
            (byte) 0x00, // P2  Parameter 2
            (byte) 0x08, // Length
            (byte) 0x31,  (byte)0x54, (byte)0x49, (byte)0x43, (byte)0x2e,
            (byte) 0x49, (byte)0x43, (byte)0x41, // AID 315449432e494341
    };
Tag tagFromIntent = m_intent.getParcelableExtra(NfcAdapter.EXTRA_TAG);
IsoDep isoDep = IsoDep.get(tagFromIntent);
try {
    isoDep.connect();
    byte[] result = isoDep.transceive(SELECT);
    String str = bytesToHex(result);
    Log.i("test", "SELECT: " + str);
    isoDep.close();
} catch (Exception e) {
    String error = e.getMessage();
}

my bytes to hex function:

final protected static char[] hexArray = "0123456789ABCDEF".toCharArray();
public static String bytesToHex(byte[] bytes) {
    char[] hexChars = new char[bytes.length * 2];
    for ( int j = 0; j < bytes.length; j++ ) {
        int v = bytes[j] & 0xFF;
        hexChars[j * 2] = hexArray[v >>> 4];
        hexChars[j * 2 + 1] = hexArray[v & 0x0F];
    }
    return new String(hexChars);
}

=============================================================

Edit:

I have just learned that this card is using Calypso authentication scheme.

In this question's answer helped me a little: Read data from NFC tag (IsoDep) I found a good SELECT function, i have edited my question to hold the new "SELECT" command which is working- In return i get this string: "6F228408315449432E494341A516BF0C13C70800000000029780A55307060A07062004019000" which i have no idea what it means.

Then I use this command to try and read a string:

byte[] GET_STRING = {
                (byte) 0x80, // CLA Class
                0x04, // INS Instruction
                0x00, // P1  Parameter 1
                0x00, // P2  Parameter 2
                0x10  // LE  maximal number of bytes expected in result
        };

But i get error: 6E00, any ideas on how to proceed?

like image 716
eladyanai Avatar asked Aug 03 '15 19:08

eladyanai


2 Answers

You could communicate with card with IsoDep.

You want to access data on card without specifications of this card, so there's 2 ways:

  • Get specification of card (how to communicate with it)
  • Do reverse engineering, it will take lot of time and not sure about the result, and you could "lock" access to the card

UPDATE 1

To read Rav Kav card, threre's an open-source project : http://pannetrat.com/Cardpeek/ code for Rav Kav is here https://code.google.com/p/cardpeek/source/browse/trunk/dot_cardpeek_dir/scripts/calypso/c376n3.lua

like image 160
LaurentY Avatar answered Oct 22 '22 10:10

LaurentY


You are sending the wrong command to read the application's records. 6E00 means incorrect INS byte.

You can have a look at this github which reads some counters out of a MOBIB card, which is based on the Calypso spec.

https://github.com/flamingokweker/Android-NFC-Mobib-Reader

like image 27
asdk78 Avatar answered Oct 22 '22 10:10

asdk78