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

LONG IFDStatusICC ( PREADER_CONTEXT  rContext,
PDWORD  pdwStatus,
PUCHAR  pucAtr,
PDWORD  pdwAtrLen 
)

Provide statistical information about the IFD and ICC including insertions, atr, powering status/etc.

Definition at line 412 of file ifdwrapper.c.

References ATRDecodeAtr(), IFDSetCapabilities(), MAX_ATR_SIZE, SCARD_ABSENT, SCARD_E_NOT_TRANSACTED, SCARD_E_READER_UNAVAILABLE, SCARD_PRESENT, SCARD_S_SUCCESS, and SCARD_UNKNOWN.

Referenced by IFDPowerICC(), and SCardReconnect().

{
      RESPONSECODE rv = IFD_SUCCESS;
      DWORD dwTag = 0, dwCardStatus = 0;
      SMARTCARD_EXTENSION sSmartCard;
      UCHAR ucValue[1] = "\x00";

#ifndef PCSCLITE_STATIC_DRIVER
      RESPONSECODE(*IFD_is_icc_present) (void) = NULL;
      RESPONSECODE(*IFDH_icc_presence) (DWORD) = NULL;
      RESPONSECODE(*IFD_get_capabilities) (DWORD, /*@out@*/ PUCHAR) = NULL;

      if (rContext->dwVersion == IFD_HVERSION_1_0)
      {
            IFD_is_icc_present =
                  rContext->psFunctions.psFunctions_v1.pvfICCPresence;
            IFD_get_capabilities =
                  rContext->psFunctions.psFunctions_v1.pvfGetCapabilities;
      }
      else
            IFDH_icc_presence = rContext->psFunctions.psFunctions_v2.pvfICCPresence;
#endif

      /* LOCK THIS CODE REGION */ 
      (void)SYS_MutexLock(rContext->mMutex);

#ifndef PCSCLITE_STATIC_DRIVER
      if (rContext->dwVersion == IFD_HVERSION_1_0)
      {
            ucValue[0] = rContext->dwSlot;
            (void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
            rv = (*IFD_is_icc_present) ();
      }
      else
            rv = (*IFDH_icc_presence) (rContext->dwSlot);
#else
      if (rContext->dwVersion == IFD_HVERSION_1_0)
      {
            ucValue[0] = rContext->dwSlot;
            (void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);
            rv = IFD_Is_ICC_Present();
      }
      else
            rv = IFDHICCPresence(rContext->dwSlot);
#endif

      /* END OF LOCKED REGION */
      (void)SYS_MutexUnLock(rContext->mMutex);

      if (rv == IFD_SUCCESS || rv == IFD_ICC_PRESENT)
            dwCardStatus |= SCARD_PRESENT;
      else
            if (rv == IFD_ICC_NOT_PRESENT)
                  dwCardStatus |= SCARD_ABSENT;
            else
            {
                  Log2(PCSC_LOG_ERROR, "Card not transacted: %ld", rv);
                  *pdwStatus = SCARD_UNKNOWN;

                  if (rv == IFD_NO_SUCH_DEVICE)
                  {
                        (void)SendHotplugSignal();
                        return SCARD_E_READER_UNAVAILABLE;
                  }

                  return SCARD_E_NOT_TRANSACTED;
            }

      /*
       * Now lets get the ATR and process it if IFD Handler version 1.0.
       * IFD Handler version 2.0 does this immediately after reset/power up
       * to conserve resources
       */

      if (rContext->dwVersion == IFD_HVERSION_1_0)
      {
            if (rv == IFD_SUCCESS || rv == IFD_ICC_PRESENT)
            {
                  short ret;

                  dwTag = TAG_IFD_ATR;

                  /* LOCK THIS CODE REGION */ 
                  (void)SYS_MutexLock(rContext->mMutex);

                  ucValue[0] = rContext->dwSlot;
                  (void)IFDSetCapabilities(rContext, TAG_IFD_SLOTNUM, 1, ucValue);

#ifndef PCSCLITE_STATIC_DRIVER
                  rv = (*IFD_get_capabilities) (dwTag, pucAtr);
#else
                  rv = IFD_Get_Capabilities(dwTag, pucAtr);
#endif

                  /* END OF LOCKED REGION */
                  (void)SYS_MutexUnLock(rContext->mMutex);

                  /*
                   * FIX :: This is a temporary way to return the correct size
                   * of the ATR since most of the drivers return MAX_ATR_SIZE
                   */

                  ret = ATRDecodeAtr(&sSmartCard, pucAtr, MAX_ATR_SIZE);

                  /*
                   * Might be a memory card without an ATR
                   */
                  if (ret == 0)
                        *pdwAtrLen = 0;
                  else
                        *pdwAtrLen = sSmartCard.ATR.Length;
            }
            else
            {
                  /*
                   * No card is inserted - Atr length is 0
                   */
                  *pdwAtrLen = 0;
            }
            /*
             * End of FIX
             */
      }

      *pdwStatus = dwCardStatus;

      return SCARD_S_SUCCESS;
}


Generated by  Doxygen 1.6.0   Back to index