From ce2c2c0ffa365908422e3f53a9e0d3f9f40be8d9 Mon Sep 17 00:00:00 2001 From: wooferguy Date: Mon, 17 Jun 2024 02:17:33 +1200 Subject: [PATCH] RFID: Extra Action - Wipe T5577 This is a port from RougeMaster FW, and uses some of their methods. Sets T5577 Block 0 to default, all other blocks to 0. Requires passwords cleared before-hand. --- .../main/lfrfid/scenes/lfrfid_scene_config.h | 2 + .../scenes/lfrfid_scene_extra_actions.c | 27 ++++++ .../lfrfid/scenes/lfrfid_scene_wipe_t5577.c | 84 +++++++++++++++++++ .../scenes/lfrfid_scene_wipe_t5577_confirm.c | 66 +++++++++++++++ lib/lfrfid/tools/t5577.c | 13 +++ lib/lfrfid/tools/t5577.h | 6 ++ targets/f7/api_symbols.csv | 3 +- 7 files changed, 200 insertions(+), 1 deletion(-) create mode 100644 applications/main/lfrfid/scenes/lfrfid_scene_wipe_t5577.c create mode 100644 applications/main/lfrfid/scenes/lfrfid_scene_wipe_t5577_confirm.c diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_config.h b/applications/main/lfrfid/scenes/lfrfid_scene_config.h index 47844a8b38..07ad71b838 100644 --- a/applications/main/lfrfid/scenes/lfrfid_scene_config.h +++ b/applications/main/lfrfid/scenes/lfrfid_scene_config.h @@ -18,6 +18,8 @@ ADD_SCENE(lfrfid, save_type, SaveType) ADD_SCENE(lfrfid, saved_info, SavedInfo) ADD_SCENE(lfrfid, clear_t5577, ClearT5577) ADD_SCENE(lfrfid, clear_t5577_confirm, ClearT5577Confirm) +ADD_SCENE(lfrfid, wipe_t5577, WipeT5577) +ADD_SCENE(lfrfid, wipe_t5577_confirm, WipeT5577Confirm) ADD_SCENE(lfrfid, enter_password, EnterPassword) ADD_SCENE(lfrfid, delete_success, DeleteSuccess) ADD_SCENE(lfrfid, extra_actions, ExtraActions) diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_extra_actions.c b/applications/main/lfrfid/scenes/lfrfid_scene_extra_actions.c index 46472ec2a6..8b1e5d9447 100644 --- a/applications/main/lfrfid/scenes/lfrfid_scene_extra_actions.c +++ b/applications/main/lfrfid/scenes/lfrfid_scene_extra_actions.c @@ -1,10 +1,14 @@ #include "../lfrfid_i.h" #include +#define SCREEN_WIDTH_CENTER 64 +#define SCREEN_HEIGHT_CENTER 32 + typedef enum { SubmenuIndexASK, SubmenuIndexPSK, SubmenuIndexClearT5577, + SubmenuIndexWipeT5577, SubmenuIndexRAW, SubmenuIndexRAWEmulate, } SubmenuIndex; @@ -37,6 +41,12 @@ void lfrfid_scene_extra_actions_on_enter(void* context) { SubmenuIndexClearT5577, lfrfid_scene_extra_actions_submenu_callback, app); + submenu_add_item( + submenu, + "Wipe T5577", + SubmenuIndexWipeT5577, + lfrfid_scene_extra_actions_submenu_callback, + app); if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { submenu_add_item( @@ -84,6 +94,23 @@ bool lfrfid_scene_extra_actions_on_event(void* context, SceneManagerEvent event) app->scene_manager, LfRfidSceneEnterPassword, LfRfidSceneClearT5577Confirm); scene_manager_next_scene(app->scene_manager, LfRfidSceneEnterPassword); consumed = true; + } else if(event.event == SubmenuIndexWipeT5577) { + DialogMessage* message = dialog_message_alloc(); + dialog_message_set_header(message, "T5577 reset", 0, 0, AlignLeft, AlignTop); + dialog_message_set_buttons(message, "No", NULL, "Yes"); + dialog_message_set_text( + message, + " This overwrites T5577 user data blocks. Password must be cleared before", + SCREEN_WIDTH_CENTER, + SCREEN_HEIGHT_CENTER, + AlignCenter, + AlignCenter); + DialogMessageButton dialog_result = dialog_message_show(app->dialogs, message); + dialog_message_free(message); + if(dialog_result == DialogMessageButtonRight) { + scene_manager_next_scene(app->scene_manager, LfRfidSceneWipeT5577Confirm); + } + consumed = true; } else if(event.event == SubmenuIndexRAW) { scene_manager_next_scene(app->scene_manager, LfRfidSceneRawName); consumed = true; diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_wipe_t5577.c b/applications/main/lfrfid/scenes/lfrfid_scene_wipe_t5577.c new file mode 100644 index 0000000000..ebc7ec9ef3 --- /dev/null +++ b/applications/main/lfrfid/scenes/lfrfid_scene_wipe_t5577.c @@ -0,0 +1,84 @@ +#include "../lfrfid_i.h" + +#define LFRFID_DATA_NULL 0 + +static void lfrfid_wipe_t5577_do(LfRfid* app) { + Popup* popup = app->popup; + char curr_buf[50] = {}; + + uint8_t page = 0; + bool lock_bit = 0; + uint32_t data = 0; + + popup_set_header(popup, "Wiping data", 64, 10, AlignCenter, AlignCenter); + popup_set_text(popup, curr_buf, 66, 33, AlignCenter, AlignCenter); + view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup); + furi_delay_ms(1000); + notification_message(app->notifications, &sequence_blink_start_magenta); + furi_delay_ms(500); + + for(uint8_t block = 0; block < 8; block++) { + if(!block) { // page 0 block 0 is configuration data, default 0x00148040 + data = + (LFRFID_T5577_BITRATE_RF_64 | LFRFID_T5577_MODULATION_MANCHESTER | + (2 << LFRFID_T5577_MAXBLOCK_SHIFT)); + } else + data = LFRFID_DATA_NULL; + + snprintf( + curr_buf, + sizeof(curr_buf), + "Writing: Page %u Block %u\ndata %02lX %02lX %02lX %02lX", + page, + block, + data >> 24, + (data >> 16) & 0xFF, + (data >> 8) & 0xFF, + data & 0xFF); + view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup); + t5577_write_page_block_simple_with_start_and_stop( + page, block, lock_bit, data); + furi_delay_ms(150); + if(!block) furi_delay_ms(2000); + } + notification_message(app->notifications, &sequence_blink_stop); + popup_reset(app->popup); +} + +void lfrfid_scene_wipe_t5577_on_enter(void* context) { + LfRfid* app = context; + Popup* popup = app->popup; + + lfrfid_wipe_t5577_do(app); + + notification_message(app->notifications, &sequence_success); + popup_set_header(popup, "Done!", 102, 10, AlignCenter, AlignTop); + popup_set_icon(popup, 0, 7, &I_DolphinSuccess_91x55); + popup_set_context(popup, app); + popup_set_callback(popup, lfrfid_popup_timeout_callback); + popup_set_timeout(popup, 1500); + popup_enable_timeout(popup); + + view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewPopup); + notification_message_block(app->notifications, &sequence_set_green_255); +} + +bool lfrfid_scene_wipe_t5577_on_event(void* context, SceneManagerEvent event) { + LfRfid* app = context; + bool consumed = false; + + if(event.type == SceneManagerEventTypeBack) { + consumed = true; // Ignore Back button presses + } else if(event.type == SceneManagerEventTypeCustom && event.event == LfRfidEventPopupClosed) { + scene_manager_search_and_switch_to_previous_scene( + app->scene_manager, LfRfidSceneExtraActions); + consumed = true; + } + return consumed; +} + +void lfrfid_scene_wipe_t5577_on_exit(void* context) { + LfRfid* app = context; + popup_reset(app->popup); + notification_message_block(app->notifications, &sequence_reset_green); +} \ No newline at end of file diff --git a/applications/main/lfrfid/scenes/lfrfid_scene_wipe_t5577_confirm.c b/applications/main/lfrfid/scenes/lfrfid_scene_wipe_t5577_confirm.c new file mode 100644 index 0000000000..5ab4a1b247 --- /dev/null +++ b/applications/main/lfrfid/scenes/lfrfid_scene_wipe_t5577_confirm.c @@ -0,0 +1,66 @@ +#include "../lfrfid_i.h" +#include + +#define LFRFID_PAGE0_MAX_SIZE 8 +#define LFRFID_PAGE1_MAX_SIZE 4 +#define SCREEN_WIDTH_CENTER 64 +#define SCREEN_HEIGHT_CENTER 32 + +void lfrfid_scene_wipe_t5577_confirm_on_enter(void* context) { + LfRfid* app = context; + + DialogMessage* message = dialog_message_alloc(); + dialog_message_set_header( + message, "This will delete all T5577 user blocks data.", 0, 0, AlignLeft, AlignTop); + dialog_message_set_buttons(message, NULL, NULL, "Yes"); + dialog_message_set_text( + message, + "Are you sure?", + SCREEN_WIDTH_CENTER, + SCREEN_HEIGHT_CENTER, + AlignCenter, + AlignCenter); + dialog_message_show(app->dialogs, message); + dialog_message_free(message); + + Widget* widget = app->widget; + + widget_add_button_element(widget, GuiButtonTypeLeft, "Exit", lfrfid_widget_callback, app); + widget_add_button_element(widget, GuiButtonTypeRight, "Start", lfrfid_widget_callback, app); + widget_add_string_multiline_element( + widget, 64, 22, AlignCenter, AlignBottom, FontPrimary, "Apply tag to\nFlipper's back"); + widget_add_string_multiline_element( + widget, + 64, + 45, + AlignCenter, + AlignBottom, + FontSecondary, + "And don't move it\nwhile process is running"); + + view_dispatcher_switch_to_view(app->view_dispatcher, LfRfidViewWidget); +} + +bool lfrfid_scene_wipe_t5577_confirm_on_event(void* context, SceneManagerEvent event) { + LfRfid* app = context; + SceneManager* scene_manager = app->scene_manager; + bool consumed = false; + + if(event.type == SceneManagerEventTypeBack) { + consumed = true; // Ignore Back button presses + } else if(event.type == SceneManagerEventTypeCustom) { + consumed = true; + if(event.event == GuiButtonTypeLeft) { + scene_manager_search_and_switch_to_previous_scene( + scene_manager, LfRfidSceneExtraActions); + } else if(event.event == GuiButtonTypeRight) + scene_manager_next_scene(scene_manager, LfRfidSceneWipeT5577); + } + + return consumed; +} + +void lfrfid_scene_wipe_t5577_confirm_on_exit(void* context) { + LfRfid* app = context; + widget_reset(app->widget); +} \ No newline at end of file diff --git a/lib/lfrfid/tools/t5577.c b/lib/lfrfid/tools/t5577.c index 483762ff61..3d696695da 100644 --- a/lib/lfrfid/tools/t5577.c +++ b/lib/lfrfid/tools/t5577.c @@ -140,3 +140,16 @@ void t5577_write_with_mask(LFRFIDT5577* data, uint8_t page, bool with_pass, uint FURI_CRITICAL_EXIT(); t5577_stop(); } + +void t5577_write_page_block_simple_with_start_and_stop( + uint8_t page, + uint8_t block, + bool lock_bit, + uint32_t data) { + t5577_start(); + FURI_CRITICAL_ENTER(); + t5577_write_block_pass(page, block, lock_bit, data, false, 0); + t5577_write_reset(); + FURI_CRITICAL_EXIT(); + t5577_stop(); +} \ No newline at end of file diff --git a/lib/lfrfid/tools/t5577.h b/lib/lfrfid/tools/t5577.h index f7b5cc4f5a..8e89a1fca6 100644 --- a/lib/lfrfid/tools/t5577.h +++ b/lib/lfrfid/tools/t5577.h @@ -56,6 +56,12 @@ void t5577_write_with_pass(LFRFIDT5577* data, uint32_t password); void t5577_write_with_mask(LFRFIDT5577* data, uint8_t page, bool with_pass, uint32_t password); +void t5577_write_page_block_simple_with_start_and_stop( + uint8_t page, + uint8_t block, + bool lock_bit, + uint32_t data /*, bool testmode*/); + #ifdef __cplusplus } #endif \ No newline at end of file diff --git a/targets/f7/api_symbols.csv b/targets/f7/api_symbols.csv index 24839f8190..3e4261c556 100644 --- a/targets/f7/api_symbols.csv +++ b/targets/f7/api_symbols.csv @@ -1,5 +1,5 @@ entry,status,name,type,params -Version,+,65.0,, +Version,v,65.1,, Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,, Header,+,applications/services/bt/bt_service/bt.h,, Header,+,applications/services/bt/bt_service/bt_keys_storage.h,, @@ -3497,6 +3497,7 @@ Function,+,submenu_set_orientation,void,"Submenu*, ViewOrientation" Function,+,submenu_set_selected_item,void,"Submenu*, uint32_t" Function,-,system,int,const char* Function,+,t5577_write,void,LFRFIDT5577* +Function,+,t5577_write_page_block_simple_with_start_and_stop,void,"uint8_t, uint8_t, _Bool, uint32_t" Function,+,t5577_write_with_mask,void,"LFRFIDT5577*, uint8_t, _Bool, uint32_t" Function,+,t5577_write_with_pass,void,"LFRFIDT5577*, uint32_t" Function,-,tan,double,double