From 4de6dab69da6ae7dc24d7b0ddc6f197ed915e456 Mon Sep 17 00:00:00 2001 From: Aaron Berger Date: Thu, 7 Feb 2019 09:46:24 -0600 Subject: [PATCH] Support for multiple readers --- src/mfoc.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/mfoc.c b/src/mfoc.c index e2545be..5bd60ae 100644 --- a/src/mfoc.c +++ b/src/mfoc.c @@ -783,14 +783,49 @@ void mf_init(mfreader *r) { // Connect to the first NFC device nfc_init(&context); + if (context == NULL) { ERR("Unable to init libnfc (malloc)"); exit(EXIT_FAILURE); } - r->pdi = nfc_open(context, NULL); - if (!r->pdi) { - printf("No NFC device found.\n"); + + nfc_connstring connstrings[10]; + const size_t numconstrings = 10; + int num_devices = nfc_list_devices(context,connstrings,numconstrings); + + if(num_devices == 1) + { + r->pdi = nfc_open(context, NULL); + if (!r->pdi) { + printf("No NFC device found.\n"); + exit(EXIT_FAILURE); + } + } + else + { + printf("multiple readers found\n"); + //get a specific device + for(int n=0;n 0); + if(userselected >= 0 && userselected < num_devices) + { + r->pdi = nfc_open(context,connstrings[userselected]); + if (!r->pdi) { + printf("Unable to open selected device\n"); + exit(EXIT_FAILURE); + } + return; + } + + printf("Invalid selection\n"); exit(EXIT_FAILURE); + } }