mifare-classic-read-ndef: skip NULL TLV & proprio TLV
This commit is contained in:
parent
ea496c441d
commit
f86ad5a183
2 changed files with 22 additions and 11 deletions
|
@ -177,29 +177,39 @@ main(int argc, char *argv[])
|
||||||
if ((len = mifare_application_read (tags[i], mad, mad_nfcforum_aid, buffer, sizeof(buffer), mifare_classic_nfcforum_public_key_a, MFC_KEY_A)) != -1) {
|
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;
|
uint8_t tlv_type;
|
||||||
uint16_t tlv_data_len;
|
uint16_t tlv_data_len;
|
||||||
|
uint8_t * tlv_data;
|
||||||
uint8_t * tlv_data = tlv_decode (buffer, &tlv_type, &tlv_data_len);
|
uint8_t * pbuffer = buffer;
|
||||||
|
decode_tlv:
|
||||||
|
tlv_data = tlv_decode (pbuffer, &tlv_type, &tlv_data_len);
|
||||||
switch (tlv_type) {
|
switch (tlv_type) {
|
||||||
case 0x00:
|
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.
|
fprintf (message_stream, "NFC Forum application contains a \"NULL TLV\", Skipping...\n"); // According to [ANNFC1K4K], we skip this Tag to read further TLV blocks.
|
||||||
error = EXIT_FAILURE;
|
pbuffer += tlv_record_length(pbuffer, NULL, NULL);
|
||||||
goto error;
|
if (pbuffer >= buffer + sizeof(buffer)) {
|
||||||
|
error = EXIT_FAILURE;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
goto decode_tlv;
|
||||||
break;
|
break;
|
||||||
case 0x03:
|
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;
|
break;
|
||||||
case 0xFD:
|
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.
|
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.
|
||||||
error = EXIT_FAILURE;
|
pbuffer += tlv_record_length(pbuffer, NULL, NULL);
|
||||||
goto error;
|
if (pbuffer >= buffer + sizeof(buffer)) {
|
||||||
|
error = EXIT_FAILURE;
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
goto decode_tlv;
|
||||||
break;
|
break;
|
||||||
case 0xFE:
|
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;
|
error = EXIT_FAILURE;
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
fprintf (stderr, "NFCForum application contains an invalid TLV.\n");
|
fprintf (stderr, "NFC Forum application contains an invalid TLV.\n");
|
||||||
error = EXIT_FAILURE;
|
error = EXIT_FAILURE;
|
||||||
goto error;
|
goto error;
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -402,6 +402,7 @@ void mifare_desfire_key_free (MifareDESFireKey key);
|
||||||
|
|
||||||
uint8_t *tlv_encode (const uint8_t type, const uint8_t *istream, uint16_t isize, size_t *osize);
|
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);
|
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);
|
uint8_t *tlv_append (uint8_t *a, uint8_t *b);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|
Loading…
Reference in a new issue