Skip to content

Commit

Permalink
Merge branch 'master' into pn532_spi
Browse files Browse the repository at this point in the history
* master: (28 commits)
  Update Changelog
  Add missing windows files in archive
  Move log implementation for Windows in dedicated directory
  Move UART implementation for Windows in dedicated directory
  CMake: only compile usbbus.c when (at least) one USB driver is enabled
  CMake: only include UART related files when (at least) one UART driver is enabled
  Only include UART related files when (at least) one UART driver is enabled
  Fix environment vars usage when compiling with CMake
  Remove unsed code section in log.c (was commented)
  pn53x_current_target_new() now returns null ptr upon malloc() error
  fix missing tests on malloc() return
  pn53x_data_new() now returns null ptr upon malloc() error
  uart drivers: missing pn53x_data_free() on some error handling branches
  uart drivers: missing nfc_device_free() on some error handling branches
  uart drivers: missing uart_close() on some error handling branches
  uart drivers: fix missing free(ndd.port)
  config parser: missing fclose()
  UART drivers: fix double free() of serial port info
  Fix cmake build failure under linux
  quick_start_example1.c: avoid using warnx() to remove err.h dependency
  ...

Conflicts:
	libnfc/buses/Makefile.am
  • Loading branch information
doegox committed Mar 27, 2013
2 parents a3f4145 + eb515a6 commit 1417bdc
Show file tree
Hide file tree
Showing 29 changed files with 645 additions and 512 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ IF(LIBNFC_LOG)
ADD_DEFINITIONS(-DLOG)
ENDIF(LIBNFC_LOG)

SET(LIBNFC_ENVVARS ON CACHE BOOL "Enable envvars facility")
IF(LIBNFC_ENVVARS)
ADD_DEFINITIONS(-DENVVARS)
ENDIF(LIBNFC_ENVVARS)

SET(LIBNFC_DEBUG_MODE OFF CACHE BOOL "Debug mode")
IF(LIBNFC_DEBUG_MODE)
ADD_DEFINITIONS(-DDEBUG)
Expand Down Expand Up @@ -111,6 +116,8 @@ IF (WIN32)
ENDIF(PCRE_INCLUDE_DIRS)
ENDIF(WIN32)

INCLUDE(LibnfcDrivers)

IF(PCSC_INCLUDE_DIRS)
INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS})
LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS})
Expand Down
9 changes: 9 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,24 @@ Fixes:
- scanf without field width limits can crash with huge input data
- Resource leaks: missing fclose()
- Dead code, unused vars & vars scopes warnings
- Unify copyright notices & update authors lists
- Windows: Fix compilation due to new usbbus file
- Windows: Clean up compiler/linker warnings
- Fixed the suppression of the auto-fixup for linking against MS built libs
- Fixed all the formatting warnings by shifting to inttypes.h specifiers
- shifted to %lu for DWORD printf
- nfc-anticol: fix ATS length
- nfc-mfclassic: fix reporting of processed blocks total
- nfc-mfclassic: detect MIFARE Plus 2K as 2K instead of 1K

Improvements:
- Devels HACKING file: introduce clang/scan-build & cppcheck for better code
- Better internal dependencies handling (bus <> drivers)
- Cleaner handling of portability patches
- Windows: logging via OutputDebugString(), ease debugging
- nfc-mfclassic: use smaller files for cards < 4k
- nfc-mfclassic: by defaut don't authorise wrong keyfile, use "f" to force
- quick_start_example1.c: remove err.h dependency, easier for Windowsians

Changes:
- Upon malloc error, nfc_init() doesn't force exit() anymore
Expand Down
3 changes: 3 additions & 0 deletions cmake/modules/LibnfcDrivers.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@ IF(LIBNFC_DRIVER_PN53X_USB)
FIND_PACKAGE(LIBUSB REQUIRED)
ADD_DEFINITIONS("-DDRIVER_PN53X_USB_ENABLED")
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/pn53x_usb")
SET(USB_REQUIRED TRUE)
ENDIF(LIBNFC_DRIVER_PN53X_USB)

IF(LIBNFC_DRIVER_ARYGON)
ADD_DEFINITIONS("-DDRIVER_ARYGON_ENABLED")
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/arygon")
SET(UART_REQUIRED TRUE)
ENDIF(LIBNFC_DRIVER_ARYGON)

IF(LIBNFC_DRIVER_PN532_UART)
ADD_DEFINITIONS("-DDRIVER_PN532_UART_ENABLED")
SET(DRIVERS_SOURCES ${DRIVERS_SOURCES} "drivers/pn532_uart")
SET(UART_REQUIRED TRUE)
ENDIF(LIBNFC_DRIVER_PN532_UART)

INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/drivers)
Expand Down
5 changes: 5 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,9 @@ fi
# Handle --with-drivers option
LIBNFC_ARG_WITH_DRIVERS

# Enable UART if
AM_CONDITIONAL(UART_ENABLED, [test x"$uart_required" = x"yes"])

# Documentation (default: no)
AC_ARG_ENABLE([doc],AS_HELP_STRING([--enable-doc],[Enable documentation generation.]),[enable_doc=$enableval],[enable_doc="no"])

Expand Down Expand Up @@ -175,6 +178,8 @@ AC_CONFIG_FILES([
contrib/udev/Makefile
contrib/win32/Makefile
contrib/win32/sys/Makefile
contrib/win32/libnfc/Makefile
contrib/win32/libnfc/buses/Makefile
examples/Makefile
examples/pn53x-tamashell-scripts/Makefile
include/Makefile
Expand Down
2 changes: 1 addition & 1 deletion contrib/win32/Makefile.am
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
SUBDIRS = sys .
SUBDIRS = libnfc sys .

EXTRA_DIST = \
err.h \
Expand Down
4 changes: 4 additions & 0 deletions contrib/win32/libnfc/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
SUBDIRS = buses .

EXTRA_DIST = \
log-internal.c
2 changes: 2 additions & 0 deletions contrib/win32/libnfc/buses/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
EXTRA_DIST = \
uart.c
19 changes: 18 additions & 1 deletion libnfc/buses/uart_win32.c → contrib/win32/libnfc/buses/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,19 @@
*/

/**
* @file uart_win32.c
* @file uart.c
* @brief Windows UART driver
*/

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif // HAVE_CONFIG_H

#include "uart.h"

#include <nfc/nfc.h>
#include "nfc-internal.h"

#include <inttypes.h>
#include "log.h"

Expand Down Expand Up @@ -250,11 +259,19 @@ char **
uart_list_ports(void)
{
char **availablePorts = malloc((1 + MAX_SERIAL_PORT_WIN) * sizeof(char *));
if (!availablePorts) {
perror("malloc");
return availablePorts;
}
int curIndex = 0;
int i;
for (i = 1; i <= MAX_SERIAL_PORT_WIN; i++) {
if (is_port_available(i)) {
availablePorts[curIndex] = (char *)malloc(10);
if (!availablePorts[curIndex]) {
perror("malloc");
break;
}
sprintf(availablePorts[curIndex], "COM%d", i);
// printf("found candidate port: %s\n", availablePorts[curIndex]);
curIndex++;
Expand Down
File renamed without changes.
9 changes: 2 additions & 7 deletions examples/doc/quick_start_example1.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@
// To compile this simple example:
// $ gcc -o quick_start_example1 quick_start_example1.c -lnfc

#ifdef HAVE_CONFIG_H
# include "config.h"
#endif // HAVE_CONFIG_H

#include <stdlib.h>
#include <err.h>
#include <nfc/nfc.h>

static void
Expand All @@ -37,7 +32,7 @@ main(int argc, const char *argv[])
// Initialize libnfc and set the nfc_context
nfc_init(&context);
if (context == NULL) {
warnx("Unable to init libnfc (malloc)\n");
printf("Unable to init libnfc (malloc)\n");
exit(EXIT_FAILURE);
}

Expand All @@ -53,7 +48,7 @@ main(int argc, const char *argv[])
pnd = nfc_open(context, NULL);

if (pnd == NULL) {
warnx("ERROR: %s", "Unable to open NFC device.");
printf("ERROR: %s", "Unable to open NFC device.");
exit(EXIT_FAILURE);
}
// Set opened NFC device to initiator mode
Expand Down
4 changes: 2 additions & 2 deletions examples/nfc-anticol.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ transmit_bytes(const uint8_t *pbtTx, const size_t szTx)
// Transmit the command bytes
if ((res = nfc_initiator_transceive_bytes(pnd, pbtTx, szTx, abtRx, sizeof(abtRx), 0)) < 0)
return false;

szRx = res;
// Show received answer
if (!quiet_output) {
printf("Received bits: ");
print_hex(abtRx, res);
print_hex(abtRx, szRx);
}
// Succesful transfer
return true;
Expand Down
26 changes: 16 additions & 10 deletions libnfc/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,20 @@ SET(CHIPS_SOURCES chips/pn53x)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/chips)

# Library's buses
IF(LIBUSB_FOUND)
SET(BUSES_SOURCES buses/uart buses/usbbus)
ELSE(LIBUSB_FOUND)
SET(BUSES_SOURCES buses/uart)
ENDIF(LIBUSB_FOUND)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/buses)
IF(USB_REQUIRED)
LIST(APPEND BUSES_SOURCES buses/usbbus)
ENDIF(USB_REQUIRED)

IF(UART_REQUIRED)
IF(WIN32)
# Windows have a special implementation for UART
LIST(APPEND BUSES_SOURCES ../contrib/win32/libnfc/buses/uart)
ELSE(WIN32)
LIST(APPEND BUSES_SOURCES buses/uart)
ENDIF(WIN32)
ENDIF(UART_REQUIRED)

INCLUDE(LibnfcDrivers)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/buses)

IF(WIN32)
# Windows now requires regex, so we utilize PCRE
Expand All @@ -42,15 +48,15 @@ IF(LIBUSB_FOUND)
ENDIF(LIBUSB_FOUND)

# Library
SET(LIBRARY_SOURCES nfc nfc-device nfc-emulation nfc-internal conf iso14443-subr mirror-subr target-subr log ${DRIVERS_SOURCES} ${BUSES_SOURCES} ${CHIPS_SOURCES} ${WINDOWS_SOURCES})
SET(LIBRARY_SOURCES nfc nfc-device nfc-emulation nfc-internal conf iso14443-subr mirror-subr target-subr ${DRIVERS_SOURCES} ${BUSES_SOURCES} ${CHIPS_SOURCES} ${WINDOWS_SOURCES})
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})

IF(LIBNFC_LOG)
IF(WIN32)
SET(CMAKE_C_FLAGS "-fgnu89-inline ${CMAKE_C_FLAGS}")
LIST(APPEND LIBRARY_SOURCES log_win32)
LIST(APPEND LIBRARY_SOURCES log ../contrib/win32/libnfc/log-internal)
ELSE(WIN32)
LIST(APPEND LIBRARY_SOURCES log_posix)
LIST(APPEND LIBRARY_SOURCES log log-internal)
ENDIF(WIN32)
ENDIF(LIBNFC_LOG)
ADD_LIBRARY(nfc SHARED ${LIBRARY_SOURCES})
Expand Down
7 changes: 2 additions & 5 deletions libnfc/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ lib_LTLIBRARIES = libnfc.la
libnfc_la_SOURCES = \
conf.c \
iso14443-subr.c \
log.c \
mirror-subr.c \
nfc.c \
nfc-device.c \
Expand Down Expand Up @@ -41,10 +40,8 @@ if LIBUSB_ENABLED
endif

if WITH_LOG
libnfc_la_SOURCES += log_posix.c
libnfc_la_SOURCES += log.c log-internal.c
endif

EXTRA_DIST = \
CMakeLists.txt \
log_posix.c \
log_win32.c
CMakeLists.txt
12 changes: 7 additions & 5 deletions libnfc/buses/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ noinst_LTLIBRARIES = libnfcbuses.la
libnfcbuses_la_SOURCES =
libnfcbuses_la_CFLAGS = -I$(top_srcdir)/libnfc
libnfcbuses_la_LIBADD =
EXTRA_DIST =

# SPI_ENABLED
libnfcbuses_la_SOURCES += spi.c spi.h
libnfcbuses_la_CFLAGS +=
libnfcbuses_la_LIBADD +=
EXTRA_DIST = spi_posix.c

# UART_ENABLED
libnfcbuses_la_SOURCES += uart.c uart.h
libnfcbuses_la_CFLAGS +=
libnfcbuses_la_LIBADD +=
EXTRA_DIST = uart_posix.c uart_win32.c
if UART_ENABLED
libnfcbuses_la_SOURCES += uart.c uart.h
libnfcbuses_la_CFLAGS +=
libnfcbuses_la_LIBADD +=
endif
EXTRA_DIST += uart.c uart.h

if LIBUSB_ENABLED
libnfcbuses_la_SOURCES += usbbus.c usbbus.h
Expand Down
Loading

0 comments on commit 1417bdc

Please sign in to comment.