nfc_list_devices() function returns now the number of devices found.
This commit is contained in:
parent
00818e048c
commit
1ec504e163
12 changed files with 23 additions and 34 deletions
|
@ -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
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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" */
|
||||
|
|
21
libnfc/nfc.c
21
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
}
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
||||
|
|
|
@ -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");
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in a new issue