From 5ed9cc9d9cc74404ce02f8c2a0a7dbbef528b83c Mon Sep 17 00:00:00 2001 From: Stefan Kremser Date: Wed, 10 Oct 2018 18:08:27 +0200 Subject: [PATCH] Renamed LEDController to LED --- .../{LEDController.cpp => LED.cpp} | 422 +++++++++--------- esp8266_deauther/{LEDController.h => LED.h} | 210 ++++----- esp8266_deauther/SerialInterface.h | 168 +++---- esp8266_deauther/esp8266_deauther.ino | 332 +++++++------- 4 files changed, 566 insertions(+), 566 deletions(-) rename esp8266_deauther/{LEDController.cpp => LED.cpp} (59%) rename esp8266_deauther/{LEDController.h => LED.h} (93%) diff --git a/esp8266_deauther/LEDController.cpp b/esp8266_deauther/LED.cpp similarity index 59% rename from esp8266_deauther/LEDController.cpp rename to esp8266_deauther/LED.cpp index b9e8537..d6a7462 100644 --- a/esp8266_deauther/LEDController.cpp +++ b/esp8266_deauther/LED.cpp @@ -1,211 +1,211 @@ -#include "LEDController.h" - -LEDController::LEDController() {} - -LEDController::~LEDController() { - if (led) delete led; -} - -void LEDController::setup() { - #ifdef DIGITAL_LED - led = new DigitalLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_ANODE); - led->setup(); - return; - - #endif // ifdef DIGITAL_LED - - #ifdef RGB_LED - led = new LEDController::AnalogRGBLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_MODE_BRIGHTNESS, LED_ANODE); - led->setup(); - return; - - #endif // ifdef RGB_LED - - #ifdef NEOPIXEL_LED - led = new LEDController::NeopixelLED(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, LED_MODE_BRIGHTNESS); - led->setup(); - return; - - #endif // ifdef NEOPIXEL_LED - - prntln(L_NOT_CONFIGURED); -} - -void LEDController::update() { - if (!tempEnabled || !led) return; - - if (!settings.getLedEnabled() && tempEnabled) tempDisable(); - - if (scan.isScanning() && (scan.deauths < settings.getMinDeauths())) setMode(LED_MODE::SCAN, false); - else if (scan.deauths >= settings.getMinDeauths()) setMode(LED_MODE::DEAUTH, false); - else if (attack.isRunning()) setMode(LED_MODE::ATTACK, false); - else setMode(LED_MODE::IDLE, false); -} - -void LEDController::setMode(uint8_t mode, bool force) { - if (!led) return; - - if ((mode != LEDController::mode) || force) { - LEDController::mode = mode; - - switch (mode) { - case LED_MODE::OFF: - led->setColor(0, 0, 0); - break; - - case LED_MODE::SCAN: - led->setColor(0, 0, 255); - break; - - case LED_MODE::ATTACK: - led->setColor(255, 255, 0); - break; - - case LED_MODE::DEAUTH: - led->setColor(255, 0, 0); - break; - - case LED_MODE::IDLE: - led->setColor(0, 255, 0); - break; - } - } -} - -void LEDController::setColor(uint8_t r, uint8_t g, uint8_t b, bool output) { - // debug output - if (output) { - char s[30]; - sprintf_P(s, L_OUTPUT, r, g, b); - prnt(String(s)); - } - - led->setColor(r, g, b); -} - -void LEDController::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output) { - led->setBrightness(brightness); - setColor(r, g, b, output); -} - -void LEDController::tempEnable() { - tempEnabled = true; - prntln(L_ENABLED); -} - -void LEDController::tempDisable() { - tempEnabled = false; - prntln(L_DISABLED); -} - -bool LEDController::getTempEnabled() { - return tempEnabled; -} - -// ===== DigitalLED ===== // -LEDController::DigitalLED::DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode) { - LEDController::DigitalLED::anode = anode; - LEDController::DigitalLED::rPin = rPin; - LEDController::DigitalLED::gPin = gPin; - LEDController::DigitalLED::bPin = bPin; -} - -LEDController::DigitalLED::~DigitalLED() {} - -void LEDController::DigitalLED::setup() { - if (rPin < 255) pinMode(rPin, OUTPUT); - - if (gPin < 255) pinMode(gPin, OUTPUT); - - if (bPin < 255) pinMode(bPin, OUTPUT); -} - -void LEDController::DigitalLED::setColor(uint8_t r, uint8_t g, uint8_t b) { - if (anode) { - if (rPin < 255) digitalWrite(rPin, r > 0); - - if (gPin < 255) digitalWrite(gPin, g > 0); - - if (bPin < 255) digitalWrite(bPin, b > 0); - } else { - if (rPin < 255) digitalWrite(rPin, r == 0); - - if (gPin < 255) digitalWrite(gPin, g == 0); - - if (bPin < 255) digitalWrite(bPin, b == 0); - } -} - -void LEDController::DigitalLED::setBrightness(uint8_t brightness) {} - - -// ===== AnalogRGBLED ===== // -LEDController::AnalogRGBLED::AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode) { - LEDController::AnalogRGBLED::anode = anode; - LEDController::AnalogRGBLED::rPin = rPin; - LEDController::AnalogRGBLED::gPin = gPin; - LEDController::AnalogRGBLED::bPin = bPin; - setBrightness(brightness); -} - -LEDController::AnalogRGBLED::~AnalogRGBLED() {} - -void LEDController::AnalogRGBLED::setup() { - analogWriteRange(0xff); - - if (rPin < 255) pinMode(rPin, OUTPUT); - - if (gPin < 255) pinMode(gPin, OUTPUT); - - if (bPin < 255) pinMode(bPin, OUTPUT); -} - -void LEDController::AnalogRGBLED::setColor(uint8_t r, uint8_t g, uint8_t b) { - if ((r > 0) && (brightness < 100)) r = r * brightness / 100; - - if ((g > 0) && (brightness < 100)) g = g * brightness / 100; - - if ((b > 0) && (brightness < 100)) b = b * brightness / 100; - - if (anode) { - r = 255 - r; - g = 255 - g; - b = 255 - b; - } - - analogWrite(rPin, r); - analogWrite(gPin, g); - analogWrite(bPin, b); -} - -void LEDController::AnalogRGBLED::setBrightness(uint8_t brightness) { - if (brightness > 100) brightness = 100; - LEDController::AnalogRGBLED::brightness = brightness; -} - -// ===== NeopixelLED ===== // -LEDController::NeopixelLED::NeopixelLED(int num, uint8_t dataPin, uint8_t brightness) { - strip = new Adafruit_NeoPixel(num, dataPin, LED_NEOPIXEL_MODE); - setBrightness(brightness); -} - -LEDController::NeopixelLED::~NeopixelLED() { - delete strip; -} - -void LEDController::NeopixelLED::setup() { - strip->begin(); - strip->show(); -} - -void LEDController::NeopixelLED::setColor(uint8_t r, uint8_t g, uint8_t b) { - int num = strip->numPixels(); - - for (uint16_t i = 0; i < num; i++) strip->setPixelColor(i, strip->Color(r, g, b)); - strip->show(); -} - -void LEDController::NeopixelLED::setBrightness(uint8_t brightness) { - if (brightness > 100) brightness = 100; - strip->setBrightness(brightness); -} \ No newline at end of file +#include "LED.h" + +LED::LED() {} + +LED::~LED() { + if (led) delete led; +} + +void LED::setup() { + #ifdef DIGITAL_LED + led = new DigitalLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_ANODE); + led->setup(); + return; + + #endif // ifdef DIGITAL_LED + + #ifdef RGB_LED + led = new LED::AnalogRGBLED(LED_PIN_R, LED_PIN_G, LED_PIN_B, LED_MODE_BRIGHTNESS, LED_ANODE); + led->setup(); + return; + + #endif // ifdef RGB_LED + + #ifdef NEOPIXEL_LED + led = new LED::NeopixelLED(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, LED_MODE_BRIGHTNESS); + led->setup(); + return; + + #endif // ifdef NEOPIXEL_LED + + prntln(L_NOT_CONFIGURED); +} + +void LED::update() { + if (!tempEnabled || !led) return; + + if (!settings.getLedEnabled() && tempEnabled) tempDisable(); + + if (scan.isScanning() && (scan.deauths < settings.getMinDeauths())) setMode(LED_MODE::SCAN, false); + else if (scan.deauths >= settings.getMinDeauths()) setMode(LED_MODE::DEAUTH, false); + else if (attack.isRunning()) setMode(LED_MODE::ATTACK, false); + else setMode(LED_MODE::IDLE, false); +} + +void LED::setMode(uint8_t mode, bool force) { + if (!led) return; + + if ((mode != LED::mode) || force) { + LED::mode = mode; + + switch (mode) { + case LED_MODE::OFF: + led->setColor(0, 0, 0); + break; + + case LED_MODE::SCAN: + led->setColor(0, 0, 255); + break; + + case LED_MODE::ATTACK: + led->setColor(255, 255, 0); + break; + + case LED_MODE::DEAUTH: + led->setColor(255, 0, 0); + break; + + case LED_MODE::IDLE: + led->setColor(0, 255, 0); + break; + } + } +} + +void LED::setColor(uint8_t r, uint8_t g, uint8_t b, bool output) { + // debug output + if (output) { + char s[30]; + sprintf_P(s, L_OUTPUT, r, g, b); + prnt(String(s)); + } + + led->setColor(r, g, b); +} + +void LED::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output) { + led->setBrightness(brightness); + setColor(r, g, b, output); +} + +void LED::tempEnable() { + tempEnabled = true; + prntln(L_ENABLED); +} + +void LED::tempDisable() { + tempEnabled = false; + prntln(L_DISABLED); +} + +bool LED::getTempEnabled() { + return tempEnabled; +} + +// ===== DigitalLED ===== // +LED::DigitalLED::DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode) { + LED::DigitalLED::anode = anode; + LED::DigitalLED::rPin = rPin; + LED::DigitalLED::gPin = gPin; + LED::DigitalLED::bPin = bPin; +} + +LED::DigitalLED::~DigitalLED() {} + +void LED::DigitalLED::setup() { + if (rPin < 255) pinMode(rPin, OUTPUT); + + if (gPin < 255) pinMode(gPin, OUTPUT); + + if (bPin < 255) pinMode(bPin, OUTPUT); +} + +void LED::DigitalLED::setColor(uint8_t r, uint8_t g, uint8_t b) { + if (anode) { + if (rPin < 255) digitalWrite(rPin, r > 0); + + if (gPin < 255) digitalWrite(gPin, g > 0); + + if (bPin < 255) digitalWrite(bPin, b > 0); + } else { + if (rPin < 255) digitalWrite(rPin, r == 0); + + if (gPin < 255) digitalWrite(gPin, g == 0); + + if (bPin < 255) digitalWrite(bPin, b == 0); + } +} + +void LED::DigitalLED::setBrightness(uint8_t brightness) {} + + +// ===== AnalogRGBLED ===== // +LED::AnalogRGBLED::AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode) { + LED::AnalogRGBLED::anode = anode; + LED::AnalogRGBLED::rPin = rPin; + LED::AnalogRGBLED::gPin = gPin; + LED::AnalogRGBLED::bPin = bPin; + setBrightness(brightness); +} + +LED::AnalogRGBLED::~AnalogRGBLED() {} + +void LED::AnalogRGBLED::setup() { + analogWriteRange(0xff); + + if (rPin < 255) pinMode(rPin, OUTPUT); + + if (gPin < 255) pinMode(gPin, OUTPUT); + + if (bPin < 255) pinMode(bPin, OUTPUT); +} + +void LED::AnalogRGBLED::setColor(uint8_t r, uint8_t g, uint8_t b) { + if ((r > 0) && (brightness < 100)) r = r * brightness / 100; + + if ((g > 0) && (brightness < 100)) g = g * brightness / 100; + + if ((b > 0) && (brightness < 100)) b = b * brightness / 100; + + if (anode) { + r = 255 - r; + g = 255 - g; + b = 255 - b; + } + + analogWrite(rPin, r); + analogWrite(gPin, g); + analogWrite(bPin, b); +} + +void LED::AnalogRGBLED::setBrightness(uint8_t brightness) { + if (brightness > 100) brightness = 100; + LED::AnalogRGBLED::brightness = brightness; +} + +// ===== NeopixelLED ===== // +LED::NeopixelLED::NeopixelLED(int num, uint8_t dataPin, uint8_t brightness) { + strip = new Adafruit_NeoPixel(num, dataPin, LED_NEOPIXEL_MODE); + setBrightness(brightness); +} + +LED::NeopixelLED::~NeopixelLED() { + delete strip; +} + +void LED::NeopixelLED::setup() { + strip->begin(); + strip->show(); +} + +void LED::NeopixelLED::setColor(uint8_t r, uint8_t g, uint8_t b) { + int num = strip->numPixels(); + + for (uint16_t i = 0; i < num; i++) strip->setPixelColor(i, strip->Color(r, g, b)); + strip->show(); +} + +void LED::NeopixelLED::setBrightness(uint8_t brightness) { + if (brightness > 100) brightness = 100; + strip->setBrightness(brightness); +} diff --git a/esp8266_deauther/LEDController.h b/esp8266_deauther/LED.h similarity index 93% rename from esp8266_deauther/LEDController.h rename to esp8266_deauther/LED.h index 79d6add..d9ee0ad 100644 --- a/esp8266_deauther/LEDController.h +++ b/esp8266_deauther/LED.h @@ -1,105 +1,105 @@ -#ifndef LEDController_h -#define LEDController_h - -#include "Arduino.h" -extern "C" { - #include "user_interface.h" -} -#include "language.h" -#include "A_config.h" -#include "Settings.h" -#include "Attack.h" -#include "Scan.h" - -#include - -extern Settings settings; -extern Attack attack; -extern Scan scan; -extern Stations stations; - -class LEDController { - public: - enum LED_MODE { OFF = 0, SCAN = 1, ATTACK = 2, DEAUTH = 3, IDLE = 4 }; - - LEDController(); - ~LEDController(); - - void setup(); - void update(); - - void setMode(uint8_t mode, bool force); - - void setColor(uint8_t r, uint8_t g, uint8_t b, bool output); - void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output); - - void tempEnable(); - void tempDisable(); - bool getTempEnabled(); - - private: - class StatusLED { - public: - virtual ~StatusLED() = default; - - virtual void setup() = 0; - - virtual void setColor(uint8_t r, uint8_t g, uint8_t b) = 0; - virtual void setBrightness(uint8_t brightness) = 0; - }; - - class DigitalLED : public StatusLED { - public: - DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode); - ~DigitalLED(); - - void setup(); - void setColor(uint8_t r, uint8_t g, uint8_t b); - void setBrightness(uint8_t brightness); - void setMode(uint8_t mode, bool force); - - private: - bool anode = true; - uint8_t rPin = 255; - uint8_t gPin = 255; - uint8_t bPin = 255; - }; - - class AnalogRGBLED : public StatusLED { - public: - AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode); - ~AnalogRGBLED(); - - void setup(); - void setColor(uint8_t r, uint8_t g, uint8_t b); - void setBrightness(uint8_t brightness); - void setMode(uint8_t mode, bool force); - - private: - bool anode = true; - uint8_t rPin = 255; - uint8_t gPin = 255; - uint8_t bPin = 255; - uint8_t brightness = 0; - }; - - class NeopixelLED : public StatusLED { - public: - NeopixelLED(int num, uint8_t dataPin, uint8_t brightness); - ~NeopixelLED(); - - void setup(); - void setColor(uint8_t r, uint8_t g, uint8_t b); - void setBrightness(uint8_t brightness); - void setMode(uint8_t mode, bool force); - - private: - Adafruit_NeoPixel* strip; - }; - - bool tempEnabled = true; - uint8_t mode = LED_MODE::OFF; - StatusLED* led = NULL; -}; - -#endif // ifndef LEDController_h \ No newline at end of file +#ifndef LED_h +#define LED_h + +#include "Arduino.h" +extern "C" { + #include "user_interface.h" +} +#include "language.h" +#include "A_config.h" +#include "Settings.h" +#include "Attack.h" +#include "Scan.h" + +#include + +extern Settings settings; +extern Attack attack; +extern Scan scan; +extern Stations stations; + +class LED { + public: + enum LED_MODE { OFF = 0, SCAN = 1, ATTACK = 2, DEAUTH = 3, IDLE = 4 }; + + LED(); + ~LED(); + + void setup(); + void update(); + + void setMode(uint8_t mode, bool force); + + void setColor(uint8_t r, uint8_t g, uint8_t b, bool output); + void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output); + + void tempEnable(); + void tempDisable(); + bool getTempEnabled(); + + private: + class StatusLED { + public: + virtual ~StatusLED() = default; + + virtual void setup() = 0; + + virtual void setColor(uint8_t r, uint8_t g, uint8_t b) = 0; + virtual void setBrightness(uint8_t brightness) = 0; + }; + + class DigitalLED : public StatusLED { + public: + DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode); + ~DigitalLED(); + + void setup(); + void setColor(uint8_t r, uint8_t g, uint8_t b); + void setBrightness(uint8_t brightness); + void setMode(uint8_t mode, bool force); + + private: + bool anode = true; + uint8_t rPin = 255; + uint8_t gPin = 255; + uint8_t bPin = 255; + }; + + class AnalogRGBLED : public StatusLED { + public: + AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode); + ~AnalogRGBLED(); + + void setup(); + void setColor(uint8_t r, uint8_t g, uint8_t b); + void setBrightness(uint8_t brightness); + void setMode(uint8_t mode, bool force); + + private: + bool anode = true; + uint8_t rPin = 255; + uint8_t gPin = 255; + uint8_t bPin = 255; + uint8_t brightness = 0; + }; + + class NeopixelLED : public StatusLED { + public: + NeopixelLED(int num, uint8_t dataPin, uint8_t brightness); + ~NeopixelLED(); + + void setup(); + void setColor(uint8_t r, uint8_t g, uint8_t b); + void setBrightness(uint8_t brightness); + void setMode(uint8_t mode, bool force); + + private: + Adafruit_NeoPixel* strip; + }; + + bool tempEnabled = true; + uint8_t mode = LED_MODE::OFF; + StatusLED* led = NULL; +}; + +#endif // ifndef LED_h diff --git a/esp8266_deauther/SerialInterface.h b/esp8266_deauther/SerialInterface.h index b31d31c..dbee95b 100644 --- a/esp8266_deauther/SerialInterface.h +++ b/esp8266_deauther/SerialInterface.h @@ -1,84 +1,84 @@ -#ifndef SerialInterface_h -#define SerialInterface_h - -#include "Arduino.h" -#include -#include -extern "C" { - #include "user_interface.h" -} -#include "language.h" -#include "A_config.h" -#include "SimpleList.h" -#include "Settings.h" -#include "Names.h" -#include "SSIDs.h" -#include "Scan.h" -#include "Attack.h" -#include "DisplayUI.h" -#include "LEDController.h" - -extern LEDController* led; -extern Settings settings; -extern Names names; -extern SSIDs ssids; -extern Accesspoints accesspoints; -extern Stations stations; -extern Scan scan; -extern Attack attack; -extern DisplayUI displayUI; -extern uint32_t currentTime; -extern uint32_t autosaveTime; - -extern String macToStr(uint8_t* mac); -extern void strToColor(String str, uint8_t* buf); -extern void readFileToSerial(String path, bool showLineNum); -extern bool removeFile(String path); -extern bool copyFile(String pathFrom, String pathTo); -extern bool renameFile(String pathFrom, String pathTo); -extern bool appendFile(String path, String& buf); -extern bool removeLines(String path, int lineFrom, int lineTo); -extern bool replaceLine(String path, int line, String& buf); -extern bool equalsKeyword(const char* str, const char* keyword); -extern void printWifiStatus(); -extern void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal); -extern void wifiUpdate(); - -class SerialInterface { - public: - SerialInterface(); - void enable(); - void load(); - void load(String filepath); - void disable(); - void update(); - void stopScript(); - - void runCommands(String input); - void runCommand(String input); - - void error(String message); - void parameterError(String parameter); - - private: - bool enabled; - SimpleList* list; - bool executing = false; - bool continuously = false; - uint32_t continueTime = 0; - uint32_t loopTime = 0; - String execPath = "/autostart.txt"; - - struct Keyword { - const char* name; - const char* shortName; - const char* alt; - }; - - bool isInt(String str); - int toInt(String str); - uint32_t getTime(String time); - bool eqlsCMD(int i, const char* keyword); -}; - -#endif // ifndef SerialInterface_h \ No newline at end of file +#ifndef SerialInterface_h +#define SerialInterface_h + +#include "Arduino.h" +#include +#include +extern "C" { + #include "user_interface.h" +} +#include "language.h" +#include "A_config.h" +#include "SimpleList.h" +#include "Settings.h" +#include "Names.h" +#include "SSIDs.h" +#include "Scan.h" +#include "Attack.h" +#include "DisplayUI.h" +#include "LED.h" + +extern LED* led; +extern Settings settings; +extern Names names; +extern SSIDs ssids; +extern Accesspoints accesspoints; +extern Stations stations; +extern Scan scan; +extern Attack attack; +extern DisplayUI displayUI; +extern uint32_t currentTime; +extern uint32_t autosaveTime; + +extern String macToStr(uint8_t* mac); +extern void strToColor(String str, uint8_t* buf); +extern void readFileToSerial(String path, bool showLineNum); +extern bool removeFile(String path); +extern bool copyFile(String pathFrom, String pathTo); +extern bool renameFile(String pathFrom, String pathTo); +extern bool appendFile(String path, String& buf); +extern bool removeLines(String path, int lineFrom, int lineTo); +extern bool replaceLine(String path, int line, String& buf); +extern bool equalsKeyword(const char* str, const char* keyword); +extern void printWifiStatus(); +extern void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal); +extern void wifiUpdate(); + +class SerialInterface { + public: + SerialInterface(); + void enable(); + void load(); + void load(String filepath); + void disable(); + void update(); + void stopScript(); + + void runCommands(String input); + void runCommand(String input); + + void error(String message); + void parameterError(String parameter); + + private: + bool enabled; + SimpleList* list; + bool executing = false; + bool continuously = false; + uint32_t continueTime = 0; + uint32_t loopTime = 0; + String execPath = "/autostart.txt"; + + struct Keyword { + const char* name; + const char* shortName; + const char* alt; + }; + + bool isInt(String str); + int toInt(String str); + uint32_t getTime(String time); + bool eqlsCMD(int i, const char* keyword); +}; + +#endif // ifndef SerialInterface_h diff --git a/esp8266_deauther/esp8266_deauther.ino b/esp8266_deauther/esp8266_deauther.ino index 20789ca..da45f18 100644 --- a/esp8266_deauther/esp8266_deauther.ino +++ b/esp8266_deauther/esp8266_deauther.ino @@ -1,166 +1,166 @@ -/* - =========================================== - Copyright (c) 2018 Stefan Kremser - github.com/spacehuhn - =========================================== - */ -extern "C" { - #include "user_interface.h" -} -#include -#include "oui.h" -#include "language.h" -#include "functions.h" -#include "Settings.h" -#include "Names.h" -#include "SSIDs.h" -#include "Scan.h" -#include "Attack.h" -#include "SerialInterface.h" -#include "DisplayUI.h" -#include "A_config.h" -#include "webfiles.h" - -#include "LEDController.h" - -// Run-Time Variables // -LEDController* led; -Settings settings; -Names names; -SSIDs ssids; -Accesspoints accesspoints; -Stations stations; -Scan scan; -Attack attack; -SerialInterface serialInterface; -DisplayUI displayUI; - -#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); - prntln(SPIFFS.begin() ? SETUP_OK : SETUP_ERROR); - - // Start EEPROM - EEPROM.begin(4096); - - // auto repair when in boot-loop - uint8_t bootCounter = EEPROM.read(0); - - if (bootCounter >= 3) { - prnt(SETUP_FORMAT_SPIFFS); - SPIFFS.format(); - prntln(SETUP_OK); - } else { - EEPROM.write(0, bootCounter + 1); // add 1 to the boot counter - EEPROM.commit(); - } - - // get time - currentTime = millis(); - - // load settings - settings.load(); - - // set mac for access point - wifi_set_macaddr(SOFTAP_IF, settings.getMacAP()); - - // start WiFi - WiFi.mode(WIFI_OFF); - wifi_set_opmode(STATION_MODE); - wifi_set_promiscuous_rx_cb([](uint8_t* buf, uint16_t len) { - scan.sniffer(buf, len); - }); - - // set mac for station - wifi_set_macaddr(STATION_IF, settings.getMacSt()); - - // start display - if (settings.getDisplayInterface()) { - displayUI.setup(); - displayUI.mode = SCREEN_MODE_INTRO; - } - - // copy web files to SPIFFS - copyWebFiles(false); - - // load everything else - names.load(); - ssids.load(); - serialInterface.load(); - - // create scan.json - scan.setup(); - - // setup LED - led = new LEDController(); - led->setup(); - - // set channel - setWifiChannel(settings.getChannel()); - - // load Wifi settings: SSID, password,... - #ifdef DEFAULT_SSID - if(settings.getSSID() == "pwned") settings.setSSID(DEFAULT_SSID); - #endif - loadWifiConfigDefaults(); - - // dis/enable serial command interface - if (settings.getSerialInterface()) { - serialInterface.enable(); - } else { - prntln(SETUP_SERIAL_WARNING); - Serial.flush(); - Serial.end(); - } - - // start access point/web interface - if (settings.getWebInterface()) startAP(); - - // STARTED - prntln(SETUP_STARTED); - - // version - prntln(settings.getVersion()); -} - -void loop() { - currentTime = millis(); - - wifiUpdate(); // manage access point - - attack.update(); // run attacks - displayUI.update(); - serialInterface.update(); // read and run serial input - scan.update(); // run scan - ssids.update(); // run random mode, if enabled - led->update(); // update LED color - - // auto-save - if (settings.getAutosave() && (currentTime - autosaveTime > settings.getAutosaveTime())) { - autosaveTime = currentTime; - names.save(false); - ssids.save(false); - settings.save(false); - } - - if (!booted) { - // reset boot counter - EEPROM.write(0, 0); - EEPROM.commit(); - booted = true; - } -} +/* + =========================================== + Copyright (c) 2018 Stefan Kremser + github.com/spacehuhn + =========================================== + */ +extern "C" { + #include "user_interface.h" +} +#include +#include "oui.h" +#include "language.h" +#include "functions.h" +#include "Settings.h" +#include "Names.h" +#include "SSIDs.h" +#include "Scan.h" +#include "Attack.h" +#include "SerialInterface.h" +#include "DisplayUI.h" +#include "A_config.h" +#include "webfiles.h" + +#include "LED.h" + +// Run-Time Variables // +LED* led; +Settings settings; +Names names; +SSIDs ssids; +Accesspoints accesspoints; +Stations stations; +Scan scan; +Attack attack; +SerialInterface serialInterface; +DisplayUI displayUI; + +#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); + prntln(SPIFFS.begin() ? SETUP_OK : SETUP_ERROR); + + // Start EEPROM + EEPROM.begin(4096); + + // auto repair when in boot-loop + uint8_t bootCounter = EEPROM.read(0); + + if (bootCounter >= 3) { + prnt(SETUP_FORMAT_SPIFFS); + SPIFFS.format(); + prntln(SETUP_OK); + } else { + EEPROM.write(0, bootCounter + 1); // add 1 to the boot counter + EEPROM.commit(); + } + + // get time + currentTime = millis(); + + // load settings + settings.load(); + + // set mac for access point + wifi_set_macaddr(SOFTAP_IF, settings.getMacAP()); + + // start WiFi + WiFi.mode(WIFI_OFF); + wifi_set_opmode(STATION_MODE); + wifi_set_promiscuous_rx_cb([](uint8_t* buf, uint16_t len) { + scan.sniffer(buf, len); + }); + + // set mac for station + wifi_set_macaddr(STATION_IF, settings.getMacSt()); + + // start display + if (settings.getDisplayInterface()) { + displayUI.setup(); + displayUI.mode = SCREEN_MODE_INTRO; + } + + // copy web files to SPIFFS + copyWebFiles(false); + + // load everything else + names.load(); + ssids.load(); + serialInterface.load(); + + // create scan.json + scan.setup(); + + // setup LED + led = new LED(); + led->setup(); + + // set channel + setWifiChannel(settings.getChannel()); + + // load Wifi settings: SSID, password,... + #ifdef DEFAULT_SSID + if(settings.getSSID() == "pwned") settings.setSSID(DEFAULT_SSID); + #endif + loadWifiConfigDefaults(); + + // dis/enable serial command interface + if (settings.getSerialInterface()) { + serialInterface.enable(); + } else { + prntln(SETUP_SERIAL_WARNING); + Serial.flush(); + Serial.end(); + } + + // start access point/web interface + if (settings.getWebInterface()) startAP(); + + // STARTED + prntln(SETUP_STARTED); + + // version + prntln(settings.getVersion()); +} + +void loop() { + currentTime = millis(); + + wifiUpdate(); // manage access point + + attack.update(); // run attacks + displayUI.update(); + serialInterface.update(); // read and run serial input + scan.update(); // run scan + ssids.update(); // run random mode, if enabled + led->update(); // update LED color + + // auto-save + if (settings.getAutosave() && (currentTime - autosaveTime > settings.getAutosaveTime())) { + autosaveTime = currentTime; + names.save(false); + ssids.save(false); + settings.save(false); + } + + if (!booted) { + // reset boot counter + EEPROM.write(0, 0); + EEPROM.commit(); + booted = true; + } +}