diff --git a/README.md b/README.md index 88c4f5a3..597c9899 100644 --- a/README.md +++ b/README.md @@ -56,15 +56,14 @@ Minino can operate in 6 different technologies: - [x] Analyzer - [ ] Wireshark integration ### BLE -- [ ] BLE Sniffer +- [x] BLE ADV Sniffer (Wireshark Integration) - [x] BLE Spammer - [x] BLE Spoffing (HID device, audio control) - [x] BLE Trackers Scanner (AirTags, Tile, etc) -- [x] Wireshark integration ### Zigbee - [x] Zigbee sniffer - [x] Zigbee spoofing (Switch End Device) -- [ ] Wardriving +- [x] Wardriving - [x] Wireshark integration ### Thread diff --git a/firmware/Makefile b/firmware/Makefile index d31153eb..6cfa63e5 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -21,6 +21,11 @@ clean: rm sdkconfig make setup +ff: + make test_port + idf.py -p $(PORT) erase-flash + make flash monitor + all: flash monitor .PHONY: test_port setup compile flash monitor clean all diff --git a/firmware/README.md b/firmware/README.md index f2f4f459..c7f9c3a8 100644 --- a/firmware/README.md +++ b/firmware/README.md @@ -183,3 +183,33 @@ BLE_SCAN_FILTER_ALLOW_ALL = 0x0, /*!< Accept all : 2. directed advertising packets where the initiator address is a resolvable private address, and 3. directed advertising packets addressed to this device.*/ ``` + +## WIFI + +### DoS test +First run a python simple server with: +`python3 -m http.server` + +Next open the DoS app in minino and if you haven't a AP saved in the serial terminal you need to add your AP: +``` +Welcome to the Minino Console. +Type 'help' to get the list of commands. +Use UP/DOWN arrows to navigate through command history. +Press TAB when typing command name to auto-complete. +Press Enter or Ctrl+C will terminate the console environment. +minino> save AP_NAME PASSWORD +``` + +The minino will try to connect to AP. +Once you have a AP saved if the minino app do not show the AP's exit and come back to the app to load AP, once minino found a AP available this will try to connect and if done, the next screen will show the target, if target is not configured, you need to introduce manually in the serial terminal: +``` +Welcome to the Minino Console. +Type 'help' to get the list of commands. +Use UP/DOWN arrows to navigate through command history. +Press TAB when typing command name to auto-complete. +Press Enter or Ctrl+C will terminate the console environment. +minino> web_config IP_VICTIM PORT_VICTIM _PATH_VICTIM +``` +In this case our victim server are our pc so the command will be like this: `web_config 192.168.0.178 8000 /` + +Then we can execute the command `catdos` to start the attack. \ No newline at end of file diff --git a/firmware/components/ieee_sniffer/ieee_sniffer.c b/firmware/components/ieee_sniffer/ieee_sniffer.c index dc902647..97a3c953 100644 --- a/firmware/components/ieee_sniffer/ieee_sniffer.c +++ b/firmware/components/ieee_sniffer/ieee_sniffer.c @@ -10,10 +10,13 @@ #include "freertos/queue.h" #include "freertos/task.h" +#define HOPPING_TIME 3500 + static esp_err_t err; static QueueHandle_t packet_rx_queue = NULL; static ieee_sniffer_cb_t packet_callback = NULL; static int current_channel = IEEE_SNIFFER_CHANNEL_DEFAULT; +static bool running = false; static void debug_print_packet(uint8_t* packet, uint8_t packet_length); static void debug_handler_task(void* pvParameters); @@ -34,6 +37,14 @@ void ieee_sniffer_register_cb(ieee_sniffer_cb_t callback) { packet_callback = callback; } +uint8_t ieee_sniffer_get_channel() { + return current_channel; +} + +int8_t ieee_sniffer_get_rssi() { + return esp_ieee802154_get_recent_rssi(); +} + void ieee_sniffer_set_channel(int channel) { current_channel = channel; if (channel < IEEE_SNIFFER_CHANNEL_MIN) { @@ -51,7 +62,7 @@ void ieee_sniffer_set_channel(int channel) { ESP_LOGI(TAG_IEEE_SNIFFER, "Channel set to %d", current_channel); } -void ieee_sniffer_begin(void) { +static void ieee_sniffer_configure() { #if !defined(CONFIG_IEEE_SNIFFER_DEBUG) esp_log_level_set(TAG_IEEE_SNIFFER, ESP_LOG_NONE); #endif @@ -92,13 +103,33 @@ void ieee_sniffer_begin(void) { } esp_ieee802154_set_extended_address(eui64_rev); ESP_ERROR_CHECK(esp_ieee802154_receive()); +} - while (true) { +void ieee_sniffer_begin(void) { + running = true; + ieee_sniffer_configure(); + while (running) { vTaskDelay(10 / portTICK_PERIOD_MS); } + vTaskDelete(NULL); +} + +void ieee_sniffer_channel_hop() { + running = true; + ieee_sniffer_configure(); + esp_ieee802154_disable(); + while (running) { + esp_ieee802154_enable(); + ieee_sniffer_set_channel(current_channel + 1); + esp_ieee802154_receive(); + vTaskDelay(HOPPING_TIME / portTICK_PERIOD_MS); + esp_ieee802154_disable(); + } + vTaskDelete(NULL); } void ieee_sniffer_stop(void) { + running = false; err = esp_ieee802154_disable(); if (err != ESP_OK) { ESP_LOGE(TAG_IEEE_SNIFFER, "Error disabling IEEE 802.15.4 driver: %s", diff --git a/firmware/components/ieee_sniffer/ieee_sniffer.h b/firmware/components/ieee_sniffer/ieee_sniffer.h index 7e7e2ecf..836ce200 100644 --- a/firmware/components/ieee_sniffer/ieee_sniffer.h +++ b/firmware/components/ieee_sniffer/ieee_sniffer.h @@ -78,4 +78,10 @@ void ieee_sniffer_stop(void); * @param channel The channel to set */ void ieee_sniffer_set_channel(int channel); + +uint8_t ieee_sniffer_get_channel(); +int8_t ieee_sniffer_get_rssi(); + +void ieee_sniffer_channel_hop(); + #endif // IEEE_SNIFFER_H diff --git a/firmware/components/minino_config/Kconfig.projbuild b/firmware/components/minino_config/Kconfig.projbuild index ea1cbcfe..e2144bc8 100644 --- a/firmware/components/minino_config/Kconfig.projbuild +++ b/firmware/components/minino_config/Kconfig.projbuild @@ -642,6 +642,21 @@ config ZIGBEE_APP_SPOOFING help Enable or disable the Zigbee Spoofing application. +if ZIGBEE_APP_SPOOFING + +config ZIGBEE_APP_SPOOFING_SWITCH + bool "Enable Spoofing Switch App" + default true + help + Enable or disable the Zigbee Spoofing Switch application. + +config ZIGBEE_APP_SNIFFER_LIGHT + bool "Enable Spoofing Light App" + default true + help + Enable or disable the Zigbee Spoofing Light application. +endif # ZIGBEE_APP_SPOOFING + config ZIGBEE_APP_SNIFFER bool "Enable Sniffer App" default true @@ -687,6 +702,12 @@ config GPS_APP_WARDRIVING default true help Enable or disable the GPS Wardriving application. + +config GPS_APP_WARDRIVING_ZB + bool "Enable Wardriving Zigbee App" + default true + help + Enable or disable the GPS Wardriving Zigbee application. endif # GPS_APPS_ENABLE ################################# OTA ################################### diff --git a/firmware/components/sd_card/include/sd_card.h b/firmware/components/sd_card/include/sd_card.h index 970ce548..f6c3b09d 100644 --- a/firmware/components/sd_card/include/sd_card.h +++ b/firmware/components/sd_card/include/sd_card.h @@ -139,3 +139,5 @@ esp_err_t sd_card_write_file(const char* path, char* data); * @return sd_card_info_t */ sd_card_info_t sd_card_get_info(); + +esp_err_t sd_card_append_to_file(const char* path, char* data); \ No newline at end of file diff --git a/firmware/components/sd_card/sd_card.c b/firmware/components/sd_card/sd_card.c index c2b9433c..5612a4f4 100644 --- a/firmware/components/sd_card/sd_card.c +++ b/firmware/components/sd_card/sd_card.c @@ -272,6 +272,11 @@ esp_err_t sd_card_read_file(const char* path) { return ESP_FAIL; } + if (path == NULL) { + ESP_LOGE(TAG, "Path is NULL"); + return ESP_FAIL; + } + uint8_t path_len = strlen(path); char full_path[path_len + 1 + strlen(MOUNT_POINT)]; sprintf(full_path, "%s/%s", MOUNT_POINT, path); @@ -308,7 +313,7 @@ esp_err_t sd_card_write_file(const char* path, char* data) { char full_path[path_len + 1 + strlen(MOUNT_POINT)]; sprintf(full_path, "%s/%s", MOUNT_POINT, path); - ESP_LOGI(TAG, "Opening file %s", full_path); + ESP_LOGI(TAG, "Opening file w %s", full_path); FILE* file = fopen(full_path, "w"); if (file == NULL) { ESP_LOGE(TAG, "Failed to open file for writing"); @@ -321,6 +326,29 @@ esp_err_t sd_card_write_file(const char* path, char* data) { return ESP_OK; } +esp_err_t sd_card_append_to_file(const char* path, char* data) { + if (sd_card_is_not_mounted()) { + ESP_LOGE(TAG, "SD card not mounted"); + return ESP_FAIL; + } + + uint8_t path_len = strlen(path); + char full_path[path_len + 1 + strlen(MOUNT_POINT)]; + sprintf(full_path, "%s/%s", MOUNT_POINT, path); + + ESP_LOGI(TAG, "Opening file a %s", full_path); + FILE* file = fopen(full_path, "a"); + if (file == NULL) { + ESP_LOGE(TAG, "Failed to open file for writing"); + return ESP_FAIL; + } + fprintf(file, data); + fclose(file); + ESP_LOGI(TAG, "File written"); + + return ESP_OK; +} + size_t sd_card_get_file_size(FILE* file) { if (file == NULL) { return 0; diff --git a/firmware/components/wifi_scanner/wifi_scanner.c b/firmware/components/wifi_scanner/wifi_scanner.c index d7accb15..3a75addb 100644 --- a/firmware/components/wifi_scanner/wifi_scanner.c +++ b/firmware/components/wifi_scanner/wifi_scanner.c @@ -18,16 +18,44 @@ void wifi_scanner_module_scan() { if (err != ESP_OK) { ESP_LOGE(TAG_WIFI_SCANNER_MODULE, "Failed to create event loop: %s", esp_err_to_name(err)); + esp_event_loop_delete_default(); + esp_event_loop_create_default(); } ap_records.count = CONFIG_SCAN_MAX_AP; - ESP_ERROR_CHECK(esp_wifi_start()); - ESP_ERROR_CHECK(esp_wifi_clear_ap_list()); - ESP_ERROR_CHECK(esp_wifi_scan_start(NULL, true)); + wifi_init_config_t cfg = WIFI_INIT_CONFIG_DEFAULT(); + err = esp_wifi_init(&cfg); + if (err != ESP_OK) { + ESP_LOGE(TAG_WIFI_SCANNER_MODULE, "Failed to init wifi: %s", + esp_err_to_name(err)); + return; + } + err = esp_wifi_start(); + if (err != ESP_OK) { + ESP_LOGE(TAG_WIFI_SCANNER_MODULE, "Failed to start wifi: %s", + esp_err_to_name(err)); + return; + } + err = esp_wifi_clear_ap_list(); + if (err != ESP_OK) { + ESP_LOGE(TAG_WIFI_SCANNER_MODULE, "Failed to clear AP list: %s", + esp_err_to_name(err)); + return; + } + err = esp_wifi_scan_start(NULL, true); + if (err != ESP_OK) { + ESP_LOGE(TAG_WIFI_SCANNER_MODULE, "Failed to start scan: %s", + esp_err_to_name(err)); + return; + } ESP_LOGI(TAG_WIFI_SCANNER_MODULE, "Max AP number ap_info can hold = %u", ap_records.count); - ESP_ERROR_CHECK( - esp_wifi_scan_get_ap_records(&ap_records.count, ap_records.records)); + err = esp_wifi_scan_get_ap_records(&ap_records.count, ap_records.records); + if (err != ESP_OK) { + ESP_LOGE(TAG_WIFI_SCANNER_MODULE, "Failed to get AP records: %s", + esp_err_to_name(err)); + return; + } ESP_LOGI(TAG_WIFI_SCANNER_MODULE, "Found %u APs.", ap_records.count); ESP_LOGD(TAG_WIFI_SCANNER_MODULE, "Scan done."); } diff --git a/firmware/components/wifi_sniffer/cmd_pcap.c b/firmware/components/wifi_sniffer/cmd_pcap.c index 70884dcd..09b0a263 100644 --- a/firmware/components/wifi_sniffer/cmd_pcap.c +++ b/firmware/components/wifi_sniffer/cmd_pcap.c @@ -157,7 +157,6 @@ static esp_err_t pcap_open(pcap_cmd_runtime_t* pcap) { } else { ESP_LOGE(TAG, "pcap file destination hasn't specified"); } - ESP_GOTO_ON_FALSE(fp, ESP_FAIL, err, TAG, "open file failed"); pcap_config_t pcap_config = { .fp = fp, @@ -465,7 +464,7 @@ int do_pcap_cmd(int argc, char** argv) { } if (pcap_args.open->count) { - pcap_open(&pcap_cmd_rt); + ret = pcap_open(&pcap_cmd_rt); } err: return ret; diff --git a/firmware/components/wifi_sniffer/cmd_sniffer.c b/firmware/components/wifi_sniffer/cmd_sniffer.c index 251ab5ab..59b1a851 100644 --- a/firmware/components/wifi_sniffer/cmd_sniffer.c +++ b/firmware/components/wifi_sniffer/cmd_sniffer.c @@ -45,9 +45,11 @@ static wlan_filter_table_t wifi_filter_hash_table[SNIFFER_WLAN_FILTER_MAX] = { static sniffer_cb_t sniffer_cb = NULL; static sniffer_animation_cb_t sniffer_animation_start_cb = NULL; static sniffer_animation_cb_t sniffer_animation_stop_cb = NULL; +static void (*out_of_mem_cb)(); -void wifi_sniffer_register_cb(sniffer_cb_t callback) { +void wifi_sniffer_register_cb(sniffer_cb_t callback, void* _out_of_mem_cb) { sniffer_cb = callback; + out_of_mem_cb = _out_of_mem_cb; } void wifi_sniffer_register_animation_cbs(sniffer_animation_cb_t start_cb, @@ -69,6 +71,7 @@ static uint32_t hash_func(const char* str, uint32_t max_num) { } static void create_wifi_filter_hashtable(void) { + memset(wifi_filter_hash_table, 0, sizeof(wifi_filter_hash_table)); char* wifi_filter_keys[SNIFFER_WLAN_FILTER_MAX] = { "mgmt", "data", "ctrl", "misc", "mpdu", "ampdu", "fcsfail"}; uint32_t wifi_filter_values[SNIFFER_WLAN_FILTER_MAX] = { @@ -146,6 +149,7 @@ static void wifi_sniffer_cb(void* recv_buf, wifi_promiscuous_pkt_type_t type) { static void sniffer_task(void* parameters) { sniffer_packet_info_t packet_info; sniffer_runtime_t* sniffer = (sniffer_runtime_t*) parameters; + bool force_exit = false; if (sniffer_animation_start_cb) { sniffer_animation_start_cb(); } @@ -171,6 +175,11 @@ static void sniffer_task(void* parameters) { packet_info.seconds, packet_info.microseconds) != ESP_OK) { ESP_LOGW(TAG, "save captured packet failed"); + if (out_of_mem_cb) { + xSemaphoreGive(sniffer->sem_task_over); + force_exit = true; + out_of_mem_cb(); + } } free(packet_info.payload); if (sniffer->packets_to_sniff > 0) { @@ -186,7 +195,9 @@ static void sniffer_task(void* parameters) { } /* notify that sniffer task is over */ if (sniffer->packets_to_sniff != 0) { - xSemaphoreGive(sniffer->sem_task_over); + if (!force_exit) { + xSemaphoreGive(sniffer->sem_task_over); + } } if (sniffer_cb) { sniffer_cb(sniffer); @@ -322,6 +333,7 @@ static esp_err_t sniffer_start(sniffer_runtime_t* sniffer) { err_queue: sniffer->is_running = false; err: + out_of_mem_cb(); return ret; } diff --git a/firmware/components/wifi_sniffer/include/cmd_sniffer.h b/firmware/components/wifi_sniffer/include/cmd_sniffer.h index 6b3530d8..f055a7fd 100644 --- a/firmware/components/wifi_sniffer/include/cmd_sniffer.h +++ b/firmware/components/wifi_sniffer/include/cmd_sniffer.h @@ -64,7 +64,7 @@ typedef void (*sniffer_animation_cb_t)(void); void register_sniffer_cmd(void); int do_sniffer_cmd(int argc, char** argv); -void wifi_sniffer_register_cb(sniffer_cb_t callback); +void wifi_sniffer_register_cb(sniffer_cb_t callback, void* _out_of_mem_cb); void wifi_sniffer_register_animation_cbs(sniffer_animation_cb_t start_cb, sniffer_animation_cb_t stop_cb); diff --git a/firmware/components/wifi_sniffer/include/wifi_sniffer.h b/firmware/components/wifi_sniffer/include/wifi_sniffer.h index 7d59befa..38285009 100644 --- a/firmware/components/wifi_sniffer/include/wifi_sniffer.h +++ b/firmware/components/wifi_sniffer/include/wifi_sniffer.h @@ -24,7 +24,7 @@ void wifi_sniffer_begin(); * * @return void */ -void wifi_sniffer_start(); +esp_err_t wifi_sniffer_start(); /** * @brief Stop the wifi sniffer diff --git a/firmware/components/wifi_sniffer/wifi_sniffer.c b/firmware/components/wifi_sniffer/wifi_sniffer.c index c259ca1c..6df06330 100644 --- a/firmware/components/wifi_sniffer/wifi_sniffer.c +++ b/firmware/components/wifi_sniffer/wifi_sniffer.c @@ -39,14 +39,13 @@ void wifi_sniffer_begin() { #if !defined(CONFIG_WIFI_SNIFFER_DEBUG) esp_log_level_set(TAG, ESP_LOG_NONE); #endif - wifi_driver_init_null(); register_sniffer_cmd(); register_pcap_cmd(); ESP_LOGI(TAG, "Commands registered"); } -void wifi_sniffer_start() { +esp_err_t wifi_sniffer_start() { ESP_LOGI(TAG, "Starting sniffer"); if (wifi_sniffer_is_destination_sd()) { @@ -55,7 +54,10 @@ void wifi_sniffer_start() { const char** pcap_argv[] = {"pcap", "--open", "-f", "sniffer"}; uint8_t pcap_argc = 4; - do_pcap_cmd(pcap_argc, (char**) pcap_argv); + esp_err_t ret = do_pcap_cmd(pcap_argc, (char**) pcap_argv); + if (ret != ESP_OK) { + return ret; + } char* channel_str = (char*) malloc(4); uint8_t channel = wifi_sniffer_get_channel(); @@ -64,6 +66,7 @@ void wifi_sniffer_start() { channel_str, "-n", "2147483647"}; uint8_t sniffer_argc = 7; do_sniffer_cmd(sniffer_argc, (char**) sniffer_argv); + return ESP_OK; } void wifi_sniffer_stop() { diff --git a/firmware/components/zigbee_switch/zigbee_switch.c b/firmware/components/zigbee_switch/zigbee_switch.c index 51c44633..14223769 100644 --- a/firmware/components/zigbee_switch/zigbee_switch.c +++ b/firmware/components/zigbee_switch/zigbee_switch.c @@ -279,11 +279,8 @@ void network_failed_task(void* pvParameters) { */ void wait_for_devices_task(void* pvParameters) { while (true) { - if (switch_state != SWITCH_WAIT_FOR_DEVICES) { - continue; - } zigbee_switch_display_status_cb(WAITING_FOR_DEVICES); - vTaskDelay(300 / portTICK_PERIOD_MS); + vTaskDelay(pdMS_TO_TICKS(300)); } } @@ -298,7 +295,6 @@ void switch_state_machine_task(void* pvParameters) { while (true) { if (switch_state != switch_state_prev) { ESP_LOGI(TAG, "Switch state: %s", switch_state_names[switch_state]); - switch (switch_state) { case SWITCH_CREATE_NETWORK: zigbee_switch_display_status_cb(CREATING_NETWORK); diff --git a/firmware/get_build.sh b/firmware/get_build.sh index d4e345ac..101193d3 100755 --- a/firmware/get_build.sh +++ b/firmware/get_build.sh @@ -14,7 +14,6 @@ NO_OTA_BUILD_FINAL_DIR="minino-noota-firmware-$PROJECT_VERSION" # Build the firmware echo "Building ota firmware..." -make setup idf.py @profiles/ota build mkdir -p $TEMPORARY_BUILD_DIR @@ -48,5 +47,7 @@ echo "Cleaning build files..." rm -rf $TEMPORARY_BUILD_DIR rm -rf $OTA_BUILD_FINAL_DIR rm -rf $NO_OTA_BUILD_FINAL_DIR +rm -rf build-noota +rm -rf build-ota echo "Done!" diff --git a/firmware/main/apps/wifi/deauth/deauth_module.c b/firmware/main/apps/wifi/deauth/deauth_module.c index e62058a0..0f2e2d07 100644 --- a/firmware/main/apps/wifi/deauth/deauth_module.c +++ b/firmware/main/apps/wifi/deauth/deauth_module.c @@ -47,13 +47,13 @@ static void deauth_module_cb_event_run(uint8_t button_name, static void deauth_module_cb_event_captive_portal(uint8_t button_name, uint8_t button_event); -static void scanning_task(void* pvParameters); +static void scanning_task(); static void deauth_run_scan_task(); static void deauth_increment_item(); static void deauth_decrement_item(); static void deauth_handle_attacks(); -static void scanning_task(void* pvParameters) { +static void scanning_task() { uint8_t scan_count = 0; while (ap_records->count < (DEFAULT_SCAN_LIST_SIZE / 2) && scan_count < SCAN_RETRIES) { @@ -126,6 +126,13 @@ void deauth_module_begin() { memset(¤t_wifi_state.wifi_config, 0, sizeof(wifi_config_t)); current_wifi_state.wifi_config = wifi_driver_access_point_begin(); + ap_records = wifi_scanner_get_ap_records(); + if (ap_records == NULL) { + ESP_LOGE("deauth", "Failed to get ap records"); + return; + } + ap_records->count = 0; + xTaskCreate(scanning_task, "wifi_scan", 4096, NULL, 5, NULL); deauth_run_scan_task(); diff --git a/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.c b/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.c index a9e159f1..65e049ab 100644 --- a/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.c +++ b/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.c @@ -3,6 +3,7 @@ #include "animations_task.h" #include "esp_log.h" #include "esp_wifi.h" +#include "general_screens.h" #include "oled_screen.h" #include "wifi_bitmaps.h" @@ -29,6 +30,8 @@ void wifi_screens_module_display_sniffer_cb(sniffer_runtime_t* sniffer) { OLED_DISPLAY_INVERT); oled_screen_display_text(channel_str, x_offset, pkts_offset + 1, OLED_DISPLAY_INVERT); + free(packets_str); + free(channel_str); } else { ESP_LOGI(TAG_WIFI_SCREENS_MODULE, "sniffer task stopped"); } @@ -78,3 +81,7 @@ void wifi_screeens_show_sd_not_found() { vTaskDelay(2000 / portTICK_PERIOD_MS); oled_screen_clear(); } + +void wifi_screens_show_no_mem() { + genera_screen_display_card_information("Out of memory", "free up space"); +} \ No newline at end of file diff --git a/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.h b/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.h index 1b7d8a0e..fcc31836 100644 --- a/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.h +++ b/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.h @@ -58,4 +58,6 @@ void wifi_screens_sniffer_animation_stop(); void wifi_screeens_show_sd_not_supported(); -void wifi_screeens_show_sd_not_found(); \ No newline at end of file +void wifi_screeens_show_sd_not_found(); + +void wifi_screens_show_no_mem(); \ No newline at end of file diff --git a/firmware/main/apps/wifi_analyzer/wifi_analyzer.c b/firmware/main/apps/wifi_analyzer/wifi_analyzer.c index 2f2ef825..28545c95 100644 --- a/firmware/main/apps/wifi_analyzer/wifi_analyzer.c +++ b/firmware/main/apps/wifi_analyzer/wifi_analyzer.c @@ -25,6 +25,7 @@ static const char* TAG = "wifi_module"; static bool analizer_initialized = false; +static bool no_mem = false; static general_menu_t analyzer_summary_menu; static char* wifi_analizer_summary_2[120] = { @@ -32,6 +33,7 @@ static char* wifi_analizer_summary_2[120] = { }; static void wifi_module_input_cb(uint8_t button_name, uint8_t button_event); +static void wifi_module_summary_exit_cb(); uint16_t get_summary_rows_count() { uint8_t num_items = 0; @@ -48,10 +50,22 @@ uint16_t get_summary_rows_count() { return num_items; } -void wifi_module_init_sniffer() { +static void out_of_mem_handler() { + no_mem = true; + if (analizer_initialized) { + wifi_module_analyzer_run_exit(); + } else { + wifi_module_summary_exit_cb(); + } + wifi_screens_show_no_mem(); + no_mem = false; +} + +esp_err_t wifi_module_init_sniffer() { oled_screen_clear(); + esp_err_t err = ESP_OK; if (wifi_sniffer_is_destination_sd()) { - esp_err_t err = sd_card_mount(); + err = sd_card_mount(); switch (err) { case ESP_OK: ESP_LOGI(TAG, "SD card mounted"); @@ -71,11 +85,19 @@ void wifi_module_init_sniffer() { break; } } - wifi_sniffer_start(); + err = wifi_sniffer_start(); + if (err != ESP_OK) { + analizer_initialized = false; + out_of_mem_handler(); + return err; + } led_control_run_effect(led_control_zigbee_scanning); + return ESP_OK; } static void wifi_module_summary_exit_cb() { - wifi_sniffer_close_file(); + if (analizer_initialized) { + wifi_sniffer_close_file(); + } analyzer_scenes_main_menu(); } @@ -112,13 +134,21 @@ void wifi_module_analyzer_destination_exit() { } void wifi_analyzer_run() { - wifi_module_init_sniffer(); + esp_err_t err = wifi_module_init_sniffer(); + if (err != ESP_OK) { + return; + } menus_module_set_app_state(true, wifi_module_input_cb); } void wifi_analyzer_begin() { + if (no_mem) { + no_mem = false; + return; + } ESP_LOGI(TAG, "Initializing WiFi analizer module"); - wifi_sniffer_register_cb(wifi_screens_module_display_sniffer_cb); + wifi_sniffer_register_cb(wifi_screens_module_display_sniffer_cb, + out_of_mem_handler); 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); diff --git a/firmware/main/apps/wifi_analyzer/wifi_analyzer.h b/firmware/main/apps/wifi_analyzer/wifi_analyzer.h index 0ff87619..cc848cee 100644 --- a/firmware/main/apps/wifi_analyzer/wifi_analyzer.h +++ b/firmware/main/apps/wifi_analyzer/wifi_analyzer.h @@ -17,7 +17,7 @@ void wifi_module_begin(); */ void wifi_analyzer_begin(); -void wifi_module_init_sniffer(); +esp_err_t wifi_module_init_sniffer(); void wifi_analyzer_run(); diff --git a/firmware/main/main.c b/firmware/main/main.c index 9e52331b..dc581c3a 100644 --- a/firmware/main/main.c +++ b/firmware/main/main.c @@ -15,6 +15,7 @@ #include "open_thread.h" #include "preferences.h" #include "sd_card.h" +#include "warbee_module.h" #include "wardriving_module.h" #include "web_file_browser.h" #include "wifi_app.h" @@ -41,5 +42,6 @@ void app_main() { menus_module_begin(); leds_off(); preferences_put_bool("wifi_connected", false); + // warbee_module_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 ce5fdbf5..d18490ec 100644 --- a/firmware/main/modules/cat_dos/cat_console.c +++ b/firmware/main/modules/cat_dos/cat_console.c @@ -56,7 +56,7 @@ static void initialize_console(void) { esp_console_repl_config_t repl_config = ESP_CONSOLE_REPL_CONFIG_DEFAULT(); // initialize_filesystem(); // repl_config.history_save_path = HISTORY_FILE_PATH; - repl_config.prompt = "bsides>"; + repl_config.prompt = "minino>"; esp_console_dev_usb_serial_jtag_config_t usbjtag_config = ESP_CONSOLE_DEV_USB_SERIAL_JTAG_CONFIG_DEFAULT(); diff --git a/firmware/main/modules/cat_dos/catdos_module.c b/firmware/main/modules/cat_dos/catdos_module.c index 68180bb0..0c991684 100644 --- a/firmware/main/modules/cat_dos/catdos_module.c +++ b/firmware/main/modules/cat_dos/catdos_module.c @@ -35,6 +35,7 @@ static const char* CATDOS_TAG = "catdos_module"; static int selected_item = 0; static int total_items = 0; static int max_items = 6; +static bool is_exit = false; static TaskHandle_t task_atack = NULL; @@ -64,11 +65,8 @@ static void catdos_module_show_target(); static void catdos_module_display_attack_animation() { oled_screen_clear(OLED_DISPLAY_NORMAL); while (running_attack) { - for (int i = 0; i < 4; i++) { - oled_screen_clear(OLED_DISPLAY_NORMAL); - oled_screen_display_text_center("Attacking", 0, OLED_DISPLAY_NORMAL); - vTaskDelay(250 / portTICK_PERIOD_MS); - } + oled_screen_clear(OLED_DISPLAY_NORMAL); + oled_screen_display_text_center("Attacking", 0, OLED_DISPLAY_NORMAL); vTaskDelay(1000 / portTICK_PERIOD_MS); } } @@ -375,11 +373,8 @@ static void http_get_task(void* pvParameters) { // ESP_LOGI(CATDOS_TAG, "... socket send success"); close(s); } - running_attack = false; - if (task_atack) { - vTaskSuspend(task_atack); - vTaskDelete(task_atack); - } + // running_attack = false; + vTaskDelete(NULL); } void catdos_module_send_attack() { @@ -428,12 +423,14 @@ void catdos_module_send_attack() { assert(res == 0); res = pthread_join(thread8, NULL); assert(res == 0); + + vTaskDelete(NULL); } void catdos_module_begin() { -#if !defined(CONFIG_CATDOS_MODULE_DEBUG) - esp_log_level_set(CATDOS_TAG, ESP_LOG_NONE); -#endif + // #if !defined(CONFIG_CATDOS_MODULE_DEBUG) + // esp_log_level_set(CATDOS_TAG, ESP_LOG_NONE); + // #endif // ESP_ERROR_CHECK(esp_event_loop_create_default()); menus_module_set_app_state(true, catdos_module_state_machine); @@ -447,25 +444,40 @@ void catdos_module_begin() { bool wifi_connection = preferences_get_bool("wifi_connected", false); + int total_items = preferences_get_int("count_ap", 0); + ESP_LOGI(CATDOS_TAG, "Total items: %d", total_items); + if (wifi_connection) { oled_screen_display_text_center("WIFI Connection", 1, OLED_DISPLAY_NORMAL); catdos_state = CATDOS_STATE_CONFIG_TARGET; + catdos_module_show_target(); } else { catdos_state = CATDOS_STATE_CONFIG_WIFI; int total_items = preferences_get_int("count_ap", 0); + ESP_LOGI(CATDOS_TAG, "Total items: %d", total_items); if (total_items == 0) { oled_screen_display_text_center("No WIFI", 1, OLED_DISPLAY_NORMAL); oled_screen_display_text_center("Add WiFi", 2, OLED_DISPLAY_NORMAL); oled_screen_display_text_center("From console", 3, OLED_DISPLAY_NORMAL); return; } - catdos_module_display_wifi(); + // }else{ + // catdos_module_display_wifi(); + // } } } static void catdos_module_display_wifi() { oled_screen_clear(); - oled_screen_display_text_center("Selected WIFI", 0, OLED_DISPLAY_NORMAL); + oled_screen_display_text_center("Select WIFI", 0, OLED_DISPLAY_NORMAL); + int total_items = preferences_get_int("count_ap", 0); + + if (total_items == 0) { + oled_screen_display_text_center("No WIFI", 1, OLED_DISPLAY_NORMAL); + oled_screen_display_text_center("Add WIFI", 2, OLED_DISPLAY_NORMAL); + oled_screen_display_text_center("From console", 3, OLED_DISPLAY_NORMAL); + return; + } for (int i = selected_item; i < max_items + selected_item; i++) { char wifi_ap[100]; @@ -474,7 +486,7 @@ static void catdos_module_display_wifi() { esp_err_t err = preferences_get_string(wifi_ap, wifi_ssid, 100); if (err != ESP_OK) { ESP_LOGW(__func__, "Error getting AP %d", i); - return; + continue; } char wifi_text[120]; if (strlen(wifi_ssid) > 16) { @@ -509,6 +521,9 @@ static void catdos_module_cb_connection(bool state) { catdos_state = CATDOS_STATE_CONFIG_TARGET; } } else { + if (is_exit) { + return; + } oled_screen_display_text_center("WIFI", 0, OLED_DISPLAY_NORMAL); oled_screen_display_text_center("Error", 1, OLED_DISPLAY_NORMAL); vTaskDelay(2000 / portTICK_PERIOD_MS); @@ -537,6 +552,10 @@ static void catdos_module_show_target() { ESP_LOGE(CATDOS_TAG, "Error getting endpoint"); return; } + bool is_target = catdos_module_is_config_target(); + if (is_target) { + catdos_state = CATDOS_STATE_ATTACK; + } oled_screen_display_text_center("Target", 0, OLED_DISPLAY_INVERT); oled_screen_display_text_center("Host", 1, OLED_DISPLAY_NORMAL); oled_screen_display_text_center(host, 2, OLED_DISPLAY_NORMAL); @@ -626,10 +645,15 @@ static void catdos_module_state_machine(uint8_t button_name, case CATDOS_STATE_ATTACK: { switch (button_name) { case BUTTON_LEFT: - menus_module_exit_app(); + is_exit = true; + menus_module_reset(); break; case BUTTON_RIGHT: - catdos_module_send_attack(); + xTaskCreate(&catdos_module_send_attack, "http_send_task", 4096, NULL, + 5, NULL); + xTaskCreate(&catdos_module_display_attack_animation, "http_an_task", + 4096, NULL, 5, NULL); + // catdos_module_send_attack(); break; case BUTTON_UP: case BUTTON_DOWN: diff --git a/firmware/main/modules/gps/gps_module.c b/firmware/main/modules/gps/gps_module.c index 249b3c03..0618bdae 100644 --- a/firmware/main/modules/gps/gps_module.c +++ b/firmware/main/modules/gps/gps_module.c @@ -166,6 +166,20 @@ uint8_t gps_module_get_time_zone() { return preferences_get_uint("time_zone", default_time_zone); } +char* get_full_date_time(gps_t* gps) { + char* date_time = malloc(sizeof(char) * 30); + sprintf(date_time, "%d-%d-%d %d:%d:%d", gps->date.year, gps->date.month, + gps->date.day, gps->tim.hour, gps->tim.minute, gps->tim.second); + return date_time; +} + +char* get_str_date_time(gps_t* gps) { + char* date_time = malloc(sizeof(char) * 30); + sprintf(date_time, "%d%d%d%d%d%d", gps->date.year, gps->date.month, + gps->date.day, gps->tim.hour, gps->tim.minute, gps->tim.second); + return date_time; +} + void gps_module_set_time_zone(uint8_t time_zone) { preferences_put_uint("time_zone", time_zone); } diff --git a/firmware/main/modules/gps/gps_module.h b/firmware/main/modules/gps/gps_module.h index 47fd5d64..14f4b45f 100644 --- a/firmware/main/modules/gps/gps_module.h +++ b/firmware/main/modules/gps/gps_module.h @@ -84,3 +84,6 @@ void gps_module_register_cb(gps_event_callback_t callback); void gps_module_unregister_cb(); void gps_module_general_data_run(); + +char* get_full_date_time(gps_t* gps); +char* get_str_date_time(gps_t* gps); \ No newline at end of file diff --git a/firmware/main/modules/gps/war_bee/warbee_module.c b/firmware/main/modules/gps/war_bee/warbee_module.c new file mode 100644 index 00000000..ed323cb7 --- /dev/null +++ b/firmware/main/modules/gps/war_bee/warbee_module.c @@ -0,0 +1,375 @@ +#include "warbee_module.h" +#include +#include "esp_log.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "general_submenu.h" +#include "gps_module.h" +#include "ieee_sniffer.h" +#include "menus_module.h" +#include "oled_screen.h" +#include "radio_selector.h" +#include "sd_card.h" +#include "wardriving_common.h" +#include "wardriving_screens_module.h" +#include "zigbee_bitmaps.h" + +#define FILE_NAME DIR_NAME "/Warbee" + +static const char* TAG = "warbee"; + +static TaskHandle_t zigbee_task_sniffer = NULL; +static TaskHandle_t scanning_zigbee_animation_task_handle = NULL; +static warbee_module_t context_session; +static gps_t* gps_ctx; +static bool running_zigbee_scanner_animation = false; + +static uint16_t csv_lines; +char* csv_file_name = NULL; +char* csv_file_buffer = NULL; + +const char* csv_header = FORMAT_VERSION + ",appRelease=" APP_VERSION ",model=" MODEL ",release=" RELEASE + ",device=" DEVICE ",display=" DISPLAY ",board=" BOARD ",brand=" BRAND + ",star=" STAR ",body=" BODY ",subBody=" SUB_BODY + "\n" + // IEEE 802.15.4 fields + "SourcePanID,SourceADDR,DestinationADDR,Channel,RSSI,SecurityEnabled," + "FrameType," + // GPS fields + "CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,RCOIs," + "MfgrId,Type"; + +static void warbee_gps_event_handler_cb(gps_t* gps); +static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length); + +static void update_file_name(char* full_date_time) { + sprintf(csv_file_name, "%s_%s.csv", FILE_NAME, full_date_time); +} + +static void wardriving_screens_zigbee_animation_task() { + oled_screen_clear_buffer(); + + while (true) { + static uint8_t idx = 0; + oled_screen_display_bitmap(zigbee_bitmap_allArray[idx], 0, 0, 32, 32, + OLED_DISPLAY_NORMAL); + idx = ++idx > 3 ? 0 : idx; + vTaskDelay(500 / portTICK_PERIOD_MS); + } + vTaskDelete(NULL); +} + +static esp_err_t wardriving_module_verify_sd_card() { + ESP_LOGI("Warbee", "Verifying SD card"); + esp_err_t err = sd_card_mount(); + return err; +} + +static void warbee_module_cb_event(uint8_t button_name, uint8_t button_event) { + if (button_event != BUTTON_PRESS_DOWN) { + return; + } + switch (button_name) { + case BUTTON_LEFT: + warbee_module_exit(); + menus_module_restart(); + break; + case BUTTON_UP: + case BUTTON_DOWN: + case BUTTON_RIGHT: + default: + break; + } +} + +static char* get_packet_type(uint8_t frame_type) { + switch (frame_type) { + case FRAME_TYPE_BEACON: + return "Beacon"; + case FRAME_TYPE_DATA: + return "Data"; + case FRAME_TYPE_MAC_COMMAND: + return "MAC Command"; + default: + return "Unknown"; + } +} + +static void warbee_gps_event_handler_cb(gps_t* gps) { + static uint32_t counter = 0; + counter++; + + gps_ctx = gps; + + ESP_LOGI("Warbee", + "Satellites in use: %d, signal: %s \r\n" + "\t\t\t\t\t\tlatitude = %.05f°N\r\n" + "\t\t\t\t\t\tlongitude = %.05f°E\r\n", + gps->sats_in_use, gps_module_get_signal_strength(gps), gps->latitude, + gps->longitude); + + if (strcmp(context_session.session_str, "") == 0) { + esp_err_t err = sd_card_create_dir(DIR_NAME); + + if (err != ESP_OK) { + ESP_LOGE("Warbee", "Failed to create %s directory", DIR_NAME); + return; + } + ESP_LOGI("Warbee", "New session"); + context_session.session_str = get_str_date_time(gps); + context_session.session_records_count = 0; + update_file_name(context_session.session_str); + ESP_LOGI("Warbee", "Creating Session File: %s", + context_session.session_str); + sd_card_write_file(csv_file_name, csv_file_buffer); + csv_lines = CSV_HEADER_LINES; + free(csv_file_buffer); + + ESP_LOGI("Warbee", "Free heap size before allocation: %" PRIu32 " bytes", + esp_get_free_heap_size()); + ESP_LOGI("Warbee", "Allocating %d bytes for csv_file_buffer", + CSV_FILE_SIZE); + csv_file_buffer = malloc(CSV_FILE_SIZE); + if (csv_file_buffer == NULL) { + ESP_LOGE("Warbee", "Failed to allocate memory for csv_file_buffer"); + return; + } + + sprintf(csv_file_buffer, "%s\n", csv_header); // Append header to csv file + } + + if (gps->sats_in_use == 0) { + ESP_LOGW("Warbee", "No GPS signal"); + wardriving_screens_module_no_gps_signal(); + vTaskSuspend(scanning_zigbee_animation_task_handle); + running_zigbee_scanner_animation = false; + return; + } + + if (running_zigbee_scanner_animation == false) { + vTaskResume(scanning_zigbee_animation_task_handle); + wardriving_screens_module_scanning(context_session.session_records_count, + gps_module_get_signal_strength(gps)); + running_zigbee_scanner_animation = true; + } +} + +static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { + if (gps_ctx->sats_in_use == 0) { + ESP_LOGW("Warbee", "No GPS signa dont savel"); + return; + } + + char* csv_line_buffer = malloc(CSV_LINE_SIZE); + uint8_t position = 0; + mac_fcs_t* fcs = (mac_fcs_t*) &packet[position]; + position += sizeof(uint16_t); + + if (csv_lines == CSV_HEADER_LINES) { + ESP_LOGI("Warbee", "CSV Full"); + } + uint16_t pan_id = 0; + uint8_t dst_addr[8] = {0}; + uint8_t src_addr[8] = {0}; + uint16_t short_dst_addr = 0; + uint16_t short_src_addr = 0; + + char* dst_addr_str = malloc(24); + char* src_addr_str = malloc(24); + + switch (fcs->frameType) { + case FRAME_TYPE_DATA: + case FRAME_TYPE_MAC_COMMAND: + uint8_t sequence_number = packet[position]; + position += sizeof(uint8_t); + + switch (fcs->destAddrType) { + case ADDR_MODE_NONE: + printf("Originating from the PAN coordinator\n"); + break; + // Device is sending to a short address + case ADDR_MODE_SHORT: + pan_id = *((uint16_t*) &packet[position]); + position += sizeof(uint16_t); + short_dst_addr = *((uint16_t*) &packet[position]); + position += sizeof(uint16_t); + if (pan_id == 0xFFFF && short_dst_addr == 0xFFFF) { + pan_id = *((uint16_t*) &packet[position]); // srcPan + position += sizeof(uint16_t); + printf("Broadcast on PAN %04x\n", pan_id); + } else { + printf("Destination PAN: 0x%04x\n", pan_id); + printf("Destination : 0x%04x\n", short_dst_addr); + } + sprintf(dst_addr_str, "0x%04x", short_dst_addr); + break; + case ADDR_MODE_LONG: + pan_id = *((uint16_t*) &packet[position]); + position += sizeof(uint16_t); + for (uint8_t idx = 0; idx < sizeof(dst_addr); idx++) { + dst_addr[idx] = packet[position + sizeof(dst_addr) - 1 - idx]; + } + position += sizeof(dst_addr); + sprintf(dst_addr_str, ZB_ADDRESS_FORMAT, dst_addr[0], dst_addr[1], + dst_addr[2], dst_addr[3], dst_addr[4], dst_addr[5], + dst_addr[6], dst_addr[7]); + printf("On PAN %04x to long address %s\n", pan_id, dst_addr_str); + break; + default: { + ESP_LOGE(TAG_IEEE_SNIFFER, + "With reserved destination address type, ignoring packet\n"); + return; + } + } + + switch (fcs->srcAddrType) { + case ADDR_MODE_NONE: { + printf("Originating from the PAN coordinator\n"); + break; + } + case ADDR_MODE_SHORT: { + short_src_addr = *((uint16_t*) &packet[position]); + position += sizeof(uint16_t); + printf("Source: 0x%04x\n", short_src_addr); + sprintf(src_addr_str, "0x%04x", short_src_addr); + break; + } + case ADDR_MODE_LONG: { + for (uint8_t idx = 0; idx < sizeof(src_addr); idx++) { + src_addr[idx] = packet[position + sizeof(src_addr) - 1 - idx]; + } + position += sizeof(src_addr); + printf( + "Originating from long address " + "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x\n", + src_addr[0], src_addr[1], src_addr[2], src_addr[3], src_addr[4], + src_addr[5], src_addr[6], src_addr[7]); + sprintf(src_addr_str, ZB_ADDRESS_FORMAT, src_addr[0], src_addr[1], + src_addr[2], src_addr[3], src_addr[4], src_addr[5], + src_addr[6], src_addr[7]); + break; + } + default: { + ESP_LOGE(TAG_IEEE_SNIFFER, + "With reserved source address type, ignoring packet"); + return; + } + } + + break; + case FRAME_TYPE_BEACON: + default: + printf("Packet ignored because of frame type (%u)\n", fcs->frameType); + break; + } + // "Source,DestinationPAN,Channel,RSSI," + sprintf(csv_line_buffer, "0x%04x,%s,%s,%d,%d,%s,%s,%f,%f,%f,%f,%s,%s,%s\n", + // SourcePanID + pan_id, + // SourceDestination + src_addr_str, + // DestinationPAN + dst_addr_str, + // Channel + ieee_sniffer_get_channel(), + // RSSI + ieee_sniffer_get_rssi(), + // SecurityEnabled + fcs->secure ? "Yes" : "No", + // FrameType + get_packet_type(fcs->frameType), + // CurrentLatitude + gps_ctx->latitude, + // CurrentLongitude + gps_ctx->longitude, + // AltitudeMeters + gps_ctx->altitude, + // AccuracyMeters + GPS_ACCURACY, + // RCOIs + "", + // MfgrId + "", + // Type + "Zigbee"); + // xQueueSendToBackFromISR(packet_rx_queue, packet, NULL); + ESP_LOGI("Warbee", "CSV Line: %s", csv_line_buffer); + + if (context_session.session_records_count >= MAX_CSV_LINES) { + ESP_LOGW(TAG, "Max CSV lines reached, writing to file"); + context_session.session_str = get_str_date_time(gps_ctx); + context_session.session_records_count = 0; + update_file_name(context_session.session_str); + sd_card_write_file(csv_file_name, csv_file_buffer); + csv_lines = CSV_HEADER_LINES; + free(csv_file_buffer); + + ESP_LOGI(TAG, "Free heap size before allocation: %" PRIu32 " bytes", + esp_get_free_heap_size()); + ESP_LOGI(TAG, "Allocating %d bytes for csv_file_buffer", CSV_FILE_SIZE); + csv_file_buffer = malloc(CSV_FILE_SIZE); + if (csv_file_buffer == NULL) { + ESP_LOGE(TAG, "Failed to allocate memory for csv_file_buffer"); + return; + } + + sprintf(csv_file_buffer, "%s\n", + csv_header); // Append header to csv file + } else { + sd_card_append_to_file(csv_file_name, csv_line_buffer); + } + + context_session.session_records_count++; + free(csv_line_buffer); + free(dst_addr_str); +} + +void warbee_module_begin() { + if (wardriving_module_verify_sd_card() != ESP_OK) { + return; + } + ESP_LOGI("Warbee", "Warbee module begin"); + csv_lines = CSV_HEADER_LINES; + ESP_LOGI("Warbee", "Free heap size before allocation: %" PRIu32 " bytes", + esp_get_free_heap_size()); + ESP_LOGI("Warbee", "Allocating %d bytes for csv_file_buffer", CSV_FILE_SIZE); + csv_file_buffer = malloc(CSV_FILE_SIZE); + if (csv_file_buffer == NULL) { + ESP_LOGE("Warbee", "Failed to allocate memory for csv_file_buffer"); + return; + } + + csv_file_name = malloc(strlen(FILE_NAME) + 30); + if (csv_file_name == NULL) { + ESP_LOGE("Warbee", "Failed to allocate memory for csv_file_name"); + return; + } + + sprintf(csv_file_name, "%s.csv", FILE_NAME); + sprintf(csv_file_buffer, "%s\n", csv_header); + + context_session.session_str = ""; + + radio_selector_set_zigbee_sniffer(); + ieee_sniffer_register_cb(warbee_packet_dissector); + xTaskCreate(ieee_sniffer_channel_hop, "ieee_sniffer_task", 4096, NULL, 5, + &zigbee_task_sniffer); + xTaskCreate(wardriving_screens_zigbee_animation_task, + "scanning_wifi_animation_task", 4096, NULL, 5, + &scanning_zigbee_animation_task_handle); + vTaskSuspend(scanning_zigbee_animation_task_handle); + gps_module_register_cb(warbee_gps_event_handler_cb); + gps_module_start_scan(); + + menus_module_set_app_state(true, warbee_module_cb_event); +} + +void warbee_module_exit() { + ESP_LOGI("Warbee", "Warbee module end"); + ieee_sniffer_stop(); + sd_card_read_file(csv_file_name); + sd_card_unmount(); + free(csv_file_buffer); + free(csv_file_name); +} \ No newline at end of file diff --git a/firmware/main/modules/gps/war_bee/warbee_module.h b/firmware/main/modules/gps/war_bee/warbee_module.h new file mode 100644 index 00000000..8940874a --- /dev/null +++ b/firmware/main/modules/gps/war_bee/warbee_module.h @@ -0,0 +1,16 @@ +#pragma once +#include + +typedef struct { + char* session_str; + uint16_t session_records_count; +} warbee_module_t; + +/** + * @brief Initialize the wardriving zigbee module + * + * @return void + */ +void warbee_module_begin(); + +void warbee_module_exit(); \ No newline at end of file diff --git a/firmware/main/modules/gps/war_common/wardriving_common.h b/firmware/main/modules/gps/war_common/wardriving_common.h new file mode 100644 index 00000000..42ef999a --- /dev/null +++ b/firmware/main/modules/gps/war_common/wardriving_common.h @@ -0,0 +1,26 @@ +#pragma once + +#define DIR_NAME "warbee" +#define FORMAT_VERSION "ElecCats-1.0" +#define APP_VERSION CONFIG_PROJECT_VERSION +#define MODEL "MININO" +#define RELEASE APP_VERSION +#define DEVICE "MININO" +#define DISPLAY "SH1106 OLED" +#define BOARD "ESP32C6" +#define BRAND "Electronic Cats" +#define STAR "Sol" +#define BODY "3" +#define SUB_BODY "0" + +// Zigbee Packet fields +#define ZB_ADDRESS_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x" +// AP WiFi Packet fields +#define MAC_ADDRESS_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x" +#define EMPTY_MAC_ADDRESS "00:00:00:00:00:00" + +// CSV file properties +#define CSV_LINE_SIZE 150 // Got it from real time tests +#define CSV_FILE_SIZE (CSV_LINE_SIZE) * (MAX_CSV_LINES) +#define CSV_HEADER_LINES 2 // Check `csv_header` variable +#define MAX_CSV_LINES 200 + CSV_HEADER_LINES diff --git a/firmware/main/modules/gps/wardriving/wardriving_module.c b/firmware/main/modules/gps/wardriving/wardriving_module.c index e4605522..0a4051d1 100644 --- a/firmware/main/modules/gps/wardriving/wardriving_module.c +++ b/firmware/main/modules/gps/wardriving/wardriving_module.c @@ -7,32 +7,16 @@ #include "gps_module.h" #include "menus_module.h" +#include "oled_screen.h" #include "sd_card.h" #include "wardriving_module.h" #include "wardriving_screens_module.h" #include "wifi_controller.h" #include "wifi_scanner.h" -#define DIR_NAME "Wardriving" -#define FILE_NAME DIR_NAME "/Minino" -#define FORMAT_VERSION "WigleWifi-1.6" -#define APP_VERSION CONFIG_PROJECT_VERSION -#define MODEL "MININO" -#define RELEASE APP_VERSION -#define DEVICE "MININO" -#define DISPLAY "SH1106 OLED" -#define BOARD "ESP32C6" -#define BRAND "Electronic Cats" -#define STAR "Sol" -#define BODY "3" -#define SUB_BODY "0" - -#define MAC_ADDRESS_FORMAT "%02x:%02x:%02x:%02x:%02x:%02x" -#define EMPTY_MAC_ADDRESS "00:00:00:00:00:00" -#define CSV_LINE_SIZE 150 // Got it from real time tests -#define CSV_FILE_SIZE (CSV_LINE_SIZE) * (MAX_CSV_LINES) -#define CSV_HEADER_LINES 2 // Check `csv_header` variable -#define MAX_CSV_LINES 200 + CSV_HEADER_LINES +#include "wardriving_common.h" + +#define FILE_NAME DIR_NAME "/Minino" #define WIFI_SCAN_REFRESH_RATE_MS 3000 #define DISPLAY_REFRESH_RATE_SEC 2 @@ -45,7 +29,7 @@ typedef enum { WARDRIVING_MODULE_STATE_STOPPED } wardriving_module_state_t; -const char* TAG = "wardriving"; +static const char* TAG = "wardriving"; wardriving_module_state_t wardriving_module_state = WARDRIVING_MODULE_STATE_STOPPED; TaskHandle_t wardriving_module_scan_task_handle = NULL; @@ -103,20 +87,11 @@ char* get_auth_mode(int authmode) { } } -char* get_full_date_time(gps_t* gps) { - char* date_time = malloc(sizeof(char) * 30); - sprintf(date_time, "%d-%d-%d %d:%d:%d", gps->date.year, gps->date.month, - gps->date.day, gps->tim.hour, gps->tim.minute, gps->tim.second); - return date_time; -} - uint16_t get_frequency(uint8_t primary) { return 2412 + 5 * (primary - 1); } void wardriving_module_scan_task(void* pvParameters) { - wifi_driver_init_sta(); - while (true) { wifi_scanner_module_scan(); vTaskDelay(WIFI_SCAN_REFRESH_RATE_MS / portTICK_PERIOD_MS); @@ -336,10 +311,10 @@ void wardriving_module_end() { } void wardriving_module_start_scan() { + menus_module_set_app_state(true, wardriving_module_keyboard_cb); if (wardriving_module_verify_sd_card() != ESP_OK) { return; } - menus_module_set_app_state(true, wardriving_module_keyboard_cb); ESP_LOGI(TAG, "Start scan"); wardriving_module_state = WARDRIVING_MODULE_STATE_SCANNING; xTaskCreate(wardriving_module_scan_task, "wardriving_module_scan_task", 4096, @@ -381,12 +356,13 @@ void wardriving_module_stop_scan() { } void wardriving_module_keyboard_cb(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: + wardriving_module_stop_scan(); menus_module_exit_app(); break; case BUTTON_RIGHT: @@ -395,6 +371,7 @@ void wardriving_module_keyboard_cb(uint8_t button_name, uint8_t button_event) { } else if (wardriving_module_state == WARDRIVING_MODULE_STATE_INVALID_SD_CARD) { wardriving_screens_module_formating_sd_card(); + sd_card_settings_format(); esp_err_t err = sd_card_check_format(); if (err == ESP_OK) { ESP_LOGI(TAG, "Format done"); diff --git a/firmware/main/modules/gps/wardriving/wardriving_screens_module.c b/firmware/main/modules/gps/wardriving/wardriving_screens_module.c index 4ae4d722..a1c7348b 100644 --- a/firmware/main/modules/gps/wardriving/wardriving_screens_module.c +++ b/firmware/main/modules/gps/wardriving/wardriving_screens_module.c @@ -36,6 +36,7 @@ void wardriving_screens_wifi_animation_task() { idx = ++idx > 3 ? 0 : idx; vTaskDelay(500 / portTICK_PERIOD_MS); } + vTaskDelete(NULL); } void wardriving_screens_module_scanning(uint32_t packets, char* signal) { diff --git a/firmware/main/modules/menus_module/menus_include/menus.h b/firmware/main/modules/menus_module/menus_include/menus.h index 85469827..d6723601 100644 --- a/firmware/main/modules/menus_module/menus_include/menus.h +++ b/firmware/main/modules/menus_module/menus_include/menus.h @@ -20,6 +20,7 @@ #include "sd_card_settings_module.h" #include "settings_module.h" #include "stealth_mode.h" +#include "warbee_module.h" #include "wardriving_module.h" #include "wardriving_screens_module.h" #include "web_file_browser_module.h" @@ -76,6 +77,7 @@ typedef enum { MENU_GPS_HELP, /* Wardriving submenus */ MENU_GPS_WARDRIVING_START, + MENU_GPS_WARDRIVING_BEE_START, MENU_GPS_WARDRIVING_HELP, /* About submenus */ MENU_ABOUT_VERSION, @@ -281,6 +283,7 @@ menu_t menus[] = { ////////////////////////////////// .on_enter_cb = NULL, .on_exit_cb = NULL, .is_visible = true}, + #ifdef CONFIG_ZIGBEE_APP_SPOOFING_SWITCH {.display_name = "Switch", .menu_idx = MENU_ZIGBEE_SWITCH, .parent_idx = MENU_ZIGBEE_SPOOFING, @@ -289,6 +292,8 @@ menu_t menus[] = { ////////////////////////////////// .on_enter_cb = zigbee_module_switch_enter, .on_exit_cb = NULL, .is_visible = true}, + #endif + #ifdef CONFIG_ZIGBEE_APP_SNIFFER_LIGHT {.display_name = "Light", .menu_idx = MENU_ZIGBEE_LIGHT, .parent_idx = MENU_ZIGBEE_SPOOFING, @@ -297,6 +302,7 @@ menu_t menus[] = { ////////////////////////////////// .on_enter_cb = NULL, .on_exit_cb = NULL, .is_visible = true}, + #endif #endif #ifdef CONFIG_ZIGBEE_APP_SNIFFER {.display_name = "Sniffer", @@ -362,13 +368,22 @@ menu_t menus[] = { ////////////////////////////////// .on_enter_cb = wardriving_module_begin, .on_exit_cb = wardriving_module_end, .is_visible = true}, - {.display_name = "Start", + {.display_name = "AP Start", .menu_idx = MENU_GPS_WARDRIVING_START, .parent_idx = MENU_GPS_WARDRIVING, .last_selected_submenu = 0, .on_enter_cb = wardriving_module_start_scan, .on_exit_cb = wardriving_module_stop_scan, .is_visible = true}, + #ifdef CONFIG_GPS_APP_WARDRIVING_ZB + {.display_name = "Zigbee Start", + .menu_idx = MENU_GPS_WARDRIVING_BEE_START, + .parent_idx = MENU_GPS_WARDRIVING, + .last_selected_submenu = 0, + .on_enter_cb = warbee_module_begin, + .on_exit_cb = warbee_module_exit, + .is_visible = true}, + #endif {.display_name = "Help", .menu_idx = MENU_GPS_WARDRIVING_HELP, .parent_idx = MENU_GPS_WARDRIVING, diff --git a/firmware/main/modules/settings/sd_card/sd_card_settings_module.c b/firmware/main/modules/settings/sd_card/sd_card_settings_module.c index d4bd9b6a..ebbe6d4e 100644 --- a/firmware/main/modules/settings/sd_card/sd_card_settings_module.c +++ b/firmware/main/modules/settings/sd_card/sd_card_settings_module.c @@ -58,6 +58,27 @@ void sd_card_settings_verify_sd_card() { sd_card_unmount(); } +void sd_card_settings_format() { + esp_err_t err; + sd_card_settings_screens_module_formating_sd_card(); + err = sd_card_check_format(); + if (err == ESP_OK) { + ESP_LOGI(TAG, "Mount ok, formatting..."); + state = SD_CARD_SETTINGS_FORMATTING; + esp_err_t err_format = sd_card_format(); + if (err_format == ESP_OK) { + state = SD_CARD_SETTINGS_FORMAT_DONE; + sd_card_settings_screens_module_format_done(); + } else { + state = SD_CARD_SETTINGS_FAILED_FORMAT; + sd_card_settings_screens_module_failed_format_sd_card(); + } + } else { + state = SD_CARD_SETTINGS_FAILED_FORMAT; + sd_card_settings_screens_module_failed_format_sd_card(); + } +} + void sd_card_settings_keyboard_cb(uint8_t button_name, uint8_t button_event) { if (button_event != BUTTON_PRESS_DOWN) { return; @@ -84,23 +105,7 @@ void sd_card_settings_keyboard_cb(uint8_t button_name, uint8_t button_event) { } break; case SD_CARD_SETTINGS_FORMAT_QUESTION: - sd_card_settings_screens_module_formating_sd_card(); - err = sd_card_check_format(); - if (err == ESP_OK) { - ESP_LOGI(TAG, "Mount ok, formatting..."); - state = SD_CARD_SETTINGS_FORMATTING; - esp_err_t err_format = sd_card_format(); - if (err_format == ESP_OK) { - state = SD_CARD_SETTINGS_FORMAT_DONE; - sd_card_settings_screens_module_format_done(); - } else { - state = SD_CARD_SETTINGS_FAILED_FORMAT; - sd_card_settings_screens_module_failed_format_sd_card(); - } - } else { - state = SD_CARD_SETTINGS_FAILED_FORMAT; - sd_card_settings_screens_module_failed_format_sd_card(); - } + sd_card_settings_format(); break; case SD_CARD_SETTINGS_FORMATTING: // TODO: implement on LEFT button diff --git a/firmware/main/modules/settings/sd_card/sd_card_settings_module.h b/firmware/main/modules/settings/sd_card/sd_card_settings_module.h index 5804fdac..bdd52697 100644 --- a/firmware/main/modules/settings/sd_card/sd_card_settings_module.h +++ b/firmware/main/modules/settings/sd_card/sd_card_settings_module.h @@ -3,5 +3,6 @@ #include "esp_err.h" void sd_card_settings_verify_sd_card(); +void sd_card_settings_format(); void sd_card_settings_keyboard_cb(uint8_t button_name, uint8_t button_event); diff --git a/firmware/sdkconfig.defaults b/firmware/sdkconfig.defaults index 7b0d1d2f..4e48cb01 100644 --- a/firmware/sdkconfig.defaults +++ b/firmware/sdkconfig.defaults @@ -1,4 +1,4 @@ -CONFIG_PROJECT_VERSION="1.2.0.1" +CONFIG_PROJECT_VERSION="1.1.5.0" # Enable support for power management CONFIG_PM_ENABLE=y @@ -103,6 +103,8 @@ CONFIG_BLUETOOTH_APP_ADV=y ## ZIGBEE ## CONFIG_ZIGBEE_APPS_ENABLE=y CONFIG_ZIGBEE_APP_SPOOFING=y +CONFIG_ZIGBEE_APP_SPOOFING_SWITCH=y +CONFIG_ZIGBEE_APP_SPOOFING_LIGHT=n CONFIG_ZIGBEE_APP_SNIFFER=y ## THREAD ## CONFIG_THREAD_APPS_ENABLE=y @@ -111,6 +113,7 @@ CONFIG_THREAD_APP_SNIFFER=y ## GPS ## CONFIG_GPS_APPS_ENABLE=y CONFIG_GPS_APP_WARDRIVING=y +CONFIG_GPS_APP_WARDRIVING_ZB=y ## OTA ## CONFIG_OTA_ENABLE=y ## FILE MANAGER ## diff --git a/firmware/sdkconfig.noota b/firmware/sdkconfig.noota index de4a841c..e0f8f3f1 100644 --- a/firmware/sdkconfig.noota +++ b/firmware/sdkconfig.noota @@ -1,4 +1,4 @@ -CONFIG_PROJECT_VERSION="1.2.0.0" +CONFIG_PROJECT_VERSION="1.1.5.0" # # Enabled Features diff --git a/firmware/sdkconfig.ota b/firmware/sdkconfig.ota index 513bfc08..98c73986 100644 --- a/firmware/sdkconfig.ota +++ b/firmware/sdkconfig.ota @@ -1,4 +1,4 @@ -CONFIG_PROJECT_VERSION="1.2.0.0" +CONFIG_PROJECT_VERSION="1.1.5.0" # # Enabled Features