From 4c011279ffa73b7316c26e306eef1e33387d8ee2 Mon Sep 17 00:00:00 2001 From: Audrey Diacre Date: Wed, 18 Jan 2012 16:22:06 +0000 Subject: [PATCH] add context to nfc_init(), nfc_exit(), nfc_open() and nfc_list_devices() functions. --- examples/doc/quick_start_example1.c | 6 ++-- examples/nfc-anticol.c | 8 ++--- examples/nfc-dep-initiator.c | 6 ++-- examples/nfc-dep-target.c | 10 +++--- examples/nfc-emulate-forum-tag2.c | 8 ++--- examples/nfc-emulate-tag.c | 8 ++--- examples/nfc-emulate-uid.c | 8 ++--- examples/nfc-poll.c | 8 ++--- examples/nfc-relay.c | 12 ++++---- examples/pn53x-diagnose.c | 6 ++-- examples/pn53x-sam.c | 6 ++-- examples/pn53x-tamashell.c | 6 ++-- include/nfc/nfc-types.h | 2 ++ include/nfc/nfc.h | 8 ++--- libnfc/nfc.c | 14 +++++---- test/test_access_storm.c | 10 +++--- test/test_dep_active.c | 10 +++--- test/test_dep_passive.c | 10 +++--- test/test_device_modes_as_dep.c | 10 +++--- test/test_register_access.c | 8 ++--- test/test_register_endianness.c | 8 ++--- utils/nfc-emulate-forum-tag4.c | 6 ++-- utils/nfc-list.c | 14 ++++----- utils/nfc-mfclassic.c | 8 ++--- utils/nfc-mfsetuid.c | 8 ++--- utils/nfc-mfultralight.c | 10 +++--- utils/nfc-probe.c | 8 ++--- utils/nfc-read-forum-tag3.c | 6 ++-- utils/nfc-relay-picc.c | 48 ++++++++++++++--------------- 29 files changed, 142 insertions(+), 138 deletions(-) diff --git a/examples/doc/quick_start_example1.c b/examples/doc/quick_start_example1.c index 3215caf..9c405aa 100644 --- a/examples/doc/quick_start_example1.c +++ b/examples/doc/quick_start_example1.c @@ -14,14 +14,14 @@ main (int argc, const char *argv[]) nfc_device *pnd; nfc_target nt; - nfc_init(); + nfc_init (NULL); // Display libnfc version const char *acLibnfcVersion = nfc_version (); printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); // Open, using the first available NFC device - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); if (pnd == NULL) { ERR ("%s", "Unable to open NFC device."); @@ -55,6 +55,6 @@ main (int argc, const char *argv[]) } // Close NFC device nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); return EXIT_SUCCESS; } diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index ec5dd17..87aa1c4 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -148,10 +148,10 @@ main (int argc, char *argv[]) } } - nfc_init(); + nfc_init (NULL); // Try to open the NFC reader - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); if (!pnd) { printf ("Error opening NFC reader\n"); @@ -186,7 +186,7 @@ main (int argc, char *argv[]) if (!transmit_bits (abtReqa, 7)) { printf ("Error: No tag available\n"); nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); return 1; } memcpy (abtAtqa, abtRx, 2); @@ -316,6 +316,6 @@ main (int argc, char *argv[]) } nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); return 0; } diff --git a/examples/nfc-dep-initiator.c b/examples/nfc-dep-initiator.c index dc2d82f..272cdf0 100644 --- a/examples/nfc-dep-initiator.c +++ b/examples/nfc-dep-initiator.c @@ -72,9 +72,9 @@ main (int argc, const char *argv[]) return EXIT_FAILURE; } - nfc_init(); + nfc_init (NULL); - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); if (!pnd) { printf("Unable to open NFC device.\n"); return EXIT_FAILURE; @@ -110,6 +110,6 @@ main (int argc, const char *argv[]) error: nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); return EXIT_SUCCESS; } diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index 592b9e1..9786ead 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -66,16 +66,16 @@ main (int argc, const char *argv[]) uint8_t abtTx[] = "Hello Mars!"; #define MAX_DEVICE_COUNT 2 nfc_connstring connstrings[MAX_DEVICE_COUNT]; - size_t szDeviceFound = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); + size_t szDeviceFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); // Little hack to allow using nfc-dep-initiator & nfc-dep-target from // the same machine: if there is more than one readers opened // nfc-dep-target will open the second reader // (we hope they're always detected in the same order) - nfc_init (); + nfc_init (NULL); if (szDeviceFound == 1) { - pnd = nfc_open (connstrings[0]); + pnd = nfc_open (NULL, connstrings[0]); } else if (szDeviceFound > 1) { - pnd = nfc_open (connstrings[1]); + pnd = nfc_open (NULL, connstrings[1]); } else { printf("No device found.\n"); return EXIT_FAILURE; @@ -141,6 +141,6 @@ main (int argc, const char *argv[]) error: nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); return EXIT_SUCCESS; } diff --git a/examples/nfc-emulate-forum-tag2.c b/examples/nfc-emulate-forum-tag2.c index 8af29a6..2e8ef6e 100644 --- a/examples/nfc-emulate-forum-tag2.c +++ b/examples/nfc-emulate-forum-tag2.c @@ -182,8 +182,8 @@ main(int argc, char *argv[]) }; signal (SIGINT, stop_emulation); - nfc_init (); - pnd = nfc_open (NULL); + nfc_init (NULL); + pnd = nfc_open (NULL, NULL); if (pnd == NULL) { ERR("Unable to open NFC device"); @@ -198,7 +198,7 @@ main(int argc, char *argv[]) } nfc_close(pnd); - nfc_exit (); + nfc_exit (NULL); exit (EXIT_SUCCESS); @@ -206,6 +206,6 @@ error: if (pnd) { nfc_perror (pnd, argv[0]); nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); } } diff --git a/examples/nfc-emulate-tag.c b/examples/nfc-emulate-tag.c index 0e7a4c3..7e236fe 100644 --- a/examples/nfc-emulate-tag.c +++ b/examples/nfc-emulate-tag.c @@ -67,7 +67,7 @@ intr_hdlr (void) if (pnd != NULL) { nfc_close(pnd); } - nfc_exit (); + nfc_exit (NULL); exit (EXIT_FAILURE); } @@ -180,10 +180,10 @@ main (int argc, char *argv[]) signal (SIGINT, (void (*)()) intr_hdlr); #endif - nfc_init(); + nfc_init (NULL); // Try to open the NFC reader - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); // Display libnfc version acLibnfcVersion = nfc_version (); @@ -269,7 +269,7 @@ main (int argc, char *argv[]) } nfc_close(pnd); - nfc_exit (); + nfc_exit (NULL); exit (EXIT_SUCCESS); } diff --git a/examples/nfc-emulate-uid.c b/examples/nfc-emulate-uid.c index df14eb2..cfa2b4f 100644 --- a/examples/nfc-emulate-uid.c +++ b/examples/nfc-emulate-uid.c @@ -125,10 +125,10 @@ main (int argc, char *argv[]) signal (SIGINT, (void (*)()) intr_hdlr); #endif - nfc_init (); + nfc_init (NULL); // Try to open the NFC device - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); if (pnd == NULL) { printf ("Unable to open NFC device\n"); @@ -219,11 +219,11 @@ main (int argc, char *argv[]) } } nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); exit (EXIT_SUCCESS); error: nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); exit (EXIT_FAILURE); } diff --git a/examples/nfc-poll.c b/examples/nfc-poll.c index 2cfc115..e1873a4 100644 --- a/examples/nfc-poll.c +++ b/examples/nfc-poll.c @@ -103,9 +103,9 @@ main (int argc, const char *argv[]) nfc_target nt; int res = 0; - nfc_init (); + nfc_init (NULL); - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); if (pnd == NULL) { ERR ("%s", "Unable to open NFC device."); @@ -122,7 +122,7 @@ main (int argc, const char *argv[]) if ((res = nfc_initiator_poll_target (pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt)) < 0) { nfc_perror (pnd, "nfc_initiator_poll_target"); nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); exit (EXIT_FAILURE); } @@ -132,6 +132,6 @@ main (int argc, const char *argv[]) printf ("No target found.\n"); } nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); exit (EXIT_SUCCESS); } diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index 580b8d0..6a95c3f 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -109,17 +109,17 @@ main (int argc, char *argv[]) nfc_connstring connstrings[MAX_DEVICE_COUNT]; // List available devices - size_t szFound = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); + size_t szFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); if (szFound < 2) { ERR ("%zd device found but two opened devices are needed to relay NFC.", szFound); return EXIT_FAILURE; } - nfc_init (); + nfc_init (NULL); // Try to open the NFC emulator device - pndTag = nfc_open (connstrings[0]); + pndTag = nfc_open (NULL, connstrings[0]); if (pndTag == NULL) { printf ("Error opening NFC emulator device\n"); return EXIT_FAILURE; @@ -151,7 +151,7 @@ main (int argc, char *argv[]) if ((szReaderRxBits = nfc_target_init (pndTag, &nt, abtReaderRx, sizeof (abtReaderRx), 0)) < 0) { ERR ("%s", "Initialization of NFC emulator failed"); nfc_close (pndTag); - nfc_exit (); + nfc_exit (NULL); return EXIT_FAILURE; } printf ("%s", "Configuring emulator settings..."); @@ -163,7 +163,7 @@ main (int argc, char *argv[]) printf ("%s", "Done, emulated tag is initialized"); // Try to open the NFC reader - pndReader = nfc_open (connstrings[1]); + pndReader = nfc_open (NULL, connstrings[1]); printf ("NFC reader device: %s opened", nfc_device_get_name (pndReader)); printf ("%s", "Configuring NFC reader settings..."); @@ -221,6 +221,6 @@ main (int argc, char *argv[]) nfc_close (pndTag); nfc_close (pndReader); - nfc_exit (); + nfc_exit (NULL); exit (EXIT_SUCCESS); } diff --git a/examples/pn53x-diagnose.c b/examples/pn53x-diagnose.c index 625bab9..6743eaa 100644 --- a/examples/pn53x-diagnose.c +++ b/examples/pn53x-diagnose.c @@ -68,21 +68,21 @@ main (int argc, const char *argv[]) errx (1, "usage: %s", argv[0]); } - nfc_init(); + nfc_init (NULL); // Display libnfc version acLibnfcVersion = nfc_version (); printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); nfc_connstring connstrings[MAX_DEVICE_COUNT]; - size_t szFound = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); + size_t szFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); if (szFound == 0) { printf ("No NFC device found.\n"); } for (i = 0; i < szFound; i++) { - pnd = nfc_open (connstrings[i]); + pnd = nfc_open (NULL, connstrings[i]); if (pnd == NULL) { ERR ("%s", "Unable to open NFC device."); diff --git a/examples/pn53x-sam.c b/examples/pn53x-sam.c index 8de030e..10ef075 100644 --- a/examples/pn53x-sam.c +++ b/examples/pn53x-sam.c @@ -77,14 +77,14 @@ main (int argc, const char *argv[]) (void) argc; (void) argv; - nfc_init (); + nfc_init (NULL); // Display libnfc version const char *acLibnfcVersion = nfc_version (); printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); // Open using the first available NFC device - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); if (pnd == NULL) { ERR ("%s", "Unable to open NFC device."); @@ -193,7 +193,7 @@ main (int argc, const char *argv[]) // Close NFC device nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); exit (EXIT_SUCCESS); } diff --git a/examples/pn53x-tamashell.c b/examples/pn53x-tamashell.c index bcd6341..4ceee23 100644 --- a/examples/pn53x-tamashell.c +++ b/examples/pn53x-tamashell.c @@ -86,10 +86,10 @@ int main(int argc, const char* argv[]) } } - nfc_init (); + nfc_init (NULL); // Try to open the NFC reader - pnd = nfc_open(NULL); + pnd = nfc_open(NULL, NULL); if (pnd == NULL) { ERR ("%s", "Unable to open NFC device."); @@ -200,6 +200,6 @@ int main(int argc, const char* argv[]) fclose(input); } nfc_close(pnd); - nfc_exit (); + nfc_exit (NULL); return 1; } diff --git a/include/nfc/nfc-types.h b/include/nfc/nfc-types.h index 81a1270..b0c001c 100644 --- a/include/nfc/nfc-types.h +++ b/include/nfc/nfc-types.h @@ -32,6 +32,8 @@ # include # include +typedef void *nfc_context; + /** * NFC device */ diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index cbb17a8..8c2b1b7 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -63,15 +63,15 @@ extern "C" { # endif // __cplusplus /* Library initialization/deinitialization */ - NFC_EXPORT void nfc_init(); - NFC_EXPORT void nfc_exit(); + NFC_EXPORT void nfc_init(nfc_context *context); + NFC_EXPORT void nfc_exit(nfc_context *context); /* NFC Device/Hardware manipulation */ NFC_EXPORT bool nfc_get_default_device (nfc_connstring *connstring); - NFC_EXPORT nfc_device *nfc_open (const nfc_connstring connstring); + NFC_EXPORT nfc_device *nfc_open (nfc_context *context, const nfc_connstring connstring); NFC_EXPORT void nfc_close (nfc_device *pnd); NFC_EXPORT int nfc_abort_command (nfc_device *pnd); - NFC_EXPORT size_t nfc_list_devices (nfc_connstring connstrings[], size_t connstrings_len); + NFC_EXPORT size_t nfc_list_devices (nfc_context *context, nfc_connstring connstrings[], size_t connstrings_len); NFC_EXPORT int nfc_idle (nfc_device *pnd); /* NFC initiator: act as "reader" */ diff --git a/libnfc/nfc.c b/libnfc/nfc.c index bd4ec9e..d39c59e 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -64,19 +64,21 @@ const struct nfc_driver *nfc_drivers[] = { /** * @brief Initialize libnfc. * This function must be called before calling any other libnfc function + * @param context Optional output location for context pointer */ void -nfc_init() +nfc_init(nfc_context *context) { log_init (); } /** * @brief Deinitialize libnfc. - * Should be called after closing all open devices and before your application terminates. + * Should be called after closing all open devices and before your application terminates. + *@param context The context to deinitialize */ void -nfc_exit() +nfc_exit(nfc_context *context) { log_fini (); } @@ -102,7 +104,7 @@ nfc_get_default_device (nfc_connstring *connstring) if (NULL == env_default_connstring) { // LIBNFC_DEFAULT_DEVICE is not set, we fallback on probing for the first available device nfc_connstring listed_cs[1]; - size_t szDeviceFound = nfc_list_devices (listed_cs, 1); + size_t szDeviceFound = nfc_list_devices (NULL, listed_cs, 1); if (szDeviceFound) { strncpy (*connstring, listed_cs[0], sizeof(nfc_connstring)); } else { @@ -131,7 +133,7 @@ nfc_get_default_device (nfc_connstring *connstring) * optionally followed by manual tuning of the parameters if the default parameters are not suiting your goals. */ nfc_device * -nfc_open (const nfc_connstring connstring) +nfc_open (nfc_context *context, const nfc_connstring connstring) { nfc_device *pnd = NULL; @@ -200,7 +202,7 @@ nfc_close (nfc_device *pnd) * */ size_t -nfc_list_devices (nfc_connstring connstrings[] , size_t szDevices) +nfc_list_devices (nfc_context *context, nfc_connstring connstrings[] , size_t szDevices) { size_t szN; size_t szDeviceFound = 0; diff --git a/test/test_access_storm.c b/test/test_access_storm.c index 6609f3f..558f34c 100644 --- a/test/test_access_storm.c +++ b/test/test_access_storm.c @@ -17,23 +17,23 @@ test_access_storm (void) nfc_connstring connstrings[MAX_DEVICE_COUNT]; int res = 0; - nfc_init (); + nfc_init (NULL); - size_t ref_device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); + size_t ref_device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); if (!ref_device_count) cut_omit ("No NFC device found"); while (n) { size_t i; - size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); + size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count")); for (i = 0; i < device_count; i++) { nfc_device *device; nfc_target ant[MAX_TARGET_COUNT]; - device = nfc_open (connstrings[i]); + device = nfc_open (NULL, connstrings[i]); cut_assert_not_null (device, cut_message ("nfc_open")); res = nfc_initiator_init(device); @@ -51,5 +51,5 @@ test_access_storm (void) n--; } - nfc_exit (); + nfc_exit (NULL); } diff --git a/test/test_dep_active.c b/test/test_dep_active.c index c8eb2a5..de0692d 100644 --- a/test/test_dep_active.c +++ b/test/test_dep_active.c @@ -27,13 +27,13 @@ abort_test_by_keypress (int sig) void cut_setup (void) { - size_t n = nfc_list_devices (connstrings, 2); + size_t n = nfc_list_devices (NULL, connstrings, 2); if (n < 2) { cut_omit ("At least two NFC devices must be plugged-in to run this test"); } - nfc_init (); - devices[TARGET] = nfc_open (connstrings[TARGET]); - devices[INITIATOR] = nfc_open (connstrings[INITIATOR]); + nfc_init (NULL); + devices[TARGET] = nfc_open (NULL, connstrings[TARGET]); + devices[INITIATOR] = nfc_open (NULL, connstrings[INITIATOR]); signal (SIGINT, abort_test_by_keypress); } @@ -43,7 +43,7 @@ cut_teardown (void) { nfc_close (devices[TARGET]); nfc_close (devices[INITIATOR]); - nfc_exit (); + nfc_exit (NULL); } struct thread_data { diff --git a/test/test_dep_passive.c b/test/test_dep_passive.c index ff0ffb0..e792f15 100644 --- a/test/test_dep_passive.c +++ b/test/test_dep_passive.c @@ -26,14 +26,14 @@ abort_test_by_keypress (int sig) void cut_setup (void) { - size_t n = nfc_list_devices (connstrings, 2); + size_t n = nfc_list_devices (NULL, connstrings, 2); if (n < 2) { cut_omit ("At least two NFC devices must be plugged-in to run this test"); } - nfc_init (); - devices[TARGET] = nfc_open (connstrings[TARGET]); - devices[INITIATOR] = nfc_open (connstrings[INITIATOR]); + nfc_init (NULL); + devices[TARGET] = nfc_open (NULL, connstrings[TARGET]); + devices[INITIATOR] = nfc_open (NULL, connstrings[INITIATOR]); signal (SIGINT, abort_test_by_keypress); } @@ -43,7 +43,7 @@ cut_teardown (void) { nfc_close (devices[TARGET]); nfc_close (devices[INITIATOR]); - nfc_exit (); + nfc_exit (NULL); } struct thread_data { diff --git a/test/test_device_modes_as_dep.c b/test/test_device_modes_as_dep.c index cd45661..138b405 100644 --- a/test/test_device_modes_as_dep.c +++ b/test/test_device_modes_as_dep.c @@ -24,14 +24,14 @@ abort_test_by_keypress (int sig) void cut_setup (void) { - size_t n = nfc_list_devices (connstrings, 2); + size_t n = nfc_list_devices (NULL, connstrings, 2); if (n < 2) { cut_omit ("At least two NFC devices must be plugged-in to run this test"); } - nfc_init (); - second_device = nfc_open (connstrings[0]); - first_device = nfc_open (connstrings[1]); + nfc_init (NULL); + second_device = nfc_open (NULL, connstrings[0]); + first_device = nfc_open (NULL, connstrings[1]); signal (SIGINT, abort_test_by_keypress); } @@ -41,7 +41,7 @@ cut_teardown (void) { nfc_close (second_device); nfc_close (first_device); - nfc_exit (); + nfc_exit (NULL); } struct thread_data { diff --git a/test/test_register_access.c b/test/test_register_access.c index 4839437..f6abfef 100644 --- a/test/test_register_access.c +++ b/test/test_register_access.c @@ -12,15 +12,15 @@ test_register_endianness (void) nfc_connstring connstrings[MAX_DEVICE_COUNT]; int res = 0; - nfc_init (); + nfc_init (NULL); - size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); + size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); if (!device_count) cut_omit ("No NFC device found"); nfc_device *device; - device = nfc_open (connstrings[0]); + device = nfc_open (NULL, connstrings[0]); cut_assert_not_null (device, cut_message ("nfc_open")); uint8_t value; @@ -44,5 +44,5 @@ test_register_endianness (void) cut_assert_equal_uint (0x55, value, cut_message ("check register value")); nfc_close (device); - nfc_exit (); + nfc_exit (NULL); } diff --git a/test/test_register_endianness.c b/test/test_register_endianness.c index a6b15c4..09d622c 100644 --- a/test/test_register_endianness.c +++ b/test/test_register_endianness.c @@ -13,15 +13,15 @@ test_register_endianness (void) nfc_connstring connstrings[MAX_DEVICE_COUNT]; int res = 0; - nfc_init (); + nfc_init (NULL); - size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); + size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); if (!device_count) cut_omit ("No NFC device found"); nfc_device *device; - device = nfc_open (connstrings[0]); + device = nfc_open (NULL, connstrings[0]); cut_assert_not_null (device, cut_message ("nfc_open")); uint8_t value; @@ -35,5 +35,5 @@ test_register_endianness (void) cut_assert_equal_int (0, res, cut_message ("read register 0xFFF0")); nfc_close (device); - nfc_exit (); + nfc_exit (NULL); } diff --git a/utils/nfc-emulate-forum-tag4.c b/utils/nfc-emulate-forum-tag4.c index 65ff665..68edf4a 100644 --- a/utils/nfc-emulate-forum-tag4.c +++ b/utils/nfc-emulate-forum-tag4.c @@ -346,10 +346,10 @@ main (int argc, char *argv[]) } } - nfc_init (); + nfc_init (NULL); // Try to open the NFC reader - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); if (pnd == NULL) { ERR("Unable to open NFC device"); @@ -373,6 +373,6 @@ main (int argc, char *argv[]) } } - nfc_exit (); + nfc_exit (NULL); exit (EXIT_SUCCESS); } diff --git a/utils/nfc-list.c b/utils/nfc-list.c index 6afd126..d9cf393 100644 --- a/utils/nfc-list.c +++ b/utils/nfc-list.c @@ -75,7 +75,7 @@ main (int argc, const char *argv[]) bool verbose = false; int res = 0; - nfc_init (); + nfc_init (NULL); // Display libnfc version acLibnfcVersion = nfc_version (); @@ -97,7 +97,7 @@ main (int argc, const char *argv[]) /* Lazy way to open an NFC device */ #if 0 - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); #endif /* If specific device is wanted, i.e. an ARYGON device on /dev/ttyUSB0 */ @@ -106,7 +106,7 @@ main (int argc, const char *argv[]) ndd.pcDriver = "ARYGON"; ndd.pcPort = "/dev/ttyUSB0"; ndd.uiSpeed = 115200; - pnd = nfc_open (&ndd); + pnd = nfc_open (NULL, &ndd); #endif /* If specific device is wanted, i.e. a SCL3711 on USB */ @@ -114,10 +114,10 @@ main (int argc, const char *argv[]) nfc_device_desc_t ndd; ndd.pcDriver = "PN533_USB"; strcpy(ndd.acDevice, "SCM Micro / SCL3711-NFC&RW"); - pnd = nfc_open (&ndd); + pnd = nfc_open (NULL, &ndd); #endif nfc_connstring connstrings[MAX_DEVICE_COUNT]; - size_t szDeviceFound = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); + size_t szDeviceFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); if (szDeviceFound == 0) { printf ("No NFC device found.\n"); @@ -125,7 +125,7 @@ main (int argc, const char *argv[]) for (i = 0; i < szDeviceFound; i++) { nfc_target ant[MAX_TARGET_COUNT]; - pnd = nfc_open (connstrings[i]); + pnd = nfc_open (NULL, connstrings[i]); if (pnd == NULL) { ERR ("%s", "Unable to open NFC device."); @@ -252,6 +252,6 @@ main (int argc, const char *argv[]) nfc_close (pnd); } - nfc_exit (); + nfc_exit (NULL); return 0; } diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index 450ae6a..8ba1b1d 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -537,10 +537,10 @@ main (int argc, const char *argv[]) } // printf("Successfully opened required files\n"); - nfc_init (); + nfc_init (NULL); // Try to open the NFC reader - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); if (pnd == NULL) { printf ("Error opening NFC reader\n"); exit (EXIT_FAILURE); @@ -565,7 +565,7 @@ main (int argc, const char *argv[]) if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) { printf ("Error: no tag was found\n"); nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); exit (EXIT_FAILURE); } // Test if we are dealing with a MIFARE compatible tag @@ -665,6 +665,6 @@ main (int argc, const char *argv[]) } }; - nfc_exit (); + nfc_exit (NULL); exit (EXIT_SUCCESS); } diff --git a/utils/nfc-mfsetuid.c b/utils/nfc-mfsetuid.c index b2cbf3f..64ea4d2 100644 --- a/utils/nfc-mfsetuid.c +++ b/utils/nfc-mfsetuid.c @@ -177,10 +177,10 @@ main (int argc, char *argv[]) } } - nfc_init (); + nfc_init (NULL); // Try to open the NFC reader - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); if (!pnd) { printf ("Error opening NFC reader\n"); @@ -215,7 +215,7 @@ main (int argc, char *argv[]) if (!transmit_bits (abtReqa, 7)) { printf ("Error: No tag available\n"); nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); return 1; } memcpy (abtAtqa, abtRx, 2); @@ -354,6 +354,6 @@ main (int argc, char *argv[]) nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); return 0; } diff --git a/utils/nfc-mfultralight.c b/utils/nfc-mfultralight.c index 515001e..ba7394c 100644 --- a/utils/nfc-mfultralight.c +++ b/utils/nfc-mfultralight.c @@ -204,10 +204,10 @@ main (int argc, const char *argv[]) } DBG ("Successfully opened the dump file\n"); - nfc_init (); + nfc_init (NULL); // Try to open the NFC device - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); if (pnd == NULL) { ERR ("Error opening NFC device\n"); return 1; @@ -230,7 +230,7 @@ main (int argc, const char *argv[]) if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) { ERR ("no tag was found\n"); nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); return 1; } // Test if we are dealing with a MIFARE compatible tag @@ -238,7 +238,7 @@ main (int argc, const char *argv[]) if (nt.nti.nai.abtAtqa[1] != 0x44) { ERR ("tag is not a MIFARE Ultralight card\n"); nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); return EXIT_FAILURE; } // Get the info from the current tag @@ -270,6 +270,6 @@ main (int argc, const char *argv[]) } nfc_close (pnd); - nfc_exit (); + nfc_exit (NULL); return EXIT_SUCCESS; } diff --git a/utils/nfc-probe.c b/utils/nfc-probe.c index 1f751b4..9536398 100644 --- a/utils/nfc-probe.c +++ b/utils/nfc-probe.c @@ -74,7 +74,7 @@ main (int argc, const char *argv[]) size_t i; bool verbose = false; - nfc_init (); + nfc_init (NULL); // Display libnfc version acLibnfcVersion = nfc_version (); @@ -95,7 +95,7 @@ main (int argc, const char *argv[]) #endif nfc_connstring connstrings[MAX_DEVICE_COUNT]; - size_t szDeviceFound = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); + size_t szDeviceFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); if (szDeviceFound == 0) { printf ("No NFC device found.\n"); @@ -103,13 +103,13 @@ main (int argc, const char *argv[]) printf ("%d NFC device(s) found:\n", szDeviceFound); for (i = 0; i < szDeviceFound; i++) { - pnd = nfc_open (connstrings[i]); + pnd = nfc_open (NULL, connstrings[i]); if (pnd != NULL) { printf ("- %s:\n %s\n", nfc_device_get_name (pnd), nfc_device_get_connstring (pnd)); } nfc_close (pnd); } - nfc_exit (); + nfc_exit (NULL); return 0; } diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index c91b7a7..cc25a14 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -195,9 +195,9 @@ main(int argc, char *argv[]) } } - nfc_init (); + nfc_init (NULL); - pnd = nfc_open (NULL); + pnd = nfc_open (NULL, NULL); if (pnd == NULL) { ERR("Unable to open NFC device"); @@ -317,6 +317,6 @@ error: if (pnd) { nfc_close (pnd); } - nfc_exit (); + nfc_exit (NULL); exit (error); } diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index ace9f74..b74d371 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -190,11 +190,11 @@ main (int argc, char *argv[]) signal (SIGINT, (void (*)()) intr_hdlr); #endif - nfc_init (); + nfc_init (NULL); nfc_connstring connstrings[MAX_DEVICE_COUNT]; // List available devices - size_t szFound = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); + size_t szFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT); if (initiator_only_mode || target_only_mode) { if (szFound < 1) { @@ -218,9 +218,9 @@ main (int argc, char *argv[]) // if there is more than one readers opened we open the second reader // (we hope they're always detected in the same order) if (szFound == 1) { - pndInitiator = nfc_open (connstrings[0]); + pndInitiator = nfc_open (NULL, connstrings[0]); } else { - pndInitiator = nfc_open (connstrings[1]); + pndInitiator = nfc_open (NULL, connstrings[1]); } if (!pndInitiator) { @@ -233,7 +233,7 @@ main (int argc, char *argv[]) if (nfc_initiator_init (pndInitiator) < 0) { printf ("Error: fail initializing initiator\n"); nfc_close (pndInitiator); - nfc_exit (); + nfc_exit (NULL); exit (EXIT_FAILURE); } @@ -245,7 +245,7 @@ main (int argc, char *argv[]) if (nfc_initiator_select_passive_target (pndInitiator, nm, NULL, 0, &ntRealTarget) < 0) { printf ("Error: no tag was found\n"); nfc_close (pndInitiator); - nfc_exit (); + nfc_exit (NULL); exit (EXIT_FAILURE); } @@ -255,25 +255,25 @@ main (int argc, char *argv[]) if (print_hex_fd4(ntRealTarget.nti.nai.abtUid, ntRealTarget.nti.nai.szUidLen, "UID") != EXIT_SUCCESS) { fprintf (stderr, "Error while printing UID to FD4\n"); nfc_close (pndInitiator); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } if (print_hex_fd4(ntRealTarget.nti.nai.abtAtqa, 2, "ATQA") != EXIT_SUCCESS) { fprintf (stderr, "Error while printing ATQA to FD4\n"); nfc_close (pndInitiator); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } if (print_hex_fd4(&(ntRealTarget.nti.nai.btSak), 1, "SAK") != EXIT_SUCCESS) { fprintf (stderr, "Error while printing SAK to FD4\n"); nfc_close (pndInitiator); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } if (print_hex_fd4(ntRealTarget.nti.nai.abtAts, ntRealTarget.nti.nai.szAtsLen, "ATS") != EXIT_SUCCESS) { fprintf (stderr, "Error while printing ATS to FD4\n"); nfc_close (pndInitiator); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } } @@ -297,7 +297,7 @@ main (int argc, char *argv[]) if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtUid, &(ntEmulatedTarget.nti.nai.szUidLen), "UID") != EXIT_SUCCESS) { fprintf (stderr, "Error while scanning UID from FD3\n"); nfc_close (pndInitiator); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAtqa, &foo, "ATQA") != EXIT_SUCCESS) { @@ -308,13 +308,13 @@ main (int argc, char *argv[]) if (scan_hex_fd3(&(ntEmulatedTarget.nti.nai.btSak), &foo, "SAK") != EXIT_SUCCESS) { fprintf (stderr, "Error while scanning SAK from FD3\n"); nfc_close (pndInitiator); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAts, &(ntEmulatedTarget.nti.nai.szAtsLen), "ATS") != EXIT_SUCCESS) { fprintf (stderr, "Error while scanning ATS from FD3\n"); nfc_close (pndInitiator); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } } else { @@ -353,13 +353,13 @@ main (int argc, char *argv[]) print_nfc_iso14443a_info (ntEmulatedTarget.nti.nai, false); // Try to open the NFC emulator device - pndTarget = nfc_open (connstrings[0]); + pndTarget = nfc_open (NULL, connstrings[0]); if (pndTarget == NULL) { printf ("Error opening NFC emulator device\n"); if (!target_only_mode) { nfc_close (pndInitiator); } - nfc_exit (); + nfc_exit (NULL); return EXIT_FAILURE; } @@ -372,7 +372,7 @@ main (int argc, char *argv[]) nfc_close (pndInitiator); } nfc_close (pndTarget); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } printf ("%s\n", "Done, relaying frames now!"); @@ -390,7 +390,7 @@ main (int argc, char *argv[]) nfc_close (pndInitiator); } nfc_close (pndTarget); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } szCapduLen = (size_t) res; @@ -398,7 +398,7 @@ main (int argc, char *argv[]) if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) { fprintf (stderr, "Error while printing C-APDU to FD4\n"); nfc_close (pndTarget); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } } @@ -406,7 +406,7 @@ main (int argc, char *argv[]) if (scan_hex_fd3(abtCapdu, &szCapduLen, "C-APDU") != EXIT_SUCCESS) { fprintf (stderr, "Error while scanning C-APDU from FD3\n"); nfc_close (pndInitiator); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } } @@ -424,7 +424,7 @@ main (int argc, char *argv[]) if (scan_hex_fd3(abtRapdu, &szRapduLen, "R-APDU") != EXIT_SUCCESS) { fprintf (stderr, "Error while scanning R-APDU from FD3\n"); nfc_close (pndTarget); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } ret = true; @@ -451,16 +451,16 @@ main (int argc, char *argv[]) } if (!initiator_only_mode) { nfc_close (pndTarget); - nfc_exit (); + nfc_exit (NULL); } - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } } else { if (print_hex_fd4(abtRapdu, szRapduLen, "R-APDU") != EXIT_SUCCESS) { fprintf (stderr, "Error while printing R-APDU to FD4\n"); nfc_close (pndInitiator); - nfc_exit (); + nfc_exit (NULL); exit(EXIT_FAILURE); } } @@ -473,7 +473,7 @@ main (int argc, char *argv[]) if (!initiator_only_mode) { nfc_close (pndTarget); } - nfc_exit (); + nfc_exit (NULL); exit (EXIT_SUCCESS); }