From 0d0d8d76b2f0b1ad438ef6d15a1b902dbb33b53d Mon Sep 17 00:00:00 2001 From: Markus Birth Date: Sat, 28 Mar 2026 20:20:21 +0000 Subject: [PATCH] Read Mifare Ultralight data Signed-off-by: Markus Birth --- scenes/sonicare_scene_read.c | 22 +++++++++++++++++----- scenes/sonicare_scene_read_complete.c | 9 +++++---- uk_mbirth_sonicare.h | 2 ++ 3 files changed, 24 insertions(+), 9 deletions(-) diff --git a/scenes/sonicare_scene_read.c b/scenes/sonicare_scene_read.c index 1e9dd86..1893b36 100644 --- a/scenes/sonicare_scene_read.c +++ b/scenes/sonicare_scene_read.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -25,13 +26,23 @@ void nfc_scene_detect_scan_callback(NfcScannerEvent event, void* context) { } NfcCommand nfc_scene_poller_callback(NfcGenericEvent event, void* context) { - furi_assert(event.protocol == NfcProtocolIso14443_3a); + //furi_assert(event.protocol == NfcProtocolIso14443_3a); + furi_assert(event.protocol == NfcProtocolMfUltralight); Sonicare* app = context; - const Iso14443_3aPollerEvent* ev = event.event_data; + //const Iso14443_3aPollerEvent* ev = event.event_data; + const MfUltralightPollerEvent* ev = event.event_data; - if (ev->type == Iso14443_3aPollerEventTypeReady) { - nfc_device_set_data(app->nfc_device, NfcProtocolIso14443_3a, nfc_poller_get_data(app->poller)); + //if (ev->type == Iso14443_3aPollerEventTypeReady) { + if (ev->type == MfUltralightPollerEventTypeReadSuccess) { + FURI_LOG_I("sonicare_scene_read", "NFC Poller reports Read Success"); + //nfc_device_set_data(app->nfc_device, NfcProtocolIso14443_3a, nfc_poller_get_data(app->poller)); + nfc_device_set_data(app->nfc_device, NfcProtocolMfUltralight, nfc_poller_get_data(app->poller)); + FURI_LOG_D("sonicare_scene_read", "Pulling Mifare Ultralight data from poller"); + const MfUltralightData* ul_data = nfc_device_get_data(app->nfc_device, NfcProtocolMfUltralight); + app->nfc_data = ul_data; + + FURI_LOG_I("sonicare_scene_read", "Dataset has %i of %i pages read from Mifare Ultralight", ul_data->pages_read, ul_data->pages_total); view_dispatcher_send_custom_event(app->view_dispatcher, NfcCustomEventWorkerExit); return NfcCommandStop; } @@ -55,7 +66,8 @@ void sonicare_scene_read_on_enter(void* context) { // we probably don't need to "scan" but can instead directly "poll" for NTAG213 (ISO 14443-3a) data //app->scanner = nfc_scanner_alloc(app->nfc); //nfc_scanner_start(app->scanner, nfc_scene_detect_scan_callback, app); - app->poller = nfc_poller_alloc(app->nfc, NfcProtocolIso14443_3a); + //app->poller = nfc_poller_alloc(app->nfc, NfcProtocolIso14443_3a); + app->poller = nfc_poller_alloc(app->nfc, NfcProtocolMfUltralight); nfc_poller_start(app->poller, nfc_scene_poller_callback, app); } diff --git a/scenes/sonicare_scene_read_complete.c b/scenes/sonicare_scene_read_complete.c index 28fa704..76cc128 100644 --- a/scenes/sonicare_scene_read_complete.c +++ b/scenes/sonicare_scene_read_complete.c @@ -7,6 +7,7 @@ #include #include #include +#include "nfc/protocols/mf_ultralight/mf_ultralight.h" #include #include @@ -25,14 +26,14 @@ void sonicare_scene_read_complete_on_enter(void* context) { widget_reset(widget); const NfcDevice* nfc_device = app->nfc_device; - const Iso14443_3aData* nfc_data = nfc_device_get_data(nfc_device, NfcProtocolIso14443_3a); + FURI_LOG_D("sonicare_scene_read_complete", "Pulling Mifare Ultralight data from NFC device"); + const MfUltralightData* ul_data = app->nfc_data; - UNUSED(nfc_data); + UNUSED(ul_data); FuriString* temp_str = furi_string_alloc(); furi_string_cat_printf(temp_str, "\e#%s\n", nfc_device_get_name(nfc_device, NfcDeviceNameTypeFull)); - widget_add_text_scroll_element(widget, 0, 0, 128, 64, furi_string_get_cstr(temp_str)); furi_string_free(temp_str); @@ -53,7 +54,7 @@ bool sonicare_scene_read_complete_on_event(void* context, SceneManagerEvent even } } else if (event.type == SceneManagerEventTypeBack) { // Back button pressed - consumed = true; + //consumed = true; } return consumed; diff --git a/uk_mbirth_sonicare.h b/uk_mbirth_sonicare.h index 6da58aa..912e38f 100644 --- a/uk_mbirth_sonicare.h +++ b/uk_mbirth_sonicare.h @@ -29,6 +29,7 @@ #include #include #include +#include typedef struct Sonicare Sonicare; @@ -54,6 +55,7 @@ struct Sonicare { NfcScanner* scanner; NfcListener* listener; NfcDevice* nfc_device; + const MfUltralightData* nfc_data; }; typedef enum {