Add Join WiFi

This commit is contained in:
Just Call Me Koko
2020-08-27 23:22:35 -04:00
parent d32388eb2f
commit a1dd40a928
6 changed files with 285 additions and 19 deletions

View File

@@ -7,9 +7,9 @@ Big thanks to bodmer for having great TFT and JPEG libraries
https://github.com/bodmer
*/
PROGMEM lv_obj_t * slider_label;
PROGMEM lv_obj_t * ta1;
PROGMEM lv_obj_t * ta2;
//PROGMEM lv_obj_t * slider_label;
//PROGMEM lv_obj_t * ta1;
//PROGMEM lv_obj_t * ta2;
Display::Display()
{
@@ -56,7 +56,7 @@ void Display::RunSetup()
while (1) yield(); // Stay here twiddling thumbs waiting
}
this->initLVGL();
//this->initLVGL();
// Draw the title screen
@@ -71,13 +71,14 @@ void Display::RunSetup()
}
/* Interrupt driven periodic handler */
/*
void Display::lv_tick_handler()
{
lv_tick_inc(LVGL_TICK_PERIOD);
}
}*/
/* Display flushing */
/*
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
extern Display display_obj;
@@ -137,7 +138,7 @@ bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
}
return false;
}
}*/
void Display::tftDrawGraphObjects(byte x_scale)
{
@@ -818,7 +819,7 @@ void Display::buildBanner(String msg, int xpos)
img.print(msg);
}
/*
void Display::initLVGL() {
tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
@@ -922,7 +923,7 @@ void ta_event_cb(lv_obj_t * ta, lv_event_t event)
// printf("Ready\n");
// }
//}
}
}*/
void Display::main(uint8_t scan_mode)
{

View File

@@ -58,6 +58,7 @@
#define STATUSBAR_COLOR 0x4A49
/*
PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data);
@@ -69,6 +70,7 @@ PROGMEM static void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
// lvgl stuff
PROGMEM static lv_obj_t *kb;
*/
class Display
{
@@ -86,11 +88,11 @@ class Display
//void addNodes(Menu* menu, String name, Menu* child, std::function<void()> callable);
//void changeMenu(Menu* menu);
//void showMenuList(Menu* menu, int layer);
static void lv_tick_handler();
//static void lv_tick_handler();
public:
Display();
Ticker tick;
//Ticker tick;
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite img = TFT_eSprite(&tft);
TFT_eSPI_Button key[BUTTON_ARRAY_LEN];
@@ -130,9 +132,9 @@ class Display
// We can speed up scrolling of short text lines by just blanking the character we drew
int blank[19]; // We keep all the strings pixel lengths to optimise the speed of the top line blanking
void initLVGL();
void deinitLVGL();
void joinWiFiGFX();
//void initLVGL();
//void deinitLVGL();
//void joinWiFiGFX();
void tftDrawGraphObjects(byte x_scale);
void tftDrawEapolColorKey();
void tftDrawColorKey();

View File

@@ -2,11 +2,192 @@
//#include "icons.h"
extern const unsigned char menu_icons[][66];
PROGMEM lv_obj_t * slider_label;
PROGMEM lv_obj_t * ta1;
PROGMEM lv_obj_t * ta2;
MenuFunctions::MenuFunctions()
{
}
// LVGL Stuff
/* Interrupt driven periodic handler */
void MenuFunctions::lv_tick_handler()
{
lv_tick_inc(LVGL_TICK_PERIOD);
}
/* Display flushing */
void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p)
{
extern Display display_obj;
uint16_t c;
display_obj.tft.startWrite();
display_obj.tft.setAddrWindow(area->x1, area->y1, (area->x2 - area->x1 + 1), (area->y2 - area->y1 + 1));
for (int y = area->y1; y <= area->y2; y++) {
for (int x = area->x1; x <= area->x2; x++) {
c = color_p->full;
display_obj.tft.writeColor(c, 1);
color_p++;
}
}
display_obj.tft.endWrite();
lv_disp_flush_ready(disp);
}
bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data)
{
extern Display display_obj;
uint16_t touchX, touchY;
bool touched = display_obj.tft.getTouch(&touchX, &touchY, 600);
if(!touched)
{
return false;
}
if(touchX>WIDTH_1 || touchY > HEIGHT_1)
{
Serial.println("Y or y outside of expected parameters..");
Serial.print("y:");
Serial.print(touchX);
Serial.print(" x:");
Serial.print(touchY);
}
else
{
data->state = touched ? LV_INDEV_STATE_PR : LV_INDEV_STATE_REL;
//if(data->state == LV_INDEV_STATE_PR) touchpad_get_xy(&last_x, &last_y);
data->point.x = touchX;
data->point.y = touchY;
Serial.print("Data x");
Serial.println(touchX);
Serial.print("Data y");
Serial.println(touchY);
}
return false;
}
void MenuFunctions::initLVGL() {
tick.attach_ms(LVGL_TICK_PERIOD, lv_tick_handler);
lv_init();
lv_disp_buf_init(&disp_buf, buf, NULL, LV_HOR_RES_MAX * 10);
lv_disp_drv_t disp_drv;
lv_disp_drv_init(&disp_drv);
disp_drv.hor_res = WIDTH_1;
disp_drv.ver_res = HEIGHT_1;
disp_drv.flush_cb = my_disp_flush;
disp_drv.buffer = &disp_buf;
lv_disp_drv_register(&disp_drv);
lv_indev_drv_t indev_drv;
lv_indev_drv_init(&indev_drv);
indev_drv.type = LV_INDEV_TYPE_POINTER;
indev_drv.read_cb = my_touchpad_read;
lv_indev_drv_register(&indev_drv);
}
void MenuFunctions::deinitLVGL() {
Serial.println(F("Deinit LVGL"));
//lv_deinit();
}
void MenuFunctions::joinWiFiGFX(){
// Create one text area
ta1 = lv_textarea_create(lv_scr_act(), NULL);
lv_textarea_set_one_line(ta1, true);
lv_obj_set_width(ta1, LV_HOR_RES / 2 - 20);
lv_obj_set_pos(ta1, 5, 20);
//lv_ta_set_cursor_type(ta, LV_CURSOR_BLOCK);
lv_textarea_set_text(ta1, "");
lv_obj_set_event_cb(ta1, ta_event_cb);
// Create first label
lv_obj_t * ssid_label = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(ssid_label, "SSID:");
lv_obj_align(ssid_label, ta1, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
// Create second text area
ta2 = lv_textarea_create(lv_scr_act(), ta1);
//lv_textarea_set_pwd_mode(ta2, true); // This shit makes it so backspace does not work
//lv_textarea_set_pwd_show_time(ta2, 1000);
lv_textarea_set_cursor_hidden(ta2, true);
lv_obj_align(ta2, NULL, LV_ALIGN_IN_TOP_RIGHT, -5, 20);
// Create second label
lv_obj_t * pw_label = lv_label_create(lv_scr_act(), NULL);
lv_label_set_text(pw_label, "Password:");
lv_obj_align(pw_label, ta2, LV_ALIGN_OUT_TOP_LEFT, 0, 0);
// Create a keyboard and apply the styles
kb = lv_keyboard_create(lv_scr_act(), NULL);
lv_obj_set_size(kb, LV_HOR_RES, LV_VER_RES / 2);
lv_obj_set_event_cb(kb, keyboard_event_cb);
// Focus it on one of the text areas to start
lv_keyboard_set_textarea(kb, ta1);
lv_keyboard_set_cursor_manage(kb, true);
}
void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event){
extern Display display_obj;
extern MenuFunctions menu_function_obj;
extern WiFiScan wifi_scan_obj;
lv_keyboard_def_event_cb(kb, event);
if(event == LV_EVENT_APPLY){
printf("LV_EVENT_APPLY\n");
//String ta1_text = lv_textarea_get_text(lv_keyboard_get_textarea(kb));
String ta1_text = lv_textarea_get_text(ta1);
String ta2_text = lv_textarea_get_text(ta2);
Serial.println(ta1_text);
Serial.println(ta2_text);
wifi_scan_obj.joinWiFi(ta1_text, ta2_text);
}else if(event == LV_EVENT_CANCEL){
printf("LV_EVENT_CANCEL\n");
//lv_textarea_set_text(lv_keyboard_get_textarea(kb), "");
menu_function_obj.deinitLVGL();
wifi_scan_obj.StartScan(WIFI_SCAN_OFF);
display_obj.exit_draw = true; // set everything back to normal
}
}
void ta_event_cb(lv_obj_t * ta, lv_event_t event)
{
if(event == LV_EVENT_CLICKED) {
if(kb != NULL)
lv_keyboard_set_textarea(kb, ta);
}
//else if(event == LV_EVENT_INSERT) {
// const char * str = lv_event_get_data();
// if(str[0] == '\n') {
// printf("Ready\n");
// }
//}
}
// Function to check menu input
void MenuFunctions::main(uint32_t currentTime)
{
@@ -414,6 +595,8 @@ void MenuFunctions::orientDisplay()
// Function to build the menus
void MenuFunctions::RunSetup()
{
this->initLVGL();
// root menu stuff
mainMenu.list = new LinkedList<MenuNode>(); // Get list in first menu ready
@@ -547,6 +730,13 @@ void MenuFunctions::RunSetup()
this->drawStatusBar();
wifi_scan_obj.StartScan(WIFI_ATTACK_RICK_ROLL, TFT_YELLOW);
});
addNodes(&wifiAttackMenu, "Join WiFi", TFT_DARKCYAN, NULL, SNIFFERS, [this](){
display_obj.clearScreen();
wifi_scan_obj.currentScanMode = LV_JOIN_WIFI;
wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);
joinWiFiGFX();
});
// Build Bluetooth Menu
bluetoothMenu.parentMenu = &mainMenu; // Second Menu is third menu parent
@@ -609,7 +799,6 @@ void MenuFunctions::RunSetup()
changeMenu(&infoMenu);
wifi_scan_obj.RunInfo();
});
addNodes(&deviceMenu, "Join WiFi", TFT_YELLOW, NULL, SNIFFERS, [this](){display_obj.clearScreen(); wifi_scan_obj.currentScanMode = LV_JOIN_WIFI; wifi_scan_obj.StartScan(LV_JOIN_WIFI, TFT_YELLOW);});
// Select update
whichUpdateMenu.parentMenu = &deviceMenu;

View File

@@ -65,6 +65,18 @@ extern BatteryInterface battery_obj;
#define PWNAGOTCHI 24
#define ESPRESSIF 25
PROGMEM void my_disp_flush(lv_disp_drv_t *disp, const lv_area_t *area, lv_color_t *color_p);
PROGMEM bool my_touchpad_read(lv_indev_drv_t * indev_driver, lv_indev_data_t * data);
PROGMEM static lv_disp_buf_t disp_buf;
PROGMEM static lv_color_t buf[LV_HOR_RES_MAX * 10];
PROGMEM static void ta_event_cb(lv_obj_t * ta, lv_event_t event);
PROGMEM static void keyboard_event_cb(lv_obj_t * keyboard, lv_event_t event);
// lvgl stuff
PROGMEM static lv_obj_t *kb;
struct Menu;
// Individual Nodes of a menu
@@ -120,6 +132,8 @@ class MenuFunctions
Menu bluetoothSnifferMenu;
Menu bluetoothScannerMenu;
static void lv_tick_handler();
// Menu icons
@@ -136,9 +150,15 @@ class MenuFunctions
public:
MenuFunctions();
Ticker tick;
uint16_t x = -1, y = -1;
boolean pressed = false;
void initLVGL();
void deinitLVGL();
void joinWiFiGFX();
void buildButtons(Menu* menu);
void changeMenu(Menu* menu);
void displayCurrentMenu();

View File

@@ -135,6 +135,57 @@ void WiFiScan::RunSetup() {
this->shutdownBLE();
}
void WiFiScan::joinWiFi(String ssid, String password)
{
static const char * btns[] ={"Close", ""};
int count = 0;
if ((WiFi.status() == WL_CONNECTED) && (ssid == connected_network) && (ssid != "")) {
lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
lv_msgbox_set_text(mbox1, "Already Connected");
lv_msgbox_add_btns(mbox1, btns);
lv_obj_set_width(mbox1, 200);
//lv_obj_set_event_cb(mbox1, event_handler);
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
return;
}
else if (WiFi.status() == WL_CONNECTED)
WiFi.disconnect();
WiFi.begin(ssid.c_str(), password.c_str());
Serial.print("Connecting to WiFi");
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
count++;
if (count == 10)
{
Serial.println("\nCould not connect to WiFi network");
lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
lv_msgbox_set_text(mbox1, "Failed to connect");
lv_msgbox_add_btns(mbox1, btns);
lv_obj_set_width(mbox1, 200);
//lv_obj_set_event_cb(mbox1, event_handler);
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
return;
}
}
lv_obj_t * mbox1 = lv_msgbox_create(lv_scr_act(), NULL);
lv_msgbox_set_text(mbox1, "Connected");
lv_msgbox_add_btns(mbox1, btns);
lv_obj_set_width(mbox1, 200);
//lv_obj_set_event_cb(mbox1, event_handler);
lv_obj_align(mbox1, NULL, LV_ALIGN_CENTER, 0, 0); /*Align to the corner*/
connected_network = ssid;
Serial.println("\nConnected to the WiFi network");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
}
// Function to prepare to run a specific scan
void WiFiScan::StartScan(uint8_t scan_mode, uint16_t color)
{
@@ -211,7 +262,8 @@ void WiFiScan::StopScan(uint8_t scan_mode)
(currentScanMode == WIFI_SCAN_DEAUTH) ||
(currentScanMode == WIFI_ATTACK_BEACON_SPAM) ||
(currentScanMode == WIFI_ATTACK_RICK_ROLL) ||
(currentScanMode == WIFI_PACKET_MONITOR))
(currentScanMode == WIFI_PACKET_MONITOR) ||
(currentScanMode == LV_JOIN_WIFI))
{
this->shutdownWiFi();
}
@@ -322,7 +374,7 @@ void WiFiScan::RunLvJoinWiFi(uint8_t scan_mode, uint16_t color) {
lv_obj_t * scr = lv_cont_create(NULL, NULL);
lv_disp_load_scr(scr);
display_obj.joinWiFiGFX();
//display_obj.joinWiFiGFX();
}
void WiFiScan::RunInfo()

View File

@@ -82,7 +82,7 @@ class WiFiScan
const wifi_promiscuous_filter_t filt = {.filter_mask=WIFI_PROMIS_FILTER_MASK_MGMT | WIFI_PROMIS_FILTER_MASK_DATA};
BLEScan* pBLEScan;
String connected_network = "";
//String connected_network = "";
String alfa = "1234567890qwertyuiopasdfghjkklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM_";
char* rick_roll[8] = {
@@ -162,6 +162,7 @@ class WiFiScan
String free_ram = "";
String old_free_ram = "";
String connected_network = "";
//lv_obj_t * scr = lv_cont_create(NULL, NULL);
@@ -170,6 +171,7 @@ class WiFiScan
void RunSetup();
void shutdownWiFi();
void shutdownBLE();
void joinWiFi(String ssid, String password);
String getStaMAC();
String getApMAC();
String freeRAM();