Logo Search packages:      
Sourcecode: pcsc-lite version File versions  Download package

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

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.

Parameters:
[in]hCardHandle to a previous call to connect.
[in]dwShareModeMode of connection type: exclusive/shared.

[in]dwPreferredProtocolsDesired protocol use.

  • 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.
[in]dwInitializationDesired action taken on the card/reader.

[out]pdwActiveProtocolEstablished protocol to this connection.
Returns:
Error code.
Return values:
SCARD_S_SUCCESSSuccessful (SCARD_S_SUCCESS)
SCARD_E_INVALID_HANDLEInvalid hCard handle (SCARD_E_INVALID_HANDLE)
SCARD_E_INVALID_PARAMETERphContext is null. (SCARD_E_INVALID_PARAMETER)
SCARD_E_INVALID_VALUEInvalid sharing mode, requested protocol, or reader name (SCARD_E_INVALID_VALUE)
SCARD_E_NO_SERVICEThe server is not runing (SCARD_E_NO_SERVICE)
SCARD_E_NO_SMARTCARDNo smart card present (SCARD_E_NO_SMARTCARD)
SCARD_E_NOT_READYCould not allocate the desired port (SCARD_E_NOT_READY)
SCARD_E_PROTO_MISMATCHRequested protocol is unknown (SCARD_E_PROTO_MISMATCH)
SCARD_E_READER_UNAVAILABLEThe reader has been removed (SCARD_E_READER_UNAVAILABLE)
SCARD_E_SHARING_VIOLATIONSomeone else has exclusive rights (SCARD_E_SHARING_VIOLATION)
SCARD_E_UNSUPPORTED_FEATUREProtocol not supported (SCARD_E_UNSUPPORTED_FEATURE)
SCARD_F_COMM_ERRORAn internal communications error has been detected (SCARD_F_COMM_ERROR)
SCARD_F_INTERNAL_ERRORAn internal consistency check failed (SCARD_F_INTERNAL_ERROR)
SCARD_W_REMOVED_CARDThe smart card has been removed (SCARD_W_REMOVED_CARD)
SCARD_W_UNRESPONSIVE_CARDCard 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 1017 of file winscard_clnt.c.

References pubReaderStatesList::cardAtr, pubReaderStatesList::cardAtrLength, pubReaderStatesList::cardProtocol, ReaderContext::contexts, IFD_POWER_DOWN, IFD_POWER_UP, IFD_RESET, IFDPowerICC(), MessageReceive(), MessageSendWithHeader(), ReaderContext::mMutex, PCSCLITE_LOCK_POLL_RATE, PCSCLITE_SHARING_EXCLUSIVE_CONTEXT, PCSCLITE_SHARING_LAST_CONTEXT, PHGetAvailableProtocols(), PHGetDefaultProtocol(), PHSetProtocol(), pubReaderStatesList::readerSharing, pubReaderStatesList::readerState, ReaderContext::readerState, SCARD_ABSENT, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_PARAMETER, SCARD_E_INVALID_VALUE, SCARD_E_NO_SMARTCARD, SCARD_E_PROTO_MISMATCH, SCARD_E_SHARING_VIOLATION, SCARD_LEAVE_CARD, SCARD_NEGOTIABLE, SCARD_POWERED, 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_SWALLOWED, SCARD_UNPOWER_CARD, SCARD_W_REMOVED_CARD, SCARD_W_UNRESPONSIVE_CARD, and SYS_USleep().

{
      LONG rv;
      struct reconnect_struct scReconnectStruct;
      SCONTEXTMAP * currentContextMap;
      CHANNEL_MAP * pChannelMap;

      PROFILE_START

      if (pdwActiveProtocol == NULL)
            return SCARD_E_INVALID_PARAMETER;

      CHECK_SAME_PROCESS

      /*
       * Make sure this handle has been opened
       */
      rv = SCardGetContextAndChannelFromHandle(hCard, &currentContextMap,
            &pChannelMap);
      if (rv == -1)
            return SCARD_E_INVALID_HANDLE;

      (void)pthread_mutex_lock(currentContextMap->mMutex);

      /* check the handle is still valid */
      rv = SCardGetContextAndChannelFromHandle(hCard, &currentContextMap,
            &pChannelMap);
      if (rv == -1)
            /* the handle is now invalid
             * -> another thread may have called SCardReleaseContext
             * -> so the mMutex has been unlocked */
            return SCARD_E_INVALID_HANDLE;

      /* Retry loop for blocking behaviour */
retry:

      scReconnectStruct.hCard = hCard;
      scReconnectStruct.dwShareMode = dwShareMode;
      scReconnectStruct.dwPreferredProtocols = dwPreferredProtocols;
      scReconnectStruct.dwInitialization = dwInitialization;
      scReconnectStruct.dwActiveProtocol = *pdwActiveProtocol;
      scReconnectStruct.rv = SCARD_S_SUCCESS;

      rv = MessageSendWithHeader(SCARD_RECONNECT, currentContextMap->dwClientID,
            sizeof(scReconnectStruct), (void *) &scReconnectStruct);

      if (rv != SCARD_S_SUCCESS)
            goto end;

      /*
       * Read a message from the server
       */
      rv = MessageReceive(&scReconnectStruct, sizeof(scReconnectStruct),
            currentContextMap->dwClientID);

      if (rv != SCARD_S_SUCCESS)
            goto end;

      rv = scReconnectStruct.rv;

      if (sharing_shall_block && (SCARD_E_SHARING_VIOLATION == rv))
      {
            (void)SYS_USleep(PCSCLITE_LOCK_POLL_RATE);
            goto retry;
      }

      *pdwActiveProtocol = scReconnectStruct.dwActiveProtocol;

end:
      (void)pthread_mutex_unlock(currentContextMap->mMutex);

    PROFILE_END(rv)

      return rv;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index