-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode.c
More file actions
188 lines (150 loc) · 4.23 KB
/
Copy pathCode.c
File metadata and controls
188 lines (150 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
extern "C" {
#include "user_interface.h"
}
#include "EEPROMHelper.h"
#include "src/ArduinoJson-v5.13.5/ArduinoJson.h"
#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
#error Please upgrade/downgrade ArduinoJSON library to version 5!
#endif // if ARDUINOJSON_VERSION_MAJOR != 5
#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 "CLI.h"
#include "DisplayUI.h"
#include "A_config.h"
#include "led.h"
// Run-Time Variables //
Names names;
SSIDs ssids;
Accesspoints accesspoints;
Stations stations;
Scan scan;
Attack attack;
CLI cli;
DisplayUI displayUI;
simplebutton::Button* resetButton;
#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);
// bool spiffsError = !LittleFS.begin();
LittleFS.begin();
prntln(/*spiffsError ? SETUP_ERROR : */ SETUP_OK);
// Start EEPROM
EEPROMHelper::begin(EEPROM_SIZE);
#ifdef FORMAT_SPIFFS
prnt(SETUP_FORMAT_SPIFFS);
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
if (/*spiffsError || */ !EEPROMHelper::checkBootNum(BOOT_COUNTER_ADDR)) {
prnt(SETUP_FORMAT_SPIFFS);
LittleFS.format();
prntln(SETUP_OK);
prnt(SETUP_FORMAT_EEPROM);
EEPROMHelper::format(EEPROM_SIZE);
prntln(SETUP_OK);
EEPROMHelper::resetBootNum(BOOT_COUNTER_ADDR);
}
// get time
currentTime = millis();
// load settings
#ifndef RESET_SETTINGS
settings::load();
#else // ifndef RESET_SETTINGS
settings::reset();
settings::save();
#endif // ifndef RESET_SETTINGS
wifi::begin();
wifi_set_promiscuous_rx_cb([](uint8_t* buf, uint16_t len) {
scan.sniffer(buf, len);
});
// start display
if (settings::getDisplaySettings().enabled) {
displayUI.setup();
displayUI.mode = DISPLAY_MODE::INTRO;
}
// load everything else
names.load();
ssids.load();
cli.load();
// create scan.json
scan.setup();
// dis/enable serial command interface
if (settings::getCLISettings().enabled) {
cli.enable();
} else {
prntln(SETUP_SERIAL_WARNING);
Serial.flush();
Serial.end();
}
// start access point/web interface
if (settings::getWebSettings().enabled) wifi::startAP();
// STARTED
prntln(SETUP_STARTED);
// version
prntln(DEAUTHER_VERSION);
// setup LED
led::setup();
// setup reset button
resetButton = new ButtonPullup(RESET_BUTTON);
}
void loop() {
currentTime = millis();
led::update(); // update LED color
wifi::update(); // manage access point
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
if (settings::getAutosaveSettings().enabled
&& (currentTime - autosaveTime > settings::getAutosaveSettings().time)) {
autosaveTime = currentTime;
names.save(false);
ssids.save(false);
settings::save(false);
}
if (!booted) {
booted = true;
EEPROMHelper::resetBootNum(BOOT_COUNTER_ADDR);
#ifdef HIGHLIGHT_LED
displayUI.setupLED();
#endif // ifdef HIGHLIGHT_LED
}
resetButton->update();
if (resetButton->holding(5000)) {
led::setMode(LED_MODE::SCAN);
DISPLAY_MODE _mode = displayUI.mode;
displayUI.mode = DISPLAY_MODE::RESETTING;
displayUI.update(true);
settings::reset();
settings::save(true);
delay(2000);
led::setMode(LED_MODE::IDLE);
displayUI.mode = _mode;
}
}