add nfc_device_get_connstring() function and nfc-probe example to show devices connection strings
This commit is contained in:
parent
39216f9d7c
commit
b366b8c027
10 changed files with 159 additions and 19 deletions
|
|
@ -85,8 +85,8 @@ pn53x_init(struct nfc_device *pnd)
|
|||
|
||||
// Add the firmware revision to the device name
|
||||
char *pcName;
|
||||
pcName = strdup (pnd->acName);
|
||||
snprintf (pnd->acName, DEVICE_NAME_LENGTH - 1, "%s - %s", pcName, abtFirmwareText);
|
||||
pcName = strdup (pnd->name);
|
||||
snprintf (pnd->name, DEVICE_NAME_LENGTH - 1, "%s - %s", pcName, abtFirmwareText);
|
||||
free (pcName);
|
||||
return NFC_SUCCESS;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,7 +120,10 @@ arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
|
|||
uart_flush_input (sp);
|
||||
uart_set_speed (sp, ARYGON_DEFAULT_SPEED);
|
||||
|
||||
nfc_device *pnd = nfc_device_new ();
|
||||
nfc_connstring connstring;
|
||||
snprintf (connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, ARYGON_DRIVER_NAME, acPort, ARYGON_DEFAULT_SPEED);
|
||||
nfc_device *pnd = nfc_device_new (connstring);
|
||||
|
||||
pnd->driver = &arygon_driver;
|
||||
pnd->driver_data = malloc(sizeof(struct arygon_data));
|
||||
DRIVER_DATA (pnd)->port = sp;
|
||||
|
|
@ -144,7 +147,7 @@ arygon_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *pszD
|
|||
}
|
||||
|
||||
// ARYGON reader is found
|
||||
snprintf (connstrings[*pszDeviceFound], sizeof(nfc_connstring), "%s:%s:%"PRIu32, ARYGON_DRIVER_NAME, acPort, ARYGON_DEFAULT_SPEED);
|
||||
memcpy (connstrings[*pszDeviceFound], connstring, sizeof(nfc_connstring));
|
||||
(*pszDeviceFound)++;
|
||||
|
||||
// Test if we reach the maximum "wanted" devices
|
||||
|
|
@ -245,8 +248,8 @@ arygon_open (const nfc_connstring connstring)
|
|||
uart_set_speed (sp, ndd.speed);
|
||||
|
||||
// We have a connection
|
||||
pnd = nfc_device_new ();
|
||||
snprintf (pnd->acName, sizeof (pnd->acName), "%s:%s", ARYGON_DRIVER_NAME, ndd.port);
|
||||
pnd = nfc_device_new (connstring);
|
||||
snprintf (pnd->name, sizeof (pnd->name), "%s:%s", ARYGON_DRIVER_NAME, ndd.port);
|
||||
|
||||
pnd->driver_data = malloc(sizeof(struct arygon_data));
|
||||
DRIVER_DATA (pnd)->port = sp;
|
||||
|
|
@ -277,8 +280,8 @@ arygon_open (const nfc_connstring connstring)
|
|||
char arygon_firmware_version[10];
|
||||
arygon_firmware (pnd, arygon_firmware_version);
|
||||
char *pcName;
|
||||
pcName = strdup (pnd->acName);
|
||||
snprintf (pnd->acName, sizeof (pnd->acName), "%s %s", pcName, arygon_firmware_version);
|
||||
pcName = strdup (pnd->name);
|
||||
snprintf (pnd->name, sizeof (pnd->name), "%s %s", pcName, arygon_firmware_version);
|
||||
free (pcName);
|
||||
|
||||
pn53x_init(pnd);
|
||||
|
|
|
|||
|
|
@ -94,7 +94,9 @@ pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *
|
|||
// Serial port claimed but we need to check if a PN532_UART is opened.
|
||||
uart_set_speed (sp, PN532_UART_DEFAULT_SPEED);
|
||||
|
||||
nfc_device *pnd = nfc_device_new ();
|
||||
nfc_connstring connstring;
|
||||
snprintf (connstring, sizeof(nfc_connstring), "%s:%s:%"PRIu32, PN532_UART_DRIVER_NAME, acPort, PN532_UART_DEFAULT_SPEED);
|
||||
nfc_device *pnd = nfc_device_new (connstring);
|
||||
pnd->driver = &pn532_uart_driver;
|
||||
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
|
||||
DRIVER_DATA (pnd)->port = sp;
|
||||
|
|
@ -122,7 +124,7 @@ pn532_uart_probe (nfc_connstring connstrings[], size_t connstrings_len, size_t *
|
|||
continue;
|
||||
}
|
||||
|
||||
snprintf (connstrings[*pszDeviceFound], sizeof(nfc_connstring), "%s:%s:%"PRIu32, PN532_UART_DRIVER_NAME, acPort, PN532_UART_DEFAULT_SPEED);
|
||||
memcpy (connstrings[*pszDeviceFound], connstring, sizeof (nfc_connstring));
|
||||
(*pszDeviceFound)++;
|
||||
|
||||
// Test if we reach the maximum "wanted" devices
|
||||
|
|
@ -223,8 +225,8 @@ pn532_uart_open (const nfc_connstring connstring)
|
|||
uart_set_speed (sp, ndd.speed);
|
||||
|
||||
// We have a connection
|
||||
pnd = nfc_device_new ();
|
||||
snprintf (pnd->acName, sizeof (pnd->acName), "%s:%s", PN532_UART_DRIVER_NAME, ndd.port);
|
||||
pnd = nfc_device_new (connstring);
|
||||
snprintf (pnd->name, sizeof (pnd->name), "%s:%s", PN532_UART_DRIVER_NAME, ndd.port);
|
||||
|
||||
pnd->driver_data = malloc(sizeof(struct pn532_uart_data));
|
||||
DRIVER_DATA (pnd)->port = sp;
|
||||
|
|
|
|||
|
|
@ -382,8 +382,8 @@ pn53x_usb_open (const nfc_connstring connstring)
|
|||
}
|
||||
data.model = pn53x_usb_get_device_model (dev->descriptor.idVendor, dev->descriptor.idProduct);
|
||||
// Allocate memory for the device info and specification, fill it and return the info
|
||||
pnd = nfc_device_new ();
|
||||
pn53x_usb_get_usb_device_name (dev, data.pudh, pnd->acName, sizeof (pnd->acName));
|
||||
pnd = nfc_device_new (connstring);
|
||||
pn53x_usb_get_usb_device_name (dev, data.pudh, pnd->name, sizeof (pnd->name));
|
||||
|
||||
pnd->driver_data = malloc(sizeof(struct pn53x_usb_data));
|
||||
*DRIVER_DATA (pnd) = data;
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@
|
|||
/* vim:set et sw=2 ts=2: */
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
# include "config.h"
|
||||
|
|
@ -33,7 +34,7 @@
|
|||
#include "nfc-internal.h"
|
||||
|
||||
nfc_device *
|
||||
nfc_device_new (void)
|
||||
nfc_device_new (const nfc_connstring connstring)
|
||||
{
|
||||
nfc_device *res = malloc (sizeof (*res));
|
||||
|
||||
|
|
@ -50,6 +51,7 @@ nfc_device_new (void)
|
|||
res->bEasyFraming = false;
|
||||
res->bAutoIso14443_4 = false;
|
||||
res->last_error = 0;
|
||||
memcpy (res->connstring, connstring, sizeof (res->connstring));
|
||||
res->driver_data = NULL;
|
||||
res->chip_data = NULL;
|
||||
|
||||
|
|
|
|||
|
|
@ -168,7 +168,9 @@ struct nfc_device {
|
|||
void *chip_data;
|
||||
|
||||
/** Device name string, including device wrapper firmware */
|
||||
char acName[DEVICE_NAME_LENGTH];
|
||||
char name[DEVICE_NAME_LENGTH];
|
||||
/** Device connection string */
|
||||
nfc_connstring connstring;
|
||||
/** Is the CRC automaticly added, checked and removed from the frames */
|
||||
bool bCrc;
|
||||
/** Does the chip handle parity bits, all parities are handled as data */
|
||||
|
|
@ -184,7 +186,7 @@ struct nfc_device {
|
|||
int last_error;
|
||||
};
|
||||
|
||||
nfc_device *nfc_device_new (void);
|
||||
nfc_device *nfc_device_new (const nfc_connstring connstring);
|
||||
void nfc_device_free (nfc_device *dev);
|
||||
|
||||
void iso14443_cascade_uid (const uint8_t abtUID[], const size_t szUID, uint8_t * pbtCascadedUID, size_t * pszCascadedUID);
|
||||
|
|
|
|||
14
libnfc/nfc.c
14
libnfc/nfc.c
|
|
@ -163,7 +163,7 @@ nfc_open (const nfc_connstring connstring)
|
|||
return pnd;
|
||||
}
|
||||
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "[%s] has been claimed.", pnd->acName);
|
||||
log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "\"%s\" (%s) has been claimed.", pnd->name, pnd->connstring);
|
||||
log_fini ();
|
||||
return pnd;
|
||||
}
|
||||
|
|
@ -898,7 +898,17 @@ nfc_device_get_last_error (const nfc_device *pnd)
|
|||
const char *
|
||||
nfc_device_get_name (nfc_device *pnd)
|
||||
{
|
||||
return pnd->acName;
|
||||
return pnd->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns the device connection string
|
||||
* @return Returns a string with the device connstring
|
||||
*/
|
||||
const char *
|
||||
nfc_device_get_connstring (nfc_device *pnd)
|
||||
{
|
||||
return pnd->connstring;
|
||||
}
|
||||
|
||||
/* Misc. functions */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue