Use a more appropriated term regarding device detection: from probe to scan

- Rename nfc-probe to nfc-scan-device
 - Rename internal drivers function prototypes: _probe to _scan
 - Revamp _scan function prototype: it now returns device found count
This commit is contained in:
Romuald Conty 2012-10-21 14:11:17 +00:00
parent 6bc9d64fbb
commit b5aa91fd62
10 changed files with 90 additions and 105 deletions

View file

@ -135,15 +135,14 @@ acr122_pcsc_free_scardcontext(void)
/** /**
* @brief List opened devices * @brief List opened devices
* *
* Probe PCSC to find NFC capable hardware. * Probe PCSC to find ACR122 devices (ACR122U and Touchatag/Tikitag).
* *
* @param pnddDevices Array of nfc_device_desc_t previously allocated by the caller. * @param connstring array of nfc_connstring where found device's connection strings will be stored.
* @param szDevices size of the pnddDevices array. * @param connstrings_len size of connstrings array.
* @param pszDeviceFound number of devices found. * @return number of devices found.
* @return true if succeeded, false otherwise.
*/ */
static bool static size_t
acr122_pcsc_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound) acr122_pcsc_scan(nfc_connstring connstrings[], const size_t connstrings_len)
{ {
size_t szPos = 0; size_t szPos = 0;
char acDeviceNames[256 + 64 * PCSC_MAX_DEVICES]; char acDeviceNames[256 + 64 * PCSC_MAX_DEVICES];
@ -155,22 +154,18 @@ acr122_pcsc_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *
// Clear the reader list // Clear the reader list
memset(acDeviceNames, '\0', szDeviceNamesLen); memset(acDeviceNames, '\0', szDeviceNamesLen);
*pszDeviceFound = 0;
// Test if context succeeded // Test if context succeeded
if (!(pscc = acr122_pcsc_get_scardcontext())) { if (!(pscc = acr122_pcsc_get_scardcontext())) {
log_put(LOG_CATEGORY, NFC_PRIORITY_WARN, "%s", "PCSC context not found (make sure PCSC daemon is running)."); log_put(LOG_CATEGORY, NFC_PRIORITY_WARN, "%s", "PCSC context not found (make sure PCSC daemon is running).");
return false; return 0;
} }
// Retrieve the string array of all available pcsc readers // Retrieve the string array of all available pcsc readers
DWORD dwDeviceNamesLen = szDeviceNamesLen; DWORD dwDeviceNamesLen = szDeviceNamesLen;
if (SCardListReaders(*pscc, NULL, acDeviceNames, &dwDeviceNamesLen) != SCARD_S_SUCCESS) if (SCardListReaders(*pscc, NULL, acDeviceNames, &dwDeviceNamesLen) != SCARD_S_SUCCESS)
return false; return 0;
while ((acDeviceNames[szPos] != '\0') && ((*pszDeviceFound) < connstrings_len)) {
// DBG("- %s (pos=%ld)", acDeviceNames + szPos, (unsigned long) szPos);
size_t device_found = 0;
while ((acDeviceNames[szPos] != '\0') && (device_found < connstrings_len)) {
bSupported = false; bSupported = false;
for (i = 0; supported_devices[i] && !bSupported; i++) { for (i = 0; supported_devices[i] && !bSupported; i++) {
int l = strlen(supported_devices[i]); int l = strlen(supported_devices[i]);
@ -179,8 +174,8 @@ acr122_pcsc_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *
if (bSupported) { if (bSupported) {
// Supported ACR122 device found // Supported ACR122 device found
snprintf(connstrings[*pszDeviceFound], sizeof(nfc_connstring), "%s:%s", ACR122_PCSC_DRIVER_NAME, acDeviceNames + szPos); snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s", ACR122_PCSC_DRIVER_NAME, acDeviceNames + szPos);
(*pszDeviceFound)++; device_found++;
} else { } else {
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "PCSC device [%s] is not NFC capable or not supported by libnfc.", acDeviceNames + szPos); log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "PCSC device [%s] is not NFC capable or not supported by libnfc.", acDeviceNames + szPos);
} }
@ -190,7 +185,7 @@ acr122_pcsc_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *
} }
acr122_pcsc_free_scardcontext(); acr122_pcsc_free_scardcontext();
return true; return device_found;
} }
struct acr122_pcsc_descriptor { struct acr122_pcsc_descriptor {
@ -248,8 +243,7 @@ acr122_pcsc_open(const nfc_connstring connstring)
nfc_connstring fullconnstring; nfc_connstring fullconnstring;
if (connstring_decode_level == 1) { if (connstring_decode_level == 1) {
// Device was not specified, take the first one we can find // Device was not specified, take the first one we can find
size_t szDeviceFound; size_t szDeviceFound = acr122_pcsc_scan(&fullconnstring, 1);
acr122_pcsc_probe(&fullconnstring, 1, &szDeviceFound);
if (szDeviceFound < 1) if (szDeviceFound < 1)
return NULL; return NULL;
connstring_decode_level = acr122_pcsc_connstring_decode(fullconnstring, &ndd); connstring_decode_level = acr122_pcsc_connstring_decode(fullconnstring, &ndd);
@ -265,8 +259,7 @@ acr122_pcsc_open(const nfc_connstring connstring)
if (sscanf(ndd.pcsc_device_name, "%lu", &index) != 1) if (sscanf(ndd.pcsc_device_name, "%lu", &index) != 1)
return NULL; return NULL;
nfc_connstring *ncs = malloc(sizeof(nfc_connstring) * (index + 1)); nfc_connstring *ncs = malloc(sizeof(nfc_connstring) * (index + 1));
size_t szDeviceFound; size_t szDeviceFound = acr122_pcsc_scan(ncs, index + 1);
acr122_pcsc_probe(ncs, index + 1, &szDeviceFound);
if (szDeviceFound < index + 1) if (szDeviceFound < index + 1)
return NULL; return NULL;
strncpy(fullconnstring, ncs[index], sizeof(nfc_connstring)); strncpy(fullconnstring, ncs[index], sizeof(nfc_connstring));
@ -491,7 +484,7 @@ const struct pn53x_io acr122_pcsc_io = {
const struct nfc_driver acr122_pcsc_driver = { const struct nfc_driver acr122_pcsc_driver = {
.name = ACR122_PCSC_DRIVER_NAME, .name = ACR122_PCSC_DRIVER_NAME,
.probe = acr122_pcsc_probe, .scan = acr122_pcsc_scan,
.open = acr122_pcsc_open, .open = acr122_pcsc_open,
.close = acr122_pcsc_close, .close = acr122_pcsc_close,
.strerror = pn53x_strerror, .strerror = pn53x_strerror,

View file

@ -303,8 +303,8 @@ acr122_usb_get_end_points(struct usb_device *dev, struct acr122_usb_data *data)
} }
} }
static bool static size_t
acr122_usb_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *device_found) acr122_usb_scan(nfc_connstring connstrings[], const size_t connstrings_len)
{ {
usb_init(); usb_init();
@ -314,17 +314,17 @@ acr122_usb_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *d
// busses and busses removed). // busses and busses removed).
if ((res = usb_find_busses() < 0)) { if ((res = usb_find_busses() < 0)) {
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror(res)); log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror(res));
return false; return 0;
} }
// usb_find_devices will find all of the devices on each bus. This should be // usb_find_devices will find all of the devices on each bus. This should be
// called after usb_find_busses. Returns the number of changes since the // called after usb_find_busses. Returns the number of changes since the
// previous call to this function (total of new device and devices removed). // previous call to this function (total of new device and devices removed).
if ((res = usb_find_devices() < 0)) { if ((res = usb_find_devices() < 0)) {
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror(res)); log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror(res));
return false; return 0;
} }
*device_found = 0; size_t device_found = 0;
uint32_t uiBusIndex = 0; uint32_t uiBusIndex = 0;
struct usb_bus *bus; struct usb_bus *bus;
@ -349,21 +349,21 @@ acr122_usb_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *d
usb_dev_handle *udev = usb_open(dev); usb_dev_handle *udev = usb_open(dev);
// Set configuration // Set configuration
// acr122_usb_get_usb_device_name (dev, udev, pnddDevices[*device_found].acDevice, sizeof (pnddDevices[*device_found].acDevice)); // acr122_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice));
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "device found: Bus %s Device %s Name %s", bus->dirname, dev->filename, acr122_usb_supported_devices[n].name); log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "device found: Bus %s Device %s Name %s", bus->dirname, dev->filename, acr122_usb_supported_devices[n].name);
usb_close(udev); usb_close(udev);
snprintf(connstrings[*device_found], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename); snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", ACR122_USB_DRIVER_NAME, bus->dirname, dev->filename);
(*device_found)++; device_found++;
// Test if we reach the maximum "wanted" devices // Test if we reach the maximum "wanted" devices
if ((*device_found) == connstrings_len) { if (device_found == connstrings_len) {
return true; return device_found;
} }
} }
} }
} }
} }
return true; return device_found;
} }
struct acr122_usb_descriptor { struct acr122_usb_descriptor {
@ -862,7 +862,7 @@ const struct pn53x_io acr122_usb_io = {
const struct nfc_driver acr122_usb_driver = { const struct nfc_driver acr122_usb_driver = {
.name = ACR122_USB_DRIVER_NAME, .name = ACR122_USB_DRIVER_NAME,
.probe = acr122_usb_probe, .scan = acr122_usb_scan,
.open = acr122_usb_open, .open = acr122_usb_open,
.close = acr122_usb_close, .close = acr122_usb_close,
.strerror = pn53x_strerror, .strerror = pn53x_strerror,

View file

@ -447,21 +447,19 @@ acr122s_connstring_decode(const nfc_connstring connstring, struct acr122s_descri
return 3; return 3;
} }
static bool static size_t
acr122s_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound) acr122s_scan(nfc_connstring connstrings[], const size_t connstrings_len)
{ {
/** @note: Due to UART bus we can't know if its really an ACR122S without /** @note: Due to UART bus we can't know if its really an ACR122S without
* sending some commands. But using this way to probe devices, we can * sending some commands. But using this way to scan devices, we can
* have serious problem with other device on this bus */ * have serious problem with other device on this bus */
#ifndef SERIAL_AUTOPROBE_ENABLED #ifndef SERIAL_AUTOPROBE_ENABLED
(void) connstrings; (void) connstrings;
(void) connstrings_len; (void) connstrings_len;
*pszDeviceFound = 0; log_put(LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoscan.");
log_put(LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoprobe."); return 0;
return false;
#else /* SERIAL_AUTOPROBE_ENABLED */ #else /* SERIAL_AUTOPROBE_ENABLED */
*pszDeviceFound = 0; size_t device_found = 0;
serial_port sp; serial_port sp;
char **acPorts = uart_list_ports(); char **acPorts = uart_list_ports();
const char *acPort; const char *acPort;
@ -509,11 +507,11 @@ acr122s_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
continue; continue;
// ACR122S reader is found // ACR122S reader is found
memcpy(connstrings[*pszDeviceFound], connstring, sizeof(nfc_connstring)); memcpy(connstrings[device_found], connstring, sizeof(nfc_connstring));
(*pszDeviceFound)++; device_found++;
// Test if we reach the maximum "wanted" devices // Test if we reach the maximum "wanted" devices
if (*pszDeviceFound >= connstrings_len) if (device_found >= connstrings_len)
break; break;
} }
} }
@ -522,8 +520,8 @@ acr122s_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
free((void *)acPort); free((void *)acPort);
} }
free(acPorts); free(acPorts);
return device_found;
#endif /* SERIAL_AUTOPROBE_ENABLED */ #endif /* SERIAL_AUTOPROBE_ENABLED */
return true;
} }
static void static void
@ -705,7 +703,7 @@ const struct pn53x_io acr122s_io = {
const struct nfc_driver acr122s_driver = { const struct nfc_driver acr122s_driver = {
.name = ACR122S_DRIVER_NAME, .name = ACR122S_DRIVER_NAME,
.probe = acr122s_probe, .scan = acr122s_scan,
.open = acr122s_open, .open = acr122s_open,
.close = acr122s_close, .close = acr122s_close,
.strerror = pn53x_strerror, .strerror = pn53x_strerror,

View file

@ -91,21 +91,19 @@ static const uint8_t arygon_error_unknown_mode[] = "FF060000\x0d\x0a";
int arygon_reset_tama(nfc_device *pnd); int arygon_reset_tama(nfc_device *pnd);
void arygon_firmware(nfc_device *pnd, char *str); void arygon_firmware(nfc_device *pnd, char *str);
static bool static size_t
arygon_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound) arygon_scan(nfc_connstring connstrings[], const size_t connstrings_len)
{ {
/** @note: Due to UART bus we can't know if its really an ARYGON without /** @note: Due to UART bus we can't know if its really an ARYGON without
* sending some commands. But using this way to probe devices, we can * sending some commands. But using this way to scan devices, we can
* have serious problem with other device on this bus */ * have serious problem with other device on this bus */
#ifndef SERIAL_AUTOPROBE_ENABLED #ifndef SERIAL_AUTOPROBE_ENABLED
(void) connstrings; (void) connstrings;
(void) connstrings_len; (void) connstrings_len;
*pszDeviceFound = 0; log_put(LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoscan.");
log_put(LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoprobe."); return 0;
return false;
#else /* SERIAL_AUTOPROBE_ENABLED */ #else /* SERIAL_AUTOPROBE_ENABLED */
*pszDeviceFound = 0; size_t device_found = 0;
serial_port sp; serial_port sp;
char **acPorts = uart_list_ports(); char **acPorts = uart_list_ports();
const char *acPort; const char *acPort;
@ -147,11 +145,11 @@ arygon_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDe
} }
// ARYGON reader is found // ARYGON reader is found
memcpy(connstrings[*pszDeviceFound], connstring, sizeof(nfc_connstring)); memcpy(connstrings[device_found], connstring, sizeof(nfc_connstring));
(*pszDeviceFound)++; device_found++;
// Test if we reach the maximum "wanted" devices // Test if we reach the maximum "wanted" devices
if ((*pszDeviceFound) >= connstrings_len) if (device_found >= connstrings_len)
break; break;
} }
} }
@ -160,8 +158,8 @@ arygon_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDe
free((void *)acPort); free((void *)acPort);
} }
free(acPorts); free(acPorts);
return device_found;
#endif /* SERIAL_AUTOPROBE_ENABLED */ #endif /* SERIAL_AUTOPROBE_ENABLED */
return true;
} }
struct arygon_descriptor { struct arygon_descriptor {
@ -566,7 +564,7 @@ const struct pn53x_io arygon_tama_io = {
const struct nfc_driver arygon_driver = { const struct nfc_driver arygon_driver = {
.name = ARYGON_DRIVER_NAME, .name = ARYGON_DRIVER_NAME,
.probe = arygon_probe, .scan = arygon_scan,
.open = arygon_open, .open = arygon_open,
.close = arygon_close, .close = arygon_close,
.strerror = pn53x_strerror, .strerror = pn53x_strerror,

View file

@ -64,21 +64,19 @@ int pn532_uart_wakeup(nfc_device *pnd);
#define DRIVER_DATA(pnd) ((struct pn532_uart_data*)(pnd->driver_data)) #define DRIVER_DATA(pnd) ((struct pn532_uart_data*)(pnd->driver_data))
static bool static size_t
pn532_uart_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound) pn532_uart_scan(nfc_connstring connstrings[], const size_t connstrings_len)
{ {
/** @note: Due to UART bus we can't know if its really a pn532 without /** @note: Due to UART bus we can't know if its really a pn532 without
* sending some PN53x commands. But using this way to probe devices, we can * sending some PN53x commands. But using this way to scan devices, we can
* have serious problem with other device on this bus */ * have serious problem with other device on this bus */
#ifndef SERIAL_AUTOPROBE_ENABLED #ifndef SERIAL_AUTOPROBE_ENABLED
(void) connstrings; (void) connstrings;
(void) connstrings_len; (void) connstrings_len;
*pszDeviceFound = 0; log_put(LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoscan.");
log_put(LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoprobe."); return 0;
return false;
#else /* SERIAL_AUTOPROBE_ENABLED */ #else /* SERIAL_AUTOPROBE_ENABLED */
*pszDeviceFound = 0; size_t device_found = 0;
serial_port sp; serial_port sp;
char **acPorts = uart_list_ports(); char **acPorts = uart_list_ports();
const char *acPort; const char *acPort;
@ -124,11 +122,11 @@ pn532_uart_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *p
continue; continue;
} }
memcpy(connstrings[*pszDeviceFound], connstring, sizeof(nfc_connstring)); memcpy(connstrings[device_found], connstring, sizeof(nfc_connstring));
(*pszDeviceFound)++; device_found++;
// Test if we reach the maximum "wanted" devices // Test if we reach the maximum "wanted" devices
if ((*pszDeviceFound) >= connstrings_len) if (device_found >= connstrings_len)
break; break;
} }
} }
@ -137,8 +135,8 @@ pn532_uart_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *p
free((void *)acPort); free((void *)acPort);
} }
free(acPorts); free(acPorts);
return device_found;
#endif /* SERIAL_AUTOPROBE_ENABLED */ #endif /* SERIAL_AUTOPROBE_ENABLED */
return true;
} }
struct pn532_uart_descriptor { struct pn532_uart_descriptor {
@ -507,7 +505,7 @@ const struct pn53x_io pn532_uart_io = {
const struct nfc_driver pn532_uart_driver = { const struct nfc_driver pn532_uart_driver = {
.name = PN532_UART_DRIVER_NAME, .name = PN532_UART_DRIVER_NAME,
.probe = pn532_uart_probe, .scan = pn532_uart_scan,
.open = pn532_uart_open, .open = pn532_uart_open,
.close = pn532_uart_close, .close = pn532_uart_close,
.strerror = pn53x_strerror, .strerror = pn53x_strerror,

View file

@ -181,29 +181,27 @@ pn53x_usb_get_end_points(struct usb_device *dev, struct pn53x_usb_data *data)
} }
} }
static bool static size_t
pn53x_usb_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound) pn53x_usb_scan(nfc_connstring connstrings[], const size_t connstrings_len)
{ {
usb_init(); usb_init();
int res; int res;
// usb_find_busses will find all of the busses on the system. Returns the // usb_find_busses will find all of the busses on the system. Returns the
// number of changes since previous call to this function (total of new // number of changes since previous call to this function (total of new
// busses and busses removed). // busses and busses removed).
if ((res = usb_find_busses() < 0)) { if ((res = usb_find_busses() < 0)) {
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror(res)); log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB busses (%s)", _usb_strerror(res));
return false; return 0;
} }
// usb_find_devices will find all of the devices on each bus. This should be // usb_find_devices will find all of the devices on each bus. This should be
// called after usb_find_busses. Returns the number of changes since the // called after usb_find_busses. Returns the number of changes since the
// previous call to this function (total of new device and devices removed). // previous call to this function (total of new device and devices removed).
if ((res = usb_find_devices() < 0)) { if ((res = usb_find_devices() < 0)) {
log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror(res)); log_put(LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to find USB devices (%s)", _usb_strerror(res));
return false; return 0;
} }
*pszDeviceFound = 0; size_t device_found = 0;
uint32_t uiBusIndex = 0; uint32_t uiBusIndex = 0;
struct usb_bus *bus; struct usb_bus *bus;
for (bus = usb_get_busses(); bus; bus = bus->next) { for (bus = usb_get_busses(); bus; bus = bus->next) {
@ -235,21 +233,21 @@ pn53x_usb_probe(nfc_connstring connstrings[], size_t connstrings_len, size_t *ps
continue; continue;
} }
// pn53x_usb_get_usb_device_name (dev, udev, pnddDevices[*pszDeviceFound].acDevice, sizeof (pnddDevices[*pszDeviceFound].acDevice)); // pn53x_usb_get_usb_device_name (dev, udev, pnddDevices[device_found].acDevice, sizeof (pnddDevices[device_found].acDevice));
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "device found: Bus %s Device %s", bus->dirname, dev->filename); log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "device found: Bus %s Device %s", bus->dirname, dev->filename);
usb_close(udev); usb_close(udev);
snprintf(connstrings[*pszDeviceFound], sizeof(nfc_connstring), "%s:%s:%s", PN53X_USB_DRIVER_NAME, bus->dirname, dev->filename); snprintf(connstrings[device_found], sizeof(nfc_connstring), "%s:%s:%s", PN53X_USB_DRIVER_NAME, bus->dirname, dev->filename);
(*pszDeviceFound)++; device_found++;
// Test if we reach the maximum "wanted" devices // Test if we reach the maximum "wanted" devices
if ((*pszDeviceFound) == connstrings_len) { if (device_found == connstrings_len) {
return true; return device_found;
} }
} }
} }
} }
} }
return true; return device_found;
} }
struct pn53x_usb_descriptor { struct pn53x_usb_descriptor {
@ -761,7 +759,7 @@ const struct pn53x_io pn53x_usb_io = {
const struct nfc_driver pn53x_usb_driver = { const struct nfc_driver pn53x_usb_driver = {
.name = PN53X_USB_DRIVER_NAME, .name = PN53X_USB_DRIVER_NAME,
.probe = pn53x_usb_probe, .scan = pn53x_usb_scan,
.open = pn53x_usb_open, .open = pn53x_usb_open,
.close = pn53x_usb_close, .close = pn53x_usb_close,
.strerror = pn53x_strerror, .strerror = pn53x_strerror,

View file

@ -109,7 +109,7 @@
struct nfc_driver { struct nfc_driver {
const char *name; const char *name;
bool (*probe)(nfc_connstring connstrings[], size_t connstrings_len, size_t *pszDeviceFound); size_t (*scan)(nfc_connstring connstrings[], const size_t connstrings_len);
struct nfc_device *(*open)(const nfc_connstring connstring); struct nfc_device *(*open)(const nfc_connstring connstring);
void (*close)(struct nfc_device *pnd); void (*close)(struct nfc_device *pnd);
const char *(*strerror)(const struct nfc_device *pnd); const char *(*strerror)(const struct nfc_device *pnd);

View file

@ -150,8 +150,8 @@ 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(NULL, listed_cs, 1); size_t device_found = nfc_list_devices(NULL, listed_cs, 1);
if (szDeviceFound) { if (device_found) {
strncpy(*connstring, listed_cs[0], sizeof(nfc_connstring)); strncpy(*connstring, listed_cs[0], sizeof(nfc_connstring));
} else { } else {
return false; return false;
@ -255,31 +255,31 @@ nfc_close(nfc_device *pnd)
* @return Returns the number of devices found. * @return Returns the number of devices found.
* @param context The context to operate on, or NULL for the default context. * @param context The context to operate on, or NULL for the default context.
* @param connstrings array of \a nfc_connstring. * @param connstrings array of \a nfc_connstring.
* @param szDevices size of the \a connstrings array. * @param connstrings_len size of the \a connstrings array.
* *
*/ */
size_t size_t
nfc_list_devices(nfc_context *context, nfc_connstring connstrings[] , size_t szDevices) nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_t connstrings_len)
{ {
size_t szN; size_t device_found = 0;
size_t szDeviceFound = 0;
const struct nfc_driver *ndr; const struct nfc_driver *ndr;
const struct nfc_driver **pndr = nfc_drivers; const struct nfc_driver **pndr = nfc_drivers;
(void) context; (void) context;
while ((ndr = *pndr)) { while ((ndr = *pndr)) {
szN = 0; size_t _device_found = 0;
if (ndr->probe(connstrings + (szDeviceFound), szDevices - (szDeviceFound), &szN)) { _device_found = ndr->scan(connstrings + (device_found), connstrings_len - (device_found));
szDeviceFound += szN; log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%ld device(s) found using %s driver", (unsigned long) _device_found, ndr->name);
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%ld device(s) found using %s driver", (unsigned long) szN, ndr->name); if (_device_found > 0) {
if (szDeviceFound == szDevices) device_found += _device_found;
if (device_found == connstrings_len)
break; break;
} }
pndr++; pndr++;
} }
log_fini(); log_fini();
return szDeviceFound; return device_found;
} }
/** @ingroup properties /** @ingroup properties

View file

@ -3,7 +3,7 @@ bin_PROGRAMS = \
nfc-list \ nfc-list \
nfc-mfclassic \ nfc-mfclassic \
nfc-mfultralight \ nfc-mfultralight \
nfc-probe \ nfc-scan-device \
nfc-read-forum-tag3 \ nfc-read-forum-tag3 \
nfc-relay-picc nfc-relay-picc
@ -30,8 +30,8 @@ nfc_mfclassic_LDADD = $(top_builddir)/libnfc/libnfc.la \
nfc_mfultralight_SOURCES = nfc-mfultralight.c mifare.c mifare.h nfc_mfultralight_SOURCES = nfc-mfultralight.c mifare.c mifare.h
nfc_mfultralight_LDADD = $(top_builddir)/libnfc/libnfc.la nfc_mfultralight_LDADD = $(top_builddir)/libnfc/libnfc.la
nfc_probe_SOURCES = nfc-probe.c nfc_scan_device_SOURCES = nfc-scan-device.c
nfc_probe_LDADD = $(top_builddir)/libnfc/libnfc.la \ nfc_scan_device_LDADD = $(top_builddir)/libnfc/libnfc.la \
libnfcutils.la libnfcutils.la
nfc_read_forum_tag3_SOURCES = nfc-read-forum-tag3.c nfc_read_forum_tag3_SOURCES = nfc-read-forum-tag3.c

View file

@ -30,7 +30,7 @@
*/ */
/** /**
* @file nfc-probe.c * @file nfc-scan-device.c
* @brief Lists each available NFC device * @brief Lists each available NFC device
*/ */