New feature: search in a directory for devices configuration files.
This commit is contained in:
parent
84dc268781
commit
03e5611d14
10 changed files with 49 additions and 26 deletions
2
NEWS
2
NEWS
|
@ -11,6 +11,8 @@ Configuration:
|
||||||
- "device.name" and "device.connstring" to define a user device,
|
- "device.name" and "device.connstring" to define a user device,
|
||||||
this is the recommended method if user have a not-easily detectable
|
this is the recommended method if user have a not-easily detectable
|
||||||
device (ie. serial ones).
|
device (ie. serial ones).
|
||||||
|
Its also possible to define devices using dedicated configuration files and
|
||||||
|
put them into device search directory (/etc/nfc/devices.d under GNU/Linux).
|
||||||
|
|
||||||
API Changes:
|
API Changes:
|
||||||
|
|
||||||
|
|
|
@ -147,6 +147,7 @@ AC_CONFIG_FILES([
|
||||||
cmake/modules/Makefile
|
cmake/modules/Makefile
|
||||||
contrib/Makefile
|
contrib/Makefile
|
||||||
contrib/devd/Makefile
|
contrib/devd/Makefile
|
||||||
|
contrib/libnfc/Makefile
|
||||||
contrib/linux/Makefile
|
contrib/linux/Makefile
|
||||||
contrib/udev/Makefile
|
contrib/udev/Makefile
|
||||||
contrib/win32/Makefile
|
contrib/win32/Makefile
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
SUBDIRS = \
|
SUBDIRS = \
|
||||||
devd \
|
devd \
|
||||||
|
libnfc \
|
||||||
linux \
|
linux \
|
||||||
udev \
|
udev \
|
||||||
win32
|
win32
|
||||||
|
|
4
contrib/libnfc/Makefile.am
Normal file
4
contrib/libnfc/Makefile.am
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
EXTRA_DIST = \
|
||||||
|
pn532_via_uart2usb.conf.sample \
|
||||||
|
arygon.conf.sample \
|
||||||
|
pn532_uart_on_rpi.conf.sample
|
3
contrib/libnfc/arygon.conf.sample
Normal file
3
contrib/libnfc/arygon.conf.sample
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
## Typical configuration file for Arygon/IDentive device (with Arygon-MCU on board)
|
||||||
|
name = "IDentive"
|
||||||
|
connstring = arygon:/dev/ttyS0
|
5
contrib/libnfc/pn532_uart_on_rpi.conf.sample
Normal file
5
contrib/libnfc/pn532_uart_on_rpi.conf.sample
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
## Typical configuration file for PN532 device on R-Pi connected using UART
|
||||||
|
## Note: to use UART port on R-Pi, you have to disable linux serial console:
|
||||||
|
## http://learn.adafruit.com/adafruit-nfc-rfid-on-raspberry-pi/freeing-uart-on-the-pi
|
||||||
|
name = "PN532 board"
|
||||||
|
connstring = pn532_uart:/dev/ttyAMA0
|
3
contrib/libnfc/pn532_via_uart2usb.conf.sample
Normal file
3
contrib/libnfc/pn532_via_uart2usb.conf.sample
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
## Typical configuration file for PN532 board (ie. microbuilder.eu / Adafruit) device
|
||||||
|
name = "Adafruit PN532 board"
|
||||||
|
connstring = pn532_uart:/dev/ttyUSB0
|
|
@ -1,10 +1,11 @@
|
||||||
# Allow device auto-detection (default: true)
|
# Allow device auto-detection (default: true)
|
||||||
# Note: if this auto-detection is disable, user have to set manually a device
|
# Note: if this auto-detection is disabled, user have to set manually a device
|
||||||
# configuration using file or environnement variable
|
# configuration using file or environnement variable
|
||||||
#allow_autoscan = true
|
#allow_autoscan = true
|
||||||
|
|
||||||
# Allow intrusive auto-detection (default: false)
|
# Allow intrusive auto-detection (default: false)
|
||||||
# Warning: intrusive auto-detection can seriously disturb other devices
|
# Warning: intrusive auto-detection can seriously disturb other devices
|
||||||
|
# This option is not recommended, user should prefers to add manually its device.
|
||||||
#allow_intrusive_autoscan = false
|
#allow_intrusive_autoscan = false
|
||||||
|
|
||||||
# Set log level (default: error)
|
# Set log level (default: error)
|
||||||
|
|
|
@ -119,36 +119,39 @@ conf_keyvalue_device(void *data, const char* key, const char* value)
|
||||||
conf_keyvalue_context(data, newkey, value);
|
conf_keyvalue_context(data, newkey, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
static void
|
||||||
conf_load(nfc_context *context)
|
conf_devices_load(const char *dirname, nfc_context *context)
|
||||||
{
|
{
|
||||||
conf_parse_file(LIBNFC_CONFFILE, conf_keyvalue_context, context);
|
DIR *d = opendir(dirname);
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
int
|
|
||||||
main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
DIR *d = opendir(LIBNFC_DEVICECONFDIR);
|
|
||||||
if (!d) {
|
if (!d) {
|
||||||
perror ("opendir");
|
perror ("opendir");
|
||||||
} else {
|
} else {
|
||||||
struct dirent* de;
|
struct dirent* de;
|
||||||
while (de = readdir(d)) {
|
while ((de = readdir(d))) {
|
||||||
if (de->d_name[0]!='.') {
|
if (de->d_name[0]!='.') {
|
||||||
printf ("\t%s\n", de->d_name);
|
const size_t filename_len = strlen(de->d_name);
|
||||||
char filename[BUFSIZ] = LIBNFC_DEVICECONFDIR"/";
|
const size_t extension_len = strlen(".conf");
|
||||||
strcat (filename, de->d_name);
|
if ((filename_len > extension_len) && (strncmp(".conf", de->d_name + (filename_len-extension_len), extension_len) == 0)) {
|
||||||
struct stat s;
|
char filename[BUFSIZ] = LIBNFC_DEVICECONFDIR"/";
|
||||||
if (stat(filename, &s) == -1) {
|
strcat (filename, de->d_name);
|
||||||
perror("stat");
|
struct stat s;
|
||||||
continue;
|
if (stat(filename, &s) == -1) {
|
||||||
}
|
perror("stat");
|
||||||
if(S_ISREG(s.st_mode)) {
|
continue;
|
||||||
nfc_open_from_file (filename);
|
}
|
||||||
|
if(S_ISREG(s.st_mode)) {
|
||||||
|
conf_parse_file (filename, conf_keyvalue_device, context);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
void
|
||||||
|
conf_load(nfc_context *context)
|
||||||
|
{
|
||||||
|
conf_parse_file(LIBNFC_CONFFILE, conf_keyvalue_context, context);
|
||||||
|
conf_devices_load(LIBNFC_DEVICECONFDIR, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,9 +19,9 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @file nfc-device.c
|
* @file nfc-device.c
|
||||||
* @brief Provide internal function to manipulate nfc_device type
|
* @brief Provide internal function to manipulate nfc_device type
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
Loading…
Reference in a new issue