Skip to content

Commit

Permalink
Sync nfc-utils.[hc] with libnfc development version. (Fixes Issue 16)
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] committed Oct 17, 2011
1 parent 7edf0d2 commit 2a1bd21
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 48 deletions.
105 changes: 59 additions & 46 deletions src/nfc-utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +537,8 @@ print_nfc_felica_info (const nfc_felica_info_t nfi, bool verbose)
print_hex (nfi.abtId, 8);
printf (" Parameter (PAD): ");
print_hex (nfi.abtPad, 8);
printf (" System Code (SC): ");
print_hex (nfi.abtSysCode, 2);
}

void
Expand Down Expand Up @@ -607,6 +609,51 @@ 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)
{
Expand All @@ -623,52 +670,6 @@ print_nfc_dep_info (const nfc_dep_info_t ndi, bool verbose)
}
}

/**
* @brief Tries to parse arguments to find device descriptions.
* @return Returns the list of found device descriptions.
*/
nfc_device_desc_t *
parse_args (int argc, const char *argv[], size_t * szFound, bool * verbose)
{
nfc_device_desc_t *pndd = 0;
int arg;
*szFound = 0;

// Get commandline options
for (arg = 1; arg < argc; arg++) {

if (0 == strcmp (argv[arg], "--device")) {
// FIXME: this device selection by command line options is terrible & does not support USB/PCSC drivers
if (argc > arg + 1) {
char buffer[256];

pndd = malloc (sizeof (nfc_device_desc_t));

strncpy (buffer, argv[++arg], 256);

// Driver.
pndd->pcDriver = (char *) malloc (256);
strcpy (pndd->pcDriver, strtok (buffer, ":"));

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

// Speed.
sscanf (strtok (NULL, ":"), "%u", &pndd->uiSpeed);

*szFound = 1;
} else {
errx (1, "usage: %s [--device driver:port:speed]", argv[0]);
}
}
if ((0 == strcmp (argv[arg], "-v")) || (0 == strcmp (argv[arg], "--verbose"))) {
*verbose = true;
}
}
return pndd;
}

const char *
str_nfc_baud_rate (const nfc_baud_rate_t nbr)
{
Expand Down Expand Up @@ -712,6 +713,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
5 changes: 3 additions & 2 deletions src/nfc-utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,13 @@ 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);

void print_nfc_target (const nfc_target_t nt, bool verbose);

nfc_device_desc_t *parse_args (int argc, const char *argv[], size_t * szFound, bool * verbose);

#endif

0 comments on commit 2a1bd21

Please sign in to comment.