Skip to content

Commit

Permalink
refactor: analyzer app
Browse files Browse the repository at this point in the history
  • Loading branch information
Otrebor671 committed Oct 23, 2024
1 parent b494197 commit 5051b76
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 101 deletions.
157 changes: 157 additions & 0 deletions firmware/main/apps/wifi_analyzer/scenes/analyzer_scenes.c
Original file line number Diff line number Diff line change
@@ -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);
}
15 changes: 15 additions & 0 deletions firmware/main/apps/wifi_analyzer/scenes/analyzer_scenes.h
Original file line number Diff line number Diff line change
@@ -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();
68 changes: 9 additions & 59 deletions firmware/main/apps/wifi_analyzer/wifi_analyzer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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() {
Expand Down Expand Up @@ -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() {
Expand All @@ -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();
}

Expand All @@ -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;
}
Expand Down
12 changes: 6 additions & 6 deletions firmware/main/apps/wifi_analyzer/wifi_analyzer.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,19 @@ 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
*
*/
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();

Expand All @@ -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();
void analyzer_scenes_destination();
void analyzer_scenes_channel();
38 changes: 2 additions & 36 deletions firmware/main/modules/menus_module/menus_include/menus.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5051b76

Please sign in to comment.