2021-07-22 09:05:07 +03:00
|
|
|
#include "../nfc_i.h"
|
2021-11-09 00:55:06 +03:00
|
|
|
#include "../helpers/nfc_emv_parser.h"
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2021-09-15 18:24:19 +03:00
|
|
|
void nfc_scene_device_info_widget_callback(GuiButtonType result, InputType type, void* context) {
|
2021-08-20 22:56:43 +03:00
|
|
|
Nfc* nfc = context;
|
2021-09-15 18:24:19 +03:00
|
|
|
if(type == InputTypeShort) {
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
|
|
|
|
}
|
2021-07-22 09:05:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
void nfc_scene_device_info_on_enter(void* context) {
|
2021-08-20 22:56:43 +03:00
|
|
|
Nfc* nfc = context;
|
2022-08-17 18:08:13 +03:00
|
|
|
NfcDeviceData* dev_data = &nfc->dev->dev_data;
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* temp_str;
|
|
|
|
temp_str = furi_string_alloc();
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-08-17 18:08:13 +03:00
|
|
|
if(dev_data->protocol == NfcDeviceProtocolEMV) {
|
|
|
|
EmvData* emv_data = &dev_data->emv_data;
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_printf(temp_str, "\e#%s\n", emv_data->name);
|
2022-08-17 18:08:13 +03:00
|
|
|
for(uint8_t i = 0; i < emv_data->number_len; i += 2) {
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_cat_printf(
|
|
|
|
temp_str, "%02X%02X ", emv_data->number[i], emv_data->number[i + 1]);
|
2022-08-17 18:08:13 +03:00
|
|
|
}
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_trim(temp_str);
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-08-17 18:08:13 +03:00
|
|
|
// Add expiration date
|
|
|
|
if(emv_data->exp_mon) {
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_cat_printf(
|
|
|
|
temp_str, "\nExp: %02X/%02X", emv_data->exp_mon, emv_data->exp_year);
|
2021-07-22 09:05:07 +03:00
|
|
|
}
|
2022-08-17 18:08:13 +03:00
|
|
|
// Parse currency code
|
|
|
|
if((emv_data->currency_code)) {
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* currency_name;
|
|
|
|
currency_name = furi_string_alloc();
|
2022-08-17 18:08:13 +03:00
|
|
|
if(nfc_emv_parser_get_currency_name(
|
|
|
|
nfc->dev->storage, emv_data->currency_code, currency_name)) {
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_cat_printf(
|
|
|
|
temp_str, "\nCur: %s ", furi_string_get_cstr(currency_name));
|
2022-03-23 16:45:37 +03:00
|
|
|
}
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_free(currency_name);
|
2022-03-23 16:45:37 +03:00
|
|
|
}
|
2022-08-17 18:08:13 +03:00
|
|
|
// Parse country code
|
|
|
|
if((emv_data->country_code)) {
|
2022-10-05 18:15:23 +03:00
|
|
|
FuriString* country_name;
|
|
|
|
country_name = furi_string_alloc();
|
2021-11-09 00:55:06 +03:00
|
|
|
if(nfc_emv_parser_get_country_name(
|
|
|
|
nfc->dev->storage, emv_data->country_code, country_name)) {
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_cat_printf(temp_str, "Reg: %s", furi_string_get_cstr(country_name));
|
2021-11-09 00:55:06 +03:00
|
|
|
}
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_free(country_name);
|
2021-08-20 22:56:43 +03:00
|
|
|
}
|
2022-09-19 19:05:04 +03:00
|
|
|
} else if(
|
|
|
|
dev_data->protocol == NfcDeviceProtocolMifareClassic ||
|
|
|
|
dev_data->protocol == NfcDeviceProtocolMifareUl) {
|
2022-10-05 18:15:23 +03:00
|
|
|
furi_string_set(temp_str, nfc->dev->dev_data.parsed_data);
|
2021-07-22 09:05:07 +03:00
|
|
|
}
|
2022-08-17 18:08:13 +03:00
|
|
|
|
2022-10-05 18:15:23 +03:00
|
|
|
widget_add_text_scroll_element(nfc->widget, 0, 0, 128, 52, furi_string_get_cstr(temp_str));
|
|
|
|
furi_string_free(temp_str);
|
2022-08-17 18:08:13 +03:00
|
|
|
|
|
|
|
widget_add_button_element(
|
|
|
|
nfc->widget, GuiButtonTypeRight, "More", nfc_scene_device_info_widget_callback, nfc);
|
|
|
|
|
2021-07-22 09:05:07 +03:00
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
|
|
|
}
|
|
|
|
|
2021-09-21 12:34:16 +03:00
|
|
|
bool nfc_scene_device_info_on_event(void* context, SceneManagerEvent event) {
|
2021-08-20 22:56:43 +03:00
|
|
|
Nfc* nfc = context;
|
2021-07-22 09:05:07 +03:00
|
|
|
bool consumed = false;
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-08-17 18:08:13 +03:00
|
|
|
if(event.event == GuiButtonTypeRight) {
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcDataInfo);
|
2021-07-22 09:05:07 +03:00
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2021-09-21 12:34:16 +03:00
|
|
|
void nfc_scene_device_info_on_exit(void* context) {
|
2022-04-19 18:23:58 +03:00
|
|
|
Nfc* nfc = context;
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-04-19 18:23:58 +03:00
|
|
|
// Clear views
|
2022-02-02 22:59:28 +03:00
|
|
|
widget_reset(nfc->widget);
|
2021-07-22 09:05:07 +03:00
|
|
|
}
|