diff --git a/ChangeLog b/ChangeLog
index da1a693..7075bcd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,23 @@
+Jan TBD, 2013 - 1.7.0-rc3 (release candidate)
+--------------------------------------------
+
+Fixes:
+ - Fix pn53x_usb bulk write timeout
+ - Fix BCC in nfc-emulate-uid example
+ - Fix nfc-relay-picc example
+ - Fix a miss returned value within some internal functions (user program could
+ be affected)
+ - Fix nfc-scan-device -i option
+ - Remove wrong exit() calls in library
+ - Fix issue in driver acr122_usb affecting Touchatag
+ - Reenable some idle in all drivers, add selectively PowerDown when possible
+
+Changes:
+ - nfc_emulate_target() now takes timeout parameter
+
+Special thanks to:
+ - Alex Lian (Windows support refresh)
+
Jan 20, 2013 - 1.7.0-rc2 (release candidate)
--------------------------------------------
diff --git a/NEWS b/NEWS
index 62f7aa0..055aa98 100644
--- a/NEWS
+++ b/NEWS
@@ -1,3 +1,10 @@
+New in 1.7.0-rc3:
+
+API Changes:
+
+ * Functions
+ - Add timeout param to nfc_emulate_target()
+
New in 1.7.0-rc2:
Configuration:
diff --git a/README b/README
index 905fe80..5f44476 100644
--- a/README
+++ b/README
@@ -10,7 +10,7 @@ General Information
libnfc is a library which allows userspace application access to NFC devices.
The official web site is:
- http://www.libnfc.org/
+ http://www.nfc-tools.org/
The official forum site is:
http://www.libnfc.org/community/
@@ -23,17 +23,17 @@ Important note: this file covers POSIX systems, for Windows please read README-W
Requirements
============
-Some NFC drivers depends on third party software:
+Some NFC drivers depend on third party software:
-* pn53x_usb:
+* pn53x_usb & acr122_usb:
- libusb-0.1 http://libusb.sf.net
-* acr122:
+* acr122_pcsc:
- pcsc-lite http://pcsclite.alioth.debian.org/
-The regression test suite depend on the cutter framework:
+The regression test suite depends on the cutter framework:
http://cutter.sf.net
Installation
@@ -69,7 +69,14 @@ Please make sure to include:
And anything else you think is relevant.
-* How to reproduce the bug.
+* A trace with debug activated.
+
+ Reproduce the bug with debug, e.g. if it was:
+ $ nfc-list -v
+ run it as:
+ $ LIBNFC_LOG_LEVEL=3 nfc-list -v
+
+* How to reproduce the bug.
Please include a short test program that exhibits the behavior.
As a last resort, you can also provide a pointer to a larger piece
@@ -85,7 +92,8 @@ Patches
=======
Patches can be posted to http://code.google.com/p/libnfc/issues/list or
-can be sent directly to libnfc's developers: http://www.libnfc.org/contact
+can be sent directly to libnfc's developers:
+http://nfc-tools.org/index.php?title=Contact
If the patch fixes a bug, it is usually a good idea to include
all the information described in "How to Report Bugs".
diff --git a/README-Windows.txt b/README-Windows.txt
index 5f049d1..3a322c0 100644
--- a/README-Windows.txt
+++ b/README-Windows.txt
@@ -1,6 +1,8 @@
*-
* Public platform independent Near Field Communication (NFC) library
+* Windows-specific parts:
* Copyright (C) 2010, Glenn Ergeerts
+* Copyright (C) 2013, Alex Lian
-*
Requirements
diff --git a/configure.ac b/configure.ac
index 944835b..6fd18d7 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,7 +1,7 @@
# General init
# /!\ Don't forget to update 'CMakeLists.txt' too /!\
-AC_INIT([libnfc],[1.7.0-rc2],[info@libnfc.org])
+AC_INIT([libnfc],[1.7.0-rc3],[info@libnfc.org])
AC_CONFIG_MACRO_DIR([m4])
diff --git a/contrib/win32/Makefile.am b/contrib/win32/Makefile.am
index 135834f..978c2ed 100644
--- a/contrib/win32/Makefile.am
+++ b/contrib/win32/Makefile.am
@@ -1,4 +1,6 @@
SUBDIRS = sys .
EXTRA_DIST = \
- err.h
+ err.h \
+ stdlib.c \
+ unistd.h
diff --git a/contrib/win32/stdlib.c b/contrib/win32/stdlib.c
new file mode 100644
index 0000000..87cbd4e
--- /dev/null
+++ b/contrib/win32/stdlib.c
@@ -0,0 +1,46 @@
+/*-
+ * Public platform independent Near Field Communication (NFC) library
+ *
+ * Copyright (C) 2013 Alex Lian
+ *
+ * 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
+ * Free Software Foundation, either version 3 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see
+ *
+ */
+
+/**
+ * @file stdlib.c
+ * @brief Windows System compatibility
+ */
+
+// Handle platform specific includes
+#include "contrib/windows.h"
+
+int setenv(const char *name, const char *value, int overwrite)
+{
+ int exists = GetEnvironmentVariableA(name, NULL, 0);
+ if ((exists && overwrite) || (!exists)) {
+ if (!SetEnvironmentVariableA(name, value)) {
+ // Set errno here correctly
+ return -1;
+ }
+ return 0;
+ }
+ // Exists and overwrite is 0.
+ return -1;
+}
+
+void unsetenv(const char *name)
+{
+ SetEnvironmentVariableA(name, NULL);
+}
diff --git a/contrib/win32/unistd.h b/contrib/win32/unistd.h
index bc7965c..89aeda8 100644
--- a/contrib/win32/unistd.h
+++ b/contrib/win32/unistd.h
@@ -1,7 +1,7 @@
/*-
* Public platform independent Near Field Communication (NFC) library
*
- * Copyright (C) 2011, 2012 Romuald Conty
+ * Copyright (C) 2011, 2012, 2013 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
@@ -31,5 +31,11 @@
# include
# define sleep(X) Sleep( X * 1000)
+// With MinGW, getopt(3) is provided as separate header
+#if defined(WIN32) && defined(__GNUC__) /* mingw compiler */
+#include
+#endif
+
+
#endif /* _UNISTD_H_ */
diff --git a/contrib/windows.h b/contrib/windows.h
index 52d936b..2384d59 100644
--- a/contrib/windows.h
+++ b/contrib/windows.h
@@ -45,7 +45,7 @@
# define strdup _strdup
# endif
-/*
+/*
* setenv and unsetenv are not Windows compliant nor implemented in MinGW.
* These declarations get rid of the "implicit declaration warning."
*/
diff --git a/debian/changelog b/debian/changelog
index f79ff43..a83d45a 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,8 +1,8 @@
-libnfc (1.7.0~rc2-1) unstable; urgency=low
+libnfc (1.7.0~rc3-1) unstable; urgency=low
* Upload to Debian. (Closes: #672795)
- -- Nobuhiro Iwamatsu Mon, 21 Jan 2013 14:19:24 +0900
+ -- Nobuhiro Iwamatsu Fri, 01 Feb 2013 09:01:53 +0900
libnfc (1.7.0~rc2-0) unstable; urgency=low
diff --git a/debian/control b/debian/control
index 37bb20a..763d815 100644
--- a/debian/control
+++ b/debian/control
@@ -4,7 +4,7 @@ Priority: extra
Maintainer: Nobuhiro Iwamatsu
Build-Depends: debhelper (>= 8), dh-autoreconf, libtool, pkg-config, libusb-dev
Standards-Version: 3.9.4
-Homepage: http://www.libnfc.org/
+Homepage: http://www.nfc-tools.org/
Vcs-Git: https://code.googlecode.com/p/libnfc/
Vcs-Browser: http://code.google.com/p/libnfc/source/browse/
@@ -14,9 +14,14 @@ Multi-Arch: same
Pre-Depends: ${misc:Pre-Depends}
Depends: ${shlibs:Depends}, ${misc:Depends}
Description: Near Field Communication (NFC) library
- libnfc is a Free Software library for Near Field Communication.
- Supported NFC hardware devices are, theorically, all hardware
- based on the NXP PN531, PN532 or PN533 NFC controller chip.
+ libnfc is a library for Near Field Communication. It abstracts the
+ low-level details of communicating with the devices away behind an
+ easy-to-use high-level API.
+ It supports most hardware based on the NXP PN531, PN532 or PN533
+ controller chips.
+ .
+ This package contains the runtime library files needed to run software
+ using libnfc.
Package: libnfc-dev
Section: libdevel
@@ -24,24 +29,57 @@ Architecture: any
Multi-Arch: same
Pre-Depends: ${misc:Pre-Depends}
Depends: ${misc:Depends}, libnfc4 (= ${binary:Version}), libusb-dev
-Description: Near Field Communication library (development files)
- libnfc is a free software library for near-field communication.
+Description: Near Field Communication (NFC) library (development files)
+ libnfc is a library for Near Field Communication. It abstracts the
+ low-level details of communicating with the devices away behind an
+ easy-to-use high-level API.
It supports most hardware based on the NXP PN531, PN532 or PN533
controller chips.
+ .
+ This package contains the header and development files needed to build
+ programs and packages using libnfc.
+
+Package: libnfc4-dbg
+Section: debug
+Architecture: any
+Multi-Arch: same
+Pre-Depends: ${misc:Pre-Depends}
+Depends: ${misc:Depends}, libnfc4 (= ${binary:Version})
+Description: Near Field Communication (NFC) library (debugging information)
+ libnfc is a library for Near Field Communication. It abstracts the
+ low-level details of communicating with the devices away behind an
+ easy-to-use high-level API.
+ It supports most hardware based on the NXP PN531, PN532 or PN533
+ controller chips.
+ .
+ This package contains the debugging information.
Package: libnfc-bin
Section: utils
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libnfc4 (>= ${binary:Version})
-Description: Near Field Communication binaries
- Some binaries are provided with libnfc useful for development
- purposes (nfc-list, nfc-mfclassic, nfc-mfultralight, etc.).
+Description: Near Field Communication (NFC) binaries
+ libnfc is a library for Near Field Communication. It abstracts the
+ low-level details of communicating with the devices away behind an
+ easy-to-use high-level API.
+ It supports most hardware based on the NXP PN531, PN532 or PN533
+ controller chips.
+ .
+ This package contains some utils that come along with libnfc, for
+ development or debugging purposes (including nfc-list, nfc-mfclassic,
+ nfc-mfultralight, etc).
Package: libnfc-examples
Section: utils
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libnfc4 (>= ${binary:Version})
-Description: Near Field Communication examples
+Description: Near Field Communication (NFC) examples
+ libnfc is a library for Near Field Communication. It abstracts the
+ low-level details of communicating with the devices away behind an
+ easy-to-use high-level API.
+ It supports most hardware based on the NXP PN531, PN532 or PN533
+ controller chips.
+ .
Some examples are provided with libnfc for debugging and/or
educational purposes (nfc-anticol, nfc-emulate, etc.).
@@ -49,6 +87,12 @@ Package: libnfc-pn53x-examples
Section: utils
Architecture: any
Depends: ${shlibs:Depends}, ${misc:Depends}, libnfc4 (>= ${binary:Version})
-Description: Near Field Communication examples for PN53x chips only
+Description: Near Field Communication (NFC) examples for PN53x chips only
+ libnfc is a library for Near Field Communication. It abstracts the
+ low-level details of communicating with the devices away behind an
+ easy-to-use high-level API.
+ It supports most hardware based on the NXP PN531, PN532 or PN533
+ controller chips.
+ .
Some PN53x-only examples are provided with libnfc for debugging
and/or educational purposes (pn53x-sam, pn53x-tamashell, etc.).
diff --git a/debian/copyright b/debian/copyright
index 1e9b121..b1d6826 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,6 +1,6 @@
Format: http://www.debian.org/doc/packaging-manuals/copyright-format/1.0/
Upstream-Name: libnfc
-Source: http://www.libnfc.org/
+Source: http://libnfc.googlecode.com/
Files: *
Copyright: 2009, Roel Verdult , Romuald Conty
diff --git a/debian/libnfc-examples.install b/debian/libnfc-examples.install
index f78621e..936bce1 100644
--- a/debian/libnfc-examples.install
+++ b/debian/libnfc-examples.install
@@ -10,6 +10,7 @@ debian/tmp/usr/bin/nfc-relay
debian/tmp/usr/share/man/man1/nfc-anticol.1
debian/tmp/usr/share/man/man1/nfc-dep-initiator.1
debian/tmp/usr/share/man/man1/nfc-dep-target.1
+debian/tmp/usr/share/man/man1/nfc-emulate-forum-tag2.1
debian/tmp/usr/share/man/man1/nfc-emulate-tag.1
debian/tmp/usr/share/man/man1/nfc-emulate-uid.1
debian/tmp/usr/share/man/man1/nfc-mfsetuid.1
diff --git a/debian/libnfc4.symbols b/debian/libnfc4.symbols
new file mode 100644
index 0000000..7c2303f
--- /dev/null
+++ b/debian/libnfc4.symbols
@@ -0,0 +1,54 @@
+libnfc.so.4 libnfc4 #MINVER#
+ iso14443a_crc@Base 1.7.0~rc2
+ iso14443a_crc_append@Base 1.7.0~rc2
+ iso14443a_locate_historical_bytes@Base 1.7.0~rc2
+ nfc_abort_command@Base 1.7.0~rc2
+ nfc_close@Base 1.7.0~rc2
+ nfc_context_free@Base 1.7.0~rc2
+ nfc_context_new@Base 1.7.0~rc2
+ nfc_device_free@Base 1.7.0~rc2
+ nfc_device_get_connstring@Base 1.7.0~rc2
+ nfc_device_get_information_about@Base 1.7.0~rc2
+ nfc_device_get_last_error@Base 1.7.0~rc2
+ nfc_device_get_name@Base 1.7.0~rc2
+ nfc_device_get_supported_baud_rate@Base 1.7.0~rc2
+ nfc_device_get_supported_modulation@Base 1.7.0~rc2
+ nfc_device_new@Base 1.7.0~rc2
+ nfc_device_set_property_bool@Base 1.7.0~rc2
+ nfc_device_set_property_int@Base 1.7.0~rc2
+ nfc_drivers@Base 1.7.0~rc2
+ nfc_emulate_target@Base 1.7.0~rc2
+ nfc_exit@Base 1.7.0~rc2
+ nfc_idle@Base 1.7.0~rc2
+ nfc_init@Base 1.7.0~rc2
+ nfc_initiator_deselect_target@Base 1.7.0~rc2
+ nfc_initiator_init@Base 1.7.0~rc2
+ nfc_initiator_init_secure_element@Base 1.7.0~rc2
+ nfc_initiator_list_passive_targets@Base 1.7.0~rc2
+ nfc_initiator_poll_dep_target@Base 1.7.0~rc2
+ nfc_initiator_poll_target@Base 1.7.0~rc2
+ nfc_initiator_select_dep_target@Base 1.7.0~rc2
+ nfc_initiator_select_passive_target@Base 1.7.0~rc2
+ nfc_initiator_target_is_present@Base 1.7.0~rc2
+ nfc_initiator_transceive_bits@Base 1.7.0~rc2
+ nfc_initiator_transceive_bits_timed@Base 1.7.0~rc2
+ nfc_initiator_transceive_bytes@Base 1.7.0~rc2
+ nfc_initiator_transceive_bytes_timed@Base 1.7.0~rc2
+ nfc_list_devices@Base 1.7.0~rc2
+ nfc_open@Base 1.7.0~rc2
+ nfc_perror@Base 1.7.0~rc2
+ nfc_strerror@Base 1.7.0~rc2
+ nfc_strerror_r@Base 1.7.0~rc2
+ nfc_target_init@Base 1.7.0~rc2
+ nfc_target_receive_bits@Base 1.7.0~rc2
+ nfc_target_receive_bytes@Base 1.7.0~rc2
+ nfc_target_send_bits@Base 1.7.0~rc2
+ nfc_target_send_bytes@Base 1.7.0~rc2
+ nfc_version@Base 1.7.0~rc2
+ pn532_SAMConfiguration@Base 1.7.0~rc2
+ pn53x_read_register@Base 1.7.0~rc2
+ pn53x_transceive@Base 1.7.0~rc2
+ pn53x_write_register@Base 1.7.0~rc2
+ str_nfc_baud_rate@Base 1.7.0~rc2
+ str_nfc_modulation_type@Base 1.7.0~rc2
+ str_nfc_target@Base 1.7.0~rc2
diff --git a/debian/rules b/debian/rules
index fbdd8f3..fad10c8 100755
--- a/debian/rules
+++ b/debian/rules
@@ -27,3 +27,7 @@ override_dh_auto_configure:
%:
dh $@ --with autoreconf
+
+override_dh_strip:
+ dh_strip -plibnfc4 --dbg-package=libnfc4-dbg
+ dh_strip --remaining-packages
diff --git a/examples/Makefile.am b/examples/Makefile.am
index d822df0..c767532 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -96,6 +96,7 @@ dist_man_MANS = \
nfc-mfsetuid.1 \
pn53x-diagnose.1 \
pn53x-sam.1 \
- pn53x-tamashell.1
+ pn53x-tamashell.1 \
+ nfc-emulate-forum-tag2.1
EXTRA_DIST = CMakeLists.txt
diff --git a/examples/nfc-emulate-forum-tag2.c b/examples/nfc-emulate-forum-tag2.c
index 325e256..8240a4e 100644
--- a/examples/nfc-emulate-forum-tag2.c
+++ b/examples/nfc-emulate-forum-tag2.c
@@ -197,7 +197,7 @@ main(int argc, char *argv[])
printf("NFC device: %s opened\n", nfc_device_get_name(pnd));
printf("Emulating NDEF tag now, please touch it with a second NFC device\n");
- if (nfc_emulate_target(pnd, &emulator) < 0) {
+ if (nfc_emulate_target(pnd, &emulator, 0) < 0) {
goto error;
}
diff --git a/include/nfc/nfc-emulation.h b/include/nfc/nfc-emulation.h
index 1a8576f..430f5b1 100644
--- a/include/nfc/nfc-emulation.h
+++ b/include/nfc/nfc-emulation.h
@@ -55,7 +55,7 @@ extern "C" {
void *data;
};
- NFC_EXPORT int nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator);
+ NFC_EXPORT int nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator, const int timeout);
#ifdef __cplusplus
}
diff --git a/libnfc/CMakeLists.txt b/libnfc/CMakeLists.txt
index f26d8ba..6bed790 100644
--- a/libnfc/CMakeLists.txt
+++ b/libnfc/CMakeLists.txt
@@ -1,7 +1,7 @@
# Windows MinGW workarounds
IF(WIN32)
message("Adding in contrib win32 sources")
- SET(WINDOWS_SOURCES ../contrib/win32/nfc_win32)
+ SET(WINDOWS_SOURCES ../contrib/win32/stdlib)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32)
message("Win32: " ${WINDOWS_SOURCES})
ENDIF(WIN32)
diff --git a/libnfc/additional-pages.dox b/libnfc/additional-pages.dox
index 37f1268..1fc57f9 100644
--- a/libnfc/additional-pages.dox
+++ b/libnfc/additional-pages.dox
@@ -4,7 +4,7 @@
* @section intro_sec Introduction
* This is the developer manual for \b libnfc.
* libnfc is an open source library that allows you to communicate with NFC devices. For more info, see the
- * libnfc homepage.
+ * libnfc homepage.
*
* @section quick_start_sec Quick start
* If you are looking for libnfc's public API, you should start with the Modules page which links to the different categories of libnfc's functionality.
diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c
index cd7c9d5..92ce658 100644
--- a/libnfc/chips/pn53x.c
+++ b/libnfc/chips/pn53x.c
@@ -947,30 +947,25 @@ pn53x_idle(struct nfc_device *pnd)
if ((res = pn53x_InRelease(pnd, 0)) < 0) {
return res;
}
- if (CHIP_DATA(pnd)->type == PN532) {
+ if ((CHIP_DATA(pnd)->type == PN532) && (pnd->driver->powerdown)) {
// Use PowerDown to go in "Low VBat" power mode
- if ((res = pn53x_PowerDown(pnd)) < 0) {
+ if ((res = pnd->driver->powerdown(pnd)) < 0) {
return res;
}
}
break;
case INITIATOR:
- // Deselect all active communications
- if ((res = pn53x_InDeselect(pnd, 0)) < 0) {
+ // Use InRelease to go in "Standby mode"
+ if ((res = pn53x_InRelease(pnd, 0)) < 0) {
return res;
}
// Disable RF field to avoid heating
if ((res = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, false)) < 0) {
return res;
}
- if (CHIP_DATA(pnd)->type == PN532) {
+ if ((CHIP_DATA(pnd)->type == PN532) && (pnd->driver->powerdown)) {
// Use PowerDown to go in "Low VBat" power mode
- if ((res = pn53x_PowerDown(pnd)) < 0) {
- return res;
- }
- } else {
- // Use InRelease to go in "Standby mode"
- if ((res = pn53x_InRelease(pnd, 0)) < 0) {
+ if ((res = pnd->driver->powerdown(pnd)) < 0) {
return res;
}
}
diff --git a/libnfc/drivers/acr122_pcsc.c b/libnfc/drivers/acr122_pcsc.c
index f189167..105a392 100644
--- a/libnfc/drivers/acr122_pcsc.c
+++ b/libnfc/drivers/acr122_pcsc.c
@@ -80,7 +80,7 @@
#define ACR122_PCSC_RESPONSE_LEN 268
#define LOG_GROUP NFC_LOG_GROUP_DRIVER
-#define LOG_CATEGORY "libnfc.driver.acr122"
+#define LOG_CATEGORY "libnfc.driver.acr122_pcsc"
// Internal data struct
const struct pn53x_io acr122_pcsc_io;
@@ -324,6 +324,8 @@ error:
static void
acr122_pcsc_close(nfc_device *pnd)
{
+ pn53x_idle(pnd);
+
SCardDisconnect(DRIVER_DATA(pnd)->hCard, SCARD_LEAVE_CARD);
acr122_pcsc_free_scardcontext();
@@ -516,6 +518,8 @@ const struct nfc_driver acr122_pcsc_driver = {
.device_get_information_about = pn53x_get_information_about,
.abort_command = NULL, // Abort is not supported in this driver
- .idle = NULL, // Idle is not supported in this driver
+ .idle = pn53x_idle,
+ /* Even if PN532, PowerDown is not recommended on those devices */
+ .powerdown = NULL,
};
diff --git a/libnfc/drivers/acr122_usb.c b/libnfc/drivers/acr122_usb.c
index e469aba..da14a60 100644
--- a/libnfc/drivers/acr122_usb.c
+++ b/libnfc/drivers/acr122_usb.c
@@ -551,7 +551,6 @@ static void
acr122_usb_close(nfc_device *pnd)
{
acr122_usb_ack(pnd);
-
pn53x_idle(pnd);
int res;
@@ -895,5 +894,7 @@ const struct nfc_driver acr122_usb_driver = {
.device_get_information_about = pn53x_get_information_about,
.abort_command = acr122_usb_abort_command,
- .idle = pn53x_idle,
+ .idle = pn53x_idle,
+ /* Even if PN532, PowerDown is not recommended on those devices */
+ .powerdown = NULL,
};
diff --git a/libnfc/drivers/acr122s.c b/libnfc/drivers/acr122s.c
index a2f4fa3..932d7c0 100644
--- a/libnfc/drivers/acr122s.c
+++ b/libnfc/drivers/acr122s.c
@@ -520,6 +520,8 @@ static void
acr122s_close(nfc_device *pnd)
{
acr122s_deactivate_sam(pnd);
+ pn53x_idle(pnd);
+
uart_close(DRIVER_DATA(pnd)->port);
#ifndef WIN32
@@ -726,5 +728,7 @@ const struct nfc_driver acr122s_driver = {
.device_get_information_about = pn53x_get_information_about,
.abort_command = acr122s_abort_command,
- .idle = NULL,
+ .idle = pn53x_idle,
+ /* Even if PN532, PowerDown is not recommended on those devices */
+ .powerdown = NULL,
};
diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c
index 94fcda0..e713d4e 100644
--- a/libnfc/drivers/arygon.c
+++ b/libnfc/drivers/arygon.c
@@ -211,6 +211,8 @@ arygon_connstring_decode(const nfc_connstring connstring, struct arygon_descript
static void
arygon_close(nfc_device *pnd)
{
+ pn53x_idle(pnd);
+
// Release UART port
uart_close(DRIVER_DATA(pnd)->port);
@@ -587,6 +589,8 @@ const struct nfc_driver arygon_driver = {
.device_get_information_about = pn53x_get_information_about,
.abort_command = arygon_abort_command,
- .idle = NULL, // FIXME arygon driver does not support idle()
+ .idle = pn53x_idle,
+ /* Even if PN532, PowerDown is not recommended on those devices */
+ .powerdown = NULL,
};
diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c
index 3c9f2d6..c3bcd9d 100644
--- a/libnfc/drivers/pn532_uart.c
+++ b/libnfc/drivers/pn532_uart.c
@@ -188,6 +188,8 @@ pn532_connstring_decode(const nfc_connstring connstring, struct pn532_uart_descr
static void
pn532_uart_close(nfc_device *pnd)
{
+ pn53x_idle(pnd);
+
// Release UART port
uart_close(DRIVER_DATA(pnd)->port);
@@ -528,6 +530,7 @@ const struct nfc_driver pn532_uart_driver = {
.device_get_information_about = pn53x_get_information_about,
.abort_command = pn532_uart_abort_command,
- .idle = pn53x_idle,
+ .idle = pn53x_idle,
+ .powerdown = pn53x_PowerDown,
};
diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c
index 11f3164..6340cb7 100644
--- a/libnfc/drivers/pn53x_usb.c
+++ b/libnfc/drivers/pn53x_usb.c
@@ -447,14 +447,14 @@ pn53x_usb_close(nfc_device *pnd)
{
pn53x_usb_ack(pnd);
- pn53x_idle(pnd);
-
if (DRIVER_DATA(pnd)->model == ASK_LOGO) {
/* Set P30, P31, P32, P33, P35 to logic 1 and P34 to 0 logic */
/* ie. Switch all LEDs off and turn off progressive field */
pn53x_write_register(pnd, PN53X_SFR_P3, 0xFF, _BV(P30) | _BV(P31) | _BV(P32) | _BV(P33) | _BV(P35));
}
+ pn53x_idle(pnd);
+
int res;
if ((res = usb_release_interface(DRIVER_DATA(pnd)->pudh, 0)) < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to release USB interface (%s)", _usb_strerror(res));
@@ -652,7 +652,7 @@ read:
int
pn53x_usb_ack(nfc_device *pnd)
{
- return pn53x_usb_bulk_write(DRIVER_DATA(pnd), (uint8_t *) pn53x_ack_frame, sizeof(pn53x_ack_frame), -1);
+ return pn53x_usb_bulk_write(DRIVER_DATA(pnd), (uint8_t *) pn53x_ack_frame, sizeof(pn53x_ack_frame), 1000);
}
int
@@ -791,5 +791,6 @@ const struct nfc_driver pn53x_usb_driver = {
.device_get_information_about = pn53x_get_information_about,
.abort_command = pn53x_usb_abort_command,
- .idle = pn53x_idle,
+ .idle = pn53x_idle,
+ .powerdown = pn53x_PowerDown,
};
diff --git a/libnfc/log-printf.c b/libnfc/log-printf.c
index 75c5e27..c2feaf9 100644
--- a/libnfc/log-printf.c
+++ b/libnfc/log-printf.c
@@ -26,9 +26,9 @@
#include
#ifndef LOG
- // Leaving in a preprocessor error, as the build system should skip this
- // file otherwise.
- #error "No logging defined, but log-printf.c still compiled."
+// Leaving in a preprocessor error, as the build system should skip this
+// file otherwise.
+#error "No logging defined, but log-printf.c still compiled."
#else // LOG
void
diff --git a/libnfc/nfc-emulation.c b/libnfc/nfc-emulation.c
index 1085e32..e98d625 100644
--- a/libnfc/nfc-emulation.c
+++ b/libnfc/nfc-emulation.c
@@ -19,23 +19,33 @@
*/
/**
-* @file nfc-emulation.c
-* @brief Provide a small API to ease emulation in libnfc
-*/
+ * @file nfc-emulation.c
+ * @brief Provide a small API to ease emulation in libnfc
+ */
#include
#include
#include "iso7816.h"
+/** @ingroup emulation
+ * @brief Emulate a target
+ * @return Returns 0 on success, otherwise returns libnfc's error code (negative value).
+ *
+ * @param pnd \a nfc_device struct pointer that represents currently used device
+ * @param emulator \nfc_emulator struct point that handles input/output functions
+ *
+ * If timeout equals to 0, the function blocks indefinitely (until an error is raised or function is completed)
+ * If timeout equals to -1, the default timeout will be used
+ */
int
-nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator)
+nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator, const int timeout)
{
uint8_t abtRx[ISO7816_SHORT_R_APDU_MAX_LEN];
uint8_t abtTx[ISO7816_SHORT_C_APDU_MAX_LEN];
int res;
- if ((res = nfc_target_init(pnd, emulator->target, abtRx, sizeof(abtRx), 0)) < 0) {
+ if ((res = nfc_target_init(pnd, emulator->target, abtRx, sizeof(abtRx), timeout)) < 0) {
return res;
}
@@ -44,12 +54,12 @@ nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator)
while (io_res >= 0) {
io_res = emulator->state_machine->io(emulator, abtRx, szRx, abtTx, sizeof(abtTx));
if (io_res > 0) {
- if ((res = nfc_target_send_bytes(pnd, abtTx, io_res, 0)) < 0) {
+ if ((res = nfc_target_send_bytes(pnd, abtTx, io_res, timeout)) < 0) {
return res;
}
}
if (io_res >= 0) {
- if ((res = nfc_target_receive_bytes(pnd, abtRx, sizeof(abtRx), 0)) < 0) {
+ if ((res = nfc_target_receive_bytes(pnd, abtRx, sizeof(abtRx), timeout)) < 0) {
return res;
}
szRx = res;
@@ -57,3 +67,4 @@ nfc_emulate_target(nfc_device *pnd, struct nfc_emulator *emulator)
}
return (io_res < 0) ? io_res : 0;
}
+
diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h
index 5d1ff03..30e4947 100644
--- a/libnfc/nfc-internal.h
+++ b/libnfc/nfc-internal.h
@@ -147,6 +147,7 @@ struct nfc_driver {
int (*abort_command)(struct nfc_device *pnd);
int (*idle)(struct nfc_device *pnd);
+ int (*powerdown)(struct nfc_device *pnd);
};
# define DEVICE_NAME_LENGTH 256
diff --git a/libnfc/nfc.c b/libnfc/nfc.c
index 82e1ea7..b1dc537 100644
--- a/libnfc/nfc.c
+++ b/libnfc/nfc.c
@@ -114,10 +114,6 @@ const struct nfc_driver *nfc_drivers[] = {
void
nfc_init(nfc_context **context)
{
- if (!context) {
- printf("Error: NULL context is not supported anymore, please fix your code.\n");
- exit(EXIT_FAILURE);
- }
*context = nfc_context_new();
}
@@ -213,11 +209,8 @@ void
nfc_close(nfc_device *pnd)
{
if (pnd) {
- // Go in idle mode
- nfc_idle(pnd);
// Close, clean up and release the device
pnd->driver->close(pnd);
-
}
}
@@ -236,11 +229,6 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
const struct nfc_driver *ndr;
const struct nfc_driver **pndr = nfc_drivers;
- if (!context) {
- printf("NULL context is not supported anymore! Please fix your code.\n");
- exit(EXIT_FAILURE);
- }
-
// Load manually configured devices (from config file and env variables)
// TODO From env var...
for (uint32_t i = 0; i < context->user_defined_device_count; i++) {
@@ -251,8 +239,10 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_
char *old_env_log_level = NULL;
// do it silently
if (env_log_level) {
- if ((old_env_log_level = malloc(strlen(env_log_level) + 1)) == NULL)
- exit(EXIT_FAILURE);
+ if ((old_env_log_level = malloc(strlen(env_log_level) + 1)) == NULL) {
+ log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to malloc()");
+ return 0;
+ }
strcpy(old_env_log_level, env_log_level);
}
setenv("LIBNFC_LOG_LEVEL", "0", 1);
diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt
index 57f4f03..2b828cb 100644
--- a/utils/CMakeLists.txt
+++ b/utils/CMakeLists.txt
@@ -21,10 +21,12 @@ FOREACH(source ${UTILS-SOURCES})
LIST(APPEND TARGETS mifare)
ENDIF((${source} MATCHES "nfc-mfultralight") OR (${source} MATCHES "nfc-mfclassic"))
- IF(${source} MATCHES "nfc-scan-device")
- LIST(APPEND TARGETS ../contrib/win32/nfc_win32)
- INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32)
- ENDIF(${source} MATCHES "nfc-scan-device")
+ IF(WIN32)
+ IF(${source} MATCHES "nfc-scan-device")
+ LIST(APPEND TARGETS ../contrib/win32/stdlib)
+ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../contrib/win32)
+ ENDIF(${source} MATCHES "nfc-scan-device")
+ ENDIF(WIN32)
ADD_EXECUTABLE(${source} ${TARGETS})
diff --git a/utils/mifare.c b/utils/mifare.c
index 6c84724..d1d7809 100644
--- a/utils/mifare.c
+++ b/utils/mifare.c
@@ -47,7 +47,7 @@
* @note There are three different types of information (Authenticate, Data and Value).
*
* First an authentication must take place using Key A or B. It requires a 48 bit Key (6 bytes) and the UID.
- * They are both used to initialize the internal cipher-state of the PN53X chip (http://libnfc.org/hardware/pn53x-chip).
+ * They are both used to initialize the internal cipher-state of the PN53X chip.
* After a successful authentication it will be possible to execute other commands (e.g. Read/Write).
* The MIFARE Classic Specification (http://www.nxp.com/acrobat/other/identification/M001053_MF1ICS50_rev5_3.pdf) explains more about this process.
*/
diff --git a/utils/nfc-emulate-forum-tag4.c b/utils/nfc-emulate-forum-tag4.c
index 8404cfb..e17f090 100644
--- a/utils/nfc-emulate-forum-tag4.c
+++ b/utils/nfc-emulate-forum-tag4.c
@@ -382,7 +382,7 @@ main(int argc, char *argv[])
printf("NFC device: %s opened\n", nfc_device_get_name(pnd));
printf("Emulating NDEF tag now, please touch it with a second NFC device\n");
- if (0 != nfc_emulate_target(pnd, &emulator)) { // contains already nfc_target_init() call
+ if (0 != nfc_emulate_target(pnd, &emulator, 0)) { // contains already nfc_target_init() call
nfc_perror(pnd, "nfc_emulate_target");
}
diff --git a/utils/nfc-scan-device.c b/utils/nfc-scan-device.c
index 39d5c2b..0ff6393 100644
--- a/utils/nfc-scan-device.c
+++ b/utils/nfc-scan-device.c
@@ -77,11 +77,6 @@ main(int argc, const char *argv[])
bool verbose = false;
nfc_context *context;
- nfc_init(&context);
-
- // Display libnfc version
- acLibnfcVersion = nfc_version();
- printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
// Get commandline options
for (int arg = 1; arg < argc; arg++) {
@@ -91,6 +86,7 @@ main(int argc, const char *argv[])
} else if (0 == strcmp(argv[arg], "-v")) {
verbose = true;
} else if (0 == strcmp(argv[arg], "-i")) {
+ // This has to be done before the call to nfc_init()
setenv("LIBNFC_INTRUSIVE_SCAN", "yes", 1);
} else {
ERR("%s is not supported option.", argv[arg]);
@@ -99,6 +95,12 @@ main(int argc, const char *argv[])
}
}
+ nfc_init(&context);
+
+ // Display libnfc version
+ acLibnfcVersion = nfc_version();
+ printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
+
#ifdef HAVE_LIBUSB
# ifdef DEBUG
usb_set_debug(4);
diff --git a/windows/mm/libnfc.mm b/windows/mm/libnfc.mm
index 6d388c4..abd84ab 100644
--- a/windows/mm/libnfc.mm
+++ b/windows/mm/libnfc.mm
@@ -21,7 +21,7 @@
; #define? COMPANY_PRODUCT_ICON ..\win32\libnfc.ico ;; override from company.mmh
#define? UISAMPLE_DIALOG_FILE_dlgbmp nfcleft.bmp ;; override uisample.mmh
-#define? UISAMPLE_BLINE_TEXT www.libnfc.org
+#define? UISAMPLE_BLINE_TEXT www.nfc-tools.org
#define? COMPANY_WANT_TO_INSTALL_DOCUMENTATION N
;--- Include MAKEMSI support (with my customisations and MSI branding) ------