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

LONG SCardDisconnect ( SCARDHANDLE  hCard,
DWORD  dwDisposition 
)

This function terminates a connection to the connection made through SCardConnect(). dwDisposition can have the following values:

Parameters:
[in] hCard Connection made from SCardConnect.
[in] dwDisposition Reader function to execute.
  • 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.
Returns:
Error code.
Return values:
SCARD_S_SUCCESS Successful.
SCARD_E_INVALID_HANDLE Invalid hCard handle.
SCARD_E_INVALID_VALUE - Invalid dwDisposition.
Test:
 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 843 of file winscard_clnt.c.

References rxSharedSegment::data, disconnect_struct::dwDisposition, disconnect_struct::hCard, psContextMap, SCardCheckDaemonAvailability(), SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite().

{
      LONG rv;
      disconnect_struct scDisconnectStruct;
      sharedSegmentMsg msgStruct;
      DWORD dwContextIndex, dwChannelIndex;

      if (dwDisposition != SCARD_LEAVE_CARD &&
            dwDisposition != SCARD_RESET_CARD &&
            dwDisposition != SCARD_UNPOWER_CARD &&
            dwDisposition != SCARD_EJECT_CARD)
      {
            return SCARD_E_INVALID_VALUE;
      }

      if (SCardCheckDaemonAvailability() != SCARD_S_SUCCESS)
            return SCARD_E_NO_SERVICE;

      /*
       * Make sure this handle has been opened
       */
      rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);

      if (rv == -1)
            return SCARD_E_INVALID_HANDLE;

      SYS_MutexLock(psContextMap[dwContextIndex].mMutex);   

      scDisconnectStruct.hCard = hCard;
      scDisconnectStruct.dwDisposition = dwDisposition;

      rv = WrapSHMWrite(SCARD_DISCONNECT, psContextMap[dwContextIndex].dwClientID,
            sizeof(scDisconnectStruct),
            PCSCLITE_CLIENT_ATTEMPTS, (void *) &scDisconnectStruct);

      if (rv == -1)
      {
            SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex); 
            return SCARD_E_NO_SERVICE;
      }

      /*
       * Read a message from the server
       */
      rv = SHMClientRead(&msgStruct, psContextMap[dwContextIndex].dwClientID, PCSCLITE_CLIENT_ATTEMPTS);

      memcpy(&scDisconnectStruct, &msgStruct.data,
            sizeof(scDisconnectStruct));

      if (rv == -1)
      {
            SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex); 
            return SCARD_F_COMM_ERROR;
      }

      SCardRemoveHandle(hCard);

      SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex); 

      return scDisconnectStruct.rv;
}


Generated by  Doxygen 1.6.0   Back to index