From 58beca313d229fe2c3345005f6f20250deeac09b Mon Sep 17 00:00:00 2001 From: Z3BRO <101530102+Z3BRO@users.noreply.github.com> Date: Thu, 27 Jul 2023 17:25:32 +0200 Subject: [PATCH 01/44] SubGHz External High Power --- .../scenes/subghz_scene_radio_settings.c | 32 ++++++++++++++++ .../main/subghz/subghz_last_settings.c | 19 +++++++++- .../main/subghz/subghz_last_settings.h | 1 + lib/subghz/devices/devices.c | 38 +++++++++++++++++++ 4 files changed, 89 insertions(+), 1 deletion(-) diff --git a/applications/main/subghz/scenes/subghz_scene_radio_settings.c b/applications/main/subghz/scenes/subghz_scene_radio_settings.c index 6fb6e50895..598d6fdce0 100644 --- a/applications/main/subghz/scenes/subghz_scene_radio_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_radio_settings.c @@ -20,6 +20,12 @@ const char* const timestamp_names_text[TIMESTAMP_NAMES_COUNT] = { "ON", }; +#define EXT_MOD_POWER_AMP_COUNT 2 +const char* const ext_mod_power_amp_text[EXT_MOD_POWER_AMP_COUNT] = { + "OFF", + "ON", +}; + #define DEBUG_P_COUNT 2 const char* const debug_pin_text[DEBUG_P_COUNT] = { "OFF", @@ -105,6 +111,22 @@ static void subghz_scene_receiver_config_set_debug_counter(VariableItem* item) { // subghz_last_settings_save(subghz->last_settings); // } +static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem* item) { + SubGhz* subghz = variable_item_get_context(item); + uint8_t index = variable_item_get_current_value_index(item); + + variable_item_set_current_value_text(item, ext_mod_power_amp_text[index]); + + if(index == 1) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); + } else { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); + } + + subghz->last_settings->external_module_power_amp = index == 1; + subghz_last_settings_save(subghz->last_settings); +} + static void subghz_scene_receiver_config_set_timestamp_file_names(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); @@ -137,6 +159,16 @@ void subghz_scene_radio_settings_on_enter(void* context) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, radio_device_text[value_index]); + item = variable_item_list_add( + variable_item_list, + "Ext High Power", + EXT_MOD_POWER_AMP_COUNT, + subghz_scene_reciever_config_set_ext_mod_power_amp_text, + subghz); + value_index = subghz->last_settings->external_module_power_amp ? 1 : 0; + variable_item_set_current_value_index(item, value_index); + variable_item_set_current_value_text(item, ext_mod_power_amp_text[value_index]); + item = variable_item_list_add( variable_item_list, "Time in names", diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index b61ed37693..5f67fc7802 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -19,6 +19,7 @@ #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER "FATrigger" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED "External" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER "ExtPower" +#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp" #define SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES "TimestampNames" SubGhzLastSettings* subghz_last_settings_alloc(void) { @@ -46,6 +47,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count float temp_frequency_analyzer_trigger = 0; bool temp_external_module_enabled = false; bool temp_external_module_power_5v_disable = false; + bool temp_external_module_power_amp = false; bool temp_timestamp_file_names = false; //int32_t temp_preset = 0; bool frequency_analyzer_feedback_level_was_read = false; @@ -77,6 +79,11 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count fff_data_file, SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER, (bool*)&temp_external_module_power_5v_disable, + 1); + flipper_format_read_bool( + fff_data_file, + SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, + (bool*)&temp_external_module_power_amp, 1); flipper_format_read_bool( fff_data_file, @@ -96,6 +103,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL; instance->frequency_analyzer_trigger = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER; instance->external_module_enabled = false; + instance->external_module_power_amp = false; instance->timestamp_file_names = false; } else { @@ -118,7 +126,9 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->external_module_power_5v_disable = temp_external_module_power_5v_disable; instance->timestamp_file_names = temp_timestamp_file_names; - + + instance->external_module_power_amp = temp_external_module_power_amp; + /*/} else { instance->preset = temp_preset; }*/ @@ -188,6 +198,13 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { &instance->external_module_power_5v_disable, 1)) { break; + } + if(!flipper_format_insert_or_update_bool( + file, + SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, + &instance->external_module_power_amp, + 1)) { + break; } if(!flipper_format_insert_or_update_bool( file, diff --git a/applications/main/subghz/subghz_last_settings.h b/applications/main/subghz/subghz_last_settings.h index d1a5b495f5..c351cb6a5a 100644 --- a/applications/main/subghz/subghz_last_settings.h +++ b/applications/main/subghz/subghz_last_settings.h @@ -13,6 +13,7 @@ typedef struct { // TODO not using but saved so as not to change the version bool external_module_enabled; bool external_module_power_5v_disable; + bool external_module_power_amp; // saved so as not to change the version bool timestamp_file_names; } SubGhzLastSettings; diff --git a/lib/subghz/devices/devices.c b/lib/subghz/devices/devices.c index a90bf73a32..525c38323f 100644 --- a/lib/subghz/devices/devices.c +++ b/lib/subghz/devices/devices.c @@ -2,14 +2,34 @@ #include "registry.h" +#include + void subghz_devices_init() { furi_check(!subghz_device_registry_is_valid()); subghz_device_registry_init(); + + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); + } + + subghz_last_settings_free(last_settings); } void subghz_devices_deinit(void) { furi_check(subghz_device_registry_is_valid()); subghz_device_registry_deinit(); + + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); + } + + subghz_last_settings_free(last_settings); } const SubGhzDevice* subghz_devices_get_by_name(const char* device_name) { @@ -69,6 +89,7 @@ void subghz_devices_idle(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->idle) { device->interconnect->idle(); + furi_hal_gpio_write(&gpio_ext_pc3, 0); } } @@ -121,6 +142,15 @@ bool subghz_devices_set_tx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_tx) { ret = device->interconnect->set_tx(); + + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_write(&gpio_ext_pc3, 1); + } + + subghz_last_settings_free(last_settings); } return ret; } @@ -161,6 +191,14 @@ void subghz_devices_set_rx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_rx) { device->interconnect->set_rx(); + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + if(last_settings->external_module_power_amp) { + furi_hal_gpio_write(&gpio_ext_pc3, 0); + } + + subghz_last_settings_free(last_settings); } } From d4ff1e3a5087b58d36b62ae0b4ff0321ed95562c Mon Sep 17 00:00:00 2001 From: Cody Tolene Date: Thu, 27 Jul 2023 22:25:37 -0500 Subject: [PATCH 02/44] Update '[ESP32] Camera Suite' to v1.1.0 --- .../external/camera_suite/camera_suite.c | 25 +- .../external/camera_suite/camera_suite.h | 10 +- .../helpers/camera_suite_custom_event.h | 21 +- ..._style_1.c => camera_suite_scene_camera.c} | 28 +- .../scenes/camera_suite_scene_config.h | 3 +- .../scenes/camera_suite_scene_menu.c | 26 +- .../scenes/camera_suite_scene_start.c | 2 +- .../scenes/camera_suite_scene_style_2.c | 54 ---- ...w_style_1.c => camera_suite_view_camera.c} | 157 +++++------ ...w_style_1.h => camera_suite_view_camera.h} | 27 +- .../views/camera_suite_view_style_2.c | 249 ------------------ .../views/camera_suite_view_style_2.h | 19 -- 12 files changed, 120 insertions(+), 501 deletions(-) rename applications/external/camera_suite/scenes/{camera_suite_scene_style_1.c => camera_suite_scene_camera.c} (59%) delete mode 100644 applications/external/camera_suite/scenes/camera_suite_scene_style_2.c rename applications/external/camera_suite/views/{camera_suite_view_style_1.c => camera_suite_view_camera.c} (72%) rename applications/external/camera_suite/views/{camera_suite_view_style_1.h => camera_suite_view_camera.h} (56%) delete mode 100644 applications/external/camera_suite/views/camera_suite_view_style_2.c delete mode 100644 applications/external/camera_suite/views/camera_suite_view_style_2.h diff --git a/applications/external/camera_suite/camera_suite.c b/applications/external/camera_suite/camera_suite.c index 13ee09c22c..cbe7e3d62d 100644 --- a/applications/external/camera_suite/camera_suite.c +++ b/applications/external/camera_suite/camera_suite.c @@ -13,7 +13,7 @@ void camera_suite_tick_event_callback(void* context) { scene_manager_handle_tick_event(app->scene_manager); } -//leave app if back button pressed +// Leave app if back button pressed. bool camera_suite_navigation_event_callback(void* context) { furi_assert(context); CameraSuite* app = context; @@ -25,10 +25,10 @@ CameraSuite* camera_suite_app_alloc() { app->gui = furi_record_open(RECORD_GUI); app->notification = furi_record_open(RECORD_NOTIFICATION); - //Turn backlight on, believe me this makes testing your app easier + // Turn backlight on. notification_message(app->notification, &sequence_display_backlight_on); - //Scene additions + // Scene additions app->view_dispatcher = view_dispatcher_alloc(); view_dispatcher_enable_queue(app->view_dispatcher); @@ -60,17 +60,11 @@ CameraSuite* camera_suite_app_alloc() { CameraSuiteViewIdStartscreen, camera_suite_view_start_get_view(app->camera_suite_view_start)); - app->camera_suite_view_style_1 = camera_suite_view_style_1_alloc(); + app->camera_suite_view_camera = camera_suite_view_camera_alloc(); view_dispatcher_add_view( app->view_dispatcher, - CameraSuiteViewIdScene1, - camera_suite_view_style_1_get_view(app->camera_suite_view_style_1)); - - app->camera_suite_view_style_2 = camera_suite_view_style_2_alloc(); - view_dispatcher_add_view( - app->view_dispatcher, - CameraSuiteViewIdScene2, - camera_suite_view_style_2_get_view(app->camera_suite_view_style_2)); + CameraSuiteViewIdCamera, + camera_suite_view_camera_get_view(app->camera_suite_view_camera)); app->camera_suite_view_guide = camera_suite_view_guide_alloc(); view_dispatcher_add_view( @@ -98,9 +92,9 @@ void camera_suite_app_free(CameraSuite* app) { scene_manager_free(app->scene_manager); // View Dispatcher + view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdStartscreen); view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdMenu); - view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdScene1); - view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdScene2); + view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdCamera); view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdGuide); view_dispatcher_remove_view(app->view_dispatcher, CameraSuiteViewIdSettings); submenu_free(app->submenu); @@ -110,8 +104,7 @@ void camera_suite_app_free(CameraSuite* app) { // Free remaining resources camera_suite_view_start_free(app->camera_suite_view_start); - camera_suite_view_style_1_free(app->camera_suite_view_style_1); - camera_suite_view_style_2_free(app->camera_suite_view_style_2); + camera_suite_view_camera_free(app->camera_suite_view_camera); camera_suite_view_guide_free(app->camera_suite_view_guide); button_menu_free(app->button_menu); variable_item_list_free(app->variable_item_list); diff --git a/applications/external/camera_suite/camera_suite.h b/applications/external/camera_suite/camera_suite.h index 2b6a7748b8..a8b9825bef 100644 --- a/applications/external/camera_suite/camera_suite.h +++ b/applications/external/camera_suite/camera_suite.h @@ -4,9 +4,7 @@ #include "scenes/camera_suite_scene.h" #include "views/camera_suite_view_guide.h" #include "views/camera_suite_view_start.h" -#include "views/camera_suite_view_style_1.h" -#include "views/camera_suite_view_style_2.h" -#include +#include "views/camera_suite_view_camera.h" #include #include #include @@ -29,8 +27,7 @@ typedef struct { SceneManager* scene_manager; VariableItemList* variable_item_list; CameraSuiteViewStart* camera_suite_view_start; - CameraSuiteViewStyle1* camera_suite_view_style_1; - CameraSuiteViewStyle2* camera_suite_view_style_2; + CameraSuiteViewCamera* camera_suite_view_camera; CameraSuiteViewGuide* camera_suite_view_guide; uint32_t orientation; uint32_t haptic; @@ -42,8 +39,7 @@ typedef struct { typedef enum { CameraSuiteViewIdStartscreen, CameraSuiteViewIdMenu, - CameraSuiteViewIdScene1, - CameraSuiteViewIdScene2, + CameraSuiteViewIdCamera, CameraSuiteViewIdGuide, CameraSuiteViewIdSettings, } CameraSuiteViewId; diff --git a/applications/external/camera_suite/helpers/camera_suite_custom_event.h b/applications/external/camera_suite/helpers/camera_suite_custom_event.h index 7727a0de3c..4d472d577a 100644 --- a/applications/external/camera_suite/helpers/camera_suite_custom_event.h +++ b/applications/external/camera_suite/helpers/camera_suite_custom_event.h @@ -8,20 +8,13 @@ typedef enum { CameraSuiteCustomEventStartRight, CameraSuiteCustomEventStartOk, CameraSuiteCustomEventStartBack, - // Scene events: Camera style 1 - CameraSuiteCustomEventSceneStyle1Up, - CameraSuiteCustomEventSceneStyle1Down, - CameraSuiteCustomEventSceneStyle1Left, - CameraSuiteCustomEventSceneStyle1Right, - CameraSuiteCustomEventSceneStyle1Ok, - CameraSuiteCustomEventSceneStyle1Back, - // Scene events: Camera style 2 - CameraSuiteCustomEventSceneStyle2Up, - CameraSuiteCustomEventSceneStyle2Down, - CameraSuiteCustomEventSceneStyle2Left, - CameraSuiteCustomEventSceneStyle2Right, - CameraSuiteCustomEventSceneStyle2Ok, - CameraSuiteCustomEventSceneStyle2Back, + // Scene events: Camera + CameraSuiteCustomEventSceneCameraUp, + CameraSuiteCustomEventSceneCameraDown, + CameraSuiteCustomEventSceneCameraLeft, + CameraSuiteCustomEventSceneCameraRight, + CameraSuiteCustomEventSceneCameraOk, + CameraSuiteCustomEventSceneCameraBack, // Scene events: Guide CameraSuiteCustomEventSceneGuideUp, CameraSuiteCustomEventSceneGuideDown, diff --git a/applications/external/camera_suite/scenes/camera_suite_scene_style_1.c b/applications/external/camera_suite/scenes/camera_suite_scene_camera.c similarity index 59% rename from applications/external/camera_suite/scenes/camera_suite_scene_style_1.c rename to applications/external/camera_suite/scenes/camera_suite_scene_camera.c index 1aeecec7a8..809d9a5c11 100644 --- a/applications/external/camera_suite/scenes/camera_suite_scene_style_1.c +++ b/applications/external/camera_suite/scenes/camera_suite_scene_camera.c @@ -1,35 +1,35 @@ #include "../camera_suite.h" #include "../helpers/camera_suite_custom_event.h" -#include "../views/camera_suite_view_style_1.h" +#include "../views/camera_suite_view_camera.h" -static void camera_suite_view_style_1_callback(CameraSuiteCustomEvent event, void* context) { +void camera_suite_view_camera_callback(CameraSuiteCustomEvent event, void* context) { furi_assert(context); CameraSuite* app = context; view_dispatcher_send_custom_event(app->view_dispatcher, event); } -void camera_suite_scene_style_1_on_enter(void* context) { +void camera_suite_scene_camera_on_enter(void* context) { furi_assert(context); CameraSuite* app = context; - camera_suite_view_style_1_set_callback( - app->camera_suite_view_style_1, camera_suite_view_style_1_callback, app); - view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdScene1); + camera_suite_view_camera_set_callback( + app->camera_suite_view_camera, camera_suite_view_camera_callback, app); + view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdCamera); } -bool camera_suite_scene_style_1_on_event(void* context, SceneManagerEvent event) { +bool camera_suite_scene_camera_on_event(void* context, SceneManagerEvent event) { CameraSuite* app = context; bool consumed = false; if(event.type == SceneManagerEventTypeCustom) { switch(event.event) { - case CameraSuiteCustomEventSceneStyle1Left: - case CameraSuiteCustomEventSceneStyle1Right: - case CameraSuiteCustomEventSceneStyle1Up: - case CameraSuiteCustomEventSceneStyle1Down: - case CameraSuiteCustomEventSceneStyle1Ok: + case CameraSuiteCustomEventSceneCameraLeft: + case CameraSuiteCustomEventSceneCameraRight: + case CameraSuiteCustomEventSceneCameraUp: + case CameraSuiteCustomEventSceneCameraDown: + case CameraSuiteCustomEventSceneCameraOk: // Do nothing. break; - case CameraSuiteCustomEventSceneStyle1Back: + case CameraSuiteCustomEventSceneCameraBack: notification_message(app->notification, &sequence_reset_red); notification_message(app->notification, &sequence_reset_green); notification_message(app->notification, &sequence_reset_blue); @@ -46,7 +46,7 @@ bool camera_suite_scene_style_1_on_event(void* context, SceneManagerEvent event) return consumed; } -void camera_suite_scene_style_1_on_exit(void* context) { +void camera_suite_scene_camera_on_exit(void* context) { CameraSuite* app = context; UNUSED(app); } diff --git a/applications/external/camera_suite/scenes/camera_suite_scene_config.h b/applications/external/camera_suite/scenes/camera_suite_scene_config.h index fca73ae169..2cb9245efc 100644 --- a/applications/external/camera_suite/scenes/camera_suite_scene_config.h +++ b/applications/external/camera_suite/scenes/camera_suite_scene_config.h @@ -1,6 +1,5 @@ ADD_SCENE(camera_suite, start, Start) ADD_SCENE(camera_suite, menu, Menu) -ADD_SCENE(camera_suite, style_1, Style_1) -ADD_SCENE(camera_suite, style_2, Style_2) +ADD_SCENE(camera_suite, camera, Camera) ADD_SCENE(camera_suite, guide, Guide) ADD_SCENE(camera_suite, settings, Settings) \ No newline at end of file diff --git a/applications/external/camera_suite/scenes/camera_suite_scene_menu.c b/applications/external/camera_suite/scenes/camera_suite_scene_menu.c index 09c4dade7b..ae37e11b6a 100644 --- a/applications/external/camera_suite/scenes/camera_suite_scene_menu.c +++ b/applications/external/camera_suite/scenes/camera_suite_scene_menu.c @@ -1,10 +1,8 @@ #include "../camera_suite.h" enum SubmenuIndex { - /** Atkinson Dithering Algorithm. */ - SubmenuIndexSceneStyle1 = 10, - /** Floyd-Steinberg Dithering Algorithm. */ - SubmenuIndexSceneStyle2, + /** Camera. */ + SubmenuIndexSceneCamera = 10, /** Guide/how-to. */ SubmenuIndexGuide, /** Settings menu. */ @@ -22,16 +20,9 @@ void camera_suite_scene_menu_on_enter(void* context) { submenu_add_item( app->submenu, "Open Camera", - SubmenuIndexSceneStyle1, + SubmenuIndexSceneCamera, camera_suite_scene_menu_submenu_callback, app); - // Staged view for the future. - // submenu_add_item( - // app->submenu, - // "Test", - // SubmenuIndexSceneStyle2, - // camera_suite_scene_menu_submenu_callback, - // app); submenu_add_item( app->submenu, "Guide", SubmenuIndexGuide, camera_suite_scene_menu_submenu_callback, app); submenu_add_item( @@ -56,15 +47,10 @@ bool camera_suite_scene_menu_on_event(void* context, SceneManagerEvent event) { view_dispatcher_stop(app->view_dispatcher); return true; } else if(event.type == SceneManagerEventTypeCustom) { - if(event.event == SubmenuIndexSceneStyle1) { + if(event.event == SubmenuIndexSceneCamera) { scene_manager_set_scene_state( - app->scene_manager, CameraSuiteSceneMenu, SubmenuIndexSceneStyle1); - scene_manager_next_scene(app->scene_manager, CameraSuiteSceneStyle_1); - return true; - } else if(event.event == SubmenuIndexSceneStyle2) { - scene_manager_set_scene_state( - app->scene_manager, CameraSuiteSceneMenu, SubmenuIndexSceneStyle2); - scene_manager_next_scene(app->scene_manager, CameraSuiteSceneStyle_2); + app->scene_manager, CameraSuiteSceneMenu, SubmenuIndexSceneCamera); + scene_manager_next_scene(app->scene_manager, CameraSuiteSceneCamera); return true; } else if(event.event == SubmenuIndexGuide) { scene_manager_set_scene_state( diff --git a/applications/external/camera_suite/scenes/camera_suite_scene_start.c b/applications/external/camera_suite/scenes/camera_suite_scene_start.c index 12591760c3..0dda05edef 100644 --- a/applications/external/camera_suite/scenes/camera_suite_scene_start.c +++ b/applications/external/camera_suite/scenes/camera_suite_scene_start.c @@ -24,9 +24,9 @@ bool camera_suite_scene_start_on_event(void* context, SceneManagerEvent event) { switch(event.event) { case CameraSuiteCustomEventStartLeft: case CameraSuiteCustomEventStartRight: - break; case CameraSuiteCustomEventStartUp: case CameraSuiteCustomEventStartDown: + // Do nothing. break; case CameraSuiteCustomEventStartOk: scene_manager_next_scene(app->scene_manager, CameraSuiteSceneMenu); diff --git a/applications/external/camera_suite/scenes/camera_suite_scene_style_2.c b/applications/external/camera_suite/scenes/camera_suite_scene_style_2.c deleted file mode 100644 index b74d33784e..0000000000 --- a/applications/external/camera_suite/scenes/camera_suite_scene_style_2.c +++ /dev/null @@ -1,54 +0,0 @@ -#include "../camera_suite.h" -#include "../helpers/camera_suite_custom_event.h" -#include "../helpers/camera_suite_haptic.h" -#include "../helpers/camera_suite_led.h" -#include "../views/camera_suite_view_style_2.h" - -void camera_suite_view_style_2_callback(CameraSuiteCustomEvent event, void* context) { - furi_assert(context); - CameraSuite* app = context; - view_dispatcher_send_custom_event(app->view_dispatcher, event); -} - -void camera_suite_scene_style_2_on_enter(void* context) { - furi_assert(context); - CameraSuite* app = context; - camera_suite_view_style_2_set_callback( - app->camera_suite_view_style_2, camera_suite_view_style_2_callback, app); - view_dispatcher_switch_to_view(app->view_dispatcher, CameraSuiteViewIdScene2); -} - -bool camera_suite_scene_style_2_on_event(void* context, SceneManagerEvent event) { - CameraSuite* app = context; - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - switch(event.event) { - case CameraSuiteCustomEventSceneStyle2Left: - case CameraSuiteCustomEventSceneStyle2Right: - case CameraSuiteCustomEventSceneStyle2Up: - case CameraSuiteCustomEventSceneStyle2Down: - case CameraSuiteCustomEventSceneStyle2Ok: - // Do nothing. - break; - case CameraSuiteCustomEventSceneStyle2Back: - notification_message(app->notification, &sequence_reset_red); - notification_message(app->notification, &sequence_reset_green); - notification_message(app->notification, &sequence_reset_blue); - if(!scene_manager_search_and_switch_to_previous_scene( - app->scene_manager, CameraSuiteSceneMenu)) { - scene_manager_stop(app->scene_manager); - view_dispatcher_stop(app->view_dispatcher); - } - consumed = true; - break; - } - } - - return consumed; -} - -void camera_suite_scene_style_2_on_exit(void* context) { - CameraSuite* app = context; - UNUSED(app); -} diff --git a/applications/external/camera_suite/views/camera_suite_view_style_1.c b/applications/external/camera_suite/views/camera_suite_view_camera.c similarity index 72% rename from applications/external/camera_suite/views/camera_suite_view_style_1.c rename to applications/external/camera_suite/views/camera_suite_view_camera.c index 6d16d02318..5d710044b9 100644 --- a/applications/external/camera_suite/views/camera_suite_view_style_1.c +++ b/applications/external/camera_suite/views/camera_suite_view_camera.c @@ -8,23 +8,19 @@ #include "../helpers/camera_suite_speaker.h" #include "../helpers/camera_suite_led.h" -static CameraSuiteViewStyle1* current_instance = NULL; -// Dithering type: -// 0 = Floyd Steinberg (default) -// 1 = Atkinson -static int current_dithering = 0; - -struct CameraSuiteViewStyle1 { - CameraSuiteViewStyle1Callback callback; +static CameraSuiteViewCamera* current_instance = NULL; + +struct CameraSuiteViewCamera { + CameraSuiteViewCameraCallback callback; FuriStreamBuffer* rx_stream; FuriThread* worker_thread; View* view; void* context; }; -void camera_suite_view_style_1_set_callback( - CameraSuiteViewStyle1* instance, - CameraSuiteViewStyle1Callback callback, +void camera_suite_view_camera_set_callback( + CameraSuiteViewCamera* instance, + CameraSuiteViewCameraCallback callback, void* context) { furi_assert(instance); furi_assert(callback); @@ -32,7 +28,29 @@ void camera_suite_view_style_1_set_callback( instance->context = context; } -static void camera_suite_view_style_1_draw(Canvas* canvas, UartDumpModel* model) { +// Function to draw pixels on the canvas based on camera orientation +static void draw_pixel_by_orientation(Canvas* canvas, uint8_t x, uint8_t y, uint8_t orientation) { + switch(orientation) { + case 0: // Camera rotated 0 degrees (right side up, default) + canvas_draw_dot(canvas, x, y); + break; + case 1: // Camera rotated 90 degrees + canvas_draw_dot(canvas, y, FRAME_WIDTH - 1 - x); + break; + case 2: // Camera rotated 180 degrees (upside down) + canvas_draw_dot(canvas, FRAME_WIDTH - 1 - x, FRAME_HEIGHT - 1 - y); + break; + case 3: // Camera rotated 270 degrees + canvas_draw_dot(canvas, FRAME_HEIGHT - 1 - y, x); + break; + default: + break; + } +} + +static void camera_suite_view_camera_draw(Canvas* canvas, void* _model) { + UartDumpModel* model = _model; + // Clear the screen. canvas_set_color(canvas, ColorBlack); @@ -41,60 +59,17 @@ static void camera_suite_view_style_1_draw(Canvas* canvas, UartDumpModel* model) CameraSuite* app = current_instance->context; - // Draw the pixels with rotation. for(size_t p = 0; p < FRAME_BUFFER_LENGTH; ++p) { uint8_t x = p % ROW_BUFFER_LENGTH; // 0 .. 15 uint8_t y = p / ROW_BUFFER_LENGTH; // 0 .. 63 - // Apply rotation - int16_t rotated_x, rotated_y; - switch(app->orientation) { - case 1: // 90 degrees - rotated_x = y; - rotated_y = FRAME_WIDTH - 1 - x; - break; - case 2: // 180 degrees - rotated_x = FRAME_WIDTH - 1 - x; - rotated_y = FRAME_HEIGHT - 1 - y; - break; - case 3: // 270 degrees - rotated_x = FRAME_HEIGHT - 1 - y; - rotated_y = x; - break; - case 0: // 0 degrees - default: - rotated_x = x; - rotated_y = y; - break; - } - for(uint8_t i = 0; i < 8; ++i) { - if((model->pixels[p] & (1 << i)) != 0) { - // Adjust the coordinates based on the new screen dimensions - uint16_t screen_x, screen_y; - switch(app->orientation) { - case 1: // 90 degrees - screen_x = rotated_x; - screen_y = FRAME_HEIGHT - 8 + (rotated_y * 8) + i; - break; - case 2: // 180 degrees - screen_x = FRAME_WIDTH - 8 + (rotated_x * 8) + i; - screen_y = FRAME_HEIGHT - 1 - rotated_y; - break; - case 3: // 270 degrees - screen_x = FRAME_WIDTH - 1 - rotated_x; - screen_y = rotated_y * 8 + i; - break; - case 0: // 0 degrees - default: - screen_x = rotated_x * 8 + i; - screen_y = rotated_y; - break; - } - canvas_draw_dot(canvas, screen_x, screen_y); + if((model->pixels[p] & (1 << (7 - i))) != 0) { + draw_pixel_by_orientation(canvas, (x * 8) + i, y, app->orientation); } } } + // Draw the guide if the camera is not initialized. if(!model->initialized) { canvas_draw_icon(canvas, 74, 16, &I_DolphinCommon_56x48); @@ -107,15 +82,15 @@ static void camera_suite_view_style_1_draw(Canvas* canvas, UartDumpModel* model) } } -static void camera_suite_view_style_1_model_init(UartDumpModel* const model) { +static void camera_suite_view_camera_model_init(UartDumpModel* const model) { for(size_t i = 0; i < FRAME_BUFFER_LENGTH; i++) { model->pixels[i] = 0; } } -static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { +static bool camera_suite_view_camera_input(InputEvent* event, void* context) { furi_assert(context); - CameraSuiteViewStyle1* instance = context; + CameraSuiteViewCamera* instance = context; if(event->type == InputTypeRelease) { switch(event->key) { default: // Stop all sounds, reset the LED. @@ -144,7 +119,7 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { UartDumpModel * model, { UNUSED(model); - instance->callback(CameraSuiteCustomEventSceneStyle1Back, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraBack, instance->context); }, true); break; @@ -159,7 +134,7 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { camera_suite_play_happy_bump(instance->context); camera_suite_play_input_sound(instance->context); camera_suite_led_set_rgb(instance->context, 0, 0, 255); - instance->callback(CameraSuiteCustomEventSceneStyle1Left, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraLeft, instance->context); }, true); break; @@ -174,7 +149,7 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { camera_suite_play_happy_bump(instance->context); camera_suite_play_input_sound(instance->context); camera_suite_led_set_rgb(instance->context, 0, 0, 255); - instance->callback(CameraSuiteCustomEventSceneStyle1Right, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraRight, instance->context); }, true); break; @@ -189,7 +164,7 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { camera_suite_play_happy_bump(instance->context); camera_suite_play_input_sound(instance->context); camera_suite_led_set_rgb(instance->context, 0, 0, 255); - instance->callback(CameraSuiteCustomEventSceneStyle1Up, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraUp, instance->context); }, true); break; @@ -204,18 +179,13 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { camera_suite_play_happy_bump(instance->context); camera_suite_play_input_sound(instance->context); camera_suite_led_set_rgb(instance->context, 0, 0, 255); - instance->callback(CameraSuiteCustomEventSceneStyle1Down, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraDown, instance->context); }, true); break; case InputKeyOk: - if(current_dithering == 0) { - data[0] = 'd'; // Update to Floyd Steinberg dithering. - current_dithering = 1; - } else { - data[0] = 'D'; // Update to Atkinson dithering. - current_dithering = 0; - } + // Switch dithering types. + data[0] = 'D'; with_view_model( instance->view, UartDumpModel * model, @@ -224,7 +194,7 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { camera_suite_play_happy_bump(instance->context); camera_suite_play_input_sound(instance->context); camera_suite_led_set_rgb(instance->context, 0, 0, 255); - instance->callback(CameraSuiteCustomEventSceneStyle1Ok, instance->context); + instance->callback(CameraSuiteCustomEventSceneCameraOk, instance->context); }, true); break; @@ -237,16 +207,16 @@ static bool camera_suite_view_style_1_input(InputEvent* event, void* context) { return true; } -static void camera_suite_view_style_1_exit(void* context) { +static void camera_suite_view_camera_exit(void* context) { furi_assert(context); } -static void camera_suite_view_style_1_enter(void* context) { +static void camera_suite_view_camera_enter(void* context) { // Check `context` for null. If it is null, abort program, else continue. furi_assert(context); - // Cast `context` to `CameraSuiteViewStyle1*` and store it in `instance`. - CameraSuiteViewStyle1* instance = (CameraSuiteViewStyle1*)context; + // Cast `context` to `CameraSuiteViewCamera*` and store it in `instance`. + CameraSuiteViewCamera* instance = (CameraSuiteViewCamera*)context; // Assign the current instance to the global variable current_instance = instance; @@ -259,7 +229,7 @@ static void camera_suite_view_style_1_enter(void* context) { with_view_model( instance->view, UartDumpModel * model, - { camera_suite_view_style_1_model_init(model); }, + { camera_suite_view_camera_model_init(model); }, true); } @@ -267,8 +237,8 @@ static void camera_on_irq_cb(UartIrqEvent uartIrqEvent, uint8_t data, void* cont // Check `context` for null. If it is null, abort program, else continue. furi_assert(context); - // Cast `context` to `CameraSuiteViewStyle1*` and store it in `instance`. - CameraSuiteViewStyle1* instance = context; + // Cast `context` to `CameraSuiteViewCamera*` and store it in `instance`. + CameraSuiteViewCamera* instance = context; // If `uartIrqEvent` is `UartIrqEventRXNE`, send the data to the // `rx_stream` and set the `WorkerEventRx` flag. @@ -319,7 +289,7 @@ static void process_ringbuffer(UartDumpModel* model, uint8_t byte) { static int32_t camera_worker(void* context) { furi_assert(context); - CameraSuiteViewStyle1* instance = context; + CameraSuiteViewCamera* instance = context; while(1) { uint32_t events = @@ -348,14 +318,17 @@ static int32_t camera_worker(void* context) { false); } } while(length > 0); + + with_view_model( + instance->view, UartDumpModel * model, { UNUSED(model); }, true); } } return 0; } -CameraSuiteViewStyle1* camera_suite_view_style_1_alloc() { - CameraSuiteViewStyle1* instance = malloc(sizeof(CameraSuiteViewStyle1)); +CameraSuiteViewCamera* camera_suite_view_camera_alloc() { + CameraSuiteViewCamera* instance = malloc(sizeof(CameraSuiteViewCamera)); instance->view = view_alloc(); @@ -364,15 +337,15 @@ CameraSuiteViewStyle1* camera_suite_view_style_1_alloc() { // Set up views view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(UartDumpModel)); view_set_context(instance->view, instance); // furi_assert crashes in events without this - view_set_draw_callback(instance->view, (ViewDrawCallback)camera_suite_view_style_1_draw); - view_set_input_callback(instance->view, camera_suite_view_style_1_input); - view_set_enter_callback(instance->view, camera_suite_view_style_1_enter); - view_set_exit_callback(instance->view, camera_suite_view_style_1_exit); + view_set_draw_callback(instance->view, (ViewDrawCallback)camera_suite_view_camera_draw); + view_set_input_callback(instance->view, camera_suite_view_camera_input); + view_set_enter_callback(instance->view, camera_suite_view_camera_enter); + view_set_exit_callback(instance->view, camera_suite_view_camera_exit); with_view_model( instance->view, UartDumpModel * model, - { camera_suite_view_style_1_model_init(model); }, + { camera_suite_view_camera_model_init(model); }, true); instance->worker_thread = furi_thread_alloc_ex("UsbUartWorker", 2048, camera_worker, instance); @@ -386,7 +359,7 @@ CameraSuiteViewStyle1* camera_suite_view_style_1_alloc() { return instance; } -void camera_suite_view_style_1_free(CameraSuiteViewStyle1* instance) { +void camera_suite_view_camera_free(CameraSuiteViewCamera* instance) { furi_assert(instance); with_view_model( @@ -395,7 +368,7 @@ void camera_suite_view_style_1_free(CameraSuiteViewStyle1* instance) { free(instance); } -View* camera_suite_view_style_1_get_view(CameraSuiteViewStyle1* instance) { +View* camera_suite_view_camera_get_view(CameraSuiteViewCamera* instance) { furi_assert(instance); return instance->view; -} +} \ No newline at end of file diff --git a/applications/external/camera_suite/views/camera_suite_view_style_1.h b/applications/external/camera_suite/views/camera_suite_view_camera.h similarity index 56% rename from applications/external/camera_suite/views/camera_suite_view_style_1.h rename to applications/external/camera_suite/views/camera_suite_view_camera.h index c460c94bab..5ccbac71a2 100644 --- a/applications/external/camera_suite/views/camera_suite_view_style_1.h +++ b/applications/external/camera_suite/views/camera_suite_view_camera.h @@ -19,11 +19,12 @@ #define FRAME_WIDTH 128 #define FRAME_HEIGHT 64 #define FRAME_BIT_DEPTH 1 -#define FRAME_BUFFER_LENGTH \ - (FRAME_WIDTH * FRAME_HEIGHT * FRAME_BIT_DEPTH / 8) // 128*64*1 / 8 = 1024 -#define ROW_BUFFER_LENGTH (FRAME_WIDTH / 8) // 128/8 = 16 -#define RING_BUFFER_LENGTH (ROW_BUFFER_LENGTH + 3) // ROW_BUFFER_LENGTH + Header => 16 + 3 = 19 -#define LAST_ROW_INDEX (FRAME_BUFFER_LENGTH - ROW_BUFFER_LENGTH) // 1024 - 16 = 1008 +#define FRAME_BUFFER_LENGTH 1024 +#define ROW_BUFFER_LENGTH 16 +#define RING_BUFFER_LENGTH 19 +#define LAST_ROW_INDEX 1008 + +extern const Icon I_DolphinCommon_56x48; typedef struct UartDumpModel UartDumpModel; @@ -35,20 +36,20 @@ struct UartDumpModel { uint8_t row_ringbuffer[RING_BUFFER_LENGTH]; }; -typedef struct CameraSuiteViewStyle1 CameraSuiteViewStyle1; +typedef struct CameraSuiteViewCamera CameraSuiteViewCamera; -typedef void (*CameraSuiteViewStyle1Callback)(CameraSuiteCustomEvent event, void* context); +typedef void (*CameraSuiteViewCameraCallback)(CameraSuiteCustomEvent event, void* context); -void camera_suite_view_style_1_set_callback( - CameraSuiteViewStyle1* camera_suite_view_style_1, - CameraSuiteViewStyle1Callback callback, +void camera_suite_view_camera_set_callback( + CameraSuiteViewCamera* camera_suite_view_camera, + CameraSuiteViewCameraCallback callback, void* context); -CameraSuiteViewStyle1* camera_suite_view_style_1_alloc(); +CameraSuiteViewCamera* camera_suite_view_camera_alloc(); -void camera_suite_view_style_1_free(CameraSuiteViewStyle1* camera_suite_static); +void camera_suite_view_camera_free(CameraSuiteViewCamera* camera_suite_static); -View* camera_suite_view_style_1_get_view(CameraSuiteViewStyle1* camera_suite_static); +View* camera_suite_view_camera_get_view(CameraSuiteViewCamera* camera_suite_static); typedef enum { // Reserved for StreamBuffer internal event diff --git a/applications/external/camera_suite/views/camera_suite_view_style_2.c b/applications/external/camera_suite/views/camera_suite_view_style_2.c deleted file mode 100644 index 0a7ac0b832..0000000000 --- a/applications/external/camera_suite/views/camera_suite_view_style_2.c +++ /dev/null @@ -1,249 +0,0 @@ -#include "../camera_suite.h" -#include -#include -#include -#include -#include -#include "../helpers/camera_suite_haptic.h" -#include "../helpers/camera_suite_speaker.h" -#include "../helpers/camera_suite_led.h" - -struct CameraSuiteViewStyle2 { - View* view; - CameraSuiteViewStyle2Callback callback; - void* context; -}; - -typedef struct { - int screen_text; -} CameraSuiteViewStyle2Model; - -char buttonText[11][14] = { - "", - "Press Up", - "Press Down", - "Press Left", - "Press Right", - "Press Ok", - "Release Up", - "Release Down", - "Release Left", - "Release Right", - "Release Ok", -}; - -void camera_suite_view_style_2_set_callback( - CameraSuiteViewStyle2* instance, - CameraSuiteViewStyle2Callback callback, - void* context) { - furi_assert(instance); - furi_assert(callback); - instance->callback = callback; - instance->context = context; -} - -void camera_suite_view_style_2_draw(Canvas* canvas, CameraSuiteViewStyle2Model* model) { - canvas_clear(canvas); - canvas_set_color(canvas, ColorBlack); - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned(canvas, 0, 10, AlignLeft, AlignTop, "Scene 2: Input Examples"); - canvas_set_font(canvas, FontSecondary); - char* strInput = malloc(15); - strcpy(strInput, buttonText[model->screen_text]); - canvas_draw_str_aligned(canvas, 0, 22, AlignLeft, AlignTop, strInput); - free(strInput); -} - -static void camera_suite_view_style_2_model_init(CameraSuiteViewStyle2Model* const model) { - model->screen_text = 0; -} - -bool camera_suite_view_style_2_input(InputEvent* event, void* context) { - furi_assert(context); - CameraSuiteViewStyle2* instance = context; - if(event->type == InputTypeRelease) { - switch(event->key) { - case InputKeyBack: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - UNUSED(model); - camera_suite_stop_all_sound(instance->context); - instance->callback(CameraSuiteCustomEventSceneStyle2Back, instance->context); - camera_suite_play_long_bump(instance->context); - }, - true); - break; - case InputKeyUp: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 6; - camera_suite_play_bad_bump(instance->context); - camera_suite_stop_all_sound(instance->context); - camera_suite_led_set_rgb(instance->context, 255, 0, 255); - }, - true); - break; - case InputKeyDown: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 7; - camera_suite_play_bad_bump(instance->context); - camera_suite_stop_all_sound(instance->context); - camera_suite_led_set_rgb(instance->context, 255, 255, 0); - }, - true); - break; - case InputKeyLeft: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 8; - camera_suite_play_bad_bump(instance->context); - camera_suite_stop_all_sound(instance->context); - camera_suite_led_set_rgb(instance->context, 0, 255, 255); - }, - true); - break; - case InputKeyRight: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 9; - camera_suite_play_bad_bump(instance->context); - camera_suite_stop_all_sound(instance->context); - camera_suite_led_set_rgb(instance->context, 255, 0, 0); - }, - true); - break; - case InputKeyOk: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 10; - camera_suite_play_bad_bump(instance->context); - camera_suite_stop_all_sound(instance->context); - camera_suite_led_set_rgb(instance->context, 255, 255, 255); - }, - true); - break; - case InputKeyMAX: - break; - } - } else if(event->type == InputTypePress) { - switch(event->key) { - case InputKeyUp: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 1; - camera_suite_play_happy_bump(instance->context); - camera_suite_play_input_sound(instance->context); - }, - true); - break; - case InputKeyDown: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 2; - camera_suite_play_happy_bump(instance->context); - camera_suite_play_input_sound(instance->context); - }, - true); - break; - case InputKeyLeft: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 3; - camera_suite_play_happy_bump(instance->context); - camera_suite_play_input_sound(instance->context); - }, - true); - break; - case InputKeyRight: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 4; - camera_suite_play_happy_bump(instance->context); - camera_suite_play_input_sound(instance->context); - }, - true); - break; - case InputKeyOk: - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { - model->screen_text = 5; - camera_suite_play_happy_bump(instance->context); - camera_suite_play_input_sound(instance->context); - }, - true); - break; - case InputKeyBack: - case InputKeyMAX: - break; - } - } - - return true; -} - -void camera_suite_view_style_2_exit(void* context) { - furi_assert(context); - CameraSuite* app = context; - camera_suite_stop_all_sound(app); - //camera_suite_led_reset(app); -} - -void camera_suite_view_style_2_enter(void* context) { - furi_assert(context); - dolphin_deed(DolphinDeedPluginStart); -} - -CameraSuiteViewStyle2* camera_suite_view_style_2_alloc() { - CameraSuiteViewStyle2* instance = malloc(sizeof(CameraSuiteViewStyle2)); - instance->view = view_alloc(); - view_allocate_model(instance->view, ViewModelTypeLocking, sizeof(CameraSuiteViewStyle2Model)); - view_set_context(instance->view, instance); - view_set_draw_callback(instance->view, (ViewDrawCallback)camera_suite_view_style_2_draw); - view_set_input_callback(instance->view, camera_suite_view_style_2_input); - //view_set_enter_callback(instance->view, camera_suite_view_style_2_enter); - view_set_exit_callback(instance->view, camera_suite_view_style_2_exit); - - with_view_model( - instance->view, - CameraSuiteViewStyle2Model * model, - { camera_suite_view_style_2_model_init(model); }, - true); - - return instance; -} - -void camera_suite_view_style_2_free(CameraSuiteViewStyle2* instance) { - furi_assert(instance); - - view_free(instance->view); - free(instance); -} - -View* camera_suite_view_style_2_get_view(CameraSuiteViewStyle2* instance) { - furi_assert(instance); - - return instance->view; -} diff --git a/applications/external/camera_suite/views/camera_suite_view_style_2.h b/applications/external/camera_suite/views/camera_suite_view_style_2.h deleted file mode 100644 index d24b895f82..0000000000 --- a/applications/external/camera_suite/views/camera_suite_view_style_2.h +++ /dev/null @@ -1,19 +0,0 @@ -#pragma once - -#include -#include "../helpers/camera_suite_custom_event.h" - -typedef struct CameraSuiteViewStyle2 CameraSuiteViewStyle2; - -typedef void (*CameraSuiteViewStyle2Callback)(CameraSuiteCustomEvent event, void* context); - -void camera_suite_view_style_2_set_callback( - CameraSuiteViewStyle2* instance, - CameraSuiteViewStyle2Callback callback, - void* context); - -CameraSuiteViewStyle2* camera_suite_view_style_2_alloc(); - -void camera_suite_view_style_2_free(CameraSuiteViewStyle2* camera_suite_static); - -View* camera_suite_view_style_2_get_view(CameraSuiteViewStyle2* boilerpate_static); From ff2e1acfdb480712b06f6c913424294d9a38e70d Mon Sep 17 00:00:00 2001 From: Max Andreev Date: Fri, 28 Jul 2023 22:45:27 +0300 Subject: [PATCH 03/44] Fix fbtenv restore (#2924) --- scripts/toolchain/fbtenv.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/scripts/toolchain/fbtenv.sh b/scripts/toolchain/fbtenv.sh index 85d139040b..a86b0ecedb 100755 --- a/scripts/toolchain/fbtenv.sh +++ b/scripts/toolchain/fbtenv.sh @@ -38,11 +38,11 @@ fbtenv_wget() fbtenv_restore_env() { TOOLCHAIN_ARCH_DIR_SED="$(echo "$TOOLCHAIN_ARCH_DIR" | sed 's/\//\\\//g')" - PATH="$(echo "$PATH" | /usr/bin/sed "s/$TOOLCHAIN_ARCH_DIR_SED\/python\/bin://g")"; - PATH="$(echo "$PATH" | /usr/bin/sed "s/$TOOLCHAIN_ARCH_DIR_SED\/bin://g")"; - PATH="$(echo "$PATH" | /usr/bin/sed "s/$TOOLCHAIN_ARCH_DIR_SED\/protobuf\/bin://g")"; - PATH="$(echo "$PATH" | /usr/bin/sed "s/$TOOLCHAIN_ARCH_DIR_SED\/openocd\/bin://g")"; - PATH="$(echo "$PATH" | /usr/bin/sed "s/$TOOLCHAIN_ARCH_DIR_SED\/openssl\/bin://g")"; + PATH="$(echo "$PATH" | sed "s/$TOOLCHAIN_ARCH_DIR_SED\/python\/bin://g")"; + PATH="$(echo "$PATH" | sed "s/$TOOLCHAIN_ARCH_DIR_SED\/bin://g")"; + PATH="$(echo "$PATH" | sed "s/$TOOLCHAIN_ARCH_DIR_SED\/protobuf\/bin://g")"; + PATH="$(echo "$PATH" | sed "s/$TOOLCHAIN_ARCH_DIR_SED\/openocd\/bin://g")"; + PATH="$(echo "$PATH" | sed "s/$TOOLCHAIN_ARCH_DIR_SED\/openssl\/bin://g")"; if [ -n "${PS1:-""}" ]; then PS1="$(echo "$PS1" | sed 's/\[fbt\]//g')"; elif [ -n "${PROMPT:-""}" ]; then @@ -104,8 +104,6 @@ fbtenv_check_if_sourced_multiple_times() return 0; fi fi - echo "Warning! FBT environment script was sourced more than once!"; - echo "You might be doing things wrong, please open a new shell!"; return 1; } @@ -160,7 +158,7 @@ fbtenv_get_kernel_type() fbtenv_check_rosetta() { if [ "$ARCH_TYPE" = "arm64" ]; then - if ! /usr/bin/pgrep -q oahd; then + if ! pgrep -q oahd; then echo "Flipper Zero Toolchain needs Rosetta2 to run under Apple Silicon"; echo "Please instal it by typing 'softwareupdate --install-rosetta --agree-to-license'"; return 1; @@ -312,7 +310,9 @@ fbtenv_main() fbtenv_restore_env; return 0; fi - fbtenv_check_if_sourced_multiple_times; + if ! fbtenv_check_if_sourced_multiple_times; then + return 0; + fi; fbtenv_check_env_vars || return 1; fbtenv_check_download_toolchain || return 1; fbtenv_set_shell_prompt; From e698d6274fe5c7fe364fcbbbe5a8b618da2b71bf Mon Sep 17 00:00:00 2001 From: Cody Tolene Date: Fri, 28 Jul 2023 17:49:42 -0500 Subject: [PATCH 04/44] Update to match changes from here: https://github.com/flipperdevices/flipper-application-catalog/pull/90 --- .../external/camera_suite/application.fam | 4 +- .../external/camera_suite/docs/CHANGELOG.md | 20 ++++++++++ .../external/camera_suite/docs/README.md | 35 ++++++++++++++++++ .../screenshots/camera_preview.png | Bin 0 -> 3342 bytes .../camera_suite/screenshots/guide.png | Bin 0 -> 2233 bytes .../camera_suite/screenshots/main_menu.png | Bin 0 -> 1499 bytes .../camera_suite/screenshots/settings.png | Bin 0 -> 1900 bytes .../camera_suite/screenshots/start_screen.png | Bin 0 -> 1707 bytes 8 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 applications/external/camera_suite/docs/CHANGELOG.md create mode 100644 applications/external/camera_suite/docs/README.md create mode 100644 applications/external/camera_suite/screenshots/camera_preview.png create mode 100644 applications/external/camera_suite/screenshots/guide.png create mode 100644 applications/external/camera_suite/screenshots/main_menu.png create mode 100644 applications/external/camera_suite/screenshots/settings.png create mode 100644 applications/external/camera_suite/screenshots/start_screen.png diff --git a/applications/external/camera_suite/application.fam b/applications/external/camera_suite/application.fam index 40131ae9a1..63687833e9 100644 --- a/applications/external/camera_suite/application.fam +++ b/applications/external/camera_suite/application.fam @@ -1,9 +1,9 @@ App( - appid="camerasuite", + appid="camera_suite", apptype=FlipperAppType.EXTERNAL, cdefines=["APP_CAMERA_SUITE"], entry_point="camera_suite_app", - fap_author="Cody Tolene", + fap_author="@CodyTolene @Z4urce @leedave", fap_category="GPIO", fap_description="A camera suite application for the Flipper Zero ESP32-CAM module.", fap_icon="icons/camera_suite.png", diff --git a/applications/external/camera_suite/docs/CHANGELOG.md b/applications/external/camera_suite/docs/CHANGELOG.md new file mode 100644 index 0000000000..40f20dfc41 --- /dev/null +++ b/applications/external/camera_suite/docs/CHANGELOG.md @@ -0,0 +1,20 @@ +## v1.1 + +- Support and picture stabilization for all camera orientations (0°, 90°, 180°, 270°). +- Rename "Scene 1" to "Camera". No UX changes, strictly internal. +- Clean up unused "Scene 2". This was inaccessible to users previously and unused. +- Add new dithering variations (needs new module firmware, see https://github.com/CodyTolene/Flipper-Zero-Camera-Suite#firmware-installation): + - Add `Jarvis Judice` Ninke Dithering option + - Add `Stucki` dithering option. + - Add ability to toggle dithering options from default `Floyd-Steinberg` and back. +- Resolves issue https://github.com/CodyTolene/Flipper-Zero-Camera-Suite/issues/7 +- Resolves issue https://github.com/CodyTolene/Flipper-Zero-Camera-Suite/pull/17 + +## v1.0 + +- Builds upon Z4urce's software found here (updated 6 months ago): https://github.com/Z4urce/flipperzero-camera +- Utilizes the superb C boilerplate examples laid out by leedave (updated last month): https://github.com/leedave/flipper-zero-fap-boilerplate +- Repurpose and build upon the "[ESP32] Camera" software into the new "[ESP32] Camera Suite" application with new purpose: + - Adding more scene for a guide. + - Adding more scene for saveable settings. + - Add ability to rotate the camera orientation. diff --git a/applications/external/camera_suite/docs/README.md b/applications/external/camera_suite/docs/README.md new file mode 100644 index 0000000000..1f436a0675 --- /dev/null +++ b/applications/external/camera_suite/docs/README.md @@ -0,0 +1,35 @@ +## Flipper Zero - Camera Suite + +Software to run an ESP32-CAM module on your Flipper Zero device. + +## Software Guide + +### Flipper Zero button mappings: + +🔼 = Contrast Up + +🔽 = Contrast Down + +◀️ = Toggle invert. + +▶️ = Toggle dithering on/off. + +⚪ = Cycle Floyd–Steinberg/Jarvis-Judice-Ninke/Stucki dithering types. + +↩️ = Go back. + +### Camera Suite settings: + +**Orientation** = Rotate the camera image 90 degrees counter-clockwise starting at zero by default (0, 90, 180, 270). This is useful if you have your camera module mounted in a different orientation than the default. + +**Haptic FX** = Toggle haptic feedback on/off. + +**Sound FX** = Toggle sound effects on/off. + +**LED FX** = Toggle LED effects on/off. + +## Links + +Full setup, wiring guide, etc. in the main project README here: https://github.com/CodyTolene/Flipper-Zero-Camera-Suite + +A firmware is needed for the ESP32-CAM module, see here for more information: https://github.com/CodyTolene/Flipper-Zero-Camera-Suite#firmware-installation diff --git a/applications/external/camera_suite/screenshots/camera_preview.png b/applications/external/camera_suite/screenshots/camera_preview.png new file mode 100644 index 0000000000000000000000000000000000000000..5f66ec42c833d6464c028af3aa5be312a7bc09a0 GIT binary patch literal 3342 zcmZ8kYgkh07T$KzEVG!#X|Ri>W6p`p)Ja2AE48vF?Izwrvr#l*w7g)bh||SPGb@HV zD#D~wQz_VJNQjq8dlKU^F51dg3*&Tf9Z&$plb?EQW3UTeMYTKmHO z;9ZLs+AahDU~$myfP(-qXZF$zSnz(?qmI}#yI7vs9gzkA*6r_MMnPDw0066pK>^zj zpQ0-J4_x}@4h;BXBI(i_jc%zgUG#&l%CYE0p^eqNc{VB{15+Qg-n-g=-qM-BEM_+Y zfU#oZN$%VOM!kw;G_{&$KvJ&046Tj){e=-hKiSKZrUaBX3Rj8Titg%fhlvl@3@r1Jo={}7)t+nHq-5Mh04V(8Bc|_0 zZeyojcLFaaba*ESi!tG38o_$qw88F*&Tu?F+oF5UoTDo~9Z-9B{&(d?xX_N@NL{oG zAU#&bxt++S#WqOM`KlrquR6~MIEGT{~ zO<#8cF}-Tj9N^nMzz2-zBDZlz&ajh*4#tS&16OsN_$hQ#o!>1vMb*vJT_i(k_jy=c zCI~X}TjDzoB@DMQvg1!BBT(uoL^LnHb+mVe4CT^~%;W2(DR?}?V7iqv%$RxOIiz*Z ziK&dQ=FpX83zE#tmhSk(f)}|BE;N7XX#Z5ZPqU1%+z;&3cKEC0J(gE@(1qVc)^yv9#Q)y7dXjtQ8bf6V+Nx;YD(>E-J$8>A@g8t;e=olX_H#T zz;T3RP9IvoK2m0$%lEAw&N>2f&MiEj1tuj&f9Iw(t#@<(%`AvgG#Fvz3vnTKNex6YnJb(qYt`e=M zhFA=do|l)!iPUBj^9VtKLYG+)Y08lFa;LOgVp&+Fl#bJzXMx(dDeq<5o!0;ju#Yd= zmd)+BhtKXsXv`dv8UCV%{OP!jxnVTJpvo}~T_K(^cBVZWgS+!>ilO34lKAG4Ibf7F zDL!1`Q=XaJ+>(p*w?olLh)V0wbiG(DgHPUS>VT$TR_ymvrDWuv6l^4n)t$Y5(7&D& zdOiVs)z;aJuZZ_aC7QF1JK+#LOeh8gZt~YzS-SQsMX@m`+RL$kVqMh0_^_+@McV*Ed9FG)fGYC%ih{#r~J$&FsCZ^Wf7L1dhF>lkaU zo-xk4(BHz#xc}9DMAU$@e{$x~5%I7)kleGUaI}p{Uv)gKokv^?+gxQ&r7kJD7Avg! zOi(OjUSd7+5t`GzK&7D-XxCOdH3~z|^3x)JEQd@;JC)2$n2k>GF=pC_WI8ItO^xZD%R=WqRRFsA( zO-WZ8$r=ln(U^!U3_s{W23tVI&$NDL+t;2Hyow6%F^1t zm3LCxJ2%%?Y7?3sLrd%i5pckOgF@Nj5Lq8;TCCaQdlHO3yTD0bf6z%jXgsqVd@NcR zVagp7V~o+z0R2+|-6rjSQyyD~d2vpn6wWAk{NH+;dz|(C)xGyl8lk@M}G5JBr!b zBV)_pG4DvS#)A%c7Cn~a-(LE#wjehI+SV2#m;Ay)w6@lH5QcI<%4Bvl&w*48(j~mI z9paHQfhOEpzUU8V1iwrJ>cQF?am?GcjbgPi^;Ro*o{UvyA_=$B+mAdc5^Z&dTHIr- zS@8@G8)l%3vC((1KRd@na8lrtNpZPGhLuzh0heJap@Oz)c~5A`mSf+X|N6jhiSf;8 z`P9_SFjZXsv>rk9j=&~1tWudu(4x=GyDAOvaiLkRbPd_Bd)Eak)wIIoq5J{QsNy>? zuBe)$CCv-;HN2tKf<*JN+nN z2GIo*bbiS$`bnQuX@T^3zBVpEmTLwucv0#O&+clhz)k^fi|=hOE9saCDBtcx1d9y z^fI|Oj+!=HYx zuOyP4eY*BQ|F9MC_nf(pZrP-$d5+fF>clj%f}8D^?RMQua(;KuoXi=;t2bmKdSxWAA z^iTHGYz-KH^?f_-Dq0@W@x1l3xLro(k+IpCJy%i~_v%eiJnJn90K5K}q#)DtG*G+DFQ!G1cY zuJ_Q{l<5uZ!}_Mr=B1=W>(_(EJe169$8*E+Kx)Wk1}!(hd!}P-tNZv*t!@y9SwHjr z>)s+(z8iJI_T=h!8{w%2_CPgSnQ%y{xir-)!a|vj6M&f>CiN}PeQu@Pa_|z^Y^;e^ jk>*1T`G3D4K+GVif8!4SwB3hk?{5SJ1_v;A96kMCO?d&z literal 0 HcmV?d00001 diff --git a/applications/external/camera_suite/screenshots/guide.png b/applications/external/camera_suite/screenshots/guide.png new file mode 100644 index 0000000000000000000000000000000000000000..87ed51218cb4f7b5cd39414798c3fa0335e10d28 GIT binary patch literal 2233 zcmaJ@dr*^C7QYc`kq)t|18tPZ&a%E&D>BG4fUf1yvC&!-kf?0al0r-nD9;dxEw+n7 z5Tzg$5?ERD077d>Qh5YBl#o_14v?e}61R#56CSJZB@pd2Dq&(A3RIk<6PF9jY-S`0Q>XGhxv9Vb|V08 z)YyajSc%}VXTxfJmYkIHuc}K!ftz9` z5r@N$n(r?oTnB3INl&Fwsx|hwo?J~1AX>G&T)G54nx$MY1dFbkkz zllvB)ApWg>_e=@K?d0pe%z(W_!jSaQ$L3J|;z=?42TE}Y>Jrplsj%bnIr-+8Nk<8J0tcnbbjLdqu|MKS3Qlm13@6RuoC!uV@z%cM z)if^8gPBI$Ua!o{P6xI@bDXb@j7n_?+ve zrdWm8j{P4ckk{<)waJ>0 ztuu+IcswpcQzGD8_cZ2CBox%i-#|_F#6ib;OC!_*ZFq(I6|R3!pE5YJNRT-={&z^+ z4vx#!M?W*Fhs)}GjWs*80~DzCN4%UOoQ;5Z6`XYN4Q8}y@vC9&KZ}R*Z)NElw;~(k z;7hGk%(NoU@6sX2&5c1!%a0Xu$~Cc^s@d0UzE&}x)J&s_KIzLXZ=W8O9Ukngvy7Ky+WNNMGbDwEEXaZD$*P-MnkDJNCmZ-nTL73^xzb6gtk z-zD2_r$gzMAl|p>5Bn51ixq`n3T`%oSaY#QC@OVq7qh!5p`Ca}MVf=e6#86lqwwMS z)3#(BvgXeHRYX|_mG5iwV5Hp$K+r`-OKZP@UFAiK-nryayQBkOEp|R^~OjhZb zC@6a8m}N?bCC{(v3DCf!E;S2?6<+bzBl{tZNynwXxq882$_XP z;Zm3>lwY*dJUCIEA@n?35cx|U`%klHCS(su%a1#{xljb%j^)ZWA-SGFi{?apE@?Fc z5}utT(3*9)QMpfLB%DnHmw^EV2R7TS@UA4A6%>M^lpj_wuH3apo5u8YA zJ$96)+t8ELedAYUf`R^!wM(oxI$PJ18l17KKCM_fc4{!>^v=)1PYhCctL|x|j)fYC`osW0^i-6eo Li3ddolE3^P)2XN* literal 0 HcmV?d00001 diff --git a/applications/external/camera_suite/screenshots/main_menu.png b/applications/external/camera_suite/screenshots/main_menu.png new file mode 100644 index 0000000000000000000000000000000000000000..3ae802cc2d31175779a3914ea594a0390fe8809e GIT binary patch literal 1499 zcmeAS@N?(olHy`uVBq!ia0y~yU;;8388|?c*QZDWAjMhW5n0T@z;^_M8K-LVNi#68 z_IkQFhE&XXdpEFeikCz~;O#R-G4s0%YS$hAacik2JIk)d_j9(-{-SW$_nCL#-@}iu z_vgnm?3lj(etq4)nc{QU8Pru67y_9X1ipU!Bk%oAlJP@a_1n8qj0`TE3=UHm7+h@c z)iN>s*?+UH!IFVt84H7g7X!m0e3YHt{}WZ-^Fm{*zc*wv&FK||m;*HKN?tX?`R_ZX z-#H!k`=@r1Z-en>CWa0nh6W8rh7PL~zJ%_*`}FsJvz?j#W8S}M_p{69?6s@kmR;BO zKfa(e4B|{xAhrB9bH%nN|K7j(_x0BNyPw|6<-UDyy7}q%s_Ulri{>5JABk}N+$#PA z?(a?U=S|zQHzF+C^;YhH=zQkluiqJCKF(Qqh70bktnIc9y5|?nkNjQpbML(D{nPiZ zJ9+Ezo=e*6f6iRb95WHgH;?bCe^|b{UR>_M)NOC}B3TLzIamPJyq9|r^{wjOEF`@j z>=@2Ru)o-Va1t~aD5R?X{Q8*ty}9o1zt5M?%lv)6&i3E5`K&vXv>|~EG<`+?UcN2g z4&G3F#`@Yotgwyj_4oJ>mW=K$grlU)?4L8fbt$)<@oF{>gp`j6&hCp$Ddmd|v z>%PbQF%yC5hz*$FKrz{`{4QJn=e|F;zO(6Do{M|W9PxYeH?{`tO^9%@O5tZ{_-w$= zaKHg#_bEAGf0WN@5uLGjp0Z!vWcCcpcoj+5*(16eUq7?14;VU+qnlA=1fL1gQhVu dhzze|{_==S09OD2 literal 0 HcmV?d00001 diff --git a/applications/external/camera_suite/screenshots/settings.png b/applications/external/camera_suite/screenshots/settings.png new file mode 100644 index 0000000000000000000000000000000000000000..32de46d72a82b836a5cb4da71a8b5dee4f9166f3 GIT binary patch literal 1900 zcmaJ?eN<9s7=MZKYcpIso*DVkvK>8oI$2F;8feYUkENChMfs7_tb;XI9GyW1xm>mU z*m9H=qNbH8*;y?6Km%fnEa6%b99y84#gqiU@Tv&zvT$8@I{V|E_rCA@+~?!>Jip&P zz9}x!*$M9i0C0|uibw!p9`cF-4%Q`Rgc5)(j^9R6XaFqy-TGkI{tK4?VDA|nu|6rE zGpJr)`Xb0>K}UXvv~6<#G0sY@<247DiU38;*}5bJGbhmP=FV-+)8g|d=w`FlAjAwM z3oR2mAydfI&fLxj0MFt9II;+Unp7nKtIuHGZ03XT`l|waAlfzsz-|Y?+B6R={e_6E zS%@ie>x%&{FBoZVj{(@=h}?ZO1vI+Y$Si_k^WMfnf2ndbnGLy`&gQnJO}2`K z?KU&SmEt!di*I~MG42i&ACi+|Lz`snw>5?-&CP_ORXUW*m*ew7Oxt_-LS|Tq{JtCA zl9$Pegc#$u{HhvL25#|}3&;6%Vg|c}cYx<630-5$6aWX(H_koksFFQOP4KRnyt-G! zgwtM^SCE6ZIC7I<1LXw%5x?|$tw4z#!+;K#H&xX?&IbI~sh{;N_M7%RSVUo%!}>Yy zkL*FXqqTm-tLv|JLkjwH{UYj}$hW@kQcV+XI&e@4rdP`T^31{9sfPNOQt{QE*(qfu3GeslJG94XPv7 z<{s@t<#f@Aaeq>gMX|i7o*F5a0S!e0IRQm#Dpfk zyE>{TTBv#Js`z?|I1q(iy{eo_I~4Cc6pd<$p9&#NGAf#)7THYH{ZCt8FPJ|RPJpRF zNV~0Fw6aKs5095Quo$v|?$xN{f9ME#XbfABkdd<#w2jBRx70SmVa9kvoB$S?*7hG5 z^fna;y_kImIyK(JlH`Z}M2WYww|udU&4{bB&34twmeNrPo1FZRPn3kFzQ-2oP*b8f zNo09?3yTbs>ftVF`#_4@q-?~AK)`rwohLL=X>uxRCagT*(dk9>vHMfv9}6~TU5PJN zEb~|Rcd6Lfd)Q%(Pn6iXz5xRx3)D>)^U_7f`dV2Ul0b|D|qN&ta(4&<%v4hIa5Zu7{(zk+S<@Rg? z(%5i=T~8;EAVo)@g|RN_cj81oC{h^{VEg>$TGP67Z=?8T&n1>ZH4`?URf*O~WGXhG zl-5c`+$GeM#OkoY4XaArwY-bXxg){5q%B`_2pJW*-1Jl2?B2il1Eb89s4PggaXZK* zIk|f`uQ>TZsPg&~J$xSJjh%{(>gfEiBQcDWp*{iY%4yf+z3{z1UVv%`o0#~u+67#b z-e+f(&@#)aowSDym-jJq`bHrbJ@be-3KSM{cj9`&*y5H;<}dYwVjq;`G>qZH3%T2d zc;>=-2}1?ZMQA~ywjrt*k^*_cjb(hsU@koD^XG7D==Rgy!-2%(L;&zMi8Usi!{!H} q{64_Xm9m$I{(~2S?HsYRU@Cmq(bqmZDnx#tAo`2Ah^7rY3jYS@P22$h literal 0 HcmV?d00001 diff --git a/applications/external/camera_suite/screenshots/start_screen.png b/applications/external/camera_suite/screenshots/start_screen.png new file mode 100644 index 0000000000000000000000000000000000000000..6fe690c58414675c4fff5ef8552d1619c1ad7442 GIT binary patch literal 1707 zcmd5-ZA@EL7(N9Y4h81o7aNo%lW4+1hD2aMDJXJ*Et{V})iTD%uCWM=YT9z4m(4^s zMrjtNp#&~E{j<>yVnx289j4$YTuH{Q4B9#n3M=-)@DA5P>#ZzuuRr~xKW?6LbIy6+ z=Y5~&&AIT}aVRigUjP6gFf$|V4FG)TB?mm}g{*sm!!+zJ&k%?K2>QYMaXya>+7G}k zVP;zDThiv=%&Dcbu^?sg_UM_4!O$DFFjW}gB^?B4}EZ3mo{9VDcZ?{g}dCN2(DugUzi)Oxk5Z){;q?f$x zP?W&umaGvaf;D6`;WPlR`+z+WG~5SK9Zvb(O9N-05^YJOj`@yO$crTy z+3!_@;P2+#jyClmf9o24cd7RQHc%^Ba||_{DA=_fj*eO!{EI>(cZ`S4KIkilCO+=s zU5FWQaSaWPY^p>8skXWJQw`Yu^>18GC}|mX)*Au1;s*|7(NGnxQy44LH?hL{*)sW* z_*cl%=hQY)!ohd5>rhJT-sqR(h+yRL?c?;Vn_ODTkbfcPUkX$~LuL1;CP^h#z1P!7 zsfJYyGAo><*;=YtM4$;yRozO6?hvbo@g=y`zhwHI$Z#2n&8w41F65EV8AV4bqcA;_ zpl-OO$1q@PLyW|ZnQCOkuqu}@ABACjweEdu+Zr2A=XoVf{<6;s$q zt!qK#ifhJMJ4fr1PP&(njjHGMD*G}-TG6l>m8qf&SFAI zI^v-*XjmX=85m8V74Z$L=5DoVcwg~GLcOIL_u;j4y>2y*5}iLMR_%(}cBV;xE{v2!x(A{VPy5Tel(`2{<rJ}h= zgZML1|M0W#zsL>%k%6f2lf1P%y=4KiuG7! z#XFu^5TqOvf7DW0By<_Y`ZpOSoA%8gC2l(>k@cMR$+9r9s2MTDR45L%ceU!-^CLZa zP-I8ywXhi_EIQ1Ty8%DKGD$xV_c`Zb&-yFrj<@;iE>Oc~=WG(-ww{@u^ohqLr*~*l or@|U?99PkQuxC4-{YS-R{fMTn1YbTuzdj)I)#GW`U(P@GC%ZCr_5c6? literal 0 HcmV?d00001 From 0f9c6ba847f6550709bc4f75ad10222946950881 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 29 Jul 2023 03:51:46 +0300 Subject: [PATCH 05/44] Remake it more properly still has problems, need to rewrite subghz_devices tx/rx switch code, checking strcmp every time is not good too, but better than loading whole config from microsd --- .../scenes/subghz_scene_radio_settings.c | 14 +++-- .../main/subghz/subghz_dangerous_freq.c | 13 ++++ .../main/subghz/subghz_last_settings.c | 34 +++++----- firmware/targets/f7/api_symbols.csv | 2 + .../targets/f7/furi_hal/furi_hal_subghz.c | 11 +++- .../targets/f7/furi_hal/furi_hal_subghz.h | 5 ++ lib/subghz/devices/devices.c | 63 +++++++++---------- 7 files changed, 87 insertions(+), 55 deletions(-) diff --git a/applications/main/subghz/scenes/subghz_scene_radio_settings.c b/applications/main/subghz/scenes/subghz_scene_radio_settings.c index 598d6fdce0..2ff2f565fb 100644 --- a/applications/main/subghz/scenes/subghz_scene_radio_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_radio_settings.c @@ -124,6 +124,10 @@ static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem } subghz->last_settings->external_module_power_amp = index == 1; + + // Set globally in furi hal + furi_hal_subghz_set_ext_power_amp(subghz->last_settings->external_module_power_amp); + subghz_last_settings_save(subghz->last_settings); } @@ -159,9 +163,9 @@ void subghz_scene_radio_settings_on_enter(void* context) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, radio_device_text[value_index]); - item = variable_item_list_add( + item = variable_item_list_add( variable_item_list, - "Ext High Power", + "Ext Power Amp", EXT_MOD_POWER_AMP_COUNT, subghz_scene_reciever_config_set_ext_mod_power_amp_text, subghz); @@ -171,7 +175,7 @@ void subghz_scene_radio_settings_on_enter(void* context) { item = variable_item_list_add( variable_item_list, - "Time in names", + "Time In Names", TIMESTAMP_NAMES_COUNT, subghz_scene_receiver_config_set_timestamp_file_names, subghz); @@ -182,7 +186,7 @@ void subghz_scene_radio_settings_on_enter(void* context) { if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { item = variable_item_list_add( variable_item_list, - "Counter incr.", + "Counter Incr.", DEBUG_COUNTER_COUNT, subghz_scene_receiver_config_set_debug_counter, subghz); @@ -211,7 +215,7 @@ void subghz_scene_radio_settings_on_enter(void* context) { } else { item = variable_item_list_add( variable_item_list, - "Counter incr.", + "Counter Incr.", 3, subghz_scene_receiver_config_set_debug_counter, subghz); diff --git a/applications/main/subghz/subghz_dangerous_freq.c b/applications/main/subghz/subghz_dangerous_freq.c index 69a54f04bc..8552c5f164 100644 --- a/applications/main/subghz/subghz_dangerous_freq.c +++ b/applications/main/subghz/subghz_dangerous_freq.c @@ -5,6 +5,8 @@ #include +#include + void subghz_dangerous_freq() { bool is_extended_i = false; @@ -19,5 +21,16 @@ void subghz_dangerous_freq() { furi_hal_subghz_set_dangerous_frequency(is_extended_i); flipper_format_free(fff_data_file); + + // Load external module power amp setting (TODO: move to other place) + // TODO: Disable this when external module is not CC1101 E07 + SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); + subghz_last_settings_load(last_settings, 0); + + // Set globally in furi hal + furi_hal_subghz_set_ext_power_amp(last_settings->external_module_power_amp); + + subghz_last_settings_free(last_settings); + furi_record_close(RECORD_STORAGE); } diff --git a/applications/main/subghz/subghz_last_settings.c b/applications/main/subghz/subghz_last_settings.c index 5f67fc7802..465312b197 100644 --- a/applications/main/subghz/subghz_last_settings.c +++ b/applications/main/subghz/subghz_last_settings.c @@ -19,8 +19,8 @@ #define SUBGHZ_LAST_SETTING_FIELD_FREQUENCY_ANALYZER_TRIGGER "FATrigger" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_ENABLED "External" #define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER "ExtPower" -#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp" #define SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES "TimestampNames" +#define SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP "ExtPowerAmp" SubGhzLastSettings* subghz_last_settings_alloc(void) { SubGhzLastSettings* instance = malloc(sizeof(SubGhzLastSettings)); @@ -47,7 +47,7 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count float temp_frequency_analyzer_trigger = 0; bool temp_external_module_enabled = false; bool temp_external_module_power_5v_disable = false; - bool temp_external_module_power_amp = false; + bool temp_external_module_power_amp = false; bool temp_timestamp_file_names = false; //int32_t temp_preset = 0; bool frequency_analyzer_feedback_level_was_read = false; @@ -79,17 +79,17 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count fff_data_file, SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER, (bool*)&temp_external_module_power_5v_disable, - 1); - flipper_format_read_bool( - fff_data_file, - SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, - (bool*)&temp_external_module_power_amp, 1); flipper_format_read_bool( fff_data_file, SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES, (bool*)&temp_timestamp_file_names, 1); + flipper_format_read_bool( + fff_data_file, + SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, + (bool*)&temp_external_module_power_amp, + 1); } else { FURI_LOG_E(TAG, "Error open file %s", SUBGHZ_LAST_SETTINGS_PATH); @@ -103,8 +103,8 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_FEEDBACK_LEVEL; instance->frequency_analyzer_trigger = SUBGHZ_LAST_SETTING_FREQUENCY_ANALYZER_TRIGGER; instance->external_module_enabled = false; - instance->external_module_power_amp = false; instance->timestamp_file_names = false; + instance->external_module_power_amp = false; } else { instance->frequency = temp_frequency; @@ -126,9 +126,13 @@ void subghz_last_settings_load(SubGhzLastSettings* instance, size_t preset_count instance->external_module_power_5v_disable = temp_external_module_power_5v_disable; instance->timestamp_file_names = temp_timestamp_file_names; - + + // External power amp CC1101 instance->external_module_power_amp = temp_external_module_power_amp; - + + // Set globally in furi hal + furi_hal_subghz_set_ext_power_amp(instance->external_module_power_amp); + /*/} else { instance->preset = temp_preset; }*/ @@ -199,17 +203,17 @@ bool subghz_last_settings_save(SubGhzLastSettings* instance) { 1)) { break; } - if(!flipper_format_insert_or_update_bool( + if(!flipper_format_insert_or_update_bool( file, - SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, - &instance->external_module_power_amp, + SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES, + &instance->timestamp_file_names, 1)) { break; } if(!flipper_format_insert_or_update_bool( file, - SUBGHZ_LAST_SETTING_FIELD_TIMESTAMP_FILE_NAMES, - &instance->timestamp_file_names, + SUBGHZ_LAST_SETTING_FIELD_EXTERNAL_MODULE_POWER_AMP, + &instance->external_module_power_amp, 1)) { break; } diff --git a/firmware/targets/f7/api_symbols.csv b/firmware/targets/f7/api_symbols.csv index 81cae40134..a6807e131a 100644 --- a/firmware/targets/f7/api_symbols.csv +++ b/firmware/targets/f7/api_symbols.csv @@ -1401,6 +1401,7 @@ Function,-,furi_hal_subghz_dump_state,void, Function,+,furi_hal_subghz_flush_rx,void, Function,+,furi_hal_subghz_flush_tx,void, Function,+,furi_hal_subghz_get_data_gpio,const GpioPin*, +Function,+,furi_hal_subghz_get_ext_power_amp,_Bool, Function,+,furi_hal_subghz_get_lqi,uint8_t, Function,+,furi_hal_subghz_get_rolling_counter_mult,uint8_t, Function,+,furi_hal_subghz_get_rssi,float, @@ -1418,6 +1419,7 @@ Function,+,furi_hal_subghz_reset,void, Function,+,furi_hal_subghz_rx,void, Function,+,furi_hal_subghz_rx_pipe_not_empty,_Bool, Function,+,furi_hal_subghz_set_async_mirror_pin,void,const GpioPin* +Function,+,furi_hal_subghz_set_ext_power_amp,void,_Bool Function,+,furi_hal_subghz_set_frequency,uint32_t,uint32_t Function,+,furi_hal_subghz_set_frequency_and_path,uint32_t,uint32_t Function,+,furi_hal_subghz_set_path,void,FuriHalSubGhzPath diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.c b/firmware/targets/f7/furi_hal/furi_hal_subghz.c index 936d685fe2..b651fc59fc 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.c +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.c @@ -53,7 +53,7 @@ typedef struct { const GpioPin* async_mirror_pin; uint8_t rolling_counter_mult; - bool timestamp_file_names : 1; + bool ext_power_amp : 1; bool dangerous_frequency_i : 1; } FuriHalSubGhz; @@ -62,6 +62,7 @@ volatile FuriHalSubGhz furi_hal_subghz = { .regulation = SubGhzRegulationTxRx, .async_mirror_pin = NULL, .rolling_counter_mult = 1, + .ext_power_amp = false, .dangerous_frequency_i = false, }; @@ -77,6 +78,14 @@ void furi_hal_subghz_set_dangerous_frequency(bool state_i) { furi_hal_subghz.dangerous_frequency_i = state_i; } +void furi_hal_subghz_set_ext_power_amp(bool enabled) { + furi_hal_subghz.ext_power_amp = enabled; +} + +bool furi_hal_subghz_get_ext_power_amp() { + return furi_hal_subghz.ext_power_amp; +} + void furi_hal_subghz_set_async_mirror_pin(const GpioPin* pin) { furi_hal_subghz.async_mirror_pin = pin; } diff --git a/firmware/targets/f7/furi_hal/furi_hal_subghz.h b/firmware/targets/f7/furi_hal/furi_hal_subghz.h index c7249e1a6a..b390ac6cc4 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_subghz.h +++ b/firmware/targets/f7/furi_hal/furi_hal_subghz.h @@ -282,6 +282,11 @@ void furi_hal_subghz_stop_async_tx(); // */ // void furi_hal_subghz_select_radio_type(SubGhzRadioType state); +// External CC1101 Ebytes power amplifier control +void furi_hal_subghz_set_ext_power_amp(bool enabled); + +bool furi_hal_subghz_get_ext_power_amp(); + #ifdef __cplusplus } #endif diff --git a/lib/subghz/devices/devices.c b/lib/subghz/devices/devices.c index 525c38323f..98cb0f6091 100644 --- a/lib/subghz/devices/devices.c +++ b/lib/subghz/devices/devices.c @@ -2,34 +2,14 @@ #include "registry.h" -#include - void subghz_devices_init() { furi_check(!subghz_device_registry_is_valid()); subghz_device_registry_init(); - - SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); - subghz_last_settings_load(last_settings, 0); - - if(last_settings->external_module_power_amp) { - furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); - } - - subghz_last_settings_free(last_settings); } void subghz_devices_deinit(void) { furi_check(subghz_device_registry_is_valid()); subghz_device_registry_deinit(); - - SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); - subghz_last_settings_load(last_settings, 0); - - if(last_settings->external_module_power_amp) { - furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); - } - - subghz_last_settings_free(last_settings); } const SubGhzDevice* subghz_devices_get_by_name(const char* device_name) { @@ -50,6 +30,13 @@ bool subghz_devices_begin(const SubGhzDevice* device) { bool ret = false; furi_assert(device); if(device->interconnect->begin) { + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); + } + } + ret = device->interconnect->begin(); } return ret; @@ -58,6 +45,12 @@ bool subghz_devices_begin(const SubGhzDevice* device) { void subghz_devices_end(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->end) { + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); + } + } device->interconnect->end(); } } @@ -89,7 +82,12 @@ void subghz_devices_idle(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->idle) { device->interconnect->idle(); - furi_hal_gpio_write(&gpio_ext_pc3, 0); + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_write(&gpio_ext_pc3, 0); + } + } } } @@ -143,14 +141,12 @@ bool subghz_devices_set_tx(const SubGhzDevice* device) { if(device->interconnect->set_tx) { ret = device->interconnect->set_tx(); - SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); - subghz_last_settings_load(last_settings, 0); - - if(last_settings->external_module_power_amp) { - furi_hal_gpio_write(&gpio_ext_pc3, 1); + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_write(&gpio_ext_pc3, 1); + } } - - subghz_last_settings_free(last_settings); } return ret; } @@ -191,14 +187,13 @@ void subghz_devices_set_rx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_rx) { device->interconnect->set_rx(); - SubGhzLastSettings* last_settings = subghz_last_settings_alloc(); - subghz_last_settings_load(last_settings, 0); - if(last_settings->external_module_power_amp) { - furi_hal_gpio_write(&gpio_ext_pc3, 0); + // TODO: Remake this check and move this code + if(strcmp("cc1101_ext", device->name) == 0) { + if(furi_hal_subghz_get_ext_power_amp()) { + furi_hal_gpio_write(&gpio_ext_pc3, 0); + } } - - subghz_last_settings_free(last_settings); } } From 2c656f9c49ac69a125353e45a8b0110500ea2a9a Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 29 Jul 2023 05:21:58 +0300 Subject: [PATCH 06/44] Update wifi marauder --- .../wifi_marauder_companion/ReadMe.md | 25 +- .../wifi_marauder_companion/application.fam | 18 +- .../wifi_marauder_companion/docs/changelog.md | 7 + .../lib/esp-serial-flasher/LICENSE | 202 --------- .../lib/esp-serial-flasher/README.md | 154 ------- .../esp-serial-flasher/include/esp_loader.h | 313 ------------- .../include/esp_loader_io.h | 112 ----- .../esp-serial-flasher/include/serial_io.h | 24 - .../lib/esp-serial-flasher/port/esp32_port.c | 181 -------- .../lib/esp-serial-flasher/port/esp32_port.h | 59 --- .../esp-serial-flasher/port/esp32_spi_port.c | 298 ------------- .../esp-serial-flasher/port/esp32_spi_port.h | 60 --- .../esp-serial-flasher/port/raspberry_port.c | 302 ------------- .../esp-serial-flasher/port/raspberry_port.h | 36 -- .../lib/esp-serial-flasher/port/stm32_port.c | 140 ------ .../lib/esp-serial-flasher/port/stm32_port.h | 38 -- .../lib/esp-serial-flasher/port/zephyr_port.c | 170 ------- .../lib/esp-serial-flasher/port/zephyr_port.h | 39 -- .../private_include/esp_targets.h | 33 -- .../private_include/md5_hash.h | 28 -- .../private_include/protocol.h | 230 ---------- .../private_include/protocol_prv.h | 31 -- .../esp-serial-flasher/private_include/slip.h | 28 -- .../lib/esp-serial-flasher/src/esp_loader.c | 415 ------------------ .../lib/esp-serial-flasher/src/esp_targets.c | 263 ----------- .../lib/esp-serial-flasher/src/md5_hash.c | 262 ----------- .../esp-serial-flasher/src/protocol_common.c | 301 ------------- .../lib/esp-serial-flasher/src/protocol_spi.c | 312 ------------- .../esp-serial-flasher/src/protocol_uart.c | 114 ----- .../lib/esp-serial-flasher/src/slip.c | 125 ------ .../esp-serial-flasher/zephyr/CMakeLists.txt | 30 -- .../lib/esp-serial-flasher/zephyr/Kconfig | 16 - .../lib/esp-serial-flasher/zephyr/module.yml | 5 - .../scenes/wifi_marauder_scene_config.h | 1 - .../wifi_marauder_scene_console_output.c | 28 +- .../scenes/wifi_marauder_scene_flasher.c | 266 ----------- .../scenes/wifi_marauder_scene_start.c | 38 +- .../scenes/wifi_marauder_scene_text_input.c | 4 +- .../screenshots/marauder-save-pcaps.png | Bin 0 -> 2336 bytes .../screenshots/marauder-script-demo.png | Bin 0 -> 1599 bytes .../screenshots/marauder-topmenu.png | Bin 0 -> 1752 bytes .../wifi_marauder_app.c | 3 - .../wifi_marauder_app.h | 2 +- .../wifi_marauder_app_i.h | 26 +- .../wifi_marauder_custom_event.h | 4 +- .../wifi_marauder_flasher.c | 251 ----------- .../wifi_marauder_flasher.h | 17 - .../wifi_marauder_pcap.c | 64 --- .../wifi_marauder_pcap.h | 20 - 49 files changed, 37 insertions(+), 5058 deletions(-) delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/LICENSE delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/README.md delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader_io.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/serial_io.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/esp_targets.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/md5_hash.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol_prv.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/slip.h delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_loader.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_targets.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/md5_hash.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_common.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_spi.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_uart.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/slip.c delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/CMakeLists.txt delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/Kconfig delete mode 100644 applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/module.yml delete mode 100644 applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_flasher.c create mode 100755 applications/external/wifi_marauder_companion/screenshots/marauder-save-pcaps.png create mode 100755 applications/external/wifi_marauder_companion/screenshots/marauder-script-demo.png create mode 100755 applications/external/wifi_marauder_companion/screenshots/marauder-topmenu.png delete mode 100644 applications/external/wifi_marauder_companion/wifi_marauder_flasher.c delete mode 100644 applications/external/wifi_marauder_companion/wifi_marauder_flasher.h delete mode 100644 applications/external/wifi_marauder_companion/wifi_marauder_pcap.c delete mode 100644 applications/external/wifi_marauder_companion/wifi_marauder_pcap.h diff --git a/applications/external/wifi_marauder_companion/ReadMe.md b/applications/external/wifi_marauder_companion/ReadMe.md index bc14e0f8c4..00de704243 100644 --- a/applications/external/wifi_marauder_companion/ReadMe.md +++ b/applications/external/wifi_marauder_companion/ReadMe.md @@ -1,8 +1,10 @@ +[![FAP Build](https://github.com/0xchocolate/flipperzero-wifi-marauder/actions/workflows/build.yml/badge.svg)](https://github.com/0xchocolate/flipperzero-wifi-marauder/actions/workflows/build.yml) + # WiFi Marauder companion app for Flipper Zero Requires a connected dev board running Marauder FW. [See install instructions from UberGuidoZ here.](https://github.com/UberGuidoZ/Flipper/tree/main/Wifi_DevBoard#marauder-install-information) -## https://github.com/0xchocolate/flipperzero-wifi-marauder + ## Get the app 1. Make sure you're logged in with a github account (otherwise the downloads in step 2 won't work) @@ -15,27 +17,8 @@ Requires a connected dev board running Marauder FW. [See install instructions fr From a local clone of this repo, you can also build the app yourself using ufbt. -## In-app ESP32 flasher (WIP) -Guide by [@francis2054](https://github.com/francis2054) - -The app now contains a work-in-progress of an ESP32 flasher (close to the bottom of the marauder menu). Use at your own risk. This hardcodes addresses for non-S3 ESP32 chips. - -To use this method: -1. Make sure you follow the instructions for how to get the Marauder app on your Flipper Zero, they can be found on the top of this page. Latest release needs to be downloaded and installed. -2. Go to [Justcallmekoko's firmware page](https://github.com/justcallmekoko/ESP32Marauder/wiki/update-firmware#using-spacehuhn-web-updater) and download all files necessary for the board you are flashing, most boards will want all 4 files but for the Wifi Devboard you want to download these 3 files: `0x1000` (Bootloader), `0x8000` (partitions), `0x10000` (Firmware). The `Boot App` is not needed for the Wifi Devboard with this method. The Firmware one will redirect you to the releases page where you'll need to pick the one relevant to the board you're flashing, if you are using the official Wi-Fi Devboard you want to pick the one ending in `_flipper_sd_serial.bin`. -3. Place all files downloaded in step 2 in a new folder on your desktop, the name does not matter. Rename the `_flipper_sd_serial.bin` file you downloaded in step 2 to `Firmware.bin`. -4. Now for transferring the files to the Flipper Zero, drag all the files from the folder on your desktop to the "Marauder" folder inside "apps_data" folder on the Flipper Zero SD card. Preferred method to transfer these files is plugging the SD card into your computer with an adapter, but qFlipper works as well. Insert the Flipper Zero SD Card back into the Flipper before proceeding to the next step. -5. Plug your Wi-Fi Devboard into the Flipper. -6. Press and keep holding the boot button while you press the reset button once, release the boot button after 2 seconds. -7. Open the Marauder app on your Flipper Zero, it should be named "esp32_wifi_marauder" and be located under Apps->GPIO from the main menu if you followed the instructions for how to install the app further up on this page. (You might get an API mismatch error if the Flipper firmware you are running doesn't match the files you've downloaded, you can try "Continue" anyway, otherwise the app needs to be rebuilt or you might need to update the firmware on your Flipper). -8. Press the up arrow on the Flipper three times to get to "Reflash ESP32 (WIP)" and open it. -9. For "Bootloader" scroll down in the list and select `esp32_marauder.ino.bootloader.bin`, for "Paritition table" select `esp32_marauder.ino.partitions.bin` and for "Firmware" select `Firmware.bin`. -10. Scroll down and click "[>] FLASH" and wait for it to complete. (If you get errors here, press back button once and repeat step 6 then try "[>] FLASH" again). -11. Once it says "Done flashing" on the screen, restart the Flipper and you are done :) - -## For future updates, just repeat from step 2 and only download the new "Firmware" bin +### FYI - the ESP flasher is now its own app: https://github.com/0xchocolate/flipperzero-esp-flasher -This process will improve with future updates! :) ## Support diff --git a/applications/external/wifi_marauder_companion/application.fam b/applications/external/wifi_marauder_companion/application.fam index 6b3403f39a..ee4578efca 100644 --- a/applications/external/wifi_marauder_companion/application.fam +++ b/applications/external/wifi_marauder_companion/application.fam @@ -1,6 +1,7 @@ App( appid="esp32_wifi_marauder", name="[ESP32] WiFi Marauder", + fap_version=(6,0), apptype=FlipperAppType.EXTERNAL, entry_point="wifi_marauder_app", requires=["gui"], @@ -8,22 +9,5 @@ App( order=90, fap_icon="wifi_10px.png", fap_category="GPIO", - fap_private_libs=[ - Lib( - name="esp-serial-flasher", - fap_include_paths=["include"], - sources=[ - "src/esp_loader.c", - "src/esp_targets.c", - "src/md5_hash.c", - "src/protocol_common.c", - "src/protocol_uart.c", - "src/slip.c" - ], - cincludes=["lib/esp-serial-flasher/private_include"], - cdefines=["SERIAL_FLASHER_INTERFACE_UART=1", "MD5_ENABLED=1"], - ), - ], - cdefines=["SERIAL_FLASHER_INTERFACE_UART=1"], fap_icon_assets="assets", ) diff --git a/applications/external/wifi_marauder_companion/docs/changelog.md b/applications/external/wifi_marauder_companion/docs/changelog.md index ae0f328e7c..207478f71e 100644 --- a/applications/external/wifi_marauder_companion/docs/changelog.md +++ b/applications/external/wifi_marauder_companion/docs/changelog.md @@ -1,3 +1,10 @@ +## v0.6.0 + +Evil Portal and LED control! Thanks @justcallmekoko for adding the commands! See Evil Portal workflow here: https://github.com/justcallmekoko/ESP32Marauder/wiki/evil-portal-workflow + +This version also removes the in-app ESP flasher, but don't worry! It's grown up into its own app, where development will continue separately: https://github.com/0xchocolate/flipperzero-esp-flasher + + ## v0.4.0 Added Signal Monitor (thanks @justcallmekoko!) to support new sigmon command in Marauder v0.10.5: https://github.com/justcallmekoko/ESP32Marauder/releases diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/LICENSE b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/LICENSE deleted file mode 100644 index d645695673..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/LICENSE +++ /dev/null @@ -1,202 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS - - APPENDIX: How to apply the Apache License to your work. - - To apply the Apache License to your work, attach the following - boilerplate notice, with the fields enclosed by brackets "[]" - replaced with your own identifying information. (Don't include - the brackets!) The text should be enclosed in the appropriate - comment syntax for the file format. We also recommend that a - file or class name and description of purpose be included on the - same "printed page" as the copyright notice for easier - identification within third-party archives. - - Copyright [yyyy] [name of copyright owner] - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/README.md b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/README.md deleted file mode 100644 index b1ae448d77..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/README.md +++ /dev/null @@ -1,154 +0,0 @@ -# esp-serial-flasher - -`esp-serial-flasher` is a portable C library for flashing or loading apps to RAM of Espressif SoCs from other host microcontrollers. - -## Using the library -Espressif SoCs are normally programmed via serial interface (UART). The port layer for the given host microcontroller has to be implemented if not available. Details can be found in section below. - -Supported **host** microcontrollers: - -- STM32 -- Raspberry Pi SBC -- ESP32 -- Any MCU running Zephyr OS - -Supported **target** microcontrollers: - -- ESP32 -- ESP8266 -- ESP32-S2 -- ESP32-S3 -- ESP32-C3 -- ESP32-C2 -- ESP32-H2 - -Supported hardware interfaces: -- UART -- SPI (only for RAM download, experimental) - -For example usage check the `examples` directory. - -## Supporting a new host target - -In order to support a new target, following functions have to be implemented by user: - -- `loader_port_read()` -- `loader_port_write()` -- `loader_port_enter_bootloader()` -- `loader_port_delay_ms()` -- `loader_port_start_timer()` -- `loader_port_remaining_time()` - -For the SPI interface ports -- `loader_port_spi_set_cs()` -needs to be implemented as well. - -The following functions are part of the [io.h](include/io.h) header for convenience, however, the user does not have to strictly follow function signatures, as there are not called directly from library. - -- `loader_port_change_transmission_rate()` -- `loader_port_reset_target()` -- `loader_port_debug_print()` - -Prototypes of all functions mentioned above can be found in [io.h](include/io.h). - -## Configuration - -These are the configuration toggles available to the user: - -* `SERIAL_FLASHER_INTERFACE_UART/SERIAL_FLASHER_INTERFACE_SPI` - -This defines the hardware interface to use. SPI interface only supports RAM download mode and is in experimental stage and can undergo changes. - -Default: SERIAL_FLASHER_INTERFACE_UART - -* `MD5_ENABLED` - -If enabled, `esp-serial-flasher` is capable of verifying flash integrity after writing to flash. - -Default: Enabled -> Warning: As ROM bootloader of the ESP8266 does not support MD5_CHECK, this option has to be disabled! - -* `SERIAL_FLASHER_RESET_HOLD_TIME_MS` - -This is the time for which the reset pin is asserted when doing a hard reset in milliseconds. - -Default: 100 - -* `SERIAL_FLASHER_BOOT_HOLD_TIME_MS` - -This is the time for which the boot pin is asserted when doing a hard reset in milliseconds. - -Default: 50 - -Configuration can be passed to `cmake` via command line: - -``` -cmake -DMD5_ENABLED=1 .. && cmake --build . -``` - -### STM32 support - -The STM32 port makes use of STM32 HAL libraries, and these do not come with CMake support. In order to compile the project, `stm32-cmake` (a `CMake` support package) has to be pulled as submodule. - -``` -git clone --recursive https://github.com/espressif/esp-serial-flasher.git -``` - -If you have cloned this repository without the `--recursive` flag, you can initialize the submodule using the following command: - -``` -git submodule update --init -``` - -In addition to configuration parameters mentioned above, following definitions has to be set: - -- TOOLCHAIN_PREFIX: path to arm toolchain (i.e /home/user/gcc-arm-none-eabi-9-2019-q4-major) -- STM32Cube_DIR: path to STM32 Cube libraries (i.e /home/user/STM32Cube/Repository/STM32Cube_FW_F4_V1.25.0) -- STM32_CHIP: name of STM32 for which project should be compiled (i.e STM32F407VG) -- PORT: STM32 - -This can be achieved by passing definitions to the command line, such as: - -``` -cmake -DTOOLCHAIN_PREFIX="/path_to_toolchain" -DSTM32Cube_DIR="path_to_stm32Cube" -DSTM32_CHIP="STM32F407VG" -DPORT="STM32" .. && cmake --build . -``` - -Alternatively, those variables can be set in the top level `cmake` directory: - -``` -set(TOOLCHAIN_PREFIX path_to_toolchain) -set(STM32Cube_DIR path_to_stm32_HAL) -set(STM32_CHIP STM32F407VG) -set(PORT STM32) -``` - -### Zephyr support - -The Zephyr port is ready to be integrated into Zephyr apps as a Zephyr module. In the manifest file (west.yml), add: - -``` - - name: esp-flasher - url: https://github.com/espressif/esp-serial-flasher - revision: master - path: modules/lib/esp_flasher -``` - -And add - -``` -CONFIG_ESP_SERIAL_FLASHER=y -CONFIG_CONSOLE_GETCHAR=y -CONFIG_SERIAL_FLASHER_MD5_ENABLED=y -``` - -to the project configuration `prj.conf`. - -For the C/C++ source code, the example code provided in `examples/zephyr_example` can be used as a starting point. - -## Licence - -Code is distributed under Apache 2.0 license. - -## Known limitations - -Size of new binary image has to be known before flashing. diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader.h deleted file mode 100644 index 43f4fb9d96..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader.h +++ /dev/null @@ -1,313 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Used for backwards compatibility with the previous API */ -#define esp_loader_change_baudrate esp_loader_change_transmission_rate - -/** - * Macro which can be used to check the error code, - * and return in case the code is not ESP_LOADER_SUCCESS. - */ -#define RETURN_ON_ERROR(x) do { \ - esp_loader_error_t _err_ = (x); \ - if (_err_ != ESP_LOADER_SUCCESS) { \ - return _err_; \ - } \ -} while(0) - -/** - * @brief Error codes - */ -typedef enum { - ESP_LOADER_SUCCESS, /*!< Success */ - ESP_LOADER_ERROR_FAIL, /*!< Unspecified error */ - ESP_LOADER_ERROR_TIMEOUT, /*!< Timeout elapsed */ - ESP_LOADER_ERROR_IMAGE_SIZE, /*!< Image size to flash is larger than flash size */ - ESP_LOADER_ERROR_INVALID_MD5, /*!< Computed and received MD5 does not match */ - ESP_LOADER_ERROR_INVALID_PARAM, /*!< Invalid parameter passed to function */ - ESP_LOADER_ERROR_INVALID_TARGET, /*!< Connected target is invalid */ - ESP_LOADER_ERROR_UNSUPPORTED_CHIP, /*!< Attached chip is not supported */ - ESP_LOADER_ERROR_UNSUPPORTED_FUNC, /*!< Function is not supported on attached target */ - ESP_LOADER_ERROR_INVALID_RESPONSE /*!< Internal error */ -} esp_loader_error_t; - -/** - * @brief Supported targets - */ -typedef enum { - ESP8266_CHIP = 0, - ESP32_CHIP = 1, - ESP32S2_CHIP = 2, - ESP32C3_CHIP = 3, - ESP32S3_CHIP = 4, - ESP32C2_CHIP = 5, - ESP32H4_CHIP = 6, - ESP32H2_CHIP = 7, - ESP_MAX_CHIP = 8, - ESP_UNKNOWN_CHIP = 8 -} target_chip_t; - -/** - * @brief Application binary header - */ -typedef struct { - uint8_t magic; - uint8_t segments; - uint8_t flash_mode; - uint8_t flash_size_freq; - uint32_t entrypoint; -} esp_loader_bin_header_t; - -/** - * @brief Segment binary header - */ -typedef struct { - uint32_t addr; - uint32_t size; - uint8_t *data; -} esp_loader_bin_segment_t; - -/** - * @brief SPI pin configuration arguments - */ -typedef union { - struct { - uint32_t pin_clk: 6; - uint32_t pin_q: 6; - uint32_t pin_d: 6; - uint32_t pin_cs: 6; - uint32_t pin_hd: 6; - uint32_t zero: 2; - }; - uint32_t val; -} esp_loader_spi_config_t; - -/** - * @brief Connection arguments - */ -typedef struct { - uint32_t sync_timeout; /*!< Maximum time to wait for response from serial interface. */ - int32_t trials; /*!< Number of trials to connect to target. If greater than 1, - 100 millisecond delay is inserted after each try. */ -} esp_loader_connect_args_t; - -#define ESP_LOADER_CONNECT_DEFAULT() { \ - .sync_timeout = 100, \ - .trials = 10, \ -} - -/** - * @brief Connects to the target - * - * @param connect_args[in] Timing parameters to be used for connecting to target. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_connect(esp_loader_connect_args_t *connect_args); - -/** - * @brief Returns attached target chip. - * - * @warning This function can only be called after connection with target - * has been successfully established by calling esp_loader_connect(). - * - * @return One of target_chip_t - */ -target_chip_t esp_loader_get_target(void); - - -#ifdef SERIAL_FLASHER_INTERFACE_UART -/** - * @brief Initiates flash operation - * - * @param offset[in] Address from which flash operation will be performed. - * @param image_size[in] Size of the whole binary to be loaded into flash. - * @param block_size[in] Size of buffer used in subsequent calls to esp_loader_flash_write. - * - * @note image_size is size of the whole image, whereas, block_size is chunk of data sent - * to the target, each time esp_loader_flash_write function is called. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_flash_start(uint32_t offset, uint32_t image_size, uint32_t block_size); - -/** - * @brief Writes supplied data to target's flash memory. - * - * @param payload[in] Data to be flashed into target's memory. - * @param size[in] Size of payload in bytes. - * - * @note size must not be greater that block_size supplied to previously called - * esp_loader_flash_start function. If size is less than block_size, - * remaining bytes of payload buffer will be padded with 0xff. - * Therefore, size of payload buffer has to be equal or greater than block_size. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_flash_write(void *payload, uint32_t size); - -/** - * @brief Ends flash operation. - * - * @param reboot[in] reboot the target if true. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_flash_finish(bool reboot); -#endif /* SERIAL_FLASHER_INTERFACE_UART */ - - -/** - * @brief Initiates mem operation, initiates loading for program into target RAM - * - * @param offset[in] Address from which mem operation will be performed. - * @param size[in] Size of the whole binary to be loaded into mem. - * @param block_size[in] Size of buffer used in subsequent calls to esp_loader_mem_write. - * - * @note image_size is size of the whole image, whereas, block_size is chunk of data sent - * to the target, each time esp_mem_flash_write function is called. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_mem_start(uint32_t offset, uint32_t size, uint32_t block_size); - - -/** - * @brief Writes supplied data to target's mem memory. - * - * @param payload[in] Data to be loaded into target's memory. - * @param size[in] Size of data in bytes. - * - * @note size must not be greater that block_size supplied to previously called - * esp_loader_mem_start function. - * Therefore, size of data buffer has to be equal or greater than block_size. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_mem_write(const void *payload, uint32_t size); - - -/** - * @brief Ends mem operation, finish loading for program into target RAM - * and send the entrypoint of ram_loadable app - * - * @param entrypoint[in] entrypoint of ram program. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_mem_finish(uint32_t entrypoint); - - -/** - * @brief Writes register. - * - * @param address[in] Address of register. - * @param reg_value[in] New register value. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_write_register(uint32_t address, uint32_t reg_value); - -/** - * @brief Reads register. - * - * @param address[in] Address of register. - * @param reg_value[out] Register value. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - */ -esp_loader_error_t esp_loader_read_register(uint32_t address, uint32_t *reg_value); - -/** - * @brief Change baud rate. - * - * @note Baud rate has to be also adjusted accordingly on host MCU, as - * target's baud rate is changed upon return from this function. - * - * @param transmission_rate[in] new baud rate to be set. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - * - ESP_LOADER_ERROR_UNSUPPORTED_FUNC Unsupported on the target - */ -esp_loader_error_t esp_loader_change_transmission_rate(uint32_t transmission_rate); - -/** - * @brief Verify target's flash integrity by checking MD5. - * MD5 checksum is computed from data pushed to target's memory by calling - * esp_loader_flash_write() function and compared against target's MD5. - * Target computes checksum based on offset and image_size passed to - * esp_loader_flash_start() function. - * - * @note This function is only available if MD5_ENABLED is set. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_INVALID_MD5 MD5 does not match - * - ESP_LOADER_ERROR_TIMEOUT Timeout - * - ESP_LOADER_ERROR_INVALID_RESPONSE Internal error - * - ESP_LOADER_ERROR_UNSUPPORTED_FUNC Unsupported on the target - */ -#if MD5_ENABLED -esp_loader_error_t esp_loader_flash_verify(void); -#endif -/** - * @brief Toggles reset pin. - */ -void esp_loader_reset_target(void); - - - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader_io.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader_io.h deleted file mode 100644 index 2ff99b4f9e..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/esp_loader_io.h +++ /dev/null @@ -1,112 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - #pragma once - -#include -#include "esp_loader.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** - * @brief Changes the transmission rate of the used peripheral. - */ -esp_loader_error_t loader_port_change_transmission_rate(uint32_t transmission_rate); - -/** - * @brief Writes data over the io interface. - * - * @param data[in] Buffer with data to be written. - * @param size[in] Size of data in bytes. - * @param timeout[in] Timeout in milliseconds. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout elapsed - */ -esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout); - -/** - * @brief Reads data from the io interface. - * - * @param data[out] Buffer into which received data will be written. - * @param size[in] Number of bytes to read. - * @param timeout[in] Timeout in milliseconds. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_TIMEOUT Timeout elapsed - */ -esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout); - -/** - * @brief Delay in milliseconds. - * - * @param ms[in] Number of milliseconds. - * - */ -void loader_port_delay_ms(uint32_t ms); - -/** - * @brief Starts timeout timer. - * - * @param ms[in] Number of milliseconds. - * - */ -void loader_port_start_timer(uint32_t ms); - -/** - * @brief Returns remaining time since timer was started by calling esp_loader_start_timer. - * 0 if timer has elapsed. - * - * @return Number of milliseconds. - * - */ -uint32_t loader_port_remaining_time(void); - -/** - * @brief Asserts bootstrap pins to enter boot mode and toggles reset pin. - * - * @note Reset pin should stay asserted for at least 20 milliseconds. - */ -void loader_port_enter_bootloader(void); - -/** - * @brief Toggles reset pin. - * - * @note Reset pin should stay asserted for at least 20 milliseconds. - */ -void loader_port_reset_target(void); - -/** - * @brief Function can be defined by user to print debug message. - * - * @note Empty weak function is used, otherwise. - * - */ -void loader_port_debug_print(const char *str); - -#ifdef SERIAL_FLASHER_INTERFACE_SPI -/** - * @brief Sets the chip select to a defined level - */ -void loader_port_spi_set_cs(uint32_t level); -#endif /* SERIAL_FLASHER_INTERFACE_SPI */ - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/serial_io.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/serial_io.h deleted file mode 100644 index e349393008..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/include/serial_io.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#warning Please replace serial_io.h with esp_loader_io.h and change the function names \ - to match the new API - -/* Defines used to avoid breaking existing ports */ -#define loader_port_change_baudrate loader_port_change_transmission_rate -#define loader_port_serial_write loader_port_write -#define loader_port_serial_read loader_port_read - -#include "esp_loader_io.h" diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.c deleted file mode 100644 index a6c8687c6a..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.c +++ /dev/null @@ -1,181 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "esp32_port.h" -#include "driver/uart.h" -#include "driver/gpio.h" -#include "esp_timer.h" -#include "esp_log.h" -#include "esp_idf_version.h" -#include - -#ifdef SERIAL_FLASHER_DEBUG_TRACE -static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write) -{ - static bool write_prev = false; - - if (write_prev != write) { - write_prev = write; - printf("\n--- %s ---\n", write ? "WRITE" : "READ"); - } - - for (uint32_t i = 0; i < size; i++) { - printf("%02x ", data[i]); - } -} -#endif - -static int64_t s_time_end; -static int32_t s_uart_port; -static int32_t s_reset_trigger_pin; -static int32_t s_gpio0_trigger_pin; - -esp_loader_error_t loader_port_esp32_init(const loader_esp32_config_t *config) -{ - s_uart_port = config->uart_port; - s_reset_trigger_pin = config->reset_trigger_pin; - s_gpio0_trigger_pin = config->gpio0_trigger_pin; - - // Initialize UART - uart_config_t uart_config = { - .baud_rate = config->baud_rate, - .data_bits = UART_DATA_8_BITS, - .parity = UART_PARITY_DISABLE, - .stop_bits = UART_STOP_BITS_1, - .flow_ctrl = UART_HW_FLOWCTRL_DISABLE, -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(5, 0, 0) - .source_clk = UART_SCLK_DEFAULT, -#endif - }; - - int rx_buffer_size = config->rx_buffer_size ? config->rx_buffer_size : 400; - int tx_buffer_size = config->tx_buffer_size ? config->tx_buffer_size : 400; - QueueHandle_t *uart_queue = config->uart_queue ? config->uart_queue : NULL; - int queue_size = config->queue_size ? config->queue_size : 0; - - if ( uart_param_config(s_uart_port, &uart_config) != ESP_OK ) { - return ESP_LOADER_ERROR_FAIL; - } - if ( uart_set_pin(s_uart_port, config->uart_tx_pin, config->uart_rx_pin, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE) != ESP_OK ) { - return ESP_LOADER_ERROR_FAIL; - } - if ( uart_driver_install(s_uart_port, rx_buffer_size, tx_buffer_size, queue_size, uart_queue, 0) != ESP_OK ) { - return ESP_LOADER_ERROR_FAIL; - } - - // Initialize boot pin selection pins - gpio_reset_pin(s_reset_trigger_pin); - gpio_set_pull_mode(s_reset_trigger_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_reset_trigger_pin, GPIO_MODE_OUTPUT); - - gpio_reset_pin(s_gpio0_trigger_pin); - gpio_set_pull_mode(s_gpio0_trigger_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_gpio0_trigger_pin, GPIO_MODE_OUTPUT); - - return ESP_LOADER_SUCCESS; -} - -void loader_port_esp32_deinit(void) -{ - uart_driver_delete(s_uart_port); -} - - -esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout) -{ - uart_write_bytes(s_uart_port, (const char *)data, size); - esp_err_t err = uart_wait_tx_done(s_uart_port, pdMS_TO_TICKS(timeout)); - - if (err == ESP_OK) { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, size, true); -#endif - return ESP_LOADER_SUCCESS; - } else if (err == ESP_ERR_TIMEOUT) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - - -esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout) -{ - int read = uart_read_bytes(s_uart_port, data, size, pdMS_TO_TICKS(timeout)); - - if (read < 0) { - return ESP_LOADER_ERROR_FAIL; - } else if (read < size) { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, read, false); -#endif - return ESP_LOADER_ERROR_TIMEOUT; - } else { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, read, false); -#endif - return ESP_LOADER_SUCCESS; - } -} - - -// Set GPIO0 LOW, then -// assert reset pin for 50 milliseconds. -void loader_port_enter_bootloader(void) -{ - gpio_set_level(s_gpio0_trigger_pin, 0); - loader_port_reset_target(); - loader_port_delay_ms(SERIAL_FLASHER_BOOT_HOLD_TIME_MS); - gpio_set_level(s_gpio0_trigger_pin, 1); -} - - -void loader_port_reset_target(void) -{ - gpio_set_level(s_reset_trigger_pin, 0); - loader_port_delay_ms(SERIAL_FLASHER_RESET_HOLD_TIME_MS); - gpio_set_level(s_reset_trigger_pin, 1); -} - - -void loader_port_delay_ms(uint32_t ms) -{ - usleep(ms * 1000); -} - - -void loader_port_start_timer(uint32_t ms) -{ - s_time_end = esp_timer_get_time() + ms * 1000; -} - - -uint32_t loader_port_remaining_time(void) -{ - int64_t remaining = (s_time_end - esp_timer_get_time()) / 1000; - return (remaining > 0) ? (uint32_t)remaining : 0; -} - - -void loader_port_debug_print(const char *str) -{ - printf("DEBUG: %s\n", str); -} - -esp_loader_error_t loader_port_change_transmission_rate(uint32_t baudrate) -{ - esp_err_t err = uart_set_baudrate(s_uart_port, baudrate); - return (err == ESP_OK) ? ESP_LOADER_SUCCESS : ESP_LOADER_ERROR_FAIL; -} \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.h deleted file mode 100644 index c098762d25..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_port.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - #pragma once - -#include "esp_loader_io.h" -#include "freertos/FreeRTOS.h" -#include "freertos/queue.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct -{ - uint32_t baud_rate; /*!< Initial baud rate, can be changed later */ - uint32_t uart_port; /*!< UART port */ - uint32_t uart_rx_pin; /*!< This pin will be configured as UART Rx pin */ - uint32_t uart_tx_pin; /*!< This pin will be configured as UART Tx pin */ - uint32_t reset_trigger_pin; /*!< This pin will be used to reset target chip */ - uint32_t gpio0_trigger_pin; /*!< This pin will be used to toggle set IO0 of target chip */ - uint32_t rx_buffer_size; /*!< Set to zero for default RX buffer size */ - uint32_t tx_buffer_size; /*!< Set to zero for default TX buffer size */ - uint32_t queue_size; /*!< Set to zero for default UART queue size */ - QueueHandle_t *uart_queue; /*!< Set to NULL, if UART queue handle is not - necessary. Otherwise, it will be assigned here */ -} loader_esp32_config_t; - -/** - * @brief Initializes serial interface. - * - * @param baud_rate[in] Communication speed. - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_FAIL Initialization failure - */ -esp_loader_error_t loader_port_esp32_init(const loader_esp32_config_t *config); - -/** - * @brief Deinitialize serial interface. - */ -void loader_port_esp32_deinit(void); - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.c deleted file mode 100644 index 55e8f3e571..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.c +++ /dev/null @@ -1,298 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "esp32_spi_port.h" -#include "esp_log.h" -#include "driver/gpio.h" -#include "esp_timer.h" -#include "esp_log.h" -#include "esp_idf_version.h" -#include - -// #define SERIAL_DEBUG_ENABLE - -#if ESP_IDF_VERSION >= ESP_IDF_VERSION_VAL(4, 3, 0) -#define DMA_CHAN SPI_DMA_CH_AUTO -#else -#define DMA_CHAN 1 -#endif - -#define WORD_ALIGNED(ptr) ((size_t)ptr % sizeof(size_t) == 0) - -#ifdef SERIAL_DEBUG_ENABLE - -static void dec_to_hex_str(const uint8_t dec, uint8_t hex_str[3]) -{ - static const uint8_t dec_to_hex[] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' - }; - - hex_str[0] = dec_to_hex[dec >> 4]; - hex_str[1] = dec_to_hex[dec & 0xF]; - hex_str[2] = '\0'; -} - -static void serial_debug_print(const uint8_t *data, uint16_t size, bool write) -{ - static bool write_prev = false; - uint8_t hex_str[3]; - - if(write_prev != write) { - write_prev = write; - printf("\n--- %s ---\n", write ? "WRITE" : "READ"); - } - - for(uint32_t i = 0; i < size; i++) { - dec_to_hex_str(data[i], hex_str); - printf("%s ", hex_str); - } -} - -#else -static void serial_debug_print(const uint8_t *data, uint16_t size, bool write) { } -#endif - -static spi_host_device_t s_spi_bus; -static spi_bus_config_t s_spi_config; -static spi_device_handle_t s_device_h; -static spi_device_interface_config_t s_device_config; -static int64_t s_time_end; -static uint32_t s_reset_trigger_pin; -static uint32_t s_strap_bit0_pin; -static uint32_t s_strap_bit1_pin; -static uint32_t s_strap_bit2_pin; -static uint32_t s_strap_bit3_pin; -static uint32_t s_spi_cs_pin; - -esp_loader_error_t loader_port_esp32_spi_init(const loader_esp32_spi_config_t *config) -{ - /* Initialize the global static variables*/ - s_spi_bus = config->spi_bus; - s_reset_trigger_pin = config->reset_trigger_pin; - s_strap_bit0_pin = config->strap_bit0_pin; - s_strap_bit1_pin = config->strap_bit1_pin; - s_strap_bit2_pin = config->strap_bit2_pin; - s_strap_bit3_pin = config->strap_bit3_pin; - s_spi_cs_pin = config->spi_cs_pin; - - /* Configure and initialize the SPI bus*/ - s_spi_config.mosi_io_num = config->spi_mosi_pin; - s_spi_config.miso_io_num = config->spi_miso_pin; - s_spi_config.sclk_io_num = config->spi_clk_pin; - s_spi_config.quadwp_io_num = config->spi_quadwp_pin; - s_spi_config.quadhd_io_num = config->spi_quadhd_pin; - s_spi_config.max_transfer_sz = 4096 * 4; - - if (spi_bus_initialize(s_spi_bus, &s_spi_config, DMA_CHAN) != ESP_OK) { - return ESP_LOADER_ERROR_FAIL; - } - - /* Configure and add the device */ - s_device_config.clock_speed_hz = config->frequency; - s_device_config.spics_io_num = -1; /* We're using the chip select pin as GPIO as we need to - chain multiple transactions with CS pulled down */ - s_device_config.flags = SPI_DEVICE_HALFDUPLEX; - s_device_config.queue_size = 16; - - if (spi_bus_add_device(s_spi_bus, &s_device_config, &s_device_h) != ESP_OK) { - return ESP_LOADER_ERROR_FAIL; - } - - /* Initialize the pins except for the strapping ones */ - gpio_reset_pin(s_reset_trigger_pin); - gpio_set_pull_mode(s_reset_trigger_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_reset_trigger_pin, GPIO_MODE_OUTPUT); - gpio_set_level(s_reset_trigger_pin, 1); - - gpio_reset_pin(s_spi_cs_pin); - gpio_set_pull_mode(s_spi_cs_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_spi_cs_pin, GPIO_MODE_OUTPUT); - gpio_set_level(s_spi_cs_pin, 1); - - return ESP_LOADER_SUCCESS; -} - - -void loader_port_esp32_spi_deinit(void) -{ - gpio_reset_pin(s_reset_trigger_pin); - gpio_reset_pin(s_spi_cs_pin); - spi_bus_remove_device(s_device_h); - spi_bus_free(s_spi_bus); -} - - -void loader_port_spi_set_cs(const uint32_t level) { - gpio_set_level(s_spi_cs_pin, level); -} - - -esp_loader_error_t loader_port_write(const uint8_t *data, const uint16_t size, const uint32_t timeout) -{ - /* Due to the fact that the SPI driver uses DMA for larger transfers, - and the DMA requirements, the buffer must be word aligned */ - if (data == NULL || !WORD_ALIGNED(data)) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - serial_debug_print(data, size, true); - - spi_transaction_t transaction = { - .tx_buffer = data, - .rx_buffer = NULL, - .length = size * 8U, - .rxlength = 0, - }; - - esp_err_t err = spi_device_transmit(s_device_h, &transaction); - - if (err == ESP_OK) { - serial_debug_print(data, size, false); - return ESP_LOADER_SUCCESS; - } else if (err == ESP_ERR_TIMEOUT) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - - -esp_loader_error_t loader_port_read(uint8_t *data, const uint16_t size, const uint32_t timeout) -{ - /* Due to the fact that the SPI driver uses DMA for larger transfers, - and the DMA requirements, the buffer must be word aligned */ - if (data == NULL || !WORD_ALIGNED(data)) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - serial_debug_print(data, size, true); - - spi_transaction_t transaction = { - .tx_buffer = NULL, - .rx_buffer = data, - .rxlength = size * 8, - }; - - esp_err_t err = spi_device_transmit(s_device_h, &transaction); - - if (err == ESP_OK) { - serial_debug_print(data, size, false); - return ESP_LOADER_SUCCESS; - } else if (err == ESP_ERR_TIMEOUT) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - - -void loader_port_enter_bootloader(void) -{ - /* - We have to initialize the GPIO pins for the target strapping pins here, - as they may overlap with target SPI pins. - For instance in the case of ESP32C3 MISO and strapping bit 0 pins overlap. - */ - spi_bus_remove_device(s_device_h); - spi_bus_free(s_spi_bus); - - gpio_reset_pin(s_strap_bit0_pin); - gpio_set_pull_mode(s_strap_bit0_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_strap_bit0_pin, GPIO_MODE_OUTPUT); - - gpio_reset_pin(s_strap_bit1_pin); - gpio_set_pull_mode(s_strap_bit1_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_strap_bit1_pin, GPIO_MODE_OUTPUT); - - gpio_reset_pin(s_strap_bit2_pin); - gpio_set_pull_mode(s_strap_bit2_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_strap_bit2_pin, GPIO_MODE_OUTPUT); - - gpio_reset_pin(s_strap_bit3_pin); - gpio_set_pull_mode(s_strap_bit3_pin, GPIO_PULLUP_ONLY); - gpio_set_direction(s_strap_bit3_pin, GPIO_MODE_OUTPUT); - - /* Set the strapping pins and perform the reset sequence */ - gpio_set_level(s_strap_bit0_pin, 1); - gpio_set_level(s_strap_bit1_pin, 0); - gpio_set_level(s_strap_bit2_pin, 0); - gpio_set_level(s_strap_bit3_pin, 0); - loader_port_reset_target(); - loader_port_delay_ms(SERIAL_FLASHER_BOOT_HOLD_TIME_MS); - gpio_set_level(s_strap_bit3_pin, 1); - gpio_set_level(s_strap_bit0_pin, 0); - - /* Disable the strapping pins so they can be used by the slave later */ - gpio_reset_pin(s_strap_bit0_pin); - gpio_reset_pin(s_strap_bit1_pin); - gpio_reset_pin(s_strap_bit2_pin); - gpio_reset_pin(s_strap_bit3_pin); - - /* Restore the SPI bus pins */ - spi_bus_initialize(s_spi_bus, &s_spi_config, DMA_CHAN); - spi_bus_add_device(s_spi_bus, &s_device_config, &s_device_h); -} - - -void loader_port_reset_target(void) -{ - gpio_set_level(s_reset_trigger_pin, 0); - loader_port_delay_ms(SERIAL_FLASHER_RESET_HOLD_TIME_MS); - gpio_set_level(s_reset_trigger_pin, 1); -} - - -void loader_port_delay_ms(const uint32_t ms) -{ - usleep(ms * 1000); -} - - -void loader_port_start_timer(const uint32_t ms) -{ - s_time_end = esp_timer_get_time() + ms * 1000; -} - - -uint32_t loader_port_remaining_time(void) -{ - int64_t remaining = (s_time_end - esp_timer_get_time()) / 1000; - return (remaining > 0) ? (uint32_t)remaining : 0; -} - - -void loader_port_debug_print(const char *str) -{ - printf("DEBUG: %s\n", str); -} - - -esp_loader_error_t loader_port_change_transmission_rate(const uint32_t frequency) -{ - if (spi_bus_remove_device(s_device_h) != ESP_OK) { - return ESP_LOADER_ERROR_FAIL; - } - - uint32_t old_frequency = s_device_config.clock_speed_hz; - s_device_config.clock_speed_hz = frequency; - - if (spi_bus_add_device(s_spi_bus, &s_device_config, &s_device_h) != ESP_OK) { - s_device_config.clock_speed_hz = old_frequency; - return ESP_LOADER_ERROR_FAIL; - } - - return ESP_LOADER_SUCCESS; -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.h deleted file mode 100644 index 72304c5df4..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/esp32_spi_port.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - #pragma once - -#include "esp_loader_io.h" -#include "driver/spi_master.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct -{ - spi_host_device_t spi_bus; - uint32_t frequency; - uint32_t spi_clk_pin; - uint32_t spi_miso_pin; - uint32_t spi_mosi_pin; - uint32_t spi_cs_pin; - uint32_t spi_quadwp_pin; - uint32_t spi_quadhd_pin; - uint32_t reset_trigger_pin; - uint32_t strap_bit0_pin; - uint32_t strap_bit1_pin; - uint32_t strap_bit2_pin; - uint32_t strap_bit3_pin; -} loader_esp32_spi_config_t; - -/** - * @brief Initializes the SPI interface. - * - * @param config[in] Configuration structure - * - * @return - * - ESP_LOADER_SUCCESS Success - * - ESP_LOADER_ERROR_FAIL Initialization failure - */ -esp_loader_error_t loader_port_esp32_spi_init(const loader_esp32_spi_config_t *config); - -/** - * @brief Deinitializes the SPI interface. - */ -void loader_port_esp32_spi_deinit(void); - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.c deleted file mode 100644 index d733db702f..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.c +++ /dev/null @@ -1,302 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "esp_loader_io.h" -#include "protocol.h" -#include -#include "raspberry_port.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef SERIAL_FLASHER_DEBUG_TRACE -static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write) -{ - static bool write_prev = false; - - if (write_prev != write) { - write_prev = write; - printf("\n--- %s ---\n", write ? "WRITE" : "READ"); - } - - for (uint32_t i = 0; i < size; i++) { - printf("%02x ", data[i]); - } -} -#endif - -static int serial; -static int64_t s_time_end; -static int32_t s_reset_trigger_pin; -static int32_t s_gpio0_trigger_pin; - - -static speed_t convert_baudrate(int baud) -{ - switch (baud) { - case 50: return B50; - case 75: return B75; - case 110: return B110; - case 134: return B134; - case 150: return B150; - case 200: return B200; - case 300: return B300; - case 600: return B600; - case 1200: return B1200; - case 1800: return B1800; - case 2400: return B2400; - case 4800: return B4800; - case 9600: return B9600; - case 19200: return B19200; - case 38400: return B38400; - case 57600: return B57600; - case 115200: return B115200; - case 230400: return B230400; - case 460800: return B460800; - case 500000: return B500000; - case 576000: return B576000; - case 921600: return B921600; - case 1000000: return B1000000; - case 1152000: return B1152000; - case 1500000: return B1500000; - case 2000000: return B2000000; - case 2500000: return B2500000; - case 3000000: return B3000000; - case 3500000: return B3500000; - case 4000000: return B4000000; - default: return -1; - } -} - -static int serialOpen (const char *device, uint32_t baudrate) -{ - struct termios options; - int status, fd; - - if ((fd = open (device, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) == -1) { - printf("Error occured while opening serial port !\n"); - return -1 ; - } - - fcntl (fd, F_SETFL, O_RDWR) ; - - // Get and modify current options: - - tcgetattr (fd, &options); - speed_t baud = convert_baudrate(baudrate); - - if(baud < 0) { - printf("Invalid baudrate!\n"); - return -1; - } - - cfmakeraw (&options) ; - cfsetispeed (&options, baud) ; - cfsetospeed (&options, baud) ; - - options.c_cflag |= (CLOCAL | CREAD) ; - options.c_cflag &= ~(PARENB | CSTOPB | CSIZE) ; - options.c_cflag |= CS8 ; - options.c_lflag &= ~(ICANON | ECHO | ECHOE | ISIG) ; - options.c_oflag &= ~OPOST ; - options.c_iflag &= ~(IXON | IXOFF | IXANY); // Turn off s/w flow ctrl - options.c_iflag &= ~(IGNBRK | BRKINT | PARMRK | ISTRIP | INLCR | IGNCR | ICRNL); // Disable any special handling of received bytes - - options.c_cc [VMIN] = 0 ; - options.c_cc [VTIME] = 10 ; // 1 Second - - tcsetattr (fd, TCSANOW, &options) ; - - ioctl (fd, TIOCMGET, &status); - - status |= TIOCM_DTR ; - status |= TIOCM_RTS ; - - ioctl (fd, TIOCMSET, &status); - - usleep (10000) ; // 10mS - - return fd ; -} - -static esp_loader_error_t change_baudrate(int file_desc, int baudrate) -{ - struct termios options; - speed_t baud = convert_baudrate(baudrate); - - if(baud < 0) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - tcgetattr (file_desc, &options); - - cfmakeraw (&options) ; - cfsetispeed (&options, baud); - cfsetospeed (&options, baud); - - tcsetattr (file_desc, TCSANOW, &options); - - return ESP_LOADER_SUCCESS; -} - -static void set_timeout(uint32_t timeout) -{ - struct termios options; - - timeout /= 100; - timeout = MAX(timeout, 1); - - tcgetattr(serial, &options); - options.c_cc[VTIME] = timeout; - tcsetattr(serial, TCSANOW, &options); -} - -static esp_loader_error_t read_char(char *c, uint32_t timeout) -{ - set_timeout(timeout); - int read_bytes = read(serial, c, 1); - - if (read_bytes == 1) { - return ESP_LOADER_SUCCESS; - } else if (read_bytes == 0) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - -static esp_loader_error_t read_data(char *buffer, uint32_t size) -{ - for (int i = 0; i < size; i++) { - uint32_t remaining_time = loader_port_remaining_time(); - RETURN_ON_ERROR( read_char(&buffer[i], remaining_time) ); - } - - return ESP_LOADER_SUCCESS; -} - -esp_loader_error_t loader_port_raspberry_init(const loader_raspberry_config_t *config) -{ - s_reset_trigger_pin = config->reset_trigger_pin; - s_gpio0_trigger_pin = config->gpio0_trigger_pin; - - serial = serialOpen(config->device, config->baudrate); - if (serial < 0) { - printf("Serial port could not be opened!\n"); - return ESP_LOADER_ERROR_FAIL; - } - - if (gpioInitialise() < 0) { - printf("pigpio initialisation failed\n"); - return ESP_LOADER_ERROR_FAIL; - } - - gpioSetMode(config->reset_trigger_pin, PI_OUTPUT); - gpioSetMode(config->gpio0_trigger_pin, PI_OUTPUT); - - return ESP_LOADER_SUCCESS; -} - - -esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout) -{ - int written = write(serial, data, size); - - if (written < 0) { - return ESP_LOADER_ERROR_FAIL; - } else if (written < size) { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, written, true); -#endif - return ESP_LOADER_ERROR_TIMEOUT; - } else { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, written, true); -#endif - return ESP_LOADER_SUCCESS; - } -} - - -esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout) -{ - RETURN_ON_ERROR( read_data(data, size) ); - -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, size, false); -#endif - - return ESP_LOADER_SUCCESS; -} - - -// Set GPIO0 LOW, then assert reset pin for 50 milliseconds. -void loader_port_enter_bootloader(void) -{ - gpioWrite(s_gpio0_trigger_pin, 0); - loader_port_reset_target(); - loader_port_delay_ms(SERIAL_FLASHER_BOOT_HOLD_TIME_MS); - gpioWrite(s_gpio0_trigger_pin, 1); -} - - -void loader_port_reset_target(void) -{ - gpioWrite(s_reset_trigger_pin, 0); - loader_port_delay_ms(SERIAL_FLASHER_RESET_HOLD_TIME_MS); - gpioWrite(s_reset_trigger_pin, 1); -} - - -void loader_port_delay_ms(uint32_t ms) -{ - usleep(ms * 1000); -} - - -void loader_port_start_timer(uint32_t ms) -{ - s_time_end = clock() + (ms * (CLOCKS_PER_SEC / 1000)); -} - - -uint32_t loader_port_remaining_time(void) -{ - int64_t remaining = (s_time_end - clock()) / 1000; - return (remaining > 0) ? (uint32_t)remaining : 0; -} - - -void loader_port_debug_print(const char *str) -{ - printf("DEBUG: %s\n", str); -} - -esp_loader_error_t loader_port_change_transmission_rate(uint32_t baudrate) -{ - return change_baudrate(serial, baudrate); -} \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.h deleted file mode 100644 index 803ab72ddb..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/raspberry_port.h +++ /dev/null @@ -1,36 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include "esp_loader_io.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - const char *device; - uint32_t baudrate; - uint32_t reset_trigger_pin; - uint32_t gpio0_trigger_pin; -} loader_raspberry_config_t; - -esp_loader_error_t loader_port_raspberry_init(const loader_raspberry_config_t *config); - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.c deleted file mode 100644 index 716c9c91b0..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.c +++ /dev/null @@ -1,140 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include -#include -#include -#include -#include -#include "stm32_port.h" - -static UART_HandleTypeDef *uart; -static GPIO_TypeDef* gpio_port_io0, *gpio_port_rst; -static uint16_t gpio_num_io0, gpio_num_rst; - -#ifdef SERIAL_FLASHER_DEBUG_TRACE -static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write) -{ - static bool write_prev = false; - - if (write_prev != write) { - write_prev = write; - printf("\n--- %s ---\n", write ? "WRITE" : "READ"); - } - - for (uint32_t i = 0; i < size; i++) { - printf("%02x ", data[i]); - } -} -#endif - -static uint32_t s_time_end; - -esp_loader_error_t loader_port_write(const uint8_t *data, uint16_t size, uint32_t timeout) -{ - HAL_StatusTypeDef err = HAL_UART_Transmit(uart, (uint8_t *)data, size, timeout); - - if (err == HAL_OK) { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, size, true); -#endif - return ESP_LOADER_SUCCESS; - } else if (err == HAL_TIMEOUT) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - - -esp_loader_error_t loader_port_read(uint8_t *data, uint16_t size, uint32_t timeout) -{ - HAL_StatusTypeDef err = HAL_UART_Receive(uart, data, size, timeout); - - if (err == HAL_OK) { -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, size, false); -#endif - return ESP_LOADER_SUCCESS; - } else if (err == HAL_TIMEOUT) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_ERROR_FAIL; - } -} - -void loader_port_stm32_init(loader_stm32_config_t *config) - -{ - uart = config->huart; - gpio_port_io0 = config->port_io0; - gpio_port_rst = config->port_rst; - gpio_num_io0 = config->pin_num_io0; - gpio_num_rst = config->pin_num_rst; -} - -// Set GPIO0 LOW, then -// assert reset pin for 100 milliseconds. -void loader_port_enter_bootloader(void) -{ - HAL_GPIO_WritePin(gpio_port_io0, gpio_num_io0, GPIO_PIN_RESET); - loader_port_reset_target(); - HAL_Delay(SERIAL_FLASHER_BOOT_HOLD_TIME_MS); - HAL_GPIO_WritePin(gpio_port_io0, gpio_num_io0, GPIO_PIN_SET); -} - - -void loader_port_reset_target(void) -{ - HAL_GPIO_WritePin(gpio_port_rst, gpio_num_rst, GPIO_PIN_RESET); - HAL_Delay(SERIAL_FLASHER_RESET_HOLD_TIME_MS); - HAL_GPIO_WritePin(gpio_port_rst, gpio_num_rst, GPIO_PIN_SET); -} - - -void loader_port_delay_ms(uint32_t ms) -{ - HAL_Delay(ms); -} - - -void loader_port_start_timer(uint32_t ms) -{ - s_time_end = HAL_GetTick() + ms; -} - - -uint32_t loader_port_remaining_time(void) -{ - int32_t remaining = s_time_end - HAL_GetTick(); - return (remaining > 0) ? (uint32_t)remaining : 0; -} - - -void loader_port_debug_print(const char *str) -{ - printf("DEBUG: %s", str); -} - -esp_loader_error_t loader_port_change_transmission_rate(uint32_t baudrate) -{ - uart->Init.BaudRate = baudrate; - - if( HAL_UART_Init(uart) != HAL_OK ) { - return ESP_LOADER_ERROR_FAIL; - } - - return ESP_LOADER_SUCCESS; -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.h deleted file mode 100644 index a3a89a7331..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/stm32_port.h +++ /dev/null @@ -1,38 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include "esp_loader_io.h" -#include "stm32f4xx_hal.h" - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - UART_HandleTypeDef *huart; - GPIO_TypeDef *port_io0; - uint16_t pin_num_io0; - GPIO_TypeDef *port_rst; - uint16_t pin_num_rst; -} loader_stm32_config_t; - -void loader_port_stm32_init(loader_stm32_config_t *config); - -#ifdef __cplusplus -} -#endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.c deleted file mode 100644 index 21270ba0af..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.c +++ /dev/null @@ -1,170 +0,0 @@ -/* - * Copyright (c) 2022 KT-Elektronik, Klaucke und Partner GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "zephyr_port.h" -#include -#include - -static const struct device *uart_dev; -static struct gpio_dt_spec enable_spec; -static struct gpio_dt_spec boot_spec; - -static struct tty_serial tty; -static char tty_rx_buf[CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE]; -static char tty_tx_buf[CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE]; - -#ifdef SERIAL_FLASHER_DEBUG_TRACE -static void transfer_debug_print(const uint8_t *data, uint16_t size, bool write) -{ - static bool write_prev = false; - - if (write_prev != write) { - write_prev = write; - printk("\n--- %s ---\n", write ? "WRITE" : "READ"); - } - - for (uint32_t i = 0; i < size; i++) { - printk("%02x ", data[i]); - } -} -#endif - -esp_loader_error_t configure_tty() -{ - if (tty_init(&tty, uart_dev) < 0 || - tty_set_rx_buf(&tty, tty_rx_buf, sizeof(tty_rx_buf)) < 0 || - tty_set_tx_buf(&tty, tty_tx_buf, sizeof(tty_tx_buf)) < 0) { - return ESP_LOADER_ERROR_FAIL; - } - - return ESP_LOADER_SUCCESS; -} - -esp_loader_error_t loader_port_read(uint8_t *data, const uint16_t size, const uint32_t timeout) -{ - if (!device_is_ready(uart_dev) || data == NULL || size == 0) { - return ESP_LOADER_ERROR_FAIL; - } - - ssize_t total_read = 0; - ssize_t remaining = size; - - tty_set_rx_timeout(&tty, timeout); - while (remaining > 0) { - const uint16_t chunk_size = remaining < CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE ? - remaining : CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE; - ssize_t read = tty_read(&tty, &data[total_read], chunk_size); - if (read < 0) { - return ESP_LOADER_ERROR_TIMEOUT; - } -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, read, false); -#endif - total_read += read; - remaining -= read; - } - - return ESP_LOADER_SUCCESS; -} - -esp_loader_error_t loader_port_write(const uint8_t *data, const uint16_t size, const uint32_t timeout) -{ - if (!device_is_ready(uart_dev) || data == NULL || size == 0) { - return ESP_LOADER_ERROR_FAIL; - } - - ssize_t total_written = 0; - ssize_t remaining = size; - - tty_set_tx_timeout(&tty, timeout); - while (remaining > 0) { - const uint16_t chunk_size = remaining < CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE ? - remaining : CONFIG_ESP_SERIAL_FLASHER_UART_BUFSIZE; - ssize_t written = tty_write(&tty, &data[total_written], chunk_size); - if (written < 0) { - return ESP_LOADER_ERROR_TIMEOUT; - } -#ifdef SERIAL_FLASHER_DEBUG_TRACE - transfer_debug_print(data, written, true); -#endif - total_written += written; - remaining -= written; - } - - return ESP_LOADER_SUCCESS; -} - -esp_loader_error_t loader_port_zephyr_init(const loader_zephyr_config_t *config) -{ - uart_dev = config->uart_dev; - enable_spec = config->enable_spec; - boot_spec = config->boot_spec; - return configure_tty(); -} - -void loader_port_reset_target(void) -{ - gpio_pin_set_dt(&enable_spec, false); - loader_port_delay_ms(CONFIG_SERIAL_FLASHER_RESET_HOLD_TIME_MS); - gpio_pin_set_dt(&enable_spec, true); -} - -void loader_port_enter_bootloader(void) -{ - gpio_pin_set_dt(&boot_spec, false); - loader_port_reset_target(); - loader_port_delay_ms(CONFIG_SERIAL_FLASHER_BOOT_HOLD_TIME_MS); - gpio_pin_set_dt(&boot_spec, true); -} - -void loader_port_delay_ms(uint32_t ms) -{ - k_msleep(ms); -} - -static uint64_t s_time_end; - -void loader_port_start_timer(uint32_t ms) -{ - s_time_end = sys_clock_timeout_end_calc(Z_TIMEOUT_MS(ms)); -} - -uint32_t loader_port_remaining_time(void) -{ - int64_t remaining = k_ticks_to_ms_floor64(s_time_end - k_uptime_ticks()); - return (remaining > 0) ? (uint32_t)remaining : 0; -} - -esp_loader_error_t loader_port_change_transmission_rate(uint32_t baudrate) -{ - struct uart_config uart_config; - - if (!device_is_ready(uart_dev)) { - return ESP_LOADER_ERROR_FAIL; - } - - if (uart_config_get(uart_dev, &uart_config) != 0) { - return ESP_LOADER_ERROR_FAIL; - } - uart_config.baudrate = baudrate; - - if (uart_configure(uart_dev, &uart_config) != 0) { - return ESP_LOADER_ERROR_FAIL; - } - - /* bitrate-change can require tty re-configuration */ - return configure_tty(); -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.h deleted file mode 100644 index 0b104e3756..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/port/zephyr_port.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2022 KT-Elektronik, Klaucke und Partner GmbH - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "esp_loader_io.h" -#include -#include -#include - -#ifdef __cplusplus -extern "C" { -#endif - -typedef struct { - const struct device *uart_dev; - const struct gpio_dt_spec enable_spec; - const struct gpio_dt_spec boot_spec; -} loader_zephyr_config_t; - -esp_loader_error_t loader_port_zephyr_init(const loader_zephyr_config_t *config); - -#ifdef __cplusplus -} -#endif - diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/esp_targets.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/esp_targets.h deleted file mode 100644 index cf8af91fa8..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/esp_targets.h +++ /dev/null @@ -1,33 +0,0 @@ -/* Copyright 2020 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include "esp_loader.h" - -typedef struct { - uint32_t cmd; - uint32_t usr; - uint32_t usr1; - uint32_t usr2; - uint32_t w0; - uint32_t mosi_dlen; - uint32_t miso_dlen; -} target_registers_t; - -esp_loader_error_t loader_detect_chip(target_chip_t *target, const target_registers_t **regs); -esp_loader_error_t loader_read_spi_config(target_chip_t target_chip, uint32_t *spi_config); -bool encryption_in_begin_flash_cmd(target_chip_t target); \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/md5_hash.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/md5_hash.h deleted file mode 100644 index eb5738c8b0..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/md5_hash.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * MD5 hash implementation and interface functions - * Copyright (c) 2003-2005, Jouni Malinen - * - * This software may be distributed under the terms of the BSD license. - * See README for more details. - */ - -#pragma once - -#include - -#ifdef __cplusplus -extern "C" { -#endif -struct MD5Context { - uint32_t buf[4]; - uint32_t bits[2]; - uint8_t in[64]; -}; - -void MD5Init(struct MD5Context *context); -void MD5Update(struct MD5Context *context, unsigned char const *buf, unsigned len); -void MD5Final(unsigned char digest[16], struct MD5Context *context); - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol.h deleted file mode 100644 index fb8b086fd4..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol.h +++ /dev/null @@ -1,230 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include "esp_loader.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#define STATUS_FAILURE 1 -#define STATUS_SUCCESS 0 - -#define READ_DIRECTION 1 -#define WRITE_DIRECTION 0 - -#define MD5_SIZE 32 - -typedef enum __attribute__((packed)) -{ - FLASH_BEGIN = 0x02, - FLASH_DATA = 0x03, - FLASH_END = 0x04, - MEM_BEGIN = 0x05, - MEM_END = 0x06, - MEM_DATA = 0x07, - SYNC = 0x08, - WRITE_REG = 0x09, - READ_REG = 0x0a, - - SPI_SET_PARAMS = 0x0b, - SPI_ATTACH = 0x0d, - CHANGE_BAUDRATE = 0x0f, - FLASH_DEFL_BEGIN = 0x10, - FLASH_DEFL_DATA = 0x11, - FLASH_DEFL_END = 0x12, - SPI_FLASH_MD5 = 0x13, -} command_t; - -typedef enum __attribute__((packed)) -{ - RESPONSE_OK = 0x00, - INVALID_COMMAND = 0x05, // parameters or length field is invalid - COMMAND_FAILED = 0x06, // Failed to act on received message - INVALID_CRC = 0x07, // Invalid CRC in message - FLASH_WRITE_ERR = 0x08, // After writing a block of data to flash, the ROM loader reads the value back and the 8-bit CRC is compared to the data read from flash. If they don't match, this error is returned. - FLASH_READ_ERR = 0x09, // SPI read failed - READ_LENGTH_ERR = 0x0a, // SPI read request length is too long - DEFLATE_ERROR = 0x0b, // ESP32 compressed uploads only -} error_code_t; - -typedef struct __attribute__((packed)) -{ - uint8_t direction; - uint8_t command; // One of command_t - uint16_t size; - uint32_t checksum; -} command_common_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t erase_size; - uint32_t packet_count; - uint32_t packet_size; - uint32_t offset; - uint32_t encrypted; -} flash_begin_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t data_size; - uint32_t sequence_number; - uint32_t zero_0; - uint32_t zero_1; -} data_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t stay_in_loader; -} flash_end_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t total_size; - uint32_t blocks; - uint32_t block_size; - uint32_t offset; -} mem_begin_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t stay_in_loader; - uint32_t entry_point_address; -} mem_end_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint8_t sync_sequence[36]; -} sync_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t address; - uint32_t value; - uint32_t mask; - uint32_t delay_us; -} write_reg_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t address; -} read_reg_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t configuration; - uint32_t zero; // ESP32 ROM only -} spi_attach_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t new_baudrate; - uint32_t old_baudrate; -} change_baudrate_command_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t address; - uint32_t size; - uint32_t reserved_0; - uint32_t reserved_1; -} spi_flash_md5_command_t; - -typedef struct __attribute__((packed)) -{ - uint8_t direction; - uint8_t command; // One of command_t - uint16_t size; - uint32_t value; -} common_response_t; - -typedef struct __attribute__((packed)) -{ - uint8_t failed; - uint8_t error; -} response_status_t; - -typedef struct __attribute__((packed)) -{ - common_response_t common; - response_status_t status; -} response_t; - -typedef struct __attribute__((packed)) -{ - common_response_t common; - uint8_t md5[MD5_SIZE]; // ROM only - response_status_t status; -} rom_md5_response_t; - -typedef struct __attribute__((packed)) -{ - command_common_t common; - uint32_t id; - uint32_t total_size; - uint32_t block_size; - uint32_t sector_size; - uint32_t page_size; - uint32_t status_mask; -} write_spi_command_t; - -esp_loader_error_t loader_initialize_conn(esp_loader_connect_args_t *connect_args); - -#ifdef SERIAL_FLASHER_INTERFACE_UART -esp_loader_error_t loader_flash_begin_cmd(uint32_t offset, uint32_t erase_size, uint32_t block_size, uint32_t blocks_to_write, bool encryption); - -esp_loader_error_t loader_flash_data_cmd(const uint8_t *data, uint32_t size); - -esp_loader_error_t loader_flash_end_cmd(bool stay_in_loader); - -esp_loader_error_t loader_sync_cmd(void); - -esp_loader_error_t loader_spi_attach_cmd(uint32_t config); - -esp_loader_error_t loader_md5_cmd(uint32_t address, uint32_t size, uint8_t *md5_out); - -esp_loader_error_t loader_spi_parameters(uint32_t total_size); -#endif /* SERIAL_FLASHER_INTERFACE_UART */ - -esp_loader_error_t loader_mem_begin_cmd(uint32_t offset, uint32_t size, uint32_t blocks_to_write, uint32_t block_size); - -esp_loader_error_t loader_mem_data_cmd(const uint8_t *data, uint32_t size); - -esp_loader_error_t loader_mem_end_cmd(uint32_t entrypoint); - -esp_loader_error_t loader_write_reg_cmd(uint32_t address, uint32_t value, uint32_t mask, uint32_t delay_us); - -esp_loader_error_t loader_read_reg_cmd(uint32_t address, uint32_t *reg); - -esp_loader_error_t loader_change_baudrate_cmd(uint32_t baudrate); - -#ifdef __cplusplus -} -#endif \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol_prv.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol_prv.h deleted file mode 100644 index 3b95756062..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/protocol_prv.h +++ /dev/null @@ -1,31 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include -#include -#include -#include "esp_loader.h" -#include "protocol.h" - -void log_loader_internal_error(error_code_t error); - -esp_loader_error_t send_cmd(const void *cmd_data, uint32_t size, uint32_t *reg_value); - -esp_loader_error_t send_cmd_with_data(const void *cmd_data, size_t cmd_size, - const void *data, size_t data_size); - -esp_loader_error_t send_cmd_md5(const void *cmd_data, size_t cmd_size, uint8_t md5_out[MD5_SIZE]); diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/slip.h b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/slip.h deleted file mode 100644 index 00f1f7d0d2..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/private_include/slip.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#pragma once - -#include "esp_loader.h" -#include -#include - -esp_loader_error_t SLIP_receive_data(uint8_t *buff, size_t size); - -esp_loader_error_t SLIP_receive_packet(uint8_t *buff, size_t size); - -esp_loader_error_t SLIP_send(const uint8_t *data, size_t size); - -esp_loader_error_t SLIP_send_delimiter(void); diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_loader.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_loader.c deleted file mode 100644 index 6ef32673c2..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_loader.c +++ /dev/null @@ -1,415 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "protocol.h" -#include "esp_loader_io.h" -#include "esp_loader.h" -#include "esp_targets.h" -#include "md5_hash.h" -#include -#include - -#ifndef MAX -#define MAX(a, b) ((a) > (b)) ? (a) : (b) -#endif - -#ifndef MIN -#define MIN(a, b) ((a) < (b)) ? (a) : (b) -#endif - -#ifndef ROUNDUP -#define ROUNDUP(a, b) (((int)a + (int)b - 1) / (int)b) -#endif - -static const uint32_t DEFAULT_TIMEOUT = 1000; -static const uint32_t DEFAULT_FLASH_TIMEOUT = 3000; // timeout for most flash operations -static const uint32_t LOAD_RAM_TIMEOUT_PER_MB = 2000000; // timeout (per megabyte) for erasing a region - -typedef enum { - SPI_FLASH_READ_ID = 0x9F -} spi_flash_cmd_t; - -static const target_registers_t *s_reg = NULL; -static target_chip_t s_target = ESP_UNKNOWN_CHIP; - -#if MD5_ENABLED - -static const uint32_t MD5_TIMEOUT_PER_MB = 800; -static struct MD5Context s_md5_context; -static uint32_t s_start_address; -static uint32_t s_image_size; - -static inline void init_md5(uint32_t address, uint32_t size) -{ - s_start_address = address; - s_image_size = size; - MD5Init(&s_md5_context); -} - -static inline void md5_update(const uint8_t *data, uint32_t size) -{ - MD5Update(&s_md5_context, data, size); -} - -static inline void md5_final(uint8_t digets[16]) -{ - MD5Final(digets, &s_md5_context); -} - -#else - -static inline void init_md5(uint32_t address, uint32_t size) { } -static inline void md5_update(const uint8_t *data, uint32_t size) { } -static inline void md5_final(uint8_t digets[16]) { } - -#endif - - -static uint32_t timeout_per_mb(uint32_t size_bytes, uint32_t time_per_mb) -{ - uint32_t timeout = time_per_mb * (size_bytes / 1e6); - return MAX(timeout, DEFAULT_FLASH_TIMEOUT); -} - -esp_loader_error_t esp_loader_connect(esp_loader_connect_args_t *connect_args) -{ - loader_port_enter_bootloader(); - - RETURN_ON_ERROR(loader_initialize_conn(connect_args)); - - RETURN_ON_ERROR(loader_detect_chip(&s_target, &s_reg)); - -#ifdef SERIAL_FLASHER_INTERFACE_UART - esp_loader_error_t err; - uint32_t spi_config; - if (s_target == ESP8266_CHIP) { - err = loader_flash_begin_cmd(0, 0, 0, 0, s_target); - } else { - RETURN_ON_ERROR( loader_read_spi_config(s_target, &spi_config) ); - loader_port_start_timer(DEFAULT_TIMEOUT); - err = loader_spi_attach_cmd(spi_config); - } - return err; -#endif /* SERIAL_FLASHER_INTERFACE_UART */ - return ESP_LOADER_SUCCESS; -} - -target_chip_t esp_loader_get_target(void) -{ - return s_target; -} - -#ifdef SERIAL_FLASHER_INTERFACE_UART -static uint32_t s_flash_write_size = 0; - -static esp_loader_error_t spi_set_data_lengths(size_t mosi_bits, size_t miso_bits) -{ - if (mosi_bits > 0) { - RETURN_ON_ERROR( esp_loader_write_register(s_reg->mosi_dlen, mosi_bits - 1) ); - } - if (miso_bits > 0) { - RETURN_ON_ERROR( esp_loader_write_register(s_reg->miso_dlen, miso_bits - 1) ); - } - - return ESP_LOADER_SUCCESS; -} - -static esp_loader_error_t spi_set_data_lengths_8266(size_t mosi_bits, size_t miso_bits) -{ - uint32_t mosi_mask = (mosi_bits == 0) ? 0 : mosi_bits - 1; - uint32_t miso_mask = (miso_bits == 0) ? 0 : miso_bits - 1; - return esp_loader_write_register(s_reg->usr1, (miso_mask << 8) | (mosi_mask << 17)); -} - -static esp_loader_error_t spi_flash_command(spi_flash_cmd_t cmd, void *data_tx, size_t tx_size, void *data_rx, size_t rx_size) -{ - assert(rx_size <= 32); // Reading more than 32 bits back from a SPI flash operation is unsupported - assert(tx_size <= 64); // Writing more than 64 bytes of data with one SPI command is unsupported - - uint32_t SPI_USR_CMD = (1 << 31); - uint32_t SPI_USR_MISO = (1 << 28); - uint32_t SPI_USR_MOSI = (1 << 27); - uint32_t SPI_CMD_USR = (1 << 18); - uint32_t CMD_LEN_SHIFT = 28; - - // Save SPI configuration - uint32_t old_spi_usr; - uint32_t old_spi_usr2; - RETURN_ON_ERROR( esp_loader_read_register(s_reg->usr, &old_spi_usr) ); - RETURN_ON_ERROR( esp_loader_read_register(s_reg->usr2, &old_spi_usr2) ); - - if (s_target == ESP8266_CHIP) { - RETURN_ON_ERROR( spi_set_data_lengths_8266(tx_size, rx_size) ); - } else { - RETURN_ON_ERROR( spi_set_data_lengths(tx_size, rx_size) ); - } - - uint32_t usr_reg_2 = (7 << CMD_LEN_SHIFT) | cmd; - uint32_t usr_reg = SPI_USR_CMD; - if (rx_size > 0) { - usr_reg |= SPI_USR_MISO; - } - if (tx_size > 0) { - usr_reg |= SPI_USR_MOSI; - } - - RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr, usr_reg) ); - RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr2, usr_reg_2 ) ); - - if (tx_size == 0) { - // clear data register before we read it - RETURN_ON_ERROR( esp_loader_write_register(s_reg->w0, 0) ); - } else { - uint32_t *data = (uint32_t *)data_tx; - uint32_t words_to_write = (tx_size + 31) / (8 * 4); - uint32_t data_reg_addr = s_reg->w0; - - while (words_to_write--) { - uint32_t word = *data++; - RETURN_ON_ERROR( esp_loader_write_register(data_reg_addr, word) ); - data_reg_addr += 4; - } - } - - RETURN_ON_ERROR( esp_loader_write_register(s_reg->cmd, SPI_CMD_USR) ); - - uint32_t trials = 10; - while (trials--) { - uint32_t cmd_reg; - RETURN_ON_ERROR( esp_loader_read_register(s_reg->cmd, &cmd_reg) ); - if ((cmd_reg & SPI_CMD_USR) == 0) { - break; - } - } - - if (trials == 0) { - return ESP_LOADER_ERROR_TIMEOUT; - } - - RETURN_ON_ERROR( esp_loader_read_register(s_reg->w0, data_rx) ); - - // Restore SPI configuration - RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr, old_spi_usr) ); - RETURN_ON_ERROR( esp_loader_write_register(s_reg->usr2, old_spi_usr2) ); - - return ESP_LOADER_SUCCESS; -} - -static esp_loader_error_t detect_flash_size(size_t *flash_size) -{ - uint32_t flash_id = 0; - - RETURN_ON_ERROR( spi_flash_command(SPI_FLASH_READ_ID, NULL, 0, &flash_id, 24) ); - uint32_t size_id = flash_id >> 16; - - if (size_id < 0x12 || size_id > 0x18) { - return ESP_LOADER_ERROR_UNSUPPORTED_CHIP; - } - - *flash_size = 1 << size_id; - - return ESP_LOADER_SUCCESS; -} - -static uint32_t calc_erase_size(const target_chip_t target, const uint32_t offset, - const uint32_t image_size) -{ - if (target != ESP8266_CHIP) { - return image_size; - } else { - /* Needed to fix a bug in the ESP8266 ROM */ - const uint32_t sectors_per_block = 16U; - const uint32_t sector_size = 4096U; - - const uint32_t num_sectors = (image_size + sector_size - 1) / sector_size; - const uint32_t start_sector = offset / sector_size; - - uint32_t head_sectors = sectors_per_block - (start_sector % sectors_per_block); - - /* The ROM bug deletes extra num_sectors if we don't cross the block boundary - and extra head_sectors if we do */ - if (num_sectors <= head_sectors) { - return ((num_sectors + 1) / 2) * sector_size; - } else { - return (num_sectors - head_sectors) * sector_size; - } - } -} - -esp_loader_error_t esp_loader_flash_start(uint32_t offset, uint32_t image_size, uint32_t block_size) -{ - s_flash_write_size = block_size; - - size_t flash_size = 0; - if (detect_flash_size(&flash_size) == ESP_LOADER_SUCCESS) { - if (image_size > flash_size) { - return ESP_LOADER_ERROR_IMAGE_SIZE; - } - loader_port_start_timer(DEFAULT_TIMEOUT); - RETURN_ON_ERROR( loader_spi_parameters(flash_size) ); - } else { - loader_port_debug_print("Flash size detection failed, falling back to default"); - } - - init_md5(offset, image_size); - - bool encryption_in_cmd = encryption_in_begin_flash_cmd(s_target); - const uint32_t erase_size = calc_erase_size(esp_loader_get_target(), offset, image_size); - const uint32_t blocks_to_write = (image_size + block_size - 1) / block_size; - - const uint32_t erase_region_timeout_per_mb = 10000; - loader_port_start_timer(timeout_per_mb(erase_size, erase_region_timeout_per_mb)); - return loader_flash_begin_cmd(offset, erase_size, block_size, blocks_to_write, encryption_in_cmd); -} - - -esp_loader_error_t esp_loader_flash_write(void *payload, uint32_t size) -{ - uint32_t padding_bytes = s_flash_write_size - size; - uint8_t *data = (uint8_t *)payload; - uint32_t padding_index = size; - - if (size > s_flash_write_size) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - const uint8_t padding_pattern = 0xFF; - while (padding_bytes--) { - data[padding_index++] = padding_pattern; - } - - md5_update(payload, (size + 3) & ~3); - - loader_port_start_timer(DEFAULT_TIMEOUT); - - return loader_flash_data_cmd(data, s_flash_write_size); -} - - -esp_loader_error_t esp_loader_flash_finish(bool reboot) -{ - loader_port_start_timer(DEFAULT_TIMEOUT); - - return loader_flash_end_cmd(!reboot); -} -#endif /* SERIAL_FLASHER_INTERFACE_UART */ - -esp_loader_error_t esp_loader_mem_start(uint32_t offset, uint32_t size, uint32_t block_size) -{ - uint32_t blocks_to_write = ROUNDUP(size, block_size); - loader_port_start_timer(timeout_per_mb(size, LOAD_RAM_TIMEOUT_PER_MB)); - return loader_mem_begin_cmd(offset, size, blocks_to_write, block_size); -} - - -esp_loader_error_t esp_loader_mem_write(const void *payload, uint32_t size) -{ - const uint8_t *data = (const uint8_t *)payload; - loader_port_start_timer(timeout_per_mb(size, LOAD_RAM_TIMEOUT_PER_MB)); - return loader_mem_data_cmd(data, size); -} - - -esp_loader_error_t esp_loader_mem_finish(uint32_t entrypoint) -{ - loader_port_start_timer(DEFAULT_TIMEOUT); - return loader_mem_end_cmd(entrypoint); -} - - -esp_loader_error_t esp_loader_read_register(uint32_t address, uint32_t *reg_value) -{ - loader_port_start_timer(DEFAULT_TIMEOUT); - - return loader_read_reg_cmd(address, reg_value); -} - - -esp_loader_error_t esp_loader_write_register(uint32_t address, uint32_t reg_value) -{ - loader_port_start_timer(DEFAULT_TIMEOUT); - - return loader_write_reg_cmd(address, reg_value, 0xFFFFFFFF, 0); -} - -esp_loader_error_t esp_loader_change_transmission_rate(uint32_t transmission_rate) -{ - if (s_target == ESP8266_CHIP) { - return ESP_LOADER_ERROR_UNSUPPORTED_FUNC; - } - - loader_port_start_timer(DEFAULT_TIMEOUT); - - return loader_change_baudrate_cmd(transmission_rate); -} - -#if MD5_ENABLED - -static void hexify(const uint8_t raw_md5[16], uint8_t hex_md5_out[32]) -{ - static const uint8_t dec_to_hex[] = { - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' - }; - for (int i = 0; i < 16; i++) { - *hex_md5_out++ = dec_to_hex[raw_md5[i] >> 4]; - *hex_md5_out++ = dec_to_hex[raw_md5[i] & 0xF]; - } -} - - -esp_loader_error_t esp_loader_flash_verify(void) -{ - if (s_target == ESP8266_CHIP) { - return ESP_LOADER_ERROR_UNSUPPORTED_FUNC; - } - - uint8_t raw_md5[16] = {0}; - - /* Zero termination and new line character require 2 bytes */ - uint8_t hex_md5[MD5_SIZE + 2] = {0}; - uint8_t received_md5[MD5_SIZE + 2] = {0}; - - md5_final(raw_md5); - hexify(raw_md5, hex_md5); - - loader_port_start_timer(timeout_per_mb(s_image_size, MD5_TIMEOUT_PER_MB)); - - RETURN_ON_ERROR( loader_md5_cmd(s_start_address, s_image_size, received_md5) ); - - bool md5_match = memcmp(hex_md5, received_md5, MD5_SIZE) == 0; - - if (!md5_match) { - hex_md5[MD5_SIZE] = '\n'; - received_md5[MD5_SIZE] = '\n'; - - loader_port_debug_print("Error: MD5 checksum does not match:\n"); - loader_port_debug_print("Expected:\n"); - loader_port_debug_print((char *)received_md5); - loader_port_debug_print("Actual:\n"); - loader_port_debug_print((char *)hex_md5); - - return ESP_LOADER_ERROR_INVALID_MD5; - } - - return ESP_LOADER_SUCCESS; -} - -#endif - -void esp_loader_reset_target(void) -{ - loader_port_reset_target(); -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_targets.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_targets.c deleted file mode 100644 index 8764d2369f..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/esp_targets.c +++ /dev/null @@ -1,263 +0,0 @@ -/* Copyright 2020 Espressif Systems (Shanghai) PTE LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "esp_targets.h" -#include - -#define MAX_MAGIC_VALUES 2 - -typedef esp_loader_error_t (*read_spi_config_t)(uint32_t efuse_base, uint32_t *spi_config); - -typedef struct { - target_registers_t regs; - uint32_t efuse_base; - uint32_t chip_magic_value[MAX_MAGIC_VALUES]; - read_spi_config_t read_spi_config; - bool encryption_in_begin_flash_cmd; -} esp_target_t; - -// This ROM address has a different value on each chip model -#define CHIP_DETECT_MAGIC_REG_ADDR 0x40001000 - -#define ESP8266_SPI_REG_BASE 0x60000200 -#define ESP32S2_SPI_REG_BASE 0x3f402000 -#define ESP32xx_SPI_REG_BASE 0x60002000 -#define ESP32_SPI_REG_BASE 0x3ff42000 - -static esp_loader_error_t spi_config_esp32(uint32_t efuse_base, uint32_t *spi_config); -static esp_loader_error_t spi_config_esp32xx(uint32_t efuse_base, uint32_t *spi_config); - -static const esp_target_t esp_target[ESP_MAX_CHIP] = { - - // ESP8266 - { - .regs = { - .cmd = ESP8266_SPI_REG_BASE + 0x00, - .usr = ESP8266_SPI_REG_BASE + 0x1c, - .usr1 = ESP8266_SPI_REG_BASE + 0x20, - .usr2 = ESP8266_SPI_REG_BASE + 0x24, - .w0 = ESP8266_SPI_REG_BASE + 0x40, - .mosi_dlen = 0, - .miso_dlen = 0, - }, - .efuse_base = 0, // Not used - .chip_magic_value = { 0xfff0c101, 0 }, - .read_spi_config = NULL, // Not used - }, - - // ESP32 - { - .regs = { - .cmd = ESP32_SPI_REG_BASE + 0x00, - .usr = ESP32_SPI_REG_BASE + 0x1c, - .usr1 = ESP32_SPI_REG_BASE + 0x20, - .usr2 = ESP32_SPI_REG_BASE + 0x24, - .w0 = ESP32_SPI_REG_BASE + 0x80, - .mosi_dlen = ESP32_SPI_REG_BASE + 0x28, - .miso_dlen = ESP32_SPI_REG_BASE + 0x2c, - }, - .efuse_base = 0x3ff5A000, - .chip_magic_value = { 0x00f01d83, 0 }, - .read_spi_config = spi_config_esp32, - }, - - // ESP32S2 - { - .regs = { - .cmd = ESP32S2_SPI_REG_BASE + 0x00, - .usr = ESP32S2_SPI_REG_BASE + 0x18, - .usr1 = ESP32S2_SPI_REG_BASE + 0x1c, - .usr2 = ESP32S2_SPI_REG_BASE + 0x20, - .w0 = ESP32S2_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32S2_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32S2_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x3f41A000, - .chip_magic_value = { 0x000007c6, 0 }, - .read_spi_config = spi_config_esp32xx, - }, - - // ESP32C3 - { - .regs = { - .cmd = ESP32xx_SPI_REG_BASE + 0x00, - .usr = ESP32xx_SPI_REG_BASE + 0x18, - .usr1 = ESP32xx_SPI_REG_BASE + 0x1c, - .usr2 = ESP32xx_SPI_REG_BASE + 0x20, - .w0 = ESP32xx_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32xx_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32xx_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x60008800, - .chip_magic_value = { 0x6921506f, 0x1b31506f }, - .read_spi_config = spi_config_esp32xx, - }, - - // ESP32S3 - { - .regs = { - .cmd = ESP32xx_SPI_REG_BASE + 0x00, - .usr = ESP32xx_SPI_REG_BASE + 0x18, - .usr1 = ESP32xx_SPI_REG_BASE + 0x1c, - .usr2 = ESP32xx_SPI_REG_BASE + 0x20, - .w0 = ESP32xx_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32xx_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32xx_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x60007000, - .chip_magic_value = { 0x00000009, 0 }, - .read_spi_config = spi_config_esp32xx, - }, - - // ESP32C2 - { - .regs = { - .cmd = ESP32xx_SPI_REG_BASE + 0x00, - .usr = ESP32xx_SPI_REG_BASE + 0x18, - .usr1 = ESP32xx_SPI_REG_BASE + 0x1c, - .usr2 = ESP32xx_SPI_REG_BASE + 0x20, - .w0 = ESP32xx_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32xx_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32xx_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x60008800, - .chip_magic_value = { 0x6f51306f, 0x7c41a06f }, - .read_spi_config = spi_config_esp32xx, - }, - // ESP32H4 - { - .regs = { - .cmd = ESP32xx_SPI_REG_BASE + 0x00, - .usr = ESP32xx_SPI_REG_BASE + 0x18, - .usr1 = ESP32xx_SPI_REG_BASE + 0x1c, - .usr2 = ESP32xx_SPI_REG_BASE + 0x20, - .w0 = ESP32xx_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32xx_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32xx_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x6001A000, - .chip_magic_value = {0xca26cc22, 0x6881b06f}, // ESP32H4-BETA1, ESP32H4-BETA2 - .read_spi_config = spi_config_esp32xx, - }, - // ESP32H2 - { - .regs = { - .cmd = ESP32xx_SPI_REG_BASE + 0x00, - .usr = ESP32xx_SPI_REG_BASE + 0x18, - .usr1 = ESP32xx_SPI_REG_BASE + 0x1c, - .usr2 = ESP32xx_SPI_REG_BASE + 0x20, - .w0 = ESP32xx_SPI_REG_BASE + 0x58, - .mosi_dlen = ESP32xx_SPI_REG_BASE + 0x24, - .miso_dlen = ESP32xx_SPI_REG_BASE + 0x28, - }, - .efuse_base = 0x6001A000, - .chip_magic_value = {0xd7b73e80, 0}, - .read_spi_config = spi_config_esp32xx, - }, -}; - -const target_registers_t *get_esp_target_data(target_chip_t chip) -{ - return (const target_registers_t *)&esp_target[chip]; -} - -esp_loader_error_t loader_detect_chip(target_chip_t *target_chip, const target_registers_t **target_data) -{ - uint32_t magic_value; - RETURN_ON_ERROR( esp_loader_read_register(CHIP_DETECT_MAGIC_REG_ADDR, &magic_value) ); - - for (int chip = 0; chip < ESP_MAX_CHIP; chip++) { - for(int index = 0; index < MAX_MAGIC_VALUES; index++) { - if (magic_value == esp_target[chip].chip_magic_value[index]) { - *target_chip = (target_chip_t)chip; - *target_data = (target_registers_t *)&esp_target[chip]; - return ESP_LOADER_SUCCESS; - } - } - } - - return ESP_LOADER_ERROR_INVALID_TARGET; -} - -esp_loader_error_t loader_read_spi_config(target_chip_t target_chip, uint32_t *spi_config) -{ - const esp_target_t *target = &esp_target[target_chip]; - return target->read_spi_config(target->efuse_base, spi_config); -} - -static inline uint32_t efuse_word_addr(uint32_t efuse_base, uint32_t n) -{ - return efuse_base + (n * 4); -} - -// 30->GPIO32 | 31->GPIO33 -static inline uint8_t adjust_pin_number(uint8_t num) -{ - return (num >= 30) ? num + 2 : num; -} - - -static esp_loader_error_t spi_config_esp32(uint32_t efuse_base, uint32_t *spi_config) -{ - *spi_config = 0; - - uint32_t reg5, reg3; - RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 5), ®5) ); - RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 3), ®3) ); - - uint32_t pins = reg5 & 0xfffff; - - if (pins == 0 || pins == 0xfffff) { - return ESP_LOADER_SUCCESS; - } - - uint8_t clk = adjust_pin_number( (pins >> 0) & 0x1f ); - uint8_t q = adjust_pin_number( (pins >> 5) & 0x1f ); - uint8_t d = adjust_pin_number( (pins >> 10) & 0x1f ); - uint8_t cs = adjust_pin_number( (pins >> 15) & 0x1f ); - uint8_t hd = adjust_pin_number( (reg3 >> 4) & 0x1f ); - - if (clk == cs || clk == d || clk == q || q == cs || q == d || q == d) { - return ESP_LOADER_SUCCESS; - } - - *spi_config = (hd << 24) | (cs << 18) | (d << 12) | (q << 6) | clk; - - return ESP_LOADER_SUCCESS; -} - -// Applies for esp32s2, esp32c3 and esp32c3 -static esp_loader_error_t spi_config_esp32xx(uint32_t efuse_base, uint32_t *spi_config) -{ - *spi_config = 0; - - uint32_t reg1, reg2; - RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 18), ®1) ); - RETURN_ON_ERROR( esp_loader_read_register(efuse_word_addr(efuse_base, 19), ®2) ); - - uint32_t pins = ((reg1 >> 16) | ((reg2 & 0xfffff) << 16)) & 0x3fffffff; - - if (pins == 0 || pins == 0xffffffff) { - return ESP_LOADER_SUCCESS; - } - - *spi_config = pins; - return ESP_LOADER_SUCCESS; -} - -bool encryption_in_begin_flash_cmd(target_chip_t target) -{ - return target == ESP32_CHIP || target == ESP8266_CHIP; -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/md5_hash.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/md5_hash.c deleted file mode 100644 index 4da76bcb51..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/md5_hash.c +++ /dev/null @@ -1,262 +0,0 @@ -/* - * MD5 hash implementation and interface functions - * Copyright (c) 2003-2005, Jouni Malinen - * - * This software may be distributed under the terms of the BSD license. - * See README for more details. - */ - - -#include "md5_hash.h" -#include -#include - - -static void MD5Transform(uint32_t buf[4], uint32_t const in[16]); - - -/* ===== start - public domain MD5 implementation ===== */ -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to MD5Init, call MD5Update as - * needed on buffers full of bytes, and then call MD5Final, which - * will fill a supplied 16-byte array with the digest. - */ - -#ifndef WORDS_BIGENDIAN -#define byteReverse(buf, len) /* Nothing */ -#else -/* - * Note: this code is harmless on little-endian machines. - */ -static void byteReverse(unsigned char *buf, unsigned longs) -{ - uint32_t t; - do { - t = (uint32_t) ((unsigned) buf[3] << 8 | buf[2]) << 16 | - ((unsigned) buf[1] << 8 | buf[0]); - *(uint32_t *) buf = t; - buf += 4; - } while (--longs); -} -#endif - -/* - * Start MD5 accumulation. Set bit count to 0 and buffer to mysterious - * initialization constants. - */ -void MD5Init(struct MD5Context *ctx) -{ - ctx->buf[0] = 0x67452301; - ctx->buf[1] = 0xefcdab89; - ctx->buf[2] = 0x98badcfe; - ctx->buf[3] = 0x10325476; - - ctx->bits[0] = 0; - ctx->bits[1] = 0; -} - -/* - * Update context to reflect the concatenation of another buffer full - * of bytes. - */ -void MD5Update(struct MD5Context *ctx, unsigned char const *buf, unsigned len) -{ - uint32_t t; - - /* Update bitcount */ - - t = ctx->bits[0]; - if ((ctx->bits[0] = t + ((uint32_t) len << 3)) < t) { - ctx->bits[1]++; /* Carry from low to high */ - } - ctx->bits[1] += len >> 29; - - t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ - - /* Handle any leading odd-sized chunks */ - - if (t) { - unsigned char *p = (unsigned char *) ctx->in + t; - - t = 64 - t; - if (len < t) { - memcpy(p, buf, len); - return; - } - memcpy(p, buf, t); - byteReverse(ctx->in, 16); - MD5Transform((uint32_t *)ctx->buf, (uint32_t *) ctx->in); - buf += t; - len -= t; - } - /* Process data in 64-byte chunks */ - - while (len >= 64) { - memcpy(ctx->in, buf, 64); - byteReverse(ctx->in, 16); - MD5Transform((uint32_t *)ctx->buf, (uint32_t *) ctx->in); - buf += 64; - len -= 64; - } - - /* Handle any remaining bytes of data. */ - - memcpy(ctx->in, buf, len); -} - -/* - * Final wrapup - pad to 64-byte boundary with the bit pattern - * 1 0* (64-bit count of bits processed, MSB-first) - */ -void MD5Final(unsigned char digest[16], struct MD5Context *ctx) -{ - unsigned count; - unsigned char *p; - - /* Compute number of bytes mod 64 */ - count = (ctx->bits[0] >> 3) & 0x3F; - - /* Set the first char of padding to 0x80. This is safe since there is - always at least one byte free */ - p = ctx->in + count; - *p++ = 0x80; - - /* Bytes of padding needed to make 64 bytes */ - count = 64 - 1 - count; - - /* Pad out to 56 mod 64 */ - if (count < 8) { - /* Two lots of padding: Pad the first block to 64 bytes */ - memset(p, 0, count); - byteReverse(ctx->in, 16); - MD5Transform((uint32_t *)ctx->buf, (uint32_t *) ctx->in); - - /* Now fill the next block with 56 bytes */ - memset(ctx->in, 0, 56); - } else { - /* Pad block to 56 bytes */ - memset(p, 0, count - 8); - } - byteReverse(ctx->in, 14); - - /* Append length in bits and transform */ - ((uint32_t *) ctx->in)[14] = ctx->bits[0]; - ((uint32_t *) ctx->in)[15] = ctx->bits[1]; - - MD5Transform((uint32_t *)ctx->buf, (uint32_t *) ctx->in); - byteReverse((unsigned char *) ctx->buf, 4); - memcpy(digest, ctx->buf, 16); - memset(ctx, 0, sizeof(struct MD5Context)); /* In case it's sensitive */ -} - -/* The four core functions - F1 is optimized somewhat */ - -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -/* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f, w, x, y, z, data, s) \ - ( w += f(x, y, z) + data, w = w<>(32-s), w += x ) - -/* - * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. MD5Update blocks - * the data and converts bytes into longwords for this routine. - */ -static void MD5Transform(uint32_t buf[4], uint32_t const in[16]) -{ - register uint32_t a, b, c, d; - - a = buf[0]; - b = buf[1]; - c = buf[2]; - d = buf[3]; - - MD5STEP(F1, a, b, c, d, in[0] + 0xd76aa478, 7); - MD5STEP(F1, d, a, b, c, in[1] + 0xe8c7b756, 12); - MD5STEP(F1, c, d, a, b, in[2] + 0x242070db, 17); - MD5STEP(F1, b, c, d, a, in[3] + 0xc1bdceee, 22); - MD5STEP(F1, a, b, c, d, in[4] + 0xf57c0faf, 7); - MD5STEP(F1, d, a, b, c, in[5] + 0x4787c62a, 12); - MD5STEP(F1, c, d, a, b, in[6] + 0xa8304613, 17); - MD5STEP(F1, b, c, d, a, in[7] + 0xfd469501, 22); - MD5STEP(F1, a, b, c, d, in[8] + 0x698098d8, 7); - MD5STEP(F1, d, a, b, c, in[9] + 0x8b44f7af, 12); - MD5STEP(F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP(F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP(F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP(F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP(F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP(F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP(F2, a, b, c, d, in[1] + 0xf61e2562, 5); - MD5STEP(F2, d, a, b, c, in[6] + 0xc040b340, 9); - MD5STEP(F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP(F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); - MD5STEP(F2, a, b, c, d, in[5] + 0xd62f105d, 5); - MD5STEP(F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP(F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP(F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); - MD5STEP(F2, a, b, c, d, in[9] + 0x21e1cde6, 5); - MD5STEP(F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP(F2, c, d, a, b, in[3] + 0xf4d50d87, 14); - MD5STEP(F2, b, c, d, a, in[8] + 0x455a14ed, 20); - MD5STEP(F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP(F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); - MD5STEP(F2, c, d, a, b, in[7] + 0x676f02d9, 14); - MD5STEP(F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP(F3, a, b, c, d, in[5] + 0xfffa3942, 4); - MD5STEP(F3, d, a, b, c, in[8] + 0x8771f681, 11); - MD5STEP(F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP(F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP(F3, a, b, c, d, in[1] + 0xa4beea44, 4); - MD5STEP(F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); - MD5STEP(F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); - MD5STEP(F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP(F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP(F3, d, a, b, c, in[0] + 0xeaa127fa, 11); - MD5STEP(F3, c, d, a, b, in[3] + 0xd4ef3085, 16); - MD5STEP(F3, b, c, d, a, in[6] + 0x04881d05, 23); - MD5STEP(F3, a, b, c, d, in[9] + 0xd9d4d039, 4); - MD5STEP(F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP(F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP(F3, b, c, d, a, in[2] + 0xc4ac5665, 23); - - MD5STEP(F4, a, b, c, d, in[0] + 0xf4292244, 6); - MD5STEP(F4, d, a, b, c, in[7] + 0x432aff97, 10); - MD5STEP(F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP(F4, b, c, d, a, in[5] + 0xfc93a039, 21); - MD5STEP(F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP(F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); - MD5STEP(F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP(F4, b, c, d, a, in[1] + 0x85845dd1, 21); - MD5STEP(F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); - MD5STEP(F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP(F4, c, d, a, b, in[6] + 0xa3014314, 15); - MD5STEP(F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP(F4, a, b, c, d, in[4] + 0xf7537e82, 6); - MD5STEP(F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP(F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); - MD5STEP(F4, b, c, d, a, in[9] + 0xeb86d391, 21); - - buf[0] += a; - buf[1] += b; - buf[2] += c; - buf[3] += d; -} -/* ===== end - public domain MD5 implementation ===== */ diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_common.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_common.c deleted file mode 100644 index 8d1d9dd530..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_common.c +++ /dev/null @@ -1,301 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "protocol.h" -#include "protocol_prv.h" -#include "esp_loader_io.h" -#include -#include - -#define CMD_SIZE(cmd) ( sizeof(cmd) - sizeof(command_common_t) ) - -static uint32_t s_sequence_number = 0; - -static uint8_t compute_checksum(const uint8_t *data, uint32_t size) -{ - uint8_t checksum = 0xEF; - - while (size--) { - checksum ^= *data++; - } - - return checksum; -} - -void log_loader_internal_error(error_code_t error) -{ - loader_port_debug_print("Error: "); - - switch (error) { - case INVALID_CRC: loader_port_debug_print("INVALID_CRC"); break; - case INVALID_COMMAND: loader_port_debug_print("INVALID_COMMAND"); break; - case COMMAND_FAILED: loader_port_debug_print("COMMAND_FAILED"); break; - case FLASH_WRITE_ERR: loader_port_debug_print("FLASH_WRITE_ERR"); break; - case FLASH_READ_ERR: loader_port_debug_print("FLASH_READ_ERR"); break; - case READ_LENGTH_ERR: loader_port_debug_print("READ_LENGTH_ERR"); break; - case DEFLATE_ERROR: loader_port_debug_print("DEFLATE_ERROR"); break; - default: loader_port_debug_print("UNKNOWN ERROR"); break; - } - - loader_port_debug_print("\n"); -} - - -esp_loader_error_t loader_flash_begin_cmd(uint32_t offset, - uint32_t erase_size, - uint32_t block_size, - uint32_t blocks_to_write, - bool encryption) -{ - uint32_t encryption_size = encryption ? sizeof(uint32_t) : 0; - - flash_begin_command_t flash_begin_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = FLASH_BEGIN, - .size = CMD_SIZE(flash_begin_cmd) - encryption_size, - .checksum = 0 - }, - .erase_size = erase_size, - .packet_count = blocks_to_write, - .packet_size = block_size, - .offset = offset, - .encrypted = 0 - }; - - s_sequence_number = 0; - - return send_cmd(&flash_begin_cmd, sizeof(flash_begin_cmd) - encryption_size, NULL); -} - - -esp_loader_error_t loader_flash_data_cmd(const uint8_t *data, uint32_t size) -{ - data_command_t data_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = FLASH_DATA, - .size = CMD_SIZE(data_cmd) + size, - .checksum = compute_checksum(data, size) - }, - .data_size = size, - .sequence_number = s_sequence_number++, - }; - - return send_cmd_with_data(&data_cmd, sizeof(data_cmd), data, size); -} - - -esp_loader_error_t loader_flash_end_cmd(bool stay_in_loader) -{ - flash_end_command_t end_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = FLASH_END, - .size = CMD_SIZE(end_cmd), - .checksum = 0 - }, - .stay_in_loader = stay_in_loader - }; - - return send_cmd(&end_cmd, sizeof(end_cmd), NULL); -} - - -esp_loader_error_t loader_mem_begin_cmd(uint32_t offset, uint32_t size, uint32_t blocks_to_write, uint32_t block_size) -{ - - mem_begin_command_t mem_begin_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = MEM_BEGIN, - .size = CMD_SIZE(mem_begin_cmd), - .checksum = 0 - }, - .total_size = size, - .blocks = blocks_to_write, - .block_size = block_size, - .offset = offset - }; - - s_sequence_number = 0; - - return send_cmd(&mem_begin_cmd, sizeof(mem_begin_cmd), NULL); -} - - -esp_loader_error_t loader_mem_data_cmd(const uint8_t *data, uint32_t size) -{ - data_command_t data_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = MEM_DATA, - .size = CMD_SIZE(data_cmd) + size, - .checksum = compute_checksum(data, size) - }, - .data_size = size, - .sequence_number = s_sequence_number++, - }; - return send_cmd_with_data(&data_cmd, sizeof(data_cmd), data, size); -} - -esp_loader_error_t loader_mem_end_cmd(uint32_t entrypoint) -{ - mem_end_command_t end_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = MEM_END, - .size = CMD_SIZE(end_cmd), - }, - .stay_in_loader = (entrypoint == 0), - .entry_point_address = entrypoint - }; - - return send_cmd(&end_cmd, sizeof(end_cmd), NULL); -} - - -esp_loader_error_t loader_sync_cmd(void) -{ - sync_command_t sync_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = SYNC, - .size = CMD_SIZE(sync_cmd), - .checksum = 0 - }, - .sync_sequence = { - 0x07, 0x07, 0x12, 0x20, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, - } - }; - - return send_cmd(&sync_cmd, sizeof(sync_cmd), NULL); -} - - -esp_loader_error_t loader_write_reg_cmd(uint32_t address, uint32_t value, - uint32_t mask, uint32_t delay_us) -{ - write_reg_command_t write_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = WRITE_REG, - .size = CMD_SIZE(write_cmd), - .checksum = 0 - }, - .address = address, - .value = value, - .mask = mask, - .delay_us = delay_us - }; - - return send_cmd(&write_cmd, sizeof(write_cmd), NULL); -} - - -esp_loader_error_t loader_read_reg_cmd(uint32_t address, uint32_t *reg) -{ - read_reg_command_t read_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = READ_REG, - .size = CMD_SIZE(read_cmd), - .checksum = 0 - }, - .address = address, - }; - - return send_cmd(&read_cmd, sizeof(read_cmd), reg); -} - - -esp_loader_error_t loader_spi_attach_cmd(uint32_t config) -{ - spi_attach_command_t attach_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = SPI_ATTACH, - .size = CMD_SIZE(attach_cmd), - .checksum = 0 - }, - .configuration = config, - .zero = 0 - }; - - return send_cmd(&attach_cmd, sizeof(attach_cmd), NULL); -} - -esp_loader_error_t loader_change_baudrate_cmd(uint32_t baudrate) -{ - change_baudrate_command_t baudrate_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = CHANGE_BAUDRATE, - .size = CMD_SIZE(baudrate_cmd), - .checksum = 0 - }, - .new_baudrate = baudrate, - .old_baudrate = 0 // ESP32 ROM only - }; - - return send_cmd(&baudrate_cmd, sizeof(baudrate_cmd), NULL); -} - -esp_loader_error_t loader_md5_cmd(uint32_t address, uint32_t size, uint8_t *md5_out) -{ - spi_flash_md5_command_t md5_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = SPI_FLASH_MD5, - .size = CMD_SIZE(md5_cmd), - .checksum = 0 - }, - .address = address, - .size = size, - .reserved_0 = 0, - .reserved_1 = 0 - }; - - return send_cmd_md5(&md5_cmd, sizeof(md5_cmd), md5_out); -} - -esp_loader_error_t loader_spi_parameters(uint32_t total_size) -{ - write_spi_command_t spi_cmd = { - .common = { - .direction = WRITE_DIRECTION, - .command = SPI_SET_PARAMS, - .size = 24, - .checksum = 0 - }, - .id = 0, - .total_size = total_size, - .block_size = 64 * 1024, - .sector_size = 4 * 1024, - .page_size = 0x100, - .status_mask = 0xFFFF, - }; - - return send_cmd(&spi_cmd, sizeof(spi_cmd), NULL); -} - -__attribute__ ((weak)) void loader_port_debug_print(const char *str) -{ - (void)(str); -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_spi.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_spi.c deleted file mode 100644 index bd04fe79f2..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_spi.c +++ /dev/null @@ -1,312 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "protocol.h" -#include "protocol_prv.h" -#include "esp_loader_io.h" -#include -#include - -typedef struct __attribute__((packed)) { - uint8_t cmd; - uint8_t addr; - uint8_t dummy; -} transaction_preamble_t; - -typedef enum { - TRANS_CMD_WRBUF = 0x01, - TRANS_CMD_RDBUF = 0x02, - TRANS_CMD_WRDMA = 0x03, - TRANS_CMD_RDDMA = 0x04, - TRANS_CMD_SEG_DONE = 0x05, - TRANS_CMD_ENQPI = 0x06, - TRANS_CMD_WR_DONE = 0x07, - TRANS_CMD_CMD8 = 0x08, - TRANS_CMD_CMD9 = 0x09, - TRANS_CMD_CMDA = 0x0A, - TRANS_CMD_EXQPI = 0xDD, -} transaction_cmd_t; - -/* Slave protocol registers */ -typedef enum { - SLAVE_REGISTER_VER = 0, - SLAVE_REGISTER_RXSTA = 4, - SLAVE_REGISTER_TXSTA = 8, - SLAVE_REGISTER_CMD = 12, -} slave_register_addr_t; - -#define SLAVE_STA_TOGGLE_BIT (0x01U << 0) -#define SLAVE_STA_INIT_BIT (0x01U << 1) -#define SLAVE_STA_BUF_LENGTH_POS 2U - -typedef enum { - SLAVE_STATE_INIT = SLAVE_STA_TOGGLE_BIT | SLAVE_STA_INIT_BIT, - SLAVE_STATE_FIRST_PACKET = SLAVE_STA_INIT_BIT, -} slave_state_t; - -typedef enum { - /* Target to host */ - SLAVE_CMD_IDLE = 0xAA, - SLAVE_CMD_READY = 0xA5, - /* Host to target */ - SLAVE_CMD_REBOOT = 0xFE, - SLAVE_CMD_COMM_REINIT = 0x5A, - SLAVE_CMD_DONE = 0x55, -} slave_cmd_t; - -static uint8_t s_slave_seq_tx; -static uint8_t s_slave_seq_rx; - -static esp_loader_error_t write_slave_reg(const uint8_t *data, const uint32_t addr, - const uint8_t size); -static esp_loader_error_t read_slave_reg(uint8_t *out_data, const uint32_t addr, - const uint8_t size); -static esp_loader_error_t handle_slave_state(const uint32_t status_reg_addr, uint8_t *seq_state, - bool *slave_ready, uint32_t *buf_size); -static esp_loader_error_t check_response(command_t cmd, uint32_t *reg_value); - -esp_loader_error_t loader_initialize_conn(esp_loader_connect_args_t *connect_args) -{ - for (uint8_t trial = 0; trial < connect_args->trials; trial++) { - uint8_t slave_ready_flag; - RETURN_ON_ERROR(read_slave_reg(&slave_ready_flag, SLAVE_REGISTER_CMD, - sizeof(slave_ready_flag))); - - if (slave_ready_flag != SLAVE_CMD_IDLE) { - loader_port_debug_print("Waiting for Slave to be idle...\n"); - loader_port_delay_ms(100); - } else { - break; - } - } - - const uint8_t reg_val = SLAVE_CMD_READY; - RETURN_ON_ERROR(write_slave_reg(®_val, SLAVE_REGISTER_CMD, sizeof(reg_val))); - - for (uint8_t trial = 0; trial < connect_args->trials; trial++) { - uint8_t slave_ready_flag; - RETURN_ON_ERROR(read_slave_reg(&slave_ready_flag, SLAVE_REGISTER_CMD, - sizeof(slave_ready_flag))); - - if (slave_ready_flag != SLAVE_CMD_READY) { - loader_port_debug_print("Waiting for Slave to be ready...\n"); - loader_port_delay_ms(100); - } else { - break; - } - } - - return ESP_LOADER_SUCCESS; -} - - -esp_loader_error_t send_cmd(const void *cmd_data, uint32_t size, uint32_t *reg_value) -{ - command_t command = ((const command_common_t *)cmd_data)->command; - - uint32_t buf_size; - bool slave_ready = false; - while (!slave_ready) { - RETURN_ON_ERROR(handle_slave_state(SLAVE_REGISTER_RXSTA, &s_slave_seq_rx, &slave_ready, - &buf_size)); - } - - if (size > buf_size) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - /* Start and write the command */ - transaction_preamble_t preamble = {.cmd = TRANS_CMD_WRDMA}; - - loader_port_spi_set_cs(0); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)cmd_data, size, - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - /* Terminate the write */ - loader_port_spi_set_cs(0); - preamble.cmd = TRANS_CMD_WR_DONE; - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - return check_response(command, reg_value); -} - - -esp_loader_error_t send_cmd_with_data(const void *cmd_data, size_t cmd_size, - const void *data, size_t data_size) -{ - uint32_t buf_size; - bool slave_ready = false; - while (!slave_ready) { - RETURN_ON_ERROR(handle_slave_state(SLAVE_REGISTER_RXSTA, &s_slave_seq_rx, &slave_ready, - &buf_size)); - } - - if (cmd_size + data_size > buf_size) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - /* Start and write the command and the data */ - transaction_preamble_t preamble = {.cmd = TRANS_CMD_WRDMA}; - - loader_port_spi_set_cs(0); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)cmd_data, cmd_size, - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)data, data_size, - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - /* Terminate the write */ - loader_port_spi_set_cs(0); - preamble.cmd = TRANS_CMD_WR_DONE; - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - command_t command = ((const command_common_t *)cmd_data)->command; - return check_response(command, NULL); -} - - -static esp_loader_error_t read_slave_reg(uint8_t *out_data, const uint32_t addr, - const uint8_t size) -{ - transaction_preamble_t preamble = { - .cmd = TRANS_CMD_RDBUF, - .addr = addr, - }; - - loader_port_spi_set_cs(0); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_read(out_data, size, loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - return ESP_LOADER_SUCCESS; -} - - -static esp_loader_error_t write_slave_reg(const uint8_t *data, const uint32_t addr, - const uint8_t size) -{ - transaction_preamble_t preamble = { - .cmd = TRANS_CMD_WRBUF, - .addr = addr, - }; - - loader_port_spi_set_cs(0); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_write(data, size, loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - return ESP_LOADER_SUCCESS; -} - - -static esp_loader_error_t handle_slave_state(const uint32_t status_reg_addr, uint8_t *seq_state, - bool *slave_ready, uint32_t *buf_size) -{ - uint32_t status_reg; - RETURN_ON_ERROR(read_slave_reg((uint8_t *)&status_reg, status_reg_addr, - sizeof(status_reg))); - const slave_state_t state = status_reg & (SLAVE_STA_TOGGLE_BIT | SLAVE_STA_INIT_BIT); - - switch(state) { - case SLAVE_STATE_INIT: { - const uint32_t initial = 0U; - RETURN_ON_ERROR(write_slave_reg((uint8_t *)&initial, status_reg_addr, sizeof(initial))); - break; - } - - case SLAVE_STATE_FIRST_PACKET: { - *seq_state = state & SLAVE_STA_TOGGLE_BIT; - *buf_size = status_reg >> SLAVE_STA_BUF_LENGTH_POS; - *slave_ready = true; - break; - } - - default: { - const uint8_t new_seq = state & SLAVE_STA_TOGGLE_BIT; - if (new_seq != *seq_state) { - *seq_state = new_seq; - *buf_size = status_reg >> SLAVE_STA_BUF_LENGTH_POS; - *slave_ready = true; - } - break; - } - } - - return ESP_LOADER_SUCCESS; -} - - -static esp_loader_error_t check_response(command_t cmd, uint32_t *reg_value) -{ - response_t resp; - - uint32_t buf_size; - bool slave_ready = false; - while (!slave_ready) { - RETURN_ON_ERROR(handle_slave_state(SLAVE_REGISTER_TXSTA, &s_slave_seq_tx, &slave_ready, - &buf_size)); - } - - if (sizeof(resp) > buf_size) { - return ESP_LOADER_ERROR_INVALID_PARAM; - } - - transaction_preamble_t preamble = { - .cmd = TRANS_CMD_RDDMA, - }; - - loader_port_spi_set_cs(0); - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - RETURN_ON_ERROR(loader_port_read((uint8_t *)&resp, sizeof(resp), - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - /* Terminate the read */ - loader_port_spi_set_cs(0); - preamble.cmd = TRANS_CMD_CMD8; - RETURN_ON_ERROR(loader_port_write((const uint8_t *)&preamble, sizeof(preamble), - loader_port_remaining_time())); - loader_port_spi_set_cs(1); - - common_response_t *common = (common_response_t *)&resp; - if ((common->direction != READ_DIRECTION) || (common->command != cmd)) { - return ESP_LOADER_ERROR_INVALID_RESPONSE; - } - - response_status_t *status = - (response_status_t *)((uint8_t *)&resp + sizeof(resp) - sizeof(response_status_t)); - if (status->failed) { - log_loader_internal_error(status->error); - return ESP_LOADER_ERROR_INVALID_RESPONSE; - } - - if (reg_value != NULL) { - *reg_value = common->value; - } - - return ESP_LOADER_SUCCESS; -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_uart.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_uart.c deleted file mode 100644 index c5a51cec6a..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/protocol_uart.c +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "protocol.h" -#include "protocol_prv.h" -#include "esp_loader_io.h" -#include "slip.h" -#include -#include - -static esp_loader_error_t check_response(command_t cmd, uint32_t *reg_value, void* resp, uint32_t resp_size); - -esp_loader_error_t loader_initialize_conn(esp_loader_connect_args_t *connect_args) { - esp_loader_error_t err; - int32_t trials = connect_args->trials; - - do { - loader_port_start_timer(connect_args->sync_timeout); - err = loader_sync_cmd(); - if (err == ESP_LOADER_ERROR_TIMEOUT) { - if (--trials == 0) { - return ESP_LOADER_ERROR_TIMEOUT; - } - loader_port_delay_ms(100); - } else if (err != ESP_LOADER_SUCCESS) { - return err; - } - } while (err != ESP_LOADER_SUCCESS); - - return err; -} - -esp_loader_error_t send_cmd(const void *cmd_data, uint32_t size, uint32_t *reg_value) -{ - response_t response; - command_t command = ((const command_common_t *)cmd_data)->command; - - RETURN_ON_ERROR( SLIP_send_delimiter() ); - RETURN_ON_ERROR( SLIP_send((const uint8_t *)cmd_data, size) ); - RETURN_ON_ERROR( SLIP_send_delimiter() ); - - return check_response(command, reg_value, &response, sizeof(response)); -} - - -esp_loader_error_t send_cmd_with_data(const void *cmd_data, size_t cmd_size, - const void *data, size_t data_size) -{ - response_t response; - command_t command = ((const command_common_t *)cmd_data)->command; - - RETURN_ON_ERROR( SLIP_send_delimiter() ); - RETURN_ON_ERROR( SLIP_send((const uint8_t *)cmd_data, cmd_size) ); - RETURN_ON_ERROR( SLIP_send(data, data_size) ); - RETURN_ON_ERROR( SLIP_send_delimiter() ); - - return check_response(command, NULL, &response, sizeof(response)); -} - - -esp_loader_error_t send_cmd_md5(const void *cmd_data, size_t cmd_size, uint8_t md5_out[MD5_SIZE]) -{ - rom_md5_response_t response; - command_t command = ((const command_common_t *)cmd_data)->command; - - RETURN_ON_ERROR( SLIP_send_delimiter() ); - RETURN_ON_ERROR( SLIP_send((const uint8_t *)cmd_data, cmd_size) ); - RETURN_ON_ERROR( SLIP_send_delimiter() ); - - RETURN_ON_ERROR( check_response(command, NULL, &response, sizeof(response)) ); - - memcpy(md5_out, response.md5, MD5_SIZE); - - return ESP_LOADER_SUCCESS; -} - - -static esp_loader_error_t check_response(command_t cmd, uint32_t *reg_value, void* resp, uint32_t resp_size) -{ - esp_loader_error_t err; - common_response_t *response = (common_response_t *)resp; - - do { - err = SLIP_receive_packet(resp, resp_size); - if (err != ESP_LOADER_SUCCESS) { - return err; - } - } while ((response->direction != READ_DIRECTION) || (response->command != cmd)); - - response_status_t *status = (response_status_t *)((uint8_t *)resp + resp_size - sizeof(response_status_t)); - - if (status->failed) { - log_loader_internal_error(status->error); - return ESP_LOADER_ERROR_INVALID_RESPONSE; - } - - if (reg_value != NULL) { - *reg_value = response->value; - } - - return ESP_LOADER_SUCCESS; -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/slip.c b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/slip.c deleted file mode 100644 index ba926169c7..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/src/slip.c +++ /dev/null @@ -1,125 +0,0 @@ -/* Copyright 2020-2023 Espressif Systems (Shanghai) CO LTD - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "slip.h" -#include "esp_loader_io.h" - -static const uint8_t DELIMITER = 0xC0; -static const uint8_t C0_REPLACEMENT[2] = {0xDB, 0xDC}; -static const uint8_t DB_REPLACEMENT[2] = {0xDB, 0xDD}; - -static inline esp_loader_error_t peripheral_read(uint8_t *buff, const size_t size) -{ - return loader_port_read(buff, size, loader_port_remaining_time()); -} - -static inline esp_loader_error_t peripheral_write(const uint8_t *buff, const size_t size) -{ - return loader_port_write(buff, size, loader_port_remaining_time()); -} - -esp_loader_error_t SLIP_receive_data(uint8_t *buff, const size_t size) -{ - uint8_t ch; - - for (uint32_t i = 0; i < size; i++) { - RETURN_ON_ERROR( peripheral_read(&ch, 1) ); - - if (ch == 0xDB) { - RETURN_ON_ERROR( peripheral_read(&ch, 1) ); - if (ch == 0xDC) { - buff[i] = 0xC0; - } else if (ch == 0xDD) { - buff[i] = 0xDB; - } else { - return ESP_LOADER_ERROR_INVALID_RESPONSE; - } - } else { - buff[i] = ch; - } - } - - return ESP_LOADER_SUCCESS; -} - - -esp_loader_error_t SLIP_receive_packet(uint8_t *buff, const size_t size) -{ - uint8_t ch; - - // Wait for delimiter - do { - RETURN_ON_ERROR( peripheral_read(&ch, 1) ); - } while (ch != DELIMITER); - - // Workaround: bootloader sends two dummy(0xC0) bytes after response when baud rate is changed. - do { - RETURN_ON_ERROR( peripheral_read(&ch, 1) ); - } while (ch == DELIMITER); - - buff[0] = ch; - - RETURN_ON_ERROR( SLIP_receive_data(&buff[1], size - 1) ); - - // Wait for delimiter - do { - RETURN_ON_ERROR( peripheral_read(&ch, 1) ); - } while (ch != DELIMITER); - - return ESP_LOADER_SUCCESS; -} - - -esp_loader_error_t SLIP_send(const uint8_t *data, const size_t size) -{ - uint32_t to_write = 0; // Bytes ready to write as they are - uint32_t written = 0; // Bytes already written - - for (uint32_t i = 0; i < size; i++) { - if (data[i] != 0xC0 && data[i] != 0xDB) { - to_write++; // Queue this byte for writing - continue; - } - - // We have a byte that needs encoding, write the queue first - if (to_write > 0) { - RETURN_ON_ERROR( peripheral_write(&data[written], to_write) ); - } - - // Write the encoded byte - if (data[i] == 0xC0) { - RETURN_ON_ERROR( peripheral_write(C0_REPLACEMENT, 2) ); - } else { - RETURN_ON_ERROR( peripheral_write(DB_REPLACEMENT, 2) ); - } - - // Update to start again after the encoded byte - written = i + 1; - to_write = 0; - } - - // Write the rest of the bytes that didn't need encoding - if (to_write > 0) { - RETURN_ON_ERROR( peripheral_write(&data[written], to_write) ); - } - - return ESP_LOADER_SUCCESS; -} - - -esp_loader_error_t SLIP_send_delimiter(void) -{ - return peripheral_write(&DELIMITER, 1); -} diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/CMakeLists.txt b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/CMakeLists.txt deleted file mode 100644 index 97da4eaae7..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/CMakeLists.txt +++ /dev/null @@ -1,30 +0,0 @@ -cmake_minimum_required(VERSION 3.5) - -if (CONFIG_ESP_SERIAL_FLASHER) - zephyr_include_directories( - "${ZEPHYR_CURRENT_MODULE_DIR}/include" - "${ZEPHYR_CURRENT_MODULE_DIR}/port" - "${ZEPHYR_CURRENT_MODULE_DIR}/private_include" - ) - - zephyr_interface_library_named(esp_flasher) - - zephyr_library() - - zephyr_library_sources(${ZEPHYR_CURRENT_MODULE_DIR}/src/esp_loader.c - ${ZEPHYR_CURRENT_MODULE_DIR}/src/esp_targets.c - ${ZEPHYR_CURRENT_MODULE_DIR}/src/protocol_common.c - ${ZEPHYR_CURRENT_MODULE_DIR}/src/protocol_uart.c - ${ZEPHYR_CURRENT_MODULE_DIR}/src/slip.c - ${ZEPHYR_CURRENT_MODULE_DIR}/src/md5_hash.c - ${ZEPHYR_CURRENT_MODULE_DIR}/port/zephyr_port.c - ) - - target_compile_definitions(esp_flasher INTERFACE SERIAL_FLASHER_INTERFACE_UART) - - zephyr_library_link_libraries(esp_flasher) - - if(DEFINED MD5_ENABLED OR CONFIG_SERIAL_FLASHER_MD5_ENABLED) - target_compile_definitions(esp_flasher INTERFACE -DMD5_ENABLED=1) - endif() -endif() diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/Kconfig b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/Kconfig deleted file mode 100644 index ebb524c866..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/Kconfig +++ /dev/null @@ -1,16 +0,0 @@ -config ESP_SERIAL_FLASHER - bool "Enable ESP serial flasher library" - default y - select CONSOLE_SUBSYS - help - Select this option to enable the ESP serial flasher library. - -config ESP_SERIAL_FLASHER_UART_BUFSIZE - int "ESP Serial Flasher UART buffer size" - default 512 - help - Buffer size for UART TX and RX packets - -if ESP_SERIAL_FLASHER - rsource "../Kconfig" -endif diff --git a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/module.yml b/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/module.yml deleted file mode 100644 index 01d484fcbd..0000000000 --- a/applications/external/wifi_marauder_companion/lib/esp-serial-flasher/zephyr/module.yml +++ /dev/null @@ -1,5 +0,0 @@ -name: esp-flasher - -build: - cmake: zephyr - kconfig: zephyr/Kconfig diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_config.h b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_config.h index 402fca4796..d223af79ad 100644 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_config.h +++ b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_config.h @@ -13,4 +13,3 @@ ADD_SCENE(wifi_marauder, script_stage_edit, ScriptStageEdit) ADD_SCENE(wifi_marauder, script_stage_add, ScriptStageAdd) ADD_SCENE(wifi_marauder, script_stage_edit_list, ScriptStageEditList) ADD_SCENE(wifi_marauder, sniffpmkid_options, SniffPmkidOptions) -ADD_SCENE(wifi_marauder, flasher, Flasher) diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c index 9e1719d089..05d94fe804 100644 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c +++ b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_console_output.c @@ -1,7 +1,5 @@ #include "../wifi_marauder_app_i.h" -#include "../wifi_marauder_flasher.h" - char* _wifi_marauder_get_prefix_from_cmd(const char* command) { int end = strcspn(command, " "); char* prefix = (char*)malloc(sizeof(char) * (end + 1)); @@ -103,24 +101,13 @@ void wifi_marauder_scene_console_output_on_enter(void* context) { view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewConsoleOutput); // Register callbacks to receive data - // setup callback for general log rx thread - if(app->flash_mode) { - wifi_marauder_uart_set_handle_rx_data_cb( - app->uart, - wifi_marauder_flash_handle_rx_data_cb); // setup callback for general log rx thread - } else { - wifi_marauder_uart_set_handle_rx_data_cb( - app->uart, - wifi_marauder_console_output_handle_rx_data_cb); // setup callback for general log rx thread - } + wifi_marauder_uart_set_handle_rx_data_cb( + app->uart, + wifi_marauder_console_output_handle_rx_data_cb); // setup callback for general log rx thread wifi_marauder_uart_set_handle_rx_data_cb( app->lp_uart, wifi_marauder_console_output_handle_rx_packets_cb); // setup callback for packets rx thread - if(app->flash_mode) { - wifi_marauder_flash_start_thread(app); - } - // Get ready to send command if((app->is_command && app->selected_tx_string) || app->script) { const char* prefix = @@ -182,11 +169,6 @@ bool wifi_marauder_scene_console_output_on_event(void* context, SceneManagerEven consumed = true; } else if(event.type == SceneManagerEventTypeTick) { consumed = true; - } else { - if(app->flash_worker_busy) { - // ignore button presses while flashing - consumed = true; - } } return consumed; @@ -201,10 +183,6 @@ void wifi_marauder_scene_console_output_on_exit(void* context) { furi_delay_ms(50); } - if(app->flash_mode) { - wifi_marauder_flash_stop_thread(app); - } - // Unregister rx callback wifi_marauder_uart_set_handle_rx_data_cb(app->uart, NULL); wifi_marauder_uart_set_handle_rx_data_cb(app->lp_uart, NULL); diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_flasher.c b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_flasher.c deleted file mode 100644 index 2d6b8ea507..0000000000 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_flasher.c +++ /dev/null @@ -1,266 +0,0 @@ -#include "../wifi_marauder_app_i.h" -#include "../wifi_marauder_flasher.h" - -enum SubmenuIndex { - SubmenuIndexS3Mode, - SubmenuIndexBoot, - SubmenuIndexPart, - SubmenuIndexNvs, - SubmenuIndexBootApp0, - SubmenuIndexApp, - SubmenuIndexCustom, - SubmenuIndexFlash, -}; - -static void wifi_marauder_scene_flasher_callback(void* context, uint32_t index) { - WifiMarauderApp* app = context; - - scene_manager_set_scene_state(app->scene_manager, WifiMarauderSceneFlasher, index); - - // browse for files - FuriString* predefined_filepath = furi_string_alloc_set_str(MARAUDER_APP_FOLDER); - FuriString* selected_filepath = furi_string_alloc(); - DialogsFileBrowserOptions browser_options; - dialog_file_browser_set_basic_options(&browser_options, ".bin", &I_Text_10x10); - - // TODO refactor - switch(index) { - case SubmenuIndexS3Mode: - // toggle S3 mode - app->selected_flash_options[SelectedFlashS3Mode] = - !app->selected_flash_options[SelectedFlashS3Mode]; - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexBoot: - app->selected_flash_options[SelectedFlashBoot] = - !app->selected_flash_options[SelectedFlashBoot]; - if(app->selected_flash_options[SelectedFlashBoot]) { - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_boot, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_boot)); - } - } - if(app->bin_file_path_boot[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashBoot] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexPart: - app->selected_flash_options[SelectedFlashPart] = - !app->selected_flash_options[SelectedFlashPart]; - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_part, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_part)); - } - if(app->bin_file_path_part[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashPart] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexNvs: - app->selected_flash_options[SelectedFlashNvs] = - !app->selected_flash_options[SelectedFlashNvs]; - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_nvs, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_nvs)); - } - if(app->bin_file_path_nvs[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashNvs] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexBootApp0: - app->selected_flash_options[SelectedFlashBootApp0] = - !app->selected_flash_options[SelectedFlashBootApp0]; - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_boot_app0, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_boot_app0)); - } - if(app->bin_file_path_boot_app0[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashBootApp0] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexApp: - app->selected_flash_options[SelectedFlashApp] = - !app->selected_flash_options[SelectedFlashApp]; - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_app, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_app)); - } - if(app->bin_file_path_app[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashApp] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexCustom: - app->selected_flash_options[SelectedFlashCustom] = - !app->selected_flash_options[SelectedFlashCustom]; - if(dialog_file_browser_show( - app->dialogs, selected_filepath, predefined_filepath, &browser_options)) { - strncpy( - app->bin_file_path_custom, - furi_string_get_cstr(selected_filepath), - sizeof(app->bin_file_path_custom)); - } - if(app->bin_file_path_custom[0] == '\0') { - // if user didn't select a file, leave unselected - app->selected_flash_options[SelectedFlashCustom] = false; - } - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventRefreshSubmenu); - break; - case SubmenuIndexFlash: - // count how many options are selected - app->num_selected_flash_options = 0; - for(bool* option = &app->selected_flash_options[SelectedFlashBoot]; - option < &app->selected_flash_options[NUM_FLASH_OPTIONS]; - ++option) { - if(*option) { - ++app->num_selected_flash_options; - } - } - if(app->num_selected_flash_options) { - // only start next scene if at least one option is selected - scene_manager_next_scene(app->scene_manager, WifiMarauderSceneConsoleOutput); - } - break; - } - - furi_string_free(selected_filepath); - furi_string_free(predefined_filepath); -} - -#define STR_SELECT "[x]" -#define STR_UNSELECT "[ ]" -#define STR_BOOT "Bootloader (" TOSTRING(ESP_ADDR_BOOT) ")" -#define STR_BOOT_S3 "Bootloader (" TOSTRING(ESP_ADDR_BOOT_S3) ")" -#define STR_PART "Part Table (" TOSTRING(ESP_ADDR_PART) ")" -#define STR_NVS "NVS (" TOSTRING(ESP_ADDR_NVS) ")" -#define STR_BOOT_APP0 "boot_app0 (" TOSTRING(ESP_ADDR_BOOT_APP0) ")" -#define STR_APP "Firmware (" TOSTRING(ESP_ADDR_APP) ")" -#define STR_CUSTOM "Custom" -#define STR_FLASH_S3 "[>] FLASH (ESP32-S3)" -#define STR_FLASH "[>] FLASH" -static void _refresh_submenu(WifiMarauderApp* app) { - Submenu* submenu = app->submenu; - - submenu_reset(app->submenu); - - submenu_set_header(submenu, "Browse for files to flash"); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashS3Mode] ? "[x] Using ESP32-S3" : - "[ ] Check if using S3", - SubmenuIndexS3Mode, - wifi_marauder_scene_flasher_callback, - app); - const char* strSelectBootloader = STR_UNSELECT " " STR_BOOT; - if(app->selected_flash_options[SelectedFlashS3Mode]) { - if(app->selected_flash_options[SelectedFlashBoot]) { - strSelectBootloader = STR_SELECT " " STR_BOOT_S3; - } else { - strSelectBootloader = STR_UNSELECT " " STR_BOOT_S3; - } - } else { - if(app->selected_flash_options[SelectedFlashBoot]) { - strSelectBootloader = STR_SELECT " " STR_BOOT; - } else { - strSelectBootloader = STR_UNSELECT " " STR_BOOT; - } - } - submenu_add_item( - submenu, strSelectBootloader, SubmenuIndexBoot, wifi_marauder_scene_flasher_callback, app); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashPart] ? STR_SELECT " " STR_PART : - STR_UNSELECT " " STR_PART, - SubmenuIndexPart, - wifi_marauder_scene_flasher_callback, - app); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashNvs] ? STR_SELECT " " STR_NVS : - STR_UNSELECT " " STR_NVS, - SubmenuIndexNvs, - wifi_marauder_scene_flasher_callback, - app); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashBootApp0] ? STR_SELECT " " STR_BOOT_APP0 : - STR_UNSELECT " " STR_BOOT_APP0, - SubmenuIndexBootApp0, - wifi_marauder_scene_flasher_callback, - app); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashApp] ? STR_SELECT " " STR_APP : - STR_UNSELECT " " STR_APP, - SubmenuIndexApp, - wifi_marauder_scene_flasher_callback, - app); - // TODO: custom addr - //submenu_add_item( - // submenu, app->selected_flash_options[SelectedFlashCustom] ? STR_SELECT " " STR_CUSTOM : STR_UNSELECT " " STR_CUSTOM, SubmenuIndexCustom, wifi_marauder_scene_flasher_callback, app); - submenu_add_item( - submenu, - app->selected_flash_options[SelectedFlashS3Mode] ? STR_FLASH_S3 : STR_FLASH, - SubmenuIndexFlash, - wifi_marauder_scene_flasher_callback, - app); - - submenu_set_selected_item( - submenu, scene_manager_get_scene_state(app->scene_manager, WifiMarauderSceneFlasher)); - view_dispatcher_switch_to_view(app->view_dispatcher, WifiMarauderAppViewSubmenu); -} - -void wifi_marauder_scene_flasher_on_enter(void* context) { - WifiMarauderApp* app = context; - - memset(app->selected_flash_options, 0, sizeof(app->selected_flash_options)); - app->bin_file_path_boot[0] = '\0'; - app->bin_file_path_part[0] = '\0'; - app->bin_file_path_nvs[0] = '\0'; - app->bin_file_path_boot_app0[0] = '\0'; - app->bin_file_path_app[0] = '\0'; - app->bin_file_path_custom[0] = '\0'; - - _refresh_submenu(app); -} - -bool wifi_marauder_scene_flasher_on_event(void* context, SceneManagerEvent event) { - WifiMarauderApp* app = context; - bool consumed = false; - if(event.type == SceneManagerEventTypeCustom) { - if(event.event == WifiMarauderEventRefreshSubmenu) { - _refresh_submenu(app); - consumed = true; - } - } - - return consumed; -} - -void wifi_marauder_scene_flasher_on_exit(void* context) { - WifiMarauderApp* app = context; - submenu_reset(app->submenu); -} diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c index 97b26fc7fc..6ce66b1a44 100644 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c +++ b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c @@ -68,6 +68,13 @@ const WifiMarauderItem items[NUM_MENU_ITEMS] = { NO_ARGS, FOCUS_CONSOLE_END, SHOW_STOPSCAN_TIP}, + {"Evil Portal", + {"start"}, + 1, + {"evilportal -c start"}, + NO_ARGS, + FOCUS_CONSOLE_END, + SHOW_STOPSCAN_TIP}, {"Targeted Deauth", {"station", "manual"}, 2, @@ -83,11 +90,10 @@ const WifiMarauderItem items[NUM_MENU_ITEMS] = { FOCUS_CONSOLE_END, SHOW_STOPSCAN_TIP}, {"Sniff", - {"beacon", "deauth", "esp", "pmkid", "probe", "pwn", "raw", "bt", "skim"}, - 9, + {"beacon", "deauth", "pmkid", "probe", "pwn", "raw", "bt", "skim"}, + 8, {"sniffbeacon", "sniffdeauth", - "sniffesp", "sniffpmkid", "sniffprobe", "sniffpwn", @@ -105,6 +111,13 @@ const WifiMarauderItem items[NUM_MENU_ITEMS] = { TOGGLE_ARGS, FOCUS_CONSOLE_END, NO_TIP}, + {"LED", + {"hex", "pattern"}, + 2, + {"led -s", "led -p"}, + INPUT_ARGS, + FOCUS_CONSOLE_END, + NO_TIP}, {"Settings", {"display", "restore", "ForcePMKID", "ForceProbe", "SavePCAP", "EnableLED", "other"}, 7, @@ -118,10 +131,9 @@ const WifiMarauderItem items[NUM_MENU_ITEMS] = { TOGGLE_ARGS, FOCUS_CONSOLE_START, NO_TIP}, - {"Update", {"ota", "sd"}, 2, {"update -w", "update -s"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, + {"Update", {"sd"}, 1, {"update -s"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, {"Reboot", {""}, 1, {"reboot"}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, {"Help", {""}, 1, {"help"}, NO_ARGS, FOCUS_CONSOLE_START, SHOW_STOPSCAN_TIP}, - {"Reflash ESP32 (WIP)", {""}, 1, {""}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, {"Scripts", {""}, 1, {""}, NO_ARGS, FOCUS_CONSOLE_END, NO_TIP}, {"Save to flipper sdcard", // keep as last entry or change logic in callback below {""}, @@ -150,17 +162,6 @@ static void wifi_marauder_scene_start_var_list_enter_callback(void* context, uin item->focus_console; app->show_stopscan_tip = item->show_stopscan_tip; - // TODO cleanup - if(index == NUM_MENU_ITEMS - 3) { - // flasher - app->is_command = false; - app->flash_mode = true; - view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventStartFlasher); - return; - } - - app->flash_mode = false; - if(!app->is_command && selected_option_index == 0) { // View Log from start view_dispatcher_send_custom_event(app->view_dispatcher, WifiMarauderEventStartLogViewer); @@ -243,6 +244,7 @@ void wifi_marauder_scene_start_on_enter(void* context) { } bool wifi_marauder_scene_start_on_event(void* context, SceneManagerEvent event) { + UNUSED(context); WifiMarauderApp* app = context; bool consumed = false; @@ -271,10 +273,6 @@ bool wifi_marauder_scene_start_on_event(void* context, SceneManagerEvent event) scene_manager_set_scene_state( app->scene_manager, WifiMarauderSceneStart, app->selected_menu_index); scene_manager_next_scene(app->scene_manager, WifiMarauderSceneSniffPmkidOptions); - } else if(event.event == WifiMarauderEventStartFlasher) { - scene_manager_set_scene_state( - app->scene_manager, WifiMarauderSceneStart, app->selected_menu_index); - scene_manager_next_scene(app->scene_manager, WifiMarauderSceneFlasher); } consumed = true; } else if(event.type == SceneManagerEventTypeTick) { diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_text_input.c b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_text_input.c index 66a508f662..e6091a4104 100644 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_text_input.c +++ b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_text_input.c @@ -46,9 +46,7 @@ void wifi_marauder_scene_text_input_on_enter(void* context) { // Setup view WIFI_TextInput* text_input = app->text_input; // Add help message to header - if(app->flash_mode) { - wifi_text_input_set_header_text(text_input, "Enter destination address"); - } else if(app->special_case_input_step == 1) { + if(app->special_case_input_step == 1) { wifi_text_input_set_header_text(text_input, "Enter source MAC"); } else if(0 == strncmp("ssid -a -g", app->selected_tx_string, strlen("ssid -a -g"))) { wifi_text_input_set_header_text(text_input, "Enter # SSIDs to generate"); diff --git a/applications/external/wifi_marauder_companion/screenshots/marauder-save-pcaps.png b/applications/external/wifi_marauder_companion/screenshots/marauder-save-pcaps.png new file mode 100755 index 0000000000000000000000000000000000000000..dd4bcc1a0ea4b5bf86b0cd8d5dfb66ae557ca216 GIT binary patch literal 2336 zcmb7GZBSF$89tFJB45^)1y>Sw)~Qq&Tp$CAB$4i_E9nHUMt_*m+PD z{%%JA*#A88>~CW7_{&pC+?iuudj}dW2ly`bz5iEfqi^p=ziepyIey^P*yuXHHFE3b zlMXSsnY_Ja>M7l}Y#9wcM+xiSU`;q-6>(!+C3FVzke`8wU!%Z5y&CorS%=74p_ME! z;aF9~`MSN};3oileF%UD_ftVN4JJa<8u7eQRLI#fZV2I8e|_e4En57jI0(G8n(9GE zwZPnj2?@7tA`~z7%T{r;5BS&#$^3e;VQ>%F|0@7KbOJ?}3@T2^nrAC~AL{l{O0vh8 zk`>MGOj^IvLeAgryt4~!2Lp4x6H6Gc!x^X71GO}>$fwu@SvkYQod`UB!OW^8ptH9DZm^{v$Xd>rQUH64(7B-BPhIm8WX&rq4$@Hs8|jR0Y9 z+coZm#m*Wsx)~;r`9fVMR!0fZK*J=?Q3jI1-X1`qjTFYWPzT)T-lV3|7u*v7Axx9<# z2;?{Hn4eO#>ZMJC+`45^vaX@8{RFq3LDY_v!JXjwJ>+`A_Mm>z!1Ecn^2BmAOxT*v zYg?>-MSiqP;M zH%Y`~tk(DtvNmXfu^2h$e(E9LyADNB`**V)Hn0CVvxT(SjcX{)tMFB;%EYrn^Lg?z zG26okz^Q|~!mR)JHmaoXV#@XYmBA1#q$qEOJF(`f_|}dJs9UM(`V=ju5Vr;Jn8+mn z3E~5Tf!jKkHVB$UxtCvukCE2 zyTN%GYGPd4Vh}Jg{H3JuYz2=wKPJ^B_OBQC>O23!$C}~?HMs2C_@1%l&4n-n&r~p{ zHIvdtUrvl86EqC2=R<-R ziC`@FOn&a_Dh-W}W#qfDmJ+SLYNIl@o`~d$v4~cas|V-XXKKt!K10$ZYRBOPnghus zB}pfs8rikUW(D+Gpo7%yYmhjpxr+(c3efHgYFKcp^pA#cw;tQjM>w*|i>N zn2>09kJ3`P5j?6b78|xleeB2mThq!h`n(%JTr9DC3|J{?zh? zOUm`6yZU9}VfUibkofl@%@&?tZ!IEXt<>>*AMY0h!fpqosl4)vI49c{SR2V>xvXl> zQ$0Fu;Ua@Z6Gtp2dYIR|vsX_cj8Z^%`5tC(lPp=HWd>F2aH@wS!$MYTN!3L}ra8A! z61drqpMRq0a*gaF#C5b;VT7lhhj*#Y|I7n__~M$y^3{((>i|;j+1oIR{foR}0$ddw zx9xZ@$QT~|V~0e4G71s-srZCEiFX&|luT42YrAvO+pYS|!H<|)oUia-j($6HXxMh; P0g>lEJ1hP$<*WYy?q1WU literal 0 HcmV?d00001 diff --git a/applications/external/wifi_marauder_companion/screenshots/marauder-script-demo.png b/applications/external/wifi_marauder_companion/screenshots/marauder-script-demo.png new file mode 100755 index 0000000000000000000000000000000000000000..900fcef7ee210335f4552a2c96a958c58f9704a8 GIT binary patch literal 1599 zcmb`IYfO_@7{{Nt6>1SE*%o2qkS}ga8d7G1$fd1l8G?ySGOjAAX3`CW;i^Jut94sM zAi}b2PR4aI24=KY2}LQ@vWXKmDaxfodf_rILW@+WU}<45vD$;lzU{-C^X9zgJm>%X zp8s>+f{*q^dAMzI0|1ZcJ?uCD0{)7@`qd%kX>uSwkhAwB^8h^WtUlQHR8L<37jrZ_ z;^W+MlP;oobo*P84|YtBeIiO`_iLuf+k!~D?tJ@c&#eh}-;0Iu>5FG=)_+C~XO^u* z@sp<$hTAJEbeazdeBS`rPXPZI05%!K?_=P#72xtZ*!dm6dB?{oO<|dzDdMoTV zG+_|JSCLUQ+h>Umc1W-nh;*p)TjwEp-YEiFaFn^Hh&Wmk#nzaW~tmLgt>= zm{sp>BfdH%y~QKE@T@8bkS4dh*sp77%JxhJ$+1rxEC2jm@2v6Oo_D-N9TRQlV zsI@S|H20ZB3VjbL^>?SNdQ&>+>-2vZ8B04hjajAvoM)ggaDY<#w&uH z(^KXd3}$)UDa;Dsv;IY%wXQJRCY@h*342vp%e0ONoB$DkyW{YbhonG7unVwiC?NjK zk%O+E6ey6(8qZ^?ySD%k9iGt3y}OT93`sLeW@>V<#e{rAEzOSvWnM1;PRTc^4oyGi zT8YI>y1-O;4Ksd-?7ldUHRw0ovxceoh)9ck4wz$HOc;uYdXz=0rZ3$5B4FnQCV;C$ z6+_PeI6c$(d;+Q16%2$jDkBz|Vi+Zq+2k~h-GV{jOKpb@Lh-u@`>e1xeZ-8%I1PV? z+nG2uWWhWhI0Vu3kOW>wU7gK=FQ?Vv%+5NDu-6KenzG`C<(mpiurYjlHPRpTgH}k> z+>jIyThAd0DKlx+1EFokChAOx!1Q3Ek0nkFwH4=?aesa72;1BT=W_Paj4mhAM8ZgQ z+pyrex3oe@QMn-yn|`Kn+FNXg60|)(GG%l`b>1K!xD81Mu2w|4S0idm`Z7kM5}w>< z4IYqLg@ls?PB20+0H-RWAYtNgtD%kBQK|wXY7LwgyVU8kS_%yP`9H#KwqW5`Kd3NE z?4+oS%*HA#=|0ltTSdU_Z<2hqmhNgJ?*F{)*oEPHvW=&P?e?0gAc4B(8g}sbqJ3`U zILOEjU*ng7wrL|vF@Cz;=u<2e{Sr&KQH0bfGm)4pKce)jM(r$@V!12t457A7i6dUp z6|GDfxC@;uo~hJ4$%0!2NFYXQ24z-BfezjjO$ zckN8TvN_!iHFrKPN(ob|Cw3J5dVXNt?vO&m2}{5>hgU6Es>hNir!DH0GQz#LWVR`* zYL}&K2V=jZ7j0 z^+&Iklfa`2Tbh}i+5$m;iWcXl`1v@@mdyph)=oZjNv_MOUVNcUT-Tw!&*U$ndD?bP z*`(t?j-jUV9EaI1J6oK;^kH!?wFSo?i_;hWL4^93(OLE;clv-~=rqxY7E=H#we^U<+)SCp(>{_8{7*?!hTi6Y@`*~t^)lU##2v-hU_{O*E|?TYUZ;Z4}qjtO8W zmCV+7QE>ckb-w!^ui^t#d0_C8`hcTaQ*-8^sM*=LUH|9?4!Yt#WSIUgwn{@xOG_?_ zb2Vy{Dz)^{M9HAZJXIx=YP_d4BLwJnMF1UveoocnEVp=1$1I=p_fy3N;FRox1CvEm zi7Hxg8K-;Ew3EB;O+V{PJw%`boc+(U->t(=kr_A_D|xGYK*k`0;1K55FaZww;<_U~ zYa4Nl?;~!@QH{MH!sSH;!BKR?Q%jQgpq^@=%n$`ET-mujRDsqUogk&?!j`n;qo!}$ zH=~SYGRbL*&;(&@F1O-T? z=4mU$1=7TD9QYjGs(YpaLLH4vO6O-%&xqT{MV?UqB9>*okq3>&d1;KY(P|31Q`oXM zcWwRQF{Nbbds)4_K+E(O9p3IT-2aIWqSFLo?`a0D6t{YFJQQH08%Or-4KzA=^FWVo#C{5oUj`V2*J zLJrF?X?{=~pZ}GKq6!qIXv~(Z2%x`?0TX4|Rz$CY6r&WZ3Q;TS(Epi?ZXj0lPVr0*c%;20OOuYZ`FzI&GeFJ9Sg-UnX9hUfL9z z|3cG)B)!{dTm@~3p%MBca3`RtL)wE2^@Y&I%LMPB!#*IP8DYmvK_Yu%?t zA4M}EnMsD2IK3Mp{B&epXeN{oScfvxQ?qX`2f0-vm6fQHRR6drgt)3B)WyqmEiSUd zvG)1?WZYFsmb${wv&zalQ7)g1DX%OPx^fHvQvQbQSlhrSC80l<(WeTc!ehc(Hl`i; E7q5hJfB*mh literal 0 HcmV?d00001 diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_app.c b/applications/external/wifi_marauder_companion/wifi_marauder_app.c index c27a941ad7..97b1d97155 100644 --- a/applications/external/wifi_marauder_companion/wifi_marauder_app.c +++ b/applications/external/wifi_marauder_companion/wifi_marauder_app.c @@ -86,9 +86,6 @@ WifiMarauderApp* wifi_marauder_app_alloc() { view_dispatcher_add_view( app->view_dispatcher, WifiMarauderAppViewSubmenu, submenu_get_view(app->submenu)); - app->flash_mode = false; - app->flash_worker_busy = false; - scene_manager_next_scene(app->scene_manager, WifiMarauderSceneStart); return app; diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_app.h b/applications/external/wifi_marauder_companion/wifi_marauder_app.h index 187a0aaaaf..ceacbb489a 100644 --- a/applications/external/wifi_marauder_companion/wifi_marauder_app.h +++ b/applications/external/wifi_marauder_companion/wifi_marauder_app.h @@ -4,7 +4,7 @@ extern "C" { #endif -#define WIFI_MARAUDER_APP_VERSION "v0.5.1" +#define WIFI_MARAUDER_APP_VERSION "v0.6.0" typedef struct WifiMarauderApp WifiMarauderApp; diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_app_i.h b/applications/external/wifi_marauder_companion/wifi_marauder_app_i.h index a5c4818f07..4920bd229f 100644 --- a/applications/external/wifi_marauder_companion/wifi_marauder_app_i.h +++ b/applications/external/wifi_marauder_companion/wifi_marauder_app_i.h @@ -26,7 +26,7 @@ #include #include -#define NUM_MENU_ITEMS (19) +#define NUM_MENU_ITEMS (20) #define WIFI_MARAUDER_TEXT_BOX_STORE_SIZE (4096) #define WIFI_MARAUDER_TEXT_INPUT_STORE_SIZE (512) @@ -48,17 +48,6 @@ typedef enum WifiMarauderUserInputType { WifiMarauderUserInputTypeFileName } WifiMarauderUserInputType; -typedef enum SelectedFlashOptions { - SelectedFlashS3Mode, - SelectedFlashBoot, - SelectedFlashPart, - SelectedFlashNvs, - SelectedFlashBootApp0, - SelectedFlashApp, - SelectedFlashCustom, - NUM_FLASH_OPTIONS -} SelectedFlashOptions; - struct WifiMarauderApp { Gui* gui; ViewDispatcher* view_dispatcher; @@ -124,19 +113,6 @@ struct WifiMarauderApp { int special_case_input_step; char special_case_input_src_addr[20]; char special_case_input_dst_addr[20]; - - // For flashing - TODO: put into its own struct? - bool selected_flash_options[NUM_FLASH_OPTIONS]; - int num_selected_flash_options; - char bin_file_path_boot[100]; - char bin_file_path_part[100]; - char bin_file_path_nvs[100]; - char bin_file_path_boot_app0[100]; - char bin_file_path_app[100]; - char bin_file_path_custom[100]; - FuriThread* flash_worker; - bool flash_worker_busy; - bool flash_mode; }; // Supported commands: diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_custom_event.h b/applications/external/wifi_marauder_companion/wifi_marauder_custom_event.h index ff03f31dd9..b6d9f8274e 100644 --- a/applications/external/wifi_marauder_companion/wifi_marauder_custom_event.h +++ b/applications/external/wifi_marauder_companion/wifi_marauder_custom_event.h @@ -9,7 +9,5 @@ typedef enum { WifiMarauderEventStartSettingsInit, WifiMarauderEventStartLogViewer, WifiMarauderEventStartScriptSelect, - WifiMarauderEventStartSniffPmkidOptions, - WifiMarauderEventStartFlasher, - WifiMarauderEventRefreshSubmenu + WifiMarauderEventStartSniffPmkidOptions } WifiMarauderCustomEvent; diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_flasher.c b/applications/external/wifi_marauder_companion/wifi_marauder_flasher.c deleted file mode 100644 index ffc1acb78b..0000000000 --- a/applications/external/wifi_marauder_companion/wifi_marauder_flasher.c +++ /dev/null @@ -1,251 +0,0 @@ -#include "wifi_marauder_flasher.h" - -FuriStreamBuffer* flash_rx_stream; // TODO make safe -WifiMarauderApp* global_app; // TODO make safe -FuriTimer* timer; // TODO make - -static uint32_t _remaining_time = 0; -static void _timer_callback(void* context) { - UNUSED(context); - if(_remaining_time > 0) { - _remaining_time--; - } -} - -static esp_loader_error_t _flash_file(WifiMarauderApp* app, char* filepath, uint32_t addr) { - // TODO cleanup - esp_loader_error_t err; - static uint8_t payload[1024]; - File* bin_file = storage_file_alloc(app->storage); - - char user_msg[256]; - - // open file - if(!storage_file_open(bin_file, filepath, FSAM_READ, FSOM_OPEN_EXISTING)) { - storage_file_close(bin_file); - storage_file_free(bin_file); - dialog_message_show_storage_error(app->dialogs, "Cannot open file"); - return ESP_LOADER_ERROR_FAIL; - } - - uint64_t size = storage_file_size(bin_file); - - loader_port_debug_print("Erasing flash...this may take a while\n"); - err = esp_loader_flash_start(addr, size, sizeof(payload)); - if(err != ESP_LOADER_SUCCESS) { - storage_file_close(bin_file); - storage_file_free(bin_file); - snprintf(user_msg, sizeof(user_msg), "Erasing flash failed with error %d\n", err); - loader_port_debug_print(user_msg); - return err; - } - - loader_port_debug_print("Start programming\n"); - uint64_t last_updated = size; - while(size > 0) { - if((last_updated - size) > 50000) { - // inform user every 50k bytes - // TODO: draw a progress bar next update - snprintf(user_msg, sizeof(user_msg), "%llu bytes left.\n", size); - loader_port_debug_print(user_msg); - last_updated = size; - } - size_t to_read = MIN(size, sizeof(payload)); - uint16_t num_bytes = storage_file_read(bin_file, payload, to_read); - err = esp_loader_flash_write(payload, num_bytes); - if(err != ESP_LOADER_SUCCESS) { - snprintf(user_msg, sizeof(user_msg), "Packet could not be written! Error: %u\n", err); - storage_file_close(bin_file); - storage_file_free(bin_file); - loader_port_debug_print(user_msg); - return err; - } - - size -= num_bytes; - } - - loader_port_debug_print("Finished programming\n"); - - // TODO verify - - storage_file_close(bin_file); - storage_file_free(bin_file); - - return ESP_LOADER_SUCCESS; -} - -typedef struct { - SelectedFlashOptions selected; - const char* description; - char* path; - uint32_t addr; -} FlashItem; - -static void _flash_all_files(WifiMarauderApp* app) { - esp_loader_error_t err; - const int num_steps = app->num_selected_flash_options; - -#define NUM_FLASH_ITEMS 6 - FlashItem items[NUM_FLASH_ITEMS] = { - {SelectedFlashBoot, - "bootloader", - app->bin_file_path_boot, - app->selected_flash_options[SelectedFlashS3Mode] ? ESP_ADDR_BOOT_S3 : ESP_ADDR_BOOT}, - {SelectedFlashPart, "partition table", app->bin_file_path_part, ESP_ADDR_PART}, - {SelectedFlashNvs, "NVS", app->bin_file_path_nvs, ESP_ADDR_NVS}, - {SelectedFlashBootApp0, "boot_app0", app->bin_file_path_boot_app0, ESP_ADDR_BOOT_APP0}, - {SelectedFlashApp, "firmware", app->bin_file_path_app, ESP_ADDR_APP}, - {SelectedFlashCustom, "custom data", app->bin_file_path_custom, 0x0}, - /* if you add more entries, update NUM_FLASH_ITEMS above! */ - }; - - char user_msg[256]; - - int current_step = 1; - for(FlashItem* item = &items[0]; item < &items[NUM_FLASH_ITEMS]; ++item) { - if(app->selected_flash_options[item->selected]) { - snprintf( - user_msg, - sizeof(user_msg), - "Flashing %s (%d/%d) to address 0x%lx\n", - item->description, - current_step++, - num_steps, - item->addr); - loader_port_debug_print(user_msg); - err = _flash_file(app, item->path, item->addr); - if(err) { - break; - } - } - } -} - -static int32_t wifi_marauder_flash_bin(void* context) { - WifiMarauderApp* app = (void*)context; - esp_loader_error_t err; - - app->flash_worker_busy = true; - - // alloc global objects - flash_rx_stream = furi_stream_buffer_alloc(RX_BUF_SIZE, 1); - timer = furi_timer_alloc(_timer_callback, FuriTimerTypePeriodic, app); - - loader_port_debug_print("Connecting\n"); - esp_loader_connect_args_t connect_config = ESP_LOADER_CONNECT_DEFAULT(); - err = esp_loader_connect(&connect_config); - if(err != ESP_LOADER_SUCCESS) { - char err_msg[256]; - snprintf(err_msg, sizeof(err_msg), "Cannot connect to target. Error: %u\n", err); - loader_port_debug_print(err_msg); - } - -#if 0 // still getting packet drops with this - // higher BR - if(!err) { - loader_port_debug_print("Increasing speed for faster flash\n"); - err = esp_loader_change_transmission_rate(230400); - if (err != ESP_LOADER_SUCCESS) { - char err_msg[256]; - snprintf( - err_msg, - sizeof(err_msg), - "Cannot change transmission rate. Error: %u\n", - err); - loader_port_debug_print(err_msg); - } - furi_hal_uart_set_br(FuriHalUartIdUSART1, 230400); - } -#endif - - if(!err) { - loader_port_debug_print("Connected\n"); - _flash_all_files(app); -#if 0 - loader_port_debug_print("Restoring transmission rate\n"); - furi_hal_uart_set_br(FuriHalUartIdUSART1, 115200); -#endif - loader_port_debug_print("Done flashing. Please reset the board manually.\n"); - } - - // done - app->flash_worker_busy = false; - - // cleanup - furi_stream_buffer_free(flash_rx_stream); - flash_rx_stream = NULL; - furi_timer_free(timer); - return 0; -} - -void wifi_marauder_flash_start_thread(WifiMarauderApp* app) { - global_app = app; - - app->flash_worker = furi_thread_alloc(); - furi_thread_set_name(app->flash_worker, "WifiMarauderFlashWorker"); - furi_thread_set_stack_size(app->flash_worker, 2048); - furi_thread_set_context(app->flash_worker, app); - furi_thread_set_callback(app->flash_worker, wifi_marauder_flash_bin); - furi_thread_start(app->flash_worker); -} - -void wifi_marauder_flash_stop_thread(WifiMarauderApp* app) { - furi_thread_join(app->flash_worker); - furi_thread_free(app->flash_worker); -} - -esp_loader_error_t loader_port_read(uint8_t* data, uint16_t size, uint32_t timeout) { - size_t read = furi_stream_buffer_receive(flash_rx_stream, data, size, pdMS_TO_TICKS(timeout)); - if(read < size) { - return ESP_LOADER_ERROR_TIMEOUT; - } else { - return ESP_LOADER_SUCCESS; - } -} - -esp_loader_error_t loader_port_write(const uint8_t* data, uint16_t size, uint32_t timeout) { - UNUSED(timeout); - wifi_marauder_uart_tx((uint8_t*)data, size); - return ESP_LOADER_SUCCESS; -} - -void loader_port_enter_bootloader(void) { - // unimplemented -} - -void loader_port_delay_ms(uint32_t ms) { - furi_delay_ms(ms); -} - -void loader_port_start_timer(uint32_t ms) { - _remaining_time = ms; - furi_timer_start(timer, pdMS_TO_TICKS(1)); -} - -uint32_t loader_port_remaining_time(void) { - return _remaining_time; -} - -extern void wifi_marauder_console_output_handle_rx_data_cb( - uint8_t* buf, - size_t len, - void* context); // TODO cleanup -void loader_port_debug_print(const char* str) { - if(global_app) - wifi_marauder_console_output_handle_rx_data_cb((uint8_t*)str, strlen(str), global_app); -} - -void loader_port_spi_set_cs(uint32_t level) { - UNUSED(level); - // unimplemented -} - -void wifi_marauder_flash_handle_rx_data_cb(uint8_t* buf, size_t len, void* context) { - UNUSED(context); - if(flash_rx_stream) { - furi_stream_buffer_send(flash_rx_stream, buf, len, 0); - } else { - // done flashing - if(global_app) wifi_marauder_console_output_handle_rx_data_cb(buf, len, global_app); - } -} \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_flasher.h b/applications/external/wifi_marauder_companion/wifi_marauder_flasher.h deleted file mode 100644 index d875c2dbef..0000000000 --- a/applications/external/wifi_marauder_companion/wifi_marauder_flasher.h +++ /dev/null @@ -1,17 +0,0 @@ -#pragma once - -#include "wifi_marauder_app_i.h" -#include "wifi_marauder_uart.h" -#define SERIAL_FLASHER_INTERFACE_UART /* TODO why is application.fam not passing this via cdefines */ -#include "esp_loader_io.h" - -#define ESP_ADDR_BOOT_S3 0x0 -#define ESP_ADDR_BOOT 0x1000 -#define ESP_ADDR_PART 0x8000 -#define ESP_ADDR_NVS 0x9000 -#define ESP_ADDR_BOOT_APP0 0xE000 -#define ESP_ADDR_APP 0x10000 - -void wifi_marauder_flash_start_thread(WifiMarauderApp* app); -void wifi_marauder_flash_stop_thread(WifiMarauderApp* app); -void wifi_marauder_flash_handle_rx_data_cb(uint8_t* buf, size_t len, void* context); \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_pcap.c b/applications/external/wifi_marauder_companion/wifi_marauder_pcap.c deleted file mode 100644 index 73e3d98ea0..0000000000 --- a/applications/external/wifi_marauder_companion/wifi_marauder_pcap.c +++ /dev/null @@ -1,64 +0,0 @@ -#include "wifi_marauder_app_i.h" -#include "wifi_marauder_pcap.h" - -void wifi_marauder_get_prefix_from_sniff_cmd(char* dest, const char* command) { - int start, end, delta; - start = strlen("sniff"); - end = strcspn(command, " "); - delta = end - start; - strncpy(dest, command + start, end - start); - dest[delta] = '\0'; -} - -void wifi_marauder_get_prefix_from_cmd(char* dest, const char* command) { - int end; - end = strcspn(command, " "); - strncpy(dest, command, end); - dest[end] = '\0'; -} - -void wifi_marauder_create_pcap_file(WifiMarauderApp* app) { - char prefix[10]; - char capture_file_path[100]; - wifi_marauder_get_prefix_from_sniff_cmd(prefix, app->selected_tx_string); - - int i = 0; - do { - snprintf( - capture_file_path, - sizeof(capture_file_path), - "%s/%s_%d.pcap", - MARAUDER_APP_FOLDER_PCAPS, - prefix, - i); - i++; - } while(storage_file_exists(app->storage, capture_file_path)); - - if(!storage_file_open(app->capture_file, capture_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) { - dialog_message_show_storage_error(app->dialogs, "Cannot open pcap file"); - } -} - -void wifi_marauder_create_log_file(WifiMarauderApp* app) { - char prefix[10]; - char log_file_path[100]; - wifi_marauder_get_prefix_from_cmd(prefix, app->selected_tx_string); - - int i = 0; - do { - snprintf( - log_file_path, - sizeof(log_file_path), - "%s/%s_%d.log", - MARAUDER_APP_FOLDER_LOGS, - prefix, - i); - i++; - } while(storage_file_exists(app->storage, log_file_path)); - - if(!storage_file_open(app->log_file, log_file_path, FSAM_WRITE, FSOM_CREATE_ALWAYS)) { - dialog_message_show_storage_error(app->dialogs, "Cannot open log file"); - } else { - strcpy(app->log_file_path, log_file_path); - } -} \ No newline at end of file diff --git a/applications/external/wifi_marauder_companion/wifi_marauder_pcap.h b/applications/external/wifi_marauder_companion/wifi_marauder_pcap.h deleted file mode 100644 index 94f6282f3d..0000000000 --- a/applications/external/wifi_marauder_companion/wifi_marauder_pcap.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include "furi_hal.h" - -/** - * Creates a PCAP file to store incoming packets. - * The file name will have a prefix according to the type of scan being performed by the application (Eg: raw_0.pcap) - * - * @param app Application context - */ -void wifi_marauder_create_pcap_file(WifiMarauderApp* app); - -/** - * Creates a log file to store text from console output. - * The file name will have a prefix according to the command being performed by the application (Eg: scanap_0.log) - * - * @param app Application context - */ -// same as wifi_marauder_create_pcap_file, but for log files (to save console text output) -void wifi_marauder_create_log_file(WifiMarauderApp* app); From c3f7a0d12802cabb04878638f16e837deef992f1 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 29 Jul 2023 05:52:40 +0300 Subject: [PATCH 07/44] update changelog --- CHANGELOG.md | 10 ++++------ .../scenes/wifi_marauder_scene_start.c | 8 +------- 2 files changed, 5 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf018c3d9c..8aad209a6d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,10 +1,8 @@ ## New changes -* Plugins: **22+ plugins was fixed (UI update issues) in extra pack and in base firmware pack** -* Plugins: Spectrum Analyzer - Modulation switching (hold OK) (by @ALEEF02 | PR #557) -* Plugins: BadBT -> Temp fix for macOS -* Plugins: Update TOTP (Authenticator) [(by akopachov)](https://github.com/akopachov/flipper-zero_authenticator) -> + added fix for UI update too -* Infrared: Add Play / Pause in universal projector remote -* Infrared: Update Universal remote assets (by @amec0e) +* SubGHz: Support for Ebyte E07 module power amp switch (works with TehRabbitt's Flux Capacitor Board) (by @Sil333033) (PR #559 by @Z3BRO) -> Remade by @xMasterX +* Plugins: Update ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-wifi-marauder) +* Plugins: Update ESP32-CAM -> Camera Suite [(by CodyTolene)](https://github.com/CodyTolene/Flipper-Zero-Camera-Suite) -> (PR #562 by @CodyTolene) +* OFW: Fix fbtenv restore ---- diff --git a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c index 6ce66b1a44..6e6be90dfa 100644 --- a/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c +++ b/applications/external/wifi_marauder_companion/scenes/wifi_marauder_scene_start.c @@ -111,13 +111,7 @@ const WifiMarauderItem items[NUM_MENU_ITEMS] = { TOGGLE_ARGS, FOCUS_CONSOLE_END, NO_TIP}, - {"LED", - {"hex", "pattern"}, - 2, - {"led -s", "led -p"}, - INPUT_ARGS, - FOCUS_CONSOLE_END, - NO_TIP}, + {"LED", {"hex", "pattern"}, 2, {"led -s", "led -p"}, INPUT_ARGS, FOCUS_CONSOLE_END, NO_TIP}, {"Settings", {"display", "restore", "ForcePMKID", "ForceProbe", "SavePCAP", "EnableLED", "other"}, 7, From c6b6aec05747db40565ad2e35ff0899e33f2a5b9 Mon Sep 17 00:00:00 2001 From: gid9798 <30450294+gid9798@users.noreply.github.com> Date: Sun, 30 Jul 2023 12:12:59 +0300 Subject: [PATCH 08/44] replace power amp in driver --- .../drivers/subghz/cc1101_ext/cc1101_ext.c | 49 ++++++- .../drivers/subghz/cc1101_ext/cc1101_ext.h | 3 +- .../scenes/subghz_scene_radio_settings.c | 127 ++++-------------- lib/subghz/devices/devices.c | 41 +----- lib/subghz/devices/types.h | 11 +- 5 files changed, 88 insertions(+), 143 deletions(-) diff --git a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c index bd15f9cc6d..4e8b395d5b 100644 --- a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c +++ b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c @@ -18,7 +18,10 @@ #define TAG "SubGhz_Device_CC1101_Ext" #define SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO &gpio_ext_pb2 -#define SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE false +#define SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO &gpio_ext_pc3 +#define SUBGHZ_DEVICE_CC1101_EXT_FORCE_DANGEROUS_RANGE false + +#define SUBGHZ_DEVICE_CC1101_CONFIG_VER 1 /* DMA Channels definition */ #define SUBGHZ_DEVICE_CC1101_EXT_DMA DMA2 @@ -78,6 +81,8 @@ typedef struct { const GpioPin* g0_pin; SubGhzDeviceCC1101ExtAsyncTx async_tx; SubGhzDeviceCC1101ExtAsyncRx async_rx; + bool power_amp; + bool extended_range; } SubGhzDeviceCC1101Ext; static SubGhzDeviceCC1101Ext* subghz_device_cc1101_ext = NULL; @@ -187,7 +192,7 @@ static bool subghz_device_cc1101_ext_check_init() { return ret; } -bool subghz_device_cc1101_ext_alloc() { +bool subghz_device_cc1101_ext_alloc(SubGhzDeviceConf* conf) { furi_assert(subghz_device_cc1101_ext == NULL); subghz_device_cc1101_ext = malloc(sizeof(SubGhzDeviceCC1101Ext)); subghz_device_cc1101_ext->state = SubGhzDeviceCC1101ExtStateInit; @@ -195,16 +200,35 @@ bool subghz_device_cc1101_ext_alloc() { subghz_device_cc1101_ext->async_mirror_pin = NULL; subghz_device_cc1101_ext->spi_bus_handle = &furi_hal_spi_bus_handle_external; subghz_device_cc1101_ext->g0_pin = SUBGHZ_DEVICE_CC1101_EXT_TX_GPIO; + subghz_device_cc1101_ext->power_amp = false; + subghz_device_cc1101_ext->extended_range = false; + if(conf) { + if(conf->ver == SUBGHZ_DEVICE_CC1101_CONFIG_VER) { + subghz_device_cc1101_ext->power_amp = conf->power_amp; + subghz_device_cc1101_ext->extended_range = conf->extented_range; + } else { + FURI_LOG_E(TAG, "Config version mismatch"); + } + } subghz_device_cc1101_ext->async_rx.capture_delta_duration = 0; furi_hal_spi_bus_handle_init(subghz_device_cc1101_ext->spi_bus_handle); + if(subghz_device_cc1101_ext->power_amp) { + furi_hal_gpio_init_simple(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, GpioModeOutputPushPull); + } + return subghz_device_cc1101_ext_check_init(); } void subghz_device_cc1101_ext_free() { furi_assert(subghz_device_cc1101_ext != NULL); + furi_hal_spi_bus_handle_deinit(subghz_device_cc1101_ext->spi_bus_handle); + if(subghz_device_cc1101_ext->power_amp) { + furi_hal_gpio_init_simple(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, GpioModeAnalog); + } + free(subghz_device_cc1101_ext); subghz_device_cc1101_ext = NULL; } @@ -221,7 +245,7 @@ bool subghz_device_cc1101_ext_is_connect() { bool ret = false; if(subghz_device_cc1101_ext == NULL) { // not initialized - ret = subghz_device_cc1101_ext_alloc(); + ret = subghz_device_cc1101_ext_alloc(NULL); subghz_device_cc1101_ext_free(); } else { // initialized furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle); @@ -381,12 +405,18 @@ void subghz_device_cc1101_ext_idle() { furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle); cc1101_switch_to_idle(subghz_device_cc1101_ext->spi_bus_handle); furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle); + if(subghz_device_cc1101_ext->power_amp) { + furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, 0); + } } void subghz_device_cc1101_ext_rx() { furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle); cc1101_switch_to_rx(subghz_device_cc1101_ext->spi_bus_handle); furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle); + if(subghz_device_cc1101_ext->power_amp) { + furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, 0); + } } bool subghz_device_cc1101_ext_tx() { @@ -394,6 +424,9 @@ bool subghz_device_cc1101_ext_tx() { furi_hal_spi_acquire(subghz_device_cc1101_ext->spi_bus_handle); cc1101_switch_to_tx(subghz_device_cc1101_ext->spi_bus_handle); furi_hal_spi_release(subghz_device_cc1101_ext->spi_bus_handle); + if(subghz_device_cc1101_ext->power_amp) { + furi_hal_gpio_write(SUBGHZ_DEVICE_CC1101_EXT_E07_AMP_GPIO, 1); + } return true; } @@ -432,14 +465,16 @@ bool subghz_device_cc1101_ext_is_frequency_valid(uint32_t value) { } bool subghz_device_cc1101_ext_is_tx_allowed(uint32_t value) { - if(!(SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE) && + if(!(SUBGHZ_DEVICE_CC1101_EXT_FORCE_DANGEROUS_RANGE || + subghz_device_cc1101_ext->extended_range) && !(value >= 299999755 && value <= 350000335) && // was increased from 348 to 350 !(value >= 386999938 && value <= 467750000) && // was increased from 464 to 467.75 !(value >= 778999847 && value <= 928000000)) { FURI_LOG_I(TAG, "Frequency blocked - outside default range"); return false; } else if( - (SUBGHZ_DEVICE_CC1101_EXT_DANGEROUS_RANGE) && + (SUBGHZ_DEVICE_CC1101_EXT_FORCE_DANGEROUS_RANGE || + subghz_device_cc1101_ext->extended_range) && !subghz_device_cc1101_ext_is_frequency_valid(value)) { FURI_LOG_I(TAG, "Frequency blocked - outside dangerous range"); return false; @@ -529,7 +564,7 @@ void subghz_device_cc1101_ext_start_async_rx( furi_hal_bus_enable(FuriHalBusTIM17); // Configure TIM - //Set the timer resolution to 2 s + //Set the timer resolution to 2 �s LL_TIM_SetPrescaler(TIM17, (64 << 1) - 1); LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP); LL_TIM_SetAutoReload(TIM17, 0xFFFF); @@ -710,7 +745,7 @@ bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callb furi_hal_bus_enable(FuriHalBusTIM17); // Configure TIM - // Set the timer resolution to 2 s + // Set the timer resolution to 2 �s LL_TIM_SetPrescaler(TIM17, (64 << 1) - 1); LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP); LL_TIM_SetAutoReload(TIM17, 0xFFFF); diff --git a/applications/drivers/subghz/cc1101_ext/cc1101_ext.h b/applications/drivers/subghz/cc1101_ext/cc1101_ext.h index d972fcb661..130402f8ef 100644 --- a/applications/drivers/subghz/cc1101_ext/cc1101_ext.h +++ b/applications/drivers/subghz/cc1101_ext/cc1101_ext.h @@ -5,6 +5,7 @@ #pragma once #include +#include #include #include #include @@ -34,7 +35,7 @@ const GpioPin* subghz_device_cc1101_ext_get_data_gpio(); * * @return true if success */ -bool subghz_device_cc1101_ext_alloc(); +bool subghz_device_cc1101_ext_alloc(SubGhzDeviceConf* conf); /** Deinitialize device */ diff --git a/applications/main/subghz/scenes/subghz_scene_radio_settings.c b/applications/main/subghz/scenes/subghz_scene_radio_settings.c index 2ff2f565fb..0bd2b1f3eb 100644 --- a/applications/main/subghz/scenes/subghz_scene_radio_settings.c +++ b/applications/main/subghz/scenes/subghz_scene_radio_settings.c @@ -41,6 +41,14 @@ const char* const debug_counter_text[DEBUG_COUNTER_COUNT] = { "+5", "+10", }; +const uint32_t debug_counter_val[DEBUG_COUNTER_COUNT] = { + 1, + 2, + 3, + 4, + 5, + 10, +}; static void subghz_scene_radio_settings_set_device(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); @@ -69,66 +77,28 @@ static void subghz_scene_receiver_config_set_debug_counter(VariableItem* item) { uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, debug_counter_text[index]); - - switch(index) { - case 0: - furi_hal_subghz_set_rolling_counter_mult(1); - break; - case 1: - furi_hal_subghz_set_rolling_counter_mult(2); - break; - case 2: - furi_hal_subghz_set_rolling_counter_mult(3); - break; - case 3: - furi_hal_subghz_set_rolling_counter_mult(4); - break; - case 4: - furi_hal_subghz_set_rolling_counter_mult(5); - break; - case 5: - furi_hal_subghz_set_rolling_counter_mult(10); - break; - default: - break; - } + furi_hal_subghz_set_rolling_counter_mult(debug_counter_val[index]); } -// static void subghz_scene_receiver_config_set_ext_mod_power(VariableItem* item) { -// SubGhz* subghz = variable_item_get_context(item); -// uint8_t index = variable_item_get_current_value_index(item); - -// variable_item_set_current_value_text(item, ext_mod_power_text[index]); - -// furi_hal_subghz_set_external_power_disable(index == 1); -// if(index == 1) { -// furi_hal_subghz_disable_ext_power(); -// } else { -// furi_hal_subghz_enable_ext_power(); -// } - -// subghz->last_settings->external_module_power_5v_disable = index == 1; -// subghz_last_settings_save(subghz->last_settings); -// } - static void subghz_scene_reciever_config_set_ext_mod_power_amp_text(VariableItem* item) { SubGhz* subghz = variable_item_get_context(item); uint8_t index = variable_item_get_current_value_index(item); variable_item_set_current_value_text(item, ext_mod_power_amp_text[index]); - if(index == 1) { - furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); - } else { - furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); - } - subghz->last_settings->external_module_power_amp = index == 1; // Set globally in furi hal furi_hal_subghz_set_ext_power_amp(subghz->last_settings->external_module_power_amp); subghz_last_settings_save(subghz->last_settings); + + // reinit external device + const SubGhzRadioDeviceType current = subghz_txrx_radio_device_get(subghz->txrx); + if(current != SubGhzRadioDeviceTypeInternal) { + subghz_txrx_radio_device_set(subghz->txrx, SubGhzRadioDeviceTypeInternal); + subghz_txrx_radio_device_set(subghz->txrx, current); + } } static void subghz_scene_receiver_config_set_timestamp_file_names(VariableItem* item) { @@ -183,59 +153,18 @@ void subghz_scene_radio_settings_on_enter(void* context) { variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, timestamp_names_text[value_index]); - if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { - item = variable_item_list_add( - variable_item_list, - "Counter Incr.", - DEBUG_COUNTER_COUNT, - subghz_scene_receiver_config_set_debug_counter, - subghz); - switch(furi_hal_subghz_get_rolling_counter_mult()) { - case 1: - value_index = 0; - break; - case 2: - value_index = 1; - break; - case 3: - value_index = 2; - break; - case 4: - value_index = 3; - break; - case 5: - value_index = 4; - break; - case 10: - value_index = 5; - break; - default: - break; - } - } else { - item = variable_item_list_add( - variable_item_list, - "Counter Incr.", - 3, - subghz_scene_receiver_config_set_debug_counter, - subghz); - switch(furi_hal_subghz_get_rolling_counter_mult()) { - case 1: - value_index = 0; - break; - case 2: - value_index = 1; - break; - case 3: - value_index = 2; - break; - default: - // Reset to default value - value_index = 0; - furi_hal_subghz_set_rolling_counter_mult(1); - break; - } - } + item = variable_item_list_add( + variable_item_list, + "Counter Incr.", + furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) ? DEBUG_COUNTER_COUNT : 3, + subghz_scene_receiver_config_set_debug_counter, + subghz); + value_index = value_index_uint32( + furi_hal_subghz_get_rolling_counter_mult(), + debug_counter_val, + furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug) ? DEBUG_COUNTER_COUNT : 3); + furi_hal_subghz_set_rolling_counter_mult(debug_counter_val[value_index]); + variable_item_set_current_value_index(item, value_index); variable_item_set_current_value_text(item, debug_counter_text[value_index]); diff --git a/lib/subghz/devices/devices.c b/lib/subghz/devices/devices.c index 98cb0f6091..e034c474d4 100644 --- a/lib/subghz/devices/devices.c +++ b/lib/subghz/devices/devices.c @@ -30,14 +30,13 @@ bool subghz_devices_begin(const SubGhzDevice* device) { bool ret = false; furi_assert(device); if(device->interconnect->begin) { - // TODO: Remake this check and move this code - if(strcmp("cc1101_ext", device->name) == 0) { - if(furi_hal_subghz_get_ext_power_amp()) { - furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeOutputPushPull); - } - } - - ret = device->interconnect->begin(); + SubGhzDeviceConf conf = { + .ver = 1, + .extended_range = false, // TODO + .power_amp = furi_hal_subghz_get_ext_power_amp(), + }; + + ret = device->interconnect->begin(&conf); } return ret; } @@ -45,12 +44,6 @@ bool subghz_devices_begin(const SubGhzDevice* device) { void subghz_devices_end(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->end) { - // TODO: Remake this check and move this code - if(strcmp("cc1101_ext", device->name) == 0) { - if(furi_hal_subghz_get_ext_power_amp()) { - furi_hal_gpio_init_simple(&gpio_ext_pc3, GpioModeAnalog); - } - } device->interconnect->end(); } } @@ -82,12 +75,6 @@ void subghz_devices_idle(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->idle) { device->interconnect->idle(); - // TODO: Remake this check and move this code - if(strcmp("cc1101_ext", device->name) == 0) { - if(furi_hal_subghz_get_ext_power_amp()) { - furi_hal_gpio_write(&gpio_ext_pc3, 0); - } - } } } @@ -140,13 +127,6 @@ bool subghz_devices_set_tx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_tx) { ret = device->interconnect->set_tx(); - - // TODO: Remake this check and move this code - if(strcmp("cc1101_ext", device->name) == 0) { - if(furi_hal_subghz_get_ext_power_amp()) { - furi_hal_gpio_write(&gpio_ext_pc3, 1); - } - } } return ret; } @@ -187,13 +167,6 @@ void subghz_devices_set_rx(const SubGhzDevice* device) { furi_assert(device); if(device->interconnect->set_rx) { device->interconnect->set_rx(); - - // TODO: Remake this check and move this code - if(strcmp("cc1101_ext", device->name) == 0) { - if(furi_hal_subghz_get_ext_power_amp()) { - furi_hal_gpio_write(&gpio_ext_pc3, 0); - } - } } } diff --git a/lib/subghz/devices/types.h b/lib/subghz/devices/types.h index 8a41984263..f5f140c6a7 100644 --- a/lib/subghz/devices/types.h +++ b/lib/subghz/devices/types.h @@ -12,12 +12,13 @@ #include #define SUBGHZ_RADIO_DEVICE_PLUGIN_APP_ID "subghz_radio_device" -#define SUBGHZ_RADIO_DEVICE_PLUGIN_API_VERSION 1 +#define SUBGHZ_RADIO_DEVICE_PLUGIN_API_VERSION 2 typedef struct SubGhzDeviceRegistry SubGhzDeviceRegistry; typedef struct SubGhzDevice SubGhzDevice; +typedef struct SubGhzDeviceConf SubGhzDeviceConf; -typedef bool (*SubGhzBegin)(void); +typedef bool (*SubGhzBegin)(SubGhzDeviceConf* conf); typedef void (*SubGhzEnd)(void); typedef bool (*SubGhzIsConnect)(void); typedef void (*SubGhzReset)(void); @@ -89,3 +90,9 @@ struct SubGhzDevice { const char* name; const SubGhzDeviceInterconnect* interconnect; }; + +struct SubGhzDeviceConf { + uint8_t ver; + bool extended_range; + bool power_amp; +}; \ No newline at end of file From 5d21da17379f084e570663c02879107efc93c031 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Mon, 31 Jul 2023 01:21:17 +0300 Subject: [PATCH 09/44] fix --- applications/drivers/subghz/cc1101_ext/cc1101_ext.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c index 4e8b395d5b..405132a6b5 100644 --- a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c +++ b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c @@ -205,7 +205,7 @@ bool subghz_device_cc1101_ext_alloc(SubGhzDeviceConf* conf) { if(conf) { if(conf->ver == SUBGHZ_DEVICE_CC1101_CONFIG_VER) { subghz_device_cc1101_ext->power_amp = conf->power_amp; - subghz_device_cc1101_ext->extended_range = conf->extented_range; + subghz_device_cc1101_ext->extended_range = conf->extended_range; } else { FURI_LOG_E(TAG, "Config version mismatch"); } From a2a4fa8cdac2a3c7753100ccaa2f7c9f8c28b9c8 Mon Sep 17 00:00:00 2001 From: Nikolay Minaylov Date: Tue, 1 Aug 2023 10:56:11 +0300 Subject: [PATCH 10/44] [FL-3408, FL-3429, FL-3430] Backlight notification fix (#2878) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Notifications: display brightness override fix * FuriHalVersionColor update * float comparison fix Co-authored-by: あく --- .../services/notification/notification_app.c | 15 +++++++++++---- .../targets/furi_hal_include/furi_hal_version.h | 1 + scripts/otp.py | 1 + 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/applications/services/notification/notification_app.c b/applications/services/notification/notification_app.c index 2f947fe8a0..6fa48e7f4e 100644 --- a/applications/services/notification/notification_app.c +++ b/applications/services/notification/notification_app.c @@ -5,7 +5,7 @@ #include #include #include - +#include #include "notification.h" #include "notification_messages.h" #include "notification_app.h" @@ -104,7 +104,10 @@ static void notification_reset_notification_led_layer(NotificationLedLayer* laye furi_hal_light_set(layer->light, layer->value[LayerInternal]); } -static void notification_reset_notification_layer(NotificationApp* app, uint8_t reset_mask) { +static void notification_reset_notification_layer( + NotificationApp* app, + uint8_t reset_mask, + float display_brightness_set) { if(reset_mask & reset_blink_mask) { furi_hal_light_blink_stop(); } @@ -124,6 +127,9 @@ static void notification_reset_notification_layer(NotificationApp* app, uint8_t notification_sound_off(); } if(reset_mask & reset_display_mask) { + if(!float_is_equal(display_brightness_set, app->settings.display_brightness)) { + furi_hal_light_set(LightBacklight, app->settings.display_brightness * 0xFF); + } furi_timer_start(app->display_timer, notification_settings_display_off_delay_ticks(app)); } } @@ -212,13 +218,14 @@ static void notification_process_notification_message( notification_apply_notification_led_layer( &app->display, notification_message->data.led.value * display_brightness_setting); + reset_mask |= reset_display_mask; } else { + reset_mask &= ~reset_display_mask; notification_reset_notification_led_layer(&app->display); if(furi_timer_is_running(app->display_timer)) { furi_timer_stop(app->display_timer); } } - reset_mask |= reset_display_mask; break; case NotificationMessageTypeLedDisplayBacklightEnforceOn: furi_assert(app->display_led_lock < UINT8_MAX); @@ -370,7 +377,7 @@ static void notification_process_notification_message( } if(reset_notifications) { - notification_reset_notification_layer(app, reset_mask); + notification_reset_notification_layer(app, reset_mask, display_brightness_setting); } } diff --git a/firmware/targets/furi_hal_include/furi_hal_version.h b/firmware/targets/furi_hal_include/furi_hal_version.h index a9339a6c0e..98d011cb38 100644 --- a/firmware/targets/furi_hal_include/furi_hal_version.h +++ b/firmware/targets/furi_hal_include/furi_hal_version.h @@ -33,6 +33,7 @@ typedef enum { FuriHalVersionColorUnknown = 0x00, FuriHalVersionColorBlack = 0x01, FuriHalVersionColorWhite = 0x02, + FuriHalVersionColorTransparent = 0x03, } FuriHalVersionColor; /** Device Regions */ diff --git a/scripts/otp.py b/scripts/otp.py index 19b8c4df42..e3f070999a 100755 --- a/scripts/otp.py +++ b/scripts/otp.py @@ -17,6 +17,7 @@ "unknown": 0x00, "black": 0x01, "white": 0x02, + "transparent": 0x03, } OTP_REGIONS = { From 68eb1ecebb463b148b21358dd2ba89b1bfc29e41 Mon Sep 17 00:00:00 2001 From: Dzhos Oleksii <35292229+Programistich@users.noreply.github.com> Date: Tue, 1 Aug 2023 11:20:30 +0300 Subject: [PATCH 11/44] [FL-3385] New RTC flags in device info (#2884) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Add new rtc flags to device info * FuriHal: bump info version * Fix local * Rework device info by hierarchy filtering Co-authored-by: あく --- firmware/targets/f7/furi_hal/furi_hal_info.c | 49 +++++++++++++++++++- 1 file changed, 47 insertions(+), 2 deletions(-) diff --git a/firmware/targets/f7/furi_hal/furi_hal_info.c b/firmware/targets/f7/furi_hal/furi_hal_info.c index a2c9232c05..cefb6a11bb 100644 --- a/firmware/targets/f7/furi_hal/furi_hal_info.c +++ b/firmware/targets/f7/furi_hal/furi_hal_info.c @@ -24,10 +24,10 @@ void furi_hal_info_get(PropertyValueCallback out, char sep, void* context) { // Device Info version if(sep == '.') { property_value_out(&property_context, NULL, 2, "format", "major", "3"); - property_value_out(&property_context, NULL, 2, "format", "minor", "2"); + property_value_out(&property_context, NULL, 2, "format", "minor", "3"); } else { property_value_out(&property_context, NULL, 3, "device", "info", "major", "2"); - property_value_out(&property_context, NULL, 3, "device", "info", "minor", "3"); + property_value_out(&property_context, NULL, 3, "device", "info", "minor", "4"); } // Model name @@ -298,6 +298,7 @@ void furi_hal_info_get(PropertyValueCallback out, char sep, void* context) { property_value_out(&property_context, NULL, 2, "radio", "alive", "false"); } + // RTC flags property_value_out( &property_context, "%u", @@ -305,8 +306,52 @@ void furi_hal_info_get(PropertyValueCallback out, char sep, void* context) { "system", "debug", furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)); + property_value_out( + &property_context, "%u", 2, "system", "lock", furi_hal_rtc_is_flag_set(FuriHalRtcFlagLock)); + property_value_out( + &property_context, + "%u", + 2, + "system", + "orient", + furi_hal_rtc_is_flag_set(FuriHalRtcFlagHandOrient)); + property_value_out( + &property_context, + "%u", + 3, + "system", + "sleep", + "legacy", + furi_hal_rtc_is_flag_set(FuriHalRtcFlagLegacySleep)); + property_value_out( + &property_context, + "%u", + 2, + "system", + "stealth", + furi_hal_rtc_is_flag_set(FuriHalRtcFlagStealthMode)); + property_value_out( &property_context, "%u", 3, "system", "heap", "track", furi_hal_rtc_get_heap_track_mode()); + property_value_out(&property_context, "%u", 2, "system", "boot", furi_hal_rtc_get_boot_mode()); + property_value_out( + &property_context, + "%u", + 3, + "system", + "locale", + "time", + furi_hal_rtc_get_locale_timeformat()); + property_value_out( + &property_context, + "%u", + 3, + "system", + "locale", + "date", + furi_hal_rtc_get_locale_dateformat()); + property_value_out( + &property_context, "%u", 3, "system", "locale", "unit", furi_hal_rtc_get_locale_units()); property_value_out( &property_context, "%u", 3, "system", "log", "level", furi_hal_rtc_get_log_level()); From aadb72af53b2b9d95c6b52ce200df1c7112d0d94 Mon Sep 17 00:00:00 2001 From: MMX <10697207+xMasterX@users.noreply.github.com> Date: Tue, 1 Aug 2023 12:09:30 +0300 Subject: [PATCH 12/44] UI: New way to input bytes in byte_input (#2890) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * New byte input UI option * Gui: reformat and cleanup byte_input docs, make PVS happy Co-authored-by: hedger Co-authored-by: あく --- .../services/gui/modules/byte_input.c | 442 ++++++++++-------- 1 file changed, 251 insertions(+), 191 deletions(-) diff --git a/applications/services/gui/modules/byte_input.c b/applications/services/gui/modules/byte_input.c index b2d21f7ae3..3bca8fc744 100644 --- a/applications/services/gui/modules/byte_input.c +++ b/applications/services/gui/modules/byte_input.c @@ -4,6 +4,7 @@ #include #include +/** ByteInput type */ struct ByteInput { View* view; }; @@ -25,7 +26,7 @@ typedef struct { bool selected_high_nibble; uint8_t selected_byte; - int8_t selected_row; // row -1 - input, row 0 & 1 - keyboard + int8_t selected_row; // row -2 - mini_editor, -1 - input, row 0 & 1 - keyboard uint8_t selected_column; uint8_t first_visible_byte; } ByteInputModel; @@ -61,11 +62,11 @@ static const ByteInputKey keyboard_keys_row_2[] = { {enter_symbol, 95, 17}, }; -/** - * @brief Get row size - * - * @param row_index Index of row - * @return uint8_t Row size +/** Get row size + * + * @param row_index Index of row + * + * @return uint8_t Row size */ static uint8_t byte_input_get_row_size(uint8_t row_index) { uint8_t row_size = 0; @@ -84,11 +85,11 @@ static uint8_t byte_input_get_row_size(uint8_t row_index) { return row_size; } -/** - * @brief Get row pointer - * - * @param row_index Index of row - * @return const ByteInputKey* Row pointer +/** Get row pointer + * + * @param row_index Index of row + * + * @return const ByteInputKey* Row pointer */ static const ByteInputKey* byte_input_get_row(uint8_t row_index) { const ByteInputKey* row = NULL; @@ -107,12 +108,12 @@ static const ByteInputKey* byte_input_get_row(uint8_t row_index) { return row; } -/** - * @brief Get text from nibble - * - * @param byte byte value - * @param high_nibble Get from high nibble, otherwise low nibble - * @return char nibble text +/** Get text from nibble + * + * @param byte byte value + * @param high_nibble Get from high nibble, otherwise low nibble + * + * @return char nibble text */ static char byte_input_get_nibble_text(uint8_t byte, bool high_nibble) { if(high_nibble) { @@ -149,15 +150,20 @@ static char byte_input_get_nibble_text(uint8_t byte, bool high_nibble) { return byte; } -/** - * @brief Draw input box (common view) - * - * @param canvas - * @param model +const char num_to_char[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'}; + +/** Draw input box (common view) + * + * @param canvas The canvas + * @param model The model */ static void byte_input_draw_input(Canvas* canvas, ByteInputModel* model) { const uint8_t text_x = 8; const uint8_t text_y = 25; + const uint8_t text_y2 = 40; + const bool draw_index_line = + (model->selected_row == -2) && + (model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes + 1) <= 100); elements_slightly_rounded_frame(canvas, 6, 14, 116, 15); @@ -225,6 +231,27 @@ static void byte_input_draw_input(Canvas* canvas, ByteInputModel* model) { text_y, byte_input_get_nibble_text(model->bytes[i], false)); } + + if(draw_index_line) { + canvas_draw_glyph( + canvas, text_x + 2 + byte_position * 14, text_y2, num_to_char[(i + 1) / 10]); + + canvas_draw_glyph( + canvas, text_x + 8 + byte_position * 14, text_y2, num_to_char[(i + 1) % 10]); + } + } + + if((model->selected_row == -2) && + (model->first_visible_byte + MIN(model->bytes_count, max_drawable_bytes + 1) > 100)) { + char str[20]; + + canvas_set_font(canvas, FontSecondary); + snprintf(str, 20, "Selected index"); + canvas_draw_str(canvas, text_x, text_y2, str); + + canvas_set_font(canvas, FontPrimary); + snprintf(str, 20, "%u", (model->selected_byte + 1)); + canvas_draw_str(canvas, text_x + 75, text_y2, str); } if(model->bytes_count - model->first_visible_byte > max_drawable_bytes) { @@ -236,11 +263,10 @@ static void byte_input_draw_input(Canvas* canvas, ByteInputModel* model) { } } -/** - * @brief Draw input box (selected view) - * - * @param canvas - * @param model +/** Draw input box (selected view) + * + * @param canvas The canvas + * @param model The model */ static void byte_input_draw_input_selected(Canvas* canvas, ByteInputModel* model) { const uint8_t text_x = 7; @@ -297,13 +323,12 @@ static void byte_input_draw_input_selected(Canvas* canvas, ByteInputModel* model canvas_invert_color(canvas); } -/** - * @brief Set nibble at position - * - * @param data where to set nibble - * @param position byte position - * @param value char value - * @param high_nibble set high nibble +/** Set nibble at position + * + * @param data where to set nibble + * @param position byte position + * @param value char value + * @param high_nibble set high nibble */ static void byte_input_set_nibble(uint8_t* data, uint8_t position, char value, bool high_nibble) { switch(value) { @@ -341,29 +366,28 @@ static void byte_input_set_nibble(uint8_t* data, uint8_t position, char value, b } } -/** - * @brief What currently selected - * - * @return true - keyboard selected, false - input selected +/** What currently selected + * + * @param model The model + * + * @return true - keyboard selected, false - input selected */ static bool byte_input_keyboard_selected(ByteInputModel* model) { return model->selected_row >= 0; } -/** - * @brief Do transition from keyboard - * - * @param model +/** Do transition from keyboard + * + * @param model The model */ static void byte_input_transition_from_keyboard(ByteInputModel* model) { model->selected_row += 1; model->selected_high_nibble = true; } -/** - * @brief Increase selected byte position - * - * @param model +/** Increase selected byte position + * + * @param model The model */ static void byte_input_inc_selected_byte(ByteInputModel* model) { if(model->selected_byte < model->bytes_count - 1) { @@ -379,10 +403,20 @@ static void byte_input_inc_selected_byte(ByteInputModel* model) { } } -/** - * @brief Decrease selected byte position - * - * @param model +static void byte_input_inc_selected_byte_mini(ByteInputModel* model) { + if((model->selected_byte < model->bytes_count - 1) || model->selected_high_nibble) { + if(!model->selected_high_nibble) { + model->selected_high_nibble = !model->selected_high_nibble; //-V547 + byte_input_inc_selected_byte(model); + } else { + model->selected_high_nibble = !model->selected_high_nibble; //-V547 + } + } +} + +/** Decrease selected byte position + * + * @param model The model */ static void byte_input_dec_selected_byte(ByteInputModel* model) { if(model->selected_byte > 0) { @@ -397,10 +431,20 @@ static void byte_input_dec_selected_byte(ByteInputModel* model) { } } -/** - * @brief Call input callback - * - * @param model +static void byte_input_dec_selected_byte_mini(ByteInputModel* model) { + if(model->selected_byte > 0 || !model->selected_high_nibble) { + if(model->selected_high_nibble) { + model->selected_high_nibble = !model->selected_high_nibble; //-V547 + byte_input_dec_selected_byte(model); + } else { + model->selected_high_nibble = !model->selected_high_nibble; //-V547 + } + } +} + +/** Call input callback + * + * @param model The model */ static void byte_input_call_input_callback(ByteInputModel* model) { if(model->input_callback != NULL) { @@ -408,10 +452,9 @@ static void byte_input_call_input_callback(ByteInputModel* model) { } } -/** - * @brief Call changed callback - * - * @param model +/** Call changed callback + * + * @param model The model */ static void byte_input_call_changed_callback(ByteInputModel* model) { if(model->changed_callback != NULL) { @@ -419,8 +462,9 @@ static void byte_input_call_changed_callback(ByteInputModel* model) { } } -/** - * @brief Clear selected byte +/** Clear selected byte + * + * @param model The model */ static void byte_input_clear_selected_byte(ByteInputModel* model) { @@ -430,36 +474,55 @@ static void byte_input_clear_selected_byte(ByteInputModel* model) { byte_input_call_changed_callback(model); } -/** - * @brief Handle up button - * - * @param model +/** Handle up button + * + * @param model The model */ static void byte_input_handle_up(ByteInputModel* model) { - if(model->selected_row > -1) { + if(model->selected_row > -2) { model->selected_row -= 1; + } else if(model->selected_row == -2) { + if(!model->selected_high_nibble) { + model->bytes[model->selected_byte] = (model->bytes[model->selected_byte] & 0xF0) | + ((model->bytes[model->selected_byte] + 1) & 0x0F); + } else { + model->bytes[model->selected_byte] = + ((model->bytes[model->selected_byte] + 0x10) & 0xF0) | + (model->bytes[model->selected_byte] & 0x0F); + } + byte_input_call_changed_callback(model); } } -/** - * @brief Handle down button - * - * @param model +/** Handle down button + * + * @param model The model */ static void byte_input_handle_down(ByteInputModel* model) { - if(byte_input_keyboard_selected(model)) { - if(model->selected_row < keyboard_row_count - 1) { - model->selected_row += 1; + if(model->selected_row != -2) { + if(byte_input_keyboard_selected(model)) { + if(model->selected_row < keyboard_row_count - 1) { + model->selected_row += 1; + } + } else { + byte_input_transition_from_keyboard(model); } } else { - byte_input_transition_from_keyboard(model); + if(!model->selected_high_nibble) { + model->bytes[model->selected_byte] = (model->bytes[model->selected_byte] & 0xF0) | + ((model->bytes[model->selected_byte] - 1) & 0x0F); + } else { + model->bytes[model->selected_byte] = + ((model->bytes[model->selected_byte] - 0x10) & 0xF0) | + (model->bytes[model->selected_byte] & 0x0F); + } + byte_input_call_changed_callback(model); } } -/** - * @brief Handle left button - * - * @param model +/** Handle left button + * + * @param model The model */ static void byte_input_handle_left(ByteInputModel* model) { if(byte_input_keyboard_selected(model)) { @@ -469,14 +532,17 @@ static void byte_input_handle_left(ByteInputModel* model) { model->selected_column = byte_input_get_row_size(model->selected_row) - 1; } } else { - byte_input_dec_selected_byte(model); + if(model->selected_row != -2) { + byte_input_dec_selected_byte(model); + } else { + byte_input_dec_selected_byte_mini(model); + } } } -/** - * @brief Handle right button - * - * @param model +/** Handle right button + * + * @param model The model */ static void byte_input_handle_right(ByteInputModel* model) { if(byte_input_keyboard_selected(model)) { @@ -486,14 +552,17 @@ static void byte_input_handle_right(ByteInputModel* model) { model->selected_column = 0; } } else { - byte_input_inc_selected_byte(model); + if(model->selected_row != -2) { + byte_input_inc_selected_byte(model); + } else { + byte_input_inc_selected_byte_mini(model); + } } } -/** - * @brief Handle OK button - * - * @param model +/** Handle OK button + * + * @param model The model */ static void byte_input_handle_ok(ByteInputModel* model) { if(byte_input_keyboard_selected(model)) { @@ -514,16 +583,17 @@ static void byte_input_handle_ok(ByteInputModel* model) { } byte_input_call_changed_callback(model); } + } else if(model->selected_row == -2) { + byte_input_call_input_callback(model); } else { byte_input_transition_from_keyboard(model); } } -/** - * @brief Draw callback - * - * @param canvas - * @param _model +/** Draw callback + * + * @param canvas The canvas + * @param _model The model */ static void byte_input_view_draw_callback(Canvas* canvas, void* _model) { ByteInputModel* model = _model; @@ -541,80 +611,89 @@ static void byte_input_view_draw_callback(Canvas* canvas, void* _model) { byte_input_draw_input(canvas, model); } - for(uint8_t row = 0; row < keyboard_row_count; row++) { - const uint8_t column_count = byte_input_get_row_size(row); - const ByteInputKey* keys = byte_input_get_row(row); + if(model->selected_row == -2) { + canvas_set_font(canvas, FontSecondary); + canvas_draw_icon(canvas, 3, 52, &I_Pin_back_arrow_10x8); + canvas_draw_str_aligned(canvas, 16, 60, AlignLeft, AlignBottom, "back to keyboard"); + } else { + // Draw keyboard + for(uint8_t row = 0; row < keyboard_row_count; row++) { + const uint8_t column_count = byte_input_get_row_size(row); + const ByteInputKey* keys = byte_input_get_row(row); - for(size_t column = 0; column < column_count; column++) { - if(keys[column].value == enter_symbol) { - canvas_set_color(canvas, ColorBlack); - if(model->selected_row == row && model->selected_column == column) { - canvas_draw_icon( - canvas, - keyboard_origin_x + keys[column].x, - keyboard_origin_y + keys[column].y, - &I_KeySaveSelected_24x11); - } else { - canvas_draw_icon( - canvas, - keyboard_origin_x + keys[column].x, - keyboard_origin_y + keys[column].y, - &I_KeySave_24x11); - } - } else if(keys[column].value == backspace_symbol) { - canvas_set_color(canvas, ColorBlack); - if(model->selected_row == row && model->selected_column == column) { - canvas_draw_icon( - canvas, - keyboard_origin_x + keys[column].x, - keyboard_origin_y + keys[column].y, - &I_KeyBackspaceSelected_16x9); + for(size_t column = 0; column < column_count; column++) { + if(keys[column].value == enter_symbol) { + canvas_set_color(canvas, ColorBlack); + if(model->selected_row == row && model->selected_column == column) { + canvas_draw_icon( + canvas, + keyboard_origin_x + keys[column].x, + keyboard_origin_y + keys[column].y, + &I_KeySaveSelected_24x11); + } else { + canvas_draw_icon( + canvas, + keyboard_origin_x + keys[column].x, + keyboard_origin_y + keys[column].y, + &I_KeySave_24x11); + } + } else if(keys[column].value == backspace_symbol) { + canvas_set_color(canvas, ColorBlack); + if(model->selected_row == row && model->selected_column == column) { + canvas_draw_icon( + canvas, + keyboard_origin_x + keys[column].x, + keyboard_origin_y + keys[column].y, + &I_KeyBackspaceSelected_16x9); + } else { + canvas_draw_icon( + canvas, + keyboard_origin_x + keys[column].x, + keyboard_origin_y + keys[column].y, + &I_KeyBackspace_16x9); + } } else { - canvas_draw_icon( + if(model->selected_row == row && model->selected_column == column) { + canvas_set_color(canvas, ColorBlack); + canvas_draw_box( + canvas, + keyboard_origin_x + keys[column].x - 3, + keyboard_origin_y + keys[column].y - 10, + 11, + 13); + canvas_set_color(canvas, ColorWhite); + } else if( + model->selected_row == -1 && row == 0 && + model->selected_column == column) { + canvas_set_color(canvas, ColorBlack); + canvas_draw_frame( + canvas, + keyboard_origin_x + keys[column].x - 3, + keyboard_origin_y + keys[column].y - 10, + 11, + 13); + } else { + canvas_set_color(canvas, ColorBlack); + } + + canvas_draw_glyph( canvas, keyboard_origin_x + keys[column].x, keyboard_origin_y + keys[column].y, - &I_KeyBackspace_16x9); - } - } else { - if(model->selected_row == row && model->selected_column == column) { - canvas_set_color(canvas, ColorBlack); - canvas_draw_box( - canvas, - keyboard_origin_x + keys[column].x - 3, - keyboard_origin_y + keys[column].y - 10, - 11, - 13); - canvas_set_color(canvas, ColorWhite); - } else if(model->selected_row == -1 && row == 0 && model->selected_column == column) { - canvas_set_color(canvas, ColorBlack); - canvas_draw_frame( - canvas, - keyboard_origin_x + keys[column].x - 3, - keyboard_origin_y + keys[column].y - 10, - 11, - 13); - } else { - canvas_set_color(canvas, ColorBlack); + keys[column].value); } - - canvas_draw_glyph( - canvas, - keyboard_origin_x + keys[column].x, - keyboard_origin_y + keys[column].y, - keys[column].value); } } } } -/** - * @brief Input callback - * - * @param event - * @param context - * @return true - * @return false +/** Input callback + * + * @param event The event + * @param context The context + * + * @return true + * @return false */ static bool byte_input_view_input_callback(InputEvent* event, void* context) { ByteInput* byte_input = context; @@ -656,6 +735,20 @@ static bool byte_input_view_input_callback(InputEvent* event, void* context) { } } + if(event->type == InputTypeShort && event->key == InputKeyBack) { + // Back to keyboard + with_view_model( + byte_input->view, + ByteInputModel * model, + { + if(model->selected_row == -2) { + model->selected_row += 1; + consumed = true; + }; + }, + true); + } + if((event->type == InputTypeLong || event->type == InputTypeRepeat) && event->key == InputKeyBack) { with_view_model( @@ -669,10 +762,9 @@ static bool byte_input_view_input_callback(InputEvent* event, void* context) { return consumed; } -/** - * @brief Reset all input-related data in model - * - * @param model ByteInputModel +/** Reset all input-related data in model + * + * @param model The model */ static void byte_input_reset_model_input_data(ByteInputModel* model) { model->bytes = NULL; @@ -684,11 +776,6 @@ static void byte_input_reset_model_input_data(ByteInputModel* model) { model->first_visible_byte = 0; } -/** - * @brief Allocate and initialize byte input. This byte input is used to enter bytes. - * - * @return ByteInput instance pointer - */ ByteInput* byte_input_alloc() { ByteInput* byte_input = malloc(sizeof(ByteInput)); byte_input->view = view_alloc(); @@ -712,38 +799,17 @@ ByteInput* byte_input_alloc() { return byte_input; } -/** - * @brief Deinitialize and free byte input - * - * @param byte_input Byte input instance - */ void byte_input_free(ByteInput* byte_input) { furi_assert(byte_input); view_free(byte_input->view); free(byte_input); } -/** - * @brief Get byte input view - * - * @param byte_input byte input instance - * @return View instance that can be used for embedding - */ View* byte_input_get_view(ByteInput* byte_input) { furi_assert(byte_input); return byte_input->view; } -/** - * @brief Deinitialize and free byte input - * - * @param byte_input byte input instance - * @param input_callback input callback fn - * @param changed_callback changed callback fn - * @param callback_context callback context - * @param bytes buffer to use - * @param bytes_count buffer length - */ void byte_input_set_result_callback( ByteInput* byte_input, ByteInputCallback input_callback, @@ -765,12 +831,6 @@ void byte_input_set_result_callback( true); } -/** - * @brief Set byte input header text - * - * @param byte_input byte input instance - * @param text text to be shown - */ void byte_input_set_header_text(ByteInput* byte_input, const char* text) { with_view_model( byte_input->view, ByteInputModel * model, { model->header = text; }, true); From fe7a1c2fccc96a1dc0589d5f01db8e22ffd9c122 Mon Sep 17 00:00:00 2001 From: MMX <10697207+xMasterX@users.noreply.github.com> Date: Tue, 1 Aug 2023 12:32:24 +0300 Subject: [PATCH 13/44] SubGHz - Keeloq: Read Centurion Nova remotes (#2892) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: hedger Co-authored-by: あく --- assets/resources/subghz/assets/keeloq_mfcodes | 107 +++++++++--------- lib/subghz/protocols/keeloq.c | 26 ++++- 2 files changed, 77 insertions(+), 56 deletions(-) diff --git a/assets/resources/subghz/assets/keeloq_mfcodes b/assets/resources/subghz/assets/keeloq_mfcodes index 3eedc564f2..f2e45b491b 100644 --- a/assets/resources/subghz/assets/keeloq_mfcodes +++ b/assets/resources/subghz/assets/keeloq_mfcodes @@ -1,56 +1,57 @@ Filetype: Flipper SubGhz Keystore File Version: 0 Encryption: 1 -IV: 41 84 34 43 84 1D 43 04 45 44 34 38 41 24 3E 74 -8C5AEF725F0620DB3952B40BB8E76A815BCEE1D1B92F7E8E8E63D1894F1C7FD0 -1DFF1D6A322D6B3D8AD7C594A02462AADE723D417B9233585526982F08187DAA -0A9184F15D4A5589DDDA6422063BACD58580661CFE60EE600D87F73F0CB5013E -6E56802DAA049C3DFDEDC90432A0E694A172C369EBECD136F4C911B979AA098D -A659716B51053604059F7FC3651D6A153F5EAB1852F95B20C44C41A7889A0DE91A078B63E3C311280C4315F0A3C8BA1F -A315170EDC51627157725D9A96490DB75EBF8232957FBA313C03B2BA2884EA85 -DEAB3C2C2E2DC76FE45AEBAC7EBFB478CECCD970A63B8DE2024FBFDCCBD1B26E -7BBFC36CBA77468B4624C6B685610877D53985C985DAD8EFE47527EB7C7260CD -879EE18B314ED4F3F548B41176099176FB97F4F1A062481C935B2DDFBCE2FE4D -493372D7D47A96A66305DFDC8A915EB651620881AE1D603B7E9605E004C04CA9 -F80AAA4C447F8E8C0B039DDAECF9126119C32FF164118780BE268E326A8CBF8010DE2EBF94033CEAC39815D6A8958CF4 -41C1393A039E665F6A53A5E5D1C105008BD14D9755751545A667860C39B2E39AA47306E76E2BA7DDDAA2A286FDB58D23 -34853A4CDE42CB80045E641AB4800C86C1CF6907EAAFA399156CCC727A008584 -D0783A34BD6A36D31BFF5F70FA1116CAE48EF02716D80481AE406DABB3C3400E -0BB3582605434CF2A5D74A27773B88DA331B6033C444837E9F7A155897258B03 -E4E71F3EB290B9436FFF0FDADA468BE37D964E89BE8D9971A14776F821822769 -744AA59D129C892120B5DAB81C8A3D573B0AD80EF0708C1B9ECF13DA60CECA07DC0591A08611DB4D3A8B7C70994D5DEF -716F9F8D5D2C697BC4183EFCC97E52D08ECA07B613A0F389C801F65803DFF4A4 -560262DA8489D2C18C8D97E314DC663403AFE4DE9DCB6D453087D2BFBD36532D -9E31F7152C50B6940EE3E3894C98F75702C7897F702B48E5C9B54B6E25083641AD2E521267505066C7E5BAB7F6CF1433 -6630EDA18A6E58BD395792CCC656DD10CD9C5DD2B1949FE677122FA39A53C724E79C0D0752A3A39A03407BBA2282185E -00D15A06F5DD82A4B926B78809CC4D129AAFA9A92B0A81568F255D15697FE0FD -29FF9A4F5346ABEE8FEDE034988F87FCD29EA747735898F1E7207EF74FAB71A8 -C0E8EB6AE6F77EE38DF2AB1B7742E34ED5236F3D8E964845E66762A4675AA21F -00FC4C459DC4CE92B62D0AC2546F9FBBE0893F84D2AF0A20ED462A5EAE63DE3B -E92EF482A40CEEFC8339BBB713BBC452A266A09B2645EDEB12716544B2DB9B09 -D7D9C5C757831BCE2FF1DB25A080D77769FB36A1F3F48F4361418A0A45609280 -C19246F52AE1EE5CE968CED52F642D9CD78B020029632FE83C49C657D23ED075 -FEE3C05432FB3860D5D28562323F5D1B053B8F3ADCD416BD0C4645F6F4D43DCF -D780A4AADD0205E0BACDCC9AF46ED259E0946C5DA888C341BFE96E09A87CCCFA -CE3C13CFA08E532B637FDB707E29548D57EE92EAEF6516C3D67E9D36FCD59CF9 -5E88CE71258CB0D91631FEB41C9A2F47AE0FF4810A9A1EDF3F308BBDE6944D5E -1531F4107FC64810BA5DB5E46C7B9AD61531AF5430E137B7688109FBC06B6221 -68050A39C0B302E0B713FAAC5F829C79AB30E18B1D982A94005DBAC7CCFB95379A619C0B9F7409C44D19FF2C5E8E4546 -3F73E8BA22C602280496EF8E88E2CAA9EC442E3B3083B684942DBF9CB5121241 -FA1FCD7C9182FAE8FFF4E88433AE68F66076B3BDFF8AD0BF5CEA43870082E9BE -DFF7DD2678C03401656B093BF7AC7E033F15FD0F30188E48A62045740B423699 -371BCFF653E7811D99C048A1A39921AAA563E06AC86CB3D2F392C2C955A1ABD0 -F4F1766DEAEDE934478208B9EB3050326D9FFCC001C73EEE93407D8B12CD49E4 -A241C9FC62DDF67D645936245FAFFE2A42C86151F484B7BCE5410E8F36FC87901D3AC4E40334E08FFFC2AD676E490D94 -3566A94A9C0479E0C4387D9137375ADF2C921504364F3903F198D6757CDFD21B -7274E1B5A6445FDC29C355D550E981C17F349BC4A14251B3B51BC96FC334FBCA -04EEA5EDD9B3BC3E0638E53A5561DC8BF761D615A64D435BD31A94AF2650159E -B84818CC1695FE8B731CD653D0679D1AAA0578C0B06AD1E3510785B2DE20841C -4121343D6B79E38C06DD038D770D76D10336AFF47ED0D0DCDDD6B0FEA4DAE67C -75E49C839CCD7019D9CE90AC364F488468B2AB01E387A8BEF8815915925166A6 -CFAA9F4717568C1EC7B96E0D71D260B828A70484E1D9CA7C99A50D10704F8BBBAE62EE98C9FBDFF06F357F1C1E2F2677 -41E4D250B92BC57442B91DE2015C41226531CF9A8D77B83AFC8E4F3183DB11DE -45EA8BD854D7F044FB249C16F08A0C24FF117D54BC20A4CC667B3DAD09EAC4F9 -F455CA0BB8B496C301406DE4FB52C9B0F64645776803BC2935A2F38675318BE2 -22FF72A5D2E1A2EBFB6C55FFD0A3CEA0474CCBD13462D63229C9708276E87D3F -8470F9A300170F226C0216C07AA829591CBD4CE34AA918EAE49363BDE86CC77EEEBEEA84A097488D35B92F773F5DBB4C +IV: 23 17 32 54 92 3A 28 13 12 DE 8B A7 24 71 25 74 +B8ACA082EA4B34E8B217A6FE63F3545D160AB7F4833C87E8743BAA7002ACC123 +E779135FE66629CAC4661B1C3D5C9857C9417CAF216241933FF6CE60A74D53C0 +15340C049A444C79ED489619A31E2AFDCFF6E4864CC4D9B1DA8E98D7EAB9C8D5 +8E696E85837B3BA8D6D380E1F36E445D630CF0B7B18A45930A08F832EE634A02 +C85341BE669E509E902FEFCA7D025A20DC80D4F14FE1C3542B1DC3A5C7393A36F901A63C3BC074B058897B12F0F5F0D6 +2834E5D7726670A03ED6C8B27B5863EEE2FD3668795251AB65B9E4FF76ADEC3E +8E71AF7660BCFC545E92674D74F98A35FCF1B54AB5BACCEE182B7F8EDB3FA356 +C20442D506332D1A410AF3187C29BE01729C282A69B85CF8D92D70FAE3407BA8 +00BC449D006566A6549A86F52B98410871B0C14D60C181BFC017446B192C934A +8A6A28DAF1F61867B1209AB9105986A7383ECE72A40F8D93F1D0066251800A3A +4A6AFDFA6130A50180358B111145D7914C720E04D69EE5459C049FCD64249153315F86A5A9F75AEE5CB726847BA64F2A +91F838BC515C8CDD32C5803679B81A24FD5CF0C3A4AEA2C07342ACA1020E05F3B393A410B33847A8C48141D923202CF3 +7C4DEBC03295291EC5B2EBB002670D14E7C972F32DB2B3CD4E61B2BE846345D9 +8FFEB948DA3D1A7FCF620F043B1D35354F83861F22B6D693F2A7119A2E287D01 +309C66AF38E6447CB33FB0967C9365CA36314DBF74695F63CF9E558A4FF5193B +411D32EC6ADED3360DE9E9A0962F97DF2B80A09F2A2AC8D4DB6DB09FAD6EA217 +A5E5550BD59425003F9166237CD4BB6A323885D7916F71F3B2795B8A4C7125ACC1237BBF0840F0E999BD2EC14327654F +4370A828AFED684B96E8EDAB670C46D2D525FCB7E469B63CD1228C902C3ACF4E +88E3853F58129C4D834B18E4D01785591094301148D802A3A21B63521DDDA325 +D5365BF55DFE7107909684F4ECCE052E617F91FAF08CE5254721A30BEF87F368F329C46439BD1EA2819DC416B2CEF247 +BDAB9FFD3A82ECE05E8CA00F11954CDB1C124B558A5D369DFE16D32C3AEF08B2013945CC69212F170F17F62A55D35928 +8E448AA1D39C894F306FE65B0D0DD733717EF81758FFA908AF7583BFD00108E5 +019A1B0AA3492427DF3DB817B438D0302B0B8C77807D19EE45EAC7F697B2EB85 +C678A3F9DA726FE1688F86BB063EA017EDB5389E0F185484D9F5DFD4EBEE0579 +760F77AB9BD99593AC855E4AE00FBAFBB34FA2BFF504BD5CC9557658E850C6D0 +4F3E77342E9A655D4EC167E2B0428833FEE31CF603FA1CE3D1BCD619D5C9D511 +2233EFBEDD4A3A95BA8160EFCED533D9F25B65AAB10F627681D2753871814366 +A1261BE878933B4905956BE7708F7C40E999714503B52B8021D44E131D87FF6C +8F31E76314A46EA9B0CCD3EDA4B2DF603829D8E3AF8CE41AEA6BFFBA2E2990AC +850C08E45CDA4E42BD4F09B956299C0ED58615BE3664791C88D1E2608D46D205 +6283656518C6ADFC3B7D309D2763BD91111720CD51029FAA691211DEFF84CB47 +9FCAF9F77C9D1B9B6934E53DB10DFF88D392D8E7BB4DC28D65F65DC396E2E00A +41D2406BE1887FCC094861E4DF0683B1BE534C5CBF059259E946F9D04222C2AB +1D6F37E645591F0C491312C1E0CB54F1A6B70F94B54D63100C4584AA016DB589338A704B6D8B6B89C2381F660D987A2F +DCEA08D6E5C0D6229EBDE07DBB6CBC0EA8D6E24A3B631CC3775CE23A496CF178 +907051215A741BE55603F27C3FD86561CC6231CEED83AA76665D6A0B6B3FEC88 +36CD5B5BCC63D45B89592B2938D6542B9D82AB47BEB73C0D30D2EC19BD8B35C2 +1FD9651ABAD773D6D22DE677CF7B19615D5B805594DCA117F04AC3255AE8184A +4900723A8F7736C9BEAE938EE021F3E44AD806244010F825D04C59E6C67B5EA2 +0D56A8CE77106DA2CB44F65B8CF5F4A024B9CC774D1C4CB8E862C95BD30B42E7B2E946CAC361F2830361C010DC938833 +11543FD104EA7D68B6B9C3BFE3F25A84F651FCB7FB5423AADDC472A48E12AFB2 +98CD236E8B92D706DA0F92F43AC1D2CAF1CFBCDC7B330A7C9D65CDC4F2E2A677 +753557A9A5075C033206111E3C832044227A32EBF3AB2B08F6FBFCC2109B2F2A +4AA124232EF6C25CB7321F5E5F7BE11114C763F8DDAFB6B05E8412ADF37B5C7B +01514EA408E26BAFD30290429DE1A0211F4FBDB09DE2E66CE92A6F09B998EF29 +4715716D5AFF99A2D8205A46AEEF0BC20D72F3F54991F7DF4142FF187485C178 +281A32B90F8B85F31F54BF0D83B6D03E4E65A72ADB3D5A297C91881E36B45E8F +9C05D3CB9F473D5693697A8567DBA7CF650C0A0D6C1BBE3ACE78ACDE0BD027B6C836B6CB6365D5B5D00F101FA83876B9 +DC88B0237634CB007244A4169A5D9F5F65FC782E3C4388358A7E2019F7B4CC05 +BC7ACAA91D23616A0070DCA328901DDDE3BB5B59260FB45083916B6ED0E6450C +A280434D059D652D77ACB9F44409CDC7393A876239BA894DD4BE843FAB0AC561 +334F1316A35EB8A838F6B209FA4F8148062972E27A296379731B1F728A0BB32E +DDC9883E90EBE73915CFDF8EA7193F2449B66010D45F5EC6F20949D5C49719A9298B95269531A3440577B00EADE1B379 diff --git a/lib/subghz/protocols/keeloq.c b/lib/subghz/protocols/keeloq.c index 7748da1ee0..80fecbbf93 100644 --- a/lib/subghz/protocols/keeloq.c +++ b/lib/subghz/protocols/keeloq.c @@ -467,6 +467,19 @@ static inline bool subghz_protocol_keeloq_check_decrypt( } return false; } +// Centurion specific check +static inline bool subghz_protocol_keeloq_check_decrypt_centurion( + SubGhzBlockGeneric* instance, + uint32_t decrypt, + uint8_t btn) { + furi_assert(instance); + + if((decrypt >> 28 == btn) && (((((uint16_t)(decrypt >> 16)) & 0x3FF) == 0x1CE))) { + instance->cnt = decrypt & 0x0000FFFF; + return true; + } + return false; +} /** * Checking the accepted code against the database manafacture key @@ -509,9 +522,16 @@ static uint8_t subghz_protocol_keeloq_check_remote_controller_selector( // https://phreakerclub.com/forum/showpost.php?p=43557&postcount=37 man = subghz_protocol_keeloq_common_normal_learning(fix, manufacture_code->key); decrypt = subghz_protocol_keeloq_common_decrypt(hop, man); - if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { - *manufacture_name = furi_string_get_cstr(manufacture_code->name); - return 1; + if((strcmp(furi_string_get_cstr(manufacture_code->name), "Centurion") == 0)) { + if(subghz_protocol_keeloq_check_decrypt_centurion(instance, decrypt, btn)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + return 1; + } + } else { + if(subghz_protocol_keeloq_check_decrypt(instance, decrypt, btn, end_serial)) { + *manufacture_name = furi_string_get_cstr(manufacture_code->name); + return 1; + } } break; case KEELOQ_LEARNING_SECURE: From 67ca96ea96cdcdf0942b7186128db9a8db3e88a6 Mon Sep 17 00:00:00 2001 From: Francis Date: Tue, 1 Aug 2023 11:45:39 +0200 Subject: [PATCH 14/44] Added French Canadian layout (#2896) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit French Canadian layout for Windows Co-authored-by: あく --- assets/resources/badusb/assets/layouts/fr-CA.kl | Bin 0 -> 256 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 assets/resources/badusb/assets/layouts/fr-CA.kl diff --git a/assets/resources/badusb/assets/layouts/fr-CA.kl b/assets/resources/badusb/assets/layouts/fr-CA.kl new file mode 100644 index 0000000000000000000000000000000000000000..9de8a4732d3184c4de543bec65d445bcc6e82200 GIT binary patch literal 256 zcmaKnHx9x;0KhDZ-g|F>6hxO$lJ)-oDp*d}Zgp{{$itwNeC-+vYTC;A$rY+lc?Ao*Mz@a0@PMkV(?!u)j*KXXJ vhTJSXx%&(is??~{ph=519lG@BGhoPwF%zcDn6qHXiZvUy#32t!czw@4f$0q} literal 0 HcmV?d00001 From 1536f7a643ce9636745f5270bbd79f53249bfc2a Mon Sep 17 00:00:00 2001 From: Astro <130178009+astro-cyberpaws@users.noreply.github.com> Date: Tue, 1 Aug 2023 06:33:17 -0700 Subject: [PATCH 15/44] Update audio.ir (#2897) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Update audio.ir: added Panasonic SA-PM193 codes to universal remote * Update audio.ir: added play/pause code as Pause button Co-authored-by: あく --- assets/resources/infrared/assets/audio.ir | 49 +++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/assets/resources/infrared/assets/audio.ir b/assets/resources/infrared/assets/audio.ir index 825d1bc3ef..3b9e626ba5 100644 --- a/assets/resources/infrared/assets/audio.ir +++ b/assets/resources/infrared/assets/audio.ir @@ -328,3 +328,52 @@ type: parsed protocol: NECext address: 30 FC 00 00 command: 0C F3 00 00 +# +# Model: Panasonic SA-PM193 +name: Power +type: parsed +protocol: Kaseikyo +address: AC 02 20 00 +command: D1 03 00 00 +# CD play/pause, tape play also exists but probably less commonly used +name: Play +type: parsed +protocol: Kaseikyo +address: AA 02 20 00 +command: A0 00 00 00 +# same as above +name: Pause +type: parsed +protocol: Kaseikyo +address: AA 02 20 00 +command: A0 00 00 00 +# +name: Vol_up +type: parsed +protocol: Kaseikyo +address: A0 02 20 00 +command: 00 02 00 00 +# +name: Vol_dn +type: parsed +protocol: Kaseikyo +address: A0 02 20 00 +command: 10 02 00 00 +# +name: Next +type: parsed +protocol: Kaseikyo +address: AC 02 20 01 +command: A1 00 00 00 +# +name: Prev +type: parsed +protocol: Kaseikyo +address: AC 02 20 01 +command: 91 00 00 00 +# +name: Mute +type: parsed +protocol: Kaseikyo +address: A0 02 20 00 +command: 20 03 00 00 From 17bcfee2242f5fe00923fdc61cec5a4f3c856719 Mon Sep 17 00:00:00 2001 From: hedger Date: Tue, 1 Aug 2023 18:43:14 +0300 Subject: [PATCH 16/44] [FL-3441] faploader: always create app dir, even if it doesn't have subdirs (#2901) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく --- lib/flipper_application/application_assets.c | 25 ++++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/flipper_application/application_assets.c b/lib/flipper_application/application_assets.c index 1262870d5e..083c3ca197 100644 --- a/lib/flipper_application/application_assets.c +++ b/lib/flipper_application/application_assets.c @@ -157,14 +157,6 @@ static bool flipper_application_assets_process_dirs( FuriString* full_path = flipper_application_assets_alloc_app_full_path(app_name); do { - if(!storage_simply_mkdir(storage, APPS_ASSETS_PATH)) { - break; - } - - if(!storage_simply_mkdir(storage, furi_string_get_cstr(full_path))) { - break; - } - FuriString* dir_path = furi_string_alloc(); char* path = NULL; @@ -279,6 +271,8 @@ bool flipper_application_assets_load(File* file, const char* elf_path, size_t of FURI_LOG_D(TAG, "Loading assets for %s", furi_string_get_cstr(app_name)); + FuriString* full_path = flipper_application_assets_alloc_app_full_path(app_name); + do { if(!storage_file_seek(file, offset, true)) { break; @@ -319,13 +313,23 @@ bool flipper_application_assets_load(File* file, const char* elf_path, size_t of FURI_LOG_D(TAG, "Assets removed"); } + if(!storage_simply_mkdir(storage, APPS_ASSETS_PATH)) { + break; + } + + if(!storage_simply_mkdir(storage, furi_string_get_cstr(full_path))) { + break; + } + // process directories - if(!flipper_application_assets_process_dirs(storage, file, app_name, header.dirs_count)) { + if(header.dirs_count && + !flipper_application_assets_process_dirs(storage, file, app_name, header.dirs_count)) { break; } // process files - if(!flipper_application_assets_process_files(storage, file, app_name, header.files_count)) { + if(header.files_count && !flipper_application_assets_process_files( + storage, file, app_name, header.files_count)) { break; } @@ -353,6 +357,7 @@ bool flipper_application_assets_load(File* file, const char* elf_path, size_t of } furi_record_close(RECORD_STORAGE); + furi_string_free(full_path); furi_string_free(app_name); FURI_LOG_D(TAG, "Assets loading %s", result ? "success" : "failed"); From a677b2bcc23a6f44f584b4bfdd4bbdfb8443b815 Mon Sep 17 00:00:00 2001 From: Astra <93453568+Astrrra@users.noreply.github.com> Date: Wed, 2 Aug 2023 00:50:17 +0900 Subject: [PATCH 17/44] [FL-3469] Move U2F path to ext (#2935) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく --- applications/main/u2f/u2f_data.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/main/u2f/u2f_data.c b/applications/main/u2f/u2f_data.c index 66604d166a..e5433544a1 100644 --- a/applications/main/u2f/u2f_data.c +++ b/applications/main/u2f/u2f_data.c @@ -7,7 +7,7 @@ #define TAG "U2F" -#define U2F_DATA_FOLDER ANY_PATH("u2f/") +#define U2F_DATA_FOLDER EXT_PATH("u2f/") #define U2F_CERT_FILE U2F_DATA_FOLDER "assets/cert.der" #define U2F_CERT_KEY_FILE U2F_DATA_FOLDER "assets/cert_key.u2f" #define U2F_KEY_FILE U2F_DATA_FOLDER "key.u2f" From be86b0f38ad7245749ac8bcafa12bf55f142f76b Mon Sep 17 00:00:00 2001 From: plgcoder <112718803+plgcoder@users.noreply.github.com> Date: Wed, 2 Aug 2023 05:43:36 +0200 Subject: [PATCH 18/44] Overly missed feature: Infrared: move button (change button order in a remote) (#2894) * Feature: Infrared: move button (change button order in a remote) * little fix in furi_assert (case Move button to the end) --- applications/main/infrared/infrared_i.h | 3 + applications/main/infrared/infrared_remote.c | 15 +++ applications/main/infrared/infrared_remote.h | 1 + .../infrared/scenes/infrared_scene_config.h | 2 + .../infrared/scenes/infrared_scene_edit.c | 12 ++ .../infrared_scene_edit_button_select.c | 35 +++++- .../scenes/infrared_scene_edit_move.c | 103 ++++++++++++++++++ .../scenes/infrared_scene_edit_move_done.c | 48 ++++++++ 8 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 applications/main/infrared/scenes/infrared_scene_edit_move.c create mode 100644 applications/main/infrared/scenes/infrared_scene_edit_move_done.c diff --git a/applications/main/infrared/infrared_i.h b/applications/main/infrared/infrared_i.h index 9e65c2b1c9..96932d9bc5 100644 --- a/applications/main/infrared/infrared_i.h +++ b/applications/main/infrared/infrared_i.h @@ -60,6 +60,8 @@ typedef enum { InfraredEditModeNone, InfraredEditModeRename, InfraredEditModeDelete, + InfraredEditModeMove, + InfraredEditModeMoveSelectDest } InfraredEditMode; typedef struct { @@ -69,6 +71,7 @@ typedef struct { InfraredEditTarget edit_target : 8; InfraredEditMode edit_mode : 8; int32_t current_button_index; + int32_t current_button_index_move_orig; uint32_t last_transmit_time; } InfraredAppState; diff --git a/applications/main/infrared/infrared_remote.c b/applications/main/infrared/infrared_remote.c index d3dfc2cce9..a04a338baa 100644 --- a/applications/main/infrared/infrared_remote.c +++ b/applications/main/infrared/infrared_remote.c @@ -108,6 +108,21 @@ bool infrared_remote_delete_button(InfraredRemote* remote, size_t index) { return infrared_remote_store(remote); } +bool infrared_remote_move_button(InfraredRemote* remote, size_t index_orig, size_t index_dest) { + furi_assert(index_orig < InfraredButtonArray_size(remote->buttons)); + furi_assert(index_dest <= InfraredButtonArray_size(remote->buttons)); + if(index_orig == index_dest) { + return true; + } + InfraredRemoteButton* button; + InfraredButtonArray_pop_at(&button, remote->buttons, index_orig); + if(index_orig > index_dest) + InfraredButtonArray_push_at(remote->buttons, index_dest, button); + else + InfraredButtonArray_push_at(remote->buttons, index_dest - 1, button); + return infrared_remote_store(remote); +} + bool infrared_remote_store(InfraredRemote* remote) { Storage* storage = furi_record_open(RECORD_STORAGE); FlipperFormat* ff = flipper_format_file_alloc(storage); diff --git a/applications/main/infrared/infrared_remote.h b/applications/main/infrared/infrared_remote.h index 6eac193d3a..2640149a48 100644 --- a/applications/main/infrared/infrared_remote.h +++ b/applications/main/infrared/infrared_remote.h @@ -23,6 +23,7 @@ bool infrared_remote_find_button_by_name(InfraredRemote* remote, const char* nam bool infrared_remote_add_button(InfraredRemote* remote, const char* name, InfraredSignal* signal); bool infrared_remote_rename_button(InfraredRemote* remote, const char* new_name, size_t index); bool infrared_remote_delete_button(InfraredRemote* remote, size_t index); +bool infrared_remote_move_button(InfraredRemote* remote, size_t index_orig, size_t index_dest); bool infrared_remote_store(InfraredRemote* remote); bool infrared_remote_load(InfraredRemote* remote, FuriString* path); diff --git a/applications/main/infrared/scenes/infrared_scene_config.h b/applications/main/infrared/scenes/infrared_scene_config.h index 27eabe225f..36e6ae252f 100644 --- a/applications/main/infrared/scenes/infrared_scene_config.h +++ b/applications/main/infrared/scenes/infrared_scene_config.h @@ -7,6 +7,8 @@ ADD_SCENE(infrared, edit_delete_done, EditDeleteDone) ADD_SCENE(infrared, edit_button_select, EditButtonSelect) ADD_SCENE(infrared, edit_rename, EditRename) ADD_SCENE(infrared, edit_rename_done, EditRenameDone) +ADD_SCENE(infrared, edit_move, EditMove) +ADD_SCENE(infrared, edit_move_done, EditMoveDone) ADD_SCENE(infrared, learn, Learn) ADD_SCENE(infrared, learn_done, LearnDone) ADD_SCENE(infrared, learn_enter_name, LearnEnterName) diff --git a/applications/main/infrared/scenes/infrared_scene_edit.c b/applications/main/infrared/scenes/infrared_scene_edit.c index 360ed49b35..79de04bda6 100644 --- a/applications/main/infrared/scenes/infrared_scene_edit.c +++ b/applications/main/infrared/scenes/infrared_scene_edit.c @@ -3,6 +3,7 @@ typedef enum { SubmenuIndexAddButton, SubmenuIndexRenameButton, + SubmenuIndexMoveButton, SubmenuIndexDeleteButton, SubmenuIndexRenameRemote, SubmenuIndexDeleteRemote, @@ -30,6 +31,12 @@ void infrared_scene_edit_on_enter(void* context) { SubmenuIndexRenameButton, infrared_scene_edit_submenu_callback, context); + submenu_add_item( + submenu, + "Move Button", + SubmenuIndexMoveButton, + infrared_scene_edit_submenu_callback, + context); submenu_add_item( submenu, "Delete Button", @@ -74,6 +81,11 @@ bool infrared_scene_edit_on_event(void* context, SceneManagerEvent event) { infrared->app_state.edit_mode = InfraredEditModeRename; scene_manager_next_scene(scene_manager, InfraredSceneEditButtonSelect); consumed = true; + } else if(submenu_index == SubmenuIndexMoveButton) { + infrared->app_state.edit_target = InfraredEditTargetButton; + infrared->app_state.edit_mode = InfraredEditModeMove; + scene_manager_next_scene(scene_manager, InfraredSceneEditButtonSelect); + consumed = true; } else if(submenu_index == SubmenuIndexDeleteButton) { infrared->app_state.edit_target = InfraredEditTargetButton; infrared->app_state.edit_mode = InfraredEditModeDelete; diff --git a/applications/main/infrared/scenes/infrared_scene_edit_button_select.c b/applications/main/infrared/scenes/infrared_scene_edit_button_select.c index a7f8a2bf7a..7056a20539 100644 --- a/applications/main/infrared/scenes/infrared_scene_edit_button_select.c +++ b/applications/main/infrared/scenes/infrared_scene_edit_button_select.c @@ -11,9 +11,23 @@ void infrared_scene_edit_button_select_on_enter(void* context) { InfraredRemote* remote = infrared->remote; InfraredAppState* app_state = &infrared->app_state; - const char* header = infrared->app_state.edit_mode == InfraredEditModeRename ? - "Rename Button:" : - "Delete Button:"; + const char* header = NULL; + switch(infrared->app_state.edit_mode) { + case InfraredEditModeRename: + header = "Rename Button:"; + break; + case InfraredEditModeDelete: + header = "Delete Button:"; + break; + case InfraredEditModeMove: + header = "Select Button to Move:"; + break; + case InfraredEditModeMoveSelectDest: + case InfraredEditModeNone: + default: + header = "Move Button Before:"; + break; + } submenu_set_header(submenu, header); const size_t button_count = infrared_remote_get_button_count(remote); @@ -26,7 +40,14 @@ void infrared_scene_edit_button_select_on_enter(void* context) { infrared_scene_edit_button_select_submenu_callback, context); } - + if(infrared->app_state.edit_mode == InfraredEditModeMoveSelectDest) { + submenu_add_item( + submenu, + "-- Move to the end --", + button_count, + infrared_scene_edit_button_select_submenu_callback, + context); + } if(button_count && app_state->current_button_index != InfraredButtonIndexNone) { submenu_set_selected_item(submenu, app_state->current_button_index); app_state->current_button_index = InfraredButtonIndexNone; @@ -48,6 +69,12 @@ bool infrared_scene_edit_button_select_on_event(void* context, SceneManagerEvent scene_manager_next_scene(scene_manager, InfraredSceneEditRename); } else if(edit_mode == InfraredEditModeDelete) { scene_manager_next_scene(scene_manager, InfraredSceneEditDelete); + } else if(edit_mode == InfraredEditModeMove) { + app_state->current_button_index_move_orig = event.event; + app_state->edit_mode = InfraredEditModeMoveSelectDest; + scene_manager_next_scene(scene_manager, InfraredSceneEditButtonSelect); + } else if(edit_mode == InfraredEditModeMoveSelectDest) { + scene_manager_next_scene(scene_manager, InfraredSceneEditMove); } else { furi_assert(0); } diff --git a/applications/main/infrared/scenes/infrared_scene_edit_move.c b/applications/main/infrared/scenes/infrared_scene_edit_move.c new file mode 100644 index 0000000000..69c7ec41de --- /dev/null +++ b/applications/main/infrared/scenes/infrared_scene_edit_move.c @@ -0,0 +1,103 @@ +#include "../infrared_i.h" + +static void infrared_scene_edit_move_dialog_result_callback(DialogExResult result, void* context) { + Infrared* infrared = context; + view_dispatcher_send_custom_event(infrared->view_dispatcher, result); +} + +void infrared_scene_edit_move_on_enter(void* context) { + Infrared* infrared = context; + DialogEx* dialog_ex = infrared->dialog_ex; + InfraredRemote* remote = infrared->remote; + + const InfraredEditTarget edit_target = infrared->app_state.edit_target; + if(edit_target == InfraredEditTargetButton) { + int32_t current_button_index = infrared->app_state.current_button_index_move_orig; + furi_assert(current_button_index != InfraredButtonIndexNone); + + dialog_ex_set_header(dialog_ex, "Move Button?", 64, 0, AlignCenter, AlignTop); + InfraredRemoteButton* current_button = + infrared_remote_get_button(remote, current_button_index); + InfraredSignal* signal = infrared_remote_button_get_signal(current_button); + + if(infrared_signal_is_raw(signal)) { + const InfraredRawSignal* raw = infrared_signal_get_raw_signal(signal); + infrared_text_store_set( + infrared, + 0, + "%s\nRAW\n%ld samples", + infrared_remote_button_get_name(current_button), + raw->timings_size); + + } else { + const InfraredMessage* message = infrared_signal_get_message(signal); + infrared_text_store_set( + infrared, + 0, + "%s\n%s\nA=0x%0*lX C=0x%0*lX", + infrared_remote_button_get_name(current_button), + infrared_get_protocol_name(message->protocol), + ROUND_UP_TO(infrared_get_protocol_address_length(message->protocol), 4), + message->address, + ROUND_UP_TO(infrared_get_protocol_command_length(message->protocol), 4), + message->command); + } + } else { + furi_assert(0); + } + + dialog_ex_set_text(dialog_ex, infrared->text_store[0], 64, 31, AlignCenter, AlignCenter); + dialog_ex_set_icon(dialog_ex, 0, 0, NULL); + dialog_ex_set_left_button_text(dialog_ex, "Cancel"); + dialog_ex_set_right_button_text(dialog_ex, "Move"); + dialog_ex_set_result_callback(dialog_ex, infrared_scene_edit_move_dialog_result_callback); + dialog_ex_set_context(dialog_ex, context); + + view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewDialogEx); +} + +bool infrared_scene_edit_move_on_event(void* context, SceneManagerEvent event) { + Infrared* infrared = context; + SceneManager* scene_manager = infrared->scene_manager; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == DialogExResultLeft) { + scene_manager_previous_scene(scene_manager); + consumed = true; + } else if(event.event == DialogExResultRight) { + bool success = false; + InfraredRemote* remote = infrared->remote; + InfraredAppState* app_state = &infrared->app_state; + const InfraredEditTarget edit_target = app_state->edit_target; + + if(edit_target == InfraredEditTargetButton) { + furi_assert(app_state->current_button_index != InfraredButtonIndexNone); + success = infrared_remote_move_button( + remote, + app_state->current_button_index_move_orig, + app_state->current_button_index); + app_state->current_button_index_move_orig = InfraredButtonIndexNone; + app_state->current_button_index = InfraredButtonIndexNone; + } else { + furi_assert(0); + } + + if(success) { + scene_manager_next_scene(scene_manager, InfraredSceneEditMoveDone); + } else { + const uint32_t possible_scenes[] = {InfraredSceneRemoteList, InfraredSceneStart}; + scene_manager_search_and_switch_to_previous_scene_one_of( + scene_manager, possible_scenes, COUNT_OF(possible_scenes)); + } + consumed = true; + } + } + + return consumed; +} + +void infrared_scene_edit_move_on_exit(void* context) { + Infrared* infrared = context; + UNUSED(infrared); +} diff --git a/applications/main/infrared/scenes/infrared_scene_edit_move_done.c b/applications/main/infrared/scenes/infrared_scene_edit_move_done.c new file mode 100644 index 0000000000..9f9b4b80d3 --- /dev/null +++ b/applications/main/infrared/scenes/infrared_scene_edit_move_done.c @@ -0,0 +1,48 @@ +#include "../infrared_i.h" + +void infrared_scene_edit_move_done_on_enter(void* context) { + Infrared* infrared = context; + Popup* popup = infrared->popup; + + popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62); + popup_set_header(popup, "Moved", 83, 19, AlignLeft, AlignBottom); + + popup_set_callback(popup, infrared_popup_closed_callback); + popup_set_context(popup, context); + popup_set_timeout(popup, 1500); + popup_enable_timeout(popup); + + view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewPopup); +} + +bool infrared_scene_edit_move_done_on_event(void* context, SceneManagerEvent event) { + Infrared* infrared = context; + SceneManager* scene_manager = infrared->scene_manager; + bool consumed = false; + + if(event.type == SceneManagerEventTypeCustom) { + if(event.event == InfraredCustomEventTypePopupClosed) { + const InfraredEditTarget edit_target = infrared->app_state.edit_target; + if(edit_target == InfraredEditTargetButton) { + scene_manager_search_and_switch_to_previous_scene( + scene_manager, InfraredSceneRemote); + } else if(edit_target == InfraredEditTargetRemote) { + const uint32_t possible_scenes[] = {InfraredSceneStart, InfraredSceneRemoteList}; + if(!scene_manager_search_and_switch_to_previous_scene_one_of( + scene_manager, possible_scenes, COUNT_OF(possible_scenes))) { + view_dispatcher_stop(infrared->view_dispatcher); + } + } else { + furi_assert(0); + } + consumed = true; + } + } + + return consumed; +} + +void infrared_scene_edit_move_done_on_exit(void* context) { + Infrared* infrared = context; + UNUSED(infrared); +} From 035e447009b6e075ef2f94fd5e761ffb2ed87f99 Mon Sep 17 00:00:00 2001 From: Astra <93453568+Astrrra@users.noreply.github.com> Date: Wed, 2 Aug 2023 12:58:39 +0900 Subject: [PATCH 19/44] [FL-3462] External apps icounter (#2928) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: あく --- applications/external/hid_app/hid.c | 5 ----- applications/services/dolphin/helpers/dolphin_deed.c | 2 +- applications/services/loader/loader_applications.c | 3 +++ 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/applications/external/hid_app/hid.c b/applications/external/hid_app/hid.c index a969a933a1..2be9afd919 100644 --- a/applications/external/hid_app/hid.c +++ b/applications/external/hid_app/hid.c @@ -1,7 +1,6 @@ #include "hid.h" #include "views.h" #include -#include #define TAG "HidApp" @@ -389,8 +388,6 @@ int32_t hid_usb_app(void* p) { bt_hid_connection_status_changed_callback(BtStatusConnected, app); - dolphin_deed(DolphinDeedPluginStart); - view_dispatcher_run(app->view_dispatcher); furi_hal_usb_set_config(usb_mode_prev, NULL); @@ -429,8 +426,6 @@ int32_t hid_ble_app(void* p) { furi_hal_bt_start_advertising(); bt_set_status_changed_callback(app->bt, bt_hid_connection_status_changed_callback, app); - dolphin_deed(DolphinDeedPluginStart); - view_dispatcher_run(app->view_dispatcher); bt_set_status_changed_callback(app->bt, NULL, NULL); diff --git a/applications/services/dolphin/helpers/dolphin_deed.c b/applications/services/dolphin/helpers/dolphin_deed.c index 51db56fdf6..f1f42b770f 100644 --- a/applications/services/dolphin/helpers/dolphin_deed.c +++ b/applications/services/dolphin/helpers/dolphin_deed.c @@ -39,7 +39,7 @@ static const DolphinDeedWeight dolphin_deed_weights[] = { {1, DolphinAppPlugin}, // DolphinDeedGpioUartBridge - {1, DolphinAppPlugin}, // DolphinDeedPluginStart + {2, DolphinAppPlugin}, // DolphinDeedPluginStart {1, DolphinAppPlugin}, // DolphinDeedPluginGameStart {10, DolphinAppPlugin}, // DolphinDeedPluginGameWin }; diff --git a/applications/services/loader/loader_applications.c b/applications/services/loader/loader_applications.c index 8ae91d7640..2e1de6134a 100644 --- a/applications/services/loader/loader_applications.c +++ b/applications/services/loader/loader_applications.c @@ -6,6 +6,7 @@ #include #include #include +#include #define TAG "LoaderApplications" @@ -119,6 +120,8 @@ static void loader_pubsub_callback(const void* message, void* context) { static void loader_applications_start_app(LoaderApplicationsApp* app) { const char* name = furi_string_get_cstr(app->fap_path); + dolphin_deed(DolphinDeedPluginStart); + // load app FuriThreadId thread_id = furi_thread_get_current_id(); FuriPubSubSubscription* subscription = From c72531edc636ddbacda75d86f9bb74e0f1bb92fb Mon Sep 17 00:00:00 2001 From: Leopold Date: Wed, 2 Aug 2023 12:23:04 +0800 Subject: [PATCH 20/44] change FuriThreadPriorityIsr to 31 (configMAX_PRIORITIES-1) (#2920) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * change FuriThreadPriorityIsr to 31 (configMAX_PRIORITIES-1) * Furi: less hardcoded max priority, fix spelling * Format sources Co-authored-by: hedger Co-authored-by: あく --- furi/core/thread.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/furi/core/thread.h b/furi/core/thread.h index 022894ee8f..692f2a1008 100644 --- a/furi/core/thread.h +++ b/furi/core/thread.h @@ -28,7 +28,7 @@ typedef enum { FuriThreadPriorityNormal = 16, /**< Normal */ FuriThreadPriorityHigh = 17, /**< High */ FuriThreadPriorityHighest = 18, /**< Highest */ - FuriThreadPriorityIsr = 32, /**< Deffered Isr (highest possible) */ + FuriThreadPriorityIsr = (configMAX_PRIORITIES - 1), /**< Deferred ISR (highest possible) */ } FuriThreadPriority; /** FuriThread anonymous structure */ From 313e9c3d890f874ef62821b0108540071fe59e61 Mon Sep 17 00:00:00 2001 From: minchogaydarov <134236905+minchogaydarov@users.noreply.github.com> Date: Wed, 2 Aug 2023 07:32:12 +0300 Subject: [PATCH 21/44] Add Daikin FTXC35DV1B ac remote (#2913) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: hedger Co-authored-by: あく --- assets/resources/infrared/assets/ac.ir | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/assets/resources/infrared/assets/ac.ir b/assets/resources/infrared/assets/ac.ir index 6ec6fc8295..ac7628e178 100644 --- a/assets/resources/infrared/assets/ac.ir +++ b/assets/resources/infrared/assets/ac.ir @@ -581,3 +581,40 @@ type: raw frequency: 38000 duty_cycle: 0.330000 data: 3204 9889 537 1587 491 529 512 544 489 545 489 1573 510 530 511 543 491 552 490 538 511 543 491 543 491 532 509 543 491 1587 489 537 512 543 491 1577 490 543 491 543 491 544 489 543 491 1586 489 544 490 1587 489 539 510 543 491 543 491 1586 490 +# +# Model: Daikin FTXC35DV1B +name: Off +type: raw +frequency: 38000 +duty_cycle: 0.330000 +data: 530 315 532 314 532 314 532 314 532 314 506 340 561 24780 3568 1647 507 1213 535 313 534 340 506 340 506 1212 507 339 507 339 506 339 506 339 506 1214 505 341 504 1215 505 1216 504 343 503 1217 503 1218 502 1218 502 1218 502 1218 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 1218 502 344 502 1219 501 345 501 344 502 345 501 1219 501 1219 501 345 501 344 502 344 502 345 501 344 502 345 501 344 502 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 1219 501 1219 501 1219 501 345 501 1219 501 345 501 1219 501 1219 501 34807 3563 1652 502 1218 502 344 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 1219 501 344 502 1218 502 1219 501 344 502 1219 501 1218 502 1219 501 1219 501 1219 501 345 501 344 502 1219 501 345 501 344 502 345 501 344 502 344 502 345 501 345 501 345 501 344 502 345 501 345 501 1219 501 345 501 345 501 345 501 345 501 1219 501 345 501 345 501 1219 501 345 501 345 501 1219 501 1219 501 345 501 1219 501 1219 501 1219 501 345 501 345 501 345 501 345 501 345 501 345 501 1219 501 345 501 345 501 1220 500 346 500 345 501 346 500 346 500 34806 3564 1652 502 1218 502 344 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 1218 502 344 502 1218 502 1218 502 344 502 1218 502 1218 502 1218 502 1219 501 1218 502 344 502 345 501 1219 501 345 501 344 502 345 501 344 502 344 502 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 1219 501 345 501 1219 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 1219 501 1219 501 345 501 345 501 345 501 346 500 345 501 345 501 345 501 345 501 346 500 346 500 346 500 346 500 346 500 1220 499 346 500 1220 499 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 347 499 346 500 1221 499 1221 499 1221 499 347 499 347 499 347 499 347 499 347 499 347 499 347 499 347 499 347 499 1245 475 1222 498 1245 475 371 475 348 498 348 498 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 372 474 372 474 372 474 371 475 371 475 1246 474 371 475 1246 474 372 474 372 474 372 474 1246 474 1246 474 372 474 371 475 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 1246 474 372 474 1246 474 1246 473 372 474 372 474 1246 474 372 474 +# +name: Dh +type: raw +frequency: 38000 +duty_cycle: 0.330000 +data: 536 339 507 311 535 312 534 312 534 312 534 339 507 24807 3710 1507 594 1156 563 305 543 304 542 304 570 1126 592 304 515 304 542 304 542 304 542 1155 564 304 541 1158 505 1215 505 342 504 1217 503 1217 503 1218 502 1218 502 1218 502 344 502 343 503 1218 502 343 503 343 503 344 502 344 502 344 502 344 502 344 502 343 503 343 503 344 502 1218 502 344 502 1218 502 344 502 344 502 344 502 1218 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 1218 502 1218 502 1218 501 344 502 1218 502 344 502 1218 502 1218 502 34800 3564 1651 503 1217 503 343 503 344 502 343 503 1217 503 343 503 343 503 344 502 344 502 1218 502 344 502 1217 503 1218 502 344 502 1218 502 1218 502 1218 502 1218 502 1218 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 1218 502 344 502 1218 502 1218 502 344 502 344 502 1218 502 1218 502 344 502 1218 502 1219 501 1219 501 345 501 344 502 344 502 344 502 344 502 345 501 345 501 1219 501 345 501 1219 501 345 501 345 501 345 501 345 501 34805 3565 1650 503 1216 503 343 503 343 503 344 502 1217 503 343 503 344 502 343 503 343 503 1217 503 344 502 1218 502 1218 502 344 502 1218 502 1218 502 1218 502 1218 502 1218 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 1218 502 344 502 344 502 1218 502 344 502 1218 501 344 502 344 502 344 502 345 501 344 502 345 501 344 502 345 501 1219 501 1219 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 1219 501 345 501 1219 501 345 501 345 501 345 501 345 501 346 500 345 501 345 501 346 500 370 476 346 500 346 500 346 500 370 476 346 500 346 500 346 500 346 500 1221 499 1244 476 1244 476 370 476 346 500 370 476 370 476 370 476 370 476 370 476 370 476 370 476 1244 476 1244 476 1244 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 1244 476 370 476 1245 475 370 476 371 475 370 476 1245 475 1245 475 371 475 371 475 370 476 370 476 370 476 370 476 370 476 371 475 370 476 371 475 371 475 371 475 371 475 370 476 371 475 371 475 371 475 1245 475 1245 475 1245 475 371 475 371 475 1245 475 371 475 +# +name: Cool_hi +type: raw +frequency: 38000 +duty_cycle: 0.330000 +data: 507 340 559 306 487 341 530 315 531 313 561 305 541 24776 3569 1646 508 1212 537 340 506 340 506 340 506 1213 507 339 507 339 506 339 506 340 505 1214 505 341 504 1215 504 1216 503 343 503 1217 502 1218 502 1218 502 1218 502 1218 501 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 1218 502 344 502 1218 502 344 502 344 502 344 502 1219 501 1218 502 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 1219 501 1219 501 1219 501 345 501 1219 501 345 501 1219 501 1219 501 34800 3563 1652 502 1217 502 344 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 1218 502 344 502 1218 502 1218 501 344 502 1218 502 1218 502 1218 502 1218 502 1218 502 344 502 344 502 1218 502 345 501 345 501 344 502 345 501 344 502 345 501 345 501 345 501 344 502 345 501 345 501 1219 501 345 501 345 501 345 501 345 501 1219 501 345 501 1219 501 1219 501 345 501 345 501 1219 501 1219 501 345 501 1219 500 1219 500 1219 500 345 501 345 501 345 501 345 501 345 501 345 501 345 501 1219 501 345 501 1220 500 346 500 346 500 346 500 346 500 34808 3564 1652 503 1218 502 344 502 344 502 344 502 1218 502 344 502 344 502 345 501 344 502 1218 502 345 501 1218 502 1219 501 344 502 1219 501 1219 501 1219 501 1219 501 1219 501 345 501 345 501 1219 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 1219 500 345 501 345 501 1219 500 1219 501 1219 501 345 501 345 501 345 501 345 501 1219 501 345 501 345 501 1219 501 346 500 346 500 345 501 345 501 346 500 346 500 346 500 345 501 346 500 346 500 346 500 346 500 346 500 346 500 346 500 1220 500 346 500 1220 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 347 499 347 499 346 500 1221 499 1245 475 1221 499 347 499 347 499 347 499 348 498 347 499 348 498 348 498 371 475 348 498 1222 498 1245 475 1245 475 348 498 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 372 474 372 474 372 474 371 475 1245 474 372 474 1246 474 372 474 372 474 372 474 1246 474 1246 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 1246 474 372 474 372 474 372 474 372 474 1247 473 1247 473 +# +name: Cool_lo +type: raw +frequency: 38000 +duty_cycle: 0.330000 +data: 533 311 535 312 534 312 534 313 533 310 536 312 534 24804 3705 1509 593 1129 590 305 542 305 542 305 569 1127 590 304 514 305 541 304 542 305 541 1155 564 305 540 1157 561 1159 504 341 504 1217 503 1217 503 1217 503 1218 502 1218 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 1218 502 344 502 1218 502 344 502 344 502 344 502 1218 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 345 501 1218 502 1218 502 1218 502 344 502 1219 501 345 501 1219 501 1219 501 34806 3565 1650 503 1217 502 343 503 343 503 343 503 1217 503 344 502 344 502 344 502 344 502 1218 502 344 502 1218 502 1218 502 344 502 1218 502 1218 502 1218 502 1218 502 1218 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 1218 502 344 502 1219 501 344 502 1218 502 344 502 1219 501 1218 501 345 501 1218 501 1219 501 1218 502 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 1219 501 1219 501 345 501 345 501 345 501 345 501 34805 3565 1651 503 1217 502 343 503 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 1218 502 344 502 1218 502 1218 502 344 502 1218 502 1218 502 1218 502 1218 502 1218 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 1218 502 344 502 344 502 1218 502 1219 501 1218 502 345 501 344 502 345 501 1219 501 1219 501 1219 501 345 501 1219 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 1219 501 345 501 1219 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 346 500 346 500 345 501 345 501 346 500 346 500 346 500 346 500 346 500 346 500 1220 500 1221 499 1221 498 346 500 346 500 370 476 346 500 347 499 347 499 370 476 370 476 370 476 1244 476 1244 476 1244 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 371 475 370 476 370 476 370 476 371 475 370 476 370 476 370 476 370 476 1244 476 371 475 1245 475 370 476 371 475 371 475 1245 475 1245 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 476 371 475 1245 475 1245 475 371 475 371 475 1246 474 1245 475 +# +name: Heat_lo +type: raw +frequency: 38000 +duty_cycle: 0.330000 +data: 535 313 533 311 535 311 535 312 534 312 534 313 533 24805 3711 1506 592 1129 592 305 543 305 540 305 569 1126 592 304 514 304 542 304 541 304 485 1213 507 340 506 1214 506 1215 505 342 504 1217 503 1218 502 1218 502 1218 502 1218 502 344 502 344 502 1218 503 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 1218 502 344 502 1218 502 344 502 344 502 344 502 1218 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 503 344 502 1219 501 1219 501 1219 501 345 501 1219 501 345 501 1219 502 1219 502 34818 3566 1651 503 1217 503 343 503 344 502 344 502 1218 502 344 502 344 502 344 502 344 503 1218 502 344 502 1218 503 1218 502 344 502 1218 502 1218 503 1218 503 1218 502 1218 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 1218 502 344 502 345 501 344 502 344 502 1219 501 345 501 345 502 1219 501 345 501 1219 502 1219 502 1219 502 344 502 1219 501 1219 502 1219 501 345 501 345 501 345 501 345 501 345 501 345 501 1219 501 345 501 345 501 345 501 1219 501 345 501 345 501 345 501 34812 3566 1651 503 1217 503 344 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 1218 503 344 502 1218 502 1218 502 344 502 1218 502 1218 502 1218 502 1219 501 1218 502 344 502 344 502 1218 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 344 502 345 501 344 502 345 501 345 501 1219 502 345 501 345 501 1219 502 345 501 345 501 1219 501 345 501 345 501 1219 501 1219 501 1219 501 345 501 1219 501 345 501 345 501 345 501 345 501 345 501 345 502 345 501 345 501 345 501 346 500 345 501 345 501 345 501 345 501 345 501 1220 500 346 500 1220 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 347 499 346 500 347 499 347 499 370 476 1244 476 1221 499 1244 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 370 476 1245 475 1245 476 1245 475 371 475 370 476 370 476 371 475 371 475 370 476 370 476 371 475 371 476 370 476 370 476 371 475 371 475 371 475 371 475 371 475 1245 475 371 475 1245 475 371 475 371 475 371 475 1245 475 1245 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 476 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 371 475 1245 475 1245 475 1245 475 371 475 1245 475 1246 474 +# +name: Heat_hi +type: raw +frequency: 38000 +duty_cycle: 0.330000 +data: 535 314 532 314 533 313 533 312 534 313 533 312 508 24840 3569 1647 508 1213 536 342 505 342 504 341 505 1214 506 340 506 340 506 340 505 340 506 1214 506 341 504 1216 504 1217 503 343 503 1218 502 1219 501 1219 502 1219 502 1219 502 345 502 344 502 1219 502 345 501 345 502 345 502 345 501 345 501 345 501 345 501 345 501 345 502 345 501 1219 502 345 501 1219 501 345 502 345 501 345 501 1219 501 1219 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 1220 500 1219 501 1220 500 345 501 1220 500 345 501 1220 501 1220 500 34815 3564 1653 502 1218 502 344 502 345 501 344 502 1219 501 345 501 345 501 345 501 345 501 1219 502 345 501 1219 502 1220 501 345 502 1219 501 1219 502 1219 501 1219 502 1219 502 345 501 345 501 1220 501 345 502 345 501 345 501 345 501 345 501 345 501 345 502 345 501 345 502 345 501 345 501 1220 501 345 501 345 501 345 501 345 501 1220 500 345 501 346 501 1220 500 1220 501 345 501 345 501 346 500 1220 500 1220 500 1220 500 1220 500 346 500 346 500 346 500 345 501 346 500 345 501 1220 500 346 500 1220 500 1220 500 1220 500 346 500 346 500 346 500 34816 3565 1653 502 1219 501 344 502 345 501 345 501 1219 502 345 501 345 502 345 501 345 501 1219 501 345 501 1219 502 1219 501 345 501 1219 502 1219 501 1219 501 1219 501 1219 501 345 501 345 501 1219 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 345 501 1220 501 346 501 345 501 1220 501 346 500 346 500 1220 500 346 500 345 501 346 500 1220 500 1220 500 1220 501 1220 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 346 500 1220 500 346 500 1220 500 347 499 346 500 346 500 346 500 347 499 347 499 346 500 346 500 347 499 347 499 347 499 347 499 347 499 347 499 347 499 347 499 347 499 1222 498 1222 499 1222 498 347 499 348 498 348 498 347 499 371 475 348 498 348 498 348 498 371 475 1222 498 1246 474 1246 474 372 475 371 475 372 474 372 474 348 498 371 475 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 1246 474 372 474 1246 474 372 474 372 474 372 474 1246 474 1246 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 372 474 1246 474 372 474 1247 473 372 474 1246 474 1246 474 1246 474 From 9fd9dd85e3a157bed74f4ce4b6120433b2983be8 Mon Sep 17 00:00:00 2001 From: Skorpionm <85568270+Skorpionm@users.noreply.github.com> Date: Wed, 2 Aug 2023 08:45:39 +0400 Subject: [PATCH 22/44] =?UTF-8?q?SubGhz:=20change=20CC1101=5Fext=20TIM17?= =?UTF-8?q?=20resolution=20to=202=C2=B5s=20(#2909)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * SubGhz: change the operation of the TIM17 timer in CC1101_ext to 2µs * SubGhz: remove special characters Co-authored-by: あく --- .../drivers/subghz/cc1101_ext/cc1101_ext.c | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c index 594a74a015..e9560ce5f3 100644 --- a/applications/drivers/subghz/cc1101_ext/cc1101_ext.c +++ b/applications/drivers/subghz/cc1101_ext/cc1101_ext.c @@ -37,7 +37,7 @@ #define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL (256) #define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_HALF \ (SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_BUFFER_FULL / 2) -#define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_GUARD_TIME 999 +#define SUBGHZ_DEVICE_CC1101_EXT_ASYNC_TX_GUARD_TIME 999 << 1 /** SubGhz state */ typedef enum { @@ -483,7 +483,7 @@ static void subghz_device_cc1101_ext_capture_ISR() { subghz_device_cc1101_ext->async_rx.capture_callback( true, - LL_TIM_GetCounter(TIM17), + LL_TIM_GetCounter(TIM17) << 1, (void*)subghz_device_cc1101_ext->async_rx.capture_callback_context); } } else { @@ -493,11 +493,11 @@ static void subghz_device_cc1101_ext_capture_ISR() { subghz_device_cc1101_ext->async_rx.capture_callback( false, - LL_TIM_GetCounter(TIM17), + LL_TIM_GetCounter(TIM17) << 1, (void*)subghz_device_cc1101_ext->async_rx.capture_callback_context); } } - LL_TIM_SetCounter(TIM17, 6); + LL_TIM_SetCounter(TIM17, 4); //8>>1 } void subghz_device_cc1101_ext_start_async_rx( @@ -512,7 +512,8 @@ void subghz_device_cc1101_ext_start_async_rx( furi_hal_bus_enable(FuriHalBusTIM17); // Configure TIM - LL_TIM_SetPrescaler(TIM17, 64 - 1); + //Set the timer resolution to 2 us + LL_TIM_SetPrescaler(TIM17, (64 << 1) - 1); LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP); LL_TIM_SetAutoReload(TIM17, 0xFFFF); LL_TIM_SetClockDivision(TIM17, LL_TIM_CLOCKDIVISION_DIV1); @@ -606,7 +607,7 @@ static void subghz_device_cc1101_ext_async_tx_refill(uint32_t* buffer, size_t sa uint32_t duration = level_duration_get_duration(ld); furi_assert(duration > 0); - *buffer = duration - 1; + *buffer = duration >> 1; buffer++; samples--; } @@ -692,7 +693,8 @@ bool subghz_device_cc1101_ext_start_async_tx(SubGhzDeviceCC1101ExtCallback callb furi_hal_bus_enable(FuriHalBusTIM17); // Configure TIM - LL_TIM_SetPrescaler(TIM17, 64 - 1); + // Set the timer resolution to 2 us + LL_TIM_SetPrescaler(TIM17, (64 << 1) - 1); LL_TIM_SetCounterMode(TIM17, LL_TIM_COUNTERMODE_UP); LL_TIM_SetAutoReload(TIM17, 0xFFFF); LL_TIM_SetClockDivision(TIM17, LL_TIM_CLOCKDIVISION_DIV1); From 7a45db38812f50649f6501fa43acfc16d16dc2b5 Mon Sep 17 00:00:00 2001 From: Andrey Zakharov Date: Wed, 2 Aug 2023 08:19:00 +0300 Subject: [PATCH 23/44] Fix about screen (#2907) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix about screen * About: use COUNT_OF Co-authored-by: Andrey Zakharov Co-authored-by: あく --- applications/settings/about/about.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/applications/settings/about/about.c b/applications/settings/about/about.c index 55bd43e5c5..dcd7656fc4 100644 --- a/applications/settings/about/about.c +++ b/applications/settings/about/about.c @@ -87,6 +87,7 @@ static DialogMessageButton icon2_screen(DialogsApp* dialogs, DialogMessage* mess message, furi_hal_version_get_mic_id(), 63, 27, AlignLeft, AlignCenter); result = dialog_message_show(dialogs, message); dialog_message_set_icon(message, NULL, 0, 0); + dialog_message_set_text(message, NULL, 0, 0, AlignLeft, AlignTop); return result; } @@ -172,8 +173,6 @@ const AboutDialogScreen about_screens[] = { hw_version_screen, fw_version_screen}; -const size_t about_screens_count = sizeof(about_screens) / sizeof(AboutDialogScreen); - int32_t about_settings_app(void* p) { UNUSED(p); DialogsApp* dialogs = furi_record_open(RECORD_DIALOGS); @@ -194,7 +193,7 @@ int32_t about_settings_app(void* p) { view_dispatcher_switch_to_view(view_dispatcher, empty_screen_index); while(1) { - if(screen_index >= about_screens_count - 1) { + if(screen_index >= COUNT_OF(about_screens) - 1) { dialog_message_set_buttons(message, "Back", NULL, NULL); } else { dialog_message_set_buttons(message, "Back", NULL, "Next"); @@ -209,7 +208,7 @@ int32_t about_settings_app(void* p) { screen_index--; } } else if(screen_result == DialogMessageButtonRight) { - if(screen_index < about_screens_count) { + if(screen_index < COUNT_OF(about_screens) - 1) { screen_index++; } } else if(screen_result == DialogMessageButtonBack) { From 3e8e99990909c241e164f309a583d76ca3b7305e Mon Sep 17 00:00:00 2001 From: Astra <93453568+Astrrra@users.noreply.github.com> Date: Wed, 2 Aug 2023 23:58:59 +0900 Subject: [PATCH 24/44] [FL-3470] Rename Applications to Apps (#2939) * Applications are now apps * Desktop: Apps in settings Co-authored-by: Aleksandr Kutuzov --- applications/services/loader/loader.h | 2 +- applications/services/loader/loader_cli.c | 2 +- .../desktop_settings/scenes/desktop_settings_scene_favorite.c | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/applications/services/loader/loader.h b/applications/services/loader/loader.h index 9fc4059f2d..3da676e651 100644 --- a/applications/services/loader/loader.h +++ b/applications/services/loader/loader.h @@ -6,7 +6,7 @@ extern "C" { #endif #define RECORD_LOADER "loader" -#define LOADER_APPLICATIONS_NAME "Applications" +#define LOADER_APPLICATIONS_NAME "Apps" typedef struct Loader Loader; diff --git a/applications/services/loader/loader_cli.c b/applications/services/loader/loader_cli.c index af3ebf9e00..cbec4adca8 100644 --- a/applications/services/loader/loader_cli.c +++ b/applications/services/loader/loader_cli.c @@ -14,7 +14,7 @@ static void loader_cli_print_usage() { } static void loader_cli_list() { - printf("Applications:\r\n"); + printf("Apps:\r\n"); for(size_t i = 0; i < FLIPPER_APPS_COUNT; i++) { printf("\t%s\r\n", FLIPPER_APPS[i].name); } diff --git a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c index 26e7bc5875..e0b4c118e1 100644 --- a/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c +++ b/applications/settings/desktop_settings/scenes/desktop_settings_scene_favorite.c @@ -7,10 +7,10 @@ #define APPS_COUNT (FLIPPER_APPS_COUNT + FLIPPER_EXTERNAL_APPS_COUNT) -#define EXTERNAL_BROWSER_NAME ("Applications") +#define EXTERNAL_BROWSER_NAME ("Apps") #define EXTERNAL_BROWSER_INDEX (APPS_COUNT + 1) -#define EXTERNAL_APPLICATION_NAME ("[External Application]") +#define EXTERNAL_APPLICATION_NAME ("[Select App]") #define EXTERNAL_APPLICATION_INDEX (APPS_COUNT + 2) #define PRESELECTED_SPECIAL 0xffffffff From a7aef0bfc27541639aa7be0cfc06a2db0ecc8c9a Mon Sep 17 00:00:00 2001 From: AloneLiberty <111039319+AloneLiberty@users.noreply.github.com> Date: Wed, 2 Aug 2023 15:06:38 +0000 Subject: [PATCH 25/44] NFC: Fix MFC key invalidation (#2912) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * NFC: Fix key invalidation (again~) * NFC: shouldn't be there This code get called each time we check for B key Co-authored-by: あく --- lib/nfc/nfc_worker.c | 69 +++++++++++++++++++------------------------- 1 file changed, 30 insertions(+), 39 deletions(-) diff --git a/lib/nfc/nfc_worker.c b/lib/nfc/nfc_worker.c index 145007bd3b..b2c845f07d 100644 --- a/lib/nfc/nfc_worker.c +++ b/lib/nfc/nfc_worker.c @@ -810,16 +810,10 @@ static void nfc_worker_mf_classic_key_attack( uint8_t block_num = mf_classic_get_sector_trailer_block_num_by_sector(i); if(mf_classic_is_sector_read(data, i)) continue; if(!mf_classic_is_key_found(data, i, MfClassicKeyA)) { - FURI_LOG_D( - TAG, - "Trying A key for sector %d, key: %04lx%08lx", - i, - (uint32_t)(key >> 32), - (uint32_t)key); + FURI_LOG_D(TAG, "Trying A key for sector %d, key: %012llX", i, key); if(mf_classic_authenticate(tx_rx, block_num, key, MfClassicKeyA)) { mf_classic_set_key_found(data, i, MfClassicKeyA, key); - FURI_LOG_D( - TAG, "Key A found: %04lx%08lx", (uint32_t)(key >> 32), (uint32_t)key); + FURI_LOG_D(TAG, "Key A found: %012llX", key); nfc_worker->callback(NfcWorkerEventFoundKeyA, nfc_worker->context); uint64_t found_key; @@ -832,18 +826,13 @@ static void nfc_worker_mf_classic_key_attack( } } } + furi_hal_nfc_sleep(); } if(!mf_classic_is_key_found(data, i, MfClassicKeyB)) { - FURI_LOG_D( - TAG, - "Trying B key for sector %d, key: %04lx%08lx", - i, - (uint32_t)(key >> 32), - (uint32_t)key); + FURI_LOG_D(TAG, "Trying B key for sector %d, key: %012llX", i, key); if(mf_classic_authenticate(tx_rx, block_num, key, MfClassicKeyB)) { mf_classic_set_key_found(data, i, MfClassicKeyB, key); - FURI_LOG_D( - TAG, "Key B found: %04lx%08lx", (uint32_t)(key >> 32), (uint32_t)key); + FURI_LOG_D(TAG, "Key B found: %012llX", key); nfc_worker->callback(NfcWorkerEventFoundKeyB, nfc_worker->context); } } @@ -891,8 +880,9 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) { nfc_worker->callback(NfcWorkerEventNewSector, nfc_worker->context); uint8_t block_num = mf_classic_get_sector_trailer_block_num_by_sector(i); if(mf_classic_is_sector_read(data, i)) continue; - bool is_key_a_found = mf_classic_is_key_found(data, i, MfClassicKeyA); - bool is_key_b_found = mf_classic_is_key_found(data, i, MfClassicKeyB); + if(mf_classic_is_key_found(data, i, MfClassicKeyA) && + mf_classic_is_key_found(data, i, MfClassicKeyB)) + continue; uint16_t key_index = 0; while(mf_classic_dict_get_next_key(dict, &key)) { FURI_LOG_T(TAG, "Key %d", key_index); @@ -910,19 +900,12 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) { nfc_worker_mf_classic_key_attack(nfc_worker, prev_key, &tx_rx, i); deactivated = true; } - FURI_LOG_D( - TAG, - "Try to auth to sector %d with key %04lx%08lx", - i, - (uint32_t)(key >> 32), - (uint32_t)key); - if(!is_key_a_found) { - is_key_a_found = mf_classic_is_key_found(data, i, MfClassicKeyA); + FURI_LOG_D(TAG, "Try to auth to sector %d with key %012llX", i, key); + if(!mf_classic_is_key_found(data, i, MfClassicKeyA)) { if(mf_classic_authenticate_skip_activate( &tx_rx, block_num, key, MfClassicKeyA, !deactivated, cuid)) { mf_classic_set_key_found(data, i, MfClassicKeyA, key); - FURI_LOG_D( - TAG, "Key A found: %04lx%08lx", (uint32_t)(key >> 32), (uint32_t)key); + FURI_LOG_D(TAG, "Key A found: %012llX", key); nfc_worker->callback(NfcWorkerEventFoundKeyA, nfc_worker->context); uint64_t found_key; @@ -952,17 +935,19 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) { if(mf_classic_is_key_found(data, i, MfClassicKeyA) && memcmp(sec_trailer->key_a, current_key, 6) == 0) { - mf_classic_set_key_not_found(data, i, MfClassicKeyA); - is_key_a_found = false; - FURI_LOG_D(TAG, "Key %dA not found in attack", i); + if(!mf_classic_authenticate_skip_activate( + &tx_rx, block_num, key, MfClassicKeyA, !deactivated, cuid)) { + mf_classic_set_key_not_found(data, i, MfClassicKeyA); + FURI_LOG_D(TAG, "Key %dA not found in attack", i); + } } + furi_hal_nfc_sleep(); + deactivated = true; } - if(!is_key_b_found) { - is_key_b_found = mf_classic_is_key_found(data, i, MfClassicKeyB); + if(!mf_classic_is_key_found(data, i, MfClassicKeyB)) { if(mf_classic_authenticate_skip_activate( &tx_rx, block_num, key, MfClassicKeyB, !deactivated, cuid)) { - FURI_LOG_D( - TAG, "Key B found: %04lx%08lx", (uint32_t)(key >> 32), (uint32_t)key); + FURI_LOG_D(TAG, "Key B found: %012llX", key); mf_classic_set_key_found(data, i, MfClassicKeyB, key); nfc_worker->callback(NfcWorkerEventFoundKeyB, nfc_worker->context); nfc_worker_mf_classic_key_attack(nfc_worker, key, &tx_rx, i + 1); @@ -978,12 +963,18 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) { if(mf_classic_is_key_found(data, i, MfClassicKeyB) && memcmp(sec_trailer->key_b, current_key, 6) == 0) { - mf_classic_set_key_not_found(data, i, MfClassicKeyB); - is_key_b_found = false; - FURI_LOG_D(TAG, "Key %dB not found in attack", i); + if(!mf_classic_authenticate_skip_activate( + &tx_rx, block_num, key, MfClassicKeyB, !deactivated, cuid)) { + mf_classic_set_key_not_found(data, i, MfClassicKeyB); + FURI_LOG_D(TAG, "Key %dB not found in attack", i); + } + furi_hal_nfc_sleep(); + deactivated = true; } } - if(is_key_a_found && is_key_b_found) break; + if(mf_classic_is_key_found(data, i, MfClassicKeyA) && + mf_classic_is_key_found(data, i, MfClassicKeyB)) + break; if(nfc_worker->state != NfcWorkerStateMfClassicDictAttack) break; } else { if(!card_removed_notified) { From cf6706c42eebff3631d702aa51119af6925a5b24 Mon Sep 17 00:00:00 2001 From: erikj95 Date: Wed, 2 Aug 2023 17:24:02 +0200 Subject: [PATCH 26/44] NFC CLI: Fix multiple apdu commands from not working when one of them gives an empty response (#2922) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * NFC CLI: Fix multiple apdu commands from not working when one of them gives an empty response * Make PVS happy Co-authored-by: hedger Co-authored-by: あく --- applications/main/nfc/nfc_cli.c | 2 +- lib/nfc/nfc_worker.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/applications/main/nfc/nfc_cli.c b/applications/main/nfc/nfc_cli.c index 0b7e754754..e961743812 100644 --- a/applications/main/nfc/nfc_cli.c +++ b/applications/main/nfc/nfc_cli.c @@ -146,7 +146,7 @@ static void nfc_cli_apdu(Cli* cli, FuriString* args) { resp_size = (tx_rx.rx_bits / 8) * 2; if(!resp_size) { printf("No response\r\n"); - break; + continue; } resp_buffer = malloc(resp_size); uint8_to_hex_chars(tx_rx.rx_data, resp_buffer, resp_size); diff --git a/lib/nfc/nfc_worker.c b/lib/nfc/nfc_worker.c index b2c845f07d..36776d8047 100644 --- a/lib/nfc/nfc_worker.c +++ b/lib/nfc/nfc_worker.c @@ -946,13 +946,13 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) { } if(!mf_classic_is_key_found(data, i, MfClassicKeyB)) { if(mf_classic_authenticate_skip_activate( - &tx_rx, block_num, key, MfClassicKeyB, !deactivated, cuid)) { + &tx_rx, block_num, key, MfClassicKeyB, !deactivated, cuid)) { //-V547 FURI_LOG_D(TAG, "Key B found: %012llX", key); mf_classic_set_key_found(data, i, MfClassicKeyB, key); nfc_worker->callback(NfcWorkerEventFoundKeyB, nfc_worker->context); nfc_worker_mf_classic_key_attack(nfc_worker, key, &tx_rx, i + 1); } - deactivated = true; + deactivated = true; //-V1048 } else { // If the key B is marked as found and matches the searching key, invalidate it MfClassicSectorTrailer* sec_trailer = @@ -964,12 +964,12 @@ void nfc_worker_mf_classic_dict_attack(NfcWorker* nfc_worker) { if(mf_classic_is_key_found(data, i, MfClassicKeyB) && memcmp(sec_trailer->key_b, current_key, 6) == 0) { if(!mf_classic_authenticate_skip_activate( - &tx_rx, block_num, key, MfClassicKeyB, !deactivated, cuid)) { + &tx_rx, block_num, key, MfClassicKeyB, !deactivated, cuid)) { //-V547 mf_classic_set_key_not_found(data, i, MfClassicKeyB); FURI_LOG_D(TAG, "Key %dB not found in attack", i); } furi_hal_nfc_sleep(); - deactivated = true; + deactivated = true; //-V1048 } } if(mf_classic_is_key_found(data, i, MfClassicKeyA) && From c7648eb932bb8accedfc3a10ca54c953c7476996 Mon Sep 17 00:00:00 2001 From: Lesha Lomalkin Date: Wed, 2 Aug 2023 18:38:51 +0300 Subject: [PATCH 27/44] fbtenv: add additional environ variable to control execution flow (#2938) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * fbtenv: add flags FBT_PRESERVE_TAR, FBT_SKIP_CHECK_SOURCED for usage with external tools * fbtenv: beautify, add info to fbtenv_print_config section if FBT_VERBOSE * fbtenv: fixes Co-authored-by: あく --- scripts/toolchain/fbtenv.sh | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/scripts/toolchain/fbtenv.sh b/scripts/toolchain/fbtenv.sh index a86b0ecedb..c5040ed81e 100755 --- a/scripts/toolchain/fbtenv.sh +++ b/scripts/toolchain/fbtenv.sh @@ -82,6 +82,9 @@ fbtenv_restore_env() fbtenv_check_sourced() { + if [ -n "${FBT_SKIP_CHECK_SOURCED:-""}" ]; then + return 0; + fi case "${ZSH_EVAL_CONTEXT:-""}" in *:file:*) setopt +o nomatch; # disabling 'no match found' warning in zsh return 0;; @@ -200,7 +203,7 @@ fbtenv_download_toolchain_tar() return 0; } -fbtenv_remove_old_tooclhain() +fbtenv_remove_old_toolchain() { printf "Removing old toolchain.."; rm -rf "${TOOLCHAIN_ARCH_DIR:?}"; @@ -231,12 +234,14 @@ fbtenv_unpack_toolchain() fbtenv_cleanup() { - printf "Cleaning up.."; if [ -n "${FBT_TOOLCHAIN_PATH:-""}" ]; then - rm -rf "${FBT_TOOLCHAIN_PATH:?}/toolchain/"*.tar.gz; + printf "Cleaning up.."; rm -rf "${FBT_TOOLCHAIN_PATH:?}/toolchain/"*.part; + if [ -z "${FBT_PRESERVE_TAR:-""}" ]; then + rm -rf "${FBT_TOOLCHAIN_PATH:?}/toolchain/"*.tar.gz; + fi + echo "done"; fi - echo "done"; trap - 2; return 0; } @@ -289,16 +294,22 @@ fbtenv_download_toolchain() fbtenv_curl_wget_check || return 1; fbtenv_download_toolchain_tar || return 1; fi - fbtenv_remove_old_tooclhain; + fbtenv_remove_old_toolchain; fbtenv_unpack_toolchain || return 1; fbtenv_cleanup; return 0; } -fbtenv_print_version() +fbtenv_print_config() { - if [ -n "$FBT_VERBOSE" ]; then + if [ -n "${FBT_VERBOSE:-""}" ]; then echo "FBT: using toolchain version $(cat "$TOOLCHAIN_ARCH_DIR/VERSION")"; + if [ -n "${FBT_SKIP_CHECK_SOURCED:-""}" ]; then + echo "FBT: fbtenv will not check if it is sourced or not"; + fi + if [ -n "${FBT_PRESERVE_TAR:-""}" ]; then + echo "FBT: toolchain archives will be saved"; + fi fi } @@ -316,7 +327,7 @@ fbtenv_main() fbtenv_check_env_vars || return 1; fbtenv_check_download_toolchain || return 1; fbtenv_set_shell_prompt; - fbtenv_print_version; + fbtenv_print_config; PATH="$TOOLCHAIN_ARCH_DIR/python/bin:$PATH"; PATH="$TOOLCHAIN_ARCH_DIR/bin:$PATH"; PATH="$TOOLCHAIN_ARCH_DIR/protobuf/bin:$PATH"; From 66deaad4f48b8a45d702cff34df59089e4036d6e Mon Sep 17 00:00:00 2001 From: leptoptilos Date: Sat, 5 Aug 2023 18:44:47 +0900 Subject: [PATCH 28/44] ac.ir: Modified LG General signal. 'Off' now becomes 'raw', Cool_lo set to 16 --- assets/resources/infrared/assets/ac.ir | 36 +++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/assets/resources/infrared/assets/ac.ir b/assets/resources/infrared/assets/ac.ir index 1fe72fde7b..1d7a12370e 100644 --- a/assets/resources/infrared/assets/ac.ir +++ b/assets/resources/infrared/assets/ac.ir @@ -551,40 +551,40 @@ data: 9076 4445 577 503 602 1587 603 477 601 1589 600 1590 599 481 573 507 572 5 # # Model: LG Generic name: Off -type: parsed -protocol: NECext -address: 81 66 00 00 -command: 81 7E 00 00 -# +type: raw +frequency: 38000 +duty_cycle: 0.330000 +data: 8518 4239 547 1511 572 495 547 495 571 470 572 1512 571 470 570 471 569 473 569 1515 568 1515 568 474 568 473 568 475 567 473 568 473 568 474 567 475 567 473 567 474 568 473 568 474 567 1516 567 474 567 1516 567 475 567 474 567 474 567 1517 567 +# name: Cool_hi type: raw frequency: 38000 duty_cycle: 0.330000 -data: 8725 4071 527 1527 501 521 501 517 500 520 500 1545 499 523 498 521 521 525 495 529 470 550 470 549 494 527 470 552 471 549 470 552 471 547 495 529 470 548 471 1572 470 1574 470 548 494 1551 470 547 470 552 470 551 470 1571 496 1547 469 1573 471 -# -name: Heat_hi +data: 8508 4216 570 1512 570 498 599 442 598 442 598 1485 597 445 595 446 594 448 566 476 566 475 566 476 566 475 566 475 566 476 565 474 566 475 566 476 566 474 566 475 566 1517 565 475 566 1518 566 475 567 1516 566 475 566 1516 567 1516 566 476 566 +# +name: Cool_lo type: raw frequency: 38000 duty_cycle: 0.330000 -data: 8755 4064 528 1524 502 523 501 517 501 520 500 1543 500 519 498 524 497 523 497 527 496 521 496 525 521 500 496 527 496 1545 496 525 496 526 496 1545 495 1550 496 1541 496 1549 496 523 495 1546 496 526 496 523 521 499 496 1550 495 1544 495 1548 495 -# -name: Heat_lo +data: 8512 4239 546 1536 546 496 545 495 545 496 545 1539 569 471 568 473 542 499 542 500 542 499 542 501 541 499 542 499 542 500 542 499 542 500 541 1541 541 500 542 499 542 499 542 500 541 1542 542 500 541 1541 541 1541 542 1543 541 500 541 1542 540 +# +name: Dh type: raw frequency: 38000 duty_cycle: 0.330000 -data: 8783 4042 556 1497 502 521 501 518 501 520 500 1546 499 517 499 523 497 525 496 527 522 496 497 523 497 524 496 528 522 1516 521 500 496 526 497 1542 520 501 496 527 496 522 497 524 496 1548 496 521 521 500 521 500 520 503 497 521 521 500 497 -# -name: Cool_lo +data: 8518 4238 546 1535 547 494 546 495 546 495 546 1537 545 497 544 497 543 498 543 499 542 500 542 499 542 500 542 500 541 499 542 500 541 1542 541 501 541 499 541 500 541 1542 541 499 541 499 541 500 541 500 541 499 541 500 541 1542 541 499 541 +# +name: Heat_lo type: raw frequency: 38000 duty_cycle: 0.330000 -data: 8721 4070 527 1526 501 524 501 517 501 518 500 1544 500 519 498 524 497 526 496 550 471 549 470 549 470 551 494 531 470 548 470 549 470 552 470 1572 494 526 494 528 470 551 470 549 470 1573 470 551 470 548 495 1548 470 1572 469 551 494 527 495 -# -name: Dh +data: 8512 4215 571 1512 570 497 599 442 598 443 597 1486 580 461 568 473 567 474 567 475 567 474 566 475 566 474 567 474 567 1516 566 475 567 474 566 1517 566 474 567 475 567 474 566 475 566 1516 566 474 567 1517 566 475 567 474 566 475 566 1518 566 +# +name: Heat_hi type: raw frequency: 38000 duty_cycle: 0.330000 -data: 8780 4015 578 1498 553 471 526 494 525 494 524 1520 525 495 523 498 522 499 521 502 522 497 522 499 522 500 521 1519 522 500 521 499 521 1520 546 1496 521 503 523 494 522 500 521 499 522 1520 521 499 522 499 522 502 522 1518 521 501 521 1522 522 +data: 8514 4239 546 1536 546 495 546 494 546 495 546 1538 570 471 544 497 543 498 543 500 542 499 542 500 542 499 542 499 542 1541 541 501 541 499 541 1542 541 1543 540 1566 517 1567 517 524 517 1566 517 524 517 1567 516 1566 516 525 517 524 517 524 517 # # Model: Shivaki SSA18002 name: Off From fe630362a8ec4e31759f38a8cbd075c9697eea64 Mon Sep 17 00:00:00 2001 From: leptoptilos Date: Sat, 5 Aug 2023 18:52:58 +0900 Subject: [PATCH 29/44] ac.ir: Tosot deleted (duplicate) --- assets/resources/infrared/assets/ac.ir | 39 +------------------------- 1 file changed, 1 insertion(+), 38 deletions(-) diff --git a/assets/resources/infrared/assets/ac.ir b/assets/resources/infrared/assets/ac.ir index 1d7a12370e..55ab643425 100644 --- a/assets/resources/infrared/assets/ac.ir +++ b/assets/resources/infrared/assets/ac.ir @@ -78,6 +78,7 @@ duty_cycle: 0.330000 data: 8972 4491 592 1651 592 1655 598 532 599 535 597 542 600 541 601 544 598 1656 597 526 595 1652 591 1658 595 539 593 545 597 545 597 546 596 537 594 529 592 535 596 1653 600 534 597 541 601 539 592 552 600 533 598 525 596 530 591 538 593 539 592 1665 598 1662 591 1673 601 533 598 526 595 533 598 532 600 534 597 540 591 548 594 550 592 542 600 523 598 528 593 536 595 537 594 543 599 542 600 543 599 517 594 7937 593 531 601 526 595 535 597 537 594 542 600 541 601 543 599 1654 599 523 598 528 593 536 596 538 594 542 600 541 590 552 600 532 599 524 597 528 593 536 595 537 595 541 601 539 593 551 591 542 600 522 599 527 594 536 595 537 594 543 599 540 591 552 600 532 600 523 598 527 594 535 596 537 595 542 600 540 591 552 600 532 600 523 598 528 593 536 595 538 593 543 599 541 601 543 599 535 596 527 594 532 600 531 601 534 597 540 592 549 593 552 600 534 597 525 596 529 592 1655 598 534 597 1656 597 1661 592 1671 592 1644 599 7934 596 529 592 535 597 535 597 538 593 544 598 543 599 545 597 538 593 1650 593 535 596 534 597 536 595 540 591 547 595 547 595 536 595 526 595 529 592 536 595 535 596 539 593 546 596 547 595 538 593 528 593 531 601 529 592 541 601 536 596 545 597 548 594 540 592 532 600 526 595 535 596 1656 597 541 601 540 592 553 599 534 597 526 595 532 599 531 600 533 598 539 593 548 594 552 600 535 596 1647 596 531 590 538 593 1656 597 538 594 545 597 545 597 518 593 # # Model: Daichi DA25AVQS1-W +# Compatible Brands: Gree, Tosot name: Dh type: raw frequency: 38000 @@ -511,44 +512,6 @@ frequency: 38000 duty_cycle: 0.330000 data: 6059 7355 592 1633 592 1633 592 1633 592 1633 592 1633 592 1633 592 1633 618 1608 617 489 617 490 616 490 616 491 590 517 589 517 614 492 590 517 590 1636 589 1636 590 1636 590 1636 589 1636 590 1636 590 1636 590 1636 590 517 589 517 589 517 589 517 590 517 589 517 589 517 589 517 589 517 589 1636 614 492 590 1636 590 1636 590 1636 589 1636 590 1636 589 1637 589 517 589 1636 590 517 589 517 589 517 614 492 590 517 589 1636 590 517 589 1636 590 517 589 517 589 517 589 517 590 1636 590 517 589 1636 590 517 589 1636 589 1636 590 1636 590 1637 589 517 589 517 589 1637 588 1637 589 517 589 1637 589 1636 590 517 589 1636 590 1636 590 517 589 517 589 1637 589 517 589 517 589 1637 589 517 589 518 588 1637 589 518 588 1637 589 517 590 1637 588 518 588 518 588 1637 589 518 588 1637 589 518 588 1637 589 518 588 1637 589 1637 589 7357 589 # -# Model: Tosot T24H-ILF/I/T24H-ILU/O -# Compatible Brands: Gree -name: Off -type: raw -frequency: 38000 -duty_cycle: 0.330000 -data: 9072 4445 602 1586 603 477 601 478 600 479 599 480 598 481 598 482 597 482 572 1617 597 1593 572 1617 597 483 572 507 572 507 572 507 572 507 572 507 597 482 597 482 572 507 597 482 572 1618 571 507 572 507 572 507 572 507 572 507 572 507 572 1618 571 507 572 1618 572 507 572 507 572 1618 572 507 652 20153 572 507 597 482 572 507 572 507 597 482 597 482 572 507 596 483 572 507 572 507 572 507 572 507 572 507 572 1618 596 483 572 507 596 483 595 484 572 507 597 482 595 484 597 482 597 482 572 507 572 507 597 482 572 507 597 482 572 507 597 483 571 1618 597 482 675 40391 9179 4421 599 1590 599 481 597 482 597 482 597 481 598 482 597 482 597 482 597 1592 597 1592 598 1592 597 482 597 482 597 482 597 482 597 482 597 482 597 482 597 482 597 482 572 507 597 1593 597 482 572 507 572 507 572 507 572 507 572 508 571 1618 597 1593 596 1593 572 507 572 507 572 1618 597 482 678 20152 597 483 596 482 597 482 597 482 597 482 597 482 572 507 597 482 597 482 597 482 572 507 597 482 597 482 597 482 597 482 597 482 572 507 597 482 597 482 572 507 597 482 572 507 572 507 572 507 572 507 572 507 572 507 572 507 572 507 572 1618 596 482 572 507 572 -# -name: Cool_hi -type: raw -frequency: 38000 -duty_cycle: 0.330000 -data: 9049 4446 575 1613 577 503 601 478 601 1590 599 480 598 482 572 507 572 507 572 508 571 507 572 507 572 507 572 508 571 508 571 507 573 507 572 508 571 508 572 507 572 508 571 507 572 1618 572 508 572 507 572 508 571 508 571 508 571 508 571 1618 572 508 571 1618 572 508 571 508 571 1619 571 508 651 20157 572 507 572 507 572 507 572 507 572 507 572 507 573 507 572 507 572 507 572 507 572 507 572 507 572 507 572 1618 572 507 572 507 572 507 572 507 573 507 572 508 571 507 572 508 571 507 572 507 573 507 572 507 572 507 572 508 571 1619 571 507 572 1618 572 508 651 40424 9180 4422 599 1591 598 482 597 483 572 1618 572 507 598 482 597 482 572 507 572 507 598 482 572 507 598 482 572 507 598 482 597 482 572 507 572 507 572 507 573 507 572 507 573 507 572 1618 572 507 598 482 572 507 572 507 597 483 596 483 597 1593 572 1618 572 1618 572 508 572 507 572 1618 572 508 678 20157 572 507 597 482 597 482 597 481 598 482 572 507 572 507 572 507 572 507 597 482 572 507 597 482 572 507 573 507 572 507 572 507 572 507 572 507 572 507 572 507 572 508 572 507 572 507 572 507 572 507 572 507 572 508 571 508 571 1619 571 1618 572 508 571 507 572 -# -name: Cool_lo -type: raw -frequency: 38000 -duty_cycle: 0.330000 -data: 9075 4419 603 1586 603 476 602 478 600 1589 600 480 599 481 598 482 597 482 597 1593 597 1593 597 1593 597 482 597 482 572 507 572 507 596 483 573 507 572 507 573 507 598 482 572 507 573 1618 572 508 572 507 572 508 572 507 596 483 572 508 571 1618 596 484 572 1618 572 507 572 507 572 1618 572 508 651 20158 597 482 598 482 597 482 597 482 597 482 572 507 572 507 572 507 597 482 597 483 597 482 572 507 573 507 597 1594 572 507 597 482 572 507 597 482 598 482 572 508 571 508 571 508 572 507 572 507 597 482 597 483 572 508 571 508 571 508 596 483 597 1593 596 1593 652 40424 9181 4422 599 1591 598 481 598 482 572 1618 598 482 597 481 598 482 598 481 598 1593 597 1593 597 1592 598 482 598 482 597 482 597 482 598 482 597 482 597 482 598 482 597 482 597 482 598 1593 597 482 597 482 597 482 597 483 597 482 572 508 597 1593 596 1594 597 1593 597 483 571 508 571 1618 572 508 678 20157 572 507 572 507 573 507 572 507 572 507 572 507 572 507 572 507 572 507 572 507 572 507 572 507 572 507 572 507 572 507 573 507 572 507 573 507 572 507 573 507 572 507 572 507 572 507 572 508 571 507 572 508 571 508 571 508 571 508 572 1618 572 508 571 1618 572 -# -name: Heat_lo -type: raw -frequency: 38000 -duty_cycle: 0.330000 -data: 9048 4447 576 503 576 503 601 1589 600 1590 599 481 573 507 572 507 572 507 572 1618 572 1618 572 1618 572 507 572 507 573 507 572 508 572 507 572 507 572 507 572 507 572 507 572 507 572 1618 572 507 573 507 572 508 571 507 572 507 572 508 571 1618 572 507 572 1618 572 508 571 507 572 1618 572 508 651 20157 572 507 572 507 572 507 572 507 572 508 572 507 572 507 572 507 572 508 571 508 572 508 571 508 571 508 571 1619 571 507 572 508 571 508 571 508 571 508 571 508 571 508 571 508 571 508 571 508 571 508 571 508 571 509 570 509 570 1620 570 1620 570 1620 570 1620 649 40424 9153 4450 573 506 573 507 572 1619 571 1618 572 508 571 508 571 508 572 508 571 1619 571 1619 571 1619 571 508 571 508 571 508 571 508 571 508 571 508 571 508 571 508 571 509 570 509 571 1619 571 509 571 509 570 509 571 509 570 509 570 509 570 1620 570 1621 569 1644 546 509 570 509 570 1620 570 510 676 20158 571 508 572 507 572 508 571 508 571 508 571 508 571 508 571 508 572 508 571 508 571 508 571 508 572 508 571 508 571 508 571 508 571 509 570 509 570 509 571 509 570 509 570 534 545 511 568 533 546 534 546 533 546 534 545 534 545 1645 545 534 545 1645 545 1644 546 -# -name: Heat_hi -type: raw -frequency: 38000 -duty_cycle: 0.330000 -data: 9072 4445 602 476 602 476 602 1588 600 1589 600 480 599 481 597 481 598 481 598 481 598 1592 598 1592 598 1592 598 481 598 481 598 481 598 481 598 481 598 481 598 481 598 482 597 482 597 1592 598 481 598 481 598 481 598 481 598 481 598 481 598 1592 598 481 598 1592 598 481 598 481 598 1592 598 481 678 20126 598 481 598 481 598 481 598 481 598 481 598 481 598 481 598 481 598 481 598 481 598 481 598 481 598 481 598 1592 597 481 598 481 598 481 599 481 598 481 598 481 598 481 598 481 598 481 598 481 598 481 598 481 598 482 597 481 598 481 598 1592 597 1592 597 481 677 40388 9180 4420 600 479 599 480 599 1591 599 1591 598 481 598 481 598 481 598 481 598 481 598 1591 598 1591 598 1591 599 480 599 481 598 481 598 481 598 481 598 481 598 481 598 481 598 481 598 1591 598 481 598 481 598 481 598 481 598 481 598 481 598 1591 598 1592 598 1591 598 481 598 481 598 1592 598 481 704 20126 598 480 599 480 599 480 599 481 598 480 599 480 599 480 599 481 598 480 599 480 599 480 599 481 598 481 598 480 599 481 598 480 599 481 598 480 599 480 599 481 598 481 598 481 598 480 599 481 598 481 598 481 598 481 598 481 598 481 598 481 598 1591 599 481 598 -# -name: Dh -type: raw -frequency: 38000 -duty_cycle: 0.330000 -data: 9076 4445 577 503 602 1587 603 477 601 1589 600 1590 599 481 573 507 572 507 572 1618 572 1618 572 1618 572 507 572 507 573 507 572 507 572 507 572 507 572 507 572 507 572 507 572 507 572 1618 572 507 573 507 572 507 572 507 573 507 572 507 572 1618 572 507 573 1618 572 507 572 507 572 1618 572 507 652 20157 597 482 573 507 597 483 572 507 572 507 573 507 572 507 572 507 596 483 597 482 572 507 572 507 572 507 597 1593 572 507 572 507 573 507 572 507 572 507 572 507 572 507 572 507 572 507 572 507 596 484 572 507 572 507 572 507 597 1593 596 483 572 1618 572 1618 652 40424 9181 4422 599 480 598 1591 599 481 598 1592 598 1592 598 481 598 481 598 481 598 1592 598 1592 598 1592 598 481 598 481 598 481 598 482 597 481 598 481 599 481 598 482 598 482 597 482 598 1592 598 482 597 482 597 482 597 482 597 482 598 482 597 1593 597 1593 597 1592 598 482 598 482 596 1593 597 482 703 20132 598 481 598 481 599 481 598 481 598 481 598 481 598 481 598 481 598 482 598 481 598 482 597 482 597 482 597 482 598 482 598 481 598 481 598 482 597 482 598 482 598 1592 598 482 597 482 597 482 598 482 597 482 597 482 572 507 572 507 598 482 597 1593 597 1593 572 -# # Model: LG Generic name: Off type: raw From eb54fef384b538d350f3141065c9159a4e83d3b6 Mon Sep 17 00:00:00 2001 From: leptoptilos Date: Sat, 5 Aug 2023 18:55:52 +0900 Subject: [PATCH 30/44] ac.ir: Ghost samples deleted --- assets/resources/infrared/assets/ac.ir | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/assets/resources/infrared/assets/ac.ir b/assets/resources/infrared/assets/ac.ir index 55ab643425..b1198bf438 100644 --- a/assets/resources/infrared/assets/ac.ir +++ b/assets/resources/infrared/assets/ac.ir @@ -101,7 +101,7 @@ name: Heat_hi type: raw frequency: 38000 duty_cycle: 0.330000 -data: 148 110377 9082 4422 707 499 706 500 704 1603 703 1606 701 505 700 507 699 506 700 507 699 506 700 1607 700 1608 700 1609 699 506 699 507 699 506 699 507 699 507 699 506 700 507 699 507 699 507 699 1608 699 1607 699 507 699 507 699 507 699 507 699 507 699 1609 699 507 699 1608 699 507 699 507 699 1609 699 507 699 19940 700 506 700 506 699 507 699 507 699 506 700 506 700 507 699 507 699 507 700 507 699 506 699 507 699 507 699 507 699 507 699 507 699 507 699 507 699 507 698 507 700 507 699 507 699 507 699 507 699 507 699 508 698 508 698 507 699 507 699 508 698 1610 699 508 698 +data: 9082 4422 707 499 706 500 704 1603 703 1606 701 505 700 507 699 506 700 507 699 506 700 1607 700 1608 700 1609 699 506 699 507 699 506 699 507 699 507 699 506 700 507 699 507 699 507 699 1608 699 1607 699 507 699 507 699 507 699 507 699 507 699 1609 699 507 699 1608 699 507 699 507 699 1609 699 507 699 19940 700 506 700 506 699 507 699 507 699 506 700 506 700 507 699 507 699 507 700 507 699 506 699 507 699 507 699 507 699 507 699 507 699 507 699 507 699 507 698 507 700 507 699 507 699 507 699 507 699 507 699 508 698 508 698 507 699 507 699 508 698 1610 699 508 698 # name: Heat_lo type: raw @@ -226,13 +226,13 @@ name: Cool_hi type: raw frequency: 38000 duty_cycle: 0.330000 -data: 315 101050 3094 3056 3093 4437 580 1648 572 534 576 1649 582 525 574 530 580 1646 574 1653 578 529 570 534 576 529 571 534 576 529 570 1655 576 1651 580 527 572 532 578 1647 573 1654 577 1651 580 526 573 531 579 526 573 531 579 526 573 531 579 526 573 531 579 526 573 531 579 525 574 531 579 525 574 531 579 1646 574 532 578 526 573 531 579 526 573 531 579 526 573 1652 579 527 572 1653 578 528 571 534 576 528 571 533 577 528 571 533 577 528 572 533 577 528 572 532 578 527 572 532 578 527 572 532 578 526 573 1652 579 527 572 532 578 527 572 532 578 527 572 532 578 526 573 531 579 526 573 531 579 526 573 531 579 525 574 530 580 525 574 530 580 525 574 530 580 524 575 529 581 524 575 529 571 534 576 528 571 533 577 528 571 533 577 528 571 533 577 527 572 532 578 527 572 532 578 526 573 531 579 526 573 531 579 525 574 531 579 525 574 530 580 525 574 1650 581 525 574 1651 580 1647 573 533 577 527 572 1653 578 528 572 1654 577 1650 581 1646 574 71637 254 +data: 3094 3056 3093 4437 580 1648 572 534 576 1649 582 525 574 530 580 1646 574 1653 578 529 570 534 576 529 571 534 576 529 570 1655 576 1651 580 527 572 532 578 1647 573 1654 577 1651 580 526 573 531 579 526 573 531 579 526 573 531 579 526 573 531 579 526 573 531 579 525 574 531 579 525 574 531 579 1646 574 532 578 526 573 531 579 526 573 531 579 526 573 1652 579 527 572 1653 578 528 571 534 576 528 571 533 577 528 571 533 577 528 572 533 577 528 572 532 578 527 572 532 578 527 572 532 578 526 573 1652 579 527 572 532 578 527 572 532 578 527 572 532 578 526 573 531 579 526 573 531 579 526 573 531 579 525 574 530 580 525 574 530 580 525 574 530 580 524 575 529 581 524 575 529 571 534 576 528 571 533 577 528 571 533 577 528 571 533 577 527 572 532 578 527 572 532 578 526 573 531 579 526 573 531 579 525 574 531 579 525 574 530 580 525 574 1650 581 525 574 1651 580 1647 573 533 577 527 572 1653 578 528 572 1654 577 1650 581 1646 574 71637 254 # name: Cool_lo type: raw frequency: 38000 duty_cycle: 0.330000 -data: 284 19161 3098 3053 3096 4435 572 1656 575 532 578 1648 572 534 576 530 570 1682 549 1652 579 527 572 534 576 1649 571 1656 575 1652 579 1649 571 1656 575 531 579 527 572 1653 578 1649 571 1656 575 531 579 527 572 532 578 527 572 533 577 527 572 533 577 527 573 532 578 527 572 532 578 527 573 532 578 527 572 1652 579 527 572 533 577 528 571 533 577 528 571 533 577 1648 572 533 577 1649 571 535 575 530 569 536 574 531 569 536 574 530 569 536 574 530 570 535 575 530 570 535 575 530 569 535 575 530 569 535 575 1649 571 535 575 531 568 536 574 531 568 536 574 531 568 536 574 531 569 536 574 530 569 536 574 530 569 535 575 530 569 535 575 530 569 535 575 530 570 535 575 529 570 534 576 529 570 534 576 529 570 534 576 528 571 534 576 528 571 534 576 528 571 534 576 528 571 534 576 528 571 533 577 528 571 533 577 528 572 533 577 528 571 533 577 528 572 1652 579 527 572 1653 578 529 570 534 576 529 570 535 575 529 570 1654 577 1677 554 1673 547 +data: 3098 3053 3096 4435 572 1656 575 532 578 1648 572 534 576 530 570 1682 549 1652 579 527 572 534 576 1649 571 1656 575 1652 579 1649 571 1656 575 531 579 527 572 1653 578 1649 571 1656 575 531 579 527 572 532 578 527 572 533 577 527 572 533 577 527 573 532 578 527 572 532 578 527 573 532 578 527 572 1652 579 527 572 533 577 528 571 533 577 528 571 533 577 1648 572 533 577 1649 571 535 575 530 569 536 574 531 569 536 574 530 569 536 574 530 570 535 575 530 570 535 575 530 569 535 575 530 569 535 575 1649 571 535 575 531 568 536 574 531 568 536 574 531 568 536 574 531 569 536 574 530 569 536 574 530 569 535 575 530 569 535 575 530 569 535 575 530 570 535 575 529 570 534 576 529 570 534 576 529 570 534 576 528 571 534 576 528 571 534 576 528 571 534 576 528 571 534 576 528 571 533 577 528 571 533 577 528 572 533 577 528 571 533 577 528 572 1652 579 527 572 1653 578 529 570 534 576 529 570 535 575 529 570 1654 577 1677 554 1673 547 # name: Off type: raw @@ -257,7 +257,7 @@ name: Cool_lo type: raw frequency: 38000 duty_cycle: 0.330000 -data: 301 132136 5036 2167 337 1766 361 689 358 692 366 684 363 1770 357 692 366 684 363 718 329 690 357 1776 361 687 360 1773 364 1767 360 689 358 1775 362 1769 357 1774 363 1768 359 1773 364 684 363 718 329 1773 364 684 363 718 329 691 356 694 364 716 331 719 328 1775 362 1769 358 1774 363 1768 359 1772 365 714 333 1770 357 1774 363 716 331 719 328 722 336 715 332 718 329 721 326 724 334 716 331 719 328 722 336 715 332 718 329 1773 364 1767 360 1772 354 1777 360 719 328 721 326 725 333 717 330 29455 5036 2139 354 1777 360 688 359 691 367 714 333 1770 356 692 366 684 363 687 360 690 357 1776 361 688 359 1773 364 1768 359 689 358 1775 362 1769 357 1774 363 1768 359 1773 364 684 363 687 360 1773 364 685 362 688 359 691 356 694 364 686 361 689 358 692 366 685 362 688 359 691 356 1777 360 1771 355 693 365 685 362 1771 355 693 365 1768 359 1773 364 1767 360 689 358 692 366 685 362 1771 355 1775 362 687 360 690 357 1775 362 687 360 690 357 693 365 716 331 689 358 1774 363 686 361 689 358 692 366 685 362 688 359 691 356 694 364 686 361 689 358 692 366 685 362 688 359 691 356 694 364 686 361 689 358 692 366 685 362 1771 355 693 365 1768 358 1773 364 684 363 687 360 690 357 693 365 1768 359 690 357 1776 361 688 359 691 356 694 364 686 361 689 358 692 366 685 362 1770 356 693 365 685 362 688 359 691 356 1777 360 1771 355 693 365 686 361 689 358 692 366 685 362 1770 356 +data: 5036 2167 337 1766 361 689 358 692 366 684 363 1770 357 692 366 684 363 718 329 690 357 1776 361 687 360 1773 364 1767 360 689 358 1775 362 1769 357 1774 363 1768 359 1773 364 684 363 718 329 1773 364 684 363 718 329 691 356 694 364 716 331 719 328 1775 362 1769 358 1774 363 1768 359 1772 365 714 333 1770 357 1774 363 716 331 719 328 722 336 715 332 718 329 721 326 724 334 716 331 719 328 722 336 715 332 718 329 1773 364 1767 360 1772 354 1777 360 719 328 721 326 725 333 717 330 29455 5036 2139 354 1777 360 688 359 691 367 714 333 1770 356 692 366 684 363 687 360 690 357 1776 361 688 359 1773 364 1768 359 689 358 1775 362 1769 357 1774 363 1768 359 1773 364 684 363 687 360 1773 364 685 362 688 359 691 356 694 364 686 361 689 358 692 366 685 362 688 359 691 356 1777 360 1771 355 693 365 685 362 1771 355 693 365 1768 359 1773 364 1767 360 689 358 692 366 685 362 1771 355 1775 362 687 360 690 357 1775 362 687 360 690 357 693 365 716 331 689 358 1774 363 686 361 689 358 692 366 685 362 688 359 691 356 694 364 686 361 689 358 692 366 685 362 688 359 691 356 694 364 686 361 689 358 692 366 685 362 1771 355 693 365 1768 358 1773 364 684 363 687 360 690 357 693 365 1768 359 690 357 1776 361 688 359 691 356 694 364 686 361 689 358 692 366 685 362 1770 356 693 365 685 362 688 359 691 356 1777 360 1771 355 693 365 686 361 689 358 692 366 685 362 1770 356 # name: Off type: raw From afa7bd7f79a56792e32ae173c702da7ce00d1019 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 5 Aug 2023 13:57:55 +0300 Subject: [PATCH 31/44] Update TOTP https://github.com/akopachov/flipper-zero_authenticator --- applications/external/totp/application.fam | 2 +- applications/external/totp/cli/cli.c | 10 +- applications/external/totp/cli/cli.h | 18 +- applications/external/totp/cli/cli_helpers.h | 14 +- .../external/totp/cli/commands/add/add.c | 9 +- .../totp/cli/commands/automation/automation.c | 89 ++++- .../totp/cli/commands/automation/automation.h | 3 +- .../external/totp/cli/commands/help/help.c | 2 + .../external/totp/cli/commands/pin/pin.c | 64 +++- .../external/totp/cli/commands/pin/pin.h | 3 +- .../external/totp/cli/commands/reset/reset.c | 7 +- .../external/totp/cli/commands/reset/reset.h | 5 +- .../totp/cli/commands/update/update.c | 8 +- .../totp/cli/common_command_arguments.h | 55 +++ applications/external/totp/features_config.h | 10 +- .../totp/images/totp_arrow_bottom_10x5.png | Bin 147 -> 0 bytes .../external/totp/services/config/config.c | 232 +++++++++--- .../external/totp/services/config/config.h | 14 + .../external/totp/services/config/constants.h | 7 +- .../config/migrations/common_migration.c | 38 ++ .../services/config/token_info_iterator.c | 13 +- .../services/config/token_info_iterator.h | 8 +- .../totp/services/crypto/common_types.h | 23 ++ .../external/totp/services/crypto/constants.h | 11 + .../totp/services/crypto/crypto_facade.c | 78 ++++ .../crypto/{crypto.h => crypto_facade.h} | 47 +-- .../services/crypto/{crypto.c => crypto_v1.c} | 61 ++-- .../external/totp/services/crypto/crypto_v1.h | 52 +++ .../external/totp/services/crypto/crypto_v2.c | 184 ++++++++++ .../external/totp/services/crypto/crypto_v2.h | 52 +++ applications/external/totp/totp_app.c | 216 ++++++----- .../totp/types/automation_kb_layout.h | 8 + .../external/totp/types/automation_method.h | 2 +- .../external/totp/types/crypto_settings.h | 41 +++ applications/external/totp/types/event_type.h | 2 +- .../external/totp/types/plugin_state.h | 56 +-- applications/external/totp/types/token_info.c | 9 +- applications/external/totp/types/token_info.h | 7 +- .../external/totp/ui/canvas_extensions.h | 9 + .../external/totp/ui/common_dialogs.h | 11 + .../external/totp/ui/scene_director.c | 5 + .../external/totp/ui/scene_director.h | 6 + .../add_new_token/totp_scene_add_new_token.c | 6 +- .../scenes/app_settings/totp_app_settings.c | 335 +++++++++--------- .../authenticate/totp_scene_authenticate.c | 16 +- .../totp_scene_generate_token.c | 128 +++---- applications/external/totp/ui/ui_controls.c | 24 ++ applications/external/totp/ui/ui_controls.h | 19 + applications/external/totp/version.h | 5 + .../totp/workers/bt_type_code/bt_type_code.c | 11 +- .../totp/workers/bt_type_code/bt_type_code.h | 5 +- .../generate_totp_code/generate_totp_code.c | 11 +- .../generate_totp_code/generate_totp_code.h | 4 +- .../external/totp/workers/type_code_common.c | 39 +- .../external/totp/workers/type_code_common.h | 5 +- .../workers/usb_type_code/usb_type_code.c | 8 +- .../workers/usb_type_code/usb_type_code.h | 5 +- 57 files changed, 1528 insertions(+), 584 deletions(-) delete mode 100644 applications/external/totp/images/totp_arrow_bottom_10x5.png create mode 100644 applications/external/totp/services/crypto/common_types.h create mode 100644 applications/external/totp/services/crypto/constants.h create mode 100644 applications/external/totp/services/crypto/crypto_facade.c rename applications/external/totp/services/crypto/{crypto.h => crypto_facade.h} (58%) rename applications/external/totp/services/crypto/{crypto.c => crypto_v1.c} (66%) create mode 100644 applications/external/totp/services/crypto/crypto_v1.h create mode 100644 applications/external/totp/services/crypto/crypto_v2.c create mode 100644 applications/external/totp/services/crypto/crypto_v2.h create mode 100644 applications/external/totp/types/automation_kb_layout.h create mode 100644 applications/external/totp/types/crypto_settings.h create mode 100644 applications/external/totp/version.h diff --git a/applications/external/totp/application.fam b/applications/external/totp/application.fam index 4d9fe46345..aba01fe739 100644 --- a/applications/external/totp/application.fam +++ b/applications/external/totp/application.fam @@ -15,7 +15,7 @@ App( ], stack_size=2 * 1024, order=20, - fap_version="2.3", + fap_version="3.20", fap_author="Alexander Kopachov (@akopachov)", fap_description="Software-based TOTP authenticator for Flipper Zero device", fap_weburl="https://github.com/akopachov/flipper-zero_authenticator", diff --git a/applications/external/totp/cli/cli.c b/applications/external/totp/cli/cli.c index c860b5a36c..4cb68ce832 100644 --- a/applications/external/totp/cli/cli.c +++ b/applications/external/totp/cli/cli.c @@ -16,6 +16,10 @@ #include "commands/automation/automation.h" #include "commands/details/details.h" +struct TotpCliContext { + PluginState* plugin_state; +}; + static void totp_cli_print_unknown_command(const FuriString* unknown_command) { TOTP_CLI_PRINTF_ERROR( "Command \"%s\" is unknown. Use \"" TOTP_CLI_COMMAND_HELP @@ -63,7 +67,7 @@ static void totp_cli_handler(Cli* cli, FuriString* args, void* context) { } else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_AUTOMATION) == 0) { totp_cli_command_automation_handle(plugin_state, args, cli); } else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_RESET) == 0) { - totp_cli_command_reset_handle(plugin_state, cli, cli_context->event_queue); + totp_cli_command_reset_handle(plugin_state, cli); } else if(furi_string_cmp_str(cmd, TOTP_CLI_COMMAND_UPDATE) == 0) { totp_cli_command_update_handle(plugin_state, args, cli); } else if( @@ -77,13 +81,11 @@ static void totp_cli_handler(Cli* cli, FuriString* args, void* context) { furi_string_free(cmd); } -TotpCliContext* - totp_cli_register_command_handler(PluginState* plugin_state, FuriMessageQueue* event_queue) { +TotpCliContext* totp_cli_register_command_handler(PluginState* plugin_state) { Cli* cli = furi_record_open(RECORD_CLI); TotpCliContext* context = malloc(sizeof(TotpCliContext)); furi_check(context != NULL); context->plugin_state = plugin_state; - context->event_queue = event_queue; cli_add_command( cli, TOTP_CLI_COMMAND_NAME, CliCommandFlagParallelSafe, totp_cli_handler, context); furi_record_close(RECORD_CLI); diff --git a/applications/external/totp/cli/cli.h b/applications/external/totp/cli/cli.h index 2e4b92db89..13afef78ff 100644 --- a/applications/external/totp/cli/cli.h +++ b/applications/external/totp/cli/cli.h @@ -3,11 +3,17 @@ #include #include "../types/plugin_state.h" -typedef struct { - PluginState* plugin_state; - FuriMessageQueue* event_queue; -} TotpCliContext; +typedef struct TotpCliContext TotpCliContext; -TotpCliContext* - totp_cli_register_command_handler(PluginState* plugin_state, FuriMessageQueue* event_queue); +/** + * @brief Registers TOTP CLI handler + * @param plugin_state application state + * @return TOTP CLI context + */ +TotpCliContext* totp_cli_register_command_handler(PluginState* plugin_state); + +/** + * @brief Unregisters TOTP CLI handler + * @param context application state + */ void totp_cli_unregister_command_handler(TotpCliContext* context); \ No newline at end of file diff --git a/applications/external/totp/cli/cli_helpers.h b/applications/external/totp/cli/cli_helpers.h index b8f4f236ad..9c40bff13f 100644 --- a/applications/external/totp/cli/cli_helpers.h +++ b/applications/external/totp/cli/cli_helpers.h @@ -33,12 +33,14 @@ extern const char* TOTP_CLI_COLOR_INFO; #define TOTP_CLI_PRINTF_INFO(format, ...) \ TOTP_CLI_PRINTF_COLORFUL(TOTP_CLI_COLOR_INFO, format, ##__VA_ARGS__) -#define TOTP_CLI_LOCK_UI(plugin_state) \ - Scene __previous_scene = plugin_state->current_scene; \ - totp_scene_director_activate_scene(plugin_state, TotpSceneStandby) +#define TOTP_CLI_LOCK_UI(plugin_state) \ + Scene __previous_scene = plugin_state->current_scene; \ + totp_scene_director_activate_scene(plugin_state, TotpSceneStandby); \ + totp_scene_director_force_redraw(plugin_state) -#define TOTP_CLI_UNLOCK_UI(plugin_state) \ - totp_scene_director_activate_scene(plugin_state, __previous_scene) +#define TOTP_CLI_UNLOCK_UI(plugin_state) \ + totp_scene_director_activate_scene(plugin_state, __previous_scene); \ + totp_scene_director_force_redraw(plugin_state) /** * @brief Checks whether user is authenticated and entered correct PIN. @@ -109,6 +111,6 @@ void totp_cli_print_error_updating_config_file(); void totp_cli_print_error_loading_token_info(); /** - * @brief Prints message to let user knwo that command is processing now + * @brief Prints message to let user know that command is processing now */ void totp_cli_print_processing(); \ No newline at end of file diff --git a/applications/external/totp/cli/commands/add/add.c b/applications/external/totp/cli/commands/add/add.c index fa64bd41cd..d2bf8b9071 100644 --- a/applications/external/totp/cli/commands/add/add.c +++ b/applications/external/totp/cli/commands/add/add.c @@ -11,7 +11,7 @@ struct TotpAddContext { FuriString* args; Cli* cli; - uint8_t* iv; + const CryptoSettings* crypto_settings; }; enum TotpIteratorUpdateTokenResultsEx { @@ -54,7 +54,7 @@ static TotpIteratorUpdateTokenResult // Reading token secret furi_string_reset(temp_str); - TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]\r\n"); + TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]:\r\n"); if(!totp_cli_read_line(context_t->cli, temp_str, mask_user_input)) { totp_cli_delete_last_line(); furi_string_secure_free(temp_str); @@ -68,7 +68,7 @@ static TotpIteratorUpdateTokenResult furi_string_get_cstr(temp_str), furi_string_size(temp_str), token_secret_encoding, - context_t->iv); + context_t->crypto_settings); furi_string_secure_free(temp_str); @@ -166,7 +166,8 @@ void totp_cli_command_add_handle(PluginState* plugin_state, FuriString* args, Cl TOTP_CLI_LOCK_UI(plugin_state); - struct TotpAddContext add_context = {.args = args, .cli = cli, .iv = &plugin_state->iv[0]}; + struct TotpAddContext add_context = { + .args = args, .cli = cli, .crypto_settings = &plugin_state->crypto_settings}; TotpIteratorUpdateTokenResult add_result = totp_token_info_iterator_add_new_token(iterator_context, &add_token_handler, &add_context); diff --git a/applications/external/totp/cli/commands/automation/automation.c b/applications/external/totp/cli/commands/automation/automation.c index c9f6ac34b3..87c121dbe5 100644 --- a/applications/external/totp/cli/commands/automation/automation.c +++ b/applications/external/totp/cli/commands/automation/automation.c @@ -7,17 +7,23 @@ #define TOTP_CLI_COMMAND_AUTOMATION_ARG_METHOD "automation" #define TOTP_CLI_COMMAND_AUTOMATION_METHOD_NONE "none" #define TOTP_CLI_COMMAND_AUTOMATION_METHOD_USB "usb" -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED #define TOTP_CLI_COMMAND_AUTOMATION_METHOD_BT "bt" #endif +#define TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTY "QWERTY" +#define TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY "AZERTY" +#define TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT_PREFIX "-k" +#define TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT "layout" void totp_cli_command_automation_docopt_commands() { - TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_AUTOMATION " Get or set automation method\r\n"); + TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_AUTOMATION " Get or set automation settings\r\n"); } void totp_cli_command_automation_docopt_usage() { - TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_AUTOMATION " " DOCOPT_OPTIONAL( - DOCOPT_MULTIPLE(DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_AUTOMATION_ARG_METHOD))) "\r\n"); + TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_AUTOMATION " " DOCOPT_OPTIONAL(DOCOPT_OPTION( + TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT_PREFIX, + DOCOPT_ARGUMENT( + TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT))) " " DOCOPT_OPTIONAL(DOCOPT_MULTIPLE(DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_AUTOMATION_ARG_METHOD))) "\r\n"); } void totp_cli_command_automation_docopt_arguments() { @@ -25,24 +31,33 @@ void totp_cli_command_automation_docopt_arguments() { " " TOTP_CLI_COMMAND_AUTOMATION_ARG_METHOD " Automation method to be set. Must be one of: " TOTP_CLI_COMMAND_AUTOMATION_METHOD_NONE ", " TOTP_CLI_COMMAND_AUTOMATION_METHOD_USB -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED ", " TOTP_CLI_COMMAND_AUTOMATION_METHOD_BT #endif "\r\n"); } -static void totp_cli_command_automation_print_method(AutomationMethod method, const char* color) { -#ifdef TOTP_BADBT_TYPE_ENABLED +void totp_cli_command_automation_docopt_options() { + TOTP_CLI_PRINTF(" " DOCOPT_OPTION( + TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT_PREFIX, + DOCOPT_ARGUMENT( + TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT)) " Automation keyboard layout. Must be one of: " TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTY + ", " TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY + "\r\n"); +} + +static void print_method(AutomationMethod method, const char* color) { +#ifdef TOTP_BADBT_AUTOMATION_ENABLED bool has_previous_method = false; #endif if(method & AutomationMethodBadUsb) { TOTP_CLI_PRINTF_COLORFUL(color, "\"" TOTP_CLI_COMMAND_AUTOMATION_METHOD_USB "\""); -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED has_previous_method = true; #endif } -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED if(method & AutomationMethodBadBt) { if(has_previous_method) { TOTP_CLI_PRINTF_COLORFUL(color, " and "); @@ -57,6 +72,37 @@ static void totp_cli_command_automation_print_method(AutomationMethod method, co } } +static void print_kb_layout(AutomationKeyboardLayout layout, const char* color) { + char* layoutToPrint; + switch(layout) { + case AutomationKeyboardLayoutQWERTY: + layoutToPrint = TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTY; + break; + case AutomationKeyboardLayoutAZERTY: + layoutToPrint = TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY; + break; + default: + furi_crash("Unknown automation keyboard layout"); + break; + } + + TOTP_CLI_PRINTF_COLORFUL(color, "%s", layoutToPrint); +} + +static bool + parse_automation_keyboard_layout(const FuriString* str, AutomationKeyboardLayout* out) { + bool result = true; + if(furi_string_cmpi_str(str, TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_QWERTY) == 0) { + *out = AutomationKeyboardLayoutQWERTY; + } else if(furi_string_cmpi_str(str, TOTP_CLI_COMMAND_AUTOMATION_LAYOUT_AZERTY) == 0) { + *out = AutomationKeyboardLayoutAZERTY; + } else { + result = false; + } + + return result; +} + void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* args, Cli* cli) { if(!totp_cli_ensure_authenticated(plugin_state, cli)) { return; @@ -65,6 +111,7 @@ void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* a FuriString* temp_str = furi_string_alloc(); bool new_method_provided = false; AutomationMethod new_method = AutomationMethodNone; + AutomationKeyboardLayout new_kb_layout = plugin_state->automation_kb_layout; bool args_valid = true; while(args_read_string_and_trim(args, temp_str)) { if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_AUTOMATION_METHOD_NONE) == 0) { @@ -74,13 +121,19 @@ void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* a new_method_provided = true; new_method |= AutomationMethodBadUsb; } -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED else if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_AUTOMATION_METHOD_BT) == 0) { new_method_provided = true; new_method |= AutomationMethodBadBt; } #endif - else { + else if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_AUTOMATION_ARG_KB_LAYOUT_PREFIX) == 0) { + if(!args_read_string_and_trim(args, temp_str) || + !parse_automation_keyboard_layout(temp_str, &new_kb_layout)) { + args_valid = false; + break; + } + } else { args_valid = false; break; } @@ -96,15 +149,19 @@ void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* a TOTP_CLI_LOCK_UI(plugin_state); plugin_state->automation_method = new_method; + plugin_state->automation_kb_layout = new_kb_layout; if(totp_config_file_update_automation_method(plugin_state)) { TOTP_CLI_PRINTF_SUCCESS("Automation method is set to "); - totp_cli_command_automation_print_method(new_method, TOTP_CLI_COLOR_SUCCESS); + print_method(new_method, TOTP_CLI_COLOR_SUCCESS); + TOTP_CLI_PRINTF_SUCCESS(" ("); + print_kb_layout(plugin_state->automation_kb_layout, TOTP_CLI_COLOR_SUCCESS); + TOTP_CLI_PRINTF_SUCCESS(")"); cli_nl(); } else { totp_cli_print_error_updating_config_file(); } -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED if(!(new_method & AutomationMethodBadBt) && plugin_state->bt_type_code_worker_context != NULL) { totp_bt_type_code_worker_free(plugin_state->bt_type_code_worker_context); @@ -115,8 +172,10 @@ void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* a TOTP_CLI_UNLOCK_UI(plugin_state); } else { TOTP_CLI_PRINTF_INFO("Current automation method is "); - totp_cli_command_automation_print_method( - plugin_state->automation_method, TOTP_CLI_COLOR_INFO); + print_method(plugin_state->automation_method, TOTP_CLI_COLOR_INFO); + TOTP_CLI_PRINTF_INFO(" ("); + print_kb_layout(plugin_state->automation_kb_layout, TOTP_CLI_COLOR_INFO); + TOTP_CLI_PRINTF_INFO(")"); cli_nl(); } } while(false); diff --git a/applications/external/totp/cli/commands/automation/automation.h b/applications/external/totp/cli/commands/automation/automation.h index fb62e638ef..4a713d49be 100644 --- a/applications/external/totp/cli/commands/automation/automation.h +++ b/applications/external/totp/cli/commands/automation/automation.h @@ -8,4 +8,5 @@ void totp_cli_command_automation_handle(PluginState* plugin_state, FuriString* args, Cli* cli); void totp_cli_command_automation_docopt_commands(); void totp_cli_command_automation_docopt_usage(); -void totp_cli_command_automation_docopt_arguments(); \ No newline at end of file +void totp_cli_command_automation_docopt_arguments(); +void totp_cli_command_automation_docopt_options(); \ No newline at end of file diff --git a/applications/external/totp/cli/commands/help/help.c b/applications/external/totp/cli/commands/help/help.c index cc47db11f8..7093877ea8 100644 --- a/applications/external/totp/cli/commands/help/help.c +++ b/applications/external/totp/cli/commands/help/help.c @@ -64,4 +64,6 @@ void totp_cli_command_help_handle() { totp_cli_command_add_docopt_options(); totp_cli_command_update_docopt_options(); totp_cli_command_delete_docopt_options(); + totp_cli_command_pin_docopt_options(); + totp_cli_command_automation_docopt_options(); } \ No newline at end of file diff --git a/applications/external/totp/cli/commands/pin/pin.c b/applications/external/totp/cli/commands/pin/pin.c index 62531b96a0..2b989a713b 100644 --- a/applications/external/totp/cli/commands/pin/pin.c +++ b/applications/external/totp/cli/commands/pin/pin.c @@ -7,19 +7,35 @@ #include "../../../services/config/config.h" #include "../../cli_helpers.h" #include -#include "../../../services/crypto/crypto.h" +#include "../../../services/crypto/crypto_facade.h" #include "../../../ui/scene_director.h" #define TOTP_CLI_COMMAND_PIN_COMMAND_SET "set" #define TOTP_CLI_COMMAND_PIN_COMMAND_REMOVE "remove" +#define TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT_PREFIX "-c" +#define TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT "slot" void totp_cli_command_pin_docopt_commands() { TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_PIN " Set\\change\\remove PIN\r\n"); } void totp_cli_command_pin_docopt_usage() { - TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_PIN " " DOCOPT_REQUIRED( - TOTP_CLI_COMMAND_PIN_COMMAND_SET " | " TOTP_CLI_COMMAND_PIN_COMMAND_REMOVE) "\r\n"); + TOTP_CLI_PRINTF( + " " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_PIN + " " DOCOPT_REQUIRED(TOTP_CLI_COMMAND_PIN_COMMAND_SET " | " TOTP_CLI_COMMAND_PIN_COMMAND_REMOVE) " " DOCOPT_OPTIONAL( + DOCOPT_OPTION( + TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT_PREFIX, + DOCOPT_ARGUMENT(TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT))) "\r\n"); +} + +void totp_cli_command_pin_docopt_options() { + TOTP_CLI_PRINTF( + " " DOCOPT_OPTION( + TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT_PREFIX, + DOCOPT_ARGUMENT( + TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT)) " New crypto key slot. Must be between %d and %d\r\n", + ACCEPTABLE_CRYPTO_KEY_SLOT_START, + ACCEPTABLE_CRYPTO_KEY_SLOT_END); } static inline uint8_t totp_cli_key_to_pin_code(uint8_t key) { @@ -89,35 +105,49 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl bool do_change = false; bool do_remove = false; - UNUSED(do_remove); - if(args_read_string_and_trim(args, temp_str)) { + uint8_t crypto_key_slot = plugin_state->crypto_settings.crypto_key_slot; + + bool arguments_parsed = true; + while(args_read_string_and_trim(args, temp_str)) { if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_PIN_COMMAND_SET) == 0) { do_change = true; } else if(furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_PIN_COMMAND_REMOVE) == 0) { do_remove = true; + } else if( + furi_string_cmpi_str(temp_str, TOTP_CLI_COMMAND_PIN_ARG_NEW_CRYPTO_KEY_SLOT_PREFIX) == + 0) { + if(!args_read_uint8_and_trim(args, &crypto_key_slot) || + !totp_crypto_check_key_slot(crypto_key_slot)) { + TOTP_CLI_PRINTF_ERROR("Slot \"%" PRIu8 "\" can not be used\r\n", crypto_key_slot); + arguments_parsed = false; + break; + } } else { totp_cli_print_invalid_arguments(); + arguments_parsed = false; + break; } - } else { + } + + if(!(do_change || do_remove) || (do_change && do_remove)) { totp_cli_print_invalid_arguments(); + arguments_parsed = false; } - if((do_change || do_remove) && totp_cli_ensure_authenticated(plugin_state, cli)) { + if(arguments_parsed && totp_cli_ensure_authenticated(plugin_state, cli)) { TOTP_CLI_LOCK_UI(plugin_state); do { - uint8_t old_iv[TOTP_IV_SIZE]; - memcpy(&old_iv[0], &plugin_state->iv[0], TOTP_IV_SIZE); - uint8_t new_pin[TOTP_IV_SIZE]; - memset(&new_pin[0], 0, TOTP_IV_SIZE); + uint8_t new_pin[CRYPTO_IV_LENGTH]; + memset(&new_pin[0], 0, CRYPTO_IV_LENGTH); uint8_t new_pin_length = 0; if(do_change) { if(!totp_cli_read_pin(cli, &new_pin[0], &new_pin_length)) { - memset_s(&new_pin[0], TOTP_IV_SIZE, 0, TOTP_IV_SIZE); + memset_s(&new_pin[0], CRYPTO_IV_LENGTH, 0, CRYPTO_IV_LENGTH); break; } } else if(do_remove) { new_pin_length = 0; - memset(&new_pin[0], 0, TOTP_IV_SIZE); + memset(&new_pin[0], 0, CRYPTO_IV_LENGTH); } char* backup_path = totp_config_file_backup(plugin_state); @@ -127,7 +157,7 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl "Once you make sure everything is fine and works as expected, please delete this backup file\r\n"); free(backup_path); } else { - memset_s(&new_pin[0], TOTP_IV_SIZE, 0, TOTP_IV_SIZE); + memset_s(&new_pin[0], CRYPTO_IV_LENGTH, 0, CRYPTO_IV_LENGTH); TOTP_CLI_PRINTF_ERROR( "An error has occurred during taking backup of config file\r\n"); break; @@ -135,10 +165,10 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cl TOTP_CLI_PRINTF("Encrypting...\r\n"); - bool update_result = - totp_config_file_update_encryption(plugin_state, new_pin, new_pin_length); + bool update_result = totp_config_file_update_encryption( + plugin_state, crypto_key_slot, new_pin, new_pin_length); - memset_s(&new_pin[0], TOTP_IV_SIZE, 0, TOTP_IV_SIZE); + memset_s(&new_pin[0], CRYPTO_IV_LENGTH, 0, CRYPTO_IV_LENGTH); totp_cli_delete_last_line(); diff --git a/applications/external/totp/cli/commands/pin/pin.h b/applications/external/totp/cli/commands/pin/pin.h index 1308ae7367..2d320a02a7 100644 --- a/applications/external/totp/cli/commands/pin/pin.h +++ b/applications/external/totp/cli/commands/pin/pin.h @@ -7,4 +7,5 @@ void totp_cli_command_pin_handle(PluginState* plugin_state, FuriString* args, Cli* cli); void totp_cli_command_pin_docopt_commands(); -void totp_cli_command_pin_docopt_usage(); \ No newline at end of file +void totp_cli_command_pin_docopt_usage(); +void totp_cli_command_pin_docopt_options(); \ No newline at end of file diff --git a/applications/external/totp/cli/commands/reset/reset.c b/applications/external/totp/cli/commands/reset/reset.c index 96b2cc56a2..250d594bf8 100644 --- a/applications/external/totp/cli/commands/reset/reset.c +++ b/applications/external/totp/cli/commands/reset/reset.c @@ -17,10 +17,7 @@ void totp_cli_command_reset_docopt_usage() { TOTP_CLI_PRINTF(" " TOTP_CLI_COMMAND_NAME " " TOTP_CLI_COMMAND_RESET "\r\n"); } -void totp_cli_command_reset_handle( - PluginState* plugin_state, - Cli* cli, - FuriMessageQueue* event_queue) { +void totp_cli_command_reset_handle(PluginState* plugin_state, Cli* cli) { TOTP_CLI_LOCK_UI(plugin_state); TOTP_CLI_PRINTF_WARNING( "As a result of reset all the settings and tokens will be permanently lost.\r\n"); @@ -35,7 +32,7 @@ void totp_cli_command_reset_handle( totp_config_file_reset(plugin_state); TOTP_CLI_PRINTF_SUCCESS("Application has been successfully reset to default.\r\n"); TOTP_CLI_PRINTF_SUCCESS("Now application will be closed to apply all the changes.\r\n"); - totp_cli_force_close_app(event_queue); + totp_cli_force_close_app(plugin_state->event_queue); } else { TOTP_CLI_PRINTF_INFO("Action was not confirmed by user\r\n"); TOTP_CLI_UNLOCK_UI(plugin_state); diff --git a/applications/external/totp/cli/commands/reset/reset.h b/applications/external/totp/cli/commands/reset/reset.h index 3a4675587b..221c843045 100644 --- a/applications/external/totp/cli/commands/reset/reset.h +++ b/applications/external/totp/cli/commands/reset/reset.h @@ -5,9 +5,6 @@ #define TOTP_CLI_COMMAND_RESET "reset" -void totp_cli_command_reset_handle( - PluginState* plugin_state, - Cli* cli, - FuriMessageQueue* event_queue); +void totp_cli_command_reset_handle(PluginState* plugin_state, Cli* cli); void totp_cli_command_reset_docopt_commands(); void totp_cli_command_reset_docopt_usage(); \ No newline at end of file diff --git a/applications/external/totp/cli/commands/update/update.c b/applications/external/totp/cli/commands/update/update.c index 49beb7b6d6..79ed756708 100644 --- a/applications/external/totp/cli/commands/update/update.c +++ b/applications/external/totp/cli/commands/update/update.c @@ -13,7 +13,7 @@ struct TotpUpdateContext { FuriString* args; Cli* cli; - uint8_t* iv; + const CryptoSettings* crypto_settings; }; enum TotpIteratorUpdateTokenResultsEx { @@ -83,7 +83,7 @@ static TotpIteratorUpdateTokenResult if(update_token_secret) { // Reading token secret furi_string_reset(temp_str); - TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]\r\n"); + TOTP_CLI_PRINTF("Enter token secret and confirm with [ENTER]:\r\n"); bool token_secret_read = totp_cli_read_line(context_t->cli, temp_str, mask_user_input); totp_cli_delete_last_line(); if(!token_secret_read) { @@ -96,7 +96,7 @@ static TotpIteratorUpdateTokenResult furi_string_get_cstr(temp_str), furi_string_size(temp_str), token_secret_encoding, - context_t->iv)) { + context_t->crypto_settings)) { furi_string_secure_free(temp_str); return TotpIteratorUpdateTokenResultInvalidSecret; } @@ -151,7 +151,7 @@ void totp_cli_command_update_handle(PluginState* plugin_state, FuriString* args, totp_token_info_iterator_go_to(iterator_context, token_number - 1); struct TotpUpdateContext update_context = { - .args = args, .cli = cli, .iv = &plugin_state->iv[0]}; + .args = args, .cli = cli, .crypto_settings = &plugin_state->crypto_settings}; TotpIteratorUpdateTokenResult update_result = totp_token_info_iterator_update_current_token( iterator_context, &update_token_handler, &update_context); diff --git a/applications/external/totp/cli/common_command_arguments.h b/applications/external/totp/cli/common_command_arguments.h index be1c0bdfe6..0bf8342259 100644 --- a/applications/external/totp/cli/common_command_arguments.h +++ b/applications/external/totp/cli/common_command_arguments.h @@ -18,32 +18,87 @@ #define TOTP_CLI_COMMAND_ARG_SECRET_ENCODING_PREFIX "-e" #define TOTP_CLI_COMMAND_ARG_SECRET_ENCODING "encoding" +/** + * @brief Prints information about unknown argument + * @param arg + */ void totp_cli_printf_unknown_argument(const FuriString* arg); +/** + * @brief Prints information about missed required argument + * @param arg + */ void totp_cli_printf_missed_argument_value(char* arg); +/** + * @brief Tries to read token hashing algo + * @param token_info token info to set parsed algo to if successfully read and parsed + * @param arg argument to parse + * @param args rest of arguments + * @param[out] parsed will be set to \c true if token hashing algo sucecssfully read and parsed; \c false otherwise + * @return \c true if \c arg represents token hashing algo argument; \c false otherwise + */ bool totp_cli_try_read_algo(TokenInfo* token_info, FuriString* arg, FuriString* args, bool* parsed); +/** + * @brief Tries to read token digits count + * @param token_info token info to set parsed digits count to if successfully read and parsed + * @param arg argument to parse + * @param args rest of arguments + * @param[out] parsed will be set to \c true if token digits count sucecssfully read and parsed; \c false otherwise + * @return \c true if \c arg represents token digits count argument; \c false otherwise + */ bool totp_cli_try_read_digits( TokenInfo* token_info, const FuriString* arg, FuriString* args, bool* parsed); +/** + * @brief Tries to read token duration + * @param token_info token info to set parsed duration to if successfully read and parsed + * @param arg argument to parse + * @param args rest of arguments + * @param[out] parsed will be set to \c true if token duration sucecssfully read and parsed; \c false otherwise + * @return \c true if \c arg represents token duration argument; \c false otherwise + */ bool totp_cli_try_read_duration( TokenInfo* token_info, const FuriString* arg, FuriString* args, bool* parsed); +/** + * @brief Tries to read token automation features + * @param token_info token info to set parsed automation features to if successfully read and parsed + * @param arg argument to parse + * @param args rest of arguments + * @param[out] parsed will be set to \c true if token automation features sucecssfully read and parsed; \c false otherwise + * @return \c true if \c arg represents token automation features argument; \c false otherwise + */ bool totp_cli_try_read_automation_features( TokenInfo* token_info, FuriString* arg, FuriString* args, bool* parsed); +/** + * @brief Tries to read unsecure flag + * @param arg argument to parse + * @param[out] parsed will be set to \c true if unsecure flag sucecssfully read and parsed; \c false otherwise + * @param[out] unsecure_flag will be set to parsed unsecure flag state if read and parsed successfully + * @return \c true if \c arg represents unsecure flag argument; \c false otherwise + */ bool totp_cli_try_read_unsecure_flag(const FuriString* arg, bool* parsed, bool* unsecure_flag); +/** + * @brief Tries to read plain token secret encoding + * @param arg argument to parse + * @param args rest of arguments + * @param[out] parsed will be set to \c true if plain token secret encoding sucecssfully read and parsed; \c false otherwise + * @param[out] secret_encoding will be set to parsed plain token secret encoding if read and parsed successfully + * @return \c true if \c arg represents plain token secret encoding argument; \c false otherwise + */ bool totp_cli_try_read_plain_token_secret_encoding( FuriString* arg, FuriString* args, diff --git a/applications/external/totp/features_config.h b/applications/external/totp/features_config.h index 54bbaba945..764f27bea7 100644 --- a/applications/external/totp/features_config.h +++ b/applications/external/totp/features_config.h @@ -4,13 +4,8 @@ #endif // Include Bluetooth token input automation -#ifndef TOTP_NO_BADBT_TYPE -#define TOTP_BADBT_TYPE_ENABLED -#endif - -// Include token input automation icons on the main screen -#ifndef TOTP_NO_AUTOMATION_ICONS -#define TOTP_AUTOMATION_ICONS_ENABLED +#ifndef TOTP_NO_BADBT_AUTOMATION +#define TOTP_BADBT_AUTOMATION_ENABLED #endif // List of compatible firmwares @@ -19,6 +14,7 @@ #define TOTP_FIRMWARE_XTREME_UL (3) // End of list +// Target firmware #ifndef TOTP_TARGET_FIRMWARE #define TOTP_TARGET_FIRMWARE TOTP_FIRMWARE_XTREME_UL #endif diff --git a/applications/external/totp/images/totp_arrow_bottom_10x5.png b/applications/external/totp/images/totp_arrow_bottom_10x5.png deleted file mode 100644 index 54e22f5efb619f61ce67200003756ba900d6f926..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 147 zcmeAS@N?(olHy`uVBq!ia0vp^AT}!_Gmvy!^VM%xNb!1@J z*w6hZkrl{i3-AeX1=9cj|6h7@{#_u8v%n*=n1O-sAP6(=n3(+*C@ALX;us=vIhmn} kjlGSTT|!PS;YSSvgKQM*)U5pmj6f9(p00i_>zopr0Imci+W-In diff --git a/applications/external/totp/services/config/config.c b/applications/external/totp/services/config/config.c index 5b7cd936ea..19b1cf3688 100644 --- a/applications/external/totp/services/config/config.c +++ b/applications/external/totp/services/config/config.c @@ -9,7 +9,8 @@ #include "../../types/common.h" #include "../../types/token_info.h" #include "../../features_config.h" -#include "../crypto/crypto.h" +#include "../crypto/crypto_facade.h" +#include "../crypto/constants.h" #include "migrations/common_migration.h" #define CONFIG_FILE_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf" @@ -110,7 +111,16 @@ static char* totp_config_file_backup_i(Storage* storage) { static bool totp_open_config_file(Storage* storage, FlipperFormat** file) { FlipperFormat* fff_data_file = flipper_format_file_alloc(storage); - if(storage_common_stat(storage, CONFIG_FILE_PATH, NULL) == FSE_OK) { + bool conf_file_exists = storage_common_stat(storage, CONFIG_FILE_PATH, NULL) == FSE_OK; + if(!conf_file_exists) { + FURI_LOG_I(LOGGING_TAG, "Application catalog needs to be migrated"); + FS_Error migration_result = + storage_common_migrate(storage, EXT_PATH("authenticator"), CONFIG_FILE_DIRECTORY_PATH); + FURI_LOG_I(LOGGING_TAG, "Migrated catalog. Result code: %d", (int)migration_result); + conf_file_exists = storage_common_stat(storage, CONFIG_FILE_PATH, NULL) == FSE_OK; + } + + if(conf_file_exists) { FURI_LOG_D(LOGGING_TAG, "Config file %s found", CONFIG_FILE_PATH); if(!flipper_format_file_open_existing(fff_data_file, CONFIG_FILE_PATH)) { FURI_LOG_E(LOGGING_TAG, "Error opening existing file %s", CONFIG_FILE_PATH); @@ -119,16 +129,6 @@ static bool totp_open_config_file(Storage* storage, FlipperFormat** file) { } } else { FURI_LOG_D(LOGGING_TAG, "Config file %s is not found. Will create new.", CONFIG_FILE_PATH); - if(storage_common_stat(storage, CONFIG_FILE_DIRECTORY_PATH, NULL) == FSE_NOT_EXIST) { - FURI_LOG_D( - LOGGING_TAG, - "Directory %s doesn't exist. Will create new.", - CONFIG_FILE_DIRECTORY_PATH); - if(!storage_simply_mkdir(storage, CONFIG_FILE_DIRECTORY_PATH)) { - FURI_LOG_E(LOGGING_TAG, "Error creating directory %s", CONFIG_FILE_DIRECTORY_PATH); - return false; - } - } if(!flipper_format_file_open_new(fff_data_file, CONFIG_FILE_PATH)) { totp_close_config_file(fff_data_file); @@ -139,6 +139,13 @@ static bool totp_open_config_file(Storage* storage, FlipperFormat** file) { flipper_format_write_header_cstr( fff_data_file, CONFIG_FILE_HEADER, CONFIG_FILE_ACTUAL_VERSION); + uint32_t tmp_uint32 = CRYPTO_LATEST_VERSION; + flipper_format_write_uint32(fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERSION, &tmp_uint32, 1); + + tmp_uint32 = DEFAULT_CRYPTO_KEY_SLOT; + flipper_format_write_uint32( + fff_data_file, TOTP_CONFIG_KEY_CRYPTO_KEY_SLOT, &tmp_uint32, 1); + flipper_format_write_comment_cstr( fff_data_file, "Config file format specification can be found here: https://github.com/akopachov/flipper-zero_authenticator/blob/master/docs/conf-file_description.md"); @@ -146,7 +153,7 @@ static bool totp_open_config_file(Storage* storage, FlipperFormat** file) { float tmp_tz = 0; flipper_format_write_float(fff_data_file, TOTP_CONFIG_KEY_TIMEZONE, &tmp_tz, 1); - uint32_t tmp_uint32 = NotificationMethodSound | NotificationMethodVibro; + tmp_uint32 = NotificationMethodSound | NotificationMethodVibro; flipper_format_write_uint32( fff_data_file, TOTP_CONFIG_KEY_NOTIFICATION_METHOD, &tmp_uint32, 1); @@ -154,7 +161,11 @@ static bool totp_open_config_file(Storage* storage, FlipperFormat** file) { flipper_format_write_uint32( fff_data_file, TOTP_CONFIG_KEY_AUTOMATION_METHOD, &tmp_uint32, 1); - tmp_uint32 = 0; + tmp_uint32 = AutomationKeyboardLayoutQWERTY; + flipper_format_write_uint32( + fff_data_file, TOTP_CONFIG_KEY_AUTOMATION_KB_LAYOUT, &tmp_uint32, 1); + + tmp_uint32 = 0; //-V1048 flipper_format_write_uint32(fff_data_file, TOTP_CONFIG_KEY_FONT, &tmp_uint32, 1); if(!flipper_format_rewind(fff_data_file)) { @@ -233,6 +244,12 @@ bool totp_config_file_update_automation_method(const PluginState* plugin_state) break; } + tmp_uint32 = plugin_state->automation_kb_layout; + if(!flipper_format_insert_or_update_uint32( + file, TOTP_CONFIG_KEY_AUTOMATION_KB_LAYOUT, &tmp_uint32, 1)) { + break; + } + update_result = true; } while(false); @@ -265,6 +282,12 @@ bool totp_config_file_update_user_settings(const PluginState* plugin_state) { break; } + tmp_uint32 = plugin_state->automation_kb_layout; + if(!flipper_format_insert_or_update_uint32( + file, TOTP_CONFIG_KEY_AUTOMATION_KB_LAYOUT, &tmp_uint32, 1)) { + break; + } + update_result = true; } while(false); @@ -344,8 +367,38 @@ bool totp_config_file_load(PluginState* const plugin_state) { } } + uint32_t tmp_uint32; + + if(!flipper_format_read_uint32( + fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERSION, &tmp_uint32, 1)) { + FURI_LOG_E(LOGGING_TAG, "Missing required " TOTP_CONFIG_KEY_CRYPTO_VERSION "property"); + break; + } + + plugin_state->crypto_settings.crypto_version = tmp_uint32; + + if(!flipper_format_rewind(fff_data_file)) { + break; + } + + if(!flipper_format_read_uint32( + fff_data_file, TOTP_CONFIG_KEY_CRYPTO_KEY_SLOT, &tmp_uint32, 1)) { + FURI_LOG_E( + LOGGING_TAG, "Missing required " TOTP_CONFIG_KEY_CRYPTO_KEY_SLOT "property"); + break; + } + + plugin_state->crypto_settings.crypto_key_slot = tmp_uint32; + + if(!flipper_format_rewind(fff_data_file)) { + break; + } + if(!flipper_format_read_hex( - fff_data_file, TOTP_CONFIG_KEY_BASE_IV, &plugin_state->base_iv[0], TOTP_IV_SIZE)) { + fff_data_file, + TOTP_CONFIG_KEY_BASE_IV, + &plugin_state->crypto_settings.base_iv[0], + CRYPTO_IV_LENGTH)) { FURI_LOG_D(LOGGING_TAG, "Missing base IV"); } @@ -357,22 +410,23 @@ bool totp_config_file_load(PluginState* const plugin_state) { if(flipper_format_get_value_count( fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, &crypto_size) && crypto_size > 0) { - plugin_state->crypto_verify_data = malloc(sizeof(uint8_t) * crypto_size); - furi_check(plugin_state->crypto_verify_data != NULL); - plugin_state->crypto_verify_data_length = crypto_size; + plugin_state->crypto_settings.crypto_verify_data = + malloc(sizeof(uint8_t) * crypto_size); + furi_check(plugin_state->crypto_settings.crypto_verify_data != NULL); + plugin_state->crypto_settings.crypto_verify_data_length = crypto_size; if(!flipper_format_read_hex( fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, - plugin_state->crypto_verify_data, + plugin_state->crypto_settings.crypto_verify_data, crypto_size)) { FURI_LOG_D(LOGGING_TAG, "Missing crypto verify token"); - free(plugin_state->crypto_verify_data); - plugin_state->crypto_verify_data = NULL; - plugin_state->crypto_verify_data_length = 0; + free(plugin_state->crypto_settings.crypto_verify_data); + plugin_state->crypto_settings.crypto_verify_data = NULL; + plugin_state->crypto_settings.crypto_verify_data_length = 0; } } else { - plugin_state->crypto_verify_data = NULL; - plugin_state->crypto_verify_data_length = 0; + plugin_state->crypto_settings.crypto_verify_data = NULL; + plugin_state->crypto_settings.crypto_verify_data_length = 0; } if(!flipper_format_rewind(fff_data_file)) { @@ -390,13 +444,17 @@ bool totp_config_file_load(PluginState* const plugin_state) { } if(!flipper_format_read_bool( - fff_data_file, TOTP_CONFIG_KEY_PINSET, &plugin_state->pin_set, 1)) { - plugin_state->pin_set = true; + fff_data_file, + TOTP_CONFIG_KEY_PINSET, + &plugin_state->crypto_settings.pin_required, + 1)) { + plugin_state->crypto_settings.pin_required = true; } - flipper_format_rewind(fff_data_file); + if(!flipper_format_rewind(fff_data_file)) { + break; + } - uint32_t tmp_uint32; if(!flipper_format_read_uint32( fff_data_file, TOTP_CONFIG_KEY_NOTIFICATION_METHOD, &tmp_uint32, 1)) { tmp_uint32 = NotificationMethodSound | NotificationMethodVibro; @@ -404,7 +462,9 @@ bool totp_config_file_load(PluginState* const plugin_state) { plugin_state->notification_method = tmp_uint32; - flipper_format_rewind(fff_data_file); + if(!flipper_format_rewind(fff_data_file)) { + break; + } if(!flipper_format_read_uint32( fff_data_file, TOTP_CONFIG_KEY_AUTOMATION_METHOD, &tmp_uint32, 1)) { @@ -413,6 +473,21 @@ bool totp_config_file_load(PluginState* const plugin_state) { plugin_state->automation_method = tmp_uint32; + if(!flipper_format_rewind(fff_data_file)) { + break; + } + + if(!flipper_format_read_uint32( + fff_data_file, TOTP_CONFIG_KEY_AUTOMATION_KB_LAYOUT, &tmp_uint32, 1)) { + tmp_uint32 = AutomationKeyboardLayoutQWERTY; + } + + plugin_state->automation_kb_layout = tmp_uint32; + + if(!flipper_format_rewind(fff_data_file)) { + break; + } + if(!flipper_format_read_uint32(fff_data_file, TOTP_CONFIG_KEY_FONT, &tmp_uint32, 1)) { tmp_uint32 = 0; } @@ -425,7 +500,9 @@ bool totp_config_file_load(PluginState* const plugin_state) { plugin_state->config_file_context->config_file = fff_data_file; plugin_state->config_file_context->token_info_iterator_context = totp_token_info_iterator_alloc( - storage, plugin_state->config_file_context->config_file, plugin_state->iv); + storage, + plugin_state->config_file_context->config_file, + &plugin_state->crypto_settings); result = true; } while(false); @@ -438,21 +515,39 @@ bool totp_config_file_update_crypto_signatures(const PluginState* plugin_state) flipper_format_rewind(config_file); bool update_result = false; do { + uint32_t tmp_uint32 = plugin_state->crypto_settings.crypto_version; + if(!flipper_format_insert_or_update_uint32( + config_file, TOTP_CONFIG_KEY_CRYPTO_VERSION, &tmp_uint32, 1)) { + break; + } + + tmp_uint32 = plugin_state->crypto_settings.crypto_key_slot; + if(!flipper_format_insert_or_update_uint32( + config_file, TOTP_CONFIG_KEY_CRYPTO_KEY_SLOT, &tmp_uint32, 1)) { + break; + } + if(!flipper_format_insert_or_update_hex( - config_file, TOTP_CONFIG_KEY_BASE_IV, plugin_state->base_iv, TOTP_IV_SIZE)) { + config_file, + TOTP_CONFIG_KEY_BASE_IV, + plugin_state->crypto_settings.base_iv, + CRYPTO_IV_LENGTH)) { break; } if(!flipper_format_insert_or_update_hex( config_file, TOTP_CONFIG_KEY_CRYPTO_VERIFY, - plugin_state->crypto_verify_data, - plugin_state->crypto_verify_data_length)) { + plugin_state->crypto_settings.crypto_verify_data, + plugin_state->crypto_settings.crypto_verify_data_length)) { break; } if(!flipper_format_insert_or_update_bool( - config_file, TOTP_CONFIG_KEY_PINSET, &plugin_state->pin_set, 1)) { + config_file, + TOTP_CONFIG_KEY_PINSET, + &plugin_state->crypto_settings.pin_required, + 1)) { break; } @@ -480,6 +575,7 @@ void totp_config_file_reset(PluginState* const plugin_state) { bool totp_config_file_update_encryption( PluginState* plugin_state, + uint8_t new_crypto_key_slot, const uint8_t* new_pin, uint8_t new_pin_length) { FlipperFormat* config_file = plugin_state->config_file_context->config_file; @@ -489,23 +585,28 @@ bool totp_config_file_update_encryption( return false; } - uint8_t old_iv[TOTP_IV_SIZE]; - memcpy(&old_iv[0], &plugin_state->iv[0], TOTP_IV_SIZE); + if(!totp_crypto_check_key_slot(new_crypto_key_slot)) { + return false; + } + + CryptoSettings old_crypto_settings = plugin_state->crypto_settings; - memset(&plugin_state->iv[0], 0, TOTP_IV_SIZE); - memset(&plugin_state->base_iv[0], 0, TOTP_IV_SIZE); - if(plugin_state->crypto_verify_data != NULL) { - free(plugin_state->crypto_verify_data); - plugin_state->crypto_verify_data = NULL; + memset(&plugin_state->crypto_settings.iv[0], 0, CRYPTO_IV_LENGTH); + memset(&plugin_state->crypto_settings.base_iv[0], 0, CRYPTO_IV_LENGTH); + if(plugin_state->crypto_settings.crypto_verify_data != NULL) { + free(plugin_state->crypto_settings.crypto_verify_data); + plugin_state->crypto_settings.crypto_verify_data = NULL; } - CryptoSeedIVResult seed_result = - totp_crypto_seed_iv(plugin_state, new_pin_length > 0 ? new_pin : NULL, new_pin_length); + plugin_state->crypto_settings.crypto_key_slot = new_crypto_key_slot; + plugin_state->crypto_settings.crypto_version = CRYPTO_LATEST_VERSION; + + CryptoSeedIVResult seed_result = totp_crypto_seed_iv( + &plugin_state->crypto_settings, new_pin_length > 0 ? new_pin : NULL, new_pin_length); if(seed_result & CryptoSeedIVResultFlagSuccess && - seed_result & CryptoSeedIVResultFlagNewCryptoVerifyData) { - if(!totp_config_file_update_crypto_signatures(plugin_state)) { - return false; - } + seed_result & CryptoSeedIVResultFlagNewCryptoVerifyData && + !totp_config_file_update_crypto_signatures(plugin_state)) { + return false; } else if(seed_result == CryptoSeedIVResultFailed) { return false; } @@ -552,12 +653,15 @@ bool totp_config_file_update_encryption( size_t plain_token_length; uint8_t* plain_token = totp_crypto_decrypt( - encrypted_token, secret_bytes_count, &old_iv[0], &plain_token_length); + encrypted_token, secret_bytes_count, &old_crypto_settings, &plain_token_length); free(encrypted_token); size_t encrypted_token_length; encrypted_token = totp_crypto_encrypt( - plain_token, plain_token_length, &plugin_state->iv[0], &encrypted_token_length); + plain_token, + plain_token_length, + &plugin_state->crypto_settings, + &encrypted_token_length); memset_s(plain_token, plain_token_length, 0, plain_token_length); free(plain_token); @@ -588,6 +692,36 @@ bool totp_config_file_update_encryption( return result; } +bool totp_config_file_ensure_latest_encryption( + PluginState* plugin_state, + const uint8_t* pin, + uint8_t pin_length) { + bool result = true; + if(plugin_state->crypto_settings.crypto_version < CRYPTO_LATEST_VERSION) { + FURI_LOG_I(LOGGING_TAG, "Migration to crypto v%d is needed", CRYPTO_LATEST_VERSION); + char* backup_path = totp_config_file_backup(plugin_state); + if(backup_path != NULL) { + free(backup_path); + uint8_t crypto_key_slot = plugin_state->crypto_settings.crypto_key_slot; + if(!totp_crypto_check_key_slot(crypto_key_slot)) { + crypto_key_slot = DEFAULT_CRYPTO_KEY_SLOT; + } + + result = + totp_config_file_update_encryption(plugin_state, crypto_key_slot, pin, pin_length); + FURI_LOG_I( + LOGGING_TAG, + "Migration to crypto v%d is done. Result: %d", + CRYPTO_LATEST_VERSION, + result); + } else { + result = false; + } + } + + return result; +} + TokenInfoIteratorContext* totp_config_get_token_iterator_context(const PluginState* plugin_state) { return plugin_state->config_file_context->token_info_iterator_context; } \ No newline at end of file diff --git a/applications/external/totp/services/config/config.h b/applications/external/totp/services/config/config.h index d2fe957c66..38bc06ba2d 100644 --- a/applications/external/totp/services/config/config.h +++ b/applications/external/totp/services/config/config.h @@ -73,15 +73,29 @@ void totp_config_file_close(PluginState* const plugin_state); /** * @brief Updates config file encryption by re-encrypting it using new user's PIN and new randomly generated IV * @param plugin_state application state + * @param new_crypto_key_slot new crypto key slot to be used * @param new_pin new user's PIN * @param new_pin_length new user's PIN length * @return \c true if config file encryption successfully updated; \c false otherwise */ bool totp_config_file_update_encryption( PluginState* plugin_state, + uint8_t new_crypto_key_slot, const uint8_t* new_pin, uint8_t new_pin_length); +/** + * @brief Ensures application config file uses latest encryption and upgrades encryption if needed + * @param plugin_state application state + * @param pin user's PIN + * @param pin_length user's PIN length + * @return \c true if operation succeeded; \c false otherwise + */ +bool totp_config_file_ensure_latest_encryption( + PluginState* plugin_state, + const uint8_t* pin, + uint8_t pin_length); + /** * @brief Gets token info iterator context * @param plugin_state application state diff --git a/applications/external/totp/services/config/constants.h b/applications/external/totp/services/config/constants.h index ba6658fb5b..1205bae073 100644 --- a/applications/external/totp/services/config/constants.h +++ b/applications/external/totp/services/config/constants.h @@ -2,9 +2,9 @@ #include -#define CONFIG_FILE_DIRECTORY_PATH EXT_PATH("authenticator") +#define CONFIG_FILE_DIRECTORY_PATH STORAGE_APP_DATA_PATH_PREFIX #define CONFIG_FILE_HEADER "Flipper TOTP plugin config file" -#define CONFIG_FILE_ACTUAL_VERSION (6) +#define CONFIG_FILE_ACTUAL_VERSION (8) #define TOTP_CONFIG_KEY_TIMEZONE "Timezone" #define TOTP_CONFIG_KEY_TOKEN_NAME "TokenName" @@ -18,4 +18,7 @@ #define TOTP_CONFIG_KEY_PINSET "PinIsSet" #define TOTP_CONFIG_KEY_NOTIFICATION_METHOD "NotificationMethod" #define TOTP_CONFIG_KEY_AUTOMATION_METHOD "AutomationMethod" +#define TOTP_CONFIG_KEY_AUTOMATION_KB_LAYOUT "AutomationKbLayout" #define TOTP_CONFIG_KEY_FONT "Font" +#define TOTP_CONFIG_KEY_CRYPTO_VERSION "CryptoVersion" +#define TOTP_CONFIG_KEY_CRYPTO_KEY_SLOT "CryptoKeySlot" diff --git a/applications/external/totp/services/config/migrations/common_migration.c b/applications/external/totp/services/config/migrations/common_migration.c index e8537da0b1..4a12cbd3a9 100644 --- a/applications/external/totp/services/config/migrations/common_migration.c +++ b/applications/external/totp/services/config/migrations/common_migration.c @@ -1,6 +1,7 @@ #include "common_migration.h" #include "../constants.h" #include "../../../types/token_info.h" +#include "../../../types/automation_kb_layout.h" #include bool totp_config_migrate_to_latest( @@ -17,6 +18,28 @@ bool totp_config_migrate_to_latest( break; } + if(flipper_format_read_string( + fff_backup_data_file, TOTP_CONFIG_KEY_CRYPTO_VERSION, temp_str)) { + flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERSION, temp_str); + } else { + uint32_t old_crypto_version = 1; + flipper_format_write_uint32( + fff_data_file, TOTP_CONFIG_KEY_CRYPTO_VERSION, &old_crypto_version, 1); + } + + flipper_format_rewind(fff_backup_data_file); + + if(flipper_format_read_string( + fff_backup_data_file, TOTP_CONFIG_KEY_CRYPTO_KEY_SLOT, temp_str)) { + flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_CRYPTO_KEY_SLOT, temp_str); + } else { + uint32_t default_old_key_slot = 2; + flipper_format_write_uint32( + fff_data_file, TOTP_CONFIG_KEY_CRYPTO_KEY_SLOT, &default_old_key_slot, 1); + } + + flipper_format_rewind(fff_backup_data_file); + if(flipper_format_read_string(fff_backup_data_file, TOTP_CONFIG_KEY_BASE_IV, temp_str)) { flipper_format_write_string(fff_data_file, TOTP_CONFIG_KEY_BASE_IV, temp_str); } @@ -68,6 +91,21 @@ bool totp_config_migrate_to_latest( flipper_format_rewind(fff_backup_data_file); + if(flipper_format_read_string( + fff_backup_data_file, TOTP_CONFIG_KEY_AUTOMATION_KB_LAYOUT, temp_str)) { + flipper_format_write_string( + fff_data_file, TOTP_CONFIG_KEY_AUTOMATION_KB_LAYOUT, temp_str); + } else { + uint32_t default_automation_kb_layout = AutomationKeyboardLayoutQWERTY; + flipper_format_write_uint32( + fff_data_file, + TOTP_CONFIG_KEY_AUTOMATION_KB_LAYOUT, + &default_automation_kb_layout, + 1); + } + + flipper_format_rewind(fff_backup_data_file); + while(true) { if(!flipper_format_read_string( fff_backup_data_file, TOTP_CONFIG_KEY_TOKEN_NAME, temp_str)) { diff --git a/applications/external/totp/services/config/token_info_iterator.c b/applications/external/totp/services/config/token_info_iterator.c index 1f4a757760..75424ef435 100644 --- a/applications/external/totp/services/config/token_info_iterator.c +++ b/applications/external/totp/services/config/token_info_iterator.c @@ -4,6 +4,7 @@ #include #include #include "../../types/common.h" +#include "../../types/crypto_settings.h" #define CONFIG_FILE_PART_FILE_PATH CONFIG_FILE_DIRECTORY_PATH "/totp.conf.part" #define STREAM_COPY_BUFFER_SIZE 128 @@ -15,7 +16,7 @@ struct TokenInfoIteratorContext { size_t last_seek_index; TokenInfo* current_token; FlipperFormat* config_file; - uint8_t* iv; + CryptoSettings* crypto_settings; Storage* storage; }; @@ -237,8 +238,10 @@ static bool return result; } -TokenInfoIteratorContext* - totp_token_info_iterator_alloc(Storage* storage, FlipperFormat* config_file, uint8_t* iv) { +TokenInfoIteratorContext* totp_token_info_iterator_alloc( + Storage* storage, + FlipperFormat* config_file, + CryptoSettings* crypto_settings) { Stream* stream = flipper_format_get_raw_stream(config_file); stream_rewind(stream); size_t tokens_count = 0; @@ -256,7 +259,7 @@ TokenInfoIteratorContext* context->total_count = tokens_count; context->current_token = token_info_alloc(); context->config_file = config_file; - context->iv = iv; + context->crypto_settings = crypto_settings; context->storage = storage; return context; } @@ -453,7 +456,7 @@ bool totp_token_info_iterator_go_to(TokenInfoIteratorContext* context, size_t to furi_string_get_cstr(temp_str), furi_string_size(temp_str), PlainTokenSecretEncodingBase32, - context->iv)) { + context->crypto_settings)) { FURI_LOG_W( LOGGING_TAG, "Token \"%s\" has plain secret", diff --git a/applications/external/totp/services/config/token_info_iterator.h b/applications/external/totp/services/config/token_info_iterator.h index 7e9a658537..ce4d8c72b2 100644 --- a/applications/external/totp/services/config/token_info_iterator.h +++ b/applications/external/totp/services/config/token_info_iterator.h @@ -28,11 +28,13 @@ enum TotpIteratorUpdateTokenResults { * @brief Initializes a new token info iterator * @param storage storage reference * @param config_file config file to use - * @param iv initialization vector (IV) to be used for encryption\decryption + * @param crypto_settings crypto settings * @return Token info iterator context */ -TokenInfoIteratorContext* - totp_token_info_iterator_alloc(Storage* storage, FlipperFormat* config_file, uint8_t* iv); +TokenInfoIteratorContext* totp_token_info_iterator_alloc( + Storage* storage, + FlipperFormat* config_file, + CryptoSettings* crypto_settings); /** * @brief Navigates iterator to the token with given index diff --git a/applications/external/totp/services/crypto/common_types.h b/applications/external/totp/services/crypto/common_types.h new file mode 100644 index 0000000000..fb8e4c83c0 --- /dev/null +++ b/applications/external/totp/services/crypto/common_types.h @@ -0,0 +1,23 @@ +#pragma once + +#include + +typedef uint8_t CryptoSeedIVResult; + +enum CryptoSeedIVResults { + + /** + * @brief IV seeding operation failed + */ + CryptoSeedIVResultFailed = 0b00, + + /** + * @brief IV seeding operation succeeded + */ + CryptoSeedIVResultFlagSuccess = 0b01, + + /** + * @brief As a part of IV seeding operation new crypto verify data has been generated + */ + CryptoSeedIVResultFlagNewCryptoVerifyData = 0b10 +}; \ No newline at end of file diff --git a/applications/external/totp/services/crypto/constants.h b/applications/external/totp/services/crypto/constants.h new file mode 100644 index 0000000000..294ae4361a --- /dev/null +++ b/applications/external/totp/services/crypto/constants.h @@ -0,0 +1,11 @@ +#pragma once + +#define CRYPTO_IV_LENGTH (16) + +// According to this explanation: https://github.com/flipperdevices/flipperzero-firmware/issues/2885#issuecomment-1646664666 +// disabling usage of any key which is "the same across all devices" +#define ACCEPTABLE_CRYPTO_KEY_SLOT_START (12) +#define ACCEPTABLE_CRYPTO_KEY_SLOT_END (100) + +#define DEFAULT_CRYPTO_KEY_SLOT ACCEPTABLE_CRYPTO_KEY_SLOT_START +#define CRYPTO_LATEST_VERSION (2) \ No newline at end of file diff --git a/applications/external/totp/services/crypto/crypto_facade.c b/applications/external/totp/services/crypto/crypto_facade.c new file mode 100644 index 0000000000..acbc09a4ee --- /dev/null +++ b/applications/external/totp/services/crypto/crypto_facade.c @@ -0,0 +1,78 @@ +#include "crypto_facade.h" +#include +#include +#include "crypto_v1.h" +#include "crypto_v2.h" +#include "constants.h" + +bool totp_crypto_check_key_slot(uint8_t key_slot) { + uint8_t empty_iv[CRYPTO_IV_LENGTH] = {0}; + if(key_slot < ACCEPTABLE_CRYPTO_KEY_SLOT_START || key_slot > ACCEPTABLE_CRYPTO_KEY_SLOT_END) { + return false; + } + + return furi_hal_crypto_verify_key(key_slot) && + furi_hal_crypto_store_load_key(key_slot, empty_iv) && + furi_hal_crypto_store_unload_key(key_slot); +} + +uint8_t* totp_crypto_encrypt( + const uint8_t* plain_data, + const size_t plain_data_length, + const CryptoSettings* crypto_settings, + size_t* encrypted_data_length) { + if(crypto_settings->crypto_version == 1) { + return totp_crypto_encrypt_v1( + plain_data, plain_data_length, crypto_settings, encrypted_data_length); + } + + if(crypto_settings->crypto_version == 2) { + return totp_crypto_encrypt_v2( + plain_data, plain_data_length, crypto_settings, encrypted_data_length); + } + + furi_crash("Unsupported crypto version"); +} + +uint8_t* totp_crypto_decrypt( + const uint8_t* encrypted_data, + const size_t encrypted_data_length, + const CryptoSettings* crypto_settings, + size_t* decrypted_data_length) { + if(crypto_settings->crypto_version == 1) { + return totp_crypto_decrypt_v1( + encrypted_data, encrypted_data_length, crypto_settings, decrypted_data_length); + } + + if(crypto_settings->crypto_version == 2) { + return totp_crypto_decrypt_v2( + encrypted_data, encrypted_data_length, crypto_settings, decrypted_data_length); + } + + furi_crash("Unsupported crypto version"); +} + +CryptoSeedIVResult + totp_crypto_seed_iv(CryptoSettings* crypto_settings, const uint8_t* pin, uint8_t pin_length) { + if(crypto_settings->crypto_version == 1) { + return totp_crypto_seed_iv_v1(crypto_settings, pin, pin_length); + } + + if(crypto_settings->crypto_version == 2) { + return totp_crypto_seed_iv_v2(crypto_settings, pin, pin_length); + } + + furi_crash("Unsupported crypto version"); +} + +bool totp_crypto_verify_key(const CryptoSettings* crypto_settings) { + if(crypto_settings->crypto_version == 1) { + return totp_crypto_verify_key_v1(crypto_settings); + } + + if(crypto_settings->crypto_version == 2) { + return totp_crypto_verify_key_v2(crypto_settings); + } + + furi_crash("Unsupported crypto version"); +} \ No newline at end of file diff --git a/applications/external/totp/services/crypto/crypto.h b/applications/external/totp/services/crypto/crypto_facade.h similarity index 58% rename from applications/external/totp/services/crypto/crypto.h rename to applications/external/totp/services/crypto/crypto_facade.h index ab27191a8a..bbcbf7c007 100644 --- a/applications/external/totp/services/crypto/crypto.h +++ b/applications/external/totp/services/crypto/crypto_facade.h @@ -1,68 +1,59 @@ #pragma once -#include "../../types/plugin_state.h" +#include +#include +#include +#include "../../types/crypto_settings.h" +#include "common_types.h" -typedef uint8_t CryptoSeedIVResult; - -enum CryptoSeedIVResults { - - /** - * @brief IV seeding operation failed - */ - CryptoSeedIVResultFailed = 0b00, - - /** - * @brief IV seeding operation succeeded - */ - CryptoSeedIVResultFlagSuccess = 0b01, - - /** - * @brief As a part of IV seeding operation new crypto verify data has been generated - */ - CryptoSeedIVResultFlagNewCryptoVerifyData = 0b10 -}; +/** + * @brief Checks whether key slot can be used for encryption purposes + * @param key_slot key slot index + * @return \c true if key slot can be used for encryption; \c false otherwise + */ +bool totp_crypto_check_key_slot(uint8_t key_slot); /** * @brief Encrypts plain data using built-in certificate and given initialization vector (IV) * @param plain_data plain data to be encrypted * @param plain_data_length plain data length - * @param iv initialization vector (IV) to be used to encrypt plain data + * @param crypto_settings crypto settings * @param[out] encrypted_data_length encrypted data length * @return Encrypted data */ uint8_t* totp_crypto_encrypt( const uint8_t* plain_data, const size_t plain_data_length, - const uint8_t* iv, + const CryptoSettings* crypto_settings, size_t* encrypted_data_length); /** * @brief Decrypts encrypted data using built-in certificate and given initialization vector (IV) * @param encrypted_data encrypted data to be decrypted * @param encrypted_data_length encrypted data length - * @param iv initialization vector (IV) to be used to encrypt plain data + * @param crypto_settings crypto settings * @param[out] decrypted_data_length decrypted data length * @return Decrypted data */ uint8_t* totp_crypto_decrypt( const uint8_t* encrypted_data, const size_t encrypted_data_length, - const uint8_t* iv, + const CryptoSettings* crypto_settings, size_t* decrypted_data_length); /** * @brief Seed initialization vector (IV) using user's PIN - * @param plugin_state application state + * @param crypto_settings crypto settings * @param pin user's PIN * @param pin_length user's PIN length * @return Results of seeding IV */ CryptoSeedIVResult - totp_crypto_seed_iv(PluginState* plugin_state, const uint8_t* pin, uint8_t pin_length); + totp_crypto_seed_iv(CryptoSettings* crypto_settings, const uint8_t* pin, uint8_t pin_length); /** * @brief Verifies whether cryptographic information (certificate + IV) is valid and can be used for encryption and decryption - * @param plugin_state application state + * @param crypto_settings crypto settings * @return \c true if cryptographic information is valid; \c false otherwise */ -bool totp_crypto_verify_key(const PluginState* plugin_state); \ No newline at end of file +bool totp_crypto_verify_key(const CryptoSettings* crypto_settings); diff --git a/applications/external/totp/services/crypto/crypto.c b/applications/external/totp/services/crypto/crypto_v1.c similarity index 66% rename from applications/external/totp/services/crypto/crypto.c rename to applications/external/totp/services/crypto/crypto_v1.c index 95ddc32103..d637599f56 100644 --- a/applications/external/totp/services/crypto/crypto.c +++ b/applications/external/totp/services/crypto/crypto_v1.c @@ -1,4 +1,6 @@ -#include "crypto.h" +#include "crypto_v1.h" +#include +#include #include #include #include @@ -8,13 +10,14 @@ #define CRYPTO_KEY_SLOT (2) #define CRYPTO_VERIFY_KEY_LENGTH (16) #define CRYPTO_ALIGNMENT_FACTOR (16) +#define TOTP_IV_SIZE (16) static const char* CRYPTO_VERIFY_KEY = "FFF_Crypto_pass"; -uint8_t* totp_crypto_encrypt( +uint8_t* totp_crypto_encrypt_v1( const uint8_t* plain_data, const size_t plain_data_length, - const uint8_t* iv, + const CryptoSettings* crypto_settings, size_t* encrypted_data_length) { uint8_t* encrypted_data; size_t remain = plain_data_length % CRYPTO_ALIGNMENT_FACTOR; @@ -29,7 +32,7 @@ uint8_t* totp_crypto_encrypt( furi_check(encrypted_data != NULL); *encrypted_data_length = plain_data_aligned_length; - furi_hal_crypto_store_load_key(CRYPTO_KEY_SLOT, iv); + furi_hal_crypto_store_load_key(CRYPTO_KEY_SLOT, crypto_settings->iv); furi_hal_crypto_encrypt(plain_data_aligned, encrypted_data, plain_data_aligned_length); furi_hal_crypto_store_unload_key(CRYPTO_KEY_SLOT); @@ -40,7 +43,7 @@ uint8_t* totp_crypto_encrypt( furi_check(encrypted_data != NULL); *encrypted_data_length = plain_data_length; - furi_hal_crypto_store_load_key(CRYPTO_KEY_SLOT, iv); + furi_hal_crypto_store_load_key(CRYPTO_KEY_SLOT, crypto_settings->iv); furi_hal_crypto_encrypt(plain_data, encrypted_data, plain_data_length); furi_hal_crypto_store_unload_key(CRYPTO_KEY_SLOT); } @@ -48,29 +51,31 @@ uint8_t* totp_crypto_encrypt( return encrypted_data; } -uint8_t* totp_crypto_decrypt( +uint8_t* totp_crypto_decrypt_v1( const uint8_t* encrypted_data, const size_t encrypted_data_length, - const uint8_t* iv, + const CryptoSettings* crypto_settings, size_t* decrypted_data_length) { *decrypted_data_length = encrypted_data_length; uint8_t* decrypted_data = malloc(*decrypted_data_length); furi_check(decrypted_data != NULL); - furi_hal_crypto_store_load_key(CRYPTO_KEY_SLOT, iv); + furi_hal_crypto_store_load_key(CRYPTO_KEY_SLOT, crypto_settings->iv); furi_hal_crypto_decrypt(encrypted_data, decrypted_data, encrypted_data_length); furi_hal_crypto_store_unload_key(CRYPTO_KEY_SLOT); return decrypted_data; } -CryptoSeedIVResult - totp_crypto_seed_iv(PluginState* plugin_state, const uint8_t* pin, uint8_t pin_length) { +CryptoSeedIVResult totp_crypto_seed_iv_v1( + CryptoSettings* crypto_settings, + const uint8_t* pin, + uint8_t pin_length) { CryptoSeedIVResult result; - if(plugin_state->crypto_verify_data == NULL) { + if(crypto_settings->crypto_verify_data == NULL) { FURI_LOG_I(LOGGING_TAG, "Generating new IV"); - furi_hal_random_fill_buf(&plugin_state->base_iv[0], TOTP_IV_SIZE); + furi_hal_random_fill_buf(&crypto_settings->base_iv[0], TOTP_IV_SIZE); } - memcpy(&plugin_state->iv[0], &plugin_state->base_iv[0], TOTP_IV_SIZE); + memcpy(&crypto_settings->iv[0], &crypto_settings->base_iv[0], TOTP_IV_SIZE); if(pin != NULL && pin_length > 0) { uint8_t max_i; if(pin_length > TOTP_IV_SIZE) { @@ -80,7 +85,7 @@ CryptoSeedIVResult } for(uint8_t i = 0; i < max_i; i++) { - plugin_state->iv[i] = plugin_state->iv[i] ^ (uint8_t)(pin[i] * (i + 1)); + crypto_settings->iv[i] = crypto_settings->iv[i] ^ (uint8_t)(pin[i] * (i + 1)); } } else { uint8_t max_i; @@ -93,24 +98,24 @@ CryptoSeedIVResult const uint8_t* uid = (const uint8_t*)UID64_BASE; //-V566 for(uint8_t i = 0; i < max_i; i++) { - plugin_state->iv[i] = plugin_state->iv[i] ^ uid[i]; + crypto_settings->iv[i] = crypto_settings->iv[i] ^ uid[i]; } } result = CryptoSeedIVResultFlagSuccess; - if(plugin_state->crypto_verify_data == NULL) { + if(crypto_settings->crypto_verify_data == NULL) { FURI_LOG_I(LOGGING_TAG, "Generating crypto verify data"); - plugin_state->crypto_verify_data = malloc(CRYPTO_VERIFY_KEY_LENGTH); - furi_check(plugin_state->crypto_verify_data != NULL); - plugin_state->crypto_verify_data_length = CRYPTO_VERIFY_KEY_LENGTH; + crypto_settings->crypto_verify_data = malloc(CRYPTO_VERIFY_KEY_LENGTH); + furi_check(crypto_settings->crypto_verify_data != NULL); + crypto_settings->crypto_verify_data_length = CRYPTO_VERIFY_KEY_LENGTH; - plugin_state->crypto_verify_data = totp_crypto_encrypt( + crypto_settings->crypto_verify_data = totp_crypto_encrypt_v1( (const uint8_t*)CRYPTO_VERIFY_KEY, CRYPTO_VERIFY_KEY_LENGTH, - &plugin_state->iv[0], - &plugin_state->crypto_verify_data_length); + crypto_settings, + &crypto_settings->crypto_verify_data_length); - plugin_state->pin_set = pin != NULL && pin_length > 0; + crypto_settings->pin_required = pin != NULL && pin_length > 0; result |= CryptoSeedIVResultFlagNewCryptoVerifyData; } @@ -118,12 +123,12 @@ CryptoSeedIVResult return result; } -bool totp_crypto_verify_key(const PluginState* plugin_state) { +bool totp_crypto_verify_key_v1(const CryptoSettings* crypto_settings) { size_t decrypted_key_length; - uint8_t* decrypted_key = totp_crypto_decrypt( - plugin_state->crypto_verify_data, - plugin_state->crypto_verify_data_length, - &plugin_state->iv[0], + uint8_t* decrypted_key = totp_crypto_decrypt_v1( + crypto_settings->crypto_verify_data, + crypto_settings->crypto_verify_data_length, + crypto_settings, &decrypted_key_length); bool key_valid = true; diff --git a/applications/external/totp/services/crypto/crypto_v1.h b/applications/external/totp/services/crypto/crypto_v1.h new file mode 100644 index 0000000000..80e850196f --- /dev/null +++ b/applications/external/totp/services/crypto/crypto_v1.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include +#include +#include "../../types/crypto_settings.h" +#include "common_types.h" + +/** + * @brief Encrypts plain data using built-in certificate and given initialization vector (IV) + * @param plain_data plain data to be encrypted + * @param plain_data_length plain data length + * @param crypto_settings crypto settings + * @param[out] encrypted_data_length encrypted data length + * @return Encrypted data + */ +uint8_t* totp_crypto_encrypt_v1( + const uint8_t* plain_data, + const size_t plain_data_length, + const CryptoSettings* crypto_settings, + size_t* encrypted_data_length); + +/** + * @brief Decrypts encrypted data using built-in certificate and given initialization vector (IV) + * @param encrypted_data encrypted data to be decrypted + * @param encrypted_data_length encrypted data length + * @param crypto_settings crypto settings + * @param[out] decrypted_data_length decrypted data length + * @return Decrypted data + */ +uint8_t* totp_crypto_decrypt_v1( + const uint8_t* encrypted_data, + const size_t encrypted_data_length, + const CryptoSettings* crypto_settings, + size_t* decrypted_data_length); + +/** + * @brief Seed initialization vector (IV) using user's PIN + * @param crypto_settings crypto settings + * @param pin user's PIN + * @param pin_length user's PIN length + * @return Results of seeding IV + */ +CryptoSeedIVResult + totp_crypto_seed_iv_v1(CryptoSettings* crypto_settings, const uint8_t* pin, uint8_t pin_length); + +/** + * @brief Verifies whether cryptographic information (certificate + IV) is valid and can be used for encryption and decryption + * @param crypto_settings crypto settings + * @return \c true if cryptographic information is valid; \c false otherwise + */ +bool totp_crypto_verify_key_v1(const CryptoSettings* crypto_settings); \ No newline at end of file diff --git a/applications/external/totp/services/crypto/crypto_v2.c b/applications/external/totp/services/crypto/crypto_v2.c new file mode 100644 index 0000000000..897a7fd32e --- /dev/null +++ b/applications/external/totp/services/crypto/crypto_v2.c @@ -0,0 +1,184 @@ +#include "crypto_v2.h" +#include +#include +#include +#include +#include +#include "../../types/common.h" +#include "../hmac/hmac_sha512.h" +#include "memset_s.h" +#include "constants.h" + +#define CRYPTO_ALIGNMENT_FACTOR (16) + +static const uint8_t* get_device_uid() { + return (const uint8_t*)UID64_BASE; //-V566 +} + +static uint8_t get_device_uid_length() { + return furi_hal_version_uid_size(); +} + +static const uint8_t* get_crypto_verify_key() { + return get_device_uid(); +} + +static uint8_t get_crypto_verify_key_length() { + return get_device_uid_length(); +} + +uint8_t* totp_crypto_encrypt_v2( + const uint8_t* plain_data, + const size_t plain_data_length, + const CryptoSettings* crypto_settings, + size_t* encrypted_data_length) { + uint8_t* encrypted_data; + size_t remain = plain_data_length % CRYPTO_ALIGNMENT_FACTOR; + if(remain) { + size_t plain_data_aligned_length = plain_data_length - remain + CRYPTO_ALIGNMENT_FACTOR; + uint8_t* plain_data_aligned = malloc(plain_data_aligned_length); + furi_check(plain_data_aligned != NULL); + memset(plain_data_aligned, 0, plain_data_aligned_length); + memcpy(plain_data_aligned, plain_data, plain_data_length); + + encrypted_data = malloc(plain_data_aligned_length); + furi_check(encrypted_data != NULL); + *encrypted_data_length = plain_data_aligned_length; + + furi_check( + furi_hal_crypto_store_load_key(crypto_settings->crypto_key_slot, crypto_settings->iv), + "Encryption failed: store_load_key"); + furi_check( + furi_hal_crypto_encrypt(plain_data_aligned, encrypted_data, plain_data_aligned_length), + "Encryption failed: encrypt"); + furi_check( + furi_hal_crypto_store_unload_key(crypto_settings->crypto_key_slot), + "Encryption failed: store_unload_key"); + + memset_s(plain_data_aligned, plain_data_aligned_length, 0, plain_data_aligned_length); + free(plain_data_aligned); + } else { + encrypted_data = malloc(plain_data_length); + furi_check(encrypted_data != NULL); + *encrypted_data_length = plain_data_length; + + furi_check( + furi_hal_crypto_store_load_key(crypto_settings->crypto_key_slot, crypto_settings->iv), + "Encryption failed: store_load_key"); + furi_check( + furi_hal_crypto_encrypt(plain_data, encrypted_data, plain_data_length), + "Encryption failed: encrypt"); + furi_check( + furi_hal_crypto_store_unload_key(crypto_settings->crypto_key_slot), + "Encryption failed: store_unload_key"); + } + + return encrypted_data; +} + +uint8_t* totp_crypto_decrypt_v2( + const uint8_t* encrypted_data, + const size_t encrypted_data_length, + const CryptoSettings* crypto_settings, + size_t* decrypted_data_length) { + *decrypted_data_length = encrypted_data_length; + uint8_t* decrypted_data = malloc(*decrypted_data_length); + furi_check(decrypted_data != NULL); + furi_check( + furi_hal_crypto_store_load_key(crypto_settings->crypto_key_slot, crypto_settings->iv), + "Decryption failed: store_load_key"); + furi_check( + furi_hal_crypto_decrypt(encrypted_data, decrypted_data, encrypted_data_length), + "Decryption failed: decrypt"); + furi_check( + furi_hal_crypto_store_unload_key(crypto_settings->crypto_key_slot), + "Decryption failed: store_unload_key"); + return decrypted_data; +} + +CryptoSeedIVResult totp_crypto_seed_iv_v2( + CryptoSettings* crypto_settings, + const uint8_t* pin, + uint8_t pin_length) { + CryptoSeedIVResult result; + if(crypto_settings->crypto_verify_data == NULL) { + FURI_LOG_I(LOGGING_TAG, "Generating new IV"); + furi_hal_random_fill_buf(&crypto_settings->base_iv[0], CRYPTO_IV_LENGTH); + } + + memcpy(&crypto_settings->iv[0], &crypto_settings->base_iv[0], CRYPTO_IV_LENGTH); + + const uint8_t* device_uid = get_device_uid(); + uint8_t device_uid_length = get_device_uid_length(); + + uint8_t hmac_key_length = device_uid_length; + if(pin != NULL && pin_length > 0) { + hmac_key_length += pin_length; + } + + uint8_t* hmac_key = malloc(hmac_key_length); + furi_check(hmac_key != NULL); + + memcpy(hmac_key, device_uid, device_uid_length); + + if(pin != NULL && pin_length > 0) { + memcpy(hmac_key + device_uid_length, pin, pin_length); + } + + uint8_t hmac[HMAC_SHA512_RESULT_SIZE] = {0}; + int hmac_result_code = hmac_sha512( + hmac_key, hmac_key_length, &crypto_settings->base_iv[0], CRYPTO_IV_LENGTH, &hmac[0]); + + memset_s(hmac_key, hmac_key_length, 0, hmac_key_length); + free(hmac_key); + + if(hmac_result_code == 0) { + uint8_t offset = + hmac[HMAC_SHA512_RESULT_SIZE - 1] % (HMAC_SHA512_RESULT_SIZE - CRYPTO_IV_LENGTH - 1); + memcpy(&crypto_settings->iv[0], &hmac[offset], CRYPTO_IV_LENGTH); + + result = CryptoSeedIVResultFlagSuccess; + if(crypto_settings->crypto_verify_data == NULL) { + const uint8_t* crypto_vkey = get_crypto_verify_key(); + uint8_t crypto_vkey_length = get_crypto_verify_key_length(); + FURI_LOG_I(LOGGING_TAG, "Generating crypto verify data"); + crypto_settings->crypto_verify_data = malloc(crypto_vkey_length); + furi_check(crypto_settings->crypto_verify_data != NULL); + crypto_settings->crypto_verify_data_length = crypto_vkey_length; + + crypto_settings->crypto_verify_data = totp_crypto_encrypt_v2( + crypto_vkey, + crypto_vkey_length, + crypto_settings, + &crypto_settings->crypto_verify_data_length); + + crypto_settings->pin_required = pin != NULL && pin_length > 0; + + result |= CryptoSeedIVResultFlagNewCryptoVerifyData; + } + } else { + result = CryptoSeedIVResultFailed; + } + + return result; +} + +bool totp_crypto_verify_key_v2(const CryptoSettings* crypto_settings) { + size_t decrypted_key_length; + uint8_t* decrypted_key = totp_crypto_decrypt_v2( + crypto_settings->crypto_verify_data, + crypto_settings->crypto_verify_data_length, + crypto_settings, + &decrypted_key_length); + + const uint8_t* crypto_vkey = get_crypto_verify_key(); + uint8_t crypto_vkey_length = get_crypto_verify_key_length(); + bool key_valid = true; + for(uint8_t i = 0; i < crypto_vkey_length && key_valid; i++) { + if(decrypted_key[i] != crypto_vkey[i]) key_valid = false; + } + + free(decrypted_key); + + return key_valid; +} \ No newline at end of file diff --git a/applications/external/totp/services/crypto/crypto_v2.h b/applications/external/totp/services/crypto/crypto_v2.h new file mode 100644 index 0000000000..1395e7046f --- /dev/null +++ b/applications/external/totp/services/crypto/crypto_v2.h @@ -0,0 +1,52 @@ +#pragma once + +#include +#include +#include +#include "../../types/crypto_settings.h" +#include "common_types.h" + +/** + * @brief Encrypts plain data using built-in certificate and given initialization vector (IV) + * @param plain_data plain data to be encrypted + * @param plain_data_length plain data length + * @param crypto_settings crypto settings + * @param[out] encrypted_data_length encrypted data length + * @return Encrypted data + */ +uint8_t* totp_crypto_encrypt_v2( + const uint8_t* plain_data, + const size_t plain_data_length, + const CryptoSettings* crypto_settings, + size_t* encrypted_data_length); + +/** + * @brief Decrypts encrypted data using built-in certificate and given initialization vector (IV) + * @param encrypted_data encrypted data to be decrypted + * @param encrypted_data_length encrypted data length + * @param crypto_settings crypto settings + * @param[out] decrypted_data_length decrypted data length + * @return Decrypted data + */ +uint8_t* totp_crypto_decrypt_v2( + const uint8_t* encrypted_data, + const size_t encrypted_data_length, + const CryptoSettings* crypto_settings, + size_t* decrypted_data_length); + +/** + * @brief Seed initialization vector (IV) using user's PIN + * @param crypto_settings crypto settings + * @param pin user's PIN + * @param pin_length user's PIN length + * @return Results of seeding IV + */ +CryptoSeedIVResult + totp_crypto_seed_iv_v2(CryptoSettings* crypto_settings, const uint8_t* pin, uint8_t pin_length); + +/** + * @brief Verifies whether cryptographic information (certificate + IV) is valid and can be used for encryption and decryption + * @param crypto_settings crypto settings + * @return \c true if cryptographic information is valid; \c false otherwise + */ +bool totp_crypto_verify_key_v2(const CryptoSettings* crypto_settings); \ No newline at end of file diff --git a/applications/external/totp/totp_app.c b/applications/external/totp/totp_app.c index 301100b589..251d7bb5ba 100644 --- a/applications/external/totp/totp_app.c +++ b/applications/external/totp/totp_app.c @@ -15,60 +15,53 @@ #include "ui/scene_director.h" #include "ui/constants.h" #include "ui/common_dialogs.h" -#include "services/crypto/crypto.h" +#include "services/crypto/crypto_facade.h" #include "cli/cli.h" +#include "version.h" -static void render_callback(Canvas* const canvas, void* ctx) { +struct TotpRenderCallbackContext { + FuriMutex* mutex; + PluginState* plugin_state; +}; + +static void render_callback(Canvas* const canvas, void* const ctx) { furi_assert(ctx); - PluginState* plugin_state = ctx; - if(furi_mutex_acquire(plugin_state->mutex, 25) == FuriStatusOk) { - totp_scene_director_render(canvas, plugin_state); - furi_mutex_release(plugin_state->mutex); + const struct TotpRenderCallbackContext* context = ctx; + if(furi_mutex_acquire(context->mutex, 25) == FuriStatusOk) { + totp_scene_director_render(canvas, context->plugin_state); + furi_mutex_release(context->mutex); } } -static void input_callback(InputEvent* input_event, FuriMessageQueue* event_queue) { - furi_assert(event_queue); - +static void input_callback(InputEvent* const input_event, void* const ctx) { + furi_assert(ctx); + FuriMessageQueue* event_queue = ctx; PluginEvent event = {.type = EventTypeKey, .input = *input_event}; furi_message_queue_put(event_queue, &event, FuriWaitForever); } -static bool totp_activate_initial_scene(PluginState* const plugin_state) { - if(plugin_state->crypto_verify_data == NULL) { - DialogMessage* message = dialog_message_alloc(); - dialog_message_set_buttons(message, "No", NULL, "Yes"); - dialog_message_set_text( - message, - "Would you like to setup PIN?", - SCREEN_WIDTH_CENTER, - SCREEN_HEIGHT_CENTER, - AlignCenter, - AlignCenter); - DialogMessageButton dialog_result = - dialog_message_show(plugin_state->dialogs_app, message); - dialog_message_free(message); - if(dialog_result == DialogMessageButtonRight) { - totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication); - } else { - CryptoSeedIVResult seed_result = totp_crypto_seed_iv(plugin_state, NULL, 0); - if(seed_result & CryptoSeedIVResultFlagSuccess && - seed_result & CryptoSeedIVResultFlagNewCryptoVerifyData) { - if(!totp_config_file_update_crypto_signatures(plugin_state)) { - totp_dialogs_config_loading_error(plugin_state); - return false; - } - } else if(seed_result == CryptoSeedIVResultFailed) { - totp_dialogs_config_loading_error(plugin_state); - return false; - } +static bool first_run_init(PluginState* const plugin_state) { + DialogMessage* message = dialog_message_alloc(); + dialog_message_set_buttons(message, "No", NULL, "Yes"); + dialog_message_set_text( + message, + "Would you like to setup PIN?", + SCREEN_WIDTH_CENTER, + SCREEN_HEIGHT_CENTER, + AlignCenter, + AlignCenter); + DialogMessageButton dialog_result = dialog_message_show(plugin_state->dialogs_app, message); + dialog_message_free(message); + if(!totp_crypto_check_key_slot(plugin_state->crypto_settings.crypto_key_slot)) { + totp_dialogs_config_loading_error(plugin_state); + return false; + } - totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken); - } - } else if(plugin_state->pin_set) { + if(dialog_result == DialogMessageButtonRight) { totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication); } else { - CryptoSeedIVResult seed_result = totp_crypto_seed_iv(plugin_state, NULL, 0); + CryptoSeedIVResult seed_result = + totp_crypto_seed_iv(&plugin_state->crypto_settings, NULL, 0); if(seed_result & CryptoSeedIVResultFlagSuccess && seed_result & CryptoSeedIVResultFlagNewCryptoVerifyData) { if(!totp_config_file_update_crypto_signatures(plugin_state)) { @@ -80,23 +73,65 @@ static bool totp_activate_initial_scene(PluginState* const plugin_state) { return false; } - if(totp_crypto_verify_key(plugin_state)) { - totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken); - } else { - FURI_LOG_E( - LOGGING_TAG, - "Digital signature verification failed. Looks like conf file was created on another flipper and can't be used on any other"); - DialogMessage* message = dialog_message_alloc(); - dialog_message_set_buttons(message, "Exit", NULL, NULL); - dialog_message_set_text( - message, - "Digital signature verification failed", - SCREEN_WIDTH_CENTER, - SCREEN_HEIGHT_CENTER, - AlignCenter, - AlignCenter); - dialog_message_show(plugin_state->dialogs_app, message); - dialog_message_free(message); + totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken); + } + + return true; +} + +static bool pinless_activation(PluginState* const plugin_state) { + CryptoSeedIVResult seed_result = totp_crypto_seed_iv(&plugin_state->crypto_settings, NULL, 0); + if(seed_result & CryptoSeedIVResultFlagSuccess && + seed_result & CryptoSeedIVResultFlagNewCryptoVerifyData) { + if(!totp_config_file_update_crypto_signatures(plugin_state)) { + totp_dialogs_config_loading_error(plugin_state); + return false; + } + } else if(seed_result == CryptoSeedIVResultFailed) { + totp_dialogs_config_loading_error(plugin_state); + return false; + } + + if(totp_crypto_verify_key(&plugin_state->crypto_settings)) { + totp_config_file_ensure_latest_encryption(plugin_state, NULL, 0); + totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken); + } else { + FURI_LOG_E( + LOGGING_TAG, + "Digital signature verification failed. Looks like conf file was created on another device and can't be used on any other"); + DialogMessage* message = dialog_message_alloc(); + dialog_message_set_buttons(message, "Exit", NULL, NULL); + dialog_message_set_text( + message, + "Digital signature verification failed", + SCREEN_WIDTH_CENTER, + SCREEN_HEIGHT_CENTER, + AlignCenter, + AlignCenter); + dialog_message_show(plugin_state->dialogs_app, message); + dialog_message_free(message); + return false; + } + + return true; +} + +static bool pin_activation(PluginState* const plugin_state) { + totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication); + return true; +} + +static bool totp_activate_initial_scene(PluginState* const plugin_state) { + if(plugin_state->crypto_settings.crypto_verify_data == NULL) { + if(!first_run_init(plugin_state)) { + return false; + } + } else if(plugin_state->crypto_settings.pin_required) { + if(!pin_activation(plugin_state)) { + return false; + } + } else { + if(!pinless_activation(plugin_state)) { return false; } } @@ -109,6 +144,7 @@ static bool on_user_idle(void* context) { if(plugin_state->current_scene != TotpSceneAuthentication && plugin_state->current_scene != TotpSceneStandby) { totp_scene_director_activate_scene(plugin_state, TotpSceneAuthentication); + totp_scene_director_force_redraw(plugin_state); return true; } @@ -117,18 +153,17 @@ static bool on_user_idle(void* context) { static bool totp_plugin_state_init(PluginState* const plugin_state) { plugin_state->gui = furi_record_open(RECORD_GUI); - plugin_state->notification_app = furi_record_open(RECORD_NOTIFICATION); plugin_state->dialogs_app = furi_record_open(RECORD_DIALOGS); - memset(&plugin_state->iv[0], 0, TOTP_IV_SIZE); + memset(&plugin_state->crypto_settings.iv[0], 0, CRYPTO_IV_LENGTH); if(!totp_config_file_load(plugin_state)) { totp_dialogs_config_loading_error(plugin_state); return false; } - plugin_state->mutex = furi_mutex_alloc(FuriMutexTypeNormal); + plugin_state->event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED if(plugin_state->automation_method & AutomationMethodBadBt) { plugin_state->bt_type_code_worker_context = totp_bt_type_code_worker_init(); } else { @@ -136,7 +171,7 @@ static bool totp_plugin_state_init(PluginState* const plugin_state) { } #endif - if(plugin_state->pin_set) { + if(plugin_state->crypto_settings.pin_required) { plugin_state->idle_timeout_context = idle_timeout_alloc(TOTP_AUTO_LOCK_IDLE_TIMEOUT_SEC, &on_user_idle, plugin_state); idle_timeout_start(plugin_state->idle_timeout_context); @@ -154,28 +189,35 @@ static void totp_plugin_state_free(PluginState* plugin_state) { } furi_record_close(RECORD_GUI); - furi_record_close(RECORD_NOTIFICATION); furi_record_close(RECORD_DIALOGS); totp_config_file_close(plugin_state); - if(plugin_state->crypto_verify_data != NULL) { - free(plugin_state->crypto_verify_data); + if(plugin_state->crypto_settings.crypto_verify_data != NULL) { + free(plugin_state->crypto_settings.crypto_verify_data); } -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED if(plugin_state->bt_type_code_worker_context != NULL) { totp_bt_type_code_worker_free(plugin_state->bt_type_code_worker_context); plugin_state->bt_type_code_worker_context = NULL; } #endif - furi_mutex_free(plugin_state->mutex); + if(plugin_state->event_queue != NULL) { + furi_message_queue_free(plugin_state->event_queue); + } + free(plugin_state); } int32_t totp_app() { - FuriMessageQueue* event_queue = furi_message_queue_alloc(8, sizeof(PluginEvent)); + FURI_LOG_I( + LOGGING_TAG, + "App version: %" PRIu8 ".%" PRIu8 ".%" PRIu8, + TOTP_APP_VERSION_MAJOR, + TOTP_APP_VERSION_MINOR, + TOTP_APP_VERSION_PATCH); PluginState* plugin_state = malloc(sizeof(PluginState)); furi_check(plugin_state != NULL); @@ -185,7 +227,7 @@ int32_t totp_app() { return 254; } - TotpCliContext* cli_context = totp_cli_register_command_handler(plugin_state, event_queue); + TotpCliContext* cli_context = totp_cli_register_command_handler(plugin_state); if(!totp_activate_initial_scene(plugin_state)) { FURI_LOG_E(LOGGING_TAG, "An error ocurred during activating initial scene\r\n"); @@ -196,10 +238,14 @@ int32_t totp_app() { // Affecting dolphin level dolphin_deed(DolphinDeedPluginStart); + FuriMutex* main_loop_mutex = furi_mutex_alloc(FuriMutexTypeNormal); + struct TotpRenderCallbackContext render_context = { + .plugin_state = plugin_state, .mutex = main_loop_mutex}; + // Set system callbacks ViewPort* view_port = view_port_alloc(); - view_port_draw_callback_set(view_port, render_callback, plugin_state); - view_port_input_callback_set(view_port, input_callback, event_queue); + view_port_draw_callback_set(view_port, render_callback, &render_context); + view_port_input_callback_set(view_port, input_callback, plugin_state->event_queue); // Open GUI and register view_port gui_add_view_port(plugin_state->gui, view_port, GuiLayerFullscreen); @@ -207,24 +253,24 @@ int32_t totp_app() { PluginEvent event; bool processing = true; while(processing) { - FuriStatus event_status = furi_message_queue_get(event_queue, &event, 100); - - if(furi_mutex_acquire(plugin_state->mutex, FuriWaitForever) == FuriStatusOk) { - if(event_status == FuriStatusOk) { + if(furi_message_queue_get(plugin_state->event_queue, &event, FuriWaitForever) == + FuriStatusOk) { + if(event.type == EventForceCloseApp) { + processing = false; + } else if(event.type == EventForceRedraw) { + processing = true; //-V1048 + } else if(furi_mutex_acquire(main_loop_mutex, FuriWaitForever) == FuriStatusOk) { if(event.type == EventTypeKey && plugin_state->idle_timeout_context != NULL) { idle_timeout_report_activity(plugin_state->idle_timeout_context); } - if(event.type == EventForceCloseApp) { - processing = false; - } else { - processing = totp_scene_director_handle_event(&event, plugin_state); - } - } + processing = totp_scene_director_handle_event(&event, plugin_state); - view_port_update(view_port); - furi_mutex_release(plugin_state->mutex); + furi_mutex_release(main_loop_mutex); + } } + + view_port_update(view_port); } totp_cli_unregister_command_handler(cli_context); @@ -233,7 +279,7 @@ int32_t totp_app() { view_port_enabled_set(view_port, false); gui_remove_view_port(plugin_state->gui, view_port); view_port_free(view_port); - furi_message_queue_free(event_queue); + furi_mutex_free(main_loop_mutex); totp_plugin_state_free(plugin_state); return 0; } diff --git a/applications/external/totp/types/automation_kb_layout.h b/applications/external/totp/types/automation_kb_layout.h new file mode 100644 index 0000000000..9c23e91ab4 --- /dev/null +++ b/applications/external/totp/types/automation_kb_layout.h @@ -0,0 +1,8 @@ +#pragma once + +typedef uint8_t AutomationKeyboardLayout; + +enum AutomationKeyboardLayouts { + AutomationKeyboardLayoutQWERTY = 0, + AutomationKeyboardLayoutAZERTY = 1 +}; \ No newline at end of file diff --git a/applications/external/totp/types/automation_method.h b/applications/external/totp/types/automation_method.h index b51e59e03c..89e39e18e2 100644 --- a/applications/external/totp/types/automation_method.h +++ b/applications/external/totp/types/automation_method.h @@ -7,7 +7,7 @@ typedef uint8_t AutomationMethod; enum AutomationMethods { AutomationMethodNone = 0b00, AutomationMethodBadUsb = 0b01, -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED AutomationMethodBadBt = 0b10, #endif }; diff --git a/applications/external/totp/types/crypto_settings.h b/applications/external/totp/types/crypto_settings.h new file mode 100644 index 0000000000..8b970fd6d8 --- /dev/null +++ b/applications/external/totp/types/crypto_settings.h @@ -0,0 +1,41 @@ +#pragma once + +#include +#include "../services/crypto/constants.h" + +typedef struct { + /** + * @brief Crypto key slot to be used + */ + uint8_t crypto_key_slot; + + /** + * @brief Crypto algorithms version to be used + */ + uint8_t crypto_version; + + /** + * @brief Initialization vector (IV) to be used for encryption\decryption + */ + uint8_t iv[CRYPTO_IV_LENGTH]; + + /** + * @brief Basic randomly-generated initialization vector (IV) + */ + uint8_t base_iv[CRYPTO_IV_LENGTH]; + + /** + * @brief Encrypted well-known data + */ + uint8_t* crypto_verify_data; + + /** + * @brief Encrypted well-known data length + */ + size_t crypto_verify_data_length; + + /** + * @brief Whether user's PIN is required or not + */ + bool pin_required; +} CryptoSettings; \ No newline at end of file diff --git a/applications/external/totp/types/event_type.h b/applications/external/totp/types/event_type.h index 7bdf6981f1..138f528d85 100644 --- a/applications/external/totp/types/event_type.h +++ b/applications/external/totp/types/event_type.h @@ -3,4 +3,4 @@ typedef uint8_t EventType; -enum EventTypes { EventTypeTick, EventTypeKey, EventForceCloseApp }; +enum EventTypes { EventTypeTick, EventTypeKey, EventForceCloseApp, EventForceRedraw }; diff --git a/applications/external/totp/types/plugin_state.h b/applications/external/totp/types/plugin_state.h index 87ed51abd5..a3b2f5c8fe 100644 --- a/applications/external/totp/types/plugin_state.h +++ b/applications/external/totp/types/plugin_state.h @@ -9,11 +9,11 @@ #include "../services/idle_timeout/idle_timeout.h" #include "notification_method.h" #include "automation_method.h" -#ifdef TOTP_BADBT_TYPE_ENABLED +#include "automation_kb_layout.h" +#ifdef TOTP_BADBT_AUTOMATION_ENABLED #include "../workers/bt_type_code/bt_type_code.h" #endif - -#define TOTP_IV_SIZE (16) +#include "crypto_settings.h" /** * @brief Application state structure @@ -29,11 +29,6 @@ typedef struct { */ void* current_scene_state; - /** - * @brief Reference to the firmware notification subsystem - */ - NotificationApp* notification_app; - /** * @brief Reference to the firmware dialogs subsystem */ @@ -54,47 +49,22 @@ typedef struct { */ ConfigFileContext* config_file_context; - /** - * @brief Encrypted well-known string data - */ - uint8_t* crypto_verify_data; - - /** - * @brief Encrypted well-known string data length - */ - size_t crypto_verify_data_length; - - /** - * @brief Whether PIN is set by user or not - */ - bool pin_set; - - /** - * @brief Initialization vector (IV) to be used for encryption\decryption - */ - uint8_t iv[TOTP_IV_SIZE]; - - /** - * @brief Basic randomly-generated initialization vector (IV) - */ - uint8_t base_iv[TOTP_IV_SIZE]; - /** * @brief Notification method */ NotificationMethod notification_method; /** - * @brief Main rendering loop mutex + * @brief Automation method */ - FuriMutex* mutex; + AutomationMethod automation_method; /** - * @brief Automation method + * @brief Automation keyboard layout to be used */ - AutomationMethod automation_method; + AutomationKeyboardLayout automation_kb_layout; -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED /** * @brief Bad-Bluetooth worker context */ @@ -110,4 +80,14 @@ typedef struct { * @brief Font index to be used to draw TOTP token */ uint8_t active_font_index; + + /** + * @brief Application even queue + */ + FuriMessageQueue* event_queue; + + /** + * @brief Crypto settings + */ + CryptoSettings crypto_settings; } PluginState; diff --git a/applications/external/totp/types/token_info.c b/applications/external/totp/types/token_info.c index ab47f4e3ed..1d1e731606 100644 --- a/applications/external/totp/types/token_info.c +++ b/applications/external/totp/types/token_info.c @@ -1,9 +1,10 @@ #include "token_info.h" +#include #include #include #include #include "common.h" -#include "../services/crypto/crypto.h" +#include "../services/crypto/crypto_facade.h" TokenInfo* token_info_alloc() { TokenInfo* tokenInfo = malloc(sizeof(TokenInfo)); @@ -25,7 +26,7 @@ bool token_info_set_secret( const char* plain_token_secret, size_t token_secret_length, PlainTokenSecretEncoding plain_token_secret_encoding, - const uint8_t* iv) { + const CryptoSettings* crypto_settings) { if(token_secret_length == 0) return false; uint8_t* plain_secret; size_t plain_secret_length; @@ -54,8 +55,8 @@ bool token_info_set_secret( free(token_info->token); } - token_info->token = - totp_crypto_encrypt(plain_secret, plain_secret_length, iv, &token_info->token_length); + token_info->token = totp_crypto_encrypt( + plain_secret, plain_secret_length, crypto_settings, &token_info->token_length); result = true; } else { result = false; diff --git a/applications/external/totp/types/token_info.h b/applications/external/totp/types/token_info.h index 163a0492e5..969445dff5 100644 --- a/applications/external/totp/types/token_info.h +++ b/applications/external/totp/types/token_info.h @@ -1,8 +1,9 @@ #pragma once -#include +#include #include #include +#include "crypto_settings.h" #define TOKEN_HASH_ALGO_SHA1_NAME "sha1" #define TOKEN_HASH_ALGO_STEAM_NAME "steam" @@ -200,7 +201,7 @@ void token_info_free(TokenInfo* token_info); * @param plain_token_secret plain token secret * @param token_secret_length plain token secret length * @param plain_token_secret_encoding plain token secret encoding - * @param iv initialization vecor (IV) to be used for encryption + * @param crypto_settings crypto settings * @return \c true if token successfully set; \c false otherwise */ bool token_info_set_secret( @@ -208,7 +209,7 @@ bool token_info_set_secret( const char* plain_token_secret, size_t token_secret_length, PlainTokenSecretEncoding plain_token_secret_encoding, - const uint8_t* iv); + const CryptoSettings* crypto_settings); /** * @brief Sets token digits count from \c uint8_t value diff --git a/applications/external/totp/ui/canvas_extensions.h b/applications/external/totp/ui/canvas_extensions.h index ab55191400..2e053b488d 100644 --- a/applications/external/totp/ui/canvas_extensions.h +++ b/applications/external/totp/ui/canvas_extensions.h @@ -4,6 +4,15 @@ #include #include +/** + * @brief Draw string using given font + * @param canvas canvas to draw string at + * @param x horizontal position + * @param y vertical position + * @param text string to draw + * @param text_length string length + * @param font font to be used to draw string + */ void canvas_draw_str_ex( Canvas* canvas, uint8_t x, diff --git a/applications/external/totp/ui/common_dialogs.h b/applications/external/totp/ui/common_dialogs.h index 187d0e95c9..1ddd80a758 100644 --- a/applications/external/totp/ui/common_dialogs.h +++ b/applications/external/totp/ui/common_dialogs.h @@ -3,5 +3,16 @@ #include #include "../types/plugin_state.h" +/** + * @brief Shows standard dialog about the fact that error occurred when loading config file + * @param plugin_state application state + * @return dialog button which user pressed to close the dialog + */ DialogMessageButton totp_dialogs_config_loading_error(PluginState* plugin_state); + +/** + * @brief Shows standard dialog about the fact that error occurred when updating config file + * @param plugin_state application state + * @return dialog button which user pressed to close the dialog + */ DialogMessageButton totp_dialogs_config_updating_error(PluginState* plugin_state); \ No newline at end of file diff --git a/applications/external/totp/ui/scene_director.c b/applications/external/totp/ui/scene_director.c index 657762a94e..fd7cf1dca5 100644 --- a/applications/external/totp/ui/scene_director.c +++ b/applications/external/totp/ui/scene_director.c @@ -116,3 +116,8 @@ bool totp_scene_director_handle_event(PluginEvent* const event, PluginState* con return processing; } + +void totp_scene_director_force_redraw(PluginState* const plugin_state) { + PluginEvent event = {.type = EventForceRedraw}; + furi_message_queue_put(plugin_state->event_queue, &event, FuriWaitForever); +} \ No newline at end of file diff --git a/applications/external/totp/ui/scene_director.h b/applications/external/totp/ui/scene_director.h index e452239975..1f09f9ea98 100644 --- a/applications/external/totp/ui/scene_director.h +++ b/applications/external/totp/ui/scene_director.h @@ -33,3 +33,9 @@ void totp_scene_director_render(Canvas* const canvas, PluginState* const plugin_ * @return \c true if event handled and applilcation should continue; \c false if application should be closed */ bool totp_scene_director_handle_event(PluginEvent* const event, PluginState* const plugin_state); + +/** + * @brief Forces screen to be redraw\updated + * @param plugin_state application state + */ +void totp_scene_director_force_redraw(PluginState* const plugin_state); \ No newline at end of file diff --git a/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.c b/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.c index 6856d1e308..6ae288d4c6 100644 --- a/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.c +++ b/applications/external/totp/ui/scenes/add_new_token/totp_scene_add_new_token.c @@ -42,7 +42,7 @@ typedef struct { struct TotpAddContext { SceneState* scene_state; - uint8_t* iv; + const CryptoSettings* crypto_settings; }; enum TotpIteratorUpdateTokenResultsEx { TotpIteratorUpdateTokenResultInvalidSecret = 1 }; @@ -58,7 +58,7 @@ static TotpIteratorUpdateTokenResult add_token_handler(TokenInfo* tokenInfo, con context_t->scene_state->token_secret, context_t->scene_state->token_secret_length, PlainTokenSecretEncodingBase32, - context_t->iv)) { + context_t->crypto_settings)) { return TotpIteratorUpdateTokenResultInvalidSecret; } @@ -271,7 +271,7 @@ bool totp_scene_add_new_token_handle_event( break; case ConfirmButton: { struct TotpAddContext add_context = { - .iv = plugin_state->iv, .scene_state = scene_state}; + .scene_state = scene_state, .crypto_settings = &plugin_state->crypto_settings}; TokenInfoIteratorContext* iterator_context = totp_config_get_token_iterator_context(plugin_state); TotpIteratorUpdateTokenResult add_result = totp_token_info_iterator_add_new_token( diff --git a/applications/external/totp/ui/scenes/app_settings/totp_app_settings.c b/applications/external/totp/ui/scenes/app_settings/totp_app_settings.c index 7575d0f2df..33dcd5b43b 100644 --- a/applications/external/totp/ui/scenes/app_settings/totp_app_settings.c +++ b/applications/external/totp/ui/scenes/app_settings/totp_app_settings.c @@ -12,14 +12,30 @@ #include "../../../services/convert/convert.h" #include #include "../../../features_config.h" -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED #include "../../../workers/bt_type_code/bt_type_code.h" #endif +#ifdef TOTP_BADBT_AUTOMATION_ENABLED +#define AUTOMATION_LIST_MAX_INDEX (3) +#else +#define AUTOMATION_LIST_MAX_INDEX (1) +#endif +#define BAD_KB_LAYOUT_LIST_MAX_INDEX (1) +#define FONT_TEST_STR_LENGTH (7) + static const char* YES_NO_LIST[] = {"NO", "YES"}; -static const char* ON_OFF_LIST[] = {"OFF", "ON"}; +static const char* AUTOMATION_LIST[] = { + "None", + "USB" +#ifdef TOTP_BADBT_AUTOMATION_ENABLED + , + "Bluetooth", + "BT and USB" +#endif +}; +static const char* BAD_KB_LAYOUT_LIST[] = {"QWERTY", "AZERTY"}; static const char* FONT_TEST_STR = "0123BCD"; -static const uint8_t FONT_TEST_STR_LENGTH = 7; typedef enum { HoursInput, @@ -27,10 +43,8 @@ typedef enum { FontSelect, SoundSwitch, VibroSwitch, - BadUsbSwitch, -#ifdef TOTP_BADBT_TYPE_ENABLED - BadBtSwitch, -#endif + AutomationSwitch, + BadKeyboardLayoutSelect, ConfirmButton } Control; @@ -39,11 +53,9 @@ typedef struct { uint8_t tz_offset_minutes; bool notification_sound; bool notification_vibro; - bool badusb_enabled; -#ifdef TOTP_BADBT_TYPE_ENABLED - bool badbt_enabled; -#endif - uint8_t y_offset; + AutomationMethod automation_method; + uint16_t y_offset; + AutomationKeyboardLayout automation_kb_layout; Control selected_control; uint8_t active_font; } SceneState; @@ -59,10 +71,11 @@ void totp_scene_app_settings_activate(PluginState* plugin_state) { scene_state->tz_offset_minutes = 60.0f * off_dec; scene_state->notification_sound = plugin_state->notification_method & NotificationMethodSound; scene_state->notification_vibro = plugin_state->notification_method & NotificationMethodVibro; - scene_state->badusb_enabled = plugin_state->automation_method & AutomationMethodBadUsb; -#ifdef TOTP_BADBT_TYPE_ENABLED - scene_state->badbt_enabled = plugin_state->automation_method & AutomationMethodBadBt; -#endif + scene_state->automation_method = + MIN(plugin_state->automation_method, AUTOMATION_LIST_MAX_INDEX); + scene_state->automation_kb_layout = + MIN(plugin_state->automation_kb_layout, BAD_KB_LAYOUT_LIST_MAX_INDEX); + scene_state->active_font = plugin_state->active_font_index; } @@ -82,127 +95,121 @@ static void two_digit_to_str(int8_t num, char* str) { void totp_scene_app_settings_render(Canvas* const canvas, const PluginState* plugin_state) { const SceneState* scene_state = plugin_state->current_scene_state; + if(scene_state->selected_control < FontSelect) { + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned( + canvas, 0, 0 - scene_state->y_offset, AlignLeft, AlignTop, "Timezone offset"); + canvas_set_font(canvas, FontSecondary); + + char tmp_str[4]; + two_digit_to_str(scene_state->tz_offset_hours, &tmp_str[0]); + canvas_draw_str_aligned( + canvas, 0, 17 - scene_state->y_offset, AlignLeft, AlignTop, "Hours:"); + ui_control_select_render( + canvas, + 36, + 10 - scene_state->y_offset, + SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH, + &tmp_str[0], + scene_state->selected_control == HoursInput); + + two_digit_to_str(scene_state->tz_offset_minutes, &tmp_str[0]); + canvas_draw_str_aligned( + canvas, 0, 35 - scene_state->y_offset, AlignLeft, AlignTop, "Minutes:"); + ui_control_select_render( + canvas, + 36, + 28 - scene_state->y_offset, + SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH, + &tmp_str[0], + scene_state->selected_control == MinutesInput); + + } else if(scene_state->selected_control < SoundSwitch) { + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned( + canvas, 0, 64 - scene_state->y_offset, AlignLeft, AlignTop, "Font"); + canvas_set_font(canvas, FontSecondary); + + const FONT_INFO* const font = available_fonts[scene_state->active_font]; + ui_control_select_render( + canvas, + 0, + 74 - scene_state->y_offset, + SCREEN_WIDTH - UI_CONTROL_VSCROLL_WIDTH, + font->name, + scene_state->selected_control == FontSelect); + + uint8_t font_x_offset = + SCREEN_WIDTH_CENTER - + (((font->charInfo[0].width + font->spacePixels) * FONT_TEST_STR_LENGTH) >> 1); + uint8_t font_y_offset = 108 - scene_state->y_offset - (font->height >> 1); + canvas_draw_str_ex( + canvas, font_x_offset, font_y_offset, FONT_TEST_STR, FONT_TEST_STR_LENGTH, font); + + } else if(scene_state->selected_control < AutomationSwitch) { + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned( + canvas, 0, 128 - scene_state->y_offset, AlignLeft, AlignTop, "Notifications"); + canvas_set_font(canvas, FontSecondary); + + canvas_draw_str_aligned( + canvas, 0, 145 - scene_state->y_offset, AlignLeft, AlignTop, "Sound:"); + ui_control_select_render( + canvas, + 36, + 138 - scene_state->y_offset, + SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH, + YES_NO_LIST[scene_state->notification_sound], + scene_state->selected_control == SoundSwitch); + + canvas_draw_str_aligned( + canvas, 0, 163 - scene_state->y_offset, AlignLeft, AlignTop, "Vibro:"); + ui_control_select_render( + canvas, + 36, + 156 - scene_state->y_offset, + SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH, + YES_NO_LIST[scene_state->notification_vibro], + scene_state->selected_control == VibroSwitch); + } else { + canvas_set_font(canvas, FontPrimary); + canvas_draw_str_aligned( + canvas, 0, 192 - scene_state->y_offset, AlignLeft, AlignTop, "Automation"); + canvas_set_font(canvas, FontSecondary); + + canvas_draw_str_aligned( + canvas, 0, 209 - scene_state->y_offset, AlignLeft, AlignTop, "Method:"); + ui_control_select_render( + canvas, + 36, + 202 - scene_state->y_offset, + SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH, + AUTOMATION_LIST[scene_state->automation_method], + scene_state->selected_control == AutomationSwitch); + + canvas_draw_str_aligned( + canvas, 0, 227 - scene_state->y_offset, AlignLeft, AlignTop, "Layout:"); + + ui_control_select_render( + canvas, + 36, + 220 - scene_state->y_offset, + SCREEN_WIDTH - 36 - UI_CONTROL_VSCROLL_WIDTH, + BAD_KB_LAYOUT_LIST[scene_state->automation_kb_layout], + scene_state->selected_control == BadKeyboardLayoutSelect); + + ui_control_button_render( + canvas, + SCREEN_WIDTH_CENTER - 24, + 242 - scene_state->y_offset, + 48, + 13, + "Confirm", + scene_state->selected_control == ConfirmButton); + } - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned( - canvas, 0, 0 - scene_state->y_offset, AlignLeft, AlignTop, "Timezone offset"); - canvas_set_font(canvas, FontSecondary); - - char tmp_str[4]; - two_digit_to_str(scene_state->tz_offset_hours, &tmp_str[0]); - canvas_draw_str_aligned(canvas, 0, 17 - scene_state->y_offset, AlignLeft, AlignTop, "Hours:"); - ui_control_select_render( - canvas, - 36, - 10 - scene_state->y_offset, - SCREEN_WIDTH - 36, - &tmp_str[0], - scene_state->selected_control == HoursInput); - - two_digit_to_str(scene_state->tz_offset_minutes, &tmp_str[0]); - canvas_draw_str_aligned( - canvas, 0, 35 - scene_state->y_offset, AlignLeft, AlignTop, "Minutes:"); - ui_control_select_render( - canvas, - 36, - 28 - scene_state->y_offset, - SCREEN_WIDTH - 36, - &tmp_str[0], - scene_state->selected_control == MinutesInput); - - canvas_draw_icon( - canvas, - SCREEN_WIDTH_CENTER - 5, - SCREEN_HEIGHT - 5 - scene_state->y_offset, - &I_totp_arrow_bottom_10x5); - - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned(canvas, 0, 64 - scene_state->y_offset, AlignLeft, AlignTop, "Font"); - canvas_set_font(canvas, FontSecondary); - - const FONT_INFO* const font = available_fonts[scene_state->active_font]; - ui_control_select_render( - canvas, - 0, - 74 - scene_state->y_offset, - SCREEN_WIDTH, - font->name, - scene_state->selected_control == FontSelect); - - uint8_t font_x_offset = - SCREEN_WIDTH_CENTER - - (((font->charInfo[0].width + font->spacePixels) * FONT_TEST_STR_LENGTH) >> 1); - uint8_t font_y_offset = 108 - scene_state->y_offset - (font->height >> 1); - canvas_draw_str_ex( - canvas, font_x_offset, font_y_offset, FONT_TEST_STR, FONT_TEST_STR_LENGTH, font); - - canvas_draw_icon( - canvas, SCREEN_WIDTH_CENTER - 5, 123 - scene_state->y_offset, &I_totp_arrow_bottom_10x5); - - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned( - canvas, 0, 128 - scene_state->y_offset, AlignLeft, AlignTop, "Notifications"); - canvas_set_font(canvas, FontSecondary); - - canvas_draw_str_aligned(canvas, 0, 145 - scene_state->y_offset, AlignLeft, AlignTop, "Sound:"); - ui_control_select_render( - canvas, - 36, - 138 - scene_state->y_offset, - SCREEN_WIDTH - 36, - YES_NO_LIST[scene_state->notification_sound], - scene_state->selected_control == SoundSwitch); - - canvas_draw_str_aligned(canvas, 0, 163 - scene_state->y_offset, AlignLeft, AlignTop, "Vibro:"); - ui_control_select_render( - canvas, - 36, - 156 - scene_state->y_offset, - SCREEN_WIDTH - 36, - YES_NO_LIST[scene_state->notification_vibro], - scene_state->selected_control == VibroSwitch); - - canvas_draw_icon( - canvas, SCREEN_WIDTH_CENTER - 5, 187 - scene_state->y_offset, &I_totp_arrow_bottom_10x5); - - canvas_set_font(canvas, FontPrimary); - canvas_draw_str_aligned( - canvas, 0, 192 - scene_state->y_offset, AlignLeft, AlignTop, "Automation"); - canvas_set_font(canvas, FontSecondary); - - canvas_draw_str_aligned( - canvas, 0, 209 - scene_state->y_offset, AlignLeft, AlignTop, "BadUSB:"); - ui_control_select_render( - canvas, - 36, - 202 - scene_state->y_offset, - SCREEN_WIDTH - 36, - ON_OFF_LIST[scene_state->badusb_enabled], - scene_state->selected_control == BadUsbSwitch); - -#ifdef TOTP_BADBT_TYPE_ENABLED - canvas_draw_str_aligned(canvas, 0, 227 - scene_state->y_offset, AlignLeft, AlignTop, "BadBT:"); - ui_control_select_render( - canvas, - 36, - 220 - scene_state->y_offset, - SCREEN_WIDTH - 36, - ON_OFF_LIST[scene_state->badbt_enabled], - scene_state->selected_control == BadBtSwitch); -#endif - - ui_control_button_render( - canvas, - SCREEN_WIDTH_CENTER - 24, -#ifdef TOTP_BADBT_TYPE_ENABLED - 242 - scene_state->y_offset, -#else - 229 - scene_state->y_offset, -#endif - 48, - 13, - "Confirm", - scene_state->selected_control == ConfirmButton); + ui_control_vscroll_render( + canvas, SCREEN_WIDTH - 3, 0, SCREEN_HEIGHT, scene_state->selected_control, ConfirmButton); } bool totp_scene_app_settings_handle_event( @@ -267,14 +274,21 @@ bool totp_scene_app_settings_handle_event( scene_state->notification_sound = !scene_state->notification_sound; } else if(scene_state->selected_control == VibroSwitch) { scene_state->notification_vibro = !scene_state->notification_vibro; - } else if(scene_state->selected_control == BadUsbSwitch) { - scene_state->badusb_enabled = !scene_state->badusb_enabled; - } -#ifdef TOTP_BADBT_TYPE_ENABLED - else if(scene_state->selected_control == BadBtSwitch) { - scene_state->badbt_enabled = !scene_state->badbt_enabled; + } else if(scene_state->selected_control == AutomationSwitch) { + totp_roll_value_uint8_t( + &scene_state->automation_method, + 1, + 0, + AUTOMATION_LIST_MAX_INDEX, + RollOverflowBehaviorRoll); + } else if(scene_state->selected_control == BadKeyboardLayoutSelect) { + totp_roll_value_uint8_t( + &scene_state->automation_kb_layout, + 1, + 0, + BAD_KB_LAYOUT_LIST_MAX_INDEX, + RollOverflowBehaviorRoll); } -#endif break; case InputKeyLeft: if(scene_state->selected_control == HoursInput) { @@ -294,14 +308,21 @@ bool totp_scene_app_settings_handle_event( scene_state->notification_sound = !scene_state->notification_sound; } else if(scene_state->selected_control == VibroSwitch) { scene_state->notification_vibro = !scene_state->notification_vibro; - } else if(scene_state->selected_control == BadUsbSwitch) { - scene_state->badusb_enabled = !scene_state->badusb_enabled; - } -#ifdef TOTP_BADBT_TYPE_ENABLED - else if(scene_state->selected_control == BadBtSwitch) { - scene_state->badbt_enabled = !scene_state->badbt_enabled; + } else if(scene_state->selected_control == AutomationSwitch) { + totp_roll_value_uint8_t( + &scene_state->automation_method, + -1, + 0, + AUTOMATION_LIST_MAX_INDEX, + RollOverflowBehaviorRoll); + } else if(scene_state->selected_control == BadKeyboardLayoutSelect) { + totp_roll_value_uint8_t( + &scene_state->automation_kb_layout, + -1, + 0, + BAD_KB_LAYOUT_LIST_MAX_INDEX, + RollOverflowBehaviorRoll); } -#endif break; case InputKeyOk: break; @@ -322,22 +343,18 @@ bool totp_scene_app_settings_handle_event( (scene_state->notification_sound ? NotificationMethodSound : NotificationMethodNone) | (scene_state->notification_vibro ? NotificationMethodVibro : NotificationMethodNone); - plugin_state->automation_method = scene_state->badusb_enabled ? AutomationMethodBadUsb : - AutomationMethodNone; -#ifdef TOTP_BADBT_TYPE_ENABLED - plugin_state->automation_method |= scene_state->badbt_enabled ? AutomationMethodBadBt : - AutomationMethodNone; -#endif - + plugin_state->automation_method = scene_state->automation_method; plugin_state->active_font_index = scene_state->active_font; + plugin_state->automation_kb_layout = scene_state->automation_kb_layout; if(!totp_config_file_update_user_settings(plugin_state)) { totp_dialogs_config_updating_error(plugin_state); return false; } -#ifdef TOTP_BADBT_TYPE_ENABLED - if(!scene_state->badbt_enabled && plugin_state->bt_type_code_worker_context != NULL) { +#ifdef TOTP_BADBT_AUTOMATION_ENABLED + if((scene_state->automation_method & AutomationMethodBadBt) == 0 && + plugin_state->bt_type_code_worker_context != NULL) { totp_bt_type_code_worker_free(plugin_state->bt_type_code_worker_context); plugin_state->bt_type_code_worker_context = NULL; } diff --git a/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.c b/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.c index 218e5e3975..ea407395a2 100644 --- a/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.c +++ b/applications/external/totp/ui/scenes/authenticate/totp_scene_authenticate.c @@ -6,10 +6,10 @@ #include "../../../services/config/config.h" #include "../../scene_director.h" #include "../../totp_scenes_enum.h" -#include "../../../services/crypto/crypto.h" +#include "../../../services/crypto/crypto_facade.h" #include "../../../types/user_pin_codes.h" -#define MAX_CODE_LENGTH TOTP_IV_SIZE +#define MAX_CODE_LENGTH CRYPTO_IV_LENGTH static const uint8_t PIN_ASTERISK_RADIUS = 3; static const uint8_t PIN_ASTERISK_STEP = (PIN_ASTERISK_RADIUS << 1) + 2; @@ -24,7 +24,7 @@ void totp_scene_authenticate_activate(PluginState* plugin_state) { scene_state->code_length = 0; memset(&scene_state->code_input[0], 0, MAX_CODE_LENGTH); plugin_state->current_scene_state = scene_state; - memset(&plugin_state->iv[0], 0, TOTP_IV_SIZE); + memset(&plugin_state->crypto_settings.iv[0], 0, CRYPTO_IV_LENGTH); } void totp_scene_authenticate_render(Canvas* const canvas, PluginState* plugin_state) { @@ -35,7 +35,7 @@ void totp_scene_authenticate_render(Canvas* const canvas, PluginState* plugin_st v_shift = -10; } - if(plugin_state->crypto_verify_data == NULL) { + if(plugin_state->crypto_settings.crypto_verify_data == NULL) { canvas_draw_str_aligned( canvas, SCREEN_WIDTH_CENTER, @@ -123,20 +123,22 @@ bool totp_scene_authenticate_handle_event( } } else if(event->input.type == InputTypeRelease && event->input.key == InputKeyOk) { CryptoSeedIVResult seed_result = totp_crypto_seed_iv( - plugin_state, &scene_state->code_input[0], scene_state->code_length); + &plugin_state->crypto_settings, &scene_state->code_input[0], scene_state->code_length); if(seed_result & CryptoSeedIVResultFlagSuccess && seed_result & CryptoSeedIVResultFlagNewCryptoVerifyData) { totp_config_file_update_crypto_signatures(plugin_state); } - if(totp_crypto_verify_key(plugin_state)) { + if(totp_crypto_verify_key(&plugin_state->crypto_settings)) { FURI_LOG_D(LOGGING_TAG, "PIN is valid"); + totp_config_file_ensure_latest_encryption( + plugin_state, &scene_state->code_input[0], scene_state->code_length); totp_scene_director_activate_scene(plugin_state, TotpSceneGenerateToken); } else { FURI_LOG_D(LOGGING_TAG, "PIN is NOT valid"); memset(&scene_state->code_input[0], 0, MAX_CODE_LENGTH); - memset(&plugin_state->iv[0], 0, TOTP_IV_SIZE); + memset(&plugin_state->crypto_settings.iv[0], 0, CRYPTO_IV_LENGTH); scene_state->code_length = 0; DialogMessage* message = dialog_message_alloc(); diff --git a/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.c b/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.c index 0a0c8373a5..de1c0685f7 100644 --- a/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.c +++ b/applications/external/totp/ui/scenes/generate_token/totp_scene_generate_token.c @@ -15,7 +15,7 @@ #include "../../../features_config.h" #include "../../../workers/generate_totp_code/generate_totp_code.h" #include "../../../workers/usb_type_code/usb_type_code.h" -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED #include "../../../workers/bt_type_code/bt_type_code.h" #endif @@ -33,50 +33,40 @@ typedef struct { typedef struct { char last_code[TokenDigitsCountMax + 1]; TotpUsbTypeCodeWorkerContext* usb_type_code_worker_context; - NotificationMessage const** notification_sequence_new_token; - NotificationMessage const** notification_sequence_automation; + NotificationMessage const* notification_sequence_new_token[8]; + NotificationMessage const* notification_sequence_automation[11]; FuriMutex* last_code_update_sync; TotpGenerateCodeWorkerContext* generate_code_worker_context; UiPrecalculatedDimensions ui_precalculated_dimensions; const FONT_INFO* active_font; + NotificationApp* notification_app; } SceneState; static const NotificationSequence* get_notification_sequence_new_token(const PluginState* plugin_state, SceneState* scene_state) { - if(scene_state->notification_sequence_new_token == NULL) { - uint8_t i = 0; - uint8_t length = 4; + if(scene_state->notification_sequence_new_token[0] == NULL) { + NotificationMessage const** sequence = &scene_state->notification_sequence_new_token[0]; + *(sequence++) = &message_display_backlight_on; + *(sequence++) = &message_green_255; if(plugin_state->notification_method & NotificationMethodVibro) { - length += 2; + *(sequence++) = &message_vibro_on; } if(plugin_state->notification_method & NotificationMethodSound) { - length += 2; + *(sequence++) = &message_note_c5; } - scene_state->notification_sequence_new_token = malloc(sizeof(void*) * length); - furi_check(scene_state->notification_sequence_new_token != NULL); - scene_state->notification_sequence_new_token[i++] = &message_display_backlight_on; - scene_state->notification_sequence_new_token[i++] = &message_green_255; - if(plugin_state->notification_method & NotificationMethodVibro) { - scene_state->notification_sequence_new_token[i++] = &message_vibro_on; - } - - if(plugin_state->notification_method & NotificationMethodSound) { - scene_state->notification_sequence_new_token[i++] = &message_note_c5; - } - - scene_state->notification_sequence_new_token[i++] = &message_delay_50; + *(sequence++) = &message_delay_50; if(plugin_state->notification_method & NotificationMethodVibro) { - scene_state->notification_sequence_new_token[i++] = &message_vibro_off; + *(sequence++) = &message_vibro_off; } if(plugin_state->notification_method & NotificationMethodSound) { - scene_state->notification_sequence_new_token[i++] = &message_sound_off; + *(sequence++) = &message_sound_off; } - scene_state->notification_sequence_new_token[i++] = NULL; + *(sequence++) = NULL; } return (NotificationSequence*)scene_state->notification_sequence_new_token; @@ -84,44 +74,33 @@ static const NotificationSequence* static const NotificationSequence* get_notification_sequence_automation(const PluginState* plugin_state, SceneState* scene_state) { - if(scene_state->notification_sequence_automation == NULL) { - uint8_t i = 0; - uint8_t length = 3; - if(plugin_state->notification_method & NotificationMethodVibro) { - length += 2; - } - - if(plugin_state->notification_method & NotificationMethodSound) { - length += 6; - } + if(scene_state->notification_sequence_automation[0] == NULL) { + NotificationMessage const** sequence = &scene_state->notification_sequence_automation[0]; - scene_state->notification_sequence_automation = malloc(sizeof(void*) * length); - furi_check(scene_state->notification_sequence_automation != NULL); - - scene_state->notification_sequence_automation[i++] = &message_blue_255; + *(sequence++) = &message_blue_255; if(plugin_state->notification_method & NotificationMethodVibro) { - scene_state->notification_sequence_automation[i++] = &message_vibro_on; + *(sequence++) = &message_vibro_on; } if(plugin_state->notification_method & NotificationMethodSound) { - scene_state->notification_sequence_automation[i++] = &message_note_d5; //-V525 - scene_state->notification_sequence_automation[i++] = &message_delay_50; - scene_state->notification_sequence_automation[i++] = &message_note_e4; - scene_state->notification_sequence_automation[i++] = &message_delay_50; - scene_state->notification_sequence_automation[i++] = &message_note_f3; + *(sequence++) = &message_note_d5; //-V525 + *(sequence++) = &message_delay_50; + *(sequence++) = &message_note_e4; + *(sequence++) = &message_delay_50; + *(sequence++) = &message_note_f3; } - scene_state->notification_sequence_automation[i++] = &message_delay_50; + *(sequence++) = &message_delay_50; if(plugin_state->notification_method & NotificationMethodVibro) { - scene_state->notification_sequence_automation[i++] = &message_vibro_off; + *(sequence++) = &message_vibro_off; } if(plugin_state->notification_method & NotificationMethodSound) { - scene_state->notification_sequence_automation[i++] = &message_sound_off; + *(sequence++) = &message_sound_off; } - scene_state->notification_sequence_automation[i++] = NULL; + *(sequence++) = NULL; } return (NotificationSequence*)scene_state->notification_sequence_automation; @@ -153,7 +132,7 @@ static void draw_totp_code(Canvas* const canvas, const PluginState* const plugin } static void on_new_token_code_generated(bool time_left, void* context) { - const PluginState* plugin_state = context; + PluginState* const plugin_state = context; const TokenInfoIteratorContext* iterator_context = totp_config_get_token_iterator_context(plugin_state); if(totp_token_info_iterator_get_total_count(iterator_context) == 0) { @@ -174,13 +153,16 @@ static void on_new_token_code_generated(bool time_left, void* context) { if(time_left) { notification_message( - plugin_state->notification_app, - get_notification_sequence_new_token(plugin_state, plugin_state->current_scene_state)); + scene_state->notification_app, + get_notification_sequence_new_token(plugin_state, scene_state)); } + + totp_scene_director_force_redraw(plugin_state); } static void on_code_lifetime_updated_generated(float code_lifetime_percent, void* context) { - SceneState* scene_state = context; + PluginState* const plugin_state = context; + SceneState* scene_state = plugin_state->current_scene_state; scene_state->ui_precalculated_dimensions.progress_bar_width = (uint8_t)((float)(SCREEN_WIDTH - (PROGRESS_BAR_MARGIN << 1)) * code_lifetime_percent); scene_state->ui_precalculated_dimensions.progress_bar_x = @@ -188,6 +170,7 @@ static void on_code_lifetime_updated_generated(float code_lifetime_percent, void scene_state->ui_precalculated_dimensions.progress_bar_width) >> 1) + PROGRESS_BAR_MARGIN; + totp_scene_director_force_redraw(plugin_state); } void totp_scene_generate_token_activate(PluginState* plugin_state) { @@ -200,12 +183,18 @@ void totp_scene_generate_token_activate(PluginState* plugin_state) { scene_state->last_code_update_sync = furi_mutex_alloc(FuriMutexTypeNormal); if(plugin_state->automation_method & AutomationMethodBadUsb) { scene_state->usb_type_code_worker_context = totp_usb_type_code_worker_start( - scene_state->last_code, TokenDigitsCountMax + 1, scene_state->last_code_update_sync); + scene_state->last_code, + TokenDigitsCountMax + 1, + scene_state->last_code_update_sync, + plugin_state->automation_kb_layout); } scene_state->active_font = available_fonts[plugin_state->active_font_index]; + scene_state->notification_app = furi_record_open(RECORD_NOTIFICATION); + scene_state->notification_sequence_automation[0] = NULL; + scene_state->notification_sequence_new_token[0] = NULL; -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED if(plugin_state->automation_method & AutomationMethodBadBt) { if(plugin_state->bt_type_code_worker_context == NULL) { @@ -215,7 +204,8 @@ void totp_scene_generate_token_activate(PluginState* plugin_state) { plugin_state->bt_type_code_worker_context, scene_state->last_code, TokenDigitsCountMax + 1, - scene_state->last_code_update_sync); + scene_state->last_code_update_sync, + plugin_state->automation_kb_layout); } #endif const TokenInfoIteratorContext* iterator_context = @@ -225,7 +215,7 @@ void totp_scene_generate_token_activate(PluginState* plugin_state) { totp_token_info_iterator_get_current_token(iterator_context), scene_state->last_code_update_sync, plugin_state->timezone_offset, - plugin_state->iv); + &plugin_state->crypto_settings); totp_generate_code_worker_set_code_generated_handler( scene_state->generate_code_worker_context, &on_new_token_code_generated, plugin_state); @@ -233,7 +223,7 @@ void totp_scene_generate_token_activate(PluginState* plugin_state) { totp_generate_code_worker_set_lifetime_changed_handler( scene_state->generate_code_worker_context, &on_code_lifetime_updated_generated, - scene_state); + plugin_state); update_totp_params( plugin_state, totp_token_info_iterator_get_current_token_index(iterator_context)); @@ -297,11 +287,10 @@ void totp_scene_generate_token_render(Canvas* const canvas, PluginState* plugin_ canvas, SCREEN_WIDTH - 8, SCREEN_HEIGHT_CENTER - 24, &I_totp_arrow_right_8x9); } -#ifdef TOTP_AUTOMATION_ICONS_ENABLED if(plugin_state->automation_method & AutomationMethodBadUsb) { canvas_draw_icon( canvas, -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED SCREEN_WIDTH_CENTER - (plugin_state->automation_method & AutomationMethodBadBt ? 33 : 15), #else @@ -312,7 +301,7 @@ void totp_scene_generate_token_render(Canvas* const canvas, PluginState* plugin_ &I_hid_usb_31x9); } -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED if(plugin_state->automation_method & AutomationMethodBadBt && plugin_state->bt_type_code_worker_context != NULL && totp_bt_type_code_worker_is_advertising(plugin_state->bt_type_code_worker_context)) { @@ -324,7 +313,6 @@ void totp_scene_generate_token_render(Canvas* const canvas, PluginState* plugin_ &I_hid_ble_31x9); } #endif -#endif } bool totp_scene_generate_token_handle_event( @@ -350,11 +338,11 @@ bool totp_scene_generate_token_handle_event( TotpUsbTypeCodeWorkerEventType, totp_token_info_iterator_get_current_token(iterator_context)->automation_features); notification_message( - plugin_state->notification_app, + scene_state->notification_app, get_notification_sequence_automation(plugin_state, scene_state)); return true; } -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED else if( event->input.key == InputKeyUp && plugin_state->automation_method & AutomationMethodBadBt) { @@ -366,7 +354,7 @@ bool totp_scene_generate_token_handle_event( TotpBtTypeCodeWorkerEventType, totp_token_info_iterator_get_current_token(iterator_context)->automation_features); notification_message( - plugin_state->notification_app, + scene_state->notification_app, get_notification_sequence_automation(plugin_state, scene_state)); return true; } @@ -427,23 +415,17 @@ void totp_scene_generate_token_deactivate(PluginState* plugin_state) { totp_generate_code_worker_stop(scene_state->generate_code_worker_context); + furi_record_close(RECORD_NOTIFICATION); + if(plugin_state->automation_method & AutomationMethodBadUsb) { totp_usb_type_code_worker_stop(scene_state->usb_type_code_worker_context); } -#ifdef TOTP_BADBT_TYPE_ENABLED +#ifdef TOTP_BADBT_AUTOMATION_ENABLED if(plugin_state->automation_method & AutomationMethodBadBt) { totp_bt_type_code_worker_stop(plugin_state->bt_type_code_worker_context); } #endif - if(scene_state->notification_sequence_new_token != NULL) { - free(scene_state->notification_sequence_new_token); - } - - if(scene_state->notification_sequence_automation != NULL) { - free(scene_state->notification_sequence_automation); - } - furi_mutex_free(scene_state->last_code_update_sync); free(scene_state); diff --git a/applications/external/totp/ui/ui_controls.c b/applications/external/totp/ui/ui_controls.c index d5e86aa581..28a7d57dae 100644 --- a/applications/external/totp/ui/ui_controls.c +++ b/applications/external/totp/ui/ui_controls.c @@ -112,3 +112,27 @@ void ui_control_button_render( canvas_set_color(canvas, ColorBlack); } } + +void ui_control_vscroll_render( + Canvas* const canvas, + uint8_t x, + uint8_t y, + uint8_t height, + uint8_t position, + uint8_t max_position) { + canvas_draw_line(canvas, x, y, x, y + height); + uint8_t block_height = height / MIN(10, max_position); + uint8_t block_position_y = + height * ((float)position / (float)max_position) - (block_height >> 1); + uint8_t block_position_y_abs = y + block_position_y; + if(block_position_y_abs + block_height > height) { + block_position_y_abs = height - block_height; + } + + canvas_draw_box( + canvas, + x - (UI_CONTROL_VSCROLL_WIDTH >> 1), + block_position_y_abs, + UI_CONTROL_VSCROLL_WIDTH, + block_height); +} diff --git a/applications/external/totp/ui/ui_controls.h b/applications/external/totp/ui/ui_controls.h index b97006a03c..ccee4edfca 100644 --- a/applications/external/totp/ui/ui_controls.h +++ b/applications/external/totp/ui/ui_controls.h @@ -3,6 +3,8 @@ #include #include +#define UI_CONTROL_VSCROLL_WIDTH (3) + /** * @brief Renders TextBox control * @param canvas canvas to render control at @@ -51,3 +53,20 @@ void ui_control_select_render( uint8_t width, const char* text, bool is_selected); + +/** + * @brief Renders vertical scroll bar + * @param canvas canvas to render control at + * @param x horizontal position of a control to be rendered at + * @param y vertical position of a control to be rendered at + * @param height control height + * @param position current position + * @param max_position maximal position + */ +void ui_control_vscroll_render( + Canvas* const canvas, + uint8_t x, + uint8_t y, + uint8_t height, + uint8_t position, + uint8_t max_position); diff --git a/applications/external/totp/version.h b/applications/external/totp/version.h new file mode 100644 index 0000000000..e6925b600a --- /dev/null +++ b/applications/external/totp/version.h @@ -0,0 +1,5 @@ +#pragma once + +#define TOTP_APP_VERSION_MAJOR (3) +#define TOTP_APP_VERSION_MINOR (2) +#define TOTP_APP_VERSION_PATCH (0) \ No newline at end of file diff --git a/applications/external/totp/workers/bt_type_code/bt_type_code.c b/applications/external/totp/workers/bt_type_code/bt_type_code.c index a27467ed69..16dfcc0e84 100644 --- a/applications/external/totp/workers/bt_type_code/bt_type_code.c +++ b/applications/external/totp/workers/bt_type_code/bt_type_code.c @@ -12,13 +12,14 @@ #include "../../types/token_info.h" #include "../type_code_common.h" #include "../../features_config.h" +#include "../../services/config/constants.h" #if TOTP_TARGET_FIRMWARE == TOTP_FIRMWARE_XTREME_UL #define TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN FURI_HAL_BT_ADV_NAME_LENGTH #define TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN GAP_MAC_ADDR_SIZE #endif -#define HID_BT_KEYS_STORAGE_PATH EXT_PATH("authenticator/.bt_hid.keys") +#define HID_BT_KEYS_STORAGE_PATH CONFIG_FILE_DIRECTORY_PATH "/.bt_hid.keys" struct TotpBtTypeCodeWorkerContext { char* code_buffer; @@ -33,6 +34,7 @@ struct TotpBtTypeCodeWorkerContext { char previous_bt_name[TOTP_BT_WORKER_BT_ADV_NAME_MAX_LEN]; uint8_t previous_bt_mac[TOTP_BT_WORKER_BT_MAC_ADDRESS_LEN]; #endif + AutomationKeyboardLayout keyboard_layout; }; static inline bool totp_type_code_worker_stop_requested() { @@ -73,7 +75,8 @@ static void totp_type_code_worker_type_code(TotpBtTypeCodeWorkerContext* context &furi_hal_bt_hid_kb_release, context->code_buffer, context->code_buffer_size, - context->flags); + context->flags, + context->keyboard_layout); furi_mutex_release(context->code_buffer_sync); } } @@ -119,11 +122,13 @@ void totp_bt_type_code_worker_start( TotpBtTypeCodeWorkerContext* context, char* code_buffer, uint8_t code_buffer_size, - FuriMutex* code_buffer_sync) { + FuriMutex* code_buffer_sync, + AutomationKeyboardLayout keyboard_layout) { furi_check(context != NULL); context->code_buffer = code_buffer; context->code_buffer_size = code_buffer_size; context->code_buffer_sync = code_buffer_sync; + context->keyboard_layout = keyboard_layout; context->thread = furi_thread_alloc(); furi_thread_set_name(context->thread, "TOTPBtHidWorker"); furi_thread_set_stack_size(context->thread, 1024); diff --git a/applications/external/totp/workers/bt_type_code/bt_type_code.h b/applications/external/totp/workers/bt_type_code/bt_type_code.h index 85016592e3..1b9db9bee9 100644 --- a/applications/external/totp/workers/bt_type_code/bt_type_code.h +++ b/applications/external/totp/workers/bt_type_code/bt_type_code.h @@ -3,6 +3,7 @@ #include #include #include +#include "../../types/automation_kb_layout.h" typedef uint8_t TotpBtTypeCodeWorkerEvent; @@ -47,12 +48,14 @@ void totp_bt_type_code_worker_free(TotpBtTypeCodeWorkerContext* context); * @param code_buffer code buffer to be used to automate * @param code_buffer_size code buffer size * @param code_buffer_sync code buffer synchronization primitive + * @param keyboard_layout keyboard layout to be used */ void totp_bt_type_code_worker_start( TotpBtTypeCodeWorkerContext* context, char* code_buffer, uint8_t code_buffer_size, - FuriMutex* code_buffer_sync); + FuriMutex* code_buffer_sync, + AutomationKeyboardLayout keyboard_layout); /** * @brief Stops bluetooth token input automation worker diff --git a/applications/external/totp/workers/generate_totp_code/generate_totp_code.c b/applications/external/totp/workers/generate_totp_code/generate_totp_code.c index 74482517f1..20a7bb54c4 100644 --- a/applications/external/totp/workers/generate_totp_code/generate_totp_code.c +++ b/applications/external/totp/workers/generate_totp_code/generate_totp_code.c @@ -1,6 +1,7 @@ #include "generate_totp_code.h" #include -#include "../../services/crypto/crypto.h" +#include +#include "../../services/crypto/crypto_facade.h" #include "../../services/totp/totp.h" #include "../../services/convert/convert.h" #include @@ -14,7 +15,7 @@ struct TotpGenerateCodeWorkerContext { FuriMutex* code_buffer_sync; const TokenInfo* token_info; float timezone_offset; - uint8_t* iv; + const CryptoSettings* crypto_settings; TOTP_NEW_CODE_GENERATED_HANDLER on_new_code_generated_handler; void* on_new_code_generated_handler_context; TOTP_CODE_LIFETIME_CHANGED_HANDLER on_code_lifetime_changed_handler; @@ -69,7 +70,7 @@ static void generate_totp_code( if(token_info->token != NULL && token_info->token_length > 0) { size_t key_length; uint8_t* key = totp_crypto_decrypt( - token_info->token, token_info->token_length, context->iv, &key_length); + token_info->token, token_info->token_length, context->crypto_settings, &key_length); int_token_to_str( totp_at( @@ -147,14 +148,14 @@ TotpGenerateCodeWorkerContext* totp_generate_code_worker_start( const TokenInfo* token_info, FuriMutex* code_buffer_sync, float timezone_offset, - uint8_t* iv) { + const CryptoSettings* crypto_settings) { TotpGenerateCodeWorkerContext* context = malloc(sizeof(TotpGenerateCodeWorkerContext)); furi_check(context != NULL); context->code_buffer = code_buffer; context->token_info = token_info; context->code_buffer_sync = code_buffer_sync; context->timezone_offset = timezone_offset; - context->iv = iv; + context->crypto_settings = crypto_settings; context->thread = furi_thread_alloc(); furi_thread_set_name(context->thread, "TOTPGenerateWorker"); furi_thread_set_stack_size(context->thread, 2048); diff --git a/applications/external/totp/workers/generate_totp_code/generate_totp_code.h b/applications/external/totp/workers/generate_totp_code/generate_totp_code.h index f351ffa68b..eb234313e3 100644 --- a/applications/external/totp/workers/generate_totp_code/generate_totp_code.h +++ b/applications/external/totp/workers/generate_totp_code/generate_totp_code.h @@ -38,7 +38,7 @@ enum TotGenerateCodeWorkerEvents { * @param token_info token info to be used to generate code * @param code_buffer_sync code buffer synchronization primitive * @param timezone_offset timezone offset to be used to generate code - * @param iv initialization vector (IV) to be used to decrypt token secret + * @param crypto_settings crypto settings * @return worker context */ TotpGenerateCodeWorkerContext* totp_generate_code_worker_start( @@ -46,7 +46,7 @@ TotpGenerateCodeWorkerContext* totp_generate_code_worker_start( const TokenInfo* token_info, FuriMutex* code_buffer_sync, float timezone_offset, - uint8_t* iv); + const CryptoSettings* crypto_settings); /** * @brief Stops generate code worker diff --git a/applications/external/totp/workers/type_code_common.c b/applications/external/totp/workers/type_code_common.c index 82a5a028e4..122c0b2a51 100644 --- a/applications/external/totp/workers/type_code_common.c +++ b/applications/external/totp/workers/type_code_common.c @@ -3,7 +3,9 @@ #include #include "../../services/convert/convert.h" -static const uint8_t hid_number_keys[] = { +#define HID_KEYS_MAP_LENGTH (36) + +static const uint8_t hid_qwerty_keys_map[HID_KEYS_MAP_LENGTH] = { HID_KEYBOARD_0, HID_KEYBOARD_1, HID_KEYBOARD_2, HID_KEYBOARD_3, HID_KEYBOARD_4, HID_KEYBOARD_5, HID_KEYBOARD_6, HID_KEYBOARD_7, HID_KEYBOARD_8, HID_KEYBOARD_9, HID_KEYBOARD_A, HID_KEYBOARD_B, HID_KEYBOARD_C, HID_KEYBOARD_D, HID_KEYBOARD_E, @@ -13,6 +15,16 @@ static const uint8_t hid_number_keys[] = { HID_KEYBOARD_U, HID_KEYBOARD_V, HID_KEYBOARD_W, HID_KEYBOARD_X, HID_KEYBOARD_Y, HID_KEYBOARD_Z}; +static const uint8_t hid_azerty_keys_map[HID_KEYS_MAP_LENGTH] = { + HID_KEYBOARD_0, HID_KEYBOARD_1, HID_KEYBOARD_2, HID_KEYBOARD_3, HID_KEYBOARD_4, + HID_KEYBOARD_5, HID_KEYBOARD_6, HID_KEYBOARD_7, HID_KEYBOARD_8, HID_KEYBOARD_9, + HID_KEYBOARD_Q, HID_KEYBOARD_B, HID_KEYBOARD_C, HID_KEYBOARD_D, HID_KEYBOARD_E, + HID_KEYBOARD_F, HID_KEYBOARD_G, HID_KEYBOARD_H, HID_KEYBOARD_I, HID_KEYBOARD_J, + HID_KEYBOARD_K, HID_KEYBOARD_L, HID_KEYBOARD_SEMICOLON, HID_KEYBOARD_N, HID_KEYBOARD_O, + HID_KEYBOARD_P, HID_KEYBOARD_A, HID_KEYBOARD_R, HID_KEYBOARD_S, HID_KEYBOARD_T, + HID_KEYBOARD_U, HID_KEYBOARD_V, HID_KEYBOARD_Z, HID_KEYBOARD_X, HID_KEYBOARD_Y, + HID_KEYBOARD_W}; + static uint32_t get_keystroke_delay(TokenAutomationFeature features) { if(features & TokenAutomationFeatureTypeSlower) { return 100; @@ -44,21 +56,38 @@ void totp_type_code_worker_execute_automation( TOTP_AUTOMATION_KEY_HANDLER key_release_fn, const char* code_buffer, uint8_t code_buffer_size, - TokenAutomationFeature features) { + TokenAutomationFeature features, + AutomationKeyboardLayout keyboard_layout) { furi_delay_ms(500); uint8_t i = 0; char cb_char; + const uint8_t* keyboard_layout_dict; + switch(keyboard_layout) { + case AutomationKeyboardLayoutQWERTY: + keyboard_layout_dict = &hid_qwerty_keys_map[0]; + break; + case AutomationKeyboardLayoutAZERTY: + keyboard_layout_dict = &hid_azerty_keys_map[0]; + break; + + default: + return; + } + while(i < code_buffer_size && (cb_char = code_buffer[i]) != 0) { uint8_t char_index = CONVERT_CHAR_TO_DIGIT(cb_char); if(char_index > 9) { char_index = cb_char - 'A' + 10; } - if(char_index >= sizeof(hid_number_keys)) break; + if(char_index >= HID_KEYS_MAP_LENGTH) break; - uint16_t hid_kb_key = hid_number_keys[char_index]; - if(char_index > 9) { + uint16_t hid_kb_key = keyboard_layout_dict[char_index]; + + // For non-AZERTY press shift for all non-digit chars + // For AZERTY press shift for all characters + if(char_index > 9 || keyboard_layout == AutomationKeyboardLayoutAZERTY) { hid_kb_key |= KEY_MOD_LEFT_SHIFT; } diff --git a/applications/external/totp/workers/type_code_common.h b/applications/external/totp/workers/type_code_common.h index db357329a8..81b273c367 100644 --- a/applications/external/totp/workers/type_code_common.h +++ b/applications/external/totp/workers/type_code_common.h @@ -1,6 +1,7 @@ #pragma once #include #include "../types/token_info.h" +#include "../types/automation_kb_layout.h" typedef bool (*TOTP_AUTOMATION_KEY_HANDLER)(uint16_t key); @@ -11,10 +12,12 @@ typedef bool (*TOTP_AUTOMATION_KEY_HANDLER)(uint16_t key); * @param code_buffer code buffer to be typed * @param code_buffer_size code buffer size * @param features automation features + * @param keyboard_layout keyboard layout to be used */ void totp_type_code_worker_execute_automation( TOTP_AUTOMATION_KEY_HANDLER key_press_fn, TOTP_AUTOMATION_KEY_HANDLER key_release_fn, const char* code_buffer, uint8_t code_buffer_size, - TokenAutomationFeature features); \ No newline at end of file + TokenAutomationFeature features, + AutomationKeyboardLayout keyboard_layout); \ No newline at end of file diff --git a/applications/external/totp/workers/usb_type_code/usb_type_code.c b/applications/external/totp/workers/usb_type_code/usb_type_code.c index a391bdf827..4e3259424d 100644 --- a/applications/external/totp/workers/usb_type_code/usb_type_code.c +++ b/applications/external/totp/workers/usb_type_code/usb_type_code.c @@ -15,6 +15,7 @@ struct TotpUsbTypeCodeWorkerContext { FuriThread* thread; FuriMutex* code_buffer_sync; FuriHalUsbInterface* usb_mode_prev; + AutomationKeyboardLayout keyboard_layout; }; static void totp_type_code_worker_restore_usb_mode(TotpUsbTypeCodeWorkerContext* context) { @@ -45,7 +46,8 @@ static void totp_type_code_worker_type_code(TotpUsbTypeCodeWorkerContext* contex &furi_hal_hid_kb_release, context->code_buffer, context->code_buffer_size, - context->flags); + context->flags, + context->keyboard_layout); furi_mutex_release(context->code_buffer_sync); furi_delay_ms(100); @@ -83,7 +85,8 @@ static int32_t totp_type_code_worker_callback(void* context) { TotpUsbTypeCodeWorkerContext* totp_usb_type_code_worker_start( char* code_buffer, uint8_t code_buffer_size, - FuriMutex* code_buffer_sync) { + FuriMutex* code_buffer_sync, + AutomationKeyboardLayout keyboard_layout) { TotpUsbTypeCodeWorkerContext* context = malloc(sizeof(TotpUsbTypeCodeWorkerContext)); furi_check(context != NULL); context->code_buffer = code_buffer; @@ -91,6 +94,7 @@ TotpUsbTypeCodeWorkerContext* totp_usb_type_code_worker_start( context->code_buffer_sync = code_buffer_sync; context->thread = furi_thread_alloc(); context->usb_mode_prev = NULL; + context->keyboard_layout = keyboard_layout; furi_thread_set_name(context->thread, "TOTPUsbHidWorker"); furi_thread_set_stack_size(context->thread, 1024); furi_thread_set_context(context->thread, context); diff --git a/applications/external/totp/workers/usb_type_code/usb_type_code.h b/applications/external/totp/workers/usb_type_code/usb_type_code.h index 0a700e7fea..d2d1bdf82b 100644 --- a/applications/external/totp/workers/usb_type_code/usb_type_code.h +++ b/applications/external/totp/workers/usb_type_code/usb_type_code.h @@ -3,6 +3,7 @@ #include #include #include +#include "../../types/automation_kb_layout.h" typedef uint8_t TotpUsbTypeCodeWorkerEvent; @@ -34,12 +35,14 @@ enum TotpUsbTypeCodeWorkerEvents { * @param code_buffer code buffer to be used to automate * @param code_buffer_size code buffer size * @param code_buffer_sync code buffer synchronization primitive + * @param keyboard_layout keyboard layout to be used * @return worker context */ TotpUsbTypeCodeWorkerContext* totp_usb_type_code_worker_start( char* code_buffer, uint8_t code_buffer_size, - FuriMutex* code_buffer_sync); + FuriMutex* code_buffer_sync, + AutomationKeyboardLayout keyboard_layout); /** * @brief Stops USB token input automation worker From d09cf6c69273b052e8116799f8fe43a62aa576cf Mon Sep 17 00:00:00 2001 From: Astra Date: Thu, 3 Aug 2023 18:37:10 +0900 Subject: [PATCH 32/44] FDX-B temperature now uses system units --- lib/lfrfid/protocols/protocol_fdx_b.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/lfrfid/protocols/protocol_fdx_b.c b/lib/lfrfid/protocols/protocol_fdx_b.c index dd54cffb06..a02b44f037 100644 --- a/lib/lfrfid/protocols/protocol_fdx_b.c +++ b/lib/lfrfid/protocols/protocol_fdx_b.c @@ -4,6 +4,7 @@ #include #include #include "lfrfid_protocols.h" +#include #define FDX_B_ENCODED_BIT_SIZE (128) #define FDX_B_ENCODED_BYTE_SIZE (((FDX_B_ENCODED_BIT_SIZE) / 8)) @@ -323,8 +324,12 @@ void protocol_fdx_b_render_brief_data(ProtocolFDXB* protocol, FuriString* result float temperature; if(protocol_fdx_b_get_temp(protocol->data, &temperature)) { - float temperature_c = (temperature - 32) / 1.8; - furi_string_cat_printf(result, "T: %.2fC", (double)temperature_c); + if(furi_hal_rtc_get_locale_units() == FuriHalRtcLocaleUnitsMetric) { + float temperature_c = (temperature - 32) / 1.8; + furi_string_cat_printf(result, "T: %.2fC", (double)temperature_c); + } else { + furi_string_cat_printf(result, "T: %.2fF", (double)temperature); + } } else { furi_string_cat_printf(result, "T: ---"); } From becc8edd8cc2d67ea49d61075113bf5eeafbfe02 Mon Sep 17 00:00:00 2001 From: nminaylov Date: Fri, 4 Aug 2023 18:52:03 +0300 Subject: [PATCH 33/44] IR: buttons move feature rework --- applications/main/infrared/infrared.c | 7 + applications/main/infrared/infrared_i.h | 5 +- applications/main/infrared/infrared_remote.c | 14 +- applications/main/infrared/infrared_remote.h | 2 +- .../infrared/scenes/infrared_scene_config.h | 1 - .../infrared/scenes/infrared_scene_edit.c | 4 +- .../infrared_scene_edit_button_select.c | 34 +-- .../scenes/infrared_scene_edit_move.c | 101 ++------ .../scenes/infrared_scene_edit_move_done.c | 48 ---- .../main/infrared/views/infrared_move_view.c | 215 ++++++++++++++++++ .../main/infrared/views/infrared_move_view.h | 25 ++ 11 files changed, 280 insertions(+), 176 deletions(-) delete mode 100644 applications/main/infrared/scenes/infrared_scene_edit_move_done.c create mode 100644 applications/main/infrared/views/infrared_move_view.c create mode 100644 applications/main/infrared/views/infrared_move_view.h diff --git a/applications/main/infrared/infrared.c b/applications/main/infrared/infrared.c index 893aff809d..9c31a15fcf 100644 --- a/applications/main/infrared/infrared.c +++ b/applications/main/infrared/infrared.c @@ -171,6 +171,10 @@ static Infrared* infrared_alloc() { view_dispatcher_add_view( view_dispatcher, InfraredViewStack, view_stack_get_view(infrared->view_stack)); + infrared->move_view = infrared_move_view_alloc(); + view_dispatcher_add_view( + view_dispatcher, InfraredViewMove, infrared_move_view_get_view(infrared->move_view)); + if(app_state->is_debug_enabled) { infrared->debug_view = infrared_debug_view_alloc(); view_dispatcher_add_view( @@ -218,6 +222,9 @@ static void infrared_free(Infrared* infrared) { view_dispatcher_remove_view(view_dispatcher, InfraredViewStack); view_stack_free(infrared->view_stack); + view_dispatcher_remove_view(view_dispatcher, InfraredViewMove); + infrared_move_view_free(infrared->move_view); + if(app_state->is_debug_enabled) { view_dispatcher_remove_view(view_dispatcher, InfraredViewDebugView); infrared_debug_view_free(infrared->debug_view); diff --git a/applications/main/infrared/infrared_i.h b/applications/main/infrared/infrared_i.h index 089c2c7f8e..4e69b886e2 100644 --- a/applications/main/infrared/infrared_i.h +++ b/applications/main/infrared/infrared_i.h @@ -31,6 +31,7 @@ #include "scenes/infrared_scene.h" #include "views/infrared_progress_view.h" #include "views/infrared_debug_view.h" +#include "views/infrared_move_view.h" #include "rpc/rpc_app.h" @@ -61,8 +62,6 @@ typedef enum { InfraredEditModeNone, InfraredEditModeRename, InfraredEditModeDelete, - InfraredEditModeMove, - InfraredEditModeMoveSelectDest } InfraredEditMode; typedef struct { @@ -98,6 +97,7 @@ struct Infrared { ViewStack* view_stack; InfraredDebugView* debug_view; + InfraredMoveView* move_view; ButtonPanel* button_panel; Loading* loading; @@ -119,6 +119,7 @@ typedef enum { InfraredViewPopup, InfraredViewStack, InfraredViewDebugView, + InfraredViewMove, } InfraredView; typedef enum { diff --git a/applications/main/infrared/infrared_remote.c b/applications/main/infrared/infrared_remote.c index a04a338baa..70d1b59ef3 100644 --- a/applications/main/infrared/infrared_remote.c +++ b/applications/main/infrared/infrared_remote.c @@ -108,19 +108,13 @@ bool infrared_remote_delete_button(InfraredRemote* remote, size_t index) { return infrared_remote_store(remote); } -bool infrared_remote_move_button(InfraredRemote* remote, size_t index_orig, size_t index_dest) { +void infrared_remote_move_button(InfraredRemote* remote, size_t index_orig, size_t index_dest) { furi_assert(index_orig < InfraredButtonArray_size(remote->buttons)); - furi_assert(index_dest <= InfraredButtonArray_size(remote->buttons)); - if(index_orig == index_dest) { - return true; - } + furi_assert(index_dest < InfraredButtonArray_size(remote->buttons)); + InfraredRemoteButton* button; InfraredButtonArray_pop_at(&button, remote->buttons, index_orig); - if(index_orig > index_dest) - InfraredButtonArray_push_at(remote->buttons, index_dest, button); - else - InfraredButtonArray_push_at(remote->buttons, index_dest - 1, button); - return infrared_remote_store(remote); + InfraredButtonArray_push_at(remote->buttons, index_dest, button); } bool infrared_remote_store(InfraredRemote* remote) { diff --git a/applications/main/infrared/infrared_remote.h b/applications/main/infrared/infrared_remote.h index 2640149a48..47aa77e2ef 100644 --- a/applications/main/infrared/infrared_remote.h +++ b/applications/main/infrared/infrared_remote.h @@ -23,7 +23,7 @@ bool infrared_remote_find_button_by_name(InfraredRemote* remote, const char* nam bool infrared_remote_add_button(InfraredRemote* remote, const char* name, InfraredSignal* signal); bool infrared_remote_rename_button(InfraredRemote* remote, const char* new_name, size_t index); bool infrared_remote_delete_button(InfraredRemote* remote, size_t index); -bool infrared_remote_move_button(InfraredRemote* remote, size_t index_orig, size_t index_dest); +void infrared_remote_move_button(InfraredRemote* remote, size_t index_orig, size_t index_dest); bool infrared_remote_store(InfraredRemote* remote); bool infrared_remote_load(InfraredRemote* remote, FuriString* path); diff --git a/applications/main/infrared/scenes/infrared_scene_config.h b/applications/main/infrared/scenes/infrared_scene_config.h index 77ae82af2a..40b22a7ef4 100644 --- a/applications/main/infrared/scenes/infrared_scene_config.h +++ b/applications/main/infrared/scenes/infrared_scene_config.h @@ -8,7 +8,6 @@ ADD_SCENE(infrared, edit_button_select, EditButtonSelect) ADD_SCENE(infrared, edit_rename, EditRename) ADD_SCENE(infrared, edit_rename_done, EditRenameDone) ADD_SCENE(infrared, edit_move, EditMove) -ADD_SCENE(infrared, edit_move_done, EditMoveDone) ADD_SCENE(infrared, learn, Learn) ADD_SCENE(infrared, learn_done, LearnDone) ADD_SCENE(infrared, learn_enter_name, LearnEnterName) diff --git a/applications/main/infrared/scenes/infrared_scene_edit.c b/applications/main/infrared/scenes/infrared_scene_edit.c index 79de04bda6..02bba7a3f4 100644 --- a/applications/main/infrared/scenes/infrared_scene_edit.c +++ b/applications/main/infrared/scenes/infrared_scene_edit.c @@ -82,9 +82,7 @@ bool infrared_scene_edit_on_event(void* context, SceneManagerEvent event) { scene_manager_next_scene(scene_manager, InfraredSceneEditButtonSelect); consumed = true; } else if(submenu_index == SubmenuIndexMoveButton) { - infrared->app_state.edit_target = InfraredEditTargetButton; - infrared->app_state.edit_mode = InfraredEditModeMove; - scene_manager_next_scene(scene_manager, InfraredSceneEditButtonSelect); + scene_manager_next_scene(scene_manager, InfraredSceneEditMove); consumed = true; } else if(submenu_index == SubmenuIndexDeleteButton) { infrared->app_state.edit_target = InfraredEditTargetButton; diff --git a/applications/main/infrared/scenes/infrared_scene_edit_button_select.c b/applications/main/infrared/scenes/infrared_scene_edit_button_select.c index 7056a20539..5f5a1d8fac 100644 --- a/applications/main/infrared/scenes/infrared_scene_edit_button_select.c +++ b/applications/main/infrared/scenes/infrared_scene_edit_button_select.c @@ -11,23 +11,9 @@ void infrared_scene_edit_button_select_on_enter(void* context) { InfraredRemote* remote = infrared->remote; InfraredAppState* app_state = &infrared->app_state; - const char* header = NULL; - switch(infrared->app_state.edit_mode) { - case InfraredEditModeRename: - header = "Rename Button:"; - break; - case InfraredEditModeDelete: - header = "Delete Button:"; - break; - case InfraredEditModeMove: - header = "Select Button to Move:"; - break; - case InfraredEditModeMoveSelectDest: - case InfraredEditModeNone: - default: - header = "Move Button Before:"; - break; - } + const char* header = infrared->app_state.edit_mode == InfraredEditModeRename ? + "Rename Button:" : + "Delete Button:"; submenu_set_header(submenu, header); const size_t button_count = infrared_remote_get_button_count(remote); @@ -40,14 +26,6 @@ void infrared_scene_edit_button_select_on_enter(void* context) { infrared_scene_edit_button_select_submenu_callback, context); } - if(infrared->app_state.edit_mode == InfraredEditModeMoveSelectDest) { - submenu_add_item( - submenu, - "-- Move to the end --", - button_count, - infrared_scene_edit_button_select_submenu_callback, - context); - } if(button_count && app_state->current_button_index != InfraredButtonIndexNone) { submenu_set_selected_item(submenu, app_state->current_button_index); app_state->current_button_index = InfraredButtonIndexNone; @@ -69,12 +47,6 @@ bool infrared_scene_edit_button_select_on_event(void* context, SceneManagerEvent scene_manager_next_scene(scene_manager, InfraredSceneEditRename); } else if(edit_mode == InfraredEditModeDelete) { scene_manager_next_scene(scene_manager, InfraredSceneEditDelete); - } else if(edit_mode == InfraredEditModeMove) { - app_state->current_button_index_move_orig = event.event; - app_state->edit_mode = InfraredEditModeMoveSelectDest; - scene_manager_next_scene(scene_manager, InfraredSceneEditButtonSelect); - } else if(edit_mode == InfraredEditModeMoveSelectDest) { - scene_manager_next_scene(scene_manager, InfraredSceneEditMove); } else { furi_assert(0); } diff --git a/applications/main/infrared/scenes/infrared_scene_edit_move.c b/applications/main/infrared/scenes/infrared_scene_edit_move.c index 69c7ec41de..370c352dbd 100644 --- a/applications/main/infrared/scenes/infrared_scene_edit_move.c +++ b/applications/main/infrared/scenes/infrared_scene_edit_move.c @@ -1,103 +1,44 @@ #include "../infrared_i.h" -static void infrared_scene_edit_move_dialog_result_callback(DialogExResult result, void* context) { - Infrared* infrared = context; - view_dispatcher_send_custom_event(infrared->view_dispatcher, result); +static void infrared_scene_move_button(uint32_t index_old, uint32_t index_new, void* context) { + InfraredRemote* remote = context; + furi_assert(remote); + infrared_remote_move_button(remote, index_old, index_new); +} + +static const char* infrared_scene_get_btn_name(uint32_t index, void* context) { + InfraredRemote* remote = context; + furi_assert(remote); + InfraredRemoteButton* button = infrared_remote_get_button(remote, index); + return (infrared_remote_button_get_name(button)); } void infrared_scene_edit_move_on_enter(void* context) { Infrared* infrared = context; - DialogEx* dialog_ex = infrared->dialog_ex; InfraredRemote* remote = infrared->remote; - const InfraredEditTarget edit_target = infrared->app_state.edit_target; - if(edit_target == InfraredEditTargetButton) { - int32_t current_button_index = infrared->app_state.current_button_index_move_orig; - furi_assert(current_button_index != InfraredButtonIndexNone); - - dialog_ex_set_header(dialog_ex, "Move Button?", 64, 0, AlignCenter, AlignTop); - InfraredRemoteButton* current_button = - infrared_remote_get_button(remote, current_button_index); - InfraredSignal* signal = infrared_remote_button_get_signal(current_button); - - if(infrared_signal_is_raw(signal)) { - const InfraredRawSignal* raw = infrared_signal_get_raw_signal(signal); - infrared_text_store_set( - infrared, - 0, - "%s\nRAW\n%ld samples", - infrared_remote_button_get_name(current_button), - raw->timings_size); - - } else { - const InfraredMessage* message = infrared_signal_get_message(signal); - infrared_text_store_set( - infrared, - 0, - "%s\n%s\nA=0x%0*lX C=0x%0*lX", - infrared_remote_button_get_name(current_button), - infrared_get_protocol_name(message->protocol), - ROUND_UP_TO(infrared_get_protocol_address_length(message->protocol), 4), - message->address, - ROUND_UP_TO(infrared_get_protocol_command_length(message->protocol), 4), - message->command); - } - } else { - furi_assert(0); - } + infrared_move_view_set_callback(infrared->move_view, infrared_scene_move_button); - dialog_ex_set_text(dialog_ex, infrared->text_store[0], 64, 31, AlignCenter, AlignCenter); - dialog_ex_set_icon(dialog_ex, 0, 0, NULL); - dialog_ex_set_left_button_text(dialog_ex, "Cancel"); - dialog_ex_set_right_button_text(dialog_ex, "Move"); - dialog_ex_set_result_callback(dialog_ex, infrared_scene_edit_move_dialog_result_callback); - dialog_ex_set_context(dialog_ex, context); + uint32_t btn_count = infrared_remote_get_button_count(remote); + infrared_move_view_list_init( + infrared->move_view, btn_count, infrared_scene_get_btn_name, remote); + infrared_move_view_list_update(infrared->move_view); - view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewDialogEx); + view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewMove); } bool infrared_scene_edit_move_on_event(void* context, SceneManagerEvent event) { Infrared* infrared = context; - SceneManager* scene_manager = infrared->scene_manager; bool consumed = false; - if(event.type == SceneManagerEventTypeCustom) { - if(event.event == DialogExResultLeft) { - scene_manager_previous_scene(scene_manager); - consumed = true; - } else if(event.event == DialogExResultRight) { - bool success = false; - InfraredRemote* remote = infrared->remote; - InfraredAppState* app_state = &infrared->app_state; - const InfraredEditTarget edit_target = app_state->edit_target; - - if(edit_target == InfraredEditTargetButton) { - furi_assert(app_state->current_button_index != InfraredButtonIndexNone); - success = infrared_remote_move_button( - remote, - app_state->current_button_index_move_orig, - app_state->current_button_index); - app_state->current_button_index_move_orig = InfraredButtonIndexNone; - app_state->current_button_index = InfraredButtonIndexNone; - } else { - furi_assert(0); - } - - if(success) { - scene_manager_next_scene(scene_manager, InfraredSceneEditMoveDone); - } else { - const uint32_t possible_scenes[] = {InfraredSceneRemoteList, InfraredSceneStart}; - scene_manager_search_and_switch_to_previous_scene_one_of( - scene_manager, possible_scenes, COUNT_OF(possible_scenes)); - } - consumed = true; - } - } + UNUSED(event); + UNUSED(infrared); return consumed; } void infrared_scene_edit_move_on_exit(void* context) { Infrared* infrared = context; - UNUSED(infrared); + InfraredRemote* remote = infrared->remote; + infrared_remote_store(remote); } diff --git a/applications/main/infrared/scenes/infrared_scene_edit_move_done.c b/applications/main/infrared/scenes/infrared_scene_edit_move_done.c deleted file mode 100644 index 9f9b4b80d3..0000000000 --- a/applications/main/infrared/scenes/infrared_scene_edit_move_done.c +++ /dev/null @@ -1,48 +0,0 @@ -#include "../infrared_i.h" - -void infrared_scene_edit_move_done_on_enter(void* context) { - Infrared* infrared = context; - Popup* popup = infrared->popup; - - popup_set_icon(popup, 0, 2, &I_DolphinMafia_115x62); - popup_set_header(popup, "Moved", 83, 19, AlignLeft, AlignBottom); - - popup_set_callback(popup, infrared_popup_closed_callback); - popup_set_context(popup, context); - popup_set_timeout(popup, 1500); - popup_enable_timeout(popup); - - view_dispatcher_switch_to_view(infrared->view_dispatcher, InfraredViewPopup); -} - -bool infrared_scene_edit_move_done_on_event(void* context, SceneManagerEvent event) { - Infrared* infrared = context; - SceneManager* scene_manager = infrared->scene_manager; - bool consumed = false; - - if(event.type == SceneManagerEventTypeCustom) { - if(event.event == InfraredCustomEventTypePopupClosed) { - const InfraredEditTarget edit_target = infrared->app_state.edit_target; - if(edit_target == InfraredEditTargetButton) { - scene_manager_search_and_switch_to_previous_scene( - scene_manager, InfraredSceneRemote); - } else if(edit_target == InfraredEditTargetRemote) { - const uint32_t possible_scenes[] = {InfraredSceneStart, InfraredSceneRemoteList}; - if(!scene_manager_search_and_switch_to_previous_scene_one_of( - scene_manager, possible_scenes, COUNT_OF(possible_scenes))) { - view_dispatcher_stop(infrared->view_dispatcher); - } - } else { - furi_assert(0); - } - consumed = true; - } - } - - return consumed; -} - -void infrared_scene_edit_move_done_on_exit(void* context) { - Infrared* infrared = context; - UNUSED(infrared); -} diff --git a/applications/main/infrared/views/infrared_move_view.c b/applications/main/infrared/views/infrared_move_view.c new file mode 100644 index 0000000000..d838a5f828 --- /dev/null +++ b/applications/main/infrared/views/infrared_move_view.c @@ -0,0 +1,215 @@ +#include "infrared_move_view.h" + +#include +#include + +#include +#include + +#define LIST_ITEMS 4U +#define LIST_LINE_H 13U +#define HEADER_H 12U +#define MOVE_X_OFFSET 5U + +struct InfraredMoveView { + View* view; + InfraredMoveCallback move_cb; + void* cb_context; +}; + +typedef struct { + const char** btn_names; + uint32_t btn_number; + int32_t list_offset; + int32_t item_idx; + bool is_moving; + + InfraredMoveGetItemCallback get_item_cb; +} InfraredMoveViewModel; + +static void infrared_move_view_draw_callback(Canvas* canvas, void* _model) { + InfraredMoveViewModel* model = _model; + + UNUSED(model); + + canvas_set_color(canvas, ColorBlack); + canvas_set_font(canvas, FontPrimary); + elements_multiline_text_aligned( + canvas, canvas_width(canvas) / 2, 0, AlignCenter, AlignTop, "Select a button to move"); + + bool show_scrollbar = model->btn_number > LIST_ITEMS; + + canvas_set_font(canvas, FontSecondary); + + for(uint32_t i = 0; i < MIN(model->btn_number, LIST_ITEMS); i++) { + int32_t idx = CLAMP((uint32_t)(i + model->list_offset), model->btn_number, 0u); + uint8_t x_offset = (model->is_moving && model->item_idx == idx) ? MOVE_X_OFFSET : 0; + uint8_t y_offset = HEADER_H + i * LIST_LINE_H; + uint8_t box_end_x = canvas_width(canvas) - (show_scrollbar ? 6 : 1); + + canvas_set_color(canvas, ColorBlack); + if(model->item_idx == idx) { + canvas_draw_box(canvas, x_offset, y_offset, box_end_x - x_offset, LIST_LINE_H); + + canvas_set_color(canvas, ColorWhite); + canvas_draw_dot(canvas, x_offset, y_offset); + canvas_draw_dot(canvas, x_offset + 1, y_offset); + canvas_draw_dot(canvas, x_offset, y_offset + 1); + canvas_draw_dot(canvas, x_offset, y_offset + LIST_LINE_H - 1); + canvas_draw_dot(canvas, box_end_x - 1, y_offset); + canvas_draw_dot(canvas, box_end_x - 1, y_offset + LIST_LINE_H - 1); + } + canvas_draw_str_aligned( + canvas, x_offset + 3, y_offset + 3, AlignLeft, AlignTop, model->btn_names[idx]); + } + + if(show_scrollbar) { + elements_scrollbar_pos( + canvas, + canvas_width(canvas), + HEADER_H, + canvas_height(canvas) - HEADER_H, + model->item_idx, + model->btn_number); + } +} + +static void update_list_offset(InfraredMoveViewModel* model) { + int32_t bounds = model->btn_number > (LIST_ITEMS - 1) ? 2 : model->btn_number; + + if((model->btn_number > (LIST_ITEMS - 1)) && + (model->item_idx >= ((int32_t)model->btn_number - 1))) { + model->list_offset = model->item_idx - (LIST_ITEMS - 1); + } else if(model->list_offset < model->item_idx - bounds) { + model->list_offset = CLAMP( + model->item_idx - (int32_t)(LIST_ITEMS - 2), (int32_t)model->btn_number - bounds, 0); + } else if(model->list_offset > model->item_idx - bounds) { + model->list_offset = CLAMP(model->item_idx - 1, (int32_t)model->btn_number - bounds, 0); + } +} + +static bool infrared_move_view_input_callback(InputEvent* event, void* context) { + InfraredMoveView* move_view = context; + + bool consumed = false; + + if(((event->type == InputTypeShort || event->type == InputTypeRepeat)) && + ((event->key == InputKeyUp) || (event->key == InputKeyDown))) { + bool is_moving = false; + uint32_t index_old = 0; + uint32_t index_new = 0; + with_view_model( + move_view->view, + InfraredMoveViewModel * model, + { + is_moving = model->is_moving; + index_old = model->item_idx; + if(event->key == InputKeyUp) { + if(model->item_idx <= 0) { + model->item_idx = model->btn_number; + } + model->item_idx--; + } else if(event->key == InputKeyDown) { + model->item_idx++; + if(model->item_idx >= (int32_t)(model->btn_number)) { + model->item_idx = 0; + } + } + index_new = model->item_idx; + update_list_offset(model); + }, + !is_moving); + if((is_moving) && (move_view->move_cb)) { + move_view->move_cb(index_old, index_new, move_view->cb_context); + infrared_move_view_list_update(move_view); + } + consumed = true; + } + + if((event->key == InputKeyOk) && (event->type == InputTypeShort)) { + with_view_model( + move_view->view, + InfraredMoveViewModel * model, + { model->is_moving = !(model->is_moving); }, + true); + consumed = true; + } + return consumed; +} + +static void infrared_move_view_on_exit(void* context) { + furi_assert(context); + InfraredMoveView* move_view = context; + + with_view_model( + move_view->view, + InfraredMoveViewModel * model, + { + if(model->btn_names) { + free(model->btn_names); + model->btn_names = NULL; + } + model->btn_number = 0; + model->get_item_cb = NULL; + }, + false); + move_view->cb_context = NULL; +} + +void infrared_move_view_set_callback(InfraredMoveView* move_view, InfraredMoveCallback callback) { + furi_assert(move_view); + move_view->move_cb = callback; +} + +void infrared_move_view_list_init( + InfraredMoveView* move_view, + uint32_t item_count, + InfraredMoveGetItemCallback load_cb, + void* context) { + furi_assert(move_view); + move_view->cb_context = context; + with_view_model( + move_view->view, + InfraredMoveViewModel * model, + { + furi_assert(model->btn_names == NULL); + model->btn_names = malloc(sizeof(char*) * item_count); + model->btn_number = item_count; + model->get_item_cb = load_cb; + }, + false); +} + +void infrared_move_view_list_update(InfraredMoveView* move_view) { + furi_assert(move_view); + with_view_model( + move_view->view, + InfraredMoveViewModel * model, + { + for(uint32_t i = 0; i < model->btn_number; i++) { + if(!model->get_item_cb) break; + model->btn_names[i] = model->get_item_cb(i, move_view->cb_context); + } + }, + true); +} + +InfraredMoveView* infrared_move_view_alloc(void) { + InfraredMoveView* move_view = malloc(sizeof(InfraredMoveView)); + move_view->view = view_alloc(); + view_allocate_model(move_view->view, ViewModelTypeLocking, sizeof(InfraredMoveViewModel)); + view_set_draw_callback(move_view->view, infrared_move_view_draw_callback); + view_set_input_callback(move_view->view, infrared_move_view_input_callback); + view_set_exit_callback(move_view->view, infrared_move_view_on_exit); + view_set_context(move_view->view, move_view); + return move_view; +} + +void infrared_move_view_free(InfraredMoveView* move_view) { + view_free(move_view->view); + free(move_view); +} + +View* infrared_move_view_get_view(InfraredMoveView* move_view) { + return move_view->view; +} diff --git a/applications/main/infrared/views/infrared_move_view.h b/applications/main/infrared/views/infrared_move_view.h new file mode 100644 index 0000000000..b9b0cd864a --- /dev/null +++ b/applications/main/infrared/views/infrared_move_view.h @@ -0,0 +1,25 @@ +#pragma once + +#include + +typedef struct InfraredMoveView InfraredMoveView; + +typedef void (*InfraredMoveCallback)(uint32_t index_old, uint32_t index_new, void* context); + +typedef const char* (*InfraredMoveGetItemCallback)(uint32_t index, void* context); + +InfraredMoveView* infrared_move_view_alloc(void); + +void infrared_move_view_free(InfraredMoveView* debug_view); + +View* infrared_move_view_get_view(InfraredMoveView* debug_view); + +void infrared_move_view_set_callback(InfraredMoveView* move_view, InfraredMoveCallback callback); + +void infrared_move_view_list_init( + InfraredMoveView* move_view, + uint32_t item_count, + InfraredMoveGetItemCallback load_cb, + void* context); + +void infrared_move_view_list_update(InfraredMoveView* move_view); \ No newline at end of file From d30510f70024afee9cad000bfb7919cecd1b5b37 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 5 Aug 2023 14:02:32 +0300 Subject: [PATCH 34/44] upd subbrute --- applications/external/subbrute | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/applications/external/subbrute b/applications/external/subbrute index a2d198782d..32290f6b5f 160000 --- a/applications/external/subbrute +++ b/applications/external/subbrute @@ -1 +1 @@ -Subproject commit a2d198782d456f0be3b1da31c28164a5a7f93a7d +Subproject commit 32290f6b5f30f9ca8a0ee95213d1c1ffcca1ae80 From 07f6859a8030746c7d174e0888875a0854d6faf0 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 5 Aug 2023 14:16:02 +0300 Subject: [PATCH 35/44] update changelog --- CHANGELOG.md | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8aad209a6d..4db4311900 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,21 @@ ## New changes -* SubGHz: Support for Ebyte E07 module power amp switch (works with TehRabbitt's Flux Capacitor Board) (by @Sil333033) (PR #559 by @Z3BRO) -> Remade by @xMasterX +* SubGHz: Support for Ebyte E07 module power amp switch (works with TehRabbitt's Flux Capacitor Board) (by @Sil333033) (PR #559 by @Z3BRO) -> Remade by @xMasterX -> Driver code fixed and reworked by @gid9798 +* Plugins: Update TOTP (Authenticator) [(by akopachov)](https://github.com/akopachov/flipper-zero_authenticator) * Plugins: Update ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-wifi-marauder) * Plugins: Update ESP32-CAM -> Camera Suite [(by CodyTolene)](https://github.com/CodyTolene/Flipper-Zero-Camera-Suite) -> (PR #562 by @CodyTolene) +* OFW PR 2949: IR: buttons move feature rework (by nminaylov) +* OFW PR 2941: FDX-B temperature now uses system units (by Astrrra) +* OFW: fbtenv: add additional environ variable to control execution flow +* OFW: NFC CLI: Fix multiple apdu commands from not working when one of them gives an empty response +* OFW: NFC: Fix MFC key invalidation +* OFW: Rename Applications to Apps +* OFW: Fix about screen +* OFW: change FuriThreadPriorityIsr to 31 (configMAX_PRIORITIES-1) +* OFW: External apps icounter +* OFW: Overly missed feature: Infrared: move button (change button order in a remote) +* OFW: Move U2F path to ext +* OFW: New RTC flags in device info +* OFW: Backlight notification fix * OFW: Fix fbtenv restore ---- From f70d2b5ae7f1aa47e234450c9654c4aceb0fa1cc Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 5 Aug 2023 14:25:16 +0300 Subject: [PATCH 36/44] revert old nfc debug defines was used to save space --- applications/main/nfc/scenes/nfc_scene_config.h | 4 ---- applications/main/nfc/scenes/nfc_scene_debug.c | 2 -- .../main/nfc/scenes/nfc_scene_emulate_apdu_sequence.c | 2 -- applications/main/nfc/scenes/nfc_scene_field.c | 2 -- applications/main/nfc/scenes/nfc_scene_start.c | 11 +++-------- lib/nfc/nfc_worker.c | 11 +++-------- lib/nfc/protocols/emv.c | 6 ++---- 7 files changed, 8 insertions(+), 30 deletions(-) diff --git a/applications/main/nfc/scenes/nfc_scene_config.h b/applications/main/nfc/scenes/nfc_scene_config.h index aea59957d8..f11d147983 100644 --- a/applications/main/nfc/scenes/nfc_scene_config.h +++ b/applications/main/nfc/scenes/nfc_scene_config.h @@ -53,18 +53,14 @@ ADD_SCENE(nfc, mf_classic_update_success, MfClassicUpdateSuccess) ADD_SCENE(nfc, mf_classic_wrong_card, MfClassicWrongCard) ADD_SCENE(nfc, emv_read_success, EmvReadSuccess) ADD_SCENE(nfc, emv_menu, EmvMenu) -#if FURI_DEBUG ADD_SCENE(nfc, emulate_apdu_sequence, EmulateApduSequence) -#endif ADD_SCENE(nfc, device_info, DeviceInfo) ADD_SCENE(nfc, delete, Delete) ADD_SCENE(nfc, delete_success, DeleteSuccess) ADD_SCENE(nfc, restore_original_confirm, RestoreOriginalConfirm) ADD_SCENE(nfc, restore_original, RestoreOriginal) -#if FURI_DEBUG ADD_SCENE(nfc, debug, Debug) ADD_SCENE(nfc, field, Field) -#endif ADD_SCENE(nfc, dict_not_found, DictNotFound) ADD_SCENE(nfc, rpc, Rpc) ADD_SCENE(nfc, exit_confirm, ExitConfirm) diff --git a/applications/main/nfc/scenes/nfc_scene_debug.c b/applications/main/nfc/scenes/nfc_scene_debug.c index 5dc29c96af..ed079c2ed9 100644 --- a/applications/main/nfc/scenes/nfc_scene_debug.c +++ b/applications/main/nfc/scenes/nfc_scene_debug.c @@ -1,4 +1,3 @@ -#if FURI_DEBUG #include "../nfc_i.h" enum SubmenuDebugIndex { @@ -53,4 +52,3 @@ void nfc_scene_debug_on_exit(void* context) { submenu_reset(nfc->submenu); } -#endif \ No newline at end of file diff --git a/applications/main/nfc/scenes/nfc_scene_emulate_apdu_sequence.c b/applications/main/nfc/scenes/nfc_scene_emulate_apdu_sequence.c index bc3f0f42d7..358ad2ab6f 100644 --- a/applications/main/nfc/scenes/nfc_scene_emulate_apdu_sequence.c +++ b/applications/main/nfc/scenes/nfc_scene_emulate_apdu_sequence.c @@ -1,4 +1,3 @@ -#if FURI_DEBUG #include "../nfc_i.h" #include @@ -33,4 +32,3 @@ void nfc_scene_emulate_apdu_sequence_on_exit(void* context) { nfc_blink_stop(nfc); } -#endif \ No newline at end of file diff --git a/applications/main/nfc/scenes/nfc_scene_field.c b/applications/main/nfc/scenes/nfc_scene_field.c index f287e8796d..e3eb6a7088 100644 --- a/applications/main/nfc/scenes/nfc_scene_field.c +++ b/applications/main/nfc/scenes/nfc_scene_field.c @@ -1,4 +1,3 @@ -#if FURI_DEBUG #include "../nfc_i.h" void nfc_scene_field_on_enter(void* context) { @@ -32,4 +31,3 @@ void nfc_scene_field_on_exit(void* context) { notification_internal_message(nfc->notifications, &sequence_reset_blue); popup_reset(nfc->popup); } -#endif \ No newline at end of file diff --git a/applications/main/nfc/scenes/nfc_scene_start.c b/applications/main/nfc/scenes/nfc_scene_start.c index 87a0427d30..c9e8bf78cf 100644 --- a/applications/main/nfc/scenes/nfc_scene_start.c +++ b/applications/main/nfc/scenes/nfc_scene_start.c @@ -8,9 +8,7 @@ enum SubmenuIndex { SubmenuIndexSaved, SubmenuIndexExtraAction, SubmenuIndexAddManually, -#if FURI_DEBUG SubmenuIndexDebug, -#endif }; void nfc_scene_start_submenu_callback(void* context, uint32_t index) { @@ -31,12 +29,12 @@ void nfc_scene_start_on_enter(void* context) { submenu, "Extra Actions", SubmenuIndexExtraAction, nfc_scene_start_submenu_callback, nfc); submenu_add_item( submenu, "Add Manually", SubmenuIndexAddManually, nfc_scene_start_submenu_callback, nfc); -#if FURI_DEBUG + if(furi_hal_rtc_is_flag_set(FuriHalRtcFlagDebug)) { submenu_add_item( submenu, "Debug", SubmenuIndexDebug, nfc_scene_start_submenu_callback, nfc); } -#endif + submenu_set_selected_item( submenu, scene_manager_get_scene_state(nfc->scene_manager, NfcSceneStart)); @@ -84,14 +82,11 @@ bool nfc_scene_start_on_event(void* context, SceneManagerEvent event) { nfc->scene_manager, NfcSceneStart, SubmenuIndexAddManually); scene_manager_next_scene(nfc->scene_manager, NfcSceneSetType); consumed = true; - } -#if FURI_DEBUG - else if(event.event == SubmenuIndexDebug) { + } else if(event.event == SubmenuIndexDebug) { scene_manager_set_scene_state(nfc->scene_manager, NfcSceneStart, SubmenuIndexDebug); scene_manager_next_scene(nfc->scene_manager, NfcSceneDebug); consumed = true; } -#endif } return consumed; } diff --git a/lib/nfc/nfc_worker.c b/lib/nfc/nfc_worker.c index 857b6ac825..77c95de347 100644 --- a/lib/nfc/nfc_worker.c +++ b/lib/nfc/nfc_worker.c @@ -95,13 +95,9 @@ int32_t nfc_worker_task(void* context) { } } else if(nfc_worker->state == NfcWorkerStateUidEmulate) { nfc_worker_emulate_uid(nfc_worker); - } -#if FURI_DEBUG - else if(nfc_worker->state == NfcWorkerStateEmulateApdu) { + } else if(nfc_worker->state == NfcWorkerStateEmulateApdu) { nfc_worker_emulate_apdu(nfc_worker); - } -#endif - else if(nfc_worker->state == NfcWorkerStateMfUltralightEmulate) { + } else if(nfc_worker->state == NfcWorkerStateMfUltralightEmulate) { nfc_worker_emulate_mf_ultralight(nfc_worker); } else if(nfc_worker->state == NfcWorkerStateMfClassicEmulate) { nfc_worker_emulate_mf_classic(nfc_worker); @@ -755,7 +751,7 @@ void nfc_worker_emulate_uid(NfcWorker* nfc_worker) { } } } -#if FURI_DEBUG + void nfc_worker_emulate_apdu(NfcWorker* nfc_worker) { FuriHalNfcTxRxContext tx_rx = {}; FuriHalNfcDevData params = { @@ -788,7 +784,6 @@ void nfc_worker_emulate_apdu(NfcWorker* nfc_worker) { reader_analyzer_stop(nfc_worker->reader_analyzer); } } -#endif void nfc_worker_mf_ultralight_auth_received_callback(MfUltralightAuth auth, void* context) { furi_assert(context); diff --git a/lib/nfc/protocols/emv.c b/lib/nfc/protocols/emv.c index 8cc5fc44ef..4c4ac856b1 100644 --- a/lib/nfc/protocols/emv.c +++ b/lib/nfc/protocols/emv.c @@ -44,7 +44,7 @@ const PDOLValue* const pdol_values[] = { &pdol_transaction_cert, &pdol_unpredict_number, }; -#if FURI_DEBUG + static const uint8_t select_ppse_ans[] = {0x6F, 0x29, 0x84, 0x0E, 0x32, 0x50, 0x41, 0x59, 0x2E, 0x53, 0x59, 0x53, 0x2E, 0x44, 0x44, 0x46, 0x30, 0x31, 0xA5, 0x17, 0xBF, 0x0C, 0x14, 0x61, 0x12, 0x4F, 0x07, @@ -61,7 +61,7 @@ static const uint8_t pdol_ans[] = {0x77, 0x40, 0x82, 0x02, 0x20, 0x00, 0x57, 0x1 0x00, 0x9F, 0x26, 0x08, 0x7A, 0x65, 0x7F, 0xD3, 0x52, 0x96, 0xC9, 0x85, 0x9F, 0x27, 0x01, 0x00, 0x9F, 0x36, 0x02, 0x06, 0x0C, 0x9F, 0x6C, 0x02, 0x10, 0x00, 0x90, 0x00}; -#endif + static void emv_trace(FuriHalNfcTxRxContext* tx_rx, const char* message) { if(furi_log_get_level() == FuriLogLevelTrace) { FURI_LOG_T(TAG, "%s", message); @@ -409,7 +409,6 @@ bool emv_read_bank_card(FuriHalNfcTxRxContext* tx_rx, EmvApplication* emv_app) { return card_num_read; } -#if FURI_DEBUG bool emv_card_emulation(FuriHalNfcTxRxContext* tx_rx) { furi_assert(tx_rx); bool emulation_complete = false; @@ -443,4 +442,3 @@ bool emv_card_emulation(FuriHalNfcTxRxContext* tx_rx) { return emulation_complete; } -#endif \ No newline at end of file From 0f61a8eb4677343947e5860e923b35d961517dda Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 5 Aug 2023 14:28:24 +0300 Subject: [PATCH 37/44] upd changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4db4311900..dd2dbf9e5c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## New changes * SubGHz: Support for Ebyte E07 module power amp switch (works with TehRabbitt's Flux Capacitor Board) (by @Sil333033) (PR #559 by @Z3BRO) -> Remade by @xMasterX -> Driver code fixed and reworked by @gid9798 +* Infrared: Update universal AC asset (by @Leptopt1los | PR #569) * Plugins: Update TOTP (Authenticator) [(by akopachov)](https://github.com/akopachov/flipper-zero_authenticator) * Plugins: Update ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-wifi-marauder) * Plugins: Update ESP32-CAM -> Camera Suite [(by CodyTolene)](https://github.com/CodyTolene/Flipper-Zero-Camera-Suite) -> (PR #562 by @CodyTolene) From c1438ce85083722fd58ce834325a287c771ef2c2 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 5 Aug 2023 15:08:56 +0300 Subject: [PATCH 38/44] remove unused variable --- applications/services/desktop/scenes/desktop_scene_main.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/applications/services/desktop/scenes/desktop_scene_main.c b/applications/services/desktop/scenes/desktop_scene_main.c index 1de8a3cd87..d1b8df309d 100644 --- a/applications/services/desktop/scenes/desktop_scene_main.c +++ b/applications/services/desktop/scenes/desktop_scene_main.c @@ -12,8 +12,6 @@ #define TAG "DesktopSrv" -#define FAP_LOADER_APP_NAME "Applications" - static void desktop_scene_main_new_idle_animation_callback(void* context) { furi_assert(context); Desktop* desktop = context; From 49d2b31446c7a624a3b5c76754e7b95869714ab8 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 5 Aug 2023 15:25:06 +0300 Subject: [PATCH 39/44] Add extra symbol, upd readme, upd codeowners --- .github/CODEOWNERS | 2 +- CHANGELOG.md | 1 + ReadMe.md | 5 +++-- applications/external/nfc_maker/nfc_maker_text_input.c | 2 ++ 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index e2283966b0..33a9b8dbae 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -2,4 +2,4 @@ * @xMasterX # Assets -/assets/resources/infrared/ @xMasterX @amec0e \ No newline at end of file +/assets/resources/infrared/assets/ @amec0e @Leptopt1los @xMasterX \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index dd2dbf9e5c..f936411d0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ ## New changes * SubGHz: Support for Ebyte E07 module power amp switch (works with TehRabbitt's Flux Capacitor Board) (by @Sil333033) (PR #559 by @Z3BRO) -> Remade by @xMasterX -> Driver code fixed and reworked by @gid9798 * Infrared: Update universal AC asset (by @Leptopt1los | PR #569) +* Plugins: Add * in NFC Maker keyboard (hold `.`) * Plugins: Update TOTP (Authenticator) [(by akopachov)](https://github.com/akopachov/flipper-zero_authenticator) * Plugins: Update ESP32: WiFi Marauder companion plugin [(by 0xchocolate)](https://github.com/0xchocolate/flipperzero-wifi-marauder) * Plugins: Update ESP32-CAM -> Camera Suite [(by CodyTolene)](https://github.com/CodyTolene/Flipper-Zero-Camera-Suite) -> (PR #562 by @CodyTolene) diff --git a/ReadMe.md b/ReadMe.md index 1cedb8b6c4..40c81c3bad 100644 --- a/ReadMe.md +++ b/ReadMe.md @@ -114,9 +114,10 @@ Encoders made by @assasinfil & @xMasterX: The majority of this project is developed and maintained by me, @xMasterX. I'm unemployed, and the only income I receive is from your donations. Our team is small and the guys are working on this project as much as they can solely based on the enthusiasm they have for this project and the community. -- @assasinfil - SubGHz +- @gid9798 - SubGHz, Plugins, many other things +- @assasinfil - SubGHz protocols - @Svaarich - UI design and animations -- @Amec0e - Infrared assets +- @amec0e & @Leptopt1los - Infrared assets - Community moderators in Telegram, Discord, and Reddit - And of course our GitHub community. Your PRs are a very important part of this firmware and open-source development. diff --git a/applications/external/nfc_maker/nfc_maker_text_input.c b/applications/external/nfc_maker/nfc_maker_text_input.c index 64691b79ca..e6beb1f227 100644 --- a/applications/external/nfc_maker/nfc_maker_text_input.c +++ b/applications/external/nfc_maker/nfc_maker_text_input.c @@ -238,6 +238,8 @@ static char char_to_uppercase(const char letter) { return 0x5C; } else if(letter == '\'') { return 0x60; + } else if(letter == '.') { + return 0x2A; } else if(char_is_lowercase(letter)) { return (letter - 0x20); } else { From e50cab3da1e177e2119f45c587c05e7b90b3952d Mon Sep 17 00:00:00 2001 From: amec0e <88857687+amec0e@users.noreply.github.com> Date: Sat, 5 Aug 2023 15:35:47 +0100 Subject: [PATCH 40/44] Update audio.ir Updated last checked --- assets/resources/infrared/assets/audio.ir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/resources/infrared/assets/audio.ir b/assets/resources/infrared/assets/audio.ir index 11533746cd..da679b4e7f 100644 --- a/assets/resources/infrared/assets/audio.ir +++ b/assets/resources/infrared/assets/audio.ir @@ -1,7 +1,7 @@ Filetype: IR library file Version: 1 # Last Updated 24th Jul, 2023 -# Last Checked 24th Jul, 2023 +# Last Checked 5th Aug, 2023 # name: Power type: parsed From d11fdca90357c1a45a3923a072585439fba8abf1 Mon Sep 17 00:00:00 2001 From: amec0e <88857687+amec0e@users.noreply.github.com> Date: Sat, 5 Aug 2023 15:36:21 +0100 Subject: [PATCH 41/44] Update fans.ir New additions --- assets/resources/infrared/assets/fans.ir | 28 ++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/assets/resources/infrared/assets/fans.ir b/assets/resources/infrared/assets/fans.ir index bbae727a29..45cc810aba 100644 --- a/assets/resources/infrared/assets/fans.ir +++ b/assets/resources/infrared/assets/fans.ir @@ -1,7 +1,7 @@ Filetype: IR library file Version: 1 -# Last Updated 24th Jul, 2023 -# Last Checked 24th Jul, 2023 +# Last Updated 5th Aug, 2023 +# Last Checked 5th Aug, 2023 # name: Power type: raw @@ -1911,3 +1911,27 @@ type: raw frequency: 38000 duty_cycle: 0.330000 data: 1253 434 1258 435 492 1200 1258 438 1258 434 498 1194 494 1202 1257 433 494 1200 493 1200 493 1200 493 7940 1259 434 1258 433 493 1200 1259 438 1258 433 493 1199 494 1200 1259 434 492 1200 493 1200 493 1199 494 7939 1258 435 1257 434 497 1196 1258 437 1259 433 498 1196 492 1201 1258 434 497 1197 491 1200 493 1201 492 7941 1258 434 1258 435 495 1197 1258 437 1259 433 497 1197 497 1196 1259 434 496 1197 496 1197 496 1196 497 7939 1258 435 1257 434 495 1198 1258 438 1258 434 495 1198 495 1199 1257 435 494 1199 494 1197 496 1197 496 +# +name: Power +type: raw +frequency: 38000 +duty_cycle: 0.33 +data: 121 20917 311 387 1345 372 1316 372 450 1212 1319 400 1292 396 450 1210 479 1212 476 1238 450 1238 451 1238 451 1238 1345 7078 1316 372 1315 372 474 1216 1314 377 1314 374 472 1217 472 1217 472 1217 472 1217 472 1217 472 1217 1314 7106 1314 375 1313 374 472 1218 1313 378 1314 375 471 1218 471 1218 471 1218 471 1218 471 1218 471 1218 1313 7108 1312 376 1312 375 471 1219 1312 380 1312 376 470 1218 471 1218 471 1219 470 1218 471 1219 470 1219 1312 7110 1311 376 1312 376 470 1219 1312 381 1311 377 469 1219 470 1219 469 1220 469 1220 469 1220 469 1221 1310 7133 1286 402 1286 401 445 1245 1285 406 1286 401 445 1244 444 1244 445 1244 445 1244 445 1244 445 1245 1286 7134 1285 402 1286 402 444 1245 1286 406 1286 402 444 1245 444 1245 444 1245 444 1245 443 1245 444 1245 1285 7136 1284 403 1285 403 443 1245 1285 407 1285 403 443 1246 443 1246 443 1246 443 1246 443 1246 443 1246 1285 7135 1284 404 1284 404 442 1247 1284 408 1284 404 442 1247 442 1247 442 1247 442 1247 442 1248 441 1248 1283 7138 1282 405 1283 405 441 1249 1282 410 1281 407 440 1250 439 1249 440 1273 415 1274 390 1299 415 1274 1256 7166 1256 432 1256 431 415 1275 1255 436 1232 456 390 1299 415 1275 390 1299 390 1299 390 1299 390 1300 1231 7189 1231 457 1232 457 389 1301 1230 461 1231 458 388 1301 388 1301 388 1301 388 1326 363 1326 363 1327 1204 7217 1204 484 1205 484 362 1328 1203 488 1204 485 361 1328 361 1328 361 1328 361 1329 360 1353 335 1330 1202 7246 1177 511 1177 512 334 1356 1175 542 1150 539 307 1383 306 1383 306 1382 307 1409 280 1409 280 1410 1122 +# +name: Rotate +type: raw +frequency: 38000 +duty_cycle: 0.33 +data: 1293 396 1293 395 450 1238 1294 399 1293 395 450 1238 451 1238 1294 395 450 1237 452 1237 452 1237 452 7964 1294 395 1318 370 475 1215 1316 377 1315 397 448 1241 448 1242 1290 398 447 1242 447 1242 447 1242 447 7970 1290 398 1292 372 473 1217 1316 377 1315 397 448 1217 473 1217 1316 372 473 1216 473 1217 473 1216 473 7944 1316 373 1316 372 473 1217 1316 376 1316 372 473 1216 473 1217 1316 372 473 1216 473 1216 473 1216 473 7942 1318 372 1317 371 474 1216 1317 375 1317 371 473 1216 473 1216 1318 371 474 1216 473 1216 473 1216 473 7943 1318 371 1318 371 474 1216 1318 375 1317 371 474 1216 474 1216 1318 371 474 1216 473 1216 473 1216 474 7943 1317 372 1317 372 473 1217 1317 376 1316 372 473 1217 472 1217 1316 372 473 1217 472 1217 472 1217 472 7944 1314 375 1314 398 447 1243 1290 403 1289 398 447 1243 446 1244 1289 399 446 1243 447 1243 446 1243 446 7971 1289 400 1289 399 446 1244 1289 403 1289 399 446 1243 446 1244 1289 399 446 1244 446 1244 445 1244 445 7972 1288 400 1289 399 446 1244 1290 403 1289 399 446 1244 445 1244 1289 399 446 1244 446 1244 445 1244 445 7946 1288 401 1288 400 469 1222 1311 380 1312 399 445 1244 445 1245 1289 399 445 1244 445 1245 445 1244 446 7971 1289 400 1289 400 444 1246 1289 403 1289 400 443 1246 444 1245 1272 416 445 1244 420 1269 444 1245 420 7996 1288 401 1288 400 420 1270 1264 429 1263 425 419 1270 419 1270 1264 425 419 1270 419 1270 419 1270 419 7995 1262 426 1263 425 419 1270 1263 430 1262 425 419 1270 419 1271 1262 426 418 1271 418 1271 418 1271 418 +# +name: Timer +type: raw +frequency: 38000 +duty_cycle: 0.33 +data: 1321 393 1295 393 451 1211 1322 396 1295 393 451 1210 507 1182 507 1181 1351 364 479 1208 480 1208 480 7933 1322 366 1320 368 475 1213 1319 373 1318 370 474 1214 474 1215 474 1215 1317 371 473 1215 473 1215 473 7939 1315 372 1316 372 472 1216 1316 376 1315 373 471 1217 472 1218 470 1218 1313 398 446 1242 446 1242 446 7967 1262 425 1263 425 444 1245 1263 429 1287 400 445 1244 445 1243 446 1244 1288 400 445 1243 446 1243 446 7966 1288 400 1288 400 445 1244 1287 404 1288 400 445 1244 444 1244 444 1245 1286 401 444 1244 444 1245 444 7968 1261 426 1286 401 419 1270 1285 406 1285 402 444 1244 445 1244 445 1245 1287 400 444 1244 445 1244 444 7968 1288 400 1288 400 444 1244 1288 404 1287 399 445 1244 444 1244 445 1244 1263 425 444 1244 444 1244 444 7967 1261 427 1261 426 418 1272 1260 456 1235 452 392 1296 392 1296 393 1297 1235 453 392 1296 393 1296 393 7996 1261 427 1261 427 418 1270 1262 430 1285 402 444 1245 443 1245 444 1245 1286 402 444 1245 444 1245 444 7969 1286 402 1286 402 444 1245 1286 406 1285 402 444 1245 444 1245 444 1245 1286 402 444 1245 444 1245 444 7968 1284 403 1285 403 443 1246 1284 407 1284 403 443 1246 442 1246 443 1246 1284 403 443 1246 443 1246 442 7971 1284 405 1283 405 441 1247 1283 408 1283 405 441 1248 441 1248 440 1249 1281 406 440 1249 440 1249 440 7974 1281 408 1280 431 390 1299 1232 460 1256 432 389 1299 390 1299 389 1300 1231 456 390 1299 390 1299 390 8023 1231 457 1231 457 389 1300 1231 461 1230 458 388 1300 389 1301 388 1301 1230 458 388 1302 387 1301 388 8027 1228 484 1204 484 362 1327 1204 488 1203 484 362 1328 361 1328 361 1329 1202 486 360 1354 335 1329 360 8080 1176 512 1176 512 334 1356 1175 542 1149 539 306 1382 307 1384 305 1383 1149 566 279 1436 252 1410 279 +# +name: Mode +type: raw +frequency: 38000 +duty_cycle: 0.33 +data: 1373 341 1295 393 452 1211 1322 397 1295 393 451 1210 479 1210 479 1211 478 1237 1296 393 451 1236 453 7962 1321 367 1320 368 476 1214 1318 374 1318 370 474 1215 474 1215 474 1215 474 1216 1316 371 473 1215 474 7941 1316 372 1316 372 472 1217 1316 376 1316 372 473 1216 473 1216 473 1217 472 1217 1315 373 472 1217 472 7941 1315 374 1314 374 471 1218 1314 401 1291 398 447 1242 447 1242 447 1242 447 1243 1290 398 446 1242 447 7968 1290 399 1289 398 447 1243 1290 402 1290 398 447 1242 447 1242 447 1242 447 1243 1289 398 446 1243 446 7968 1289 399 1289 398 447 1243 1290 402 1290 398 446 1243 446 1243 446 1243 446 1243 1290 398 446 1243 446 7967 1289 399 1289 399 446 1244 1289 403 1289 398 446 1243 446 1243 446 1243 446 1244 1289 399 446 1243 446 7969 1288 400 1288 399 445 1244 1288 403 1288 400 445 1244 445 1244 445 1244 445 1244 1288 400 445 1244 420 7995 1261 427 1261 428 416 1296 1236 456 1236 452 392 1296 393 1296 393 1296 393 1296 1236 452 393 1296 393 7997 1260 428 1260 428 416 1273 1260 432 1259 428 417 1296 392 1272 417 1296 393 1296 1237 452 393 1296 393 8021 1236 452 1236 452 392 1297 1236 456 1236 452 393 1297 392 1297 392 1297 392 1298 1235 453 391 1298 391 From 6f37f01b205e6f3fec633ce747950c43efe8ec24 Mon Sep 17 00:00:00 2001 From: amec0e <88857687+amec0e@users.noreply.github.com> Date: Sat, 5 Aug 2023 15:36:45 +0100 Subject: [PATCH 42/44] Update projectors.ir Updated last checked --- assets/resources/infrared/assets/projectors.ir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/resources/infrared/assets/projectors.ir b/assets/resources/infrared/assets/projectors.ir index 628a3f5306..a2af75fe61 100644 --- a/assets/resources/infrared/assets/projectors.ir +++ b/assets/resources/infrared/assets/projectors.ir @@ -1,7 +1,7 @@ Filetype: IR library file Version: 1 # Last Updated 24th Jul, 2023 -# Last Checked 24th Jul, 2023 +# Last Checked 5th Aug, 2023 # # ON name: Power From e01e6f163c0d0fa68642b8e9cd671514bfee4e78 Mon Sep 17 00:00:00 2001 From: amec0e <88857687+amec0e@users.noreply.github.com> Date: Sat, 5 Aug 2023 15:37:47 +0100 Subject: [PATCH 43/44] Update tv.ir Updated last checked --- assets/resources/infrared/assets/tv.ir | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/assets/resources/infrared/assets/tv.ir b/assets/resources/infrared/assets/tv.ir index 5c0a4c1a9d..953fe6dbc7 100755 --- a/assets/resources/infrared/assets/tv.ir +++ b/assets/resources/infrared/assets/tv.ir @@ -1,7 +1,7 @@ Filetype: IR library file Version: 1 # Last Updated 24th Jul, 2023 -# Last Checked 24th Jul, 2023 +# Last Checked 5th Aug, 2023 # name: Power type: parsed From 20a6aa078c0f22c9169cc8c3345c3c2707582ff0 Mon Sep 17 00:00:00 2001 From: MX <10697207+xMasterX@users.noreply.github.com> Date: Sat, 5 Aug 2023 19:09:32 +0300 Subject: [PATCH 44/44] update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f936411d0a..23a516f084 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,6 @@ ## New changes * SubGHz: Support for Ebyte E07 module power amp switch (works with TehRabbitt's Flux Capacitor Board) (by @Sil333033) (PR #559 by @Z3BRO) -> Remade by @xMasterX -> Driver code fixed and reworked by @gid9798 +* Infrared: Update universal remote assets (by @amec0e | PR #570) * Infrared: Update universal AC asset (by @Leptopt1los | PR #569) * Plugins: Add * in NFC Maker keyboard (hold `.`) * Plugins: Update TOTP (Authenticator) [(by akopachov)](https://github.com/akopachov/flipper-zero_authenticator)