From a5e5f6988f560461dae63fd9f545ae17c9ba84ff Mon Sep 17 00:00:00 2001 From: turbocool3r Date: Sat, 8 Jun 2024 14:28:07 +0300 Subject: [PATCH] Fix a bug that made Ultralight EV1 and NTAG unreadable. --- firmware/application/src/rfid/nfctag/hf/nfc_mf0_ntag.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/firmware/application/src/rfid/nfctag/hf/nfc_mf0_ntag.c b/firmware/application/src/rfid/nfctag/hf/nfc_mf0_ntag.c index 6a85a4b4..a6b1625a 100644 --- a/firmware/application/src/rfid/nfctag/hf/nfc_mf0_ntag.c +++ b/firmware/application/src/rfid/nfctag/hf/nfc_mf0_ntag.c @@ -260,10 +260,11 @@ static void handle_read_command(uint8_t block_num) { uint8_t pwd_page = get_first_cfg_page_by_tag_type(m_tag_type); if (pwd_page != 0) pwd_page += CONF_PWD_PAGE_OFFSET; - for (int block = 0; block < 4; block++) { - // In case PWD or PACK pages are read we need to write zero to the output buffer. In UID magic mode we don't care. - if (m_tag_information->config.mode_uid_magic || (pwd_page == 0) || ((block - pwd_page) >= 2)) { - memcpy(m_tag_tx_buffer.tx_buffer + block * 4, m_tag_information->memory[(block_num + block) % block_max], NFC_TAG_MF0_NTAG_DATA_SIZE); + for (uint8_t block = 0; block < 4; block++) { + // In case PWD or PACK pages are read we need to write zero to the output buffer. In UID magic mode we don't care. + uint8_t block_to_read = (block_num + block) % block_max; + if (m_tag_information->config.mode_uid_magic || (pwd_page == 0) || (block_to_read < pwd_page) || (block_to_read > (pwd_page + 1))) { + memcpy(m_tag_tx_buffer.tx_buffer + block * 4, m_tag_information->memory[block_to_read], NFC_TAG_MF0_NTAG_DATA_SIZE); } else { memset(m_tag_tx_buffer.tx_buffer + block * 4, 0, NFC_TAG_MF0_NTAG_DATA_SIZE); }