diff --git a/examples/doc/quick_start_example1.c b/examples/doc/quick_start_example1.c index 18b35e6..413e055 100644 --- a/examples/doc/quick_start_example1.c +++ b/examples/doc/quick_start_example1.c @@ -13,12 +13,14 @@ main (int argc, const char *argv[]) { nfc_device *pnd; nfc_target nt; + + nfc_init(); // Display libnfc version const char *acLibnfcVersion = nfc_version (); printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); - // Ope, using the first available NFC device + // Open, using the first available NFC device pnd = nfc_open (NULL); if (pnd == NULL) { diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index c48517c..fc9d62d 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -148,6 +148,8 @@ main (int argc, char *argv[]) } } + nfc_init(); + // Try to open the NFC reader pnd = nfc_open (NULL); diff --git a/examples/nfc-dep-initiator.c b/examples/nfc-dep-initiator.c index 94adf8a..3c54877 100644 --- a/examples/nfc-dep-initiator.c +++ b/examples/nfc-dep-initiator.c @@ -71,6 +71,8 @@ main (int argc, const char *argv[]) printf ("Usage: %s\n", argv[0]); return EXIT_FAILURE; } + + nfc_init(); pnd = nfc_open (NULL); if (!pnd) { diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index fa1203c..4ca6636 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -71,6 +71,7 @@ main (int argc, const char *argv[]) // 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 (); if (szDeviceFound == 1) { pnd = nfc_open (connstrings[0]); } else if (szDeviceFound > 1) { diff --git a/examples/nfc-emulate-forum-tag2.c b/examples/nfc-emulate-forum-tag2.c index 19fe7c7..ea0c9d0 100644 --- a/examples/nfc-emulate-forum-tag2.c +++ b/examples/nfc-emulate-forum-tag2.c @@ -182,6 +182,7 @@ main(int argc, char *argv[]) }; signal (SIGINT, stop_emulation); + nfc_init (); pnd = nfc_open (NULL); if (pnd == NULL) { diff --git a/examples/nfc-emulate-tag.c b/examples/nfc-emulate-tag.c index 93dd0b6..509dff0 100644 --- a/examples/nfc-emulate-tag.c +++ b/examples/nfc-emulate-tag.c @@ -179,6 +179,8 @@ main (int argc, char *argv[]) signal (SIGINT, (void (*)()) intr_hdlr); #endif + nfc_init(); + // Try to open the NFC reader pnd = nfc_open (NULL); diff --git a/examples/nfc-emulate-uid.c b/examples/nfc-emulate-uid.c index d2854cb..5e28ca7 100644 --- a/examples/nfc-emulate-uid.c +++ b/examples/nfc-emulate-uid.c @@ -125,6 +125,8 @@ main (int argc, char *argv[]) signal (SIGINT, (void (*)()) intr_hdlr); #endif + nfc_init (); + // Try to open the NFC device pnd = nfc_open (NULL); diff --git a/examples/nfc-poll.c b/examples/nfc-poll.c index d800a14..12894c3 100644 --- a/examples/nfc-poll.c +++ b/examples/nfc-poll.c @@ -102,6 +102,8 @@ main (int argc, const char *argv[]) nfc_target nt; int res = 0; + + nfc_init (); pnd = nfc_open (NULL); diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index 4fad476..a255977 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -115,6 +115,9 @@ main (int argc, char *argv[]) ERR ("%zd device found but two opened devices are needed to relay NFC.", szFound); return EXIT_FAILURE; } + + nfc_init (); + // Try to open the NFC emulator device pndTag = nfc_open (connstrings[0]); if (pndTag == NULL) { diff --git a/examples/pn53x-diagnose.c b/examples/pn53x-diagnose.c index 46f0532..625bab9 100644 --- a/examples/pn53x-diagnose.c +++ b/examples/pn53x-diagnose.c @@ -67,6 +67,9 @@ main (int argc, const char *argv[]) if (argc > 1) { errx (1, "usage: %s", argv[0]); } + + nfc_init(); + // Display libnfc version acLibnfcVersion = nfc_version (); printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); diff --git a/examples/pn53x-sam.c b/examples/pn53x-sam.c index 9745149..b584161 100644 --- a/examples/pn53x-sam.c +++ b/examples/pn53x-sam.c @@ -77,6 +77,8 @@ main (int argc, const char *argv[]) (void) argc; (void) argv; + nfc_init (); + // Display libnfc version const char *acLibnfcVersion = nfc_version (); printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); diff --git a/examples/pn53x-tamashell.c b/examples/pn53x-tamashell.c index 7d23100..b2ed7ca 100644 --- a/examples/pn53x-tamashell.c +++ b/examples/pn53x-tamashell.c @@ -86,6 +86,8 @@ int main(int argc, const char* argv[]) } } + nfc_init (); + // Try to open the NFC reader pnd = nfc_open(NULL); diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 5baf7dd..47a411a 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -63,7 +63,7 @@ const struct nfc_driver *nfc_drivers[] = { /** * @brief Initialize libnfc. - * + * This function must be called before calling any other libnfc function */ void nfc_init() @@ -75,7 +75,7 @@ nfc_init() * @brief Deinitialize libnfc. * */ -void +void nfc_exit() { log_fini (); @@ -133,7 +133,6 @@ nfc_get_default_device (nfc_connstring *connstring) nfc_device * nfc_open (const nfc_connstring connstring) { - log_init (); nfc_device *pnd = NULL; nfc_connstring ncs; @@ -209,7 +208,6 @@ nfc_list_devices (nfc_connstring connstrings[] , size_t szDevices) const struct nfc_driver *ndr; const struct nfc_driver **pndr = nfc_drivers; - log_init (); while ((ndr = *pndr)) { szN = 0; if (ndr->probe (connstrings + (szDeviceFound), szDevices - (szDeviceFound), &szN)) { diff --git a/test/test_access_storm.c b/test/test_access_storm.c index e934cee..d373401 100644 --- a/test/test_access_storm.c +++ b/test/test_access_storm.c @@ -17,6 +17,8 @@ test_access_storm (void) nfc_connstring connstrings[MAX_DEVICE_COUNT]; int res = 0; + nfc_init (); + size_t ref_device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); if (!ref_device_count) cut_omit ("No NFC device found"); diff --git a/test/test_dep_active.c b/test/test_dep_active.c index 58dda2c..69f3fb3 100644 --- a/test/test_dep_active.c +++ b/test/test_dep_active.c @@ -31,7 +31,7 @@ cut_setup (void) 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]); diff --git a/test/test_dep_passive.c b/test/test_dep_passive.c index fb8cae6..93a1491 100644 --- a/test/test_dep_passive.c +++ b/test/test_dep_passive.c @@ -30,7 +30,8 @@ cut_setup (void) 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]); diff --git a/test/test_device_modes_as_dep.c b/test/test_device_modes_as_dep.c index 04e1c48..0b64bfb 100644 --- a/test/test_device_modes_as_dep.c +++ b/test/test_device_modes_as_dep.c @@ -29,6 +29,7 @@ cut_setup (void) 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]); diff --git a/test/test_register_access.c b/test/test_register_access.c index d073cf9..a126815 100644 --- a/test/test_register_access.c +++ b/test/test_register_access.c @@ -11,6 +11,8 @@ test_register_endianness (void) { nfc_connstring connstrings[MAX_DEVICE_COUNT]; int res = 0; + + nfc_init (); size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); if (!device_count) diff --git a/test/test_register_endianness.c b/test/test_register_endianness.c index ab3dd70..f0239af 100644 --- a/test/test_register_endianness.c +++ b/test/test_register_endianness.c @@ -12,6 +12,8 @@ test_register_endianness (void) { nfc_connstring connstrings[MAX_DEVICE_COUNT]; int res = 0; + + nfc_init (); size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); if (!device_count) diff --git a/utils/nfc-emulate-forum-tag4.c b/utils/nfc-emulate-forum-tag4.c index 403bbd1..d2794d6 100644 --- a/utils/nfc-emulate-forum-tag4.c +++ b/utils/nfc-emulate-forum-tag4.c @@ -345,6 +345,8 @@ main (int argc, char *argv[]) err (EXIT_FAILURE, "Can't load NDEF file '%s'", argv[1]); } } + + nfc_init (); // Try to open the NFC reader pnd = nfc_open (NULL); diff --git a/utils/nfc-list.c b/utils/nfc-list.c index 876c569..0515682 100644 --- a/utils/nfc-list.c +++ b/utils/nfc-list.c @@ -75,6 +75,8 @@ main (int argc, const char *argv[]) bool verbose = false; int res = 0; + nfc_init (); + // Display libnfc version acLibnfcVersion = nfc_version (); printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index 686cd30..481b0de 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -537,6 +537,8 @@ main (int argc, const char *argv[]) } // printf("Successfully opened required files\n"); + nfc_init (); + // Try to open the NFC reader pnd = nfc_open (NULL); if (pnd == NULL) { diff --git a/utils/nfc-mfsetuid.c b/utils/nfc-mfsetuid.c index 470b821..8c8ed7f 100644 --- a/utils/nfc-mfsetuid.c +++ b/utils/nfc-mfsetuid.c @@ -177,6 +177,8 @@ main (int argc, char *argv[]) } } + nfc_init (); + // Try to open the NFC reader pnd = nfc_open (NULL); diff --git a/utils/nfc-mfultralight.c b/utils/nfc-mfultralight.c index 7959f31..dfc0000 100644 --- a/utils/nfc-mfultralight.c +++ b/utils/nfc-mfultralight.c @@ -204,6 +204,8 @@ main (int argc, const char *argv[]) } DBG ("Successfully opened the dump file\n"); + nfc_init (); + // Try to open the NFC device pnd = nfc_open (NULL); if (pnd == NULL) { diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index 8d42efe..8a80b28 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -194,6 +194,8 @@ main(int argc, char *argv[]) exit (EXIT_FAILURE); } } + + nfc_init (); pnd = nfc_open (NULL); diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index 44b32e6..0ef048d 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -190,6 +190,8 @@ main (int argc, char *argv[]) signal (SIGINT, (void (*)()) intr_hdlr); #endif + nfc_init (); + nfc_connstring connstrings[MAX_DEVICE_COUNT]; // List available devices size_t szFound = nfc_list_devices (connstrings, MAX_DEVICE_COUNT);