Fix build on Microsoft Windows.

Windows users: I hate you in secret.
This commit is contained in:
Romain Tartiere 2010-08-10 19:50:29 +00:00
parent d7c16d6d1a
commit fd0efd4a62
9 changed files with 52 additions and 30 deletions

View file

@ -295,6 +295,7 @@ pn53x_InListPassiveTarget(const nfc_device_t* pnd,
const byte_t* pbtInitiatorData, const size_t szInitiatorDataLen,
byte_t* pbtTargetsData, size_t* pszTargetsData)
{
size_t szRxLen;
byte_t abtCmd[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);
// 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
if(pnd->pdc->transceive(pnd->nds,abtCmd,4+szInitiatorDataLen,pbtTargetsData,&szRxLen)) {
*pszTargetsData = szRxLen;

View file

@ -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 abtRx[BUFFER_LENGTH];
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)
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);
#endif
uint8_t ack_frame[] = { 0x00, 0x00, 0xff, 0x00, 0xff, 0x00 };
if ((ret != 6) || (memcmp (abtRx, ack_frame, 6))) {
DBG ("%s", "===> No ACK!!!!!!");
return false;

View file

@ -33,6 +33,13 @@
#include <nfc/nfc.h>
#ifdef _WIN32
#include <windows.h>
#define strdup _strdup
#define snprintf sprintf_s
#endif
#include "chips.h"
#include "drivers.h"
@ -176,6 +183,7 @@ nfc_device_t* nfc_connect(nfc_device_desc_t* pndd)
// Test if the connection was successful
if (pnd != NULL)
{
char* pcName;
DBG("[%s] has been claimed.", pnd->acName);
// Great we have claimed a device
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
char* pcName = strdup(pnd->acName);
pcName = strdup(pnd->acName);
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_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];
size_t szInitLen;
size_t szTargetsData;
byte_t abtTargetsData[MAX_FRAME_LEN];
// Make sure we are dealing with a active device
if (!pnd->bActive) return false;
@ -458,9 +469,6 @@ nfc_initiator_select_passive_target(const nfc_device_t* pnd,
szInitLen = szInitDataLen;
break;
}
size_t szTargetsData;
byte_t abtTargetsData[MAX_FRAME_LEN];
if(!pn53x_InListPassiveTarget(pnd, nmInitModulation, 1, abtInit, szInitLen, abtTargetsData, &szTargetsData)) return false;
@ -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 )
{
// Let the reader only try once to find a target
nfc_configure (pnd, NDO_INFINITE_SELECT, false);
nfc_target_info_t nti;
bool bCollisionDetected = false;
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)) {
nfc_initiator_deselect_target(pnd);