Revision: f86ad5a183c8
Author: Philippe Teuwen <
yob...@gmail.com>
Date: Sun Jul 14 12:18:22 2013
Log: mifare-classic-read-ndef: skip NULL TLV & proprio TLV
http://code.google.com/p/libfreefare/source/detail?r=f86ad5a183c8
Modified:
/examples/mifare-classic-read-ndef.c
/libfreefare/freefare.h
=======================================
--- /examples/mifare-classic-read-ndef.c Sat Mar 30 10:07:34 2013
+++ /examples/mifare-classic-read-ndef.c Sun Jul 14 12:18:22 2013
@@ -177,29 +177,39 @@
if ((len = mifare_application_read (tags[i], mad, mad_nfcforum_aid,
buffer, sizeof(buffer), mifare_classic_nfcforum_public_key_a,
MFC_KEY_A)) != -1) {
uint8_t tlv_type;
uint16_t tlv_data_len;
-
- uint8_t * tlv_data = tlv_decode (buffer, &tlv_type, &tlv_data_len);
+ uint8_t * tlv_data;
+ uint8_t * pbuffer = buffer;
+decode_tlv:
+ tlv_data = tlv_decode (pbuffer, &tlv_type, &tlv_data_len);
switch (tlv_type) {
case 0x00:
- fprintf (stderr, "NFCForum application contains a \"NULL TLV\".\n");
// FIXME: According to [ANNFC1K4K], we should skip this TLV to read further
TLV blocks.
- error = EXIT_FAILURE;
- goto error;
+ fprintf (message_stream, "NFC Forum application contains a \"NULL
TLV\", Skipping...\n"); // According to [ANNFC1K4K], we skip this Tag to
read further TLV blocks.
+ pbuffer += tlv_record_length(pbuffer, NULL, NULL);
+ if (pbuffer >= buffer + sizeof(buffer)) {
+ error = EXIT_FAILURE;
+ goto error;
+ }
+ goto decode_tlv;
break;
case 0x03:
- fprintf (message_stream, "NFCForum application contains a \"NDEF
Message TLV\".\n");
+ fprintf (message_stream, "NFC Forum application contains a \"NDEF
Message TLV\".\n");
break;
case 0xFD:
- fprintf (stderr, "NFCForum application contains a \"Proprietary
TLV\".\n"); // FIXME: According to [ANNFC1K4K], we should skip this TLV to
read further TLV blocks.
- error = EXIT_FAILURE;
- goto error;
+ fprintf (message_stream, "NFC Forum application contains a
\"Proprietary TLV\", Skipping...\n"); // According to [ANNFC1K4K], we can
skip this TLV to read further TLV blocks.
+ pbuffer += tlv_record_length(pbuffer, NULL, NULL);
+ if (pbuffer >= buffer + sizeof(buffer)) {
+ error = EXIT_FAILURE;
+ goto error;
+ }
+ goto decode_tlv;
break;
case 0xFE:
- fprintf (stderr, "NFCForum application contains a \"Terminator TLV\",
no available data.\n");
+ fprintf (stderr, "NFC Forum application contains a \"Terminator TLV\",
no available data.\n");
error = EXIT_FAILURE;
goto error;
break;
default:
- fprintf (stderr, "NFCForum application contains an invalid TLV.\n");
+ fprintf (stderr, "NFC Forum application contains an invalid TLV.\n");
error = EXIT_FAILURE;
goto error;
break;
=======================================
--- /libfreefare/freefare.h Fri May 18 09:26:37 2012
+++ /libfreefare/freefare.h Sun Jul 14 12:18:22 2013
@@ -402,6 +402,7 @@
uint8_t *tlv_encode (const uint8_t type, const uint8_t *istream, uint16_t
isize, size_t *osize);
uint8_t *tlv_decode (const uint8_t *istream, uint8_t *type, uint16_t
*size);
+size_t tlv_record_length (const uint8_t *istream, size_t
*field_length_size, size_t *field_value_size);
uint8_t *tlv_append (uint8_t *a, uint8_t *b);
#ifdef __cplusplus