This commit is contained in:
Willy-JL
2024-01-31 01:59:45 +00:00
12 changed files with 110 additions and 27 deletions

View File

@@ -30,4 +30,6 @@ typedef enum {
NfcCustomEventPollerFailure,
NfcCustomEventListenerUpdate,
NfcCustomEventEmulationTimeExpired,
} NfcCustomEvent;

View File

@@ -97,12 +97,12 @@ void nfc_render_emv_application(const EmvApplication* apl, FuriString* str) {
static void nfc_render_emv_pin_try_counter(uint8_t counter, FuriString* str) {
if(counter == 0xff) return;
furi_string_cat_printf(str, "PIN try left: %d\n", counter);
furi_string_cat_printf(str, "PIN attempts left: %d\n", counter);
}
void nfc_render_emv_transactions(const EmvApplication* apl, FuriString* str) {
if(apl->transaction_counter)
furi_string_cat_printf(str, "Transactions: %d\n", apl->transaction_counter);
furi_string_cat_printf(str, "Transactions count: %d\n", apl->transaction_counter);
if(apl->last_online_atc)
furi_string_cat_printf(str, "Last Online ATC: %d\n", apl->last_online_atc);
@@ -115,27 +115,31 @@ void nfc_render_emv_transactions(const EmvApplication* apl, FuriString* str) {
Storage* storage = furi_record_open(RECORD_STORAGE);
FuriString* tmp = furi_string_alloc();
//furi_string_cat_printf(str, "Transactions:\n");
furi_string_cat_printf(str, "Transactions:\n");
for(int i = 0; i < len; i++) {
if(!apl->trans[i].amount) continue;
//if(!apl->trans[i].amount) continue; - NO Skip here pls
// transaction counter
furi_string_cat_printf(str, "\e#%d: ", apl->trans[i].atc);
// Print transaction amount
uint8_t* a = (uint8_t*)&apl->trans[i].amount;
bool top = true;
for(int x = 0; x < 6; x++) {
// cents
if(x == 5) {
furi_string_cat_printf(str, ".%02X", a[x]);
break;
}
if(a[x]) {
if(top) {
furi_string_cat_printf(str, "%X", a[x]);
top = false;
} else {
furi_string_cat_printf(str, "%02X", a[x]);
if(!apl->trans[i].amount) {
furi_string_cat_printf(str, "???");
} else {
uint8_t* a = (uint8_t*)&apl->trans[i].amount;
bool top = true;
for(int x = 0; x < 6; x++) {
// cents
if(x == 5) {
furi_string_cat_printf(str, ".%02X", a[x]);
break;
}
if(a[x]) {
if(top) {
furi_string_cat_printf(str, "%X", a[x]);
top = false;
} else {
furi_string_cat_printf(str, "%02X", a[x]);
}
}
}
}
@@ -155,7 +159,7 @@ void nfc_render_emv_transactions(const EmvApplication* apl, FuriString* str) {
if(apl->trans[i].date)
furi_string_cat_printf(
str,
"%02lx/%02lx/%02lx ",
"%02lx.%02lx.%02lx ",
apl->trans[i].date >> 16,
(apl->trans[i].date >> 8) & 0xff,
apl->trans[i].date & 0xff);

View File

@@ -105,7 +105,7 @@ static bool emv_parse(const NfcDevice* device, FuriString* parsed_data) {
furi_string_cat_printf(parsed_data, "Currency: %s\n", furi_string_get_cstr(str));
if(app.pin_try_counter != 0xFF)
furi_string_cat_printf(parsed_data, "PIN try left: %d\n", app.pin_try_counter);
furi_string_cat_printf(parsed_data, "PIN attempts left: %d\n", app.pin_try_counter);
parsed = true;
} while(false);

View File

@@ -51,8 +51,11 @@ bool nfc_scene_delete_on_event(void* context, SceneManagerEvent event) {
if(nfc_delete(nfc)) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneDeleteSuccess);
} else {
scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneStart);
if(!scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneStart)) {
scene_manager_stop(nfc->scene_manager);
view_dispatcher_stop(nfc->view_dispatcher);
}
}
consumed = true;
}

View File

@@ -31,6 +31,11 @@ bool nfc_scene_delete_success_on_event(void* context, SceneManagerEvent event) {
} else {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneFileSelect);
if(!consumed) {
scene_manager_stop(nfc->scene_manager);
view_dispatcher_stop(nfc->view_dispatcher);
}
}
}
}

View File

@@ -1,13 +1,47 @@
#include "../helpers/protocol_support/nfc_protocol_support.h"
#include "nfc_app_i.h"
#define NFC_EMULATION_TIME_MAX_MS (5 * 60 * 1000)
FuriTimer* timer_auto_exit;
void nfc_scene_emulate_timer_callback(void* context) {
NfcApp* instance = context;
view_dispatcher_send_custom_event(
instance->view_dispatcher, NfcCustomEventEmulationTimeExpired);
}
void nfc_scene_emulate_on_enter(void* context) {
NfcApp* instance = context;
nfc_protocol_support_on_enter(NfcProtocolSupportSceneEmulate, context);
timer_auto_exit =
furi_timer_alloc(nfc_scene_emulate_timer_callback, FuriTimerTypeOnce, instance);
furi_timer_start(timer_auto_exit, NFC_EMULATION_TIME_MAX_MS);
}
bool nfc_scene_emulate_on_event(void* context, SceneManagerEvent event) {
NfcApp* instance = context;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == NfcCustomEventEmulationTimeExpired) {
if(!scene_manager_previous_scene(instance->scene_manager)) {
scene_manager_stop(instance->scene_manager);
view_dispatcher_stop(instance->view_dispatcher);
} else {
scene_manager_previous_scene(instance->scene_manager);
}
return true;
}
}
return nfc_protocol_support_on_event(NfcProtocolSupportSceneEmulate, context, event);
}
void nfc_scene_emulate_on_exit(void* context) {
furi_timer_stop(timer_auto_exit);
furi_timer_free(timer_auto_exit);
nfc_protocol_support_on_exit(NfcProtocolSupportSceneEmulate, context);
}

View File

@@ -32,8 +32,12 @@ bool nfc_scene_save_success_on_event(void* context, SceneManagerEvent event) {
scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicDetectReader);
consumed = true;
} else {
consumed = scene_manager_search_and_switch_to_another_scene(
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneFileSelect);
if(!consumed) {
consumed = scene_manager_search_and_switch_to_previous_scene(
nfc->scene_manager, NfcSceneSavedMenu);
}
}
}
}