8 static const char *
const TAG =
"nfc";
11 char buf[(uid.size() * 2) + uid.size() - 1];
13 for (
size_t i = 0; i < uid.size(); i++) {
14 const char *format =
"%02X";
15 if (i + 1 < uid.size())
17 offset += sprintf(buf + offset, format, uid[i]);
19 return std::string(buf);
23 char buf[(bytes.size() * 2) + bytes.size() - 1];
25 for (
size_t i = 0; i < bytes.size(); i++) {
26 const char *format =
"%02X";
27 if (i + 1 < bytes.size())
29 offset += sprintf(buf + offset, format, bytes[i]);
31 return std::string(buf);
35 if (uid_length == 4) {
36 return TAG_TYPE_MIFARE_CLASSIC;
43 for (uint8_t i = 0; i < MIFARE_CLASSIC_BLOCK_SIZE; i++) {
44 if (data[i] == 0x00) {
46 }
else if (data[i] == 0x03) {
57 if (data[i] != 0x03) {
58 ESP_LOGE(TAG,
"Error, Can't decode message length.");
61 if (data[i + 1] == 0xFF) {
62 message_length = ((0xFF & data[i + 2]) << 8) | (0xFF & data[i + 3]);
63 message_start_index = i + MIFARE_CLASSIC_LONG_TLV_SIZE;
65 message_length = data[i + 1];
66 message_start_index = i + MIFARE_CLASSIC_SHORT_TLV_SIZE;
72 uint32_t buffer_size = message_length + 2 + 1;
73 if (buffer_size % MIFARE_ULTRALIGHT_READ_SIZE != 0)
74 buffer_size = ((buffer_size / MIFARE_ULTRALIGHT_READ_SIZE) + 1) * MIFARE_ULTRALIGHT_READ_SIZE;
79 uint32_t buffer_size = message_length;
80 if (message_length < 255) {
81 buffer_size += MIFARE_CLASSIC_SHORT_TLV_SIZE + 1;
83 buffer_size += MIFARE_CLASSIC_LONG_TLV_SIZE + 1;
85 if (buffer_size % MIFARE_CLASSIC_BLOCK_SIZE != 0) {
86 buffer_size = ((buffer_size / MIFARE_CLASSIC_BLOCK_SIZE) + 1) * MIFARE_CLASSIC_BLOCK_SIZE;
92 if (block_num < MIFARE_CLASSIC_BLOCKS_PER_SECT_LOW * MIFARE_CLASSIC_16BLOCK_SECT_START) {
93 return (block_num % MIFARE_CLASSIC_BLOCKS_PER_SECT_LOW == 0);
95 return (block_num % MIFARE_CLASSIC_BLOCKS_PER_SECT_HIGH == 0);
100 if (block_num < MIFARE_CLASSIC_BLOCKS_PER_SECT_LOW * MIFARE_CLASSIC_16BLOCK_SECT_START) {
101 return ((block_num + 1) % MIFARE_CLASSIC_BLOCKS_PER_SECT_LOW == 0);
103 return ((block_num + 1) % MIFARE_CLASSIC_BLOCKS_PER_SECT_HIGH == 0);
uint32_t get_mifare_classic_buffer_size(uint32_t message_length)
bool mifare_classic_is_trailer_block(uint8_t block_num)
bool decode_mifare_classic_tlv(std::vector< uint8_t > &data, uint32_t &message_length, uint8_t &message_start_index)
uint8_t get_mifare_classic_ndef_start_index(std::vector< uint8_t > &data)
std::string format_uid(std::vector< uint8_t > &uid)
uint8_t guess_tag_type(uint8_t uid_length)
bool mifare_classic_is_first_block(uint8_t block_num)
Implementation of SPI Controller mode.
std::vector< uint8_t > bytes
uint32_t get_mifare_ultralight_buffer_size(uint32_t message_length)
std::string format_bytes(std::vector< uint8_t > &bytes)