From f22f467315fb64fed6aebba9e8c015a0df1007da Mon Sep 17 00:00:00 2001 From: Yang Kun <91833768+ikspress@users.noreply.github.com> Date: Sun, 23 Jun 2024 00:06:20 +0800 Subject: [PATCH] Cleanup codes --- CMakeLists.txt | 38 ++++++++----------- contrib/win32/libnfc/buses/uart.c | 4 +- examples/nfc-emulate-forum-tag2.c | 2 +- examples/nfc-emulate-tag.c | 4 -- examples/nfc-emulate-uid.c | 4 -- examples/nfc-poll.c | 1 - examples/nfc-relay.c | 4 -- examples/nfc-st25tb.c | 6 +-- examples/pn53x-diagnose.c | 1 - examples/pn53x-tamashell.c | 15 +------- libnfc/buses/i2c.c | 2 +- libnfc/buses/spi.c | 1 - libnfc/buses/uart.c | 22 ++--------- libnfc/chips/pn53x.c | 43 ++++++++++----------- libnfc/conf.c | 6 +-- libnfc/drivers/acr122_pcsc.c | 6 +-- libnfc/drivers/acr122_usb.c | 32 ++++++++-------- libnfc/drivers/acr122s.c | 32 ++++++++-------- libnfc/drivers/arygon.c | 48 ++++++++++++------------ libnfc/drivers/pcsc.c | 28 ++++++-------- libnfc/drivers/pn532_i2c.c | 16 ++++---- libnfc/drivers/pn532_spi.c | 62 ++++++++++++------------------- libnfc/drivers/pn532_uart.c | 42 ++++++++++----------- libnfc/drivers/pn53x_usb.c | 36 +++++++++--------- libnfc/nfc-internal.h | 21 ++++++++--- libnfc/nfc.c | 2 +- utils/nfc-list.c | 1 - utils/nfc-mfclassic.c | 1 - utils/nfc-read-forum-tag3.c | 4 -- utils/nfc-relay-picc.c | 5 --- utils/nfc-scan-device.c | 1 - utils/nfc-utils.c | 1 - 32 files changed, 205 insertions(+), 286 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index a8605fa4..edc36516 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") @@ -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) @@ -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) @@ -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}) diff --git a/contrib/win32/libnfc/buses/uart.c b/contrib/win32/libnfc/buses/uart.c index ba7ddfe8..44153385 100644 --- a/contrib/win32/libnfc/buses/uart.c +++ b/contrib/win32/libnfc/buses/uart.c @@ -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 @@ -143,7 +141,7 @@ uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) // Set baud rate spw->dcb.BaudRate = uiPortSpeed; if (!SetCommState(spw->hPort, &spw->dcb)) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to apply new speed settings."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to apply new speed settings."); return; } PurgeComm(spw->hPort, PURGE_RXABORT | PURGE_RXCLEAR); diff --git a/examples/nfc-emulate-forum-tag2.c b/examples/nfc-emulate-forum-tag2.c index 516de1d0..8aa5655f 100644 --- a/examples/nfc-emulate-forum-tag2.c +++ b/examples/nfc-emulate-forum-tag2.c @@ -120,8 +120,8 @@ static uint8_t __nfcforum_tag2_memory_area[] = { #define READ 0x30 #define WRITE 0xA2 #define SECTOR_SELECT 0xC2 - #define HALT 0x50 + static int nfcforum_tag2_io(struct nfc_emulator *emulator, const uint8_t *data_in, const size_t data_in_len, uint8_t *data_out, const size_t data_out_len) { diff --git a/examples/nfc-emulate-tag.c b/examples/nfc-emulate-tag.c index a2adbe67..a3f96e26 100644 --- a/examples/nfc-emulate-tag.c +++ b/examples/nfc-emulate-tag.c @@ -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) { diff --git a/examples/nfc-emulate-uid.c b/examples/nfc-emulate-uid.c index 690388ed..ff29d879 100644 --- a/examples/nfc-emulate-uid.c +++ b/examples/nfc-emulate-uid.c @@ -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) { diff --git a/examples/nfc-poll.c b/examples/nfc-poll.c index 4cea5d63..2acacc60 100644 --- a/examples/nfc-poll.c +++ b/examples/nfc-poll.c @@ -44,7 +44,6 @@ # include "config.h" #endif // HAVE_CONFIG_H -#include #include #include #include diff --git a/examples/nfc-relay.c b/examples/nfc-relay.c index e03c8cd2..6c0948c8 100644 --- a/examples/nfc-relay.c +++ b/examples/nfc-relay.c @@ -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); diff --git a/examples/nfc-st25tb.c b/examples/nfc-st25tb.c index 7eb5deeb..47c7263f 100644 --- a/examples/nfc-st25tb.c +++ b/examples/nfc-st25tb.c @@ -64,11 +64,7 @@ #include #include -#if defined(WIN32) /* mingw compiler */ -#include -#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 { diff --git a/examples/pn53x-diagnose.c b/examples/pn53x-diagnose.c index b5b0e525..50f5169b 100644 --- a/examples/pn53x-diagnose.c +++ b/examples/pn53x-diagnose.c @@ -43,7 +43,6 @@ # include "config.h" #endif // HAVE_CONFIG_H -#include #include #include diff --git a/examples/pn53x-tamashell.c b/examples/pn53x-tamashell.c index 52beee16..d384098a 100644 --- a/examples/pn53x-tamashell.c +++ b/examples/pn53x-tamashell.c @@ -54,24 +54,11 @@ #include #include -#ifndef _WIN32 -# include -# 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 -# define msleep Sleep -#endif - - #include #include "utils/nfc-utils.h" #include "libnfc/chips/pn53x.h" +#include "libnfc/nfc-internal.h" #define MAX_FRAME_LEN 264 diff --git a/libnfc/buses/i2c.c b/libnfc/buses/i2c.c index dc1ad1f0..b400bc7e 100644 --- a/libnfc/buses/i2c.c +++ b/libnfc/buses/i2c.c @@ -41,10 +41,10 @@ #include #include #include -#include #include #include #include +#include #include #include #include diff --git a/libnfc/buses/spi.c b/libnfc/buses/spi.c index 0e68f9b4..4a2bc308 100644 --- a/libnfc/buses/spi.c +++ b/libnfc/buses/spi.c @@ -45,7 +45,6 @@ #include #include #include -#include #include #include #include diff --git a/libnfc/buses/uart.c b/libnfc/buses/uart.c index ffe64aa5..212199d1 100644 --- a/libnfc/buses/uart.c +++ b/libnfc/buses/uart.c @@ -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 -# include -# 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 -# 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__) @@ -233,7 +217,7 @@ uart_set_speed(serial_port sp, const uint32_t uiPortSpeed) cfsetispeed(&(UART_DATA(sp)->termios_new), stPortSpeed); cfsetospeed(&(UART_DATA(sp)->termios_new), stPortSpeed); if (tcsetattr(UART_DATA(sp)->fd, TCSADRAIN, &(UART_DATA(sp)->termios_new)) == -1) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to apply new speed settings."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to apply new speed settings."); } } @@ -338,13 +322,13 @@ uart_receive(serial_port sp, uint8_t *pbtRx, const size_t szRx, void *abort_p, i } // Read time-out if (res == 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Timeout!"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeout!"); return NFC_ETIMEOUT; } if (FD_ISSET(iAbortFd, &rfds)) { // Abort requested - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Abort!"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Abort!"); close(iAbortFd); return NFC_EOPABORTED; } diff --git a/libnfc/chips/pn53x.c b/libnfc/chips/pn53x.c index e5d9d940..096120a8 100644 --- a/libnfc/chips/pn53x.c +++ b/libnfc/chips/pn53x.c @@ -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 }; @@ -179,7 +182,7 @@ pn53x_transceive(struct nfc_device *pnd, const uint8_t *pbtTx, const size_t szTx if (timeout > 0) { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Timeout value: %d", timeout); } else if (timeout == 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "No timeout"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "No timeout"); } else if (timeout == -1) { timeout = CHIP_DATA(pnd)->timeout_command; } else { @@ -1993,7 +1996,7 @@ static int pn53x_Diagnose06(struct nfc_device *pnd) static int pn53x_ISO14443A_4_is_present(struct nfc_device *pnd) { int ret; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping -4A"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping -4A"); if (CHIP_DATA(pnd)->type == PN533) { ret = pn53x_Diagnose06(pnd); if ((ret == NFC_ETIMEOUT) || (ret == NFC_ETGRELEASED)) { @@ -2034,7 +2037,7 @@ static int pn53x_ISO14443A_4_is_present(struct nfc_device *pnd) static int pn53x_ISO14443A_Jewel_is_present(struct nfc_device *pnd) { int ret; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping Jewel"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping Jewel"); uint8_t abtCmd[1] = {0x78}; int failures = 0; while (failures < 2) { @@ -2054,7 +2057,7 @@ static int pn53x_ISO14443A_Jewel_is_present(struct nfc_device *pnd) static int pn53x_ISO14443A_Barcode_is_present(struct nfc_device *pnd) { int ret; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping Barcode"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping Barcode"); // We turn RF field off first for a better detection rate but this doesn't work well with ASK LoGO if ((! CHIP_DATA(pnd)->progressive_field) && (ret = nfc_device_set_property_bool(pnd, NP_ACTIVATE_FIELD, false)) < 0) { @@ -2088,7 +2091,7 @@ static int pn53x_ISO14443A_Barcode_is_present(struct nfc_device *pnd) static int pn53x_ISO14443A_MFUL_is_present(struct nfc_device *pnd) { int ret; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping MFUL"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping MFUL"); // Limitation: test on MFULC non-authenticated with read of first sector forbidden will fail if (CHIP_DATA(pnd)->type == PN533) { ret = pn53x_Diagnose06(pnd); @@ -2113,7 +2116,7 @@ static int pn53x_ISO14443A_MFUL_is_present(struct nfc_device *pnd) static int pn53x_ISO14443A_MFC_is_present(struct nfc_device *pnd) { int ret; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping MFC"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping MFC"); if ((CHIP_DATA(pnd)->type == PN533) && (CHIP_DATA(pnd)->current_target->nti.nai.btSak != 0x09)) { // MFC Mini (atqa0004/sak09) fails on PN533, so we exclude it ret = pn53x_Diagnose06(pnd); @@ -2142,7 +2145,7 @@ static int pn53x_ISO14443A_MFC_is_present(struct nfc_device *pnd) static int pn53x_DEP_is_present(struct nfc_device *pnd) { int ret; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping DEP"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping DEP"); if ((CHIP_DATA(pnd)->type == PN531) || (CHIP_DATA(pnd)->type == PN532) || (CHIP_DATA(pnd)->type == PN533)) ret = pn53x_Diagnose06(pnd); else @@ -2152,7 +2155,7 @@ static int pn53x_DEP_is_present(struct nfc_device *pnd) static int pn53x_Felica_is_present(struct nfc_device *pnd) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping Felica"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping Felica"); // if (CHIP_DATA(pnd)->type == PN533) { ret = pn53x_Diagnose06(pnd); } else... // Because ping fails now & then, better not to use Diagnose at all // Limitation: does not work on Felica Lite cards (neither Diagnose nor our method) @@ -2173,7 +2176,7 @@ static int pn53x_Felica_is_present(struct nfc_device *pnd) static int pn53x_ISO14443B_4_is_present(struct nfc_device *pnd) { int ret; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping -4B"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping -4B"); if (CHIP_DATA(pnd)->type == PN533) { // Not supported on PN532 even if the doc is same as for PN533 ret = pn53x_Diagnose06(pnd); } else { @@ -2206,7 +2209,7 @@ static int pn53x_ISO14443B_4_is_present(struct nfc_device *pnd) static int pn53x_ISO14443B_I_is_present(struct nfc_device *pnd) { int ret; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B'"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping B'"); // Sending ATTRIB in raw: if ((ret = pn53x_set_property_bool(pnd, NP_EASY_FRAMING, false)) < 0) return ret; @@ -2235,7 +2238,7 @@ static int pn53x_ISO14443B_I_is_present(struct nfc_device *pnd) static int pn53x_ISO14443B_SR_is_present(struct nfc_device *pnd) { int ret; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B2 ST SRx"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping B2 ST SRx"); // Sending Get_UID in raw: (EASY_FRAMING is already supposed to be false) uint8_t abtCmd[1] = {0x0b}; int failures = 0; @@ -2258,7 +2261,7 @@ static int pn53x_ISO14443B_SR_is_present(struct nfc_device *pnd) static int pn53x_ISO14443B_ICLASS_is_present(struct nfc_device *pnd) { int timeout = 300; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B iClass"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping B iClass"); pn53x_initiator_init_iclass_modulation(pnd); // // Some work to do before getting the UID... @@ -2281,7 +2284,7 @@ static int pn53x_ISO14443B_ICLASS_is_present(struct nfc_device *pnd) static int pn53x_ISO14443B_CT_is_present(struct nfc_device *pnd) { int ret; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): Ping B2 ASK CTx"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): Ping B2 ASK CTx"); // Sending SELECT in raw: (EASY_FRAMING is already supposed to be false) uint8_t abtCmd[3] = {0x9f}; memcpy(abtCmd + 1, CHIP_DATA(pnd)->current_target->nti.nci.abtUID, 2); @@ -2307,13 +2310,13 @@ pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt) { // Check if there is a saved target if (CHIP_DATA(pnd)->current_target == NULL) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): no saved target"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): no saved target"); return pnd->last_error = NFC_EINVARG; } // Check if the argument target nt is equals to current saved target if ((pnt != NULL) && (!pn53x_current_target_is(pnd, pnt))) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): another target"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): another target"); return pnd->last_error = NFC_ETGRELEASED; } @@ -2330,7 +2333,7 @@ pn53x_initiator_target_is_present(struct nfc_device *pnd, const nfc_target *pnt) } else if (CHIP_DATA(pnd)->current_target->nti.nai.btSak & 0x08) { ret = pn53x_ISO14443A_MFC_is_present(pnd); } else { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "target_is_present(): card type A not supported"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "target_is_present(): card type A not supported"); ret = NFC_EDEVNOTSUPP; } break; @@ -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) { @@ -3310,12 +3311,12 @@ pn53x_check_ack_frame(struct nfc_device *pnd, const uint8_t *pbtRxFrame, const s { if (szRxFrameLen >= sizeof(pn53x_ack_frame)) { if (0 == memcmp(pbtRxFrame, pn53x_ack_frame, sizeof(pn53x_ack_frame))) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "PN53x ACKed"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "PN53x ACKed"); return NFC_SUCCESS; } } pnd->last_error = NFC_EIO; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unexpected PN53x reply!"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unexpected PN53x reply!"); return pnd->last_error; } @@ -3324,7 +3325,7 @@ pn53x_check_error_frame(struct nfc_device *pnd, const uint8_t *pbtRxFrame, const { if (szRxFrameLen >= sizeof(pn53x_error_frame)) { if (0 == memcmp(pbtRxFrame, pn53x_error_frame, sizeof(pn53x_error_frame))) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "PN53x sent an error frame"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "PN53x sent an error frame"); pnd->last_error = NFC_EIO; return pnd->last_error; } diff --git a/libnfc/conf.c b/libnfc/conf.c index 785c310e..43ff6ebf 100644 --- a/libnfc/conf.c +++ b/libnfc/conf.c @@ -220,7 +220,7 @@ conf_keyvalue_context(void *data, const char *key, const char *value) } else if (strcmp(key, "device.name") == 0) { if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].name, "") != 0) { if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Configuration exceeded maximum user-defined devices."); return; } context->user_defined_device_count++; @@ -230,7 +230,7 @@ conf_keyvalue_context(void *data, const char *key, const char *value) } else if (strcmp(key, "device.connstring") == 0) { if ((context->user_defined_device_count == 0) || strcmp(context->user_defined_devices[context->user_defined_device_count - 1].connstring, "") != 0) { if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Configuration exceeded maximum user-defined devices."); return; } context->user_defined_device_count++; @@ -240,7 +240,7 @@ conf_keyvalue_context(void *data, const char *key, const char *value) } else if (strcmp(key, "device.optional") == 0) { if ((context->user_defined_device_count == 0) || context->user_defined_devices[context->user_defined_device_count - 1].optional) { if (context->user_defined_device_count >= MAX_USER_DEFINED_DEVICES) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Configuration exceeded maximum user-defined devices."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Configuration exceeded maximum user-defined devices."); return; } context->user_defined_device_count++; diff --git a/libnfc/drivers/acr122_pcsc.c b/libnfc/drivers/acr122_pcsc.c index f5cc02e2..b16f5817 100644 --- a/libnfc/drivers/acr122_pcsc.c +++ b/libnfc/drivers/acr122_pcsc.c @@ -276,11 +276,11 @@ acr122_pcsc_open(const nfc_context *context, const nfc_connstring connstring) if (!(pscc = acr122_pcsc_get_scardcontext())) goto error; // Test if we were able to connect to the "emulator" card - if (SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_EXCLUSIVE, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &(DRIVER_DATA(pnd)->hCard), (void *) & (DRIVER_DATA(pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) { + if (SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_EXCLUSIVE, SCARD_PROTOCOL_T0 | SCARD_PROTOCOL_T1, &(DRIVER_DATA(pnd)->hCard), &(DRIVER_DATA(pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) { // Connect to ACR122 firmware version >2.0 - if (SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_DIRECT, 0, &(DRIVER_DATA(pnd)->hCard), (void *) & (DRIVER_DATA(pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) { + if (SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_DIRECT, 0, &(DRIVER_DATA(pnd)->hCard), &(DRIVER_DATA(pnd)->ioCard.dwProtocol)) != SCARD_S_SUCCESS) { // We can not connect to this device. - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "PCSC connect failed"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "PCSC connect failed"); goto error; } } diff --git a/libnfc/drivers/acr122_usb.c b/libnfc/drivers/acr122_usb.c index fc545014..aaa86a03 100644 --- a/libnfc/drivers/acr122_usb.c +++ b/libnfc/drivers/acr122_usb.c @@ -625,14 +625,14 @@ acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, co } } if (res < 10) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Invalid RDR_to_PC_DataBlock frame"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Invalid RDR_to_PC_DataBlock frame"); // try to interrupt current device state acr122_usb_ack(pnd); pnd->last_error = NFC_EIO; return pnd->last_error; } if (abtRxBuf[offset] != attempted_response) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame header mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame header mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -645,22 +645,22 @@ acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, co // Do not check status; my ACR122U seemingly has status=0 in this case, // even though the spec says it should have had bmCommandStatus=1 // and bmICCStatus=1. - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Command timed out"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Command timed out"); pnd->last_error = NFC_ETIMEOUT; return pnd->last_error; } if (!((len > 1) && (abtRxBuf[10] == 0xd5))) { // In case we didn't get an immediate answer: if (len != 2) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Wrong reply"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Wrong reply"); pnd->last_error = NFC_EIO; return pnd->last_error; } if (abtRxBuf[10] != SW1_More_Data_Available) { if ((abtRxBuf[10] == SW1_Warning_with_NV_changed) && (abtRxBuf[11] == PN53x_Specific_Application_Level_Error_Code)) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "PN532 has detected an error at the application level"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "PN532 has detected an error at the application level"); } else if ((abtRxBuf[10] == SW1_Warning_with_NV_changed) && (abtRxBuf[11] == 0x00)) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "PN532 didn't reply"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "PN532 didn't reply"); } else { log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unexpected Status Word (SW1: %02x SW2: %02x)", abtRxBuf[10], abtRxBuf[11]); } @@ -687,7 +687,7 @@ acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, co } offset = 0; if (abtRxBuf[offset] != attempted_response) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame header mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame header mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -696,14 +696,14 @@ acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, co // XXX In CCID specification, len is a 32-bits (dword), do we need to decode more than 1 byte ? (0-255 bytes for PN532 reply) 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; + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Not implemented: only 1-byte length is supported, please report this bug with a full trace."); + pnd->last_error = NFC_ENOTIMPL; return pnd->last_error; } offset += 3; if (len < 4) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Too small reply"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Too small reply"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -722,14 +722,14 @@ acr122_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, co // TFI + PD0 (CC+1) if (abtRxBuf[offset] != 0xD5) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "TFI Mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "TFI Mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } offset += 1; if (abtRxBuf[offset] != CHIP_DATA(pnd)->last_command + 1) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Command Code verification failed"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Command Code verification failed"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -746,7 +746,7 @@ acr122_usb_ack(nfc_device *pnd) (void) pnd; int res = 0; uint8_t acr122_ack_frame[] = { GetFirmwareVersion }; // We can't send a PN532's ACK frame, so we use a normal command to cancel current command - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "ACR122 Abort"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "ACR122 Abort"); if ((res = acr122_build_frame_from_tama(pnd, acr122_ack_frame, sizeof(acr122_ack_frame))) < 0) return res; if ((res = acr122_usb_bulk_write(DRIVER_DATA(pnd), (unsigned char *) & (DRIVER_DATA(pnd)->tama_frame), res, 1000)) < 0) @@ -792,7 +792,7 @@ acr122_usb_init(nfc_device *pnd) 0x00, 0x00, 0x00, 0x00, // Blinking duration control }; - log_put (LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "ACR122 Get LED state"); + log_put (LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "ACR122 Get LED state"); if ((res = acr122_usb_bulk_write (DRIVER_DATA (pnd), (uint8_t *) acr122u_get_led_state_frame, sizeof (acr122u_get_led_state_frame), 1000)) < 0) return res; @@ -813,14 +813,14 @@ acr122_usb_init(nfc_device *pnd) if ((res = acr122_usb_bulk_read(DRIVER_DATA(pnd), abtRxBuf, sizeof(abtRxBuf), 1000)) < 0) return res; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "ACR122 PICC Operating Parameters"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "ACR122 PICC Operating Parameters"); if ((res = acr122_usb_send_apdu(pnd, 0x00, 0x51, 0x00, NULL, 0, 0, abtRxBuf, sizeof(abtRxBuf))) < 0) return res; res = 0; for (i = 0; i < 3; i++) { if (res < 0) - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "PN532 init failed, trying again..."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "PN532 init failed, trying again..."); if ((res = pn53x_init(pnd)) >= 0) break; } diff --git a/libnfc/drivers/acr122s.c b/libnfc/drivers/acr122s.c index 7a6a9f45..df65a954 100644 --- a/libnfc/drivers/acr122s.c +++ b/libnfc/drivers/acr122s.c @@ -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 @@ -261,7 +261,7 @@ acr122s_recv_frame(nfc_device *pnd, uint8_t *frame, size_t frame_size, void *abo struct xfr_block_res *res = (struct xfr_block_res *) &frame[1]; if ((uint8_t)(res->seq + 1) != DRIVER_DATA(pnd)->seq) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Invalid response sequence number."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Invalid response sequence number."); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -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) @@ -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++])) { @@ -437,7 +437,7 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz uart_close(sp); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -451,7 +451,7 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz nfc_device_free(pnd); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -465,7 +465,7 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz nfc_device_free(pnd); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -480,7 +480,7 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz nfc_device_free(pnd); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -512,7 +512,7 @@ acr122s_scan(const nfc_context *context, nfc_connstring connstrings[], const siz } iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return device_found; @@ -621,11 +621,10 @@ 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) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Cannot get reader firmware."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Cannot get reader firmware."); acr122s_close(pnd); return NULL; } @@ -637,18 +636,17 @@ 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."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "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."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Failed initializing PN532 chip."); acr122s_close(pnd); return NULL; } @@ -668,7 +666,7 @@ acr122s_send(nfc_device *pnd, const uint8_t *buf, const size_t buf_len, int time int ret; if ((ret = acr122s_send_frame(pnd, cmd, timeout)) != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to transmit data. (TX)"); pnd->last_error = ret; return pnd->last_error; } @@ -696,7 +694,7 @@ acr122s_receive(nfc_device *pnd, uint8_t *buf, size_t buf_len, int timeout) } if (pnd->last_error < 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); return -1; } diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index acaab465..9f033299 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -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++])) { @@ -123,7 +123,7 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size uart_close(sp); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -137,7 +137,7 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size nfc_device_free(pnd); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -151,7 +151,7 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size nfc_device_free(pnd); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -165,7 +165,7 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size nfc_device_free(pnd); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -193,7 +193,7 @@ arygon_scan(const nfc_context *context, nfc_connstring connstrings[], const size } iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return device_found; @@ -357,14 +357,14 @@ arygon_tama_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i } if ((res = uart_send(DRIVER_DATA(pnd)->port, abtFrame, szFrame + 1, timeout)) != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to transmit data. (TX)"); pnd->last_error = res; return pnd->last_error; } uint8_t abtRxBuf[PN53x_ACK_FRAME__LEN]; if ((res = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, sizeof(abtRxBuf), 0, timeout)) != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to read ACK"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to read ACK"); pnd->last_error = res; return pnd->last_error; } @@ -372,7 +372,7 @@ arygon_tama_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, i if (pn53x_check_ack_frame(pnd, abtRxBuf, sizeof(abtRxBuf)) == 0) { // The PN53x is running the sent command } else if (0 == memcmp(arygon_error_unknown_mode, abtRxBuf, sizeof(abtRxBuf))) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Bad frame format."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Bad frame format."); // We have already read 6 bytes and arygon_error_unknown_mode is 10 bytes long // so we have to read 4 remaining bytes to be synchronized at the next receiving pass. pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 4, 0, timeout); @@ -405,7 +405,7 @@ arygon_tama_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i #ifndef WIN32 abort_p = &(DRIVER_DATA(pnd)->iAbortFds[1]); #else - abort_p = (void *) & (DRIVER_DATA(pnd)->abort_flag); + abort_p = &(DRIVER_DATA(pnd)->abort_flag); #endif pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p, timeout); @@ -419,13 +419,13 @@ arygon_tama_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i } if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); return pnd->last_error; } const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff }; if (0 != (memcmp(abtRxBuf, pn53x_preamble, 3))) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame preamble+start code mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -433,7 +433,7 @@ arygon_tama_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i if ((0x01 == abtRxBuf[3]) && (0xff == abtRxBuf[4])) { // Error frame uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0, timeout); - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Application level error detected"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Application level error detected"); pnd->last_error = NFC_EIO; return pnd->last_error; } else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) { @@ -444,7 +444,7 @@ arygon_tama_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i // Normal frame if (256 != (abtRxBuf[3] + abtRxBuf[4])) { // TODO: Retry - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Length checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Length checksum mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -462,18 +462,18 @@ arygon_tama_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i // TFI + PD0 (CC+1) pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0, timeout); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); return pnd->last_error; } if (abtRxBuf[0] != 0xD5) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "TFI Mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "TFI Mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } if (abtRxBuf[1] != CHIP_DATA(pnd)->last_command + 1) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Command Code verification failed"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Command Code verification failed"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -481,14 +481,14 @@ arygon_tama_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i if (len) { pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, pbtData, len, 0, timeout); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); return pnd->last_error; } } pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0, timeout); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); return pnd->last_error; } @@ -499,13 +499,13 @@ arygon_tama_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, i } if (btDCS != abtRxBuf[0]) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Data checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Data checksum mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } if (0x00 != abtRxBuf[1]) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame postamble mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame postamble mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -523,12 +523,12 @@ arygon_firmware(nfc_device *pnd, char *str) int res = uart_send(DRIVER_DATA(pnd)->port, arygon_firmware_version_cmd, sizeof(arygon_firmware_version_cmd), 0); if (res != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Unable to send ARYGON firmware command."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to send ARYGON firmware command."); return; } res = uart_receive(DRIVER_DATA(pnd)->port, abtRx, szRx, 0, 0); if (res != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Unable to retrieve ARYGON firmware version."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to retrieve ARYGON firmware version."); return; } @@ -557,7 +557,7 @@ arygon_reset_tama(nfc_device *pnd) // or arygon_error_unknown_mode (ie. in case of the first byte was bad-transmitted) res = uart_receive(DRIVER_DATA(pnd)->port, abtRx, szRx, 0, 1000); if (res != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "No reply to 'reset TAMA' command."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "No reply to 'reset TAMA' command."); pnd->last_error = res; return pnd->last_error; } diff --git a/libnfc/drivers/pcsc.c b/libnfc/drivers/pcsc.c index 106d99ac..84a5a658 100644 --- a/libnfc/drivers/pcsc.c +++ b/libnfc/drivers/pcsc.c @@ -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 #endif #include #endif -#ifdef WIN32 -#include -#define usleep(x) Sleep((x + 999) / 1000) -#endif - #define PCSC_DRIVER_NAME "pcsc" #include @@ -85,6 +80,8 @@ #define LOG_GROUP NFC_LOG_GROUP_DRIVER #define LOG_CATEGORY "libnfc.driver.pcsc" +#define SAK_ISO14443_4_COMPLIANT 0x20 + static const char *supported_devices[] = { "ACS ACR122", // ACR122U & Touchatag, last version "ACS ACR 38U-CCID", // Touchatag, early version @@ -159,7 +156,7 @@ static int pcsc_transmit(struct nfc_device *pnd, const uint8_t *tx, const size_t data->last_error = SCardTransmit(data->hCard, &data->ioCard, tx, tx_len, NULL, rx, &dw_rx_len); if (data->last_error != SCARD_S_SUCCESS) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "PCSC transmit failed"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "PCSC transmit failed"); return NFC_EIO; } *rx_len = dw_rx_len; @@ -370,8 +367,7 @@ static int pcsc_props_to_target(struct nfc_device *pnd, uint8_t it, const uint8_ memcpy(pnt->nti.nai.abtAts, ats, ats_len); pnt->nti.nai.szAtsLen = ats_len; } else { - /* SAK_ISO14443_4_COMPLIANT */ - pnt->nti.nai.btSak = 0x20; + pnt->nti.nai.btSak = SAK_ISO14443_4_COMPLIANT; /* Choose TL, TA, TB, TC according to Mifare DESFire */ memcpy(pnt->nti.nai.abtAts, "\x75\x77\x81\x02", 4); /* copy historical bytes */ @@ -538,10 +534,10 @@ pcsc_open(const nfc_context *context, const nfc_connstring connstring) // Test if context succeeded if (!(pscc = pcsc_get_scardcontext())) goto error; - DRIVER_DATA(pnd)->last_error = SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_DIRECT, 0 | 1, &(DRIVER_DATA(pnd)->hCard), (void *) & (DRIVER_DATA(pnd)->ioCard.dwProtocol)); + DRIVER_DATA(pnd)->last_error = SCardConnect(*pscc, ndd.pcsc_device_name, SCARD_SHARE_DIRECT, 0 | 1, &(DRIVER_DATA(pnd)->hCard), &(DRIVER_DATA(pnd)->ioCard.dwProtocol)); if (DRIVER_DATA(pnd)->last_error != SCARD_S_SUCCESS) { // We can not connect to this device. - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "PCSC connect failed"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "PCSC connect failed"); goto error; } // Configure I/O settings for card communication @@ -549,7 +545,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; @@ -713,14 +709,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 */ @@ -826,7 +822,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; diff --git a/libnfc/drivers/pn532_i2c.c b/libnfc/drivers/pn532_i2c.c index a3c0cf46..35d8d215 100644 --- a/libnfc/drivers/pn532_i2c.c +++ b/libnfc/drivers/pn532_i2c.c @@ -194,7 +194,7 @@ pn532_i2c_scan(const nfc_context *context, nfc_connstring connstrings[], const s i2c_close(id); iDevice = 0; while ((i2cPort = i2cPorts[iDevice++])) { - free((void *)i2cPort); + free(i2cPort); } free(i2cPorts); return 0; @@ -207,7 +207,7 @@ pn532_i2c_scan(const nfc_context *context, nfc_connstring connstrings[], const s nfc_device_free(pnd); iDevice = 0; while ((i2cPort = i2cPorts[iDevice++])) { - free((void *)i2cPort); + free(i2cPort); } free(i2cPorts); return 0; @@ -221,7 +221,7 @@ pn532_i2c_scan(const nfc_context *context, nfc_connstring connstrings[], const s nfc_device_free(pnd); iDevice = 0; while ((i2cPort = i2cPorts[iDevice++])) { - free((void *)i2cPort); + free(i2cPort); } free(i2cPorts); return 0; @@ -253,7 +253,7 @@ pn532_i2c_scan(const nfc_context *context, nfc_connstring connstrings[], const s } iDevice = 0; while ((i2cPort = i2cPorts[iDevice++])) { - free((void *)i2cPort); + free(i2cPort); } free(i2cPorts); return device_found; @@ -420,7 +420,7 @@ pn532_i2c_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int } if (res < 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to transmit data. (TX)"); pnd->last_error = res; return pnd->last_error; } @@ -550,7 +550,7 @@ pn532_i2c_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int } if (0 != (memcmp(frameBuf, pn53x_preamble_and_start, PN53X_PREAMBLE_AND_START_LEN))) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame preamble+start code mismatch"); pnd->last_error = NFC_EIO; goto error; } @@ -578,7 +578,7 @@ pn532_i2c_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int // Verify length checksum if ((uint8_t)(frameBuf[3] + frameBuf[4])) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Length checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Length checksum mismatch"); pnd->last_error = NFC_EIO; goto error; } @@ -593,7 +593,7 @@ pn532_i2c_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int uint8_t TFI = frameBuf[TFI_idx]; if (TFI != 0xD5) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "TFI Mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "TFI Mismatch"); pnd->last_error = NFC_EIO; goto error; } diff --git a/libnfc/drivers/pn532_spi.c b/libnfc/drivers/pn532_spi.c index 39a8b51a..983aef0e 100644 --- a/libnfc/drivers/pn532_spi.c +++ b/libnfc/drivers/pn532_spi.c @@ -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 -# include -# 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 -# define msleep Sleep -#endif - // Internal data structs const struct pn53x_io pn532_spi_io; struct pn532_spi_data { @@ -113,7 +97,7 @@ pn532_spi_scan(const nfc_context *context, nfc_connstring connstrings[], const s spi_close(sp); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -126,7 +110,7 @@ pn532_spi_scan(const nfc_context *context, nfc_connstring connstrings[], const s nfc_device_free(pnd); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -140,7 +124,7 @@ pn532_spi_scan(const nfc_context *context, nfc_connstring connstrings[], const s nfc_device_free(pnd); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -171,7 +155,7 @@ pn532_spi_scan(const nfc_context *context, nfc_connstring connstrings[], const s } iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return device_found; @@ -292,7 +276,7 @@ pn532_spi_read_spi_status(nfc_device *pnd) if (res != NFC_SUCCESS) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Unable to read SPI status"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to read SPI status"); return res; } @@ -324,7 +308,7 @@ pn532_spi_wakeup(nfc_device *pnd) msleep(1); if (spi_byte == 0xff) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Wakeup is needed"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Wakeup is needed"); spi_set_speed(DRIVER_DATA(pnd)->port, 5000); // set slow speed res = pn532_SAMConfiguration(pnd, PSM_NORMAL, 1000); // wakeup by sending SAMConfiguration, which works just fine @@ -429,7 +413,7 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int } if (pnd->last_error != NFC_SUCCESS) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to wait for SPI data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to wait for SPI data. (RX)"); goto error; } @@ -451,7 +435,7 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int // need one more byte pnd->last_error = pn532_spi_receive_next_chunk(pnd, abtRxBuf + 3, 1); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive one more byte for long preamble frame. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive one more byte for long preamble frame. (RX)"); goto error; } } @@ -459,7 +443,7 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int const uint8_t pn53x_preamble[2] = { 0x00, 0xff }; if (0 != (memcmp(abtRxBuf, pn53x_preamble, 2))) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", " preamble+start code mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, " preamble+start code mismatch"); pnd->last_error = NFC_EIO; goto error; } @@ -468,7 +452,7 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int // Error frame pn532_spi_receive_next_chunk(pnd, abtRxBuf, 3); - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Application level error detected"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Application level error detected"); pnd->last_error = NFC_EIO; goto error; } else if ((0xff == abtRxBuf[2]) && (0xff == abtRxBuf[3])) { @@ -476,13 +460,13 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int pnd->last_error = pn532_spi_receive_next_chunk(pnd, abtRxBuf, 3); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); goto error; } // (abtRxBuf[0] << 8) + abtRxBuf[1] (LEN) include TFI + (CC+1) len = (abtRxBuf[0] << 8) + abtRxBuf[1] - 2; if (((abtRxBuf[0] + abtRxBuf[1] + abtRxBuf[2]) % 256) != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Length checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Length checksum mismatch"); pnd->last_error = NFC_EIO; goto error; } @@ -490,7 +474,7 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int // Normal frame if (256 != (abtRxBuf[2] + abtRxBuf[3])) { // TODO: Retry - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Length checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Length checksum mismatch"); pnd->last_error = NFC_EIO; goto error; } @@ -510,18 +494,18 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int pnd->last_error = pn532_spi_receive_next_chunk(pnd, abtRxBuf, 2); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); goto error; } if (abtRxBuf[0] != 0xD5) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "TFI Mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "TFI Mismatch"); pnd->last_error = NFC_EIO; goto error; } if (abtRxBuf[1] != CHIP_DATA(pnd)->last_command + 1) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Command Code verification failed"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Command Code verification failed"); pnd->last_error = NFC_EIO; goto error; } @@ -530,7 +514,7 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int pnd->last_error = pn532_spi_receive_next_chunk(pnd, pbtData, len); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); goto error; } } @@ -538,7 +522,7 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int pnd->last_error = pn532_spi_receive_next_chunk(pnd, abtRxBuf, 2); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); goto error; } @@ -549,13 +533,13 @@ pn532_spi_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, int } if (btDCS != abtRxBuf[0]) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Data checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Data checksum mismatch"); pnd->last_error = NFC_EIO; goto error; } if (0x00 != abtRxBuf[1]) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame postamble mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame postamble mismatch"); pnd->last_error = NFC_EIO; goto error; } @@ -603,14 +587,14 @@ pn532_spi_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int res = spi_send(DRIVER_DATA(pnd)->port, abtFrame, szFrame, true); if (res != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to transmit data. (TX)"); pnd->last_error = res; return pnd->last_error; } res = pn532_spi_wait_for_data(pnd, timeout); if (res != NFC_SUCCESS) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to wait for SPI data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to wait for SPI data. (RX)"); pnd->last_error = res; return pnd->last_error; } @@ -621,7 +605,7 @@ pn532_spi_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, int res = spi_send_receive(DRIVER_DATA(pnd)->port, &pn532_spi_cmd_dataread, 1, abtRxBuf, sizeof(abtRxBuf), true); if (res != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Unable to read ACK"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to read ACK"); pnd->last_error = res; return pnd->last_error; } diff --git a/libnfc/drivers/pn532_uart.c b/libnfc/drivers/pn532_uart.c index d82051d7..1a935286 100644 --- a/libnfc/drivers/pn532_uart.c +++ b/libnfc/drivers/pn532_uart.c @@ -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++])) { @@ -98,7 +98,7 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const uart_close(sp); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -111,7 +111,7 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const nfc_device_free(pnd); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -125,7 +125,7 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const nfc_device_free(pnd); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -143,7 +143,7 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const nfc_device_free(pnd); iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return 0; @@ -171,7 +171,7 @@ pn532_uart_scan(const nfc_context *context, nfc_connstring connstrings[], const } iDevice = 0; while ((acPort = acPorts[iDevice++])) { - free((void *)acPort); + free(acPort); } free(acPorts); return device_found; @@ -350,7 +350,7 @@ pn532_uart_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, in res = uart_send(DRIVER_DATA(pnd)->port, abtFrame, szFrame, timeout); if (res != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to transmit data. (TX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to transmit data. (TX)"); pnd->last_error = res; return pnd->last_error; } @@ -358,7 +358,7 @@ pn532_uart_send(nfc_device *pnd, const uint8_t *pbtData, const size_t szData, in uint8_t abtRxBuf[PN53x_ACK_FRAME__LEN]; res = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, sizeof(abtRxBuf), 0, timeout); if (res != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "Unable to read ACK"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "Unable to read ACK"); pnd->last_error = res; return pnd->last_error; } @@ -381,7 +381,7 @@ pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, in #ifndef WIN32 abort_p = &(DRIVER_DATA(pnd)->iAbortFds[1]); #else - abort_p = (void *) & (DRIVER_DATA(pnd)->abort_flag); + abort_p = &(DRIVER_DATA(pnd)->abort_flag); #endif pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 5, abort_p, timeout); @@ -397,7 +397,7 @@ pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, in const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff }; if (0 != (memcmp(abtRxBuf, pn53x_preamble, 3))) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame preamble+start code mismatch"); pnd->last_error = NFC_EIO; goto error; } @@ -405,20 +405,20 @@ pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, in if ((0x01 == abtRxBuf[3]) && (0xff == abtRxBuf[4])) { // Error frame uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0, timeout); - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Application level error detected"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Application level error detected"); pnd->last_error = NFC_EIO; goto error; } else if ((0xff == abtRxBuf[3]) && (0xff == abtRxBuf[4])) { // Extended frame pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 3, 0, timeout); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); goto error; } // (abtRxBuf[0] << 8) + abtRxBuf[1] (LEN) include TFI + (CC+1) len = (abtRxBuf[0] << 8) + abtRxBuf[1] - 2; if (((abtRxBuf[0] + abtRxBuf[1] + abtRxBuf[2]) % 256) != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Length checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Length checksum mismatch"); pnd->last_error = NFC_EIO; goto error; } @@ -426,7 +426,7 @@ pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, in // Normal frame if (256 != (abtRxBuf[3] + abtRxBuf[4])) { // TODO: Retry - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Length checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Length checksum mismatch"); pnd->last_error = NFC_EIO; goto error; } @@ -444,18 +444,18 @@ pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, in // TFI + PD0 (CC+1) pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0, timeout); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); goto error; } if (abtRxBuf[0] != 0xD5) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "TFI Mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "TFI Mismatch"); pnd->last_error = NFC_EIO; goto error; } if (abtRxBuf[1] != CHIP_DATA(pnd)->last_command + 1) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Command Code verification failed"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Command Code verification failed"); pnd->last_error = NFC_EIO; goto error; } @@ -463,14 +463,14 @@ pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, in if (len) { pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, pbtData, len, 0, timeout); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); goto error; } } pnd->last_error = uart_receive(DRIVER_DATA(pnd)->port, abtRxBuf, 2, 0, timeout); if (pnd->last_error != 0) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Unable to receive data. (RX)"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to receive data. (RX)"); goto error; } @@ -481,13 +481,13 @@ pn532_uart_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, in } if (btDCS != abtRxBuf[0]) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Data checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Data checksum mismatch"); pnd->last_error = NFC_EIO; goto error; } if (0x00 != abtRxBuf[1]) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame postamble mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame postamble mismatch"); pnd->last_error = NFC_EIO; goto error; } diff --git a/libnfc/drivers/pn53x_usb.c b/libnfc/drivers/pn53x_usb.c index 52c40f08..7b3a87c5 100644 --- a/libnfc/drivers/pn53x_usb.c +++ b/libnfc/drivers/pn53x_usb.c @@ -196,7 +196,7 @@ static void pn533_fix_usbdesc(nfc_device *pnd) uint8_t abtCmdRR[] = { ReadRegister, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; uint8_t nRRreg = ((sizeof(abtCmdRR) - 1) / 2); uint8_t abtRxRR[1 + nRRreg]; - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "%s", "Checking USB descriptors corruption in XRAM"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Checking USB descriptors corruption in XRAM"); for (uint8_t i = 0x19, j = 0; i < 0x19 + szXramUsbDesc;) { for (uint8_t k = 0; k < nRRreg; k++) { abtCmdRR[(2 * k) + 2] = i++; @@ -213,7 +213,7 @@ static void pn533_fix_usbdesc(nfc_device *pnd) } #endif // Abuse the overflow bug to restore USB descriptors in one go - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "%s", "Fixing USB descriptors corruption"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_INFO, "Fixing USB descriptors corruption"); uint8_t abtCmdWR[19 + MAXSZXRAMUSBDESC] = { GetFirmwareVersion }; for (uint8_t i = 0; i < szXramUsbDesc; i++) { abtCmdWR[i + 19] = btXramUsbDesc[i]; @@ -257,7 +257,11 @@ pn53x_usb_get_end_points_default(struct usb_device *dev, struct pn53x_usb_data * return false; } -int pn53x_usb_ack(nfc_device *pnd); +int +pn53x_usb_ack(nfc_device *pnd) +{ + return pn53x_usb_bulk_write(DRIVER_DATA(pnd), (uint8_t *) pn53x_ack_frame, sizeof(pn53x_ack_frame), 1000); +} // Find transfer endpoints for bulk transfers static void @@ -655,7 +659,7 @@ pn53x_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, con const uint8_t pn53x_preamble[3] = { 0x00, 0x00, 0xff }; if (0 != (memcmp(abtRxBuf, pn53x_preamble, 3))) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame preamble+start code mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame preamble+start code mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -663,7 +667,7 @@ pn53x_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, con if ((0x01 == abtRxBuf[offset]) && (0xff == abtRxBuf[offset + 1])) { // Error frame - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Application level error detected"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Application level error detected"); pnd->last_error = NFC_EIO; return pnd->last_error; } else if ((0xff == abtRxBuf[offset]) && (0xff == abtRxBuf[offset + 1])) { @@ -674,7 +678,7 @@ pn53x_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, con len = (abtRxBuf[offset] << 8) + abtRxBuf[offset + 1] - 2; if (((abtRxBuf[offset] + abtRxBuf[offset + 1] + abtRxBuf[offset + 2]) % 256) != 0) { // TODO: Retry - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Length checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Length checksum mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -683,7 +687,7 @@ pn53x_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, con // Normal frame if (256 != (abtRxBuf[offset] + abtRxBuf[offset + 1])) { // TODO: Retry - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Length checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Length checksum mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -701,14 +705,14 @@ pn53x_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, con // TFI + PD0 (CC+1) if (abtRxBuf[offset] != 0xD5) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "TFI Mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "TFI Mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } offset += 1; if (abtRxBuf[offset] != CHIP_DATA(pnd)->last_command + 1) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Command Code verification failed"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Command Code verification failed"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -724,14 +728,14 @@ pn53x_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, con } if (btDCS != abtRxBuf[offset]) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Data checksum mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Data checksum mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } offset += 1; if (0x00 != abtRxBuf[offset]) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "%s", "Frame postamble mismatch"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Frame postamble mismatch"); pnd->last_error = NFC_EIO; return pnd->last_error; } @@ -741,12 +745,6 @@ pn53x_usb_receive(nfc_device *pnd, uint8_t *pbtData, const size_t szDataLen, con return len; } -int -pn53x_usb_ack(nfc_device *pnd) -{ - return pn53x_usb_bulk_write(DRIVER_DATA(pnd), (uint8_t *) pn53x_ack_frame, sizeof(pn53x_ack_frame), 1000); -} - int pn53x_usb_init(nfc_device *pnd) { @@ -758,7 +756,7 @@ pn53x_usb_init(nfc_device *pnd) // ...and we don't care about error pnd->last_error = 0; if (SONY_RCS360 == DRIVER_DATA(pnd)->model) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "SONY RC-S360 initialization."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "SONY RC-S360 initialization."); const uint8_t abtCmd2[] = { 0x18, 0x01 }; pn53x_transceive(pnd, abtCmd2, sizeof(abtCmd2), NULL, 0, -1); pn53x_usb_ack(pnd); @@ -768,7 +766,7 @@ pn53x_usb_init(nfc_device *pnd) return res; if (ASK_LOGO == DRIVER_DATA(pnd)->model) { - log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "%s", "ASK LoGO initialization."); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_DEBUG, "ASK LoGO initialization."); /* Internal registers */ /* Disable 100mA current limit, Power on Secure IC (SVDD) */ pn53x_write_register(pnd, PN53X_REG_Control_switch_rng, 0xFF, SYMBOL_CURLIMOFF | SYMBOL_SIC_SWITCH_EN | SYMBOL_RANDOM_DATAREADY); diff --git a/libnfc/nfc-internal.h b/libnfc/nfc-internal.h index 74c05c21..6f140731 100644 --- a/libnfc/nfc-internal.h +++ b/libnfc/nfc-internal.h @@ -33,13 +33,8 @@ #define __NFC_INTERNAL_H__ #include -#include -#if !defined(_MSC_VER) -# include -#endif #include "nfc/nfc.h" - #include "log.h" /** @@ -63,6 +58,22 @@ #define MAX(a,b) (((a) > (b)) ? (a) : (b)) #endif +#ifndef _WIN32 +// Needed by sleep() under Unix +# include +# include +# 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 +# define msleep Sleep +#endif + /* * Buffer management macros. * diff --git a/libnfc/nfc.c b/libnfc/nfc.c index dc625d04..82eb324a 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -371,7 +371,7 @@ nfc_list_devices(nfc_context *context, nfc_connstring connstrings[], const size_ // do it silently if (env_log_level) { 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()"); + log_put(LOG_GROUP, LOG_CATEGORY, NFC_LOG_PRIORITY_ERROR, "Unable to malloc()"); return 0; } strcpy(old_env_log_level, env_log_level); diff --git a/utils/nfc-list.c b/utils/nfc-list.c index bb6aaef9..ebc53bc3 100644 --- a/utils/nfc-list.c +++ b/utils/nfc-list.c @@ -44,7 +44,6 @@ # include "config.h" #endif // HAVE_CONFIG_H -#include #include #include #include diff --git a/utils/nfc-mfclassic.c b/utils/nfc-mfclassic.c index 244af45c..0e9c2f6a 100644 --- a/utils/nfc-mfclassic.c +++ b/utils/nfc-mfclassic.c @@ -50,7 +50,6 @@ #include #include #include - #include #include diff --git a/utils/nfc-read-forum-tag3.c b/utils/nfc-read-forum-tag3.c index 52c6c2f8..890cecd1 100644 --- a/utils/nfc-read-forum-tag3.c +++ b/utils/nfc-read-forum-tag3.c @@ -62,10 +62,6 @@ #include "nfc-utils.h" -#if defined(WIN32) /* mingw compiler */ -#include -#endif - static nfc_device *pnd; static nfc_context *context; diff --git a/utils/nfc-relay-picc.c b/utils/nfc-relay-picc.c index d694f8a6..9199edfe 100644 --- a/utils/nfc-relay-picc.c +++ b/utils/nfc-relay-picc.c @@ -55,7 +55,6 @@ #include #include #include - #include #include @@ -199,11 +198,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); diff --git a/utils/nfc-scan-device.c b/utils/nfc-scan-device.c index bdc100de..24482eed 100644 --- a/utils/nfc-scan-device.c +++ b/utils/nfc-scan-device.c @@ -43,7 +43,6 @@ # include "config.h" #endif // HAVE_CONFIG_H -#include #include #include #include diff --git a/utils/nfc-utils.c b/utils/nfc-utils.c index 72a33eda..c9e94ac8 100644 --- a/utils/nfc-utils.c +++ b/utils/nfc-utils.c @@ -38,7 +38,6 @@ * @brief Provide some examples shared functions like print, parity calculation, options parsing. */ #include -#include #include "nfc-utils.h"