0

I am writing a C++ code using winscard. I noticed that, if I send a command with Scardtransmit where only data is sent or only data received, there is no problem. I can send data or get correct response. However, when the command both sends data and expects a response then I always get 61xx. I know the error code 61xx means there is an xx bytes response where Le is not correct, and checked every possible Le, including the returned value xx, but nothing changes. For example let the Apdu be in the form CLA INS P1 P2 Lc Data Le, and I get 61XX, then I send CLA INS P1 P2 Lc Data XX, again I get 61XX.

I checked the card using java and other tools and verified that there is nothing with the card.

As far as I understand, there is a single byte P3 allocated for Lc and Le. Is there a way to get responses (apart from the SW1SW2) from the DATADATA commands?

Some programmer dude
  • 400,186
  • 35
  • 402
  • 621
user1927822
  • 3
  • 1
  • 3

1 Answers1

4

When you send a command that has Command Data and the command is expecting Result Data as well, and the communication is made using T=0 protocol, then you need to send two APDUs. One for the command itself, and another one to retrieve the result.

61XX is not an error. It is a (successful) Status Word that indicates you have XX bytes of response which you can retrieve using GET RESPONSE (INS=0xC0).

Here is the reference of the command.

David
  • 3,957
  • 2
  • 28
  • 52
  • Thanks for your answer David. Does this mean I need to store the result and then retrive it using another APDU? And, I wonder, what is the difference between Java and C++ so that I don't need to send two APDUs in Java? – user1927822 Aug 02 '13 at 07:11
  • Yes, you need to store the value of SW2 and then use it as Le in the GET RESPONSE APDU. You can also retrieve partial data, which Le < previous SW2 if you wish. It should not related to the programming language (Java/C++) that you use, however some readers have capability to automatically retrieve the response data if SW1 is 61XX. – David Aug 02 '13 at 15:34