Codebase list libfreefare / 5b0e276
Examples and utils are now updated to use the requiered nfc_context Romuald Conty 11 years ago
20 changed file(s) with 139 addition(s) and 106 deletion(s). Raw diff Collapse all Expand all
148148 }
149149 }
150150
151 nfc_init(NULL);
151 nfc_context *context;
152 nfc_init(&context);
152153
153154 // Try to open the NFC reader
154 pnd = nfc_open(NULL, NULL);
155 pnd = nfc_open(context, NULL);
155156
156157 if (!pnd) {
157158 printf("Error opening NFC reader\n");
186187 if (!transmit_bits(abtReqa, 7)) {
187188 printf("Error: No tag available\n");
188189 nfc_close(pnd);
189 nfc_exit(NULL);
190 return 1;
190 nfc_exit(context);
191 return EXIT_FAILURE;
191192 }
192193 memcpy(abtAtqa, abtRx, 2);
193194
316317 }
317318
318319 nfc_close(pnd);
319 nfc_exit(NULL);
320 return 0;
320 nfc_exit(context);
321 return EXIT_SUCCESS;
321322 }
7070 return EXIT_FAILURE;
7171 }
7272
73 nfc_init(NULL);
73 nfc_context *context;
74 nfc_init(&context);
7475
75 pnd = nfc_open(NULL, NULL);
76 pnd = nfc_open(context, NULL);
7677 if (!pnd) {
7778 printf("Unable to open NFC device.\n");
7879 return EXIT_FAILURE;
109110
110111 error:
111112 nfc_close(pnd);
112 nfc_exit(NULL);
113 nfc_exit(context);
113114 return EXIT_SUCCESS;
114115 }
6363 uint8_t abtRx[MAX_FRAME_LEN];
6464 int szRx;
6565 uint8_t abtTx[] = "Hello Mars!";
66
67 nfc_context *context;
68 nfc_init(&context);
6669 #define MAX_DEVICE_COUNT 2
6770 nfc_connstring connstrings[MAX_DEVICE_COUNT];
68 size_t szDeviceFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
71 size_t szDeviceFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
6972 // Little hack to allow using nfc-dep-initiator & nfc-dep-target from
7073 // the same machine: if there is more than one readers opened
7174 // nfc-dep-target will open the second reader
7275 // (we hope they're always detected in the same order)
73 nfc_init(NULL);
7476 if (szDeviceFound == 1) {
75 pnd = nfc_open(NULL, connstrings[0]);
77 pnd = nfc_open(context, connstrings[0]);
7678 } else if (szDeviceFound > 1) {
77 pnd = nfc_open(NULL, connstrings[1]);
79 pnd = nfc_open(context, connstrings[1]);
7880 } else {
7981 printf("No device found.\n");
8082 return EXIT_FAILURE;
140142
141143 error:
142144 nfc_close(pnd);
143 nfc_exit(NULL);
145 nfc_exit(context);
144146 return EXIT_SUCCESS;
145147 }
183183 };
184184
185185 signal(SIGINT, stop_emulation);
186 nfc_init(NULL);
187 pnd = nfc_open(NULL, NULL);
186
187 nfc_context *context;
188 nfc_init(&context);
189 pnd = nfc_open(context, NULL);
188190
189191 if (pnd == NULL) {
190192 ERR("Unable to open NFC device");
199201 }
200202
201203 nfc_close(pnd);
202 nfc_exit(NULL);
204 nfc_exit(context);
203205
204206 exit(EXIT_SUCCESS);
205207
207209 if (pnd) {
208210 nfc_perror(pnd, argv[0]);
209211 nfc_close(pnd);
210 nfc_exit(NULL);
212 nfc_exit(context);
211213 }
212214 }
5555
5656 static uint8_t abtRx[MAX_FRAME_LEN];
5757 static int szRx;
58 static nfc_context *context;
5859 static nfc_device *pnd;
5960 static bool quiet_output = false;
6061 static bool init_mfc_auth = false;
6768 if (pnd != NULL) {
6869 nfc_close(pnd);
6970 }
70 nfc_exit(NULL);
71 nfc_exit(context);
7172 exit(EXIT_FAILURE);
7273 }
7374
180181 signal(SIGINT, intr_hdlr);
181182 #endif
182183
183 nfc_init(NULL);
184 nfc_init(&context);
184185
185186 // Try to open the NFC reader
186 pnd = nfc_open(NULL, NULL);
187 pnd = nfc_open(context, NULL);
187188
188189 // Display libnfc version
189190 acLibnfcVersion = nfc_version();
269270 }
270271
271272 nfc_close(pnd);
272 nfc_exit(NULL);
273 nfc_exit(context);
273274 exit(EXIT_SUCCESS);
274275 }
275276
125125 signal(SIGINT, intr_hdlr);
126126 #endif
127127
128 nfc_init(NULL);
128 nfc_context *context;
129 nfc_init(&context);
129130
130131 // Try to open the NFC device
131 pnd = nfc_open(NULL, NULL);
132 pnd = nfc_open(context, NULL);
132133
133134 if (pnd == NULL) {
134135 printf("Unable to open NFC device\n");
219220 }
220221 }
221222 nfc_close(pnd);
222 nfc_exit(NULL);
223 nfc_exit(context);
223224 exit(EXIT_SUCCESS);
224225
225226 error:
226227 nfc_close(pnd);
227 nfc_exit(NULL);
228 nfc_exit(context);
228229 exit(EXIT_FAILURE);
229230 }
176176 }
177177 }
178178
179 nfc_init(NULL);
179 nfc_context *context;
180 nfc_init(&context);
180181
181182 // Try to open the NFC reader
182 pnd = nfc_open(NULL, NULL);
183 pnd = nfc_open(context, NULL);
183184
184185 if (!pnd) {
185186 printf("Error opening NFC reader\n");
214215 if (!transmit_bits(abtReqa, 7)) {
215216 printf("Error: No tag available\n");
216217 nfc_close(pnd);
217 nfc_exit(NULL);
218 nfc_exit(context);
218219 return 1;
219220 }
220221 memcpy(abtAtqa, abtRx, 2);
353354
354355
355356 nfc_close(pnd);
356 nfc_exit(NULL);
357 return 0;
357 nfc_exit(context);
358 return EXIT_SUCCESS;
358359 }
102102 nfc_target nt;
103103 int res = 0;
104104
105 nfc_init(NULL);
105 nfc_context *context;
106 nfc_init(&context);
106107
107 pnd = nfc_open(NULL, NULL);
108 pnd = nfc_open(context, NULL);
108109
109110 if (pnd == NULL) {
110111 ERR("%s", "Unable to open NFC device.");
121122 if ((res = nfc_initiator_poll_target(pnd, nmModulations, szModulations, uiPollNr, uiPeriod, &nt)) < 0) {
122123 nfc_perror(pnd, "nfc_initiator_poll_target");
123124 nfc_close(pnd);
124 nfc_exit(NULL);
125 nfc_exit(context);
125126 exit(EXIT_FAILURE);
126127 }
127128
131132 printf("No target found.\n");
132133 }
133134 nfc_close(pnd);
134 nfc_exit(NULL);
135 nfc_exit(context);
135136 exit(EXIT_SUCCESS);
136137 }
107107 signal(SIGINT, intr_hdlr);
108108 #endif
109109
110 nfc_context *context;
111 nfc_init(&context);
110112 nfc_connstring connstrings[MAX_DEVICE_COUNT];
111113 // List available devices
112 size_t szFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
114 size_t szFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
113115
114116 if (szFound < 2) {
115117 ERR("%zd device found but two opened devices are needed to relay NFC.", szFound);
116118 return EXIT_FAILURE;
117119 }
118120
119 nfc_init(NULL);
120
121121 // Try to open the NFC emulator device
122 pndTag = nfc_open(NULL, connstrings[0]);
122 pndTag = nfc_open(context, connstrings[0]);
123123 if (pndTag == NULL) {
124124 printf("Error opening NFC emulator device\n");
125125 return EXIT_FAILURE;
151151 if ((szReaderRxBits = nfc_target_init(pndTag, &nt, abtReaderRx, sizeof(abtReaderRx), 0)) < 0) {
152152 ERR("%s", "Initialization of NFC emulator failed");
153153 nfc_close(pndTag);
154 nfc_exit(NULL);
154 nfc_exit(context);
155155 return EXIT_FAILURE;
156156 }
157157 printf("%s", "Configuring emulator settings...");
163163 printf("%s", "Done, emulated tag is initialized");
164164
165165 // Try to open the NFC reader
166 pndReader = nfc_open(NULL, connstrings[1]);
166 pndReader = nfc_open(context, connstrings[1]);
167167
168168 printf("NFC reader device: %s opened", nfc_device_get_name(pndReader));
169169 printf("%s", "Configuring NFC reader settings...");
221221
222222 nfc_close(pndTag);
223223 nfc_close(pndReader);
224 nfc_exit(NULL);
224 nfc_exit(context);
225225 exit(EXIT_SUCCESS);
226226 }
6565 errx(1, "usage: %s", argv[0]);
6666 }
6767
68 nfc_init(NULL);
68 nfc_context *context;
69 nfc_init(&context);
6970
7071 // Display libnfc version
7172 acLibnfcVersion = nfc_version();
7273 printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
7374
7475 nfc_connstring connstrings[MAX_DEVICE_COUNT];
75 size_t szFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
76 size_t szFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
7677
7778 if (szFound == 0) {
7879 printf("No NFC device found.\n");
7980 }
8081
8182 for (i = 0; i < szFound; i++) {
82 pnd = nfc_open(NULL, connstrings[i]);
83 pnd = nfc_open(context, connstrings[i]);
8384
8485 if (pnd == NULL) {
8586 ERR("%s", "Unable to open NFC device.");
7676
7777 int ret = EXIT_FAILURE;
7878
79 nfc_init(NULL);
79 nfc_context *context;
80 nfc_init(&context);
8081
8182 // Display libnfc version
8283 const char *acLibnfcVersion = nfc_version();
8485
8586 // Open using the first available NFC device
8687 nfc_device *pnd;
87 pnd = nfc_open(NULL, NULL);
88 pnd = nfc_open(context, NULL);
8889
8990 if (pnd == NULL) {
9091 ERR("%s", "Unable to open NFC device.");
210211
211212 // Close NFC device
212213 nfc_close(pnd);
213 nfc_exit(NULL);
214 nfc_exit(context);
214215
215216 exit(ret);
216217 }
8282 }
8383 }
8484
85 nfc_init(NULL);
85 nfc_context *context;
86 nfc_init(&context);
8687
8788 // Try to open the NFC reader
88 pnd = nfc_open(NULL, NULL);
89 pnd = nfc_open(context, NULL);
8990
9091 if (pnd == NULL) {
9192 ERR("%s", "Unable to open NFC device.");
196197 fclose(input);
197198 }
198199 nfc_close(pnd);
199 nfc_exit(NULL);
200 return 1;
200 nfc_exit(context);
201 return EXIT_SUCCESS;
201202 }
5757
5858 # include <nfc/nfc-types.h>
5959
60 # ifndef __has_attribute
61 # define __has_attribute(x) 0
62 # endif
63
64 # if __has_attribute(nonnull) || defined(__GNUC__)
65 # define __has_attribute_nonnull 1
66 # endif
67
68 # if __has_attribute_nonnull
69 # define ATTRIBUTE_NONNULL( param ) __attribute__((nonnull (param)))
70 # else
71 # define ATTRIBUTE_NONNULL( param )
72 # endif
73
6074 # ifdef __cplusplus
6175 extern "C" {
6276 # endif // __cplusplus
6377
6478 /* Library initialization/deinitialization */
65 NFC_EXPORT void nfc_init(nfc_context **context);
66 NFC_EXPORT void nfc_exit(nfc_context *context);
79 NFC_EXPORT void nfc_init(nfc_context **context) ATTRIBUTE_NONNULL(1);
80 NFC_EXPORT void nfc_exit(nfc_context *context) ATTRIBUTE_NONNULL(1);
6781
6882 /* NFC Device/Hardware manipulation */
69 NFC_EXPORT nfc_device *nfc_open(nfc_context *context, const nfc_connstring connstring);
83 NFC_EXPORT nfc_device *nfc_open(nfc_context *context, const nfc_connstring connstring) ATTRIBUTE_NONNULL(1);
7084 NFC_EXPORT void nfc_close(nfc_device *pnd);
7185 NFC_EXPORT int nfc_abort_command(nfc_device *pnd);
72 NFC_EXPORT size_t nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], size_t connstrings_len);
86 NFC_EXPORT size_t nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], size_t connstrings_len) ATTRIBUTE_NONNULL(1);
7387 NFC_EXPORT int nfc_idle(nfc_device *pnd);
7488
7589 /* NFC initiator: act as "reader" */
365365 }
366366 }
367367
368 nfc_init(NULL);
368 nfc_context *context;
369 nfc_init(&context);
369370
370371 // Try to open the NFC reader
371 pnd = nfc_open(NULL, NULL);
372 pnd = nfc_open(context, NULL);
372373
373374 if (pnd == NULL) {
374375 ERR("Unable to open NFC device");
392393 }
393394 }
394395
395 nfc_exit(NULL);
396 nfc_exit(context);
396397 exit(EXIT_SUCCESS);
397398 }
252252 nfc_close(pnd);
253253 }
254254
255 nfc_exit(NULL);
256 return 0;
255 nfc_exit(context);
256 return EXIT_SUCCESS;
257257 }
5252 #include "mifare.h"
5353 #include "nfc-utils.h"
5454
55 static nfc_context *context;
5556 static nfc_device *pnd;
5657 static nfc_target nt;
5758 static mifare_param mp;
507508 }
508509 // printf("Successfully opened required files\n");
509510
510 nfc_init(NULL);
511 nfc_init(&context);
511512
512513 // Try to open the NFC reader
513 pnd = nfc_open(NULL, NULL);
514 pnd = nfc_open(context, NULL);
514515 if (pnd == NULL) {
515516 printf("Error opening NFC reader\n");
516517 exit(EXIT_FAILURE);
535536 if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) < 0) {
536537 printf("Error: no tag was found\n");
537538 nfc_close(pnd);
538 nfc_exit(NULL);
539 nfc_exit(context);
539540 exit(EXIT_FAILURE);
540541 }
541542 // Test if we are dealing with a MIFARE compatible tag
595596 break;
596597 };
597598
598 nfc_exit(NULL);
599 nfc_exit(context);
599600 exit(EXIT_SUCCESS);
600601 }
203203 }
204204 DBG("Successfully opened the dump file\n");
205205
206 nfc_init(NULL);
206 nfc_context *context;
207 nfc_init(&context);
207208
208209 // Try to open the NFC device
209 pnd = nfc_open(NULL, NULL);
210 pnd = nfc_open(context, NULL);
210211 if (pnd == NULL) {
211212 ERR("Error opening NFC device\n");
212213 return 1;
229230 if (nfc_initiator_select_passive_target(pnd, nmMifare, NULL, 0, &nt) < 0) {
230231 ERR("no tag was found\n");
231232 nfc_close(pnd);
232 nfc_exit(NULL);
233 return 1;
233 nfc_exit(context);
234 return EXIT_FAILURE;
234235 }
235236 // Test if we are dealing with a MIFARE compatible tag
236237
237238 if (nt.nti.nai.abtAtqa[1] != 0x44) {
238239 ERR("tag is not a MIFARE Ultralight card\n");
239240 nfc_close(pnd);
240 nfc_exit(NULL);
241 nfc_exit(context);
241242 return EXIT_FAILURE;
242243 }
243244 // Get the info from the current tag
269270 }
270271
271272 nfc_close(pnd);
272 nfc_exit(NULL);
273 nfc_exit(context);
273274 return EXIT_SUCCESS;
274275 }
191191 }
192192 }
193193
194 nfc_init(NULL);
195
196 pnd = nfc_open(NULL, NULL);
194 nfc_context *context;
195 nfc_init(&context);
196
197 pnd = nfc_open(context, NULL);
197198
198199 if (pnd == NULL) {
199200 ERR("Unable to open NFC device");
313314 if (pnd) {
314315 nfc_close(pnd);
315316 }
316 nfc_exit(NULL);
317 nfc_exit(context);
317318 exit(error);
318319 }
194194 signal(SIGINT, intr_hdlr);
195195 #endif
196196
197 nfc_init(NULL);
197 nfc_context *context;
198 nfc_init(&context);
198199
199200 nfc_connstring connstrings[MAX_DEVICE_COUNT];
200201 // List available devices
201 size_t szFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
202 size_t szFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
202203
203204 if (initiator_only_mode || target_only_mode) {
204205 if (szFound < 1) {
221222 // if there is more than one readers opened we open the second reader
222223 // (we hope they're always detected in the same order)
223224 if ((szFound == 1) || swap_devices) {
224 pndInitiator = nfc_open(NULL, connstrings[0]);
225 } else {
226 pndInitiator = nfc_open(NULL, connstrings[1]);
225 pndInitiator = nfc_open(context, connstrings[0]);
226 } else {
227 pndInitiator = nfc_open(context, connstrings[1]);
227228 }
228229
229230 if (!pndInitiator) {
236237 if (nfc_initiator_init(pndInitiator) < 0) {
237238 printf("Error: fail initializing initiator\n");
238239 nfc_close(pndInitiator);
239 nfc_exit(NULL);
240 nfc_exit(context);
240241 exit(EXIT_FAILURE);
241242 }
242243
248249 if (nfc_initiator_select_passive_target(pndInitiator, nm, NULL, 0, &ntRealTarget) < 0) {
249250 printf("Error: no tag was found\n");
250251 nfc_close(pndInitiator);
251 nfc_exit(NULL);
252 nfc_exit(context);
252253 exit(EXIT_FAILURE);
253254 }
254255
258259 if (print_hex_fd4(ntRealTarget.nti.nai.abtUid, ntRealTarget.nti.nai.szUidLen, "UID") != EXIT_SUCCESS) {
259260 fprintf(stderr, "Error while printing UID to FD4\n");
260261 nfc_close(pndInitiator);
261 nfc_exit(NULL);
262 nfc_exit(context);
262263 exit(EXIT_FAILURE);
263264 }
264265 if (print_hex_fd4(ntRealTarget.nti.nai.abtAtqa, 2, "ATQA") != EXIT_SUCCESS) {
265266 fprintf(stderr, "Error while printing ATQA to FD4\n");
266267 nfc_close(pndInitiator);
267 nfc_exit(NULL);
268 nfc_exit(context);
268269 exit(EXIT_FAILURE);
269270 }
270271 if (print_hex_fd4(&(ntRealTarget.nti.nai.btSak), 1, "SAK") != EXIT_SUCCESS) {
271272 fprintf(stderr, "Error while printing SAK to FD4\n");
272273 nfc_close(pndInitiator);
273 nfc_exit(NULL);
274 nfc_exit(context);
274275 exit(EXIT_FAILURE);
275276 }
276277 if (print_hex_fd4(ntRealTarget.nti.nai.abtAts, ntRealTarget.nti.nai.szAtsLen, "ATS") != EXIT_SUCCESS) {
277278 fprintf(stderr, "Error while printing ATS to FD4\n");
278279 nfc_close(pndInitiator);
279 nfc_exit(NULL);
280 nfc_exit(context);
280281 exit(EXIT_FAILURE);
281282 }
282283 }
300301 if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtUid, &(ntEmulatedTarget.nti.nai.szUidLen), "UID") != EXIT_SUCCESS) {
301302 fprintf(stderr, "Error while scanning UID from FD3\n");
302303 nfc_close(pndInitiator);
303 nfc_exit(NULL);
304 nfc_exit(context);
304305 exit(EXIT_FAILURE);
305306 }
306307 if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAtqa, &foo, "ATQA") != EXIT_SUCCESS) {
311312 if (scan_hex_fd3(&(ntEmulatedTarget.nti.nai.btSak), &foo, "SAK") != EXIT_SUCCESS) {
312313 fprintf(stderr, "Error while scanning SAK from FD3\n");
313314 nfc_close(pndInitiator);
314 nfc_exit(NULL);
315 nfc_exit(context);
315316 exit(EXIT_FAILURE);
316317 }
317318 if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAts, &(ntEmulatedTarget.nti.nai.szAtsLen), "ATS") != EXIT_SUCCESS) {
318319 fprintf(stderr, "Error while scanning ATS from FD3\n");
319320 nfc_close(pndInitiator);
320 nfc_exit(NULL);
321 nfc_exit(context);
321322 exit(EXIT_FAILURE);
322323 }
323324 } else {
357358
358359 // Try to open the NFC emulator device
359360 if (swap_devices) {
360 pndTarget = nfc_open(NULL, connstrings[1]);
361 } else {
362 pndTarget = nfc_open(NULL, connstrings[0]);
361 pndTarget = nfc_open(context, connstrings[1]);
362 } else {
363 pndTarget = nfc_open(context, connstrings[0]);
363364 }
364365 if (pndTarget == NULL) {
365366 printf("Error opening NFC emulator device\n");
366367 if (!target_only_mode) {
367368 nfc_close(pndInitiator);
368369 }
369 nfc_exit(NULL);
370 nfc_exit(context);
370371 return EXIT_FAILURE;
371372 }
372373
378379 nfc_close(pndInitiator);
379380 }
380381 nfc_close(pndTarget);
381 nfc_exit(NULL);
382 nfc_exit(context);
382383 exit(EXIT_FAILURE);
383384 }
384385 printf("%s\n", "Done, relaying frames now!");
395396 nfc_close(pndInitiator);
396397 }
397398 nfc_close(pndTarget);
398 nfc_exit(NULL);
399 nfc_exit(context);
399400 exit(EXIT_FAILURE);
400401 }
401402 szCapduLen = (size_t) res;
403404 if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) {
404405 fprintf(stderr, "Error while printing C-APDU to FD4\n");
405406 nfc_close(pndTarget);
406 nfc_exit(NULL);
407 nfc_exit(context);
407408 exit(EXIT_FAILURE);
408409 }
409410 }
411412 if (scan_hex_fd3(abtCapdu, &szCapduLen, "C-APDU") != EXIT_SUCCESS) {
412413 fprintf(stderr, "Error while scanning C-APDU from FD3\n");
413414 nfc_close(pndInitiator);
414 nfc_exit(NULL);
415 nfc_exit(context);
415416 exit(EXIT_FAILURE);
416417 }
417418 }
433434 if (scan_hex_fd3(abtRapdu, &szRapduLen, "R-APDU") != EXIT_SUCCESS) {
434435 fprintf(stderr, "Error while scanning R-APDU from FD3\n");
435436 nfc_close(pndTarget);
436 nfc_exit(NULL);
437 nfc_exit(context);
437438 exit(EXIT_FAILURE);
438439 }
439440 ret = true;
460461 }
461462 if (!initiator_only_mode) {
462463 nfc_close(pndTarget);
463 nfc_exit(NULL);
464 nfc_exit(context);
464465 }
465 nfc_exit(NULL);
466 nfc_exit(context);
466467 exit(EXIT_FAILURE);
467468 }
468469 } else {
469470 if (print_hex_fd4(abtRapdu, szRapduLen, "R-APDU") != EXIT_SUCCESS) {
470471 fprintf(stderr, "Error while printing R-APDU to FD4\n");
471472 nfc_close(pndInitiator);
472 nfc_exit(NULL);
473 nfc_exit(context);
473474 exit(EXIT_FAILURE);
474475 }
475476 }
482483 if (!initiator_only_mode) {
483484 nfc_close(pndTarget);
484485 }
485 nfc_exit(NULL);
486 nfc_exit(context);
486487 exit(EXIT_SUCCESS);
487488 }
488489
7575 size_t i;
7676 bool verbose = false;
7777
78 nfc_init(NULL);
78 nfc_context *context;
79 nfc_init(&context);
7980
8081 // Display libnfc version
8182 acLibnfcVersion = nfc_version();
104105 #endif
105106
106107 nfc_connstring connstrings[MAX_DEVICE_COUNT];
107 size_t szDeviceFound = nfc_list_devices(NULL, connstrings, MAX_DEVICE_COUNT);
108 size_t szDeviceFound = nfc_list_devices(context, connstrings, MAX_DEVICE_COUNT);
108109
109110 int res = EXIT_FAILURE;
110111 if (szDeviceFound == 0) {
115116 printf("%d NFC device(s) found:\n", (int)szDeviceFound);
116117 char *strinfo = NULL;
117118 for (i = 0; i < szDeviceFound; i++) {
118 pnd = nfc_open(NULL, connstrings[i]);
119 pnd = nfc_open(context, connstrings[i]);
119120 if (pnd != NULL) {
120121 printf("- %s:\n %s\n", nfc_device_get_name(pnd), nfc_device_get_connstring(pnd));
121122 if (verbose) {
132133 res = EXIT_SUCCESS;
133134
134135 bye:
135 nfc_exit(NULL);
136 nfc_exit(context);
136137 return res;
137138 }