From b67817b19db59add8bd467e0c7d7dc807c96bdbb Mon Sep 17 00:00:00 2001 From: Frank Morgner Date: Thu, 2 Aug 2012 11:38:01 +0200 Subject: [PATCH] added LEVEL_NORMAL for in interactive mode --- pcsc-relay/src/lnfc.c | 3 +-- pcsc-relay/src/opicc.c | 3 +-- pcsc-relay/src/pcsc-relay.c | 30 +++++++++++++++--------------- pcsc-relay/src/pcsc-relay.h | 4 ++++ 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/pcsc-relay/src/lnfc.c b/pcsc-relay/src/lnfc.c index 7c0d818..c4e6f82 100644 --- a/pcsc-relay/src/lnfc.c +++ b/pcsc-relay/src/lnfc.c @@ -146,8 +146,7 @@ static int lnfc_connect(driver_data_t **driver_data) return 0; } - if (verbose >= 0) - printf("Connected to %s\n", nfc_device_get_name(data->pndTarget)); + PRINTF("Connected to %s\n", nfc_device_get_name(data->pndTarget)); DEBUG("Waiting for a command that is not part of the anti-collision...\n"); data->iCapduLen = nfc_target_init(data->pndTarget, &ntEmulatedTarget, data->abtCapdu, sizeof data->abtCapdu, 0); diff --git a/pcsc-relay/src/opicc.c b/pcsc-relay/src/opicc.c index 0c2ec91..732a953 100644 --- a/pcsc-relay/src/opicc.c +++ b/pcsc-relay/src/opicc.c @@ -172,8 +172,7 @@ static int picc_connect(driver_data_t **driver_data) un_braindead_ify_device(fileno(data->fd)); - if (verbose >= 0) - printf("Connected to %s\n", PICCDEV); + PRINTF("Connected to %s\n", PICCDEV); return 1; } diff --git a/pcsc-relay/src/pcsc-relay.c b/pcsc-relay/src/pcsc-relay.c index 7fcabd2..6c34c28 100644 --- a/pcsc-relay/src/pcsc-relay.c +++ b/pcsc-relay/src/pcsc-relay.c @@ -47,7 +47,7 @@ static driver_data_t *scdriver_data = NULL; static void daemonize(void); static void cleanup_exit(int signo); static void cleanup(void); -static void printb(const char *label, unsigned char *buf, size_t len); +static void hexdump(const char *label, unsigned char *buf, size_t len); #if HAVE_WORKING_FORK @@ -113,19 +113,21 @@ void cleanup(void) { } void -printb(const char *label, unsigned char *buf, size_t len) +hexdump(const char *label, unsigned char *buf, size_t len) { size_t i = 0; - printf("%s", label); - while (i < len) { - printf("%02X", buf[i]); - i++; - if (i%20) - printf(" "); - else if (i != len) - printf("\n"); + if (verbose >= LEVEL_NORMAL) { + printf("%s", label); + while (i < len) { + printf("%02X", buf[i]); + i++; + if (i%20) + printf(" "); + else if (i != len) + printf("\n"); + } + printf("\n"); } - printf("\n"); } int main (int argc, char **argv) @@ -209,8 +211,7 @@ int main (int argc, char **argv) if (!buflen || !buf) continue; - if (verbose >= 0) - printb("C-APDU:\n", buf, buflen); + hexdump("C-APDU:\n", buf, buflen); /* transmit APDU to card */ @@ -221,8 +222,7 @@ int main (int argc, char **argv) /* send R-APDU */ - if (verbose >= 0) - printb("R-APDU:\n", outputBuffer, outputLength); + hexdump("R-APDU:\n", outputBuffer, outputLength); if (!rfdriver->send_rapdu(rfdriver_data, outputBuffer, outputLength)) goto err; diff --git a/pcsc-relay/src/pcsc-relay.h b/pcsc-relay/src/pcsc-relay.h index 55172fa..081d9c8 100644 --- a/pcsc-relay/src/pcsc-relay.h +++ b/pcsc-relay/src/pcsc-relay.h @@ -58,8 +58,12 @@ extern unsigned int readernum; extern struct sc_driver driver_vpcd; extern unsigned int vpcdport; +#define LEVEL_NORMAL 0 #define LEVEL_INFO 1 #define LEVEL_DEBUG 2 +#define PRINTF(...) \ + {if (verbose >= LEVEL_DEBUG) \ + printf (__VA_ARGS__);} #define DEBUG(...) \ {if (verbose >= LEVEL_DEBUG) \ printf (__VA_ARGS__);}