From bf41cc43a1b17ebda9ffdc601c5cd41906f676ac Mon Sep 17 00:00:00 2001 From: gornekich Date: Wed, 29 May 2024 18:23:34 +0100 Subject: [PATCH] mf plus: fix read fail event handling --- .../helpers/protocol_support/mf_plus/mf_plus.c | 15 +++++++++------ lib/nfc/protocols/mf_plus/mf_plus_poller.c | 7 +++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.c b/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.c index a020c9bbd..894f13652 100644 --- a/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.c +++ b/applications/main/nfc/helpers/protocol_support/mf_plus/mf_plus.c @@ -26,23 +26,26 @@ static void nfc_scene_info_on_enter_mf_plus(NfcApp* instance) { furi_string_free(temp_str); } static NfcCommand nfc_scene_read_poller_callback_mf_plus(NfcGenericEvent event, void* context) { + furi_assert(context); furi_assert(event.protocol == NfcProtocolMfPlus); + furi_assert(event.event_data); NfcApp* instance = context; const MfPlusPollerEvent* mf_plus_event = event.event_data; + NfcCommand command = NfcCommandContinue; + if(mf_plus_event->type == MfPlusPollerEventTypeReadSuccess) { nfc_device_set_data( instance->nfc_device, NfcProtocolMfPlus, nfc_poller_get_data(instance->poller)); - FURI_LOG_D( - "MFP", - "Read success: %s", - nfc_device_get_name(instance->nfc_device, NfcDeviceNameTypeFull)); view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerSuccess); - return NfcCommandStop; + command = NfcCommandStop; + } else if(mf_plus_event->type == MfPlusPollerEventTypeReadFailed) { + view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerFailure); + command = NfcCommandStop; } - return NfcCommandContinue; + return command; } static void nfc_scene_read_on_enter_mf_plus(NfcApp* instance) { diff --git a/lib/nfc/protocols/mf_plus/mf_plus_poller.c b/lib/nfc/protocols/mf_plus/mf_plus_poller.c index 2cd3a57ca..dac95b912 100644 --- a/lib/nfc/protocols/mf_plus/mf_plus_poller.c +++ b/lib/nfc/protocols/mf_plus/mf_plus_poller.c @@ -101,20 +101,27 @@ static NfcCommand mf_plus_poller_handler_parse_iso4(MfPlusPoller* instance) { static NfcCommand mf_plus_poller_handler_read_failed(MfPlusPoller* instance) { furi_assert(instance); + FURI_LOG_D(TAG, "Read failed"); iso14443_4a_poller_halt(instance->iso14443_4a_poller); + + instance->mfp_event.type = MfPlusPollerEventTypeReadFailed; instance->mfp_event.data->error = instance->error; NfcCommand command = instance->callback(instance->general_event, instance->context); instance->state = MfPlusPollerStateIdle; + return command; } static NfcCommand mf_plus_poller_handler_read_success(MfPlusPoller* instance) { furi_assert(instance); + FURI_LOG_D(TAG, "Read success"); iso14443_4a_poller_halt(instance->iso14443_4a_poller); + instance->mfp_event.type = MfPlusPollerEventTypeReadSuccess; NfcCommand command = instance->callback(instance->general_event, instance->context); + return command; }