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
|
|
|
|
|
|
|
enum {
|
|
|
|
NfcSceneDeviceInfoUid,
|
|
|
|
NfcSceneDeviceInfoData,
|
|
|
|
};
|
|
|
|
|
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_dialog_callback(DialogExResult result, void* context) {
|
2021-08-20 22:56:43 +03:00
|
|
|
Nfc* nfc = context;
|
2022-02-02 22:59:28 +03:00
|
|
|
if(result == DialogExResultLeft) {
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventViewExit);
|
|
|
|
}
|
2021-08-20 22:56:43 +03:00
|
|
|
}
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2021-09-15 18:24:19 +03:00
|
|
|
void nfc_scene_device_info_bank_card_callback(GuiButtonType result, InputType type, void* context) {
|
2022-05-06 16:37:10 +03:00
|
|
|
UNUSED(result);
|
2021-08-20 22:56:43 +03:00
|
|
|
Nfc* nfc = context;
|
2021-09-15 18:24:19 +03:00
|
|
|
if(type == InputTypeShort) {
|
2022-02-02 22:59:28 +03:00
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, NfcCustomEventViewExit);
|
2021-09-15 18:24:19 +03:00
|
|
|
}
|
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;
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2022-03-24 01:14:34 +03:00
|
|
|
bool data_display_supported = (nfc->dev->format == NfcDeviceSaveFormatUid) ||
|
|
|
|
(nfc->dev->format == NfcDeviceSaveFormatMifareUl) ||
|
|
|
|
(nfc->dev->format == NfcDeviceSaveFormatMifareDesfire) ||
|
|
|
|
(nfc->dev->format == NfcDeviceSaveFormatBankCard);
|
2021-07-22 09:05:07 +03:00
|
|
|
// Setup Custom Widget view
|
2021-10-27 21:55:03 +03:00
|
|
|
widget_add_text_box_element(
|
2022-04-19 22:23:50 +03:00
|
|
|
nfc->widget, 0, 0, 128, 22, AlignCenter, AlignTop, nfc->dev->dev_name, false);
|
2021-07-23 16:09:34 +03:00
|
|
|
widget_add_button_element(
|
2021-07-22 09:05:07 +03:00
|
|
|
nfc->widget, GuiButtonTypeLeft, "Back", nfc_scene_device_info_widget_callback, nfc);
|
2022-03-24 01:14:34 +03:00
|
|
|
if(data_display_supported) {
|
|
|
|
widget_add_button_element(
|
|
|
|
nfc->widget, GuiButtonTypeRight, "Data", nfc_scene_device_info_widget_callback, nfc);
|
|
|
|
}
|
2022-04-19 18:23:58 +03:00
|
|
|
char temp_str[32];
|
|
|
|
FuriHalNfcDevData* data = &nfc->dev->dev_data.nfc_data;
|
2021-07-22 09:05:07 +03:00
|
|
|
if(data->uid_len == 4) {
|
|
|
|
snprintf(
|
2022-04-19 18:23:58 +03:00
|
|
|
temp_str,
|
|
|
|
sizeof(temp_str),
|
2021-07-22 09:05:07 +03:00
|
|
|
"UID: %02X %02X %02X %02X",
|
|
|
|
data->uid[0],
|
|
|
|
data->uid[1],
|
|
|
|
data->uid[2],
|
|
|
|
data->uid[3]);
|
|
|
|
} else if(data->uid_len == 7) {
|
|
|
|
snprintf(
|
2022-04-19 18:23:58 +03:00
|
|
|
temp_str,
|
|
|
|
sizeof(temp_str),
|
2021-07-22 09:05:07 +03:00
|
|
|
"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]);
|
|
|
|
}
|
2022-04-19 18:23:58 +03:00
|
|
|
widget_add_string_element(nfc->widget, 64, 21, AlignCenter, AlignTop, FontSecondary, temp_str);
|
2021-07-22 09:05:07 +03:00
|
|
|
|
2021-12-21 15:33:17 +03:00
|
|
|
const char* protocol_name = NULL;
|
2022-04-19 18:23:58 +03:00
|
|
|
NfcProtocol protocol = nfc->dev->dev_data.protocol;
|
|
|
|
if(protocol == NfcDeviceProtocolEMV || protocol == NfcDeviceProtocolMifareDesfire) {
|
|
|
|
protocol_name = nfc_guess_protocol(protocol);
|
|
|
|
} else if(protocol == NfcDeviceProtocolMifareUl) {
|
2021-12-21 15:33:17 +03:00
|
|
|
protocol_name = nfc_mf_ul_type(nfc->dev->dev_data.mf_ul_data.type, false);
|
2022-04-19 18:23:58 +03:00
|
|
|
} else if(protocol == NfcDeviceProtocolMifareClassic) {
|
2022-03-24 01:14:34 +03:00
|
|
|
protocol_name = nfc_mf_classic_type(nfc->dev->dev_data.mf_classic_data.type);
|
2021-12-21 15:33:17 +03:00
|
|
|
}
|
|
|
|
if(protocol_name) {
|
2021-07-23 16:09:34 +03:00
|
|
|
widget_add_string_element(
|
2021-12-21 15:33:17 +03:00
|
|
|
nfc->widget, 10, 32, AlignLeft, AlignTop, FontSecondary, protocol_name);
|
2021-07-22 09:05:07 +03:00
|
|
|
}
|
|
|
|
// TODO change dinamically
|
2021-07-23 16:09:34 +03:00
|
|
|
widget_add_string_element(nfc->widget, 118, 32, AlignRight, AlignTop, FontSecondary, "NFC-A");
|
2022-04-19 18:23:58 +03:00
|
|
|
snprintf(temp_str, sizeof(temp_str), "SAK: %02X", data->sak);
|
|
|
|
widget_add_string_element(nfc->widget, 10, 42, AlignLeft, AlignTop, FontSecondary, temp_str);
|
|
|
|
snprintf(temp_str, sizeof(temp_str), "ATQA: %02X%02X", data->atqa[0], data->atqa[1]);
|
|
|
|
widget_add_string_element(nfc->widget, 118, 42, AlignRight, AlignTop, FontSecondary, temp_str);
|
2021-07-22 09:05:07 +03:00
|
|
|
|
|
|
|
// Setup Data View
|
2021-11-09 00:55:06 +03:00
|
|
|
if(nfc->dev->format == NfcDeviceSaveFormatUid) {
|
2021-07-22 09:05:07 +03:00
|
|
|
DialogEx* dialog_ex = nfc->dialog_ex;
|
|
|
|
dialog_ex_set_left_button_text(dialog_ex, "Back");
|
|
|
|
dialog_ex_set_text(dialog_ex, "No data", 64, 32, AlignCenter, AlignCenter);
|
|
|
|
dialog_ex_set_context(dialog_ex, nfc);
|
|
|
|
dialog_ex_set_result_callback(dialog_ex, nfc_scene_device_info_dialog_callback);
|
2021-11-09 00:55:06 +03:00
|
|
|
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
|
2022-04-19 18:23:58 +03:00
|
|
|
MfUltralightData* mf_ul_data = &nfc->dev->dev_data.mf_ul_data;
|
2021-07-22 09:05:07 +03:00
|
|
|
TextBox* text_box = nfc->text_box;
|
|
|
|
text_box_set_font(text_box, TextBoxFontHex);
|
|
|
|
for(uint16_t i = 0; i < mf_ul_data->data_size; i += 2) {
|
|
|
|
if(!(i % 8) && i) {
|
|
|
|
string_push_back(nfc->text_box_store, '\n');
|
|
|
|
}
|
|
|
|
string_cat_printf(
|
|
|
|
nfc->text_box_store, "%02X%02X ", mf_ul_data->data[i], mf_ul_data->data[i + 1]);
|
|
|
|
}
|
|
|
|
text_box_set_text(text_box, string_get_cstr(nfc->text_box_store));
|
2022-03-23 16:45:37 +03:00
|
|
|
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareDesfire) {
|
|
|
|
MifareDesfireData* mf_df_data = &nfc->dev->dev_data.mf_df_data;
|
|
|
|
uint16_t n_apps = 0;
|
|
|
|
uint16_t n_files = 0;
|
|
|
|
for(MifareDesfireApplication* app = mf_df_data->app_head; app; app = app->next) {
|
|
|
|
n_apps++;
|
|
|
|
for(MifareDesfireFile* file = app->file_head; file; file = file->next) {
|
|
|
|
n_files++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
nfc_text_store_set(
|
|
|
|
nfc,
|
|
|
|
"%d application%s, %d file%s",
|
|
|
|
n_apps,
|
|
|
|
n_apps == 1 ? "" : "s",
|
|
|
|
n_files,
|
|
|
|
n_files == 1 ? "" : "s");
|
|
|
|
widget_add_string_element(
|
|
|
|
nfc->widget, 64, 17, AlignCenter, AlignBottom, FontSecondary, nfc->text_store);
|
2021-11-09 00:55:06 +03:00
|
|
|
} else if(nfc->dev->format == NfcDeviceSaveFormatBankCard) {
|
2022-04-19 18:23:58 +03:00
|
|
|
EmvData* emv_data = &nfc->dev->dev_data.emv_data;
|
2021-07-22 09:05:07 +03:00
|
|
|
BankCard* bank_card = nfc->bank_card;
|
|
|
|
bank_card_set_name(bank_card, emv_data->name);
|
2021-10-05 08:14:19 +03:00
|
|
|
bank_card_set_number(bank_card, emv_data->number, emv_data->number_len);
|
2021-08-20 22:56:43 +03:00
|
|
|
bank_card_set_back_callback(bank_card, nfc_scene_device_info_bank_card_callback, nfc);
|
2021-07-22 09:05:07 +03:00
|
|
|
if(emv_data->exp_mon) {
|
|
|
|
bank_card_set_exp_date(bank_card, emv_data->exp_mon, emv_data->exp_year);
|
|
|
|
}
|
2021-11-09 00:55:06 +03:00
|
|
|
string_t display_str;
|
|
|
|
string_init(display_str);
|
2021-08-20 22:56:43 +03:00
|
|
|
if(emv_data->country_code) {
|
2021-11-09 00:55:06 +03:00
|
|
|
string_t country_name;
|
|
|
|
string_init(country_name);
|
|
|
|
if(nfc_emv_parser_get_country_name(
|
|
|
|
nfc->dev->storage, emv_data->country_code, country_name)) {
|
|
|
|
string_printf(display_str, "Reg:%s", string_get_cstr(country_name));
|
|
|
|
bank_card_set_country_name(bank_card, string_get_cstr(display_str));
|
|
|
|
}
|
|
|
|
string_clear(country_name);
|
2021-08-20 22:56:43 +03:00
|
|
|
}
|
|
|
|
if(emv_data->currency_code) {
|
2021-11-09 00:55:06 +03:00
|
|
|
string_t currency_name;
|
|
|
|
string_init(currency_name);
|
|
|
|
if(nfc_emv_parser_get_currency_name(
|
|
|
|
nfc->dev->storage, emv_data->country_code, currency_name)) {
|
|
|
|
string_printf(display_str, "Cur:%s", string_get_cstr(currency_name));
|
|
|
|
bank_card_set_currency_name(bank_card, string_get_cstr(display_str));
|
|
|
|
}
|
|
|
|
string_clear(currency_name);
|
2021-08-20 22:56:43 +03:00
|
|
|
}
|
2021-11-09 00:55:06 +03:00
|
|
|
string_clear(display_str);
|
2021-07-22 09:05:07 +03:00
|
|
|
}
|
|
|
|
scene_manager_set_scene_state(nfc->scene_manager, NfcSceneDeviceInfo, NfcSceneDeviceInfoUid);
|
|
|
|
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;
|
|
|
|
uint32_t state = scene_manager_get_scene_state(nfc->scene_manager, NfcSceneDeviceInfo);
|
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
|
|
|
if((state == NfcSceneDeviceInfoUid) && (event.event == GuiButtonTypeLeft)) {
|
|
|
|
consumed = scene_manager_previous_scene(nfc->scene_manager);
|
|
|
|
} else if((state == NfcSceneDeviceInfoUid) && (event.event == GuiButtonTypeRight)) {
|
2021-11-09 00:55:06 +03:00
|
|
|
if(nfc->dev->format == NfcDeviceSaveFormatUid) {
|
2021-07-22 09:05:07 +03:00
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager, NfcSceneDeviceInfo, NfcSceneDeviceInfoData);
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx);
|
|
|
|
consumed = true;
|
2021-11-09 00:55:06 +03:00
|
|
|
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
|
2021-07-22 09:05:07 +03:00
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager, NfcSceneDeviceInfo, NfcSceneDeviceInfoData);
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewTextBox);
|
|
|
|
consumed = true;
|
2021-11-09 00:55:06 +03:00
|
|
|
} else if(nfc->dev->format == NfcDeviceSaveFormatBankCard) {
|
2021-07-22 09:05:07 +03:00
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager, NfcSceneDeviceInfo, NfcSceneDeviceInfoData);
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewBankCard);
|
|
|
|
consumed = true;
|
2022-03-23 16:45:37 +03:00
|
|
|
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareDesfire) {
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneMifareDesfireData);
|
|
|
|
consumed = true;
|
2021-07-22 09:05:07 +03:00
|
|
|
}
|
2022-02-02 22:59:28 +03:00
|
|
|
} else if(state == NfcSceneDeviceInfoData && event.event == NfcCustomEventViewExit) {
|
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager, NfcSceneDeviceInfo, NfcSceneDeviceInfoUid);
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
} else if(event.type == SceneManagerEventTypeBack) {
|
|
|
|
if(state == NfcSceneDeviceInfoData) {
|
2021-07-22 09:05:07 +03:00
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager, NfcSceneDeviceInfo, NfcSceneDeviceInfoUid);
|
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewWidget);
|
|
|
|
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-11-09 00:55:06 +03:00
|
|
|
if(nfc->dev->format == NfcDeviceSaveFormatUid) {
|
2022-04-19 18:23:58 +03:00
|
|
|
dialog_ex_reset(nfc->dialog_ex);
|
2021-11-09 00:55:06 +03:00
|
|
|
} else if(nfc->dev->format == NfcDeviceSaveFormatMifareUl) {
|
2022-01-21 20:32:03 +03:00
|
|
|
text_box_reset(nfc->text_box);
|
2021-11-15 20:09:40 +03:00
|
|
|
string_reset(nfc->text_box_store);
|
2021-11-09 00:55:06 +03:00
|
|
|
} else if(nfc->dev->format == NfcDeviceSaveFormatBankCard) {
|
2021-07-22 09:05:07 +03:00
|
|
|
bank_card_clear(nfc->bank_card);
|
|
|
|
}
|
|
|
|
}
|