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-anticol.c b/examples/nfc-anticol.c index a646e71..9b1857f 100644 --- a/examples/nfc-anticol.c +++ b/examples/nfc-anticol.c @@ -33,8 +33,6 @@ #include #include -#include - #include #include @@ -200,12 +198,10 @@ int main(int argc,char* argv[]) transmit_bytes(abtHalt,4); printf("\nFound tag with UID: "); - if (szUidLen == 4) - { - printf("%08x\n", bswap32( *((uint32_t *)&abtUid))); - } else { - printf("%014llx\n",bswap64(*((uint64_t *) &abtUid))&0x00ffffffffffffffull); + if (szUidLen == 7) { + printf("%02x%02x%02x", abtUid[6], abtUid[5], abtUid[4]); } + printf("%02x%02x%02x%02x\n", abtUid[3], abtUid[2], abtUid[1], abtUid[0]); nfc_disconnect(pnd); return 0; diff --git a/examples/nfc-list.c b/examples/nfc-list.c index 6aae21a..9a39277 100644 --- a/examples/nfc-list.c +++ b/examples/nfc-list.c @@ -54,13 +54,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/examples/nfc-mfclassic.c b/examples/nfc-mfclassic.c index 49c249d..4ecd107 100644 --- a/examples/nfc-mfclassic.c +++ b/examples/nfc-mfclassic.c @@ -35,8 +35,6 @@ #include #include -#include - #include #include "mifaretag.h" @@ -466,14 +464,14 @@ int main(int argc, const char* argv[]) // Compare if key dump UID is the same as the current tag UID if (memcmp(nti.nai.abtUid,pbtUID,4) != 0) { - printf("Expected MIFARE Classic %cK card with UID: %08x\n",b4K?'4':'1',bswap32(*((uint32_t *)&pbtUID))); + printf("Expected MIFARE Classic %cK card with UID: %02x%02x%02x%02x\n",b4K?'4':'1', pbtUID[3], pbtUID[2], pbtUID[1], pbtUID[0]); } } // Get the info from the current tag pbtUID = nti.nai.abtUid; b4K = (nti.nai.abtAtqa[1] == 0x02); - printf("Found MIFARE Classic %cK card with UID: %08x\n",b4K?'4':'1',bswap32(*((uint32_t *)&pbtUID))); + printf("Found MIFARE Classic %cK card with UID: %02x%02x%02x%02x\n",b4K?'4':'1', pbtUID[3], pbtUID[2], pbtUID[1], pbtUID[0]); uiBlocks = (b4K)?0xff:0x3f; diff --git a/examples/nfc-mfultralight.c b/examples/nfc-mfultralight.c index c70c65e..88452c4 100644 --- a/examples/nfc-mfultralight.c +++ b/examples/nfc-mfultralight.c @@ -35,8 +35,6 @@ #include #include -#include - #include #include "mifareultag.h" @@ -217,9 +215,9 @@ int main(int argc, const char* argv[]) } - // Get the info from the current tag + // Get the info from the current tag (UID is stored little-endian) pbtUID = nti.nai.abtUid; - printf("Found MIFARE Ultralight card with uid: %08x\n", bswap32(*((uint32_t *)&pbtUID))); + printf("Found MIFARE Ultralight card with uid: %02x%02x%02x%02x\n", pbtUID[3], pbtUID[2], pbtUID[1], pbtUID[0]); if (bReadAction) { diff --git a/libnfc/drivers/acr122.c b/libnfc/drivers/acr122.c index f4539be..dba6e64 100644 --- a/libnfc/drivers/acr122.c +++ b/libnfc/drivers/acr122.c @@ -347,11 +347,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 12e6d5a..733de56 100644 --- a/libnfc/drivers/arygon.c +++ b/libnfc/drivers/arygon.c @@ -217,6 +217,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 @@ -251,8 +254,6 @@ bool arygon_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, const s PRINT_HEX("RX", 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_ */