Subsections

SCardReconnect

Synopsis:

#include <winscard.h>

LONG SCardReconnect(SCARDHANDLE hCard,
   DWORD dwShareMode,
   DWORD dwPreferredProtocols,
   DWORD dwInitialization,
   LPDWORD pdwActiveProtocol);

Parameters:

hCard IN Handle to a previous call to connect
dwShareMode IN Mode of connection type: exclusive/shared
dwPreferredProtocols IN Desired protocol use
dwInitialization IN Desired action taken on the card/reader
pdwActiveProtocol OUT Established protocol to this connection

Description:

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.

Value of dwShareMode Meaning
SCARD_SHARE_SHARED This application will allow others to share the reader
SCARD_SHARE_EXCLUSIVE This application will NOT allow others to share the reader

Value of dwPreferredProtocols Meaning
SCARD_PROTOCOL_T0 Use the T=0 protocol
SCARD_PROTOCOL_T1 Use the T=1 protocol
SCARD_PROTOCOL_RAW Use with memory type cards

dwPreferredProtocols is a bit mask of acceptable protocols for the connection. You can use (SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1) if you do not have a preferred protocol.

Value of dwInitialization Meaning
SCARD_LEAVE_CARD Do nothing
SCARD_RESET_CARD Reset the card (warm reset)
SCARD_UNPOWER_CARD Unpower the card (cold reset)
SCARD_EJECT_CARD Eject the card

Example:

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);
}

Returns:

SCARD_S_SUCCESS Successful
SCARD_E_INVALID_HANDLE Invalid hCard handle
SCARD_E_NOT_READY Could not allocate the desired port
SCARD_E_INVALID_VALUE Invalid sharing mode, requested protocol, or reader name
SCARD_E_READER_UNAVAILABLE The reader has been removed
SCARD_E_UNSUPPORTED_FEATURE Protocol not supported
SCARD_E_SHARING_VIOLATION Someone else has exclusive rights

2007-06-17