Search code examples
javasmartcardapdu

can not select file on ISO-7816-4 smartcard


I am trying to read data from ISO-7816-4 eVCR (electronic vehicle registration card) using javax.smartcardio. Whenever I try to select file from card I get SW code 6A86 which translates to 'Incorrect P1 or P2 parameter'. I tried many combinations of values for P1 and P2 and got same result. Card itself works fine with other programs and sample code works fine with other cards. Card I have problem with is same card as in this question.

This is code I use: Card card = terminal.connect("*"); System.out.println("ATR: " + Utils.bytes2HexString(card.getATR().getBytes()));

    byte aid[] = {(byte)0xA0, 0x00, 0x00, 0x00, 0x77, 0x01, 0x08, 0x00, 0x07, 
        0x00, 0x00, (byte) 0xFE, 0x00, 0x00, (byte) 0xAD, (byte) 0xF2};
    ResponseAPDU response = null;
    CardChannel channel = card.getBasicChannel();
    response = channel.transmit(new CommandAPDU(0x00, 0xA4, 0x04, 0x0C, aid));
    System.out.println("AID: " + response);

    response = channel.transmit(new CommandAPDU(0x00, 0xA4, 0x02, 0x00, new byte[]{(byte)0xD0, 0x01}));
    System.out.println("SELECT: " + response);

And output is:

    ATR: 3B:DB:96:00:80:B1:FE:45:1F:83:00:31:C0:64:1A:18:01:00:0F:90:00:52
    AID: ResponseAPDU: 2 bytes, SW=9000
    SELECT: ResponseAPDU: 2 bytes, SW=6a86

I can't see what am I doing wrong. Do some cards require extra initialization steps or some extra parameters for select?


Solution

  • You could use 0x0C as P2 (instead of 0x00)? Maybe the file ID is correct, but it cannot give back any file information (0x0C means: don't give back file information).

    It depends on the card operating system and/or application if this would influence the returned status word.