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_connect(struct vicc_ctx *ctx, long secs, long usecs) { if (!ctx) return 0; if (ctx->client_sock == INVALID_SOCKET) { if (ctx->server_sock) { /* server mode, try to accept a client */ ctx->client_sock = waitforclient(ctx->server_sock, secs, usecs); if (!ctx->client_sock) { ctx->client_sock = INVALID_SOCKET; } } else { /* client mode, try to connect (again) */ ctx->client_sock = connectsock(ctx->hostname, ctx->port); } } if (ctx->client_sock == INVALID_SOCKET) /* not connected */ return 0; else return 1; }