From 3e8e1c8844852ded18d2381f01f48aae8d1c0823 Mon Sep 17 00:00:00 2001 From: Romain Tartiere Date: Fri, 16 Apr 2010 20:39:56 +0000 Subject: [PATCH] Fix build on Windows (using cmake and nmake). --- CMakeLists.txt | 4 ++++ examples/nfc-list.c | 3 ++- libnfc/drivers/acr122.c | 2 +- libnfc/drivers/arygon.c | 5 +++-- libnfc/nfc.c | 17 ++++++++++------- win32/err.h | 12 ++++++++++++ 6 files changed, 32 insertions(+), 11 deletions(-) create mode 100644 win32/err.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 0daee7f..b698019 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,6 +17,10 @@ ENDIF(NOT MSVC) CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include) +IF(MSVC) + INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/win32 ${CMAKE_CURRENT_SOURCE_DIR}/win32/stdint) +ENDIF(MSVC) + # make it easy to locate CMake modules for finding libraries SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/") diff --git a/examples/nfc-list.c b/examples/nfc-list.c index b641bfb..0bc4eaa 100644 --- a/examples/nfc-list.c +++ b/examples/nfc-list.c @@ -55,13 +55,14 @@ int main(int argc, const char* argv[]) size_t i; nfc_target_info_t nti; nfc_device_desc_t *pnddDevices; + const char* acLibnfcVersion; if (argc > 1) { errx (1, "usage: %s", argv[0]); } // Display libnfc version - const char* acLibnfcVersion = nfc_version(); + acLibnfcVersion = nfc_version(); printf("%s use libnfc %s\n", argv[0], acLibnfcVersion); #ifdef HAVE_LIBUSB diff --git a/libnfc/drivers/acr122.c b/libnfc/drivers/acr122.c index c2ad6db..670dc50 100644 --- a/libnfc/drivers/acr122.c +++ b/libnfc/drivers/acr122.c @@ -350,11 +350,11 @@ char* acr122_firmware(const nfc_device_spec_t nds) bool acr122_led_red(const nfc_device_spec_t nds, bool bOn) { - (void)bOn; byte_t abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 }; acr122_spec_t* pas = (acr122_spec_t*)nds; byte_t abtBuf[2]; size_t szBufLen = sizeof(abtBuf); + (void)bOn; if (pas->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED) { return (SCardControl(pas->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtLed,sizeof(abtLed),abtBuf,szBufLen,(void*)&szBufLen) == SCARD_S_SUCCESS); diff --git a/libnfc/drivers/arygon.c b/libnfc/drivers/arygon.c index c323bad..f777834 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -218,6 +218,9 @@ bool arygon_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const s size_t szRxBufLen = BUFFER_LENGTH; size_t szPos; + const byte_t pn53x_ack_frame[] = { 0x00,0x00,0xff,0x00,0xff,0x00 }; + const byte_t pn53x_nack_frame[] = { 0x00,0x00,0xff,0xff,0x00,0x00 }; + // Packet length = data length (len) + checksum (1) + end of stream marker (1) abtTxBuf[4] = szTxLen; // Packet length checksum @@ -254,8 +257,6 @@ bool arygon_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const s print_hex(abtRxBuf,szRxBufLen); #endif - const byte_t pn53x_ack_frame[] = { 0x00,0x00,0xff,0x00,0xff,0x00 }; - const byte_t pn53x_nack_frame[] = { 0x00,0x00,0xff,0xff,0x00,0x00 }; if(szRxBufLen >= sizeof(pn53x_ack_frame)) { // Check if PN53x reply ACK diff --git a/libnfc/nfc.c b/libnfc/nfc.c index debb4ab..ed04105 100644 --- a/libnfc/nfc.c +++ b/libnfc/nfc.c @@ -590,14 +590,17 @@ nfc_initiator_poll_targets(const nfc_device_t* pnd, const byte_t btPollNr, const byte_t btPeriod, nfc_target_t* pntTargets, size_t* pszTargetFound) { + size_t szTxInAutoPoll, n, szRxLen; + byte_t abtRx[256]; + bool res; + byte_t *pbtTxInAutoPoll; if(pnd->nc == NC_PN531) { // errno = ENOSUPP return false; } // byte_t abtInAutoPoll[] = { 0xd4, 0x60, 0x0f, 0x01, 0x00 }; - size_t szTxInAutoPoll = 4 + szTargetTypes; - size_t n; - byte_t *pbtTxInAutoPoll = malloc( szTxInAutoPoll ); + szTxInAutoPoll = 4 + szTargetTypes; + pbtTxInAutoPoll = malloc( szTxInAutoPoll ); pbtTxInAutoPoll[0] = 0xd4; pbtTxInAutoPoll[1] = 0x60; pbtTxInAutoPoll[2] = btPollNr; @@ -606,9 +609,8 @@ nfc_initiator_poll_targets(const nfc_device_t* pnd, pbtTxInAutoPoll[4+n] = pnttTargetTypes[n]; } - size_t szRxLen = 256; - byte_t abtRx[256]; - bool res = pnd->pdc->transceive(pnd->nds, pbtTxInAutoPoll, szTxInAutoPoll, abtRx, &szRxLen); + szRxLen = 256; + res = pnd->pdc->transceive(pnd->nds, pbtTxInAutoPoll, szTxInAutoPoll, abtRx, &szRxLen); if((szRxLen == 0)||(res == false)) { DBG("pnd->pdc->tranceive() failed: szRxLen=%d, res=%d", szRxLen, res); @@ -616,12 +618,13 @@ nfc_initiator_poll_targets(const nfc_device_t* pnd, } else { *pszTargetFound = abtRx[0]; if( *pszTargetFound ) { + uint8_t ln; byte_t* pbt = abtRx + 1; /* 1st target */ // Target type pntTargets[0].ntt = *(pbt++); // AutoPollTargetData length - uint8_t ln = *(pbt++); + ln = *(pbt++); pn53x_decode_target_data(pbt, ln, pnd->nc, pntTargets[0].ntt, &(pntTargets[0].nti)); pbt += ln; diff --git a/win32/err.h b/win32/err.h new file mode 100644 index 0000000..545d9e6 --- /dev/null +++ b/win32/err.h @@ -0,0 +1,12 @@ +#ifndef _ERR_H_ +#define _ERR_H_ + +#include + +#define warnx(...) fprintf (stderr, __VA_ARGS__) +#define errx(code, ...) do { \ + fprintf (stderr, __VA_ARGS__); \ + exit (code); \ +} while (0) + +#endif /* !_ERR_H_ */