mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-20 04:54:45 -07:00
NFC: Implement Type 4 Tag NDEF parsing
This commit is contained in:
@@ -247,6 +247,16 @@ App(
|
|||||||
sources=["plugins/supported_cards/ndef.c"],
|
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(
|
App(
|
||||||
appid="disney_infinity_parser",
|
appid="disney_infinity_parser",
|
||||||
apptype=FlipperAppType.PLUGIN,
|
apptype=FlipperAppType.PLUGIN,
|
||||||
|
|||||||
@@ -20,6 +20,7 @@
|
|||||||
#include <nfc/protocols/mf_ultralight/mf_ultralight.h>
|
#include <nfc/protocols/mf_ultralight/mf_ultralight.h>
|
||||||
#include <nfc/protocols/mf_classic/mf_classic.h>
|
#include <nfc/protocols/mf_classic/mf_classic.h>
|
||||||
#include <nfc/protocols/slix/slix.h>
|
#include <nfc/protocols/slix/slix.h>
|
||||||
|
#include <nfc/protocols/type_4_tag/type_4_tag.h>
|
||||||
|
|
||||||
#include <bit_lib.h>
|
#include <bit_lib.h>
|
||||||
|
|
||||||
@@ -30,7 +31,8 @@
|
|||||||
#define NDEF_PROTO_UL (1)
|
#define NDEF_PROTO_UL (1)
|
||||||
#define NDEF_PROTO_MFC (2)
|
#define NDEF_PROTO_MFC (2)
|
||||||
#define NDEF_PROTO_SLIX (3)
|
#define NDEF_PROTO_SLIX (3)
|
||||||
#define NDEF_PROTO_TOTAL (4)
|
#define NDEF_PROTO_T4T (4)
|
||||||
|
#define NDEF_PROTO_TOTAL (5)
|
||||||
|
|
||||||
#ifndef NDEF_PROTO
|
#ifndef NDEF_PROTO
|
||||||
#error Must specify what protocol to use with NDEF_PROTO define!
|
#error Must specify what protocol to use with NDEF_PROTO define!
|
||||||
@@ -150,6 +152,11 @@ typedef struct {
|
|||||||
const uint8_t* start;
|
const uint8_t* start;
|
||||||
size_t size;
|
size_t size;
|
||||||
} slix;
|
} slix;
|
||||||
|
#elif NDEF_PROTO == NDEF_PROTO_T4T
|
||||||
|
struct {
|
||||||
|
const uint8_t* data;
|
||||||
|
size_t size;
|
||||||
|
} t4t;
|
||||||
#endif
|
#endif
|
||||||
} Ndef;
|
} 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);
|
memcpy(buf, ndef->slix.start + pos, len);
|
||||||
return true;
|
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
|
#else
|
||||||
|
|
||||||
UNUSED(ndef);
|
UNUSED(ndef);
|
||||||
@@ -1030,6 +1044,38 @@ static bool ndef_slix_parse(const NfcDevice* device, FuriString* parsed_data) {
|
|||||||
return parsed > 0;
|
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
|
#endif
|
||||||
|
|
||||||
// ---=== boilerplate ===---
|
// ---=== boilerplate ===---
|
||||||
@@ -1047,6 +1093,9 @@ static const NfcSupportedCardsPlugin ndef_plugin = {
|
|||||||
#elif NDEF_PROTO == NDEF_PROTO_SLIX
|
#elif NDEF_PROTO == NDEF_PROTO_SLIX
|
||||||
.parse = ndef_slix_parse,
|
.parse = ndef_slix_parse,
|
||||||
.protocol = NfcProtocolSlix,
|
.protocol = NfcProtocolSlix,
|
||||||
|
#elif NDEF_PROTO == NDEF_PROTO_T4T
|
||||||
|
.parse = ndef_t4t_parse,
|
||||||
|
.protocol = NfcProtocolType4Tag,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user