9static const char *
const TAG =
"nfc";
16 if (uid_length == 4) {
17 return TAG_TYPE_MIFARE_CLASSIC;
24 for (uint8_t i = 0; i < MIFARE_CLASSIC_BLOCK_SIZE; i++) {
25 if (data[i] == 0x00) {
27 }
else if (data[i] == 0x03) {
38 if (data[i] != 0x03) {
39 ESP_LOGE(TAG,
"Error, Can't decode message length.");
42 if (data[i + 1] == 0xFF) {
43 message_length = ((0xFF & data[i + 2]) << 8) | (0xFF & data[i + 3]);
44 message_start_index = i + MIFARE_CLASSIC_LONG_TLV_SIZE;
46 message_length = data[i + 1];
47 message_start_index = i + MIFARE_CLASSIC_SHORT_TLV_SIZE;
53 uint32_t buffer_size = message_length + 2 + 1;
54 if (buffer_size % MIFARE_ULTRALIGHT_READ_SIZE != 0)
55 buffer_size = ((buffer_size / MIFARE_ULTRALIGHT_READ_SIZE) + 1) * MIFARE_ULTRALIGHT_READ_SIZE;
60 uint32_t buffer_size = message_length;
61 if (message_length < 255) {
62 buffer_size += MIFARE_CLASSIC_SHORT_TLV_SIZE + 1;
64 buffer_size += MIFARE_CLASSIC_LONG_TLV_SIZE + 1;
66 if (buffer_size % MIFARE_CLASSIC_BLOCK_SIZE != 0) {
67 buffer_size = ((buffer_size / MIFARE_CLASSIC_BLOCK_SIZE) + 1) * MIFARE_CLASSIC_BLOCK_SIZE;
73 if (block_num < MIFARE_CLASSIC_BLOCKS_PER_SECT_LOW * MIFARE_CLASSIC_16BLOCK_SECT_START) {
74 return (block_num % MIFARE_CLASSIC_BLOCKS_PER_SECT_LOW == 0);
76 return (block_num % MIFARE_CLASSIC_BLOCKS_PER_SECT_HIGH == 0);
81 if (block_num < MIFARE_CLASSIC_BLOCKS_PER_SECT_LOW * MIFARE_CLASSIC_16BLOCK_SECT_START) {
82 return ((block_num + 1) % MIFARE_CLASSIC_BLOCKS_PER_SECT_LOW == 0);
84 return ((block_num + 1) % MIFARE_CLASSIC_BLOCKS_PER_SECT_HIGH == 0);
bool decode_mifare_classic_tlv(std::vector< uint8_t > &data, uint32_t &message_length, uint8_t &message_start_index)
std::string format_bytes(const std::vector< uint8_t > &bytes)
uint32_t get_mifare_ultralight_buffer_size(uint32_t message_length)
uint8_t get_mifare_classic_ndef_start_index(std::vector< uint8_t > &data)
std::string format_uid(const std::vector< uint8_t > &uid)
uint8_t guess_tag_type(uint8_t uid_length)
bool mifare_classic_is_trailer_block(uint8_t block_num)
uint32_t get_mifare_classic_buffer_size(uint32_t message_length)
bool mifare_classic_is_first_block(uint8_t block_num)
Providing packet encoding functions for exchanging data with a remote host.
std::string format_hex_pretty(const uint8_t *data, size_t length, char separator, bool show_length)
Format a byte array in pretty-printed, human-readable hex format.