From a40cde2d049a89e77f7e756d1d7e9594cd70e1d1 Mon Sep 17 00:00:00 2001 From: Peter Marschall Date: Sun, 5 Jan 2020 10:54:47 +0100 Subject: [PATCH] util: refactor listing card drivers Make util_list_card_drivers() a function in util.c to allow consistent listing of available card drivers from tools. --- src/tools/util.c | 20 ++++++++++++++++++++ src/tools/util.h | 1 + 2 files changed, 21 insertions(+) diff --git a/src/tools/util.c b/src/tools/util.c index 5faab385..ade86fb1 100644 --- a/src/tools/util.c +++ b/src/tools/util.c @@ -305,6 +305,26 @@ util_print_usage_and_die(const char *app_name, const struct option options[], exit(2); } +int util_list_card_drivers(const sc_context_t *ctx) +{ + int i; + + if (ctx == NULL) { + fprintf(stderr, "Unable to get card drivers!\n"); + return 1; + } + if (ctx->card_drivers[0] == NULL) { + fprintf(stderr, "No card drivers installed!\n"); + return 1; + } + printf("Available card drivers:\n"); + for (i = 0; ctx->card_drivers[i] != NULL; i++) { + printf(" %-16s %s\n", ctx->card_drivers[i]->short_name, + ctx->card_drivers[i]->name); + } + return 0; +} + const char * util_acl_to_str(const sc_acl_entry_t *e) { static char line[80], buf[20]; diff --git a/src/tools/util.h b/src/tools/util.h index 21c8293e..929928d8 100644 --- a/src/tools/util.h +++ b/src/tools/util.h @@ -41,6 +41,7 @@ void util_hex_dump(FILE *f, const u8 *in, int len, const char *sep); void util_hex_dump_asc(FILE *f, const u8 *in, size_t count, int addr); NORETURN void util_print_usage_and_die(const char *app_name, const struct option options[], const char *option_help[], const char *args); +int util_list_card_drivers(const sc_context_t *ctx); const char * util_acl_to_str(const struct sc_acl_entry *e); void util_warn(const char *fmt, ...); void util_error(const char *fmt, ...);