(libnfc-less-bitutils-more-ponies) Fix build on windows:
- do not depends on byte swapping functions / macros; - add basic err.h functionalities.
This commit is contained in:
commit
086e24c407
9 changed files with 39 additions and 26 deletions
|
@ -17,6 +17,10 @@ ENDIF(NOT MSVC)
|
||||||
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/config.h.cmake ${CMAKE_CURRENT_SOURCE_DIR}/config.h)
|
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)
|
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
|
# make it easy to locate CMake modules for finding libraries
|
||||||
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/")
|
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake_modules/")
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,6 @@
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include <sys/endian.h>
|
|
||||||
|
|
||||||
#include <nfc/nfc.h>
|
#include <nfc/nfc.h>
|
||||||
|
|
||||||
#include <nfc/nfc-messages.h>
|
#include <nfc/nfc-messages.h>
|
||||||
|
@ -200,12 +198,10 @@ int main(int argc,char* argv[])
|
||||||
transmit_bytes(abtHalt,4);
|
transmit_bytes(abtHalt,4);
|
||||||
|
|
||||||
printf("\nFound tag with UID: ");
|
printf("\nFound tag with UID: ");
|
||||||
if (szUidLen == 4)
|
if (szUidLen == 7) {
|
||||||
{
|
printf("%02x%02x%02x", abtUid[6], abtUid[5], abtUid[4]);
|
||||||
printf("%08x\n", bswap32( *((uint32_t *)&abtUid)));
|
|
||||||
} else {
|
|
||||||
printf("%014llx\n",bswap64(*((uint64_t *) &abtUid))&0x00ffffffffffffffull);
|
|
||||||
}
|
}
|
||||||
|
printf("%02x%02x%02x%02x\n", abtUid[3], abtUid[2], abtUid[1], abtUid[0]);
|
||||||
|
|
||||||
nfc_disconnect(pnd);
|
nfc_disconnect(pnd);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -54,13 +54,14 @@ int main(int argc, const char* argv[])
|
||||||
size_t i;
|
size_t i;
|
||||||
nfc_target_info_t nti;
|
nfc_target_info_t nti;
|
||||||
nfc_device_desc_t *pnddDevices;
|
nfc_device_desc_t *pnddDevices;
|
||||||
|
const char* acLibnfcVersion;
|
||||||
|
|
||||||
if (argc > 1) {
|
if (argc > 1) {
|
||||||
errx (1, "usage: %s", argv[0]);
|
errx (1, "usage: %s", argv[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display libnfc version
|
// Display libnfc version
|
||||||
const char* acLibnfcVersion = nfc_version();
|
acLibnfcVersion = nfc_version();
|
||||||
printf("%s use libnfc %s\n", argv[0], acLibnfcVersion);
|
printf("%s use libnfc %s\n", argv[0], acLibnfcVersion);
|
||||||
|
|
||||||
#ifdef HAVE_LIBUSB
|
#ifdef HAVE_LIBUSB
|
||||||
|
|
|
@ -35,8 +35,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <sys/endian.h>
|
|
||||||
|
|
||||||
#include <nfc/nfc.h>
|
#include <nfc/nfc.h>
|
||||||
|
|
||||||
#include "mifaretag.h"
|
#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
|
// Compare if key dump UID is the same as the current tag UID
|
||||||
if (memcmp(nti.nai.abtUid,pbtUID,4) != 0)
|
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
|
// Get the info from the current tag
|
||||||
pbtUID = nti.nai.abtUid;
|
pbtUID = nti.nai.abtUid;
|
||||||
b4K = (nti.nai.abtAtqa[1] == 0x02);
|
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;
|
uiBlocks = (b4K)?0xff:0x3f;
|
||||||
|
|
||||||
|
|
|
@ -35,8 +35,6 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
|
||||||
#include <sys/endian.h>
|
|
||||||
|
|
||||||
#include <nfc/nfc.h>
|
#include <nfc/nfc.h>
|
||||||
|
|
||||||
#include "mifareultag.h"
|
#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;
|
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)
|
if (bReadAction)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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)
|
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 };
|
byte_t abtLed[9] = { 0xFF,0x00,0x40,0x05,0x04,0x00,0x00,0x00,0x00 };
|
||||||
acr122_spec_t* pas = (acr122_spec_t*)nds;
|
acr122_spec_t* pas = (acr122_spec_t*)nds;
|
||||||
byte_t abtBuf[2];
|
byte_t abtBuf[2];
|
||||||
size_t szBufLen = sizeof(abtBuf);
|
size_t szBufLen = sizeof(abtBuf);
|
||||||
|
(void)bOn;
|
||||||
if (pas->ioCard.dwProtocol == SCARD_PROTOCOL_UNDEFINED)
|
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);
|
return (SCardControl(pas->hCard,IOCTL_CCID_ESCAPE_SCARD_CTL_CODE,abtLed,sizeof(abtLed),abtBuf,szBufLen,(void*)&szBufLen) == SCARD_S_SUCCESS);
|
||||||
|
|
|
@ -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 szRxBufLen = BUFFER_LENGTH;
|
||||||
size_t szPos;
|
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)
|
// Packet length = data length (len) + checksum (1) + end of stream marker (1)
|
||||||
abtTxBuf[4] = szTxLen;
|
abtTxBuf[4] = szTxLen;
|
||||||
// Packet length checksum
|
// 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);
|
PRINT_HEX("RX", abtRxBuf,szRxBufLen);
|
||||||
#endif
|
#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)) {
|
if(szRxBufLen >= sizeof(pn53x_ack_frame)) {
|
||||||
|
|
||||||
// Check if PN53x reply ACK
|
// Check if PN53x reply ACK
|
||||||
|
|
17
libnfc/nfc.c
17
libnfc/nfc.c
|
@ -590,14 +590,17 @@ nfc_initiator_poll_targets(const nfc_device_t* pnd,
|
||||||
const byte_t btPollNr, const byte_t btPeriod,
|
const byte_t btPollNr, const byte_t btPeriod,
|
||||||
nfc_target_t* pntTargets, size_t* pszTargetFound)
|
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) {
|
if(pnd->nc == NC_PN531) {
|
||||||
// errno = ENOSUPP
|
// errno = ENOSUPP
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// byte_t abtInAutoPoll[] = { 0xd4, 0x60, 0x0f, 0x01, 0x00 };
|
// byte_t abtInAutoPoll[] = { 0xd4, 0x60, 0x0f, 0x01, 0x00 };
|
||||||
size_t szTxInAutoPoll = 4 + szTargetTypes;
|
szTxInAutoPoll = 4 + szTargetTypes;
|
||||||
size_t n;
|
pbtTxInAutoPoll = malloc( szTxInAutoPoll );
|
||||||
byte_t *pbtTxInAutoPoll = malloc( szTxInAutoPoll );
|
|
||||||
pbtTxInAutoPoll[0] = 0xd4;
|
pbtTxInAutoPoll[0] = 0xd4;
|
||||||
pbtTxInAutoPoll[1] = 0x60;
|
pbtTxInAutoPoll[1] = 0x60;
|
||||||
pbtTxInAutoPoll[2] = btPollNr;
|
pbtTxInAutoPoll[2] = btPollNr;
|
||||||
|
@ -606,9 +609,8 @@ nfc_initiator_poll_targets(const nfc_device_t* pnd,
|
||||||
pbtTxInAutoPoll[4+n] = pnttTargetTypes[n];
|
pbtTxInAutoPoll[4+n] = pnttTargetTypes[n];
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t szRxLen = 256;
|
szRxLen = 256;
|
||||||
byte_t abtRx[256];
|
res = pnd->pdc->transceive(pnd->nds, pbtTxInAutoPoll, szTxInAutoPoll, abtRx, &szRxLen);
|
||||||
bool res = pnd->pdc->transceive(pnd->nds, pbtTxInAutoPoll, szTxInAutoPoll, abtRx, &szRxLen);
|
|
||||||
|
|
||||||
if((szRxLen == 0)||(res == false)) {
|
if((szRxLen == 0)||(res == false)) {
|
||||||
DBG("pnd->pdc->tranceive() failed: szRxLen=%d, res=%d", szRxLen, res);
|
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 {
|
} else {
|
||||||
*pszTargetFound = abtRx[0];
|
*pszTargetFound = abtRx[0];
|
||||||
if( *pszTargetFound ) {
|
if( *pszTargetFound ) {
|
||||||
|
uint8_t ln;
|
||||||
byte_t* pbt = abtRx + 1;
|
byte_t* pbt = abtRx + 1;
|
||||||
/* 1st target */
|
/* 1st target */
|
||||||
// Target type
|
// Target type
|
||||||
pntTargets[0].ntt = *(pbt++);
|
pntTargets[0].ntt = *(pbt++);
|
||||||
// AutoPollTargetData length
|
// AutoPollTargetData length
|
||||||
uint8_t ln = *(pbt++);
|
ln = *(pbt++);
|
||||||
pn53x_decode_target_data(pbt, ln, pnd->nc, pntTargets[0].ntt, &(pntTargets[0].nti));
|
pn53x_decode_target_data(pbt, ln, pnd->nc, pntTargets[0].ntt, &(pntTargets[0].nti));
|
||||||
pbt += ln;
|
pbt += ln;
|
||||||
|
|
||||||
|
|
12
win32/err.h
Normal file
12
win32/err.h
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
#ifndef _ERR_H_
|
||||||
|
#define _ERR_H_
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
#define warnx(...) fprintf (stderr, __VA_ARGS__)
|
||||||
|
#define errx(code, ...) do { \
|
||||||
|
fprintf (stderr, __VA_ARGS__); \
|
||||||
|
exit (code); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#endif /* !_ERR_H_ */
|
Loading…
Reference in a new issue