diff --git a/CMakeLists.txt b/CMakeLists.txt index 56a8f54..564218b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -88,6 +88,16 @@ IF(NOT WIN32) INSTALL(FILES ${CMAKE_CURRENT_BINARY_DIR}/libnfc.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) ENDIF(NOT WIN32) +IF(PCSC_INCLUDE_DIRS) + INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS}) + LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS}) +ENDIF(PCSC_INCLUDE_DIRS) + +IF(LIBUSB_INCLUDE_DIRS) + INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIRS}) + LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS}) +ENDIF(LIBUSB_INCLUDE_DIRS) + ADD_SUBDIRECTORY(libnfc) ADD_SUBDIRECTORY(include) ADD_SUBDIRECTORY(utils) diff --git a/examples/CMakeLists.txt b/examples/CMakeLists.txt index 6e8863f..f4571d1 100644 --- a/examples/CMakeLists.txt +++ b/examples/CMakeLists.txt @@ -1,10 +1,7 @@ -SET(EXAMPLES-SOURCES nfc-anticol nfc-dep-initiator nfc-dep-target nfc-emulate-tag nfc-emulate-uid nfc-poll nfc-relay pn53x-diagnose pn53x-sam pn53x-tamashell) +SET(EXAMPLES-SOURCES nfc-anticol nfc-dep-initiator nfc-dep-target nfc-emulate-tag nfc-emulate-uid nfc-poll nfc-relay) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libnfc) -INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIRS} ${PCSC_INCLUDE_DIRS}) -LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS} ${PCSC_LIBRARY_DIRS}) - # Examples FOREACH(source ${EXAMPLES-SOURCES}) ADD_EXECUTABLE(${source} ${source}.c) diff --git a/libnfc/CMakeLists.txt b/libnfc/CMakeLists.txt index 090130d..7ade8ca 100644 --- a/libnfc/CMakeLists.txt +++ b/libnfc/CMakeLists.txt @@ -14,14 +14,29 @@ ENDIF(LIBNFC_SERIAL_AUTOPROBE_ENABLED) INCLUDE(LibnfcDrivers) -INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIRS} ${PCSC_INCLUDE_DIRS}) -LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS} ${PCSC_LIBRARY_DIRS}) +IF(PCSC_INCLUDE_DIRS) + INCLUDE_DIRECTORIES(${PCSC_INCLUDE_DIRS}) + LINK_DIRECTORIES(${PCSC_LIBRARY_DIRS}) +ENDIF(PCSC_INCLUDE_DIRS) + +IF(LIBUSB_INCLUDE_DIRS) + INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIRS}) + LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS}) +ENDIF(LIBUSB_INCLUDE_DIRS) # Library SET(LIBRARY_SOURCES nfc nfc-device nfc-emulation iso14443-subr mirror-subr ${DRIVERS_SOURCES} ${BUSES_SOURCES} ${CHIPS_SOURCES}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) ADD_LIBRARY(nfc SHARED ${LIBRARY_SOURCES}) -TARGET_LINK_LIBRARIES(nfc ${LIBUSB_LIBRARIES} ${PCSC_LIBRARIES}) + +IF(PCSC_INCLUDE_DIRS) + TARGET_LINK_LIBRARIES(nfc ${PCSC_LIBRARIES}) +ENDIF(PCSC_INCLUDE_DIRS) + +IF(LIBUSB_INCLUDE_DIRS) + TARGET_LINK_LIBRARIES(nfc ${LIBUSB_LIBRARIES}) +ENDIF(LIBUSB_INCLUDE_DIRS) + IF(WIN32) TARGET_LINK_LIBRARIES(nfc wsock32) ENDIF(WIN32) diff --git a/libnfc/buses/uart_win32.c b/libnfc/buses/uart_win32.c index 7ce2250..29977c6 100644 --- a/libnfc/buses/uart_win32.c +++ b/libnfc/buses/uart_win32.c @@ -147,23 +147,25 @@ uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, BOOL res; // XXX Put this part into uart_win32_timeouts () ? + DWORD timeout_ms = timeout ? ((timeout->tv_sec * 1000) + (timeout->tv_usec / 1000)) : 0; COMMTIMEOUTS timeouts; timeouts.ReadIntervalTimeout = 0; timeouts.ReadTotalTimeoutMultiplier = 0; - timeouts.ReadTotalTimeoutConstant = timeout ? ((timeout->tv_sec * 1000) + (timeout->tv_usec / 1000)) : 0; + timeouts.ReadTotalTimeoutConstant = timeout_ms; timeouts.WriteTotalTimeoutMultiplier = 0; - timeouts.WriteTotalTimeoutConstant = timeout ? ((timeout->tv_sec * 1000) + (timeout->tv_usec / 1000)) : 0; + timeouts.WriteTotalTimeoutConstant = timeout_ms; if (!SetCommTimeouts (((serial_port_windows *) sp)->hPort, &timeouts)) { log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "Unable to apply new timeout settings."); return ECOMIO; } + log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "Timeouts are set to %u ms", timeout_ms); // TODO Enhance the reception method // - According to MSDN, it could be better to implement nfc_abort_command() mecanism using Cancello() - // - ECOMTIMEOUT should be return is case of timeout (as of uart_posix implementation) volatile bool * abort_flag_p = (volatile bool *)abort_p; do { + log_put (LOG_CATEGORY, NFC_PRIORITY_TRACE, "ReadFile"); res = ReadFile (((serial_port_windows *) sp)->hPort, pbtRx + dwTotalBytesReceived, dwBytesToGet, &dwBytesReceived, NULL); @@ -174,7 +176,10 @@ uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, DWORD err = GetLastError(); log_put (LOG_CATEGORY, NFC_PRIORITY_ERROR, "ReadFile error: %u", err); return ECOMIO; - } + } else if (dwBytesReceived == 0) { + return ECOMTIMEOUT; + } + if (((DWORD)szRx) > dwTotalBytesReceived) { dwBytesToGet -= dwBytesReceived; } @@ -183,6 +188,7 @@ uart_receive (serial_port sp, byte_t * pbtRx, const size_t szRx, void * abort_p, return EOPABORT; } } while (((DWORD)szRx) > dwTotalBytesReceived); + LOG_HEX ("RX", pbtRx, szRx); return (dwTotalBytesReceived == (DWORD) szRx) ? 0 : ECOMIO; } @@ -204,6 +210,7 @@ uart_send (serial_port sp, const byte_t * pbtTx, const size_t szTx, struct timev return ECOMIO; } + LOG_HEX ("TX", pbtTx, szTx); if (!WriteFile (((serial_port_windows *) sp)->hPort, pbtTx, szTx, &dwTxLen, NULL)) { return ECOMIO; } diff --git a/utils/CMakeLists.txt b/utils/CMakeLists.txt index 5107cd6..c96d2e7 100644 --- a/utils/CMakeLists.txt +++ b/utils/CMakeLists.txt @@ -1,11 +1,5 @@ SET(UTILS-SOURCES nfc-emulate-forum-tag2 nfc-emulate-forum-tag4 nfc-list nfc-relay-picc nfc-mfclassic nfc-mfultralight) -# XXX: Examples should not use private API! -#INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../libnfc) - -INCLUDE_DIRECTORIES(${LIBUSB_INCLUDE_DIRS} ${PCSC_INCLUDE_DIRS}) -LINK_DIRECTORIES(${LIBUSB_LIBRARY_DIRS} ${PCSC_LIBRARY_DIRS}) - ADD_LIBRARY(nfcutils STATIC nfc-utils.c )