esp8266_deauther/esp8266_deauther/esp8266_deauther.ino

197 lines
4.6 KiB
Arduino
Raw Permalink Normal View History

2021-01-11 18:14:55 +01:00
/* =====================
This software is licensed under the MIT License:
https://github.com/spacehuhntech/esp8266_deauther
===================== */
2019-05-10 08:01:57 +02:00
extern "C" {
// Please follow this tutorial:
// https://github.com/spacehuhn/esp8266_deauther/wiki/Installation#compiling-using-arduino-ide
// And be sure to have the right board selected
#include "user_interface.h"
}
#include "EEPROMHelper.h"
2019-05-10 08:01:57 +02:00
2021-01-10 22:30:14 +01:00
#include "src/ArduinoJson-v5.13.5/ArduinoJson.h"
2019-05-10 08:01:57 +02:00
#if ARDUINOJSON_VERSION_MAJOR != 5
// The software was build using ArduinoJson v5.x
// version 6 is still in beta at the time of writing
// go to tools -> manage libraries, search for ArduinoJSON and install version 5
2019-05-10 08:01:57 +02:00
#error Please upgrade/downgrade ArduinoJSON library to version 5!
#endif // if ARDUINOJSON_VERSION_MAJOR != 5
#include "oui.h"
#include "language.h"
#include "functions.h"
2020-07-05 15:48:39 +02:00
#include "settings.h"
2019-05-10 08:01:57 +02:00
#include "Names.h"
#include "SSIDs.h"
#include "Scan.h"
#include "Attack.h"
#include "CLI.h"
#include "DisplayUI.h"
#include "A_config.h"
2020-07-15 20:02:09 +02:00
#include "led.h"
2019-05-10 08:01:57 +02:00
// Run-Time Variables //
2021-01-10 22:30:14 +01:00
Names names;
SSIDs ssids;
2019-05-10 08:01:57 +02:00
Accesspoints accesspoints;
Stations stations;
Scan scan;
Attack attack;
CLI cli;
DisplayUI displayUI;
simplebutton::Button* resetButton;
2019-05-10 08:01:57 +02:00
#include "wifi.h"
uint32_t autosaveTime = 0;
uint32_t currentTime = 0;
bool booted = false;
void setup() {
// for random generator
randomSeed(os_random());
// start serial
Serial.begin(115200);
Serial.println();
// start SPIFFS
prnt(SETUP_MOUNT_SPIFFS);
2021-01-10 22:30:14 +01:00
// bool spiffsError = !LittleFS.begin();
2020-07-05 16:34:27 +02:00
LittleFS.begin();
2021-01-10 22:30:14 +01:00
prntln(/*spiffsError ? SETUP_ERROR : */ SETUP_OK);
2019-05-10 08:01:57 +02:00
// Start EEPROM
EEPROMHelper::begin(EEPROM_SIZE);
2019-05-10 08:01:57 +02:00
#ifdef FORMAT_SPIFFS
prnt(SETUP_FORMAT_SPIFFS);
2020-07-05 15:49:44 +02:00
LittleFS.format();
prntln(SETUP_OK);
#endif // ifdef FORMAT_SPIFFS
#ifdef FORMAT_EEPROM
prnt(SETUP_FORMAT_EEPROM);
EEPROMHelper::format(EEPROM_SIZE);
prntln(SETUP_OK);
#endif // ifdef FORMAT_EEPROM
// Format SPIFFS when in boot-loop
2021-01-10 22:30:14 +01:00
if (/*spiffsError || */ !EEPROMHelper::checkBootNum(BOOT_COUNTER_ADDR)) {
2019-05-10 08:01:57 +02:00
prnt(SETUP_FORMAT_SPIFFS);
2020-07-05 15:49:44 +02:00
LittleFS.format();
2019-05-10 08:01:57 +02:00
prntln(SETUP_OK);
prnt(SETUP_FORMAT_EEPROM);
EEPROMHelper::format(EEPROM_SIZE);
prntln(SETUP_OK);
EEPROMHelper::resetBootNum(BOOT_COUNTER_ADDR);
2019-05-10 08:01:57 +02:00
}
// get time
currentTime = millis();
// load settings
#ifndef RESET_SETTINGS
2020-07-05 15:48:39 +02:00
settings::load();
#else // ifndef RESET_SETTINGS
2020-07-05 15:48:39 +02:00
settings::reset();
settings::save();
#endif // ifndef RESET_SETTINGS
2019-05-10 08:01:57 +02:00
2020-07-14 18:07:42 +02:00
wifi::begin();
2019-05-10 08:01:57 +02:00
wifi_set_promiscuous_rx_cb([](uint8_t* buf, uint16_t len) {
scan.sniffer(buf, len);
});
// start display
2020-07-05 15:48:39 +02:00
if (settings::getDisplaySettings().enabled) {
2019-05-10 08:01:57 +02:00
displayUI.setup();
displayUI.mode = DISPLAY_MODE::INTRO;
2019-05-10 08:01:57 +02:00
}
// load everything else
names.load();
ssids.load();
cli.load();
// create scan.json
scan.setup();
// dis/enable serial command interface
2020-07-05 15:48:39 +02:00
if (settings::getCLISettings().enabled) {
2019-05-10 08:01:57 +02:00
cli.enable();
} else {
prntln(SETUP_SERIAL_WARNING);
Serial.flush();
Serial.end();
}
// start access point/web interface
2020-07-14 18:07:42 +02:00
if (settings::getWebSettings().enabled) wifi::startAP();
2019-05-10 08:01:57 +02:00
// STARTED
prntln(SETUP_STARTED);
// version
prntln(DEAUTHER_VERSION);
2019-05-10 08:01:57 +02:00
// setup LED
2020-07-15 20:02:09 +02:00
led::setup();
// setup reset button
resetButton = new ButtonPullup(RESET_BUTTON);
2019-05-10 08:01:57 +02:00
}
void loop() {
currentTime = millis();
2021-01-10 22:30:14 +01:00
led::update(); // update LED color
wifi::update(); // manage access point
2019-05-10 08:01:57 +02:00
attack.update(); // run attacks
displayUI.update();
cli.update(); // read and run serial input
scan.update(); // run scan
ssids.update(); // run random mode, if enabled
// auto-save
2020-07-05 15:48:39 +02:00
if (settings::getAutosaveSettings().enabled
&& (currentTime - autosaveTime > settings::getAutosaveSettings().time)) {
2019-05-10 08:01:57 +02:00
autosaveTime = currentTime;
names.save(false);
ssids.save(false);
2020-07-05 15:48:39 +02:00
settings::save(false);
2019-05-10 08:01:57 +02:00
}
if (!booted) {
booted = true;
EEPROMHelper::resetBootNum(BOOT_COUNTER_ADDR);
2019-05-10 08:01:57 +02:00
#ifdef HIGHLIGHT_LED
displayUI.setupLED();
#endif // ifdef HIGHLIGHT_LED
}
resetButton->update();
if (resetButton->holding(5000)) {
led::setMode(LED_MODE::SCAN);
2021-01-11 11:58:20 +01:00
DISPLAY_MODE _mode = displayUI.mode;
displayUI.mode = DISPLAY_MODE::RESETTING;
displayUI.update(true);
settings::reset();
settings::save(true);
2021-01-11 11:58:20 +01:00
delay(2000);
led::setMode(LED_MODE::IDLE);
2021-01-11 11:58:20 +01:00
displayUI.mode = _mode;
}
}