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

LONG SCardEndTransaction ( SCARDHANDLE  hCard,
DWORD  dwDisposition 
)

Ends a previously begun transaction.

The calling application must be the owner of the previously begun transaction or an error will occur.

Parameters:
[in]hCardConnection made from SCardConnect().
[in]dwDispositionAction to be taken on the reader. The disposition action is not currently used in this release.
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 value for dwDisposition (SCARD_E_INVALID_VALUE)
SCARD_E_NO_SERVICEThe server is not running (SCARD_E_NO_SERVICE)
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_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 = SCardBeginTransaction(hCard);
 ...
 / * Do some transmit commands * /
 ...
 rv = SCardEndTransaction(hCard, SCARD_LEAVE_CARD);

Definition at line 1252 of file winscard_clnt.c.

References pubReaderStatesList::cardAtr, pubReaderStatesList::cardAtrLength, pubReaderStatesList::cardProtocol, _psContextMap::dwClientID, IFD_POWER_DOWN, IFD_POWER_UP, IFD_RESET, IFDPowerICC(), MAX_BUFFER_SIZE, MessageReceive(), MessageSendWithHeader(), _psContextMap::mMutex, pubReaderStatesList::readerState, ReaderContext::readerState, SCARD_ABSENT, SCARD_E_INVALID_HANDLE, SCARD_E_INVALID_VALUE, SCARD_EJECT_CARD, SCARD_END_TRANSACTION, 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, and SYS_USleep().

{
      LONG rv;
      struct end_struct scEndStruct;
      int randnum;
      SCONTEXTMAP * currentContextMap;
      CHANNEL_MAP * pChannelMap;

      PROFILE_START

      /*
       * 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;

      scEndStruct.hCard = hCard;
      scEndStruct.dwDisposition = dwDisposition;
      scEndStruct.rv = SCARD_S_SUCCESS;

      rv = MessageSendWithHeader(SCARD_END_TRANSACTION,
            currentContextMap->dwClientID,
            sizeof(scEndStruct), (void *) &scEndStruct);

      if (rv != SCARD_S_SUCCESS)
            goto end;

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

      if (rv != SCARD_S_SUCCESS)
            goto end;

      /*
       * This helps prevent starvation
       */
      randnum = SYS_RandomInt(1000, 10000);
      (void)SYS_USleep(randnum);
      rv = scEndStruct.rv;

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