Unknown response from WINSCARD.DLL method SCardTransmit on O2Micro reader with response length information

StackOverflow https://stackoverflow.com/questions/7174340

Question

For communcation with a Smartcard I use the WINSCARD.DLL as an API to send APDU commands to Smartcards. For a couple of cardreaders this is working as expected, but somehow I get an unkown return (it is not on http://msdn.microsoft.com/en-us/library/ms936965.aspx) value from the method SCardTransmit if I send the command to a O2Micro reader.

What is working: If I send command (values in hex):

CLA: 00, INS: A4, P1: 02, P2: 04, Lc: 02, Data: "4401", Le: (not present)

I get the response SW1: 61. SW2: 1F

The response tells that there are 0x1F bytes available. So I send command:

CLA: 00, INS: A4, P1: 02, P2: 04, Lc: 02, Data: "4401", Le: 1F

But on that command I get no data and return value 0x57.

My question is if anyone knows what the return value 0x57 is telling and maybe a way how to solve or workaround it.

Was it helpful?

Solution

Your error code is one of the windows System Error Codes from winerror.h: ERROR_INVALID_PARAMETER. This almost always means that your APDUs are ok, but the SCardTransmit arguments are the problem. I recommend looking closely at the pbRecvBuffer parameter. Caveat: I've only used SCard functions with C++, not with C#.

PC/SC functions can return standard windows error codes as well as PC/SC-specific error codes. Note the bit about the FormatMessage call: you can use that to make error reporting a little more generic with predefined error messages supplied by windows.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top