From 5b0e276572a135cfbc5b0b45415857aaa9ce11a6 Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Tue, 4 Dec 2012 19:29:57 +0100 Subject: [PATCH] Examples and utils are now updated to use the requiered nfc_context --- examples/nfc-anticol.c | 13 ++++---- examples/nfc-dep-initiator.c | 7 +++-- examples/nfc-dep-target.c | 12 +++++--- examples/nfc-emulate-forum-tag2.c | 10 +++--- examples/nfc-emulate-tag.c | 9 +++--- examples/nfc-emulate-uid.c | 9 +++--- examples/nfc-mfsetuid.c | 11 ++++--- examples/nfc-poll.c | 9 +++--- examples/nfc-relay.c | 14 ++++----- examples/pn53x-diagnose.c | 7 +++-- examples/pn53x-sam.c | 7 +++-- examples/pn53x-tamashell.c | 9 +++--- include/nfc/nfc.h | 22 ++++++++++--- utils/nfc-emulate-forum-tag4.c | 7 +++-- utils/nfc-list.c | 4 +-- utils/nfc-mfclassic.c | 9 +++--- utils/nfc-mfultralight.c | 13 ++++---- utils/nfc-read-forum-tag3.c | 7 +++-- utils/nfc-relay-picc.c | 51 ++++++++++++++++--------------- utils/nfc-scan-device.c | 9 +++--- 20 files changed, 136 insertions(+), 103 deletions(-) diff --git a/examples/nfc-anticol.c b/examples/nfc-anticol.c index 0fa4e03..f517230 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -149,10 +149,11 @@ main(int argc, char *argv[]) } } - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); // Try to open the NFC reader - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); if (!pnd) { printf("Error opening NFC reader\n"); @@ -187,8 +188,8 @@ main(int argc, char *argv[]) if (!transmit_bits(abtReqa, 7)) { printf("Error: No tag available\n"); nfc_close(pnd); - nfc_exit(NULL); - return 1; + nfc_exit(context); + return EXIT_FAILURE; } memcpy(abtAtqa, abtRx, 2); @@ -317,6 +318,6 @@ main(int argc, char *argv[]) } nfc_close(pnd); - nfc_exit(NULL); - return 0; + nfc_exit(context); + return EXIT_SUCCESS; } diff --git a/examples/nfc-dep-initiator.c b/examples/nfc-dep-initiator.c index 5be6383..e6737bc 100644 --- a/examples/nfc-dep-initiator.c +++ b/examples/nfc-dep-initiator.c @@ -71,9 +71,10 @@ main(int argc, const char *argv[]) return EXIT_FAILURE; } - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); if (!pnd) { printf("Unable to open NFC device.\n"); return EXIT_FAILURE; @@ -110,6 +111,6 @@ main(int argc, const char *argv[]) error: nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); return EXIT_SUCCESS; } diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index 4a86222..7bbb996 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -64,18 +64,20 @@ main(int argc, const char *argv[]) uint8_t abtRx[MAX_FRAME_LEN]; int szRx; uint8_t abtTx[] = "Hello Mars!"; + + nfc_context *context; + nfc_init(&context); #define MAX_DEVICE_COUNT 2 nfc_connstring connstrings[MAX_DEVICE_COUNT]; - size_t szDeviceFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT); + size_t szDeviceFound = nfc_list_devices(context, 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(NULL); if (szDeviceFound == 1) { - pnd = nfc_open(NULL, connstrings[0]); + pnd = nfc_open(context, connstrings[0]); } else if (szDeviceFound > 1) { - pnd = nfc_open(NULL, connstrings[1]); + pnd = nfc_open(context, connstrings[1]); } else { printf("No device found.\n"); return EXIT_FAILURE; @@ -141,6 +143,6 @@ main(int argc, const char *argv[]) error: nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); return EXIT_SUCCESS; } diff --git a/examples/nfc-emulate-forum-tag2.c b/examples/nfc-emulate-forum-tag2.c index 78e2d66..325e256 100644 --- a/examples/nfc-emulate-forum-tag2.c +++ b/examples/nfc-emulate-forum-tag2.c @@ -184,8 +184,10 @@ main(int argc, char *argv[]) }; signal(SIGINT, stop_emulation); - nfc_init(NULL); - pnd = nfc_open(NULL, NULL); + + nfc_context *context; + nfc_init(&context); + pnd = nfc_open(context, NULL); if (pnd == NULL) { ERR("Unable to open NFC device"); @@ -200,7 +202,7 @@ main(int argc, char *argv[]) } nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_SUCCESS); @@ -208,6 +210,6 @@ error: if (pnd) { nfc_perror(pnd, argv[0]); nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); } } diff --git a/examples/nfc-emulate-tag.c b/examples/nfc-emulate-tag.c index a616ca5..c7267b4 100644 --- a/examples/nfc-emulate-tag.c +++ b/examples/nfc-emulate-tag.c @@ -56,6 +56,7 @@ static uint8_t abtRx[MAX_FRAME_LEN]; static int szRx; +static nfc_context *context; static nfc_device *pnd; static bool quiet_output = false; static bool init_mfc_auth = false; @@ -68,7 +69,7 @@ intr_hdlr(int sig) if (pnd != NULL) { nfc_close(pnd); } - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } @@ -181,10 +182,10 @@ main(int argc, char *argv[]) signal(SIGINT, intr_hdlr); #endif - nfc_init(NULL); + nfc_init(&context); // Try to open the NFC reader - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); // Display libnfc version acLibnfcVersion = nfc_version(); @@ -270,7 +271,7 @@ main(int argc, char *argv[]) } nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_SUCCESS); } diff --git a/examples/nfc-emulate-uid.c b/examples/nfc-emulate-uid.c index 485ac35..af56426 100644 --- a/examples/nfc-emulate-uid.c +++ b/examples/nfc-emulate-uid.c @@ -126,10 +126,11 @@ main(int argc, char *argv[]) signal(SIGINT, intr_hdlr); #endif - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); // Try to open the NFC device - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); if (pnd == NULL) { printf("Unable to open NFC device\n"); @@ -220,11 +221,11 @@ main(int argc, char *argv[]) } } nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_SUCCESS); error: nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } diff --git a/examples/nfc-mfsetuid.c b/examples/nfc-mfsetuid.c index 5c23785..3943a8a 100644 --- a/examples/nfc-mfsetuid.c +++ b/examples/nfc-mfsetuid.c @@ -177,10 +177,11 @@ main(int argc, char *argv[]) } } - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); // Try to open the NFC reader - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); if (!pnd) { printf("Error opening NFC reader\n"); @@ -215,7 +216,7 @@ main(int argc, char *argv[]) if (!transmit_bits(abtReqa, 7)) { printf("Error: No tag available\n"); nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); return 1; } memcpy(abtAtqa, abtRx, 2); @@ -354,6 +355,6 @@ main(int argc, char *argv[]) nfc_close(pnd); - nfc_exit(NULL); - return 0; + nfc_exit(context); + return EXIT_SUCCESS; } diff --git a/examples/nfc-poll.c b/examples/nfc-poll.c index 71bdf75..1507833 100644 --- a/examples/nfc-poll.c +++ b/examples/nfc-poll.c @@ -103,9 +103,10 @@ main(int argc, const char *argv[]) nfc_target nt; int res = 0; - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); if (pnd == NULL) { ERR("%s", "Unable to open NFC device."); @@ -122,7 +123,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(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } @@ -132,6 +133,6 @@ main(int argc, const char *argv[]) printf("No target found.\n"); } nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_SUCCESS); } diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index b728c57..224352e 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -108,19 +108,19 @@ main(int argc, char *argv[]) signal(SIGINT, intr_hdlr); #endif + nfc_context *context; + nfc_init(&context); nfc_connstring connstrings[MAX_DEVICE_COUNT]; // List available devices - size_t szFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT); + size_t szFound = nfc_list_devices(context, 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(NULL); - // Try to open the NFC emulator device - pndTag = nfc_open(NULL, connstrings[0]); + pndTag = nfc_open(context, connstrings[0]); if (pndTag == NULL) { printf("Error opening NFC emulator device\n"); return EXIT_FAILURE; @@ -152,7 +152,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(NULL); + nfc_exit(context); return EXIT_FAILURE; } printf("%s", "Configuring emulator settings..."); @@ -164,7 +164,7 @@ main(int argc, char *argv[]) printf("%s", "Done, emulated tag is initialized"); // Try to open the NFC reader - pndReader = nfc_open(NULL, connstrings[1]); + pndReader = nfc_open(context, connstrings[1]); printf("NFC reader device: %s opened", nfc_device_get_name(pndReader)); printf("%s", "Configuring NFC reader settings..."); @@ -222,6 +222,6 @@ main(int argc, char *argv[]) nfc_close(pndTag); nfc_close(pndReader); - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_SUCCESS); } diff --git a/examples/pn53x-diagnose.c b/examples/pn53x-diagnose.c index d16fea1..1457977 100644 --- a/examples/pn53x-diagnose.c +++ b/examples/pn53x-diagnose.c @@ -66,21 +66,22 @@ main(int argc, const char *argv[]) errx(1, "usage: %s", argv[0]); } - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); // 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(NULL, connstrings, MAX_DEVICE_COUNT); + size_t szFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT); if (szFound == 0) { printf("No NFC device found.\n"); } for (i = 0; i < szFound; i++) { - pnd = nfc_open(NULL, connstrings[i]); + pnd = nfc_open(context, 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 0e1d796..05ff351 100644 --- a/examples/pn53x-sam.c +++ b/examples/pn53x-sam.c @@ -77,7 +77,8 @@ main(int argc, const char *argv[]) int ret = EXIT_FAILURE; - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); // Display libnfc version const char *acLibnfcVersion = nfc_version(); @@ -85,7 +86,7 @@ main(int argc, const char *argv[]) // Open using the first available NFC device nfc_device *pnd; - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); if (pnd == NULL) { ERR("%s", "Unable to open NFC device."); @@ -211,7 +212,7 @@ error: // Close NFC device nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); exit(ret); } diff --git a/examples/pn53x-tamashell.c b/examples/pn53x-tamashell.c index 1a6ede6..82c20c5 100644 --- a/examples/pn53x-tamashell.c +++ b/examples/pn53x-tamashell.c @@ -83,10 +83,11 @@ int main(int argc, const char *argv[]) } } - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); // Try to open the NFC reader - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); if (pnd == NULL) { ERR("%s", "Unable to open NFC device."); @@ -197,6 +198,6 @@ int main(int argc, const char *argv[]) fclose(input); } nfc_close(pnd); - nfc_exit(NULL); - return 1; + nfc_exit(context); + return EXIT_SUCCESS; } diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index ac749d9..bd311b2 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -58,19 +58,33 @@ # include +# ifndef __has_attribute +# define __has_attribute(x) 0 +# endif + +# if __has_attribute(nonnull) || defined(__GNUC__) +# define __has_attribute_nonnull 1 +# endif + +# if __has_attribute_nonnull +# define ATTRIBUTE_NONNULL( param ) __attribute__((nonnull (param))) +# else +# define ATTRIBUTE_NONNULL( param ) +# endif + # ifdef __cplusplus extern "C" { # endif // __cplusplus /* Library initialization/deinitialization */ - NFC_EXPORT void nfc_init(nfc_context **context); - NFC_EXPORT void nfc_exit(nfc_context *context); + NFC_EXPORT void nfc_init(nfc_context **context) ATTRIBUTE_NONNULL(1); + NFC_EXPORT void nfc_exit(nfc_context *context) ATTRIBUTE_NONNULL(1); /* NFC Device/Hardware manipulation */ - NFC_EXPORT nfc_device *nfc_open(nfc_context *context, const nfc_connstring connstring); + NFC_EXPORT nfc_device *nfc_open(nfc_context *context, const nfc_connstring connstring) ATTRIBUTE_NONNULL(1); 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_context *context, nfc_connstring connstrings[], size_t connstrings_len); + NFC_EXPORT size_t nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], size_t connstrings_len) ATTRIBUTE_NONNULL(1); NFC_EXPORT int nfc_idle(nfc_device *pnd); /* NFC initiator: act as "reader" */ diff --git a/utils/nfc-emulate-forum-tag4.c b/utils/nfc-emulate-forum-tag4.c index b6183ff..8404cfb 100644 --- a/utils/nfc-emulate-forum-tag4.c +++ b/utils/nfc-emulate-forum-tag4.c @@ -366,10 +366,11 @@ main(int argc, char *argv[]) } } - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); // Try to open the NFC reader - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); if (pnd == NULL) { ERR("Unable to open NFC device"); @@ -393,6 +394,6 @@ main(int argc, char *argv[]) } } - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_SUCCESS); } diff --git a/utils/nfc-list.c b/utils/nfc-list.c index e615741..ca49be9 100644 --- a/utils/nfc-list.c +++ b/utils/nfc-list.c @@ -253,6 +253,6 @@ main(int argc, const char *argv[]) nfc_close(pnd); } - nfc_exit(NULL); - return 0; + nfc_exit(context); + return EXIT_SUCCESS; } diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index e3dc96f..34ed512 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -53,6 +53,7 @@ #include "mifare.h" #include "nfc-utils.h" +static nfc_context *context; static nfc_device *pnd; static nfc_target nt; static mifare_param mp; @@ -508,10 +509,10 @@ main(int argc, const char *argv[]) } // printf("Successfully opened required files\n"); - nfc_init(NULL); + nfc_init(&context); // Try to open the NFC reader - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); if (pnd == NULL) { printf("Error opening NFC reader\n"); exit(EXIT_FAILURE); @@ -536,7 +537,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(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } // Test if we are dealing with a MIFARE compatible tag @@ -596,6 +597,6 @@ main(int argc, const char *argv[]) break; }; - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_SUCCESS); } diff --git a/utils/nfc-mfultralight.c b/utils/nfc-mfultralight.c index d4c107f..d686734 100644 --- a/utils/nfc-mfultralight.c +++ b/utils/nfc-mfultralight.c @@ -204,10 +204,11 @@ main(int argc, const char *argv[]) } DBG("Successfully opened the dump file\n"); - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); // Try to open the NFC device - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); if (pnd == NULL) { ERR("Error opening NFC device\n"); return 1; @@ -230,15 +231,15 @@ 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(NULL); - return 1; + nfc_exit(context); + return EXIT_FAILURE; } // Test if we are dealing with a MIFARE compatible tag if (nt.nti.nai.abtAtqa[1] != 0x44) { ERR("tag is not a MIFARE Ultralight card\n"); nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); return EXIT_FAILURE; } // Get the info from the current tag @@ -270,6 +271,6 @@ main(int argc, const char *argv[]) } nfc_close(pnd); - nfc_exit(NULL); + nfc_exit(context); return EXIT_SUCCESS; } diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index 10fa0d1..f522727 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -192,9 +192,10 @@ main(int argc, char *argv[]) } } - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); - pnd = nfc_open(NULL, NULL); + pnd = nfc_open(context, NULL); if (pnd == NULL) { ERR("Unable to open NFC device"); @@ -314,6 +315,6 @@ error: if (pnd) { nfc_close(pnd); } - nfc_exit(NULL); + nfc_exit(context); exit(error); } diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index ebc119e..b43f644 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -195,11 +195,12 @@ main(int argc, char *argv[]) signal(SIGINT, intr_hdlr); #endif - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); nfc_connstring connstrings[MAX_DEVICE_COUNT]; // List available devices - size_t szFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT); + size_t szFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT); if (initiator_only_mode || target_only_mode) { if (szFound < 1) { @@ -222,9 +223,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) || swap_devices) { - pndInitiator = nfc_open(NULL, connstrings[0]); + pndInitiator = nfc_open(context, connstrings[0]); } else { - pndInitiator = nfc_open(NULL, connstrings[1]); + pndInitiator = nfc_open(context, connstrings[1]); } if (!pndInitiator) { @@ -237,7 +238,7 @@ main(int argc, char *argv[]) if (nfc_initiator_init(pndInitiator) < 0) { printf("Error: fail initializing initiator\n"); nfc_close(pndInitiator); - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } @@ -249,7 +250,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(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } @@ -259,25 +260,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(NULL); + nfc_exit(context); 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(NULL); + nfc_exit(context); 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(NULL); + nfc_exit(context); 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(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } } @@ -301,7 +302,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(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAtqa, &foo, "ATQA") != EXIT_SUCCESS) { @@ -312,13 +313,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(NULL); + nfc_exit(context); 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(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } } else { @@ -358,16 +359,16 @@ main(int argc, char *argv[]) // Try to open the NFC emulator device if (swap_devices) { - pndTarget = nfc_open(NULL, connstrings[1]); + pndTarget = nfc_open(context, connstrings[1]); } else { - pndTarget = nfc_open(NULL, connstrings[0]); + pndTarget = nfc_open(context, connstrings[0]); } if (pndTarget == NULL) { printf("Error opening NFC emulator device\n"); if (!target_only_mode) { nfc_close(pndInitiator); } - nfc_exit(NULL); + nfc_exit(context); return EXIT_FAILURE; } @@ -379,7 +380,7 @@ main(int argc, char *argv[]) nfc_close(pndInitiator); } nfc_close(pndTarget); - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } printf("%s\n", "Done, relaying frames now!"); @@ -396,7 +397,7 @@ main(int argc, char *argv[]) nfc_close(pndInitiator); } nfc_close(pndTarget); - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } szCapduLen = (size_t) res; @@ -404,7 +405,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(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } } @@ -412,7 +413,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(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } } @@ -434,7 +435,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(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } ret = true; @@ -461,16 +462,16 @@ main(int argc, char *argv[]) } if (!initiator_only_mode) { nfc_close(pndTarget); - nfc_exit(NULL); + nfc_exit(context); } - nfc_exit(NULL); + nfc_exit(context); 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(NULL); + nfc_exit(context); exit(EXIT_FAILURE); } } @@ -483,7 +484,7 @@ main(int argc, char *argv[]) if (!initiator_only_mode) { nfc_close(pndTarget); } - nfc_exit(NULL); + nfc_exit(context); exit(EXIT_SUCCESS); } diff --git a/utils/nfc-scan-device.c b/utils/nfc-scan-device.c index 7105942..39d5c2b 100644 --- a/utils/nfc-scan-device.c +++ b/utils/nfc-scan-device.c @@ -76,7 +76,8 @@ main(int argc, const char *argv[]) size_t i; bool verbose = false; - nfc_init(NULL); + nfc_context *context; + nfc_init(&context); // Display libnfc version acLibnfcVersion = nfc_version(); @@ -105,7 +106,7 @@ main(int argc, const char *argv[]) #endif nfc_connstring connstrings[MAX_DEVICE_COUNT]; - size_t szDeviceFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT); + size_t szDeviceFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT); int res = EXIT_FAILURE; if (szDeviceFound == 0) { @@ -116,7 +117,7 @@ main(int argc, const char *argv[]) printf("%d NFC device(s) found:\n", (int)szDeviceFound); char *strinfo = NULL; for (i = 0; i < szDeviceFound; i++) { - pnd = nfc_open(NULL, connstrings[i]); + pnd = nfc_open(context, connstrings[i]); if (pnd != NULL) { printf("- %s:\n %s\n", nfc_device_get_name(pnd), nfc_device_get_connstring(pnd)); if (verbose) { @@ -133,6 +134,6 @@ main(int argc, const char *argv[]) res = EXIT_SUCCESS; bye: - nfc_exit(NULL); + nfc_exit(context); return res; }