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_E_NO_SMARTCARD No smart card present (SCARD_E_NO_SMARTCARD)
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 1100 of file winscard_clnt.c.

References disconnect_struct::dwDisposition, disconnect_struct::hCard, IFD_POWER_DOWN, IFD_POWER_UP, IFD_RESET, IFDPowerICC(), MAX_BUFFER_SIZE, PCSCLITE_LOCK_POLL_RATE, PCSCLITE_READ_TIMEOUT, disconnect_struct::rv, SCARD_ABSENT, SCARD_DISCONNECT, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_VALUE, SCARD_E_NO_SERVICE, SCARD_E_NO_SMARTCARD, SCARD_EJECT_CARD, SCARD_EXCLUSIVE_CONTEXT, SCARD_F_COMM_ERROR, SCARD_LEAVE_CARD, SCARD_NEGOTIABLE, SCARD_NO_CONTEXT, SCARD_POWERED, SCARD_PRESENT, SCARD_PROTOCOL_UNDEFINED, SCARD_RESET, SCARD_RESET_CARD, SCARD_S_SUCCESS, SCARD_SPECIFIC, SCARD_SWALLOWED, SCARD_UNKNOWN, SCARD_UNPOWER_CARD, SHMMessageReceive(), SHMMessageSendWithHeader(), and SYS_USleep().

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

      PROFILE_START

      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;

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

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

      if (rv == -1)
      {
            rv = SCARD_E_NO_SERVICE;
            goto end;
      }

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

      if (rv < 0)
      {
            rv = SCARD_F_COMM_ERROR;
            goto end;
      }

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

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

      PROFILE_END(rv)

      return rv;
}


Generated by  Doxygen 1.6.0   Back to index