int vicc_present(struct vicc_ctx *ctx) { unsigned char *atr = NULL; if (!ctx) return 0; if (ctx->client_sock < 0) { if (ctx->server_sock) { /* server mode, try to accept a client */ ctx->client_sock = waitforclient(ctx->server_sock, 0, 0); if (!ctx->client_sock) { ctx->client_sock = -1; } } else { /* client mode, try to connect (again) */ ctx->client_sock = connectsock(ctx->hostname, ctx->port); } } if (ctx->client_sock < 0) /* not connected */ return 0; /* get the atr to check if the card is still alive */ if (vicc_getatr(ctx, &atr) <= 0) return 0; free(atr); return 1; }
int vicc_present(struct vicc_ctx *ctx) { unsigned char *atr = NULL; /* get the atr to check if the card is still alive */ if (!vicc_connect(ctx, 0, 0) || vicc_getatr(ctx, &atr) <= 0) return 0; free(atr); return 1; }
RESPONSECODE IFDHGetCapabilities (DWORD Lun, DWORD Tag, PDWORD Length, PUCHAR Value) { unsigned char *atr = NULL; ssize_t size; if (!Length || !Value) return IFD_COMMUNICATION_ERROR; switch (Tag) { case TAG_IFD_ATR: size = vicc_getatr(&atr); if (size < 0) { Log1(PCSC_LOG_ERROR, "could not get ATR"); return IFD_COMMUNICATION_ERROR; } if (size == 0) { Log1(PCSC_LOG_ERROR, "Virtual ICC removed"); return IFD_ICC_NOT_PRESENT; } Log2(PCSC_LOG_DEBUG, "Got ATR (%d bytes)", size); if (*Length < size) { free(atr); Log1(PCSC_LOG_ERROR, "Not enough memory for ATR"); return IFD_COMMUNICATION_ERROR; } memcpy(Value, atr, size); *Length = size; free(atr); break; case TAG_IFD_SLOTS_NUMBER: if (*Length < 1) { Log1(PCSC_LOG_ERROR, "Invalid input data"); return IFD_COMMUNICATION_ERROR; } *Value = 1; *Length = 1; break; default: Log2(PCSC_LOG_DEBUG, "unknown tag %d", (int)Tag); return IFD_ERROR_TAG; } return IFD_SUCCESS; }
RESPONSECODE IFDHGetCapabilities (DWORD Lun, DWORD Tag, PDWORD Length, PUCHAR Value) { unsigned char *atr = NULL; ssize_t size; size_t slot = Lun & 0xffff; RESPONSECODE r = IFD_COMMUNICATION_ERROR; if (slot >= vicc_max_slots) goto err; if (!Length || !Value) goto err; switch (Tag) { case TAG_IFD_ATR: size = vicc_getatr(ctx[slot], &atr); if (size < 0) { Log1(PCSC_LOG_ERROR, "could not get ATR"); goto err; } if (size == 0) { Log1(PCSC_LOG_ERROR, "Virtual ICC removed"); goto err; } Log2(PCSC_LOG_DEBUG, "Got ATR (%d bytes)", size); #ifndef __APPLE__ if (*Length < size) { #else /* Apple's new SmartCardServices on OS X 10.10 doesn't set the * length correctly so we only check for the maximum */ if (MAX_ATR_SIZE < size) { #endif free(atr); Log1(PCSC_LOG_ERROR, "Not enough memory for ATR"); goto err; } memcpy(Value, atr, size); *Length = size; free(atr); break; case TAG_IFD_SLOTS_NUMBER: if (*Length < 1) { Log1(PCSC_LOG_ERROR, "Invalid input data"); goto err; } *Value = vicc_max_slots; *Length = 1; break; case TAG_IFD_THREAD_SAFE: if (*Length < 1) { Log1(PCSC_LOG_ERROR, "Invalid input data"); goto err; } /* We are not thread safe due to * the global hostname and ctx */ *Value = 0; *Length = 1; break; case TAG_IFD_SLOT_THREAD_SAFE: if (*Length < 1) { Log1(PCSC_LOG_ERROR, "Invalid input data"); goto err; } /* driver supports access to multiple slots of the same reader at * the same time */ *Value = 1; *Length = 1; break; default: Log2(PCSC_LOG_DEBUG, "unknown tag %d", (int)Tag); r = IFD_ERROR_TAG; goto err; } r = IFD_SUCCESS; err: if (r != IFD_SUCCESS && Length) *Length = 0; return r; } RESPONSECODE IFDHSetCapabilities (DWORD Lun, DWORD Tag, DWORD Length, PUCHAR Value) { Log9(PCSC_LOG_DEBUG, "IFDHSetCapabilities not supported (Lun=%u Tag=%u Length=%u Value=%p)%s%s%s%s", (unsigned int) Lun, (unsigned int) Tag, (unsigned int) Length, (unsigned char *) Value, "", "", "", ""); return IFD_NOT_SUPPORTED; }
RESPONSECODE IFDHGetCapabilities (DWORD Lun, DWORD Tag, PDWORD Length, PUCHAR Value) { unsigned char *atr = NULL; ssize_t size; size_t slot = Lun & 0xffff; if (slot >= vicc_max_slots) { return IFD_COMMUNICATION_ERROR; } if (!Length || !Value) return IFD_COMMUNICATION_ERROR; switch (Tag) { case TAG_IFD_ATR: size = vicc_getatr(ctx[slot], &atr); if (size < 0) { Log1(PCSC_LOG_ERROR, "could not get ATR"); return IFD_COMMUNICATION_ERROR; } if (size == 0) { Log1(PCSC_LOG_ERROR, "Virtual ICC removed"); return IFD_ICC_NOT_PRESENT; } Log2(PCSC_LOG_DEBUG, "Got ATR (%d bytes)", size); if (*Length < size) { free(atr); Log1(PCSC_LOG_ERROR, "Not enough memory for ATR"); return IFD_COMMUNICATION_ERROR; } memcpy(Value, atr, size); *Length = size; free(atr); break; case TAG_IFD_SLOTS_NUMBER: if (*Length < 1) { Log1(PCSC_LOG_ERROR, "Invalid input data"); return IFD_COMMUNICATION_ERROR; } *Value = vicc_max_slots; *Length = 1; break; case TAG_IFD_SLOT_THREAD_SAFE: /* driver supports access to multiple slots of the same reader at * the same time */ *Value = 1; *Length = 1; break; default: Log2(PCSC_LOG_DEBUG, "unknown tag %d", (int)Tag); return IFD_ERROR_TAG; } return IFD_SUCCESS; }