diff --git a/applications/nfc/scenes/nfc_scene_config.h b/applications/nfc/scenes/nfc_scene_config.h index 711281093..92dea6394 100644 --- a/applications/nfc/scenes/nfc_scene_config.h +++ b/applications/nfc/scenes/nfc_scene_config.h @@ -39,6 +39,7 @@ ADD_SCENE(nfc, passport_read, PassportReadSuccess) ADD_SCENE(nfc, passport_menu, PassportMenu) ADD_SCENE(nfc, passport_bac, PassportBac) //TODO: rename to Auth ADD_SCENE(nfc, passport_date, PassportDate) +ADD_SCENE(nfc, passport_docnr, PassportDocNr) ADD_SCENE(nfc, passport_pace_todo, PassportPaceTodo) ADD_SCENE(nfc, emulate_apdu_sequence, EmulateApduSequence) ADD_SCENE(nfc, device_info, DeviceInfo) diff --git a/applications/nfc/scenes/nfc_scene_passport_bac.c b/applications/nfc/scenes/nfc_scene_passport_bac.c index ba3b3dfd0..ca4efb6bd 100644 --- a/applications/nfc/scenes/nfc_scene_passport_bac.c +++ b/applications/nfc/scenes/nfc_scene_passport_bac.c @@ -37,7 +37,7 @@ void nfc_scene_passport_bac_on_enter(void* context) { VariableItem* item; uint8_t value_index; - const size_t temp_str_size = 10; + const size_t temp_str_size = 15; char temp_str[temp_str_size]; snprintf(temp_str, temp_str_size, "%02u%02u%02u", nfc->dev->dev_data.mrtd_data.auth.birth_date.year, @@ -55,8 +55,19 @@ void nfc_scene_passport_bac_on_enter(void* context) { item = variable_item_list_add(variable_item_list, "Expiry Date", 1, NULL, NULL); variable_item_set_current_value_text(item, temp_str); - variable_item_list_add(variable_item_list, "Document Nr.", 1, NULL, NULL); - //TODO: add scene to enter docnr, based on nfc_scene_passport_date.c + item = variable_item_list_add(variable_item_list, "Document Nr.", 1, NULL, NULL); + + strncpy(temp_str, nfc->dev->dev_data.mrtd_data.auth.doc_number, temp_str_size); + temp_str[temp_str_size] = '\x00'; + if(strlen(temp_str) > 8) { + temp_str[8] = '.'; + temp_str[9] = '.'; + temp_str[10] = '.'; + temp_str[11] = '\x00'; + } + variable_item_set_current_value_text( + item, + temp_str); item = variable_item_list_add( variable_item_list, @@ -94,6 +105,7 @@ bool nfc_scene_passport_bac_on_event(void* context, SceneManagerEvent event) { consumed = true; break; case NfcScenePassportAuthSelectDocNr: + scene_manager_next_scene(nfc->scene_manager, NfcScenePassportDocNr); consumed = true; break; case NfcScenePassportAuthSelectMethod: diff --git a/applications/nfc/scenes/nfc_scene_passport_docnr.c b/applications/nfc/scenes/nfc_scene_passport_docnr.c new file mode 100644 index 000000000..a4ee1c2cd --- /dev/null +++ b/applications/nfc/scenes/nfc_scene_passport_docnr.c @@ -0,0 +1,67 @@ +#include "../nfc_i.h" +#include "m-string.h" +#include + +#define TAG "PassportDocnr" + +void nfc_scene_passport_docnr_text_input_callback(void* context) { + Nfc* nfc = context; + + view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventTextInputDone); +} + +void nfc_scene_passport_docnr_on_enter(void* context) { + Nfc* nfc = context; + + TextInput* text_input = nfc->text_input; + text_input_set_header_text(text_input, "Document Nr."); + + char* docnr = nfc->dev->dev_data.mrtd_data.auth.doc_number; + bool docnr_empty = false; + + if(*docnr) { + nfc_text_store_set(nfc, docnr); + docnr_empty = false; + } else { + nfc_text_store_set(nfc, "PA7HJ34M8"); + docnr_empty = true; + } + + text_input_set_result_callback( + text_input, + nfc_scene_passport_docnr_text_input_callback, + nfc, + nfc->text_store, + MRTD_DOCNR_MAX_LENGTH, // incl. '\x00' + docnr_empty); // Use as template + + //TODO: add validator? + + view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextInput); +} + +bool nfc_scene_passport_docnr_save(Nfc* nfc) { + strncpy(nfc->dev->dev_data.mrtd_data.auth.doc_number, nfc->text_store, MRTD_DOCNR_MAX_LENGTH); + return true; +} + +bool nfc_scene_passport_docnr_on_event(void* context, SceneManagerEvent event) { + Nfc* nfc = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == NfcCustomEventTextInputDone) { + nfc_scene_passport_docnr_save(nfc); + + consumed = scene_manager_search_and_switch_to_previous_scene( + nfc->scene_manager, NfcScenePassportBac); + } + } + return consumed; +} + +void nfc_scene_passport_docnr_on_exit(void* context) { + Nfc* nfc = context; + + text_input_reset(nfc->text_input); +}