2022-03-23 13:45:37 +00:00
|
|
|
#include "../nfc_i.h"
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
#define TAG "NfcSceneMfDesfireData"
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
MifareDesfireDataStateMenu,
|
|
|
|
MifareDesfireDataStateItem, // MUST be last, states >= this correspond with submenu index
|
|
|
|
};
|
|
|
|
|
|
|
|
enum SubmenuIndex {
|
|
|
|
SubmenuIndexCardInfo,
|
|
|
|
SubmenuIndexDynamic, // dynamic indexes start here
|
|
|
|
};
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
void nfc_scene_mf_desfire_data_submenu_callback(void* context, uint32_t index) {
|
2022-03-23 13:45:37 +00:00
|
|
|
Nfc* nfc = (Nfc*)context;
|
|
|
|
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, index);
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
void nfc_scene_mf_desfire_data_on_enter(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2022-03-23 13:45:37 +00:00
|
|
|
Submenu* submenu = nfc->submenu;
|
2022-07-26 15:30:49 +00:00
|
|
|
uint32_t state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfDesfireData);
|
2022-03-23 13:45:37 +00:00
|
|
|
MifareDesfireData* data = &nfc->dev->dev_data.mf_df_data;
|
|
|
|
|
|
|
|
text_box_set_font(nfc->text_box, TextBoxFontHex);
|
|
|
|
|
|
|
|
submenu_add_item(
|
|
|
|
submenu,
|
|
|
|
"Card info",
|
|
|
|
SubmenuIndexCardInfo,
|
2022-07-26 15:30:49 +00:00
|
|
|
nfc_scene_mf_desfire_data_submenu_callback,
|
2022-03-23 13:45:37 +00:00
|
|
|
nfc);
|
|
|
|
|
2022-12-30 03:44:07 +00:00
|
|
|
FuriString* label = furi_string_alloc();
|
2022-03-23 13:45:37 +00:00
|
|
|
int idx = SubmenuIndexDynamic;
|
|
|
|
for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
|
2022-12-30 03:44:07 +00:00
|
|
|
furi_string_printf(label, "App %02x%02x%02x", app->id[0], app->id[1], app->id[2]);
|
|
|
|
submenu_add_item(
|
|
|
|
submenu,
|
|
|
|
furi_string_get_cstr(label),
|
|
|
|
idx++,
|
|
|
|
nfc_scene_mf_desfire_data_submenu_callback,
|
|
|
|
nfc);
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
2022-12-30 03:44:07 +00:00
|
|
|
furi_string_free(label);
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
if(state >= MifareDesfireDataStateItem) {
|
|
|
|
submenu_set_selected_item(
|
|
|
|
nfc->submenu, state - MifareDesfireDataStateItem + SubmenuIndexDynamic);
|
|
|
|
scene_manager_set_scene_state(
|
2022-07-26 15:30:49 +00:00
|
|
|
nfc->scene_manager, NfcSceneMfDesfireData, MifareDesfireDataStateMenu);
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu);
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
bool nfc_scene_mf_desfire_data_on_event(void* context, SceneManagerEvent event) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
|
|
|
bool consumed = false;
|
2022-07-26 15:30:49 +00:00
|
|
|
uint32_t state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfDesfireData);
|
2022-03-23 13:45:37 +00:00
|
|
|
MifareDesfireData* data = &nfc->dev->dev_data.mf_df_data;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
TextBox* text_box = nfc->text_box;
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_reset(nfc->text_box_store);
|
2022-03-23 13:45:37 +00:00
|
|
|
if(event.event == SubmenuIndexCardInfo) {
|
|
|
|
mf_df_cat_card_info(data, nfc->text_box_store);
|
2022-10-05 15:15:23 +00:00
|
|
|
text_box_set_text(text_box, furi_string_get_cstr(nfc->text_box_store));
|
2022-03-23 13:45:37 +00:00
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextBox);
|
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager,
|
2022-07-26 15:30:49 +00:00
|
|
|
NfcSceneMfDesfireData,
|
2022-03-23 13:45:37 +00:00
|
|
|
MifareDesfireDataStateItem + SubmenuIndexCardInfo);
|
2022-04-19 15:23:58 +00:00
|
|
|
consumed = true;
|
2022-03-23 13:45:37 +00:00
|
|
|
} else {
|
|
|
|
uint16_t index = event.event - SubmenuIndexDynamic;
|
|
|
|
scene_manager_set_scene_state(
|
2022-07-26 15:30:49 +00:00
|
|
|
nfc->scene_manager, NfcSceneMfDesfireData, MifareDesfireDataStateItem + index);
|
|
|
|
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneMfDesfireApp, index << 1);
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfDesfireApp);
|
2022-04-19 15:23:58 +00:00
|
|
|
consumed = true;
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
|
|
|
} else if(event.type == SceneManagerEventTypeBack) {
|
|
|
|
if(state >= MifareDesfireDataStateItem) {
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu);
|
|
|
|
scene_manager_set_scene_state(
|
2022-07-26 15:30:49 +00:00
|
|
|
nfc->scene_manager, NfcSceneMfDesfireData, MifareDesfireDataStateMenu);
|
2022-04-19 15:23:58 +00:00
|
|
|
consumed = true;
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-19 15:23:58 +00:00
|
|
|
return consumed;
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
void nfc_scene_mf_desfire_data_on_exit(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2022-03-23 13:45:37 +00:00
|
|
|
|
2022-04-19 15:23:58 +00:00
|
|
|
// Clear views
|
2022-03-23 13:45:37 +00:00
|
|
|
text_box_reset(nfc->text_box);
|
2022-10-05 15:15:23 +00:00
|
|
|
furi_string_reset(nfc->text_box_store);
|
2022-03-23 13:45:37 +00:00
|
|
|
submenu_reset(nfc->submenu);
|
|
|
|
}
|