From e3f7e1c2d3c6db75428cf41376a69b0208650467 Mon Sep 17 00:00:00 2001 From: Willy-JL <49810075+Willy-JL@users.noreply.github.com> Date: Thu, 6 Mar 2025 02:54:40 +0000 Subject: [PATCH] NFC: Implement Type 4 Tag NDEF parsing --- applications/main/nfc/application.fam | 10 ++++ .../main/nfc/plugins/supported_cards/ndef.c | 51 ++++++++++++++++++- 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/applications/main/nfc/application.fam b/applications/main/nfc/application.fam index 29bdf390a..11dca519a 100644 --- a/applications/main/nfc/application.fam +++ b/applications/main/nfc/application.fam @@ -247,6 +247,16 @@ App( sources=["plugins/supported_cards/ndef.c"], ) +App( + appid="ndef_t4t_parser", + apptype=FlipperAppType.PLUGIN, + cdefines=[("NDEF_PROTO", "NDEF_PROTO_T4T")], + entry_point="ndef_plugin_ep", + targets=["f7"], + requires=["nfc"], + sources=["plugins/supported_cards/ndef.c"], +) + App( appid="disney_infinity_parser", apptype=FlipperAppType.PLUGIN, diff --git a/applications/main/nfc/plugins/supported_cards/ndef.c b/applications/main/nfc/plugins/supported_cards/ndef.c index fb2c4da48..2b7ea2dbc 100644 --- a/applications/main/nfc/plugins/supported_cards/ndef.c +++ b/applications/main/nfc/plugins/supported_cards/ndef.c @@ -20,6 +20,7 @@ #include #include #include +#include #include @@ -30,7 +31,8 @@ #define NDEF_PROTO_UL (1) #define NDEF_PROTO_MFC (2) #define NDEF_PROTO_SLIX (3) -#define NDEF_PROTO_TOTAL (4) +#define NDEF_PROTO_T4T (4) +#define NDEF_PROTO_TOTAL (5) #ifndef NDEF_PROTO #error Must specify what protocol to use with NDEF_PROTO define! @@ -150,6 +152,11 @@ typedef struct { const uint8_t* start; size_t size; } slix; +#elif NDEF_PROTO == NDEF_PROTO_T4T + struct { + const uint8_t* data; + size_t size; + } t4t; #endif } Ndef; @@ -225,6 +232,13 @@ static bool ndef_get(Ndef* ndef, size_t pos, size_t len, void* buf) { memcpy(buf, ndef->slix.start + pos, len); return true; +#elif NDEF_PROTO == NDEF_PROTO_T4T + + // Memory space is contiguous, simply need to remap to data pointer + if(pos + len > ndef->t4t.size) return false; + memcpy(buf, ndef->t4t.data + pos, len); + return true; + #else UNUSED(ndef); @@ -1030,6 +1044,38 @@ static bool ndef_slix_parse(const NfcDevice* device, FuriString* parsed_data) { return parsed > 0; } +#elif NDEF_PROTO == NDEF_PROTO_T4T + +static bool ndef_t4t_parse(const NfcDevice* device, FuriString* parsed_data) { + furi_assert(device); + furi_assert(parsed_data); + + const Type4TagData* data = nfc_device_get_data(device, NfcProtocolType4Tag); + size_t data_start = 0; + size_t data_size = simple_array_get_count(data->ndef_data); + + NDEF_TITLE(device, parsed_data); + + Ndef ndef = { + .output = parsed_data, + .t4t = + { + .data = data_size == 0 ? NULL : simple_array_cget_data(data->ndef_data), + .size = data_size, + }, + }; + size_t parsed = ndef_parse_message(&ndef, data_start, data_size - data_start, 1, false); + + if(parsed) { + furi_string_trim(parsed_data, "\n"); + furi_string_cat(parsed_data, "\n"); + } else { + furi_string_reset(parsed_data); + } + + return parsed > 0; +} + #endif // ---=== boilerplate ===--- @@ -1047,6 +1093,9 @@ static const NfcSupportedCardsPlugin ndef_plugin = { #elif NDEF_PROTO == NDEF_PROTO_SLIX .parse = ndef_slix_parse, .protocol = NfcProtocolSlix, +#elif NDEF_PROTO == NDEF_PROTO_T4T + .parse = ndef_t4t_parse, + .protocol = NfcProtocolType4Tag, #endif };