[FL-3706], [FL-3674] NFC NTAG and ISO14443-3b reading fix (#3285)

* mf ultralight poller: reset field after reading tearing flags
* iso14443-3b poller: change cid comparison in ATTRIB cmd

Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
gornekich 2023-12-12 19:24:06 +04:00 committed by GitHub
parent 90cb1c4f2e
commit 155e4e9fa4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 7 deletions

View File

@ -117,12 +117,13 @@ Iso14443_3bError iso14443_3b_poller_activate(Iso14443_3bPoller* instance, Iso144
bit_buffer_reset(instance->rx_buffer); bit_buffer_reset(instance->rx_buffer);
// Send ATTRIB // Send ATTRIB
uint8_t cid = 0;
bit_buffer_append_byte(instance->tx_buffer, 0x1d); bit_buffer_append_byte(instance->tx_buffer, 0x1d);
bit_buffer_append_bytes(instance->tx_buffer, data->uid, ISO14443_3B_UID_SIZE); 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, 0x00);
bit_buffer_append_byte(instance->tx_buffer, ISO14443_3B_ATTRIB_FRAME_SIZE_256); 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, 0x01);
bit_buffer_append_byte(instance->tx_buffer, 0x00); bit_buffer_append_byte(instance->tx_buffer, cid);
ret = iso14443_3b_poller_frame_exchange( ret = iso14443_3b_poller_frame_exchange(
instance, instance->tx_buffer, instance->rx_buffer, iso14443_3b_get_fwt_fc_max(data)); 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)); bit_buffer_get_size_bytes(instance->rx_buffer));
} }
if(bit_buffer_get_byte(instance->rx_buffer, 0) != 0) { uint8_t cid_received = bit_buffer_get_byte(instance->rx_buffer, 0);
FURI_LOG_D( // 15 bit is RFU
TAG, if((cid_received & 0x7f) != cid) {
"Incorrect CID in ATTRIB response: %02X", FURI_LOG_D(TAG, "Incorrect CID in ATTRIB response: %02X", cid_received);
bit_buffer_get_byte(instance->rx_buffer, 0));
instance->state = Iso14443_3bPollerStateActivationFailed; instance->state = Iso14443_3bPollerStateActivationFailed;
ret = Iso14443_3bErrorCommunication; ret = Iso14443_3bErrorCommunication;
break; break;

View File

@ -371,11 +371,14 @@ static NfcCommand mf_ultralight_poller_handler_read_counters(MfUltralightPoller*
} }
static NfcCommand mf_ultralight_poller_handler_read_tearing_flags(MfUltralightPoller* instance) { static NfcCommand mf_ultralight_poller_handler_read_tearing_flags(MfUltralightPoller* instance) {
NfcCommand command = NfcCommandContinue;
if(mf_ultralight_support_feature( if(mf_ultralight_support_feature(
instance->feature_set, instance->feature_set,
MfUltralightFeatureSupportCheckTearingFlag | MfUltralightFeatureSupportSingleCounter)) { MfUltralightFeatureSupportCheckTearingFlag | MfUltralightFeatureSupportSingleCounter)) {
if(instance->tearing_flag_read == instance->tearing_flag_total) { if(instance->tearing_flag_read == instance->tearing_flag_total) {
instance->state = MfUltralightPollerStateTryDefaultPass; instance->state = MfUltralightPollerStateTryDefaultPass;
command = NfcCommandReset;
} else { } else {
bool single_counter = mf_ultralight_support_feature( bool single_counter = mf_ultralight_support_feature(
instance->feature_set, MfUltralightFeatureSupportSingleCounter); instance->feature_set, MfUltralightFeatureSupportSingleCounter);
@ -391,6 +394,7 @@ static NfcCommand mf_ultralight_poller_handler_read_tearing_flags(MfUltralightPo
} else if(instance->error != MfUltralightErrorNone) { } else if(instance->error != MfUltralightErrorNone) {
FURI_LOG_D(TAG, "Reading tearing flag %d failed", instance->tearing_flag_read); FURI_LOG_D(TAG, "Reading tearing flag %d failed", instance->tearing_flag_read);
instance->state = MfUltralightPollerStateTryDefaultPass; instance->state = MfUltralightPollerStateTryDefaultPass;
command = NfcCommandReset;
} else { } else {
instance->tearing_flag_read++; instance->tearing_flag_read++;
} }
@ -398,9 +402,10 @@ static NfcCommand mf_ultralight_poller_handler_read_tearing_flags(MfUltralightPo
} else { } else {
FURI_LOG_D(TAG, "Skip reading tearing flags"); FURI_LOG_D(TAG, "Skip reading tearing flags");
instance->state = MfUltralightPollerStateTryDefaultPass; instance->state = MfUltralightPollerStateTryDefaultPass;
command = NfcCommandReset;
} }
return NfcCommandContinue; return command;
} }
static NfcCommand mf_ultralight_poller_handler_auth(MfUltralightPoller* instance) { static NfcCommand mf_ultralight_poller_handler_auth(MfUltralightPoller* instance) {