From 93494aad24080e7a30eb71175fc475223bc98b6f Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Sat, 31 Jul 2010 10:13:18 +0000 Subject: [PATCH 1/4] Fix serial string for FreeBSD. I am sure we don't have /dev/ttyUSB*, and since I use /dev/cuau0 with a cross-over cable to connect 2 machines and have a serial console, I guess "/dev/cuau" is the SERIAL_STRING that's expected to work for me. A quick test would be cool however, but I don't own a serial NFC device. --- libnfc/drivers/pn532_uart.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 981a7dc..334671e 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -54,8 +54,15 @@ // MacOS // TODO: find UART connection string for PN53X device on Mac OS X #define SERIAL_STRING "" + #elif defined(__FreeBSD__) + // XXX: Not tested + #define SERIAL_STRING "/dev/cuau" #else - // *BSD, Linux and others POSIX systems + // Linux and maybe some operating systems + // FIXME: We'd rather have an #elif defined(__linux__) or something like + // that and an #else that triggers an error at compile time instead + // of "falling-back" on a value that is likely to not be suitable + // for most operating systems. #define SERIAL_STRING "/dev/ttyUSB" #endif #endif From bb06d45a0580913a927c723c9483fa01a012363e Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Sat, 31 Jul 2010 12:57:02 +0000 Subject: [PATCH 2/4] Really silent down gcc with -Wextra. --- examples/nfc-sam.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/nfc-sam.c b/examples/nfc-sam.c index d2581ec..253f280 100644 --- a/examples/nfc-sam.c +++ b/examples/nfc-sam.c @@ -110,7 +110,8 @@ int main(int argc, const char* argv[]) { nfc_device_t* pnd; - (void)(argc, argv); + (void)argc; + (void)argv; // Display libnfc version const char* acLibnfcVersion = nfc_version(); From cd53efb0380c4726882a7c8928d4ece277aba34a Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Sat, 31 Jul 2010 13:21:56 +0000 Subject: [PATCH 3/4] Enforce ISO C conformance about empty files. ISO C forbids empty source files. Instead of compiling possibly empty source files depending on the compiler parameters, only compile required files to build the library as requested at the ./configure stage. Windows users (and more precisely non-autotools users), you may have to update whatever you use to build the libnfc to fit your needs. The Makefile shipped in the windows directory compiles all drivers as it is written so you should not notice any difference, but if you don't use _that_ makefile, then you will have to do some adjustment. For now, keep the defines in CFLAGS just in case. Planned for removal in circa one week. While here, pet `./configure` output (--help format and summary). --- configure.ac | 2 ++ libnfc/drivers/Makefile.am | 25 ++++++++++++++++++++++++- libnfc/drivers/acr122.c | 4 ---- libnfc/drivers/arygon.c | 4 ---- libnfc/drivers/pn531_usb.c | 4 ---- libnfc/drivers/pn532_uart.c | 4 ---- libnfc/drivers/pn533_usb.c | 4 ---- libnfc/drivers/pn53x_usb.c | 8 ++++++++ m4/libnfc_drivers.m4 | 28 +++++++++++++++++++++++++++- 9 files changed, 61 insertions(+), 22 deletions(-) diff --git a/configure.ac b/configure.ac index b0473a8..37874bd 100644 --- a/configure.ac +++ b/configure.ac @@ -132,3 +132,5 @@ AC_CONFIG_FILES([ ]) AC_OUTPUT + +LIBNFC_DRIVERS_SUMMARY diff --git a/libnfc/drivers/Makefile.am b/libnfc/drivers/Makefile.am index 79bd5bc..3aff81f 100644 --- a/libnfc/drivers/Makefile.am +++ b/libnfc/drivers/Makefile.am @@ -3,16 +3,39 @@ INCLUDES= $(all_includes) $(LIBNFC_CFLAGS) noinst_HEADERS = acr122.h arygon.h pn531_usb.h pn532_uart.h pn533_usb.h pn53x_usb.h noinst_LTLIBRARIES = libnfcdrivers.la -libnfcdrivers_la_SOURCES = acr122.c arygon.c pn531_usb.c pn532_uart.c pn533_usb.c pn53x_usb.c + +libnfcdrivers_la_SOURCES = libnfcdrivers_la_CFLAGS = @DRIVERS_CFLAGS@ -I$(top_srcdir)/libnfc -I$(top_srcdir)/libnfc/buses libnfcdrivers_la_LIBADD = +if DRIVER_ACR122_ENABLED +libnfcdrivers_la_SOURCES += acr122.c +endif + +if DRIVER_ARYGON_ENABLED +libnfcdrivers_la_SOURCES += arygon.c +endif + +if DRIVER_PN531_USB_ENABLED +libnfcdrivers_la_SOURCES += pn531_usb.c +endif + +if DRIVER_PN533_USB_ENABLED +libnfcdrivers_la_SOURCES += pn533_usb.c +endif + + +if DRIVER_PN532_UART_ENABLED +libnfcdrivers_la_SOURCES += pn532_uart.c +endif + if PCSC_ENABLED libnfcdrivers_la_CFLAGS += @libpcsclite_CFLAGS@ libnfcdrivers_la_LIBADD += @libpcsclite_LIBS@ endif if LIBUSB_ENABLED + libnfcdrivers_la_SOURCES += pn53x_usb.c libnfcdrivers_la_CFLAGS += @libusb_CFLAGS@ libnfcdrivers_la_LIBADD += @libusb_LIBS@ endif diff --git a/libnfc/drivers/acr122.c b/libnfc/drivers/acr122.c index 47357e8..4b94db8 100644 --- a/libnfc/drivers/acr122.c +++ b/libnfc/drivers/acr122.c @@ -22,8 +22,6 @@ * @brief Driver for ACR122 devices (e.g. Tikitag, Touchatag, ACS ACR122) */ -#ifdef DRIVER_ACR122_ENABLED - #ifdef HAVE_CONFIG_H #include "config.h" #endif // HAVE_CONFIG_H @@ -360,5 +358,3 @@ bool acr122_led_red(const nfc_device_spec_t nds, bool bOn) } } -#endif // DRIVER_ACR122_ENABLED - diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index 2d5fbd6..8c43f21 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -25,8 +25,6 @@ * UART connection can be direct (host<->arygon_uc) or could be provided by internal USB to serial interface (e.g. host<->ftdi_chip<->arygon_uc) */ -#ifdef DRIVER_ARYGON_ENABLED - #ifdef HAVE_CONFIG_H #include "config.h" #endif // HAVE_CONFIG_H @@ -331,5 +329,3 @@ arygon_check_communication(const nfc_device_spec_t nds) return true; } -#endif // DRIVER_ARYGON_ENABLED - diff --git a/libnfc/drivers/pn531_usb.c b/libnfc/drivers/pn531_usb.c index 274af28..2386245 100644 --- a/libnfc/drivers/pn531_usb.c +++ b/libnfc/drivers/pn531_usb.c @@ -26,8 +26,6 @@ Thanks to d18c7db and Okko for example code */ -#ifdef DRIVER_PN531_USB_ENABLED - #ifdef HAVE_CONFIG_H #include "config.h" #endif // HAVE_CONFIG_H @@ -73,5 +71,3 @@ nfc_device_t* pn531_usb_connect(const nfc_device_desc_t* pndd) return pn53x_usb_connect(pndd, pndd->acDevice, NC_PN531); } -#endif // DRIVER_PN531_USB_ENABLED - diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index 334671e..26c89a0 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -22,8 +22,6 @@ * @brief PN532 driver using UART bus (UART, RS232, etc.) */ -#ifdef DRIVER_PN532_UART_ENABLED - #ifdef HAVE_CONFIG_H #include "config.h" #endif // HAVE_CONFIG_H @@ -339,5 +337,3 @@ pn532_uart_check_communication(const nfc_device_spec_t nds) return true; } -#endif // DRIVER_PN532_UART_ENABLED - diff --git a/libnfc/drivers/pn533_usb.c b/libnfc/drivers/pn533_usb.c index f18d0cf..19d6b71 100644 --- a/libnfc/drivers/pn533_usb.c +++ b/libnfc/drivers/pn533_usb.c @@ -26,8 +26,6 @@ Thanks to d18c7db and Okko for example code */ -#ifdef DRIVER_PN533_USB_ENABLED - #ifdef HAVE_CONFIG_H #include "config.h" #endif // HAVE_CONFIG_H @@ -71,5 +69,3 @@ nfc_device_t* pn533_usb_connect(const nfc_device_desc_t* pndd) return pn53x_usb_connect(pndd, pndd->acDevice, NC_PN533); } -#endif // DRIVER_PN533_USB_ENABLED - diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 1fd9d39..b0f3d96 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -281,6 +281,12 @@ bool pn53x_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, cons #ifdef DEBUG PRINT_HEX("RX", abtRx,ret); #endif + + uint8_t ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 }; + if ((ret != 6) || (memcmp (abtRx, ack_frame, 6))) { + DBG ("%s", "===> No ACK!!!!!!"); + return false; + } if( ret == 6 ) { @@ -296,6 +302,8 @@ bool pn53x_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, cons #endif } + usb_bulk_write(pus->pudh, pus->uiEndPointOut, (char *)ack_frame, 6, USB_TIMEOUT); + // When the answer should be ignored, just return a succesful result if(pbtRx == NULL || pszRxLen == NULL) return true; diff --git a/m4/libnfc_drivers.m4 b/m4/libnfc_drivers.m4 index 81db849..d51883f 100644 --- a/m4/libnfc_drivers.m4 +++ b/m4/libnfc_drivers.m4 @@ -4,7 +4,7 @@ AC_DEFUN([LIBNFC_ARG_WITH_DRIVERS], [ AC_MSG_CHECKING(which drivers to build) AC_ARG_WITH(drivers, - AC_HELP_STRING([[[[--with-drivers=driver@<:@,driver...@:>@]]]], [Only use specific drivers (default set)]), + AC_HELP_STRING([[[--with-drivers=driver@<:@,driver...@:>@]]], [Only use specific drivers (default set)]), [ case "${withval}" in yes | no) dnl ignore calls without any arguments @@ -34,25 +34,36 @@ AC_DEFUN([LIBNFC_ARG_WITH_DRIVERS], DRIVERS_CFLAGS="" + driver_acr122_enabled="no" + driver_pn531_usb_enabled="no" + driver_pn533_usb_enabled="no" + driver_arygon_enabled="no" + driver_pn532_uart_enabled="no" + for driver in ${DRIVER_BUILD_LIST} do case "${driver}" in acr122) pcsc_required="yes" + driver_acr122_enabled="yes" DRIVERS_CFLAGS="$DRIVERS_CFLAGS -DDRIVER_ACR122_ENABLED" ;; pn531_usb) libusb_required="yes" + driver_pn531_usb_enabled="yes" DRIVERS_CFLAGS="$DRIVERS_CFLAGS -DDRIVER_PN531_USB_ENABLED" ;; pn533_usb) libusb_required="yes" + driver_pn533_usb_enabled="yes" DRIVERS_CFLAGS="$DRIVERS_CFLAGS -DDRIVER_PN533_USB_ENABLED" ;; arygon) + driver_arygon_enabled="yes" DRIVERS_CFLAGS="$DRIVERS_CFLAGS -DDRIVER_ARYGON_ENABLED" ;; pn532_uart) + driver_pn532_uart_enabled="yes" DRIVERS_CFLAGS="$DRIVERS_CFLAGS -DDRIVER_PN532_UART_ENABLED" ;; *) @@ -61,4 +72,19 @@ AC_DEFUN([LIBNFC_ARG_WITH_DRIVERS], esac done AC_SUBST(DRIVERS_CFLAGS) + AM_CONDITIONAL(DRIVER_ACR122_ENABLED, [test x"$driver_acr122_enabled" = xyes]) + AM_CONDITIONAL(DRIVER_PN531_USB_ENABLED, [test x"$driver_pn531_usb_enabled" = xyes]) + AM_CONDITIONAL(DRIVER_PN533_USB_ENABLED, [test x"$driver_pn533_usb_enabled" = xyes]) + AM_CONDITIONAL(DRIVER_ARYGON_ENABLED, [test x"$driver_arygon_enabled" = xyes]) + AM_CONDITIONAL(DRIVER_PN532_UART_ENABLED, [test x"$driver_pn532_uart_enabled" = xyes]) +]) + +AC_DEFUN([LIBNFC_DRIVERS_SUMMARY],[ +echo +echo "Selected drivers:" +echo " acr122........... $driver_acr122_enabled" +echo " arygon........... $driver_arygon_enabled" +echo " pn531_usb........ $driver_pn531_usb_enabled" +echo " pn532_uart....... $driver_pn532_uart_enabled" +echo " pn533_usb........ $driver_pn533_usb_enabled" ]) From b60d04553739b95e045b44892d38594ec74fe866 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Sat, 31 Jul 2010 13:46:32 +0000 Subject: [PATCH 4/4] Remove another deprecated test that '^#ifdef' did not matched for previous commit. --- libnfc/drivers/pn53x_usb.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index b0f3d96..7603c96 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -30,8 +30,6 @@ Thanks to d18c7db and Okko for example code */ -#if defined (DRIVER_PN531_USB_ENABLED) || defined (DRIVER_PN533_USB_ENABLED) - #include #include #include @@ -329,5 +327,3 @@ bool pn53x_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, cons return true; } - -#endif // DRIVER_PN531_USB_ENABLED || DRIVER_PN533_USB_ENABLED