diff --git a/pcsc-relay/configure.ac b/pcsc-relay/configure.ac
index cde4d9f..f130323 100644
--- a/pcsc-relay/configure.ac
+++ b/pcsc-relay/configure.ac
@@ -57,14 +57,21 @@ fi
# If you need to see the details, just run make V=1.
m4_ifdef([AM_SILENT_RULES],[AM_SILENT_RULES([yes])])
+AC_ARG_ENABLE(
+ [libnfc],
+ [AS_HELP_STRING([--enable-libnfc],[enable emulation hardware supported via libnfc @<:@detect@:>@])],
+ ,
+ [enable_libnfc="detect"]
+)
+
# Checks for libraries.
PKG_CHECK_EXISTS([libpcsclite],
[PKG_CHECK_MODULES([PCSC], [libpcsclite])],
[AC_MSG_WARN([libpcsclite not found by pkg-config])])
+
# Checks for libraries.
PKG_CHECK_EXISTS([libnfc >= 1.6],
- [PKG_CHECK_MODULES([LIBNFC], [libnfc >= 1.6])],
- [AC_MSG_WARN([libnfc >= 1.6 not found by pkg-config])])
+ [PKG_CHECK_MODULES([LIBNFC], [libnfc >= 1.6])])
saved_CPPFLAGS="$CPPFLAGS"
@@ -72,18 +79,40 @@ CPPFLAGS="$CPPFLAGS $PCSC_CFLAGS $LIBNFC_CFLAGS"
AC_CHECK_HEADERS(winscard.h, [], [ AC_MSG_ERROR([winscard.h not found, install PC/SC Lite or similar or use ./configure PCSC_CFLAGS=...]) ])
AC_CHECK_HEADERS(reader.h, [AC_DEFINE(HAVE_READER_H, 1, [use reader.h from PC/SC Lite])], [])
AC_CHECK_HEADERS(pcsclite.h, [AC_DEFINE(HAVE_PCSCLITE_H, 1, [use pcsclite.h from PC/SC Lite])], [])
-AC_CHECK_HEADERS(nfc/nfc.h,,
- [ AC_MSG_ERROR([nfc/nfc.h not found, install libnfc >= 5.1.9 or use ./configure LIBNFC_CFLAGS=...]) ])
-AC_MSG_CHECKING([for nfc_initiator_select_passive_target])
+AC_CHECK_HEADERS(nfc/nfc.h,, [ have_libnfc="no"])
CPPFLAGS="$saved_CPPFLAGS"
-#saved_LIBS="$LIBS"
-#LIBS="$LIBS $PCSC_LIBS $LIBNFC_LIBS"
-#AC_MSG_CHECKING([for SCardEstablishContext])
-#AC_TRY_LINK_FUNC(SCardEstablishContext, [ AC_MSG_RESULT([yes]) ],
- #[ AC_MSG_ERROR([libpcsclite not found, use ./configure PCSC_LIBS=...]) ])
-#AC_TRY_LINK_FUNC(nfc_initiator_select_passive_target, [ AC_MSG_RESULT([yes]) ],
- #[ AC_MSG_ERROR([libnfc >= 1.6 not found, use ./configure LIBNFC_LIBS=...]) ])
-#LIBS="$saved_LIBS"
+saved_LIBS="$LIBS"
+LIBS="$LIBS $PCSC_LIBS $LIBNFC_LIBS"
+AC_MSG_CHECKING([for SCardEstablishContext])
+AC_TRY_LINK_FUNC(SCardEstablishContext, [ AC_MSG_RESULT([yes]) ],
+ [ AC_MSG_ERROR([libpcsclite not found, use ./configure PCSC_LIBS=...]) ])
+AC_MSG_CHECKING([for nfc_initiator_select_passive_target])
+AC_TRY_LINK_FUNC(nfc_initiator_select_passive_target, [ AC_MSG_RESULT([yes]) ],
+ [ AC_MSG_RESULT([no])
+ have_libnfc="no" ])
+LIBS="$saved_LIBS"
+
+case "${enable_libnfc}" in
+ no)
+ have_libnfc="no"
+ ;;
+ detect)
+ if test "${have_libnfc}" = "yes"; then
+ enable_libnfc="yes"
+ else
+ enable_libnfc="no"
+ fi
+ ;;
+esac
+
+if test "${enable_libnfc}" = "yes"; then
+ if test "${have_libnfc}" = "yes"; then
+ AC_DEFINE([ENABLE_LIBNFC], [1], [Use emulation hardware supported via libnfc])
+ else
+ AC_MSG_ERROR([libnfc >= 1.6 not found, use ./configure LIBNFC_LIBS=... LIBNFC_CFLAGS=...])
+ fi
+fi
+AM_CONDITIONAL([ENABLE_LIBNFC], [test "${enable_libnfc}" = "yes"])
# --enable-piccdev=DEV
@@ -120,7 +149,7 @@ pcsc-relay has been configured with following options:
Version: ${PACKAGE_VERSION}
User binaries: $(eval eval eval echo "${bindir}")
-
+Enable libnfc: ${enable_libnfc}
Host: ${host}
Compiler: ${CC}
diff --git a/pcsc-relay/doc/README.txt.in b/pcsc-relay/doc/README.txt.in
index a0c1698..7d4db2a 100644
--- a/pcsc-relay/doc/README.txt.in
+++ b/pcsc-relay/doc/README.txt.in
@@ -169,7 +169,6 @@ to completely emulate an ISO/IEC 14443 smart card.
@PACKAGE_NAME@ has the following dependencies:
- PC/SC middleware
-- libnfc_
.. include:: relay-note.txt
diff --git a/pcsc-relay/src/lnfc.c b/pcsc-relay/src/lnfc.c
index 38ae8c2..14c1c7e 100644
--- a/pcsc-relay/src/lnfc.c
+++ b/pcsc-relay/src/lnfc.c
@@ -16,12 +16,18 @@
* You should have received a copy of the GNU General Public License along with
* pcsc-relay. If not, see .
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "pcsc-relay.h"
+
+#ifdef ENABLE_LIBNFC
+
#include
#include
#include
-#include "pcsc-relay.h"
-
struct lnfc_data {
/* PN53X only supports short APDUs */
uint8_t abtCapdu[4+1+0xff+1];
@@ -101,7 +107,6 @@ static size_t get_historical_bytes(unsigned char *atr, size_t atrlen,
}
#endif
-
static int lnfc_connect(driver_data_t **driver_data)
{
struct lnfc_data *data;
@@ -237,6 +242,37 @@ static int lnfc_send_rapdu(driver_data_t *driver_data,
return 1;
}
+#else
+
+static int error(void)
+{
+ RELAY_ERROR("Compiled without support for libnfc\n");
+ return 0;
+}
+
+static int lnfc_connect(driver_data_t **driver_data)
+{
+ return error();
+}
+
+static int lnfc_disconnect(driver_data_t *driver_data)
+{
+ return error();
+}
+
+static int lnfc_receive_capdu(driver_data_t *driver_data,
+ unsigned char **capdu, size_t *len)
+{
+ return error();
+}
+
+static int lnfc_send_rapdu(driver_data_t *driver_data,
+ const unsigned char *rapdu, size_t len)
+{
+ return error();
+}
+
+#endif
struct rf_driver driver_libnfc = {
.connect = lnfc_connect,