diff --git a/examples/doc/quick_start_example1.c b/examples/doc/quick_start_example1.c index 413e055..3215caf 100644 --- a/examples/doc/quick_start_example1.c +++ b/examples/doc/quick_start_example1.c @@ -55,5 +55,6 @@ main (int argc, const char *argv[]) } // Close NFC device nfc_close (pnd); + nfc_exit (); return EXIT_SUCCESS; } diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index fc9d62d..ec5dd17 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -186,6 +186,7 @@ main (int argc, char *argv[]) if (!transmit_bits (abtReqa, 7)) { printf ("Error: No tag available\n"); nfc_close (pnd); + nfc_exit (); return 1; } memcpy (abtAtqa, abtRx, 2); @@ -315,5 +316,6 @@ main (int argc, char *argv[]) } nfc_close (pnd); + nfc_exit (); return 0; } diff --git a/examples/nfc-dep-initiator.c b/examples/nfc-dep-initiator.c index 3c54877..dc2d82f 100644 --- a/examples/nfc-dep-initiator.c +++ b/examples/nfc-dep-initiator.c @@ -110,5 +110,6 @@ main (int argc, const char *argv[]) error: nfc_close (pnd); + nfc_exit (); return EXIT_SUCCESS; } diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index 4ca6636..592b9e1 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -141,5 +141,6 @@ main (int argc, const char *argv[]) error: nfc_close (pnd); + nfc_exit (); return EXIT_SUCCESS; } diff --git a/examples/nfc-emulate-forum-tag2.c b/examples/nfc-emulate-forum-tag2.c index ea0c9d0..8af29a6 100644 --- a/examples/nfc-emulate-forum-tag2.c +++ b/examples/nfc-emulate-forum-tag2.c @@ -198,6 +198,7 @@ main(int argc, char *argv[]) } nfc_close(pnd); + nfc_exit (); exit (EXIT_SUCCESS); @@ -205,5 +206,6 @@ error: if (pnd) { nfc_perror (pnd, argv[0]); nfc_close (pnd); + nfc_exit (); } } diff --git a/examples/nfc-emulate-tag.c b/examples/nfc-emulate-tag.c index 509dff0..0e7a4c3 100644 --- a/examples/nfc-emulate-tag.c +++ b/examples/nfc-emulate-tag.c @@ -65,8 +65,9 @@ intr_hdlr (void) { printf ("\nQuitting...\n"); if (pnd != NULL) { - nfc_close(pnd); + nfc_close(pnd); } + nfc_exit (); exit (EXIT_FAILURE); } @@ -268,6 +269,7 @@ main (int argc, char *argv[]) } nfc_close(pnd); + nfc_exit (); exit (EXIT_SUCCESS); } diff --git a/examples/nfc-emulate-uid.c b/examples/nfc-emulate-uid.c index 5e28ca7..df14eb2 100644 --- a/examples/nfc-emulate-uid.c +++ b/examples/nfc-emulate-uid.c @@ -219,9 +219,11 @@ main (int argc, char *argv[]) } } nfc_close (pnd); + nfc_exit (); exit (EXIT_SUCCESS); error: nfc_close (pnd); + nfc_exit (); exit (EXIT_FAILURE); } diff --git a/examples/nfc-poll.c b/examples/nfc-poll.c index 12894c3..2cfc115 100644 --- a/examples/nfc-poll.c +++ b/examples/nfc-poll.c @@ -122,6 +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 (); exit (EXIT_FAILURE); } @@ -131,5 +132,6 @@ main (int argc, const char *argv[]) printf ("No target found.\n"); } nfc_close (pnd); + nfc_exit (); exit (EXIT_SUCCESS); } diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index a255977..580b8d0 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -151,6 +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 (); return EXIT_FAILURE; } printf ("%s", "Configuring emulator settings..."); @@ -218,7 +219,8 @@ main (int argc, char *argv[]) } } - nfc_close (pndTag); + nfc_close (pndTag); nfc_close (pndReader); + nfc_exit (); exit (EXIT_SUCCESS); } diff --git a/examples/pn53x-sam.c b/examples/pn53x-sam.c index b584161..8de030e 100644 --- a/examples/pn53x-sam.c +++ b/examples/pn53x-sam.c @@ -193,6 +193,7 @@ main (int argc, const char *argv[]) // Close NFC device nfc_close (pnd); + nfc_exit (); exit (EXIT_SUCCESS); } diff --git a/examples/pn53x-tamashell.c b/examples/pn53x-tamashell.c index b2ed7ca..bcd6341 100644 --- a/examples/pn53x-tamashell.c +++ b/examples/pn53x-tamashell.c @@ -200,5 +200,6 @@ int main(int argc, const char* argv[]) fclose(input); } nfc_close(pnd); + nfc_exit (); return 1; } diff --git a/libnfc/nfc.c b/libnfc/nfc.c index 47a411a..c03d91c 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -73,7 +73,7 @@ nfc_init() /** * @brief Deinitialize libnfc. - * + * Should be called after closing all open devices and before your application terminates. */ void nfc_exit() @@ -188,8 +188,7 @@ nfc_close (nfc_device *pnd) nfc_idle (pnd); // Close, clean up and release the device pnd->driver->close (pnd); - - log_fini (); + } } diff --git a/test/test_access_storm.c b/test/test_access_storm.c index d373401..6609f3f 100644 --- a/test/test_access_storm.c +++ b/test/test_access_storm.c @@ -51,4 +51,5 @@ test_access_storm (void) n--; } + nfc_exit (); } diff --git a/test/test_dep_active.c b/test/test_dep_active.c index 69f3fb3..c8eb2a5 100644 --- a/test/test_dep_active.c +++ b/test/test_dep_active.c @@ -43,6 +43,7 @@ cut_teardown (void) { nfc_close (devices[TARGET]); nfc_close (devices[INITIATOR]); + nfc_exit (); } struct thread_data { diff --git a/test/test_dep_passive.c b/test/test_dep_passive.c index 93a1491..ff0ffb0 100644 --- a/test/test_dep_passive.c +++ b/test/test_dep_passive.c @@ -43,6 +43,7 @@ cut_teardown (void) { nfc_close (devices[TARGET]); nfc_close (devices[INITIATOR]); + nfc_exit (); } struct thread_data { diff --git a/test/test_device_modes_as_dep.c b/test/test_device_modes_as_dep.c index 0b64bfb..cd45661 100644 --- a/test/test_device_modes_as_dep.c +++ b/test/test_device_modes_as_dep.c @@ -41,6 +41,7 @@ cut_teardown (void) { nfc_close (second_device); nfc_close (first_device); + nfc_exit (); } struct thread_data { diff --git a/test/test_register_access.c b/test/test_register_access.c index a126815..4839437 100644 --- a/test/test_register_access.c +++ b/test/test_register_access.c @@ -44,4 +44,5 @@ test_register_endianness (void) cut_assert_equal_uint (0x55, value, cut_message ("check register value")); nfc_close (device); + nfc_exit (); } diff --git a/test/test_register_endianness.c b/test/test_register_endianness.c index f0239af..a6b15c4 100644 --- a/test/test_register_endianness.c +++ b/test/test_register_endianness.c @@ -35,4 +35,5 @@ test_register_endianness (void) cut_assert_equal_int (0, res, cut_message ("read register 0xFFF0")); nfc_close (device); + nfc_exit (); } diff --git a/utils/nfc-emulate-forum-tag4.c b/utils/nfc-emulate-forum-tag4.c index d2794d6..65ff665 100644 --- a/utils/nfc-emulate-forum-tag4.c +++ b/utils/nfc-emulate-forum-tag4.c @@ -372,6 +372,7 @@ main (int argc, char *argv[]) err (EXIT_FAILURE, "Can't save NDEF file '%s'", argv[2]); } } - + + nfc_exit (); exit (EXIT_SUCCESS); } diff --git a/utils/nfc-list.c b/utils/nfc-list.c index 0515682..6afd126 100644 --- a/utils/nfc-list.c +++ b/utils/nfc-list.c @@ -251,6 +251,7 @@ main (int argc, const char *argv[]) } nfc_close (pnd); } - + + nfc_exit (); return 0; } diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index 481b0de..450ae6a 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -565,6 +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 (); exit (EXIT_FAILURE); } // Test if we are dealing with a MIFARE compatible tag @@ -663,6 +664,7 @@ main (int argc, const char *argv[]) printf ("Done, all bytes have been extracted!\n"); } }; - + + nfc_exit (); exit (EXIT_SUCCESS); } diff --git a/utils/nfc-mfsetuid.c b/utils/nfc-mfsetuid.c index 8c8ed7f..b2cbf3f 100644 --- a/utils/nfc-mfsetuid.c +++ b/utils/nfc-mfsetuid.c @@ -215,6 +215,7 @@ main (int argc, char *argv[]) if (!transmit_bits (abtReqa, 7)) { printf ("Error: No tag available\n"); nfc_close (pnd); + nfc_exit (); return 1; } memcpy (abtAtqa, abtRx, 2); @@ -353,5 +354,6 @@ main (int argc, char *argv[]) nfc_close (pnd); + nfc_exit (); return 0; } diff --git a/utils/nfc-mfultralight.c b/utils/nfc-mfultralight.c index dfc0000..515001e 100644 --- a/utils/nfc-mfultralight.c +++ b/utils/nfc-mfultralight.c @@ -230,6 +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 (); return 1; } // Test if we are dealing with a MIFARE compatible tag @@ -237,6 +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 (); return EXIT_FAILURE; } // Get the info from the current tag @@ -268,6 +270,6 @@ main (int argc, const char *argv[]) } nfc_close (pnd); - + nfc_exit (); return EXIT_SUCCESS; } diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index 8a80b28..c91b7a7 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -317,5 +317,6 @@ error: if (pnd) { nfc_close (pnd); } + nfc_exit (); exit (error); } diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index 0ef048d..ace9f74 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -233,6 +233,7 @@ main (int argc, char *argv[]) if (nfc_initiator_init (pndInitiator) < 0) { printf ("Error: fail initializing initiator\n"); nfc_close (pndInitiator); + nfc_exit (); exit (EXIT_FAILURE); } @@ -244,6 +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 (); exit (EXIT_FAILURE); } @@ -253,21 +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 (); 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 (); 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 (); 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 (); exit(EXIT_FAILURE); } } @@ -291,6 +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 (); exit(EXIT_FAILURE); } if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAtqa, &foo, "ATQA") != EXIT_SUCCESS) { @@ -301,11 +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 (); 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 (); exit(EXIT_FAILURE); } } else { @@ -350,6 +359,7 @@ main (int argc, char *argv[]) if (!target_only_mode) { nfc_close (pndInitiator); } + nfc_exit (); return EXIT_FAILURE; } @@ -362,6 +372,7 @@ main (int argc, char *argv[]) nfc_close (pndInitiator); } nfc_close (pndTarget); + nfc_exit (); exit(EXIT_FAILURE); } printf ("%s\n", "Done, relaying frames now!"); @@ -379,6 +390,7 @@ main (int argc, char *argv[]) nfc_close (pndInitiator); } nfc_close (pndTarget); + nfc_exit (); exit(EXIT_FAILURE); } szCapduLen = (size_t) res; @@ -386,6 +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 (); exit(EXIT_FAILURE); } } @@ -393,6 +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 (); exit(EXIT_FAILURE); } } @@ -410,6 +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 (); exit(EXIT_FAILURE); } ret = true; @@ -436,13 +451,16 @@ main (int argc, char *argv[]) } if (!initiator_only_mode) { nfc_close (pndTarget); + nfc_exit (); } + nfc_exit (); 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 (); exit(EXIT_FAILURE); } } @@ -455,6 +473,7 @@ main (int argc, char *argv[]) if (!initiator_only_mode) { nfc_close (pndTarget); } + nfc_exit (); exit (EXIT_SUCCESS); }