From 79ebce25499440f14371383a5eab7e6357522e9c Mon Sep 17 00:00:00 2001 From: Romuald Conty Date: Fri, 8 Oct 2010 14:05:10 +0000 Subject: [PATCH] examples: rename nfc-emulate to nfc-emulate-uid. Add some code documentation. Update man page. --- examples/nfc-emulate-uid.1 | 43 +++++++++++++++++++ examples/{nfc-emulate.c => nfc-emulate-uid.c} | 40 +++++++++++------ examples/nfc-emulate.1 | 37 ---------------- 3 files changed, 70 insertions(+), 50 deletions(-) create mode 100644 examples/nfc-emulate-uid.1 rename examples/{nfc-emulate.c => nfc-emulate-uid.c} (78%) delete mode 100644 examples/nfc-emulate.1 diff --git a/examples/nfc-emulate-uid.1 b/examples/nfc-emulate-uid.1 new file mode 100644 index 0000000..04b9473 --- /dev/null +++ b/examples/nfc-emulate-uid.1 @@ -0,0 +1,43 @@ +.TH NFC-EMULATE-UID 1 "June 26, 2009" +.SH NAME +nfc-emulate-uid \- NFC target emulation command line tool based on libnfc +.SH SYNOPSIS +.B nfc-emulate-uid +.RI [ OPTIONS ] +.RI [ UID ] +.SH DESCRIPTION +.B nfc-emulate-uid +is an tag emulation tool that allow to choose tag UID. Tag emulation is one of +the main added features in NFC. To avoid abuse of existing systems, +manufacturers of the NFC controller intentionally did not support emulation of +fully customized UID. The nfc-emulate-uid tool demonstrates that this can still +be done using transmission of raw-frames, and the desired UID can be optionally +specified. + +Fast communication is necessary to respond in time during the anti-collision +protocol. Using the ACR122 device gives many timing issues, "PN53x only" USB +devices also give some timing issues but an embedded microprocessor could be +fast enough to emulate a tag with any UID. + +This makes it a serious thread for security systems that rely only on the +uniqueness of the UID. + +.SH OPTIONS +.IR UID +8 hex digits format that represents desired UID (default is DEADBEAF). + +.SH BUGS +Please report any bugs on the +.B libnfc +forum at +.BR http://www.libnfc.org/community/ "." +.SH LICENCE +.B libnfc +and +.B libnfc-examples +are covered by the GNU Lesser General Public License (LGPL), version 3. +.SH AUTHORS +Roel Verdult +.PP +This manual page was written by Romuald Conty . +It is licensed under the terms of the GNU GPL (version 2 or later). diff --git a/examples/nfc-emulate.c b/examples/nfc-emulate-uid.c similarity index 78% rename from examples/nfc-emulate.c rename to examples/nfc-emulate-uid.c index 4334d2e..ed91558 100644 --- a/examples/nfc-emulate.c +++ b/examples/nfc-emulate-uid.c @@ -18,8 +18,22 @@ */ /** - * @file nfc-emulate.c + * @file nfc-emulate-uid.c * @brief This example can be used to emulate a tag which which have a "really" custom UID + * + * NFC devices are able to emulate passive tags but manufacters restricts the + * customization of UID. With PN53x, UID is only 4 bytes long and the first + * byte of emulated UID is hardwarely set to 0x08. This example show how to + * emulate a full customized UID by "manually" replying to anticollision + * process sent by the initiator. + * + * @note Unfortunately, this example can't directly start in fully customisable + * target mode. Just after launching this example, you will have to unlock an + * hardware situation by sending a RATS (Request for Answer To Select) command. + * To do this, you can use a second NFC device (placed in target's field) and + * launch nfc-list or nfc-anticol. After this first step, you now have a NFC + * device (configured as target) that really emulate custom UID. You could view + * it using the second NFC device with nfc-list. */ #ifdef HAVE_CONFIG_H @@ -54,7 +68,7 @@ print_usage (char *argv[]) printf ("Usage: %s [OPTIONS] [UID]\n", argv[0]); printf ("Options:\n"); printf ("\t-h\tHelp. Print this message.\n"); - printf ("\t-q\tQuiet mode. Suppress output of READER and EMULATOR data (improves timing).\n"); + printf ("\t-q\tQuiet mode. Silent output: received and sent frames will not be shown (improves timing).\n"); printf ("\n"); printf ("\t[UID]\tUID to emulate, specified as 8 HEX digits (default is DEADBEAF).\n"); } @@ -73,9 +87,9 @@ main (int argc, char *argv[]) for (arg = 1; arg < argc; arg++) { if (0 == strcmp (argv[arg], "-h")) { print_usage (argv); - return 0; + exit(EXIT_SUCCESS); } else if (0 == strcmp (argv[arg], "-q")) { - INFO ("%s", "Quiet mode."); + printf ("Quiet mode.\n"); quiet_output = true; } else if ((arg == argc - 1) && (strlen (argv[arg]) == 8)) { // See if UID was specified as HEX string byte_t abtTmp[3] = { 0x00, 0x00, 0x00 }; @@ -89,23 +103,23 @@ main (int argc, char *argv[]) } else { ERR ("%s is not supported option.", argv[arg]); print_usage (argv); - return -1; + exit(EXIT_FAILURE); } } - // Try to open the NFC reader + // Try to open the NFC device pnd = nfc_connect (NULL); if (pnd == NULL) { - printf ("Error connecting NFC reader\n"); - return 1; + printf ("Unable to connect to NFC device\n"); + exit(EXIT_FAILURE); } printf ("\n"); - printf ("[+] Connected to NFC reader: %s\n", pnd->acName); - printf ("[+] Try to break out the auto-emulation, this requires a second reader!\n"); + printf ("Connected to NFC device: %s\n", pnd->acName); + printf ("[+] Try to break out the auto-emulation, this requires a second NFC device!\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"); + printf ("[+] For example, send a RATS command or use the \"nfc-anticol\" or \"nfc-list\" tool.\n"); // Note: We have to build a "fake" nfc_target_t in order to do exactly the same that was done before the new nfc_target_init() was introduced. nfc_target_t nt = { @@ -117,8 +131,8 @@ main (int argc, char *argv[]) .nti.nai.szAtsLen = 0, }; if (!nfc_target_init (pnd, NTM_PASSIVE, nt, abtRecv, &szRecvBits)) { - printf ("Error: Could not come out of auto-emulation, no command was received\n"); - return 1; + ERR ("Could not come out of auto-emulation, no command was received"); + exit(EXIT_FAILURE); } printf ("[+] Received initiator command: "); print_hex_bits (abtRecv, szRecvBits); diff --git a/examples/nfc-emulate.1 b/examples/nfc-emulate.1 deleted file mode 100644 index 7376945..0000000 --- a/examples/nfc-emulate.1 +++ /dev/null @@ -1,37 +0,0 @@ -.TH NFC-EMULATE 1 "June 26, 2009" -.SH NAME -nfc-emulate \- NFC target emulation command line tool based on libnfc -.SH SYNOPSIS -.B nfc-emulate -.RI [ UID ] -.SH DESCRIPTION -.B nfc-emulate -is an tag emulatation tool. Tag emulation is one of the main added features in NFC. -To avoid abuse of existing systems, manufacturers of the NFC controller intentionally did not -support emulation of custom UID numbers. -The emulate tool demonstrates that this can still be done using transmission of raw-frames, -and the desired UID can be optionally specified. -Fast communication is necessary to respond in time during the anti-collision protocol. -Using the USB interface gives some timing issues but an embedded microprocessor could -be fast enough to emulate a tag with any UID. This makes it a serious thread -for security systems that rely only on the uniqueness of the UID. - -.SH OPTIONS -.IR UID -8 hex digits format that represents desired UID (default is DEADBEAF). - -.SH BUGS -Please report any bugs on the -.B libnfc -forum at -.BR http://www.libnfc.org/community/ "." -.SH LICENCE -.B libnfc -and -.B libnfc-examples -are covered by the GNU Lesser General Public License (LGPL), version 3. -.SH AUTHORS -Roel Verdult -.PP -This manual page was written by Romuald Conty . -It is licensed under the terms of the GNU GPL (version 2 or later).