mirror of
https://github.com/Next-Flip/Momentum-Firmware.git
synced 2026-04-25 03:29:58 -07:00
@@ -85,6 +85,13 @@ Nfc* nfc_alloc() {
|
||||
nfc->view_dispatcher, NfcViewTextBox, text_box_get_view(nfc->text_box));
|
||||
nfc->text_box_store = furi_string_alloc();
|
||||
|
||||
// Variable Item List
|
||||
nfc->variable_item_list = variable_item_list_alloc();
|
||||
view_dispatcher_add_view(
|
||||
nfc->view_dispatcher,
|
||||
NfcViewVarItemList,
|
||||
variable_item_list_get_view(nfc->variable_item_list));
|
||||
|
||||
// Custom Widget
|
||||
nfc->widget = widget_alloc();
|
||||
view_dispatcher_add_view(nfc->view_dispatcher, NfcViewWidget, widget_get_view(nfc->widget));
|
||||
@@ -155,6 +162,10 @@ void nfc_free(Nfc* nfc) {
|
||||
text_box_free(nfc->text_box);
|
||||
furi_string_free(nfc->text_box_store);
|
||||
|
||||
// Variable Item List
|
||||
view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewVarItemList);
|
||||
variable_item_list_free(nfc->variable_item_list);
|
||||
|
||||
// Custom Widget
|
||||
view_dispatcher_remove_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
widget_free(nfc->widget);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
#include <gui/modules/byte_input.h>
|
||||
#include <gui/modules/text_box.h>
|
||||
#include <gui/modules/widget.h>
|
||||
#include <gui/modules/variable_item_list.h>
|
||||
|
||||
#include <lib/nfc/nfc_types.h>
|
||||
#include <lib/nfc/nfc_worker.h>
|
||||
@@ -77,6 +78,7 @@ struct Nfc {
|
||||
TextInput* text_input;
|
||||
ByteInput* byte_input;
|
||||
TextBox* text_box;
|
||||
VariableItemList* variable_item_list;
|
||||
Widget* widget;
|
||||
DictAttack* dict_attack;
|
||||
DetectReader* detect_reader;
|
||||
@@ -92,6 +94,7 @@ typedef enum {
|
||||
NfcViewTextInput,
|
||||
NfcViewByteInput,
|
||||
NfcViewTextBox,
|
||||
NfcViewVarItemList,
|
||||
NfcViewWidget,
|
||||
NfcViewDictAttack,
|
||||
NfcViewDetectReader,
|
||||
|
||||
@@ -38,6 +38,13 @@ ADD_SCENE(nfc, mf_classic_keys_warn_duplicate, MfClassicKeysWarnDuplicate)
|
||||
ADD_SCENE(nfc, mf_classic_dict_attack, MfClassicDictAttack)
|
||||
ADD_SCENE(nfc, emv_read_success, EmvReadSuccess)
|
||||
ADD_SCENE(nfc, emv_menu, EmvMenu)
|
||||
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_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)
|
||||
ADD_SCENE(nfc, delete, Delete)
|
||||
|
||||
@@ -32,6 +32,8 @@ void nfc_scene_nfc_data_info_on_enter(void* context) {
|
||||
// Set tag type
|
||||
if(protocol == NfcDeviceProtocolEMV) {
|
||||
furi_string_cat_printf(temp_str, "\e#EMV Bank Card\n");
|
||||
} else if(protocol == NfcDeviceProtocolMRTD) {
|
||||
furi_string_cat_printf(temp_str, "\e#Passport/ID\n");
|
||||
} else if(protocol == NfcDeviceProtocolMifareUl) {
|
||||
furi_string_cat_printf(
|
||||
temp_str, "\e#%s\n", nfc_mf_ul_type(dev_data->mf_ul_data.type, true));
|
||||
@@ -131,4 +133,4 @@ void nfc_scene_nfc_data_info_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
widget_reset(nfc->widget);
|
||||
}
|
||||
}
|
||||
|
||||
145
applications/main/nfc/scenes/nfc_scene_passport_auth.c
Normal file
145
applications/main/nfc/scenes/nfc_scene_passport_auth.c
Normal file
@@ -0,0 +1,145 @@
|
||||
#include "../nfc_i.h"
|
||||
|
||||
#define TAG "PassportAuth"
|
||||
|
||||
#define MRTD_AUTH_METHOD_COUNT 4
|
||||
// Indexes must match MrtdAuthMethod (lib/nfc/protocols/mrtd_helpers.h)
|
||||
const char* const mrtd_auth_method_text[MRTD_AUTH_METHOD_COUNT] = {
|
||||
"None",
|
||||
"Any",
|
||||
"BAC",
|
||||
"PACE",
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
NfcScenePassportAuthSelectDob,
|
||||
NfcScenePassportAuthSelectDoe,
|
||||
NfcScenePassportAuthSelectDocNr,
|
||||
NfcScenePassportAuthSelectMethod,
|
||||
NfcScenePassportAuthSelectAuth,
|
||||
} NfcScenePassportAuthSelect;
|
||||
|
||||
void nfc_scene_passport_auth_var_list_enter_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = context;
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void nfc_scene_passport_auth_method_changed(VariableItem* item) {
|
||||
Nfc* nfc = variable_item_get_context(item);
|
||||
uint8_t index = variable_item_get_current_value_index(item);
|
||||
nfc->dev->dev_data.mrtd_data.auth.method = index;
|
||||
variable_item_set_current_value_text(item, mrtd_auth_method_text[index]);
|
||||
}
|
||||
|
||||
void nfc_scene_passport_auth_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
MrtdData* mrtd_data = &nfc->dev->dev_data.mrtd_data;
|
||||
|
||||
// By entering the Auth menu, we default to Auth: Any
|
||||
MrtdAuthMethod* auth_method = &mrtd_data->auth.method;
|
||||
if(*auth_method == MrtdAuthMethodNone) {
|
||||
*auth_method = MrtdAuthMethodAny;
|
||||
}
|
||||
|
||||
VariableItemList* variable_item_list = nfc->variable_item_list;
|
||||
|
||||
VariableItem* item;
|
||||
uint8_t value_index;
|
||||
|
||||
const size_t temp_str_size = 15;
|
||||
char temp_str[temp_str_size];
|
||||
snprintf(temp_str, temp_str_size, "%02u%02u%02u",
|
||||
mrtd_data->auth.birth_date.year,
|
||||
mrtd_data->auth.birth_date.month,
|
||||
mrtd_data->auth.birth_date.day);
|
||||
|
||||
item = variable_item_list_add(variable_item_list, "Birth Date", 1, NULL, NULL);
|
||||
variable_item_set_current_value_text(item, temp_str);
|
||||
|
||||
snprintf(temp_str, temp_str_size, "%02u%02u%02u",
|
||||
mrtd_data->auth.expiry_date.year,
|
||||
mrtd_data->auth.expiry_date.month,
|
||||
mrtd_data->auth.expiry_date.day);
|
||||
|
||||
item = variable_item_list_add(variable_item_list, "Expiry Date", 1, NULL, NULL);
|
||||
variable_item_set_current_value_text(item, temp_str);
|
||||
|
||||
item = variable_item_list_add(variable_item_list, "Document Nr.", 1, NULL, NULL);
|
||||
|
||||
strncpy(temp_str, 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,
|
||||
"Method",
|
||||
MRTD_AUTH_METHOD_COUNT,
|
||||
nfc_scene_passport_auth_method_changed,
|
||||
nfc);
|
||||
|
||||
value_index = *auth_method;
|
||||
variable_item_set_current_value_index(item, value_index);
|
||||
variable_item_set_current_value_text(item, mrtd_auth_method_text[value_index]);
|
||||
|
||||
variable_item_list_add(variable_item_list, "Authenticate and read", 1, NULL, NULL);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
bool nfc_scene_passport_auth_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
FURI_LOG_D(TAG, "event.event: %ld", event.event);
|
||||
switch(event.event) {
|
||||
case NfcScenePassportAuthSelectDob:
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcScenePassportDate, 0);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportDate);
|
||||
consumed = true;
|
||||
break;
|
||||
case NfcScenePassportAuthSelectDoe:
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcScenePassportDate, 1);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportDate);
|
||||
consumed = true;
|
||||
break;
|
||||
case NfcScenePassportAuthSelectDocNr:
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportDocNr);
|
||||
consumed = true;
|
||||
break;
|
||||
case NfcScenePassportAuthSelectMethod:
|
||||
consumed = true;
|
||||
break;
|
||||
case NfcScenePassportAuthSelectAuth:
|
||||
if(nfc->dev->dev_data.mrtd_data.auth.method == MrtdAuthMethodPace) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportPaceTodo);
|
||||
} else {
|
||||
nfc_device_clear(nfc->dev);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneRead);
|
||||
}
|
||||
consumed = true;
|
||||
break;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
consumed = scene_manager_previous_scene(nfc->scene_manager);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_passport_auth_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
// Clear view
|
||||
variable_item_list_reset(nfc->variable_item_list);
|
||||
}
|
||||
126
applications/main/nfc/scenes/nfc_scene_passport_date.c
Normal file
126
applications/main/nfc/scenes/nfc_scene_passport_date.c
Normal file
@@ -0,0 +1,126 @@
|
||||
#include "../nfc_i.h"
|
||||
#include "m-string.h"
|
||||
#include <gui/modules/validators.h>
|
||||
|
||||
#define TAG "PassportDate"
|
||||
|
||||
#define DATE_LENGTH 6
|
||||
|
||||
//TODO: use types in .h file? also in nfc_scene_passport_bac.c
|
||||
#define NFC_PASSPORT_DATE_BIRTH 0
|
||||
#define NFC_PASSPORT_DATE_EXPIRY 1
|
||||
|
||||
void nfc_scene_passport_date_text_input_callback(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventTextInputDone);
|
||||
}
|
||||
|
||||
void nfc_scene_passport_date_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
MrtdDate date_value;
|
||||
|
||||
uint32_t date_type = scene_manager_get_scene_state(nfc->scene_manager, NfcScenePassportDate);
|
||||
|
||||
//TODO: numbers only
|
||||
TextInput* text_input = nfc->text_input;
|
||||
|
||||
switch(date_type) {
|
||||
case NFC_PASSPORT_DATE_BIRTH:
|
||||
text_input_set_header_text(text_input, "Birth Date");
|
||||
date_value = nfc->dev->dev_data.mrtd_data.auth.birth_date;
|
||||
break;
|
||||
case NFC_PASSPORT_DATE_EXPIRY:
|
||||
text_input_set_header_text(text_input, "Expiry Date");
|
||||
date_value = nfc->dev->dev_data.mrtd_data.auth.expiry_date;
|
||||
break;
|
||||
}
|
||||
|
||||
bool date_empty = false;
|
||||
if(date_value.year == 0 || date_value.month == 0 || date_value.day == 0 ||
|
||||
date_value.year > 100 || date_value.month > 13 || date_value.day > 31) {
|
||||
nfc_text_store_set(nfc, "YYMMDD");
|
||||
date_empty = true;
|
||||
} else {
|
||||
char temp_str[10];
|
||||
snprintf(
|
||||
temp_str,
|
||||
10,
|
||||
"%02u%02u%02u",
|
||||
date_value.year,
|
||||
date_value.month,
|
||||
date_value.day);
|
||||
|
||||
memcpy(nfc->text_store, temp_str, DATE_LENGTH);
|
||||
nfc->text_store[DATE_LENGTH] = '\x00';
|
||||
}
|
||||
|
||||
text_input_set_result_callback(
|
||||
text_input,
|
||||
nfc_scene_passport_date_text_input_callback,
|
||||
nfc,
|
||||
nfc->text_store,
|
||||
DATE_LENGTH + 1, // incl. '\x00'
|
||||
date_empty); // Use as template
|
||||
|
||||
//TODO: add validator for valid date (YYMMDD)
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextInput);
|
||||
}
|
||||
|
||||
bool nfc_scene_passport_date_save(Nfc* nfc) {
|
||||
int year;
|
||||
int month;
|
||||
int day;
|
||||
int ret = sscanf(nfc->text_store, "%02d%02d%02d", &year, &month, &day);
|
||||
|
||||
if(ret != 3) {
|
||||
FURI_LOG_E(TAG, "Invalid date entered (YYMMDD): %s", nfc->text_store);
|
||||
return false;
|
||||
}
|
||||
|
||||
MrtdDate date_value;
|
||||
date_value.year = year;
|
||||
date_value.month = month;
|
||||
date_value.day = day;
|
||||
|
||||
uint32_t date_type = scene_manager_get_scene_state(nfc->scene_manager, NfcScenePassportDate);
|
||||
|
||||
//TODO: use types in .h file? also in nfc_scene_passport_bac.c
|
||||
switch(date_type) {
|
||||
case NFC_PASSPORT_DATE_BIRTH:
|
||||
nfc->dev->dev_data.mrtd_data.auth.birth_date = date_value;
|
||||
break;
|
||||
case NFC_PASSPORT_DATE_EXPIRY:
|
||||
nfc->dev->dev_data.mrtd_data.auth.expiry_date = date_value;
|
||||
break;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool nfc_scene_passport_date_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == NfcCustomEventTextInputDone) {
|
||||
nfc_scene_passport_date_save(nfc);
|
||||
//TODO: handle invalid date (returned false)
|
||||
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
nfc->scene_manager, NfcScenePassportAuth);
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_passport_date_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
// Clear view
|
||||
// TODO: clear validator
|
||||
|
||||
text_input_reset(nfc->text_input);
|
||||
}
|
||||
67
applications/main/nfc/scenes/nfc_scene_passport_docnr.c
Normal file
67
applications/main/nfc/scenes/nfc_scene_passport_docnr.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "../nfc_i.h"
|
||||
#include "m-string.h"
|
||||
#include <gui/modules/validators.h>
|
||||
|
||||
#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, NfcScenePassportAuth);
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_passport_docnr_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
text_input_reset(nfc->text_input);
|
||||
}
|
||||
57
applications/main/nfc/scenes/nfc_scene_passport_menu.c
Normal file
57
applications/main/nfc/scenes/nfc_scene_passport_menu.c
Normal file
@@ -0,0 +1,57 @@
|
||||
#include "../nfc_i.h"
|
||||
|
||||
enum SubmenuIndex {
|
||||
SubmenuIndexSave,
|
||||
SubmenuIndexInfo,
|
||||
};
|
||||
|
||||
void nfc_scene_passport_menu_submenu_callback(void* context, uint32_t index) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, index);
|
||||
}
|
||||
|
||||
void nfc_scene_passport_menu_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
Submenu* submenu = nfc->submenu;
|
||||
|
||||
submenu_add_item(
|
||||
submenu, "Save", SubmenuIndexSave, nfc_scene_passport_menu_submenu_callback, nfc);
|
||||
submenu_add_item(
|
||||
submenu, "Info", SubmenuIndexInfo, nfc_scene_passport_menu_submenu_callback, nfc);
|
||||
submenu_set_selected_item(
|
||||
nfc->submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcScenePassportMenu));
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewMenu);
|
||||
}
|
||||
|
||||
bool nfc_scene_passport_menu_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == SubmenuIndexSave) {
|
||||
//TODO: save more than just UID
|
||||
nfc->dev->format = NfcDeviceSaveFormatUid;
|
||||
// Clear device name
|
||||
nfc_device_set_name(nfc->dev, "");
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName);
|
||||
consumed = true;
|
||||
} else if(event.event == SubmenuIndexInfo) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcDataInfo);
|
||||
consumed = true;
|
||||
}
|
||||
scene_manager_set_scene_state(nfc->scene_manager, NfcScenePassportMenu, event.event);
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
consumed = scene_manager_previous_scene(nfc->scene_manager);
|
||||
}
|
||||
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_passport_menu_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
// Clear view
|
||||
submenu_reset(nfc->submenu);
|
||||
}
|
||||
40
applications/main/nfc/scenes/nfc_scene_passport_pace_todo.c
Normal file
40
applications/main/nfc/scenes/nfc_scene_passport_pace_todo.c
Normal file
@@ -0,0 +1,40 @@
|
||||
#include "../nfc_i.h"
|
||||
|
||||
void nfc_scene_passport_pace_todo_popup_callback(void* context) {
|
||||
Nfc* nfc = context;
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventViewExit);
|
||||
}
|
||||
|
||||
void nfc_scene_passport_pace_todo_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
// Setup view
|
||||
Popup* popup = nfc->popup;
|
||||
popup_set_icon(popup, 64, 16, &I_DolphinCommon_56x48);
|
||||
popup_set_header(popup, "PACE not yet implemented", 4, 4, AlignLeft, AlignTop);
|
||||
popup_set_timeout(popup, 2000);
|
||||
popup_set_context(popup, nfc);
|
||||
popup_set_callback(popup, nfc_scene_passport_pace_todo_popup_callback);
|
||||
popup_enable_timeout(popup);
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewPopup);
|
||||
}
|
||||
|
||||
bool nfc_scene_passport_pace_todo_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == NfcCustomEventViewExit) {
|
||||
consumed = scene_manager_search_and_switch_to_previous_scene(
|
||||
nfc->scene_manager, NfcScenePassportAuth);
|
||||
}
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_passport_pace_todo_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
// Clear view
|
||||
popup_reset(nfc->popup);
|
||||
}
|
||||
73
applications/main/nfc/scenes/nfc_scene_passport_read.c
Normal file
73
applications/main/nfc/scenes/nfc_scene_passport_read.c
Normal file
@@ -0,0 +1,73 @@
|
||||
#include "../nfc_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
void nfc_scene_passport_read_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
Nfc* nfc = context;
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void nfc_scene_passport_read_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
FuriHalNfcDevData* data = &nfc->dev->dev_data.nfc_data;
|
||||
|
||||
DOLPHIN_DEED(DolphinDeedNfcReadSuccess);
|
||||
|
||||
Widget* widget = nfc->widget;
|
||||
|
||||
// Setup Custom Widget view
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
furi_string_set(temp_str, "\e#Passport\n");
|
||||
char iso_type = FURI_BIT(data->sak, 5) ? '4' : '3';
|
||||
//TODO: NFC-B?
|
||||
furi_string_cat_printf(temp_str, "ISO 14443-%c (NFC-A)\n", iso_type);
|
||||
furi_string_cat_printf(temp_str, "UID:");
|
||||
for(size_t i = 0; i < data->uid_len; i++) {
|
||||
furi_string_cat_printf(temp_str, " %02X", data->uid[i]);
|
||||
}
|
||||
furi_string_cat_printf(temp_str, "\nATQA: %02X %02X ", data->atqa[1], data->atqa[0]);
|
||||
furi_string_cat_printf(temp_str, " SAK: %02X", data->sak);
|
||||
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeLeft, "Retry", nfc_scene_passport_read_widget_callback, nfc);
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeCenter, "Auth", nfc_scene_passport_read_widget_callback, nfc);
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeRight, "More", nfc_scene_passport_read_widget_callback, nfc);
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
}
|
||||
|
||||
bool nfc_scene_passport_read_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeLeft) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
|
||||
consumed = true;
|
||||
} else if(event.event == GuiButtonTypeCenter) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportAuth);
|
||||
consumed = true;
|
||||
} else if(event.event == GuiButtonTypeRight) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportMenu);
|
||||
consumed = true;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
|
||||
consumed = true;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_passport_read_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
// Clear view
|
||||
widget_reset(nfc->widget);
|
||||
}
|
||||
121
applications/main/nfc/scenes/nfc_scene_passport_read_auth.c
Normal file
121
applications/main/nfc/scenes/nfc_scene_passport_read_auth.c
Normal file
@@ -0,0 +1,121 @@
|
||||
#include "../nfc_i.h"
|
||||
#include <dolphin/dolphin.h>
|
||||
|
||||
const char months[13][4] = {
|
||||
"---",
|
||||
"JAN",
|
||||
"FEB",
|
||||
"MAR",
|
||||
"APR",
|
||||
"MAY",
|
||||
"JUN",
|
||||
"JUL",
|
||||
"AUG",
|
||||
"SEP",
|
||||
"OCT",
|
||||
"NOV",
|
||||
"DEC",
|
||||
};
|
||||
|
||||
void nfc_scene_passport_read_auth_widget_callback(GuiButtonType result, InputType type, void* context) {
|
||||
Nfc* nfc = context;
|
||||
if(type == InputTypeShort) {
|
||||
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
|
||||
}
|
||||
}
|
||||
|
||||
void nfc_scene_passport_read_auth_on_enter(void* context) {
|
||||
Nfc* nfc = context;
|
||||
MrtdData* mrtd_data = &nfc->dev->dev_data.mrtd_data;
|
||||
|
||||
Widget* widget = nfc->widget;
|
||||
|
||||
// Setup Custom Widget view
|
||||
FuriString* temp_str;
|
||||
temp_str = furi_string_alloc();
|
||||
furi_string_set(temp_str, "\e#Passport\n");
|
||||
furi_string_cat_printf(temp_str, "Authenticated: %d\n", mrtd_data->auth_success);
|
||||
// TODO: indicate BAC / PACE used
|
||||
|
||||
uint16_t lds_version = mrtd_data->files.EF_COM.lds_version;
|
||||
furi_string_cat_printf(temp_str, "LDS version: %d.%d\n", lds_version/100, lds_version%100);
|
||||
|
||||
uint32_t unicode_version = mrtd_data->files.EF_COM.unicode_version;
|
||||
furi_string_cat_printf(temp_str, "Unicode version: %d.%d.%d\n", (uint8_t)(unicode_version/10000), (uint8_t)(unicode_version/100%100), (uint8_t)(unicode_version%100));
|
||||
|
||||
furi_string_cat_printf(temp_str, "Avail.files: ");
|
||||
for(size_t i=0; i<MAX_EFCOM_TAGS; ++i) {
|
||||
uint8_t tag = mrtd_data->files.EF_COM.tag_list[i];
|
||||
const EFFile* file = mrtd_tag_to_file(tag);
|
||||
if(file->tag) {
|
||||
if(i > 0) furi_string_cat_printf(temp_str, ", ");
|
||||
furi_string_cat_printf(temp_str, "%s", file->name);
|
||||
}
|
||||
}
|
||||
furi_string_cat_printf(temp_str, "\n");
|
||||
|
||||
EF_DIR_contents* EF_DIR = &mrtd_data->files.EF_DIR;
|
||||
if(EF_DIR->applications_count > 0) {
|
||||
furi_string_cat_printf(temp_str, "Apps:\n");
|
||||
for(uint8_t i=0; i<EF_DIR->applications_count; ++i) {
|
||||
for(uint8_t n=0; n<sizeof(AIDValue); ++n) {
|
||||
furi_string_cat_printf(temp_str, "%02X ", EF_DIR->applications[i][n]);
|
||||
}
|
||||
furi_string_cat_printf(temp_str, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
EF_DG1_contents* DG1 = &mrtd_data->files.DG1;
|
||||
furi_string_cat_printf(temp_str, "\e#DG1\n");
|
||||
furi_string_cat_printf(temp_str, "Doc Type: %s\n", DG1->doctype);
|
||||
furi_string_cat_printf(temp_str, "Issuing State: %s\n", DG1->issuing_state);
|
||||
furi_string_cat_printf(temp_str, "Name: %s\n", DG1->name);
|
||||
furi_string_cat_printf(temp_str, "DocNr: %s\n", DG1->docnr);
|
||||
furi_string_cat_printf(temp_str, "Nationality: %s\n", DG1->nationality);
|
||||
furi_string_cat_printf(temp_str, "Birth Date: %02d %s %02d\n", DG1->birth_date.day, months[DG1->birth_date.month], DG1->birth_date.year);
|
||||
furi_string_cat_printf(temp_str, "Sex: %s\n", DG1->sex);
|
||||
furi_string_cat_printf(temp_str, "Expiry Date: %02d %s %02d\n", DG1->expiry_date.day, months[DG1->expiry_date.month], DG1->expiry_date.year);
|
||||
|
||||
widget_add_text_scroll_element(widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
||||
furi_string_free(temp_str);
|
||||
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeLeft, "Retry", nfc_scene_passport_read_auth_widget_callback, nfc);
|
||||
/*
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeCenter, "Auth", nfc_scene_passport_read_auth_widget_callback, nfc);
|
||||
widget_add_button_element(
|
||||
nfc->widget, GuiButtonTypeRight, "More", nfc_scene_passport_read_auth_widget_callback, nfc);
|
||||
*/
|
||||
|
||||
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
||||
}
|
||||
|
||||
bool nfc_scene_passport_read_auth_on_event(void* context, SceneManagerEvent event) {
|
||||
Nfc* nfc = context;
|
||||
bool consumed = false;
|
||||
|
||||
if(event.type == SceneManagerEventTypeCustom) {
|
||||
if(event.event == GuiButtonTypeLeft) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
|
||||
consumed = true;
|
||||
} else if(event.event == GuiButtonTypeCenter) {
|
||||
//scene_manager_next_scene(nfc->scene_manager, NfcScenePassportAuth);
|
||||
//consumed = true;
|
||||
} else if(event.event == GuiButtonTypeRight) {
|
||||
//scene_manager_next_scene(nfc->scene_manager, NfcScenePassportMenu);
|
||||
//consumed = true;
|
||||
}
|
||||
} else if(event.type == SceneManagerEventTypeBack) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
|
||||
consumed = true;
|
||||
}
|
||||
return consumed;
|
||||
}
|
||||
|
||||
void nfc_scene_passport_read_auth_on_exit(void* context) {
|
||||
Nfc* nfc = context;
|
||||
|
||||
// Clear view
|
||||
widget_reset(nfc->widget);
|
||||
}
|
||||
@@ -83,6 +83,16 @@ bool nfc_scene_read_on_event(void* context, SceneManagerEvent event) {
|
||||
notification_message(nfc->notifications, &sequence_success);
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneEmvReadSuccess);
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventReadPassport) {
|
||||
notification_message(nfc->notifications, &sequence_success);
|
||||
if(nfc->dev->dev_data.mrtd_data.auth_success) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportReadAuthSuccess);
|
||||
//TODO: } else if(nfc->dev->dev_data.mrtd_data.auth.method != MrtdAuthMethodNone) {
|
||||
//scene_manager_next_scene(nfc->scene_manager, NfcScenePassportReadAuthFailed);
|
||||
} else {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcScenePassportReadSuccess);
|
||||
}
|
||||
consumed = true;
|
||||
} else if(event.event == NfcWorkerEventReadMfClassicDictAttackRequired) {
|
||||
if(mf_classic_dict_check_presence(MfClassicDictTypeFlipper)) {
|
||||
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicDictAttack);
|
||||
|
||||
Reference in New Issue
Block a user