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

LONG SCardDisconnect ( SCARDHANDLE  hCard,
DWORD  dwDisposition 
)

This function terminates a connection made through SCardConnect().

Parameters:
[in] hCard Connection made from SCardConnect().
[in] dwDisposition Reader function to execute.
Returns:
Error code.
Return values:
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_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 1030 of file winscard_clnt.c.

References rxSharedSegment::data, disconnect_struct::dwDisposition, disconnect_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, psContextMap, disconnect_struct::rv, SCARD_DISCONNECT, SCARD_E_INVALID_HANDLE, SCARD_E_NO_SERVICE, SCARD_F_COMM_ERROR, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SHMClientRead(), and WrapSHMWrite().

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

      PROFILE_START

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

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

      (void)SYS_MutexLock(psContextMap[dwContextIndex].mMutex);

      /* check the handle is still valid */
      rv = SCardGetIndicesFromHandle(hCard, &dwContextIndex, &dwChannelIndex);
      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;

      scDisconnectStruct.hCard = hCard;
      scDisconnectStruct.dwDisposition = dwDisposition;
      scDisconnectStruct.rv = SCARD_S_SUCCESS;

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

      if (rv == -1)
      {
            (void)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)
      {
            (void)SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
            return SCARD_F_COMM_ERROR;
      }

      (void)SCardRemoveHandle(hCard);

      (void)SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);

      PROFILE_END(scDisconnectStruct.rv)

      return scDisconnectStruct.rv;
}


Generated by  Doxygen 1.6.0   Back to index