SCardTransmit function (winscard.h)
The SCardTransmit function sends a service request to the smart card and expects to receive data back from the card.
Syntax
LONG SCardTransmit(
[in] SCARDHANDLE hCard,
[in] LPCSCARD_IO_REQUEST pioSendPci,
[in] LPCBYTE pbSendBuffer,
[in] DWORD cbSendLength,
[in, out, optional] LPSCARD_IO_REQUEST pioRecvPci,
[out] LPBYTE pbRecvBuffer,
[in, out] LPDWORD pcbRecvLength
);
Parameters
[in] hCard
A reference value returned from the SCardConnect function.
[in] pioSendPci
A pointer to the protocol header structure for the instruction. This buffer is in the format of an SCARD_IO_REQUEST structure, followed by the specific protocol control information (PCI).
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.
[in] pbSendBuffer
A pointer to the actual data to be written to the card.
For T=0, the data parameters are placed into the address pointed to by 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;
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.
[in] cbSendLength
The length, in bytes, of the pbSendBuffer parameter.
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)
.
[in, out, optional] pioRecvPci
Pointer to the protocol header structure for the instruction, followed by a buffer in which to receive any returned protocol control information (PCI) specific to the protocol in use. This parameter can be NULL if no PCI is returned.
[out] pbRecvBuffer
Pointer to any data returned from the card.
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.
[in, out] pcbRecvLength
Supplies the length, in bytes, of the pbRecvBuffer parameter and receives the actual number of bytes received from the smart card.
This value cannot be SCARD_AUTOALLOCATE because SCardTransmit does not support SCARD_AUTOALLOCATE.
For T=0, the receive buffer must be at least two bytes long to receive the SW1 and SW2 status bytes.
Return value
If the function successfully sends a service request to the smart card, the return value is SCARD_S_SUCCESS.
If the function fails, it returns an error code. For more information, see Smart Card Return Values.
Remarks
The SCardTransmit function is a smart card and reader access function. For information about other access functions, see Smart Card and Reader Access Functions.
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 about the send and receive buffers used to transfer data and issue a command.
Examples
The following example shows sending a service request to the smart card.
// Transmit the request.
// lReturn is of type LONG.
// hCardHandle was set by a previous call to SCardConnect.
// pbSend points to the buffer of bytes to send.
// dwSend is the DWORD value for the number of bytes to send.
// pbRecv points to the buffer for returned bytes.
// dwRecv is the DWORD value for the number of returned bytes.
lReturn = SCardTransmit(hCardHandle,
SCARD_PCI_T0,
pbSend,
dwSend,
NULL,
pbRecv,
&dwRecv );
if ( SCARD_S_SUCCESS != lReturn )
{
printf("Failed SCardTransmit\n");
exit(1); // or other appropriate error action
}
Requirements
Requirement | Value |
---|---|
Minimum supported client | Windows XP [desktop apps only] |
Minimum supported server | Windows Server 2003 [desktop apps only] |
Target Platform | Windows |
Header | winscard.h |
Library | Winscard.lib |
DLL | Winscard.dll |