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

PCSC_API LONG SCardStatus ( SCARDHANDLE  hCard,
LPSTR  mszReaderNames,
LPDWORD  pcchReaderLen,
LPDWORD  pdwState,
LPDWORD  pdwProtocol,
LPBYTE  pbAtr,
LPDWORD  pcbAtrLen 
)

This function returns the current status of the reader connected to by hCard.

It's friendly name will be stored in szReaderName. pcchReaderLen will be the size of the allocated buffer for szReaderName, while pcbAtrLen will be the size of the allocated buffer for pbAtr. If either of these is too small, the function will return with SCARD_E_INSUFFICIENT_BUFFER and the necessary size in pcchReaderLen and pcbAtrLen. The current state, and protocol will be stored in pdwState and pdwProtocol respectively.

Parameters:
[in] hCard Connection made from SCardConnect.
mszReaderNames [inout] Friendly name of this reader.
pcchReaderLen [inout] Size of the szReaderName multistring.
[out] pdwState Current state of this reader. pdwState is a DWORD possibly OR'd with the following values:
  • SCARD_ABSENT - There is no card in the reader.
  • SCARD_PRESENT - There is a card in the reader, but it has not been moved into position for use.
  • SCARD_SWALLOWED - There is a card in the reader in position for use. The card is not powered.
  • SCARD_POWERED - Power is being provided to the card, but the reader driver is unaware of the mode of the card.
  • SCARD_NEGOTIABLE - The card has been reset and is awaiting PTS negotiation.
  • SCARD_SPECIFIC - The card has been reset and specific communication protocols have been established.
[out] pdwProtocol Current protocol of this reader.
  • SCARD_PROTOCOL_T0 Use the T=0 protocol.
  • SCARD_PROTOCOL_T1 Use the T=1 protocol.
[out] pbAtr Current ATR of a card in this reader.
[out] pcbAtrLen Length of ATR.
Returns:
Error code.
Return values:
SCARD_S_SUCCESS Successful.
SCARD_E_INVALID_HANDLE Invalid hCard handle.
SCARD_E_INSUFFICIENT_BUFFER Not enough allocated memory for szReaderName or for pbAtr.
SCARD_E_READER_UNAVAILABLE The reader has been removed.
Test:
 SCARDCONTEXT hContext;
 SCARDHANDLE hCard;
 DWORD dwActiveProtocol;
 DWORD dwState, dwProtocol, dwAtrLen, dwReaderLen;
 BYTE pbAtr[MAX_ATR_SIZE];
 ...
 rv = SCardEstablishContext(SCARD_SCOPE_SYSTEM, NULL, NULL, &hContext);
 rv = SCardConnect(hContext, "Reader X", SCARD_SHARE_SHARED, SCARD_PROTOCOL_T0, &hCard, &dwActiveProtocol);
 ...
 dwAtrLen = sizeof(pbAtr);
 rv=SCardStatus(hCard, NULL, &dwReaderLen, &dwState, &dwProtocol, pbAtr, &dwAtrLen);

Definition at line 1070 of file winscard.c.

References rxSharedSegment::data, status_struct::hCard, MAX_ATR_SIZE, MAX_BUFFER_SIZE, status_struct::mszReaderNames, status_struct::pbAtr, status_struct::pcbAtrLen, status_struct::pcchReaderLen, PCSCLITE_CLIENT_ATTEMPTS, PCSCLITE_MAX_READERS_CONTEXTS, _psContextMap::psChannelMap, psContextMap, _psChannelMap::readerName, SCardCheckDaemonAvailability(), SCardLockThread(), SCardUnlockThread(), SHMClientRead(), SYS_MutexLock(), SYS_MutexUnLock(), and WrapSHMWrite().

Referenced by MSGFunctionDemarshall().

{
      LONG rv;
      PREADER_CONTEXT rContext = NULL;

      rv = RFReaderInfoById(hCard, &rContext);

      /*
       * Cannot find the hCard in this context
       */
      if (rv != SCARD_S_SUCCESS)
            return rv;

      if (strlen(rContext->lpcReader) > MAX_BUFFER_SIZE
                  || rContext->readerState->cardAtrLength > MAX_ATR_SIZE
                  || rContext->readerState->cardAtrLength < 0)
            return SCARD_F_INTERNAL_ERROR;

      /*
       * This is a client side function however the server maintains the
       * list of events between applications so it must be passed through to
       * obtain this event if it has occurred
       */

      /*
       * Make sure some event has not occurred
       */
      if ((rv = RFCheckReaderEventState(rContext, hCard)) != SCARD_S_SUCCESS)
            return rv;

      /*
       * Make sure the reader is working properly
       */
      rv = RFCheckReaderStatus(rContext);
      if (rv != SCARD_S_SUCCESS)
            return rv;

      if (mszReaderNames)
      {  /* want reader name */
            if (pcchReaderLen)
            { /* & present reader name length */
                  if (*pcchReaderLen >= strlen(rContext->lpcReader))
                  { /* & enough room */
                        *pcchReaderLen = strlen(rContext->lpcReader);
                        strncpy(mszReaderNames, rContext->lpcReader, MAX_READERNAME);
                  }
                  else
                  {        /* may report only reader name len */
                        *pcchReaderLen = strlen(rContext->lpcReader);
                        rv = SCARD_E_INSUFFICIENT_BUFFER;
                  }
            }
            else
            {            /* present buf & no buflen */
                  return SCARD_E_INVALID_PARAMETER;
            }
      }
      else
      {
            if (pcchReaderLen)
            { /* want reader len only */
                  *pcchReaderLen = strlen(rContext->lpcReader);
            }
            else
            {
            /* nothing todo */
            }
      }

      if (pdwState)
            *pdwState = rContext->readerState->readerState;

      if (pdwProtocol)
            *pdwProtocol = rContext->readerState->cardProtocol;

      if (pbAtr)
      {  /* want ATR */
            if (pcbAtrLen)
            { /* & present ATR length */
                  if (*pcbAtrLen >= rContext->readerState->cardAtrLength)
                  { /* & enough room */
                        *pcbAtrLen = rContext->readerState->cardAtrLength;
                        memcpy(pbAtr, rContext->readerState->cardAtr,
                              rContext->readerState->cardAtrLength);
                  }
                  else
                  { /* may report only ATR len */
                        *pcbAtrLen = rContext->readerState->cardAtrLength;
                        rv = SCARD_E_INSUFFICIENT_BUFFER;
                  }
            }
            else
            { /* present buf & no buflen */
                  return SCARD_E_INVALID_PARAMETER;
            }
      }
      else
      {
            if (pcbAtrLen)
            { /* want ATR len only */
                  *pcbAtrLen = rContext->readerState->cardAtrLength;
            }
            else
            {
                  /* nothing todo */
            }
      }

      return rv;
}


Generated by  Doxygen 1.6.0   Back to index