void test_tlv_decode_short (void) { uint8_t *res; uint16_t size; uint8_t type; res = tlv_decode (eshortdata, &type, &size); cut_assert_equal_int (3, type, cut_message ("Wrong type")); cut_assert_equal_int (sizeof (shortdata), size, cut_message ("Wrong value length")); cut_assert_equal_memory (shortdata, sizeof (shortdata), res, size, cut_message ("Wrong decoded value")); free (res); }
int mifare_classic_read_ndef(MifareTag tag, char * buffer, char *max_size) { int error = EXIT_SUCCESS; Mad mad; // NFCForum card has a MAD, load it. if (0 == mifare_classic_connect (tag)) { } else { return -2; } if ((mad = mad_read (tag))) { // Dump the NFCForum application using MAD information ssize_t len; if ((len = mifare_application_read (tag, mad, mad_nfcforum_aid, buffer, max_size, mifare_classic_nfcforum_public_key_a, MFC_KEY_A)) != -1) { uint8_t tlv_type; uint16_t tlv_data_len; uint8_t * tlv_data; uint8_t * pbuffer = buffer; uint8_t found = false; while (!found) { tlv_data = tlv_decode (pbuffer, &tlv_type, &tlv_data_len); switch (tlv_type) { case 0x00: printf ("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= -3; found = true; } break; case 0x03: printf ("NFC Forum application contains a \"NDEF Message TLV\".\n"); found = true; error = tlv_data_len; memcpy(buffer,tlv_data,tlv_data_len); break; case 0xFD: printf ("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= -4; found = true; } break; case 0xFE: printf ("NFC Forum application contains a \"Terminator TLV\", no available data.\n"); error= -5; found = true; break; default: printf ("NFC Forum application contains an invalid TLV.\n"); error= -6; found = true; } } } else { printf ("No NFC Forum application.\n"); error= -7; } } else { printf ("No MAD detected.\n"); } vPortFree (mad); return error; }