mirror of
https://github.com/justcallmekoko/ESP32Marauder.git
synced 2025-12-23 07:29:14 -08:00
Add join wifi for switch hardware
This commit is contained in:
@@ -253,6 +253,7 @@ void CommandLine::runCommand(String input) {
|
||||
Serial.println(HELP_SSID_CMD_B);
|
||||
Serial.println(HELP_SAVE_CMD);
|
||||
Serial.println(HELP_LOAD_CMD);
|
||||
Serial.println(HELP_JOIN_CMD);
|
||||
|
||||
// Bluetooth sniff/scan
|
||||
#ifdef HAS_BT
|
||||
@@ -1241,6 +1242,28 @@ void CommandLine::runCommand(String input) {
|
||||
wifi_scan_obj.RunInfo();
|
||||
}
|
||||
}
|
||||
else if (cmd_args.get(0) == JOIN_CMD) {
|
||||
int ap_sw = this->argSearch(&cmd_args, "-a");
|
||||
int pw_sw = this->argSearch(&cmd_args, "-p");
|
||||
|
||||
if ((ap_sw != -1) && (pw_sw != -1)) {
|
||||
int index = cmd_args.get(ap_sw + 1).toInt();
|
||||
String password = cmd_args.get(pw_sw + 1);
|
||||
Serial.println("Using SSID: " + (String)access_points->get(index).essid + " Password: " + (String)password);
|
||||
wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
|
||||
wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
|
||||
wifi_scan_obj.joinWiFi(access_points->get(index).essid, password);
|
||||
#ifdef HAS_SCREEN
|
||||
#ifdef HAS_MINI_KB
|
||||
menu_function_obj.changeMenu(menu_function_obj.current_menu);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
Serial.println("You did not provide the proper args");
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Select access points or stations
|
||||
else if (cmd_args.get(0) == SEL_CMD) {
|
||||
// Get switches
|
||||
|
||||
@@ -85,6 +85,7 @@ const char PROGMEM SEL_CMD[] = "select";
|
||||
const char PROGMEM SSID_CMD[] = "ssid";
|
||||
const char PROGMEM SAVE_CMD[] = "save";
|
||||
const char PROGMEM LOAD_CMD[] = "load";
|
||||
const char PROGMEM JOIN_CMD[] = "join";
|
||||
|
||||
// Bluetooth sniff/scan
|
||||
const char PROGMEM BT_SPAM_CMD[] = "blespam";
|
||||
@@ -145,6 +146,7 @@ const char PROGMEM HELP_SSID_CMD_A[] = "ssid -a [-g <count>/-n <name>]";
|
||||
const char PROGMEM HELP_SSID_CMD_B[] = "ssid -r <index>";
|
||||
const char PROGMEM HELP_SAVE_CMD[] = "save -a/-s";
|
||||
const char PROGMEM HELP_LOAD_CMD[] = "load -a/-s";
|
||||
const char PROGMEM HELP_JOIN_CMD[] = "join -a <index> -p <password>";
|
||||
|
||||
// Bluetooth sniff/scan
|
||||
const char PROGMEM HELP_BT_SNIFF_CMD[] = "sniffbt [-t] <airtag/flipper>";
|
||||
|
||||
@@ -760,6 +760,7 @@ void MenuFunctions::main(uint32_t currentTime)
|
||||
this->orientDisplay();
|
||||
}
|
||||
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
|
||||
(wifi_scan_obj.currentScanMode == WIFI_CONNECTED) ||
|
||||
(wifi_scan_obj.currentScanMode == OTA_UPDATE) ||
|
||||
(wifi_scan_obj.currentScanMode == ESP_UPDATE) ||
|
||||
(wifi_scan_obj.currentScanMode == SHOW_INFO) ||
|
||||
@@ -797,6 +798,7 @@ void MenuFunctions::main(uint32_t currentTime)
|
||||
|
||||
// Get the display buffer out of the way
|
||||
if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF ) &&
|
||||
(wifi_scan_obj.currentScanMode != WIFI_CONNECTED) &&
|
||||
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_BEACON_SPAM) &&
|
||||
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_AP_SPAM) &&
|
||||
(wifi_scan_obj.currentScanMode != WIFI_ATTACK_AUTH) &&
|
||||
@@ -820,6 +822,7 @@ void MenuFunctions::main(uint32_t currentTime)
|
||||
#ifdef HAS_ILI9341
|
||||
if ((wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
|
||||
(pressed) &&
|
||||
(wifi_scan_obj.currentScanMode != WIFI_CONNECTED) &&
|
||||
(wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
|
||||
(wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
|
||||
(wifi_scan_obj.currentScanMode != SHOW_INFO) &&
|
||||
@@ -890,6 +893,7 @@ void MenuFunctions::main(uint32_t currentTime)
|
||||
|
||||
if ((c_btn_press) &&
|
||||
(wifi_scan_obj.currentScanMode != WIFI_SCAN_OFF) &&
|
||||
(wifi_scan_obj.currentScanMode != WIFI_CONNECTED) &&
|
||||
(wifi_scan_obj.currentScanMode != OTA_UPDATE) &&
|
||||
(wifi_scan_obj.currentScanMode != ESP_UPDATE) &&
|
||||
(wifi_scan_obj.currentScanMode != SHOW_INFO) &&
|
||||
@@ -996,6 +1000,7 @@ void MenuFunctions::main(uint32_t currentTime)
|
||||
if (menu_button > -1) {
|
||||
if (menu_button == UP_BUTTON) {
|
||||
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
|
||||
(wifi_scan_obj.currentScanMode == WIFI_CONNECTED) ||
|
||||
(wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
|
||||
if (current_menu->selected > 0) {
|
||||
current_menu->selected--;
|
||||
@@ -1034,6 +1039,7 @@ void MenuFunctions::main(uint32_t currentTime)
|
||||
}
|
||||
if (menu_button == DOWN_BUTTON) {
|
||||
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
|
||||
(wifi_scan_obj.currentScanMode == WIFI_CONNECTED) ||
|
||||
(wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
|
||||
if (current_menu->selected < current_menu->list->size() - 1) {
|
||||
current_menu->selected++;
|
||||
@@ -1079,7 +1085,8 @@ void MenuFunctions::main(uint32_t currentTime)
|
||||
current_menu->list->get(current_menu->selected).callable();
|
||||
}
|
||||
else {
|
||||
if (wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF)
|
||||
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
|
||||
(wifi_scan_obj.currentScanMode == WIFI_CONNECTED))
|
||||
this->displayMenuButtons();
|
||||
}
|
||||
}
|
||||
@@ -1131,6 +1138,7 @@ void MenuFunctions::main(uint32_t currentTime)
|
||||
#if !defined(MARAUDER_M5STICKC) || defined(MARAUDER_M5STICKCP2)
|
||||
if (u_btn.justPressed()){
|
||||
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
|
||||
(wifi_scan_obj.currentScanMode == WIFI_CONNECTED) ||
|
||||
(wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
|
||||
if (current_menu->selected > 0) {
|
||||
current_menu->selected--;
|
||||
@@ -1170,6 +1178,7 @@ void MenuFunctions::main(uint32_t currentTime)
|
||||
#endif
|
||||
if (d_btn.justPressed()){
|
||||
if ((wifi_scan_obj.currentScanMode == WIFI_SCAN_OFF) ||
|
||||
(wifi_scan_obj.currentScanMode == WIFI_CONNECTED) ||
|
||||
(wifi_scan_obj.currentScanMode == OTA_UPDATE)) {
|
||||
if (current_menu->selected < current_menu->list->size() - 1) {
|
||||
current_menu->selected++;
|
||||
@@ -2225,8 +2234,20 @@ void MenuFunctions::RunSetup()
|
||||
for (int i = 0; i < access_points->size(); i++) {
|
||||
// This is the menu node
|
||||
this->addNodes(&wifiAPMenu, access_points->get(i).essid, TFTCYAN, NULL, 255, [this, i](){
|
||||
//this->changeMenu(&miniKbMenu);
|
||||
//this->miniKeyboard(&miniKbMenu);
|
||||
// Join WiFi using mini keyboard
|
||||
#ifdef HAS_MINI_KB
|
||||
this->changeMenu(&miniKbMenu);
|
||||
String password = this->miniKeyboard(&miniKbMenu, true);
|
||||
if (password != "") {
|
||||
Serial.println("Using SSID: " + (String)access_points->get(i).essid + " Password: " + (String)password);
|
||||
wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
|
||||
wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
|
||||
wifi_scan_obj.joinWiFi(access_points->get(i).essid, password);
|
||||
this->changeMenu(current_menu);
|
||||
}
|
||||
#endif
|
||||
|
||||
// Join WiFi using touch screen keyboard
|
||||
#ifdef HAS_TOUCH
|
||||
wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
|
||||
wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
|
||||
@@ -2853,10 +2874,12 @@ void MenuFunctions::RunSetup()
|
||||
}
|
||||
|
||||
//#if (!defined(HAS_ILI9341) && defined(HAS_BUTTONS))
|
||||
void MenuFunctions::miniKeyboard(Menu * targetMenu) {
|
||||
String MenuFunctions::miniKeyboard(Menu * targetMenu, bool do_pass) {
|
||||
// Prepare a char array and reset temp SSID string
|
||||
extern LinkedList<ssid>* ssids;
|
||||
|
||||
String ret_val = "";
|
||||
|
||||
bool pressed = true;
|
||||
|
||||
wifi_scan_obj.current_mini_kb_ssid = "";
|
||||
@@ -3002,16 +3025,19 @@ void MenuFunctions::RunSetup()
|
||||
// Exit
|
||||
if (c_btn.isHeld()) {
|
||||
this->changeMenu(targetMenu->parentMenu);
|
||||
return;
|
||||
return wifi_scan_obj.current_mini_kb_ssid;
|
||||
}
|
||||
delay(1);
|
||||
}
|
||||
|
||||
if (!do_pass) {
|
||||
// If we have a string, add it to list of SSIDs
|
||||
if (wifi_scan_obj.current_mini_kb_ssid != "") {
|
||||
pressed = true;
|
||||
ssid s = {wifi_scan_obj.current_mini_kb_ssid, random(1, 12), {random(256), random(256), random(256), random(256), random(256), random(256)}, false};
|
||||
ssids->unshift(s);
|
||||
wifi_scan_obj.current_mini_kb_ssid = "";
|
||||
if (wifi_scan_obj.current_mini_kb_ssid != "") {
|
||||
pressed = true;
|
||||
ssid s = {wifi_scan_obj.current_mini_kb_ssid, random(1, 12), {random(256), random(256), random(256), random(256), random(256), random(256)}, false};
|
||||
ssids->unshift(s);
|
||||
wifi_scan_obj.current_mini_kb_ssid = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -3180,8 +3206,13 @@ void MenuFunctions::RunSetup()
|
||||
#ifdef HAS_MINI_KB
|
||||
display_obj.tft.println("U/D - Rem/Add Char");
|
||||
display_obj.tft.println("L/R - Prev/Nxt Char");
|
||||
display_obj.tft.println("C - Save");
|
||||
display_obj.tft.println("C(Hold) - Exit");
|
||||
if (!do_pass) {
|
||||
display_obj.tft.println("C - Save");
|
||||
display_obj.tft.println("C(Hold) - Exit");
|
||||
}
|
||||
else {
|
||||
display_obj.tft.println("C(Hold) - Enter");
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAS_TOUCH
|
||||
|
||||
@@ -215,7 +215,7 @@ class MenuFunctions
|
||||
void buttonSelected(int b, int x = -1);
|
||||
void buttonNotSelected(int b, int x = -1);
|
||||
//#if (!defined(HAS_ILI9341) && defined(HAS_BUTTONS))
|
||||
void miniKeyboard(Menu * targetMenu);
|
||||
String miniKeyboard(Menu * targetMenu, bool do_pass = false);
|
||||
//#endif
|
||||
|
||||
public:
|
||||
|
||||
@@ -691,13 +691,13 @@ int WiFiScan::generateSSIDs(int count) {
|
||||
return num_gen;
|
||||
}
|
||||
|
||||
void WiFiScan::joinWiFi(String ssid, String password)
|
||||
bool WiFiScan::joinWiFi(String ssid, String password)
|
||||
{
|
||||
static const char * btns[] ={text16, ""};
|
||||
int count = 0;
|
||||
|
||||
if ((WiFi.status() == WL_CONNECTED) && (ssid == connected_network) && (ssid != "")) {
|
||||
#ifdef HAS_SCREEN
|
||||
#ifdef HAS_TOUCH
|
||||
lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
|
||||
lv_msgbox_set_text(mbox1, text_table4[2]);
|
||||
lv_msgbox_add_btns(mbox1, btns);
|
||||
@@ -705,29 +705,46 @@ void WiFiScan::joinWiFi(String ssid, String password)
|
||||
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); //Align to the corner
|
||||
#endif
|
||||
this->wifi_initialized = true;
|
||||
return;
|
||||
this->currentScanMode = WIFI_CONNECTED;
|
||||
return true;
|
||||
}
|
||||
else if (WiFi.status() == WL_CONNECTED) {
|
||||
Serial.println("Already connected. Disconnecting...");
|
||||
WiFi.disconnect();
|
||||
}
|
||||
|
||||
//esp_wifi_init(&cfg);
|
||||
//esp_wifi_set_storage(WIFI_STORAGE_RAM);
|
||||
//esp_wifi_set_mode(WIFI_MODE_NULL);
|
||||
//esp_wifi_start();
|
||||
|
||||
WiFi.begin(ssid.c_str(), password.c_str());
|
||||
|
||||
#ifdef HAS_SCREEN
|
||||
#ifdef HAS_MINI_KB
|
||||
display_obj.clearScreen();
|
||||
display_obj.tft.setCursor(0, TFT_HEIGHT / 2);
|
||||
display_obj.tft.setTextSize(1);
|
||||
display_obj.tft.print("Connecting");
|
||||
display_obj.tft.setTextWrap(true, false);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Serial.print("Connecting to WiFi");
|
||||
while (WiFi.status() != WL_CONNECTED) {
|
||||
delay(500);
|
||||
Serial.print(".");
|
||||
#ifdef HAS_SCREEN
|
||||
#ifdef HAS_MINI_KB
|
||||
display_obj.tft.print(".");
|
||||
#endif
|
||||
#endif
|
||||
count++;
|
||||
if (count == 20)
|
||||
{
|
||||
Serial.println("\nCould not connect to WiFi network");
|
||||
#ifdef HAS_SCREEN
|
||||
#ifdef HAS_MINI_KB
|
||||
display_obj.tft.println("\nFailed to connect");
|
||||
delay(1000);
|
||||
#endif
|
||||
#endif
|
||||
#ifdef HAS_TOUCH
|
||||
lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
|
||||
lv_msgbox_set_text(mbox1, text_table4[3]);
|
||||
lv_msgbox_add_btns(mbox1, btns);
|
||||
@@ -735,12 +752,14 @@ void WiFiScan::joinWiFi(String ssid, String password)
|
||||
//lv_obj_set_event_cb(mbox1, event_handler);
|
||||
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); //Align to the corner
|
||||
#endif
|
||||
WiFi.mode(WIFI_OFF);
|
||||
return;
|
||||
this->wifi_initialized = true;
|
||||
this->StartScan(WIFI_SCAN_OFF, TFT_BLACK);
|
||||
display_obj.tft.setTextWrap(false, false);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAS_SCREEN
|
||||
#ifdef HAS_TOUCH
|
||||
lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
|
||||
lv_msgbox_set_text(mbox1, text_table4[4]);
|
||||
lv_msgbox_add_btns(mbox1, btns);
|
||||
@@ -752,7 +771,18 @@ void WiFiScan::joinWiFi(String ssid, String password)
|
||||
Serial.println("\nConnected to the WiFi network");
|
||||
Serial.print("IP address: ");
|
||||
Serial.println(WiFi.localIP());
|
||||
#ifdef HAS_SCREEN
|
||||
#ifdef HAS_MINI_KB
|
||||
display_obj.tft.println("\nConnected!");
|
||||
display_obj.tft.println(WiFi.localIP());
|
||||
display_obj.tft.println("Returning...");
|
||||
delay(2000);
|
||||
#endif
|
||||
#endif
|
||||
this->wifi_initialized = true;
|
||||
this->currentScanMode = WIFI_CONNECTED;
|
||||
display_obj.tft.setTextWrap(false, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
// Apply WiFi settings
|
||||
@@ -1071,11 +1101,14 @@ void WiFiScan::StopScan(uint8_t scan_mode)
|
||||
(currentScanMode == WIFI_PACKET_MONITOR) ||
|
||||
(currentScanMode == WIFI_SCAN_CHAN_ANALYZER) ||
|
||||
(currentScanMode == WIFI_SCAN_PACKET_RATE) ||
|
||||
(currentScanMode == WIFI_CONNECTED) ||
|
||||
(currentScanMode == LV_JOIN_WIFI) ||
|
||||
(this->wifi_initialized))
|
||||
{
|
||||
this->shutdownWiFi();
|
||||
|
||||
this->connected_network = "";
|
||||
|
||||
#ifdef HAS_SCREEN
|
||||
for (int i = 0; i < TFT_WIDTH; i++) {
|
||||
this->_analyzer_values[i] = 0;
|
||||
@@ -1731,8 +1764,10 @@ void WiFiScan::RunAPScan(uint8_t scan_mode, uint16_t color)
|
||||
#ifdef HAS_SCREEN
|
||||
void WiFiScan::RunLvJoinWiFi(uint8_t scan_mode, uint16_t color) {
|
||||
|
||||
display_obj.tft.init();
|
||||
display_obj.tft.setRotation(1);
|
||||
#ifdef HAS_TOUCH
|
||||
display_obj.tft.init();
|
||||
display_obj.tft.setRotation(1);
|
||||
#endif
|
||||
|
||||
#ifndef HAS_CYD_TOUCH
|
||||
#ifdef TFT_SHIELD
|
||||
@@ -1749,9 +1784,10 @@ void WiFiScan::RunAPScan(uint8_t scan_mode, uint16_t color)
|
||||
//display_obj.touchscreen.setRotation(1);
|
||||
#endif
|
||||
|
||||
|
||||
lv_obj_t * scr = lv_cont_create(NULL, NULL);
|
||||
lv_disp_load_scr(scr);
|
||||
#ifdef HAS_TOUCH
|
||||
lv_obj_t * scr = lv_cont_create(NULL, NULL);
|
||||
lv_disp_load_scr(scr);
|
||||
#endif
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -104,6 +104,7 @@
|
||||
#define WIFI_SCAN_AP_STA 49
|
||||
#define WIFI_SCAN_PINESCAN 50
|
||||
#define WIFI_SCAN_MULTISSID 51
|
||||
#define WIFI_CONNECTED 52
|
||||
|
||||
#define BASE_MULTIPLIER 4
|
||||
|
||||
@@ -586,7 +587,7 @@ class WiFiScan
|
||||
bool shutdownWiFi();
|
||||
bool shutdownBLE();
|
||||
bool scanning();
|
||||
void joinWiFi(String ssid, String password);
|
||||
bool joinWiFi(String ssid, String password);
|
||||
String getStaMAC();
|
||||
String getApMAC();
|
||||
String freeRAM();
|
||||
|
||||
Reference in New Issue
Block a user