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.
  • SCARD_LEAVE_CARD - Do nothing.
  • SCARD_RESET_CARD - Reset the card.
  • SCARD_UNPOWER_CARD - Unpower the card.
  • SCARD_EJECT_CARD - Eject the card.
Returns:
Error code.
Return values:
SCARD_S_SUCCESS Successful.
SCARD_E_INVALID_HANDLE Invalid hCard handle.
SCARD_E_SHARING_VIOLATION Someone else has exclusive rights.
SCARD_E_READER_UNAVAILABLE The reader has been removed.
Test:
 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 1156 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, SCARD_EJECT_CARD, SCARD_LEAVE_CARD, SCARD_RESET_CARD, SCARD_UNPOWER_CARD, SCardCheckDaemonAvailability(), SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), SYS_USleep(), and WrapSHMWrite().

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

      PROFILE_START

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

      if (dwDisposition != SCARD_LEAVE_CARD &&
            dwDisposition != SCARD_RESET_CARD &&
            dwDisposition != SCARD_UNPOWER_CARD &&
            dwDisposition != SCARD_EJECT_CARD)
      {
            return SCARD_E_INVALID_VALUE;
      }

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

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

      if (rv == -1)
            return SCARD_E_INVALID_HANDLE;

      SYS_MutexLock(psContextMap[dwContextIndex].mMutex);   

      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)
      {
            SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex); 
            return SCARD_E_READER_UNAVAILABLE;
      }

      scEndStruct.hCard = hCard;
      scEndStruct.dwDisposition = dwDisposition;

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

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

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

      SYS_MutexUnLock(psContextMap[dwContextIndex].mMutex); 

      PROFILE_END

      return scEndStruct.rv;
}


Generated by  Doxygen 1.6.0   Back to index