Skip to content

Commit

Permalink
pcsc-relay: Made libnfc optional
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmorgner committed Mar 2, 2017
1 parent 7e70c87 commit c2b90a0
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 18 deletions.
57 changes: 43 additions & 14 deletions pcsc-relay/configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -57,33 +57,62 @@ 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"
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
Expand Down Expand Up @@ -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}
Expand Down
1 change: 0 additions & 1 deletion pcsc-relay/doc/README.txt.in
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 39 additions & 3 deletions pcsc-relay/src/lnfc.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,18 @@
* You should have received a copy of the GNU General Public License along with
* pcsc-relay. If not, see <http://www.gnu.org/licenses/>.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include "pcsc-relay.h"

#ifdef ENABLE_LIBNFC

#include <nfc/nfc.h>
#include <stdlib.h>
#include <string.h>

#include "pcsc-relay.h"

struct lnfc_data {
/* PN53X only supports short APDUs */
uint8_t abtCapdu[4+1+0xff+1];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit c2b90a0

Please sign in to comment.