mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-05-13 00:28:36 -07:00
MRTD save/load BAC params
This commit is contained in:
@@ -42,6 +42,7 @@ ADD_SCENE(nfc, passport_read, PassportReadSuccess)
|
||||
ADD_SCENE(nfc, passport_read_auth, PassportReadAuthSuccess)
|
||||
ADD_SCENE(nfc, passport_menu, PassportMenu)
|
||||
ADD_SCENE(nfc, passport_auth, PassportAuth)
|
||||
ADD_SCENE(nfc, passport_auth_save_name, PassportAuthSaveName)
|
||||
ADD_SCENE(nfc, passport_date, PassportDate)
|
||||
ADD_SCENE(nfc, passport_docnr, PassportDocNr)
|
||||
ADD_SCENE(nfc, passport_pace_todo, PassportPaceTodo)
|
||||
|
||||
@@ -11,6 +11,8 @@ typedef enum {
|
||||
NfcScenePassportAuthSelectDocNr,
|
||||
NfcScenePassportAuthSelectMethod,
|
||||
NfcScenePassportAuthSelectAuth,
|
||||
NfcScenePassportAuthSelectSave,
|
||||
NfcScenePassportAuthSelectLoad,
|
||||
} NfcScenePassportAuthSelect;
|
||||
|
||||
void nfc_scene_passport_auth_var_list_enter_callback(void* context, uint32_t index) {
|
||||
@@ -25,6 +27,47 @@ void nfc_scene_passport_auth_method_changed(VariableItem* item) {
|
||||
variable_item_set_current_value_text(item, mrtd_auth_method_string(index));
|
||||
}
|
||||
|
||||
void nfc_scene_passport_load_select_changed(VariableItem* item) {
|
||||
Nfc* nfc = variable_item_get_context(item);
|
||||
UNUSED(nfc); //TODO: remove either this or previous line
|
||||
//TODO: iterate through params
|
||||
}
|
||||
|
||||
bool nfc_scene_passport_auth_load(Nfc* nfc) {
|
||||
const DialogsFileBrowserOptions browser_options = {
|
||||
.extension = MRTD_APP_EXTENSION,
|
||||
.skip_assets = true,
|
||||
.icon = &I_Nfc_10px, //TODO: custom icon?
|
||||
.hide_ext = true,
|
||||
.item_loader_callback = NULL,
|
||||
.item_loader_context = NULL,
|
||||
};
|
||||
|
||||
FuriString* mrtd_app_folder;
|
||||
mrtd_app_folder = furi_string_alloc_set(MRTD_APP_FOLDER);
|
||||
|
||||
FuriString* file_path;
|
||||
file_path = furi_string_alloc();
|
||||
|
||||
bool res = dialog_file_browser_show(nfc->dev->dialogs, file_path, mrtd_app_folder, &browser_options);
|
||||
|
||||
furi_string_free(mrtd_app_folder);
|
||||
|
||||
if(res) {
|
||||
mrtd_auth_params_load(
|
||||
nfc->dev->storage,
|
||||
nfc->dev->dialogs,
|
||||
&nfc->dev->dev_data.mrtd_data.auth,
|
||||
furi_string_get_cstr(file_path),
|
||||
true);
|
||||
|
||||
//TODO: make sure this call is ok:
|
||||
nfc_scene_passport_auth_on_enter(nfc);
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
void nfc_scene_passport_auth_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
MrtdData* mrtd_data = &nfc->dev->dev_data.mrtd_data;
|
||||
@@ -36,12 +79,16 @@ void nfc_scene_passport_auth_on_enter(void* context) {
|
||||
}
|
||||
|
||||
VariableItemList* variable_item_list = nfc->variable_item_list;
|
||||
variable_item_list_reset(variable_item_list);
|
||||
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
const size_t temp_str_size = 15;
|
||||
char temp_str[temp_str_size];
|
||||
|
||||
uint8_t num_params_saved = 0;
|
||||
|
||||
snprintf(temp_str, temp_str_size, "%02u%02u%02u",
|
||||
mrtd_data->auth.birth_date.year,
|
||||
mrtd_data->auth.birth_date.month,
|
||||
@@ -85,6 +132,9 @@ void nfc_scene_passport_auth_on_enter(void* context) {
|
||||
|
||||
variable_item_list_add(variable_item_list, "Authenticate and read", 1, NULL, NULL);
|
||||
|
||||
variable_item_list_add(variable_item_list, "Save parameters", 1, NULL, NULL);
|
||||
variable_item_list_add(variable_item_list, "Load parameters", num_params_saved, nfc_scene_passport_load_select_changed, nfc);
|
||||
|
||||
variable_item_list_set_enter_callback(
|
||||
variable_item_list, nfc_scene_passport_auth_var_list_enter_callback, nfc);
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewVarItemList);
|
||||
@@ -97,6 +147,10 @@ bool nfc_scene_passport_auth_on_event(void* context, SceneManagerEvent event) {
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
FURI_LOG_D(TAG, "event.event: %ld", event.event);
|
||||
switch(event.event) {
|
||||
case NfcScenePassportAuthSelectLoad:
|
||||
nfc_scene_passport_auth_load(nfc);
|
||||
consumed = true;
|
||||
break;
|
||||
case NfcScenePassportAuthSelectDob:
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcScenePassportDate, 0);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportDate);
|
||||
@@ -123,6 +177,10 @@ bool nfc_scene_passport_auth_on_event(void* context, SceneManagerEvent event) {
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
case NfcScenePassportAuthSelectSave:
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportAuthSaveName);
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
consumed = scene_manager_previous_scene(nfc->scene_manager);
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
#include "../nfc_i.h"
|
||||
#include <lib/toolbox/random_name.h>
|
||||
#include <gui/modules/validators.h>
|
||||
#include <toolbox/path.h>
|
||||
|
||||
void nfc_scene_passport_auth_save_name_text_input_callback(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventTextInputDone);
|
||||
}
|
||||
|
||||
void nfc_scene_passport_auth_save_name_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
MrtdData* mrtd_data = &nfc->dev->dev_data.mrtd_data;
|
||||
|
||||
// Setup view
|
||||
TextInput* text_input = nfc->text_input;
|
||||
bool docnr_empty = false;
|
||||
if(!strcmp(mrtd_data->auth.doc_number, "")) {
|
||||
set_random_name(nfc->text_store, sizeof(nfc->text_store));
|
||||
docnr_empty = true;
|
||||
} else {
|
||||
nfc_text_store_set(nfc, mrtd_data->auth.doc_number);
|
||||
}
|
||||
text_input_set_header_text(text_input, "Name the parameters");
|
||||
text_input_set_result_callback(
|
||||
text_input,
|
||||
nfc_scene_passport_auth_save_name_text_input_callback,
|
||||
nfc,
|
||||
nfc->text_store,
|
||||
NFC_DEV_NAME_MAX_LEN,
|
||||
docnr_empty);
|
||||
|
||||
FuriString* folder_path;
|
||||
folder_path = furi_string_alloc();
|
||||
|
||||
if(furi_string_end_with(nfc->dev->load_path, NFC_APP_EXTENSION)) {
|
||||
path_extract_dirname(furi_string_get_cstr(nfc->dev->load_path), folder_path);
|
||||
} else {
|
||||
furi_string_set(folder_path, NFC_APP_FOLDER);
|
||||
}
|
||||
|
||||
ValidatorIsFile* validator_is_file = validator_is_file_alloc_init(
|
||||
furi_string_get_cstr(folder_path), NFC_APP_EXTENSION, NULL);
|
||||
text_input_set_validator(text_input, validator_is_file_callback, validator_is_file);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextInput);
|
||||
|
||||
furi_string_free(folder_path);
|
||||
}
|
||||
|
||||
bool nfc_scene_passport_auth_save_name_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
MrtdData* mrtd_data = &nfc->dev->dev_data.mrtd_data;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == NfcCustomEventTextInputDone) {
|
||||
if(mrtd_auth_params_save(nfc->dev->storage, nfc->dev->dialogs, &mrtd_data->auth, nfc->text_store)) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveSuccess);
|
||||
consumed = true;
|
||||
} else {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
nfc->scene_manager, NfcSceneStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_passport_auth_save_name_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
// Clear view
|
||||
void* validator_context = text_input_get_validator_callback_context(nfc->text_input);
|
||||
text_input_set_validator(nfc->text_input, NULL, NULL);
|
||||
validator_is_file_free(validator_context);
|
||||
|
||||
text_input_reset(nfc->text_input);
|
||||
}
|
||||
@@ -33,6 +33,9 @@ bool nfc_scene_save_success_on_event(void* context, SceneManagerEvent event) {
|
||||
} else if(scene_manager_has_previous_scene(nfc->scene_manager, NfcSceneSavedMenu)) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
nfc->scene_manager, NfcSceneSavedMenu);
|
||||
} else if(scene_manager_has_previous_scene(nfc->scene_manager, NfcScenePassportAuth)) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
nfc->scene_manager, NfcScenePassportAuth);
|
||||
} else {
|
||||
consumed = scene_manager_search_and_switch_to_another_scene(
|
||||
nfc->scene_manager, NfcSceneFileSelect);
|
||||
|
||||
Reference in New Issue
Block a user