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

@@ -65,6 +65,7 @@ enum LfRfidCustomEvent {
LfRfidEventWriteTooLongToWrite,
LfRfidEventRpcLoadFile,
LfRfidEventRpcSessionClose,
LfRfidEventEmulationTimeExpired,
};
typedef enum {

View File

@@ -1,5 +1,14 @@
#include "../lfrfid_i.h"
#define LFRFID_EMULATION_TIME_MAX_MS (5 * 60 * 1000)
FuriTimer* timer_auto_exit;
void lfrfid_scene_emulate_popup_callback(void* context) {
LfRfid* app = context;
view_dispatcher_send_custom_event(app->view_dispatcher, LfRfidEventEmulationTimeExpired);
}
void lfrfid_scene_emulate_on_enter(void* context) {
LfRfid* app = context;
Popup* popup = app->popup;
@@ -22,18 +31,38 @@ void lfrfid_scene_emulate_on_enter(void* context) {
lfrfid_worker_emulate_start(app->lfworker, (LFRFIDProtocol)app->protocol_id);
notification_message(app->notifications, &sequence_blink_start_magenta);
timer_auto_exit =
furi_timer_alloc(lfrfid_scene_emulate_popup_callback, FuriTimerTypeOnce, app);
furi_timer_start(timer_auto_exit, LFRFID_EMULATION_TIME_MAX_MS);
view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup);
}
bool lfrfid_scene_emulate_on_event(void* context, SceneManagerEvent event) {
UNUSED(context);
UNUSED(event);
LfRfid* app = context;
bool consumed = false;
if(event.type == SceneManagerEventTypeCustom) {
if(event.event == LfRfidEventEmulationTimeExpired) {
if(!scene_manager_previous_scene(app->scene_manager)) {
scene_manager_stop(app->scene_manager);
view_dispatcher_stop(app->view_dispatcher);
} else {
scene_manager_previous_scene(app->scene_manager);
}
consumed = true;
}
}
return consumed;
}
void lfrfid_scene_emulate_on_exit(void* context) {
LfRfid* app = context;
furi_timer_stop(timer_auto_exit);
furi_timer_free(timer_auto_exit);
notification_message(app->notifications, &sequence_blink_stop);
popup_reset(app->popup);
lfrfid_worker_stop(app->lfworker);

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);
}
}
}
}

View File

@@ -55,6 +55,7 @@ bool subghz_scene_need_saving_on_event(void* context, SceneManagerEvent event) {
subghz_delete_file(subghz);
}
}
subghz_txrx_set_preset(
subghz->txrx, "AM650", subghz->last_settings->frequency, 0, 0, NULL, 0);
scene_manager_search_and_switch_to_previous_scene(

View File

@@ -3,4 +3,4 @@
#include "expansion_settings.h"
#include "expansion.h"
ExpansionSettings* expansion_get_settings(Expansion* instance);
ExpansionSettings* expansion_get_settings(Expansion* instance);

View File

@@ -255,7 +255,7 @@ static bool subghz_protocol_keeloq_gen_data(
// Centurion -> no serial in hop, uses fixed value 0x1CE - normal learning
} else if(strcmp(instance->manufacture_name, "Dea_Mio") == 0) {
uint8_t first_disc_num = (instance->generic.serial >> 8) & 0xF;
uint8_t result_disc = (0xC + ((first_disc_num % 4) ? 2 : 0));
uint8_t result_disc = (0xC + (first_disc_num % 4));
uint32_t dea_serial = (instance->generic.serial & 0xFF) |
(((uint32_t)result_disc) << 8);
decrypt = btn << 28 | (dea_serial & 0xFFF) << 16 | instance->generic.cnt;