in SmartCard

PC/SC Winscard SCardTransmit error 0x00000016 returned

Use PC/SC Winscard SCardTransmit function, it returns error 0x00000016 when using Contactless card reader, found the 2nd parameter of SCardTransmit( ) was wrong. If I replace the 2nd parameter from SCARD_PCI_T0 to SCARD_PCI_RAW under PC/SC contactless mode, the problem was resolved.

The change was as below,

lErrCode = SCardTransmit(m_hSCard, SCARD_PCI_T0, send, sendLen, NULL, recv, &recvLen);

It was changed to:

lErrCode = SCardTransmit(m_hSCard, SCARD_PCI_RAW, send, sendLen, NULL, recv, &recvLen);

Or another way to apply to all cases is as below code:

if (SCardTransmit(m_hSCard, SCARD_PCI_T0, send, sendLen, NULL, recv, &recvLen)) {
    lErrCode = SCardTransmit(m_hSCard, SCARD_PCI_RAW, send, sendLen, NULL, recv, &recvLen);
} else {
    lErrCode = 0x0;
}

From SCardTransmit function- Microsoft Winscard document, the SCardTransmit function is as below,

LONG SCardTransmit(
  SCARDHANDLE         hCard,
  LPCSCARD_IO_REQUEST pioSendPci,
  LPCBYTE             pbSendBuffer,
  DWORD               cbSendLength,
  LPSCARD_IO_REQUEST  pioRecvPci,
  LPBYTE              pbRecvBuffer,
  LPDWORD             pcbRecvLength
);

Reference

SCardPCI Class – SCARD_IO_REQUEST
SCardTransmit function- Microsoft Winscard document
SCARD_IO_REQUEST structure – Microsoft Winscard document
Re: Sending TPDU – This 2nd parameter of SCardTransmit( ) is wrong.

Write a Comment

Comment