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

@ -14,14 +14,14 @@ main (int argc, const char *argv[])
nfc_device *pnd;
nfc_target nt;
nfc_init();
nfc_init (NULL);
// Display libnfc version
const char *acLibnfcVersion = nfc_version ();
printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
// Open, using the first available NFC device
pnd = nfc_open (NULL);
pnd = nfc_open (NULL, NULL);
if (pnd == NULL) {
ERR ("%s", "Unable to open NFC device.");
@ -55,6 +55,6 @@ main (int argc, const char *argv[])
}
// Close NFC device
nfc_close (pnd);
nfc_exit ();
nfc_exit (NULL);
return EXIT_SUCCESS;
}

View file

@ -148,10 +148,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");
@ -186,7 +186,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);
@ -316,6 +316,6 @@ main (int argc, char *argv[])
}
nfc_close (pnd);
nfc_exit ();
nfc_exit (NULL);
return 0;
}

View file

@ -72,9 +72,9 @@ main (int argc, const char *argv[])
return EXIT_FAILURE;
}
nfc_init();
nfc_init (NULL);
pnd = nfc_open (NULL);
pnd = nfc_open (NULL, NULL);
if (!pnd) {
printf("Unable to open NFC device.\n");
return EXIT_FAILURE;
@ -110,6 +110,6 @@ main (int argc, const char *argv[])
error:
nfc_close (pnd);
nfc_exit ();
nfc_exit (NULL);
return EXIT_SUCCESS;
}

View file

@ -66,16 +66,16 @@ main (int argc, const char *argv[])
uint8_t abtTx[] = "Hello Mars!";
#define MAX_DEVICE_COUNT 2
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);
// 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 ();
nfc_init (NULL);
if (szDeviceFound == 1) {
pnd = nfc_open (connstrings[0]);
pnd = nfc_open (NULL, connstrings[0]);
} else if (szDeviceFound > 1) {
pnd = nfc_open (connstrings[1]);
pnd = nfc_open (NULL, connstrings[1]);
} else {
printf("No device found.\n");
return EXIT_FAILURE;
@ -141,6 +141,6 @@ main (int argc, const char *argv[])
error:
nfc_close (pnd);
nfc_exit ();
nfc_exit (NULL);
return EXIT_SUCCESS;
}

View file

@ -182,8 +182,8 @@ main(int argc, char *argv[])
};
signal (SIGINT, stop_emulation);
nfc_init ();
pnd = nfc_open (NULL);
nfc_init (NULL);
pnd = nfc_open (NULL, NULL);
if (pnd == NULL) {
ERR("Unable to open NFC device");
@ -198,7 +198,7 @@ main(int argc, char *argv[])
}
nfc_close(pnd);
nfc_exit ();
nfc_exit (NULL);
exit (EXIT_SUCCESS);
@ -206,6 +206,6 @@ error:
if (pnd) {
nfc_perror (pnd, argv[0]);
nfc_close (pnd);
nfc_exit ();
nfc_exit (NULL);
}
}

View file

@ -67,7 +67,7 @@ intr_hdlr (void)
if (pnd != NULL) {
nfc_close(pnd);
}
nfc_exit ();
nfc_exit (NULL);
exit (EXIT_FAILURE);
}
@ -180,10 +180,10 @@ main (int argc, char *argv[])
signal (SIGINT, (void (*)()) intr_hdlr);
#endif
nfc_init();
nfc_init (NULL);
// Try to open the NFC reader
pnd = nfc_open (NULL);
pnd = nfc_open (NULL, NULL);
// Display libnfc version
acLibnfcVersion = nfc_version ();
@ -269,7 +269,7 @@ main (int argc, char *argv[])
}
nfc_close(pnd);
nfc_exit ();
nfc_exit (NULL);
exit (EXIT_SUCCESS);
}

View file

@ -125,10 +125,10 @@ main (int argc, char *argv[])
signal (SIGINT, (void (*)()) intr_hdlr);
#endif
nfc_init ();
nfc_init (NULL);
// Try to open the NFC device
pnd = nfc_open (NULL);
pnd = nfc_open (NULL, NULL);
if (pnd == NULL) {
printf ("Unable to open NFC device\n");
@ -219,11 +219,11 @@ main (int argc, char *argv[])
}
}
nfc_close (pnd);
nfc_exit ();
nfc_exit (NULL);
exit (EXIT_SUCCESS);
error:
nfc_close (pnd);
nfc_exit ();
nfc_exit (NULL);
exit (EXIT_FAILURE);
}

View file

@ -103,9 +103,9 @@ main (int argc, const char *argv[])
nfc_target nt;
int res = 0;
nfc_init ();
nfc_init (NULL);
pnd = nfc_open (NULL);
pnd = nfc_open (NULL, NULL);
if (pnd == NULL) {
ERR ("%s", "Unable to open NFC device.");
@ -122,7 +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 ();
nfc_exit (NULL);
exit (EXIT_FAILURE);
}
@ -132,6 +132,6 @@ main (int argc, const char *argv[])
printf ("No target found.\n");
}
nfc_close (pnd);
nfc_exit ();
nfc_exit (NULL);
exit (EXIT_SUCCESS);
}

View file

@ -109,17 +109,17 @@ main (int argc, char *argv[])
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 (szFound < 2) {
ERR ("%zd device found but two opened devices are needed to relay NFC.", szFound);
return EXIT_FAILURE;
}
nfc_init ();
nfc_init (NULL);
// Try to open the NFC emulator device
pndTag = nfc_open (connstrings[0]);
pndTag = nfc_open (NULL, connstrings[0]);
if (pndTag == NULL) {
printf ("Error opening NFC emulator device\n");
return EXIT_FAILURE;
@ -151,7 +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 ();
nfc_exit (NULL);
return EXIT_FAILURE;
}
printf ("%s", "Configuring emulator settings...");
@ -163,7 +163,7 @@ main (int argc, char *argv[])
printf ("%s", "Done, emulated tag is initialized");
// Try to open the NFC reader
pndReader = nfc_open (connstrings[1]);
pndReader = nfc_open (NULL, connstrings[1]);
printf ("NFC reader device: %s opened", nfc_device_get_name (pndReader));
printf ("%s", "Configuring NFC reader settings...");
@ -221,6 +221,6 @@ main (int argc, char *argv[])
nfc_close (pndTag);
nfc_close (pndReader);
nfc_exit ();
nfc_exit (NULL);
exit (EXIT_SUCCESS);
}

View file

@ -68,21 +68,21 @@ main (int argc, const char *argv[])
errx (1, "usage: %s", argv[0]);
}
nfc_init();
nfc_init (NULL);
// 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 (connstrings, MAX_DEVICE_COUNT);
size_t szFound = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
if (szFound == 0) {
printf ("No NFC device found.\n");
}
for (i = 0; i < szFound; i++) {
pnd = nfc_open (connstrings[i]);
pnd = nfc_open (NULL, connstrings[i]);
if (pnd == NULL) {
ERR ("%s", "Unable to open NFC device.");

View file

@ -77,14 +77,14 @@ main (int argc, const char *argv[])
(void) argc;
(void) argv;
nfc_init ();
nfc_init (NULL);
// Display libnfc version
const char *acLibnfcVersion = nfc_version ();
printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
// Open using the first available NFC device
pnd = nfc_open (NULL);
pnd = nfc_open (NULL, NULL);
if (pnd == NULL) {
ERR ("%s", "Unable to open NFC device.");
@ -193,7 +193,7 @@ main (int argc, const char *argv[])
// Close NFC device
nfc_close (pnd);
nfc_exit ();
nfc_exit (NULL);
exit (EXIT_SUCCESS);
}

View file

@ -86,10 +86,10 @@ int main(int argc, const 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 ("%s", "Unable to open NFC device.");
@ -200,6 +200,6 @@ int main(int argc, const char* argv[])
fclose(input);
}
nfc_close(pnd);
nfc_exit ();
nfc_exit (NULL);
return 1;
}