From f291c9546d133ada7b570d44d1a1cc8aa34eeca1 Mon Sep 17 00:00:00 2001 From: ESurge Date: Thu, 20 Oct 2022 23:29:07 -0700 Subject: [PATCH 1/8] Cleaned up error checking in unirfremix_cfg_set_check Fixed a bug where all options are disabled and set to N/A but it doesn't show Config is invalid screen. --- applications/main/unirfremix/unirfremix_app.c | 261 ++++++++---------- 1 file changed, 109 insertions(+), 152 deletions(-) diff --git a/applications/main/unirfremix/unirfremix_app.c b/applications/main/unirfremix/unirfremix_app.c index 659ee9ac1..f2f292583 100644 --- a/applications/main/unirfremix/unirfremix_app.c +++ b/applications/main/unirfremix/unirfremix_app.c @@ -89,7 +89,6 @@ typedef struct { int file_result; bool tx_not_allowed; - int file_blank; FuriString* signal; } UniRFRemix; @@ -168,14 +167,13 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) { Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); - app->file_result = 3; - app->file_blank = 0; + app->file_result = 1; - app->up_enabled = 1; - app->down_enabled = 1; - app->left_enabled = 1; - app->right_enabled = 1; - app->ok_enabled = 1; + app->up_enabled = 0; + app->down_enabled = 0; + app->left_enabled = 0; + app->right_enabled = 0; + app->ok_enabled = 0; int label_len = 16; @@ -189,61 +187,55 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) { //set missing filenames to N/A if(!flipper_format_read_string(fff_data_file, "UP", app->up_file)) { FURI_LOG_W(TAG, "Could not read UP string"); - //increment file_blank for processing later - app->file_blank++; //set label to "N/A" app->up_label = "N/A"; - //disable the ability to process the signal on button press - app->up_enabled = 0; } else { //check name length for proper screen fit //then set filename as label. Might be replaced with defined label later on below. app->up_label = extract_filename(furi_string_get_cstr(app->up_file), label_len); FURI_LOG_I(TAG, "UP file: %s", furi_string_get_cstr(app->up_file)); + //enable processing of the signal on button press + app->up_enabled = 1; } //Repeat process for Down if(!flipper_format_read_string(fff_data_file, "DOWN", app->down_file)) { FURI_LOG_W(TAG, "Could not read DOWN string"); - app->file_blank++; app->down_label = "N/A"; - app->down_enabled = 0; } else { app->down_label = extract_filename(furi_string_get_cstr(app->down_file), label_len); FURI_LOG_I(TAG, "DOWN file: %s", furi_string_get_cstr(app->down_file)); + app->down_enabled = 1; } //Repeat process for Left if(!flipper_format_read_string(fff_data_file, "LEFT", app->left_file)) { FURI_LOG_W(TAG, "Could not read LEFT string"); - app->file_blank++; app->left_label = "N/A"; - app->left_enabled = 0; } else { app->left_label = extract_filename(furi_string_get_cstr(app->left_file), label_len); FURI_LOG_I(TAG, "LEFT file: %s", furi_string_get_cstr(app->left_file)); + app->left_enabled = 1; } //Repeat process for Right if(!flipper_format_read_string(fff_data_file, "RIGHT", app->right_file)) { FURI_LOG_W(TAG, "Could not read RIGHT string"); - app->file_blank++; app->right_label = "N/A"; - app->right_enabled = 0; } else { app->right_label = extract_filename(furi_string_get_cstr(app->right_file), label_len); FURI_LOG_I(TAG, "RIGHT file: %s", furi_string_get_cstr(app->right_file)); + app->right_enabled = 1; } //Repeat process for Ok if(!flipper_format_read_string(fff_data_file, "OK", app->ok_file)) { FURI_LOG_W(TAG, "Could not read OK string"); - app->file_blank++; app->ok_label = "N/A"; - app->ok_enabled = 0; } else { app->ok_label = extract_filename(furi_string_get_cstr(app->ok_file), label_len); FURI_LOG_I(TAG, "OK file: %s", furi_string_get_cstr(app->ok_file)); + app->ok_enabled = 1; } //File definitions are done. @@ -254,15 +246,9 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) { //assign variables to values within map file if(!flipper_format_read_string(fff_data_file, "ULABEL", app->up_l)) { FURI_LOG_W(TAG, "Could not read ULABEL string"); - //if Up button is disabled, set the label to "N/A"; - if(app->up_enabled == 0) { - app->up_label = "N/A"; - } } else { - //check if button is disabled, and set label to "N/A" from missing map definition above - if(app->up_enabled == 0) { - app->up_label = "N/A"; - } else { + //check if button is enabled, and set label + if(app->up_enabled == 1) { //set label from map to variable and shrink to fit screen app->up_label = char_to_str((char*)furi_string_get_cstr(app->up_l), label_len); } @@ -271,13 +257,8 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) { if(!flipper_format_read_string(fff_data_file, "DLABEL", app->down_l)) { FURI_LOG_W(TAG, "Could not read DLABEL string"); - if(app->down_enabled == 0) { - app->down_label = "N/A"; - } } else { - if(app->down_enabled == 0) { - app->down_label = "N/A"; - } else { + if(app->down_enabled == 1) { app->down_label = char_to_str((char*)furi_string_get_cstr(app->down_l), label_len); } FURI_LOG_I(TAG, "DOWN label: %s", app->down_label); @@ -285,13 +266,8 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) { if(!flipper_format_read_string(fff_data_file, "LLABEL", app->left_l)) { FURI_LOG_W(TAG, "Could not read LLABEL string"); - if(app->left_enabled == 0) { - app->left_label = "N/A"; - } } else { - if(app->left_enabled == 0) { - app->left_label = "N/A"; - } else { + if(app->left_enabled == 1) { app->left_label = char_to_str((char*)furi_string_get_cstr(app->left_l), label_len); } FURI_LOG_I(TAG, "LEFT label: %s", app->left_label); @@ -299,13 +275,8 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) { if(!flipper_format_read_string(fff_data_file, "RLABEL", app->right_l)) { FURI_LOG_W(TAG, "Could not read RLABEL string"); - if(app->right_enabled == 0) { - app->right_label = "N/A"; - } } else { - if(app->right_enabled == 0) { - app->right_label = "N/A"; - } else { + if(app->right_enabled == 1) { app->right_label = char_to_str((char*)furi_string_get_cstr(app->right_l), label_len); } @@ -314,19 +285,12 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) { if(!flipper_format_read_string(fff_data_file, "OKLABEL", app->ok_l)) { FURI_LOG_W(TAG, "Could not read OKLABEL string"); - if(app->ok_enabled == 0) { - app->ok_label = "N/A"; - } } else { - if(app->ok_enabled == 0) { - app->ok_label = "N/A"; - } else { + if(app->ok_enabled == 1) { app->ok_label = char_to_str((char*)furi_string_get_cstr(app->ok_l), label_len); } FURI_LOG_I(TAG, "OK label: %s", app->ok_label); } - - app->file_result = 2; } flipper_format_file_close(fff_data_file); @@ -339,106 +303,91 @@ void unirfremix_cfg_set_check(UniRFRemix* app, FuriString* file_name) { //determine whether or not to continue to launch app with missing variables //if 5 files are missing, throw error - FURI_LOG_D(TAG, "app->file_blank: %d", app->file_blank); + //if button is still enabled, check that file exists + if(app->up_enabled == 1) { + furi_string_set(file_name, app->up_file); + fff_data_file = flipper_format_file_alloc(storage); - if(app->file_blank == 5) { - //trigger invalid file error screen + if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) { + FURI_LOG_W(TAG, "Could not open UP file %s", furi_string_get_cstr(file_name)); + + //disable button, and set label to "N/A" + app->up_enabled = 0; + app->up_label = "N/A"; + } + + //close the file + flipper_format_file_close(fff_data_file); + flipper_format_free(fff_data_file); + } + + if(app->down_enabled == 1) { + furi_string_set(file_name, app->down_file); + fff_data_file = flipper_format_file_alloc(storage); + + if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) { + FURI_LOG_W(TAG, "Could not open DOWN file %s", furi_string_get_cstr(file_name)); + + app->down_enabled = 0; + app->down_label = "N/A"; + } + + flipper_format_file_close(fff_data_file); + flipper_format_free(fff_data_file); + } + + if(app->left_enabled == 1) { + furi_string_set(file_name, app->left_file); + fff_data_file = flipper_format_file_alloc(storage); + + if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) { + FURI_LOG_W(TAG, "Could not open LEFT file %s", furi_string_get_cstr(file_name)); + + app->left_enabled = 0; + app->left_label = "N/A"; + } + + flipper_format_file_close(fff_data_file); + flipper_format_free(fff_data_file); + } + + if(app->right_enabled == 1) { + furi_string_set(file_name, app->right_file); + fff_data_file = flipper_format_file_alloc(storage); + + if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) { + FURI_LOG_W(TAG, "Could not open RIGHT file %s", furi_string_get_cstr(file_name)); + + app->right_enabled = 0; + app->right_label = "N/A"; + } + + flipper_format_file_close(fff_data_file); + flipper_format_free(fff_data_file); + } + + if(app->ok_enabled == 1) { + furi_string_set(file_name, app->ok_file); + fff_data_file = flipper_format_file_alloc(storage); + + if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) { + FURI_LOG_W(TAG, "Could not open OK file %s", furi_string_get_cstr(file_name)); + + app->ok_enabled = 0; + app->ok_label = "N/A"; + } + + flipper_format_file_close(fff_data_file); + flipper_format_free(fff_data_file); + } + + furi_record_close(RECORD_STORAGE); + + if(app->up_enabled == 0 && app->down_enabled == 0 && app->left_enabled == 0 && + app->right_enabled == 0 && app->ok_enabled == 0) { app->file_result = 1; } else { - //check all files - //reset app->file_blank to redetermine if error needs to be thrown - app->file_blank = 0; - - //if button is still enabled, check that file exists - if(app->up_enabled == 1) { - furi_string_set(file_name, app->up_file); - fff_data_file = flipper_format_file_alloc(storage); - - if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) { - FURI_LOG_W(TAG, "Could not open UP file %s", furi_string_get_cstr(file_name)); - - //disable button, and set label to "N/A" - app->up_enabled = 0; - app->up_label = "N/A"; - app->file_blank++; - } - - //close the file - flipper_format_file_close(fff_data_file); - flipper_format_free(fff_data_file); - } - - if(app->down_enabled == 1) { - furi_string_set(file_name, app->down_file); - fff_data_file = flipper_format_file_alloc(storage); - - if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) { - FURI_LOG_W(TAG, "Could not open DOWN file %s", furi_string_get_cstr(file_name)); - - app->down_enabled = 0; - app->down_label = "N/A"; - app->file_blank++; - } - - flipper_format_file_close(fff_data_file); - flipper_format_free(fff_data_file); - } - - if(app->left_enabled == 1) { - furi_string_set(file_name, app->left_file); - fff_data_file = flipper_format_file_alloc(storage); - - if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) { - FURI_LOG_W(TAG, "Could not open LEFT file %s", furi_string_get_cstr(file_name)); - - app->left_enabled = 0; - app->left_label = "N/A"; - app->file_blank++; - } - - flipper_format_file_close(fff_data_file); - flipper_format_free(fff_data_file); - } - - if(app->right_enabled == 1) { - furi_string_set(file_name, app->right_file); - fff_data_file = flipper_format_file_alloc(storage); - - if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) { - FURI_LOG_W(TAG, "Could not open RIGHT file %s", furi_string_get_cstr(file_name)); - - app->right_enabled = 0; - app->right_label = "N/A"; - app->file_blank++; - } - - flipper_format_file_close(fff_data_file); - flipper_format_free(fff_data_file); - } - - if(app->ok_enabled == 1) { - furi_string_set(file_name, app->ok_file); - fff_data_file = flipper_format_file_alloc(storage); - - if(!flipper_format_file_open_existing(fff_data_file, furi_string_get_cstr(file_name))) { - FURI_LOG_W(TAG, "Could not open OK file %s", furi_string_get_cstr(file_name)); - - app->ok_enabled = 0; - app->ok_label = "N/A"; - app->file_blank++; - } - - flipper_format_file_close(fff_data_file); - flipper_format_free(fff_data_file); - } - - furi_record_close(RECORD_STORAGE); - - if(app->file_blank == 5) { - app->file_result = 1; - } else { - app->file_result = 2; - } + app->file_result = 2; } } @@ -742,6 +691,14 @@ static void render_callback(Canvas* canvas, void* ctx) { canvas_set_font(canvas, FontSecondary); canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignTop, "Please configure map."); canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Press Back to Exit."); + } else if(app->file_result == 3) { + //if map has no valid filenames defined + canvas_clear(canvas); + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned(canvas, 62, 5, AlignCenter, AlignTop, "Checking config."); + canvas_set_font(canvas, FontSecondary); + canvas_draw_str_aligned(canvas, 62, 30, AlignCenter, AlignTop, "If app is stuck..."); + canvas_draw_str_aligned(canvas, 62, 60, AlignCenter, AlignBottom, "Press Back to Exit."); } else if(app->tx_not_allowed) { canvas_clear(canvas); canvas_set_font(canvas, FontPrimary); @@ -1129,7 +1086,7 @@ int32_t unirfremix_app(void* p) { furi_mutex_release(app->model_mutex); view_port_update(app->view_port); } - } else if(app->file_result == 1) { + } else if(app->file_result == 1 || app->file_result == 3) { //refresh screen to update variables before processing main screen or error screens view_port_update(app->view_port); From a0a8e0457a2c1647b3d9d8fad043a7d898ea4aa2 Mon Sep 17 00:00:00 2001 From: TQMatvey Date: Fri, 21 Oct 2022 13:58:26 +0700 Subject: [PATCH 2/8] Snake: Allow snake to turn anywhere --- applications/plugins/snake_game/snake_game.c | 33 +++----------------- 1 file changed, 4 insertions(+), 29 deletions(-) diff --git a/applications/plugins/snake_game/snake_game.c b/applications/plugins/snake_game/snake_game.c index 943b802f0..1d7530849 100644 --- a/applications/plugins/snake_game/snake_game.c +++ b/applications/plugins/snake_game/snake_game.c @@ -41,7 +41,7 @@ typedef enum { DirectionLeft, } Direction; -#define MAX_SNAKE_LEN 253 +#define MAX_SNAKE_LEN 128*64/4 typedef struct { Point points[MAX_SNAKE_LEN]; @@ -268,10 +268,8 @@ static void return; } - bool can_turn = (snake_state->points[0].x % 2 == 0) && (snake_state->points[0].y % 2 == 0); - if(can_turn) { - snake_state->currentMovement = snake_game_get_turn_snake(snake_state); - } + + snake_state->currentMovement = snake_game_get_turn_snake(snake_state); Point next_step = snake_game_get_next_step(snake_state); @@ -408,27 +406,4 @@ int32_t snake_game_app(void* p) { free(snake_state); return 0; -} - -// Screen is 128x64 px -// (4 + 4) * 16 - 4 + 2 + 2border == 128 -// (4 + 4) * 8 - 4 + 2 + 2border == 64 -// Game field from point{x: 0, y: 0} to point{x: 30, y: 14}. -// The snake turns only in even cells - intersections. -// ┌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┐ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// ╎ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ▪ ╎ -// └╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌╌┘ +} \ No newline at end of file From 235af1aacbd217efaa8a5650fbf129ccaa7067e2 Mon Sep 17 00:00:00 2001 From: SG Date: Sat, 22 Oct 2022 03:41:09 +1000 Subject: [PATCH 3/8] Dap-link: fix C symbol --- applications/plugins/dap_link/gui/scenes/dap_scene_help.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/applications/plugins/dap_link/gui/scenes/dap_scene_help.c b/applications/plugins/dap_link/gui/scenes/dap_scene_help.c index 7193f4f4b..d8d70e7ff 100644 --- a/applications/plugins/dap_link/gui/scenes/dap_scene_help.c +++ b/applications/plugins/dap_link/gui/scenes/dap_scene_help.c @@ -72,13 +72,13 @@ void dap_scene_help_on_enter(void* context) { if(config->uart_swap == DapUartTXRXNormal) { furi_string_cat( string, - " TX: 15 [С1]\r\n" - " RX: 16 [С0]\r\n"); + " TX: 15 [C1]\r\n" + " RX: 16 [C0]\r\n"); } else { furi_string_cat( string, - " RX: 15 [С1]\r\n" - " TX: 16 [С0]\r\n"); + " RX: 15 [C1]\r\n" + " TX: 16 [C0]\r\n"); } break; default: From 12dda6b76bb2fe04908c62eab39587235f3084cb Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Fri, 21 Oct 2022 21:52:06 +0300 Subject: [PATCH 4/8] update changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index bcc7b6ca8..1c023ba2a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ### New changes -* Plugins: Added Temperature Sensor Plugin - HTU21D / SI7021 [(By Mywk)](https://github.com/Mywk/FlipperTemperatureSensor) - [How to Connect](https://github.com/DarkFlippers/unleashed-firmware/blob/dev/applications/plugins/temperature_sensor/Readme.md) +* PR: SubGHz Remote (UniRFRemix) - Cleaned up error checking + Bug fix (by @ESurge | PR #124) +* Plugins -> PR: Snake: Allow snake to turn anywhere (by @TQMatvey | PR #125) +* OFW PR: Dap-link: fix C symbol (OFW PR 1905 by DrZlo13) **Note: Version naming changed to be more clear what version is newer, now we using -> unlshd-123 where 123 is build number** From 12bbe3e68ee59e0b8bebde52c8fde5f84eee7016 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Fri, 21 Oct 2022 21:58:59 +0300 Subject: [PATCH 5/8] return saving of emv --- .../main/nfc/scenes/nfc_scene_emv_menu.c | 10 +++++- lib/nfc/nfc_device.c | 34 +++++++++++++++++-- 2 files changed, 41 insertions(+), 3 deletions(-) diff --git a/applications/main/nfc/scenes/nfc_scene_emv_menu.c b/applications/main/nfc/scenes/nfc_scene_emv_menu.c index eb1e10043..1da630fcf 100644 --- a/applications/main/nfc/scenes/nfc_scene_emv_menu.c +++ b/applications/main/nfc/scenes/nfc_scene_emv_menu.c @@ -1,6 +1,7 @@ #include "../nfc_i.h" enum SubmenuIndex { + SubmenuIndexSave, SubmenuIndexInfo, }; @@ -14,6 +15,7 @@ void nfc_scene_emv_menu_on_enter(void* context) { Nfc* nfc = context; Submenu* submenu = nfc->submenu; + submenu_add_item(submenu, "Save", SubmenuIndexSave, nfc_scene_emv_menu_submenu_callback, nfc); submenu_add_item(submenu, "Info", SubmenuIndexInfo, nfc_scene_emv_menu_submenu_callback, nfc); submenu_set_selected_item( nfc->submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneEmvMenu)); @@ -26,7 +28,13 @@ bool nfc_scene_emv_menu_on_event(void* context, SceneManagerEvent event) { bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SubmenuIndexInfo) { + if(event.event == SubmenuIndexSave) { + nfc->dev->format = NfcDeviceSaveFormatBankCard; + // Clear device name + nfc_device_set_name(nfc->dev, ""); + scene_manager_next_scene(nfc->scene_manager, NfcSceneSaveName); + consumed = true; + } else if(event.event == SubmenuIndexInfo) { scene_manager_next_scene(nfc->scene_manager, NfcSceneNfcDataInfo); consumed = true; } diff --git a/lib/nfc/nfc_device.c b/lib/nfc/nfc_device.c index 740cfae5e..419ef0f20 100644 --- a/lib/nfc/nfc_device.c +++ b/lib/nfc/nfc_device.c @@ -636,7 +636,35 @@ bool nfc_device_load_mifare_df_data(FlipperFormat* file, NfcDevice* dev) { return parsed; } -// Leave for backward compatibility +static bool nfc_device_save_bank_card_data(FlipperFormat* file, NfcDevice* dev) { + bool saved = false; + EmvData* data = &dev->dev_data.emv_data; + uint32_t data_temp = 0; + + do { + // Write Bank card specific data + if(!flipper_format_write_comment_cstr(file, "Bank card specific data")) break; + if(!flipper_format_write_hex(file, "AID", data->aid, data->aid_len)) break; + if(!flipper_format_write_string_cstr(file, "Name", data->name)) break; + if(!flipper_format_write_hex(file, "Number", data->number, data->number_len)) break; + if(data->exp_mon) { + uint8_t exp_data[2] = {data->exp_mon, data->exp_year}; + if(!flipper_format_write_hex(file, "Exp data", exp_data, sizeof(exp_data))) break; + } + if(data->country_code) { + data_temp = data->country_code; + if(!flipper_format_write_uint32(file, "Country code", &data_temp, 1)) break; + } + if(data->currency_code) { + data_temp = data->currency_code; + if(!flipper_format_write_uint32(file, "Currency code", &data_temp, 1)) break; + } + saved = true; + } while(false); + + return saved; +} + bool nfc_device_load_bank_card_data(FlipperFormat* file, NfcDevice* dev) { bool parsed = false; EmvData* data = &dev->dev_data.emv_data; @@ -1040,7 +1068,7 @@ static bool nfc_device_save_file( if(!flipper_format_write_header_cstr(file, nfc_file_header, nfc_file_version)) break; // Write nfc device type if(!flipper_format_write_comment_cstr( - file, "Nfc device type can be UID, Mifare Ultralight, Mifare Classic")) + file, "Nfc device type can be UID, Mifare Ultralight, Mifare Classic, Bank card")) break; nfc_device_prepare_format_string(dev, temp_str); if(!flipper_format_write_string(file, "Device type", temp_str)) break; @@ -1055,6 +1083,8 @@ static bool nfc_device_save_file( if(!nfc_device_save_mifare_ul_data(file, dev)) break; } else if(dev->format == NfcDeviceSaveFormatMifareDesfire) { if(!nfc_device_save_mifare_df_data(file, dev)) break; + } else if(dev->format == NfcDeviceSaveFormatBankCard) { + if(!nfc_device_save_bank_card_data(file, dev)) break; } else if(dev->format == NfcDeviceSaveFormatMifareClassic) { // Save data if(!nfc_device_save_mifare_classic_data(file, dev)) break; From 6189511a87d165331ef0c8377f4d829bddb6151b Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Fri, 21 Oct 2022 22:00:54 +0300 Subject: [PATCH 6/8] allow uid emulation of emv --- applications/main/nfc/scenes/nfc_scene_saved_menu.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/applications/main/nfc/scenes/nfc_scene_saved_menu.c b/applications/main/nfc/scenes/nfc_scene_saved_menu.c index fe65b5b8a..c1043b3a7 100644 --- a/applications/main/nfc/scenes/nfc_scene_saved_menu.c +++ b/applications/main/nfc/scenes/nfc_scene_saved_menu.c @@ -20,7 +20,8 @@ void nfc_scene_saved_menu_on_enter(void* context) { Submenu* submenu = nfc->submenu; if(nfc->dev->format == NfcDeviceSaveFormatUid || - nfc->dev->format == NfcDeviceSaveFormatMifareDesfire) { + nfc->dev->format == NfcDeviceSaveFormatMifareDesfire || + nfc->dev->format == NfcDeviceSaveFormatBankCard) { submenu_add_item( submenu, "Emulate UID", From c19f3a3a6a4f79160c62e3348d166880a2aa728b Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Fri, 21 Oct 2022 22:10:21 +0300 Subject: [PATCH 7/8] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c023ba2a..dfa3c41ec 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,5 @@ ### New changes +* Allow UID emulation of EMV cards, allow saving EMV cards * PR: SubGHz Remote (UniRFRemix) - Cleaned up error checking + Bug fix (by @ESurge | PR #124) * Plugins -> PR: Snake: Allow snake to turn anywhere (by @TQMatvey | PR #125) * OFW PR: Dap-link: fix C symbol (OFW PR 1905 by DrZlo13) From a44739cde97af2e351ad63435e59704db2412dc6 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Fri, 21 Oct 2022 22:15:36 +0300 Subject: [PATCH 8/8] emulate uid from fav --- applications/main/nfc/nfc.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/applications/main/nfc/nfc.c b/applications/main/nfc/nfc.c index 0b685f545..44a0f6368 100644 --- a/applications/main/nfc/nfc.c +++ b/applications/main/nfc/nfc.c @@ -277,8 +277,6 @@ int32_t nfc_app(void* p) { scene_manager_next_scene(nfc->scene_manager, NfcSceneMfUltralightEmulate); } else if(nfc->dev->format == NfcDeviceSaveFormatMifareClassic) { scene_manager_next_scene(nfc->scene_manager, NfcSceneMfClassicEmulate); - } else if(nfc->dev->format == NfcDeviceSaveFormatBankCard) { - scene_manager_next_scene(nfc->scene_manager, NfcSceneDeviceInfo); } else { scene_manager_next_scene(nfc->scene_manager, NfcSceneEmulateUid); }