This handles smartcard reader communications and forwarding requests over message queues. More...
Functions | |
PCSC_API char * | pcsc_stringify_error (const long pcscError) |
This function return a human readable text for the given PC/SC error code. | |
LONG | SCardEstablishContext (DWORD dwScope, LPCVOID pvReserved1, LPCVOID pvReserved2, LPSCARDCONTEXT phContext) |
Creates an Application Context to the PC/SC Resource Manager. | |
LONG | SCardReleaseContext (SCARDCONTEXT hContext) |
This function destroys a communication context to the PC/SC Resource Manager. | |
LONG | SCardSetTimeout (SCARDCONTEXT hContext, DWORD dwTimeout) |
The function does not do anything except returning SCARD_S_SUCCESS. | |
LONG | SCardConnect (SCARDCONTEXT hContext, LPCSTR szReader, DWORD dwShareMode, DWORD dwPreferredProtocols, LPSCARDHANDLE phCard, LPDWORD pdwActiveProtocol) |
This function establishes a connection to the reader specified in szReader . | |
LONG | SCardReconnect (SCARDHANDLE hCard, DWORD dwShareMode, DWORD dwPreferredProtocols, DWORD dwInitialization, LPDWORD pdwActiveProtocol) |
This function reestablishes a connection to a reader that was previously connected to using SCardConnect(). | |
LONG | SCardDisconnect (SCARDHANDLE hCard, DWORD dwDisposition) |
This function terminates a connection made through SCardConnect(). | |
LONG | SCardBeginTransaction (SCARDHANDLE hCard) |
This function establishes a temporary exclusive access mode for doing a serie of commands in a transaction. | |
LONG | SCardEndTransaction (SCARDHANDLE hCard, DWORD dwDisposition) |
This function ends a previously begun transaction. | |
LONG | SCardCancelTransaction (SCARDHANDLE hCard) |
LONG | SCardStatus (SCARDHANDLE hCard, LPSTR mszReaderName, LPDWORD pcchReaderLen, LPDWORD pdwState, LPDWORD pdwProtocol, LPBYTE pbAtr, LPDWORD pcbAtrLen) |
This function returns the current status of the reader connected to by hCard . | |
LONG | SCardGetStatusChange (SCARDCONTEXT hContext, DWORD dwTimeout, LPSCARD_READERSTATE_A rgReaderStates, DWORD cReaders) |
This function blocks execution until the current availability of the cards in a specific set of readers changes. | |
LONG | SCardControl (SCARDHANDLE hCard, DWORD dwControlCode, LPCVOID pbSendBuffer, DWORD cbSendLength, LPVOID pbRecvBuffer, DWORD cbRecvLength, LPDWORD lpBytesReturned) |
This function sends a command directly to the IFD Handler (reader driver) to be processed by the reader. | |
LONG | SCardGetAttrib (SCARDHANDLE hCard, DWORD dwAttrId, LPBYTE pbAttr, LPDWORD pcbAttrLen) |
This function get an attribute from the IFD Handler (reader driver). | |
LONG | SCardSetAttrib (SCARDHANDLE hCard, DWORD dwAttrId, LPCBYTE pbAttr, DWORD cbAttrLen) |
This function set an attribute of the IFD Handler. | |
LONG | SCardTransmit (SCARDHANDLE hCard, LPCSCARD_IO_REQUEST pioSendPci, LPCBYTE pbSendBuffer, DWORD cbSendLength, LPSCARD_IO_REQUEST pioRecvPci, LPBYTE pbRecvBuffer, LPDWORD pcbRecvLength) |
This function sends an APDU to the smart card contained in the reader connected to by SCardConnect(). | |
LONG | SCardListReaders (SCARDCONTEXT hContext, LPCSTR mszGroups, LPSTR mszReaders, LPDWORD pcchReaders) |
This function returns a list of currently available readers on the system. | |
LONG | SCardFreeMemory (SCARDCONTEXT hContext, LPCVOID pvMem) |
Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE length designator. | |
LONG | SCardListReaderGroups (SCARDCONTEXT hContext, LPSTR mszGroups, LPDWORD pcchGroups) |
This function returns a list of currently available reader groups on the system. | |
LONG | SCardCancel (SCARDCONTEXT hContext) |
This function cancels all pending blocking requests on the SCardGetStatusChange() function. | |
LONG | SCardIsValidContext (SCARDCONTEXT hContext) |
Check if a SCARDCONTEXT is valid. |
This handles smartcard reader communications and forwarding requests over message queues.
Here is exposed the API for client applications.
if (dwState & SCARD_PRESENT) { // card is present }
0x8010001F
in pcsc-lite but 0x80100022
in Windows WinSCard. You should not have any problem if you always use the symbolic name. 0x8010001F
is also used by SCARD_E_UNEXPECTED on pcsc-lite but SCARD_E_UNEXPECTED is never returned by pcsc-lite. So 0x8010001F
does always means SCARD_E_UNSUPPORTED_FEATURE. PCSC_API char* pcsc_stringify_error | ( | const long | pcscError | ) |
This function return a human readable text for the given PC/SC error code.
[in] | pcscError | Error code to be translated to text. |
SCARDCONTEXT hContext; LONG rv; rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); if (rv != SCARD_S_SUCCESS) printf("SCardReleaseContext: %s (0x%lX)\n", pcsc_stringify_error(rv), rv);
Definition at line 57 of file error.c.
References SCARD_E_CANCELLED, SCARD_E_CANT_DISPOSE, SCARD_E_CARD_UNSUPPORTED, SCARD_E_DUPLICATE_READER, SCARD_E_INSUFFICIENT_BUFFER, SCARD_E_INVALID_ATR, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_PARAMETER, SCARD_E_INVALID_TARGET, SCARD_E_INVALID_VALUE, SCARD_E_NO_MEMORY, SCARD_E_NO_READERS_AVAILABLE, SCARD_E_NO_SERVICE, SCARD_E_NO_SMARTCARD, SCARD_E_NOT_READY, SCARD_E_NOT_TRANSACTED, SCARD_E_PCI_TOO_SMALL, SCARD_E_PROTO_MISMATCH, SCARD_E_READER_UNAVAILABLE, SCARD_E_READER_UNSUPPORTED, SCARD_E_SERVICE_STOPPED, SCARD_E_SHARING_VIOLATION, SCARD_E_SYSTEM_CANCELLED, SCARD_E_TIMEOUT, SCARD_E_UNKNOWN_CARD, SCARD_E_UNKNOWN_READER, SCARD_E_UNSUPPORTED_FEATURE, SCARD_F_COMM_ERROR, SCARD_F_INTERNAL_ERROR, SCARD_F_UNKNOWN_ERROR, SCARD_F_WAITED_TOO_LONG, SCARD_S_SUCCESS, SCARD_W_REMOVED_CARD, SCARD_W_RESET_CARD, SCARD_W_UNPOWERED_CARD, SCARD_W_UNRESPONSIVE_CARD, and SCARD_W_UNSUPPORTED_CARD.
LONG SCardBeginTransaction | ( | SCARDHANDLE | hCard | ) |
This function establishes a temporary exclusive access mode for doing a serie of commands in a transaction.
You might want to use this when you are selecting a few files and then writing a large file so you can make sure that another application will not change the current file. If another application has a lock on this reader or this application is in SCARD_SHARE_EXCLUSIVE there will be no action taken.
[in] | hCard | Connection made from SCardConnect(). |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) | |
SCARD_E_SHARING_VIOLATION | Someone else has exclusive rights (SCARD_E_SHARING_VIOLATION) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); rv = SCardBeginTransaction(hCard); ... / * Do some transmit commands * /
Definition at line 1199 of file winscard_clnt.c.
References MessageReceive(), MessageSendWithHeader(), PCSCLITE_LOCK_POLL_RATE, SCARD_BEGIN_TRANSACTION, SCARD_E_SHARING_VIOLATION, SCARD_S_SUCCESS, and SYS_USleep().
LONG SCardCancel | ( | SCARDCONTEXT | hContext | ) |
This function cancels all pending blocking requests on the SCardGetStatusChange() function.
[in] | hContext | Connection context to the PC/SC Resource Manager. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hContext handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_NO_SERVICE | Server is not running (SCARD_E_NO_SERVICE) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) |
SCARDCONTEXT hContext; DWORD cReaders; SCARD_READERSTATE rgReaderStates; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rgReaderStates.szReader = strdup("Reader X"); rgReaderStates.dwCurrentState = SCARD_STATE_EMPTY; ... / * Spawn off thread for following function * / ... rv = SCardGetStatusChange(hContext, 0, rgReaderStates, cReaders); rv = SCardCancel(hContext);
Definition at line 3312 of file winscard_clnt.c.
References ClientCloseSession(), ClientSetupSession(), MessageReceive(), MessageSendWithHeader(), SCARD_CANCEL, and SCardGetContext().
LONG SCardCancelTransaction | ( | SCARDHANDLE | hCard | ) |
Definition at line 1399 of file winscard_clnt.c.
References MessageReceive(), MessageSendWithHeader(), SCARD_CANCEL_TRANSACTION, and SCARD_S_SUCCESS.
LONG SCardConnect | ( | SCARDCONTEXT | hContext, | |
LPCSTR | szReader, | |||
DWORD | dwShareMode, | |||
DWORD | dwPreferredProtocols, | |||
LPSCARDHANDLE | phCard, | |||
LPDWORD | pdwActiveProtocol | |||
) |
This function establishes a connection to the reader specified in szReader
.
[in] | hContext | Connection context to the PC/SC Resource Manager. |
[in] | szReader | Reader name to connect to. |
[in] | dwShareMode | Mode of connection type: exclusive or shared.
|
[in] | dwPreferredProtocols | Desired protocol use.
|
[out] | phCard | Handle to this connection. |
[out] | pdwActiveProtocol | Established protocol to this connection. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hContext handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_PARAMETER | phCard or pdwActiveProtocol is NULL (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_INVALID_VALUE | Invalid sharing mode, requested protocol, or reader name (SCARD_E_INVALID_VALUE) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_NO_SMARTCARD | No smart card present (SCARD_E_NO_SMARTCARD) | |
SCARD_E_NOT_READY | Could not allocate the desired port (SCARD_E_NOT_READY) | |
SCARD_E_PROTO_MISMATCH | Requested protocol is unknown (SCARD_E_PROTO_MISMATCH) | |
SCARD_E_READER_UNAVAILABLE | Could not power up the reader or card (SCARD_E_READER_UNAVAILABLE) | |
SCARD_E_SHARING_VIOLATION | Someone else has exclusive rights (SCARD_E_SHARING_VIOLATION) | |
SCARD_E_UNKNOWN_READER | szReader is NULL (SCARD_E_UNKNOWN_READER) | |
SCARD_E_UNSUPPORTED_FEATURE | Protocol not supported (SCARD_E_UNSUPPORTED_FEATURE) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) | |
SCARD_F_INTERNAL_ERROR | An internal consistency check failed (SCARD_F_INTERNAL_ERROR) | |
SCARD_W_UNPOWERED_CARD | Card is not powered (SCARD_W_UNPOWERED_CARD) | |
SCARD_W_UNRESPONSIVE_CARD | Card is mute (SCARD_W_UNRESPONSIVE_CARD) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
Definition at line 806 of file winscard_clnt.c.
References ReaderContext::contexts, ReaderContext::hLockId, MessageReceive(), MessageSendWithHeader(), ReaderContext::mMutex, PCSCLITE_LOCK_POLL_RATE, PHGetAvailableProtocols(), PHGetDefaultProtocol(), PHSetProtocol(), ReaderContext::readerState, SCARD_CONNECT, SCARD_E_PROTO_MISMATCH, SCARD_EXCLUSIVE_CONTEXT, SCARD_NO_CONTEXT, SCARD_PRESENT, SCARD_PROTOCOL_ANY_OLD, SCARD_PROTOCOL_RAW, SCARD_PROTOCOL_T0, SCARD_PROTOCOL_T1, SCARD_PROTOCOL_UNDEFINED, SCARD_S_SUCCESS, SCARD_SHARE_DIRECT, SCARD_SHARE_EXCLUSIVE, SCARD_SHARE_SHARED, SCARD_SWALLOWED, SCardGetContext(), and SYS_USleep().
LONG SCardControl | ( | SCARDHANDLE | hCard, | |
DWORD | dwControlCode, | |||
LPCVOID | pbSendBuffer, | |||
DWORD | cbSendLength, | |||
LPVOID | pbRecvBuffer, | |||
DWORD | cbRecvLength, | |||
LPDWORD | lpBytesReturned | |||
) |
This function sends a command directly to the IFD Handler (reader driver) to be processed by the reader.
This is useful for creating client side reader drivers for functions like PIN pads, biometrics, or other extensions to the normal smart card reader that are not normally handled by PC/SC.
[in] | hCard | Connection made from SCardConnect(). |
[in] | dwControlCode | Control code for the operation. Click here for a list of supported commands by some drivers. |
[in] | pbSendBuffer | Command to send to the reader. |
[in] | cbSendLength | Length of the command. |
[out] | pbRecvBuffer | Response from the reader. |
[in] | cbRecvLength | Length of the response buffer. |
[out] | lpBytesReturned | Length of the response. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INSUFFICIENT_BUFFER | cbSendLength or cbRecvLength are too big (SCARD_E_INSUFFICIENT_BUFFER) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_PARAMETER | pbSendBuffer is NULL or cbSendLength is null and the IFDHandler is version 2.0 (without dwControlCode ) (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_INVALID_VALUE | Invalid value was presented (SCARD_E_INVALID_VALUE) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_NOT_TRANSACTED | Data exchange not successful (SCARD_E_NOT_TRANSACTED) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed(SCARD_E_READER_UNAVAILABLE) | |
SCARD_E_UNSUPPORTED_FEATURE | Driver does not support (SCARD_E_UNSUPPORTED_FEATURE) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) | |
SCARD_W_REMOVED_CARD | The card has been removed from the reader(SCARD_W_REMOVED_CARD) | |
SCARD_W_RESET_CARD | The card has been reset by another application (SCARD_W_RESET_CARD) |
LONG rv; SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol, dwSendLength, dwRecvLength; BYTE pbRecvBuffer[10]; BYTE pbSendBuffer[] = { 0x06, 0x00, 0x0A, 0x01, 0x01, 0x10 0x00 }; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_RAW, &hCard, &dwActiveProtocol); dwSendLength = sizeof(pbSendBuffer); dwRecvLength = sizeof(pbRecvBuffer); rv = SCardControl(hCard, 0x42000001, pbSendBuffer, dwSendLength, pbRecvBuffer, sizeof(pbRecvBuffer), &dwRecvLength);
Definition at line 2367 of file winscard_clnt.c.
References IFDControl(), MAX_BUFFER_SIZE_EXTENDED, MessageReceive(), MessageSend(), MessageSendWithHeader(), SCARD_CONTROL, SCARD_E_INVALID_HANDLE, SCARD_S_SUCCESS, and ReaderContext::version.
LONG SCardDisconnect | ( | SCARDHANDLE | hCard, | |
DWORD | dwDisposition | |||
) |
This function terminates a connection made through SCardConnect().
[in] | hCard | Connection made from SCardConnect(). |
[in] | dwDisposition | Reader function to execute.
|
SCARD_S_SUCCESS | Successful(SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_VALUE | Invalid dwDisposition (SCARD_E_INVALID_VALUE) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_NO_SMARTCARD | No smart card present (SCARD_E_NO_SMARTCARD) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); rv = SCardDisconnect(hCard, SCARD_UNPOWER_CARD);
Definition at line 1095 of file winscard_clnt.c.
References ReaderContext::contexts, ReaderContext::hLockId, IFD_POWER_DOWN, IFD_POWER_UP, IFD_RESET, IFDPowerICC(), MessageReceive(), MessageSendWithHeader(), PCSCLITE_LOCK_POLL_RATE, ReaderContext::readerState, SCARD_ABSENT, SCARD_DISCONNECT, SCARD_EJECT_CARD, SCARD_EXCLUSIVE_CONTEXT, SCARD_LEAVE_CARD, SCARD_RESET, SCARD_RESET_CARD, SCARD_S_SUCCESS, SCARD_UNPOWER_CARD, ReaderContext::slot, and SYS_USleep().
LONG SCardEndTransaction | ( | SCARDHANDLE | hCard, | |
DWORD | dwDisposition | |||
) |
This function ends a previously begun transaction.
The calling application must be the owner of the previously begun transaction or an error will occur.
[in] | hCard | Connection made from SCardConnect(). |
[in] | dwDisposition | Action to be taken on the reader. The disposition action is not currently used in this release.
|
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_VALUE | Invalid value for dwDisposition (SCARD_E_INVALID_VALUE) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) | |
SCARD_E_SHARING_VIOLATION | Someone else has exclusive rights (SCARD_E_SHARING_VIOLATION) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); rv = SCardBeginTransaction(hCard); ... / * Do some transmit commands * / ... rv = SCardEndTransaction(hCard, SCARD_LEAVE_CARD);
Definition at line 1315 of file winscard_clnt.c.
References _psContextMap::dwClientID, IFD_POWER_DOWN, IFD_POWER_UP, IFD_RESET, IFDPowerICC(), MessageReceive(), MessageSendWithHeader(), _psContextMap::mMutex, ReaderContext::readerState, SCARD_ABSENT, SCARD_EJECT_CARD, SCARD_END_TRANSACTION, SCARD_LEAVE_CARD, SCARD_RESET, SCARD_RESET_CARD, SCARD_S_SUCCESS, SCARD_UNPOWER_CARD, ReaderContext::slot, and SYS_USleep().
LONG SCardEstablishContext | ( | DWORD | dwScope, | |
LPCVOID | pvReserved1, | |||
LPCVOID | pvReserved2, | |||
LPSCARDCONTEXT | phContext | |||
) |
Creates an Application Context to the PC/SC Resource Manager.
Creates an Application Context for a client.
This must be the first WinSCard function called in a PC/SC application. Each thread of an application shall use its own SCARDCONTEXT.
[in] | dwScope | Scope of the establishment. This can either be a local or remote connection.
|
[in] | pvReserved1 | Reserved for future use. |
[in] | pvReserved2 | Reserved for future use. |
[out] | phContext | Returned Application Context. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_PARAMETER | phContext is null (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_INVALID_VALUE | Invalid scope type passed (SCARD_E_INVALID_VALUE ) | |
SCARD_E_NO_MEMORY | There is no free slot to store hContext (SCARD_E_NO_MEMORY) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) | |
SCARD_F_INTERNAL_ERROR | An internal consistency check failed (SCARD_F_INTERNAL_ERROR) |
SCARDCONTEXT hContext; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
Definition at line 386 of file winscard_clnt.c.
References SCARD_E_INVALID_HANDLE, SCARD_E_NO_SERVICE, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SCardEstablishContextTH(), SCardLockThread(), SCardUnlockThread(), and SYS_USleep().
LONG SCardFreeMemory | ( | SCARDCONTEXT | hContext, | |
LPCVOID | pvMem | |||
) |
Releases memory that has been returned from the resource manager using the SCARD_AUTOALLOCATE length designator.
[in] | hContext | Connection context to the PC/SC Resource Manager. |
[in] | pvMem | pointer to allocated memory |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hContext handle (SCARD_E_INVALID_HANDLE) |
Definition at line 3138 of file winscard_clnt.c.
References SCardGetContext().
LONG SCardGetAttrib | ( | SCARDHANDLE | hCard, | |
DWORD | dwAttrId, | |||
LPBYTE | pbAttr, | |||
LPDWORD | pcbAttrLen | |||
) |
This function get an attribute from the IFD Handler (reader driver).
The list of possible attributes is available in the file reader.h
.
If *pcbAttrLen
is equal to SCARD_AUTOALLOCATE then the function will allocate itself the needed memory. Use SCardFreeMemory() to release it.
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INSUFFICIENT_BUFFER | cbAttrLen is too big (SCARD_E_INSUFFICIENT_BUFFER) | |
SCARD_E_INSUFFICIENT_BUFFER | Reader buffer not large enough (SCARD_E_INSUFFICIENT_BUFFER) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_PARAMETER | A parameter is NULL and should not (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_NO_MEMORY | Memory allocation failed (SCARD_E_NO_MEMORY) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_NOT_TRANSACTED | Data exchange not successful (SCARD_E_NOT_TRANSACTED) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) |
LONG rv; SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; unsigned char pbAtr[MAX_ATR_SIZE]; DWORD dwAtrLen; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_RAW, &hCard, &dwActiveProtocol); dwAtrLen = sizeof(pbAtr); rv = SCardGetAttrib(hCard, SCARD_ATTR_ATR_STRING, pbAtr, &dwAtrLen);
LONG rv; SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; unsigned char *pbAttr; DWORD dwAttrLen; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_RAW, &hCard, &dwActiveProtocol); dwAttrLen = SCARD_AUTOALLOCATE; rv = SCardGetAttrib(hCard, SCARD_ATTR_ATR_STRING, (unsigned char *)&pbAttr, &dwAttrLen);
Definition at line 2581 of file winscard_clnt.c.
References IFD_ERROR_INSUFFICIENT_BUFFER, IFD_ERROR_TAG, IFD_SUCCESS, IFDGetCapabilities(), ReaderContext::lpcReader, SCARD_ATTR_DEVICE_FRIENDLY_NAME, SCARD_AUTOALLOCATE, SCARD_GET_ATTRIB, and SCARD_S_SUCCESS.
LONG SCardGetStatusChange | ( | SCARDCONTEXT | hContext, | |
DWORD | dwTimeout, | |||
LPSCARD_READERSTATE_A | rgReaderStates, | |||
DWORD | cReaders | |||
) |
This function blocks execution until the current availability of the cards in a specific set of readers changes.
This function receives a structure or list of structures containing reader names. It then blocks for a change in state to occur for a maximum blocking time of dwTimeout
or forever if INFINITE is used.
The new event state will be contained in dwEventState
. A status change might be a card insertion or removal event, a change in ATR, etc.
To wait for a reader event (reader added or removed) you may use the special reader name "\\?PnP?\Notification"
. If a reader event occurs the state of this reader will change and the bit SCARD_STATE_CHANGED will be set.
typedef struct { LPCSTR szReader; // Reader name LPVOID pvUserData; // User defined data DWORD dwCurrentState; // Current state of reader DWORD dwEventState; // Reader state after a state change DWORD cbAtr; // ATR Length, usually MAX_ATR_SIZE BYTE rgbAtr[MAX_ATR_SIZE]; // ATR Value } SCARD_READERSTATE; ... typedef SCARD_READERSTATE *PSCARD_READERSTATE, **LPSCARD_READERSTATE; ...
Value of dwCurrentState
and dwEventState:
[in] | hContext | Connection context to the PC/SC Resource Manager. |
[in] | dwTimeout | Maximum waiting time (in milliseconds) for status change, zero (or INFINITE) for infinite. |
[in,out] | rgReaderStates | Structures of readers with current states. |
[in] | cReaders | Number of structures. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_NO_SERVICE | Server is not running (SCARD_E_NO_SERVICE) | |
SCARD_E_INVALID_PARAMETER | rgReaderStates is NULL and cReaders > 0 (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_INVALID_VALUE | Invalid States, reader name, etc (SCARD_E_INVALID_VALUE) | |
SCARD_E_INVALID_HANDLE | Invalid hContext handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_READER_UNAVAILABLE | The reader is unavailable (SCARD_E_READER_UNAVAILABLE) | |
SCARD_E_TIMEOUT | The user-specified timeout value has expired (SCARD_E_TIMEOUT) |
SCARDCONTEXT hContext; SCARD_READERSTATE_A rgReaderStates[2]; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); ... rgReaderStates[0].szReader = "Reader X"; rgReaderStates[0].dwCurrentState = SCARD_STATE_UNAWARE; rgReaderStates[1].szReader = "\\\\?PnP?\\Notification"; rgReaderStates[1].dwCurrentState = SCARD_STATE_UNAWARE; ... rv = SCardGetStatusChange(hContext, INFINITE, rgReaderStates, 2); printf("reader state: 0x%04X\n", rgReaderStates[0].dwEventState); printf("reader state: 0x%04X\n", rgReaderStates[1].dwEventState);
Definition at line 1850 of file winscard_clnt.c.
References CMD_STOP_WAITING_READER_STATE_CHANGE, CMD_WAIT_READER_STATE_CHANGE, INFINITE, MessageReceive(), MessageReceiveTimeout(), MessageSendWithHeader(), PCSCLITE_MAX_READERS_CONTEXTS, PCSCLITE_STATUS_POLL_RATE, SCARD_ABSENT, SCARD_EXCLUSIVE_CONTEXT, SCARD_LAST_CONTEXT, SCARD_NO_CONTEXT, SCARD_PRESENT, SCARD_S_SUCCESS, SCARD_STATE_EMPTY, SCARD_STATE_EXCLUSIVE, SCARD_STATE_IGNORE, SCARD_STATE_INUSE, SCARD_STATE_MUTE, SCARD_STATE_PRESENT, SCARD_STATE_UNAVAILABLE, SCARD_STATE_UNAWARE, SCARD_STATE_UNKNOWN, SCARD_SWALLOWED, SCARD_UNKNOWN, SCardGetContext(), SYS_USleep(), time_sub(), and wait_reader_state_change::timeOut.
LONG SCardIsValidContext | ( | SCARDCONTEXT | hContext | ) |
Check if a SCARDCONTEXT is valid.
Call this function to determine whether a smart card context handle is still valid. After a smart card context handle has been set by SCardEstablishContext(), it may become not valid if the resource manager service has been shut down.
[in] | hContext | Connection context to the PC/SC Resource Manager. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid Handle (SCARD_E_INVALID_HANDLE) |
SCARDCONTEXT hContext; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardIsValidContext(hContext);
Definition at line 3393 of file winscard_clnt.c.
References SCardGetContext().
LONG SCardListReaderGroups | ( | SCARDCONTEXT | hContext, | |
LPSTR | mszGroups, | |||
LPDWORD | pcchGroups | |||
) |
This function returns a list of currently available reader groups on the system.
mszGroups
is a pointer to a character string that is allocated by the application. If the application sends mszGroups
as NULL then this function will return the size of the buffer needed to allocate in pcchGroups
.
The group names is a multi-string and separated by a nul character ('\0'
) and ended by a double nul character like "SCard$DefaultReaders\\0Group 2\\0\\0"
.
If *pcchGroups
is equal to SCARD_AUTOALLOCATE then the function will allocate itself the needed memory. Use SCardFreeMemory() to release it.
[in] | hContext | Connection context to the PC/SC Resource Manager. |
[out] | mszGroups | List of groups to list readers. |
[in,out] | pcchGroups | Size of multi-string buffer including NUL's. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INSUFFICIENT_BUFFER | Reader buffer not large enough (SCARD_E_INSUFFICIENT_BUFFER) | |
SCARD_E_INVALID_HANDLE | Invalid Scope Handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_PARAMETER | mszGroups is NULL (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_NO_MEMORY | Memory allocation failed (SCARD_E_NO_MEMORY) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) |
SCARDCONTEXT hContext; LPSTR mszGroups; DWORD dwGroups; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardListReaderGroups(hContext, NULL, &dwGroups); mszGroups = malloc(sizeof(char)*dwGroups); rv = SCardListReaderGroups(hContext, mszGroups, &dwGroups);
SCARDCONTEXT hContext; LPSTR mszGroups; DWORD dwGroups; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); dwGroups = SCARD_AUTOALLOCATE; rv = SCardListReaderGroups(hContext, (LPSTR)&mszGroups, &dwGroups); rv = SCardFreeMemory(hContext, mszGroups);
Definition at line 3212 of file winscard_clnt.c.
References SCARD_AUTOALLOCATE, and SCardGetContext().
LONG SCardListReaders | ( | SCARDCONTEXT | hContext, | |
LPCSTR | mszGroups, | |||
LPSTR | mszReaders, | |||
LPDWORD | pcchReaders | |||
) |
This function returns a list of currently available readers on the system.
mszReaders
is a pointer to a character string that is allocated by the application. If the application sends mszGroups
and mszReaders
as NULL then this function will return the size of the buffer needed to allocate in pcchReaders
.
If *pcchReaders
is equal to SCARD_AUTOALLOCATE then the function will allocate itself the needed memory. Use SCardFreeMemory() to release it.
[in] | hContext | Connection context to the PC/SC Resource Manager. |
[in] | mszGroups | List of groups to list readers (not used). |
[out] | mszReaders | Multi-string with list of readers. |
[in,out] | pcchReaders | Size of multi-string buffer including NULL's. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INSUFFICIENT_BUFFER | Reader buffer not large enough (SCARD_E_INSUFFICIENT_BUFFER) | |
SCARD_E_INVALID_HANDLE | Invalid Scope Handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_PARAMETER | pcchReaders is NULL (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_NO_MEMORY | Memory allocation failed (SCARD_E_NO_MEMORY) | |
SCARD_E_NO_READERS_AVAILABLE | No readers available (SCARD_E_NO_READERS_AVAILABLE) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) |
SCARDCONTEXT hContext; LPSTR mszReaders; DWORD dwReaders; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardListReaders(hContext, NULL, NULL, &dwReaders); mszReaders = malloc(sizeof(char)*dwReaders); rv = SCardListReaders(hContext, NULL, mszReaders, &dwReaders);
SCARDCONTEXT hContext; LPSTR mszReaders; DWORD dwReaders; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); dwReaders = SCARD_AUTOALLOCATE rv = SCardListReaders(hContext, NULL, (LPSTR)&mszReaders, &dwReaders); rv = SCardFreeMemory(hContext, mszReaders);
Definition at line 3012 of file winscard_clnt.c.
References SCARD_AUTOALLOCATE, SCARD_E_INVALID_HANDLE, SCARD_S_SUCCESS, and SCardGetContext().
LONG SCardReconnect | ( | SCARDHANDLE | hCard, | |
DWORD | dwShareMode, | |||
DWORD | dwPreferredProtocols, | |||
DWORD | dwInitialization, | |||
LPDWORD | pdwActiveProtocol | |||
) |
This function reestablishes a connection to a reader that was previously connected to using SCardConnect().
In a multi application environment it is possible for an application to reset the card in shared mode. When this occurs any other application trying to access certain commands will be returned the value SCARD_W_RESET_CARD. When this occurs SCardReconnect() must be called in order to acknowledge that the card was reset and allow it to change it's state accordingly.
[in] | hCard | Handle to a previous call to connect. |
[in] | dwShareMode | Mode of connection type: exclusive/shared.
|
[in] | dwPreferredProtocols | Desired protocol use.
|
[in] | dwInitialization | Desired action taken on the card/reader.
|
[out] | pdwActiveProtocol | Established protocol to this connection. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_PARAMETER | phContext is null. (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_INVALID_VALUE | Invalid sharing mode, requested protocol, or reader name (SCARD_E_INVALID_VALUE) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_NO_SMARTCARD | No smart card present (SCARD_E_NO_SMARTCARD) | |
SCARD_E_NOT_READY | Could not allocate the desired port (SCARD_E_NOT_READY) | |
SCARD_E_PROTO_MISMATCH | Requested protocol is unknown (SCARD_E_PROTO_MISMATCH) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) | |
SCARD_E_SHARING_VIOLATION | Someone else has exclusive rights (SCARD_E_SHARING_VIOLATION) | |
SCARD_E_UNSUPPORTED_FEATURE | Protocol not supported (SCARD_E_UNSUPPORTED_FEATURE) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) | |
SCARD_F_INTERNAL_ERROR | An internal consistency check failed (SCARD_F_INTERNAL_ERROR) | |
SCARD_W_REMOVED_CARD | The smart card has been removed (SCARD_W_REMOVED_CARD) | |
SCARD_W_UNRESPONSIVE_CARD | Card is mute (SCARD_W_UNRESPONSIVE_CARD) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol, dwSendLength, dwRecvLength; LONG rv; 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); / * Card has been reset by another application * / if (rv == SCARD_W_RESET_CARD) { rv = SCardReconnect(hCard, SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, SCARD_RESET_CARD, &dwActiveProtocol); }
Definition at line 977 of file winscard_clnt.c.
References ReaderContext::contexts, IFD_POWER_DOWN, IFD_POWER_UP, IFD_RESET, IFDPowerICC(), IFDStatusICC(), MessageReceive(), MessageSendWithHeader(), ReaderContext::mMutex, PCSCLITE_LOCK_POLL_RATE, PHGetAvailableProtocols(), PHGetDefaultProtocol(), PHSetProtocol(), ReaderContext::readerState, SCARD_E_PROTO_MISMATCH, SCARD_E_SHARING_VIOLATION, SCARD_EXCLUSIVE_CONTEXT, SCARD_LAST_CONTEXT, SCARD_LEAVE_CARD, SCARD_PRESENT, SCARD_PROTOCOL_ANY_OLD, SCARD_PROTOCOL_RAW, SCARD_PROTOCOL_T0, SCARD_PROTOCOL_T1, SCARD_PROTOCOL_UNDEFINED, SCARD_RECONNECT, SCARD_RESET, SCARD_RESET_CARD, SCARD_S_SUCCESS, SCARD_SHARE_DIRECT, SCARD_SHARE_EXCLUSIVE, SCARD_SHARE_SHARED, SCARD_UNPOWER_CARD, and SYS_USleep().
LONG SCardReleaseContext | ( | SCARDCONTEXT | hContext | ) |
This function destroys a communication context to the PC/SC Resource Manager.
This must be the last function called in a PC/SC application.
[in] | hContext | Connection context to be closed. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_INVALID_HANDLE | Invalid hContext handle (SCARD_E_INVALID_HANDLE) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) |
SCARDCONTEXT hContext; LONG rv; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardReleaseContext(hContext);
Definition at line 650 of file winscard_clnt.c.
References MessageReceive(), MessageSendWithHeader(), SCARD_E_INVALID_HANDLE, SCARD_RELEASE_CONTEXT, SCardGetContext(), SCardLockThread(), SCardRemoveContext(), and SCardUnlockThread().
LONG SCardSetAttrib | ( | SCARDHANDLE | hCard, | |
DWORD | dwAttrId, | |||
LPCBYTE | pbAttr, | |||
DWORD | cbAttrLen | |||
) |
This function set an attribute of the IFD Handler.
The list of attributes you can set is dependent on the IFD Handler you are using.
[in] | hCard | Connection made from SCardConnect(). |
[in] | dwAttrId | Identifier for the attribute to set. |
[in] | pbAttr | Pointer to a buffer that receives the attribute. |
[in] | cbAttrLen | Length of the pbAttr buffer in bytes. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INSUFFICIENT_BUFFER | cbAttrLen is too big (SCARD_E_INSUFFICIENT_BUFFER) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_PARAMETER | A parameter is NULL and should not (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_NOT_TRANSACTED | Data exchange not successful (SCARD_E_NOT_TRANSACTED) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) |
LONG rv; SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; unsigned char pbAttr[] = { 0x12, 0x34, 0x56 }; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_RAW, &hCard, &dwActiveProtocol); rv = SCardSetAttrib(hCard, 0x42000001, pbAttr, sizeof(pbAttr));
Definition at line 2657 of file winscard_clnt.c.
References IFD_ERROR_TAG, IFD_SUCCESS, IFDSetCapabilities(), SCARD_S_SUCCESS, and SCARD_SET_ATTRIB.
LONG SCardSetTimeout | ( | SCARDCONTEXT | hContext, | |
DWORD | dwTimeout | |||
) |
The function does not do anything except returning SCARD_S_SUCCESS.
[in] | hContext | Connection context to the PC/SC Resource Manager. |
[in] | dwTimeout | New timeout value. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) |
Definition at line 738 of file winscard_clnt.c.
LONG SCardStatus | ( | SCARDHANDLE | hCard, | |
LPSTR | mszReaderName, | |||
LPDWORD | pcchReaderLen, | |||
LPDWORD | pdwState, | |||
LPDWORD | pdwProtocol, | |||
LPBYTE | pbAtr, | |||
LPDWORD | pcbAtrLen | |||
) |
This function returns the current status of the reader connected to by hCard
.
It's friendly name will be stored in szReaderName
. pcchReaderLen
will be the size of the allocated buffer for szReaderName
, while pcbAtrLen
will be the size of the allocated buffer for pbAtr
. If either of these is too small, the function will return with SCARD_E_INSUFFICIENT_BUFFER and the necessary size in pcchReaderLen
and pcbAtrLen
. The current state, and protocol will be stored in pdwState and pdwProtocol
respectively.
If *pcchReaderLen
is equal to SCARD_AUTOALLOCATE then the function will allocate itself the needed memory for mszReaderName. Use SCardFreeMemory() to release it.
If *pcbAtrLen
is equal to SCARD_AUTOALLOCATE then the function will allocate itself the needed memory for pbAtr. Use SCardFreeMemory() to release it.
[in] | hCard | Connection made from SCardConnect(). |
[in,out] | mszReaderName | Friendly name of this reader. |
[in,out] | pcchReaderLen | Size of the szReaderName multistring. |
[out] | pdwState | Current state of this reader. pdwState is a DWORD possibly OR'd with the following values:
|
[out] | pdwProtocol | Current protocol of this reader.
|
[out] | pbAtr | Current ATR of a card in this reader. |
[out] | pcbAtrLen | Length of ATR. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INSUFFICIENT_BUFFER | Not enough allocated memory for szReaderName or for pbAtr (SCARD_E_INSUFFICIENT_BUFFER) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_PARAMETER | pcchReaderLen or pcbAtrLen is NULL (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_NO_MEMORY | Memory allocation failed (SCARD_E_NO_MEMORY) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) | |
SCARD_F_INTERNAL_ERROR | An internal consistency check failed (SCARD_F_INTERNAL_ERROR) | |
SCARD_W_REMOVED_CARD | The smart card has been removed (SCARD_W_REMOVED_CARD) | |
SCARD_W_RESET_CARD | The smart card has been reset (SCARD_W_RESET_CARD) |
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; DWORD dwState, dwProtocol, dwAtrLen, dwReaderLen; BYTE pbAtr[MAX_ATR_SIZE]; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); ... dwAtrLen = sizeof(pbAtr); rv = SCardStatus(hCard, NULL, &dwReaderLen, &dwState, &dwProtocol, pbAtr, &dwAtrLen);
SCARDCONTEXT hContext; SCARDHANDLE hCard; DWORD dwActiveProtocol; DWORD dwState, dwProtocol, dwAtrLen, dwReaderLen; BYTE *pbAtr = NULL; char *pcReader = NULL; ... rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext); rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol); ... dwReaderLen = SCARD_AUTOALLOCATE; dwAtrLen = SCARD_AUTOALLOCATE; rv = SCardStatus(hCard, (LPSTR)&pcReader, &dwReaderLen, &dwState, &dwProtocol, (LPBYTE)&pbAtr, &dwAtrLen);
Definition at line 1551 of file winscard_clnt.c.
References ReaderContext::lpcReader, MAX_ATR_SIZE, MAX_BUFFER_SIZE, MessageReceive(), MessageSendWithHeader(), PCSCLITE_LOCK_POLL_RATE, ReaderContext::readerState, SCARD_AUTOALLOCATE, SCARD_E_INSUFFICIENT_BUFFER, SCARD_E_SHARING_VIOLATION, SCARD_S_SUCCESS, SCARD_STATUS, and SYS_USleep().
LONG SCardTransmit | ( | SCARDHANDLE | hCard, | |
LPCSCARD_IO_REQUEST | pioSendPci, | |||
LPCBYTE | pbSendBuffer, | |||
DWORD | cbSendLength, | |||
LPSCARD_IO_REQUEST | pioRecvPci, | |||
LPBYTE | pbRecvBuffer, | |||
LPDWORD | pcbRecvLength | |||
) |
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 pcbRecvLength
. pioSendPci
and pioRecvPci
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;
[in] | hCard | Connection made from SCardConnect(). |
[in,out] | pioSendPci | Structure of Protocol Control Information.
|
[in] | pbSendBuffer | APDU to send to the card. |
[in] | cbSendLength | Length of the APDU. |
[in,out] | pioRecvPci | Structure of protocol information. |
[out] | pbRecvBuffer | Response from the card. |
[in,out] | pcbRecvLength | Length of the response. |
SCARD_S_SUCCESS | Successful (SCARD_S_SUCCESS) | |
SCARD_E_INSUFFICIENT_BUFFER | cbSendLength or cbRecvLength are too big (SCARD_E_INSUFFICIENT_BUFFER) | |
SCARD_E_INVALID_HANDLE | Invalid hCard handle (SCARD_E_INVALID_HANDLE) | |
SCARD_E_INVALID_PARAMETER | pbSendBuffer or pbRecvBuffer or pcbRecvLength or pioSendPci is null (SCARD_E_INVALID_PARAMETER) | |
SCARD_E_INVALID_VALUE | Invalid Protocol, reader name, etc (SCARD_E_INVALID_VALUE) | |
SCARD_E_NO_SERVICE | The server is not runing (SCARD_E_NO_SERVICE) | |
SCARD_E_NOT_TRANSACTED | APDU exchange not successful (SCARD_E_NOT_TRANSACTED) | |
SCARD_E_PROTO_MISMATCH | Connect protocol is different than desired (SCARD_E_PROTO_MISMATCH) | |
SCARD_E_READER_UNAVAILABLE | The reader has been removed (SCARD_E_READER_UNAVAILABLE) | |
SCARD_F_COMM_ERROR | An internal communications error has been detected (SCARD_F_COMM_ERROR) | |
SCARD_W_RESET_CARD | The card has been reset by another application (SCARD_W_RESET_CARD) | |
SCARD_W_REMOVED_CARD | The card has been removed from the reader (SCARD_W_REMOVED_CARD) |
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);
Definition at line 2824 of file winscard_clnt.c.
References SCARD_IO_REQUEST::cbPciLength, _psContextMap::dwClientID, SCARD_IO_REQUEST::dwProtocol, IFDTransmit(), MAX_BUFFER_SIZE_EXTENDED, MessageReceive(), MessageSend(), MessageSendWithHeader(), _psContextMap::mMutex, PCSCLITE_LOCK_POLL_RATE, ReaderContext::readerState, SCARD_ABSENT, SCARD_E_INVALID_HANDLE, SCARD_E_SHARING_VIOLATION, SCARD_PROTOCOL_ANY_OLD, SCARD_PROTOCOL_RAW, SCARD_PROTOCOL_T1, SCARD_S_SUCCESS, SCARD_TRANSMIT, SYS_USleep(), and ReaderContext::version.