-1

Using the framework described here, I'm trying to read from a smart card. I have built an apdu command. The command structure appears to be correct because it works in java. When I call the SCardTransmit() function, the command gets executed, but it returns an empty response buffer of length Le+2 bytes. The first two bytes holding SW1 and SW2 are 6118. I believe this means that there are more bytes to be read into the buffer. However when I change the buffer size, the response buffer size is changed but i still get error code 6118. This is a select command that is followed by a get data command returning status 6100, which I think means that there are more than 0xFF bytes to be read still. So how do I get the response buffer to be filled?

nwnoga
  • 577
  • 3
  • 12
  • 22

1 Answers1

1

The described behaviour matches a T=0 protocol card. In that protocol you never get the command response directly, but have to send a GET RESPONSE command with the length reported in the return code of the previous command, here 0x18.

guidot
  • 5,095
  • 2
  • 25
  • 37
  • That's exactly what I'm doing here, but that 18 has no relation to length of the selected data. The response of GET RESPONSE has an independent length – nwnoga Jun 21 '13 at 14:30
  • 1
    @nwnoga The response code "61 nn" exactly means "please send a GET RESPONSE with P3/LE=nn". I don't understand, where you see an independent length and also would not recommend to replace "nn" by something different, because some cards may not accept it. – guidot Jun 21 '13 at 15:14
  • In the java program the SELECT returns 26 bytes and the GET RESPONSE returns 1100 bytes. It was my understanding that the 6118 meant "your response buffer was 18 bytes short and I still have more data to give." – nwnoga Jun 21 '13 at 15:19
  • 1
    26 matches the 0x18 plus 2 bytes SW1/SW2 so the response to Select seems fine. I'm still puzzled, whether you are talking about a "GET DATA" as indicated in your question or GET RESPONSE as in my answer. GET RESPONSE in T=0 case is essential since you will get no response to ANY command without it. Note that more than one GET RESPONSE may be needed, in that case all but the last should have a SW1/SW2 of 6100. The behaviour of returning some part of the response directly and the remainder by GET RESPONSE is not like T=0. Also your SCardTransmit() does not help to identify the instruction sent. – guidot Jun 21 '13 at 15:38
  • The INS that is being used in the second command is 0xCB. Still the issue is that not even the SELECT is responding into the buffer. I think that is the main issue. The 24 data bytes are not there. – nwnoga Jun 21 '13 at 16:06
  • My hypothesis still holds; you have a T=0 card and you get no response because you send no GET RESPONSE (CLA=0, INS=C0, P1=P2=0) but simply proceed to the next command (GET DATA). You have no choice but to make yourself acquainted with T=0. – guidot Jun 22 '13 at 10:04
  • I just figured it out. Thanks. – nwnoga Jun 24 '13 at 15:15
  • 1
    The command order is as follows: Select,GET RESPONSE,GET DATA,GET RESPONSE – nwnoga Jul 01 '13 at 13:16