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.
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 theSCardTransmitarguments are the problem. I recommend looking closely at thepbRecvBufferparameter. 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
FormatMessagecall: you can use that to make error reporting a little more generic with predefined error messages supplied by windows.