Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 16 additions & 22 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ SET(PACKAGE_NAME "libnfc")
SET(PACKAGE_VERSION ${VERSION})
SET(PACKAGE_STRING "${PACKAGE_NAME} ${PACKAGE_VERSION}")

SET(CMAKE_C_STANDARD 99)

# config.h
IF(WIN32)
SET(LIBNFC_SYSCONFDIR "./config" CACHE PATH "libnfc configuration directory")
Expand Down Expand Up @@ -52,9 +54,7 @@ ENDIF(LIBNFC_ENVVARS)
SET(LIBNFC_DEBUG_MODE OFF CACHE BOOL "Debug mode")
IF(LIBNFC_DEBUG_MODE)
ADD_DEFINITIONS(-DDEBUG)
SET(CMAKE_C_FLAGS "-g3 ${CMAKE_C_FLAGS}")
SET(WIN32_MODE "debug")
SET(CMAKE_RC_FLAGS "-D_DEBUG ${CMAKE_RC_FLAGS}")
ELSE(LIBNFC_DEBUG_MODE)
SET(WIN32_MODE "release")
ENDIF(LIBNFC_DEBUG_MODE)
Expand Down Expand Up @@ -93,12 +93,6 @@ IF(NOT DEFINED SHARE_INSTALL_PREFIX)
SET(SHARE_INSTALL_PREFIX share)
ENDIF(NOT DEFINED SHARE_INSTALL_PREFIX)

# Additonnal GCC flags
IF(CMAKE_COMPILER_IS_GNUCC)
# Make sure we will not miss some warnings ;)
SET(CMAKE_C_FLAGS "-Wall -pedantic -std=c99 ${CMAKE_C_FLAGS}")
ENDIF(CMAKE_COMPILER_IS_GNUCC)

# Workarounds for libusb in C99
ADD_DEFINITIONS(-Du_int8_t=uint8_t -Du_int16_t=uint16_t)

Expand Down Expand Up @@ -152,20 +146,20 @@ ENDIF(NOT WIN32)
INCLUDE(LibnfcDrivers)

IF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IF(I2C_REQUIRED)
# Inspired from http://cmake.3232098.n2.nabble.com/RFC-cmake-analog-to-AC-SEARCH-LIBS-td7585423.html
INCLUDE (CheckFunctionExists)
INCLUDE (CheckLibraryExists)
CHECK_FUNCTION_EXISTS (clock_gettime HAVE_CLOCK_GETTIME)
IF (NOT HAVE_CLOCK_GETTIME)
CHECK_LIBRARY_EXISTS (rt clock_gettime "" HAVE_CLOCK_GETTIME_IN_RT)
IF (HAVE_CLOCK_GETTIME_IN_RT)
SET(LIBRT_FOUND TRUE)
SET(LIBRT_LIBRARIES "rt")
ENDIF (HAVE_CLOCK_GETTIME_IN_RT)
ENDIF (NOT HAVE_CLOCK_GETTIME)
ENDIF(I2C_REQUIRED)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
IF(I2C_REQUIRED)
# Inspired from http://cmake.3232098.n2.nabble.com/RFC-cmake-analog-to-AC-SEARCH-LIBS-td7585423.html
INCLUDE (CheckFunctionExists)
INCLUDE (CheckLibraryExists)
CHECK_FUNCTION_EXISTS (clock_gettime HAVE_CLOCK_GETTIME)
IF (NOT HAVE_CLOCK_GETTIME)
CHECK_LIBRARY_EXISTS (rt clock_gettime "" HAVE_CLOCK_GETTIME_IN_RT)
IF (HAVE_CLOCK_GETTIME_IN_RT)
SET(LIBRT_FOUND TRUE)
SET(LIBRT_LIBRARIES "rt")
ENDIF (HAVE_CLOCK_GETTIME_IN_RT)
ENDIF (NOT HAVE_CLOCK_GETTIME)
ENDIF(I2C_REQUIRED)
ENDIF(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

IF(PCSC_INCLUDE_DIRS)
INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS})
Expand Down
2 changes: 0 additions & 2 deletions contrib/win32/libnfc/buses/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,7 @@
#define LOG_GROUP NFC_LOG_GROUP_COM
#define LOG_CATEGORY "libnfc.bus.uart_win32"

// Handle platform specific includes
#include "contrib/windows.h"
#define delay_ms( X ) Sleep( X )

struct serial_port_windows {
HANDLE hPort; // Serial port handle
Expand Down
4 changes: 0 additions & 4 deletions examples/nfc-emulate-tag.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,7 @@ main(int argc, char *argv[])
(void) argc;
const char *acLibnfcVersion;

#ifdef WIN32
signal(SIGINT, (void (__cdecl *)(int)) intr_hdlr);
#else
signal(SIGINT, intr_hdlr);
#endif

nfc_init(&context);
if (context == NULL) {
Expand Down
4 changes: 0 additions & 4 deletions examples/nfc-emulate-uid.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,7 @@ main(int argc, char *argv[])
}
}

#ifdef WIN32
signal(SIGINT, (void (__cdecl *)(int)) intr_hdlr);
#else
signal(SIGINT, intr_hdlr);
#endif

nfc_init(&context);
if (context == NULL) {
Expand Down
1 change: 0 additions & 1 deletion examples/nfc-poll.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
# include "config.h"
#endif // HAVE_CONFIG_H

#include <err.h>
#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
Expand Down
4 changes: 0 additions & 4 deletions examples/nfc-relay.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,11 +109,7 @@ main(int argc, char *argv[])
// Display libnfc version
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);

#ifdef WIN32
signal(SIGINT, (void (__cdecl *)(int)) intr_hdlr);
#else
signal(SIGINT, intr_hdlr);
#endif

nfc_context *context;
nfc_init(&context);
Expand Down
6 changes: 1 addition & 5 deletions examples/nfc-st25tb.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@
#include <string.h>
#include <nfc/nfc.h>

#if defined(WIN32) /* mingw compiler */
#include <getopt.h>
#endif

#define ST25TB_SR_BLOCK_MAX_SIZE ((uint8_t) 4) // for static arrays
#define ST25TB_SR_BLOCK_MAX_SIZE ((size_t) 4) // for static arrays
typedef void(*get_info_specific) (uint8_t * systemArea);

typedef struct _st_data {
Expand Down
1 change: 0 additions & 1 deletion examples/pn53x-diagnose.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
# include "config.h"
#endif // HAVE_CONFIG_H

#include <err.h>
#include <stdlib.h>
#include <string.h>

Expand Down
15 changes: 1 addition & 14 deletions examples/pn53x-tamashell.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,11 @@
#include <ctype.h>
#include <time.h>

#ifndef _WIN32
# include <time.h>
# define msleep(x) do { \
struct timespec xsleep; \
xsleep.tv_sec = x / 1000; \
xsleep.tv_nsec = (x - xsleep.tv_sec * 1000) * 1000 * 1000; \
nanosleep(&xsleep, NULL); \
} while (0)
#else
# include <winbase.h>
# define msleep Sleep
#endif


#include <nfc/nfc.h>

#include "utils/nfc-utils.h"
#include "libnfc/chips/pn53x.h"
#include "libnfc/nfc-internal.h"

#define MAX_FRAME_LEN 264

Expand Down
2 changes: 1 addition & 1 deletion libnfc/buses/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <stdio.h>
#include <termios.h>
Expand Down
1 change: 0 additions & 1 deletion libnfc/buses/spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
#include <sys/types.h>
#include <ctype.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <limits.h>
#include <stdio.h>
Expand Down
16 changes: 0 additions & 16 deletions libnfc/buses/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,22 +57,6 @@
#define LOG_GROUP NFC_LOG_GROUP_COM
#define LOG_CATEGORY "libnfc.bus.uart"

#ifndef _WIN32
// Needed by sleep() under Unix
# include <unistd.h>
# include <time.h>
# define msleep(x) do { \
struct timespec xsleep; \
xsleep.tv_sec = x / 1000; \
xsleep.tv_nsec = (x - xsleep.tv_sec * 1000) * 1000 * 1000; \
nanosleep(&xsleep, NULL); \
} while (0)
#else
// Needed by Sleep() under Windows
# include <winbase.h>
# define msleep Sleep
#endif

# if defined(__APPLE__)
const char *serial_ports_device_radix[] = { "tty.SLAB_USBtoUART", "tty.usbserial", "tty.usbmodem", NULL };
# elif defined (__FreeBSD__) || defined (__OpenBSD__) || defined(__FreeBSD_kernel__)
Expand Down
5 changes: 3 additions & 2 deletions libnfc/chips/pn53x.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@
#define LOG_CATEGORY "libnfc.chip.pn53x"
#define LOG_GROUP NFC_LOG_GROUP_CHIP

#define SAK_ISO14443_4_COMPLIANT 0x20
#define SAK_ISO18092_COMPLIANT 0x40

const uint8_t pn53x_ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 };
const uint8_t pn53x_nack_frame[] = { 0x00, 0x00, 0xff, 0xff, 0x00, 0x00 };
static const uint8_t pn53x_error_frame[] = { 0x00, 0x00, 0xff, 0x01, 0xff, 0x7f, 0x81, 0x00 };
Expand Down Expand Up @@ -2367,8 +2370,6 @@ pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt)
return pnd->last_error = ret;
}

#define SAK_ISO14443_4_COMPLIANT 0x20
#define SAK_ISO18092_COMPLIANT 0x40
int
pn53x_target_init(struct nfc_device *pnd, nfc_target *pnt, uint8_t *pbtRx, const size_t szRxLen, int timeout)
{
Expand Down
2 changes: 1 addition & 1 deletion libnfc/drivers/acr122_usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, co
len = abtRxBuf[offset++];
if ((abtRxBuf[offset] != 0x00) && (abtRxBuf[offset + 1] != 0x00) && (abtRxBuf[offset + 2] != 0x00)) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Not implemented: only 1-byte length is supported, please report this bug with a full trace.");
pnd->last_error = NFC_EIO;
pnd->last_error = NFC_ENOTIMPL;
return pnd->last_error;
}
offset += 3;
Expand Down
10 changes: 4 additions & 6 deletions libnfc/drivers/acr122s.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ acr122s_send_frame(nfc_device *pnd, uint8_t *frame, int timeout)
}

/**
* Receive response frame after a successfull acr122s_send_command().
* Receive response frame after a successful acr122s_send_command().
*
* @param: pnd is target nfc device
* @param: frame is buffer where received response frame will be stored
Expand Down Expand Up @@ -272,7 +272,7 @@ acr122s_recv_frame(nfc_device *pnd, uint8_t *frame, size_t frame_size, void *abo
#define APDU_OVERHEAD (FRAME_OVERHEAD + 5)

/**
* Convert host uint32 to litle endian uint32
* Convert host uint32 to little endian uint32
*/
static uint32_t
le32(uint32_t val)
Expand Down Expand Up @@ -417,7 +417,7 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz
size_t device_found = 0;
serial_port sp;
char **acPorts = uart_list_ports();
const char *acPort;
char *acPort;
int iDevice = 0;

while ((acPort = acPorts[iDevice++])) {
Expand Down Expand Up @@ -621,7 +621,6 @@ acr122s_open(const nfc_context *context, const nfc_connstring connstring)
}
CHIP_DATA(pnd)->type = PN532;

#if 1
// Retrieve firmware version
char version[DEVICE_NAME_LENGTH];
if (acr122s_get_firmware_version(pnd, version, sizeof(version)) != 0) {
Expand All @@ -637,15 +636,14 @@ acr122s_open(const nfc_context *context, const nfc_connstring connstring)
return NULL;
}

snprintf(pnd->name, sizeof(pnd->name), "%s", version);
strncpy(pnd->name, version, DEVICE_NAME_LENGTH);

// Activate SAM before operating
if (acr122s_activate_sam(pnd) != 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Cannot activate SAM.");
acr122s_close(pnd);
return NULL;
}
#endif

if (pn53x_init(pnd) < 0) {
log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Failed initializing PN532 chip.");
Expand Down
2 changes: 1 addition & 1 deletion libnfc/drivers/arygon.c
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size
size_t device_found = 0;
serial_port sp;
char **acPorts = uart_list_ports();
const char *acPort;
char *acPort;
int iDevice = 0;

while ((acPort = acPorts[iDevice++])) {
Expand Down
17 changes: 6 additions & 11 deletions libnfc/drivers/pcsc.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,17 +67,12 @@
#define SCARD_ATTR_VENDOR_IFD_SERIAL_NO SCARD_ATTR_VALUE(SCARD_CLASS_VENDOR_INFO, 0x0103) /**< Vendor-supplied interface device serial number. */
#define SCARD_ATTR_ICC_TYPE_PER_ATR SCARD_ATTR_VALUE(SCARD_CLASS_ICC_STATE, 0x0304) /**< Single byte indicating smart card type */
#else
#ifndef _Win32
#ifndef _WIN32
#include <reader.h>
#endif
#include <winscard.h>
#endif

#ifdef WIN32
#include <windows.h>
#define usleep(x) Sleep((x + 999) / 1000)
#endif

#define PCSC_DRIVER_NAME "pcsc"

#include <nfc/nfc.h>
Expand Down Expand Up @@ -549,7 +544,7 @@ pcsc_open(const nfc_context *context, const nfc_connstring connstring)
DRIVER_DATA(pnd)->dwShareMode = SCARD_SHARE_DIRECT;

// Done, we found the reader we are looking for
snprintf(pnd->name, sizeof(pnd->name), "%s", ndd.pcsc_device_name);
strcpy(pnd->name, ndd.pcsc_device_name);

pnd->driver = &pcsc_driver;

Expand Down Expand Up @@ -713,14 +708,14 @@ static const char *stringify_error(const LONG pcscError)
msg = "Feature not supported.";
break;
default:
(void)snprintf(strError, sizeof(strError) - 1, "Unknown error: 0x%08lX",
snprintf(strError, sizeof(strError) - 1, "Unknown error: 0x%08lX",
pcscError);
};

if (msg)
(void)strncpy(strError, msg, sizeof(strError));
strncpy(strError, msg, sizeof(strError));
else
(void)snprintf(strError, sizeof(strError) - 1, "Unknown error: 0x%08lX",
snprintf(strError, sizeof(strError) - 1, "Unknown error: 0x%08lX",
pcscError);

/* add a null byte */
Expand Down Expand Up @@ -826,7 +821,7 @@ static int pcsc_initiator_transceive_bytes(struct nfc_device *pnd, const uint8_t
pnd->last_error = pcsc_transmit(pnd, apdu_data, send_size, resp, &resp_len);
memset(apdu_data, 0, sizeof(apdu_data));
memset(resp, 0, sizeof(resp));
usleep(500000);//delay 500ms
msleep(500);
}
// then auth
apdu_data[0] = 0xFF;
Expand Down
16 changes: 0 additions & 16 deletions libnfc/drivers/pn532_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,6 @@
#define LOG_CATEGORY "libnfc.driver.pn532_spi"
#define LOG_GROUP NFC_LOG_GROUP_DRIVER

#ifndef _WIN32
// Needed by sleep() under Unix
# include <unistd.h>
# include <time.h>
# define msleep(x) do { \
struct timespec xsleep; \
xsleep.tv_sec = x / 1000; \
xsleep.tv_nsec = (x - xsleep.tv_sec * 1000) * 1000 * 1000; \
nanosleep(&xsleep, NULL); \
} while (0)
#else
// Needed by Sleep() under Windows
# include <winbase.h>
# define msleep Sleep
#endif

// Internal data structs
const struct pn53x_io pn532_spi_io;
struct pn532_spi_data {
Expand Down
2 changes: 1 addition & 1 deletion libnfc/drivers/pn532_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const
size_t device_found = 0;
serial_port sp;
char **acPorts = uart_list_ports();
const char *acPort;
char *acPort;
int iDevice = 0;

while ((acPort = acPorts[iDevice++])) {
Expand Down
Loading