2021-07-22 06:05:07 +00:00
|
|
|
#include "../nfc_i.h"
|
|
|
|
|
2021-09-15 15:24:19 +00:00
|
|
|
void nfc_scene_delete_widget_callback(GuiButtonType result, InputType type, void* context) {
|
2021-07-22 06:05:07 +00:00
|
|
|
Nfc* nfc = (Nfc*)context;
|
2021-09-15 15:24:19 +00:00
|
|
|
if(type == InputTypeShort) {
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
|
|
|
|
}
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_scene_delete_on_enter(void* context) {
|
|
|
|
Nfc* nfc = (Nfc*)context;
|
|
|
|
|
|
|
|
// Setup Custom Widget view
|
|
|
|
char delete_str[64];
|
2021-11-08 21:55:06 +00:00
|
|
|
snprintf(delete_str, sizeof(delete_str), "\e#Delete %s\e#", nfc->dev->dev_name);
|
2021-10-27 18:55:03 +00:00
|
|
|
widget_add_text_box_element(nfc->widget, 0, 0, 128, 24, AlignCenter, AlignCenter, delete_str);
|
2021-07-23 13:09:34 +00:00
|
|
|
widget_add_button_element(
|
2021-07-22 06:05:07 +00:00
|
|
|
nfc->widget, GuiButtonTypeLeft, "Back", nfc_scene_delete_widget_callback, nfc);
|
2021-07-23 13:09:34 +00:00
|
|
|
widget_add_button_element(
|
2021-07-22 06:05:07 +00:00
|
|
|
nfc->widget, GuiButtonTypeRight, "Delete", nfc_scene_delete_widget_callback, nfc);
|
|
|
|
char uid_str[32];
|
2021-11-08 21:55:06 +00:00
|
|
|
NfcDeviceCommonData* data = &nfc->dev->dev_data.nfc_data;
|
2021-07-22 06:05:07 +00:00
|
|
|
if(data->uid_len == 4) {
|
|
|
|
snprintf(
|
|
|
|
uid_str,
|
|
|
|
sizeof(uid_str),
|
|
|
|
"UID: %02X %02X %02X %02X",
|
|
|
|
data->uid[0],
|
|
|
|
data->uid[1],
|
|
|
|
data->uid[2],
|
|
|
|
data->uid[3]);
|
|
|
|
} else if(data->uid_len == 7) {
|
|
|
|
snprintf(
|
|
|
|
uid_str,
|
|
|
|
sizeof(uid_str),
|
|
|
|
"UID: %02X %02X %02X %02X %02X %02X %02X",
|
|
|
|
data->uid[0],
|
|
|
|
data->uid[1],
|
|
|
|
data->uid[2],
|
|
|
|
data->uid[3],
|
|
|
|
data->uid[4],
|
|
|
|
data->uid[5],
|
|
|
|
data->uid[6]);
|
|
|
|
}
|
2021-07-23 13:09:34 +00:00
|
|
|
widget_add_string_element(nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, uid_str);
|
2021-07-22 06:05:07 +00:00
|
|
|
|
2021-12-21 12:33:17 +00:00
|
|
|
const char* protocol_name = NULL;
|
|
|
|
if(data->protocol == NfcDeviceProtocolEMV) {
|
|
|
|
protocol_name = nfc_guess_protocol(data->protocol);
|
|
|
|
} else if(data->protocol == NfcDeviceProtocolMifareUl) {
|
|
|
|
protocol_name = nfc_mf_ul_type(nfc->dev->dev_data.mf_ul_data.type, false);
|
|
|
|
}
|
|
|
|
if(protocol_name) {
|
2021-07-23 13:09:34 +00:00
|
|
|
widget_add_string_element(
|
2021-12-21 12:33:17 +00:00
|
|
|
nfc->widget, 10, 32, AlignLeft, AlignTop, FontSecondary, protocol_name);
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
// TODO change dinamically
|
2021-07-23 13:09:34 +00:00
|
|
|
widget_add_string_element(nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A");
|
2021-07-22 06:05:07 +00:00
|
|
|
char sak_str[16];
|
|
|
|
snprintf(sak_str, sizeof(sak_str), "SAK: %02X", data->sak);
|
2021-07-23 13:09:34 +00:00
|
|
|
widget_add_string_element(nfc->widget, 10, 42, AlignLeft, AlignTop, FontSecondary, sak_str);
|
2021-07-22 06:05:07 +00:00
|
|
|
char atqa_str[16];
|
|
|
|
snprintf(atqa_str, sizeof(atqa_str), "ATQA: %02X%02X", data->atqa[0], data->atqa[1]);
|
2021-07-23 13:09:34 +00:00
|
|
|
widget_add_string_element(nfc->widget, 118, 42, AlignRight, AlignTop, FontSecondary, atqa_str);
|
2021-07-22 06:05:07 +00:00
|
|
|
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
bool nfc_scene_delete_on_event(void* context, SceneManagerEvent event) {
|
2021-07-22 06:05:07 +00:00
|
|
|
Nfc* nfc = (Nfc*)context;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if(event.event == GuiButtonTypeLeft) {
|
|
|
|
return scene_manager_previous_scene(nfc->scene_manager);
|
|
|
|
} else if(event.event == GuiButtonTypeRight) {
|
2021-11-08 21:55:06 +00:00
|
|
|
if(nfc_device_delete(nfc->dev)) {
|
2021-07-22 06:05:07 +00:00
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneDeleteSuccess);
|
|
|
|
} else {
|
2021-07-28 14:52:00 +00:00
|
|
|
scene_manager_search_and_switch_to_previous_scene(
|
|
|
|
nfc->scene_manager, NfcSceneStart);
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2021-09-21 09:34:16 +00:00
|
|
|
void nfc_scene_delete_on_exit(void* context) {
|
2021-07-22 06:05:07 +00:00
|
|
|
Nfc* nfc = (Nfc*)context;
|
|
|
|
|
2021-07-23 13:09:34 +00:00
|
|
|
widget_clear(nfc->widget);
|
2021-07-22 06:05:07 +00:00
|
|
|
}
|