ACR122 devices support enhancements.

- Add driver agnostic nfc_pick_device(), nfc_list_devices();
  - New API function: nfc_list_devices();
  - PCSC Context sharing for acr122 driver;
  - List all devices in nfc-list(1);
  - Various code fixes and cleanup;
  - Remove warnings when compiling;
  - Merge r191:199 from trunk \_°< Coin!
This commit is contained in:
Romain Tartiere 2009-11-24 17:49:24 +00:00
parent 1af29561e8
commit 220bef3490
20 changed files with 248 additions and 94 deletions

View file

@ -32,18 +32,26 @@
#include "nfc-messages.h"
#include "bitutils.h"
#define MAX_DEVICE_COUNT 16
static nfc_device_t* pnd;
static byte_t abtFelica[5] = { 0x00, 0xff, 0xff, 0x00, 0x00 };
int main(int argc, const char* argv[])
{
size_t szFound;
int i;
nfc_target_info_t nti;
nfc_device_desc_t *pnddDevices;
// Display libnfc version
const char* acLibnfcVersion = nfc_version();
printf("%s use libnfc %s\n", argv[0], acLibnfcVersion);
// Try to open the NFC device
// Lazy way to open an NFC device
/*
pnd = nfc_connect(NULL);
*/
// If specific device is wanted, i.e. an ARYGON device on /dev/ttyUSB0
/*
@ -54,10 +62,27 @@ int main(int argc, const char* argv[])
pnd = nfc_connect(&ndd);
*/
if (!(pnddDevices = malloc (MAX_DEVICE_COUNT * sizeof (*pnddDevices))))
{
fprintf (stderr, "malloc() failed\n");
return EXIT_FAILURE;
}
nfc_list_devices (pnddDevices, MAX_DEVICE_COUNT, &szFound);
if (szFound == 0)
{
INFO("%s", "No device found.");
}
for (i = 0; i < szFound; i++)
{
pnd = nfc_connect(&(pnddDevices[i]));
if (pnd == NULL)
{
ERR("Unable to connect to NFC device.");
ERR("%s", "Unable to connect to NFC device.");
return 1;
}
nfc_initiator_init(pnd);
@ -121,5 +146,8 @@ int main(int argc, const char* argv[])
}
nfc_disconnect(pnd);
}
free (pnddDevices);
return 0;
}

View file

@ -25,6 +25,7 @@
#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <signal.h>
#include <nfc.h>
@ -41,6 +42,14 @@ static byte_t abtTagRxPar[MAX_FRAME_LEN];
static size_t szTagRxBits;
static nfc_device_t* pndReader;
static nfc_device_t* pndTag;
static bool quitting=false;
void intr_hdlr(void)
{
printf("\nQuitting...\n");
quitting=true;
return;
}
void print_usage(char* argv[])
{
@ -70,6 +79,12 @@ int main(int argc,char* argv[])
}
}
#ifdef WIN32
signal(SIGINT, (void (__cdecl*)(int)) intr_hdlr);
#else
signal(SIGINT, (void (*)()) intr_hdlr);
#endif
// Try to open the NFC emulator device
pndTag = nfc_connect(NULL);
if (pndTag == NULL)
@ -83,7 +98,12 @@ int main(int argc,char* argv[])
printf("[+] Try to break out the auto-emulation, this requires a second reader!\n");
printf("[+] To do this, please send any command after the anti-collision\n");
printf("[+] For example, send a RATS command or use the \"nfc-anticol\" tool\n");
nfc_target_init(pndTag,abtReaderRx,&szReaderRxBits);
if (!nfc_target_init(pndTag,abtReaderRx,&szReaderRxBits))
{
printf("[+] Initialization of NFC emulator failed\n");
nfc_disconnect(pndTag);
return 1;
}
printf("[+] Configuring emulator settings\n");
nfc_configure(pndTag,NDO_HANDLE_CRC,false);
nfc_configure(pndTag,NDO_HANDLE_PARITY,false);
@ -94,12 +114,13 @@ int main(int argc,char* argv[])
pndReader = NULL;
while (pndReader == NULL) pndReader = nfc_connect(NULL);
printf("[+] Configuring NFC reader settings\n");
nfc_initiator_init(pndReader);
nfc_configure(pndReader,NDO_HANDLE_CRC,false);
nfc_configure(pndReader,NDO_HANDLE_PARITY,false);
nfc_configure(pndReader,NDO_ACCEPT_INVALID_FRAMES,true);
printf("[+] Done, relaying frames now!\n\n");
while(true)
while(!quitting)
{
// Test if we received a frame from the reader
if (nfc_target_receive_bits(pndTag,abtReaderRx,&szReaderRxBits,abtReaderRxPar))