export vicc_connect

This commit is contained in:
Frank Morgner
2015-03-14 00:53:55 +01:00
parent 03e4a2d64e
commit a515be58f9
2 changed files with 17 additions and 4 deletions

View File

@@ -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);

View File

@@ -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);