Skip to content

Commit

Permalink
Undead nfc-eventd, use the development version of libnfc
Browse files Browse the repository at this point in the history
  • Loading branch information
neomilium committed Sep 21, 2011
1 parent 22fe643 commit 06d5d78
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ SUBDIRS = debug nfcconf modules

INCLUDES = $(all_includes)

AM_CFLAGS = -DNEMDIR=\"${nemdir}\" -DSYSCONFDIR=\"${sysconfdir}\" @LIBNFC_CFLAGS@
AM_CFLAGS = -ldl -DNEMDIR=\"${nemdir}\" -DSYSCONFDIR=\"${sysconfdir}\" @LIBNFC_CFLAGS@
AM_LDFLAGS = @LIBNFC_LIBS@

bin_PROGRAMS = nfc-eventd
Expand Down
63 changes: 61 additions & 2 deletions src/debug/nfc-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,7 @@ print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai, bool verbose)
void
print_nfc_felica_info (const nfc_felica_info_t nfi, bool verbose)
{
(void) verbose;
printf (" ID (NFCID2): ");
print_hex (nfi.abtId, 8);
printf (" Parameter (PAD): ");
Expand All @@ -541,6 +542,7 @@ print_nfc_felica_info (const nfc_felica_info_t nfi, bool verbose)
void
print_nfc_jewel_info (const nfc_jewel_info_t nji, bool verbose)
{
(void) verbose;
printf (" ATQA (SENS_RES): ");
print_hex (nji.btSensRes, 2);
printf (" 4-LSB JEWELID: ");
Expand Down Expand Up @@ -605,9 +607,55 @@ print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi, bool verbose)
}
}

void
print_nfc_iso14443bi_info (const nfc_iso14443bi_info_t nii, bool verbose)
{
printf (" DIV: ");
print_hex (nii.abtDIV, 4);
if (verbose) {
int version = (nii.btVerLog & 0x1e)>>1;
printf (" Software Version: ");
if (version == 15) {
printf ("Undefined\n");
} else {
printf ("%i\n", version);
}

if ((nii.btVerLog & 0x80) && (nii.btConfig & 0x80)){
printf (" Wait Enable: yes");
}
}
if ((nii.btVerLog & 0x80) && (nii.btConfig & 0x40)) {
printf (" ATS: ");
print_hex (nii.abtAtr, nii.szAtrLen);
}
}

void
print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info_t nsi, bool verbose)
{
(void) verbose;
printf (" UID: ");
print_hex (nsi.abtUID, 8);
}

void
print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info_t nci, bool verbose)
{
(void) verbose;
uint32_t uid;
uid = (nci.abtUID[3] << 24) + (nci.abtUID[2] << 16) + (nci.abtUID[1] << 8) + nci.abtUID[0];
printf (" UID: ");
print_hex (nci.abtUID, sizeof(nci.abtUID));
printf (" UID (decimal): %010u\n", uid);
printf (" Product Code: %02X\n", nci.btProdCode);
printf (" Fab Code: %02X\n", nci.btFabCode);
}

void
print_nfc_dep_info (const nfc_dep_info_t ndi, bool verbose)
{
(void) verbose;
printf (" NFCID3: ");
print_hex (ndi.abtNFCID3, 10);
printf (" BS: %02x\n", ndi.btBS);
Expand Down Expand Up @@ -648,8 +696,7 @@ parse_args (int argc, const char *argv[], size_t * szFound, bool * verbose)
strcpy (pndd->pcDriver, strtok (buffer, ":"));

// Port.
pndd->pcPort = (char *) malloc (256);
strcpy (pndd->pcPort, strtok (NULL, ":"));
strcpy (pndd->acPort, strtok (NULL, ":"));

// Speed.
sscanf (strtok (NULL, ":"), "%u", &pndd->uiSpeed);
Expand Down Expand Up @@ -709,6 +756,18 @@ print_nfc_target (const nfc_target_t nt, bool verbose)
printf ("ISO/IEC 14443-4B (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
print_nfc_iso14443b_info (nt.nti.nbi, verbose);
break;
case NMT_ISO14443BI:
printf ("ISO/IEC 14443-4B' (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
print_nfc_iso14443bi_info (nt.nti.nii, verbose);
break;
case NMT_ISO14443B2SR:
printf ("ISO/IEC 14443-2B ST SRx (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
print_nfc_iso14443b2sr_info (nt.nti.nsi, verbose);
break;
case NMT_ISO14443B2CT:
printf ("ISO/IEC 14443-2B ASK CTx (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
print_nfc_iso14443b2ct_info (nt.nti.nci, verbose);
break;
case NMT_DEP:
printf ("D.E.P. (%s) target:\n", str_nfc_baud_rate(nt.nm.nbr));
print_nfc_dep_info (nt.nti.ndi, verbose);
Expand Down
43 changes: 43 additions & 0 deletions src/debug/nfc-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,46 @@

# include <stdlib.h>
# include <string.h>
# include <err.h>

/**
* @macro DBG
* @brief Print a message of standard output only in DEBUG mode
*/
#ifdef DEBUG
# define DBG(...) do { \
warnx ("DBG %s:%d", __FILE__, __LINE__); \
warnx (" " __VA_ARGS__ ); \
} while (0)
#else
# define DBG(...) {}
#endif

/**
* @macro WARN
* @brief Print a warn message
*/
#ifdef DEBUG
# define WARN(...) do { \
warnx ("WARNING %s:%d", __FILE__, __LINE__); \
warnx (" " __VA_ARGS__ ); \
} while (0)
#else
# define WARN(...) warnx ("WARNING: " __VA_ARGS__ )
#endif

/**
* @macro ERR
* @brief Print a error message
*/
#ifdef DEBUG
# define ERR(...) do { \
warnx ("ERROR %s:%d", __FILE__, __LINE__); \
warnx (" " __VA_ARGS__ ); \
} while (0)
#else
# define ERR(...) warnx ("ERROR: " __VA_ARGS__ )
#endif

byte_t oddparity (const byte_t bt);
void oddparity_byte_ts (const byte_t * pbtData, const size_t szLen, byte_t * pbtPar);
Expand All @@ -48,6 +88,9 @@ void print_hex_par (const byte_t * pbtData, const size_t szBits, const byte_t

void print_nfc_iso14443a_info (const nfc_iso14443a_info_t nai, bool verbose);
void print_nfc_iso14443b_info (const nfc_iso14443b_info_t nbi, bool verbose);
void print_nfc_iso14443bi_info (const nfc_iso14443bi_info_t nii, bool verbose);
void print_nfc_iso14443b2sr_info (const nfc_iso14443b2sr_info_t nsi, bool verbose);
void print_nfc_iso14443b2ct_info (const nfc_iso14443b2ct_info_t nci, bool verbose);
void print_nfc_felica_info (const nfc_felica_info_t nfi, bool verbose);
void print_nfc_jewel_info (const nfc_jewel_info_t nji, bool verbose);
void print_nfc_dep_info (const nfc_dep_info_t ndi, bool verbose);
Expand Down
10 changes: 8 additions & 2 deletions src/nfc-eventd.c
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ static int parse_config_file() {
nfc_device_desc->pcDriver = (char*)nfcconf_get_str( my_device, "driver", "" );
char* device_name = (char*)nfcconf_get_str( my_device, "name", "" );
strncpy(nfc_device_desc->acDevice, device_name, sizeof(nfc_device_desc->acDevice));
nfc_device_desc->pcPort = (char*)nfcconf_get_str( my_device, "port", "" );
char* device_port = (char*)nfcconf_get_str( my_device, "port", "" );
strncpy(nfc_device_desc->acPort, device_port, sizeof(nfc_device_desc->acPort));
nfc_device_desc->uiSpeed = nfcconf_get_int( my_device, "speed", 9600 );
nfc_device_desc->uiBusIndex = nfcconf_get_int( my_device, "index", 0 );
break;
Expand Down Expand Up @@ -303,12 +304,17 @@ typedef enum {
nfc_target_t*
ned_poll_for_tag(nfc_device_t* nfc_device, nfc_target_t* tag)
{
static nfc_poll_mode mode = NFC_POLL_HARDWARE;
static nfc_poll_mode mode = NFC_POLL_SOFTWARE;

/*
// With libnfc 1.6 serie, we could not check the internal chip any more.
// BTW, "Capabilities" have to be introduced in libnfc, once it will be available we could switch again to a conditional statement
// http://code.google.com/p/libnfc/issues/detail?id=165
if((mode == NFC_POLL_HARDWARE) && (nfc_device->nc == NC_PN531)) {
DBG("%s doesn't support hardware polling, falling back to software polling", nfc_device->acName);
mode = NFC_POLL_SOFTWARE;
}
*/

switch(mode) {
case NFC_POLL_SOFTWARE:
Expand Down

0 comments on commit 06d5d78

Please sign in to comment.