Merge r511-519 from trunk.
This commit is contained in:
commit
b289784359
8 changed files with 125 additions and 15 deletions
|
@ -2,7 +2,7 @@ ACLOCAL_AMFLAGS = -I m4
|
||||||
|
|
||||||
AM_CFLAGS = $(LIBNFC_CFLAGS)
|
AM_CFLAGS = $(LIBNFC_CFLAGS)
|
||||||
|
|
||||||
SUBDIRS = libnfc examples include cmake_modules
|
SUBDIRS = libnfc examples include cmake_modules test
|
||||||
|
|
||||||
pkgconfigdir = $(libdir)/pkgconfig
|
pkgconfigdir = $(libdir)/pkgconfig
|
||||||
pkgconfig_DATA = libnfc.pc
|
pkgconfig_DATA = libnfc.pc
|
||||||
|
|
|
@ -111,6 +111,14 @@ AC_SUBST(PKG_CONFIG_REQUIRES)
|
||||||
AM_CONDITIONAL(LIBUSB_ENABLED, [test "$HAVE_LIBUSB" = "1"])
|
AM_CONDITIONAL(LIBUSB_ENABLED, [test "$HAVE_LIBUSB" = "1"])
|
||||||
AM_CONDITIONAL(PCSC_ENABLED, [test "$HAVE_PCSC" = "1"])
|
AM_CONDITIONAL(PCSC_ENABLED, [test "$HAVE_PCSC" = "1"])
|
||||||
|
|
||||||
|
CUTTER_REQUIRED_VERSION=1.1.2
|
||||||
|
m4_ifdef([AC_CHECK_CUTTER], [AC_CHECK_CUTTER([>= $CUTTER_REQUIRED_VERSION])], [ac_cv_use_cutter="no"])
|
||||||
|
if test x$ac_cv_with_cutter = xyes -a x$ac_cv_use_cutter = xno; then
|
||||||
|
AC_MSG_ERROR([cutter >= $CUTTER_REQUIRED_VERSION is mandatory.])
|
||||||
|
fi
|
||||||
|
AM_CONDITIONAL([WITH_CUTTER], [test "$ac_cv_use_cutter" != "no"])
|
||||||
|
|
||||||
|
|
||||||
# Defines and C flags
|
# Defines and C flags
|
||||||
CFLAGS="$CFLAGS -std=c99"
|
CFLAGS="$CFLAGS -std=c99"
|
||||||
|
|
||||||
|
@ -127,6 +135,7 @@ AC_CONFIG_FILES([
|
||||||
libnfc/Makefile
|
libnfc/Makefile
|
||||||
examples/Makefile
|
examples/Makefile
|
||||||
cmake_modules/Makefile
|
cmake_modules/Makefile
|
||||||
|
test/Makefile
|
||||||
libnfc.pc
|
libnfc.pc
|
||||||
Doxyfile
|
Doxyfile
|
||||||
])
|
])
|
||||||
|
|
|
@ -65,8 +65,8 @@ static void
|
||||||
print_success_or_failure (bool bFailure, uint32_t * uiBlockCounter)
|
print_success_or_failure (bool bFailure, uint32_t * uiBlockCounter)
|
||||||
{
|
{
|
||||||
printf ("%c", (bFailure) ? 'x' : '.');
|
printf ("%c", (bFailure) ? 'x' : '.');
|
||||||
if (uiBlockCounter)
|
if (uiBlockCounter && !bFailure)
|
||||||
*uiBlockCounter += (bFailure) ? 0 : 4;
|
*uiBlockCounter += (*uiBlockCounter < 128) ? 4 : 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool
|
static bool
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
* Public platform independent Near Field Communication (NFC) library
|
* Public platform independent Near Field Communication (NFC) library
|
||||||
*
|
*
|
||||||
* Copyright (C) 2009, Roel Verdult
|
* Copyright (C) 2009, Roel Verdult
|
||||||
|
* Copyright (C) 2010, Romain Tartière, Romuald Conty
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify it
|
* 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
|
* under the terms of the GNU Lesser General Public License as published by the
|
||||||
|
@ -220,16 +221,17 @@ void pn53x_usb_disconnect(nfc_device_t* pnd)
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if((ret = usb_release_interface(pus->pudh,0)) < 0) {
|
if((ret = usb_release_interface(pus->pudh,0)) < 0) {
|
||||||
DBG("usb_release failed %i",ret);
|
ERR("usb_release_interface failed (%i)",ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((ret = usb_close(pus->pudh)) < 0) {
|
if((ret = usb_close(pus->pudh)) < 0) {
|
||||||
DBG("usb_close failed %i",ret);
|
ERR("usb_close failed (%i)",ret);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
DBG("%s","resetting USB");
|
if((ret = usb_reset(pus->pudh)) < 0) {
|
||||||
usb_reset(pus->pudh);
|
ERR("usb_reset failed (%i, if errno: %s)",ret, strerror(-ret));
|
||||||
|
}
|
||||||
|
*/
|
||||||
free(pnd->nds);
|
free(pnd->nds);
|
||||||
free(pnd);
|
free(pnd);
|
||||||
}
|
}
|
||||||
|
|
14
libnfc/nfc.c
14
libnfc/nfc.c
|
@ -233,12 +233,14 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd)
|
||||||
*/
|
*/
|
||||||
void nfc_disconnect(nfc_device_t* pnd)
|
void nfc_disconnect(nfc_device_t* pnd)
|
||||||
{
|
{
|
||||||
// Release and deselect all active communications
|
if(pnd) {
|
||||||
nfc_initiator_deselect_target(pnd);
|
// Release and deselect all active communications
|
||||||
// Disable RF field to avoid heating
|
nfc_initiator_deselect_target(pnd);
|
||||||
nfc_configure(pnd,NDO_ACTIVATE_FIELD,false);
|
// Disable RF field to avoid heating
|
||||||
// Disconnect, clean up and release the device
|
nfc_configure(pnd,NDO_ACTIVATE_FIELD,false);
|
||||||
pnd->pdc->disconnect(pnd);
|
// Disconnect, clean up and release the device
|
||||||
|
pnd->pdc->disconnect(pnd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
24
test/Makefile.am
Normal file
24
test/Makefile.am
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
# $Id$
|
||||||
|
|
||||||
|
INCLUDES = $(CUTTER_CFLAGS) $(LIBNFC_CFLAGS)
|
||||||
|
LIBS = $(CUTTER_LIBS)
|
||||||
|
|
||||||
|
if WITH_CUTTER
|
||||||
|
TESTS = run-test.sh
|
||||||
|
TESTS_ENVIRONMENT = NO_MAKE=yes CUTTER="$(CUTTER)"
|
||||||
|
|
||||||
|
noinst_LTLIBRARIES = \
|
||||||
|
test_access.la
|
||||||
|
|
||||||
|
AM_LDFLAGS = -module -rpath $(libdir) -avoid-version -no-undefined
|
||||||
|
|
||||||
|
test_access_la_SOURCES = test_access.c
|
||||||
|
test_access_la_LIBADD = $(top_builddir)/libnfc/libnfc.la
|
||||||
|
|
||||||
|
echo-cutter:
|
||||||
|
@echo $(CUTTER)
|
||||||
|
|
||||||
|
EXTRA_DIST = run-test.sh
|
||||||
|
CLEANFILES = *.gcno
|
||||||
|
|
||||||
|
endif
|
17
test/run-test.sh
Executable file
17
test/run-test.sh
Executable file
|
@ -0,0 +1,17 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
export BASE_DIR="`dirname $0`"
|
||||||
|
|
||||||
|
if test -z "$NO_MAKE"; then
|
||||||
|
make -C "$BASE_DIR/../" > /dev/null || exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if test -z "$CUTTER"; then
|
||||||
|
CUTTER="`make -s -C "$BASE_DIR" echo-cutter`"
|
||||||
|
fi
|
||||||
|
|
||||||
|
"$CUTTER" --keep-opening-modules -s "$BASE_DIR" "$@" "$BASE_DIR"
|
||||||
|
# ^^^^^^^^^^^^^^^^^^^^^^
|
||||||
|
# FIXME: Remove this workaround once cutter has been fixed upstream.
|
||||||
|
# Bug report:
|
||||||
|
# http://sourceforge.net/mailarchive/forum.php?thread_name=20100626123941.GA258%40blogreen.org&forum_name=cutter-users-en
|
56
test/test_access.c
Normal file
56
test/test_access.c
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
#include <cutter.h>
|
||||||
|
|
||||||
|
#include <nfc/nfc.h>
|
||||||
|
|
||||||
|
#define NTESTS 42
|
||||||
|
#define MAX_TARGET_COUNT 8
|
||||||
|
|
||||||
|
void
|
||||||
|
test_access (void)
|
||||||
|
{
|
||||||
|
int n = NTESTS;
|
||||||
|
nfc_device_desc_t devices[8];
|
||||||
|
size_t device_count, ref_device_count, target_count;
|
||||||
|
bool res;
|
||||||
|
|
||||||
|
nfc_list_devices (devices, 8, &ref_device_count);
|
||||||
|
if (!ref_device_count)
|
||||||
|
cut_omit ("No NFC device found");
|
||||||
|
|
||||||
|
while (n) {
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
nfc_list_devices (devices, 8, &device_count);
|
||||||
|
cut_assert_equal_int (ref_device_count, device_count, cut_message ("device count"));
|
||||||
|
|
||||||
|
for (i = 0; i < device_count; i++) {
|
||||||
|
nfc_device_t *device;
|
||||||
|
nfc_target_info_t anti[MAX_TARGET_COUNT];
|
||||||
|
|
||||||
|
device = nfc_connect (&(devices[i]));
|
||||||
|
cut_assert_not_null (device, cut_message ("nfc_connect"));
|
||||||
|
|
||||||
|
nfc_initiator_init(device);
|
||||||
|
|
||||||
|
// Drop the field for a while
|
||||||
|
nfc_configure(device,NDO_ACTIVATE_FIELD,false);
|
||||||
|
|
||||||
|
// Let the reader only try once to find a tag
|
||||||
|
nfc_configure(device,NDO_INFINITE_SELECT,false);
|
||||||
|
|
||||||
|
// Configure the CRC and Parity settings
|
||||||
|
nfc_configure(device,NDO_HANDLE_CRC,true);
|
||||||
|
nfc_configure(device,NDO_HANDLE_PARITY,true);
|
||||||
|
|
||||||
|
// Enable field so more power consuming cards can power themselves
|
||||||
|
nfc_configure(device,NDO_ACTIVATE_FIELD,true);
|
||||||
|
|
||||||
|
res = nfc_initiator_list_passive_targets(device, NM_ISO14443A_106, anti, MAX_TARGET_COUNT, &target_count);
|
||||||
|
cut_assert_true (res, cut_message ("nfc_initiator_list_passive_targets"));
|
||||||
|
|
||||||
|
nfc_disconnect (device);
|
||||||
|
}
|
||||||
|
|
||||||
|
n--;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue