1

I am testing an ACR35 and I am having this issue with the provided SDK.

I have a DESFire EV1 card which has the following file structure:

[ Master File ]
      |
      |___ [ AID - F222222222  (Dedicated file) ]
                   |
                   |___ [ File id - 0001 (Elementary File) ]

I have verified that this file structure really exists on the card with another reader (Android device with integrated NFC reader).

I am selecting the DF (by its AID) with this code:

public void powerOn(){
    if (mReader.piccPowerOn(timeout, cardType)) {
        Log.i(TAG, "poweron true");
        byte[] test = ApduCommand.HexStringToByteArray("00A4040005F222222222");
        /*Transmit the command to the reader with timeout: 5 sec*/
        mReader.piccTransmit(timeout, test);
    }else{
        Log.i(TAG, "poweron false");
        powerOn();
    }
}

And I am waiting for the response here:

/* Set the PICC response APDU callback. */
mReader.setOnPiccResponseApduAvailableListener(new AudioJackReader.OnPiccResponseApduAvailableListener() {
    @Override
    public void onPiccResponseApduAvailable(AudioJackReader reader, byte[] responseApdu) {
        String resultHex = ApduCommand.ByteArrayToHexString(responseApdu);
        Log.i(TAG, "APDU response ("+current_status+")" + resultHex);

        if(resultHex.equals("9000")) {
            if (current_status == STATUS_SELECT_AID) {
                if (mReader.piccPowerOn(timeout, cardType)) {
                    Log.i(TAG, "selecting file");
                    byte[] selFile = ApduCommand.HexStringToByteArray("00A40200020001");
                    current_status = STATUS_SELECT_FILE;
                    mReader.piccTransmit(timeout, selFile);
                } else {
                    Log.i(TAG, "timed out..");
                }
            }else if(current_status == STATUS_SELECT_FILE) {
                if (mReader.piccPowerOn(timeout, cardType)) {
                    Log.i(TAG, "reading binary data");
                    byte[] readBinary = ApduCommand.HexStringToByteArray("00B0000000");
                    current_status = STATUS_READ_DATA;
                    mReader.piccTransmit(timeout, readBinary);
                } else {
                    Log.i(TAG, "timed out..");
                }
            }
        }
    }
});

Here, I get a success status (90 00) on selecting the DF but I get a file not found status (6A 82) while selecting the file.

Log are as follows:

12-28 18:17:02.752 27298-28923/com.example.m1alesis.smartcardreader I/acrx: APDU response (0)9000
12-28 18:17:02.752 27298-28923/com.example.m1alesis.smartcardreader I/acrx: selecting file
12-28 18:17:03.412 27298-28949/com.example.m1alesis.smartcardreader I/acrx: APDU response (1)6A82

Using the same card and the exact same APDU commands on Android NFC reader mode works fine and I am able to select the file but ACR35 doesn't seem to like multiple sequential APDU commands.

Github project: https://github.com/rthapa/smartcardreader

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
unknown
  • 207
  • 3
  • 9
  • Is there a reason why you call `piccPowerOn()` before trying to select the file? I'm not quite sure what that method does, but if it disables and re-enables power, then the DESFire application may no longer be selected. – Michael Roland Dec 28 '16 at 19:13
  • 1
    @MichaelRoland That was it !!! It makes perfectly sense now. Wow I went through these codes like 100 times and couldn't figure out. Thank you, if you post this as answer I will accept it. It maybe useful to someone else in future. – unknown Dec 28 '16 at 20:06

1 Answers1

0

Don't call mReader.piccPowerOn(timeout, cardType) between sending APDUs. The method piccPowerOn() will cause the reader to reset the DESFire card. Consequently, the application F222222222 will no longer be selected when you execute the SELECT (by FID) command 00 A4 0200 02 0001.

Michael Roland
  • 39,663
  • 10
  • 99
  • 206