nfc-list: New option to choose which technologies to poll for

This is useful especially against chips emulating several types
at once (e.g. PN53x, PN544 etc)
This commit is contained in:
Philippe Teuwen 2013-09-09 15:56:49 +02:00
parent dcb7d137c1
commit ad9694cf00
3 changed files with 159 additions and 89 deletions

View file

@ -1,3 +1,11 @@
TBD - 1.7.0.99~rc1
------------------
Fixes:
Improvements:
- nfc-list: New option to choose which technologies to poll for
Sep 03, 2013 - 1.7.0 Sep 03, 2013 - 1.7.0
-------------------- --------------------

View file

@ -24,6 +24,21 @@ Tells
nfc-list nfc-list
to be verbose and display detailed information about the targets shown. to be verbose and display detailed information about the targets shown.
This includes SAK decoding and fingerprinting is available. This includes SAK decoding and fingerprinting is available.
.TP
\fB-t\fP \fIX\fP
Polls only for types according to bitfield value of \fIX\fP:
1: ISO14443A
2: Felica (212 kbps)
4: Felica (424 kbps)
8: ISO14443B
16: ISO14443B'
32: ISO14443B-2 ST SRx
64: ISO14443B-2 ASK CTx
128: Jewel
So 255 (default) polls for all types.
Note that if 16, 32 or 64 then 8 is selected too.
.SH EXAMPLE .SH EXAMPLE
For an ISO/IEC 14443-A tag (i.e.Mifare DESFire): For an ISO/IEC 14443-A tag (i.e.Mifare DESFire):

View file

@ -61,8 +61,19 @@ static nfc_device *pnd;
static void static void
print_usage(const char *progname) print_usage(const char *progname)
{ {
printf("usage: %s [-v]\n", progname); printf("usage: %s [-v] [-t X]\n", progname);
printf(" -v\t verbose display\n"); printf(" -v\t verbose display\n");
printf(" -t X\t poll only for types according to bitfield X:\n");
printf("\t 1: ISO14443A\n");
printf("\t 2: Felica (212 kbps)\n");
printf("\t 4: Felica (424 kbps)\n");
printf("\t 8: ISO14443B\n");
printf("\t 16: ISO14443B'\n");
printf("\t 32: ISO14443B-2 ST SRx\n");
printf("\t 64: ISO14443B-2 ASK CTx\n");
printf("\t 128: Jewel\n");
printf("\tSo 255 (default) polls for all types.\n");
printf("\tNote that if 16, 32 or 64 then 8 is selected too.\n");
} }
int int
@ -73,6 +84,8 @@ main(int argc, const char *argv[])
size_t i; size_t i;
bool verbose = false; bool verbose = false;
int res = 0; int res = 0;
int mask = 0xff;
int arg;
nfc_context *context; nfc_context *context;
nfc_init(&context); nfc_init(&context);
@ -84,10 +97,27 @@ main(int argc, const char *argv[])
// Display libnfc version // Display libnfc version
acLibnfcVersion = nfc_version(); acLibnfcVersion = nfc_version();
printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion); printf("%s uses libnfc %s\n", argv[0], acLibnfcVersion);
if (argc != 1) {
if ((argc == 2) && (0 == strcmp("-v", argv[1]))) { // Get commandline options
for (arg = 1; arg < argc; arg++) {
if (0 == strcmp(argv[arg], "-h")) {
print_usage(argv[0]);
exit(EXIT_SUCCESS);
} else if (0 == strcmp(argv[arg], "-v")) {
verbose = true; verbose = true;
} else if ((0 == strcmp(argv[arg], "-t")) && (arg + 1 < argc)) {
arg++;
mask = atoi(argv[arg]);
if ((mask < 1) || (mask > 255)) {
ERR("%i is invalid value for type bitfield.", mask);
print_usage(argv[0]);
exit(EXIT_FAILURE);
}
// Force TypeB for all derivatives of B
if (mask & 0x70)
mask |= 0x08;
} else { } else {
ERR("%s is not supported option.", argv[arg]);
print_usage(argv[0]); print_usage(argv[0]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
@ -129,6 +159,7 @@ main(int argc, const char *argv[])
nfc_modulation nm; nfc_modulation nm;
if (mask & 0x1) {
nm.nmt = NMT_ISO14443A; nm.nmt = NMT_ISO14443A;
nm.nbr = NBR_106; nm.nbr = NBR_106;
// List ISO14443A targets // List ISO14443A targets
@ -142,7 +173,9 @@ main(int argc, const char *argv[])
printf("\n"); printf("\n");
} }
} }
}
if (mask & 0x02) {
nm.nmt = NMT_FELICA; nm.nmt = NMT_FELICA;
nm.nbr = NBR_212; nm.nbr = NBR_212;
// List Felica tags // List Felica tags
@ -156,7 +189,10 @@ main(int argc, const char *argv[])
printf("\n"); printf("\n");
} }
} }
}
if (mask & 0x04) {
nm.nmt = NMT_FELICA;
nm.nbr = NBR_424; nm.nbr = NBR_424;
if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) { if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
int n; int n;
@ -168,7 +204,9 @@ main(int argc, const char *argv[])
printf("\n"); printf("\n");
} }
} }
}
if (mask & 0x08) {
nm.nmt = NMT_ISO14443B; nm.nmt = NMT_ISO14443B;
nm.nbr = NBR_106; nm.nbr = NBR_106;
// List ISO14443B targets // List ISO14443B targets
@ -182,7 +220,9 @@ main(int argc, const char *argv[])
printf("\n"); printf("\n");
} }
} }
}
if (mask & 0x10) {
nm.nmt = NMT_ISO14443BI; nm.nmt = NMT_ISO14443BI;
nm.nbr = NBR_106; nm.nbr = NBR_106;
// List ISO14443B' targets // List ISO14443B' targets
@ -196,7 +236,9 @@ main(int argc, const char *argv[])
printf("\n"); printf("\n");
} }
} }
}
if (mask & 0x20) {
nm.nmt = NMT_ISO14443B2SR; nm.nmt = NMT_ISO14443B2SR;
nm.nbr = NBR_106; nm.nbr = NBR_106;
// List ISO14443B-2 ST SRx family targets // List ISO14443B-2 ST SRx family targets
@ -210,7 +252,9 @@ main(int argc, const char *argv[])
printf("\n"); printf("\n");
} }
} }
}
if (mask & 0x40) {
nm.nmt = NMT_ISO14443B2CT; nm.nmt = NMT_ISO14443B2CT;
nm.nbr = NBR_106; nm.nbr = NBR_106;
// List ISO14443B-2 ASK CTx family targets // List ISO14443B-2 ASK CTx family targets
@ -224,7 +268,9 @@ main(int argc, const char *argv[])
printf("\n"); printf("\n");
} }
} }
}
if (mask & 0x80) {
nm.nmt = NMT_JEWEL; nm.nmt = NMT_JEWEL;
nm.nbr = NBR_106; nm.nbr = NBR_106;
// List Jewel targets // List Jewel targets
@ -238,6 +284,7 @@ main(int argc, const char *argv[])
printf("\n"); printf("\n");
} }
} }
}
nfc_close(pnd); nfc_close(pnd);
} }