-1

I am trying to read a file that is under MF. The EF.DIR file. I got the file's SFID, so I don't use the method SELEC_FILE first (since it's not necessary). I might be having some problems with understanding the P2 parameter (the OFFSET). I read couple of explanations, but still don't get what OFFSET do they mean. But I tried all the numbers from 0-8 just in case, none worked.

CLA = 0x00
INS_READ = 0xB0
P1_READ = 0x9E (by the datasheed: bit(8) = 1, bit(7:6) = 00, bit(5:1): SFID)
P2 = 0x04 (I figured that the offset should be from bit0 to bit4 (the SFID)
Le = 0 (by the datasheet I have, this should mean that any size will be returned)

This is my code:

byte[] readBinary = { CLA, INS_READ, P1_READ, (byte) 0x04, (short) 0};
ResponseAPDU  read = channel.transmit(new CommandAPDU(readBinary));
String responseReadToString =read.toString();
System.out.println("Response Read: " + responseReadToString + "\n" + "Response Read (HEX): " + responseReadHex );

The output I get in Console is:

Response Read: ResponseAPDU: 2 bytes, SW=6b00
Response Read (HEX): 6B00

Explanations of SW1-SW2 for 6B00:

Incorrect parameters P1-P2

I really don't know what is wrong and it's really hard to find support on SmartCards online, so hopefully someone who knows this better can help me out. I also tried with using SELECT_FILE first and the use READ_BINARY after it (without the SFID in P1 parametr ofcourse), but it responded with "No EF is set as current".

Any help guys?

David Kasabji
  • 1,049
  • 3
  • 15
  • 32
  • There ARE some (a little bit:) dated and not perfectly legal copies of ISO 7816-4 on the internet. You will have a very hard time not having digested that one. – guidot Jan 18 '15 at 15:21
  • What card are you working with and what are its specs? – Peter Jan 22 '15 at 09:07

1 Answers1

1

The offset is the position/startpoint from where you start reading.

Example: Data = [0x00 0x01 0x02 0x03 0x04 0x05]

When you query a ReadBinary with offset=2 then returned data will be [0x02 0x03 0x4 0x05]

As you probably want to read the whole EF.DIR file offset shall be zero.

For reading EF.DIR you can either send

00 B0 9E 00 00

or

00 B1 2F 00 04 54 02 00 00 00

or

00 A4 02 0C 02 2F 00
00 B0 00 00 00
Paul Bastian
  • 2,597
  • 11
  • 26
  • Thank you Paul, I will test one of your solutions. I would like to find an example how the SELEC_FILE and READ_BINARY actually works in the code? I mean if you check my code, you see I use `chanell.transmit(new CommandAPDU(readBinary);`. In option with SELECT_FILE, I assume I'd have to use first the command for SELECT_FILE and right after the READ_BINARY command. However, if I do that, it says that I haven't selected any file. Which is weird, since I did right before the READ_BINARY. – David Kasabji Jan 19 '15 at 08:38
  • I have tried all of the above mentioned methods, but none have worked for my case. Can you please provide me with an Example code on how does SELECT_FILE and READ_BINARY afterwards work? Because the error says: No Current EF. – David Kasabji Jan 19 '15 at 16:45
  • You should try sending these APDUs in a good-working smartcard shell/pcsc suite, e.g. openSC etc – Paul Bastian Jan 20 '15 at 11:47
  • I insert the card and ASAP send a bunch of commands. They fails with SW 6986 / 6B00. I redo the sequence, waiting two seconds after card insertion : all fine. – Massimo May 13 '17 at 19:43
  • are you using Windows? there is a service that imports certificates and immediately sends commands when a new smartcard is detected, this service might disturb your commands. you can disable that, though I don't know the exact name in English(German:zertifikatsverteilung) something like: certificate distribution – Paul Bastian May 13 '17 at 19:47