Fix build on Microsoft Windows.
Windows users: I hate you in secret.
This commit is contained in:
parent
d7c16d6d1a
commit
fd0efd4a62
9 changed files with 52 additions and 30 deletions
|
@ -56,12 +56,13 @@ int main(int argc, const char* argv[])
|
||||||
size_t szTargetFound;
|
size_t szTargetFound;
|
||||||
size_t i;
|
size_t i;
|
||||||
nfc_target_info_t nti;
|
nfc_target_info_t nti;
|
||||||
|
nfc_device_desc_t *pnddDevices;
|
||||||
|
|
||||||
// Display libnfc version
|
// Display libnfc version
|
||||||
acLibnfcVersion = nfc_version();
|
acLibnfcVersion = nfc_version();
|
||||||
printf("%s use libnfc %s\n", argv[0], acLibnfcVersion);
|
printf("%s use libnfc %s\n", argv[0], acLibnfcVersion);
|
||||||
|
|
||||||
nfc_device_desc_t *pnddDevices = parse_device_desc(argc, argv, &szDeviceFound);
|
pnddDevices = parse_device_desc(argc, argv, &szDeviceFound);
|
||||||
|
|
||||||
if (argc > 1 && szDeviceFound == 0) {
|
if (argc > 1 && szDeviceFound == 0) {
|
||||||
errx (1, "usage: %s [--device driver:port:speed]", argv[0]);
|
errx (1, "usage: %s [--device driver:port:speed]", argv[0]);
|
||||||
|
@ -106,6 +107,7 @@ int main(int argc, const char* argv[])
|
||||||
|
|
||||||
for (i = 0; i < szDeviceFound; i++)
|
for (i = 0; i < szDeviceFound; i++)
|
||||||
{
|
{
|
||||||
|
nfc_target_info_t anti[MAX_TARGET_COUNT];
|
||||||
pnd = nfc_connect(&(pnddDevices[i]));
|
pnd = nfc_connect(&(pnddDevices[i]));
|
||||||
|
|
||||||
|
|
||||||
|
@ -131,10 +133,10 @@ int main(int argc, const char* argv[])
|
||||||
|
|
||||||
printf("Connected to NFC reader: %s\n",pnd->acName);
|
printf("Connected to NFC reader: %s\n",pnd->acName);
|
||||||
|
|
||||||
nfc_target_info_t anti[MAX_TARGET_COUNT];
|
|
||||||
if (nfc_initiator_list_passive_targets(pnd, NM_ISO14443A_106, anti, MAX_TARGET_COUNT, &szTargetFound )) {
|
if (nfc_initiator_list_passive_targets(pnd, NM_ISO14443A_106, anti, MAX_TARGET_COUNT, &szTargetFound )) {
|
||||||
|
size_t n;
|
||||||
printf("%zu ISO14443A passive targets was found:\n", szTargetFound);
|
printf("%zu ISO14443A passive targets was found:\n", szTargetFound);
|
||||||
for(size_t n=0; n<szTargetFound; n++) {
|
for(n=0; n<szTargetFound; n++) {
|
||||||
print_nfc_iso14443a_info (anti[n].nai);
|
print_nfc_iso14443a_info (anti[n].nai);
|
||||||
printf("\n");
|
printf("\n");
|
||||||
}
|
}
|
||||||
|
|
|
@ -94,9 +94,11 @@ write_card (void)
|
||||||
uint32_t uiWritenPages = 0;
|
uint32_t uiWritenPages = 0;
|
||||||
|
|
||||||
char buffer[BUFSIZ];
|
char buffer[BUFSIZ];
|
||||||
|
bool write_otp;
|
||||||
|
|
||||||
printf ("Write OTP bytes ? [yN] ");
|
printf ("Write OTP bytes ? [yN] ");
|
||||||
fgets (buffer, BUFSIZ, stdin);
|
fgets (buffer, BUFSIZ, stdin);
|
||||||
bool write_otp = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
write_otp = ((buffer[0] == 'y') || (buffer[0] == 'Y'));
|
||||||
|
|
||||||
/* We need to skip 3 first pages. */
|
/* We need to skip 3 first pages. */
|
||||||
printf ("Writing %d pages |", uiBlocks + 1);
|
printf ("Writing %d pages |", uiBlocks + 1);
|
||||||
|
|
|
@ -69,8 +69,17 @@ main (int argc, const char *argv[])
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < szFound; i++) {
|
for (i = 0; i < szFound; i++) {
|
||||||
pnd = nfc_connect (&(pnddDevices[i]));
|
|
||||||
|
|
||||||
|
const byte_t btPollNr = 20;
|
||||||
|
const byte_t btPeriod = 2;
|
||||||
|
const nfc_target_type_t nttMifare = NTT_MIFARE;
|
||||||
|
const size_t szTargetTypes = 1;
|
||||||
|
|
||||||
|
nfc_target_t antTargets[2];
|
||||||
|
size_t szTargetFound;
|
||||||
|
bool res;
|
||||||
|
|
||||||
|
pnd = nfc_connect (&(pnddDevices[i]));
|
||||||
|
|
||||||
if (pnd == NULL) {
|
if (pnd == NULL) {
|
||||||
ERR ("%s", "Unable to connect to NFC device.");
|
ERR ("%s", "Unable to connect to NFC device.");
|
||||||
|
@ -99,24 +108,17 @@ main (int argc, const char *argv[])
|
||||||
|
|
||||||
// bool (*transceive)(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
// bool (*transceive)(const nfc_device_spec_t nds, const byte_t* pbtTx, const size_t szTxLen, byte_t* pbtRx, size_t* pszRxLen);
|
||||||
|
|
||||||
const byte_t btPollNr = 20;
|
|
||||||
const byte_t btPeriod = 2;
|
|
||||||
const nfc_target_type_t nttMifare = NTT_MIFARE;
|
|
||||||
const size_t szTargetTypes = 1;
|
|
||||||
|
|
||||||
nfc_target_t antTargets[2];
|
|
||||||
size_t szTargetFound;
|
|
||||||
|
|
||||||
if (pnd->nc == NC_PN531) {
|
if (pnd->nc == NC_PN531) {
|
||||||
// PN531 doesn't support hardware polling (InAutoPoll)
|
// PN531 doesn't support hardware polling (InAutoPoll)
|
||||||
WARN ("%s", "PN531 doesn't support hardware polling.");
|
WARN ("%s", "PN531 doesn't support hardware polling.");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
printf ("PN53x will poll during %ld ms\n", (unsigned long) btPollNr * szTargetTypes * btPeriod * 150);
|
printf ("PN53x will poll during %ld ms\n", (unsigned long) btPollNr * szTargetTypes * btPeriod * 150);
|
||||||
bool res = nfc_initiator_poll_targets (pnd, &nttMifare, 1, btPollNr, btPeriod, antTargets, &szTargetFound);
|
res = nfc_initiator_poll_targets (pnd, &nttMifare, 1, btPollNr, btPeriod, antTargets, &szTargetFound);
|
||||||
if (res) {
|
if (res) {
|
||||||
|
uint8_t n;
|
||||||
printf ("%ld target(s) have been found.\n", (unsigned long) szTargetFound);
|
printf ("%ld target(s) have been found.\n", (unsigned long) szTargetFound);
|
||||||
for (uint8_t n = 0; n < szTargetFound; n++) {
|
for (n = 0; n < szTargetFound; n++) {
|
||||||
printf ("T%d: targetType=%02x, ", n + 1, antTargets[n].ntt);
|
printf ("T%d: targetType=%02x, ", n + 1, antTargets[n].ntt);
|
||||||
printf ("targetData:\n");
|
printf ("targetData:\n");
|
||||||
print_nfc_iso14443a_info (antTargets[n].nti.nai);
|
print_nfc_iso14443a_info (antTargets[n].nti.nai);
|
||||||
|
|
|
@ -102,8 +102,8 @@ void print_nfc_iso14443a_info(const nfc_iso14443a_info_t nai)
|
||||||
nfc_device_desc_t* parse_device_desc(int argc, const char *argv[], size_t* szFound)
|
nfc_device_desc_t* parse_device_desc(int argc, const char *argv[], size_t* szFound)
|
||||||
{
|
{
|
||||||
nfc_device_desc_t* pndd = 0;
|
nfc_device_desc_t* pndd = 0;
|
||||||
*szFound = 0;
|
|
||||||
int arg;
|
int arg;
|
||||||
|
*szFound = 0;
|
||||||
|
|
||||||
// Get commandline options
|
// Get commandline options
|
||||||
for (arg=1;arg<argc;arg++) {
|
for (arg=1;arg<argc;arg++) {
|
||||||
|
@ -111,10 +111,10 @@ nfc_device_desc_t* parse_device_desc(int argc, const char *argv[], size_t* szFou
|
||||||
if (0 == strcmp(argv[arg], "--device")) {
|
if (0 == strcmp(argv[arg], "--device")) {
|
||||||
|
|
||||||
if (argc > arg+1) {
|
if (argc > arg+1) {
|
||||||
|
char buffer[256];
|
||||||
|
|
||||||
pndd = malloc(sizeof(nfc_device_desc_t));
|
pndd = malloc(sizeof(nfc_device_desc_t));
|
||||||
|
|
||||||
char buffer[256];
|
|
||||||
strncpy(buffer, argv[++arg], 256);
|
strncpy(buffer, argv[++arg], 256);
|
||||||
|
|
||||||
// Driver.
|
// Driver.
|
||||||
|
|
|
@ -295,6 +295,7 @@ pn53x_InListPassiveTarget(const nfc_device_t* pnd,
|
||||||
const byte_t* pbtInitiatorData, const size_t szInitiatorDataLen,
|
const byte_t* pbtInitiatorData, const size_t szInitiatorDataLen,
|
||||||
byte_t* pbtTargetsData, size_t* pszTargetsData)
|
byte_t* pbtTargetsData, size_t* pszTargetsData)
|
||||||
{
|
{
|
||||||
|
size_t szRxLen;
|
||||||
byte_t abtCmd[sizeof(pncmd_initiator_list_passive)];
|
byte_t abtCmd[sizeof(pncmd_initiator_list_passive)];
|
||||||
memcpy(abtCmd,pncmd_initiator_list_passive,sizeof(pncmd_initiator_list_passive));
|
memcpy(abtCmd,pncmd_initiator_list_passive,sizeof(pncmd_initiator_list_passive));
|
||||||
|
|
||||||
|
@ -306,7 +307,7 @@ pn53x_InListPassiveTarget(const nfc_device_t* pnd,
|
||||||
if (pbtInitiatorData) memcpy(abtCmd+4,pbtInitiatorData,szInitiatorDataLen);
|
if (pbtInitiatorData) memcpy(abtCmd+4,pbtInitiatorData,szInitiatorDataLen);
|
||||||
|
|
||||||
// Try to find a tag, call the tranceive callback function of the current device
|
// Try to find a tag, call the tranceive callback function of the current device
|
||||||
size_t szRxLen = MAX_FRAME_LEN;
|
szRxLen = MAX_FRAME_LEN;
|
||||||
// We can not use pn53x_transceive() because abtRx[0] gives no status info
|
// We can not use pn53x_transceive() because abtRx[0] gives no status info
|
||||||
if(pnd->pdc->transceive(pnd->nds,abtCmd,4+szInitiatorDataLen,pbtTargetsData,&szRxLen)) {
|
if(pnd->pdc->transceive(pnd->nds,abtCmd,4+szInitiatorDataLen,pbtTargetsData,&szRxLen)) {
|
||||||
*pszTargetsData = szRxLen;
|
*pszTargetsData = szRxLen;
|
||||||
|
|
|
@ -240,6 +240,7 @@ bool pn53x_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, cons
|
||||||
byte_t abtTx[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
|
byte_t abtTx[BUFFER_LENGTH] = { 0x00, 0x00, 0xff }; // Every packet must start with "00 00 ff"
|
||||||
byte_t abtRx[BUFFER_LENGTH];
|
byte_t abtRx[BUFFER_LENGTH];
|
||||||
usb_spec_t* pus = (usb_spec_t*)nds;
|
usb_spec_t* pus = (usb_spec_t*)nds;
|
||||||
|
uint8_t ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 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)
|
||||||
abtTx[3] = szTxLen;
|
abtTx[3] = szTxLen;
|
||||||
|
@ -280,7 +281,6 @@ bool pn53x_usb_transceive(const nfc_device_spec_t nds, const byte_t* pbtTx, cons
|
||||||
PRINT_HEX("RX", abtRx,ret);
|
PRINT_HEX("RX", abtRx,ret);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 };
|
|
||||||
if ((ret != 6) || (memcmp (abtRx, ack_frame, 6))) {
|
if ((ret != 6) || (memcmp (abtRx, ack_frame, 6))) {
|
||||||
DBG ("%s", "===> No ACK!!!!!!");
|
DBG ("%s", "===> No ACK!!!!!!");
|
||||||
return false;
|
return false;
|
||||||
|
|
21
libnfc/nfc.c
21
libnfc/nfc.c
|
@ -33,6 +33,13 @@
|
||||||
|
|
||||||
#include <nfc/nfc.h>
|
#include <nfc/nfc.h>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#include <windows.h>
|
||||||
|
|
||||||
|
#define strdup _strdup
|
||||||
|
#define snprintf sprintf_s
|
||||||
|
#endif
|
||||||
|
|
||||||
#include "chips.h"
|
#include "chips.h"
|
||||||
#include "drivers.h"
|
#include "drivers.h"
|
||||||
|
|
||||||
|
@ -176,6 +183,7 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd)
|
||||||
// Test if the connection was successful
|
// Test if the connection was successful
|
||||||
if (pnd != NULL)
|
if (pnd != NULL)
|
||||||
{
|
{
|
||||||
|
char* pcName;
|
||||||
DBG("[%s] has been claimed.", pnd->acName);
|
DBG("[%s] has been claimed.", pnd->acName);
|
||||||
// Great we have claimed a device
|
// Great we have claimed a device
|
||||||
pnd->pdc = &(drivers_callbacks_list[uiDriver]);
|
pnd->pdc = &(drivers_callbacks_list[uiDriver]);
|
||||||
|
@ -191,7 +199,7 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the firmware revision to the device name, PN531 gives 2 bytes info, but PN532 and PN533 gives 4
|
// Add the firmware revision to the device name, PN531 gives 2 bytes info, but PN532 and PN533 gives 4
|
||||||
char* pcName = strdup(pnd->acName);
|
pcName = strdup(pnd->acName);
|
||||||
switch(pnd->nc) {
|
switch(pnd->nc) {
|
||||||
case NC_PN531: snprintf(pnd->acName,DEVICE_NAME_LENGTH - 1,"%s - PN531 v%d.%d",pcName,abtFw[0],abtFw[1]); break;
|
case NC_PN531: snprintf(pnd->acName,DEVICE_NAME_LENGTH - 1,"%s - PN531 v%d.%d",pcName,abtFw[0],abtFw[1]); break;
|
||||||
case NC_PN532: snprintf(pnd->acName,DEVICE_NAME_LENGTH - 1,"%s - PN532 v%d.%d (0x%02x)",pcName,abtFw[1],abtFw[2],abtFw[3]); break;
|
case NC_PN532: snprintf(pnd->acName,DEVICE_NAME_LENGTH - 1,"%s - PN532 v%d.%d (0x%02x)",pcName,abtFw[1],abtFw[2],abtFw[3]); break;
|
||||||
|
@ -423,6 +431,9 @@ nfc_initiator_select_passive_target(const nfc_device_t* pnd,
|
||||||
byte_t abtInit[MAX_FRAME_LEN];
|
byte_t abtInit[MAX_FRAME_LEN];
|
||||||
size_t szInitLen;
|
size_t szInitLen;
|
||||||
|
|
||||||
|
size_t szTargetsData;
|
||||||
|
byte_t abtTargetsData[MAX_FRAME_LEN];
|
||||||
|
|
||||||
// Make sure we are dealing with a active device
|
// Make sure we are dealing with a active device
|
||||||
if (!pnd->bActive) return false;
|
if (!pnd->bActive) return false;
|
||||||
|
|
||||||
|
@ -459,9 +470,6 @@ nfc_initiator_select_passive_target(const nfc_device_t* pnd,
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t szTargetsData;
|
|
||||||
byte_t abtTargetsData[MAX_FRAME_LEN];
|
|
||||||
|
|
||||||
if(!pn53x_InListPassiveTarget(pnd, nmInitModulation, 1, abtInit, szInitLen, abtTargetsData, &szTargetsData)) return false;
|
if(!pn53x_InListPassiveTarget(pnd, nmInitModulation, 1, abtInit, szInitLen, abtTargetsData, &szTargetsData)) return false;
|
||||||
|
|
||||||
// Make sure one tag has been found, the PN53X returns 0x00 if none was available
|
// Make sure one tag has been found, the PN53X returns 0x00 if none was available
|
||||||
|
@ -539,14 +547,13 @@ nfc_initiator_select_passive_target(const nfc_device_t* pnd,
|
||||||
|
|
||||||
bool nfc_initiator_list_passive_targets(nfc_device_t* pnd, const nfc_modulation_t nmInitModulation, nfc_target_info_t anti[], const size_t szTargets, size_t *pszTargetFound )
|
bool nfc_initiator_list_passive_targets(nfc_device_t* pnd, const nfc_modulation_t nmInitModulation, nfc_target_info_t anti[], const size_t szTargets, size_t *pszTargetFound )
|
||||||
{
|
{
|
||||||
// Let the reader only try once to find a target
|
|
||||||
nfc_configure (pnd, NDO_INFINITE_SELECT, false);
|
|
||||||
|
|
||||||
nfc_target_info_t nti;
|
nfc_target_info_t nti;
|
||||||
|
|
||||||
bool bCollisionDetected = false;
|
bool bCollisionDetected = false;
|
||||||
size_t szTargetFound = 0;
|
size_t szTargetFound = 0;
|
||||||
|
|
||||||
|
// Let the reader only try once to find a target
|
||||||
|
nfc_configure (pnd, NDO_INFINITE_SELECT, false);
|
||||||
|
|
||||||
while (nfc_initiator_select_passive_target (pnd, nmInitModulation, NULL, 0, &nti)) {
|
while (nfc_initiator_select_passive_target (pnd, nmInitModulation, NULL, 0, &nti)) {
|
||||||
nfc_initiator_deselect_target(pnd);
|
nfc_initiator_deselect_target(pnd);
|
||||||
|
|
|
@ -70,9 +70,11 @@ NFCIP_TARGET_OBJ=obj\nfcip-target.obj \
|
||||||
obj\nfc-utils.obj
|
obj\nfc-utils.obj
|
||||||
|
|
||||||
NFC_MFCLASSIC_OBJ=obj\nfc-mfclassic.obj \
|
NFC_MFCLASSIC_OBJ=obj\nfc-mfclassic.obj \
|
||||||
|
obj\mifare.obj \
|
||||||
obj\nfc-utils.obj
|
obj\nfc-utils.obj
|
||||||
|
|
||||||
NFC_MFULTRALIGHT_OBJ=obj\nfc-mfultralight.obj \
|
NFC_MFULTRALIGHT_OBJ=obj\nfc-mfultralight.obj \
|
||||||
|
obj\mifare.obj \
|
||||||
obj\nfc-utils.obj
|
obj\nfc-utils.obj
|
||||||
|
|
||||||
all: obj bin $(LIBNFC_DLL) $(NFC_LIST) $(NFC_POLL) $(NFC_RELAY) $(NFCIP_INITIATOR) $(NFCIP_TARGET) $(NFC_ANTICOL) $(NFC_EMULATE) $(NFC_MFCLASSIC) $(NFC_MFULTRALIGHT)
|
all: obj bin $(LIBNFC_DLL) $(NFC_LIST) $(NFC_POLL) $(NFC_RELAY) $(NFCIP_INITIATOR) $(NFCIP_TARGET) $(NFC_ANTICOL) $(NFC_EMULATE) $(NFC_MFCLASSIC) $(NFC_MFULTRALIGHT)
|
||||||
|
@ -157,6 +159,9 @@ $(NFC_MFULTRALIGHT): $(NFC_MFULTRALIGHT_OBJ) $(LIBNFC_DLL) bin\$(DLLNAME).lib ob
|
||||||
if exist $@.manifest mt.exe -manifest $@.manifest -outputresource:$@;#1
|
if exist $@.manifest mt.exe -manifest $@.manifest -outputresource:$@;#1
|
||||||
if exist $@.manifest del $@.manifest
|
if exist $@.manifest del $@.manifest
|
||||||
|
|
||||||
|
obj\mifare.obj: ..\examples\mifare.c
|
||||||
|
$(CC) /c $(CC_OUT_OBJ)$@ $(CFLAGS) ..\examples\mifare.c
|
||||||
|
|
||||||
obj\nfc-relay.obj: ..\examples\nfc-relay.c
|
obj\nfc-relay.obj: ..\examples\nfc-relay.c
|
||||||
$(CC) /c $(CC_OUT_OBJ)$@ $(CFLAGS) ..\examples\nfc-relay.c
|
$(CC) /c $(CC_OUT_OBJ)$@ $(CFLAGS) ..\examples\nfc-relay.c
|
||||||
|
|
||||||
|
|
|
@ -7,14 +7,14 @@ EXPORTS
|
||||||
nfc_disconnect
|
nfc_disconnect
|
||||||
nfc_configure
|
nfc_configure
|
||||||
nfc_initiator_init
|
nfc_initiator_init
|
||||||
nfc_initiator_select_tag
|
nfc_initiator_select_passive_target
|
||||||
|
nfc_initiator_list_passive_targets
|
||||||
nfc_initiator_select_dep_target
|
nfc_initiator_select_dep_target
|
||||||
nfc_initiator_deselect_tag
|
nfc_initiator_deselect_target
|
||||||
nfc_initiator_poll_targets
|
nfc_initiator_poll_targets
|
||||||
nfc_initiator_transceive_bits
|
nfc_initiator_transceive_bits
|
||||||
nfc_initiator_transceive_bytes
|
nfc_initiator_transceive_bytes
|
||||||
nfc_initiator_transceive_dep_bytes
|
nfc_initiator_transceive_dep_bytes
|
||||||
nfc_initiator_mifare_cmd
|
|
||||||
nfc_target_init
|
nfc_target_init
|
||||||
nfc_target_receive_bits
|
nfc_target_receive_bits
|
||||||
nfc_target_receive_bytes
|
nfc_target_receive_bytes
|
||||||
|
@ -26,3 +26,6 @@ EXPORTS
|
||||||
iso14443a_crc
|
iso14443a_crc
|
||||||
append_iso14443a_crc
|
append_iso14443a_crc
|
||||||
nfc_version
|
nfc_version
|
||||||
|
; FIXME: Lines bellow SUCKS!
|
||||||
|
pn53x_transceive
|
||||||
|
pncmd_initiator_exchange_data
|
||||||
|
|
Loading…
Add table
Reference in a new issue