Skip to content

Commit

Permalink
Merge remote-tracking branch 'RebornedBrain/reborned/scene_info_rewor…
Browse files Browse the repository at this point in the history
…k' into nfc_refactors_fixes_merge
  • Loading branch information
xMasterX committed Jan 30, 2024
2 parents 67eb679 + 7a89789 commit e702cde
Show file tree
Hide file tree
Showing 16 changed files with 140 additions and 76 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ 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, uint32_t event) {
if(event == SubmenuIndexCommonEdit) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,8 @@ static void nfc_scene_emulate_on_enter_iso14443_3a(NfcApp* instance) {
instance->listener, nfc_scene_emulate_listener_callback_iso14443_3a, instance);
}

static bool nfc_scene_read_menu_on_event_iso14443_3a(NfcApp* instance, uint32_t event) {
if(event == SubmenuIndexCommonEmulate) {
static bool nfc_scene_read_menu_on_event_iso14443_3a(NfcApp* instance, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom && event.event == SubmenuIndexCommonEmulate) {
scene_manager_next_scene(instance->scene_manager, NfcSceneEmulate);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,16 +60,16 @@ static void nfc_scene_read_success_on_enter_iso14443_3b(NfcApp* instance) {
furi_string_free(temp_str);
}

bool nfc_scene_saved_menu_on_event_iso14443_3b_common(NfcApp* instance, uint32_t event) {
if(event == SubmenuIndexCommonEdit) {
bool nfc_scene_saved_menu_on_event_iso14443_3b_common(NfcApp* instance, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom && event.event == SubmenuIndexCommonEdit) {
scene_manager_next_scene(instance->scene_manager, NfcSceneSetUid);
return true;
}

return false;
}

static bool nfc_scene_saved_menu_on_event_iso14443_3b(NfcApp* instance, uint32_t event) {
static bool nfc_scene_saved_menu_on_event_iso14443_3b(NfcApp* instance, SceneManagerEvent event) {
return nfc_scene_saved_menu_on_event_iso14443_3b_common(instance, event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@

#include "iso14443_3b.h"

bool nfc_scene_saved_menu_on_event_iso14443_3b_common(NfcApp* instance, uint32_t event);
bool nfc_scene_saved_menu_on_event_iso14443_3b_common(NfcApp* instance, SceneManagerEvent event);
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ static void nfc_scene_emulate_on_enter_iso14443_4a(NfcApp* instance) {
instance->listener, nfc_scene_emulate_listener_callback_iso14443_4a, instance);
}

static bool nfc_scene_read_menu_on_event_iso14443_4a(NfcApp* instance, uint32_t event) {
if(event == SubmenuIndexCommonEmulate) {
static bool nfc_scene_read_menu_on_event_iso14443_4a(NfcApp* instance, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom && event.event == SubmenuIndexCommonEmulate) {
scene_manager_next_scene(instance->scene_manager, NfcSceneEmulate);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ static void nfc_scene_saved_menu_on_enter_iso14443_4b(NfcApp* instance) {
UNUSED(instance);
}

static bool nfc_scene_read_menu_on_event_iso14443_4b(NfcApp* instance, uint32_t event) {
if(event == SubmenuIndexCommonEmulate) {
static bool nfc_scene_read_menu_on_event_iso14443_4b(NfcApp* instance, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom && event.event == SubmenuIndexCommonEmulate) {
scene_manager_next_scene(instance->scene_manager, NfcSceneEmulate);
return true;
}

return false;
}

static bool nfc_scene_saved_menu_on_event_iso14443_4b(NfcApp* instance, uint32_t event) {
static bool nfc_scene_saved_menu_on_event_iso14443_4b(NfcApp* instance, SceneManagerEvent event) {
return nfc_scene_saved_menu_on_event_iso14443_3b_common(instance, event);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ static void nfc_scene_emulate_on_enter_iso15693_3(NfcApp* instance) {
instance->listener, nfc_scene_emulate_listener_callback_iso15693_3, instance);
}

static bool nfc_scene_saved_menu_on_event_iso15693_3(NfcApp* instance, uint32_t event) {
if(event == SubmenuIndexCommonEdit) {
static bool nfc_scene_saved_menu_on_event_iso15693_3(NfcApp* instance, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom && event.event == SubmenuIndexCommonEdit) {
scene_manager_next_scene(instance->scene_manager, NfcSceneSetUid);
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ static void nfc_scene_read_on_enter_mf_classic(NfcApp* instance) {
nfc_poller_start(instance->poller, nfc_scene_read_poller_callback_mf_classic, instance);
}

static bool nfc_scene_read_on_event_mf_classic(NfcApp* instance, uint32_t event) {
if(event == NfcCustomEventPollerIncomplete) {
static bool nfc_scene_read_on_event_mf_classic(NfcApp* instance, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom &&
event.event == NfcCustomEventPollerIncomplete) {
scene_manager_next_scene(instance->scene_manager, NfcSceneMfClassicDictAttack);
}

Expand Down Expand Up @@ -171,8 +172,8 @@ static void nfc_scene_emulate_on_enter_mf_classic(NfcApp* instance) {
nfc_listener_start(instance->listener, NULL, NULL);
}

static bool nfc_scene_read_menu_on_event_mf_classic(NfcApp* instance, uint32_t event) {
if(event == SubmenuIndexDetectReader) {
static bool nfc_scene_read_menu_on_event_mf_classic(NfcApp* instance, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom && event.event == SubmenuIndexDetectReader) {
scene_manager_next_scene(instance->scene_manager, NfcSceneSaveConfirm);
dolphin_deed(DolphinDeedNfcDetectReader);
return true;
Expand All @@ -181,27 +182,29 @@ static bool nfc_scene_read_menu_on_event_mf_classic(NfcApp* instance, uint32_t e
return false;
}

static bool nfc_scene_saved_menu_on_event_mf_classic(NfcApp* instance, uint32_t event) {
static bool nfc_scene_saved_menu_on_event_mf_classic(NfcApp* instance, SceneManagerEvent event) {
bool consumed = false;

if(event == SubmenuIndexDetectReader) {
scene_manager_next_scene(instance->scene_manager, NfcSceneMfClassicDetectReader);
consumed = true;
} else if(event == SubmenuIndexWrite) {
scene_manager_next_scene(instance->scene_manager, NfcSceneMfClassicWriteInitial);
consumed = true;
} else if(event == SubmenuIndexUpdate) {
scene_manager_next_scene(instance->scene_manager, NfcSceneMfClassicUpdateInitial);
consumed = true;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexDetectReader) {
scene_manager_next_scene(instance->scene_manager, NfcSceneMfClassicDetectReader);
consumed = true;
} else if(event.event == SubmenuIndexWrite) {
scene_manager_next_scene(instance->scene_manager, NfcSceneMfClassicWriteInitial);
consumed = true;
} else if(event.event == SubmenuIndexUpdate) {
scene_manager_next_scene(instance->scene_manager, NfcSceneMfClassicUpdateInitial);
consumed = true;
}
}

return consumed;
}

static bool nfc_scene_save_name_on_event_mf_classic(NfcApp* instance, uint32_t event) {
static bool nfc_scene_save_name_on_event_mf_classic(NfcApp* instance, SceneManagerEvent event) {
bool consumed = false;

if(event == NfcCustomEventTextInputDone) {
if(event.type == SceneManagerEventTypeCustom && event.event == NfcCustomEventTextInputDone) {
mf_classic_key_cache_save(
instance->mfc_key_cache,
nfc_device_get_data(instance->nfc_device, NfcProtocolMfClassic));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "mf_ultralight_render.h"

#include <nfc/protocols/mf_ultralight/mf_ultralight_poller.h>
#include <toolbox/pretty_format.h>

#include "nfc/nfc_app_i.h"

Expand All @@ -15,6 +16,11 @@ enum {
SubmenuIndexWrite,
};

enum {
NfcSceneMoreInfoStateASCII,
NfcSceneMoreInfoStateRawData,
};

static void nfc_scene_info_on_enter_mf_ultralight(NfcApp* instance) {
const NfcDevice* device = instance->nfc_device;
const MfUltralightData* data = nfc_device_get_data(device, NfcProtocolMfUltralight);
Expand All @@ -37,11 +43,62 @@ static void nfc_scene_more_info_on_enter_mf_ultralight(NfcApp* instance) {
const MfUltralightData* mfu = nfc_device_get_data(device, NfcProtocolMfUltralight);

furi_string_reset(instance->text_box_store);
nfc_render_mf_ultralight_dump(mfu, instance->text_box_store);
uint32_t scene_state =
scene_manager_get_scene_state(instance->scene_manager, NfcSceneMoreInfo);

if(scene_state == NfcSceneMoreInfoStateASCII) {
pretty_format_bytes_hex_canonical(
instance->text_box_store,
MF_ULTRALIGHT_PAGE_SIZE,
PRETTY_FORMAT_FONT_MONOSPACE,
(uint8_t*)mfu->page,
mfu->pages_read * MF_ULTRALIGHT_PAGE_SIZE);

widget_add_text_scroll_element(
instance->widget, 0, 0, 128, 48, furi_string_get_cstr(instance->text_box_store));
widget_add_button_element(
instance->widget,
GuiButtonTypeRight,
"Raw Data",
nfc_protocol_support_common_widget_callback,
instance);

text_box_set_font(instance->text_box, TextBoxFontHex);
text_box_set_text(instance->text_box, furi_string_get_cstr(instance->text_box_store));
view_dispatcher_switch_to_view(instance->view_dispatcher, NfcViewTextBox);
widget_add_button_element(
instance->widget,
GuiButtonTypeLeft,
"Info",
nfc_protocol_support_common_widget_callback,
instance);
} else if(scene_state == NfcSceneMoreInfoStateRawData) {
nfc_render_mf_ultralight_dump(mfu, instance->text_box_store);
widget_add_text_scroll_element(
instance->widget, 0, 0, 128, 48, furi_string_get_cstr(instance->text_box_store));

widget_add_button_element(
instance->widget,
GuiButtonTypeLeft,
"ASCII",
nfc_protocol_support_common_widget_callback,
instance);
}
}

static bool nfc_scene_more_info_on_event_mf_ultralight(NfcApp* instance, SceneManagerEvent event) {
bool consumed = false;

if((event.type == SceneManagerEventTypeCustom && event.event == GuiButtonTypeLeft) ||
(event.type == SceneManagerEventTypeBack)) {
scene_manager_set_scene_state(
instance->scene_manager, NfcSceneMoreInfo, NfcSceneMoreInfoStateASCII);
scene_manager_previous_scene(instance->scene_manager);
consumed = true;
} else if(event.type == SceneManagerEventTypeCustom && event.event == GuiButtonTypeRight) {
scene_manager_set_scene_state(
instance->scene_manager, NfcSceneMoreInfo, NfcSceneMoreInfoStateRawData);
scene_manager_next_scene(instance->scene_manager, NfcSceneMoreInfo);
consumed = true;
}
return consumed;
}

static NfcCommand
Expand Down Expand Up @@ -134,15 +191,17 @@ static void nfc_scene_read_on_enter_mf_ultralight(NfcApp* instance) {
nfc_poller_start(instance->poller, nfc_scene_read_poller_callback_mf_ultralight, instance);
}

bool nfc_scene_read_on_event_mf_ultralight(NfcApp* instance, uint32_t event) {
if(event == NfcCustomEventCardDetected) {
scene_manager_set_scene_state(
instance->scene_manager, NfcSceneRead, NfcSceneMfUltralightReadMenuStateCardFound);
nfc_scene_read_setup_view(instance);
} else if((event == NfcCustomEventPollerIncomplete)) {
notification_message(instance->notifications, &sequence_semi_success);
scene_manager_next_scene(instance->scene_manager, NfcSceneReadSuccess);
dolphin_deed(DolphinDeedNfcReadSuccess);
bool nfc_scene_read_on_event_mf_ultralight(NfcApp* instance, SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventCardDetected) {
scene_manager_set_scene_state(
instance->scene_manager, NfcSceneRead, NfcSceneMfUltralightReadMenuStateCardFound);
nfc_scene_read_setup_view(instance);
} else if((event.event == NfcCustomEventPollerIncomplete)) {
notification_message(instance->notifications, &sequence_semi_success);
scene_manager_next_scene(instance->scene_manager, NfcSceneReadSuccess);
dolphin_deed(DolphinDeedNfcReadSuccess);
}
}
return true;
}
Expand Down Expand Up @@ -204,14 +263,17 @@ static void nfc_scene_emulate_on_enter_mf_ultralight(NfcApp* instance) {
nfc_listener_start(instance->listener, NULL, NULL);
}

static bool
nfc_scene_read_and_saved_menu_on_event_mf_ultralight(NfcApp* instance, uint32_t event) {
if(event == SubmenuIndexUnlock) {
scene_manager_next_scene(instance->scene_manager, NfcSceneMfUltralightUnlockMenu);
return true;
} else if(event == SubmenuIndexWrite) {
scene_manager_next_scene(instance->scene_manager, NfcSceneMfUltralightWrite);
return true;
static bool nfc_scene_read_and_saved_menu_on_event_mf_ultralight(
NfcApp* instance,
SceneManagerEvent event) {
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == SubmenuIndexUnlock) {
scene_manager_next_scene(instance->scene_manager, NfcSceneMfUltralightUnlockMenu);
return true;
} else if(event.event == SubmenuIndexWrite) {
scene_manager_next_scene(instance->scene_manager, NfcSceneMfUltralightWrite);
return true;
}
}
return false;
}
Expand All @@ -227,7 +289,7 @@ const NfcProtocolSupportBase nfc_protocol_support_mf_ultralight = {
.scene_more_info =
{
.on_enter = nfc_scene_more_info_on_enter_mf_ultralight,
.on_event = nfc_protocol_support_common_on_event_empty,
.on_event = nfc_scene_more_info_on_event_mf_ultralight,
},
.scene_read =
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ void nfc_render_mf_ultralight_info(
}

void nfc_render_mf_ultralight_dump(const MfUltralightData* data, FuriString* str) {
furi_string_cat_printf(str, "\e*");
for(size_t i = 0; i < data->pages_read; i++) {
const uint8_t* page_data = data->page[i].data;
for(size_t j = 0; j < MF_ULTRALIGHT_PAGE_SIZE; j += 2) {
furi_string_cat_printf(str, "%02X%02X ", page_data[j], page_data[j + 1]);
furi_string_cat_printf(str, " %02X%02X", page_data[j], page_data[j + 1]);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,16 +131,15 @@ static bool
nfc_protocol_support_scene_more_info_on_event(NfcApp* instance, SceneManagerEvent event) {
bool consumed = false;

if(event.type == SceneManagerEventTypeCustom) {
const NfcProtocol protocol = nfc_device_get_protocol(instance->nfc_device);
consumed = nfc_protocol_support[protocol]->scene_more_info.on_event(instance, event.event);
}
const NfcProtocol protocol = nfc_device_get_protocol(instance->nfc_device);
consumed = nfc_protocol_support[protocol]->scene_more_info.on_event(instance, event);

return consumed;
}

static void nfc_protocol_support_scene_more_info_on_exit(NfcApp* instance) {
text_box_reset(instance->text_box);
widget_reset(instance->widget);
furi_string_reset(instance->text_box_store);
}

Expand Down Expand Up @@ -188,8 +187,7 @@ static bool nfc_protocol_support_scene_read_on_event(NfcApp* instance, SceneMana
} else {
const NfcProtocol protocol =
instance->protocols_detected[instance->protocols_detected_selected_idx];
consumed =
nfc_protocol_support[protocol]->scene_read.on_event(instance, event.event);
consumed = nfc_protocol_support[protocol]->scene_read.on_event(instance, event);
}
} else if(event.event == NfcCustomEventPollerFailure) {
nfc_poller_stop(instance->poller);
Expand All @@ -202,7 +200,7 @@ static bool nfc_protocol_support_scene_read_on_event(NfcApp* instance, SceneMana
} else if(event.event == NfcCustomEventCardDetected) {
const NfcProtocol protocol =
instance->protocols_detected[instance->protocols_detected_selected_idx];
consumed = nfc_protocol_support[protocol]->scene_read.on_event(instance, event.event);
consumed = nfc_protocol_support[protocol]->scene_read.on_event(instance, event);
}
} else if(event.type == SceneManagerEventTypeBack) {
nfc_poller_stop(instance->poller);
Expand Down Expand Up @@ -287,8 +285,7 @@ static bool
consumed = true;
} else {
const NfcProtocol protocol = nfc_device_get_protocol(instance->nfc_device);
consumed =
nfc_protocol_support[protocol]->scene_read_menu.on_event(instance, event.event);
consumed = nfc_protocol_support[protocol]->scene_read_menu.on_event(instance, event);
}

} else if(event.type == SceneManagerEventTypeBack) {
Expand Down Expand Up @@ -456,8 +453,7 @@ static bool
consumed = true;
} else {
const NfcProtocol protocol = nfc_device_get_protocol(instance->nfc_device);
consumed =
nfc_protocol_support[protocol]->scene_saved_menu.on_event(instance, event.event);
consumed = nfc_protocol_support[protocol]->scene_saved_menu.on_event(instance, event);
}

} else if(event.type == SceneManagerEventTypeBack) {
Expand Down Expand Up @@ -523,8 +519,8 @@ static bool
DolphinDeedNfcSave);
const NfcProtocol protocol =
instance->protocols_detected[instance->protocols_detected_selected_idx];
consumed = nfc_protocol_support[protocol]->scene_save_name.on_event(
instance, event.event);
consumed =
nfc_protocol_support[protocol]->scene_save_name.on_event(instance, event);
} else {
consumed = scene_manager_search_and_switch_to_previous_scene(
instance->scene_manager, NfcSceneStart);
Expand Down
Loading

0 comments on commit e702cde

Please sign in to comment.