Subsections

SCardTransmit

Synopsis:

#include <winscard.h>

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

Parameters:

hCard IN Connection made from SCardConnect
pioSendPci INOUT Structure of protocol information
pbSendBuffer IN APDU to send to the card
cbSendLength IN Length of the APDU
pioRecvPci INOUT Structure of protocol information
pbRecvBuffer OUT Response from the card
pcbRecvLength INOUT Length of the response

Description:

This function sends an APDU to the smart card contained in the reader connected to by SCardConnect(). The card responds from the APDU and stores this response in pbRecvBuffer and it's length in SpcbRecvLength. SSendPci and SRecvPci are structures containing the following:

typedef struct {
    DWORD dwProtocol;    /* SCARD_PROTOCOL_T0 or SCARD_PROTOCOL_T1 */
    DWORD cbPciLength;   /* Length of this structure - not used   */
} SCARD_IO_REQUEST;

Value of pioSendPci Meaning
SCARD_PCI_T0 Pre-defined T=0 PCI structure
SCARD_PCI_T1 Pre-defined T=1 PCI structure

Example:

LONG rv;
SCARDCONTEXT hContext;
SCARDHANDLE hCard;
DWORD dwActiveProtocol, dwSendLength, dwRecvLength;
SCARD_IO_REQUEST pioRecvPci;
BYTE pbRecvBuffer[10];
BYTE pbSendBuffer[] = { 0xC0, 0xA4, 0x00, 0x00, 0x02, 0x3F, 0x00 };

rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED,
         SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
dwSendLength = sizeof(pbSendBuffer);
dwRecvLength = sizeof(pbRecvBuffer);
rv = SCardTransmit(hCard, SCARD_PCI_T0, pbSendBuffer, dwSendLength,
         &pioRecvPci, pbRecvBuffer, &dwRecvLength);

Returns:

SCARD_S_SUCCESS Successful
SCARD_E_INVALID_HANDLE Invalid hCard handle
SCARD_E_NOT_TRANSACTED APDU exchange not successful
SCARD_E_PROTO_MISMATCH Connect protocol is different than desired
SCARD_E_INVALID_VALUE Invalid Protocol, reader name, etc
SCARD_E_READER_UNAVAILABLE The reader has been removed
SCARD_W_RESET_CARD The card has been reset by another application
SCARD_W_REMOVED_CARD The card has been removed from the reader

2007-06-17