Removes --enable-serial-autoprobe option at compile and replace this feature by LIBNFC_INTRUSIVE_SCAN environment variable at run time.
This commit is contained in:
parent
b5aa91fd62
commit
397222c33f
9 changed files with 84 additions and 59 deletions
11
configure.ac
11
configure.ac
|
@ -84,17 +84,6 @@ fi
|
|||
# Handle --with-drivers option
|
||||
LIBNFC_ARG_WITH_DRIVERS
|
||||
|
||||
# Serial autoprobing support (default:no)
|
||||
AC_ARG_ENABLE([serial-autoprobe],AS_HELP_STRING([--enable-serial-autoprobe],[Allow serial ports to be probed (can seriously disturb connected serial devices)]),[enable_serial_autoprobe=$enableval],[enable_serial_autoprobe="no"])
|
||||
|
||||
AC_MSG_CHECKING(for serial autoprobe flag)
|
||||
AC_MSG_RESULT($enable_serial_autoprobe)
|
||||
|
||||
if test x"$enable_serial_autoprobe" = "xyes"
|
||||
then
|
||||
CFLAGS="$CFLAGS -DSERIAL_AUTOPROBE_ENABLED"
|
||||
fi
|
||||
|
||||
# Documentation (default: no)
|
||||
AC_ARG_ENABLE([doc],AS_HELP_STRING([--enable-doc],[Enable documentation generation.]),[enable_doc=$enableval],[enable_doc="no"])
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
*
|
||||
* Copyright (C) 2009 Roel Verdult
|
||||
* Copyright (C) 2010, 2011 Romain Tartière
|
||||
* Copyright (C) 2010, 2011 Romuald Conty
|
||||
* Copyright (C) 2010, 2011, 2012 Romuald Conty
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
|
@ -32,7 +32,10 @@
|
|||
# include <stdbool.h>
|
||||
# include <stdio.h>
|
||||
|
||||
typedef void *nfc_context;
|
||||
/**
|
||||
* NFC context
|
||||
*/
|
||||
typedef struct nfc_context nfc_context;
|
||||
|
||||
/**
|
||||
* NFC device
|
||||
|
|
|
@ -325,7 +325,6 @@ acr122_usb_scan(nfc_connstring connstrings[], const size_t connstrings_len)
|
|||
}
|
||||
|
||||
size_t device_found = 0;
|
||||
|
||||
uint32_t uiBusIndex = 0;
|
||||
struct usb_bus *bus;
|
||||
for (bus = usb_get_busses(); bus; bus = bus->next) {
|
||||
|
@ -862,6 +861,7 @@ const struct pn53x_io acr122_usb_io = {
|
|||
|
||||
const struct nfc_driver acr122_usb_driver = {
|
||||
.name = ACR122_USB_DRIVER_NAME,
|
||||
.scan_type = NOT_INTRUSIVE,
|
||||
.scan = acr122_usb_scan,
|
||||
.open = acr122_usb_open,
|
||||
.close = acr122_usb_close,
|
||||
|
|
|
@ -450,15 +450,6 @@ acr122s_connstring_decode(const nfc_connstring connstring, struct acr122s_descri
|
|||
static size_t
|
||||
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
|
||||
* sending some commands. But using this way to scan devices, we can
|
||||
* have serious problem with other device on this bus */
|
||||
#ifndef SERIAL_AUTOPROBE_ENABLED
|
||||
(void) connstrings;
|
||||
(void) connstrings_len;
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoscan.");
|
||||
return 0;
|
||||
#else /* SERIAL_AUTOPROBE_ENABLED */
|
||||
size_t device_found = 0;
|
||||
serial_port sp;
|
||||
char **acPorts = uart_list_ports();
|
||||
|
@ -521,7 +512,6 @@ acr122s_scan(nfc_connstring connstrings[], const size_t connstrings_len)
|
|||
}
|
||||
free(acPorts);
|
||||
return device_found;
|
||||
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -703,6 +693,7 @@ const struct pn53x_io acr122s_io = {
|
|||
|
||||
const struct nfc_driver acr122s_driver = {
|
||||
.name = ACR122S_DRIVER_NAME,
|
||||
.scan_type = INTRUSIVE,
|
||||
.scan = acr122s_scan,
|
||||
.open = acr122s_open,
|
||||
.close = acr122s_close,
|
||||
|
|
|
@ -94,15 +94,6 @@ void arygon_firmware(nfc_device *pnd, char *str);
|
|||
static size_t
|
||||
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
|
||||
* sending some commands. But using this way to scan devices, we can
|
||||
* have serious problem with other device on this bus */
|
||||
#ifndef SERIAL_AUTOPROBE_ENABLED
|
||||
(void) connstrings;
|
||||
(void) connstrings_len;
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoscan.");
|
||||
return 0;
|
||||
#else /* SERIAL_AUTOPROBE_ENABLED */
|
||||
size_t device_found = 0;
|
||||
serial_port sp;
|
||||
char **acPorts = uart_list_ports();
|
||||
|
@ -159,7 +150,6 @@ arygon_scan(nfc_connstring connstrings[], const size_t connstrings_len)
|
|||
}
|
||||
free(acPorts);
|
||||
return device_found;
|
||||
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
||||
}
|
||||
|
||||
struct arygon_descriptor {
|
||||
|
@ -564,6 +554,7 @@ const struct pn53x_io arygon_tama_io = {
|
|||
|
||||
const struct nfc_driver arygon_driver = {
|
||||
.name = ARYGON_DRIVER_NAME,
|
||||
.scan_type = INTRUSIVE,
|
||||
.scan = arygon_scan,
|
||||
.open = arygon_open,
|
||||
.close = arygon_close,
|
||||
|
|
|
@ -67,15 +67,6 @@ int pn532_uart_wakeup(nfc_device *pnd);
|
|||
static size_t
|
||||
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
|
||||
* sending some PN53x commands. But using this way to scan devices, we can
|
||||
* have serious problem with other device on this bus */
|
||||
#ifndef SERIAL_AUTOPROBE_ENABLED
|
||||
(void) connstrings;
|
||||
(void) connstrings_len;
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_INFO, "%s", "Serial auto-probing have been disabled at compile time. Skipping autoscan.");
|
||||
return 0;
|
||||
#else /* SERIAL_AUTOPROBE_ENABLED */
|
||||
size_t device_found = 0;
|
||||
serial_port sp;
|
||||
char **acPorts = uart_list_ports();
|
||||
|
@ -136,7 +127,6 @@ pn532_uart_scan(nfc_connstring connstrings[], const size_t connstrings_len)
|
|||
}
|
||||
free(acPorts);
|
||||
return device_found;
|
||||
#endif /* SERIAL_AUTOPROBE_ENABLED */
|
||||
}
|
||||
|
||||
struct pn532_uart_descriptor {
|
||||
|
@ -505,6 +495,7 @@ const struct pn53x_io pn532_uart_io = {
|
|||
|
||||
const struct nfc_driver pn532_uart_driver = {
|
||||
.name = PN532_UART_DRIVER_NAME,
|
||||
.scan_type = INTRUSIVE,
|
||||
.scan = pn532_uart_scan,
|
||||
.open = pn532_uart_open,
|
||||
.close = pn532_uart_close,
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/*-
|
||||
* Public platform independent Near Field Communication (NFC) library
|
||||
*
|
||||
* Copyright (C) 2011 Romuald Conty
|
||||
* Copyright (C) 2011, 2012 Romuald Conty
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU Lesser General Public License as published by the
|
||||
|
@ -25,6 +25,44 @@
|
|||
#include <nfc/nfc.h>
|
||||
#include "nfc-internal.h"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
static bool
|
||||
string_as_boolean(const char* s)
|
||||
{
|
||||
if ((s) && (
|
||||
(strcmp(s, "yes") == 0) ||
|
||||
(strcmp(s, "true") == 0) ||
|
||||
(strcmp(s, "1") == 0))) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
nfc_context *
|
||||
nfc_context_new(void)
|
||||
{
|
||||
nfc_context *res = malloc(sizeof(*res));
|
||||
|
||||
if (!res) {
|
||||
err(EXIT_FAILURE, "nfc_context_new: malloc");
|
||||
}
|
||||
|
||||
// Load "intrusive scan" option
|
||||
// XXX: Load this option from configuration file too ?
|
||||
char *envvar = getenv("LIBNFC_INTRUSIVE_SCAN");
|
||||
res->allow_intrusive_scan = string_as_boolean(envvar);
|
||||
log_put ("libnfc", NFC_PRIORITY_DEBUG, "allow_intrusive_scan is set to %s", (res->allow_intrusive_scan)?"true":"false");
|
||||
return res;
|
||||
}
|
||||
|
||||
void
|
||||
nfc_context_free(nfc_context *context)
|
||||
{
|
||||
free(context);
|
||||
}
|
||||
|
||||
void
|
||||
prepare_initiator_data(const nfc_modulation nm, uint8_t **ppbtInitiatorData, size_t *pszInitiatorData)
|
||||
{
|
||||
|
|
|
@ -107,8 +107,15 @@
|
|||
} \
|
||||
} while (0)
|
||||
|
||||
typedef enum {
|
||||
NOT_INTRUSIVE,
|
||||
INTRUSIVE,
|
||||
NOT_AVAILABLE,
|
||||
} scan_type_enum;
|
||||
|
||||
struct nfc_driver {
|
||||
const char *name;
|
||||
const scan_type_enum scan_type;
|
||||
size_t (*scan)(nfc_connstring connstrings[], const size_t connstrings_len);
|
||||
struct nfc_device *(*open)(const nfc_connstring connstring);
|
||||
void (*close)(struct nfc_device *pnd);
|
||||
|
@ -145,6 +152,18 @@ struct nfc_driver {
|
|||
# define DEVICE_NAME_LENGTH 256
|
||||
# define DEVICE_PORT_LENGTH 64
|
||||
|
||||
/**
|
||||
* @struct nfc_context
|
||||
* @brief NFC library context
|
||||
* Struct which contains internal options, references, pointers, etc. used by library
|
||||
*/
|
||||
struct nfc_context {
|
||||
bool allow_intrusive_scan;
|
||||
};
|
||||
|
||||
nfc_context *nfc_context_new(void);
|
||||
void nfc_context_free(nfc_context *context);
|
||||
|
||||
/**
|
||||
* @struct nfc_device
|
||||
* @brief NFC device information
|
||||
|
|
|
@ -125,7 +125,7 @@ nfc_init(nfc_context *context)
|
|||
void
|
||||
nfc_exit(nfc_context *context)
|
||||
{
|
||||
(void) context;
|
||||
if(context) nfc_context_free(context);
|
||||
log_fini();
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ nfc_close(nfc_device *pnd)
|
|||
}
|
||||
|
||||
/** @ingroup dev
|
||||
* @brief Probe for discoverable supported devices (ie. only available for some drivers)
|
||||
* @brief Scan for discoverable supported devices (ie. only available for some drivers)
|
||||
* @return Returns the number of devices found.
|
||||
* @param context The context to operate on, or NULL for the default context.
|
||||
* @param connstrings array of \a nfc_connstring.
|
||||
|
@ -265,10 +265,12 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
|
|||
const struct nfc_driver *ndr;
|
||||
const struct nfc_driver **pndr = nfc_drivers;
|
||||
|
||||
(void) context;
|
||||
if (!context) context = nfc_context_new(); // Should we support NULL context ?
|
||||
// FIXME: Load device(s) from configuration file(s)
|
||||
|
||||
while ((ndr = *pndr)) {
|
||||
size_t _device_found = 0;
|
||||
if((ndr->scan_type == NOT_INTRUSIVE) || ((context->allow_intrusive_scan) && (ndr->scan_type == INTRUSIVE))) {
|
||||
_device_found = ndr->scan(connstrings + (device_found), connstrings_len - (device_found));
|
||||
log_put(LOG_CATEGORY, NFC_PRIORITY_TRACE, "%ld device(s) found using %s driver", (unsigned long) _device_found, ndr->name);
|
||||
if (_device_found > 0) {
|
||||
|
@ -276,6 +278,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
|
|||
if (device_found == connstrings_len)
|
||||
break;
|
||||
}
|
||||
} // scan_type is INTRUSIVE but not allowed or NOT_AVAILABLE
|
||||
pndr++;
|
||||
}
|
||||
log_fini();
|
||||
|
|
Loading…
Add table
Reference in a new issue