From a515be58f9620e2c9320fe7b2b35faf142578cd3 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Sat, 14 Mar 2015 00:53:55 +0100 Subject: [PATCH] export vicc_connect --- virtualsmartcard/src/vpcd/vpcd.c | 14 ++++++++++---- virtualsmartcard/src/vpcd/vpcd.h | 7 +++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/virtualsmartcard/src/vpcd/vpcd.c b/virtualsmartcard/src/vpcd/vpcd.c index 55bd68c..26fb744 100644 --- a/virtualsmartcard/src/vpcd/vpcd.c +++ b/virtualsmartcard/src/vpcd/vpcd.c @@ -341,16 +341,16 @@ ssize_t vicc_transmit(struct vicc_ctx *ctx, return r; } -int vicc_present(struct vicc_ctx *ctx) { - unsigned char *atr = NULL; +int vicc_connect(struct vicc_ctx *ctx, long secs, long usecs) +{ 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); + ctx->client_sock = waitforclient(ctx->server_sock, secs, usecs); if (!ctx->client_sock) { ctx->client_sock = -1; } @@ -363,9 +363,15 @@ int vicc_present(struct vicc_ctx *ctx) { if (ctx->client_sock < 0) /* not connected */ return 0; + else + 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_getatr(ctx, &atr) <= 0) + if (!vicc_connect(ctx, 0, 0) || vicc_getatr(ctx, &atr) <= 0) return 0; free(atr); diff --git a/virtualsmartcard/src/vpcd/vpcd.h b/virtualsmartcard/src/vpcd/vpcd.h index 0739df3..7544cad 100644 --- a/virtualsmartcard/src/vpcd/vpcd.h +++ b/virtualsmartcard/src/vpcd/vpcd.h @@ -42,6 +42,12 @@ extern "C" { /** Standard port of the virtual smart card reader */ #define VPCDPORT 35963 +/** how long to wait for a card in seconds */ +extern long vpcd_waitsecs; + +/** how long to wait for a card in microseconds */ +extern long vpcd_waitusecs; + /** * @brief Initialize the module * @@ -59,6 +65,7 @@ struct vicc_ctx * vicc_init(const char *hostname, unsigned short port); int vicc_exit(struct vicc_ctx *ctx); int vicc_eject(struct vicc_ctx *ctx); +int vicc_connect(struct vicc_ctx *ctx, long secs, long usecs); int vicc_present(struct vicc_ctx *ctx); int vicc_poweron(struct vicc_ctx *ctx); int vicc_poweroff(struct vicc_ctx *ctx);