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

LONG SCardDisconnect ( SCARDHANDLE  hCard,
DWORD  dwDisposition 
)

Terminates a connection made through SCardConnect().

Parameters:
[in]hCardConnection made from SCardConnect().
[in]dwDispositionReader function to execute.
Returns:
Error code.
Return values:
SCARD_S_SUCCESSSuccessful(SCARD_S_SUCCESS)
SCARD_E_INVALID_HANDLEInvalid hCard handle (SCARD_E_INVALID_HANDLE)
SCARD_E_INVALID_VALUEInvalid dwDisposition (SCARD_E_INVALID_VALUE)
SCARD_E_NO_SERVICEThe server is not running (SCARD_E_NO_SERVICE)
SCARD_E_NO_SMARTCARDNo smart card present (SCARD_E_NO_SMARTCARD)
SCARD_F_COMM_ERRORAn 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 1042 of file winscard_clnt.c.

References pubReaderStatesList::cardAtr, pubReaderStatesList::cardAtrLength, pubReaderStatesList::cardProtocol, ReaderContext::contexts, ReaderContext::hLockId, IFD_POWER_DOWN, IFD_POWER_UP, IFD_RESET, IFD_SUCCESS, IFDGetCapabilities(), IFDPowerICC(), MAX_BUFFER_SIZE, MessageReceive(), MessageSendWithHeader(), PCSCLITE_LOCK_POLL_RATE, PCSCLITE_SHARING_EXCLUSIVE_CONTEXT, PCSCLITE_SHARING_NO_CONTEXT, POWER_STATE_GRACE_PERIOD, POWER_STATE_UNPOWERED, ReaderContext::powerState, ReaderContext::powerState_lock, pubReaderStatesList::readerSharing, pubReaderStatesList::readerState, ReaderContext::readerState, SCARD_ABSENT, SCARD_DISCONNECT, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_VALUE, SCARD_E_SHARING_VIOLATION, SCARD_EJECT_CARD, SCARD_LEAVE_CARD, SCARD_NEGOTIABLE, SCARD_POWERED, SCARD_PRESENT, SCARD_PROTOCOL_UNDEFINED, SCARD_RESET, SCARD_RESET_CARD, SCARD_S_SUCCESS, SCARD_SWALLOWED, SCARD_UNPOWER_CARD, SCARD_W_REMOVED_CARD, ReaderContext::slot, SYS_USleep(), and TAG_IFD_STOP_POLLING_THREAD.

{
      LONG rv;
      struct disconnect_struct scDisconnectStruct;
      SCONTEXTMAP * currentContextMap;
      CHANNEL_MAP * pChannelMap;

      PROFILE_START
      API_TRACE_IN("%ld %ld", hCard, dwDisposition)

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

      (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 */
      {
            rv = SCARD_E_INVALID_HANDLE;
            goto error;
      }

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

      rv = MessageSendWithHeader(SCARD_DISCONNECT, currentContextMap->dwClientID,
            sizeof(scDisconnectStruct), (void *) &scDisconnectStruct);

      if (rv != SCARD_S_SUCCESS)
            goto end;

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

      if (rv != SCARD_S_SUCCESS)
            goto end;

      if (SCARD_S_SUCCESS == scDisconnectStruct.rv)
            (void)SCardRemoveHandle(hCard);
      rv = scDisconnectStruct.rv;

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

error:
      PROFILE_END(rv)
      API_TRACE_OUT("")

      return rv;
}

Here is the call graph for this function:


Generated by  Doxygen 1.6.0   Back to index