From e285cd6afd8553bce1071ee78a1b2726bb1faea2 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Thu, 21 Nov 2024 14:47:36 -0600 Subject: [PATCH 01/25] feat: Fix DoS stack memory --- firmware/README.md | 32 +++++++++- firmware/main/modules/cat_dos/cat_console.c | 2 +- firmware/main/modules/cat_dos/catdos_module.c | 60 +++++++++++++------ 3 files changed, 74 insertions(+), 20 deletions(-) diff --git a/firmware/README.md b/firmware/README.md index 8121846..c5a6200 100644 --- a/firmware/README.md +++ b/firmware/README.md @@ -181,4 +181,34 @@ BLE_SCAN_FILTER_ALLOW_ALL = 0x0, /*!< Accept all : 1. advertisement packets from devices where the advertiser’s address is in the White list, and 2. directed advertising packets where the initiator address is a resolvable private address, and 3. directed advertising packets addressed to this device.*/ -``` \ No newline at end of file +``` + +## 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/main/modules/cat_dos/cat_console.c b/firmware/main/modules/cat_dos/cat_console.c index ce5fdbf..d18490e 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 68180bb..0c99168 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: From 025d70aa0121c3ea1d12001fca3f95b76a764dc7 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Thu, 21 Nov 2024 16:51:57 -0600 Subject: [PATCH 02/25] fix: free memory on analyzer packets counter --- firmware/Makefile | 5 +++++ .../main/apps/wifi_analyzer/screens/wifi_screens_module.c | 2 ++ 2 files changed, 7 insertions(+) diff --git a/firmware/Makefile b/firmware/Makefile index d31153e..6cfa63e 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/main/apps/wifi_analyzer/screens/wifi_screens_module.c b/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.c index a9e159f..c9112a6 100644 --- a/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.c +++ b/firmware/main/apps/wifi_analyzer/screens/wifi_screens_module.c @@ -29,6 +29,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"); } From 632ee652bfe02e787e64ab9b49f9466fde8e8a57 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Fri, 22 Nov 2024 12:00:12 -0600 Subject: [PATCH 03/25] feat: force exit when storage is full --- firmware/components/wifi_sniffer/cmd_sniffer.c | 14 ++++++++++++-- .../components/wifi_sniffer/include/cmd_sniffer.h | 2 +- .../wifi_analyzer/screens/wifi_screens_module.c | 5 +++++ .../wifi_analyzer/screens/wifi_screens_module.h | 4 +++- firmware/main/apps/wifi_analyzer/wifi_analyzer.c | 7 ++++++- 5 files changed, 27 insertions(+), 5 deletions(-) diff --git a/firmware/components/wifi_sniffer/cmd_sniffer.c b/firmware/components/wifi_sniffer/cmd_sniffer.c index 251ab5a..73ac33f 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 (*no_mem_cb)(); -void wifi_sniffer_register_cb(sniffer_cb_t callback) { +void wifi_sniffer_register_cb(sniffer_cb_t callback, void* _no_mem_cb) { sniffer_cb = callback; + no_mem_cb = _no_mem_cb; } void wifi_sniffer_register_animation_cbs(sniffer_animation_cb_t start_cb, @@ -146,6 +148,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 +174,11 @@ static void sniffer_task(void* parameters) { packet_info.seconds, packet_info.microseconds) != ESP_OK) { ESP_LOGW(TAG, "save captured packet failed"); + if (no_mem_cb) { + xSemaphoreGive(sniffer->sem_task_over); + force_exit = true; + no_mem_cb(); + } } free(packet_info.payload); if (sniffer->packets_to_sniff > 0) { @@ -186,7 +194,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); diff --git a/firmware/components/wifi_sniffer/include/cmd_sniffer.h b/firmware/components/wifi_sniffer/include/cmd_sniffer.h index 6b3530d..25976e7 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* _no_mem_cb); void wifi_sniffer_register_animation_cbs(sniffer_animation_cb_t start_cb, sniffer_animation_cb_t stop_cb); 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 c9112a6..65e049a 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" @@ -80,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 1b7d8a0..fcc3183 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 2f2ef82..4925026 100644 --- a/firmware/main/apps/wifi_analyzer/wifi_analyzer.c +++ b/firmware/main/apps/wifi_analyzer/wifi_analyzer.c @@ -48,6 +48,10 @@ uint16_t get_summary_rows_count() { return num_items; } +static void no_mem_handler() { + wifi_module_analyzer_run_exit(); + wifi_screens_show_no_mem(); +} void wifi_module_init_sniffer() { oled_screen_clear(); if (wifi_sniffer_is_destination_sd()) { @@ -118,7 +122,8 @@ void wifi_analyzer_run() { void wifi_analyzer_begin() { 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, + no_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); From 5a1f1493e0a8933925915e6a5b369d8955d64eb8 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Fri, 22 Nov 2024 16:22:47 -0600 Subject: [PATCH 04/25] feat: Channel hopping --- .../components/ieee_sniffer/ieee_sniffer.c | 26 +++- .../components/ieee_sniffer/ieee_sniffer.h | 4 + firmware/main/main.c | 2 + .../main/modules/gps/war_bee/warbee_module.c | 138 ++++++++++++++++++ .../main/modules/gps/war_bee/warbee_module.h | 8 + 5 files changed, 177 insertions(+), 1 deletion(-) create mode 100644 firmware/main/modules/gps/war_bee/warbee_module.c create mode 100644 firmware/main/modules/gps/war_bee/warbee_module.h diff --git a/firmware/components/ieee_sniffer/ieee_sniffer.c b/firmware/components/ieee_sniffer/ieee_sniffer.c index dc90264..fcc7776 100644 --- a/firmware/components/ieee_sniffer/ieee_sniffer.c +++ b/firmware/components/ieee_sniffer/ieee_sniffer.c @@ -10,6 +10,8 @@ #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; @@ -34,6 +36,10 @@ void ieee_sniffer_register_cb(ieee_sniffer_cb_t callback) { packet_callback = callback; } +uint8_t ieee_sniffer_get_channel() { + return current_channel; +} + void ieee_sniffer_set_channel(int channel) { current_channel = channel; if (channel < IEEE_SNIFFER_CHANNEL_MIN) { @@ -51,7 +57,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,10 +98,28 @@ void ieee_sniffer_begin(void) { } esp_ieee802154_set_extended_address(eui64_rev); ESP_ERROR_CHECK(esp_ieee802154_receive()); +} +void ieee_sniffer_begin(void) { + ieee_sniffer_configure(); while (true) { vTaskDelay(10 / portTICK_PERIOD_MS); } + vTaskDelete(NULL); +} + +void ieee_sniffer_channel_hop() { + ieee_sniffer_configure(); + esp_ieee802154_disable(); + while (true) { + // vTaskDelay(10 / portTICK_PERIOD_MS); + 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) { diff --git a/firmware/components/ieee_sniffer/ieee_sniffer.h b/firmware/components/ieee_sniffer/ieee_sniffer.h index 7e7e2ec..a6d6523 100644 --- a/firmware/components/ieee_sniffer/ieee_sniffer.h +++ b/firmware/components/ieee_sniffer/ieee_sniffer.h @@ -78,4 +78,8 @@ void ieee_sniffer_stop(void); * @param channel The channel to set */ void ieee_sniffer_set_channel(int channel); + +uint8_t ieee_sniffer_get_channel(); + +void ieee_sniffer_channel_hop(); #endif // IEEE_SNIFFER_H diff --git a/firmware/main/main.c b/firmware/main/main.c index 9e52331..31adcf1 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/gps/war_bee/warbee_module.c b/firmware/main/modules/gps/war_bee/warbee_module.c new file mode 100644 index 0000000..ba50545 --- /dev/null +++ b/firmware/main/modules/gps/war_bee/warbee_module.c @@ -0,0 +1,138 @@ +#include "warbee_module.h" +#include "esp_log.h" +#include "freertos/FreeRTOS.h" +#include "freertos/task.h" +#include "ieee_sniffer.h" +#include "radio_selector.h" + +#define DIR_NAME "Wardriving" +#define FILE_NAME DIR_NAME "/Minino" +#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" + +static bool running = false; + +static TaskHandle_t zigbee_task_sniffer = NULL; +static int current_channel = IEEE_SNIFFER_CHANNEL_DEFAULT; + +static char addressing_mode[4][15] = {"None", "Reserved", "Short/16-bit", + "Long/64-bit"}; + +const char* csv_header = FORMAT_VERSION ",appRelease=" APP_VERSION + ",model=" MODEL ",release=" RELEASE; + +static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { + uint8_t position = 0; + + mac_fcs_t* fcs = (mac_fcs_t*) &packet[position]; + position += sizeof(uint16_t); + // printf("Frame Control Field\n"); + // printf("└Channel: %d\n", current_channel); + // printf("└Frame type: %x\n", fcs->frameType); + // printf("└Security Enabled: %s\n", fcs->secure ? "True" : + // "False"); printf("└Frame pending: %s\n", + // fcs->framePending ? "True" : "False"); + // printf("└Acknowledge request: %s\n", + // fcs->ackReqd ? "True" : "False"); + // printf("└PAN ID Compression: %s\n", + // fcs->panIdCompressed ? "True" : "False"); + // printf("└Reserved: %s\n", fcs->rfu1 ? "True" : + // "False"); printf("└Sequence Number Suppression: %s\n", + // fcs->sequenceNumberSuppression ? "True" : "False"); + // printf("└Information Elements Present: %s\n", + // fcs->informationElementsPresent ? "True" : "False"); + // printf("└Destination addressing mode: %02X %s\n", fcs->destAddrType, + // addressing_mode[fcs->destAddrType]); + // printf("└Frame version: %x\n", fcs->frameVer); + // printf("└Source addressing mode: %02X %s\n", fcs->srcAddrType, + // addressing_mode[fcs->srcAddrType]); + + if (fcs->rfu1) { + ESP_LOGE(TAG_IEEE_SNIFFER, "Reserved field 1 is set, ignoring packet"); + return; + } + + switch (fcs->frameType) { + case FRAME_TYPE_BEACON: + printf("Beacon frame\n"); + break; + case FRAME_TYPE_DATA: + printf("Data frame\n"); + break; + case FRAME_TYPE_MAC_COMMAND: + printf("Beacon Request\n"); + printf("└Channel: %d\n", ieee_sniffer_get_channel()); + uint8_t sequence_number = packet[position]; + position += sizeof(uint8_t); + printf("Sequence number: %u\n", sequence_number); + + 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; + + 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 = *((uint8_t*) &packet[position]); + position += sizeof(uint8_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); + } + break; + default: { + ESP_LOGE(TAG_IEEE_SNIFFER, + "With reserved destination address type, ignoring packet\n"); + return; + } + } + break; + default: + printf("Packet ignored because of frame type (%u)\n", fcs->frameType); + break; + } + + esp_log_buffer_hex(">", packet, packet_length); +} + +static void warbee_channel_hopp_task() { + while (running) { + current_channel = (current_channel == IEEE_SNIFFER_CHANNEL_MAX) + ? IEEE_SNIFFER_CHANNEL_MIN + : (current_channel + 1); + ieee_sniffer_set_channel(current_channel); + + vTaskDelay(3500 / portTICK_PERIOD_MS); + } + vTaskDelete(NULL); +} + +void warbee_module_begin() { + running = true; + 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(warbee_channel_hopp_task, "warbee_channel_hopp_task", 4096, NULL, + 5, NULL); +} \ 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 0000000..8c206e5 --- /dev/null +++ b/firmware/main/modules/gps/war_bee/warbee_module.h @@ -0,0 +1,8 @@ +#pragma once + +/** + * @brief Initialize the wardriving zigbee module + * + * @return void + */ +void warbee_module_begin(); \ No newline at end of file From 8895d08d203a2f2b26dab58bc417300a33cc1bc3 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Fri, 22 Nov 2024 17:00:17 -0600 Subject: [PATCH 05/25] feat: Add RSSI field --- firmware/components/ieee_sniffer/ieee_sniffer.c | 5 ++++- firmware/components/ieee_sniffer/ieee_sniffer.h | 2 ++ .../main/modules/gps/war_bee/warbee_module.c | 17 +++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/firmware/components/ieee_sniffer/ieee_sniffer.c b/firmware/components/ieee_sniffer/ieee_sniffer.c index fcc7776..de15ad8 100644 --- a/firmware/components/ieee_sniffer/ieee_sniffer.c +++ b/firmware/components/ieee_sniffer/ieee_sniffer.c @@ -40,6 +40,10 @@ 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) { @@ -112,7 +116,6 @@ void ieee_sniffer_channel_hop() { ieee_sniffer_configure(); esp_ieee802154_disable(); while (true) { - // vTaskDelay(10 / portTICK_PERIOD_MS); esp_ieee802154_enable(); ieee_sniffer_set_channel(current_channel + 1); esp_ieee802154_receive(); diff --git a/firmware/components/ieee_sniffer/ieee_sniffer.h b/firmware/components/ieee_sniffer/ieee_sniffer.h index a6d6523..836ce20 100644 --- a/firmware/components/ieee_sniffer/ieee_sniffer.h +++ b/firmware/components/ieee_sniffer/ieee_sniffer.h @@ -80,6 +80,8 @@ void ieee_sniffer_stop(void); 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/main/modules/gps/war_bee/warbee_module.c b/firmware/main/modules/gps/war_bee/warbee_module.c index ba50545..675523d 100644 --- a/firmware/main/modules/gps/war_bee/warbee_module.c +++ b/firmware/main/modules/gps/war_bee/warbee_module.c @@ -27,8 +27,16 @@ static int current_channel = IEEE_SNIFFER_CHANNEL_DEFAULT; static char addressing_mode[4][15] = {"None", "Reserved", "Short/16-bit", "Long/64-bit"}; -const char* csv_header = FORMAT_VERSION ",appRelease=" APP_VERSION - ",model=" MODEL ",release=" RELEASE; +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 + "Source,DestinationPAN,Channel," + // GPS fields + "CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,RCOIs," + "MfgrId,Type"; static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { uint8_t position = 0; @@ -71,6 +79,7 @@ static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { case FRAME_TYPE_MAC_COMMAND: printf("Beacon Request\n"); printf("└Channel: %d\n", ieee_sniffer_get_channel()); + printf("RSSI: %d\n", ieee_sniffer_get_rssi()); uint8_t sequence_number = packet[position]; position += sizeof(uint8_t); printf("Sequence number: %u\n", sequence_number); @@ -87,8 +96,8 @@ static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { break; // Device is sending to a short address case ADDR_MODE_SHORT: - pan_id = *((uint8_t*) &packet[position]); - position += sizeof(uint8_t); + 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) { From 73e09f676d840017d2f50044c0891ea7ed486d58 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Mon, 25 Nov 2024 14:44:06 -0600 Subject: [PATCH 06/25] feat: Add csv struct --- .../components/ieee_sniffer/ieee_sniffer.c | 8 +- firmware/components/sd_card/include/sd_card.h | 2 + firmware/components/sd_card/sd_card.c | 29 +- firmware/main/main.c | 2 +- .../main/modules/gps/war_bee/warbee_module.c | 278 ++++++++++++++---- .../main/modules/gps/war_bee/warbee_module.h | 8 +- .../menus_module/menus_include/menus.h | 11 +- 7 files changed, 270 insertions(+), 68 deletions(-) diff --git a/firmware/components/ieee_sniffer/ieee_sniffer.c b/firmware/components/ieee_sniffer/ieee_sniffer.c index de15ad8..97a3c95 100644 --- a/firmware/components/ieee_sniffer/ieee_sniffer.c +++ b/firmware/components/ieee_sniffer/ieee_sniffer.c @@ -16,6 +16,7 @@ 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); @@ -105,17 +106,19 @@ static void ieee_sniffer_configure() { } void ieee_sniffer_begin(void) { + running = true; ieee_sniffer_configure(); - while (true) { + while (running) { vTaskDelay(10 / portTICK_PERIOD_MS); } vTaskDelete(NULL); } void ieee_sniffer_channel_hop() { + running = true; ieee_sniffer_configure(); esp_ieee802154_disable(); - while (true) { + while (running) { esp_ieee802154_enable(); ieee_sniffer_set_channel(current_channel + 1); esp_ieee802154_receive(); @@ -126,6 +129,7 @@ void ieee_sniffer_channel_hop() { } 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/sd_card/include/sd_card.h b/firmware/components/sd_card/include/sd_card.h index 970ce54..f6c3b09 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 c2b9433..e0e2226 100644 --- a/firmware/components/sd_card/sd_card.c +++ b/firmware/components/sd_card/sd_card.c @@ -158,9 +158,9 @@ esp_err_t unmount() { } void sd_card_begin() { -#if !defined(CONFIG_SD_CARD_DEBUG) - esp_log_level_set(TAG, ESP_LOG_NONE); -#endif + // #if !defined(CONFIG_SD_CARD_DEBUG) + // esp_log_level_set(TAG, ESP_LOG_NONE); + // #endif } esp_err_t sd_card_mount() { @@ -321,6 +321,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 %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/main/main.c b/firmware/main/main.c index 31adcf1..dc581c3 100644 --- a/firmware/main/main.c +++ b/firmware/main/main.c @@ -42,6 +42,6 @@ void app_main() { menus_module_begin(); leds_off(); preferences_put_bool("wifi_connected", false); - warbee_module_begin(); + // warbee_module_begin(); cat_console_begin(); } diff --git a/firmware/main/modules/gps/war_bee/warbee_module.c b/firmware/main/modules/gps/war_bee/warbee_module.c index 675523d..d992181 100644 --- a/firmware/main/modules/gps/war_bee/warbee_module.c +++ b/firmware/main/modules/gps/war_bee/warbee_module.c @@ -1,12 +1,18 @@ #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 "radio_selector.h" +#include "sd_card.h" +#include "wardriving_screens_module.h" -#define DIR_NAME "Wardriving" -#define FILE_NAME DIR_NAME "/Minino" +#define DIR_NAME "warbee" +#define FILE_NAME DIR_NAME "/Warbee" #define FORMAT_VERSION "ElecCats-1.0" #define APP_VERSION CONFIG_PROJECT_VERSION #define MODEL "MININO" @@ -19,13 +25,24 @@ #define BODY "3" #define SUB_BODY "0" -static bool running = false; +#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 static TaskHandle_t zigbee_task_sniffer = NULL; -static int current_channel = IEEE_SNIFFER_CHANNEL_DEFAULT; - static char addressing_mode[4][15] = {"None", "Reserved", "Short/16-bit", "Long/64-bit"}; +static QueueHandle_t packet_rx_queue = NULL; + +static warbee_module_t context_session; +static gps_t* gps_ctx; + +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 @@ -33,62 +50,135 @@ const char* csv_header = FORMAT_VERSION ",star=" STAR ",body=" BODY ",subBody=" SUB_BODY "\n" // IEEE 802.15.4 fields - "Source,DestinationPAN,Channel," + "Source,DestinationPAN,Channel,RSSI," // GPS fields "CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,RCOIs," "MfgrId,Type"; +static void warbee_gps_event_handler_cb(gps_t* gps); +static void warbee_module_save_to_file(gps_t* gps); +static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length); + +static 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; +} + +static void update_file_name(char* full_date_time) { + sprintf(csv_file_name, "%s_%s_b.csv", FILE_NAME, full_date_time); + // Replace " " by "_" and ":" by "-" + for (int i = 0; i < strlen(csv_file_name); i++) { + if (csv_file_name[i] == ' ') { + csv_file_name[i] = '_'; + } + if (csv_file_name[i] == ':') { + csv_file_name[i] = '-'; + } + } +} + +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 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", "Nueva session"); + context_session.session_str = get_full_date_time(gps); + 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(); + // return; + } + + // warbee_module_save_to_file(gps); +} + +static void warbee_module_save_to_file(gps_t* gps) { + ESP_LOGI("Warbee", "Saving to file"); +} + static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { + 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); - // printf("Frame Control Field\n"); - // printf("└Channel: %d\n", current_channel); - // printf("└Frame type: %x\n", fcs->frameType); - // printf("└Security Enabled: %s\n", fcs->secure ? "True" : - // "False"); printf("└Frame pending: %s\n", - // fcs->framePending ? "True" : "False"); - // printf("└Acknowledge request: %s\n", - // fcs->ackReqd ? "True" : "False"); - // printf("└PAN ID Compression: %s\n", - // fcs->panIdCompressed ? "True" : "False"); - // printf("└Reserved: %s\n", fcs->rfu1 ? "True" : - // "False"); printf("└Sequence Number Suppression: %s\n", - // fcs->sequenceNumberSuppression ? "True" : "False"); - // printf("└Information Elements Present: %s\n", - // fcs->informationElementsPresent ? "True" : "False"); - // printf("└Destination addressing mode: %02X %s\n", fcs->destAddrType, - // addressing_mode[fcs->destAddrType]); - // printf("└Frame version: %x\n", fcs->frameVer); - // printf("└Source addressing mode: %02X %s\n", fcs->srcAddrType, - // addressing_mode[fcs->srcAddrType]); - - if (fcs->rfu1) { - ESP_LOGE(TAG_IEEE_SNIFFER, "Reserved field 1 is set, ignoring packet"); - return; + + 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); switch (fcs->frameType) { - case FRAME_TYPE_BEACON: - printf("Beacon frame\n"); - break; case FRAME_TYPE_DATA: - printf("Data frame\n"); - break; case FRAME_TYPE_MAC_COMMAND: - printf("Beacon Request\n"); - printf("└Channel: %d\n", ieee_sniffer_get_channel()); - printf("RSSI: %d\n", ieee_sniffer_get_rssi()); uint8_t sequence_number = packet[position]; position += sizeof(uint8_t); - printf("Sequence number: %u\n", sequence_number); - - 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; switch (fcs->destAddrType) { case ADDR_MODE_NONE: @@ -108,6 +198,19 @@ static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { 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, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", + 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, @@ -116,32 +219,87 @@ static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { } } 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,0x%04x,%d,%d,%f,%f,%f,%f,%s,%s,%s\n", + // Source + pan_id, + // DestinationPAN + short_dst_addr, + // Channel + ieee_sniffer_get_channel(), + // RSSI + ieee_sniffer_get_rssi(), + // 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); - esp_log_buffer_hex(">", packet, packet_length); + sd_card_append_to_file(csv_file_name, csv_line_buffer); + free(csv_line_buffer); + free(dst_addr_str); } -static void warbee_channel_hopp_task() { - while (running) { - current_channel = (current_channel == IEEE_SNIFFER_CHANNEL_MAX) - ? IEEE_SNIFFER_CHANNEL_MIN - : (current_channel + 1); - ieee_sniffer_set_channel(current_channel); +void warbee_module_begin() { + if (wardriving_module_verify_sd_card() != ESP_OK) { + return; + } + ESP_LOGI("Warbee", "Wardriving module begin"); + packet_rx_queue = xQueueCreate(8, 257); + 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; + } - vTaskDelay(3500 / portTICK_PERIOD_MS); + 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; } - vTaskDelete(NULL); -} -void warbee_module_begin() { - running = true; + sprintf(csv_file_name, "%s_b.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(warbee_channel_hopp_task, "warbee_channel_hopp_task", 4096, NULL, - 5, NULL); + + 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", "Wardriving module end"); + ieee_sniffer_stop(); + sd_card_read_file(csv_file_name); + sd_card_unmount(); + free(csv_file_buffer); + free(csv_file_name); + vQueueDelete(packet_rx_queue); } \ 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 index 8c206e5..24cdb1f 100644 --- a/firmware/main/modules/gps/war_bee/warbee_module.h +++ b/firmware/main/modules/gps/war_bee/warbee_module.h @@ -1,8 +1,14 @@ #pragma once +typedef struct { + char* session_str; +} warbee_module_t; + /** * @brief Initialize the wardriving zigbee module * * @return void */ -void warbee_module_begin(); \ No newline at end of file +void warbee_module_begin(); + +void warbee_module_exit(); \ No newline at end of file diff --git a/firmware/main/modules/menus_module/menus_include/menus.h b/firmware/main/modules/menus_module/menus_include/menus.h index 8546982..e0fde45 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, @@ -362,13 +364,20 @@ 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}, + {.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}, {.display_name = "Help", .menu_idx = MENU_GPS_WARDRIVING_HELP, .parent_idx = MENU_GPS_WARDRIVING, From 4d72bca9b6aebc16965328cc288c4d189515896e Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Mon, 25 Nov 2024 14:52:46 -0600 Subject: [PATCH 07/25] feat: Save file --- firmware/components/sd_card/sd_card.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/firmware/components/sd_card/sd_card.c b/firmware/components/sd_card/sd_card.c index e0e2226..4f863a3 100644 --- a/firmware/components/sd_card/sd_card.c +++ b/firmware/components/sd_card/sd_card.c @@ -308,7 +308,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"); @@ -331,7 +331,7 @@ esp_err_t sd_card_append_to_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 a %s", full_path); FILE* file = fopen(full_path, "a"); if (file == NULL) { ESP_LOGE(TAG, "Failed to open file for writing"); From 4f1112d28df99110df285d4cd7c4d78b312538d2 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Tue, 26 Nov 2024 11:46:18 -0600 Subject: [PATCH 08/25] feat: Refactor wardriving - Add warbee - Add animations --- firmware/main/modules/gps/gps_module.c | 14 +++ firmware/main/modules/gps/gps_module.h | 3 + .../main/modules/gps/war_bee/warbee_module.c | 119 ++++++++++-------- .../main/modules/gps/war_bee/warbee_module.h | 2 + .../gps/war_common/wardriving_common.h | 26 ++++ .../gps/wardriving/wardriving_module.c | 30 +---- .../wardriving/wardriving_screens_module.c | 1 + 7 files changed, 113 insertions(+), 82 deletions(-) create mode 100644 firmware/main/modules/gps/war_common/wardriving_common.h diff --git a/firmware/main/modules/gps/gps_module.c b/firmware/main/modules/gps/gps_module.c index 249b3c0..0618bda 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 47fd5d6..14f4b45 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 index d992181..77423fd 100644 --- a/firmware/main/modules/gps/war_bee/warbee_module.c +++ b/firmware/main/modules/gps/war_bee/warbee_module.c @@ -7,38 +7,22 @@ #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 DIR_NAME "warbee" -#define FILE_NAME 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" - -#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 +#define FILE_NAME DIR_NAME "/Warbee" -static TaskHandle_t zigbee_task_sniffer = NULL; -static char addressing_mode[4][15] = {"None", "Reserved", "Short/16-bit", - "Long/64-bit"}; -static QueueHandle_t packet_rx_queue = NULL; +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; @@ -56,27 +40,23 @@ const char* csv_header = FORMAT_VERSION "MfgrId,Type"; static void warbee_gps_event_handler_cb(gps_t* gps); -static void warbee_module_save_to_file(gps_t* gps); static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length); -static 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; +static void update_file_name(char* full_date_time) { + sprintf(csv_file_name, "%s_%s.csv", FILE_NAME, full_date_time); } -static void update_file_name(char* full_date_time) { - sprintf(csv_file_name, "%s_%s_b.csv", FILE_NAME, full_date_time); - // Replace " " by "_" and ":" by "-" - for (int i = 0; i < strlen(csv_file_name); i++) { - if (csv_file_name[i] == ' ') { - csv_file_name[i] = '_'; - } - if (csv_file_name[i] == ':') { - csv_file_name[i] = '-'; - } +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() { @@ -123,7 +103,8 @@ static void warbee_gps_event_handler_cb(gps_t* gps) { return; } ESP_LOGI("Warbee", "Nueva session"); - context_session.session_str = get_full_date_time(gps); + 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); @@ -147,14 +128,17 @@ static void warbee_gps_event_handler_cb(gps_t* gps) { if (gps->sats_in_use == 0) { ESP_LOGW("Warbee", "No GPS signal"); wardriving_screens_module_no_gps_signal(); - // return; + vTaskSuspend(scanning_zigbee_animation_task_handle); + running_zigbee_scanner_animation = false; + return; } - // warbee_module_save_to_file(gps); -} - -static void warbee_module_save_to_file(gps_t* gps) { - ESP_LOGI("Warbee", "Saving to file"); + if (running_zigbee_scanner_animation == false) { + wardriving_screens_module_scanning(context_session.session_records_count, + gps_module_get_signal_strength(gps)); + vTaskResume(scanning_zigbee_animation_task_handle); + running_zigbee_scanner_animation = true; + } } static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { @@ -207,9 +191,9 @@ static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { dst_addr[idx] = packet[position + sizeof(dst_addr) - 1 - idx]; } position += sizeof(dst_addr); - sprintf(dst_addr_str, "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x", - dst_addr[0], dst_addr[1], dst_addr[2], dst_addr[3], - dst_addr[4], dst_addr[5], dst_addr[6], dst_addr[7]); + 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: { @@ -251,7 +235,31 @@ static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { // xQueueSendToBackFromISR(packet_rx_queue, packet, NULL); ESP_LOGI("Warbee", "CSV Line: %s", csv_line_buffer); - sd_card_append_to_file(csv_file_name, 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); } @@ -261,7 +269,6 @@ void warbee_module_begin() { return; } ESP_LOGI("Warbee", "Wardriving module begin"); - packet_rx_queue = xQueueCreate(8, 257); csv_lines = CSV_HEADER_LINES; ESP_LOGI("Warbee", "Free heap size before allocation: %" PRIu32 " bytes", esp_get_free_heap_size()); @@ -278,7 +285,7 @@ void warbee_module_begin() { return; } - sprintf(csv_file_name, "%s_b.csv", FILE_NAME); + sprintf(csv_file_name, "%s.csv", FILE_NAME); sprintf(csv_file_buffer, "%s\n", csv_header); context_session.session_str = ""; @@ -287,7 +294,10 @@ void warbee_module_begin() { 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(); @@ -301,5 +311,4 @@ void warbee_module_exit() { sd_card_unmount(); free(csv_file_buffer); free(csv_file_name); - vQueueDelete(packet_rx_queue); } \ 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 index 24cdb1f..8940874 100644 --- a/firmware/main/modules/gps/war_bee/warbee_module.h +++ b/firmware/main/modules/gps/war_bee/warbee_module.h @@ -1,7 +1,9 @@ #pragma once +#include typedef struct { char* session_str; + uint16_t session_records_count; } warbee_module_t; /** 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 0000000..42ef999 --- /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 e460552..5991da4 100644 --- a/firmware/main/modules/gps/wardriving/wardriving_module.c +++ b/firmware/main/modules/gps/wardriving/wardriving_module.c @@ -13,26 +13,9 @@ #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 @@ -103,13 +86,6 @@ 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); } diff --git a/firmware/main/modules/gps/wardriving/wardriving_screens_module.c b/firmware/main/modules/gps/wardriving/wardriving_screens_module.c index 4ae4d72..a1c7348 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) { From 8455804c58f4435f18b9773ee916153588251f70 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Tue, 26 Nov 2024 15:43:57 -0600 Subject: [PATCH 09/25] feat: Add Warbee config --- .../minino_config/Kconfig.projbuild | 6 ++ firmware/components/sd_card/sd_card.c | 6 +- .../main/modules/gps/war_bee/warbee_module.c | 69 +++++++++++++++++-- .../menus_module/menus_include/menus.h | 2 + 4 files changed, 76 insertions(+), 7 deletions(-) diff --git a/firmware/components/minino_config/Kconfig.projbuild b/firmware/components/minino_config/Kconfig.projbuild index ea1cbcf..ef7e255 100644 --- a/firmware/components/minino_config/Kconfig.projbuild +++ b/firmware/components/minino_config/Kconfig.projbuild @@ -687,6 +687,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/sd_card.c b/firmware/components/sd_card/sd_card.c index 4f863a3..db54fd3 100644 --- a/firmware/components/sd_card/sd_card.c +++ b/firmware/components/sd_card/sd_card.c @@ -158,9 +158,9 @@ esp_err_t unmount() { } void sd_card_begin() { - // #if !defined(CONFIG_SD_CARD_DEBUG) - // esp_log_level_set(TAG, ESP_LOG_NONE); - // #endif +#if !defined(CONFIG_SD_CARD_DEBUG) + esp_log_level_set(TAG, ESP_LOG_NONE); +#endif } esp_err_t sd_card_mount() { diff --git a/firmware/main/modules/gps/war_bee/warbee_module.c b/firmware/main/modules/gps/war_bee/warbee_module.c index 77423fd..8e87c75 100644 --- a/firmware/main/modules/gps/war_bee/warbee_module.c +++ b/firmware/main/modules/gps/war_bee/warbee_module.c @@ -34,7 +34,8 @@ const char* csv_header = FORMAT_VERSION ",star=" STAR ",body=" BODY ",subBody=" SUB_BODY "\n" // IEEE 802.15.4 fields - "Source,DestinationPAN,Channel,RSSI," + "SourcePanID,SourceADDR,DestinationADDR,Channel,RSSI,SecurityEnabled," + "FrameType," // GPS fields "CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,RCOIs," "MfgrId,Type"; @@ -82,6 +83,19 @@ static void warbee_module_cb_event(uint8_t button_name, uint8_t button_event) { } } +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++; @@ -142,6 +156,11 @@ static void warbee_gps_event_handler_cb(gps_t* gps) { } static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { + if (gps->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]; @@ -157,6 +176,7 @@ static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { 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: @@ -202,6 +222,41 @@ static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { 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: @@ -209,15 +264,21 @@ static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { break; } // "Source,DestinationPAN,Channel,RSSI," - sprintf(csv_line_buffer, "0x%04x,0x%04x,%d,%d,%f,%f,%f,%f,%s,%s,%s\n", - // Source + 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 - short_dst_addr, + 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 diff --git a/firmware/main/modules/menus_module/menus_include/menus.h b/firmware/main/modules/menus_module/menus_include/menus.h index e0fde45..8a7fd0e 100644 --- a/firmware/main/modules/menus_module/menus_include/menus.h +++ b/firmware/main/modules/menus_module/menus_include/menus.h @@ -371,6 +371,7 @@ menu_t menus[] = { ////////////////////////////////// .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, @@ -378,6 +379,7 @@ menu_t menus[] = { ////////////////////////////////// .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, From 6a51fbb476ab01a69e19f6bfdde9253998df6567 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Wed, 27 Nov 2024 10:32:37 -0600 Subject: [PATCH 10/25] feat: Fix gps_context --- firmware/main/modules/gps/war_bee/warbee_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/main/modules/gps/war_bee/warbee_module.c b/firmware/main/modules/gps/war_bee/warbee_module.c index 8e87c75..0b43e2b 100644 --- a/firmware/main/modules/gps/war_bee/warbee_module.c +++ b/firmware/main/modules/gps/war_bee/warbee_module.c @@ -156,7 +156,7 @@ static void warbee_gps_event_handler_cb(gps_t* gps) { } static void warbee_packet_dissector(uint8_t* packet, uint8_t packet_length) { - if (gps->sats_in_use == 0) { + if (gps_ctx->sats_in_use == 0) { ESP_LOGW("Warbee", "No GPS signa dont savel"); return; } From f1bffa43b846c42ffe5204ecab28fbea94aac332 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Thu, 28 Nov 2024 17:13:45 -0600 Subject: [PATCH 11/25] feat: enable or disable zigbee spoofing apps from menuconfig --- .../components/minino_config/Kconfig.projbuild | 15 +++++++++++++++ .../modules/menus_module/menus_include/menus.h | 4 ++++ firmware/sdkconfig.defaults | 2 ++ 3 files changed, 21 insertions(+) diff --git a/firmware/components/minino_config/Kconfig.projbuild b/firmware/components/minino_config/Kconfig.projbuild index ea1cbcf..cd36f3d 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 diff --git a/firmware/main/modules/menus_module/menus_include/menus.h b/firmware/main/modules/menus_module/menus_include/menus.h index 8546982..47cb52d 100644 --- a/firmware/main/modules/menus_module/menus_include/menus.h +++ b/firmware/main/modules/menus_module/menus_include/menus.h @@ -281,6 +281,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 +290,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 +300,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", diff --git a/firmware/sdkconfig.defaults b/firmware/sdkconfig.defaults index 7b0d1d2..9f502b2 100644 --- a/firmware/sdkconfig.defaults +++ b/firmware/sdkconfig.defaults @@ -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 From 9c531fc48598304543e0a5e8b6171254f02ad85f Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Fri, 29 Nov 2024 11:02:20 -0600 Subject: [PATCH 12/25] feat: show out of memory when no available space on destination storage --- firmware/components/wifi_sniffer/cmd_pcap.c | 3 +- .../components/wifi_sniffer/cmd_sniffer.c | 12 +++--- .../wifi_sniffer/include/cmd_sniffer.h | 2 +- .../wifi_sniffer/include/wifi_sniffer.h | 2 +- .../components/wifi_sniffer/wifi_sniffer.c | 9 ++-- .../main/apps/wifi_analyzer/wifi_analyzer.c | 41 +++++++++++++++---- .../main/apps/wifi_analyzer/wifi_analyzer.h | 2 +- 7 files changed, 50 insertions(+), 21 deletions(-) diff --git a/firmware/components/wifi_sniffer/cmd_pcap.c b/firmware/components/wifi_sniffer/cmd_pcap.c index 70884dc..09b0a26 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 73ac33f..59b1a85 100644 --- a/firmware/components/wifi_sniffer/cmd_sniffer.c +++ b/firmware/components/wifi_sniffer/cmd_sniffer.c @@ -45,11 +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 (*no_mem_cb)(); +static void (*out_of_mem_cb)(); -void wifi_sniffer_register_cb(sniffer_cb_t callback, void* _no_mem_cb) { +void wifi_sniffer_register_cb(sniffer_cb_t callback, void* _out_of_mem_cb) { sniffer_cb = callback; - no_mem_cb = _no_mem_cb; + out_of_mem_cb = _out_of_mem_cb; } void wifi_sniffer_register_animation_cbs(sniffer_animation_cb_t start_cb, @@ -71,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] = { @@ -174,10 +175,10 @@ static void sniffer_task(void* parameters) { packet_info.seconds, packet_info.microseconds) != ESP_OK) { ESP_LOGW(TAG, "save captured packet failed"); - if (no_mem_cb) { + if (out_of_mem_cb) { xSemaphoreGive(sniffer->sem_task_over); force_exit = true; - no_mem_cb(); + out_of_mem_cb(); } } free(packet_info.payload); @@ -332,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 25976e7..f055a7f 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* _no_mem_cb); +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 7d59bef..3828500 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 c259ca1..6df0633 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/main/apps/wifi_analyzer/wifi_analyzer.c b/firmware/main/apps/wifi_analyzer/wifi_analyzer.c index 4925026..28545c9 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,14 +50,22 @@ uint16_t get_summary_rows_count() { return num_items; } -static void no_mem_handler() { - wifi_module_analyzer_run_exit(); +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; } -void wifi_module_init_sniffer() { + +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"); @@ -75,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(); } @@ -116,14 +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, - no_mem_handler); + 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 0ff8761..cc848ce 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(); From ce298909d67103b690b9459dadd66dfada5a111f Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Fri, 29 Nov 2024 15:55:37 -0600 Subject: [PATCH 13/25] fix: sd card format from gps wardriving --- .../gps/wardriving/wardriving_module.c | 5 ++- .../sd_card/sd_card_settings_module.c | 39 +++++++++++-------- .../sd_card/sd_card_settings_module.h | 1 + 3 files changed, 26 insertions(+), 19 deletions(-) diff --git a/firmware/main/modules/gps/wardriving/wardriving_module.c b/firmware/main/modules/gps/wardriving/wardriving_module.c index e460552..3751e76 100644 --- a/firmware/main/modules/gps/wardriving/wardriving_module.c +++ b/firmware/main/modules/gps/wardriving/wardriving_module.c @@ -336,10 +336,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,7 +381,7 @@ 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; } @@ -395,6 +395,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/settings/sd_card/sd_card_settings_module.c b/firmware/main/modules/settings/sd_card/sd_card_settings_module.c index d4bd9b6..ebbe6d4 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 5804fda..bdd5269 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); From fa02580f6228265b36307d6591e3697c4a36a9f4 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Mon, 2 Dec 2024 10:55:04 -0600 Subject: [PATCH 14/25] feat: Fix function screen orden --- firmware/main/modules/gps/war_bee/warbee_module.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/firmware/main/modules/gps/war_bee/warbee_module.c b/firmware/main/modules/gps/war_bee/warbee_module.c index 0b43e2b..b0f26e0 100644 --- a/firmware/main/modules/gps/war_bee/warbee_module.c +++ b/firmware/main/modules/gps/war_bee/warbee_module.c @@ -148,9 +148,9 @@ static void warbee_gps_event_handler_cb(gps_t* gps) { } 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)); - vTaskResume(scanning_zigbee_animation_task_handle); running_zigbee_scanner_animation = true; } } From e5429f73faaf1e8e54a27da3ed76b44594ac7c70 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Mon, 2 Dec 2024 14:38:28 -0600 Subject: [PATCH 15/25] feat: Fix wifi_scanner loop --- firmware/components/wifi_scanner/wifi_scanner.c | 2 ++ firmware/main/modules/gps/wardriving/wardriving_module.c | 7 +++++++ 2 files changed, 9 insertions(+) diff --git a/firmware/components/wifi_scanner/wifi_scanner.c b/firmware/components/wifi_scanner/wifi_scanner.c index d7accb1..5044b0f 100644 --- a/firmware/components/wifi_scanner/wifi_scanner.c +++ b/firmware/components/wifi_scanner/wifi_scanner.c @@ -18,6 +18,8 @@ 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; diff --git a/firmware/main/modules/gps/wardriving/wardriving_module.c b/firmware/main/modules/gps/wardriving/wardriving_module.c index 7763b5a..b62a0cd 100644 --- a/firmware/main/modules/gps/wardriving/wardriving_module.c +++ b/firmware/main/modules/gps/wardriving/wardriving_module.c @@ -7,6 +7,7 @@ #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" @@ -91,9 +92,15 @@ uint16_t get_frequency(uint8_t primary) { } void wardriving_module_scan_task(void* pvParameters) { + oled_screen_clear(); + oled_screen_display_text_center("Start sta", 3, OLED_DISPLAY_NORMAL); wifi_driver_init_sta(); + oled_screen_clear(); + oled_screen_display_text_center("Finished", 3, OLED_DISPLAY_NORMAL); while (true) { + oled_screen_clear(); + oled_screen_display_text_center("Scanning module", 3, OLED_DISPLAY_NORMAL); wifi_scanner_module_scan(); vTaskDelay(WIFI_SCAN_REFRESH_RATE_MS / portTICK_PERIOD_MS); } From 7d3c36989e001a5101ff3e273d6ee548871736da Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Tue, 3 Dec 2024 15:17:41 -0600 Subject: [PATCH 16/25] feat: Fix ap scanner --- firmware/main/apps/wifi/deauth/deauth_module.c | 11 +++++++++-- .../main/modules/gps/wardriving/wardriving_module.c | 10 +--------- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/firmware/main/apps/wifi/deauth/deauth_module.c b/firmware/main/apps/wifi/deauth/deauth_module.c index e62058a..0f2e2d0 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/modules/gps/wardriving/wardriving_module.c b/firmware/main/modules/gps/wardriving/wardriving_module.c index b62a0cd..b48b1f5 100644 --- a/firmware/main/modules/gps/wardriving/wardriving_module.c +++ b/firmware/main/modules/gps/wardriving/wardriving_module.c @@ -92,16 +92,8 @@ uint16_t get_frequency(uint8_t primary) { } void wardriving_module_scan_task(void* pvParameters) { - oled_screen_clear(); - oled_screen_display_text_center("Start sta", 3, OLED_DISPLAY_NORMAL); - wifi_driver_init_sta(); - oled_screen_clear(); - oled_screen_display_text_center("Finished", 3, OLED_DISPLAY_NORMAL); - while (true) { - oled_screen_clear(); - oled_screen_display_text_center("Scanning module", 3, OLED_DISPLAY_NORMAL); - wifi_scanner_module_scan(); + // wifi_scanner_module_scan(); vTaskDelay(WIFI_SCAN_REFRESH_RATE_MS / portTICK_PERIOD_MS); } } From a46f3b6915c9b2084be4538ede2bf92ae384c1b2 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Wed, 4 Dec 2024 09:18:01 -0600 Subject: [PATCH 17/25] feat: Wardriving scan aps --- firmware/main/apps/wifi/deauth/deauth_module.c | 1 + firmware/main/modules/gps/wardriving/wardriving_module.c | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/firmware/main/apps/wifi/deauth/deauth_module.c b/firmware/main/apps/wifi/deauth/deauth_module.c index 0f2e2d0..30bc3d7 100644 --- a/firmware/main/apps/wifi/deauth/deauth_module.c +++ b/firmware/main/apps/wifi/deauth/deauth_module.c @@ -78,6 +78,7 @@ static void deauth_run_scan_task() { while (ap_records->count < (DEFAULT_SCAN_LIST_SIZE / 2)) { vTaskDelay(1000 / portTICK_PERIOD_MS); } + vTaskDelete(NULL); } static void deauth_handle_attacks() { diff --git a/firmware/main/modules/gps/wardriving/wardriving_module.c b/firmware/main/modules/gps/wardriving/wardriving_module.c index b48b1f5..a903b4b 100644 --- a/firmware/main/modules/gps/wardriving/wardriving_module.c +++ b/firmware/main/modules/gps/wardriving/wardriving_module.c @@ -93,7 +93,7 @@ uint16_t get_frequency(uint8_t primary) { void wardriving_module_scan_task(void* pvParameters) { while (true) { - // wifi_scanner_module_scan(); + wifi_scanner_module_scan(); vTaskDelay(WIFI_SCAN_REFRESH_RATE_MS / portTICK_PERIOD_MS); } } From e4b6633ca5d3764e6ecb7c10578b450bc867a2a3 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Wed, 4 Dec 2024 09:38:12 -0600 Subject: [PATCH 18/25] feat: Fix scann error --- firmware/main/apps/wifi/deauth/deauth_module.c | 1 - 1 file changed, 1 deletion(-) diff --git a/firmware/main/apps/wifi/deauth/deauth_module.c b/firmware/main/apps/wifi/deauth/deauth_module.c index 30bc3d7..0f2e2d0 100644 --- a/firmware/main/apps/wifi/deauth/deauth_module.c +++ b/firmware/main/apps/wifi/deauth/deauth_module.c @@ -78,7 +78,6 @@ static void deauth_run_scan_task() { while (ap_records->count < (DEFAULT_SCAN_LIST_SIZE / 2)) { vTaskDelay(1000 / portTICK_PERIOD_MS); } - vTaskDelete(NULL); } static void deauth_handle_attacks() { From 6bb3c1c125bdc235a04128305817de53dd2708be Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Wed, 4 Dec 2024 10:34:46 -0600 Subject: [PATCH 19/25] feat: Initialize wifi --- firmware/components/wifi_scanner/wifi_scanner.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/firmware/components/wifi_scanner/wifi_scanner.c b/firmware/components/wifi_scanner/wifi_scanner.c index 5044b0f..ede6b68 100644 --- a/firmware/components/wifi_scanner/wifi_scanner.c +++ b/firmware/components/wifi_scanner/wifi_scanner.c @@ -23,7 +23,19 @@ void wifi_scanner_module_scan() { } ap_records.count = CONFIG_SCAN_MAX_AP; - ESP_ERROR_CHECK(esp_wifi_start()); + 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; + } ESP_ERROR_CHECK(esp_wifi_clear_ap_list()); ESP_ERROR_CHECK(esp_wifi_scan_start(NULL, true)); ESP_LOGI(TAG_WIFI_SCANNER_MODULE, "Max AP number ap_info can hold = %u", From 316f5ea7e90e01f16c14686d093d214590cd9aa3 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Wed, 4 Dec 2024 11:12:39 -0600 Subject: [PATCH 20/25] feat: warbee active by default --- firmware/sdkconfig.defaults | 1 + 1 file changed, 1 insertion(+) diff --git a/firmware/sdkconfig.defaults b/firmware/sdkconfig.defaults index 9f502b2..d53abdb 100644 --- a/firmware/sdkconfig.defaults +++ b/firmware/sdkconfig.defaults @@ -113,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 ## From 4a1f0551ddb20ebd1889a664ee400d4afb7f7263 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Wed, 4 Dec 2024 12:27:07 -0600 Subject: [PATCH 21/25] refactor: wardriving tags as static --- firmware/main/modules/gps/war_bee/warbee_module.c | 8 ++++---- firmware/main/modules/gps/wardriving/wardriving_module.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/firmware/main/modules/gps/war_bee/warbee_module.c b/firmware/main/modules/gps/war_bee/warbee_module.c index b0f26e0..ed323cb 100644 --- a/firmware/main/modules/gps/war_bee/warbee_module.c +++ b/firmware/main/modules/gps/war_bee/warbee_module.c @@ -16,7 +16,7 @@ #define FILE_NAME DIR_NAME "/Warbee" -const char* TAG = "warbee"; +static const char* TAG = "warbee"; static TaskHandle_t zigbee_task_sniffer = NULL; static TaskHandle_t scanning_zigbee_animation_task_handle = NULL; @@ -116,7 +116,7 @@ static void warbee_gps_event_handler_cb(gps_t* gps) { ESP_LOGE("Warbee", "Failed to create %s directory", DIR_NAME); return; } - ESP_LOGI("Warbee", "Nueva session"); + 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); @@ -329,7 +329,7 @@ void warbee_module_begin() { if (wardriving_module_verify_sd_card() != ESP_OK) { return; } - ESP_LOGI("Warbee", "Wardriving module begin"); + 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()); @@ -366,7 +366,7 @@ void warbee_module_begin() { } void warbee_module_exit() { - ESP_LOGI("Warbee", "Wardriving module end"); + ESP_LOGI("Warbee", "Warbee module end"); ieee_sniffer_stop(); sd_card_read_file(csv_file_name); sd_card_unmount(); diff --git a/firmware/main/modules/gps/wardriving/wardriving_module.c b/firmware/main/modules/gps/wardriving/wardriving_module.c index a903b4b..1518385 100644 --- a/firmware/main/modules/gps/wardriving/wardriving_module.c +++ b/firmware/main/modules/gps/wardriving/wardriving_module.c @@ -29,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; From b093f725de8e6eb1c5026ae89d6a72534b2757eb Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Wed, 4 Dec 2024 13:57:27 -0600 Subject: [PATCH 22/25] feat: Fix wardriving AP scanner --- firmware/components/sd_card/sd_card.c | 5 +++++ .../components/wifi_scanner/wifi_scanner.c | 22 +++++++++++++++---- .../gps/wardriving/wardriving_module.c | 8 ++++--- firmware/sdkconfig.defaults | 2 +- firmware/sdkconfig.noota | 2 +- firmware/sdkconfig.ota | 2 +- 6 files changed, 31 insertions(+), 10 deletions(-) diff --git a/firmware/components/sd_card/sd_card.c b/firmware/components/sd_card/sd_card.c index db54fd3..5612a4f 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); diff --git a/firmware/components/wifi_scanner/wifi_scanner.c b/firmware/components/wifi_scanner/wifi_scanner.c index ede6b68..3a75add 100644 --- a/firmware/components/wifi_scanner/wifi_scanner.c +++ b/firmware/components/wifi_scanner/wifi_scanner.c @@ -36,12 +36,26 @@ void wifi_scanner_module_scan() { esp_err_to_name(err)); return; } - ESP_ERROR_CHECK(esp_wifi_clear_ap_list()); - ESP_ERROR_CHECK(esp_wifi_scan_start(NULL, true)); + 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/main/modules/gps/wardriving/wardriving_module.c b/firmware/main/modules/gps/wardriving/wardriving_module.c index 1518385..c05da7c 100644 --- a/firmware/main/modules/gps/wardriving/wardriving_module.c +++ b/firmware/main/modules/gps/wardriving/wardriving_module.c @@ -278,9 +278,9 @@ esp_err_t wardriving_module_verify_sd_card() { // TODO: return error code void wardriving_module_begin() { -#if !defined(CONFIG_WARDRIVING_MODULE_DEBUG) - esp_log_level_set(TAG, ESP_LOG_NONE); -#endif + // #if !defined(CONFIG_WARDRIVING_MODULE_DEBUG) + // esp_log_level_set(TAG, ESP_LOG_NONE); + // #endif ESP_LOGI(TAG, "Wardriving module begin"); csv_lines = CSV_HEADER_LINES; wifi_scanned_packets = 0; @@ -362,6 +362,8 @@ void wardriving_module_keyboard_cb(uint8_t button_name, uint8_t button_event) { switch (button_name) { case BUTTON_LEFT: + ESP_LOGI(TAG, "Left button pressed"); + wardriving_module_stop_scan(); menus_module_exit_app(); break; case BUTTON_RIGHT: diff --git a/firmware/sdkconfig.defaults b/firmware/sdkconfig.defaults index d53abdb..4e48cb0 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 diff --git a/firmware/sdkconfig.noota b/firmware/sdkconfig.noota index de4a841..e0f8f3f 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 513bfc0..98c7398 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 From 553b1fd130ef10cfbb275530534d8eb2e271498c Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Wed, 4 Dec 2024 15:24:09 -0600 Subject: [PATCH 23/25] feat: Uncomment debug and remove debug functions --- firmware/main/modules/gps/wardriving/wardriving_module.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/firmware/main/modules/gps/wardriving/wardriving_module.c b/firmware/main/modules/gps/wardriving/wardriving_module.c index c05da7c..0a4051d 100644 --- a/firmware/main/modules/gps/wardriving/wardriving_module.c +++ b/firmware/main/modules/gps/wardriving/wardriving_module.c @@ -278,9 +278,9 @@ esp_err_t wardriving_module_verify_sd_card() { // TODO: return error code void wardriving_module_begin() { - // #if !defined(CONFIG_WARDRIVING_MODULE_DEBUG) - // esp_log_level_set(TAG, ESP_LOG_NONE); - // #endif +#if !defined(CONFIG_WARDRIVING_MODULE_DEBUG) + esp_log_level_set(TAG, ESP_LOG_NONE); +#endif ESP_LOGI(TAG, "Wardriving module begin"); csv_lines = CSV_HEADER_LINES; wifi_scanned_packets = 0; @@ -362,7 +362,6 @@ void wardriving_module_keyboard_cb(uint8_t button_name, uint8_t button_event) { switch (button_name) { case BUTTON_LEFT: - ESP_LOGI(TAG, "Left button pressed"); wardriving_module_stop_scan(); menus_module_exit_app(); break; From 16fd4dcacb9cc7bac6331823d6aa2a4e078f9361 Mon Sep 17 00:00:00 2001 From: Roberto Arellano Date: Wed, 4 Dec 2024 15:57:32 -0600 Subject: [PATCH 24/25] fix: zigbee network creation --- firmware/components/zigbee_switch/zigbee_switch.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/firmware/components/zigbee_switch/zigbee_switch.c b/firmware/components/zigbee_switch/zigbee_switch.c index 51c4463..1422376 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); From 5070dd145003f04f8a8f7bc3240adec8c948c5c5 Mon Sep 17 00:00:00 2001 From: Kevin Jahaziel Leon Morales Date: Thu, 5 Dec 2024 11:34:34 -0600 Subject: [PATCH 25/25] feat: Update build generator and Docs --- README.md | 5 ++--- firmware/get_build.sh | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 786940e..9e45eaa 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) -- [ ] Wireshark integration ### Zigbee - [x] Zigbee sniffer - [x] Zigbee spoofing (Switch End Device) -- [ ] Wardriving +- [x] Wardriving - [x] Wireshark integration ### Thread diff --git a/firmware/get_build.sh b/firmware/get_build.sh index d4e345a..101193d 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!"