From caecd09d74e97d20f380fcbe97a005f2109f6e70 Mon Sep 17 00:00:00 2001 From: Just Call Me Koko Date: Thu, 3 Apr 2025 10:57:01 -0400 Subject: [PATCH] Create set macs menu and fix wifi init for macs --- esp32_marauder/MenuFunctions.cpp | 24 ++++++++++++++++++++++-- esp32_marauder/MenuFunctions.h | 1 + esp32_marauder/WiFiScan.cpp | 10 +++++----- 3 files changed, 28 insertions(+), 7 deletions(-) diff --git a/esp32_marauder/MenuFunctions.cpp b/esp32_marauder/MenuFunctions.cpp index 86672f2..c14555f 100644 --- a/esp32_marauder/MenuFunctions.cpp +++ b/esp32_marauder/MenuFunctions.cpp @@ -1456,6 +1456,7 @@ void MenuFunctions::RunSetup() wifiGeneralMenu.list = new LinkedList(); wifiAPMenu.list = new LinkedList(); apInfoMenu.list = new LinkedList(); + setMacMenu.list = new LinkedList(); genAPMacMenu.list = new LinkedList(); #ifdef HAS_BT airtagMenu.list = new LinkedList(); @@ -1524,6 +1525,7 @@ void MenuFunctions::RunSetup() clearAPsMenu.name = text_table1[29]; wifiAPMenu.name = "Access Points"; apInfoMenu.name = "AP Info"; + setMacMenu.name = "Set MACs"; genAPMacMenu.name = "Generate AP MAC"; #ifdef HAS_BT airtagMenu.name = "Select Airtag"; @@ -1944,12 +1946,30 @@ void MenuFunctions::RunSetup() }); #endif - this->addNodes(&wifiGeneralMenu, "Generate AP MAC", TFTLIGHTGREY, NULL, 0, [this]() { + this->addNodes(&wifiGeneralMenu, "Set MACs", TFTLIGHTGREY, NULL, 0, [this]() { + this->changeMenu(&setMacMenu); + }); + + + // Menu for generating and setting MAC addrs for AP and STA + setMacMenu.parentMenu = &wifiGeneralMenu; + this->addNodes(&setMacMenu, text09, TFTLIGHTGREY, NULL, 0, [this]() { + this->changeMenu(setMacMenu.parentMenu); + }); + + // Generate random MAC for AP + this->addNodes(&setMacMenu, "Generate AP MAC", TFTLIME, NULL, 0, [this]() { this->changeMenu(&genAPMacMenu); wifi_scan_obj.RunGenerateRandomMac(true); }); - // Menu for generating and setting access point MAC + // Generate random MAC for AP + this->addNodes(&setMacMenu, "Generate STA MAC", TFTCYAN, NULL, 0, [this]() { + this->changeMenu(&genAPMacMenu); + wifi_scan_obj.RunGenerateRandomMac(false); + }); + + // Menu for generating and setting access point MAC (just goes bacK) genAPMacMenu.parentMenu = &wifiGeneralMenu; this->addNodes(&genAPMacMenu, text09, TFTLIGHTGREY, NULL, 0, [this]() { this->changeMenu(genAPMacMenu.parentMenu); diff --git a/esp32_marauder/MenuFunctions.h b/esp32_marauder/MenuFunctions.h index 3d9c594..e88d4c4 100644 --- a/esp32_marauder/MenuFunctions.h +++ b/esp32_marauder/MenuFunctions.h @@ -179,6 +179,7 @@ class MenuFunctions Menu saveFileMenu; Menu apInfoMenu; Menu genAPMacMenu; + Menu setMacMenu; // Bluetooth menu stuff Menu bluetoothSnifferMenu; diff --git a/esp32_marauder/WiFiScan.cpp b/esp32_marauder/WiFiScan.cpp index 840af63..df21fdf 100644 --- a/esp32_marauder/WiFiScan.cpp +++ b/esp32_marauder/WiFiScan.cpp @@ -1078,9 +1078,9 @@ String WiFiScan::getStaMAC() char *buf; uint8_t mac[6]; char macAddrChr[18] = {0}; - esp_wifi_init(&cfg); + esp_wifi_init(&cfg2); esp_wifi_set_storage(WIFI_STORAGE_RAM); - esp_wifi_set_mode(WIFI_MODE_NULL); + esp_wifi_set_mode(WIFI_MODE_STA); esp_wifi_start(); this->setMac(); esp_err_t mac_status = esp_wifi_get_mac(WIFI_IF_STA, mac); @@ -1102,9 +1102,9 @@ String WiFiScan::getApMAC() char *buf; uint8_t mac[6]; char macAddrChr[18] = {0}; - esp_wifi_init(&cfg); + esp_wifi_init(&cfg2); esp_wifi_set_storage(WIFI_STORAGE_RAM); - esp_wifi_set_mode(WIFI_MODE_NULL); + esp_wifi_set_mode(WIFI_MODE_AP); esp_wifi_start(); this->setMac(); esp_err_t mac_status = esp_wifi_get_mac(WIFI_IF_AP, mac); @@ -1730,7 +1730,7 @@ void WiFiScan::RunGenerateRandomMac(bool ap) { if (ap) Serial.println("Setting AP MAC: " + macToString(this->ap_mac)); else Serial.println("Setting STA MAC: " + macToString(this->sta_mac)); - #ifdef HAS_DISPLAY + #ifdef HAS_SCREEN display_obj.tft.setTextWrap(false); display_obj.tft.setFreeFont(NULL); display_obj.tft.setCursor(0, 100);