/** * Provide statistical information about the IFD and ICC including insertions, * atr, powering status/etc. */ LONG IFDStatusICC(READER_CONTEXT * rContext, PDWORD pdwStatus) { RESPONSECODE rv; DWORD dwCardStatus = 0; #ifndef PCSCLITE_STATIC_DRIVER RESPONSECODE(*IFDH_icc_presence) (DWORD) = NULL; IFDH_icc_presence = rContext->psFunctions.psFunctions_v2.pvfICCPresence; #endif /* LOCK THIS CODE REGION */ (void)pthread_mutex_lock(rContext->mMutex); #ifndef PCSCLITE_STATIC_DRIVER rv = (*IFDH_icc_presence) (rContext->slot); #else rv = IFDHICCPresence(rContext->slot); #endif /* END OF LOCKED REGION */ (void)pthread_mutex_unlock(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; } *pdwStatus = dwCardStatus; return SCARD_S_SUCCESS; }
static LONG handle2atr(DWORD Lun, LPBYTE pbAtr, LPDWORD pcbAtrLen) { LONG r; void *atr; unsigned char _atr[MAX_ATR_SIZE]; SET_R_TEST( responsecode2long( IFDHICCPresence(Lun))); SET_R_TEST( autoallocate(pbAtr, pcbAtrLen, MAX_ATR_SIZE, (void **) &atr)); if (!atr) { /* caller wants to have the length */ *pcbAtrLen = sizeof _atr; atr = _atr; } SET_R_TEST( responsecode2long( IFDHGetCapabilities (Lun, TAG_IFD_ATR, pcbAtrLen, atr))); err: return r; }
/** * Provide statistical information about the IFD and ICC including insertions, * atr, powering status/etc. */ LONG IFDStatusICC(PREADER_CONTEXT rContext, PDWORD pdwStatus, const unsigned char *pucAtr, PDWORD pdwAtrLen) { 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; // Defensive measure if (!IFDH_icc_presence) return SCARD_E_SYSTEM_CANCELLED; } #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, (unsigned char *)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; }