MERGE: libnfc-mingw-cross merge with trunk (r805-821)

This commit is contained in:
Romuald Conty 2010-11-17 08:29:41 +00:00
parent 6df612a364
commit 58dcf63e7c
19 changed files with 246 additions and 110 deletions

View file

@ -1,8 +1,8 @@
PROJECT(libnfc C) PROJECT(libnfc C)
CMAKE_MINIMUM_REQUIRED(VERSION 2.6) CMAKE_MINIMUM_REQUIRED(VERSION 2.6)
SET(VERSION_MAJOR "1") SET(VERSION_MAJOR "1")
SET(VERSION_MINOR "3") SET(VERSION_MINOR "4")
SET(VERSION_PATCH "4") SET(VERSION_PATCH "0")
SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}") SET(VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
@ -11,9 +11,9 @@ SET(PACKAGE_VERSION ${VERSION})
SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}") SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")
# config.h # config.h
IF(NOT MSVC) IF(NOT WIN32)
SET(_XOPEN_SOURCE 600) SET(_XOPEN_SOURCE 600)
ENDIF(NOT MSVC) ENDIF(NOT WIN32)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
ADD_DEFINITIONS("-DHAVE_CONFIG_H") ADD_DEFINITIONS("-DHAVE_CONFIG_H")
@ -21,9 +21,9 @@ ADD_DEFINITIONS("-DHAVE_CONFIG_H")
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include)
# Win32 # Win32
IF(MSVC) IF(WIN32)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32 ${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32/stdint) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32 ${CMAKE_CURRENT_SOURCE_DIR}/contrib/win32/stdint)
ENDIF(MSVC) ENDIF(WIN32)
# make it easy to locate CMake modules for finding libraries # make it easy to locate CMake modules for finding libraries
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/") SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/")
@ -66,7 +66,7 @@ ENDIF(CMAKE_COMPILER_IS_GNU_CC)
# Workarounds for libusb in C99 # Workarounds for libusb in C99
ADD_DEFINITIONS(-Du_int8_t=uint8_t -Du_int16_t=uint16_t) ADD_DEFINITIONS(-Du_int8_t=uint8_t -Du_int16_t=uint16_t)
IF(NOT MSVC) IF(NOT WIN32)
# Set some pkg-config variables # Set some pkg-config variables
SET(prefix ${CMAKE_INSTALL_PREFIX}) SET(prefix ${CMAKE_INSTALL_PREFIX})
SET(exec_prefix ${CMAKE_INSTALL_PREFIX}) SET(exec_prefix ${CMAKE_INSTALL_PREFIX})
@ -81,18 +81,19 @@ IF(NOT MSVC)
STRING(REPLACE ";" "," PKG_CONFIG_REQUIRES "${PKG_REQ}") STRING(REPLACE ";" "," PKG_CONFIG_REQUIRES "${PKG_REQ}")
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libnfc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc @ONLY) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/libnfc.pc.in ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc @ONLY)
INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
ENDIF(NOT MSVC) ENDIF(NOT WIN32)
ADD_SUBDIRECTORY(libnfc) ADD_SUBDIRECTORY(libnfc)
ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(include)
ADD_SUBDIRECTORY(examples) ADD_SUBDIRECTORY(examples)
# Binary Package # Binary Package
IF(MSVC) IF(WIN32)
SET(CPACK_GENERATOR "NSIS") SET(CPACK_GENERATOR "NSIS")
ELSE(MSVC) ELSE(WIN32)
SET(CPACK_GENERATOR "TBZ2") SET(CPACK_GENERATOR "TBZ2")
ENDIF(MSVC) ENDIF(WIN32)
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Near Field Communication (NFC) library") SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Near Field Communication (NFC) library")
SET(CPACK_PACKAGE_VENDOR "Roel Verdult") SET(CPACK_PACKAGE_VENDOR "Roel Verdult")
SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README") SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
@ -104,21 +105,22 @@ SET(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH})
SET(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "NFC Library") SET(CPACK_COMPONENT_LIBRARIES_DISPLAY_NAME "NFC Library")
SET(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example Applications") SET(CPACK_COMPONENT_EXAMPLES_DISPLAY_NAME "Example Applications")
SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "Development Headers") SET(CPACK_COMPONENT_HEADERS_DISPLAY_NAME "Development Headers")
IF(NOT MSVC) IF(NOT WIN32)
SET(CPACK_COMPONENT_MANUALS_DISPLAY_NAME "Example Applications Manuals") SET(CPACK_COMPONENT_MANUALS_DISPLAY_NAME "Example Applications Manuals")
SET(CPACK_COMPONENT_MANUALS_DISABLED TRUE) SET(CPACK_COMPONENT_MANUALS_DISABLED TRUE)
SET(CPACK_COMPONENT_MANUALS_DEPENDS examples) SET(CPACK_COMPONENT_MANUALS_DEPENDS examples)
ENDIF(NOT MSVC) ENDIF(NOT WIN32)
SET(CPACK_COMPONENT_HEADERS_DISABLED TRUE) SET(CPACK_COMPONENT_HEADERS_DISABLED TRUE)
SET(CPACK_COMPONENT_HEADERS_DEPENDS libraries) SET(CPACK_COMPONENT_HEADERS_DEPENDS libraries)
SET(CPACK_COMPONENT_EXAMPLES_DEPENDS libraries) SET(CPACK_COMPONENT_EXAMPLES_DEPENDS libraries)
# Source Package # Source Package
IF(MSVC) IF(WIN32)
SET(CPACK_SOURCE_GENERATOR "ZIP") SET(CPACK_SOURCE_GENERATOR "ZIP")
ELSE(MSVC) ELSE(WIN32)
SET(CPACK_SOURCE_GENERATOR "ZIP;TBZ2") SET(CPACK_SOURCE_GENERATOR "ZIP;TBZ2")
ENDIF(MSVC) ENDIF(WIN32)
SET(CPACK_SOURCE_PACKAGE_FILE_NAME "libnfc-${VERSION}") SET(CPACK_SOURCE_PACKAGE_FILE_NAME "libnfc-${VERSION}")
SET(CPACK_SOURCE_IGNORE_FILES "~$" "/\\\\.svn/" "bin/") SET(CPACK_SOURCE_IGNORE_FILES "~$" "/\\\\.svn/" "bin/")
INCLUDE(CPack) INCLUDE(CPack)

View file

@ -25,25 +25,30 @@ IF(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
ENDIF(CMAKE_SYSTEM_NAME MATCHES FreeBSD) ENDIF(CMAKE_SYSTEM_NAME MATCHES FreeBSD)
IF(NOT LIBUSB_FOUND) IF(NOT LIBUSB_FOUND)
IF(MSVC) IF(WIN32)
# Windows with Microsoft Visual C++ # Windows with Microsoft Visual C++
FIND_PATH(LIBUSB_INCLUDE_DIRS usb.h "$ENV{ProgramFiles}/LibUSB-Win32/include") FIND_PATH(LIBUSB_INCLUDE_DIRS usb.h "$ENV{ProgramFiles}/LibUSB-Win32/include")
IF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x64") IF(MSVC)
# on x64 (win64) IF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x64")
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "$ENV{ProgramFiles}/LibUSB-Win32/lib/msvc_x64") # on x64 (win64)
ELSE(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x64") FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "$ENV{ProgramFiles}/LibUSB-Win32/lib/msvc_x64")
# on x86 (win32) ELSE(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x64")
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "$ENV{ProgramFiles}/LibUSB-Win32/lib/msvc") # on x86 (win32)
ENDIF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x64") FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "$ENV{ProgramFiles}/LibUSB-Win32/lib/msvc")
ELSE(MSVC) ENDIF(${CMAKE_SYSTEM_PROCESSOR} STREQUAL "x64")
# If not MS Visual Studio we use PkgConfig ENDIF(MSVC)
IF(MINGW)
FIND_LIBRARY(LIBUSB_LIBRARIES NAMES libusb PATHS "$ENV{ProgramFiles}/LibUSB-Win32/lib/gcc")
ENDIF(MINGW)
ELSE(WIN32)
# If not under Windows we use PkgConfig
FIND_PACKAGE (PkgConfig) FIND_PACKAGE (PkgConfig)
IF(PKG_CONFIG_FOUND) IF(PKG_CONFIG_FOUND)
PKG_CHECK_MODULES(LIBUSB REQUIRED libusb) PKG_CHECK_MODULES(LIBUSB REQUIRED libusb)
ELSE(PKG_CONFIG_FOUND) ELSE(PKG_CONFIG_FOUND)
MESSAGE(FATAL_ERROR "Could not find PkgConfig") MESSAGE(FATAL_ERROR "Could not find PkgConfig")
ENDIF(PKG_CONFIG_FOUND) ENDIF(PKG_CONFIG_FOUND)
ENDIF(MSVC) ENDIF(WIN32)
IF(LIBUSB_INCLUDE_DIRS AND LIBUSB_LIBRARIES) IF(LIBUSB_INCLUDE_DIRS AND LIBUSB_LIBRARIES)
SET(LIBUSB_FOUND TRUE) SET(LIBUSB_FOUND TRUE)

View file

@ -1,41 +1,37 @@
# This CMake script wants to use PC/SC functionality, therefore it looks # - Try to find the PC/SC smart card library
# for PC/SC include files and libraries. # Once done this will define
# #
# Operating Systems Supported: # PCSC_FOUND - system has the PC/SC library
# - Unix (requires pkg-config) # PCSC_INCLUDE_DIRS - the PC/SC include directory
# Tested with Ubuntu 9.04 and Fedora 11 # PCSC_LIBRARIES - The libraries needed to use PC/SC
# - Windows (requires MSVC)
# Tested with Windows XP
#
# This should work for both 32 bit and 64 bit systems.
# #
# Author: F. Kooman <fkooman@tuxed.net> # Author: F. Kooman <fkooman@tuxed.net>
# Version: 20101019
# #
IF(MSVC) FIND_PACKAGE (PkgConfig)
# Windows with Microsoft Visual C++ IF(PKG_CONFIG_FOUND)
FIND_PATH(PCSC_INCLUDE_DIRS WinSCard.h "$ENV{INCLUDE}") # Will find PC/SC library on Linux/BSDs using PkgConfig
FIND_LIBRARY(PCSC_LIBRARIES NAMES WinSCard PATHS "$ENV{LIB}") PKG_CHECK_MODULES(PCSC libpcsclite)
ELSE(MSVC) # PKG_CHECK_MODULES(PCSC QUIET libpcsclite) # IF CMake >= 2.8.2?
# If not MS Visual Studio we use PkgConfig ENDIF(PKG_CONFIG_FOUND)
FIND_PACKAGE (PkgConfig)
IF(PKG_CONFIG_FOUND)
PKG_CHECK_MODULES(PCSC REQUIRED libpcsclite)
ELSE(PKG_CONFIG_FOUND)
MESSAGE(FATAL_ERROR "Could not find PkgConfig")
ENDIF(PKG_CONFIG_FOUND)
ENDIF(MSVC)
IF(PCSC_INCLUDE_DIRS AND PCSC_LIBRARIES) IF(NOT PCSC_FOUND)
SET(PCSC_FOUND TRUE) # Will find PC/SC headers both on Mac and Windows
ENDIF(PCSC_INCLUDE_DIRS AND PCSC_LIBRARIES) FIND_PATH(PCSC_INCLUDE_DIRS WinSCard.h)
# PCSC library is for Mac, WinSCard library is for Windows
FIND_LIBRARY(PCSC_LIBRARIES NAMES PCSC WinSCard)
IF(MINGW)
# MinGW32 with PCSC framework use Microsoft SDK's WinSCard.h
SET(PCSC_INCLUDE_DIRS)
SET(PCSC_INCLUDE_DIRS "$ENV{ProgramFiles}/Microsoft SDKs/Windows/v7.0/Include")
ENDIF(MINGW)
ENDIF(NOT PCSC_FOUND)
IF(PCSC_FOUND) INCLUDE(FindPackageHandleStandardArgs)
IF(NOT PCSC_FIND_QUIETLY) FIND_PACKAGE_HANDLE_STANDARD_ARGS(PCSC DEFAULT_MSG
MESSAGE(STATUS "Found PCSC: ${PCSC_LIBRARIES}") PCSC_LIBRARIES
ENDIF(NOT PCSC_FIND_QUIETLY) PCSC_INCLUDE_DIRS
ELSE(PCSC_FOUND) )
IF(PCSC_FIND_REQUIRED) MARK_AS_ADVANCED(PCSC_INCLUDE_DIRS PCSC_LIBRARIES)
MESSAGE(FATAL_ERROR "Could not find PCSC")
ENDIF(PCSC_FIND_REQUIRED)
ENDIF(PCSC_FOUND)

View file

@ -20,14 +20,22 @@ AC_LANG_C
AC_PROG_CC AC_PROG_CC
AC_PROG_MAKE_SET AC_PROG_MAKE_SET
WITH_POSIX_ONLY_EXAMPLES=1
# Libtool # Libtool
AC_PROG_LIBTOOL AC_PROG_LIBTOOL
case "$host" in case "$host" in
*-pc-linux-gnu) *-pc-linux-gnu)
AC_MSG_RESULT([Fixing libtool for -rpath problems.]) AC_MSG_RESULT([Fixing libtool for -rpath problems.])
sed -i -r 's/(hardcode_into_libs)=.*$/\1=no/' libtool sed -i -r 's/(hardcode_into_libs)=.*$/\1=no/' libtool
;;
*-pc-mingw32msvc)
WITH_POSIX_ONLY_EXAMPLES=0
AC_MSG_RESULT([Disable extended examples due to target Windows system.])
# Undefine __STRICT_ANSI__ to allow to use strdup, putenv, etc. without warnings
CFLAGS="$CFLAGS -U__STRICT_ANSI__"
;; ;;
esac esac
AM_CONDITIONAL(POSIX_ONLY_EXAMPLES_ENABLED, [test "$WITH_POSIX_ONLY_EXAMPLES" = "1"])
AC_PATH_PROG(PKG_CONFIG, pkg-config) AC_PATH_PROG(PKG_CONFIG, pkg-config)
if test x"$PKG_CONFIG" = x""; then if test x"$PKG_CONFIG" = x""; then
@ -44,7 +52,9 @@ AC_CHECK_FUNCS([memmove memset select strdup strerror strstr strtol usleep],
AC_DEFINE(_NETBSD_SOURCE, 1, [Define on NetBSD to activate all library features]) AC_DEFINE(_NETBSD_SOURCE, 1, [Define on NetBSD to activate all library features])
AC_DEFINE(_DARWIN_C_SOURCE, 1, [Define on Darwin to activate all library features]) AC_DEFINE(_DARWIN_C_SOURCE, 1, [Define on Darwin to activate all library features])
AC_FUNC_MALLOC # XXX malloc function should be tested
# but it produces some error while cross-compiling with MinGW
# AC_FUNC_MALLOC
# Checks for types # Checks for types
AC_TYPE_SIZE_T AC_TYPE_SIZE_T

View file

@ -3,9 +3,14 @@
#include <stdlib.h> #include <stdlib.h>
#define warnx(...) fprintf (stderr, __VA_ARGS__) #define warnx(...) do { \
fprintf (stderr, __VA_ARGS__); \
fprintf (stderr, "\n"); \
} while (0)
#define errx(code, ...) do { \ #define errx(code, ...) do { \
fprintf (stderr, __VA_ARGS__); \ fprintf (stderr, __VA_ARGS__); \
fprintf (stderr, "\n"); \
exit (code); \ exit (code); \
} while (0) } while (0)

35
contrib/windows.h Normal file
View file

@ -0,0 +1,35 @@
/*-
* Public platform independent Near Field Communication (NFC) library
*
* Copyright (C) 2010, 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
* 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 <http://www.gnu.org/licenses/>
*/
/**
* @file windows.h
* @brief Provide some windows related hacks due to lack of POSIX compat
*/
#ifndef __WINDOWS_H__
#define __WINDOWS_H__
# include <windows.h>
# if defined (__MINGW32__)
# define snprintf(S, n, F, ...) sprintf(S, F, __VA_ARGS__)
# else
# define snprintf sprintf_s
# endif
#endif

View file

@ -20,8 +20,8 @@ ENDFOREACH(source)
TARGET_LINK_LIBRARIES(nfc-mfclassic mifare) TARGET_LINK_LIBRARIES(nfc-mfclassic mifare)
TARGET_LINK_LIBRARIES(nfc-mfultralight mifare) TARGET_LINK_LIBRARIES(nfc-mfultralight mifare)
IF(NOT MSVC) IF(NOT WIN32)
# Manuals for the examples # Manuals for the examples
FILE(GLOB manuals "${CMAKE_CURRENT_SOURCE_DIR}/*.1") FILE(GLOB manuals "${CMAKE_CURRENT_SOURCE_DIR}/*.1")
INSTALL(FILES ${manuals} DESTINATION ${SHARE_INSTALL_PREFIX}/man/man1 COMPONENT manuals) INSTALL(FILES ${manuals} DESTINATION ${SHARE_INSTALL_PREFIX}/man/man1 COMPONENT manuals)
ENDIF(NOT MSVC) ENDIF(NOT WIN32)

View file

@ -12,8 +12,12 @@ bin_PROGRAMS = \
nfc-relay \ nfc-relay \
nfc-relay-picc \ nfc-relay-picc \
pn53x-diagnose \ pn53x-diagnose \
pn53x-sam \ pn53x-sam
if POSIX_ONLY_EXAMPLES_ENABLED
bin_PROGRAMS += \
pn53x-tamashell pn53x-tamashell
endif
# set the include path found by configure # set the include path found by configure
INCLUDES= $(all_includes) $(LIBNFC_CFLAGS) INCLUDES= $(all_includes) $(LIBNFC_CFLAGS)

View file

@ -51,6 +51,7 @@
# define SUSP_TIME 1 // secs. # define SUSP_TIME 1 // secs.
#else #else
// Needed by Sleep() under Windows // Needed by Sleep() under Windows
# include "../contrib/windows.h"
# include <winbase.h> # include <winbase.h>
# define sleep Sleep # define sleep Sleep
# define SUSP_TIME 1000 // msecs. # define SUSP_TIME 1000 // msecs.

View file

@ -37,6 +37,7 @@
# define SUSP_TIME 1 // secs. # define SUSP_TIME 1 // secs.
#else #else
// Needed by Sleep() under Windows // Needed by Sleep() under Windows
# include "../contrib/windows.h"
# include <winbase.h> # include <winbase.h>
# define sleep Sleep # define sleep Sleep
# define SUSP_TIME 1000 // msecs. # define SUSP_TIME 1000 // msecs.

View file

@ -24,14 +24,14 @@ ADD_LIBRARY(nfc SHARED ${LIBRARY_SOURCES})
TARGET_LINK_LIBRARIES(nfc ${LIBUSB_LIBRARIES} ${PCSC_LIBRARIES}) TARGET_LINK_LIBRARIES(nfc ${LIBUSB_LIBRARIES} ${PCSC_LIBRARIES})
SET_TARGET_PROPERTIES(nfc PROPERTIES SOVERSION 0) SET_TARGET_PROPERTIES(nfc PROPERTIES SOVERSION 0)
IF(MSVC) IF(WIN32)
# On Windows the shared (runtime) library should be either in the same # On Windows the shared (runtime) library should be either in the same
# directory as the excutables or in the path, we add it to same directory # directory as the excutables or in the path, we add it to same directory
INSTALL(TARGETS nfc RUNTIME DESTINATION bin COMPONENT libraries) INSTALL(TARGETS nfc RUNTIME DESTINATION bin COMPONENT libraries)
# At compile time we need the .LIB file, we place it in the lib directory # At compile time we need the .LIB file, we place it in the lib directory
INSTALL(TARGETS nfc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT headers) INSTALL(TARGETS nfc ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT headers)
ELSE(MSVC) ELSE(WIN32)
INSTALL(TARGETS nfc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries) INSTALL(TARGETS nfc LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT libraries)
ENDIF(MSVC) ENDIF(WIN32)

View file

@ -104,11 +104,13 @@ uart_open (const char *pcPortName)
} }
// TODO Remove PN53x related timeout // TODO Remove PN53x related timeout
#define UART_TIMEOUT(X) ((X * 7) + 15000) // 1-byte duration (µs) * 6+1 bytes (ACK + 1 other chance) + 15 ms (PN532 Tmax to reply ACK) #define UART_TIMEOUT(X) ((X * 7) + 15000) // where X is 1-byte duration (µs): X * 6+1 bytes (PN53x's ACK + 1 other chance) + 15 ms (PN532 Tmax to reply ACK)
// UART_SPEED_T0_TIME(X) convert baud rate to interval between 2 bytes (in us)
#define UART_SPEED_T0_TIME(X) ((1000000 * 9)/ X) // 8,n,1 => 9 bits => data rate ~= bauds/9 (bytes/s); ex: 8N1@9600 ~= 1066 bytes/s
void void
uart_set_speed (serial_port sp, const uint32_t uiPortSpeed) uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
{ {
long int iTimeout = UART_TIMEOUT(uiPortSpeed/9); // 8,n,1 => 9bits => ~ bauds/9 long int iTimeout = UART_TIMEOUT(UART_SPEED_T0_TIME(uiPortSpeed));
DBG ("Serial port speed requested to be set to %d bauds (%ld µs).", uiPortSpeed, iTimeout); DBG ("Serial port speed requested to be set to %d bauds (%ld µs).", uiPortSpeed, iTimeout);
const serial_port_unix *spu = (serial_port_unix *) sp; const serial_port_unix *spu = (serial_port_unix *) sp;
@ -351,11 +353,11 @@ uart_open (const char *pcPortName)
return INVALID_SERIAL_PORT; return INVALID_SERIAL_PORT;
} }
sp->ct.ReadIntervalTimeout = 0; sp->ct.ReadIntervalTimeout = 30;
sp->ct.ReadTotalTimeoutMultiplier = 0; sp->ct.ReadTotalTimeoutMultiplier = 0;
sp->ct.ReadTotalTimeoutConstant = 30; sp->ct.ReadTotalTimeoutConstant = 30;
sp->ct.WriteTotalTimeoutMultiplier = 0; sp->ct.WriteTotalTimeoutMultiplier = 30;
sp->ct.WriteTotalTimeoutConstant = 30; sp->ct.WriteTotalTimeoutConstant = 0;
if (!SetCommTimeouts (sp->hPort, &sp->ct)) { if (!SetCommTimeouts (sp->hPort, &sp->ct)) {
uart_close (sp); uart_close (sp);
@ -376,6 +378,7 @@ uart_close (const serial_port sp)
free (sp); free (sp);
} }
// TODO Remove PN53x related timeout
void void
uart_set_speed (serial_port sp, const uint32_t uiPortSpeed) uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
{ {
@ -393,16 +396,32 @@ uart_set_speed (serial_port sp, const uint32_t uiPortSpeed)
case 460800: case 460800:
break; break;
default: default:
ERR ERR("Unable to set serial port speed to %d bauds. Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.", uiPortSpeed);
("Unable to set serial port speed to %d bauds. Speed value must be one of these constants: 9600 (default), 19200, 38400, 57600, 115200, 230400 or 460800.", return;
uiPortSpeed);
}; };
spw = (serial_port_windows *) sp; spw = (serial_port_windows *) sp;
// Set timeouts
//printf ("UART_SPEED_T0_TIME (%d) = %d\n", uiPortSpeed, UART_SPEED_T0_TIME(uiPortSpeed));
int iTimeout = 200;
spw->ct.ReadIntervalTimeout = 2;
spw->ct.ReadTotalTimeoutMultiplier = 0;
spw->ct.ReadTotalTimeoutConstant = iTimeout;
spw->ct.WriteTotalTimeoutMultiplier = iTimeout;
spw->ct.WriteTotalTimeoutConstant = 0;
if (!SetCommTimeouts (spw->hPort, &spw->ct)) {
ERR ("Unable to apply new timeout settings.");
return;
}
// Set baud rate
spw->dcb.BaudRate = uiPortSpeed; spw->dcb.BaudRate = uiPortSpeed;
if (!SetCommState (spw->hPort, &spw->dcb)) { if (!SetCommState (spw->hPort, &spw->dcb)) {
ERR ("Unable to apply new speed settings."); ERR ("Unable to apply new speed settings.");
return;
} }
PurgeComm (spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR);
} }
uint32_t uint32_t
@ -418,7 +437,7 @@ uart_get_speed (const serial_port sp)
int int
uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx) uart_receive (serial_port sp, byte_t * pbtRx, size_t * pszRx)
{ {
if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, *pszRx, (LPDWORD) pszRx, NULL)) { if (!ReadFile (((serial_port_windows *) sp)->hPort, pbtRx, (DWORD)(*pszRx), (LPDWORD) pszRx, NULL)) {
return DEIO; return DEIO;
} }
if (!*pszRx) if (!*pszRx)

View file

@ -39,10 +39,7 @@
#include "../mirror-subr.h" #include "../mirror-subr.h"
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> # include "../../contrib/windows.h"
# define strdup _strdup
# define snprintf sprintf_s
#endif #endif
#define MAX(a,b) (((a) > (b)) ? (a) : (b)) #define MAX(a,b) (((a) > (b)) ? (a) : (b))

View file

@ -297,7 +297,7 @@ arygon_firmware (const nfc_device_spec_t nds, char * str)
{ {
const byte_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' }; const byte_t arygon_firmware_version_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'v' };
byte_t abtRx[BUFFER_LENGTH]; byte_t abtRx[BUFFER_LENGTH];
size_t szRx; size_t szRx = BUFFER_LENGTH;
int res; int res;
#ifdef DEBUG #ifdef DEBUG
@ -307,6 +307,7 @@ arygon_firmware (const nfc_device_spec_t nds, char * str)
res = uart_receive ((serial_port) nds, abtRx, &szRx); res = uart_receive ((serial_port) nds, abtRx, &szRx);
if (res != 0) { if (res != 0) {
DBG ("Unable to retrieve ARYGON firmware version.");
return; return;
} }
#ifdef DEBUG #ifdef DEBUG
@ -315,10 +316,9 @@ arygon_firmware (const nfc_device_spec_t nds, char * str)
if ( 0 == memcmp (abtRx, arygon_error_none, 6)) { if ( 0 == memcmp (abtRx, arygon_error_none, 6)) {
byte_t * p = abtRx + 6; byte_t * p = abtRx + 6;
unsigned int szData; unsigned int szData;
sscanf (p, "%02x%s", &szData, p); sscanf ((const char*)p, "%02x%s", &szData, p);
memcpy (str, p, szData); memcpy (str, p, szData);
p += szData; *(str + szData) = '\0';
*p = '\0';
} }
} }
@ -327,7 +327,7 @@ arygon_reset_tama (const nfc_device_spec_t nds)
{ {
const byte_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' }; const byte_t arygon_reset_tama_cmd[] = { DEV_ARYGON_PROTOCOL_ARYGON_ASCII, 'a', 'r' };
byte_t abtRx[BUFFER_LENGTH]; byte_t abtRx[BUFFER_LENGTH];
size_t szRx; size_t szRx = BUFFER_LENGTH;
int res; int res;
// Sometimes the first byte we send is not well-transmited (ie. a previously sent data on a wrong baud rate can put some junk in buffer) // Sometimes the first byte we send is not well-transmited (ie. a previously sent data on a wrong baud rate can put some junk in buffer)
@ -340,6 +340,7 @@ arygon_reset_tama (const nfc_device_spec_t nds)
// or arygon_error_unknown_mode (ie. in case of the first byte was bad-transmitted) // or arygon_error_unknown_mode (ie. in case of the first byte was bad-transmitted)
res = uart_receive ((serial_port) nds, abtRx, &szRx); res = uart_receive ((serial_port) nds, abtRx, &szRx);
if (res != 0) { if (res != 0) {
DBG ("No reply to 'reset TAMA' command.");
return false; return false;
} }
#ifdef DEBUG #ifdef DEBUG

View file

@ -102,8 +102,6 @@ pn532_uart_list_devices (nfc_device_desc_t pnddDevices[], size_t szDevices, size
bool bComOk; bool bComOk;
// Serial port claimed but we need to check if a PN532_UART is connected. // Serial port claimed but we need to check if a PN532_UART is connected.
uart_set_speed (sp, SERIAL_DEFAULT_PORT_SPEED); uart_set_speed (sp, SERIAL_DEFAULT_PORT_SPEED);
// Send ACK frame to cancel a previous command
pn532_uart_ack ((nfc_device_spec_t) sp);
// PN532 could be powered down, we need to wake it up before line testing. // PN532 could be powered down, we need to wake it up before line testing.
pn532_uart_wakeup ((nfc_device_spec_t) sp); pn532_uart_wakeup ((nfc_device_spec_t) sp);
// Check communication using "Diagnose" command, with "Communication test" (0x00) // Check communication using "Diagnose" command, with "Communication test" (0x00)
@ -156,8 +154,6 @@ pn532_uart_connect (const nfc_device_desc_t * pndd)
uart_set_speed (sp, pndd->uiSpeed); uart_set_speed (sp, pndd->uiSpeed);
// Send ACK frame to cancel a previous command
pn532_uart_ack ((nfc_device_spec_t) sp);
// PN532 could be powered down, we need to wake it up before line testing. // PN532 could be powered down, we need to wake it up before line testing.
pn532_uart_wakeup ((nfc_device_spec_t) sp); pn532_uart_wakeup ((nfc_device_spec_t) sp);
// Check communication using "Diagnose" command, with "Communication test" (0x00) // Check communication using "Diagnose" command, with "Communication test" (0x00)
@ -292,13 +288,14 @@ void
pn532_uart_wakeup (const nfc_device_spec_t nds) pn532_uart_wakeup (const nfc_device_spec_t nds)
{ {
byte_t abtRx[BUFFER_LENGTH]; byte_t abtRx[BUFFER_LENGTH];
size_t szRx; size_t szRx = BUFFER_LENGTH;
/** PN532C106 wakeup. */ /** PN532C106 wakeup. */
/** High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */ /** High Speed Unit (HSU) wake up consist to send 0x55 and wait a "long" delay for PN532 being wakeup. */
/** After the preamble we request the PN532C106 chip to switch to "normal" mode (SAM is not used) */ /** After the preamble we request the PN532C106 chip to switch to "normal" mode (SAM is not used) */
const byte_t pncmd_pn532c106_wakeup_preamble[] = const byte_t pncmd_pn532c106_wakeup_preamble[] =
{ 0x55, 0x55, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0x03, 0xfd, 0xd4, 0x14, 0x01, 0x17, 0x00, 0x00, 0xff, 0x03, 0xfd, { 0x55, 0x55, 0x00, 0x00, 0x00,
0xd4, 0x14, 0x01, 0x17, 0x00 }; 0x00, 0x00, 0xff, 0x03, 0xfd, 0xd4, 0x14, 0x01, 0x17, // XXX: WTF this command is sent twice?
0x00, 0x00, 0xff, 0x03, 0xfd, 0xd4, 0x14, 0x01, 0x17, 0x00 };
#ifdef DEBUG #ifdef DEBUG
PRINT_HEX ("TX", pncmd_pn532c106_wakeup_preamble, sizeof (pncmd_pn532c106_wakeup_preamble)); PRINT_HEX ("TX", pncmd_pn532c106_wakeup_preamble, sizeof (pncmd_pn532c106_wakeup_preamble));
#endif #endif
@ -307,6 +304,8 @@ pn532_uart_wakeup (const nfc_device_spec_t nds)
#ifdef DEBUG #ifdef DEBUG
PRINT_HEX ("RX", abtRx, szRx); PRINT_HEX ("RX", abtRx, szRx);
#endif #endif
} else {
ERR ("Unable to wakeup the PN532.");
} }
} }
@ -314,7 +313,7 @@ bool
pn532_uart_check_communication (const nfc_device_spec_t nds, bool * success) pn532_uart_check_communication (const nfc_device_spec_t nds, bool * success)
{ {
byte_t abtRx[BUFFER_LENGTH]; byte_t abtRx[BUFFER_LENGTH];
size_t szRx; size_t szRx = BUFFER_LENGTH;
const byte_t attempted_result[] = const byte_t attempted_result[] =
{ 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xD5, 0x01, 0x00, 'l', 'i', 'b', 'n', 'f', 'c', { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00, 0x00, 0x00, 0xff, 0x09, 0xf7, 0xD5, 0x01, 0x00, 'l', 'i', 'b', 'n', 'f', 'c',
0xbc, 0x00 }; 0xbc, 0x00 };

View file

@ -35,9 +35,7 @@
#include <nfc/nfc.h> #include <nfc/nfc.h>
#ifdef _WIN32 #ifdef _WIN32
# include <windows.h> # include "../contrib/windows.h"
# define snprintf sprintf_s
#endif #endif
#include "chips.h" #include "chips.h"

View file

@ -6,15 +6,30 @@ AC_DEFUN([LIBNFC_CHECK_LIBUSB],
[ [
if test x"$libusb_required" = "xyes"; then if test x"$libusb_required" = "xyes"; then
HAVE_LIBUSB=0 HAVE_LIBUSB=0
AC_ARG_WITH([libusb-win32],
[AS_HELP_STRING([--with-libusb-win32], [use libusb-win32 from the following location])],
[LIBUSB_WIN32_DIR=$withval],
[LIBUSBWIN32_DIR=""])
# --with-libusb-win32 directory have been set
if test "x$LIBUSB_WIN32_DIR" != "x"; then
AC_MSG_NOTICE(["use libusb-win32 from $LIBUSB_WIN32_DIR"])
libusb_CFLAGS="-I$LIBUSB_WIN32_DIR/include"
libusb_LIBS="-L$LIBUSB_WIN32_DIR/lib/gcc -lusb"
HAVE_LIBUSB=1
fi
# Search using pkg-config # Search using pkg-config
if test x"$PKG_CONFIG" != "x"; then if test x"$HAVE_LIBUSB" = "x0"; then
PKG_CHECK_MODULES([libusb], [libusb], [HAVE_LIBUSB=1], [HAVE_LIBUSB=0]) if test x"$PKG_CONFIG" != "x"; then
if test x"$HAVE_LIBUSB" = "x1"; then PKG_CHECK_MODULES([libusb], [libusb], [HAVE_LIBUSB=1], [HAVE_LIBUSB=0])
if test x"$PKG_CONFIG_REQUIRES" != x""; then if test x"$HAVE_LIBUSB" = "x1"; then
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES," if test x"$PKG_CONFIG_REQUIRES" != x""; then
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES,"
fi
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES libusb"
fi fi
PKG_CONFIG_REQUIRES="$PKG_CONFIG_REQUIRES libusb"
fi fi
fi fi

View file

@ -22,6 +22,11 @@ AC_DEFUN([LIBNFC_CHECK_PCSC],
AC_MSG_RESULT(yes: darwin PC/SC framework) AC_MSG_RESULT(yes: darwin PC/SC framework)
fi fi
;; ;;
*mingw*)
dnl FIXME Find a way to cross-compile for Windows
HAVE_PCSC=0
AC_MSG_RESULT(no: Windows PC/SC framework)
;;
*) *)
if test x"$HAVE_PCSC" = "x0" ; then if test x"$HAVE_PCSC" = "x0" ; then
AC_MSG_ERROR([libpcsclite is mandatory.]) AC_MSG_ERROR([libpcsclite is mandatory.])

43
mingw-cross-configure.sh Normal file
View file

@ -0,0 +1,43 @@
#!/bin/sh
WITH_USB=0
LIBUSB_WIN32_BIN_VERSION="1.2.2.0"
LIBUSB_WIN32_BIN_ARCHIVE="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION.zip"
LIBUSB_WIN32_BIN_URL="http://freefr.dl.sourceforge.net/project/libusb-win32/libusb-win32-releases/$LIBUSB_WIN32_BIN_VERSION/$LIBUSB_WIN32_BIN_ARCHIVE"
LIBUSB_WIN32_BIN_DIR="libusb-win32-bin-$LIBUSB_WIN32_BIN_VERSION"
if [ "$WITH_USB" = "1" ]; then
if [ ! -d $LIBUSB_WIN32_BIN_DIR ]; then
wget -c $LIBUSB_WIN32_BIN_URL
unzip $LIBUSB_WIN32_BIN_ARCHIVE
fi
fi
MINGW_DIR="/usr/i586-mingw32msvc"
# Use MinGW binaries before others
#export PATH=$MINGW_DIR/bin:$PATH
# Set CPATH to MinGW include files
export CPATH=$MINGW_DIR/include
export LD_LIBRARY_PATH=$MINGW_DIR/lib
export LD_RUN_PATH=$MINGW_DIR/lib
# Force pkg-config to search in cross environement directory
export PKG_CONFIG_LIBDIR=$MINGW_DIR/lib/pkgconfig
# Stop compilation on first error
export CFLAGS="-Wfatal-errors"
# Include default MinGW include directory, and libnfc's win32 files
export CFLAGS="$CFLAGS -I$MINGW_DIR/include -I$PWD/contrib/win32"
## Configure to cross-compile using mingw32msvc
if [ "$WITH_USB" = "1" ]; then
# with direct-USB drivers (use libusb-win32)
./configure --target=i586-mingw32msvc --host=i586-mingw32msvc --with-drivers=pn531_usb,pn533_usb,pn532_uart,arygon --with-libusb-win32=$PWD/$LIBUSB_WIN32_BIN_DIR $*
else
# with UART divers only (can be tested under wine)
./configure --target=i586-mingw32msvc --host=i586-mingw32msvc --with-drivers=pn532_uart,arygon $*
fi