diff --git a/examples/nfc-dep-target.c b/examples/nfc-dep-target.c index b2e8570..aa19ef2 100644 --- a/examples/nfc-dep-target.c +++ b/examples/nfc-dep-target.c @@ -63,11 +63,10 @@ main (int argc, const char *argv[]) { uint8_t abtRx[MAX_FRAME_LEN]; int szRx; - size_t szDeviceFound; uint8_t abtTx[] = "Hello Mars!"; #define MAX_DEVICE_COUNT 2 nfc_connstring connstrings[MAX_DEVICE_COUNT]; - nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &szDeviceFound); + size_t szDeviceFound = nfc_list_devices (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 connected // nfc-dep-target will connect to the second reader diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index 5492ed8..9cb7a54 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -82,7 +82,6 @@ main (int argc, char *argv[]) { int arg; bool quiet_output = false; - size_t szFound; const char *acLibnfcVersion = nfc_version (); // Get commandline options @@ -110,7 +109,7 @@ main (int argc, char *argv[]) nfc_connstring connstrings[MAX_DEVICE_COUNT]; // List available devices - nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &szFound); + size_t szFound = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); if (szFound < 2) { ERR ("%zd device found but two connected devices are needed to relay NFC.", szFound); diff --git a/examples/pn53x-diagnose.c b/examples/pn53x-diagnose.c index 49e9c3e..649f6e9 100644 --- a/examples/pn53x-diagnose.c +++ b/examples/pn53x-diagnose.c @@ -52,7 +52,6 @@ int main (int argc, const char *argv[]) { - size_t szFound; size_t i; nfc_device *pnd; const char *acLibnfcVersion; @@ -73,7 +72,7 @@ main (int argc, const char *argv[]) printf ("%s uses libnfc %s\n", argv[0], acLibnfcVersion); nfc_connstring connstrings[MAX_DEVICE_COUNT]; - nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &szFound); + size_t szFound = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); if (szFound == 0) { printf ("No NFC device found.\n"); diff --git a/include/nfc/nfc.h b/include/nfc/nfc.h index de709e5..9993e2d 100644 --- a/include/nfc/nfc.h +++ b/include/nfc/nfc.h @@ -67,7 +67,7 @@ extern "C" { NFC_EXPORT nfc_device *nfc_connect (const nfc_connstring connstring); NFC_EXPORT void nfc_disconnect (nfc_device *pnd); NFC_EXPORT int nfc_abort_command (nfc_device *pnd); - NFC_EXPORT void nfc_list_devices (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound); + NFC_EXPORT size_t nfc_list_devices (nfc_connstring connstrings[], size_t connstrings_len); NFC_EXPORT int nfc_idle (nfc_device *pnd); /* NFC initiator: act as "reader" */ diff --git a/libnfc/nfc.c b/libnfc/nfc.c index a7dd02f..7c96e2b 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -81,9 +81,8 @@ nfc_get_default_device (nfc_connstring *connstring) char *env_default_connstring = getenv ("LIBNFC_DEFAULT_DEVICE"); if (NULL == env_default_connstring) { // LIBNFC_DEFAULT_DEVICE is not set, we fallback on probing for the first available device - size_t szDeviceFound; nfc_connstring listed_cs[1]; - nfc_list_devices (listed_cs, 1, &szDeviceFound); + size_t szDeviceFound = nfc_list_devices (listed_cs, 1); if (szDeviceFound) { strncpy (*connstring, listed_cs[0], sizeof(nfc_connstring)); } else { @@ -177,30 +176,32 @@ nfc_disconnect (nfc_device *pnd) /** * @brief Probe for discoverable supported devices (ie. only available for some drivers) + * @return Returns the number of devices found. * @param[out] pnddDevices array of \a nfc_device_desc_t previously allocated by the caller. * @param szDevices size of the \a pnddDevices array. - * @param[out] pszDeviceFound number of devices found. + * */ -void -nfc_list_devices (nfc_connstring connstrings[] , size_t szDevices, size_t *pszDeviceFound) +size_t +nfc_list_devices (nfc_connstring connstrings[] , size_t szDevices) { - size_t szN; - *pszDeviceFound = 0; + size_t szN; + size_t szDeviceFound = 0; const struct nfc_driver_t *ndr; const struct nfc_driver_t **pndr = nfc_drivers; log_init (); while ((ndr = *pndr)) { szN = 0; - if (ndr->probe (connstrings + (*pszDeviceFound), szDevices - (*pszDeviceFound), &szN)) { - *pszDeviceFound += szN; + if (ndr->probe (connstrings + (szDeviceFound), szDevices - (szDeviceFound), &szN)) { + szDeviceFound += szN; log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "%ld device(s) found using %s driver", (unsigned long) szN, ndr->name); - if (*pszDeviceFound == szDevices) + if (szDeviceFound == szDevices) break; } pndr++; } log_fini (); + return szDeviceFound; } /** diff --git a/test/test_access_storm.c b/test/test_access_storm.c index 2646e21..94a671a 100644 --- a/test/test_access_storm.c +++ b/test/test_access_storm.c @@ -15,17 +15,16 @@ test_access_storm (void) { int n = NTESTS; nfc_connstring connstrings[MAX_DEVICE_COUNT]; - size_t device_count, ref_device_count; int res = 0; - nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &ref_device_count); + size_t ref_device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); if (!ref_device_count) cut_omit ("No NFC device found"); while (n) { size_t i; - nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &device_count); + size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count")); for (i = 0; i < device_count; i++) { diff --git a/test/test_dep_active.c b/test/test_dep_active.c index b0e1b76..4a984fd 100644 --- a/test/test_dep_active.c +++ b/test/test_dep_active.c @@ -27,9 +27,7 @@ abort_test_by_keypress (int sig) void cut_setup (void) { - size_t n; - - nfc_list_devices (connstrings, 2, &n); + size_t n = nfc_list_devices (connstrings, 2); if (n < 2) { cut_omit ("At least two NFC devices must be plugged-in to run this test"); } diff --git a/test/test_dep_passive.c b/test/test_dep_passive.c index 42d2b7f..b300594 100644 --- a/test/test_dep_passive.c +++ b/test/test_dep_passive.c @@ -26,9 +26,7 @@ abort_test_by_keypress (int sig) void cut_setup (void) { - size_t n; - - nfc_list_devices (connstrings, 2, &n); + size_t n = nfc_list_devices (connstrings, 2); if (n < 2) { cut_omit ("At least two NFC devices must be plugged-in to run this test"); } diff --git a/test/test_register_access.c b/test/test_register_access.c index 9b57222..bf72375 100644 --- a/test/test_register_access.c +++ b/test/test_register_access.c @@ -10,10 +10,9 @@ void test_register_endianness (void) { nfc_connstring connstrings[MAX_DEVICE_COUNT]; - size_t device_count; int res = 0; - nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &device_count); + size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); if (!device_count) cut_omit ("No NFC device found"); diff --git a/test/test_register_endianness.c b/test/test_register_endianness.c index 150c840..b82b9fb 100644 --- a/test/test_register_endianness.c +++ b/test/test_register_endianness.c @@ -11,10 +11,9 @@ void test_register_endianness (void) { nfc_connstring connstrings[MAX_DEVICE_COUNT]; - size_t device_count; int res = 0; - nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &device_count); + size_t device_count = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); if (!device_count) cut_omit ("No NFC device found"); diff --git a/utils/nfc-list.c b/utils/nfc-list.c index 5508d9c..d8acd07 100644 --- a/utils/nfc-list.c +++ b/utils/nfc-list.c @@ -114,9 +114,8 @@ main (int argc, const char *argv[]) strcpy(ndd.acDevice, "SCM Micro / SCL3711-NFC&RW"); pnd = nfc_connect (&ndd); #endif - size_t szDeviceFound; nfc_connstring connstrings[MAX_DEVICE_COUNT]; - nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &szDeviceFound); + size_t szDeviceFound = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); if (szDeviceFound == 0) { printf ("No NFC device found.\n"); diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index ba89e41..932ad84 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -149,7 +149,6 @@ int main (int argc, char *argv[]) { int arg; - size_t szFound; const char *acLibnfcVersion = nfc_version (); nfc_target ntRealTarget; @@ -193,7 +192,7 @@ main (int argc, char *argv[]) nfc_connstring connstrings[MAX_DEVICE_COUNT]; // List available devices - nfc_list_devices (connstrings, MAX_DEVICE_COUNT, &szFound); + size_t szFound = nfc_list_devices (connstrings, MAX_DEVICE_COUNT); if (initiator_only_mode || target_only_mode) { if (szFound < 1) {