The SCardTransmit function sends a service request to the smart card, and expects to receive data back from the card.
LONG SCardTransmit(
IN SCARDHANDLE hCard,
IN LPCSCARD_I0_REQUEST pioSendPci,
IN LPCBYTE pbSendBuffer,
IN DWORD cbSendLength,
IN OUT LPSCARD_IO_REQUEST pioRecvPci,
OUT LPBYTE pbRecvBuffer,
IN OUT LPDWORD pcbRecvLength
);
For the T=0, T=1, and Raw protocols, the PCI structure is constant. The smart card subsystem supplies a global T=0, T=1, or Raw PCI structure, which you can reference by using the symbols SCARD_PCI_T0, SCARD_PCI_T1, and SCARD_PCI_RAW respectively.
T=0 Note For T=0, the data parameters are placed into the pbSendBuffer according to the following structure:
struct {
BYTE
bCla, // The instruction class
bIns, // The instruction code
bP1, // Parameter to the instruction
bP2, // Parameter to the instruction
bP3; // Size of I/O Transfer
} CmdBytes;
Members
The data sent to the card should immediately follow the send buffer. In the special case where no data is sent to the card and no data is expected in return, bP3 is not sent.
T=0 Note For T=0, in the special case where no data is sent to the card and no data expected in return, this length must reflect that the bP3 member is not being sent: the length should be sizeof(CmdBytes) – sizeof(BYTE).
T=0 Note For T=0, the data is immediately followed by the SW1 and SW2 status bytes. If no data is returned from the card, then this buffer will only contain the SW1 and SW2 status bytes.
T=0 Note For T=0, the receive buffer must be at least two bytes long, in order to receive the SW1 and SW2 status bytes.
If the function… | The return value is… |
---|---|
Succeeds | SCARD_S_SUCCESS. |
Fails | An error code (see Error Codes for a list of all error codes). |
SCardTransmit is a smart card and reader access function. For a description of other access functions, see Smart Card and Reader Access Functions.
T=0 Protocol Remarks
For the T=0 protocol, the data received back are the SW1 and SW2 status codes, possibly preceded by response data. The following paragraphs provide information on the send and receive buffers used to transfer data and issue a command.
The first four bytes of the pbSendBuffer buffer contain the CLA, INS, P1, and P2 values for the T=0 operation. The fifth byte shall be set to n: the size (in bytes) of the data to be transferred to the card. The next n bytes shall contain the data to be sent to the card.
The cbSendLength parameter shall be set to the size of the T=0 header information (CLA, INS, P1 and P2) plus a byte containing the length of the data to be transferred (n), plus the size of data to be sent. In this example, this is n+5.
The pbRecvBuffer will receive the SW1 and SW2 status codes from the operation.
The pcbRecvLength should be at least 2, and will be set to 2 upon return.
The first four bytes of the pbSendBuffer buffer contain the CLA, INS, P1, and P2 values for the T=0 operation. The fifth byte shall be set to n: the size (in bytes) of the data to be transferred from the card. If 256 bytes are to be transferred from the card, then this byte shall be set to zero.
The cbSendLength parameter shall be set to 5, the size of the T=0 header information.
The pbRecvBuffer will receive the data returned from the card, immediately followed by the SW1 and SW2 status codes from the operation.
The pcbRecvLength should be at least n+2, and will be set to n+2 upon return.
The pbSendBuffer buffer shall contain the CLA, INS, P1, and P2 values for the T=0 operation. The P3 value is not sent. (This is to differentiate the header from the case where 256 bytes are expected to be returned.)
The cbSendLength parameter shall be set to 4, the size of the T=0 header information (CLA, INS, P1, and P2).
The pbRecvBuffer will receive the SW1 and SW2 status codes from the operation.
The pcbRecvLength should be at least 2, and will be set to 2 upon return.
Windows NT: Use version 4.0 SP3 and later.
Windows: Use Windows 95 OSR2.1.
Windows CE: Unsupported.
Header: Declared in winscard.h.
Import Library: Link with winscard.lib.
SCardConnect, SCARD_IO_REQUEST