user3317689
user3317689

Reputation: 1

ScardTransmit always returning error 16

I am trying to build application in windows using the Winscard library to communicate with contactless smartcard reader. I am able to connect to the device but when I try so send some data using scardtransmit I get a error 16. I have attached the piece of code that I am using below

SCARD_IO_REQUEST pioSendPci = *SCARD_PCI_T1;
//SCARD_IO_REQUEST pioSendPci = *SCARD_PCI_RAW;
DWORD dwRecvLength;
BYTE pbRecvBuffer[258];
BYTE cmd1[260];
cmd1[0]= 0xA0;
cmd1[1]= 0x0D;
cmd1[2]= 0x01;
cmd1[3]= 0x00;
cmd1[4]= 0x01;
ULONG sendbuflen= 0x05;
dwRecvLength = sizeof(pbRecvBuffer);

rv2 = SCardTransmit(hCard, &pioSendPci , cmd1,sendbuflen ,NULL, pbRecvBuffer, &dwRecvLength);

Upvotes: 0

Views: 1473

Answers (1)

Michael Roland
Michael Roland

Reputation: 40851

The command you are trying to send does not look like a valid APDU.

A valid APDU (see ISO/IEC 7816-4) has this form (except for extended length APDUs):

+--------+--------+--------+--------+--------+----------+--------+
| CLA    | INS    | P1     | P2     | [Lc]   | [DATA]   | [Le]   |
+--------+--------+--------+--------+--------+----------+--------+
| 1 Byte | 1 Byte | 1 Byte | 1 Byte | 1 Byte | Lc Bytes | 1 Byte |
+--------+--------+--------+--------+--------+----------+--------+

Where Lc contains the number of transmitted command DATA bytes or is empty (i.e. no Le) if there is no DATA bytes. Le encodes the number of expected response data bytes, with the special case Le empty indicating no expected response data bytes and Le = 0x00 indicating 256 (or maximum) expected reponse data bytes.

Upvotes: 1

Related Questions