diff --git a/firmware/main/apps/wifi/deauth/deauth_module.c b/firmware/main/apps/wifi/deauth/deauth_module.c index 7246c718..61d965cb 100644 --- a/firmware/main/apps/wifi/deauth/deauth_module.c +++ b/firmware/main/apps/wifi/deauth/deauth_module.c @@ -208,8 +208,7 @@ static void deauth_module_cb_event(uint8_t button_name, uint8_t button_event) { case BUTTON_LEFT: wifi_scanner_clear_ap_records(); printf("Exit deauth: %d\n", current_item); - menus_module_set_app_state(false, NULL); - menu_screens_exit_submenu(); + menus_module_exit_app(); // led_control_stop(); break; default: diff --git a/firmware/main/modules/cat_dos/catdos_module.c b/firmware/main/modules/cat_dos/catdos_module.c index e4c2f86c..f2337741 100644 --- a/firmware/main/modules/cat_dos/catdos_module.c +++ b/firmware/main/modules/cat_dos/catdos_module.c @@ -592,8 +592,7 @@ static void catdos_module_state_machine(uint8_t button_name, case CATDOS_STATE_CONFIG_WIFI: { switch (button_name) { case BUTTON_LEFT: - menus_module_set_app_state(false, NULL); - menu_screens_exit_submenu(); + menus_module_exit_app(); break; case BUTTON_RIGHT: ESP_LOGI(CATDOS_TAG, "Selected item: %d", selected_item); diff --git a/firmware/main/modules/file_manager/file_manager_module.c b/firmware/main/modules/file_manager/file_manager_module.c index bab43fa2..201e2c8a 100644 --- a/firmware/main/modules/file_manager/file_manager_module.c +++ b/firmware/main/modules/file_manager/file_manager_module.c @@ -131,8 +131,7 @@ static file_manager_context_t* file_manager_context_alloc() { static void file_manager_module_exit() { clear_items(); free(fm_ctx); - menu_screens_exit_submenu(); - menus_module_set_app_state(false, NULL); + menus_module_exit_app(); } static void navigation_up() { diff --git a/firmware/main/modules/keyboard/keyboard_module.c b/firmware/main/modules/keyboard/keyboard_module.c index 9278705d..0db2d495 100644 --- a/firmware/main/modules/keyboard/keyboard_module.c +++ b/firmware/main/modules/keyboard/keyboard_module.c @@ -15,20 +15,6 @@ static bool lock_input = false; static void button_event_cb(void* arg, void* data); -void timer_callback() { - menu_idx_t menu = menus_module_get_current_menu(); - if (menu == MENU_WIFI_ANALYZER_RUN_2 || - menu == MENU_WIFI_ANALYZER_SUMMARY_2 || menu == MENU_GPS_DATE_TIME_2 || - menu == MENU_GPS_LOCATION_2 || menu == MENU_GPS_SPEED_2) { - return; - } - if (menus_module_get_app_state()) { - return; - } - - is_idle = true; - menus_module_screen_saver_run(); -} void keyboard_module_reset_idle_timer() { esp_timer_stop(idle_timer); esp_timer_start_once(idle_timer, IDLE_TIMEOUT_S * 1000 * 1000); @@ -129,9 +115,4 @@ void keyboard_module_begin() { button_init(RIGHT_BUTTON_PIN, RIGHT_BUTTON_MASK); button_init(UP_BUTTON_PIN, UP_BUTTON_MASK); button_init(DOWN_BUTTON_PIN, DOWN_BUTTON_MASK); - esp_timer_create_args_t timer_args = {.callback = timer_callback, - .arg = NULL, - - .name = "one_shot_timer"}; - esp_err_t err = esp_timer_create(&timer_args, &idle_timer); } diff --git a/firmware/main/modules/menu_screens/menu_screens_modules.h b/firmware/main/modules/menu_screens/menu_screens_modules.h index 69db698c..5c2396d0 100644 --- a/firmware/main/modules/menu_screens/menu_screens_modules.h +++ b/firmware/main/modules/menu_screens/menu_screens_modules.h @@ -192,6 +192,4 @@ void menu_screens_update_options(char* options[], uint8_t selected_option); * @return void */ void screen_module_set_screen(int current_menu); - -static void screen_saver_run(); void stop_screen_saver(); \ No newline at end of file diff --git a/firmware/main/modules/menus_module/menus.h b/firmware/main/modules/menus_module/menus.h index 8be664b5..9034d7c4 100644 --- a/firmware/main/modules/menus_module/menus.h +++ b/firmware/main/modules/menus_module/menus.h @@ -7,7 +7,16 @@ #include "apps/zigbee/z_switch/z_switch_module.h" #include "modules/about/about_module.h" +#include "catdos_module.h" +#include "deauth_module.h" +#include "display_settings.h" +#include "file_manager_module.h" +#include "open_thread_module.h" #include "ota_module.h" +#include "stealth_mode.h" +#include "web_file_browser_module.h" +#include "wifi_module.h" +#include "zigbee_module.h" typedef enum { MENU_MAIN_2 = 0, @@ -170,15 +179,15 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_WIFI_ANALIZER_2, .parent_idx = MENU_WIFI_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, - .on_exit_cb = NULL, + .on_enter_cb = wifi_module_analizer_begin, + .on_exit_cb = wifi_module_analizer_exit, .is_visible = true}, {.display_name = "Start", .menu_idx = MENU_WIFI_ANALYZER_RUN_2, .parent_idx = MENU_WIFI_ANALIZER_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, - .on_exit_cb = NULL, + .on_enter_cb = wifi_module_init_sniffer, + .on_exit_cb = wifi_module_analyzer_run_exit, .is_visible = true}, {.display_name = "Settings", .menu_idx = MENU_WIFI_ANALYZER_SETTINGS_2, @@ -199,7 +208,7 @@ menu_t menus[] = { ////////////////////////////////// .parent_idx = MENU_WIFI_ANALYZER_SETTINGS_2, .last_selected_submenu = 0, .on_enter_cb = NULL, - .on_exit_cb = NULL, + .on_exit_cb = wifi_module_analyzer_destination_exit, .is_visible = true}, {.display_name = "Help", .menu_idx = MENU_WIFI_ANALYZER_HELP_2, @@ -214,7 +223,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_WIFI_DEAUTH_2, .parent_idx = MENU_WIFI_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = deauth_module_begin, .on_exit_cb = NULL, .is_visible = true}, #endif @@ -223,7 +232,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_WIFI_DOS_2, .parent_idx = MENU_WIFI_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = catdos_module_begin, .on_exit_cb = NULL, .is_visible = true}, #endif @@ -284,7 +293,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_ZIGBEE_SWITCH_2, .parent_idx = MENU_ZIGBEE_SPOOFING_2, .last_selected_submenu = 0, - .on_enter_cb = z_switch_module_begin, + .on_enter_cb = zigbee_module_switch_enter, .on_exit_cb = NULL, .is_visible = true}, {.display_name = "Light", @@ -300,7 +309,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_ZIGBEE_SNIFFER_2, .parent_idx = MENU_ZIGBEE_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = zigbee_module_sniffer_enter, .on_exit_cb = NULL, .is_visible = true}, #endif @@ -318,8 +327,8 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_THREAD_BROADCAST_2, .parent_idx = MENU_THREAD_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, - .on_exit_cb = NULL, + .on_enter_cb = open_thread_module_broadcast_enter, + .on_exit_cb = open_thread_module_exit, .is_visible = true}, #endif #ifdef CONFIG_THREAD_APP_SNIFFER @@ -327,14 +336,14 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_THREAD_SNIFFER_2, .parent_idx = MENU_THREAD_APPS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, - .on_exit_cb = NULL, + .on_enter_cb = open_thread_module_sniffer_enter, + .on_exit_cb = open_thread_module_exit, .is_visible = true}, {.display_name = "Run", .menu_idx = MENU_THREAD_SNIFFER_RUN_2, .parent_idx = MENU_THREAD_SNIFFER_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = open_thread_module_sniffer_run, .on_exit_cb = NULL, .is_visible = true}, #endif @@ -419,7 +428,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_SETTINGS_DISPLAY_2, .parent_idx = MENU_SETTINGS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = display_config_module_begin, .on_exit_cb = NULL, .is_visible = true}, {.display_name = "System", @@ -470,7 +479,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_FILE_MANAGER_LOCAL_2, .parent_idx = MENU_FILE_MANAGER_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = file_manager_module_init, .on_exit_cb = NULL, .is_visible = true}, #endif @@ -479,7 +488,7 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_FILE_MANAGER_WEB_2, .parent_idx = MENU_FILE_MANAGER_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = web_file_browser_module_begin, .on_exit_cb = NULL, .is_visible = true}, #endif @@ -488,6 +497,6 @@ menu_t menus[] = { ////////////////////////////////// .menu_idx = MENU_STEALTH_MODE_2, .parent_idx = MENU_SETTINGS_2, .last_selected_submenu = 0, - .on_enter_cb = NULL, + .on_enter_cb = stealth_mode_open_menu, .on_exit_cb = NULL, .is_visible = true}}; \ No newline at end of file diff --git a/firmware/main/modules/menus_module/menus_module.c b/firmware/main/modules/menus_module/menus_module.c index f79e40ae..953e4613 100644 --- a/firmware/main/modules/menus_module/menus_module.c +++ b/firmware/main/modules/menus_module/menus_module.c @@ -2,7 +2,7 @@ #include #include "bitmaps_general.h" -#include "leds.h" +#include "led_events.h" #include "menu_screens_modules.h" #include "menus_screens.h" #include "modals_module.h" @@ -148,6 +148,7 @@ static void navigation_enter() { static void navigation_exit() { if (menus_ctx->current_menu == MENU_MAIN_2) { + screen_saver_run(); return; } menus[get_menu_idx(menus_ctx->current_menu)].last_selected_submenu = @@ -204,26 +205,21 @@ static void menus_input_cb(uint8_t button_name, uint8_t button_event) { static void show_logo() { oled_screen_clear(); - leds_on(); - buzzer_play(); + led_control_run_effect(led_control_pulse_leds); + buzzer_play_for(100); screen_saver_run(); - vTaskDelay(500 / portTICK_PERIOD_MS); - buzzer_stop(); } -void screen_module_set_reset_screen(menu_idx_t menu) { +void menus_module_set_reset_screen(menu_idx_t menu) { preferences_put_int("MENUNUMBER", menu); modals_module_show_banner("Exiting..."); } static void get_reset_menu() { menus_ctx->current_menu = preferences_get_int("MENUNUMBER", MENU_MAIN_2); - - if ((int) menus_ctx->current_menu == MENU_MAIN) { - preferences_put_int("logo_show", 1); + if ((int) menus_ctx->current_menu == MENU_MAIN_2) { show_logo(); } else { - preferences_put_int("logo_show", 0); preferences_put_int("MENUNUMBER", MENU_MAIN_2); screen_saver_get_idle_state(); refresh_menus(); @@ -251,7 +247,7 @@ void menus_module_set_app_state_last() { void menus_module_exit_app() { app_state2.in_app = false; app_state2.input_callback = NULL; - screen_module_set_reset_screen(menus_ctx->parent_menu_idx); + menus_module_set_reset_screen(menus_ctx->parent_menu_idx); esp_restart(); } diff --git a/firmware/main/modules/menus_module/menus_module.h b/firmware/main/modules/menus_module/menus_module.h index 733b81e2..99117124 100644 --- a/firmware/main/modules/menus_module/menus_module.h +++ b/firmware/main/modules/menus_module/menus_module.h @@ -27,4 +27,5 @@ void menus_module_set_app_state_last(); bool menus_module_get_app_state(); void menus_module_exit_app(); void menus_module_exit_app_information(); -void menus_module_screen_saver_run(); \ No newline at end of file +void menus_module_screen_saver_run(); +void menus_module_set_reset_screen(menu_idx_t menu); diff --git a/firmware/main/modules/menus_module/menus_screens.c b/firmware/main/modules/menus_module/menus_screens.c index 76a760dc..3cb79b04 100644 --- a/firmware/main/modules/menus_module/menus_screens.c +++ b/firmware/main/modules/menus_module/menus_screens.c @@ -49,8 +49,7 @@ void menus_screens_display_menus_f(menus_manager_t* ctx) { .display_name; char* str = (char*) malloc(strlen(display_name) + 3); sprintf(str, "%s%s", i == 1 ? prefix : " ", display_name); - oled_screen_display_text(str, 0, i * page_increment + 1, - OLED_DISPLAY_NORMAL); + oled_screen_display_text(str, 0, i * page_increment, OLED_DISPLAY_NORMAL); } #ifdef CONFIG_RESOLUTION_128X64 diff --git a/firmware/main/modules/open_thread/open_thread_module.c b/firmware/main/modules/open_thread/open_thread_module.c index 18ab944f..62f9808b 100644 --- a/firmware/main/modules/open_thread/open_thread_module.c +++ b/firmware/main/modules/open_thread/open_thread_module.c @@ -15,48 +15,12 @@ uint8_t channel = 15; static void thread_broadcast_input(uint8_t button_name, uint8_t button_event); static void thread_sniffer_input(uint8_t button_name, uint8_t button_event); -static void open_thread_module_exit_submenu_cb(); -static void open_thread_module_enter_submenu_cb( - screen_module_menu_t user_selection); void open_thread_module_begin() { #if !defined(CONFIG_OPEN_THREAD_MODULE_DEBUG) esp_log_level_set(TAG_OT_MODULE, ESP_LOG_NONE); #endif radio_selector_set_thread(); - menu_screens_register_enter_submenu_cb(open_thread_module_enter_submenu_cb); - menu_screens_register_exit_submenu_cb(open_thread_module_exit_submenu_cb); -} - -void open_thread_module_exit() { - screen_module_set_screen(MENU_THREAD_SNIFFER); - esp_restart(); -} - -static void open_thread_module_enter_submenu_cb( - screen_module_menu_t user_selection) { - oled_screen_clear(); - switch (user_selection) { - case MENU_THREAD_BROADCAST: - menus_module_set_app_state(true, thread_broadcast_input); - led_control_run_effect(led_control_zigbee_scanning); - open_thread_screens_display_broadcast_mode(channel); - thread_broadcast_set_on_msg_recieve_cb( - open_thread_screens_show_new_message); - thread_broadcast_init(); - break; - case MENU_THREAD_SNIFFER: - thread_sniffer_set_show_event_cb(thread_sniffer_show_event_handler); - thread_sniffer_init(); - break; - case MENU_THREAD_SNIFFER_RUN: - menus_module_set_app_state(true, thread_sniffer_input); - led_control_run_effect(led_control_zigbee_scanning); - thread_sniffer_run(); - break; - default: - break; - } } static void open_thread_module_exit_submenu_cb() { @@ -73,15 +37,39 @@ static void open_thread_module_exit_submenu_cb() { } } +void open_thread_module_exit() { + menus_module_set_reset_screen(MENU_THREAD_APPS_2); + esp_restart(); +} + +void open_thread_module_broadcast_enter() { + radio_selector_set_thread(); + menus_module_set_app_state(true, thread_broadcast_input); + led_control_run_effect(led_control_zigbee_scanning); + open_thread_screens_display_broadcast_mode(channel); + thread_broadcast_set_on_msg_recieve_cb(open_thread_screens_show_new_message); + thread_broadcast_init(); +} + +void open_thread_module_sniffer_enter() { + radio_selector_set_thread(); + thread_sniffer_set_show_event_cb(thread_sniffer_show_event_handler); + thread_sniffer_init(); +} +void open_thread_module_sniffer_run() { + menus_module_set_app_state(true, thread_sniffer_input); + led_control_run_effect(led_control_zigbee_scanning); + thread_sniffer_run(); +} + static void thread_broadcast_input(uint8_t button_name, uint8_t button_event) { - if (button_event != BUTTON_SINGLE_CLICK) { + if (button_event != BUTTON_PRESS_DOWN) { return; } switch (button_name) { case BUTTON_LEFT: led_control_stop(); - screen_module_set_screen(MENU_THREAD_BROADCAST); - esp_restart(); + open_thread_module_exit(); break; case BUTTON_RIGHT: case BUTTON_UP: @@ -102,15 +90,14 @@ static void thread_broadcast_input(uint8_t button_name, uint8_t button_event) { } static void thread_sniffer_input(uint8_t button_name, uint8_t button_event) { - if (button_event != BUTTON_SINGLE_CLICK) { + if (button_event != BUTTON_PRESS_DOWN) { return; } switch (button_name) { case BUTTON_LEFT: thread_sniffer_stop(); led_control_stop(); - menu_screens_exit_submenu(); - menus_module_set_app_state(false, NULL); + menus_module_exit_app(); break; case BUTTON_RIGHT: break; diff --git a/firmware/main/modules/open_thread/open_thread_module.h b/firmware/main/modules/open_thread/open_thread_module.h index 5c471d22..d2612cc3 100644 --- a/firmware/main/modules/open_thread/open_thread_module.h +++ b/firmware/main/modules/open_thread/open_thread_module.h @@ -1,10 +1,12 @@ #pragma once #define TAG_OT_MODULE "open_thread:main" -/** - * @brief Begin the bluetooth module - * - * @param app_selected The selected app - */ + void open_thread_module_begin(); void open_thread_module_exit(); + +void open_thread_module_broadcast_enter(); + +void open_thread_module_sniffer_enter(); + +void open_thread_module_sniffer_run(); \ No newline at end of file diff --git a/firmware/main/modules/screen_saver/screen_saver.c b/firmware/main/modules/screen_saver/screen_saver.c index 9f870445..2e16d635 100644 --- a/firmware/main/modules/screen_saver/screen_saver.c +++ b/firmware/main/modules/screen_saver/screen_saver.c @@ -16,7 +16,7 @@ esp_timer_handle_t screen_savar_idle_timer2; void screen_saver_run(); static void timer_callback() { - if (menus_module_get_app_state()) { + if (menus_module_get_app_state() || screen_saver_running) { return; } diff --git a/firmware/main/modules/settings/display/display_settings.c b/firmware/main/modules/settings/display/display_settings.c index 9629c652..e2638f7a 100644 --- a/firmware/main/modules/settings/display/display_settings.c +++ b/firmware/main/modules/settings/display/display_settings.c @@ -115,8 +115,7 @@ static void display_config_module_state_machine(uint8_t button_name, } switch (button_name) { case BUTTON_LEFT: - menus_module_set_app_state(false, NULL); - menu_screens_exit_submenu(); + menus_module_exit_app(); break; case BUTTON_RIGHT: ESP_LOGI(TAG_DISPLAY_CONFIG, "Selected item: %d", selected_item); diff --git a/firmware/main/modules/settings/settings_module.c b/firmware/main/modules/settings/settings_module.c index 41cb52f8..e10fe304 100644 --- a/firmware/main/modules/settings/settings_module.c +++ b/firmware/main/modules/settings/settings_module.c @@ -77,7 +77,7 @@ void settings_module_enter_submenu_cb(screen_module_menu_t user_selection) { file_manager_module_init(); break; case MENU_FILE_MANAGER_WEB: - web_file_browser_module_init(); + web_file_browser_module_begin(); break; case MENU_SETTINGS_DISPLAY: display_config_module_begin(); diff --git a/firmware/main/modules/settings/stealth_mode/stealth_mode.c b/firmware/main/modules/settings/stealth_mode/stealth_mode.c index 916817c3..ed8ef026 100644 --- a/firmware/main/modules/settings/stealth_mode/stealth_mode.c +++ b/firmware/main/modules/settings/stealth_mode/stealth_mode.c @@ -24,8 +24,7 @@ static void set_stealth_status() { buzzer_enable(); leds_begin(); } - menus_module_set_app_state(false, NULL); - menu_screens_exit_submenu(); + menus_module_exit_app(); vTaskDelete(NULL); } diff --git a/firmware/main/modules/web_file_browser/http_server/web_file_browser.c b/firmware/main/modules/web_file_browser/http_server/web_file_browser.c index 32dcb3d0..d72775a8 100644 --- a/firmware/main/modules/web_file_browser/http_server/web_file_browser.c +++ b/firmware/main/modules/web_file_browser/http_server/web_file_browser.c @@ -39,7 +39,7 @@ static void web_file_browser_show_event(uint8_t event, void* context) { } } -void web_file_browser_init() { +void web_file_browser_begin() { #if !defined(CONFIG_WEB_FILE_BROWSER_DEBUG) esp_log_level_set(TAG, ESP_LOG_NONE); #endif diff --git a/firmware/main/modules/web_file_browser/http_server/web_file_browser.h b/firmware/main/modules/web_file_browser/http_server/web_file_browser.h index 5a22447e..1ae7646e 100644 --- a/firmware/main/modules/web_file_browser/http_server/web_file_browser.h +++ b/firmware/main/modules/web_file_browser/http_server/web_file_browser.h @@ -14,6 +14,6 @@ typedef enum { typedef void (*web_file_browser_show_event_cb_t)(uint8_t, void*); web_file_browser_show_event_cb_t wfb_show_event_cb = NULL; -void web_file_browser_init(); +void web_file_browser_begin(); void web_file_browser_stop(); void web_file_browser_set_show_event_cb(web_file_browser_show_event_cb_t cb); \ No newline at end of file diff --git a/firmware/main/modules/web_file_browser/web_file_browser_module.c b/firmware/main/modules/web_file_browser/web_file_browser_module.c index 451f7dd6..0e32f19c 100644 --- a/firmware/main/modules/web_file_browser/web_file_browser_module.c +++ b/firmware/main/modules/web_file_browser/web_file_browser_module.c @@ -15,7 +15,7 @@ static void web_file_browser_input_cb(uint8_t button_name, uint8_t button_event); static void web_file_browser_module_exit(); -void web_file_browser_module_init() { +void web_file_browser_module_begin() { oled_screen_clear(); menus_module_set_app_state(true, web_file_browser_input_cb); if (sd_card_mount() == ESP_OK || flash_fs_mount() == ESP_OK) { @@ -25,7 +25,7 @@ void web_file_browser_module_init() { } // wifi_ap_init(); web_file_browser_set_show_event_cb(web_file_browse_show_event_handler); - web_file_browser_init(); + web_file_browser_begin(); } else { oled_screen_display_text(" SD Card ", 0, 3, OLED_DISPLAY_NORMAL); oled_screen_display_text(" Mount Failed ", 0, 4, OLED_DISPLAY_NORMAL); @@ -34,7 +34,7 @@ void web_file_browser_module_init() { } } void web_file_browser_module_exit() { - screen_module_set_screen(MENU_FILE_MANAGER_WEB); + menus_module_set_reset_screen(MENU_FILE_MANAGER_2); esp_restart(); } static void web_file_browser_input_cb(uint8_t button_name, diff --git a/firmware/main/modules/web_file_browser/web_file_browser_module.h b/firmware/main/modules/web_file_browser/web_file_browser_module.h index c8eb2f3c..8f33c52b 100644 --- a/firmware/main/modules/web_file_browser/web_file_browser_module.h +++ b/firmware/main/modules/web_file_browser/web_file_browser_module.h @@ -1,3 +1,3 @@ #pragma once -void web_file_browser_module_init(); \ No newline at end of file +void web_file_browser_module_begin(); \ No newline at end of file diff --git a/firmware/main/modules/wifi/wifi_module.c b/firmware/main/modules/wifi/wifi_module.c index bbd8c9a0..56fb82a0 100644 --- a/firmware/main/modules/wifi/wifi_module.c +++ b/firmware/main/modules/wifi/wifi_module.c @@ -10,15 +10,15 @@ #include "string.h" #include "apps/wifi/deauth/include/deauth_module.h" -#include "captive_portal.h" #include "led_events.h" #include "menu_screens_modules.h" -#include "modules/wifi/wifi_module.h" +#include "menus_module.h" #include "modules/wifi/wifi_screens_module.h" #include "oled_screen.h" #include "sd_card.h" #include "wifi_attacks.h" #include "wifi_controller.h" +#include "wifi_module.h" #include "wifi_scanner.h" static const char* TAG = "wifi_module"; @@ -115,6 +115,34 @@ void wifi_module_init_sniffer() { led_control_run_effect(led_control_zigbee_scanning); } +void wifi_module_analyzer_run_exit() { + wifi_sniffer_stop(); + led_control_stop(); + wifi_sniffer_load_summary(); +} + +void wifi_module_analizer_summary_exit() { + wifi_sniffer_close_file(); +} + +void wifi_module_analizer_exit() { + menus_module_set_reset_screen(MENU_WIFI_APPS_2); + esp_restart(); +} + +void wifi_module_analyzer_destination_exit() { + if (wifi_sniffer_is_destination_sd()) { + // Verify if the SD card is inserted + sd_card_unmount(); + if (sd_card_mount() == ESP_OK) { + vTaskDelay(100 / portTICK_PERIOD_MS); + sd_card_unmount(); + } else { + wifi_sniffer_set_destination_internal(); + } + } +} + void wifi_module_exit_submenu_cb() { screen_module_menu_t current_menu = menu_screens_get_current_menu(); @@ -123,9 +151,6 @@ void wifi_module_exit_submenu_cb() { menu_screens_unregister_submenu_cbs(); break; case MENU_WIFI_ANALYZER_RUN: - wifi_sniffer_stop(); - led_control_stop(); - wifi_sniffer_load_summary(); break; case MENU_WIFI_ANALYZER_ASK_SUMMARY: oled_screen_clear(); diff --git a/firmware/main/modules/wifi/wifi_module.h b/firmware/main/modules/wifi/wifi_module.h index b74aca81..0304bc9c 100644 --- a/firmware/main/modules/wifi/wifi_module.h +++ b/firmware/main/modules/wifi/wifi_module.h @@ -11,13 +11,6 @@ */ void wifi_module_begin(); -/** - * @brief Initialize the wifi module - * - * @return void - */ -void wifi_module_deauth_begin(); - /** * @brief Initialize the wifi module * @@ -25,11 +18,17 @@ void wifi_module_deauth_begin(); */ void wifi_module_analizer_begin(); +void wifi_module_init_sniffer(); + /** * @brief Stop the wifi module * */ void wifi_module_exit(void); +void wifi_module_analyzer_run_exit(); +void wifi_module_analizer_exit(); +void wifi_module_analizer_summary_exit(); +void wifi_module_analyzer_destination_exit(); /** * @brief Callback to show the summary of the wifi analizer diff --git a/firmware/main/modules/zigbee/zigbee_module.c b/firmware/main/modules/zigbee/zigbee_module.c index a5473b44..99c7a778 100644 --- a/firmware/main/modules/zigbee/zigbee_module.c +++ b/firmware/main/modules/zigbee/zigbee_module.c @@ -23,8 +23,8 @@ static TaskHandle_t zigbee_task_display_animation = NULL; static TaskHandle_t zigbee_task_sniffer = NULL; static void zigbee_module_app_selector(); -static void zigbee_module_state_machine(uint8_t button_name, - uint8_t button_event); +static void switch_input_cb(uint8_t button_name, uint8_t button_event); +static void sniffer_input_cb(uint8_t button_name, uint8_t button_event); static void zigbee_module_display_records_cb(uint8_t* packet, uint8_t packet_length) { @@ -41,106 +41,62 @@ void zigbee_module_begin(int app_selected) { #if !defined(CONFIG_ZIGBEE_MODULE_DEBUG) esp_log_level_set(TAG_ZIGBEE_MODULE, ESP_LOG_NONE); #endif - - ESP_LOGI(TAG_ZIGBEE_MODULE, - "Initializing zigbee module screen state machine"); - app_screen_state_information.app_selected = app_selected; - - menus_module_set_app_state(true, zigbee_module_state_machine); - oled_screen_clear(OLED_DISPLAY_NORMAL); - zigbee_module_app_selector(); }; void zigbee_module_app_selector() { switch (app_screen_state_information.app_selected) { case MENU_ZIGBEE_SWITCH: - radio_selector_set_zigbee_switch(); - zigbee_switch_set_display_status_cb(zigbee_screens_module_display_status); - zigbee_switch_init(); break; case MENU_ZIGBEE_SNIFFER: - radio_selector_set_zigbee_sniffer(); - zigbee_screens_display_device_ad(); - vTaskDelay(8000 / portTICK_PERIOD_MS); - ieee_sniffer_register_cb(zigbee_module_display_records_cb); - zigbee_screens_display_zigbee_sniffer_text(); - animations_task_run(zigbee_screens_display_scanning_animation, 200, NULL); - xTaskCreate(ieee_sniffer_begin, "ieee_sniffer_task", 4096, NULL, 5, - &zigbee_task_sniffer); - led_control_run_effect(led_control_zigbee_scanning); break; default: break; } } -void zigbee_module_state_machine(uint8_t button_name, uint8_t button_event) { - switch (app_screen_state_information.app_selected) { - case MENU_ZIGBEE_SWITCH: - ESP_LOGI(TAG_ZIGBEE_MODULE, "Zigbee Switch Entered"); - switch (button_name) { - case BUTTON_RIGHT: - switch (button_event) { - case BUTTON_PRESS_DOWN: - if (zigbee_switch_is_light_connected()) { - zigbee_screens_module_toogle_pressed(); - } - break; - case BUTTON_PRESS_UP: - if (zigbee_switch_is_light_connected()) { - zigbee_screens_module_toggle_released(); - zigbee_switch_toggle(); - } - break; +void zigbee_module_switch_enter() { + radio_selector_set_zigbee_switch(); + menus_module_set_app_state(true, switch_input_cb); + zigbee_switch_set_display_status_cb(zigbee_screens_module_display_status); + zigbee_switch_init(); +} + +void zigbee_module_sniffer_enter() { + radio_selector_set_zigbee_sniffer(); + menus_module_set_app_state(true, sniffer_input_cb); + zigbee_screens_display_device_ad(); + vTaskDelay(8000 / portTICK_PERIOD_MS); + ieee_sniffer_register_cb(zigbee_module_display_records_cb); + zigbee_screens_display_zigbee_sniffer_text(); + animations_task_run(zigbee_screens_display_scanning_animation, 200, NULL); + xTaskCreate(ieee_sniffer_begin, "ieee_sniffer_task", 4096, NULL, 5, + &zigbee_task_sniffer); + led_control_run_effect(led_control_zigbee_scanning); +} + +static void switch_input_cb(uint8_t button_name, uint8_t button_event) { + ESP_LOGI(TAG_ZIGBEE_MODULE, "Zigbee Switch Entered"); + switch (button_name) { + case BUTTON_RIGHT: + switch (button_event) { + case BUTTON_PRESS_DOWN: + if (zigbee_switch_is_light_connected()) { + zigbee_screens_module_toogle_pressed(); } break; - case BUTTON_LEFT: - switch (button_event) { - case BUTTON_PRESS_DOWN: - screen_module_set_screen(MENU_ZIGBEE_SWITCH); - zigbee_switch_deinit(); - break; + case BUTTON_PRESS_UP: + if (zigbee_switch_is_light_connected()) { + zigbee_screens_module_toggle_released(); + zigbee_switch_toggle(); } break; - default: - break; } break; - case MENU_ZIGBEE_SNIFFER: - ESP_LOGI(TAG_ZIGBEE_MODULE, "Zigbee Sniffer Entered"); - switch (button_name) { - case BUTTON_LEFT: - if (button_event == BUTTON_SINGLE_CLICK) { - led_control_stop(); - screen_module_set_screen(MENU_ZIGBEE_SNIFFER); - esp_restart(); - } - break; - case BUTTON_RIGHT: - ESP_LOGI(TAG_ZIGBEE_MODULE, "Button right pressed - Option selected"); - break; - case BUTTON_UP: - ESP_LOGI(TAG_ZIGBEE_MODULE, "Button up pressed"); - if (button_event == BUTTON_SINGLE_CLICK) { - current_channel = (current_channel == IEEE_SNIFFER_CHANNEL_MAX) - ? IEEE_SNIFFER_CHANNEL_MIN - : (current_channel + 1); - ieee_sniffer_set_channel(current_channel); - // zigbee_screens_display_scanning_text(0, current_channel); - } - break; - case BUTTON_DOWN: - ESP_LOGI(TAG_ZIGBEE_MODULE, "Button down pressed"); - if (button_event == BUTTON_SINGLE_CLICK) { - current_channel = (current_channel == IEEE_SNIFFER_CHANNEL_MIN) - ? IEEE_SNIFFER_CHANNEL_MAX - : (current_channel - 1); - ieee_sniffer_set_channel(current_channel); - // zigbee_screens_display_scanning_text(0, current_channel); - } - break; - case BUTTON_BOOT: - default: + case BUTTON_LEFT: + switch (button_event) { + case BUTTON_PRESS_DOWN: + menus_module_set_reset_screen(MENU_ZIGBEE_SPOOFING_2); + zigbee_switch_deinit(); break; } break; @@ -148,3 +104,42 @@ void zigbee_module_state_machine(uint8_t button_name, uint8_t button_event) { break; } } + +static void sniffer_input_cb(uint8_t button_name, uint8_t button_event) { + ESP_LOGI(TAG_ZIGBEE_MODULE, "Zigbee Sniffer Entered"); + switch (button_name) { + case BUTTON_LEFT: + if (button_event == BUTTON_SINGLE_CLICK) { + led_control_stop(); + menus_module_set_reset_screen(MENU_ZIGBEE_APPS_2); + esp_restart(); + } + break; + case BUTTON_RIGHT: + ESP_LOGI(TAG_ZIGBEE_MODULE, "Button right pressed - Option selected"); + break; + case BUTTON_UP: + ESP_LOGI(TAG_ZIGBEE_MODULE, "Button up pressed"); + if (button_event == BUTTON_SINGLE_CLICK) { + current_channel = (current_channel == IEEE_SNIFFER_CHANNEL_MAX) + ? IEEE_SNIFFER_CHANNEL_MIN + : (current_channel + 1); + ieee_sniffer_set_channel(current_channel); + // zigbee_screens_display_scanning_text(0, current_channel); + } + break; + case BUTTON_DOWN: + ESP_LOGI(TAG_ZIGBEE_MODULE, "Button down pressed"); + if (button_event == BUTTON_SINGLE_CLICK) { + current_channel = (current_channel == IEEE_SNIFFER_CHANNEL_MIN) + ? IEEE_SNIFFER_CHANNEL_MAX + : (current_channel - 1); + ieee_sniffer_set_channel(current_channel); + // zigbee_screens_display_scanning_text(0, current_channel); + } + break; + case BUTTON_BOOT: + default: + break; + } +} diff --git a/firmware/main/modules/zigbee/zigbee_module.h b/firmware/main/modules/zigbee/zigbee_module.h index 6a1c2fd0..db8c07e5 100644 --- a/firmware/main/modules/zigbee/zigbee_module.h +++ b/firmware/main/modules/zigbee/zigbee_module.h @@ -7,4 +7,9 @@ * @param app_selected The selected app */ void zigbee_module_begin(int app_selected); + +void zigbee_module_switch_enter(); + +void zigbee_module_sniffer_enter(); + #endif // ZIGBEE_MODULE_H diff --git a/firmware/main/modules/zigbee/zigbee_screens_module.c b/firmware/main/modules/zigbee/zigbee_screens_module.c index 69e64c6b..921868cc 100644 --- a/firmware/main/modules/zigbee/zigbee_screens_module.c +++ b/firmware/main/modules/zigbee/zigbee_screens_module.c @@ -1,4 +1,5 @@ #include "zigbee_screens_module.h" +#include "general/general_screens.h" #include "oled_screen.h" #include "zigbee_bitmaps.h" #include "zigbee_switch.h" @@ -15,40 +16,34 @@ void zigbee_screens_module_toggle_released() { void zigbee_screens_module_creating_network() { oled_screen_clear(); - oled_screen_display_text("Creating", 25, 3, OLED_DISPLAY_NORMAL); - oled_screen_display_text("network...", 20, 4, OLED_DISPLAY_NORMAL); + genera_screen_display_card_information("Creating network", "Please wait..."); } void zigbee_screens_module_creating_network_failed() { oled_screen_clear(); - oled_screen_display_text("Creating", 25, 3, OLED_DISPLAY_NORMAL); - oled_screen_display_text("network", 29, 4, OLED_DISPLAY_NORMAL); - oled_screen_display_text("failed", 33, 5, OLED_DISPLAY_NORMAL); + genera_screen_display_card_information("Creating network", "Failed"); } void zigbee_screens_module_waiting_for_devices() { static uint8_t dots = 0; dots = ++dots > 3 ? 0 : dots; - oled_screen_clear_line(80, 4, OLED_DISPLAY_NORMAL); - oled_screen_display_text("Waiting for", 19, 3, OLED_DISPLAY_NORMAL); - oled_screen_display_text("devices", 24, 4, OLED_DISPLAY_NORMAL); + oled_screen_clear_line(80, 3, OLED_DISPLAY_NORMAL); + genera_screen_display_card_information("Waiting for", "devices"); // Print dots from lef to right for (int i = 0; i < dots; i++) { - oled_screen_display_text(".", 80 + (i * 8), 4, OLED_DISPLAY_NORMAL); + oled_screen_display_text(".", 80 + (i * 8), 3, OLED_DISPLAY_NORMAL); } } void zigbee_screens_module_no_devices_found() { oled_screen_clear(); vTaskDelay(100 / portTICK_PERIOD_MS); - oled_screen_display_text("No devices", 24, 3, OLED_DISPLAY_NORMAL); - oled_screen_display_text("found", 44, 4, OLED_DISPLAY_NORMAL); + genera_screen_display_card_information("No devices", "found"); } void zigbee_screens_module_closing_network() { oled_screen_clear(); - oled_screen_display_text("Closing", 25, 3, OLED_DISPLAY_NORMAL); - oled_screen_display_text("network...", 20, 4, OLED_DISPLAY_NORMAL); + genera_screen_display_card_information("Closing network", "Please wait..."); } void zigbee_screens_module_display_status(uint8_t status) { @@ -81,7 +76,7 @@ void zigbee_screens_module_display_status(uint8_t status) { /////////////////////////////////////////////////////////////////////////// void zigbee_screens_display_device_ad() { oled_screen_clear(OLED_DISPLAY_NORMAL); - int index_page = 1; + int index_page = 0; oled_screen_display_text_splited("Use our", &index_page, OLED_DISPLAY_NORMAL); oled_screen_display_text_splited("PyCatSniffer", &index_page, OLED_DISPLAY_NORMAL);