mirror of
https://github.com/DarkFlippers/unleashed-firmware.git
synced 2025-12-12 04:34:43 +04:00
ofw pr 4293 NFC FeliCa Improvement: Dump All Systems
by zinongli
This commit is contained in:
@@ -102,19 +102,21 @@ static void nfc_scene_read_success_on_enter_felica(NfcApp* instance) {
|
||||
temp_str, "\e#%s\n", nfc_device_get_name(device, NfcDeviceNameTypeFull));
|
||||
nfc_render_felica_info(data, NfcProtocolFormatTypeShort, temp_str);
|
||||
} else {
|
||||
bool all_unlocked = data->blocks_read == data->blocks_total;
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"\e#%s\n",
|
||||
all_unlocked ? "All Blocks Are Unlocked" : "Some Blocks Are Locked");
|
||||
nfc_render_felica_idm(data, NfcProtocolFormatTypeShort, temp_str);
|
||||
uint8_t* ck_data = instance->felica_auth->card_key.data;
|
||||
furi_string_cat_printf(temp_str, "Key:");
|
||||
for(uint8_t i = 0; i < 7; i++) {
|
||||
furi_string_cat_printf(temp_str, " %02X", ck_data[i]);
|
||||
if(i == 6) furi_string_cat_printf(temp_str, "...");
|
||||
if(data->workflow_type == FelicaLite) {
|
||||
bool all_unlocked = data->blocks_read == data->blocks_total;
|
||||
furi_string_cat_printf(
|
||||
temp_str,
|
||||
"\e#%s\n",
|
||||
all_unlocked ? "All Blocks Are Unlocked" : "Some Blocks Are Locked");
|
||||
nfc_render_felica_idm(data, NfcProtocolFormatTypeShort, temp_str);
|
||||
uint8_t* ck_data = instance->felica_auth->card_key.data;
|
||||
furi_string_cat_printf(temp_str, "Key:");
|
||||
for(uint8_t i = 0; i < 7; i++) {
|
||||
furi_string_cat_printf(temp_str, " %02X", ck_data[i]);
|
||||
if(i == 6) furi_string_cat_printf(temp_str, "...");
|
||||
}
|
||||
nfc_render_felica_blocks_count(data, temp_str, false);
|
||||
}
|
||||
nfc_render_felica_blocks_count(data, temp_str, false);
|
||||
}
|
||||
felica_auth_reset(instance->felica_auth);
|
||||
|
||||
@@ -124,6 +126,15 @@ static void nfc_scene_read_success_on_enter_felica(NfcApp* instance) {
|
||||
furi_string_free(temp_str);
|
||||
}
|
||||
|
||||
static bool nfc_scene_saved_menu_on_event_felica(NfcApp* instance, SceneManagerEvent event) {
|
||||
if(event.type == SceneManagerEventTypeCustom && event.event == SubmenuIndexCommonEdit) {
|
||||
scene_manager_next_scene(instance->scene_manager, NfcSceneSetUid);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void nfc_scene_emulate_on_enter_felica(NfcApp* instance) {
|
||||
const FelicaData* data = nfc_device_get_data(instance->nfc_device, NfcProtocolFelica);
|
||||
instance->listener = nfc_listener_alloc(instance->nfc, NfcProtocolFelica, data);
|
||||
@@ -183,7 +194,7 @@ const NfcProtocolSupportBase nfc_protocol_support_felica = {
|
||||
.scene_saved_menu =
|
||||
{
|
||||
.on_enter = nfc_protocol_support_common_on_enter_empty,
|
||||
.on_event = nfc_protocol_support_common_on_event_empty,
|
||||
.on_event = nfc_scene_saved_menu_on_event_felica,
|
||||
},
|
||||
.scene_save_name =
|
||||
{
|
||||
@@ -195,11 +206,4 @@ const NfcProtocolSupportBase nfc_protocol_support_felica = {
|
||||
.on_enter = nfc_scene_emulate_on_enter_felica,
|
||||
.on_event = nfc_protocol_support_common_on_event_empty,
|
||||
},
|
||||
.scene_write =
|
||||
{
|
||||
.on_enter = nfc_protocol_support_common_on_enter_empty,
|
||||
.on_event = nfc_protocol_support_common_on_event_empty,
|
||||
},
|
||||
};
|
||||
|
||||
NFC_PROTOCOL_SUPPORT_PLUGIN(felica, NfcProtocolFelica);
|
||||
|
||||
@@ -6,14 +6,10 @@ void nfc_render_felica_blocks_count(
|
||||
bool render_auth_notification) {
|
||||
if(data->workflow_type == FelicaLite) {
|
||||
furi_string_cat_printf(str, "Blocks: %u\n", data->blocks_total);
|
||||
|
||||
furi_string_cat_printf(str, "\nBlocks Read: %u/%u", data->blocks_read, data->blocks_total);
|
||||
if(render_auth_notification && data->blocks_read != data->blocks_total) {
|
||||
furi_string_cat_printf(str, "\nAuth-protected blocks!");
|
||||
}
|
||||
} else if(data->workflow_type == FelicaStandard) {
|
||||
furi_string_cat_printf(
|
||||
str, "Public blocks Read: %lu", simple_array_get_count(data->public_blocks));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,11 +50,7 @@ void nfc_render_felica_info(
|
||||
}
|
||||
|
||||
furi_string_cat_printf(str, "\n");
|
||||
furi_string_cat_printf(
|
||||
str,
|
||||
"Services found: %lu \nAreas found: %lu\n",
|
||||
simple_array_get_count(data->services),
|
||||
simple_array_get_count(data->areas));
|
||||
furi_string_cat_printf(str, "Systems found: %lu \n", simple_array_get_count(data->systems));
|
||||
|
||||
nfc_render_felica_blocks_count(data, str, true);
|
||||
}
|
||||
@@ -136,9 +128,9 @@ void nfc_more_info_render_felica_lite_dump(const FelicaData* data, FuriString* s
|
||||
nfc_render_felica_block(&data->data.fs.crc_check, str, "CRC_CHCK", 15, 17);
|
||||
}
|
||||
|
||||
void nfc_more_info_render_felica_dir(const FelicaData* data, FuriString* str) {
|
||||
const size_t area_count = simple_array_get_count(data->areas);
|
||||
const size_t service_count = simple_array_get_count(data->services);
|
||||
void nfc_more_info_render_felica_dir(const FelicaSystem* system, FuriString* str) {
|
||||
const size_t area_count = simple_array_get_count(system->areas);
|
||||
const size_t service_count = simple_array_get_count(system->services);
|
||||
|
||||
furi_string_cat_printf(str, "\e#Directory Tree:\n");
|
||||
|
||||
@@ -150,11 +142,12 @@ void nfc_more_info_render_felica_dir(const FelicaData* data, FuriString* str) {
|
||||
furi_string_cat_printf(
|
||||
str, "::: ... are readable services\n||| ... are locked services\n");
|
||||
}
|
||||
felica_write_directory_tree(data, str);
|
||||
felica_write_directory_tree(system, str);
|
||||
}
|
||||
|
||||
void nfc_more_info_render_felica_blocks(
|
||||
const FelicaData* data,
|
||||
const FelicaSystem* system,
|
||||
FuriString* str,
|
||||
const uint16_t service_code_key) {
|
||||
furi_string_cat_printf(str, "\n");
|
||||
@@ -190,9 +183,9 @@ void nfc_more_info_render_felica_blocks(
|
||||
nfc_render_felica_block(&data->data.fs.crc_check, str, "CRC_CHCK", 15, 17);
|
||||
|
||||
} else if(data->workflow_type == FelicaStandard) {
|
||||
uint32_t public_blocks_count = simple_array_get_count(data->public_blocks);
|
||||
uint32_t public_blocks_count = simple_array_get_count(system->public_blocks);
|
||||
for(size_t i = 0; i < public_blocks_count; i++) {
|
||||
FelicaPublicBlock* public_block = simple_array_get(data->public_blocks, i);
|
||||
FelicaPublicBlock* public_block = simple_array_get(system->public_blocks, i);
|
||||
if(public_block->service_code != service_code_key) {
|
||||
continue; // Skip blocks not matching the requested service code
|
||||
}
|
||||
|
||||
@@ -21,9 +21,10 @@ void nfc_render_felica_idm(
|
||||
NfcProtocolFormatType format_type,
|
||||
FuriString* str);
|
||||
|
||||
void nfc_more_info_render_felica_dir(const FelicaData* data, FuriString* str);
|
||||
void nfc_more_info_render_felica_dir(const FelicaSystem* system, FuriString* str);
|
||||
|
||||
void nfc_more_info_render_felica_blocks(
|
||||
const FelicaData* data,
|
||||
const FelicaSystem* system,
|
||||
FuriString* str,
|
||||
const uint16_t service_code_key);
|
||||
|
||||
@@ -70,5 +70,6 @@ ADD_SCENE(nfc, slix_unlock, SlixUnlock)
|
||||
ADD_SCENE(nfc, slix_unlock_success, SlixUnlockSuccess)
|
||||
|
||||
ADD_SCENE(nfc, felica_more_info, FelicaMoreInfo)
|
||||
ADD_SCENE(nfc, felica_system, FelicaSystem)
|
||||
|
||||
ADD_SCENE(nfc, generate_info, GenerateInfo)
|
||||
|
||||
@@ -9,7 +9,6 @@ enum {
|
||||
};
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexDirectory,
|
||||
SubmenuIndexDynamic, // dynamic indices start here
|
||||
};
|
||||
|
||||
@@ -21,33 +20,22 @@ void nfc_scene_felica_more_info_on_enter(void* context) {
|
||||
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneFelicaMoreInfo);
|
||||
const FelicaData* data = nfc_device_get_data(nfc->nfc_device, NfcProtocolFelica);
|
||||
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
"Directory",
|
||||
SubmenuIndexDirectory,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
nfc);
|
||||
|
||||
FuriString* label = furi_string_alloc();
|
||||
|
||||
switch(data->workflow_type) {
|
||||
case FelicaLite:
|
||||
furi_string_printf(label, "All blocks");
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
furi_string_get_cstr(label),
|
||||
SubmenuIndexDynamic,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
nfc);
|
||||
widget_reset(nfc->widget);
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
nfc_more_info_render_felica_lite_dump(data, temp_str);
|
||||
widget_add_text_scroll_element(nfc->widget, 0, 0, 128, 64, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
return;
|
||||
break;
|
||||
case FelicaStandard:
|
||||
for(uint32_t i = 0; i < simple_array_get_count(data->services); ++i) {
|
||||
const FelicaService* service = simple_array_cget(data->services, i);
|
||||
bool is_public = (service->attr & FELICA_SERVICE_ATTRIBUTE_UNAUTH_READ) == 1;
|
||||
if(!is_public) {
|
||||
continue;
|
||||
}
|
||||
furi_string_printf(label, "Readable serv %04X", service->code);
|
||||
FuriString* label = furi_string_alloc();
|
||||
|
||||
for(uint32_t i = 0; i < simple_array_get_count(data->systems); ++i) {
|
||||
const FelicaSystem* system = simple_array_cget(data->systems, i);
|
||||
furi_string_printf(label, "System %04X", system->system_code);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
furi_string_get_cstr(label),
|
||||
@@ -55,13 +43,12 @@ void nfc_scene_felica_more_info_on_enter(void* context) {
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
nfc);
|
||||
}
|
||||
furi_string_free(label);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
furi_string_free(label);
|
||||
|
||||
if(state >= FelicaMoreInfoStateItem) {
|
||||
submenu_set_selected_item(
|
||||
nfc->submenu, state - FelicaMoreInfoStateItem + SubmenuIndexDynamic);
|
||||
@@ -78,49 +65,16 @@ bool nfc_scene_felica_more_info_on_event(void* context, SceneManagerEvent event)
|
||||
|
||||
const uint32_t state =
|
||||
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneFelicaMoreInfo);
|
||||
const FelicaData* data = nfc_device_get_data(nfc->nfc_device, NfcProtocolFelica);
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexDirectory) {
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
nfc_more_info_render_felica_dir(data, temp_str);
|
||||
const uint32_t index = event.event - SubmenuIndexDynamic;
|
||||
|
||||
widget_add_text_scroll_element(
|
||||
nfc->widget, 0, 0, 128, 64, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneFelicaMoreInfo, FelicaMoreInfoStateItem + index);
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneFelicaSystem, index << 4);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneFelicaSystem);
|
||||
consumed = true;
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager,
|
||||
NfcSceneFelicaMoreInfo,
|
||||
FelicaMoreInfoStateItem + SubmenuIndexDirectory);
|
||||
consumed = true;
|
||||
} else {
|
||||
const uint16_t service_ind = event.event - 1; // offset the three enums above
|
||||
|
||||
text_box_reset(nfc->text_box);
|
||||
furi_string_reset(nfc->text_box_store);
|
||||
|
||||
switch(data->workflow_type) {
|
||||
case FelicaLite:
|
||||
nfc_more_info_render_felica_lite_dump(data, nfc->text_box_store);
|
||||
break;
|
||||
case FelicaStandard:
|
||||
const FelicaService* service = simple_array_cget(data->services, service_ind);
|
||||
furi_string_cat_printf(nfc->text_box_store, "Service 0x%04X\n", service->code);
|
||||
nfc_more_info_render_felica_blocks(data, nfc->text_box_store, service->code);
|
||||
break;
|
||||
default:
|
||||
furi_string_set_str(nfc->text_box_store, "IC type not implemented yet");
|
||||
break;
|
||||
}
|
||||
text_box_set_font(nfc->text_box, TextBoxFontHex);
|
||||
text_box_set_text(nfc->text_box, furi_string_get_cstr(nfc->text_box_store));
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextBox);
|
||||
scene_manager_set_scene_state(
|
||||
nfc->scene_manager, NfcSceneFelicaMoreInfo, FelicaMoreInfoStateItem + event.event);
|
||||
consumed = true;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
if(state >= FelicaMoreInfoStateItem) {
|
||||
widget_reset(nfc->widget);
|
||||
|
||||
114
applications/main/nfc/scenes/nfc_scene_felica_system.c
Normal file
114
applications/main/nfc/scenes/nfc_scene_felica_system.c
Normal file
@@ -0,0 +1,114 @@
|
||||
#include "../nfc_app_i.h"
|
||||
|
||||
#include "../helpers/protocol_support/nfc_protocol_support_gui_common.h"
|
||||
#include "../helpers/protocol_support/felica/felica_render.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexDirectory,
|
||||
SubmenuIndexDynamic, // dynamic indices start here
|
||||
};
|
||||
|
||||
static void nfc_scene_felica_system_submenu_callback(void* context, uint32_t index) {
|
||||
NfcApp* nfc = context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void nfc_scene_felica_system_on_enter(void* context) {
|
||||
NfcApp* nfc = context;
|
||||
Submenu* submenu = nfc->submenu;
|
||||
submenu_reset(nfc->submenu);
|
||||
|
||||
const uint32_t system_index =
|
||||
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneFelicaSystem) >> 4;
|
||||
const FelicaData* data = nfc_device_get_data(nfc->nfc_device, NfcProtocolFelica);
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Directory", SubmenuIndexDirectory, nfc_scene_felica_system_submenu_callback, nfc);
|
||||
|
||||
FuriString* label = furi_string_alloc();
|
||||
|
||||
const FelicaSystem* system = simple_array_cget(data->systems, system_index);
|
||||
for(uint32_t i = 0; i < simple_array_get_count(system->services); ++i) {
|
||||
const FelicaService* service = simple_array_cget(system->services, i);
|
||||
bool is_public = (service->attr & FELICA_SERVICE_ATTRIBUTE_UNAUTH_READ) == 1;
|
||||
if(!is_public) {
|
||||
continue;
|
||||
}
|
||||
furi_string_printf(label, "Readable serv %04X", service->code);
|
||||
submenu_add_item(
|
||||
submenu,
|
||||
furi_string_get_cstr(label),
|
||||
i + SubmenuIndexDynamic,
|
||||
nfc_protocol_support_common_submenu_callback,
|
||||
nfc);
|
||||
}
|
||||
|
||||
furi_string_free(label);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
||||
bool nfc_scene_felica_system_on_event(void* context, SceneManagerEvent event) {
|
||||
NfcApp* nfc = context;
|
||||
bool consumed = false;
|
||||
|
||||
const uint32_t state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneFelicaSystem);
|
||||
const FelicaData* data = nfc_device_get_data(nfc->nfc_device, NfcProtocolFelica);
|
||||
|
||||
const uint32_t system_index = state >> 4;
|
||||
const FelicaSystem* system = simple_array_cget(data->systems, system_index);
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == NfcCustomEventViewExit) {
|
||||
consumed = scene_manager_previous_scene(nfc->scene_manager);
|
||||
} else {
|
||||
if(event.event == SubmenuIndexDirectory) {
|
||||
FuriString* temp_str = furi_string_alloc();
|
||||
nfc_more_info_render_felica_dir(system, temp_str);
|
||||
|
||||
widget_add_text_scroll_element(
|
||||
nfc->widget, 0, 0, 128, 64, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
} else {
|
||||
const uint32_t service_ind =
|
||||
event.event - SubmenuIndexDynamic; // offset the three enums above
|
||||
|
||||
text_box_reset(nfc->text_box);
|
||||
furi_string_reset(nfc->text_box_store);
|
||||
|
||||
const FelicaService* service = simple_array_cget(system->services, service_ind);
|
||||
furi_string_cat_printf(nfc->text_box_store, "Service 0x%04X\n", service->code);
|
||||
nfc_more_info_render_felica_blocks(
|
||||
data, system, nfc->text_box_store, service->code);
|
||||
|
||||
text_box_set_font(nfc->text_box, TextBoxFontHex);
|
||||
text_box_set_text(nfc->text_box, furi_string_get_cstr(nfc->text_box_store));
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextBox);
|
||||
}
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneFelicaSystem, state | 1);
|
||||
consumed = true;
|
||||
}
|
||||
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
if(state & 1) {
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu);
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneFelicaSystem, state & ~1);
|
||||
consumed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_felica_system_on_exit(void* context) {
|
||||
NfcApp* nfc = context;
|
||||
|
||||
// Clear views
|
||||
widget_reset(nfc->widget);
|
||||
text_box_reset(nfc->text_box);
|
||||
furi_string_reset(nfc->text_box_store);
|
||||
submenu_reset(nfc->submenu);
|
||||
}
|
||||
Reference in New Issue
Block a user