adapted to API changes of libnfc 1.6
git-svn-id: https://vsmartcard.svn.sourceforge.net/svnroot/vsmartcard@733 96b47cad-a561-4643-ad3b-153ac7d7599c
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
# Process this file with autoconf to produce a configure script.
|
# Process this file with autoconf to produce a configure script.
|
||||||
|
|
||||||
AC_PREREQ([2.65])
|
AC_PREREQ([2.65])
|
||||||
AC_INIT([pcsc-relay], [0.2], [http://sourceforge.net/projects/vsmartcard/support])
|
AC_INIT([pcsc-relay], [0.3], [http://sourceforge.net/projects/vsmartcard/support])
|
||||||
AC_CONFIG_SRCDIR([src/pcsc-relay.c])
|
AC_CONFIG_SRCDIR([src/pcsc-relay.c])
|
||||||
AC_CONFIG_HEADERS([config.h])
|
AC_CONFIG_HEADERS([config.h])
|
||||||
AM_INIT_AUTOMAKE
|
AM_INIT_AUTOMAKE
|
||||||
@@ -21,9 +21,9 @@ PKG_CHECK_EXISTS([libpcsclite],
|
|||||||
[PKG_CHECK_MODULES([PCSC], [libpcsclite])],
|
[PKG_CHECK_MODULES([PCSC], [libpcsclite])],
|
||||||
[AC_MSG_WARN([libpcsclite not found by pkg-config])])
|
[AC_MSG_WARN([libpcsclite not found by pkg-config])])
|
||||||
# Checks for libraries.
|
# Checks for libraries.
|
||||||
PKG_CHECK_EXISTS([libnfc >= 1.5.1],
|
PKG_CHECK_EXISTS([libnfc >= 1.6],
|
||||||
[PKG_CHECK_MODULES([LIBNFC], [libnfc >= 1.5.1])],
|
[PKG_CHECK_MODULES([LIBNFC], [libnfc >= 1.6])],
|
||||||
[AC_MSG_WARN([libnfc >= 1.5.1 not found by pkg-config])])
|
[AC_MSG_WARN([libnfc >= 1.6 not found by pkg-config])])
|
||||||
|
|
||||||
|
|
||||||
saved_CPPFLAGS="$CPPFLAGS"
|
saved_CPPFLAGS="$CPPFLAGS"
|
||||||
@@ -40,7 +40,7 @@ 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_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_MSG_CHECKING([for nfc_initiator_select_passive_target])
|
||||||
AC_TRY_LINK_FUNC(nfc_initiator_select_passive_target, [ AC_MSG_RESULT([yes]) ],
|
AC_TRY_LINK_FUNC(nfc_initiator_select_passive_target, [ AC_MSG_RESULT([yes]) ],
|
||||||
[ AC_MSG_ERROR([libnfc >= 1.5.1 not found, use ./configure LIBNFC_LIBS=...]) ])
|
[ AC_MSG_ERROR([libnfc >= 1.6 not found, use ./configure LIBNFC_LIBS=...]) ])
|
||||||
CPPFLAGS="$saved_CPPFLAGS"
|
CPPFLAGS="$saved_CPPFLAGS"
|
||||||
LIBS="$saved_LIBS"
|
LIBS="$saved_LIBS"
|
||||||
|
|
||||||
@@ -67,7 +67,6 @@ pcsc-relay has been configured with following options:
|
|||||||
|
|
||||||
Version: ${PACKAGE_VERSION}
|
Version: ${PACKAGE_VERSION}
|
||||||
User binaries: $(eval eval eval echo "${bindir}")
|
User binaries: $(eval eval eval echo "${bindir}")
|
||||||
Configuration files: $(eval eval eval echo "${sysconfdir}")
|
|
||||||
|
|
||||||
|
|
||||||
Host: ${host}
|
Host: ${host}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (C) 2011 Frank Morgner
|
* Copyright (C) 2012 Frank Morgner
|
||||||
*
|
*
|
||||||
* This file is part of pcsc-relay.
|
* This file is part of pcsc-relay.
|
||||||
*
|
*
|
||||||
@@ -24,16 +24,15 @@
|
|||||||
|
|
||||||
struct lnfc_data {
|
struct lnfc_data {
|
||||||
/* PN53X only supports short APDUs */
|
/* PN53X only supports short APDUs */
|
||||||
byte_t abtCapdu[4+1+0xff+1];
|
uint8_t abtCapdu[4+1+0xff+1];
|
||||||
size_t szCapduLen;
|
int iCapduLen;
|
||||||
nfc_device_t *pndTarget;
|
nfc_device *pndTarget;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static struct timeval transmit_timeout = {
|
/* Wait 5 seconds for (R-)APDUs, which is the maximum frame waiting time
|
||||||
1, /* seconds */
|
* according to 14443-4 */
|
||||||
0, /* microseconds */
|
#define TRANSMIT_TIMEOUT 5000
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static size_t get_historical_bytes(unsigned char *atr, size_t atrlen,
|
static size_t get_historical_bytes(unsigned char *atr, size_t atrlen,
|
||||||
@@ -109,7 +108,7 @@ static int lnfc_connect(driver_data_t **driver_data)
|
|||||||
{
|
{
|
||||||
struct lnfc_data *data;
|
struct lnfc_data *data;
|
||||||
/* data derived from German (test) identity card issued 2010 */
|
/* data derived from German (test) identity card issued 2010 */
|
||||||
nfc_target_t ntEmulatedTarget = {
|
nfc_target ntEmulatedTarget = {
|
||||||
.nti.nai.abtAtqa = {0x00, 0x08},
|
.nti.nai.abtAtqa = {0x00, 0x08},
|
||||||
.nti.nai.btSak = 0x20,
|
.nti.nai.btSak = 0x20,
|
||||||
.nti.nai.szUidLen = 4,
|
.nti.nai.szUidLen = 4,
|
||||||
@@ -141,19 +140,20 @@ static int lnfc_connect(driver_data_t **driver_data)
|
|||||||
*driver_data = data;
|
*driver_data = data;
|
||||||
|
|
||||||
|
|
||||||
data->pndTarget = nfc_connect (NULL);
|
data->pndTarget = nfc_open(NULL, NULL);
|
||||||
if (data->pndTarget == NULL) {
|
if (data->pndTarget == NULL) {
|
||||||
ERROR("Error connecting to NFC emulator device\n");
|
ERROR("Error connecting to NFC emulator device\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (verbose >= 0)
|
if (verbose >= 0)
|
||||||
printf("Connected to %s\n", nfc_device_name(data->pndTarget));
|
printf("Connected to %s\n", nfc_device_get_name(data->pndTarget));
|
||||||
|
|
||||||
DEBUG("Waiting for a command that is not part of the anti-collision...\n");
|
DEBUG("Waiting for a command that is not part of the anti-collision...\n");
|
||||||
if (!nfc_target_init (data->pndTarget, &ntEmulatedTarget, data->abtCapdu, &data->szCapduLen)) {
|
data->iCapduLen = nfc_target_init(data->pndTarget, &ntEmulatedTarget, data->abtCapdu, sizeof data->abtCapdu, 0);
|
||||||
|
if (data->iCapduLen < 0) {
|
||||||
ERROR("nfc_target_init: %s\n", nfc_strerror(data->pndTarget));
|
ERROR("nfc_target_init: %s\n", nfc_strerror(data->pndTarget));
|
||||||
nfc_disconnect (data->pndTarget);
|
nfc_close (data->pndTarget);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
DEBUG("Initialized NFC emulator\n");
|
DEBUG("Initialized NFC emulator\n");
|
||||||
@@ -168,7 +168,7 @@ static int lnfc_disconnect(driver_data_t *driver_data)
|
|||||||
|
|
||||||
|
|
||||||
if (data) {
|
if (data) {
|
||||||
nfc_disconnect (data->pndTarget);
|
nfc_close(data->pndTarget);
|
||||||
free(data);
|
free(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,20 +187,21 @@ static int lnfc_receive_capdu(driver_data_t *driver_data,
|
|||||||
|
|
||||||
|
|
||||||
// Receive external reader command through target
|
// Receive external reader command through target
|
||||||
if (!nfc_target_receive_bytes(data->pndTarget, data->abtCapdu, &data->szCapduLen, &transmit_timeout)) {
|
data->iCapduLen = nfc_target_receive_bytes(data->pndTarget, data->abtCapdu, sizeof data->abtCapdu, TRANSMIT_TIMEOUT);
|
||||||
|
if (data->iCapduLen < 0) {
|
||||||
ERROR ("nfc_target_receive_bytes: %s\n", nfc_strerror(data->pndTarget));
|
ERROR ("nfc_target_receive_bytes: %s\n", nfc_strerror(data->pndTarget));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
p = realloc(*capdu, data->szCapduLen);
|
p = realloc(*capdu, data->iCapduLen);
|
||||||
if (!p) {
|
if (!p) {
|
||||||
ERROR("Error allocating memory for C-APDU\n");
|
ERROR("Error allocating memory for C-APDU\n");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
memcpy(p, data->abtCapdu, data->szCapduLen);
|
memcpy(p, data->abtCapdu, data->iCapduLen);
|
||||||
*capdu = p;
|
*capdu = p;
|
||||||
*len = data->szCapduLen;
|
*len = data->iCapduLen;
|
||||||
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
@@ -210,15 +211,19 @@ static int lnfc_send_rapdu(driver_data_t *driver_data,
|
|||||||
const unsigned char *rapdu, size_t len)
|
const unsigned char *rapdu, size_t len)
|
||||||
{
|
{
|
||||||
struct lnfc_data *data = driver_data;
|
struct lnfc_data *data = driver_data;
|
||||||
|
int r;
|
||||||
|
|
||||||
if (!data || !rapdu)
|
if (!data || !rapdu)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
|
||||||
if (!nfc_target_send_bytes(data->pndTarget, rapdu, len, &transmit_timeout)) {
|
r = nfc_target_send_bytes(data->pndTarget, rapdu, len, TRANSMIT_TIMEOUT);
|
||||||
|
if (r < 0) {
|
||||||
ERROR ("nfc_target_send_bytes: %s\n", nfc_strerror(data->pndTarget));
|
ERROR ("nfc_target_send_bytes: %s\n", nfc_strerror(data->pndTarget));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
if (r < len)
|
||||||
|
INFO ("Transmitted %d less bytes than desired: %s\n", len-r, nfc_strerror(data->pndTarget));
|
||||||
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|||||||
Reference in New Issue
Block a user