Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ===========================================
- Copyright (c) 2018 Stefan Kremser
- github.com/spacehuhn
- ===========================================
- */
- extern "C" {
- #include "user_interface.h"
- }
- #include <EEPROM.h>
- #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();
- delay(6000);
- Serial.println("1");
- delay(500);
- // start SPIFFS
- prnt(SETUP_MOUNT_SPIFFS);
- Serial.println("2");
- delay(500);
- prntln(SPIFFS.begin() ? SETUP_OK : SETUP_ERROR);
- Serial.println("3");
- delay(500);
- // Start EEPROM
- EEPROM.begin(4096);
- Serial.println("4");
- delay(500);
- // auto repair when in boot-loop
- uint8_t bootCounter = EEPROM.read(0);
- Serial.println("5");
- delay(500);
- if (bootCounter >= 3) {
- Serial.println("6a");
- delay(500);
- prnt(SETUP_FORMAT_SPIFFS);
- SPIFFS.format();
- prntln(SETUP_OK);
- Serial.println("7a");
- delay(500);
- } else {
- Serial.println("6b");
- delay(500);
- EEPROM.write(0, bootCounter + 1); // add 1 to the boot counter
- Serial.println("7b");
- delay(500);
- EEPROM.commit();
- Serial.println("7c");
- delay(500);
- }
- // get time
- currentTime = millis();
- Serial.println("8");
- delay(500);
- // load settings
- settings.load();
- Serial.println("9");
- delay(500);
- // set mac for access point
- wifi_set_macaddr(SOFTAP_IF, settings.getMacAP());
- Serial.println("10");
- delay(500);
- // 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());
- Serial.println("11");
- delay(500);
- // start display
- if (settings.getDisplayInterface()) {
- displayUI.setup();
- displayUI.mode = SCREEN_MODE_INTRO;
- }
- Serial.println("12");
- delay(500);
- // copy web files to SPIFFS
- copyWebFiles(false);
- Serial.println("13");
- delay(500);
- // load everything else
- names.load();
- ssids.load();
- serialInterface.load();
- Serial.println("14");
- delay(500);
- // create scan.json
- scan.setup();
- Serial.println("15");
- delay(500);
- // setup LED
- led = new LEDController();
- led->setup();
- Serial.println("16");
- delay(500);
- // set channel
- setWifiChannel(settings.getChannel());
- Serial.println("17");
- delay(500);
- // load Wifi settings: SSID, password,...
- #ifdef DEFAULT_SSID
- if(settings.getSSID() == "pwned") settings.setSSID(DEFAULT_SSID);
- #endif
- loadWifiConfigDefaults();
- Serial.println("18");
- delay(500);
- // dis/enable serial command interface
- if (settings.getSerialInterface()) {
- serialInterface.enable();
- } else {
- prntln(SETUP_SERIAL_WARNING);
- Serial.flush();
- Serial.end();
- }
- Serial.println("19");
- delay(500);
- // start access point/web interface
- if (settings.getWebInterface()) startAP();
- Serial.println("20");
- delay(500);
- // STARTED
- prntln(SETUP_STARTED);
- // version
- prntln(settings.getVersion());
- Serial.println("Setup routine is completed (loop function should be executed now over and over again)");
- delay(500);
- }
- void loop() {
- Serial.println("void loop() is being executed " + String(millis()));
- delay(500);
- 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;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement