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_device *pnd;
nfc_target nt; nfc_target nt;
nfc_init(); nfc_init (NULL);
// Display libnfc version // Display libnfc version
const char *acLibnfcVersion = nfc_version (); const char *acLibnfcVersion = nfc_version ();
printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
// Open, using the first available NFC device // Open, using the first available NFC device
pnd = nfc_open (NULL); pnd = nfc_open (NULL, NULL);
if (pnd == NULL) { if (pnd == NULL) {
ERR ("%s", "Unable to open NFC device."); ERR ("%s", "Unable to open NFC device.");
@ -55,6 +55,6 @@ main (int argc, const char *argv[])
} }
// Close NFC device // Close NFC device
nfc_close (pnd); nfc_close (pnd);
nfc_exit (); nfc_exit (NULL);
return EXIT_SUCCESS; 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 // Try to open the NFC reader
pnd = nfc_open (NULL); pnd = nfc_open (NULL, NULL);
if (!pnd) { if (!pnd) {
printf ("Error opening NFC reader\n"); printf ("Error opening NFC reader\n");
@ -186,7 +186,7 @@ main (int argc, char *argv[])
if (!transmit_bits (abtReqa, 7)) { if (!transmit_bits (abtReqa, 7)) {
printf ("Error: No tag available\n"); printf ("Error: No tag available\n");
nfc_close (pnd); nfc_close (pnd);
nfc_exit (); nfc_exit (NULL);
return 1; return 1;
} }
memcpy (abtAtqa, abtRx, 2); memcpy (abtAtqa, abtRx, 2);
@ -316,6 +316,6 @@ main (int argc, char *argv[])
} }
nfc_close (pnd); nfc_close (pnd);
nfc_exit (); nfc_exit (NULL);
return 0; return 0;
} }

View file

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

View file

@ -66,16 +66,16 @@ main (int argc, const char *argv[])
uint8_t abtTx[] = "Hello Mars!"; uint8_t abtTx[] = "Hello Mars!";
#define MAX_DEVICE_COUNT 2 #define MAX_DEVICE_COUNT 2
nfc_connstring connstrings[MAX_DEVICE_COUNT]; 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 // Little hack to allow using nfc-dep-initiator & nfc-dep-target from
// the same machine: if there is more than one readers opened // the same machine: if there is more than one readers opened
// nfc-dep-target will open the second reader // nfc-dep-target will open the second reader
// (we hope they're always detected in the same order) // (we hope they're always detected in the same order)
nfc_init (); nfc_init (NULL);
if (szDeviceFound == 1) { if (szDeviceFound == 1) {
pnd = nfc_open (connstrings[0]); pnd = nfc_open (NULL, connstrings[0]);
} else if (szDeviceFound > 1) { } else if (szDeviceFound > 1) {
pnd = nfc_open (connstrings[1]); pnd = nfc_open (NULL, connstrings[1]);
} else { } else {
printf("No device found.\n"); printf("No device found.\n");
return EXIT_FAILURE; return EXIT_FAILURE;
@ -141,6 +141,6 @@ main (int argc, const char *argv[])
error: error:
nfc_close (pnd); nfc_close (pnd);
nfc_exit (); nfc_exit (NULL);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -32,6 +32,8 @@
# include <stdbool.h> # include <stdbool.h>
# include <stdio.h> # include <stdio.h>
typedef void *nfc_context;
/** /**
* NFC device * NFC device
*/ */

View file

@ -63,15 +63,15 @@ extern "C" {
# endif // __cplusplus # endif // __cplusplus
/* Library initialization/deinitialization */ /* Library initialization/deinitialization */
NFC_EXPORT void nfc_init(); NFC_EXPORT void nfc_init(nfc_context *context);
NFC_EXPORT void nfc_exit(); NFC_EXPORT void nfc_exit(nfc_context *context);
/* NFC Device/Hardware manipulation */ /* NFC Device/Hardware manipulation */
NFC_EXPORT bool nfc_get_default_device (nfc_connstring *connstring); NFC_EXPORT bool nfc_get_default_device (nfc_connstring *connstring);
NFC_EXPORT nfc_device *nfc_open (const nfc_connstring connstring); NFC_EXPORT nfc_device *nfc_open (nfc_context *context, const nfc_connstring connstring);
NFC_EXPORT void nfc_close (nfc_device *pnd); NFC_EXPORT void nfc_close (nfc_device *pnd);
NFC_EXPORT int nfc_abort_command (nfc_device *pnd); NFC_EXPORT int nfc_abort_command (nfc_device *pnd);
NFC_EXPORT size_t nfc_list_devices (nfc_connstring connstrings[], size_t connstrings_len); NFC_EXPORT size_t nfc_list_devices (nfc_context *context, nfc_connstring connstrings[], size_t connstrings_len);
NFC_EXPORT int nfc_idle (nfc_device *pnd); NFC_EXPORT int nfc_idle (nfc_device *pnd);
/* NFC initiator: act as "reader" */ /* NFC initiator: act as "reader" */

View file

@ -64,9 +64,10 @@ const struct nfc_driver *nfc_drivers[] = {
/** /**
* @brief Initialize libnfc. * @brief Initialize libnfc.
* This function must be called before calling any other libnfc function * This function must be called before calling any other libnfc function
* @param context Optional output location for context pointer
*/ */
void void
nfc_init() nfc_init(nfc_context *context)
{ {
log_init (); log_init ();
} }
@ -74,9 +75,10 @@ nfc_init()
/** /**
* @brief Deinitialize libnfc. * @brief Deinitialize libnfc.
* Should be called after closing all open devices and before your application terminates. * Should be called after closing all open devices and before your application terminates.
*@param context The context to deinitialize
*/ */
void void
nfc_exit() nfc_exit(nfc_context *context)
{ {
log_fini (); log_fini ();
} }
@ -102,7 +104,7 @@ nfc_get_default_device (nfc_connstring *connstring)
if (NULL == env_default_connstring) { if (NULL == env_default_connstring) {
// LIBNFC_DEFAULT_DEVICE is not set, we fallback on probing for the first available device // LIBNFC_DEFAULT_DEVICE is not set, we fallback on probing for the first available device
nfc_connstring listed_cs[1]; nfc_connstring listed_cs[1];
size_t szDeviceFound = nfc_list_devices (listed_cs, 1); size_t szDeviceFound = nfc_list_devices (NULL, listed_cs, 1);
if (szDeviceFound) { if (szDeviceFound) {
strncpy (*connstring, listed_cs[0], sizeof(nfc_connstring)); strncpy (*connstring, listed_cs[0], sizeof(nfc_connstring));
} else { } else {
@ -131,7 +133,7 @@ nfc_get_default_device (nfc_connstring *connstring)
* optionally followed by manual tuning of the parameters if the default parameters are not suiting your goals. * optionally followed by manual tuning of the parameters if the default parameters are not suiting your goals.
*/ */
nfc_device * nfc_device *
nfc_open (const nfc_connstring connstring) nfc_open (nfc_context *context, const nfc_connstring connstring)
{ {
nfc_device *pnd = NULL; nfc_device *pnd = NULL;
@ -200,7 +202,7 @@ nfc_close (nfc_device *pnd)
* *
*/ */
size_t size_t
nfc_list_devices (nfc_connstring connstrings[] , size_t szDevices) nfc_list_devices (nfc_context *context, nfc_connstring connstrings[] , size_t szDevices)
{ {
size_t szN; size_t szN;
size_t szDeviceFound = 0; size_t szDeviceFound = 0;

View file

@ -17,23 +17,23 @@ test_access_storm (void)
nfc_connstring connstrings[MAX_DEVICE_COUNT]; nfc_connstring connstrings[MAX_DEVICE_COUNT];
int res = 0; int res = 0;
nfc_init (); nfc_init (NULL);
size_t ref_device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); size_t ref_device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
if (!ref_device_count) if (!ref_device_count)
cut_omit ("No NFC device found"); cut_omit ("No NFC device found");
while (n) { while (n) {
size_t i; size_t i;
size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count")); cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count"));
for (i = 0; i < device_count; i++) { for (i = 0; i < device_count; i++) {
nfc_device *device; nfc_device *device;
nfc_target ant[MAX_TARGET_COUNT]; nfc_target ant[MAX_TARGET_COUNT];
device = nfc_open (connstrings[i]); device = nfc_open (NULL, connstrings[i]);
cut_assert_not_null (device, cut_message ("nfc_open")); cut_assert_not_null (device, cut_message ("nfc_open"));
res = nfc_initiator_init(device); res = nfc_initiator_init(device);
@ -51,5 +51,5 @@ test_access_storm (void)
n--; n--;
} }
nfc_exit (); nfc_exit (NULL);
} }

View file

@ -27,13 +27,13 @@ abort_test_by_keypress (int sig)
void void
cut_setup (void) cut_setup (void)
{ {
size_t n = nfc_list_devices (connstrings, 2); size_t n = nfc_list_devices (NULL, connstrings, 2);
if (n < 2) { if (n < 2) {
cut_omit ("At least two NFC devices must be plugged-in to run this test"); cut_omit ("At least two NFC devices must be plugged-in to run this test");
} }
nfc_init (); nfc_init (NULL);
devices[TARGET] = nfc_open (connstrings[TARGET]); devices[TARGET] = nfc_open (NULL, connstrings[TARGET]);
devices[INITIATOR] = nfc_open (connstrings[INITIATOR]); devices[INITIATOR] = nfc_open (NULL, connstrings[INITIATOR]);
signal (SIGINT, abort_test_by_keypress); signal (SIGINT, abort_test_by_keypress);
} }
@ -43,7 +43,7 @@ cut_teardown (void)
{ {
nfc_close (devices[TARGET]); nfc_close (devices[TARGET]);
nfc_close (devices[INITIATOR]); nfc_close (devices[INITIATOR]);
nfc_exit (); nfc_exit (NULL);
} }
struct thread_data { struct thread_data {

View file

@ -26,14 +26,14 @@ abort_test_by_keypress (int sig)
void void
cut_setup (void) cut_setup (void)
{ {
size_t n = nfc_list_devices (connstrings, 2); size_t n = nfc_list_devices (NULL, connstrings, 2);
if (n < 2) { if (n < 2) {
cut_omit ("At least two NFC devices must be plugged-in to run this test"); cut_omit ("At least two NFC devices must be plugged-in to run this test");
} }
nfc_init (); nfc_init (NULL);
devices[TARGET] = nfc_open (connstrings[TARGET]); devices[TARGET] = nfc_open (NULL, connstrings[TARGET]);
devices[INITIATOR] = nfc_open (connstrings[INITIATOR]); devices[INITIATOR] = nfc_open (NULL, connstrings[INITIATOR]);
signal (SIGINT, abort_test_by_keypress); signal (SIGINT, abort_test_by_keypress);
} }
@ -43,7 +43,7 @@ cut_teardown (void)
{ {
nfc_close (devices[TARGET]); nfc_close (devices[TARGET]);
nfc_close (devices[INITIATOR]); nfc_close (devices[INITIATOR]);
nfc_exit (); nfc_exit (NULL);
} }
struct thread_data { struct thread_data {

View file

@ -24,14 +24,14 @@ abort_test_by_keypress (int sig)
void void
cut_setup (void) cut_setup (void)
{ {
size_t n = nfc_list_devices (connstrings, 2); size_t n = nfc_list_devices (NULL, connstrings, 2);
if (n < 2) { if (n < 2) {
cut_omit ("At least two NFC devices must be plugged-in to run this test"); cut_omit ("At least two NFC devices must be plugged-in to run this test");
} }
nfc_init (); nfc_init (NULL);
second_device = nfc_open (connstrings[0]); second_device = nfc_open (NULL, connstrings[0]);
first_device = nfc_open (connstrings[1]); first_device = nfc_open (NULL, connstrings[1]);
signal (SIGINT, abort_test_by_keypress); signal (SIGINT, abort_test_by_keypress);
} }
@ -41,7 +41,7 @@ cut_teardown (void)
{ {
nfc_close (second_device); nfc_close (second_device);
nfc_close (first_device); nfc_close (first_device);
nfc_exit (); nfc_exit (NULL);
} }
struct thread_data { struct thread_data {

View file

@ -12,15 +12,15 @@ test_register_endianness (void)
nfc_connstring connstrings[MAX_DEVICE_COUNT]; nfc_connstring connstrings[MAX_DEVICE_COUNT];
int res = 0; int res = 0;
nfc_init (); nfc_init (NULL);
size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
if (!device_count) if (!device_count)
cut_omit ("No NFC device found"); cut_omit ("No NFC device found");
nfc_device *device; nfc_device *device;
device = nfc_open (connstrings[0]); device = nfc_open (NULL, connstrings[0]);
cut_assert_not_null (device, cut_message ("nfc_open")); cut_assert_not_null (device, cut_message ("nfc_open"));
uint8_t value; uint8_t value;
@ -44,5 +44,5 @@ test_register_endianness (void)
cut_assert_equal_uint (0x55, value, cut_message ("check register value")); cut_assert_equal_uint (0x55, value, cut_message ("check register value"));
nfc_close (device); nfc_close (device);
nfc_exit (); nfc_exit (NULL);
} }

View file

@ -13,15 +13,15 @@ test_register_endianness (void)
nfc_connstring connstrings[MAX_DEVICE_COUNT]; nfc_connstring connstrings[MAX_DEVICE_COUNT];
int res = 0; int res = 0;
nfc_init (); nfc_init (NULL);
size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); size_t device_count = nfc_list_devices (NULL, connstrings, MAX_DEVICE_COUNT);
if (!device_count) if (!device_count)
cut_omit ("No NFC device found"); cut_omit ("No NFC device found");
nfc_device *device; nfc_device *device;
device = nfc_open (connstrings[0]); device = nfc_open (NULL, connstrings[0]);
cut_assert_not_null (device, cut_message ("nfc_open")); cut_assert_not_null (device, cut_message ("nfc_open"));
uint8_t value; uint8_t value;
@ -35,5 +35,5 @@ test_register_endianness (void)
cut_assert_equal_int (0, res, cut_message ("read register 0xFFF0")); cut_assert_equal_int (0, res, cut_message ("read register 0xFFF0"));
nfc_close (device); nfc_close (device);
nfc_exit (); nfc_exit (NULL);
} }

View file

@ -346,10 +346,10 @@ main (int argc, char *argv[])
} }
} }
nfc_init (); nfc_init (NULL);
// Try to open the NFC reader // Try to open the NFC reader
pnd = nfc_open (NULL); pnd = nfc_open (NULL, NULL);
if (pnd == NULL) { if (pnd == NULL) {
ERR("Unable to open NFC device"); ERR("Unable to open NFC device");
@ -373,6 +373,6 @@ main (int argc, char *argv[])
} }
} }
nfc_exit (); nfc_exit (NULL);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }

View file

@ -75,7 +75,7 @@ main (int argc, const char *argv[])
bool verbose = false; bool verbose = false;
int res = 0; int res = 0;
nfc_init (); nfc_init (NULL);
// Display libnfc version // Display libnfc version
acLibnfcVersion = nfc_version (); acLibnfcVersion = nfc_version ();
@ -97,7 +97,7 @@ main (int argc, const char *argv[])
/* Lazy way to open an NFC device */ /* Lazy way to open an NFC device */
#if 0 #if 0
pnd = nfc_open (NULL); pnd = nfc_open (NULL, NULL);
#endif #endif
/* If specific device is wanted, i.e. an ARYGON device on /dev/ttyUSB0 */ /* 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.pcDriver = "ARYGON";
ndd.pcPort = "/dev/ttyUSB0"; ndd.pcPort = "/dev/ttyUSB0";
ndd.uiSpeed = 115200; ndd.uiSpeed = 115200;
pnd = nfc_open (&ndd); pnd = nfc_open (NULL, &ndd);
#endif #endif
/* If specific device is wanted, i.e. a SCL3711 on USB */ /* 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; nfc_device_desc_t ndd;
ndd.pcDriver = "PN533_USB"; ndd.pcDriver = "PN533_USB";
strcpy(ndd.acDevice, "SCM Micro / SCL3711-NFC&RW"); strcpy(ndd.acDevice, "SCM Micro / SCL3711-NFC&RW");
pnd = nfc_open (&ndd); pnd = nfc_open (NULL, &ndd);
#endif #endif
nfc_connstring connstrings[MAX_DEVICE_COUNT]; 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) { if (szDeviceFound == 0) {
printf ("No NFC device found.\n"); printf ("No NFC device found.\n");
@ -125,7 +125,7 @@ main (int argc, const char *argv[])
for (i = 0; i < szDeviceFound; i++) { for (i = 0; i < szDeviceFound; i++) {
nfc_target ant[MAX_TARGET_COUNT]; nfc_target ant[MAX_TARGET_COUNT];
pnd = nfc_open (connstrings[i]); pnd = nfc_open (NULL, connstrings[i]);
if (pnd == NULL) { if (pnd == NULL) {
ERR ("%s", "Unable to open NFC device."); ERR ("%s", "Unable to open NFC device.");
@ -252,6 +252,6 @@ main (int argc, const char *argv[])
nfc_close (pnd); nfc_close (pnd);
} }
nfc_exit (); nfc_exit (NULL);
return 0; return 0;
} }

View file

@ -537,10 +537,10 @@ main (int argc, const char *argv[])
} }
// printf("Successfully opened required files\n"); // printf("Successfully opened required files\n");
nfc_init (); nfc_init (NULL);
// Try to open the NFC reader // Try to open the NFC reader
pnd = nfc_open (NULL); pnd = nfc_open (NULL, NULL);
if (pnd == NULL) { if (pnd == NULL) {
printf ("Error opening NFC reader\n"); printf ("Error opening NFC reader\n");
exit (EXIT_FAILURE); 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) { if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) {
printf ("Error: no tag was found\n"); printf ("Error: no tag was found\n");
nfc_close (pnd); nfc_close (pnd);
nfc_exit (); nfc_exit (NULL);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
// Test if we are dealing with a MIFARE compatible tag // 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); 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 // Try to open the NFC reader
pnd = nfc_open (NULL); pnd = nfc_open (NULL, NULL);
if (!pnd) { if (!pnd) {
printf ("Error opening NFC reader\n"); printf ("Error opening NFC reader\n");
@ -215,7 +215,7 @@ main (int argc, char *argv[])
if (!transmit_bits (abtReqa, 7)) { if (!transmit_bits (abtReqa, 7)) {
printf ("Error: No tag available\n"); printf ("Error: No tag available\n");
nfc_close (pnd); nfc_close (pnd);
nfc_exit (); nfc_exit (NULL);
return 1; return 1;
} }
memcpy (abtAtqa, abtRx, 2); memcpy (abtAtqa, abtRx, 2);
@ -354,6 +354,6 @@ main (int argc, char *argv[])
nfc_close (pnd); nfc_close (pnd);
nfc_exit (); nfc_exit (NULL);
return 0; return 0;
} }

View file

@ -204,10 +204,10 @@ main (int argc, const char *argv[])
} }
DBG ("Successfully opened the dump file\n"); DBG ("Successfully opened the dump file\n");
nfc_init (); nfc_init (NULL);
// Try to open the NFC device // Try to open the NFC device
pnd = nfc_open (NULL); pnd = nfc_open (NULL, NULL);
if (pnd == NULL) { if (pnd == NULL) {
ERR ("Error opening NFC device\n"); ERR ("Error opening NFC device\n");
return 1; return 1;
@ -230,7 +230,7 @@ main (int argc, const char *argv[])
if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) { if (nfc_initiator_select_passive_target (pnd, nmMifare, NULL, 0, &nt) < 0) {
ERR ("no tag was found\n"); ERR ("no tag was found\n");
nfc_close (pnd); nfc_close (pnd);
nfc_exit (); nfc_exit (NULL);
return 1; return 1;
} }
// Test if we are dealing with a MIFARE compatible tag // 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) { if (nt.nti.nai.abtAtqa[1] != 0x44) {
ERR ("tag is not a MIFARE Ultralight card\n"); ERR ("tag is not a MIFARE Ultralight card\n");
nfc_close (pnd); nfc_close (pnd);
nfc_exit (); nfc_exit (NULL);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// Get the info from the current tag // Get the info from the current tag
@ -270,6 +270,6 @@ main (int argc, const char *argv[])
} }
nfc_close (pnd); nfc_close (pnd);
nfc_exit (); nfc_exit (NULL);
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -74,7 +74,7 @@ main (int argc, const char *argv[])
size_t i; size_t i;
bool verbose = false; bool verbose = false;
nfc_init (); nfc_init (NULL);
// Display libnfc version // Display libnfc version
acLibnfcVersion = nfc_version (); acLibnfcVersion = nfc_version ();
@ -95,7 +95,7 @@ main (int argc, const char *argv[])
#endif #endif
nfc_connstring connstrings[MAX_DEVICE_COUNT]; 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) { if (szDeviceFound == 0) {
printf ("No NFC device found.\n"); printf ("No NFC device found.\n");
@ -103,13 +103,13 @@ main (int argc, const char *argv[])
printf ("%d NFC device(s) found:\n", szDeviceFound); printf ("%d NFC device(s) found:\n", szDeviceFound);
for (i = 0; i < szDeviceFound; i++) { for (i = 0; i < szDeviceFound; i++) {
pnd = nfc_open (connstrings[i]); pnd = nfc_open (NULL, connstrings[i]);
if (pnd != NULL) { if (pnd != NULL) {
printf ("- %s:\n %s\n", nfc_device_get_name (pnd), nfc_device_get_connstring (pnd)); printf ("- %s:\n %s\n", nfc_device_get_name (pnd), nfc_device_get_connstring (pnd));
} }
nfc_close (pnd); nfc_close (pnd);
} }
nfc_exit (); nfc_exit (NULL);
return 0; 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) { if (pnd == NULL) {
ERR("Unable to open NFC device"); ERR("Unable to open NFC device");
@ -317,6 +317,6 @@ error:
if (pnd) { if (pnd) {
nfc_close (pnd); nfc_close (pnd);
} }
nfc_exit (); nfc_exit (NULL);
exit (error); exit (error);
} }

View file

@ -190,11 +190,11 @@ main (int argc, char *argv[])
signal (SIGINT, (void (*)()) intr_hdlr); signal (SIGINT, (void (*)()) intr_hdlr);
#endif #endif
nfc_init (); nfc_init (NULL);
nfc_connstring connstrings[MAX_DEVICE_COUNT]; nfc_connstring connstrings[MAX_DEVICE_COUNT];
// List available devices // 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 (initiator_only_mode || target_only_mode) {
if (szFound < 1) { 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 // if there is more than one readers opened we open the second reader
// (we hope they're always detected in the same order) // (we hope they're always detected in the same order)
if (szFound == 1) { if (szFound == 1) {
pndInitiator = nfc_open (connstrings[0]); pndInitiator = nfc_open (NULL, connstrings[0]);
} else { } else {
pndInitiator = nfc_open (connstrings[1]); pndInitiator = nfc_open (NULL, connstrings[1]);
} }
if (!pndInitiator) { if (!pndInitiator) {
@ -233,7 +233,7 @@ main (int argc, char *argv[])
if (nfc_initiator_init (pndInitiator) < 0) { if (nfc_initiator_init (pndInitiator) < 0) {
printf ("Error: fail initializing initiator\n"); printf ("Error: fail initializing initiator\n");
nfc_close (pndInitiator); nfc_close (pndInitiator);
nfc_exit (); nfc_exit (NULL);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
@ -245,7 +245,7 @@ main (int argc, char *argv[])
if (nfc_initiator_select_passive_target (pndInitiator, nm, NULL, 0, &ntRealTarget) < 0) { if (nfc_initiator_select_passive_target (pndInitiator, nm, NULL, 0, &ntRealTarget) < 0) {
printf ("Error: no tag was found\n"); printf ("Error: no tag was found\n");
nfc_close (pndInitiator); nfc_close (pndInitiator);
nfc_exit (); nfc_exit (NULL);
exit (EXIT_FAILURE); 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) { if (print_hex_fd4(ntRealTarget.nti.nai.abtUid, ntRealTarget.nti.nai.szUidLen, "UID") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing UID to FD4\n"); fprintf (stderr, "Error while printing UID to FD4\n");
nfc_close (pndInitiator); nfc_close (pndInitiator);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (print_hex_fd4(ntRealTarget.nti.nai.abtAtqa, 2, "ATQA") != EXIT_SUCCESS) { if (print_hex_fd4(ntRealTarget.nti.nai.abtAtqa, 2, "ATQA") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing ATQA to FD4\n"); fprintf (stderr, "Error while printing ATQA to FD4\n");
nfc_close (pndInitiator); nfc_close (pndInitiator);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (print_hex_fd4(&(ntRealTarget.nti.nai.btSak), 1, "SAK") != EXIT_SUCCESS) { if (print_hex_fd4(&(ntRealTarget.nti.nai.btSak), 1, "SAK") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing SAK to FD4\n"); fprintf (stderr, "Error while printing SAK to FD4\n");
nfc_close (pndInitiator); nfc_close (pndInitiator);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (print_hex_fd4(ntRealTarget.nti.nai.abtAts, ntRealTarget.nti.nai.szAtsLen, "ATS") != EXIT_SUCCESS) { if (print_hex_fd4(ntRealTarget.nti.nai.abtAts, ntRealTarget.nti.nai.szAtsLen, "ATS") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing ATS to FD4\n"); fprintf (stderr, "Error while printing ATS to FD4\n");
nfc_close (pndInitiator); nfc_close (pndInitiator);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); 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) { if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtUid, &(ntEmulatedTarget.nti.nai.szUidLen), "UID") != EXIT_SUCCESS) {
fprintf (stderr, "Error while scanning UID from FD3\n"); fprintf (stderr, "Error while scanning UID from FD3\n");
nfc_close (pndInitiator); nfc_close (pndInitiator);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAtqa, &foo, "ATQA") != EXIT_SUCCESS) { 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) { if (scan_hex_fd3(&(ntEmulatedTarget.nti.nai.btSak), &foo, "SAK") != EXIT_SUCCESS) {
fprintf (stderr, "Error while scanning SAK from FD3\n"); fprintf (stderr, "Error while scanning SAK from FD3\n");
nfc_close (pndInitiator); nfc_close (pndInitiator);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAts, &(ntEmulatedTarget.nti.nai.szAtsLen), "ATS") != EXIT_SUCCESS) { if (scan_hex_fd3(ntEmulatedTarget.nti.nai.abtAts, &(ntEmulatedTarget.nti.nai.szAtsLen), "ATS") != EXIT_SUCCESS) {
fprintf (stderr, "Error while scanning ATS from FD3\n"); fprintf (stderr, "Error while scanning ATS from FD3\n");
nfc_close (pndInitiator); nfc_close (pndInitiator);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
@ -353,13 +353,13 @@ main (int argc, char *argv[])
print_nfc_iso14443a_info (ntEmulatedTarget.nti.nai, false); print_nfc_iso14443a_info (ntEmulatedTarget.nti.nai, false);
// Try to open the NFC emulator device // Try to open the NFC emulator device
pndTarget = nfc_open (connstrings[0]); pndTarget = nfc_open (NULL, connstrings[0]);
if (pndTarget == NULL) { if (pndTarget == NULL) {
printf ("Error opening NFC emulator device\n"); printf ("Error opening NFC emulator device\n");
if (!target_only_mode) { if (!target_only_mode) {
nfc_close (pndInitiator); nfc_close (pndInitiator);
} }
nfc_exit (); nfc_exit (NULL);
return EXIT_FAILURE; return EXIT_FAILURE;
} }
@ -372,7 +372,7 @@ main (int argc, char *argv[])
nfc_close (pndInitiator); nfc_close (pndInitiator);
} }
nfc_close (pndTarget); nfc_close (pndTarget);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
printf ("%s\n", "Done, relaying frames now!"); printf ("%s\n", "Done, relaying frames now!");
@ -390,7 +390,7 @@ main (int argc, char *argv[])
nfc_close (pndInitiator); nfc_close (pndInitiator);
} }
nfc_close (pndTarget); nfc_close (pndTarget);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
szCapduLen = (size_t) res; szCapduLen = (size_t) res;
@ -398,7 +398,7 @@ main (int argc, char *argv[])
if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) { if (print_hex_fd4(abtCapdu, szCapduLen, "C-APDU") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing C-APDU to FD4\n"); fprintf (stderr, "Error while printing C-APDU to FD4\n");
nfc_close (pndTarget); nfc_close (pndTarget);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -406,7 +406,7 @@ main (int argc, char *argv[])
if (scan_hex_fd3(abtCapdu, &szCapduLen, "C-APDU") != EXIT_SUCCESS) { if (scan_hex_fd3(abtCapdu, &szCapduLen, "C-APDU") != EXIT_SUCCESS) {
fprintf (stderr, "Error while scanning C-APDU from FD3\n"); fprintf (stderr, "Error while scanning C-APDU from FD3\n");
nfc_close (pndInitiator); nfc_close (pndInitiator);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -424,7 +424,7 @@ main (int argc, char *argv[])
if (scan_hex_fd3(abtRapdu, &szRapduLen, "R-APDU") != EXIT_SUCCESS) { if (scan_hex_fd3(abtRapdu, &szRapduLen, "R-APDU") != EXIT_SUCCESS) {
fprintf (stderr, "Error while scanning R-APDU from FD3\n"); fprintf (stderr, "Error while scanning R-APDU from FD3\n");
nfc_close (pndTarget); nfc_close (pndTarget);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
ret = true; ret = true;
@ -451,16 +451,16 @@ main (int argc, char *argv[])
} }
if (!initiator_only_mode) { if (!initiator_only_mode) {
nfc_close (pndTarget); nfc_close (pndTarget);
nfc_exit (); nfc_exit (NULL);
} }
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} else { } else {
if (print_hex_fd4(abtRapdu, szRapduLen, "R-APDU") != EXIT_SUCCESS) { if (print_hex_fd4(abtRapdu, szRapduLen, "R-APDU") != EXIT_SUCCESS) {
fprintf (stderr, "Error while printing R-APDU to FD4\n"); fprintf (stderr, "Error while printing R-APDU to FD4\n");
nfc_close (pndInitiator); nfc_close (pndInitiator);
nfc_exit (); nfc_exit (NULL);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
@ -473,7 +473,7 @@ main (int argc, char *argv[])
if (!initiator_only_mode) { if (!initiator_only_mode) {
nfc_close (pndTarget); nfc_close (pndTarget);
} }
nfc_exit (); nfc_exit (NULL);
exit (EXIT_SUCCESS); exit (EXIT_SUCCESS);
} }