From 4b5230c12976bedafe805a8f05081d0c19b029d4 Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Wed, 26 Jun 2013 19:06:24 +0200 Subject: [PATCH] adapted to changes of fb4dbe59ba39e9d6526ffbdba472343ddeed9e4c --- pcsc-relay/src/vpcd-driver.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/pcsc-relay/src/vpcd-driver.c b/pcsc-relay/src/vpcd-driver.c index 9c374a5..795f5e9 100644 --- a/pcsc-relay/src/vpcd-driver.c +++ b/pcsc-relay/src/vpcd-driver.c @@ -33,19 +33,26 @@ unsigned int vpcdport = VPCDPORT; static int vpcd_connect(driver_data_t **driver_data) { + struct vicc_ctx *ctx; + int vicc_found = 0; + if (!driver_data) + return 0; - if (vicc_init(vpcdport) < 0) { + + ctx = vicc_init(vpcdport); + if (!ctx) { RELAY_ERROR("Could not initialize connection to virtual ICC\n"); return 0; } + *driver_data = ctx; + + INFO("Waiting for virtual ICC on port %hu\n", (unsigned short) vpcdport); - - do { - switch (vicc_present()) { + switch (vicc_present(ctx)) { case 0: /* not present */ sleep(1); @@ -60,7 +67,7 @@ static int vpcd_connect(driver_data_t **driver_data) } while (!vicc_found); - if (vicc_poweron() < 0) { + if (vicc_poweron(ctx) < 0) { RELAY_ERROR("could not powerup\n"); return 0; } @@ -73,10 +80,12 @@ static int vpcd_connect(driver_data_t **driver_data) static int vpcd_disconnect(driver_data_t *driver_data) { - if (vicc_eject() != 0) + struct vicc_ctx *ctx = driver_data; + + if (vicc_eject(ctx) != 0) DEBUG("Could not eject virtual ICC\n"); - if (vicc_exit() != 0) { + if (vicc_exit(ctx) != 0) { RELAY_ERROR("Could not close connection to virtual ICC\n"); return 0; } @@ -88,9 +97,11 @@ static int vpcd_transmit(driver_data_t *driver_data, const unsigned char *send, size_t send_len, unsigned char *recv, size_t *recv_len) { + struct vicc_ctx *ctx = driver_data; + unsigned char *rapdu = NULL; int r = 0; - ssize_t size = vicc_transmit(send_len, send, &rapdu); + ssize_t size = vicc_transmit(ctx, send_len, send, &rapdu); if (size < 0) { RELAY_ERROR("could not send apdu or receive rapdu\n");