utils/nfc-emulate-forum-tag4: add support for v2.0 of the spec

This commit is contained in:
Philippe Teuwen 2012-05-14 22:13:19 +00:00
parent a56e5f9cd7
commit 028db71d79
2 changed files with 38 additions and 15 deletions

View file

@ -5,14 +5,18 @@
.Nd NFC Forum tag type 4 emulation command line demonstration tool .Nd NFC Forum tag type 4 emulation command line demonstration tool
.Sh SYNOPSIS .Sh SYNOPSIS
.Nm .Nm
.Op -1
.Op infile Op outfile .Op infile Op outfile
.Sh DESCRIPTION .Sh DESCRIPTION
.Nm .Nm
is a demonstration tool that emulates a NFC Forum tag type 4 v1.0 with NDEF content. is a demonstration tool that emulates a NFC Forum tag type 4 v2.0 (or v1.0) with NDEF content.
.Pp
.Ar -1
can be provided to force old Tag Type 4 version 1.0 behavior.
.Pp .Pp
.Ar infile .Ar infile
is the file which contains NDEF message you want to share with the NFC-Forum is the file which contains NDEF message you want to share with the NFC-Forum
compliant initiator device (e.g. Nokia 6212 Classic) compliant initiator device (e.g. Nokia 6212 Classic for a v1.0 tag)
.Pp .Pp
If you want to save a shared content by the initiator device, we have to give If you want to save a shared content by the initiator device, we have to give
.Ar outfile .Ar outfile
@ -21,7 +25,7 @@ argument to point where the NDEF message will be saved.
This example uses the hardware capability of PN532 to handle ISO/IEC 14443-4 This example uses the hardware capability of PN532 to handle ISO/IEC 14443-4
low-level frames like RATS/ATS, WTX, etc. low-level frames like RATS/ATS, WTX, etc.
.Pp .Pp
All devices compliant with NFC-Forum Tag Type 4 (Version 1.0) can be used with All devices compliant with NFC-Forum Tag Type 4 (Version 2.0 or 1.0) can be used with
this example in read-write mode. this example in read-write mode.
.Pp .Pp
If no argument is given, a default NDEF file is available. If no argument is given, a default NDEF file is available.

View file

@ -30,7 +30,7 @@
/** /**
* @file nfc-emulate-forum-tag4.c * @file nfc-emulate-forum-tag4.c
* @brief Emulates a NFC Forum Tag Type 4 v1.0 with a NDEF message * @brief Emulates a NFC Forum Tag Type 4 v2.0 (or v1.0) with a NDEF message
*/ */
/* /*
@ -40,6 +40,7 @@
* NFC Forum Type 4 Tag Operation * NFC Forum Type 4 Tag Operation
* Technical Specification * Technical Specification
* NFCForum-TS-Type-4-Tag_1.0 - 2007-03-13 * NFCForum-TS-Type-4-Tag_1.0 - 2007-03-13
* NFCForum-TS-Type-4-Tag_2.0 - 2010-11-18
*/ */
// Notes & differences with nfc-emulate-tag: // Notes & differences with nfc-emulate-tag:
@ -70,6 +71,8 @@
static nfc_device *pnd; static nfc_device *pnd;
static bool quiet_output = false; static bool quiet_output = false;
// Version of the emulated type4 tag:
static int type4v = 2;
#define SYMBOL_PARAM_fISO14443_4_PICC 0x20 #define SYMBOL_PARAM_fISO14443_4_PICC 0x20
@ -86,7 +89,7 @@ struct nfcforum_tag4_state_machine_data {
uint8_t nfcforum_capability_container[] = { uint8_t nfcforum_capability_container[] = {
0x00, 0x0F, /* CCLEN 15 bytes */ 0x00, 0x0F, /* CCLEN 15 bytes */
0x10, /* Mapping version 1.0 */ 0x20, /* Mapping version 2.0, use option -1 to force v1.0 */
0x00, 0x54, /* MLe Maximum R-ADPU data size */ 0x00, 0x54, /* MLe Maximum R-ADPU data size */
// Notes: // Notes:
// - I (Romuald) don't know why Nokia 6212 Classic refuses the NDEF message if MLe is more than 0xFD (any suggests are welcome); // - I (Romuald) don't know why Nokia 6212 Classic refuses the NDEF message if MLe is more than 0xFD (any suggests are welcome);
@ -165,8 +168,11 @@ nfcforum_tag4_io (struct nfc_emulator *emulator, const uint8_t *data_in, const s
if (data_in[P2] != 0x00) if (data_in[P2] != 0x00)
return -ENOTSUP; return -ENOTSUP;
const uint8_t ndef_tag_application_name[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x00 }; const uint8_t ndef_tag_application_name_v1[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x00 };
if ((data_in[LC] == sizeof (ndef_tag_application_name)) && (0 == memcmp (ndef_tag_application_name, data_in + DATA, data_in[LC]))) const uint8_t ndef_tag_application_name_v2[] = { 0xD2, 0x76, 0x00, 0x00, 0x85, 0x01, 0x01 };
if ((type4v == 1) && (data_in[LC] == sizeof (ndef_tag_application_name_v1)) && (0 == memcmp (ndef_tag_application_name_v1, data_in + DATA, data_in[LC])))
memcpy (data_out, "\x90\x00", res = 2);
else if ((type4v == 2) && (data_in[LC] == sizeof (ndef_tag_application_name_v2)) && (0 == memcmp (ndef_tag_application_name_v2, data_in + DATA, data_in[LC])))
memcpy (data_out, "\x90\x00", res = 2); memcpy (data_out, "\x90\x00", res = 2);
else else
memcpy (data_out, "\x6a\x82", res = 2); memcpy (data_out, "\x6a\x82", res = 2);
@ -283,12 +289,14 @@ ndef_message_save (char *filename, struct nfcforum_tag4_ndef_data *tag_data)
static void static void
usage (char *progname) usage (char *progname)
{ {
fprintf (stderr, "usage: %s [infile [outfile]]\n", progname); fprintf (stderr, "usage: %s [-1] [infile [outfile]]\n", progname);
fprintf (stderr, " -1: force Tag Type 4 v1.0 (default is v2.0)\n");
} }
int int
main (int argc, char *argv[]) main (int argc, char *argv[])
{ {
int options = 0;
nfc_target nt = { nfc_target nt = {
.nm = { .nm = {
.nmt = NMT_ISO14443A, .nmt = NMT_ISO14443A,
@ -334,15 +342,26 @@ main (int argc, char *argv[])
.user_data = &nfcforum_tag4_data, .user_data = &nfcforum_tag4_data,
}; };
if (argc > 3) { if ((argc > (1 + options)) && (0 == strcmp ("-h", argv[1 + options]))) {
usage (argv[0]);
exit (EXIT_SUCCESS);
}
if ((argc > (1 + options)) && (0 == strcmp ("-1", argv[1 + options]))) {
type4v = 1;
nfcforum_capability_container[2] = 0x10;
options += 1;
}
if (argc > (3 + options)) {
usage (argv[0]); usage (argv[0]);
exit (EXIT_FAILURE); exit (EXIT_FAILURE);
} }
// If some file is provided load it // If some file is provided load it
if (argc >= 2) { if (argc >= (2 + options)) {
if (!ndef_message_load (argv[1], &nfcforum_tag4_data)) { if (!ndef_message_load (argv[1 + options], &nfcforum_tag4_data)) {
err (EXIT_FAILURE, "Can't load NDEF file '%s'", argv[1]); err (EXIT_FAILURE, "Can't load NDEF file '%s'", argv[1 + options]);
} }
} }
@ -367,9 +386,9 @@ main (int argc, char *argv[])
nfc_close(pnd); nfc_close(pnd);
if (argc == 3) { if (argc == (3 + options)) {
if (!(ndef_message_save (argv[2], &nfcforum_tag4_data))) { if (!(ndef_message_save (argv[2 + options], &nfcforum_tag4_data))) {
err (EXIT_FAILURE, "Can't save NDEF file '%s'", argv[2]); err (EXIT_FAILURE, "Can't save NDEF file '%s'", argv[2 + options]);
} }
} }