From af1fd0c46d71e5deeabf3b08500c0ce073b8cbf7 Mon Sep 17 00:00:00 2001 From: gornekich Date: Thu, 21 Oct 2021 15:46:47 +0300 Subject: [PATCH] [FL-1920] Fix NTAG emulation (#776) * mifare ultralight: fix read signature command * nfc_worker: read signature before pages --- applications/nfc/nfc_worker.c | 17 ++++++++--------- lib/nfc_protocols/mifare_ultralight.c | 2 +- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/applications/nfc/nfc_worker.c b/applications/nfc/nfc_worker.c index 97858a94c..e8312b880 100755 --- a/applications/nfc/nfc_worker.c +++ b/applications/nfc/nfc_worker.c @@ -509,6 +509,14 @@ void nfc_worker_read_mifare_ul(NfcWorker* nfc_worker) { "Mifare Ultralight Type: %d, Pages: %d", mf_ul_read.type, mf_ul_read.pages_to_read); + FURI_LOG_I(NFC_WORKER_TAG, "Reading signature ..."); + tx_len = mf_ul_prepare_read_signature(tx_buff); + if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) { + FURI_LOG_W(NFC_WORKER_TAG, "Failed reading signature"); + memset(mf_ul_read.data.signature, 0, sizeof(mf_ul_read.data.signature)); + } else { + mf_ul_parse_read_signature_response(rx_buff, &mf_ul_read); + } } else if(err == ERR_TIMEOUT) { FURI_LOG_W( NFC_WORKER_TAG, @@ -540,15 +548,6 @@ void nfc_worker_read_mifare_ul(NfcWorker* nfc_worker) { rx_buff, 0x00, mf_ul_read.pages_to_read - 1, &mf_ul_read); } - FURI_LOG_I(NFC_WORKER_TAG, "Reading signature ..."); - tx_len = mf_ul_prepare_read_signature(tx_buff); - if(furi_hal_nfc_data_exchange(tx_buff, tx_len, &rx_buff, &rx_len, false)) { - FURI_LOG_W(NFC_WORKER_TAG, "Failed reading signature"); - memset(mf_ul_read.data.signature, 0, sizeof(mf_ul_read.data.signature)); - } else { - mf_ul_parse_read_signature_response(rx_buff, &mf_ul_read); - } - FURI_LOG_I(NFC_WORKER_TAG, "Reading 3 counters ..."); for(uint8_t i = 0; i < 3; i++) { tx_len = mf_ul_prepare_read_cnt(tx_buff, i); diff --git a/lib/nfc_protocols/mifare_ultralight.c b/lib/nfc_protocols/mifare_ultralight.c index 39a93a006..962b81b08 100644 --- a/lib/nfc_protocols/mifare_ultralight.c +++ b/lib/nfc_protocols/mifare_ultralight.c @@ -72,7 +72,7 @@ void mf_ul_parse_fast_read_response(uint8_t* buff, uint8_t start_page, uint8_t e } uint16_t mf_ul_prepare_read_signature(uint8_t* dest) { - dest[0] = MF_UL_CHECK_TEARING; + dest[0] = MF_UL_READ_SIG; dest[1] = 0; return 2; }