Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFID: Extra Action - Wipe T5577 #765

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions applications/main/lfrfid/scenes/lfrfid_scene_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
27 changes: 27 additions & 0 deletions applications/main/lfrfid/scenes/lfrfid_scene_extra_actions.c
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
#include "../lfrfid_i.h"
#include <dolphin/dolphin.h>

#define SCREEN_WIDTH_CENTER 64
#define SCREEN_HEIGHT_CENTER 32

typedef enum {
SubmenuIndexASK,
SubmenuIndexPSK,
SubmenuIndexClearT5577,
SubmenuIndexWipeT5577,
SubmenuIndexRAW,
SubmenuIndexRAWEmulate,
} SubmenuIndex;
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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;
Expand Down
84 changes: 84 additions & 0 deletions applications/main/lfrfid/scenes/lfrfid_scene_wipe_t5577.c
Original file line number Diff line number Diff line change
@@ -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);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "../lfrfid_i.h"
#include <dialogs/dialogs.h>

#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);
}
13 changes: 13 additions & 0 deletions lib/lfrfid/tools/t5577.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
6 changes: 6 additions & 0 deletions lib/lfrfid/tools/t5577.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -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,,
Expand Down Expand Up @@ -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
Expand Down