mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-25 03:29:58 -07:00
NFC refactoring (#3050)
"A long time ago in a galaxy far, far away...." we started NFC subsystem refactoring. Starring: - @gornekich - NFC refactoring project lead, architect, senior developer - @gsurkov - architect, senior developer - @RebornedBrain - senior developer Supporting roles: - @skotopes, @DrZlo13, @hedger - general architecture advisors, code review - @Astrrra, @doomwastaken, @Hellitron, @ImagineVagon333 - quality assurance Special thanks: @bettse, @pcunning, @nxv, @noproto, @AloneLiberty and everyone else who has been helping us all this time and contributing valuable knowledges, ideas and source code.
This commit is contained in:
141
applications/main/nfc/helpers/protocol_support/slix/slix.c
Normal file
141
applications/main/nfc/helpers/protocol_support/slix/slix.c
Normal file
@@ -0,0 +1,141 @@
|
||||
#include "slix.h"
|
||||
#include "slix_render.h"
|
||||
|
||||
#include <nfc/protocols/slix/slix_poller.h>
|
||||
#include <nfc/protocols/slix/slix_listener.h>
|
||||
|
||||
#include "nfc/nfc_app_i.h"
|
||||
|
||||
#include "../nfc_protocol_support_common.h"
|
||||
#include "../nfc_protocol_support_gui_common.h"
|
||||
|
||||
static void nfc_scene_info_on_enter_slix(NfcApp* instance) {
|
||||
const NfcDevice* device = instance->nfc_device;
|
||||
const SlixData* data = nfc_device_get_data(device, NfcProtocolSlix);
|
||||
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
furi_string_cat_printf(
|
||||
temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
|
||||
nfc_render_slix_info(data, NfcProtocolFormatTypeFull, temp_str);
|
||||
|
||||
widget_add_text_scroll_element(
|
||||
instance->widget, 0, 0, 128, 64, furi_string_get_cstr(temp_str));
|
||||
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
|
||||
static NfcCommand nfc_scene_read_poller_callback_slix(NfcGenericEvent event, void* context) {
|
||||
furi_assert(event.protocol == NfcProtocolSlix);
|
||||
|
||||
NfcApp* instance = context;
|
||||
const SlixPollerEvent* slix_event = event.event_data;
|
||||
|
||||
if(slix_event->type == SlixPollerEventTypeReady) {
|
||||
nfc_device_set_data(
|
||||
instance->nfc_device, NfcProtocolSlix, nfc_poller_get_data(instance->poller));
|
||||
view_dispatcher_send_custom_event(instance->view_dispatcher, NfcCustomEventPollerSuccess);
|
||||
return NfcCommandStop;
|
||||
}
|
||||
|
||||
return NfcCommandContinue;
|
||||
}
|
||||
|
||||
static void nfc_scene_read_on_enter_slix(NfcApp* instance) {
|
||||
nfc_poller_start(instance->poller, nfc_scene_read_poller_callback_slix, instance);
|
||||
}
|
||||
|
||||
static void nfc_scene_read_success_on_enter_slix(NfcApp* instance) {
|
||||
const NfcDevice* device = instance->nfc_device;
|
||||
const SlixData* data = nfc_device_get_data(device, NfcProtocolSlix);
|
||||
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
furi_string_cat_printf(
|
||||
temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
|
||||
nfc_render_slix_info(data, NfcProtocolFormatTypeShort, temp_str);
|
||||
|
||||
widget_add_text_scroll_element(
|
||||
instance->widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
||||
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
|
||||
static NfcCommand nfc_scene_emulate_listener_callback_slix(NfcGenericEvent event, void* context) {
|
||||
furi_assert(context);
|
||||
furi_assert(event.protocol == NfcProtocolSlix);
|
||||
furi_assert(event.event_data);
|
||||
|
||||
NfcApp* nfc = context;
|
||||
SlixListenerEvent* slix_event = event.event_data;
|
||||
|
||||
if(slix_event->type == SlixListenerEventTypeCustomCommand) {
|
||||
if(furi_string_size(nfc->text_box_store) < NFC_LOG_SIZE_MAX) {
|
||||
furi_string_cat_printf(nfc->text_box_store, "R:");
|
||||
for(size_t i = 0; i < bit_buffer_get_size_bytes(slix_event->data->buffer); i++) {
|
||||
furi_string_cat_printf(
|
||||
nfc->text_box_store,
|
||||
" %02X",
|
||||
bit_buffer_get_byte(slix_event->data->buffer, i));
|
||||
}
|
||||
furi_string_push_back(nfc->text_box_store, '\n');
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventListenerUpdate);
|
||||
}
|
||||
}
|
||||
|
||||
return NfcCommandContinue;
|
||||
}
|
||||
|
||||
static void nfc_scene_emulate_on_enter_slix(NfcApp* instance) {
|
||||
const SlixData* data = nfc_device_get_data(instance->nfc_device, NfcProtocolSlix);
|
||||
|
||||
instance->listener = nfc_listener_alloc(instance->nfc, NfcProtocolSlix, data);
|
||||
nfc_listener_start(instance->listener, nfc_scene_emulate_listener_callback_slix, instance);
|
||||
}
|
||||
|
||||
static bool nfc_scene_saved_menu_on_event_slix(NfcApp* instance, uint32_t event) {
|
||||
if(event == SubmenuIndexCommonEdit) {
|
||||
scene_manager_next_scene(instance->scene_manager, NfcSceneSetUid);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const NfcProtocolSupportBase nfc_protocol_support_slix = {
|
||||
.features = NfcProtocolFeatureEmulateFull,
|
||||
|
||||
.scene_info =
|
||||
{
|
||||
.on_enter = nfc_scene_info_on_enter_slix,
|
||||
.on_event = nfc_protocol_support_common_on_event_empty,
|
||||
},
|
||||
.scene_read =
|
||||
{
|
||||
.on_enter = nfc_scene_read_on_enter_slix,
|
||||
.on_event = nfc_protocol_support_common_on_event_empty,
|
||||
},
|
||||
.scene_read_menu =
|
||||
{
|
||||
.on_enter = nfc_protocol_support_common_on_enter_empty,
|
||||
.on_event = nfc_protocol_support_common_on_event_empty,
|
||||
},
|
||||
.scene_read_success =
|
||||
{
|
||||
.on_enter = nfc_scene_read_success_on_enter_slix,
|
||||
.on_event = nfc_protocol_support_common_on_event_empty,
|
||||
},
|
||||
.scene_saved_menu =
|
||||
{
|
||||
.on_enter = nfc_protocol_support_common_on_enter_empty,
|
||||
.on_event = nfc_scene_saved_menu_on_event_slix,
|
||||
},
|
||||
.scene_save_name =
|
||||
{
|
||||
.on_enter = nfc_protocol_support_common_on_enter_empty,
|
||||
.on_event = nfc_protocol_support_common_on_event_empty,
|
||||
},
|
||||
.scene_emulate =
|
||||
{
|
||||
.on_enter = nfc_scene_emulate_on_enter_slix,
|
||||
.on_event = nfc_protocol_support_common_on_event_empty,
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "../nfc_protocol_support_base.h"
|
||||
|
||||
extern const NfcProtocolSupportBase nfc_protocol_support_slix;
|
||||
@@ -0,0 +1,74 @@
|
||||
#include "slix_render.h"
|
||||
|
||||
#include "../iso15693_3/iso15693_3_render.h"
|
||||
|
||||
void nfc_render_slix_info(const SlixData* data, NfcProtocolFormatType format_type, FuriString* str) {
|
||||
nfc_render_iso15693_3_brief(slix_get_base_data(data), str);
|
||||
|
||||
if(format_type != NfcProtocolFormatTypeFull) return;
|
||||
const SlixType slix_type = slix_get_type(data);
|
||||
|
||||
furi_string_cat(str, "\n\e#Passwords\n");
|
||||
|
||||
static const char* slix_password_names[] = {
|
||||
"Read",
|
||||
"Write",
|
||||
"Privacy",
|
||||
"Destroy",
|
||||
"EAS/AFI",
|
||||
};
|
||||
|
||||
for(uint32_t i = 0; i < SlixPasswordTypeCount; ++i) {
|
||||
if(slix_type_supports_password(slix_type, i)) {
|
||||
furi_string_cat_printf(
|
||||
str, "%s : %08lX\n", slix_password_names[i], data->passwords[i]);
|
||||
}
|
||||
}
|
||||
|
||||
furi_string_cat(str, "\e#Lock bits\n");
|
||||
|
||||
if(slix_type_has_features(slix_type, SLIX_TYPE_FEATURE_EAS)) {
|
||||
furi_string_cat_printf(
|
||||
str, "EAS: %s locked\n", data->system_info.lock_bits.eas ? "" : "not");
|
||||
}
|
||||
|
||||
if(slix_type_has_features(slix_type, SLIX_TYPE_FEATURE_PROTECTION)) {
|
||||
furi_string_cat_printf(
|
||||
str, "PPL: %s locked\n", data->system_info.lock_bits.ppl ? "" : "not");
|
||||
|
||||
const SlixProtection protection = data->system_info.protection;
|
||||
|
||||
furi_string_cat(str, "\e#Page protection\n");
|
||||
furi_string_cat_printf(str, "Pointer: H >= %02X\n", protection.pointer);
|
||||
|
||||
const char* rh = (protection.condition & SLIX_PP_CONDITION_RH) ? "" : "un";
|
||||
const char* rl = (protection.condition & SLIX_PP_CONDITION_RL) ? "" : "un";
|
||||
|
||||
const char* wh = (protection.condition & SLIX_PP_CONDITION_WH) ? "" : "un";
|
||||
const char* wl = (protection.condition & SLIX_PP_CONDITION_WL) ? "" : "un";
|
||||
|
||||
furi_string_cat_printf(str, "R: H %sprotec. L %sprotec.\n", rh, rl);
|
||||
furi_string_cat_printf(str, "W: H %sprotec. L %sprotec.\n", wh, wl);
|
||||
}
|
||||
|
||||
if(slix_type_has_features(slix_type, SLIX_TYPE_FEATURE_PRIVACY)) {
|
||||
furi_string_cat(str, "\e#Privacy\n");
|
||||
furi_string_cat_printf(str, "Privacy mode: %sabled\n", data->privacy ? "en" : "dis");
|
||||
}
|
||||
|
||||
if(slix_type_has_features(slix_type, SLIX_TYPE_FEATURE_SIGNATURE)) {
|
||||
furi_string_cat(str, "\e#Signature\n");
|
||||
for(uint32_t i = 0; i < 4; ++i) {
|
||||
furi_string_cat_printf(str, "%02X ", data->signature[i]);
|
||||
}
|
||||
|
||||
furi_string_cat(str, "[ ... ]");
|
||||
|
||||
for(uint32_t i = 0; i < 3; ++i) {
|
||||
furi_string_cat_printf(str, " %02X", data->signature[sizeof(SlixSignature) - i - 1]);
|
||||
}
|
||||
}
|
||||
|
||||
furi_string_cat(str, "\n\e#ISO15693-3 data");
|
||||
nfc_render_iso15693_3_extra(slix_get_base_data(data), str);
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <nfc/protocols/slix/slix.h>
|
||||
|
||||
#include "../nfc_protocol_support_render_common.h"
|
||||
|
||||
void nfc_render_slix_info(const SlixData* data, NfcProtocolFormatType format_type, FuriString* str);
|
||||
Reference in New Issue
Block a user