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

LONG SCardEndTransaction ( SCARDHANDLE  hCard,
DWORD  dwDisposition 
)

This function ends a previously begun transaction.

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

Parameters:
[in] hCard Connection made from SCardConnect().
[in] dwDisposition Action to be taken on the reader. The disposition action is not currently used in this release.
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 value for dwDisposition (SCARD_E_INVALID_VALUE)
SCARD_E_NO_SERVICE The server is not runing (SCARD_E_NO_SERVICE)
SCARD_E_READER_UNAVAILABLE The reader has been removed (SCARD_E_READER_UNAVAILABLE)
SCARD_E_SHARING_VIOLATION Someone else has exclusive rights (SCARD_E_SHARING_VIOLATION)
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 = SCardBeginTransaction(hCard);
 ...
 / * Do some transmit commands * /
 ...
 rv = SCardEndTransaction(hCard, SCARD_LEAVE_CARD);

Definition at line 1266 of file winscard_clnt.c.

References rxSharedSegment::data, end_struct::dwDisposition, end_struct::hCard, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MAX_READERS_CONTEXTS, _psContextMap::psChannelMap, psContextMap, _psChannelMap::readerName, end_struct::rv, SCARD_E_INVALID_HANDLE, SCARD_E_NO_SERVICE, SCARD_E_READER_UNAVAILABLE, SCARD_END_TRANSACTION, SCARD_F_COMM_ERROR, SCARD_S_SUCCESS, SCardCheckDaemonAvailability(), SHMClientRead(), SYS_USleep(), and WrapSHMWrite().

{
      LONG rv;
      end_struct scEndStruct;
      sharedSegmentMsg msgStruct;
      int randnum, i;
      DWORD dwContextIndex, dwChannelIndex;

      PROFILE_START

      /*
       * Zero out everything
       */
      randnum = 0;

      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;

      for (i = 0; i < PCSCLITE_MAX_READERS_CONTEXTS; i++)
      {
            char *r = psContextMap[dwContextIndex].psChannelMap[dwChannelIndex].readerName;

            /* by default r == NULL */
            if (r && strcmp(r, (readerStates[i])->readerName) == 0)
                  break;
      }

      if (i == PCSCLITE_MAX_READERS_CONTEXTS)
      {
            (void)SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex);
            return SCARD_E_READER_UNAVAILABLE;
      }

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

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

      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(&scEndStruct, &msgStruct.data, sizeof(scEndStruct));

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

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

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

      PROFILE_END(scEndStruct.rv)

      return scEndStruct.rv;
}


Generated by  Doxygen 1.6.0   Back to index