2022-03-23 13:45:37 +00:00
|
|
|
#include "../nfc_i.h"
|
|
|
|
#include <dolphin/dolphin.h>
|
|
|
|
|
|
|
|
#define NFC_SCENE_READ_SUCCESS_SHIFT " "
|
|
|
|
|
|
|
|
enum {
|
2022-07-26 15:30:49 +00:00
|
|
|
MfDesfireReadSuccessStateShowUID,
|
|
|
|
MfDesfireReadSuccessStateShowData,
|
2022-03-23 13:45:37 +00:00
|
|
|
};
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
void nfc_scene_mf_desfire_read_success_dialog_callback(DialogExResult result, void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
view_dispatcher_send_custom_event(nfc->view_dispatcher, result);
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
void nfc_scene_mf_desfire_read_success_on_enter(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
MifareDesfireData* data = &nfc->dev->dev_data.mf_df_data;
|
|
|
|
DialogEx* dialog_ex = nfc->dialog_ex;
|
2022-07-26 15:30:49 +00:00
|
|
|
dialog_ex_set_left_button_text(dialog_ex, "Retry");
|
2022-03-23 13:45:37 +00:00
|
|
|
dialog_ex_set_center_button_text(dialog_ex, "Data");
|
|
|
|
dialog_ex_set_right_button_text(dialog_ex, "More");
|
|
|
|
dialog_ex_set_icon(dialog_ex, 8, 16, &I_Medium_chip_22x21);
|
|
|
|
|
|
|
|
uint16_t n_apps = 0;
|
|
|
|
uint16_t n_files = 0;
|
|
|
|
|
|
|
|
for(MifareDesfireApplication* app = data->app_head; app; app = app->next) {
|
|
|
|
n_apps++;
|
|
|
|
for(MifareDesfireFile* file = app->file_head; file; file = file->next) {
|
|
|
|
n_files++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-28 12:34:28 +00:00
|
|
|
// TODO rework info view
|
2022-03-23 13:45:37 +00:00
|
|
|
nfc_text_store_set(
|
|
|
|
nfc,
|
2022-07-28 12:34:28 +00:00
|
|
|
NFC_SCENE_READ_SUCCESS_SHIFT "Mifare DESFire\n" NFC_SCENE_READ_SUCCESS_SHIFT
|
|
|
|
"%d%s bytes\n" NFC_SCENE_READ_SUCCESS_SHIFT "%d bytes free\n"
|
|
|
|
"%d application%s, %d file%s",
|
2022-03-23 13:45:37 +00:00
|
|
|
1 << (data->version.sw_storage >> 1),
|
|
|
|
(data->version.sw_storage & 1) ? "+" : "",
|
|
|
|
data->free_memory ? data->free_memory->bytes : 0,
|
|
|
|
n_apps,
|
|
|
|
n_apps == 1 ? "" : "s",
|
|
|
|
n_files,
|
|
|
|
n_files == 1 ? "" : "s");
|
|
|
|
dialog_ex_set_text(dialog_ex, nfc->text_store, 8, 6, AlignLeft, AlignTop);
|
|
|
|
dialog_ex_set_context(dialog_ex, nfc);
|
2022-07-26 15:30:49 +00:00
|
|
|
dialog_ex_set_result_callback(dialog_ex, nfc_scene_mf_desfire_read_success_dialog_callback);
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
scene_manager_set_scene_state(
|
2022-07-26 15:30:49 +00:00
|
|
|
nfc->scene_manager, NfcSceneMfDesfireReadSuccess, MfDesfireReadSuccessStateShowUID);
|
2022-03-23 13:45:37 +00:00
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx);
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
bool nfc_scene_mf_desfire_read_success_on_event(void* context, SceneManagerEvent event) {
|
2022-03-23 13:45:37 +00:00
|
|
|
Nfc* nfc = context;
|
2022-04-19 15:23:58 +00:00
|
|
|
bool consumed = false;
|
2022-03-23 13:45:37 +00:00
|
|
|
uint32_t state =
|
2022-07-26 15:30:49 +00:00
|
|
|
scene_manager_get_scene_state(nfc->scene_manager, NfcSceneMfDesfireReadSuccess);
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
if(event.type == SceneManagerEventTypeCustom) {
|
2022-07-26 15:30:49 +00:00
|
|
|
if(state == MfDesfireReadSuccessStateShowUID && event.event == DialogExResultLeft) {
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneRetryConfirm);
|
2022-03-23 13:45:37 +00:00
|
|
|
consumed = true;
|
2022-07-26 15:30:49 +00:00
|
|
|
} else if(state == MfDesfireReadSuccessStateShowUID && event.event == DialogExResultCenter) {
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfDesfireData);
|
2022-03-23 13:45:37 +00:00
|
|
|
consumed = true;
|
2022-07-26 15:30:49 +00:00
|
|
|
} else if(state == MfDesfireReadSuccessStateShowUID && event.event == DialogExResultRight) {
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfDesfireMenu);
|
2022-03-23 13:45:37 +00:00
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
} else if(event.type == SceneManagerEventTypeBack) {
|
2022-07-26 15:30:49 +00:00
|
|
|
if(state == MfDesfireReadSuccessStateShowData) {
|
2022-03-23 13:45:37 +00:00
|
|
|
view_dispatcher_switch_to_view(nfc->view_dispatcher, NfcViewDialogEx);
|
|
|
|
scene_manager_set_scene_state(
|
|
|
|
nfc->scene_manager,
|
2022-07-26 15:30:49 +00:00
|
|
|
NfcSceneMfDesfireReadSuccess,
|
|
|
|
MfDesfireReadSuccessStateShowUID);
|
|
|
|
consumed = true;
|
|
|
|
} else {
|
|
|
|
scene_manager_next_scene(nfc->scene_manager, NfcSceneExitConfirm);
|
2022-03-23 13:45:37 +00:00
|
|
|
consumed = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return consumed;
|
|
|
|
}
|
|
|
|
|
2022-07-26 15:30:49 +00:00
|
|
|
void nfc_scene_mf_desfire_read_success_on_exit(void* context) {
|
2022-04-19 15:23:58 +00:00
|
|
|
Nfc* nfc = context;
|
2022-03-23 13:45:37 +00:00
|
|
|
|
|
|
|
// Clean dialog
|
2022-04-19 15:23:58 +00:00
|
|
|
dialog_ex_reset(nfc->dialog_ex);
|
2022-03-23 13:45:37 +00:00
|
|
|
}
|