From 5923a2754f6a9e0b55d08c5e265d3c95976771f8 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Wed, 23 Oct 2024 12:28:34 -0600 Subject: [PATCH 1/4] feat: launch apps over commands --- firmware/main/main.c | 3 +- firmware/main/modules/cat_dos/cat_console.c | 3 ++ .../main/modules/cmd_control/cmd_control.c | 31 +++++++++++++++++++ .../main/modules/cmd_control/cmd_control.h | 5 +++ .../menus_module/menus_include/menus.h | 15 +++++++++ .../main/modules/menus_module/menus_module.c | 31 +++++++++++++++++-- .../main/modules/menus_module/menus_module.h | 1 + 7 files changed, 86 insertions(+), 3 deletions(-) create mode 100644 firmware/main/modules/cmd_control/cmd_control.c create mode 100644 firmware/main/modules/cmd_control/cmd_control.h diff --git a/firmware/main/main.c b/firmware/main/main.c index effd4b71..e43db53e 100644 --- a/firmware/main/main.c +++ b/firmware/main/main.c @@ -3,6 +3,7 @@ #include "apps/ble/trackers/trackers_module.h" #include "buzzer.h" #include "cat_console.h" +#include "cmd_control.h" #include "esp_log.h" #include "esp_timer.h" #include "flash_fs.h" @@ -39,5 +40,5 @@ void app_main() { menus_module_begin(); leds_off(); preferences_put_bool("wifi_connected", false); - // cat_console_begin(); + cat_console_begin(); } diff --git a/firmware/main/modules/cat_dos/cat_console.c b/firmware/main/modules/cat_dos/cat_console.c index 19388e24..ce5fdbf5 100644 --- a/firmware/main/modules/cat_dos/cat_console.c +++ b/firmware/main/modules/cat_dos/cat_console.c @@ -12,6 +12,7 @@ #include #include "argtable3/argtable3.h" #include "cmd_catdos.h" +#include "cmd_control.h" #include "cmd_wifi.h" // #include "driver/uart.h" // #include "driver/uart_vfs.h" @@ -83,6 +84,8 @@ void cat_console_begin() { /* Register commands */ esp_console_register_help_command(); register_wifi(); + launch_cmd_register(); + // if(show_dos){ // register_catdos_commands(); // } diff --git a/firmware/main/modules/cmd_control/cmd_control.c b/firmware/main/modules/cmd_control/cmd_control.c new file mode 100644 index 00000000..b8d69236 --- /dev/null +++ b/firmware/main/modules/cmd_control/cmd_control.c @@ -0,0 +1,31 @@ +#include "cmd_control.h" +#include "argtable3/argtable3.h" +#include "esp_console.h" +#include "esp_log.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "menus_module.h" + +static struct { + struct arg_str* app; + struct arg_end* end; +} launch_args; + +static int launch_app(int argc, char** argv) { + int nerrors = arg_parse(argc, argv, (void**) &launch_args); + menus_module_set_menu_over_cmd(launch_args.app->sval[0]); + return 0; +} + +void launch_cmd_register() { + launch_args.app = arg_str1(NULL, NULL, "", "Name of the app to launch"); + launch_args.end = arg_end(1); + + esp_console_cmd_t launch_cmd = {.command = "launch", + .help = "Launch an app", + .hint = NULL, + .func = &launch_app, + .argtable = &launch_args}; + + ESP_ERROR_CHECK(esp_console_cmd_register(&launch_cmd)); +} diff --git a/firmware/main/modules/cmd_control/cmd_control.h b/firmware/main/modules/cmd_control/cmd_control.h new file mode 100644 index 00000000..eb650946 --- /dev/null +++ b/firmware/main/modules/cmd_control/cmd_control.h @@ -0,0 +1,5 @@ +#pragma once + +#include + +void launch_cmd_register(); \ No newline at end of file diff --git a/firmware/main/modules/menus_module/menus_include/menus.h b/firmware/main/modules/menus_module/menus_include/menus.h index 6b513112..edca075f 100644 --- a/firmware/main/modules/menus_module/menus_include/menus.h +++ b/firmware/main/modules/menus_module/menus_include/menus.h @@ -101,6 +101,7 @@ typedef struct { menu_idx_t menu_idx; menu_idx_t parent_idx; const char* display_name; + const char* entry_cmd; uint8_t last_selected_submenu; void* on_enter_cb; void* on_exit_cb; @@ -186,6 +187,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "Analyzer", .menu_idx = MENU_WIFI_ANALIZER, .parent_idx = MENU_WIFI_APPS, + .entry_cmd = "analyzer", .last_selected_submenu = 0, .on_enter_cb = wifi_module_analizer_begin, .on_exit_cb = wifi_module_analyzer_exit, @@ -230,6 +232,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "Deauth", .menu_idx = MENU_WIFI_DEAUTH, .parent_idx = MENU_WIFI_APPS, + .entry_cmd = "deauth", .last_selected_submenu = 0, .on_enter_cb = deauth_module_begin, .on_exit_cb = NULL, @@ -239,6 +242,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "DoS", .menu_idx = MENU_WIFI_DOS, .parent_idx = MENU_WIFI_APPS, + .entry_cmd = "dos", .last_selected_submenu = 0, .on_enter_cb = catdos_module_begin, .on_exit_cb = NULL, @@ -257,6 +261,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "Trakers scan", .menu_idx = MENU_BLUETOOTH_TRAKERS_SCAN, .parent_idx = MENU_BLUETOOTH_APPS, + .entry_cmd = "trakers_scan", .last_selected_submenu = 0, .on_enter_cb = trackers_module_begin, .on_exit_cb = NULL, @@ -266,6 +271,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "Spam", .menu_idx = MENU_BLUETOOTH_SPAM, .parent_idx = MENU_BLUETOOTH_APPS, + .entry_cmd = "spam", .last_selected_submenu = 0, .on_enter_cb = ble_module_begin, .on_exit_cb = NULL, @@ -275,6 +281,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "HID", .menu_idx = MENU_BLUETOOTH_HID, .parent_idx = MENU_BLUETOOTH_APPS, + .entry_cmd = "hid", .last_selected_submenu = 0, .on_enter_cb = hid_module_begin, .on_exit_cb = NULL, @@ -300,6 +307,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "Switch", .menu_idx = MENU_ZIGBEE_SWITCH, .parent_idx = MENU_ZIGBEE_SPOOFING, + .entry_cmd = "switch", .last_selected_submenu = 0, .on_enter_cb = zigbee_module_switch_enter, .on_exit_cb = NULL, @@ -307,6 +315,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "Light", .menu_idx = MENU_ZIGBEE_LIGHT, .parent_idx = MENU_ZIGBEE_SPOOFING, + .entry_cmd = "light", .last_selected_submenu = 0, .on_enter_cb = NULL, .on_exit_cb = NULL, @@ -316,6 +325,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "Sniffer", .menu_idx = MENU_ZIGBEE_SNIFFER, .parent_idx = MENU_ZIGBEE_APPS, + .entry_cmd = "zigbee_sniffer", .last_selected_submenu = 0, .on_enter_cb = zigbee_module_sniffer_enter, .on_exit_cb = NULL, @@ -334,6 +344,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "Broadcast", .menu_idx = MENU_THREAD_BROADCAST, .parent_idx = MENU_THREAD_APPS, + .entry_cmd = "broadcast", .last_selected_submenu = 0, .on_enter_cb = open_thread_module_broadcast_enter, .on_exit_cb = open_thread_module_exit, @@ -343,6 +354,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "Sniffer", .menu_idx = MENU_THREAD_SNIFFER, .parent_idx = MENU_THREAD_APPS, + .entry_cmd = "thread_sniffer", .last_selected_submenu = 0, .on_enter_cb = open_thread_module_sniffer_enter, .on_exit_cb = open_thread_module_exit, @@ -368,6 +380,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "Wardriving", .menu_idx = MENU_GPS_WARDRIVING, .parent_idx = MENU_GPS, + .entry_cmd = "gps_wardriving", .last_selected_submenu = 0, .on_enter_cb = wardriving_module_begin, .on_exit_cb = wardriving_module_end, @@ -420,6 +433,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "File Manager", .menu_idx = MENU_FILE_MANAGER, .parent_idx = MENU_APPLICATIONS, + .entry_cmd = "file_manager", .last_selected_submenu = 0, .on_enter_cb = NULL, .on_exit_cb = NULL, @@ -447,6 +461,7 @@ menu_t menus[] = { ////////////////////////////////// {.display_name = "Update", .menu_idx = MENU_ABOUT_UPDATE, .parent_idx = MENU_ABOUT, + .entry_cmd = "ota", .last_selected_submenu = 0, .on_enter_cb = ota_module_init, .on_exit_cb = NULL, diff --git a/firmware/main/modules/menus_module/menus_module.c b/firmware/main/modules/menus_module/menus_module.c index 9f063eac..cb5d96e5 100644 --- a/firmware/main/modules/menus_module/menus_module.c +++ b/firmware/main/modules/menus_module/menus_module.c @@ -35,6 +35,18 @@ static uint8_t get_menu_idx(menu_idx_t menu_idx) { return 0; } +static uint8_t get_menu_idx_over_cmd(char* entry_cmd) { + for (uint8_t i = 0; i < menus_ctx->menus_count; i++) { + if (!menus[i].entry_cmd) { + continue; + } + if (!memcmp(menus[i].entry_cmd, entry_cmd, strlen(menus[i].entry_cmd))) { + return i; + } + } + return 0; +} + static void update_menus() { if (menus_ctx->submenus_idx != NULL) { for (uint8_t i = 0; i < menus_ctx->submenus_count; i++) { @@ -229,10 +241,25 @@ bool menus_module_get_app_state() { } void menus_module_set_menu(menu_idx_t menu_idx) { + if (!menus_ctx->submenus_count) { + return; + } + screen_saver_stop(); keyboard_module_set_input_callback(menus_input_cb); - menus_ctx->current_menu = menus[get_menu_idx(menu_idx)].menu_idx; - menus_ctx->parent_menu_idx = menus[get_menu_idx(menu_idx)].parent_idx; + menus[get_menu_idx(menus_ctx->current_menu)].last_selected_submenu = + menus_ctx->selected_submenu; + menus_ctx->current_menu = menus[menu_idx].menu_idx; + menus_ctx->parent_menu_idx = + menus[get_menu_idx(menus_ctx->current_menu)].parent_idx; refresh_menus(); + void (*cb)() = menus[get_menu_idx(menus_ctx->current_menu)].on_enter_cb; + if (cb) { + cb(); + } +} + +void menus_module_set_menu_over_cmd(char* entry_cmd) { + menus_module_set_menu(get_menu_idx_over_cmd(entry_cmd)); } void menus_module_hide_menu(menu_idx_t menu_idx) { diff --git a/firmware/main/modules/menus_module/menus_module.h b/firmware/main/modules/menus_module/menus_module.h index a701ea52..41d16d5d 100644 --- a/firmware/main/modules/menus_module/menus_module.h +++ b/firmware/main/modules/menus_module/menus_module.h @@ -30,6 +30,7 @@ void menus_module_exit_app(); void menus_module_screen_saver_run(); void menus_module_set_reset_screen(menu_idx_t menu); void menus_module_set_menu(menu_idx_t menu_idx); +void menus_module_set_menu_over_cmd(char* entry_cmd); void menus_module_hide_menu(menu_idx_t menu_idx); void menus_module_reveal_menu(menu_idx_t menu_idx); void menus_module_refresh(); From 257f010e4560af1c4dfac9ba98557938db699ee3 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Wed, 23 Oct 2024 12:36:44 -0600 Subject: [PATCH 2/4] fix: console blocked & stack dumps on launching apps over cmd --- firmware/main/modules/cmd_control/cmd_control.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/firmware/main/modules/cmd_control/cmd_control.c b/firmware/main/modules/cmd_control/cmd_control.c index b8d69236..669ca5db 100644 --- a/firmware/main/modules/cmd_control/cmd_control.c +++ b/firmware/main/modules/cmd_control/cmd_control.c @@ -11,9 +11,15 @@ static struct { struct arg_end* end; } launch_args; +static void launch_app_task(char* entry_cmd) { + menus_module_set_menu_over_cmd(entry_cmd); + vTaskDelete(NULL); +} + static int launch_app(int argc, char** argv) { int nerrors = arg_parse(argc, argv, (void**) &launch_args); - menus_module_set_menu_over_cmd(launch_args.app->sval[0]); + xTaskCreate(launch_app_task, "launch_app_task", 4096, + launch_args.app->sval[0], 15, NULL); return 0; } From b49419730f5411f69e01ec793563b667b9ec1d23 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Wed, 23 Oct 2024 14:51:28 -0600 Subject: [PATCH 3/4] refactor: realloc analyzer app path --- .../wifi/wifi_module.c => apps/wifi_analyzer/wifi_analyzer.c} | 4 ++-- .../wifi/wifi_module.h => apps/wifi_analyzer/wifi_analyzer.h} | 0 .../main/{modules/wifi => apps/wifi_analyzer}/wifi_bitmaps.h | 0 .../wifi => apps/wifi_analyzer}/wifi_screens_module.c | 2 +- .../wifi => apps/wifi_analyzer}/wifi_screens_module.h | 0 firmware/main/modules/menus_module/menus_include/menus.h | 2 +- 6 files changed, 4 insertions(+), 4 deletions(-) rename firmware/main/{modules/wifi/wifi_module.c => apps/wifi_analyzer/wifi_analyzer.c} (99%) rename firmware/main/{modules/wifi/wifi_module.h => apps/wifi_analyzer/wifi_analyzer.h} (100%) rename firmware/main/{modules/wifi => apps/wifi_analyzer}/wifi_bitmaps.h (100%) rename firmware/main/{modules/wifi => apps/wifi_analyzer}/wifi_screens_module.c (98%) rename firmware/main/{modules/wifi => apps/wifi_analyzer}/wifi_screens_module.h (100%) diff --git a/firmware/main/modules/wifi/wifi_module.c b/firmware/main/apps/wifi_analyzer/wifi_analyzer.c similarity index 99% rename from firmware/main/modules/wifi/wifi_module.c rename to firmware/main/apps/wifi_analyzer/wifi_analyzer.c index 1398a5b3..1f71142a 100644 --- a/firmware/main/modules/wifi/wifi_module.c +++ b/firmware/main/apps/wifi_analyzer/wifi_analyzer.c @@ -1,4 +1,4 @@ -#include "wifi_module.h" +#include "wifi_analyzer.h" #include "captive_portal.h" #include "catdos_module.h" @@ -16,9 +16,9 @@ #include "menus_module.h" #include "oled_screen.h" #include "sd_card.h" +#include "wifi_analyzer.h" #include "wifi_attacks.h" #include "wifi_controller.h" -#include "wifi_module.h" #include "wifi_scanner.h" #include "wifi_screens_module.h" diff --git a/firmware/main/modules/wifi/wifi_module.h b/firmware/main/apps/wifi_analyzer/wifi_analyzer.h similarity index 100% rename from firmware/main/modules/wifi/wifi_module.h rename to firmware/main/apps/wifi_analyzer/wifi_analyzer.h diff --git a/firmware/main/modules/wifi/wifi_bitmaps.h b/firmware/main/apps/wifi_analyzer/wifi_bitmaps.h similarity index 100% rename from firmware/main/modules/wifi/wifi_bitmaps.h rename to firmware/main/apps/wifi_analyzer/wifi_bitmaps.h diff --git a/firmware/main/modules/wifi/wifi_screens_module.c b/firmware/main/apps/wifi_analyzer/wifi_screens_module.c similarity index 98% rename from firmware/main/modules/wifi/wifi_screens_module.c rename to firmware/main/apps/wifi_analyzer/wifi_screens_module.c index e6ae5c67..a9e159f1 100644 --- a/firmware/main/modules/wifi/wifi_screens_module.c +++ b/firmware/main/apps/wifi_analyzer/wifi_screens_module.c @@ -3,8 +3,8 @@ #include "animations_task.h" #include "esp_log.h" #include "esp_wifi.h" -#include "modules/wifi/wifi_bitmaps.h" #include "oled_screen.h" +#include "wifi_bitmaps.h" TaskHandle_t wifi_sniffer_animation_task_handle = NULL; diff --git a/firmware/main/modules/wifi/wifi_screens_module.h b/firmware/main/apps/wifi_analyzer/wifi_screens_module.h similarity index 100% rename from firmware/main/modules/wifi/wifi_screens_module.h rename to firmware/main/apps/wifi_analyzer/wifi_screens_module.h diff --git a/firmware/main/modules/menus_module/menus_include/menus.h b/firmware/main/modules/menus_module/menus_include/menus.h index edca075f..270c50cd 100644 --- a/firmware/main/modules/menus_module/menus_include/menus.h +++ b/firmware/main/modules/menus_module/menus_include/menus.h @@ -21,7 +21,7 @@ #include "wardriving_module.h" #include "wardriving_screens_module.h" #include "web_file_browser_module.h" -#include "wifi_module.h" +#include "wifi_analyzer.h" #include "wifi_settings.h" #include "zigbee_module.h" From 5051b7679ccc0e11d67a5fe0bd424d819a82c207 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Wed, 23 Oct 2024 17:01:48 -0600 Subject: [PATCH 4/4] refactor: analyzer app --- .../wifi_analyzer/scenes/analyzer_scenes.c | 157 ++++++++++++++++++ .../wifi_analyzer/scenes/analyzer_scenes.h | 15 ++ .../{ => screens}/wifi_screens_module.c | 0 .../{ => screens}/wifi_screens_module.h | 0 .../main/apps/wifi_analyzer/wifi_analyzer.c | 68 +------- .../main/apps/wifi_analyzer/wifi_analyzer.h | 12 +- .../menus_module/menus_include/menus.h | 38 +---- 7 files changed, 189 insertions(+), 101 deletions(-) create mode 100644 firmware/main/apps/wifi_analyzer/scenes/analyzer_scenes.c create mode 100644 firmware/main/apps/wifi_analyzer/scenes/analyzer_scenes.h rename firmware/main/apps/wifi_analyzer/{ => screens}/wifi_screens_module.c (100%) rename firmware/main/apps/wifi_analyzer/{ => screens}/wifi_screens_module.h (100%) diff --git a/firmware/main/apps/wifi_analyzer/scenes/analyzer_scenes.c b/firmware/main/apps/wifi_analyzer/scenes/analyzer_scenes.c new file mode 100644 index 00000000..922c7853 --- /dev/null +++ b/firmware/main/apps/wifi_analyzer/scenes/analyzer_scenes.c @@ -0,0 +1,157 @@ +#include "analyzer_scenes.h" + +#include "general_radio_selection.h" +#include "general_screens.h" +#include "general_submenu.h" +#include "menus_module.h" +#include "wifi_analyzer.h" +#include "wifi_sniffer.h" + +static analyzer_scenes_e current_scene; + +void analyzer_scenes_main_menu(); +void analyzer_scenes_settings(); +void analyzer_scenes_channel(); +void analyzer_scenes_destination(); + +analyzer_scenes_e analyzer_get_current_scene() { + return current_scene; +} + +////////////////////////// MAIN MENU /////////////////////////////// +static enum { + ANALYZER_START_OPTION, + ANALYZER_SETTINGS_OPTION, + ANALYZER_HELP_OPTION +} analyzer_main_options_e; + +char* analizer_main_options[] = {"Start", "Settings", "Help"}; + +static void main_menu_selection_handler(uint8_t selection) { + switch (selection) { + case ANALYZER_START_OPTION: + wifi_analyzer_run(); + break; + case ANALYZER_SETTINGS_OPTION: + analyzer_scenes_settings(); + break; + case ANALYZER_HELP_OPTION: + wifi_analyzer_help(); + break; + default: + break; + } +} + +static void main_menu_exit_handler() { + menus_module_exit_app(); +} + +void analyzer_scenes_main_menu() { + current_scene = ANALYZER_MAIN_SCENE; + general_submenu_menu_t main_menu; + main_menu.options = analizer_main_options; + main_menu.options_count = sizeof(analizer_main_options) / sizeof(char*); + main_menu.select_cb = main_menu_selection_handler; + main_menu.exit_cb = main_menu_exit_handler; + general_submenu(main_menu); + wifi_analyzer_begin(); +} + +////////////////////////// SETTINGS MENU /////////////////////////////// +static enum { + ANALYZER_SETTINGS_CHANNEL_OPTION, + ANALYZER_SETTINGS_DESTINATION_OPTION, +} analyzer_settings_options_e; + +char* analizer_settings_options[] = {"Channel", "Destination"}; + +static void settings_selection_handler(uint8_t selection) { + switch (selection) { + case ANALYZER_SETTINGS_CHANNEL_OPTION: + analyzer_scenes_channel(); + break; + case ANALYZER_SETTINGS_DESTINATION_OPTION: + analyzer_scenes_destination(); + break; + default: + break; + } +} + +static void settings_exit_handler() { + analyzer_scenes_main_menu(); +} + +void analyzer_scenes_settings() { + current_scene = ANALYZER_SETTINGS_OPTION; + general_submenu_menu_t settings_menu; + settings_menu.options = analizer_settings_options; + settings_menu.options_count = + sizeof(analizer_settings_options) / sizeof(char*); + settings_menu.select_cb = settings_selection_handler; + settings_menu.exit_cb = settings_exit_handler; + general_submenu(settings_menu); + // wifi_analyzer_begin(); +} +////////////////////////// CHANNEL MENU /////////////////////////////// +static const char* channel_options[] = { + "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", +}; +static void set_channel(uint8_t selected_item) { + wifi_sniffer_set_channel(selected_item + 1); +} +void analyzer_scenes_channel() { + general_radio_selection_menu_t channel = {0}; + channel.banner = "Choose Channel", + channel.current_option = wifi_sniffer_get_channel() - 1; + channel.options = channel_options; + channel.options_count = sizeof(channel_options) / sizeof(char*); + channel.select_cb = set_channel; + channel.exit_cb = analyzer_scenes_settings; + channel.style = RADIO_SELECTION_OLD_STYLE; + general_radio_selection(channel); +} + +////////////////////////// DESTINATION MENU /////////////////////////////// +static const char* destination_options[] = {"SD", "Internal"}; +static void set_destination(uint8_t selected_item) { + if (selected_item == WIFI_SNIFFER_DESTINATION_SD) { + wifi_sniffer_set_destination_sd(); + } else { + wifi_sniffer_set_destination_internal(); + } +} + +static void destination_scene_exit() { + wifi_module_analyzer_destination_exit(); + analyzer_scenes_settings(); +} +void analyzer_scenes_destination() { + general_radio_selection_menu_t destination = {0}; + destination.banner = "Choose Destination", + destination.current_option = wifi_sniffer_is_destination_internal(); + destination.options = destination_options; + destination.options_count = sizeof(destination_options) / sizeof(char*); + destination.select_cb = set_destination; + destination.exit_cb = destination_scene_exit; + destination.style = RADIO_SELECTION_OLD_STYLE; + general_radio_selection(destination); +} +////////////////////////// HELP MENU /////////////////////////////// +static const char* wifi_analizer_help[] = { + "This tool", "allows you to", "analyze the", + "WiFi networks", "around you.", "", + "You can select", "the channel and", "the destination", + "to save the", "results.", +}; + +static const general_menu_t analyzer_help_menu = { + .menu_items = wifi_analizer_help, + .menu_count = 11, + .menu_level = GENERAL_TREE_APP_MENU}; + +void wifi_analyzer_help() { + general_register_scrolling_menu(&analyzer_help_menu); + general_screen_display_scrolling_text_handler(analyzer_scenes_main_menu); +} \ No newline at end of file diff --git a/firmware/main/apps/wifi_analyzer/scenes/analyzer_scenes.h b/firmware/main/apps/wifi_analyzer/scenes/analyzer_scenes.h new file mode 100644 index 00000000..5fbc9983 --- /dev/null +++ b/firmware/main/apps/wifi_analyzer/scenes/analyzer_scenes.h @@ -0,0 +1,15 @@ +#pragma once + +#include "stdio.h" + +typedef enum { + ANALYZER_MAIN_SCENE, + ANALYZER_RUN_SCENE, + ANALYZER_SETTINGS_SCENE, + ANALYZER_DESTINATION_SCENE, + ANALYZER_CHANNEL_SCENE, + ANALYZER_HELP_SCENE, +} analyzer_scenes_e; + +void analyzer_scenes_main_menu(); +void analyzer_scenes_settings(); \ No newline at end of file diff --git a/firmware/main/apps/wifi_analyzer/wifi_screens_module.c b/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.c similarity index 100% rename from firmware/main/apps/wifi_analyzer/wifi_screens_module.c rename to firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.c diff --git a/firmware/main/apps/wifi_analyzer/wifi_screens_module.h b/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.h similarity index 100% rename from firmware/main/apps/wifi_analyzer/wifi_screens_module.h rename to firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.h diff --git a/firmware/main/apps/wifi_analyzer/wifi_analyzer.c b/firmware/main/apps/wifi_analyzer/wifi_analyzer.c index 1f71142a..2f2ef825 100644 --- a/firmware/main/apps/wifi_analyzer/wifi_analyzer.c +++ b/firmware/main/apps/wifi_analyzer/wifi_analyzer.c @@ -9,6 +9,7 @@ #include "keyboard_module.h" #include "string.h" +#include "analyzer_scenes.h" #include "deauth_module.h" #include "general_radio_selection.h" #include "general_screens.h" @@ -23,33 +24,13 @@ #include "wifi_screens_module.h" static const char* TAG = "wifi_module"; -bool analizer_initialized = false; +static bool analizer_initialized = false; static general_menu_t analyzer_summary_menu; static char* wifi_analizer_summary_2[120] = { "Summary", }; -static const char* wifi_analizer_help_2[] = { - "This tool", "allows you to", "analyze the", - "WiFi networks", "around you.", "", - "You can select", "the channel and", "the destination", - "to save the", "results.", -}; - -static const general_menu_t analyzer_help_menu = { - .menu_items = wifi_analizer_help_2, - .menu_count = 11, - .menu_level = GENERAL_TREE_APP_MENU}; - -static const char* destination_options[] = {"SD", "Internal"}; -static const char* channel_options[] = { - "1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", -}; -void wifi_module_show_analyzer_help() { - general_register_scrolling_menu(&analyzer_help_menu); - general_screen_display_scrolling_text_handler(menus_module_exit_app); -} static void wifi_module_input_cb(uint8_t button_name, uint8_t button_event); uint16_t get_summary_rows_count() { @@ -95,7 +76,7 @@ void wifi_module_init_sniffer() { } static void wifi_module_summary_exit_cb() { wifi_sniffer_close_file(); - menus_module_exit_app(); + analyzer_scenes_main_menu(); } void wifi_module_analyzer_run_exit() { @@ -113,7 +94,7 @@ void wifi_module_analyzer_summary_exit() { wifi_sniffer_close_file(); } -void wifi_module_analyzer_exit() { +void wifi_analyzer_exit() { menus_module_restart(); } @@ -130,51 +111,20 @@ void wifi_module_analyzer_destination_exit() { } } -void wifi_module_analyzer_run() { +void wifi_analyzer_run() { wifi_module_init_sniffer(); menus_module_set_app_state(true, wifi_module_input_cb); } -static void wifi_module_set_destination(uint8_t selected_item) { - if (selected_item == WIFI_SNIFFER_DESTINATION_SD) { - wifi_sniffer_set_destination_sd(); - } else { - wifi_sniffer_set_destination_internal(); - } -} -static void wifi_module_set_channel(uint8_t selected_item) { - wifi_sniffer_set_channel(selected_item + 1); -} - -void wifi_module_analyzer_channel() { - general_radio_selection_menu_t channel = {0}; - channel.banner = "Choose Channel", - channel.current_option = wifi_sniffer_get_channel() - 1; - channel.options = channel_options; - channel.options_count = 14; - channel.select_cb = wifi_module_set_channel; - channel.exit_cb = menus_module_exit_app; - channel.style = RADIO_SELECTION_OLD_STYLE; - general_radio_selection(channel); -} - -void wifi_module_analyzer_destination() { - general_radio_selection_menu_t destination = {0}; - destination.banner = "Choose Destination", - destination.current_option = wifi_sniffer_is_destination_internal(); - destination.options = destination_options; - destination.options_count = 2; - destination.select_cb = wifi_module_set_destination; - destination.exit_cb = menus_module_exit_app; - destination.style = RADIO_SELECTION_OLD_STYLE; - general_radio_selection(destination); -} -void wifi_module_analizer_begin() { +void wifi_analyzer_begin() { ESP_LOGI(TAG, "Initializing WiFi analizer module"); wifi_sniffer_register_cb(wifi_screens_module_display_sniffer_cb); wifi_sniffer_register_animation_cbs(wifi_screens_sniffer_animation_start, wifi_screens_sniffer_animation_stop); wifi_sniffer_register_summary_cb(wifi_module_analizer_summary_cb); + if (analizer_initialized) { + return; + } wifi_sniffer_begin(); analizer_initialized = true; } diff --git a/firmware/main/apps/wifi_analyzer/wifi_analyzer.h b/firmware/main/apps/wifi_analyzer/wifi_analyzer.h index b42020b6..0ff87619 100644 --- a/firmware/main/apps/wifi_analyzer/wifi_analyzer.h +++ b/firmware/main/apps/wifi_analyzer/wifi_analyzer.h @@ -15,11 +15,11 @@ void wifi_module_begin(); * * @return void */ -void wifi_module_analizer_begin(); +void wifi_analyzer_begin(); void wifi_module_init_sniffer(); -void wifi_module_analyzer_run(); +void wifi_analyzer_run(); /** * @brief Stop the wifi module @@ -27,7 +27,7 @@ void wifi_module_analyzer_run(); */ void wifi_module_exit(void); void wifi_module_analyzer_run_exit(); -void wifi_module_analyzer_exit(); +void wifi_analyzer_exit(); void wifi_module_analyzer_summary_exit(); void wifi_module_analyzer_destination_exit(); @@ -40,7 +40,7 @@ void wifi_module_analyzer_destination_exit(); */ void wifi_module_analizer_summary_cb(FILE* pcap_file); -void wifi_module_show_analyzer_help(); +void wifi_analyzer_help(); -void wifi_module_analyzer_destination(); -void wifi_module_analyzer_channel(); \ No newline at end of file +void analyzer_scenes_destination(); +void analyzer_scenes_channel(); \ No newline at end of file diff --git a/firmware/main/modules/menus_module/menus_include/menus.h b/firmware/main/modules/menus_module/menus_include/menus.h index 270c50cd..df1d5bdd 100644 --- a/firmware/main/modules/menus_module/menus_include/menus.h +++ b/firmware/main/modules/menus_module/menus_include/menus.h @@ -7,6 +7,7 @@ #include "trackers_module.h" #include "z_switch_module.h" +#include "analyzer_scenes.h" #include "catdos_module.h" #include "deauth_module.h" #include "display_settings.h" @@ -189,42 +190,7 @@ menu_t menus[] = { ////////////////////////////////// .parent_idx = MENU_WIFI_APPS, .entry_cmd = "analyzer", .last_selected_submenu = 0, - .on_enter_cb = wifi_module_analizer_begin, - .on_exit_cb = wifi_module_analyzer_exit, - .is_visible = true}, - {.display_name = "Start", - .menu_idx = MENU_WIFI_ANALYZER_RUN, - .parent_idx = MENU_WIFI_ANALIZER, - .last_selected_submenu = 0, - .on_enter_cb = wifi_module_analyzer_run, - .on_exit_cb = NULL, - .is_visible = true}, - {.display_name = "Settings", - .menu_idx = MENU_WIFI_ANALYZER_SETTINGS, - .parent_idx = MENU_WIFI_ANALIZER, - .last_selected_submenu = 0, - .on_enter_cb = NULL, - .on_exit_cb = NULL, - .is_visible = true}, - {.display_name = "Channel", - .menu_idx = MENU_WIFI_ANALYZER_CHANNEL, - .parent_idx = MENU_WIFI_ANALYZER_SETTINGS, - .last_selected_submenu = 0, - .on_enter_cb = wifi_module_analyzer_channel, - .on_exit_cb = NULL, - .is_visible = true}, - {.display_name = "Destination", - .menu_idx = MENU_WIFI_ANALYZER_DESTINATION, - .parent_idx = MENU_WIFI_ANALYZER_SETTINGS, - .last_selected_submenu = 0, - .on_enter_cb = wifi_module_analyzer_destination, - .on_exit_cb = wifi_module_analyzer_destination_exit, - .is_visible = true}, - {.display_name = "Help", - .menu_idx = MENU_WIFI_ANALYZER_HELP, - .parent_idx = MENU_WIFI_ANALIZER, - .last_selected_submenu = 0, - .on_enter_cb = wifi_module_show_analyzer_help, + .on_enter_cb = analyzer_scenes_main_menu, .on_exit_cb = NULL, .is_visible = true}, #endif