add context to nfc_init(), nfc_exit(), nfc_open() and nfc_list_devices() functions.

This commit is contained in:
Audrey Diacre 2012-01-18 16:22:06 +00:00
parent 86c8ce536b
commit 4c011279ff
29 changed files with 142 additions and 138 deletions

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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);
}

View file

@ -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);
}