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,113 +159,130 @@ main(int argc, const char *argv[])
nfc_modulation nm; nfc_modulation nm;
nm.nmt = NMT_ISO14443A; if (mask & 0x1) {
nm.nbr = NBR_106; nm.nmt = NMT_ISO14443A;
// List ISO14443A targets nm.nbr = NBR_106;
if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) { // List ISO14443A targets
int n; if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
if (verbose || (res > 0)) { int n;
printf("%d ISO14443A passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); if (verbose || (res > 0)) {
} printf("%d ISO14443A passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
for (n = 0; n < res; n++) { }
print_nfc_target(&ant[n], verbose); for (n = 0; n < res; n++) {
printf("\n"); print_nfc_target(&ant[n], verbose);
printf("\n");
}
} }
} }
nm.nmt = NMT_FELICA; if (mask & 0x02) {
nm.nbr = NBR_212; nm.nmt = NMT_FELICA;
// List Felica tags nm.nbr = NBR_212;
if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) { // List Felica tags
int n; if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
if (verbose || (res > 0)) { int n;
printf("%d Felica (212 kbps) passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); if (verbose || (res > 0)) {
} printf("%d Felica (212 kbps) passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
for (n = 0; n < res; n++) { }
print_nfc_target(&ant[n], verbose); for (n = 0; n < res; n++) {
printf("\n"); print_nfc_target(&ant[n], verbose);
printf("\n");
}
} }
} }
nm.nbr = NBR_424; if (mask & 0x04) {
if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) { nm.nmt = NMT_FELICA;
int n; nm.nbr = NBR_424;
if (verbose || (res > 0)) { if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
printf("%d Felica (424 kbps) passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); int n;
} if (verbose || (res > 0)) {
for (n = 0; n < res; n++) { printf("%d Felica (424 kbps) passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
print_nfc_target(&ant[n], verbose); }
printf("\n"); for (n = 0; n < res; n++) {
print_nfc_target(&ant[n], verbose);
printf("\n");
}
} }
} }
nm.nmt = NMT_ISO14443B; if (mask & 0x08) {
nm.nbr = NBR_106; nm.nmt = NMT_ISO14443B;
// List ISO14443B targets nm.nbr = NBR_106;
if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) { // List ISO14443B targets
int n; if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
if (verbose || (res > 0)) { int n;
printf("%d ISO14443B passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); if (verbose || (res > 0)) {
} printf("%d ISO14443B passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
for (n = 0; n < res; n++) { }
print_nfc_target(&ant[n], verbose); for (n = 0; n < res; n++) {
printf("\n"); print_nfc_target(&ant[n], verbose);
printf("\n");
}
} }
} }
nm.nmt = NMT_ISO14443BI; if (mask & 0x10) {
nm.nbr = NBR_106; nm.nmt = NMT_ISO14443BI;
// List ISO14443B' targets nm.nbr = NBR_106;
if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) { // List ISO14443B' targets
int n; if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
if (verbose || (res > 0)) { int n;
printf("%d ISO14443B' passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); if (verbose || (res > 0)) {
} printf("%d ISO14443B' passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
for (n = 0; n < res; n++) { }
print_nfc_target(&ant[n], verbose); for (n = 0; n < res; n++) {
printf("\n"); print_nfc_target(&ant[n], verbose);
printf("\n");
}
} }
} }
nm.nmt = NMT_ISO14443B2SR; if (mask & 0x20) {
nm.nbr = NBR_106; nm.nmt = NMT_ISO14443B2SR;
// List ISO14443B-2 ST SRx family targets nm.nbr = NBR_106;
if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) { // List ISO14443B-2 ST SRx family targets
int n; if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
if (verbose || (res > 0)) { int n;
printf("%d ISO14443B-2 ST SRx passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); if (verbose || (res > 0)) {
} printf("%d ISO14443B-2 ST SRx passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
for (n = 0; n < res; n++) { }
print_nfc_target(&ant[n], verbose); for (n = 0; n < res; n++) {
printf("\n"); print_nfc_target(&ant[n], verbose);
printf("\n");
}
} }
} }
nm.nmt = NMT_ISO14443B2CT; if (mask & 0x40) {
nm.nbr = NBR_106; nm.nmt = NMT_ISO14443B2CT;
// List ISO14443B-2 ASK CTx family targets nm.nbr = NBR_106;
if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) { // List ISO14443B-2 ASK CTx family targets
int n; if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
if (verbose || (res > 0)) { int n;
printf("%d ISO14443B-2 ASK CTx passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); if (verbose || (res > 0)) {
} printf("%d ISO14443B-2 ASK CTx passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
for (n = 0; n < res; n++) { }
print_nfc_target(&ant[n], verbose); for (n = 0; n < res; n++) {
printf("\n"); print_nfc_target(&ant[n], verbose);
printf("\n");
}
} }
} }
nm.nmt = NMT_JEWEL; if (mask & 0x80) {
nm.nbr = NBR_106; nm.nmt = NMT_JEWEL;
// List Jewel targets nm.nbr = NBR_106;
if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) { // List Jewel targets
int n; if ((res = nfc_initiator_list_passive_targets(pnd, nm, ant, MAX_TARGET_COUNT)) >= 0) {
if (verbose || (res > 0)) { int n;
printf("%d Jewel passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":"); if (verbose || (res > 0)) {
} printf("%d Jewel passive target(s) found%s\n", res, (res == 0) ? ".\n" : ":");
for (n = 0; n < res; n++) { }
print_nfc_target(&ant[n], verbose); for (n = 0; n < res; n++) {
printf("\n"); print_nfc_target(&ant[n], verbose);
printf("\n");
}
} }
} }
nfc_close(pnd); nfc_close(pnd);