ACR35: APDU command select file returns status 6A 82 (file not found)

2.1k Views Asked by At

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

1

There are 1 best solutions below

0
On BEST ANSWER

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.