Merge r499-510 from trunk.

This commit is contained in:
Romain Tartiere 2010-08-10 21:14:13 +00:00
commit dfb82f8893
15 changed files with 94 additions and 86 deletions

View file

@ -43,8 +43,34 @@
#include <sys/stat.h>
#include <limits.h>
#include <sys/time.h>
// unistd.h is needed for usleep() fct.
#include <unistd.h>
#define delay_ms( X ) usleep( X * 1000 )
#else
#include <windows.h>
#define snprintf _snprintf
#define strdup _strdup
#define delay_ms( X ) Sleep( X )
#endif
// Path to the serial port is OS-dependant.
// Try to guess what we should use.
//
// XXX: Some review from users cross-compiling is welcome!
#if defined(_WIN32)
#define SERIAL_STRING "COM"
//#elif defined(__APPLE__)
// TODO: find UART connection string for PN53X device on Mac OS X
// #define SERIAL_STRING ""
#elif defined (__FreeBSD__) || defined (__OpenBSD__)
// XXX: Not tested
#define SERIAL_STRING "/dev/cuau"
#elif defined (__linux__)
#define SERIAL_STRING "/dev/ttyUSB"
#else
#error "Can't determine serial string for your system"
#endif
// Define shortcut to types to make code more readable

View file

@ -337,6 +337,7 @@ pn53x_InListPassiveTarget(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));
@ -348,7 +349,7 @@ pn53x_InListPassiveTarget(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;
if(pn53x_transceive(pnd,abtCmd,4+szInitiatorDataLen,pbtTargetsData,&szRxLen)) {
*pszTargetsData = szRxLen;
return true;
@ -367,6 +368,16 @@ pn53x_InDeselect(nfc_device_t* pnd, const uint8_t ui8Target)
return(pn53x_transceive(pnd,abtCmd,sizeof(abtCmd),NULL,NULL));
}
bool
pn53x_InRelease(nfc_device_t* pnd, const uint8_t ui8Target)
{
byte_t abtCmd[sizeof(pncmd_initiator_release)];
memcpy(abtCmd,pncmd_initiator_release,sizeof(pncmd_initiator_release));
abtCmd[2] = ui8Target;
return(pn53x_transceive(pnd,abtCmd,sizeof(abtCmd),NULL,NULL));
}
struct sErrorMessage {
int iErrorCode;
const char *pcErrorMsg;

View file

@ -81,6 +81,7 @@ bool pn53x_decode_target_data(const byte_t* pbtRawData, size_t szDataLen, nfc_ch
bool pn53x_InListPassiveTarget(nfc_device_t* pnd, const nfc_modulation_t nmInitModulation, const byte_t szMaxTargets, const byte_t* pbtInitiatorData, const size_t szInitiatorDataLen, byte_t* pbtTargetsData, size_t* pszTargetsData);
bool pn53x_InDeselect(nfc_device_t* pnd, const uint8_t ui8Target);
bool pn53x_InRelease(nfc_device_t* pnd, const uint8_t ui8Target);
const char *pn53x_strerror (const nfc_device_t *pnd);

View file

@ -41,25 +41,6 @@
// Bus
#include "uart.h"
#ifdef _WIN32
#define SERIAL_STRING "COM"
#define snprintf _snprintf
#define strdup _strdup
#define delay_ms( X ) Sleep( X )
#else
// unistd.h is needed for usleep() fct.
#include <unistd.h>
#define delay_ms( X ) usleep( X * 1000 )
#ifdef __APPLE__
// MacOS
#define SERIAL_STRING "/dev/tty.SLAB_USBtoUART"
#else
// *BSD, Linux and others POSIX systems
#define SERIAL_STRING "/dev/ttyUSB"
#endif
#endif
#define BUFFER_LENGTH 256
/** @def DEV_ARYGON_PROTOCOL_ARYGON_ASCII

View file

@ -38,33 +38,6 @@
// Bus
#include "uart.h"
#ifdef _WIN32
#define SERIAL_STRING "COM"
#define snprintf _snprintf
#define strdup _strdup
#define delay_ms( X ) Sleep( X )
#else
// unistd.h is needed for usleep() fct.
#include <unistd.h>
#define delay_ms( X ) usleep( X * 1000 )
#ifdef __APPLE__
// MacOS
// TODO: find UART connection string for PN53X device on Mac OS X
#define SERIAL_STRING ""
#elif defined(__FreeBSD__)
// XXX: Not tested
#define SERIAL_STRING "/dev/cuau"
#else
// Linux and maybe some operating systems
// FIXME: We'd rather have an #elif defined(__linux__) or something like
// that and an #else that triggers an error at compile time instead
// of "falling-back" on a value that is likely to not be suitable
// for most operating systems.
#define SERIAL_STRING "/dev/ttyUSB"
#endif
#endif
#define BUFFER_LENGTH 256
#define SERIAL_DEFAULT_PORT_SPEED 115200

View file

@ -241,6 +241,7 @@ bool pn53x_usb_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t s
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*)pnd->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;
@ -281,7 +282,6 @@ bool pn53x_usb_transceive(nfc_device_t* pnd, const byte_t* pbtTx, const size_t s
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]);
@ -190,7 +198,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;
@ -420,6 +428,9 @@ nfc_initiator_select_passive_target(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;
@ -455,9 +466,6 @@ nfc_initiator_select_passive_target(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;
@ -536,14 +544,13 @@ nfc_initiator_select_passive_target(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);