From 155e4e9fa4c1bf504179f9de1f55e5c44d9fb29d Mon Sep 17 00:00:00 2001 From: gornekich Date: Tue, 12 Dec 2023 19:24:06 +0400 Subject: [PATCH] [FL-3706], [FL-3674] NFC NTAG and ISO14443-3b reading fix (#3285) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * mf ultralight poller: reset field after reading tearing flags * iso14443-3b poller: change cid comparison in ATTRIB cmd Co-authored-by: あく --- lib/nfc/protocols/iso14443_3b/iso14443_3b_poller_i.c | 12 ++++++------ .../protocols/mf_ultralight/mf_ultralight_poller.c | 7 ++++++- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lib/nfc/protocols/iso14443_3b/iso14443_3b_poller_i.c b/lib/nfc/protocols/iso14443_3b/iso14443_3b_poller_i.c index 15fc609db..1266e2482 100644 --- a/lib/nfc/protocols/iso14443_3b/iso14443_3b_poller_i.c +++ b/lib/nfc/protocols/iso14443_3b/iso14443_3b_poller_i.c @@ -117,12 +117,13 @@ Iso14443_3bError iso14443_3b_poller_activate(Iso14443_3bPoller* instance, Iso144 bit_buffer_reset(instance->rx_buffer); // Send ATTRIB + uint8_t cid = 0; bit_buffer_append_byte(instance->tx_buffer, 0x1d); bit_buffer_append_bytes(instance->tx_buffer, data->uid, ISO14443_3B_UID_SIZE); bit_buffer_append_byte(instance->tx_buffer, 0x00); bit_buffer_append_byte(instance->tx_buffer, ISO14443_3B_ATTRIB_FRAME_SIZE_256); bit_buffer_append_byte(instance->tx_buffer, 0x01); - bit_buffer_append_byte(instance->tx_buffer, 0x00); + bit_buffer_append_byte(instance->tx_buffer, cid); ret = iso14443_3b_poller_frame_exchange( instance, instance->tx_buffer, instance->rx_buffer, iso14443_3b_get_fwt_fc_max(data)); @@ -138,11 +139,10 @@ Iso14443_3bError iso14443_3b_poller_activate(Iso14443_3bPoller* instance, Iso144 bit_buffer_get_size_bytes(instance->rx_buffer)); } - if(bit_buffer_get_byte(instance->rx_buffer, 0) != 0) { - FURI_LOG_D( - TAG, - "Incorrect CID in ATTRIB response: %02X", - bit_buffer_get_byte(instance->rx_buffer, 0)); + uint8_t cid_received = bit_buffer_get_byte(instance->rx_buffer, 0); + // 15 bit is RFU + if((cid_received & 0x7f) != cid) { + FURI_LOG_D(TAG, "Incorrect CID in ATTRIB response: %02X", cid_received); instance->state = Iso14443_3bPollerStateActivationFailed; ret = Iso14443_3bErrorCommunication; break; diff --git a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c index 619cd8c5f..f7f814270 100644 --- a/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c +++ b/lib/nfc/protocols/mf_ultralight/mf_ultralight_poller.c @@ -371,11 +371,14 @@ static NfcCommand mf_ultralight_poller_handler_read_counters(MfUltralightPoller* } static NfcCommand mf_ultralight_poller_handler_read_tearing_flags(MfUltralightPoller* instance) { + NfcCommand command = NfcCommandContinue; + if(mf_ultralight_support_feature( instance->feature_set, MfUltralightFeatureSupportCheckTearingFlag | MfUltralightFeatureSupportSingleCounter)) { if(instance->tearing_flag_read == instance->tearing_flag_total) { instance->state = MfUltralightPollerStateTryDefaultPass; + command = NfcCommandReset; } else { bool single_counter = mf_ultralight_support_feature( instance->feature_set, MfUltralightFeatureSupportSingleCounter); @@ -391,6 +394,7 @@ static NfcCommand mf_ultralight_poller_handler_read_tearing_flags(MfUltralightPo } else if(instance->error != MfUltralightErrorNone) { FURI_LOG_D(TAG, "Reading tearing flag %d failed", instance->tearing_flag_read); instance->state = MfUltralightPollerStateTryDefaultPass; + command = NfcCommandReset; } else { instance->tearing_flag_read++; } @@ -398,9 +402,10 @@ static NfcCommand mf_ultralight_poller_handler_read_tearing_flags(MfUltralightPo } else { FURI_LOG_D(TAG, "Skip reading tearing flags"); instance->state = MfUltralightPollerStateTryDefaultPass; + command = NfcCommandReset; } - return NfcCommandContinue; + return command; } static NfcCommand mf_ultralight_poller_handler_auth(MfUltralightPoller* instance) {