Rewritten LED classes and simplified config files
This commit is contained in:
Stefan Kremser
2018-06-05 11:50:38 +02:00
parent 1d10f3e4d2
commit 8a0f48bb4b
41 changed files with 6826 additions and 6623 deletions

View File

@@ -23,15 +23,11 @@
Adjust following settings for your type of LED Adjust following settings for your type of LED
you can ignore the rest of the #define's you can ignore the rest of the #define's
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
// === Settings for Digital LED === //
#define LED_ENABLE_R true
#define LED_ENABLE_G false
#define LED_ENABLE_B true
// === Settings for Digital LED and RGB LED === // // === Settings for Digital LED and RGB LED === //
#define LED_CATHODE false // common ground (GND) #define LED_ANODE false // common vcc (+)
#define LED_PIN_R 16 // NodeMCU on-board LED #define LED_PIN_R 16 // NodeMCU on-board LED
#define LED_PIN_G 0 #define LED_PIN_G 255 // 255 = LED disabled
#define LED_PIN_B 2 // ESP-12 LED #define LED_PIN_B 2 // ESP-12 LED
// === Settings for RGB LED and Neopixel LED === // // === Settings for RGB LED and Neopixel LED === //
@@ -42,16 +38,6 @@
#define LED_NEOPIXEL_NUM 12 #define LED_NEOPIXEL_NUM 12
#define LED_NEOPIXEL_PIN 15 #define LED_NEOPIXEL_PIN 15
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
// ===================== DISPLAY CONFIG ==================== // // ===================== DISPLAY CONFIG ==================== //
#define USE_DISPLAY true // default display setting #define USE_DISPLAY true // default display setting

View File

@@ -23,15 +23,11 @@
Adjust following settings for your type of LED Adjust following settings for your type of LED
you can ignore the rest of the #define's you can ignore the rest of the #define's
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
// === Settings for Digital LED === //
#define LED_ENABLE_R true
#define LED_ENABLE_G false
#define LED_ENABLE_B true
// === Settings for Digital LED and RGB LED === // // === Settings for Digital LED and RGB LED === //
#define LED_CATHODE false // common ground (GND) #define LED_ANODE false // common vcc (+)
#define LED_PIN_R 16 // NodeMCU on-board LED #define LED_PIN_R 16 // NodeMCU on-board LED
#define LED_PIN_G 0 #define LED_PIN_G 255 // 255 = LED disabled
#define LED_PIN_B 2 // ESP-12 LED #define LED_PIN_B 2 // ESP-12 LED
// === Settings for RGB LED and Neopixel LED === // // === Settings for RGB LED and Neopixel LED === //
@@ -41,8 +37,6 @@
// === Settings for Neopixel LED === // // === Settings for Neopixel LED === //
#define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_NUM 1
#define LED_NEOPIXEL_PIN 15 #define LED_NEOPIXEL_PIN 15
// if it doesn't work try changing NEO_GRB to NEO_GRBW
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
// ===================== DISPLAY CONFIG ==================== // // ===================== DISPLAY CONFIG ==================== //
#define USE_DISPLAY true // default display setting #define USE_DISPLAY true // default display setting

View File

@@ -23,15 +23,11 @@
Adjust following settings for your type of LED Adjust following settings for your type of LED
you can ignore the rest of the #define's you can ignore the rest of the #define's
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
// === Settings for Digital LED === //
#define LED_ENABLE_R true
#define LED_ENABLE_G false
#define LED_ENABLE_B true
// === Settings for Digital LED and RGB LED === // // === Settings for Digital LED and RGB LED === //
#define LED_CATHODE false // common ground (GND) #define LED_ANODE false // common vcc (+)
#define LED_PIN_R 16 // NodeMCU on-board LED #define LED_PIN_R 16 // NodeMCU on-board LED
#define LED_PIN_G 0 #define LED_PIN_G 255 // 255 = LED disabled
#define LED_PIN_B 2 // ESP-12 LED #define LED_PIN_B 2 // ESP-12 LED
// === Settings for RGB LED and Neopixel LED === // // === Settings for RGB LED and Neopixel LED === //
@@ -42,16 +38,6 @@
#define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_NUM 1
#define LED_NEOPIXEL_PIN 9 #define LED_NEOPIXEL_PIN 9
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
// ===================== DISPLAY CONFIG ==================== // // ===================== DISPLAY CONFIG ==================== //
#define USE_DISPLAY true // default display setting #define USE_DISPLAY true // default display setting

View File

@@ -23,15 +23,11 @@
Adjust following settings for your type of LED Adjust following settings for your type of LED
you can ignore the rest of the #define's you can ignore the rest of the #define's
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
// === Settings for Digital LED === //
#define LED_ENABLE_R true
#define LED_ENABLE_G false
#define LED_ENABLE_B true
// === Settings for Digital LED and RGB LED === // // === Settings for Digital LED and RGB LED === //
#define LED_CATHODE false // common ground (GND) #define LED_ANODE false // common vcc (+)
#define LED_PIN_R 16 // NodeMCU on-board LED #define LED_PIN_R 16 // NodeMCU on-board LED
#define LED_PIN_G 0 #define LED_PIN_G 255 // 255 = LED disabled
#define LED_PIN_B 2 // ESP-12 LED #define LED_PIN_B 2 // ESP-12 LED
// === Settings for RGB LED and Neopixel LED === // // === Settings for RGB LED and Neopixel LED === //
@@ -42,16 +38,6 @@
#define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_NUM 1
#define LED_NEOPIXEL_PIN 9 #define LED_NEOPIXEL_PIN 9
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
// ===================== DISPLAY CONFIG ==================== // // ===================== DISPLAY CONFIG ==================== //
#define USE_DISPLAY true // default display setting #define USE_DISPLAY true // default display setting

View File

@@ -23,16 +23,12 @@
Adjust following settings for your type of LED Adjust following settings for your type of LED
you can ignore the rest of the #define's you can ignore the rest of the #define's
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
// === Settings for Digital LED === //
#define LED_ENABLE_R true
#define LED_ENABLE_G false
#define LED_ENABLE_B true
// === Settings for Digital LED and RGB LED === // // === Settings for Digital LED and RGB LED === //
#define LED_CATHODE false // common ground (GND) #define LED_ANODE false // common vcc (+)
#define LED_PIN_R 2 // ESP-12 LED #define LED_PIN_R 16 // NodeMCU on-board LED
#define LED_PIN_G 0 #define LED_PIN_G 255 // 255 = LED disabled
#define LED_PIN_B 16 // NodeMCU on-board LED #define LED_PIN_B 2 // ESP-12 LED
// === Settings for RGB LED and Neopixel LED === // // === Settings for RGB LED and Neopixel LED === //
#define LED_MODE_BRIGHTNESS 10 // brightness of LED modes #define LED_MODE_BRIGHTNESS 10 // brightness of LED modes
@@ -42,16 +38,6 @@
#define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_NUM 1
#define LED_NEOPIXEL_PIN 15 #define LED_NEOPIXEL_PIN 15
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
// ===================== DISPLAY CONFIG ==================== // // ===================== DISPLAY CONFIG ==================== //
#define USE_DISPLAY true // default display setting #define USE_DISPLAY true // default display setting

View File

@@ -23,15 +23,11 @@
Adjust following settings for your type of LED Adjust following settings for your type of LED
you can ignore the rest of the #define's you can ignore the rest of the #define's
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
// === Settings for Digital LED === //
#define LED_ENABLE_R true
#define LED_ENABLE_G false
#define LED_ENABLE_B true
// === Settings for Digital LED and RGB LED === // // === Settings for Digital LED and RGB LED === //
#define LED_CATHODE false // common ground (GND) #define LED_ANODE false // common vcc (+)
#define LED_PIN_R 16 // NodeMCU on-board LED #define LED_PIN_R 16 // NodeMCU on-board LED
#define LED_PIN_G 0 #define LED_PIN_G 255 // 255 = LED disabled
#define LED_PIN_B 2 // ESP-12 LED #define LED_PIN_B 2 // ESP-12 LED
// === Settings for RGB LED and Neopixel LED === // // === Settings for RGB LED and Neopixel LED === //
@@ -42,16 +38,6 @@
#define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_NUM 1
#define LED_NEOPIXEL_PIN 15 #define LED_NEOPIXEL_PIN 15
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
// ===================== DISPLAY CONFIG ==================== // // ===================== DISPLAY CONFIG ==================== //
#define USE_DISPLAY false // default display setting #define USE_DISPLAY false // default display setting

View File

@@ -23,15 +23,11 @@
Adjust following settings for your type of LED Adjust following settings for your type of LED
you can ignore the rest of the #define's you can ignore the rest of the #define's
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
// === Settings for Digital LED === //
#define LED_ENABLE_R true
#define LED_ENABLE_G false
#define LED_ENABLE_B true
// === Settings for Digital LED and RGB LED === // // === Settings for Digital LED and RGB LED === //
#define LED_CATHODE false // common ground (GND) #define LED_ANODE false // common vcc (+)
#define LED_PIN_R 16 // NodeMCU on-board LED #define LED_PIN_R 16 // NodeMCU on-board LED
#define LED_PIN_G 0 #define LED_PIN_G 255 // 255 = LED disabled
#define LED_PIN_B 2 // ESP-12 LED #define LED_PIN_B 2 // ESP-12 LED
// === Settings for RGB LED and Neopixel LED === // // === Settings for RGB LED and Neopixel LED === //
@@ -42,16 +38,6 @@
#define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_NUM 1
#define LED_NEOPIXEL_PIN 4 #define LED_NEOPIXEL_PIN 4
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
// ===================== DISPLAY CONFIG ==================== // // ===================== DISPLAY CONFIG ==================== //
#define USE_DISPLAY false // default display setting #define USE_DISPLAY false // default display setting

View File

@@ -23,15 +23,11 @@
Adjust following settings for your type of LED Adjust following settings for your type of LED
you can ignore the rest of the #define's you can ignore the rest of the #define's
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
// === Settings for Digital LED === //
#define LED_ENABLE_R true
#define LED_ENABLE_G false
#define LED_ENABLE_B true
// === Settings for Digital LED and RGB LED === // // === Settings for Digital LED and RGB LED === //
#define LED_CATHODE false // common ground (GND) #define LED_ANODE false // common vcc (+)
#define LED_PIN_R 16 // NodeMCU on-board LED #define LED_PIN_R 16 // NodeMCU on-board LED
#define LED_PIN_G 0 #define LED_PIN_G 255 // 255 = LED disabled
#define LED_PIN_B 2 // ESP-12 LED #define LED_PIN_B 2 // ESP-12 LED
// === Settings for RGB LED and Neopixel LED === // // === Settings for RGB LED and Neopixel LED === //
@@ -40,18 +36,7 @@
// === Settings for Neopixel LED === // // === Settings for Neopixel LED === //
#define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_NUM 1
#define LED_NEOPIXEL_PIN 9 #define LED_NEOPIXEL_PIN 15
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
// ===================== DISPLAY CONFIG ==================== // // ===================== DISPLAY CONFIG ==================== //
#define USE_DISPLAY false // default display setting #define USE_DISPLAY false // default display setting

View File

@@ -11,6 +11,7 @@
// =========================== // // =========================== //
// ===================== LED CONFIG ==================== // // ===================== LED CONFIG ==================== //
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Uncomment the type of LED you're using Uncomment the type of LED you're using
Only one of them can be defined at a time! Only one of them can be defined at a time!
@@ -23,15 +24,11 @@
Adjust following settings for your type of LED Adjust following settings for your type of LED
you can ignore the rest of the #define's you can ignore the rest of the #define's
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
// === Settings for Digital LED === //
#define LED_ENABLE_R true
#define LED_ENABLE_G false
#define LED_ENABLE_B true
// === Settings for Digital LED and RGB LED === // // === Settings for Digital LED and RGB LED === //
#define LED_CATHODE false // common ground (GND) #define LED_ANODE false // common vcc (+)
#define LED_PIN_R 16 // NodeMCU on-board LED #define LED_PIN_R 16 // NodeMCU on-board LED
#define LED_PIN_G 0 #define LED_PIN_G 255 // 255 = LED disabled
#define LED_PIN_B 2 // ESP-12 LED #define LED_PIN_B 2 // ESP-12 LED
// === Settings for RGB LED and Neopixel LED === // // === Settings for RGB LED and Neopixel LED === //
@@ -40,17 +37,7 @@
// === Settings for Neopixel LED === // // === Settings for Neopixel LED === //
#define LED_NEOPIXEL_NUM 1 #define LED_NEOPIXEL_NUM 1
#define LED_NEOPIXEL_PIN 9 #define LED_NEOPIXEL_PIN 15
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
// NEO_RGBW Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
#define LED_NEOPIXEL Adafruit_NeoPixel(LED_NEOPIXEL_NUM, LED_NEOPIXEL_PIN, NEO_GRB + NEO_KHZ800)
// ===================== DISPLAY CONFIG ==================== // // ===================== DISPLAY CONFIG ==================== //
#define USE_DISPLAY false // default display setting #define USE_DISPLAY false // default display setting
@@ -86,5 +73,4 @@
// #define FLIP_DIPLAY // uncomment that to flip the display vertically // #define FLIP_DIPLAY // uncomment that to flip the display vertically
// ========================================================= // // ========================================================= //
#endif #endif // ifndef config_h

View File

@@ -26,22 +26,23 @@ void Accesspoints::add(uint8_t id, bool selected) {
void Accesspoints::printAll() { void Accesspoints::printAll() {
prntln(AP_HEADER); prntln(AP_HEADER);
int c = count(); int c = count();
if (c == 0)
prntln(AP_LIST_EMPTY); if (c == 0) prntln(AP_LIST_EMPTY);
else else
for (int i = 0; i < c; i++) for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
print(i, i == 0, i == c - 1);
} }
void Accesspoints::printSelected() { void Accesspoints::printSelected() {
prntln(AP_HEADER); prntln(AP_HEADER);
int max = selected(); int max = selected();
if (selected() == 0) { if (selected() == 0) {
prntln(AP_NO_AP_SELECTED); prntln(AP_NO_AP_SELECTED);
return; return;
} }
int c = count(); int c = count();
int j = 0; int j = 0;
for (int i = 0; i < c && j < max; i++) { for (int i = 0; i < c && j < max; i++) {
if (getSelected(i)) { if (getSelected(i)) {
print(i, j == 0, j == max - 1); print(i, j == 0, j == max - 1);
@@ -56,6 +57,7 @@ void Accesspoints::print(int num) {
void Accesspoints::print(int num, bool header, bool footer) { void Accesspoints::print(int num, bool header, bool footer) {
if (!check(num)) return; if (!check(num)) return;
if (header) { if (header) {
prntln(AP_TABLE_HEADER); prntln(AP_TABLE_HEADER);
prntln(AP_TABLE_DIVIDER); prntln(AP_TABLE_DIVIDER);
@@ -77,6 +79,7 @@ void Accesspoints::print(int num, bool header, bool footer) {
String Accesspoints::getSSID(int num) { String Accesspoints::getSSID(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
if (getHidden(num)) { if (getHidden(num)) {
return str(AP_HIDDEN); return str(AP_HIDDEN);
} else { } else {
@@ -89,41 +92,55 @@ String Accesspoints::getSSID(int num) {
String Accesspoints::getNameStr(int num) { String Accesspoints::getNameStr(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
return names.find(getMac(num)); return names.find(getMac(num));
} }
uint8_t Accesspoints::getCh(int num) { uint8_t Accesspoints::getCh(int num) {
if (!check(num)) return 0; if (!check(num)) return 0;
return WiFi.channel(getID(num)); return WiFi.channel(getID(num));
} }
int Accesspoints::getRSSI(int num) { int Accesspoints::getRSSI(int num) {
if (!check(num)) return 0; if (!check(num)) return 0;
return WiFi.RSSI(getID(num)); return WiFi.RSSI(getID(num));
} }
uint8_t Accesspoints::getEnc(int num) { uint8_t Accesspoints::getEnc(int num) {
if (!check(num)) return 0; if (!check(num)) return 0;
return WiFi.encryptionType(getID(num)); return WiFi.encryptionType(getID(num));
} }
String Accesspoints::getEncStr(int num) { String Accesspoints::getEncStr(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
switch (getEnc(num)) { switch (getEnc(num)) {
case ENC_TYPE_NONE: case ENC_TYPE_NONE:
return String(DASH); return String(DASH);
break; break;
case ENC_TYPE_WEP: case ENC_TYPE_WEP:
return str(AP_WEP); return str(AP_WEP);
break; break;
case ENC_TYPE_TKIP: case ENC_TYPE_TKIP:
return str(AP_WPA); return str(AP_WPA);
break; break;
case ENC_TYPE_CCMP: case ENC_TYPE_CCMP:
return str(AP_WPA2); return str(AP_WPA2);
break; break;
case ENC_TYPE_AUTO: case ENC_TYPE_AUTO:
return str(AP_AUTO); return str(AP_AUTO);
break; break;
} }
return String(QUESTIONMARK); return String(QUESTIONMARK);
@@ -135,32 +152,38 @@ String Accesspoints::getSelectedStr(int num) {
uint8_t* Accesspoints::getMac(int num) { uint8_t* Accesspoints::getMac(int num) {
if (!check(num)) return 0; if (!check(num)) return 0;
return WiFi.BSSID(getID(num)); return WiFi.BSSID(getID(num));
} }
String Accesspoints::getMacStr(int num) { String Accesspoints::getMacStr(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
uint8_t* mac = getMac(num); uint8_t* mac = getMac(num);
return bytesToStr(mac, 6); return bytesToStr(mac, 6);
} }
String Accesspoints::getVendorStr(int num) { String Accesspoints::getVendorStr(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
return searchVendor(getMac(num)); return searchVendor(getMac(num));
} }
bool Accesspoints::getHidden(int num) { bool Accesspoints::getHidden(int num) {
if (!check(num)) return false; if (!check(num)) return false;
return WiFi.isHidden(getID(num)); return WiFi.isHidden(getID(num));
} }
bool Accesspoints::getSelected(int num) { bool Accesspoints::getSelected(int num) {
if (!check(num)) return false; if (!check(num)) return false;
return list->get(num).selected; return list->get(num).selected;
} }
uint8_t Accesspoints::getID(int num) { uint8_t Accesspoints::getID(int num) {
if (!check(num)) return -1; if (!check(num)) return -1;
return list->get(num).id; return list->get(num).id;
} }
@@ -198,31 +221,28 @@ void Accesspoints::remove(int num) {
} }
void Accesspoints::selectAll() { void Accesspoints::selectAll() {
for(int i=0;i<count();i++) for (int i = 0; i < count(); i++) list->replace(i, AP{ list->get(i).id, true });
list->replace(i,AP{list->get(i).id,true});
prntln(AP_SELECTED_ALL); prntln(AP_SELECTED_ALL);
changed = true; changed = true;
} }
void Accesspoints::deselectAll() { void Accesspoints::deselectAll() {
for(int i=0;i<count();i++) for (int i = 0; i < count(); i++) list->replace(i, AP{ list->get(i).id, false });
list->replace(i,AP{list->get(i).id,false});
prntln(AP_DESELECTED_ALL); prntln(AP_DESELECTED_ALL);
changed = true; changed = true;
} }
void Accesspoints::removeAll() { void Accesspoints::removeAll() {
while(count() > 0) while (count() > 0) internal_remove(0);
internal_remove(0);
prntln(AP_REMOVED_ALL); prntln(AP_REMOVED_ALL);
changed = true; changed = true;
} }
int Accesspoints::find(uint8_t id) { int Accesspoints::find(uint8_t id) {
int s = list->size(); int s = list->size();
for (int i = 0; i < s; i++) { for (int i = 0; i < s; i++) {
if(list->get(i).id == id) if (list->get(i).id == id) return i;
return i;
} }
return -1; return -1;
} }
@@ -232,13 +252,15 @@ int Accesspoints::count() {
} }
int Accesspoints::selected() { int Accesspoints::selected() {
return list->count([](AP &a)->bool{ int c = 0;
return a.selected;
}); for (int i = 0; i < list->size(); i++) c += list->get(i).selected;
return c;
} }
bool Accesspoints::check(int num) { bool Accesspoints::check(int num) {
if (internal_check(num)) return true; if (internal_check(num)) return true;
prnt(AP_NO_AP_ERROR); prnt(AP_NO_AP_ERROR);
prntln((String)num); prntln((String)num);
return false; return false;
@@ -259,4 +281,3 @@ void Accesspoints::internal_deselect(int num) {
void Accesspoints::internal_remove(int num) { void Accesspoints::internal_remove(int num) {
list->remove(num); list->remove(num);
} }

View File

@@ -63,6 +63,7 @@ class Accesspoints {
bool check(int num); bool check(int num);
bool changed = false; bool changed = false;
private: private:
SimpleList<AP>* list; SimpleList<AP>* list;
@@ -72,7 +73,4 @@ class Accesspoints {
void internal_remove(int num); void internal_remove(int num);
}; };
#endif #endif // ifndef Accesspoints_h

View File

@@ -0,0 +1,44 @@
#include "AnalogRGBLED.h"
AnalogRGBLED::AnalogRGBLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, uint8_t brightness, bool anode) {
AnalogRGBLED::anode = anode;
AnalogRGBLED::rPin = rPin;
AnalogRGBLED::gPin = gPin;
AnalogRGBLED::bPin = bPin;
setBrightness(brightness);
}
AnalogRGBLED::~AnalogRGBLED() {}
void AnalogRGBLED::setup() {
analogWriteRange(0xff);
if (rPin < 255) pinMode(rPin, OUTPUT);
if (gPin < 255) pinMode(gPin, OUTPUT);
if (bPin < 255) pinMode(bPin, OUTPUT);
}
void 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 AnalogRGBLED::setBrightness(uint8_t brightness) {
if (brightness > 100) brightness = 100;
AnalogRGBLED::brightness = brightness;
}

View File

@@ -0,0 +1,23 @@
#ifndef AnalogRGBLED_H
#define AnalogRGBLED_H
#include "StatusLED.h"
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;
};
#endif // ifndef AnalogRGBLED_H

View File

@@ -37,7 +37,8 @@ void Attack::start(bool beacon, bool deauth, bool deauthAll, bool probe, bool ou
Attack::output = output; Attack::output = output;
Attack::timeout = timeout; Attack::timeout = timeout;
//if (((beacon || probe) && ssids.count() > 0) || (deauthAll && scan.countAll() > 0) || (deauth && scan.countSelected() > 0)){ // if (((beacon || probe) && ssids.count() > 0) || (deauthAll && scan.countAll() > 0) || (deauth &&
// scan.countSelected() > 0)){
if (beacon || probe || deauthAll || deauth) { if (beacon || probe || deauthAll || deauth) {
start(); start();
} else { } else {
@@ -74,7 +75,7 @@ bool Attack::isRunning() {
void Attack::updateCounter() { void Attack::updateCounter() {
// stop when timeout is active and time is up // stop when timeout is active and time is up
if (timeout > 0 && currentTime - attackStartTime >= timeout) { if ((timeout > 0) && (currentTime - attackStartTime >= timeout)) {
prntln(A_TIMEOUT); prntln(A_TIMEOUT);
stop(); stop();
return; return;
@@ -82,8 +83,10 @@ void Attack::updateCounter() {
// deauth packets per second // deauth packets per second
if (deauth.active) { if (deauth.active) {
if (deauthAll) deauth.maxPkts = settings.getDeauthsPerTarget() * (accesspoints.count() + stations.count()*2 - names.selected()); if (deauthAll) deauth.maxPkts = settings.getDeauthsPerTarget() *
else deauth.maxPkts = settings.getDeauthsPerTarget() * (accesspoints.selected() + stations.selected()*2 + names.selected() + names.stations()); (accesspoints.count() + stations.count() * 2 - names.selected());
else deauth.maxPkts = settings.getDeauthsPerTarget() *
(accesspoints.selected() + stations.selected() * 2 + names.selected() + names.stations());
} else { } else {
deauth.maxPkts = 0; deauth.maxPkts = 0;
} }
@@ -91,6 +94,7 @@ void Attack::updateCounter() {
// beacon packets per second // beacon packets per second
if (beacon.active) { if (beacon.active) {
beacon.maxPkts = ssids.count(); beacon.maxPkts = ssids.count();
if (!settings.getBeaconInterval()) beacon.maxPkts *= 10; if (!settings.getBeaconInterval()) beacon.maxPkts *= 10;
} else { } else {
beacon.maxPkts = 0; beacon.maxPkts = 0;
@@ -120,15 +124,22 @@ void Attack::updateCounter() {
void Attack::status() { void Attack::status() {
char s[120]; char s[120];
sprintf(s, str(A_STATUS).c_str(), packetRate, deauthPkts, deauth.maxPkts, beaconPkts, beacon.maxPkts, probePkts, probe.maxPkts);
sprintf(s, str(
A_STATUS).c_str(), packetRate, deauthPkts, deauth.maxPkts, beaconPkts, beacon.maxPkts, probePkts,
probe.maxPkts);
prnt(String(s)); prnt(String(s));
} }
String Attack::getStatusJSON() { String Attack::getStatusJSON() {
String json = String(OPEN_BRACKET); // [ String json = String(OPEN_BRACKET); // [
json += String(OPEN_BRACKET) + b2s(deauth.active) + String(COMMA) + String(scan.countSelected()) + String(COMMA) + String(deauthPkts) + String(COMMA) + String(deauth.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0],
json += String(OPEN_BRACKET) + b2s(beacon.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String(beaconPkts) + String(COMMA) + String(beacon.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0], json += String(OPEN_BRACKET) + b2s(deauth.active) + String(COMMA) + String(scan.countSelected()) + String(COMMA) +
json += String(OPEN_BRACKET) + b2s(probe.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String(probePkts) + String(COMMA) + String(probe.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0], String(deauthPkts) + String(COMMA) + String(deauth.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0],
json += String(OPEN_BRACKET) + b2s(beacon.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String(
beaconPkts) + String(COMMA) + String(beacon.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0],
json += String(OPEN_BRACKET) + b2s(probe.active) + String(COMMA) + String(ssids.count()) + String(COMMA) + String(
probePkts) + String(COMMA) + String(probe.maxPkts) + String(CLOSE_BRACKET) + String(COMMA); // [false,0,0,0],
json += String(packetRate); // 0 json += String(packetRate); // 0
json += CLOSE_BRACKET; // ] json += CLOSE_BRACKET; // ]
@@ -152,48 +163,49 @@ void Attack::update() {
if (currentTime - attackTime > 1000) { if (currentTime - attackTime > 1000) {
attackTime = currentTime; // update time attackTime = currentTime; // update time
updateCounter(); updateCounter();
if (output) status(); // status update if (output) status(); // status update
getRandomMac(mac); // generate new random mac getRandomMac(mac); // generate new random mac
} }
} }
void Attack::deauthUpdate() { void Attack::deauthUpdate() {
if (!deauthAll && deauth.active && deauth.maxPkts > 0 && deauth.packetCounter < deauth.maxPkts) { if (!deauthAll && deauth.active && (deauth.maxPkts > 0) && (deauth.packetCounter < deauth.maxPkts)) {
if (deauth.time <= currentTime - (1000 / deauth.maxPkts)) { if (deauth.time <= currentTime - (1000 / deauth.maxPkts)) {
// APs // APs
if (apCount > 0 && deauth.tc < apCount) { if ((apCount > 0) && (deauth.tc < apCount)) {
if (accesspoints.getSelected(deauth.tc)) { if (accesspoints.getSelected(deauth.tc)) {
deauth.tc += deauthAP(deauth.tc); deauth.tc += deauthAP(deauth.tc);
} else deauth.tc++; } else deauth.tc++;
} }
// Stations // Stations
else if (stCount > 0 && deauth.tc >= apCount && deauth.tc < stCount + apCount) { else if ((stCount > 0) && (deauth.tc >= apCount) && (deauth.tc < stCount + apCount)) {
if (stations.getSelected(deauth.tc - apCount)) { if (stations.getSelected(deauth.tc - apCount)) {
deauth.tc += deauthStation(deauth.tc - apCount); deauth.tc += deauthStation(deauth.tc - apCount);
} else deauth.tc++; } else deauth.tc++;
} }
// Names // Names
else if (nCount > 0 && deauth.tc >= apCount + stCount && deauth.tc < nCount + stCount + apCount) { else if ((nCount > 0) && (deauth.tc >= apCount + stCount) && (deauth.tc < nCount + stCount + apCount)) {
if (names.getSelected(deauth.tc - stCount - apCount)) { if (names.getSelected(deauth.tc - stCount - apCount)) {
deauth.tc += deauthName(deauth.tc - stCount - apCount); deauth.tc += deauthName(deauth.tc - stCount - apCount);
} else deauth.tc++; } else deauth.tc++;
} }
// reset counter // reset counter
if (deauth.tc >= nCount + stCount + apCount) if (deauth.tc >= nCount + stCount + apCount) deauth.tc = 0;
deauth.tc = 0;
} }
} }
} }
void Attack::deauthAllUpdate() { void Attack::deauthAllUpdate() {
if (deauthAll && deauth.active && deauth.maxPkts > 0 && deauth.packetCounter < deauth.maxPkts) { if (deauthAll && deauth.active && (deauth.maxPkts > 0) && (deauth.packetCounter < deauth.maxPkts)) {
if (deauth.time <= currentTime - (1000 / deauth.maxPkts)) { if (deauth.time <= currentTime - (1000 / deauth.maxPkts)) {
// APs // APs
if (apCount > 0 && deauth.tc < apCount) { if ((apCount > 0) && (deauth.tc < apCount)) {
tmpID = names.findID(accesspoints.getMac(deauth.tc)); tmpID = names.findID(accesspoints.getMac(deauth.tc));
if (tmpID < 0) { if (tmpID < 0) {
deauth.tc += deauthAP(deauth.tc); deauth.tc += deauthAP(deauth.tc);
} else if (!names.getSelected(tmpID)) { } else if (!names.getSelected(tmpID)) {
@@ -202,8 +214,9 @@ void Attack::deauthAllUpdate() {
} }
// Stations // Stations
else if (stCount > 0 && deauth.tc >= apCount && deauth.tc < stCount + apCount) { else if ((stCount > 0) && (deauth.tc >= apCount) && (deauth.tc < stCount + apCount)) {
tmpID = names.findID(stations.getMac(deauth.tc - apCount)); tmpID = names.findID(stations.getMac(deauth.tc - apCount));
if (tmpID < 0) { if (tmpID < 0) {
deauth.tc += deauthStation(deauth.tc - apCount); deauth.tc += deauthStation(deauth.tc - apCount);
} else if (!names.getSelected(tmpID)) { } else if (!names.getSelected(tmpID)) {
@@ -212,33 +225,34 @@ void Attack::deauthAllUpdate() {
} }
// Names // Names
else if (nCount > 0 && deauth.tc >= apCount + stCount && deauth.tc < apCount + stCount + nCount) { else if ((nCount > 0) && (deauth.tc >= apCount + stCount) && (deauth.tc < apCount + stCount + nCount)) {
if (!names.getSelected(deauth.tc - apCount - stCount)) { if (!names.getSelected(deauth.tc - apCount - stCount)) {
deauth.tc += deauthName(deauth.tc - apCount - stCount); deauth.tc += deauthName(deauth.tc - apCount - stCount);
} else deauth.tc++; } else deauth.tc++;
} }
// reset counter // reset counter
if (deauth.tc >= nCount + stCount + apCount) if (deauth.tc >= nCount + stCount + apCount) deauth.tc = 0;
deauth.tc = 0;
} }
} }
} }
void Attack::probeUpdate() { void Attack::probeUpdate() {
if (probe.active && probe.maxPkts > 0 && probe.packetCounter < probe.maxPkts) { if (probe.active && (probe.maxPkts > 0) && (probe.packetCounter < probe.maxPkts)) {
if (probe.time <= currentTime - (1000 / probe.maxPkts)) { if (probe.time <= currentTime - (1000 / probe.maxPkts)) {
if (settings.getBeaconChannel()) setWifiChannel(probe.tc % settings.getMaxCh()); if (settings.getBeaconChannel()) setWifiChannel(probe.tc % settings.getMaxCh());
probe.tc += sendProbe(probe.tc); probe.tc += sendProbe(probe.tc);
if (probe.tc >= ssids.count()) probe.tc = 0; if (probe.tc >= ssids.count()) probe.tc = 0;
} }
} }
} }
void Attack::beaconUpdate() { void Attack::beaconUpdate() {
if (beacon.active && beacon.maxPkts > 0 && beacon.packetCounter < beacon.maxPkts) { if (beacon.active && (beacon.maxPkts > 0) && (beacon.packetCounter < beacon.maxPkts)) {
if (beacon.time <= currentTime - (1000 / beacon.maxPkts)) { if (beacon.time <= currentTime - (1000 / beacon.maxPkts)) {
beacon.tc += sendBeacon(beacon.tc); beacon.tc += sendBeacon(beacon.tc);
if (beacon.tc >= ssids.count()) beacon.tc = 0; if (beacon.tc >= ssids.count()) beacon.tc = 0;
} }
} }
@@ -276,6 +290,7 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
// send deauth frame // send deauth frame
deauthPacket[0] = 0xc0; deauthPacket[0] = 0xc0;
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) {
success = true; success = true;
deauth.packetCounter++; deauth.packetCounter++;
@@ -283,6 +298,7 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
// send disassociate frame // send disassociate frame
deauthPacket[0] = 0xa0; deauthPacket[0] = 0xa0;
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) {
success = true; success = true;
deauth.packetCounter++; deauth.packetCounter++;
@@ -297,6 +313,7 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
// send deauth frame // send deauth frame
deauthPacket[0] = 0xc0; deauthPacket[0] = 0xc0;
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) {
success = true; success = true;
deauth.packetCounter++; deauth.packetCounter++;
@@ -304,14 +321,14 @@ bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_
// send disassociate frame // send disassociate frame
deauthPacket[0] = 0xa0; deauthPacket[0] = 0xa0;
if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) { if (sendPacket(deauthPacket, packetSize, ch, settings.getForcePackets())) {
success = true; success = true;
deauth.packetCounter++; deauth.packetCounter++;
} }
} }
if (success) if (success) deauth.time = currentTime;
deauth.time = currentTime;
return success; return success;
} }
@@ -333,6 +350,7 @@ bool Attack::sendBeacon(uint8_t* mac, const char* ssid, uint8_t ch, bool wpa2) {
} }
int ssidLen = strlen(ssid); int ssidLen = strlen(ssid);
if (ssidLen > 32) ssidLen = 32; if (ssidLen > 32) ssidLen = 32;
memcpy(&beaconPacket[10], mac, 6); memcpy(&beaconPacket[10], mac, 6);
@@ -359,6 +377,7 @@ bool Attack::sendProbe(uint8_t tc) {
bool Attack::sendProbe(uint8_t* mac, const char* ssid, uint8_t ch) { bool Attack::sendProbe(uint8_t* mac, const char* ssid, uint8_t ch) {
packetSize = sizeof(probePacket); packetSize = sizeof(probePacket);
int ssidLen = strlen(ssid); int ssidLen = strlen(ssid);
if (ssidLen > 32) ssidLen = 32; if (ssidLen > 32) ssidLen = 32;
memcpy(&probePacket[10], mac, 6); memcpy(&probePacket[10], mac, 6);
@@ -383,11 +402,9 @@ bool Attack::sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16
bool sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0; bool sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0;
// try again until it's sent out // try again until it's sent out
for (int i = 0; i < tries && !sent; i++) for (int i = 0; i < tries && !sent; i++) sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0;
sent = wifi_send_pkt_freedom(packet, packetSize, 0) == 0;
if(sent) if (sent) tmpPacketRate++;
tmpPacketRate ++;
return sent; return sent;
} }

View File

@@ -69,6 +69,7 @@ class Attack {
uint32_t getProbeMaxPkts(); uint32_t getProbeMaxPkts();
uint32_t getPacketRate(); uint32_t getPacketRate();
private: private:
void deauthUpdate(); void deauthUpdate();
void deauthAllUpdate(); void deauthAllUpdate();
@@ -158,9 +159,11 @@ class Attack {
/* 16 - 21 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source /* 16 - 21 */ 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, // Source
// Fixed parameters // Fixed parameters
/* 22 - 23 */ 0x00, 0x00, // Fragment & sequence number (will be done by the SDK) /* 22 - 23 */ 0x00, 0x00, // Fragment & sequence number (will be done
// by the SDK)
/* 24 - 31 */ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, // Timestamp /* 24 - 31 */ 0x83, 0x51, 0xf7, 0x8f, 0x0f, 0x00, 0x00, 0x00, // Timestamp
/* 32 - 33 */ 0x64, 0x00, // Interval: 0x64, 0x00 => every 100ms - 0xe8, 0x03 => every 1s /* 32 - 33 */ 0x64, 0x00, // Interval: 0x64, 0x00 => every 100ms -
// 0xe8, 0x03 => every 1s
/* 34 - 35 */ 0x31, 0x00, // capabilities Tnformation /* 34 - 35 */ 0x31, 0x00, // capabilities Tnformation
// Tagged parameters // Tagged parameters
@@ -203,8 +206,4 @@ class Attack {
}; };
}; };
#endif #endif // ifndef Attack_h

View File

@@ -1,111 +1,36 @@
#include "DigitalLed.h" #include "DigitalLED.h"
DigitalLed::DigitalLed() {
DigitalLED::DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode) {
DigitalLED::anode = anode;
DigitalLED::rPin = rPin;
DigitalLED::gPin = gPin;
DigitalLED::bPin = bPin;
} }
// setup pins DigitalLED::~DigitalLED() {}
void DigitalLed::setup(){
if(!settings.getLedEnabled()) return;
// ===== adjustable ===== // void DigitalLED::setup() {
if(LED_ENABLE_R) pinMode(LED_PIN_R, OUTPUT); if (rPin < 255) pinMode(rPin, OUTPUT);
if(LED_ENABLE_G) pinMode(LED_PIN_G, OUTPUT);
if(LED_ENABLE_B) pinMode(LED_PIN_B, OUTPUT);
// ====================== //
setMode(LED_MODE_OFF, true); if (gPin < 255) pinMode(gPin, OUTPUT);
if (bPin < 255) pinMode(bPin, OUTPUT);
} }
void DigitalLed::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output) { void DigitalLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
// debug output if (anode) {
if (output){ if (rPin < 255) digitalWrite(rPin, r > 0);
char s[30];
sprintf(s,str(L_OUTPUT_A).c_str(), r, g, b);
prnt(String(s));
}
// ===== adjustable ===== // if (gPin < 255) digitalWrite(gPin, g > 0);
if(LED_CATHODE){
r = r>0; if (bPin < 255) digitalWrite(bPin, b > 0);
g = g>0;
b = b>0;
} else { } else {
r = !(r>0); if (rPin < 255) digitalWrite(rPin, r == 0);
g = !(g>0);
b = !(b>0);
}
if(LED_ENABLE_R) digitalWrite(LED_PIN_R, r); if (gPin < 255) digitalWrite(gPin, g == 0);
if(LED_ENABLE_G) digitalWrite(LED_PIN_G, g);
if(LED_ENABLE_B) digitalWrite(LED_PIN_B, b);
// ====================== //
// debug output if (bPin < 255) digitalWrite(bPin, b == 0);
if (output){
char s[30];
sprintf(s,str(L_OUTPUT_B).c_str(), r?255:0, g?255:0, b?255:0);
prnt(String(s));
} }
} }
// customize color codes for different LED modes void DigitalLED::setBrightness(uint8_t brightness) {}
void DigitalLed::setMode(uint8_t mode, bool force) {
// ===== adjustable ===== //
if (mode != DigitalLed::mode || force) {
DigitalLed::mode = mode;
switch (mode) {
case LED_MODE_OFF:
setColor(0, 0, 0, 100, false);
break;
case LED_MODE_SCAN:
setColor(0, 0, 255, 100, false);
break;
case LED_MODE_ATTACK:
setColor(255, 255, 0, 100, false);
break;
case LED_MODE_DEAUTH:
setColor(255, 0, 0, 100, false);
break;
case LED_MODE_IDLE:
setColor(0, 255, 0, 100, false);
break;
}
}
// ====================== //
}
void DigitalLed::tempEnable() {
tempEnabled = true;
prntln(L_ENABLED);
}
void DigitalLed::tempDisable() {
tempEnabled = false;
prntln(L_DISABLED);
}
bool DigitalLed::getTempEnabled() {
return tempEnabled;
}
void DigitalLed::setColor(uint8_t r, uint8_t g, uint8_t b) {
setColor(r, g, b, 100, true);
}
void DigitalLed::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness) {
setColor(r, g, b, brightness, true);
}
void DigitalLed::update() {
if (!tempEnabled) 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);
}

View File

@@ -1,45 +1,23 @@
#ifndef DigitalLed_h #ifndef DigitalLED_H
#define DigitalLed_h #define DigitalLED_H
#include "Arduino.h" #include "StatusLED.h"
extern "C" {
#include "user_interface.h"
}
#include "language.h"
#include "A_config.h"
#include "Settings.h"
#include "Attack.h"
#include "Scan.h"
#define LED_MODE_OFF 0 class DigitalLED : public StatusLED {
#define LED_MODE_SCAN 1
#define LED_MODE_ATTACK 2
#define LED_MODE_DEAUTH 3
#define LED_MODE_IDLE 4
extern Settings settings;
extern Attack attack;
extern Scan scan;
extern Stations stations;
class DigitalLed {
public: public:
DigitalLed(); DigitalLED(uint8_t rPin, uint8_t gPin, uint8_t bPin, bool anode);
~DigitalLED();
void setup(); void setup();
void setColor(uint8_t r, uint8_t g, uint8_t b); void setColor(uint8_t r, uint8_t g, uint8_t b);
void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness); void setBrightness(uint8_t brightness);
void setMode(uint8_t mode, bool force); void setMode(uint8_t mode, bool force);
void update();
void tempEnable();
void tempDisable();
bool getTempEnabled();
private: private:
uint8_t mode; bool anode = true;
bool tempEnabled = true; uint8_t rPin = 255;
void setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output); uint8_t gPin = 255;
uint8_t bPin = 255;
}; };
#endif #endif // ifndef DigitalLED_H

View File

@@ -1,13 +1,12 @@
#include "DisplayUI.h" #include "DisplayUI.h"
DisplayUI::DisplayUI() { DisplayUI::DisplayUI() {}
}
void DisplayUI::setupDisplay() { void DisplayUI::setupDisplay() {
// ===== adjustable ===== // // ===== adjustable ===== //
// initialize display // initialize display
display.init(); display.init();
/* /*
In case of a compiler (conversion char/uint8_t) error, In case of a compiler (conversion char/uint8_t) error,
make sure to have version 4 of the display library installed make sure to have version 4 of the display library installed
@@ -17,7 +16,7 @@ void DisplayUI::setupDisplay() {
display.setContrast(255); display.setContrast(255);
#ifndef FLIP_DIPLAY #ifndef FLIP_DIPLAY
display.flipScreenVertically(); display.flipScreenVertically();
#endif #endif // ifndef FLIP_DIPLAY
display.clear(); display.clear();
display.display(); display.display();
// ====================== // // ====================== //
@@ -54,44 +53,44 @@ void DisplayUI::setupButtons() {
#ifdef BUTTON_UP #ifdef BUTTON_UP
buttonUp.enabled = true; buttonUp.enabled = true;
buttonUp.gpio = BUTTON_UP; buttonUp.gpio = BUTTON_UP;
#else #else // ifdef BUTTON_UP
buttonUp.enabled = false; buttonUp.enabled = false;
#endif #endif // ifdef BUTTON_UP
#ifdef BUTTON_DOWN #ifdef BUTTON_DOWN
buttonDown.enabled = true; buttonDown.enabled = true;
buttonDown.gpio = BUTTON_DOWN; buttonDown.gpio = BUTTON_DOWN;
#else #else // ifdef BUTTON_DOWN
buttonDown.enabled = false; buttonDown.enabled = false;
#endif #endif // ifdef BUTTON_DOWN
#ifdef BUTTON_LEFT #ifdef BUTTON_LEFT
buttonLeft.enabled = true; buttonLeft.enabled = true;
buttonLeft.gpio = BUTTON_LEFT; buttonLeft.gpio = BUTTON_LEFT;
#else #else // ifdef BUTTON_LEFT
buttonLeft.enabled = false; buttonLeft.enabled = false;
#endif #endif // ifdef BUTTON_LEFT
#ifdef BUTTON_RIGHT #ifdef BUTTON_RIGHT
buttonRight.enabled = true; buttonRight.enabled = true;
buttonRight.gpio = BUTTON_RIGHT; buttonRight.gpio = BUTTON_RIGHT;
#else #else // ifdef BUTTON_RIGHT
buttonRight.enabled = false; buttonRight.enabled = false;
#endif #endif // ifdef BUTTON_RIGHT
#ifdef BUTTON_A #ifdef BUTTON_A
buttonA.enabled = true; buttonA.enabled = true;
buttonA.gpio = BUTTON_A; buttonA.gpio = BUTTON_A;
#else #else // ifdef BUTTON_A
buttonA.enabled = false; buttonA.enabled = false;
#endif #endif // ifdef BUTTON_A
#ifdef BUTTON_B #ifdef BUTTON_B
buttonB.enabled = true; buttonB.enabled = true;
buttonB.gpio = BUTTON_B; buttonB.gpio = BUTTON_B;
#else #else // ifdef BUTTON_B
buttonB.enabled = false; buttonB.enabled = false;
#endif #endif // ifdef BUTTON_B
// ====================== // // ====================== //
// setup and read functions // setup and read functions
@@ -156,6 +155,7 @@ void DisplayUI::setup() {
// === BUTTON UP === // // === BUTTON UP === //
buttonUp.push = [this]() { buttonUp.push = [this]() {
if (buttonUp.time > currentTime - BUTTON_DELAY) return; if (buttonUp.time > currentTime - BUTTON_DELAY) return;
buttonUp.pushed = true; buttonUp.pushed = true;
buttonUp.time = currentTime; buttonUp.time = currentTime;
scrollCounter = 0; scrollCounter = 0;
@@ -170,12 +170,14 @@ void DisplayUI::setup() {
buttonUp.release = [this]() { buttonUp.release = [this]() {
if (!buttonUp.pushed) return; if (!buttonUp.pushed) return;
buttonUp.pushed = false; buttonUp.pushed = false;
}; };
// === BUTTON DOWN === // // === BUTTON DOWN === //
buttonDown.push = [this]() { buttonDown.push = [this]() {
if (buttonDown.time > currentTime - BUTTON_DELAY) return; if (buttonDown.time > currentTime - BUTTON_DELAY) return;
buttonDown.pushed = true; buttonDown.pushed = true;
buttonDown.time = currentTime; buttonDown.time = currentTime;
scrollCounter = 0; scrollCounter = 0;
@@ -190,12 +192,14 @@ void DisplayUI::setup() {
buttonDown.release = [this]() { buttonDown.release = [this]() {
if (!buttonDown.pushed) return; if (!buttonDown.pushed) return;
buttonDown.pushed = false; buttonDown.pushed = false;
}; };
// === BUTTON LEFT === // // === BUTTON LEFT === //
buttonLeft.push = [this]() { buttonLeft.push = [this]() {
if (buttonLeft.time > currentTime - BUTTON_DELAY) return; if (buttonLeft.time > currentTime - BUTTON_DELAY) return;
buttonLeft.pushed = true; buttonLeft.pushed = true;
buttonLeft.time = currentTime; buttonLeft.time = currentTime;
scrollCounter = 0; scrollCounter = 0;
@@ -203,12 +207,14 @@ void DisplayUI::setup() {
buttonLeft.release = [this]() { buttonLeft.release = [this]() {
if (!buttonLeft.pushed) return; if (!buttonLeft.pushed) return;
buttonLeft.pushed = false; buttonLeft.pushed = false;
}; };
// === BUTTON RIGHT === // // === BUTTON RIGHT === //
buttonRight.push = [this]() { buttonRight.push = [this]() {
if (buttonRight.time > currentTime - BUTTON_DELAY) return; if (buttonRight.time > currentTime - BUTTON_DELAY) return;
buttonRight.pushed = true; buttonRight.pushed = true;
buttonRight.time = currentTime; buttonRight.time = currentTime;
scrollCounter = 0; scrollCounter = 0;
@@ -216,6 +222,7 @@ void DisplayUI::setup() {
buttonRight.release = [this]() { buttonRight.release = [this]() {
if (!buttonRight.pushed) return; if (!buttonRight.pushed) return;
buttonRight.pushed = false; buttonRight.pushed = false;
}; };
@@ -226,8 +233,9 @@ void DisplayUI::setup() {
buttonA.time = currentTime; buttonA.time = currentTime;
scrollCounter = 0; scrollCounter = 0;
} else { // holding button } else { // holding button
if(currentTime - buttonA.time > 800 && !buttonA.hold){ if ((currentTime - buttonA.time > 800) && !buttonA.hold) {
if(currentMenu->list->get(currentMenu->selected).hold) currentMenu->list->get(currentMenu->selected).hold(); if (currentMenu->list->get(currentMenu->selected).hold) currentMenu->list->get(
currentMenu->selected).hold();
buttonA.hold = true; buttonA.hold = true;
} }
} }
@@ -236,13 +244,15 @@ void DisplayUI::setup() {
buttonA.release = [this]() { buttonA.release = [this]() {
if (!buttonA.pushed) return; // exit when button wasn't pushed before if (!buttonA.pushed) return; // exit when button wasn't pushed before
if(!buttonA.hold && currentTime - buttonA.time > 80){ if (!buttonA.hold && (currentTime - buttonA.time > 80)) {
switch (mode) { switch (mode) {
case SCREEN_MODE_MENU: case SCREEN_MODE_MENU:
if (currentMenu->list->get(currentMenu->selected).click) { if (currentMenu->list->get(currentMenu->selected).click) {
currentMenu->list->get(currentMenu->selected).click(); currentMenu->list->get(currentMenu->selected).click();
} }
break; break;
case SCREEN_MODE_PACKETMONITOR: case SCREEN_MODE_PACKETMONITOR:
case SCREEN_MODE_LOADSCAN: case SCREEN_MODE_LOADSCAN:
scan.stop(); scan.stop();
@@ -257,7 +267,8 @@ void DisplayUI::setup() {
// === BUTTON B === // // === BUTTON B === //
buttonB.push = [this]() { buttonB.push = [this]() {
if(!buttonB.pushed && buttonB.time > currentTime - BUTTON_DELAY) return; if (!buttonB.pushed && (buttonB.time > currentTime - BUTTON_DELAY)) return;
buttonB.pushed = true; buttonB.pushed = true;
buttonB.time = currentTime; buttonB.time = currentTime;
scrollCounter = 0; scrollCounter = 0;
@@ -270,6 +281,7 @@ void DisplayUI::setup() {
case SCREEN_MODE_MENU: case SCREEN_MODE_MENU:
goBack(); goBack();
break; break;
case SCREEN_MODE_PACKETMONITOR: case SCREEN_MODE_PACKETMONITOR:
case SCREEN_MODE_LOADSCAN: case SCREEN_MODE_LOADSCAN:
scan.stop(); scan.stop();
@@ -283,10 +295,15 @@ void DisplayUI::setup() {
// === RUN SETUPS === // // === RUN SETUPS === //
// setting pin modes for buttons // setting pin modes for buttons
if (buttonUp.enabled && buttonUp.setup) buttonUp.setup(); if (buttonUp.enabled && buttonUp.setup) buttonUp.setup();
if (buttonDown.enabled && buttonDown.setup) buttonDown.setup(); if (buttonDown.enabled && buttonDown.setup) buttonDown.setup();
if (buttonLeft.enabled && buttonLeft.setup) buttonLeft.setup(); if (buttonLeft.enabled && buttonLeft.setup) buttonLeft.setup();
if (buttonRight.enabled && buttonRight.setup) buttonRight.setup(); if (buttonRight.enabled && buttonRight.setup) buttonRight.setup();
if (buttonA.enabled && buttonA.setup) buttonA.setup(); if (buttonA.enabled && buttonA.setup) buttonA.setup();
if (buttonB.enabled && buttonB.setup) buttonB.setup(); if (buttonB.enabled && buttonB.setup) buttonB.setup();
// ===== MENUS ===== // // ===== MENUS ===== //
@@ -338,6 +355,7 @@ void DisplayUI::setup() {
createMenu(&apListMenu, &showMenu, [this]() { createMenu(&apListMenu, &showMenu, [this]() {
// add APs to list // add APs to list
int c = accesspoints.count(); int c = accesspoints.count();
for (int i = 0; i < c; i++) { for (int i = 0; i < c; i++) {
addMenuNode(&apListMenu, [i]() { addMenuNode(&apListMenu, [i]() {
return b2a(accesspoints.getSelected(i)) + accesspoints.getSSID(i); return b2a(accesspoints.getSelected(i)) + accesspoints.getSSID(i);
@@ -366,9 +384,11 @@ void DisplayUI::setup() {
createMenu(&stationListMenu, &showMenu, [this]() { createMenu(&stationListMenu, &showMenu, [this]() {
// add stations to list // add stations to list
int c = stations.count(); int c = stations.count();
for (int i = 0; i < c; i++) { for (int i = 0; i < c; i++) {
addMenuNode(&stationListMenu, [i]() { addMenuNode(&stationListMenu, [i]() {
return b2a(stations.getSelected(i)) + (stations.hasName(i) ? stations.getNameStr(i) : stations.getMacVendorStr(i)); return b2a(stations.getSelected(i)) +
(stations.hasName(i) ? stations.getNameStr(i) : stations.getMacVendorStr(i));
}, [this, i]() { }, [this, i]() {
stations.getSelected(i) ? stations.deselect(i) : stations.select(i); stations.getSelected(i) ? stations.deselect(i) : stations.select(i);
}, [this, i]() { }, [this, i]() {
@@ -395,6 +415,7 @@ void DisplayUI::setup() {
createMenu(&nameListMenu, &showMenu, [this]() { createMenu(&nameListMenu, &showMenu, [this]() {
// add device names to list // add device names to list
int c = names.count(); int c = names.count();
for (int i = 0; i < c; i++) { for (int i = 0; i < c; i++) {
addMenuNode(&nameListMenu, [i]() { addMenuNode(&nameListMenu, [i]() {
return names.getSelectedStr(i) + names.getName(i); return names.getSelectedStr(i) + names.getName(i);
@@ -436,6 +457,7 @@ void DisplayUI::setup() {
// add ssids to list // add ssids to list
int c = ssids.count(); int c = ssids.count();
for (int i = 0; i < c; i++) { for (int i = 0; i < c; i++) {
addMenuNode(&ssidListMenu, [i]() { addMenuNode(&ssidListMenu, [i]() {
return ssids.getName(i).substring(0, ssids.getLen(i)); return ssids.getName(i).substring(0, ssids.getLen(i));
@@ -497,7 +519,9 @@ void DisplayUI::setup() {
// STATION MENU // STATION MENU
createMenu(&stationMenu, &stationListMenu, [this]() { createMenu(&stationMenu, &stationListMenu, [this]() {
addMenuNode(&stationMenu, [this]() { addMenuNode(&stationMenu, [this]() {
return stations.getSelectedStr(selectedID) + (stations.hasName(selectedID) ? stations.getNameStr(selectedID) : stations.getMacVendorStr(selectedID)); // <station name> return stations.getSelectedStr(selectedID) +
(stations.hasName(selectedID) ? stations.getNameStr(selectedID) : stations.getMacVendorStr(selectedID)); // <station
// name>
}, [this]() { }, [this]() {
stations.getSelected(selectedID) ? stations.deselect(selectedID) : stations.select(selectedID); stations.getSelected(selectedID) ? stations.deselect(selectedID) : stations.select(selectedID);
}); });
@@ -511,6 +535,7 @@ void DisplayUI::setup() {
return str(D_AP) + stations.getAPStr(selectedID); // AP: someAP return str(D_AP) + stations.getAPStr(selectedID); // AP: someAP
}, [this]() { }, [this]() {
int apID = accesspoints.find(stations.getAP(selectedID)); int apID = accesspoints.find(stations.getAP(selectedID));
if (apID >= 0) { if (apID >= 0) {
selectedID = apID; selectedID = apID;
changeMenu(&apMenu); changeMenu(&apMenu);
@@ -590,37 +615,51 @@ void DisplayUI::setup() {
// ATTACK MENU // ATTACK MENU
createMenu(&attackMenu, &mainMenu, [this]() { createMenu(&attackMenu, &mainMenu, [this]() {
addMenuNode(&attackMenu, [this]() { // *DEAUTH 0/0 addMenuNode(&attackMenu, [this]() { // *DEAUTH 0/0
if(attack.isRunning()) return buildString(b2a(deauthSelected) + str(D_DEAUTH), (String)attack.getDeauthPkts() + SLASH + (String)attack.getDeauthMaxPkts(), CHARS_PER_LINE); if (attack.isRunning()) return buildString(b2a(deauthSelected) + str(D_DEAUTH),
(String)attack.getDeauthPkts() + SLASH +
(String)attack.getDeauthMaxPkts(), CHARS_PER_LINE);
else return buildString(b2a(deauthSelected) + str(D_DEAUTH), (String)scan.countSelected(), CHARS_PER_LINE); else return buildString(b2a(deauthSelected) + str(D_DEAUTH), (String)scan.countSelected(), CHARS_PER_LINE);
}, [this]() { // deauth }, [this]() { // deauth
deauthSelected = !deauthSelected; deauthSelected = !deauthSelected;
if (attack.isRunning()) { if (attack.isRunning()) {
attack.start(beaconSelected, deauthSelected, false, probeSelected, true, settings.getAttackTimeout() * 1000); attack.start(beaconSelected, deauthSelected, false, probeSelected, true,
settings.getAttackTimeout() * 1000);
} }
}); });
addMenuNode(&attackMenu, [this]() { // *BEACON 0/0 addMenuNode(&attackMenu, [this]() { // *BEACON 0/0
if(attack.isRunning()) return buildString(b2a(beaconSelected) + str(D_BEACON), (String)attack.getBeaconPkts() + SLASH + (String)attack.getBeaconMaxPkts(), CHARS_PER_LINE); if (attack.isRunning()) return buildString(b2a(beaconSelected) + str(D_BEACON),
(String)attack.getBeaconPkts() + SLASH +
(String)attack.getBeaconMaxPkts(), CHARS_PER_LINE);
else return buildString(b2a(beaconSelected) + str(D_BEACON), (String)ssids.count(), CHARS_PER_LINE); else return buildString(b2a(beaconSelected) + str(D_BEACON), (String)ssids.count(), CHARS_PER_LINE);
}, [this]() { // beacon }, [this]() { // beacon
beaconSelected = !beaconSelected; beaconSelected = !beaconSelected;
if (attack.isRunning()) { if (attack.isRunning()) {
attack.start(beaconSelected, deauthSelected, false, probeSelected, true, settings.getAttackTimeout() * 1000); attack.start(beaconSelected, deauthSelected, false, probeSelected, true,
settings.getAttackTimeout() * 1000);
} }
}); });
addMenuNode(&attackMenu, [this]() { // *PROBE 0/0 addMenuNode(&attackMenu, [this]() { // *PROBE 0/0
if(attack.isRunning()) return buildString(b2a(probeSelected) + str(D_PROBE), (String)attack.getProbePkts() + SLASH + (String)attack.getProbeMaxPkts(), CHARS_PER_LINE); if (attack.isRunning()) return buildString(b2a(probeSelected) + str(D_PROBE),
(String)attack.getProbePkts() + SLASH +
(String)attack.getProbeMaxPkts(), CHARS_PER_LINE);
else return buildString(b2a(probeSelected) + str(D_PROBE), (String)ssids.count(), CHARS_PER_LINE); else return buildString(b2a(probeSelected) + str(D_PROBE), (String)ssids.count(), CHARS_PER_LINE);
}, [this]() { // probe }, [this]() { // probe
probeSelected = !probeSelected; probeSelected = !probeSelected;
if (attack.isRunning()) { if (attack.isRunning()) {
attack.start(beaconSelected, deauthSelected, false, probeSelected, true, settings.getAttackTimeout() * 1000); attack.start(beaconSelected, deauthSelected, false, probeSelected, true,
settings.getAttackTimeout() * 1000);
} }
}); });
addMenuNode(&attackMenu, []() { // START addMenuNode(&attackMenu, []() { // START
return buildString(str(attack.isRunning() ? D_STOP_ATTACK : D_START_ATTACK), attack.getPacketRate() > 0 ? (String)attack.getPacketRate() : String(), CHARS_PER_LINE); return buildString(str(attack.isRunning() ? D_STOP_ATTACK : D_START_ATTACK),
attack.getPacketRate() > 0 ? (String)attack.getPacketRate() : String(), CHARS_PER_LINE);
}, [this]() { }, [this]() {
if (attack.isRunning()) attack.stop(); if (attack.isRunning()) attack.stop();
else attack.start(beaconSelected, deauthSelected, false, probeSelected, true, settings.getAttackTimeout() * 1000); else attack.start(beaconSelected, deauthSelected, false, probeSelected, true,
settings.getAttackTimeout() * 1000);
}); });
}); });
@@ -645,14 +684,16 @@ void DisplayUI::update() {
else { else {
// timeout to save display life // timeout to save display life
if (mode == SCREEN_MODE_MENU && settings.getDisplayTimeout() > 0 && currentTime > settings.getDisplayTimeout() * 1000) { if ((mode == SCREEN_MODE_MENU) && (settings.getDisplayTimeout() > 0) &&
(currentTime > settings.getDisplayTimeout() * 1000)) {
uint32_t buttonTimeout = currentTime - settings.getDisplayTimeout() * 1000; uint32_t buttonTimeout = currentTime - settings.getDisplayTimeout() * 1000;
if (buttonUp.time < buttonTimeout
&& buttonDown.time < buttonTimeout if ((buttonUp.time < buttonTimeout)
&& buttonLeft.time < buttonTimeout && (buttonDown.time < buttonTimeout)
&& buttonRight.time < buttonTimeout && (buttonLeft.time < buttonTimeout)
&& buttonA.time < buttonTimeout && (buttonRight.time < buttonTimeout)
&& buttonB.time < buttonTimeout) { && (buttonA.time < buttonTimeout)
&& (buttonB.time < buttonTimeout)) {
off(); off();
} }
} }
@@ -669,7 +710,7 @@ void DisplayUI::update() {
} }
void DisplayUI::draw() { void DisplayUI::draw() {
if (currentTime - drawTime > DRAW_INTERVAL && currentMenu) { if ((currentTime - drawTime > DRAW_INTERVAL) && currentMenu) {
drawTime = currentTime; drawTime = currentTime;
// ===== adjustable ===== // // ===== adjustable ===== //
@@ -681,16 +722,21 @@ void DisplayUI::draw() {
case SCREEN_MODE_BUTTON_TEST: case SCREEN_MODE_BUTTON_TEST:
drawButtonTest(); drawButtonTest();
break; break;
case SCREEN_MODE_MENU: case SCREEN_MODE_MENU:
drawMenu(); drawMenu();
break; break;
case SCREEN_MODE_LOADSCAN: case SCREEN_MODE_LOADSCAN:
drawLoadingScan(); drawLoadingScan();
break; break;
case SCREEN_MODE_PACKETMONITOR: case SCREEN_MODE_PACKETMONITOR:
drawPacketMonitor(); drawPacketMonitor();
break; break;
case SCREEN_MODE_INTRO: case SCREEN_MODE_INTRO:
if (currentTime - startTime >= SCREEN_INTRO_TIME) { if (currentTime - startTime >= SCREEN_INTRO_TIME) {
mode = SCREEN_MODE_MENU; mode = SCREEN_MODE_MENU;
} }
@@ -713,10 +759,15 @@ void DisplayUI::drawString(int x, int y, String str) {
void DisplayUI::drawButtonTest() { void DisplayUI::drawButtonTest() {
// ===== adjustable ===== // // ===== adjustable ===== //
if (buttonUp.enabled) display.drawString(0, 0, str(D_UP) + b2s(buttonUp.pushed)); if (buttonUp.enabled) display.drawString(0, 0, str(D_UP) + b2s(buttonUp.pushed));
if (buttonDown.enabled) display.drawString(0, 9, str(D_DOWN) + b2s(buttonDown.pushed)); if (buttonDown.enabled) display.drawString(0, 9, str(D_DOWN) + b2s(buttonDown.pushed));
if (buttonLeft.enabled) display.drawString(0, 18, str(D_LEFT) + b2s(buttonLeft.pushed)); if (buttonLeft.enabled) display.drawString(0, 18, str(D_LEFT) + b2s(buttonLeft.pushed));
if (buttonRight.enabled) display.drawString(0, 27, str(D_RIGHT) + b2s(buttonRight.pushed)); if (buttonRight.enabled) display.drawString(0, 27, str(D_RIGHT) + b2s(buttonRight.pushed));
if (buttonA.enabled) display.drawString(0, 36, str(D_A) + b2s(buttonA.pushed)); if (buttonA.enabled) display.drawString(0, 36, str(D_A) + b2s(buttonA.pushed));
if (buttonB.enabled) display.drawString(0, 45, str(D_B) + b2s(buttonB.pushed)); if (buttonB.enabled) display.drawString(0, 45, str(D_B) + b2s(buttonB.pushed));
// ====================== // // ====================== //
} }
@@ -736,9 +787,10 @@ void DisplayUI::drawMenu() {
tmpLen = tmp.length(); tmpLen = tmp.length();
// horizontal scrolling // horizontal scrolling
if (currentMenu->selected == i && tmpLen > CHARS_PER_LINE) { if ((currentMenu->selected == i) && (tmpLen > CHARS_PER_LINE)) {
tmp = tmp.substring(scrollCounter / SCROLL_SPEED); tmp = tmp.substring(scrollCounter / SCROLL_SPEED);
scrollCounter++; scrollCounter++;
if (scrollCounter / SCROLL_SPEED > tmpLen - CHARS_PER_LINE) scrollCounter = 0; if (scrollCounter / SCROLL_SPEED > tmpLen - CHARS_PER_LINE) scrollCounter = 0;
} }
@@ -751,7 +803,9 @@ void DisplayUI::drawLoadingScan() {
// ===== adjustable ===== // // ===== adjustable ===== //
if (scan.isScanning()) { if (scan.isScanning()) {
if (scan.isSniffing()) { // Scanning for Stations if (scan.isSniffing()) { // Scanning for Stations
display.drawString(2, 0, buildString(str(D_LOADING_SCREEN_0), (String)scan.getPercentage() + PERCENT, CHARS_PER_LINE)); display.drawString(2, 0,
buildString(str(D_LOADING_SCREEN_0), (String)scan.getPercentage() + PERCENT,
CHARS_PER_LINE));
display.drawProgressBar(5, 22, 118, 8, scan.getPercentage()); display.drawProgressBar(5, 22, 118, 8, scan.getPercentage());
display.drawString(2, 36, str(D_LOADING_SCREEN_1) + (String)accesspoints.count()); display.drawString(2, 36, str(D_LOADING_SCREEN_1) + (String)accesspoints.count());
display.drawString(2, 50, str(D_LOADING_SCREEN_2) + (String)stations.count()); display.drawString(2, 50, str(D_LOADING_SCREEN_2) + (String)stations.count());
@@ -769,11 +823,13 @@ void DisplayUI::drawLoadingScan() {
void DisplayUI::drawPacketMonitor() { void DisplayUI::drawPacketMonitor() {
// ===== adjustable ===== // // ===== adjustable ===== //
double scale = scan.getScaleFactor(50); double scale = scan.getScaleFactor(50);
display.drawString(0, 0, str(D_CH) + String(wifi_channel)); display.drawString(0, 0, str(D_CH) + String(wifi_channel));
display.drawString(40, 0, str(D_PKTS) + String(scan.getPacketRate())); display.drawString(40, 0, str(D_PKTS) + String(scan.getPacketRate()));
display.setTextAlignment(TEXT_ALIGN_RIGHT); display.setTextAlignment(TEXT_ALIGN_RIGHT);
display.drawString(128, 0, String(scan.deauths)); display.drawString(128, 0, String(scan.deauths));
display.setTextAlignment(TEXT_ALIGN_LEFT); display.setTextAlignment(TEXT_ALIGN_LEFT);
if (scan.getMaxPacket() > 0) { if (scan.getMaxPacket() > 0) {
for (int i = 0; i < SCAN_PACKET_LIST_SIZE * 2; i += 2) { for (int i = 0; i < SCAN_PACKET_LIST_SIZE * 2; i += 2) {
display.drawLine(i, 64, i, 64 - scan.getPackets(i / 2) * scale); display.drawLine(i, 64, i, 64 - scan.getPackets(i / 2) * scale);
@@ -816,20 +872,24 @@ void DisplayUI::clearMenu(Menu* menu) {
void DisplayUI::changeMenu(Menu* menu) { void DisplayUI::changeMenu(Menu* menu) {
if (menu) { if (menu) {
// only open list menu if it has nodes // only open list menu if it has nodes
if((menu == &apListMenu && accesspoints.count() == 0) || if (((menu == &apListMenu) && (accesspoints.count() == 0)) ||
(menu == &stationListMenu && stations.count() == 0) || ((menu == &stationListMenu) && (stations.count() == 0)) ||
(menu == &nameListMenu && names.count() == 0)){ ((menu == &nameListMenu) && (names.count() == 0))) {
return; return;
} }
if (currentMenu) clearMenu(currentMenu); if (currentMenu) clearMenu(currentMenu);
currentMenu = menu; currentMenu = menu;
currentMenu->selected = 0; currentMenu->selected = 0;
buttonA.time = currentTime; buttonA.time = currentTime;
if (selectedID < 0) selectedID = 0; if (selectedID < 0) selectedID = 0;
if (currentMenu->parentMenu) { if (currentMenu->parentMenu) {
addMenuNode(currentMenu, D_BACK, currentMenu->parentMenu); // add [BACK] addMenuNode(currentMenu, D_BACK, currentMenu->parentMenu); // add [BACK]
currentMenu->selected = 1; currentMenu->selected = 1;
} }
if (currentMenu->build) currentMenu->build(); if (currentMenu->build) currentMenu->build();
} }
} }
@@ -845,7 +905,8 @@ void DisplayUI::createMenu(Menu* menu, Menu* parent, std::function<void()> build
menu->build = build; menu->build = build;
} }
void DisplayUI::addMenuNode(Menu* menu, std::function<String()> getStr, std::function<void()> click, std::function<void()> hold) { void DisplayUI::addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click,
std::function<void()>hold) {
menu->list->add(MenuNode{ getStr, click, hold }); menu->list->add(MenuNode{ getStr, click, hold });
} }
@@ -870,5 +931,3 @@ void DisplayUI::addMenuNode(Menu* menu, const char* ptr, Menu* next) {
return str(ptr); return str(ptr);
}, next); }, next);
} }

View File

@@ -16,7 +16,6 @@ extern "C" {
#include "Attack.h" #include "Attack.h"
extern Settings settings; extern Settings settings;
extern Names names; extern Names names;
extern SSIDs ssids; extern SSIDs ssids;
@@ -83,6 +82,7 @@ class DisplayUI {
void off(); void off();
uint8_t mode = SCREEN_MODE_MENU; uint8_t mode = SCREEN_MODE_MENU;
private: private:
DEAUTHER_DISPLAY // see config.h DEAUTHER_DISPLAY // see config.h
@@ -125,7 +125,8 @@ class DisplayUI {
void goBack(); void goBack();
void createMenu(Menu* menu, Menu* parent, std::function<void()>build); void createMenu(Menu* menu, Menu* parent, std::function<void()>build);
void addMenuNode(Menu* menu, std::function<String()> getStr, std::function<void()> click, std::function<void()> hold); void addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click,
std::function<void()>hold);
void addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click); void addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click);
void addMenuNode(Menu* menu, std::function<String()>getStr, Menu* next); void addMenuNode(Menu* menu, std::function<String()>getStr, Menu* next);
void addMenuNode(Menu* menu, const char* ptr, std::function<void()>click); void addMenuNode(Menu* menu, const char* ptr, std::function<void()>click);
@@ -611,5 +612,4 @@ const uint8_t DejaVu_Sans_Mono_12[] PROGMEM = {
0x00, 0x00, 0x60, 0x40, 0x88, 0x67, 0x00, 0x1C, 0x88, 0x03, 0x60 // 255 0x00, 0x00, 0x60, 0x40, 0x88, 0x67, 0x00, 0x1C, 0x88, 0x03, 0x60 // 255
}; };
#endif #endif // ifndef DisplayUI_h

View File

@@ -0,0 +1,103 @@
#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 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 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;
}

View File

@@ -0,0 +1,49 @@
#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 "StatusLED.h"
#include "DigitalLED.h"
#include "NeopixelLED.h"
#include "AnalogRGBLED.h"
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:
bool tempEnabled = true;
uint8_t mode = LED_MODE::OFF;
StatusLED* led = NULL;
};
#endif // ifndef LEDController_h

View File

@@ -14,7 +14,8 @@ void Names::load() {
for (uint32_t i = 0; i < arr.size() && i < NAME_LIST_SIZE; i++) { for (uint32_t i = 0; i < arr.size() && i < NAME_LIST_SIZE; i++) {
JsonArray& tmpArray = arr.get<JsonVariant>(i); JsonArray& tmpArray = arr.get<JsonVariant>(i);
internal_add(tmpArray.get<String>(0), tmpArray.get<String>(2), tmpArray.get<String>(3), tmpArray.get<uint8_t>(4), false); internal_add(tmpArray.get<String>(0), tmpArray.get<String>(2), tmpArray.get<String>(3), tmpArray.get<uint8_t>(
4), false);
sort(); sort();
} }
@@ -24,6 +25,7 @@ void Names::load() {
void Names::load(String filepath) { void Names::load(String filepath) {
String tmp = FILE_PATH; String tmp = FILE_PATH;
FILE_PATH = filepath; FILE_PATH = filepath;
load(); load();
FILE_PATH = tmp; FILE_PATH = tmp;
@@ -32,6 +34,7 @@ void Names::load(String filepath) {
void Names::save(bool force) { void Names::save(bool force) {
if (!force && !changed) { if (!force && !changed) {
return; return;
prntln(N_SAVED); prntln(N_SAVED);
} }
@@ -57,6 +60,7 @@ void Names::save(bool force) {
buf += String(DOUBLEQUOTES) + getBssidStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "00:11:22:00:11:22", buf += String(DOUBLEQUOTES) + getBssidStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "00:11:22:00:11:22",
buf += String(getCh(i)) + String(COMMA); // 1, buf += String(getCh(i)) + String(COMMA); // 1,
buf += b2s(getSelected(i)) + String(CLOSE_BRACKET); // false] buf += b2s(getSelected(i)) + String(CLOSE_BRACKET); // false]
if (i < c - 1) buf += COMMA; // , if (i < c - 1) buf += COMMA; // ,
if (buf.length() >= 1024) { if (buf.length() >= 1024) {
@@ -85,6 +89,7 @@ void Names::save(bool force) {
void Names::save(bool force, String filepath) { void Names::save(bool force, String filepath) {
String tmp = FILE_PATH; String tmp = FILE_PATH;
FILE_PATH = filepath; FILE_PATH = filepath;
save(force); save(force);
FILE_PATH = tmp; FILE_PATH = tmp;
@@ -104,6 +109,7 @@ void Names::removeAll() {
bool Names::check(int num) { bool Names::check(int num) {
if (internal_check(num)) return true; if (internal_check(num)) return true;
prnt(N_ERROR_NOT_FOUND); prnt(N_ERROR_NOT_FOUND);
prntln(num); prntln(num);
return false; return false;
@@ -112,15 +118,14 @@ bool Names::check(int num) {
int Names::findID(uint8_t* mac) { int Names::findID(uint8_t* mac) {
return list->binSearch([mac](Device& a) -> int { return list->binSearch([mac](Device& a) -> int {
return memcmp(mac, a.mac, 6); return memcmp(mac, a.mac, 6);
},0,count()-1); });
} }
String Names::find(uint8_t* mac) { String Names::find(uint8_t* mac) {
int num = findID(mac); int num = findID(mac);
if (num >= 0)
return getName(num); if (num >= 0) return getName(num);
else else return String();
return String();
} }
void Names::print(int num) { void Names::print(int num) {
@@ -129,6 +134,7 @@ void Names::print(int num) {
void Names::print(int num, bool header, bool footer) { void Names::print(int num, bool header, bool footer) {
if (!check(num)) return; if (!check(num)) return;
if (header) { if (header) {
prntln(N_TABLE_HEADER); prntln(N_TABLE_HEADER);
prntln(N_TABLE_DIVIDER); prntln(N_TABLE_DIVIDER);
@@ -142,18 +148,16 @@ void Names::print(int num, bool header, bool footer) {
prnt(buildString(String(SPACE), (String)getCh(num), 3)); prnt(buildString(String(SPACE), (String)getCh(num), 3));
prntln(buildString(String(SPACE) + getSelectedStr(num), String(), 9)); prntln(buildString(String(SPACE) + getSelectedStr(num), String(), 9));
if (footer) if (footer) prntln(N_TABLE_DIVIDER);
prntln(N_TABLE_DIVIDER);
} }
void Names::printAll() { void Names::printAll() {
prntln(N_HEADER); prntln(N_HEADER);
int c = count(); int c = count();
if (c == 0)
prntln(N_ERROR_LIST_EMPTY); if (c == 0) prntln(N_ERROR_LIST_EMPTY);
else else
for (int i = 0; i < c; i++) for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
print(i, i == 0, i == c - 1);
} }
void Names::printSelected() { void Names::printSelected() {
@@ -176,8 +180,7 @@ void Names::printSelected() {
void Names::add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool selected, bool force) { void Names::add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool selected, bool force) {
if (count() >= NAME_LIST_SIZE) { if (count() >= NAME_LIST_SIZE) {
if (force) if (force) internal_remove(0);
internal_remove(0);
else { else {
prntln(N_ERROR_LIST_FULL); prntln(N_ERROR_LIST_FULL);
return; return;
@@ -196,8 +199,7 @@ void Names::add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool sele
void Names::add(String macStr, String name, String bssidStr, uint8_t ch, bool selected, bool force) { void Names::add(String macStr, String name, String bssidStr, uint8_t ch, bool selected, bool force) {
if (count() >= NAME_LIST_SIZE) { if (count() >= NAME_LIST_SIZE) {
if (force) if (force) internal_remove(0);
internal_remove(0);
else { else {
prntln(N_ERROR_LIST_FULL); prntln(N_ERROR_LIST_FULL);
return; return;
@@ -216,6 +218,7 @@ void Names::add(String macStr, String name, String bssidStr, uint8_t ch, bool se
void Names::replace(int num, String macStr, String name, String bssidStr, uint8_t ch, bool selected) { void Names::replace(int num, String macStr, String name, String bssidStr, uint8_t ch, bool selected) {
if (!check(num)) return; if (!check(num)) return;
remove(num); remove(num);
internal_add(macStr, name, bssidStr, ch, selected); internal_add(macStr, name, bssidStr, ch, selected);
@@ -227,6 +230,7 @@ void Names::replace(int num, String macStr, String name, String bssidStr, uint8_
void Names::remove(int num) { void Names::remove(int num) {
if (!check(num)) return; if (!check(num)) return;
prnt(N_REMOVED); prnt(N_REMOVED);
prntln(getName(num)); prntln(getName(num));
internal_remove(num); internal_remove(num);
@@ -235,6 +239,7 @@ void Names::remove(int num) {
void Names::setName(int num, String name) { void Names::setName(int num, String name) {
if (!check(num)) return; if (!check(num)) return;
internal_add(getMac(num), name, getBssid(num), getCh(num), getSelected(num)); internal_add(getMac(num), name, getBssid(num), getCh(num), getSelected(num));
prntln(N_CHANGED_NAME); prntln(N_CHANGED_NAME);
@@ -246,6 +251,7 @@ void Names::setName(int num, String name) {
void Names::setMac(int num, String macStr) { void Names::setMac(int num, String macStr) {
if (!check(num)) return; if (!check(num)) return;
uint8_t mac[6]; uint8_t mac[6];
strToMac(macStr, mac); strToMac(macStr, mac);
internal_add(mac, getName(num), getBssid(num), getCh(num), getSelected(num)); internal_add(mac, getName(num), getBssid(num), getCh(num), getSelected(num));
@@ -257,6 +263,7 @@ void Names::setMac(int num, String macStr) {
void Names::setCh(int num, uint8_t ch) { void Names::setCh(int num, uint8_t ch) {
if (!check(num)) return; if (!check(num)) return;
internal_add(getMac(num), getName(num), getBssid(num), ch, getSelected(num)); internal_add(getMac(num), getName(num), getBssid(num), ch, getSelected(num));
prntln(N_CHANGED_CH); prntln(N_CHANGED_CH);
internal_remove(num); internal_remove(num);
@@ -266,6 +273,7 @@ void Names::setCh(int num, uint8_t ch) {
void Names::setBSSID(int num, String bssidStr) { void Names::setBSSID(int num, String bssidStr) {
if (!check(num)) return; if (!check(num)) return;
uint8_t mac[6]; uint8_t mac[6];
strToMac(bssidStr, mac); strToMac(bssidStr, mac);
internal_add(getMac(num), getName(num), mac, getCh(num), getSelected(num)); internal_add(getMac(num), getName(num), mac, getCh(num), getSelected(num));
@@ -277,6 +285,7 @@ void Names::setBSSID(int num, String bssidStr) {
void Names::select(int num) { void Names::select(int num) {
if (!check(num)) return; if (!check(num)) return;
internal_select(num); internal_select(num);
prnt(N_SELECTED); prnt(N_SELECTED);
prntln(getName(num)); prntln(getName(num));
@@ -285,6 +294,7 @@ void Names::select(int num) {
void Names::select(String name) { void Names::select(String name) {
int c = count(); int c = count();
for (int i = 0; i < c; i++) { for (int i = 0; i < c; i++) {
if (getName(i).equals(name)) { if (getName(i).equals(name)) {
select(i); select(i);
@@ -297,6 +307,7 @@ void Names::select(String name) {
void Names::deselect(int num) { void Names::deselect(int num) {
if (!check(num)) return; if (!check(num)) return;
internal_deselect(num); internal_deselect(num);
prnt(N_DESELECTED); prnt(N_DESELECTED);
prntln(getName(num)); prntln(getName(num));
@@ -305,6 +316,7 @@ void Names::deselect(int num) {
void Names::deselect(String name) { void Names::deselect(String name) {
int c = count(); int c = count();
for (int i = 0; i < c; i++) { for (int i = 0; i < c; i++) {
if (getName(i).equals(name)) { if (getName(i).equals(name)) {
deselect(i); deselect(i);
@@ -317,46 +329,53 @@ void Names::deselect(String name) {
void Names::selectAll() { void Names::selectAll() {
int c = count(); int c = count();
for (int i = 0; i < c; i++)
internal_select(i); for (int i = 0; i < c; i++) internal_select(i);
prntln(N_SELECTED_ALL); prntln(N_SELECTED_ALL);
} }
void Names::deselectAll() { void Names::deselectAll() {
int c = count(); int c = count();
for (int i = 0; i < c; i++)
internal_deselect(i); for (int i = 0; i < c; i++) internal_deselect(i);
prntln(N_DESELECTED_ALL); prntln(N_DESELECTED_ALL);
} }
uint8_t* Names::getMac(int num) { uint8_t* Names::getMac(int num) {
if (!check(num)) return NULL; if (!check(num)) return NULL;
return list->get(num).mac; return list->get(num).mac;
} }
uint8_t* Names::getBssid(int num) { uint8_t* Names::getBssid(int num) {
if (!check(num)) return NULL; if (!check(num)) return NULL;
return list->get(num).apBssid; return list->get(num).apBssid;
} }
String Names::getMacStr(int num) { String Names::getMacStr(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
uint8_t* mac = getMac(num); uint8_t* mac = getMac(num);
return bytesToStr(mac, 6); return bytesToStr(mac, 6);
} }
String Names::getVendorStr(int num) { String Names::getVendorStr(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
return searchVendor(list->get(num).mac); return searchVendor(list->get(num).mac);
} }
String Names::getBssidStr(int num) { String Names::getBssidStr(int num) {
String value; String value;
if (getBssid(num) != NULL) { if (getBssid(num) != NULL) {
uint8_t* mac = getBssid(num); uint8_t* mac = getBssid(num);
for (int i = 0; i < 6; i++) { for (int i = 0; i < 6; i++) {
if (mac[i] < 0x10) value += ZERO; if (mac[i] < 0x10) value += ZERO;
value += String(mac[i], HEX); value += String(mac[i], HEX);
if (i < 5) value += DOUBLEPOINT; if (i < 5) value += DOUBLEPOINT;
} }
} }
@@ -365,6 +384,7 @@ String Names::getBssidStr(int num) {
String Names::getName(int num) { String Names::getName(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
return String(list->get(num).name); return String(list->get(num).name);
} }
@@ -374,11 +394,13 @@ String Names::getSelectedStr(int num) {
uint8_t Names::getCh(int num) { uint8_t Names::getCh(int num) {
if (!check(num)) return 1; if (!check(num)) return 1;
return list->get(num).ch; return list->get(num).ch;
} }
bool Names::getSelected(int num) { bool Names::getSelected(int num) {
if (!check(num)) return false; if (!check(num)) return false;
return list->get(num).selected; return list->get(num).selected;
} }
@@ -392,6 +414,7 @@ int Names::count() {
int Names::selected() { int Names::selected() {
int num = 0; int num = 0;
for (int i = 0; i < count(); i++) for (int i = 0; i < count(); i++)
if (getSelected(i)) num++; if (getSelected(i)) num++;
return num; return num;
@@ -399,6 +422,7 @@ int Names::selected() {
int Names::stations() { int Names::stations() {
int num = 0; int num = 0;
for (int i = 0; i < count(); i++) for (int i = 0; i < count(); i++)
if (isStation(i)) num++; if (isStation(i)) num++;
return num; return num;
@@ -410,18 +434,21 @@ bool Names::internal_check(int num) {
void Names::internal_select(int num) { void Names::internal_select(int num) {
Device newDevice = list->get(num); Device newDevice = list->get(num);
newDevice.selected = true; newDevice.selected = true;
list->replace(num, newDevice); list->replace(num, newDevice);
} }
void Names::internal_deselect(int num) { void Names::internal_deselect(int num) {
Device newDevice = list->get(num); Device newDevice = list->get(num);
newDevice.selected = false; newDevice.selected = false;
list->replace(num, newDevice); list->replace(num, newDevice);
} }
void Names::internal_add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool selected) { void Names::internal_add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch, bool selected) {
uint8_t* deviceMac = (uint8_t*)malloc(6); uint8_t* deviceMac = (uint8_t*)malloc(6);
if (name.length() > NAME_MAX_LENGTH) name = name.substring(0, NAME_MAX_LENGTH); if (name.length() > NAME_MAX_LENGTH) name = name.substring(0, NAME_MAX_LENGTH);
char* deviceName = (char*)malloc(name.length() + 1); char* deviceName = (char*)malloc(name.length() + 1);
uint8_t* deviceBssid = NULL; uint8_t* deviceBssid = NULL;
@@ -436,7 +463,7 @@ void Names::internal_add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch,
memcpy(deviceBssid, bssid, 6); memcpy(deviceBssid, bssid, 6);
} }
if (ch < 1 || ch > 14) ch = 1; if ((ch < 1) || (ch > 14)) ch = 1;
Device newDevice; Device newDevice;
newDevice.mac = deviceMac; newDevice.mac = deviceMac;
@@ -450,6 +477,7 @@ void Names::internal_add(uint8_t* mac, String name, uint8_t* bssid, uint8_t ch,
void Names::internal_add(String macStr, String name, String bssidStr, uint8_t ch, bool selected) { void Names::internal_add(String macStr, String name, String bssidStr, uint8_t ch, bool selected) {
uint8_t mac[6]; uint8_t mac[6];
if (!strToMac(macStr, mac)) return; if (!strToMac(macStr, mac)) return;
if (bssidStr.length() == 17) { if (bssidStr.length() == 17) {
@@ -464,8 +492,8 @@ void Names::internal_add(String macStr, String name, String bssidStr, uint8_t ch
void Names::internal_remove(int num) { void Names::internal_remove(int num) {
free(list->get(num).mac); free(list->get(num).mac);
free(list->get(num).name); free(list->get(num).name);
if (list->get(num).apBssid)
free(list->get(num).apBssid); if (list->get(num).apBssid) free(list->get(num).apBssid);
list->remove(num); list->remove(num);
} }
@@ -473,11 +501,8 @@ void Names::internal_removeAll() {
while (count() > 0) { while (count() > 0) {
free(list->get(0).mac); free(list->get(0).mac);
free(list->get(0).name); free(list->get(0).name);
if (list->get(0).apBssid)
free(list->get(0).apBssid); if (list->get(0).apBssid) free(list->get(0).apBssid);
list->remove(0); list->remove(0);
} }
} }

View File

@@ -7,7 +7,7 @@
extern "C" { extern "C" {
#include "user_interface.h" #include "user_interface.h"
} }
#include <ArduinoJson.h> #include "ArduinoJson.h"
#include "language.h" #include "language.h"
#include "SimpleList.h" #include "SimpleList.h"
@@ -76,6 +76,7 @@ class Names {
int stations(); int stations();
bool check(int num); bool check(int num);
private: private:
String FILE_PATH = "/names.json"; String FILE_PATH = "/names.json";
bool changed = false; bool changed = false;
@@ -100,7 +101,4 @@ class Names {
void internal_removeAll(); void internal_removeAll();
}; };
#endif #endif // ifndef Names_h

View File

@@ -1,110 +1,27 @@
#include "Neopixel.h" #include "NeopixelLED.h"
Neopixel::Neopixel() {
NeopixelLED::NeopixelLED(int num, uint8_t dataPin, uint8_t brightness) {
strip = new Adafruit_NeoPixel(num, dataPin, NEO_GRB + NEO_KHZ800);
setBrightness(brightness);
} }
// setup pins NeopixelLED::~NeopixelLED() {
void Neopixel::setup(){ delete strip;
if(!settings.getLedEnabled()) return;
// ===== adjustable ===== //
strip.setBrightness(100);
strip.begin();
strip.show();
// ====================== //
setMode(LED_MODE_OFF, true);
} }
void Neopixel::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness, bool output) { void NeopixelLED::setup() {
// debug output strip->begin();
if (output){ strip->show();
char s[30];
sprintf(s,str(L_OUTPUT_A).c_str(), r, g, b);
prnt(String(s));
} }
// ===== adjustable ===== // void NeopixelLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
if (brightness > 0 && brightness < 100) { int num = strip->numPixels();
if (r > 0 && brightness < 100) r = r * brightness / 100;
if (g > 0 && brightness < 100) g = g * brightness / 100; for (uint16_t i = 0; i < num; i++) strip->setPixelColor(i, strip->Color(r, g, b));
if (b > 0 && brightness < 100) b = b * brightness / 100; strip->show();
} }
for(uint16_t i=0;i<LED_NEOPIXEL_NUM;i++){ void NeopixelLED::setBrightness(uint8_t brightness) {
strip.setPixelColor(i,strip.Color(r,g,b,brightness)); if (brightness > 100) brightness = 100;
strip->setBrightness(brightness);
} }
strip.show();
// ====================== //
// debug output
if (output){
char s[30];
sprintf(s,str(L_OUTPUT_B).c_str(), r?255:0, g?255:0, b?255:0);
prnt(String(s));
}
}
// customize color codes for different LED modes
void Neopixel::setMode(uint8_t mode, bool force) {
// ===== adjustable ===== //
if (mode != Neopixel::mode || force) {
Neopixel::mode = mode;
switch (mode) {
case LED_MODE_OFF:
setColor(0, 0, 0, LED_MODE_BRIGHTNESS, false);
break;
case LED_MODE_SCAN:
if(LED_DYNAMIC_BRIGHTNESS) setColor(0, 0, 255, (uint8_t)(scan.getScaleFactor(100)*scan.getPacketRate()), false); // change color depending on packet rate
else setColor(0, 0, 255, LED_MODE_BRIGHTNESS, false);
break;
case LED_MODE_ATTACK:
setColor(255, 255, 0, LED_MODE_BRIGHTNESS, false);
break;
case LED_MODE_DEAUTH:
if(LED_DYNAMIC_BRIGHTNESS) setColor(255, 0, 0, scan.deauths > 255 ? 255 : scan.deauths , false); // brightness depending on how many deauths/s
else setColor(255, 0, 0, LED_MODE_BRIGHTNESS, false);
break;
case LED_MODE_IDLE:
setColor(0, 255, 0, LED_MODE_BRIGHTNESS, false);
break;
}
}
// ====================== //
}
void Neopixel::tempEnable() {
tempEnabled = true;
prntln(L_ENABLED);
}
void Neopixel::tempDisable() {
tempEnabled = false;
prntln(L_DISABLED);
}
bool Neopixel::getTempEnabled() {
return tempEnabled;
}
void Neopixel::setColor(uint8_t r, uint8_t g, uint8_t b) {
setColor(r, g, b, 100, true);
}
void Neopixel::setColor(uint8_t r, uint8_t g, uint8_t b, uint8_t brightness) {
setColor(r, g, b, brightness, true);
}
void Neopixel::update() {
if (!tempEnabled) 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);
}

View File

@@ -0,0 +1,21 @@
#ifndef NeopixelLED_H
#define NeopixelLED_H
#include "StatusLED.h"
#include <Adafruit_NeoPixel.h>
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;
};
#endif // ifndef NeopixelLED_H

View File

@@ -23,6 +23,7 @@ void SSIDs::load() {
void SSIDs::load(String filepath) { void SSIDs::load(String filepath) {
String tmp = FILE_PATH; String tmp = FILE_PATH;
FILE_PATH = filepath; FILE_PATH = filepath;
load(); load();
FILE_PATH = tmp; FILE_PATH = tmp;
@@ -38,8 +39,10 @@ void SSIDs::save(bool force) {
if (!force && !changed) return; if (!force && !changed) return;
String buf = String(); // create buffer String buf = String(); // create buffer
buf += String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SS_JSON_RANDOM) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + b2s(randomMode) + String(COMMA); // {"random":false, buf += String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SS_JSON_RANDOM) + String(DOUBLEQUOTES) + String(
buf += String(DOUBLEQUOTES) + str(SS_JSON_SSIDS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + String(OPEN_BRACKET); // "ssids":[ DOUBLEPOINT) + b2s(randomMode) + String(COMMA); // {"random":false,
buf += String(DOUBLEQUOTES) + str(SS_JSON_SSIDS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) +
String(OPEN_BRACKET); // "ssids":[
if (!writeFile(FILE_PATH, buf)) { if (!writeFile(FILE_PATH, buf)) {
prnt(F_ERROR_SAVING); prnt(F_ERROR_SAVING);
@@ -57,6 +60,7 @@ void SSIDs::save(bool force) {
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + name + String(DOUBLEQUOTES) + String(COMMA); // ["name", buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + name + String(DOUBLEQUOTES) + String(COMMA); // ["name",
buf += b2s(getWPA2(i)) + String(COMMA); // false, buf += b2s(getWPA2(i)) + String(COMMA); // false,
buf += String(getLen(i)) + String(CLOSE_BRACKET); // 12] buf += String(getLen(i)) + String(CLOSE_BRACKET); // 12]
if (i < c - 1) buf += COMMA; // , if (i < c - 1) buf += COMMA; // ,
if (buf.length() >= 1024) { if (buf.length() >= 1024) {
@@ -85,6 +89,7 @@ void SSIDs::save(bool force) {
void SSIDs::save(bool force, String filepath) { void SSIDs::save(bool force, String filepath) {
String tmp = FILE_PATH; String tmp = FILE_PATH;
FILE_PATH = filepath; FILE_PATH = filepath;
save(force); save(force);
FILE_PATH = tmp; FILE_PATH = tmp;
@@ -98,20 +103,17 @@ void SSIDs::update() {
for (int i = 0; i < SSID_LIST_SIZE; i++) { for (int i = 0; i < SSID_LIST_SIZE; i++) {
SSID newSSID; SSID newSSID;
if (check(i)) if (check(i)) newSSID = list->get(i);
newSSID = list->get(i);
newSSID.name = String(); newSSID.name = String();
newSSID.len = 32; newSSID.len = 32;
for (int i = 0; i < 32; i++)
newSSID.name += char(random(32, 127)); for (int i = 0; i < 32; i++) newSSID.name += char(random(32, 127));
newSSID.wpa2 = random(0, 2); newSSID.wpa2 = random(0, 2);
if (check(i)) if (check(i)) list->replace(i, newSSID);
list->replace(i, newSSID); else list->add(newSSID);
else
list->add(newSSID);
} }
randomTime = currentTime; randomTime = currentTime;
@@ -134,6 +136,7 @@ int SSIDs::getLen(int num){
void SSIDs::setWPA2(int num, bool wpa2) { void SSIDs::setWPA2(int num, bool wpa2) {
SSID newSSID = list->get(num); SSID newSSID = list->get(num);
newSSID.wpa2 = wpa2; newSSID.wpa2 = wpa2;
list->replace(num, newSSID); list->replace(num, newSSID);
} }
@@ -145,6 +148,7 @@ String SSIDs::getEncStr(int num) {
void SSIDs::remove(int num) { void SSIDs::remove(int num) {
if (!check(num)) return; if (!check(num)) return;
internal_remove(num); internal_remove(num);
prnt(SS_REMOVED); prnt(SS_REMOVED);
prntln(getName(num)); prntln(getName(num));
@@ -153,16 +157,19 @@ void SSIDs::remove(int num) {
String SSIDs::randomize(String name) { String SSIDs::randomize(String name) {
int ssidlen = name.length(); int ssidlen = name.length();
if (ssidlen > 32) name = name.substring(0, 32); if (ssidlen > 32) name = name.substring(0, 32);
if (ssidlen < 32) { if (ssidlen < 32) {
for (int i = ssidlen; i < 32; i++) { for (int i = ssidlen; i < 32; i++) {
int rnd = random(3); int rnd = random(3);
if (i < 29 && rnd == 0) { // ZERO WIDTH SPACE
if ((i < 29) && (rnd == 0)) { // ZERO WIDTH SPACE
name += char(0xE2); name += char(0xE2);
name += char(0x80); name += char(0x80);
name += char(0x8B); name += char(0x8B);
i += 2; i += 2;
} else if (i < 30 && rnd == 1) { // NO-BREAK SPACE } else if ((i < 30) && (rnd == 1)) { // NO-BREAK SPACE
name += char(0xC2); name += char(0xC2);
name += char(0xA0); name += char(0xA0);
i += 1; i += 1;
@@ -188,6 +195,7 @@ void SSIDs::add(String name, bool wpa2, int clones, bool force) {
for (int i = 0; i < clones; i++) { for (int i = 0; i < clones; i++) {
internal_add(name, wpa2, name.length()); internal_add(name, wpa2, name.length());
if (list->size() > SSID_LIST_SIZE) internal_remove(0); if (list->size() > SSID_LIST_SIZE) internal_remove(0);
} }
@@ -199,13 +207,14 @@ void SSIDs::add(String name, bool wpa2, int clones, bool force) {
void SSIDs::cloneSelected(bool force) { void SSIDs::cloneSelected(bool force) {
if (accesspoints.selected() > 0) { if (accesspoints.selected() > 0) {
int clones = SSID_LIST_SIZE; int clones = SSID_LIST_SIZE;
if (!force) clones -= list->size(); if (!force) clones -= list->size();
clones /= accesspoints.selected(); clones /= accesspoints.selected();
int apCount = accesspoints.count(); int apCount = accesspoints.count();
for (int i = 0; i < apCount; i++) { for (int i = 0; i < apCount; i++) {
if(accesspoints.getSelected(i)) if (accesspoints.getSelected(i)) add(accesspoints.getSSID(i), accesspoints.getEnc(i) != 0, clones, force);
add(accesspoints.getSSID(i), accesspoints.getEnc(i) != 0, clones, force);
} }
} }
} }
@@ -218,8 +227,8 @@ void SSIDs::replace(int num, String name, bool wpa2){
if (!check(num)) return; if (!check(num)) return;
int len = name.length(); int len = name.length();
if(len > 32)
len = 32; if (len > 32) len = 32;
SSID newSSID; SSID newSSID;
newSSID.name = randomize(name); newSSID.name = randomize(name);
newSSID.wpa2 = wpa2; newSSID.wpa2 = wpa2;
@@ -237,6 +246,7 @@ void SSIDs::print(int num) {
void SSIDs::print(int num, bool header, bool footer) { void SSIDs::print(int num, bool header, bool footer) {
if (!check(num)) return; if (!check(num)) return;
if (header) { if (header) {
prntln(SS_TABLE_HEADER); prntln(SS_TABLE_HEADER);
prntln(SS_TABLE_DIVIDER); prntln(SS_TABLE_DIVIDER);
@@ -252,11 +262,10 @@ void SSIDs::print(int num, bool header, bool footer) {
void SSIDs::printAll() { void SSIDs::printAll() {
prntln(SS_HEADER); prntln(SS_HEADER);
int c = count(); int c = count();
if (c == 0)
prntln(SS_ERROR_EMPTY); if (c == 0) prntln(SS_ERROR_EMPTY);
else else
for (int i = 0; i < c; i++) for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
print(i, i == 0, i == c - 1);
} }
int SSIDs::count() { int SSIDs::count() {
@@ -305,6 +314,3 @@ void SSIDs::internal_remove(int num) {
void SSIDs::internal_removeAll() { void SSIDs::internal_removeAll() {
list->clear(); list->clear();
} }

View File

@@ -7,7 +7,7 @@
extern "C" { extern "C" {
#include "user_interface.h" #include "user_interface.h"
} }
#include <ArduinoJson.h> #include "ArduinoJson.h"
#include "language.h" #include "language.h"
#include "SimpleList.h" #include "SimpleList.h"
#include "Settings.h" #include "Settings.h"
@@ -59,6 +59,7 @@ class SSIDs {
void removeAll(); void removeAll();
int count(); int count();
private: private:
bool changed = false; bool changed = false;
bool randomMode = false; bool randomMode = false;
@@ -83,7 +84,4 @@ class SSIDs {
void internal_removeAll(); void internal_removeAll();
}; };
#endif #endif // ifndef SSIDs_h

View File

@@ -11,13 +11,13 @@ void Scan::sniffer(uint8_t* buf, uint16_t len) {
if (len < 28) return; // drop frames that are too short to have a valid MAC header if (len < 28) return; // drop frames that are too short to have a valid MAC header
if (buf[12] == 0xc0 || buf[12] == 0xa0) { if ((buf[12] == 0xc0) || (buf[12] == 0xa0)) {
tmpDeauths++; tmpDeauths++;
return; return;
} }
// drop beacon frames, probe requests/responses and deauth/disassociation frames // drop beacon frames, probe requests/responses and deauth/disassociation frames
if (buf[12] == 0x80 || buf[12] == 0x40 || buf[12] == 0x50/* || buf[12] == 0xc0 || buf[12] == 0xa0*/) return; if ((buf[12] == 0x80) || (buf[12] == 0x40) || (buf[12] == 0x50) /* || buf[12] == 0xc0 || buf[12] == 0xa0*/) return;
// only allow data frames // only allow data frames
// if(buf[12] != 0x08 && buf[12] != 0x88) return; // if(buf[12] != 0x08 && buf[12] != 0x88) return;
@@ -25,13 +25,16 @@ void Scan::sniffer(uint8_t* buf, uint16_t len) {
uint8_t* macTo = &buf[16]; uint8_t* macTo = &buf[16];
uint8_t* macFrom = &buf[22]; uint8_t* macFrom = &buf[22];
if (macBroadcast(macTo) || macBroadcast(macFrom) || !macValid(macTo) || !macValid(macFrom) || macMulticast(macTo) || macMulticast(macFrom)) return; if (macBroadcast(macTo) || macBroadcast(macFrom) || !macValid(macTo) || !macValid(macFrom) || macMulticast(macTo) ||
macMulticast(macFrom)) return;
int accesspointNum = findAccesspoint(macFrom); int accesspointNum = findAccesspoint(macFrom);
if (accesspointNum >= 0) { if (accesspointNum >= 0) {
stations.add(macTo, accesspoints.getID(accesspointNum)); stations.add(macTo, accesspoints.getID(accesspointNum));
} else { } else {
accesspointNum = findAccesspoint(macTo); accesspointNum = findAccesspoint(macTo);
if (accesspointNum >= 0) { if (accesspointNum >= 0) {
stations.add(macFrom, accesspoints.getID(accesspointNum)); stations.add(macFrom, accesspoints.getID(accesspointNum));
} }
@@ -49,7 +52,8 @@ void Scan::start(uint8_t mode) {
start(mode, sniffTime, scan_continue_mode, continueTime, channelHop, wifi_channel); start(mode, sniffTime, scan_continue_mode, continueTime, channelHop, wifi_channel);
} }
void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop, uint8_t channel) { void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop,
uint8_t channel) {
if (mode != SCAN_MODE_OFF) stop(); if (mode != SCAN_MODE_OFF) stop();
setWifiChannel(channel); setWifiChannel(channel);
@@ -62,12 +66,13 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu
Scan::scanMode = mode; Scan::scanMode = mode;
Scan::scan_continue_mode = nextmode; Scan::scan_continue_mode = nextmode;
if(sniffTime > 0 && sniffTime < 1000) sniffTime = 1000; if ((sniffTime > 0) && (sniffTime < 1000)) sniffTime = 1000;
// Serial.printf("mode: %u, time: %u, continue-mode: %u, continueTime: %u, channelHop: %u, channel: %u\r\n", mode, time, scan_continue_mode, continueTime, channelHop, channel); // Serial.printf("mode: %u, time: %u, continue-mode: %u, continueTime: %u, channelHop: %u, channel: %u\r\n", mode,
// time, scan_continue_mode, continueTime, channelHop, channel);
/* AP Scan */ /* AP Scan */
if (mode == SCAN_MODE_APS || mode == SCAN_MODE_ALL) { if ((mode == SCAN_MODE_APS) || (mode == SCAN_MODE_ALL)) {
// remove old results // remove old results
accesspoints.removeAll(); accesspoints.removeAll();
stations.removeAll(); stations.removeAll();
@@ -86,8 +91,10 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu
} }
snifferStartTime = currentTime; snifferStartTime = currentTime;
prnt(SC_START_CLIENT); prnt(SC_START_CLIENT);
if (sniffTime > 0) prnt(String(sniffTime / 1000) + S); if (sniffTime > 0) prnt(String(sniffTime / 1000) + S);
else prnt(SC_INFINITELY); else prnt(SC_INFINITELY);
if (!channelHop) { if (!channelHop) {
prnt(SC_ON_CHANNEL); prnt(SC_ON_CHANNEL);
prnt(wifi_channel); prnt(wifi_channel);
@@ -104,6 +111,7 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu
tmpDeauths = 0; tmpDeauths = 0;
snifferStartTime = currentTime; snifferStartTime = currentTime;
prnt(SS_START_SNIFFER); prnt(SS_START_SNIFFER);
if (sniffTime > 0) prnt(String(sniffTime / 1000) + S); if (sniffTime > 0) prnt(String(sniffTime / 1000) + S);
else prnt(SC_INFINITELY); else prnt(SC_INFINITELY);
prnt(SC_ON_CHANNEL); prnt(SC_ON_CHANNEL);
@@ -117,9 +125,11 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu
/* Stop scan */ /* Stop scan */
else if (mode == SCAN_MODE_OFF) { else if (mode == SCAN_MODE_OFF) {
wifi_promiscuous_enable(false); wifi_promiscuous_enable(false);
if (settings.getWebInterface()) resumeAP(); if (settings.getWebInterface()) resumeAP();
prntln(SC_STOPPED); prntln(SC_STOPPED);
save(true); save(true);
if (scan_continue_mode != SCAN_MODE_OFF) { if (scan_continue_mode != SCAN_MODE_OFF) {
prnt(SC_RESTART); prnt(SC_RESTART);
prnt(int(continueTime / 1000)); prnt(int(continueTime / 1000));
@@ -150,6 +160,7 @@ void Scan::update() {
if (currentTime - snifferPacketTime > 1000) { if (currentTime - snifferPacketTime > 1000) {
snifferPacketTime = currentTime; snifferPacketTime = currentTime;
list->add(packets); list->add(packets);
if (list->size() > SCAN_PACKET_LIST_SIZE) list->remove(0); if (list->size() > SCAN_PACKET_LIST_SIZE) list->remove(0);
deauths = tmpDeauths; deauths = tmpDeauths;
tmpDeauths = 0; tmpDeauths = 0;
@@ -159,6 +170,7 @@ void Scan::update() {
// print status every 3s // print status every 3s
if (currentTime - snifferOutputTime > 3000) { if (currentTime - snifferOutputTime > 3000) {
char s[100]; char s[100];
if (sniffTime > 0) { if (sniffTime > 0) {
sprintf(s, str(SC_OUTPUT_A).c_str(), getPercentage(), packets, stations.count(), deauths); sprintf(s, str(SC_OUTPUT_A).c_str(), getPercentage(), packets, stations.count(), deauths);
} else { } else {
@@ -169,22 +181,25 @@ void Scan::update() {
} }
// channel hopping // channel hopping
if(channelHop && currentTime - snifferChannelTime > settings.getChTime()) { if (channelHop && (currentTime - snifferChannelTime > settings.getChTime())) {
snifferChannelTime = currentTime; snifferChannelTime = currentTime;
if (scanMode == SCAN_MODE_STATIONS) nextChannel(); // go to next channel an AP is on if (scanMode == SCAN_MODE_STATIONS) nextChannel(); // go to next channel an AP is on
else setChannel(wifi_channel + 1); // go to next channel else setChannel(wifi_channel + 1); // go to next channel
} }
} }
// APs // APs
if (scanMode == SCAN_MODE_APS || scanMode == SCAN_MODE_ALL) { if ((scanMode == SCAN_MODE_APS) || (scanMode == SCAN_MODE_ALL)) {
int16_t results = WiFi.scanComplete(); int16_t results = WiFi.scanComplete();
if (results >= 0) { if (results >= 0) {
for (int16_t i = 0; i < results && i < 256; i++) { for (int16_t i = 0; i < results && i < 256; i++) {
if(channelHop || WiFi.channel(i) == wifi_channel) accesspoints.add(i, false); if (channelHop || (WiFi.channel(i) == wifi_channel)) accesspoints.add(i, false);
} }
accesspoints.sort(); accesspoints.sort();
accesspoints.printAll(); accesspoints.printAll();
if (scanMode == SCAN_MODE_ALL) { if (scanMode == SCAN_MODE_ALL) {
delay(30); delay(30);
start(SCAN_MODE_STATIONS); start(SCAN_MODE_STATIONS);
@@ -194,8 +209,9 @@ void Scan::update() {
} }
// Stations // Stations
else if (sniffTime > 0 && currentTime > snifferStartTime + sniffTime) { else if ((sniffTime > 0) && (currentTime > snifferStartTime + sniffTime)) {
wifi_promiscuous_enable(false); wifi_promiscuous_enable(false);
if (scanMode == SCAN_MODE_STATIONS) { if (scanMode == SCAN_MODE_STATIONS) {
stations.sort(); stations.sort();
stations.printAll(); stations.printAll();
@@ -225,8 +241,10 @@ void Scan::setChannel(uint8_t ch) {
void Scan::nextChannel() { void Scan::nextChannel() {
if (accesspoints.count() > 1) { if (accesspoints.count() > 1) {
uint8_t ch = wifi_channel; uint8_t ch = wifi_channel;
do { do {
ch++; ch++;
if (ch > settings.getMaxCh()) ch = 1; if (ch > settings.getMaxCh()) ch = 1;
} while (!apWithChannel(ch)); } while (!apWithChannel(ch));
setChannel(ch); setChannel(ch);
@@ -236,11 +254,13 @@ void Scan::nextChannel() {
bool Scan::apWithChannel(uint8_t ch) { bool Scan::apWithChannel(uint8_t ch) {
for (int i = 0; i < accesspoints.count(); i++) for (int i = 0; i < accesspoints.count(); i++)
if (accesspoints.getCh(i) == ch) return true; if (accesspoints.getCh(i) == ch) return true;
return false; return false;
} }
void Scan::save(bool force, String filePath) { void Scan::save(bool force, String filePath) {
String tmp = FILE_PATH; String tmp = FILE_PATH;
FILE_PATH = filePath; FILE_PATH = filePath;
save(true); save(true);
FILE_PATH = tmp; FILE_PATH = tmp;
@@ -250,7 +270,8 @@ void Scan::save(bool force) {
if (!(accesspoints.changed || stations.changed) && !force) return; if (!(accesspoints.changed || stations.changed) && !force) return;
// Accesspoints // Accesspoints
String buf = String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SC_JSON_APS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + String(OPEN_BRACKET); // {"aps":[ String buf = String(OPEN_CURLY_BRACKET) + String(DOUBLEQUOTES) + str(SC_JSON_APS) + String(DOUBLEQUOTES) + String(
DOUBLEPOINT) + String(OPEN_BRACKET); // {"aps":[
if (!writeFile(FILE_PATH, buf)) { // overwrite old file if (!writeFile(FILE_PATH, buf)) { // overwrite old file
prnt(F_ERROR_SAVING); prnt(F_ERROR_SAVING);
@@ -262,7 +283,8 @@ void Scan::save(bool force) {
uint32_t apCount = accesspoints.count(); uint32_t apCount = accesspoints.count();
for (uint32_t i = 0; i < apCount; i++) { for (uint32_t i = 0; i < apCount; i++) {
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + escape(accesspoints.getSSID(i)) + String(DOUBLEQUOTES) + String(COMMA); // ["ssid", buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + escape(accesspoints.getSSID(i)) + String(DOUBLEQUOTES) +
String(COMMA); // ["ssid",
buf += String(DOUBLEQUOTES) + escape(accesspoints.getNameStr(i)) + String(DOUBLEQUOTES) + String(COMMA); // "name", buf += String(DOUBLEQUOTES) + escape(accesspoints.getNameStr(i)) + String(DOUBLEQUOTES) + String(COMMA); // "name",
buf += String(accesspoints.getCh(i)) + String(COMMA); // 1, buf += String(accesspoints.getCh(i)) + String(COMMA); // 1,
buf += String(accesspoints.getRSSI(i)) + String(COMMA); // -30, buf += String(accesspoints.getRSSI(i)) + String(COMMA); // -30,
@@ -270,6 +292,7 @@ void Scan::save(bool force) {
buf += String(DOUBLEQUOTES) + accesspoints.getMacStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "00:11:22:00:11:22", buf += String(DOUBLEQUOTES) + accesspoints.getMacStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "00:11:22:00:11:22",
buf += String(DOUBLEQUOTES) + accesspoints.getVendorStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "vendor", buf += String(DOUBLEQUOTES) + accesspoints.getVendorStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "vendor",
buf += b2s(accesspoints.getSelected(i)) + String(CLOSE_BRACKET); // false] buf += b2s(accesspoints.getSelected(i)) + String(CLOSE_BRACKET); // false]
if (i < apCount - 1) buf += String(COMMA); // , if (i < apCount - 1) buf += String(COMMA); // ,
if (buf.length() >= 1024) { if (buf.length() >= 1024) {
@@ -284,11 +307,13 @@ void Scan::save(bool force) {
} }
// Stations // Stations
buf += String(CLOSE_BRACKET) + String(COMMA) + String(DOUBLEQUOTES) + str(SC_JSON_STATIONS) + String(DOUBLEQUOTES) + String(DOUBLEPOINT) + String(OPEN_BRACKET); // ],"stations":[; buf += String(CLOSE_BRACKET) + String(COMMA) + String(DOUBLEQUOTES) + str(SC_JSON_STATIONS) + String(DOUBLEQUOTES) +
String(DOUBLEPOINT) + String(OPEN_BRACKET); // ],"stations":[;
uint32_t stationCount = stations.count(); uint32_t stationCount = stations.count();
for (uint32_t i = 0; i < stationCount; i++) { for (uint32_t i = 0; i < stationCount; i++) {
buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + stations.getMacStr(i) + String(DOUBLEQUOTES) + String(COMMA); // ["00:11:22:00:11:22", buf += String(OPEN_BRACKET) + String(DOUBLEQUOTES) + stations.getMacStr(i) + String(DOUBLEQUOTES) +
String(COMMA); // ["00:11:22:00:11:22",
buf += String(stations.getCh(i)) + String(COMMA); // 1, buf += String(stations.getCh(i)) + String(COMMA); // 1,
buf += String(DOUBLEQUOTES) + stations.getNameStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "name", buf += String(DOUBLEQUOTES) + stations.getNameStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "name",
buf += String(DOUBLEQUOTES) + stations.getVendorStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "vendor", buf += String(DOUBLEQUOTES) + stations.getVendorStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "vendor",
@@ -296,6 +321,7 @@ void Scan::save(bool force) {
buf += String(stations.getAP(i)) + String(COMMA); // 0, buf += String(stations.getAP(i)) + String(COMMA); // 0,
buf += String(DOUBLEQUOTES) + stations.getTimeStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "<1min", buf += String(DOUBLEQUOTES) + stations.getTimeStr(i) + String(DOUBLEQUOTES) + String(COMMA); // "<1min",
buf += b2s(stations.getSelected(i)) + String(CLOSE_BRACKET); // false] buf += b2s(stations.getSelected(i)) + String(CLOSE_BRACKET); // false]
if (i < stationCount - 1) buf += String(COMMA); // , if (i < stationCount - 1) buf += String(COMMA); // ,
if (buf.length() >= 1024) { if (buf.length() >= 1024) {
@@ -324,11 +350,11 @@ void Scan::save(bool force) {
} }
uint32_t Scan::countSelected() { uint32_t Scan::countSelected() {
return (accesspoints.selected() + stations.selected() + names.selected()); return accesspoints.selected() + stations.selected() + names.selected();
} }
uint32_t Scan::countAll() { uint32_t Scan::countAll() {
return (accesspoints.count() + stations.count() + names.count()); return accesspoints.count() + stations.count() + names.count();
} }
bool Scan::isScanning() { bool Scan::isScanning() {
@@ -341,6 +367,7 @@ bool Scan::isSniffing() {
uint8_t Scan::getPercentage() { uint8_t Scan::getPercentage() {
if (!isSniffing()) return 0; if (!isSniffing()) return 0;
return (currentTime - snifferStartTime) / (sniffTime / 100); return (currentTime - snifferStartTime) / (sniffTime / 100);
} }
@@ -372,7 +399,9 @@ void Scan::printSelected() {
uint32_t Scan::getPackets(int i) { uint32_t Scan::getPackets(int i) {
if (list->size() < SCAN_PACKET_LIST_SIZE) { if (list->size() < SCAN_PACKET_LIST_SIZE) {
uint8_t translatedNum = SCAN_PACKET_LIST_SIZE - list->size(); uint8_t translatedNum = SCAN_PACKET_LIST_SIZE - list->size();
if (i >= translatedNum) return list->get(i - translatedNum); if (i >= translatedNum) return list->get(i - translatedNum);
return 0; return 0;
} else { } else {
return list->get(i); return list->get(i);
@@ -385,6 +414,7 @@ double Scan::getScaleFactor(uint8_t height){
uint32_t Scan::getMaxPacket() { uint32_t Scan::getMaxPacket() {
uint16_t max = 0; uint16_t max = 0;
for (uint8_t i = 0; i < list->size(); i++) { for (uint8_t i = 0; i < list->size(); i++) {
if (list->get(i) > max) max = list->get(i); if (list->get(i) > max) max = list->get(i);
} }
@@ -394,5 +424,3 @@ uint32_t Scan::getMaxPacket(){
uint32_t Scan::getPacketRate() { uint32_t Scan::getPacketRate() {
return list->get(list->size() - 1); return list->get(list->size() - 1);
} }

View File

@@ -39,7 +39,8 @@ class Scan {
Scan(); Scan();
void sniffer(uint8_t* buf, uint16_t len); void sniffer(uint8_t* buf, uint16_t len);
void start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop, uint8_t channel); void start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continueTime, bool channelHop,
uint8_t channel);
void start(uint8_t mode); void start(uint8_t mode);
void setup(); void setup();
@@ -69,6 +70,7 @@ class Scan {
uint16_t deauths = 0; uint16_t deauths = 0;
uint16_t packets = 0; uint16_t packets = 0;
private: private:
SimpleList<uint16_t>* list; // packet list SimpleList<uint16_t>* list; // packet list
@@ -93,7 +95,4 @@ class Scan {
String FILE_PATH = "/scan.json"; String FILE_PATH = "/scan.json";
}; };
#endif #endif // ifndef Scan_h

View File

@@ -4,10 +4,13 @@
A short introduction for the reader: A short introduction for the reader:
This class is a huuuuuuuge mess of if statements!!!!!1!eleven This class is a huuuuuuuge mess of if statements!!!!!1!eleven
But it works and I tried to make it as compact as possible. But it works and I tried to make it as compact as possible.
If someone was able to make an Arduino framework for parsing an input string in different commands with certain rules, If someone was able to make an Arduino framework for parsing an input string in different commands with certain
required- and optional parameters of different datatypes to run different callback functions... shoot me a quick message on GitHub or Twitter: @spacehuhn! rules,
required- and optional parameters of different datatypes to run different callback functions... shoot me a quick
message on GitHub or Twitter: @spacehuhn!
PS: the framework has to be good in both CPU performance and RAM usage, otherwise it's useless. Good luck! PS: the framework has to be good in both CPU performance and RAM usage, otherwise it's useless. Good luck!
I already wasted way too much time trying to come up with the best way of programming this, so I will just keep it that way for now. I already wasted way too much time trying to come up with the best way of programming this, so I will just keep it
that way for now.
Also: NEVER CHANGE A RUNNING SYSTEM! Also: NEVER CHANGE A RUNNING SYSTEM!
*/ */
@@ -47,29 +50,28 @@ void SerialInterface::parameterError(String parameter) {
} }
bool SerialInterface::isInt(String str) { bool SerialInterface::isInt(String str) {
if (eqls(str,STR_TRUE) || eqls(str,STR_FALSE)) if (eqls(str, STR_TRUE) || eqls(str, STR_FALSE)) return true;
return true;
for (uint32_t i = 0; i < str.length(); i++) for (uint32_t i = 0; i < str.length(); i++)
if (!isDigit(str.charAt(i))) return false; if (!isDigit(str.charAt(i))) return false;
return true; return true;
} }
int SerialInterface::toInt(String str) { int SerialInterface::toInt(String str) {
if (eqls(str,STR_TRUE)) if (eqls(str, STR_TRUE)) return 1;
return 1; else if (eqls(str, STR_FALSE)) return 0;
else if (eqls(str,STR_FALSE)) else return str.toInt();
return 0;
else
return str.toInt();
} }
uint32_t SerialInterface::getTime(String time) { uint32_t SerialInterface::getTime(String time) {
int value = time.toInt(); int value = time.toInt();
if (value < 0) value = -value; if (value < 0) value = -value;
if (time.substring(time.length() - 1).equalsIgnoreCase(String(S)))
value *= 1000; if (time.substring(time.length() - 1).equalsIgnoreCase(String(S))) value *= 1000;
else if (time.substring(time.length() - 3).equalsIgnoreCase(str(STR_MIN)) || time.charAt(time.length() - 1) == M) else if (time.substring(time.length() - 3).equalsIgnoreCase(str(STR_MIN)) ||
value *= 60000; (time.charAt(time.length() - 1) == M)) value *= 60000;
return value; return value;
} }
@@ -90,16 +92,18 @@ void SerialInterface::stopScript() {
void SerialInterface::update() { void SerialInterface::update() {
if (executing) { if (executing) {
if (execPath.charAt(0) != SLASH) if (execPath.charAt(0) != SLASH) execPath = SLASH + execPath;
execPath = SLASH + execPath;
prnt(CLI_EXECUTING); prnt(CLI_EXECUTING);
prntln(execPath); prntln(execPath);
File f = SPIFFS.open(execPath, "r"); File f = SPIFFS.open(execPath, "r");
if (f.size() > 0) { if (f.size() > 0) {
String line; String line;
char tmp; char tmp;
while (f.available()) { while (f.available()) {
tmp = f.read(); tmp = f.read();
if (tmp == NEWLINE) { if (tmp == NEWLINE) {
runCommands(line); runCommands(line);
line = String(); line = String();
@@ -118,11 +122,10 @@ void SerialInterface::update() {
loopTime = currentTime; loopTime = currentTime;
} else { } else {
if (enabled && Serial.available() > 0) if (enabled && (Serial.available() > 0)) runCommands(Serial.readStringUntil(NEWLINE));
runCommands(Serial.readStringUntil(NEWLINE));
if (continuously) { if (continuously) {
if (currentTime - loopTime > continueTime) if (currentTime - loopTime > continueTime) executing = true;
executing = true;
} }
} }
} }
@@ -132,7 +135,8 @@ void SerialInterface::runCommands(String input) {
for (uint32_t i = 0; i < input.length(); i++) { for (uint32_t i = 0; i < input.length(); i++) {
// when 2 semicolons in a row without a backslash escaping the first // when 2 semicolons in a row without a backslash escaping the first
if (input.charAt(i) == SEMICOLON && input.charAt(i + 1) == SEMICOLON && input.charAt(i - 1) != BACKSLASH) { if ((input.charAt(i) == SEMICOLON) && (input.charAt(i + 1) == SEMICOLON) &&
(input.charAt(i - 1) != BACKSLASH)) {
runCommand(tmp); runCommand(tmp);
tmp = String(); tmp = String();
i++; i++;
@@ -142,6 +146,7 @@ void SerialInterface::runCommands(String input) {
} }
tmp.replace(BACKSLASH + SEMICOLON + SEMICOLON, SEMICOLON + SEMICOLON); tmp.replace(BACKSLASH + SEMICOLON + SEMICOLON, SEMICOLON + SEMICOLON);
if (tmp.length() > 0) runCommand(tmp); if (tmp.length() > 0) runCommand(tmp);
} }
@@ -156,16 +161,17 @@ void SerialInterface::runCommand(String input) {
bool withinQuotes = false; bool withinQuotes = false;
bool escaped = false; bool escaped = false;
char c; char c;
for (uint32_t i = 0; i < input.length() && i < 512; i++) { for (uint32_t i = 0; i < input.length() && i < 512; i++) {
c = input.charAt(i); c = input.charAt(i);
// when char is an unescaped // when char is an unescaped
if(!escaped && c == BACKSLASH){ if (!escaped && (c == BACKSLASH)) {
escaped = true; escaped = true;
} }
// (when char is a unescaped space AND it's not within quotes) OR char is \r or \n // (when char is a unescaped space AND it's not within quotes) OR char is \r or \n
else if ((c == SPACE && !escaped && !withinQuotes) || c == CARRIAGERETURN || c == NEWLINE) { else if (((c == SPACE) && !escaped && !withinQuotes) || (c == CARRIAGERETURN) || (c == NEWLINE)) {
// when tmp string isn't empty, add it to the list // when tmp string isn't empty, add it to the list
if (tmp.length() > 0) { if (tmp.length() > 0) {
list->add(tmp); list->add(tmp);
@@ -174,10 +180,12 @@ void SerialInterface::runCommand(String input) {
} }
// when char is an unescaped " // when char is an unescaped "
else if(c == DOUBLEQUOTES && !escaped){ else if ((c == DOUBLEQUOTES) && !escaped) {
// update wheter or not the following chars are within quotes or not // update wheter or not the following chars are within quotes or not
withinQuotes = !withinQuotes; withinQuotes = !withinQuotes;
if(tmp.length() == 0 && !withinQuotes) tmp += SPACE; // when exiting quotes and tmp string is empty, add a space
if ((tmp.length() == 0) && !withinQuotes) tmp += SPACE; // when exiting quotes and tmp string is empty, add
// a space
} }
// add character to tmp string // add character to tmp string
@@ -286,6 +294,7 @@ void SerialInterface::runCommand(String input) {
continueTime = getTime(list->get(i)); continueTime = getTime(list->get(i));
} else if (eqlsCMD(i, CLI_CHANNEL)) { } else if (eqlsCMD(i, CLI_CHANNEL)) {
i++; i++;
if (!eqlsCMD(i, CLI_ALL)) { if (!eqlsCMD(i, CLI_ALL)) {
channelHop = false; channelHop = false;
channel = list->get(i).toInt(); channel = list->get(i).toInt();
@@ -340,12 +349,12 @@ void SerialInterface::runCommand(String input) {
int mode = 0; // aps = 0, stations = 1, names = 2 int mode = 0; // aps = 0, stations = 1, names = 2
int id = -1; // -1 = all, -2 name string int id = -1; // -1 = all, -2 name string
if (list->size() == 1 || eqlsCMD(1, CLI_ALL)) { if ((list->size() == 1) || eqlsCMD(1, CLI_ALL)) {
select ? scan.selectAll() : scan.deselectAll(); select ? scan.selectAll() : scan.deselectAll();
return; return;
} }
if (list->size() == 2 || eqlsCMD(2, CLI_ALL)) id = -1; if ((list->size() == 2) || eqlsCMD(2, CLI_ALL)) id = -1;
else if (!isInt(list->get(2))) id = -2; else if (!isInt(list->get(2))) id = -2;
else id = list->get(2).toInt(); else id = list->get(2).toInt();
@@ -362,7 +371,7 @@ void SerialInterface::runCommand(String input) {
if (mode == 0) select ? accesspoints.selectAll() : accesspoints.deselectAll(); if (mode == 0) select ? accesspoints.selectAll() : accesspoints.deselectAll();
else if (mode == 1) select ? stations.selectAll() : stations.deselectAll(); else if (mode == 1) select ? stations.selectAll() : stations.deselectAll();
else if (mode == 2) select ? names.selectAll() : names.deselectAll(); else if (mode == 2) select ? names.selectAll() : names.deselectAll();
} else if (id == -2 && mode == 2) { } else if ((id == -2) && (mode == 2)) {
select ? names.select(list->get(2)) : names.deselect(list->get(2)); select ? names.select(list->get(2)) : names.deselect(list->get(2));
} else { } else {
parameterError(list->get(1) + SPACE + list->get(2)); parameterError(list->get(1) + SPACE + list->get(2));
@@ -370,8 +379,7 @@ void SerialInterface::runCommand(String input) {
} }
// ===== ADD ===== // // ===== ADD ===== //
else if (list->size() >= 3 && eqlsCMD(0, CLI_ADD) && eqlsCMD(1, CLI_SSID)) { else if ((list->size() >= 3) && eqlsCMD(0, CLI_ADD) && eqlsCMD(1, CLI_SSID)) {
// add ssid -s [-f] // add ssid -s [-f]
if (eqlsCMD(2, CLI_SELECT)) { if (eqlsCMD(2, CLI_SELECT)) {
bool force = eqlsCMD(3, CLI_FORCE); bool force = eqlsCMD(3, CLI_FORCE);
@@ -410,7 +418,7 @@ void SerialInterface::runCommand(String input) {
// add name <name> [-ap <id>] [-s] [-f] // add name <name> [-ap <id>] [-s] [-f]
// add name <name> [-st <id>] [-s] [-f] // add name <name> [-st <id>] [-s] [-f]
// add name <name> [-m <mac>] [-ch <channel>] [-b <bssid>] [-s] [-f] // add name <name> [-m <mac>] [-ch <channel>] [-b <bssid>] [-s] [-f]
else if (list->size() >= 3 && eqlsCMD(0, CLI_ADD) && eqlsCMD(1, CLI_NAME)) { else if ((list->size() >= 3) && eqlsCMD(0, CLI_ADD) && eqlsCMD(1, CLI_NAME)) {
String name = list->get(2); String name = list->get(2);
String mac; String mac;
uint8_t channel = wifi_channel; uint8_t channel = wifi_channel;
@@ -447,13 +455,13 @@ void SerialInterface::runCommand(String input) {
// ===== SET NAME ==== // // ===== SET NAME ==== //
// set name <id> <newname> // set name <id> <newname>
else if (list->size() == 4 && eqlsCMD(0, CLI_SET) && eqlsCMD(1, CLI_NAME)) { else if ((list->size() == 4) && eqlsCMD(0, CLI_SET) && eqlsCMD(1, CLI_NAME)) {
names.setName(list->get(2).toInt(), list->get(3)); names.setName(list->get(2).toInt(), list->get(3));
} }
// ===== REPLACE ===== // // ===== REPLACE ===== //
// replace name <id> [-n <name>} [-m <mac>] [-ch <channel>] [-b <bssid>] [-s] // replace name <id> [-n <name>} [-m <mac>] [-ch <channel>] [-b <bssid>] [-s]
else if (list->size() >= 4 && eqlsCMD(0, CLI_REPLACE) && eqlsCMD(1, CLI_NAME)) { else if ((list->size() >= 4) && eqlsCMD(0, CLI_REPLACE) && eqlsCMD(1, CLI_NAME)) {
int id = list->get(2).toInt(); int id = list->get(2).toInt();
String name = names.getName(id); String name = names.getName(id);
String mac = names.getMacStr(id); String mac = names.getMacStr(id);
@@ -480,7 +488,7 @@ void SerialInterface::runCommand(String input) {
} }
// replace ssid <id> [-n <name>} [-wpa2] // replace ssid <id> [-n <name>} [-wpa2]
else if (list->size() >= 3 && eqlsCMD(0, CLI_REPLACE) && eqlsCMD(1, CLI_SSID)) { else if ((list->size() >= 3) && eqlsCMD(0, CLI_REPLACE) && eqlsCMD(1, CLI_SSID)) {
int id = list->get(2).toInt(); int id = list->get(2).toInt();
String name = ssids.getName(id); String name = ssids.getName(id);
bool wpa2 = false; bool wpa2 = false;
@@ -500,8 +508,8 @@ void SerialInterface::runCommand(String input) {
// ===== REMOVE ===== // // ===== REMOVE ===== //
// remove <type> [-a] // remove <type> [-a]
// remove <type> <id> // remove <type> <id>
else if (list->size() >= 2 && eqlsCMD(0, CLI_REMOVE)) { else if ((list->size() >= 2) && eqlsCMD(0, CLI_REMOVE)) {
if (list->size() == 2 || (eqlsCMD(2, CLI_ALL))) { if ((list->size() == 2) || (eqlsCMD(2, CLI_ALL))) {
if (eqlsCMD(1, CLI_SSID)) ssids.removeAll(); if (eqlsCMD(1, CLI_SSID)) ssids.removeAll();
else if (eqlsCMD(1, CLI_NAME)) names.removeAll(); else if (eqlsCMD(1, CLI_NAME)) names.removeAll();
else if (eqlsCMD(1, CLI_AP)) accesspoints.removeAll(); else if (eqlsCMD(1, CLI_AP)) accesspoints.removeAll();
@@ -518,7 +526,7 @@ void SerialInterface::runCommand(String input) {
// ===== RANDOM ===== // // ===== RANDOM ===== //
// enable random <interval> // enable random <interval>
else if (eqlsCMD(0, CLI_ENABLE) && eqlsCMD(1, CLI_RANDOM) && list->size() == 3) { else if (eqlsCMD(0, CLI_ENABLE) && eqlsCMD(1, CLI_RANDOM) && (list->size() == 3)) {
ssids.enableRandom(getTime(list->get(2))); ssids.enableRandom(getTime(list->get(2)));
} }
@@ -535,18 +543,22 @@ void SerialInterface::runCommand(String input) {
uint32_t i = 0; uint32_t i = 0;
uint8_t multi = 1; uint8_t multi = 1;
uint8_t end = random(80, 99); uint8_t end = random(80, 99);
if (list->get(1).toInt() > 1) multi = list->get(1).toInt(); if (list->get(1).toInt() > 1) multi = list->get(1).toInt();
while (true) { while (true) {
if (i % 10 == 0 && i > 0) { if ((i % 10 == 0) && (i > 0)) {
char s[100]; char s[100];
sprintf(s, str(CLI_RICE_OUTPUT).c_str(), i / 10); sprintf(s, str(CLI_RICE_OUTPUT).c_str(), i / 10);
prnt(String(s)); prnt(String(s));
if ((i / 10) == end) { if ((i / 10) == end) {
prnt(CLI_RICE_ERROR); prnt(CLI_RICE_ERROR);
prnt(String(random(16, 255), HEX)); prnt(String(random(16, 255), HEX));
prnt(String(random(16, 255), HEX)); prnt(String(random(16, 255), HEX));
prnt(String(random(16, 255), HEX)); prnt(String(random(16, 255), HEX));
prntln(String(random(16, 255), HEX)); prntln(String(random(16, 255), HEX));
for (int i = 1; i <= 32; i++) { for (int i = 1; i <= 32; i++) {
for (int i = 0; i < 2; i++) { for (int i = 0; i < 2; i++) {
for (int i = 1; i <= 8; i++) { for (int i = 1; i <= 8; i++) {
@@ -575,13 +587,14 @@ void SerialInterface::runCommand(String input) {
// ===== LOAD/SAVE ===== // // ===== LOAD/SAVE ===== //
// save [<type>] [<file>] // save [<type>] [<file>]
// load [<type>] [<file>] // load [<type>] [<file>]
else if ((eqlsCMD(0, CLI_LOAD) || eqlsCMD(0, CLI_SAVE)) && list->size() >= 1 && list->size() <= 3) { else if ((eqlsCMD(0, CLI_LOAD) || eqlsCMD(0, CLI_SAVE)) && (list->size() >= 1) && (list->size() <= 3)) {
bool load = eqlsCMD(0, CLI_LOAD); bool load = eqlsCMD(0, CLI_LOAD);
if (list->size() == 1 || eqlsCMD(1, CLI_ALL)) { if ((list->size() == 1) || eqlsCMD(1, CLI_ALL)) {
load ? ssids.load() : ssids.save(false); load ? ssids.load() : ssids.save(false);
load ? names.load() : names.save(false); load ? names.load() : names.save(false);
load ? settings.load() : settings.save(false); load ? settings.load() : settings.save(false);
if (!load) scan.save(false); if (!load) scan.save(false);
return; return;
} }
@@ -640,12 +653,12 @@ void SerialInterface::runCommand(String input) {
// ===== GET/SET ===== // // ===== GET/SET ===== //
// get <setting> // get <setting>
else if (eqlsCMD(0, CLI_GET) && list->size() == 2) { else if (eqlsCMD(0, CLI_GET) && (list->size() == 2)) {
prntln(settings.get(list->get(1).c_str())); prntln(settings.get(list->get(1).c_str()));
} }
// set <setting> <value> // set <setting> <value>
else if (eqlsCMD(0, CLI_SET) && list->size() == 3) { else if (eqlsCMD(0, CLI_SET) && (list->size() == 3)) {
settings.set(list->get(1).c_str(), list->get(2)); settings.set(list->get(1).c_str(), list->get(2));
} }
@@ -657,10 +670,9 @@ void SerialInterface::runCommand(String input) {
// ===== STOP ===== // // ===== STOP ===== //
// stop [<mode>] // stop [<mode>]
else if (eqlsCMD(0, CLI_STOP)) { else if (eqlsCMD(0, CLI_STOP)) {
#ifdef DIGITAL_LED led->setMode(led->LED_MODE::IDLE, true);
led.setMode(LED_MODE_IDLE, true);
#endif if ((list->size() >= 2) && !(eqlsCMD(1, CLI_ALL))) {
if (list->size() >= 2 && !(eqlsCMD(1, CLI_ALL))) {
for (int i = 1; i < list->size(); i++) { for (int i = 1; i < list->size(); i++) {
if (eqlsCMD(i, CLI_SCAN)) scan.stop(); if (eqlsCMD(i, CLI_SCAN)) scan.stop();
else if (eqlsCMD(i, CLI_ATTACK)) attack.stop(); else if (eqlsCMD(i, CLI_ATTACK)) attack.stop();
@@ -679,7 +691,9 @@ void SerialInterface::runCommand(String input) {
else if (eqlsCMD(0, CLI_SYSINFO)) { else if (eqlsCMD(0, CLI_SYSINFO)) {
prntln(CLI_SYSTEM_INFO); prntln(CLI_SYSTEM_INFO);
char s[150]; char s[150];
sprintf(s,str(CLI_SYSTEM_OUTPUT).c_str(), 81920 - system_get_free_heap_size(), 100 - system_get_free_heap_size() / (81920 / 100), system_get_free_heap_size(), system_get_free_heap_size() / (81920 / 100), 81920); sprintf(s, str(CLI_SYSTEM_OUTPUT).c_str(), 81920 - system_get_free_heap_size(),
100 - system_get_free_heap_size() / (81920 / 100), system_get_free_heap_size(),
system_get_free_heap_size() / (81920 / 100), 81920);
prntln(String(s)); prntln(String(s));
prnt(CLI_SYSTEM_CHANNEL); prnt(CLI_SYSTEM_CHANNEL);
@@ -697,12 +711,15 @@ void SerialInterface::runCommand(String input) {
FSInfo fs_info; FSInfo fs_info;
SPIFFS.info(fs_info); SPIFFS.info(fs_info);
sprintf(s,str(CLI_SYSTEM_RAM_OUT).c_str(), fs_info.usedBytes, fs_info.usedBytes / (fs_info.totalBytes / 100), fs_info.totalBytes - fs_info.usedBytes, (fs_info.totalBytes - fs_info.usedBytes) / (fs_info.totalBytes / 100), fs_info.totalBytes); sprintf(s, str(
CLI_SYSTEM_RAM_OUT).c_str(), fs_info.usedBytes, fs_info.usedBytes / (fs_info.totalBytes / 100), fs_info.totalBytes - fs_info.usedBytes,
(fs_info.totalBytes - fs_info.usedBytes) / (fs_info.totalBytes / 100), fs_info.totalBytes);
prnt(String(s)); prnt(String(s));
sprintf(s, str(CLI_SYSTEM_SPIFFS_OUT).c_str(), fs_info.blockSize, fs_info.pageSize); sprintf(s, str(CLI_SYSTEM_SPIFFS_OUT).c_str(), fs_info.blockSize, fs_info.pageSize);
prnt(String(s)); prnt(String(s));
prntln(CLI_FILES); prntln(CLI_FILES);
Dir dir = SPIFFS.openDir(String(SLASH)); Dir dir = SPIFFS.openDir(String(SLASH));
while (dir.next()) { while (dir.next()) {
prnt(String(SPACE) + String(SPACE) + dir.fileName() + String(SPACE)); prnt(String(SPACE) + String(SPACE) + dir.fileName() + String(SPACE));
File f = dir.openFile("r"); File f = dir.openFile("r");
@@ -722,10 +739,9 @@ void SerialInterface::runCommand(String input) {
// ===== CLEAR ===== // // ===== CLEAR ===== //
// clear // clear
else if (eqlsCMD(0, CLI_CLEAR)) { else if (eqlsCMD(0, CLI_CLEAR)) {
for (int i = 0; i < 100; i++) for (int i = 0; i < 100; i++) prnt(HASHSIGN);
prnt(HASHSIGN);
for (int i = 0; i < 60; i++) for (int i = 0; i < 60; i++) prntln();
prntln();
} }
// ===== REBOOT ===== // // ===== REBOOT ===== //
@@ -744,7 +760,7 @@ void SerialInterface::runCommand(String input) {
// ===== DELETE ==== // // ===== DELETE ==== //
// delete <file> [<lineFrom>] [<lineTo>] // delete <file> [<lineFrom>] [<lineTo>]
else if (list->size() >= 2 && eqlsCMD(0, CLI_DELETE)) { else if ((list->size() >= 2) && eqlsCMD(0, CLI_DELETE)) {
if (list->size() == 2) { if (list->size() == 2) {
// remove whole file // remove whole file
if (removeFile(list->get(1))) { if (removeFile(list->get(1))) {
@@ -758,6 +774,7 @@ void SerialInterface::runCommand(String input) {
// remove certain lines // remove certain lines
int beginLine = list->get(2).toInt(); int beginLine = list->get(2).toInt();
int endLine = list->size() == 4 ? list->get(3).toInt() : beginLine; int endLine = list->size() == 4 ? list->get(3).toInt() : beginLine;
if (removeLines(list->get(1), beginLine, endLine)) { if (removeLines(list->get(1), beginLine, endLine)) {
prnt(CLI_REMOVING_LINES); prnt(CLI_REMOVING_LINES);
prnt(beginLine); prnt(beginLine);
@@ -773,7 +790,7 @@ void SerialInterface::runCommand(String input) {
// ===== COPY ==== // // ===== COPY ==== //
// delete <file> <newfile> // delete <file> <newfile>
else if (list->size() == 3 && eqlsCMD(0, CLI_COPY)) { else if ((list->size() == 3) && eqlsCMD(0, CLI_COPY)) {
if (copyFile(list->get(1), list->get(2))) { if (copyFile(list->get(1), list->get(2))) {
prntln(CLI_COPIED_FILES); prntln(CLI_COPIED_FILES);
} else { } else {
@@ -783,7 +800,7 @@ void SerialInterface::runCommand(String input) {
// ===== RENAME ==== // // ===== RENAME ==== //
// delete <file> <newfile> // delete <file> <newfile>
else if (list->size() == 3 && eqlsCMD(0, CLI_RENAME)) { else if ((list->size() == 3) && eqlsCMD(0, CLI_RENAME)) {
if (renameFile(list->get(1), list->get(2))) { if (renameFile(list->get(1), list->get(2))) {
prntln(CLI_RENAMED_FILE); prntln(CLI_RENAMED_FILE);
} else { } else {
@@ -793,13 +810,15 @@ void SerialInterface::runCommand(String input) {
// ===== WRITE ==== // // ===== WRITE ==== //
// write <file> <commands> // write <file> <commands>
else if (list->size() >= 3 && eqlsCMD(0, CLI_WRITE)) { else if ((list->size() >= 3) && eqlsCMD(0, CLI_WRITE)) {
String path = list->get(1); String path = list->get(1);
String buf = String(); String buf = String();
int listSize = list->size(); int listSize = list->size();
for (int i = 2; i < listSize; i++) { for (int i = 2; i < listSize; i++) {
buf += list->get(i); buf += list->get(i);
if (i < listSize - 1) buf += SPACE; if (i < listSize - 1) buf += SPACE;
} }
@@ -814,13 +833,16 @@ void SerialInterface::runCommand(String input) {
// ===== REPLACE ==== // // ===== REPLACE ==== //
// replace <file> <line> <new-content> // replace <file> <line> <new-content>
else if (list->size() >= 4 && eqlsCMD(0, CLI_REPLACE)) { else if ((list->size() >= 4) && eqlsCMD(0, CLI_REPLACE)) {
int line = list->get(2).toInt(); int line = list->get(2).toInt();
String tmp = String(); String tmp = String();
for (int i = 3; i < list->size(); i++) { for (int i = 3; i < list->size(); i++) {
tmp += list->get(i); tmp += list->get(i);
if (i < list->size() - 1) tmp += SPACE; if (i < list->size() - 1) tmp += SPACE;
} }
if (replaceLine(list->get(1), line, tmp)) { if (replaceLine(list->get(1), line, tmp)) {
prnt(CLI_REPLACED_LINE); prnt(CLI_REPLACED_LINE);
prnt(line); prnt(line);
@@ -834,14 +856,17 @@ void SerialInterface::runCommand(String input) {
// ===== RUN ==== // // ===== RUN ==== //
// run <file> [continue <num>] // run <file> [continue <num>]
else if (!executing && list->size() >= 2 && eqlsCMD(0, CLI_RUN)) { else if (!executing && (list->size() >= 2) && eqlsCMD(0, CLI_RUN)) {
executing = true; executing = true;
execPath = list->get(1); execPath = list->get(1);
if (eqlsCMD(2, CLI_CONTINUE)) { if (eqlsCMD(2, CLI_CONTINUE)) {
continuously = true; continuously = true;
continueTime = 10000; continueTime = 10000;
if (list->size() == 3) { if (list->size() == 3) {
continueTime = getTime(list->get(3)); continueTime = getTime(list->get(3));
if (continueTime < 1000) continueTime = 1000; if (continueTime < 1000) continueTime = 1000;
} }
} }
@@ -849,7 +874,7 @@ void SerialInterface::runCommand(String input) {
// ===== PRINT ==== // // ===== PRINT ==== //
// print <file> [<lines>] // print <file> [<lines>]
else if (list->size() >= 2 && eqlsCMD(0, CLI_PRINT)) { else if ((list->size() >= 2) && eqlsCMD(0, CLI_PRINT)) {
readFileToSerial(list->get(1), eqlsCMD(2, CLI_LINE)); readFileToSerial(list->get(1), eqlsCMD(2, CLI_LINE));
prntln(); prntln();
} }
@@ -868,7 +893,7 @@ void SerialInterface::runCommand(String input) {
// ===== SEND ===== // // ===== SEND ===== //
// send deauth <apMac> <stMac> <rason> <channel> // send deauth <apMac> <stMac> <rason> <channel>
else if (eqlsCMD(0, CLI_SEND) && list->size() == 6 && eqlsCMD(1, CLI_DEAUTH)) { else if (eqlsCMD(0, CLI_SEND) && (list->size() == 6) && eqlsCMD(1, CLI_DEAUTH)) {
uint8_t apMac[6]; uint8_t apMac[6];
uint8_t stMac[6]; uint8_t stMac[6];
strToMac(list->get(2), apMac); strToMac(list->get(2), apMac);
@@ -883,13 +908,13 @@ void SerialInterface::runCommand(String input) {
} }
// send beacon <mac> <ssid> <ch> [wpa2] // send beacon <mac> <ssid> <ch> [wpa2]
else if (eqlsCMD(0, CLI_SEND) && list->size() >= 5 && eqlsCMD(1, CLI_BEACON)) { else if (eqlsCMD(0, CLI_SEND) && (list->size() >= 5) && eqlsCMD(1, CLI_BEACON)) {
uint8_t mac[6]; uint8_t mac[6];
strToMac(list->get(2), mac); strToMac(list->get(2), mac);
uint8_t channel = list->get(4).toInt(); uint8_t channel = list->get(4).toInt();
String ssid = list->get(3); String ssid = list->get(3);
for (int i = ssid.length(); i < 32; i++)
ssid += SPACE; for (int i = ssid.length(); i < 32; i++) ssid += SPACE;
prnt(CLI_SENDING_BEACON); prnt(CLI_SENDING_BEACON);
prnt(list->get(3)); prnt(list->get(3));
prntln(DOUBLEQUOTES); prntln(DOUBLEQUOTES);
@@ -897,13 +922,13 @@ void SerialInterface::runCommand(String input) {
} }
// send probe <mac> <ssid> <ch> // send probe <mac> <ssid> <ch>
else if (eqlsCMD(0, CLI_SEND) && list->size() == 5 && eqlsCMD(1, CLI_PROBE)) { else if (eqlsCMD(0, CLI_SEND) && (list->size() == 5) && eqlsCMD(1, CLI_PROBE)) {
uint8_t mac[6]; uint8_t mac[6];
strToMac(list->get(2), mac); strToMac(list->get(2), mac);
uint8_t channel = list->get(4).toInt(); uint8_t channel = list->get(4).toInt();
String ssid = list->get(3); String ssid = list->get(3);
for (int i = ssid.length(); i < 32; i++)
ssid += SPACE; for (int i = ssid.length(); i < 32; i++) ssid += SPACE;
prnt(CLI_SENDING_PROBE); prnt(CLI_SENDING_PROBE);
prnt(list->get(3)); prnt(list->get(3));
prntln(DOUBLEQUOTES); prntln(DOUBLEQUOTES);
@@ -918,8 +943,8 @@ void SerialInterface::runCommand(String input) {
uint16_t packetSize = packetStr.length() / 2; uint16_t packetSize = packetStr.length() / 2;
uint8_t packet[packetSize]; uint8_t packet[packetSize];
for (int i = 0; i < packetSize; i++) for (int i = 0; i < packetSize; i++) packet[i] = strtoul((packetStr.substring(i * 2,
packet[i] = strtoul((packetStr.substring(i * 2, i * 2 + 2)).c_str(), NULL, 16); i * 2 + 2)).c_str(), NULL, 16);
if (attack.sendPacket(packet, packetSize, wifi_channel, 10)) { if (attack.sendPacket(packet, packetSize, wifi_channel, 10)) {
prntln(CLI_CUSTOM_SENT); prntln(CLI_CUSTOM_SENT);
@@ -931,52 +956,42 @@ void SerialInterface::runCommand(String input) {
// ===== LED ===== // // ===== LED ===== //
// led <r> <g> <b> [<brightness>] // led <r> <g> <b> [<brightness>]
else if (list->size() >= 4 && list->size() <= 5 && eqlsCMD(0, CLI_LED)) { else if ((list->size() >= 4) && (list->size() <= 5) && eqlsCMD(0, CLI_LED)) {
if (list->size() == 4) { if (list->size() == 4) {
#ifdef DIGITAL_LED led->setColor(list->get(1).toInt(), list->get(2).toInt(), list->get(3).toInt(), true);
led.setColor(list->get(1).toInt(), list->get(2).toInt(), list->get(3).toInt());
#endif
} else { } else {
#ifdef DIGITAL_LED led->setColor(list->get(1).toInt(), list->get(2).toInt(), list->get(3).toInt(), list->get(4).toInt(), true);
led.setColor(list->get(1).toInt(), list->get(2).toInt(), list->get(3).toInt(), list->get(4).toInt());
#endif
} }
} }
// led <#rrggbb> [<brightness>] // led <#rrggbb> [<brightness>]
else if (list->size() >= 2 && list->size() <= 3 && eqlsCMD(0, CLI_LED) && list->get(1).charAt(0) == HASHSIGN) { else if ((list->size() >= 2) && (list->size() <= 3) &&
eqlsCMD(0, CLI_LED) && (list->get(1).charAt(0) == HASHSIGN)) {
uint8_t c[3]; uint8_t c[3];
strToColor(list->get(1), c); strToColor(list->get(1), c);
if (list->size() == 2) { if (list->size() == 2) {
#ifdef DIGITAL_LED led->setColor(c[0], c[1], c[2], true);
led.setColor(c[0], c[1], c[2]);
#endif
} else { } else {
#ifdef DIGITAL_LED led->setColor(c[0], c[1], c[2], list->get(2).toInt(), true);
led.setColor(c[0], c[1], c[2], list->get(2).toInt());
#endif
} }
} }
// led <enable/disable> // led <enable/disable>
else if (list->size() == 2 && eqlsCMD(0, CLI_LED)) { else if ((list->size() == 2) && eqlsCMD(0, CLI_LED)) {
if (eqlsCMD(1, CLI_ENABLE)) { if (eqlsCMD(1, CLI_ENABLE)) {
#ifdef DIGITAL_LED led->tempEnable();
led.tempEnable();
#endif
} else if (eqlsCMD(1, CLI_DISABLE)) { } else if (eqlsCMD(1, CLI_DISABLE)) {
#ifdef DIGITAL_LED led->tempDisable();
led.tempDisable();
#endif
} else { } else {
parameterError(list->get(1)); parameterError(list->get(1));
} }
} }
// ===== DELAY ===== // // ===== DELAY ===== //
else if (list->size() == 2 && eqlsCMD(0, CLI_DELAY)) { else if ((list->size() == 2) && eqlsCMD(0, CLI_DELAY)) {
uint32_t endTime = currentTime + getTime(list->get(1)); uint32_t endTime = currentTime + getTime(list->get(1));
while (currentTime < endTime) { while (currentTime < endTime) {
// ------- loop function ----- // // ------- loop function ----- //
currentTime = millis(); currentTime = millis();
@@ -985,12 +1000,10 @@ void SerialInterface::runCommand(String input) {
scan.update(); // run scan scan.update(); // run scan
attack.update(); // run attacks attack.update(); // run attacks
ssids.update(); // run random mode, if enabled ssids.update(); // run random mode, if enabled
#ifdef DIGITAL_LED led->update(); // update LED color
led.update(); // update LED color
#endif
// auto-save // auto-save
if (settings.getAutosave() && currentTime - autosaveTime > settings.getAutosaveTime()) { if (settings.getAutosave() && (currentTime - autosaveTime > settings.getAutosaveTime())) {
autosaveTime = currentTime; autosaveTime = currentTime;
names.save(false); names.save(false);
ssids.save(false); ssids.save(false);
@@ -1005,11 +1018,14 @@ void SerialInterface::runCommand(String input) {
else if (eqlsCMD(0, CLI_DRAW)) { else if (eqlsCMD(0, CLI_DRAW)) {
int height = 25; int height = 25;
int width = 2; int width = 2;
if (list->size() >= 2) height = list->get(1).toInt(); if (list->size() >= 2) height = list->get(1).toInt();
if (list->size() >= 3) width = list->get(2).toInt(); if (list->size() >= 3) width = list->get(2).toInt();
double scale = scan.getScaleFactor(height); double scale = scan.getScaleFactor(height);
prnt(String(DASH) + String(DASH) + String(DASH) + String(DASH) + String(VERTICALBAR)); // ----| prnt(String(DASH) + String(DASH) + String(DASH) + String(DASH) + String(VERTICALBAR)); // ----|
for (int j = 0; j < SCAN_PACKET_LIST_SIZE; j++) { for (int j = 0; j < SCAN_PACKET_LIST_SIZE; j++) {
for (int k = 0; k < width; k++) prnt(EQUALS); for (int k = 0; k < width; k++) prnt(EQUALS);
} }
@@ -1017,8 +1033,12 @@ void SerialInterface::runCommand(String input) {
for (int i = height; i >= 0; i--) { for (int i = height; i >= 0; i--) {
char s[200]; char s[200];
if (i == height) sprintf(s,str(CLI_DRAW_OUTPUT).c_str(), scan.getMaxPacket() > (uint32_t)height ? scan.getMaxPacket() : (uint32_t)height);
else if (i == height / 2) sprintf(s,str(CLI_DRAW_OUTPUT).c_str(), scan.getMaxPacket() > (uint32_t)height ? scan.getMaxPacket()/2 : (uint32_t)height/2); if (i == height) sprintf(s, str(CLI_DRAW_OUTPUT).c_str(),
scan.getMaxPacket() > (uint32_t)height ? scan.getMaxPacket() : (uint32_t)height);
else if (i == height / 2) sprintf(s, str(CLI_DRAW_OUTPUT).c_str(),
scan.getMaxPacket() >
(uint32_t)height ? scan.getMaxPacket() / 2 : (uint32_t)height / 2);
else if (i == 0) sprintf(s, str(CLI_DRAW_OUTPUT).c_str(), 0); else if (i == 0) sprintf(s, str(CLI_DRAW_OUTPUT).c_str(), 0);
else { else {
s[0] = SPACE; s[0] = SPACE;
@@ -1030,6 +1050,7 @@ void SerialInterface::runCommand(String input) {
prnt(String(s)); prnt(String(s));
prnt(VERTICALBAR); prnt(VERTICALBAR);
for (int j = 0; j < SCAN_PACKET_LIST_SIZE; j++) { for (int j = 0; j < SCAN_PACKET_LIST_SIZE; j++) {
if (scan.getPackets(j) * scale > i) { if (scan.getPackets(j) * scale > i) {
for (int k = 0; k < width; k++) prnt(HASHSIGN); for (int k = 0; k < width; k++) prnt(HASHSIGN);
@@ -1048,14 +1069,17 @@ void SerialInterface::runCommand(String input) {
prntln(VERTICALBAR); prntln(VERTICALBAR);
prnt(String(SPACE) + String(SPACE) + String(SPACE) + String(SPACE) + String(VERTICALBAR)); prnt(String(SPACE) + String(SPACE) + String(SPACE) + String(SPACE) + String(VERTICALBAR));
for (int j = 0; j < SCAN_PACKET_LIST_SIZE; j++) { for (int j = 0; j < SCAN_PACKET_LIST_SIZE; j++) {
char s[6]; char s[6];
String helper = String(PERCENT) + DASH + (String)width + D; String helper = String(PERCENT) + DASH + (String)width + D;
if (j == 0) sprintf(s, helper.c_str(), SCAN_PACKET_LIST_SIZE - 1); if (j == 0) sprintf(s, helper.c_str(), SCAN_PACKET_LIST_SIZE - 1);
else if (j == SCAN_PACKET_LIST_SIZE / 2) sprintf(s, helper.c_str(), SCAN_PACKET_LIST_SIZE / 2); else if (j == SCAN_PACKET_LIST_SIZE / 2) sprintf(s, helper.c_str(), SCAN_PACKET_LIST_SIZE / 2);
else if (j == SCAN_PACKET_LIST_SIZE - 1) sprintf(s, helper.c_str(), 0); else if (j == SCAN_PACKET_LIST_SIZE - 1) sprintf(s, helper.c_str(), 0);
else { else {
int k; int k;
for (k = 0; k < width; k++) s[k] = SPACE; for (k = 0; k < width; k++) s[k] = SPACE;
s[k] = ENDOFLINE; s[k] = ENDOFLINE;
} }
@@ -1072,7 +1096,7 @@ void SerialInterface::runCommand(String input) {
String password = settings.getPassword(); String password = settings.getPassword();
int ch = wifi_channel; int ch = wifi_channel;
bool hidden = settings.getHidden(); bool hidden = settings.getHidden();
bool captivePortal = settings.getCaptivePortal();; bool captivePortal = settings.getCaptivePortal();
for (int i = 1; i < list->size(); i++) { for (int i = 1; i < list->size(); i++) {
if (eqlsCMD(i, CLI_PATH)) { if (eqlsCMD(i, CLI_PATH)) {
@@ -1130,6 +1154,7 @@ void SerialInterface::runCommand(String input) {
prnt(input); prnt(input);
prntln(CLI_ERROR_NOT_FOUND_B); prntln(CLI_ERROR_NOT_FOUND_B);
// some debug stuff // some debug stuff
/* /*
Serial.println(list->get(0)); Serial.println(list->get(0));
for(int i=0;i<input.length();i++){ for(int i=0;i<input.length();i++){
@@ -1139,5 +1164,3 @@ void SerialInterface::runCommand(String input) {
*/ */
} }
} }

View File

@@ -16,22 +16,9 @@ extern "C" {
#include "Scan.h" #include "Scan.h"
#include "Attack.h" #include "Attack.h"
#include "DisplayUI.h" #include "DisplayUI.h"
#include "DigitalLed.h" #include "LEDController.h"
#include "RGBLed.h"
#include "Neopixel.h"
#ifdef DIGITAL_LED
extern DigitalLed led;
#endif
#ifdef RGB_LED
extern RGBLed led;
#endif
#ifdef NEOPIXEL_LED
extern Neopixel led;
#endif
extern LEDController* led;
extern Settings settings; extern Settings settings;
extern Names names; extern Names names;
extern SSIDs ssids; extern SSIDs ssids;
@@ -94,7 +81,4 @@ class SerialInterface {
bool eqlsCMD(int i, const char* keyword); bool eqlsCMD(int i, const char* keyword);
}; };
#endif #endif // ifndef SerialInterface_h

View File

@@ -10,6 +10,7 @@ void Settings::load() {
// check & read file // check & read file
String json = getJsonStr(); String json = getJsonStr();
checkFile(FILE_PATH, json); checkFile(FILE_PATH, json);
JsonObject& data = parseJSONFile(FILE_PATH, jsonBuffer); JsonObject& data = parseJSONFile(FILE_PATH, jsonBuffer);
@@ -18,36 +19,59 @@ void Settings::load() {
// AP // AP
if (data.containsKey(keyword(S_SSID))) setSSID(data.get<String>(keyword(S_SSID))); if (data.containsKey(keyword(S_SSID))) setSSID(data.get<String>(keyword(S_SSID)));
if (data.containsKey(keyword(S_PASSWORD))) setPassword(data.get<String>(keyword(S_PASSWORD))); if (data.containsKey(keyword(S_PASSWORD))) setPassword(data.get<String>(keyword(S_PASSWORD)));
if (data.containsKey(keyword(S_CHANNEL))) setChannel(data.get<uint8_t>(keyword(S_CHANNEL))); if (data.containsKey(keyword(S_CHANNEL))) setChannel(data.get<uint8_t>(keyword(S_CHANNEL)));
if (data.containsKey(keyword(S_HIDDEN))) setHidden(data.get<bool>(keyword(S_HIDDEN))); if (data.containsKey(keyword(S_HIDDEN))) setHidden(data.get<bool>(keyword(S_HIDDEN)));
if (data.containsKey(keyword(S_CAPTIVEPORTAL))) setCaptivePortal(data.get<bool>(keyword(S_CAPTIVEPORTAL))); if (data.containsKey(keyword(S_CAPTIVEPORTAL))) setCaptivePortal(data.get<bool>(keyword(S_CAPTIVEPORTAL)));
// GENERAL // GENERAL
if (data.containsKey(keyword(S_LANG))) setLang(data.get<String>(keyword(S_LANG))); if (data.containsKey(keyword(S_LANG))) setLang(data.get<String>(keyword(S_LANG)));
if (data.containsKey(keyword(S_DISPLAYINTERFACE))) setDisplayInterface(data.get<bool>(keyword(S_DISPLAYINTERFACE))); if (data.containsKey(keyword(S_DISPLAYINTERFACE))) setDisplayInterface(data.get<bool>(keyword(S_DISPLAYINTERFACE)));
if (data.containsKey(keyword(S_DISPLAY_TIMEOUT))) setDisplayTimeout(data.get<uint32_t>(keyword(S_DISPLAY_TIMEOUT))); if (data.containsKey(keyword(S_DISPLAY_TIMEOUT))) setDisplayTimeout(data.get<uint32_t>(keyword(S_DISPLAY_TIMEOUT)));
if (data.containsKey(keyword(S_SERIALINTERFACE))) setSerialInterface(data.get<bool>(keyword(S_SERIALINTERFACE))); if (data.containsKey(keyword(S_SERIALINTERFACE))) setSerialInterface(data.get<bool>(keyword(S_SERIALINTERFACE)));
if (data.containsKey(keyword(S_SERIAL_ECHO))) setSerialEcho(data.get<bool>(keyword(S_SERIAL_ECHO))); if (data.containsKey(keyword(S_SERIAL_ECHO))) setSerialEcho(data.get<bool>(keyword(S_SERIAL_ECHO)));
if (data.containsKey(keyword(S_WEBINTERFACE))) setWebInterface(data.get<bool>(keyword(S_WEBINTERFACE))); if (data.containsKey(keyword(S_WEBINTERFACE))) setWebInterface(data.get<bool>(keyword(S_WEBINTERFACE)));
if (data.containsKey(keyword(S_WEB_SPIFFS))) setWebSpiffs(data.get<bool>(keyword(S_WEB_SPIFFS))); if (data.containsKey(keyword(S_WEB_SPIFFS))) setWebSpiffs(data.get<bool>(keyword(S_WEB_SPIFFS)));
if (data.containsKey(keyword(S_LEDENABLED))) setLedEnabled(data.get<bool>(keyword(S_LEDENABLED))); if (data.containsKey(keyword(S_LEDENABLED))) setLedEnabled(data.get<bool>(keyword(S_LEDENABLED)));
if (data.containsKey(keyword(S_MAXCH))) setMaxCh(data.get<uint8_t>(keyword(S_MAXCH))); if (data.containsKey(keyword(S_MAXCH))) setMaxCh(data.get<uint8_t>(keyword(S_MAXCH)));
if (data.containsKey(keyword(S_MACAP))) setMacAP(data.get<String>(keyword(S_MACAP))); if (data.containsKey(keyword(S_MACAP))) setMacAP(data.get<String>(keyword(S_MACAP)));
if (data.containsKey(keyword(S_MACST))) setMacSt(data.get<String>(keyword(S_MACST))); if (data.containsKey(keyword(S_MACST))) setMacSt(data.get<String>(keyword(S_MACST)));
// SCAN // SCAN
if (data.containsKey(keyword(S_CHTIME))) setChTime(data.get<uint16_t>(keyword(S_CHTIME))); if (data.containsKey(keyword(S_CHTIME))) setChTime(data.get<uint16_t>(keyword(S_CHTIME)));
if (data.containsKey(keyword(S_MIN_DEAUTHS))) setMinDeauths(data.get<uint16_t>(keyword(S_MIN_DEAUTHS))); if (data.containsKey(keyword(S_MIN_DEAUTHS))) setMinDeauths(data.get<uint16_t>(keyword(S_MIN_DEAUTHS)));
// ATTACK // ATTACK
if (data.containsKey(keyword(S_ATTACKTIMEOUT))) setAttackTimeout(data.get<uint32_t>(keyword(S_ATTACKTIMEOUT))); if (data.containsKey(keyword(S_ATTACKTIMEOUT))) setAttackTimeout(data.get<uint32_t>(keyword(S_ATTACKTIMEOUT)));
if (data.containsKey(keyword(S_FORCEPACKETS))) setForcePackets(data.get<uint8_t>(keyword(S_FORCEPACKETS))); if (data.containsKey(keyword(S_FORCEPACKETS))) setForcePackets(data.get<uint8_t>(keyword(S_FORCEPACKETS)));
if(data.containsKey(keyword(S_DEAUTHSPERTARGET))) setDeauthsPerTarget(data.get<uint16_t>(keyword(S_DEAUTHSPERTARGET)));
if (data.containsKey(keyword(S_DEAUTHSPERTARGET))) setDeauthsPerTarget(data.get<uint16_t>(keyword(
S_DEAUTHSPERTARGET)));
if (data.containsKey(keyword(S_DEAUTHREASON))) setDeauthReason(data.get<uint8_t>(keyword(S_DEAUTHREASON))); if (data.containsKey(keyword(S_DEAUTHREASON))) setDeauthReason(data.get<uint8_t>(keyword(S_DEAUTHREASON)));
if (data.containsKey(keyword(S_BEACONCHANNEL))) setBeaconChannel(data.get<bool>(keyword(S_BEACONCHANNEL))); if (data.containsKey(keyword(S_BEACONCHANNEL))) setBeaconChannel(data.get<bool>(keyword(S_BEACONCHANNEL)));
if (data.containsKey(keyword(S_BEACONINTERVAL))) setBeaconInterval(data.get<bool>(keyword(S_BEACONINTERVAL))); if (data.containsKey(keyword(S_BEACONINTERVAL))) setBeaconInterval(data.get<bool>(keyword(S_BEACONINTERVAL)));
if (data.containsKey(keyword(S_RANDOMTX))) setRandomTX(data.get<bool>(keyword(S_RANDOMTX))); if (data.containsKey(keyword(S_RANDOMTX))) setRandomTX(data.get<bool>(keyword(S_RANDOMTX)));
if (data.containsKey(keyword(S_PROBESPERSSID))) setProbesPerSSID(data.get<uint8_t>(keyword(S_PROBESPERSSID))); if (data.containsKey(keyword(S_PROBESPERSSID))) setProbesPerSSID(data.get<uint8_t>(keyword(S_PROBESPERSSID)));
if (version != VERSION) { if (version != VERSION) {
@@ -62,6 +86,7 @@ void Settings::load() {
// check and fix mac // check and fix mac
if (!macValid(macSt)) getRandomMac(macSt); if (!macValid(macSt)) getRandomMac(macSt);
if (!macValid(macAP)) getRandomMac(macAP); if (!macValid(macAP)) getRandomMac(macAP);
save(true); // force saving save(true); // force saving
@@ -69,6 +94,7 @@ void Settings::load() {
void Settings::load(String filepath) { void Settings::load(String filepath) {
String tmp = FILE_PATH; String tmp = FILE_PATH;
FILE_PATH = filepath; FILE_PATH = filepath;
load(); load();
FILE_PATH = tmp; FILE_PATH = tmp;
@@ -169,6 +195,7 @@ String Settings::getJsonStr() {
void Settings::save(bool force) { void Settings::save(bool force) {
if (force || changed) { if (force || changed) {
String buf = getJsonStr(); String buf = getJsonStr();
if (writeFile(FILE_PATH, buf)) { if (writeFile(FILE_PATH, buf)) {
prnt(S_SETTINGS_SAVED); prnt(S_SETTINGS_SAVED);
prntln(FILE_PATH); prntln(FILE_PATH);
@@ -182,6 +209,7 @@ void Settings::save(bool force) {
void Settings::save(bool force, String filepath) { void Settings::save(bool force, String filepath) {
String tmp = FILE_PATH; String tmp = FILE_PATH;
FILE_PATH = filepath; FILE_PATH = filepath;
save(force); save(force);
FILE_PATH = tmp; FILE_PATH = tmp;
@@ -189,6 +217,7 @@ void Settings::save(bool force, String filepath) {
void Settings::print() { void Settings::print() {
String settingsJson = getJsonStr(); String settingsJson = getJsonStr();
settingsJson.replace("{", "{\r\n"); settingsJson.replace("{", "{\r\n");
settingsJson.replace("}", "\r\n}"); settingsJson.replace("}", "\r\n}");
settingsJson.replace(",", "\r\n"); settingsJson.replace(",", "\r\n");
@@ -455,7 +484,7 @@ void Settings::setBeaconInterval(bool beaconInterval) {
} }
void Settings::setChannel(uint8_t channel) { void Settings::setChannel(uint8_t channel) {
if (channel >= 1 && channel <= maxCh) { if ((channel >= 1) && (channel <= maxCh)) {
Settings::channel = channel; Settings::channel = channel;
setWifiChannel(channel); setWifiChannel(channel);
changed = true; changed = true;
@@ -468,7 +497,7 @@ void Settings::setChannel(uint8_t channel) {
} }
void Settings::setSSID(String ssid) { void Settings::setSSID(String ssid) {
if (ssid.length() > 0 && ssid.length() <= 32) { if ((ssid.length() > 0) && (ssid.length() <= 32)) {
ssid = fixUtf8(ssid); ssid = fixUtf8(ssid);
Settings::ssid = ssid; Settings::ssid = ssid;
changed = true; changed = true;
@@ -478,7 +507,7 @@ void Settings::setSSID(String ssid) {
} }
void Settings::setPassword(String password) { void Settings::setPassword(String password) {
if (password.length() >= 8 && password.length() <= 32) { if ((password.length() >= 8) && (password.length() <= 32)) {
password = fixUtf8(password); password = fixUtf8(password);
Settings::password = password; Settings::password = password;
changed = true; changed = true;
@@ -510,10 +539,8 @@ void Settings::setChTime(uint16_t chTime) {
void Settings::setMacSt(String macStr) { void Settings::setMacSt(String macStr) {
uint8_t mac[6]; uint8_t mac[6];
if(eqls(macStr, S_RANDOM)) if (eqls(macStr, S_RANDOM)) getRandomMac(mac);
getRandomMac(mac); else strToMac(macStr, mac);
else
strToMac(macStr, mac);
setMacSt(mac); setMacSt(mac);
} }
@@ -530,10 +557,8 @@ bool Settings::setMacSt(uint8_t* macSt){
void Settings::setMacAP(String macStr) { void Settings::setMacAP(String macStr) {
uint8_t mac[6]; uint8_t mac[6];
if(eqls(macStr, S_RANDOM)) if (eqls(macStr, S_RANDOM)) getRandomMac(mac);
getRandomMac(mac); else strToMac(macStr, mac);
else
strToMac(macStr, mac);
setMacAP(mac); setMacAP(mac);
} }
@@ -603,4 +628,3 @@ void Settings::setWebSpiffs(bool webSpiffs){
Settings::webSpiffs = webSpiffs; Settings::webSpiffs = webSpiffs;
changed = true; changed = true;
} }

View File

@@ -6,11 +6,11 @@
extern "C" { extern "C" {
#include "user_interface.h" #include "user_interface.h"
} }
#include <ArduinoJson.h> #include "ArduinoJson.h"
#include "language.h" #include "language.h"
#include "A_config.h" #include "A_config.h"
#define VERSION "v2.0.5" #define VERSION "v2.0.6"
extern void checkFile(String path, String data); extern void checkFile(String path, String data);
extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer); extern JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer);
@@ -97,6 +97,7 @@ class Settings {
void setLang(String lang); void setLang(String lang);
void setSerialEcho(bool serialEcho); void setSerialEcho(bool serialEcho);
void setWebSpiffs(bool webSpiffs); void setWebSpiffs(bool webSpiffs);
private: private:
bool changed = false; bool changed = false;
@@ -138,7 +139,4 @@ class Settings {
String getJsonStr(); String getJsonStr();
}; };
#endif #endif // ifndef Settings_h

View File

@@ -32,6 +32,7 @@ class SimpleList{
virtual void clear(); virtual void clear();
virtual void sort(std::function<bool(T& a, T& b)>cmp); virtual void sort(std::function<bool(T& a, T& b)>cmp);
virtual void swap(int x, int y); virtual void swap(int x, int y);
protected: protected:
int listSize; int listSize;
Node<T>* listBegin; Node<T>* listBegin;
@@ -71,13 +72,12 @@ SimpleList<T>::~SimpleList(){
template<typename T> template<typename T>
Node<T>* SimpleList<T>::getNode(int index) { Node<T>* SimpleList<T>::getNode(int index) {
if(index < 0 || index >= listSize) if ((index < 0) || (index >= listSize)) return NULL;
return NULL;
Node<T>* hNode = listBegin; Node<T>* hNode = listBegin;
int c = 0; int c = 0;
if(isCached && index >= lastIndexGot){ if (isCached && (index >= lastIndexGot)) {
c = lastIndexGot; c = lastIndexGot;
hNode = lastNodeGot; hNode = lastNodeGot;
} }
@@ -107,8 +107,7 @@ void SimpleList<T>::add(T obj){
node->data = obj; node->data = obj;
node->next = NULL; node->next = NULL;
if(!listBegin) if (!listBegin) listBegin = node;
listBegin = node;
if (listEnd) { if (listEnd) {
listEnd->next = node; listEnd->next = node;
@@ -122,7 +121,7 @@ void SimpleList<T>::add(T obj){
template<typename T> template<typename T>
void SimpleList<T>::add(int index, T obj) { void SimpleList<T>::add(int index, T obj) {
if(index < 0 || index >= listSize){ if ((index < 0) || (index >= listSize)) {
add(obj); add(obj);
return; return;
} }
@@ -131,8 +130,7 @@ void SimpleList<T>::add(int index, T obj){
nodeNew->data = obj; nodeNew->data = obj;
nodeNew->next = NULL; nodeNew->next = NULL;
if(index == 0) if (index == 0) listBegin = nodeNew;
listBegin = nodeNew;
else { else {
Node<T>* nodePrev = getNode(index - 1); Node<T>* nodePrev = getNode(index - 1);
nodeNew->next = nodePrev->next; nodeNew->next = nodePrev->next;
@@ -144,15 +142,14 @@ void SimpleList<T>::add(int index, T obj){
template<typename T> template<typename T>
void SimpleList<T>::replace(int index, T obj) { void SimpleList<T>::replace(int index, T obj) {
if(index >= 0 && index < listSize){ if ((index >= 0) && (index < listSize)) {
getNode(index)->data = obj; getNode(index)->data = obj;
} }
} }
template<typename T> template<typename T>
void SimpleList<T>::remove(int index) { void SimpleList<T>::remove(int index) {
if (index < 0 || index >= listSize) if ((index < 0) || (index >= listSize)) return;
return;
Node<T>* nodePrev = getNode(index - 1); Node<T>* nodePrev = getNode(index - 1);
Node<T>* nodeToDelete = getNode(index); Node<T>* nodeToDelete = getNode(index);
@@ -161,8 +158,8 @@ void SimpleList<T>::remove(int index){
listBegin = nodeToDelete->next; listBegin = nodeToDelete->next;
} else { } else {
nodePrev->next = nodeToDelete->next; nodePrev->next = nodeToDelete->next;
if(!nodePrev->next)
listEnd = nodePrev; if (!nodePrev->next) listEnd = nodePrev;
} }
delete nodeToDelete; delete nodeToDelete;
@@ -175,12 +172,13 @@ void SimpleList<T>::remove(int index){
template<typename T> template<typename T>
T SimpleList<T>::get(int index) { T SimpleList<T>::get(int index) {
Node<T>* hNode = getNode(index); Node<T>* hNode = getNode(index);
return (hNode ? hNode->data : T()); return hNode ? hNode->data : T();
} }
template<typename T> template<typename T>
int SimpleList<T>::search(std::function<bool(T& a)>cmp) { int SimpleList<T>::search(std::function<bool(T& a)>cmp) {
int i = 0; int i = 0;
Node<T>* hNode = getNode(i); Node<T>* hNode = getNode(i);
bool found = cmp(hNode->data); bool found = cmp(hNode->data);
@@ -196,6 +194,7 @@ int SimpleList<T>::search(std::function<bool(T &a)> cmp){
template<typename T> template<typename T>
int SimpleList<T>::searchNext(std::function<bool(T& a)>cmp) { int SimpleList<T>::searchNext(std::function<bool(T& a)>cmp) {
int i = lastIndexGot; int i = lastIndexGot;
Node<T>* hNode = lastNodeGot; Node<T>* hNode = lastNodeGot;
bool found = cmp(hNode->data); bool found = cmp(hNode->data);
@@ -212,6 +211,7 @@ template<typename T>
int SimpleList<T>::binSearch(std::function<int(T& a)>cmp, int lowerEnd, int upperEnd) { int SimpleList<T>::binSearch(std::function<int(T& a)>cmp, int lowerEnd, int upperEnd) {
int res; int res;
int mid = (lowerEnd + upperEnd) / 2; int mid = (lowerEnd + upperEnd) / 2;
Node<T>* hNode = listBegin; Node<T>* hNode = listBegin;
int hIndex = 0; int hIndex = 0;
@@ -257,8 +257,7 @@ int SimpleList<T>::count(std::function<bool(T &a)> cmp){
template<typename T> template<typename T>
T SimpleList<T>::pop() { T SimpleList<T>::pop() {
if(listSize <= 0) if (listSize <= 0) return T();
return T();
T data = listEnd->data; T data = listEnd->data;
remove(listSize - 1); remove(listSize - 1);
@@ -267,8 +266,7 @@ T SimpleList<T>::pop(){
template<typename T> template<typename T>
T SimpleList<T>::shift() { T SimpleList<T>::shift() {
if(listSize <= 0) if (listSize <= 0) return T();
return T();
T data = listBegin->data; T data = listBegin->data;
remove(0); remove(0);
@@ -277,14 +275,13 @@ T SimpleList<T>::shift(){
template<typename T> template<typename T>
void SimpleList<T>::clear() { void SimpleList<T>::clear() {
while(listSize > 0) while (listSize > 0) remove(0);
remove(0);
} }
template<typename T> template<typename T>
void SimpleList<T>::swap(int x, int y) { void SimpleList<T>::swap(int x, int y) {
// only continue when the index numbers are unequal and at least 0 // only continue when the index numbers are unequal and at least 0
if(x != y && x >= 0 && y >= 0){ if ((x != y) && (x >= 0) && (y >= 0)) {
if (x > y) { // the first index should be smaller than the second. If not, swap them! if (x > y) { // the first index should be smaller than the second. If not, swap them!
int h = x; int h = x;
x = y; x = y;
@@ -312,21 +309,18 @@ void SimpleList<T>::swap(int x, int y){
Node<T>* nodeI = getNode(y + 1); // y.next Node<T>* nodeI = getNode(y + 1); // y.next
// a -> h -> i b -> c -> ... -> g -> h -> i // a -> h -> i b -> c -> ... -> g -> h -> i
if(nodeA) if (nodeA) nodeA->next = nodeH;
nodeA->next = nodeH; else listBegin = nodeH;
else
listBegin = nodeH;
// a -> h -> c -> ... -> g -> h -> i b -> i // a -> h -> c -> ... -> g -> h -> i b -> i
if (nodeH != nodeC) // when nodes between b and h exist if (nodeH != nodeC) // when nodes between b and h exist
nodeH->next = nodeC; nodeH->next = nodeC;
else else nodeH->next = nodeB;
nodeH->next = nodeB;
// a -> h -> i b -> i // a -> h -> i b -> i
nodeB->next = nodeI; nodeB->next = nodeI;
if(!nodeI)
listEnd = nodeB; if (!nodeI) listEnd = nodeB;
// a -> h -> c -> ... -> g -> b -> i // a -> h -> c -> ... -> g -> b -> i
if (nodeG != nodeB) // when more than 1 nodes between b and h exist if (nodeG != nodeB) // when more than 1 nodes between b and h exist
@@ -341,6 +335,7 @@ void SimpleList<T>::sort(std::function<bool(T &a, T &b)> cmp) {
int indexH; // index of node i int indexH; // index of node i
int indexMin; // index of next minimum node int indexMin; // index of next minimum node
Node<T>* nodeMin; // next minimum node Node<T>* nodeMin; // next minimum node
Node<T>* nodeH; // helper node at index j Node<T>* nodeH; // helper node at index j
@@ -348,8 +343,10 @@ void SimpleList<T>::sort(std::function<bool(T &a, T &b)> cmp) {
nodeMin = getNode(i); nodeMin = getNode(i);
indexH = i; indexH = i;
indexMin = i; indexMin = i;
for (int j = i + 1; j < listSize; j++) { for (int j = i + 1; j < listSize; j++) {
nodeH = getNode(j); nodeH = getNode(j);
if (cmp(nodeMin->data, nodeH->data)) { if (cmp(nodeMin->data, nodeH->data)) {
nodeMin = nodeH; nodeMin = nodeH;
indexMin = j; indexMin = j;
@@ -359,4 +356,4 @@ void SimpleList<T>::sort(std::function<bool(T &a, T &b)> cmp) {
} }
} }
#endif #endif // ifndef SimpleList_h

View File

@@ -19,22 +19,22 @@ void Stations::add(uint8_t* mac, int accesspointNum) {
int Stations::findStation(uint8_t* mac) { int Stations::findStation(uint8_t* mac) {
int c = count(); int c = count();
for (int i = 0; i < c; i++) { for (int i = 0; i < c; i++) {
if (memcmp(getMac(i), mac, 6) == 0) if (memcmp(getMac(i), mac, 6) == 0) return i;
return i;
} }
return -1; return -1;
} }
void Stations::sort() { void Stations::sort() {
list->sort([](Station& a, Station& b) -> bool { list->sort([](Station& a, Station& b) -> bool {
return (*a.pkts < *b.pkts); return *a.pkts < *b.pkts;
}); });
} }
void Stations::sortAfterChannel() { void Stations::sortAfterChannel() {
list->sort([](Station& a, Station& b) -> bool { list->sort([](Station& a, Station& b) -> bool {
return (a.ch > b.ch); return a.ch > b.ch;
}); });
} }
@@ -46,6 +46,7 @@ void Stations::removeAll() {
void Stations::remove(int num) { void Stations::remove(int num) {
if (!check(num)) return; if (!check(num)) return;
internal_remove(num); internal_remove(num);
prnt(ST_REMOVED_STATION); prnt(ST_REMOVED_STATION);
prntln(num); prntln(num);
@@ -55,9 +56,9 @@ void Stations::remove(int num) {
void Stations::removeOldest() { void Stations::removeOldest() {
int oldest = 0; int oldest = 0;
int c = count(); int c = count();
for (int i = 1; i < c; i++) { for (int i = 1; i < c; i++) {
if (*getTime(i) > *getTime(oldest)) if (*getTime(i) > *getTime(oldest)) oldest = i;
oldest = i;
} }
internal_remove(oldest); internal_remove(oldest);
changed = true; changed = true;
@@ -66,11 +67,10 @@ void Stations::removeOldest() {
void Stations::printAll() { void Stations::printAll() {
prntln(ST_HEADER); prntln(ST_HEADER);
int c = count(); int c = count();
if (c == 0)
prntln(ST_LIST_EMPTY); if (c == 0) prntln(ST_LIST_EMPTY);
else else
for (int i = 0; i < c; i++) for (int i = 0; i < c; i++) print(i, i == 0, i == c - 1);
print(i, i == 0, i == c - 1);
} }
void Stations::printSelected() { void Stations::printSelected() {
@@ -97,6 +97,7 @@ void Stations::print(int num) {
void Stations::print(int num, bool header, bool footer) { void Stations::print(int num, bool header, bool footer) {
if (!check(num)) return; if (!check(num)) return;
if (header) { if (header) {
prntln(ST_TABLE_HEADER); prntln(ST_TABLE_HEADER);
prntln(ST_TABLE_DIVIDER); prntln(ST_TABLE_DIVIDER);
@@ -112,60 +113,70 @@ void Stations::print(int num, bool header, bool footer) {
prnt(buildString(String(SPACE) + getTimeStr(num), String(), 10)); prnt(buildString(String(SPACE) + getTimeStr(num), String(), 10));
prntln(buildString(String(SPACE) + getSelectedStr(num), String(), 9)); prntln(buildString(String(SPACE) + getSelectedStr(num), String(), 9));
if (footer) if (footer) prntln(ST_TABLE_DIVIDER);
prntln(ST_TABLE_DIVIDER);
} }
String Stations::getAPStr(int num) { String Stations::getAPStr(int num) {
if (getAP(num) < 0) return String(); if (getAP(num) < 0) return String();
return accesspoints.getSSID(getAP(num)); return accesspoints.getSSID(getAP(num));
} }
uint8_t* Stations::getAPMac(int num) { uint8_t* Stations::getAPMac(int num) {
if (!check(num)) return 0; if (!check(num)) return 0;
return WiFi.BSSID(list->get(num).ap); return WiFi.BSSID(list->get(num).ap);
} }
String Stations::getAPMacStr(int num) { String Stations::getAPMacStr(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
uint8_t* mac = getAPMac(num); uint8_t* mac = getAPMac(num);
return bytesToStr(mac, 6); return bytesToStr(mac, 6);
} }
int Stations::getAP(int num) { int Stations::getAP(int num) {
if (!check(num)) return -1; if (!check(num)) return -1;
return accesspoints.find(list->get(num).ap); return accesspoints.find(list->get(num).ap);
} }
String Stations::getNameStr(int num) { String Stations::getNameStr(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
return names.find(getMac(num)); return names.find(getMac(num));
} }
bool Stations::hasName(int num) { bool Stations::hasName(int num) {
if (!check(num)) return false; if (!check(num)) return false;
return names.findID(getMac(num)) >= 0; return names.findID(getMac(num)) >= 0;
} }
uint8_t* Stations::getMac(int num) { uint8_t* Stations::getMac(int num) {
if (!check(num)) return 0; if (!check(num)) return 0;
return list->get(num).mac; return list->get(num).mac;
} }
String Stations::getMacStr(int num) { String Stations::getMacStr(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
uint8_t* mac = getMac(num); uint8_t* mac = getMac(num);
return bytesToStr(mac, 6); return bytesToStr(mac, 6);
} }
String Stations::getMacVendorStr(int num) { String Stations::getMacVendorStr(int num) {
String value; String value;
if (check(num)) { if (check(num)) {
value = getVendorStr(num) + ":"; value = getVendorStr(num) + ":";
uint8_t* mac = getMac(num); uint8_t* mac = getMac(num);
for (int i = 3; i < 6; i++) { for (int i = 3; i < 6; i++) {
if (mac[i] < 0x10) value += "0"; if (mac[i] < 0x10) value += "0";
value += String(mac[i], HEX); value += String(mac[i], HEX);
if (i < 5) value += ":"; if (i < 5) value += ":";
} }
} }
@@ -174,6 +185,7 @@ String Stations::getMacVendorStr(int num) {
String Stations::getVendorStr(int num) { String Stations::getVendorStr(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
return searchVendor(list->get(num).mac); return searchVendor(list->get(num).mac);
} }
@@ -183,44 +195,46 @@ String Stations::getSelectedStr(int num) {
uint32_t* Stations::getPkts(int num) { uint32_t* Stations::getPkts(int num) {
if (!check(num)) return NULL; if (!check(num)) return NULL;
return list->get(num).pkts; return list->get(num).pkts;
} }
uint32_t* Stations::getTime(int num) { uint32_t* Stations::getTime(int num) {
if (!check(num)) return NULL; if (!check(num)) return NULL;
return list->get(num).time; return list->get(num).time;
} }
String Stations::getTimeStr(int num) { String Stations::getTimeStr(int num) {
if (!check(num)) return String(); if (!check(num)) return String();
uint32_t difference = currentTime - *getTime(num); uint32_t difference = currentTime - *getTime(num);
if (difference < 1000) if (difference < 1000) return str(ST_SMALLER_ONESEC);
return str(ST_SMALLER_ONESEC); else if (difference < 60000) return str(ST_SMALLER_ONEMIN);
else if (difference < 60000)
return str(ST_SMALLER_ONEMIN);
else { else {
uint32_t minutes = difference / 60000; uint32_t minutes = difference / 60000;
if (minutes > 60)
return str(ST_BIGER_ONEHOUR);
else
return (String)minutes + str(STR_MIN);
}
if (minutes > 60) return str(ST_BIGER_ONEHOUR);
else return (String)minutes + str(STR_MIN);
}
} }
bool Stations::getSelected(int num) { bool Stations::getSelected(int num) {
if (!check(num)) return false; if (!check(num)) return false;
return list->get(num).selected; return list->get(num).selected;
} }
uint8_t Stations::getCh(int num) { uint8_t Stations::getCh(int num) {
if (!check(num)) return 0; if (!check(num)) return 0;
return list->get(num).ch; return list->get(num).ch;
} }
void Stations::select(int num) { void Stations::select(int num) {
if (!check(num)) return; if (!check(num)) return;
internal_select(num); internal_select(num);
prnt(ST_SELECTED_STATION); prnt(ST_SELECTED_STATION);
prntln(num); prntln(num);
@@ -229,6 +243,7 @@ void Stations::select(int num) {
void Stations::deselect(int num) { void Stations::deselect(int num) {
if (!check(num)) return; if (!check(num)) return;
internal_deselect(num); internal_deselect(num);
prnt(ST_DESELECTED_STATION); prnt(ST_DESELECTED_STATION);
prntln(num); prntln(num);
@@ -236,15 +251,13 @@ void Stations::deselect(int num) {
} }
void Stations::selectAll() { void Stations::selectAll() {
for (int i = 0; i < count(); i++) for (int i = 0; i < count(); i++) internal_select(i);
internal_select(i);
prntln(ST_SELECTED_ALL); prntln(ST_SELECTED_ALL);
changed = true; changed = true;
} }
void Stations::deselectAll() { void Stations::deselectAll() {
for (int i = 0; i < count(); i++) for (int i = 0; i < count(); i++) internal_deselect(i);
internal_deselect(i);
prntln(ST_DESELECTED_ALL); prntln(ST_DESELECTED_ALL);
changed = true; changed = true;
} }
@@ -255,6 +268,7 @@ int Stations::count() {
int Stations::selected() { int Stations::selected() {
int num = 0; int num = 0;
for (int i = 0; i < count(); i++) for (int i = 0; i < count(); i++)
if (getSelected(i)) num++; if (getSelected(i)) num++;
return num; return num;
@@ -276,12 +290,14 @@ bool Stations::internal_check(int num) {
void Stations::internal_select(int num) { void Stations::internal_select(int num) {
Station changedStation = list->get(num); Station changedStation = list->get(num);
changedStation.selected = true; changedStation.selected = true;
list->replace(num, changedStation); list->replace(num, changedStation);
} }
void Stations::internal_deselect(int num) { void Stations::internal_deselect(int num) {
Station changedStation = list->get(num); Station changedStation = list->get(num);
changedStation.selected = false; changedStation.selected = false;
list->replace(num, changedStation); list->replace(num, changedStation);
} }
@@ -294,8 +310,7 @@ void Stations::internal_remove(int num) {
} }
void Stations::internal_add(uint8_t* mac, int accesspointNum) { void Stations::internal_add(uint8_t* mac, int accesspointNum) {
if (count() >= STATION_LIST_SIZE) if (count() >= STATION_LIST_SIZE) removeOldest();
removeOldest();
Station newStation; Station newStation;
newStation.ap = accesspointNum; newStation.ap = accesspointNum;
@@ -314,6 +329,7 @@ void Stations::internal_add(uint8_t* mac, int accesspointNum) {
void Stations::internal_removeAll() { void Stations::internal_removeAll() {
int c = count(); int c = count();
for (int i = 0; i < c; i++) { for (int i = 0; i < c; i++) {
free(getMac(i)); free(getMac(i));
free(getPkts(i)); free(getPkts(i));
@@ -321,6 +337,3 @@ void Stations::internal_removeAll() {
} }
list->clear(); list->clear();
} }

View File

@@ -66,6 +66,7 @@ class Stations {
bool check(int num); bool check(int num);
bool changed = false; bool changed = false;
private: private:
struct Station { struct Station {
uint8_t ap; uint8_t ap;
@@ -89,7 +90,4 @@ class Stations {
void internal_removeAll(); void internal_removeAll();
}; };
#endif #endif // ifndef Stations_h

View File

@@ -0,0 +1,16 @@
#ifndef StatusLED_H
#define StatusLED_H
#include "Arduino.h"
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;
};
#endif // ifndef StatusLED_H

View File

@@ -18,25 +18,13 @@ extern "C" {
#include "Attack.h" #include "Attack.h"
#include "SerialInterface.h" #include "SerialInterface.h"
#include "DisplayUI.h" #include "DisplayUI.h"
#include "DigitalLed.h"
#include "RGBLed.h"
#include "Neopixel.h"
#include "A_config.h" #include "A_config.h"
#include "webfiles.h" #include "webfiles.h"
#ifdef DIGITAL_LED #include "LEDController.h"
DigitalLed led;
#endif
#ifdef RGB_LED
RGBLed led;
#endif
#ifdef NEOPIXEL_LED
Neopixel led;
#endif
// Run-Time Variables // // Run-Time Variables //
LEDController* led;
Settings settings; Settings settings;
Names names; Names names;
SSIDs ssids; SSIDs ssids;
@@ -55,9 +43,6 @@ uint32_t currentTime = 0;
bool booted = false; bool booted = false;
void setup() { void setup() {
// "fix" for RGB LEDs
analogWriteRange(0xff);
// for random generator // for random generator
randomSeed(os_random()); randomSeed(os_random());
@@ -74,6 +59,7 @@ void setup() {
// auto repair when in boot-loop // auto repair when in boot-loop
uint8_t bootCounter = EEPROM.read(0); uint8_t bootCounter = EEPROM.read(0);
if (bootCounter >= 3) { if (bootCounter >= 3) {
prnt(SETUP_FORMAT_SPIFFS); prnt(SETUP_FORMAT_SPIFFS);
SPIFFS.format(); SPIFFS.format();
@@ -119,10 +105,9 @@ void setup() {
// create scan.json // create scan.json
scan.setup(); scan.setup();
// set LED // setup LED
#ifdef DIGITAL_LED led = new LEDController();
led.setup(); led->setup();
#endif
// set channel // set channel
setWifiChannel(settings.getChannel()); setWifiChannel(settings.getChannel());
@@ -159,12 +144,10 @@ void loop() {
serialInterface.update(); // read and run serial input serialInterface.update(); // read and run serial input
scan.update(); // run scan scan.update(); // run scan
ssids.update(); // run random mode, if enabled ssids.update(); // run random mode, if enabled
#ifdef DIGITAL_LED led->update(); // update LED color
led.update(); // update LED color
#endif
// auto-save // auto-save
if (settings.getAutosave() && currentTime - autosaveTime > settings.getAutosaveTime()) { if (settings.getAutosave() && (currentTime - autosaveTime > settings.getAutosaveTime())) {
autosaveTime = currentTime; autosaveTime = currentTime;
names.save(false); names.save(false);
ssids.save(false); ssids.save(false);
@@ -178,8 +161,3 @@ void loop() {
booted = true; booted = true;
} }
} }

View File

@@ -6,7 +6,7 @@
extern "C" { extern "C" {
#include "user_interface.h" #include "user_interface.h"
} }
#include <ArduinoJson.h> #include "ArduinoJson.h"
/* /*
Here is a collection of useful functions and variables. Here is a collection of useful functions and variables.
@@ -24,6 +24,7 @@ String escape(String str){
str.replace(String(DOUBLEQUOTES), String(BACKSLASH) + String(DOUBLEQUOTES)); str.replace(String(DOUBLEQUOTES), String(BACKSLASH) + String(DOUBLEQUOTES));
return str; return str;
} }
bool ascii(char c) { bool ascii(char c) {
return c >= 0 && c <= 127; return c >= 0 && c <= 127;
} }
@@ -38,9 +39,13 @@ bool getBit(uint8_t b, uint8_t n){
uint8_t utf8(uint8_t c) { uint8_t utf8(uint8_t c) {
if (!getBit(c, 7)) return 1; if (!getBit(c, 7)) return 1;
if (getBit(c, 7) && getBit(c, 6) && !getBit(c, 5)) return 2; if (getBit(c, 7) && getBit(c, 6) && !getBit(c, 5)) return 2;
if (getBit(c, 7) && getBit(c, 6) && getBit(c, 5) && !getBit(c, 4)) return 3; if (getBit(c, 7) && getBit(c, 6) && getBit(c, 5) && !getBit(c, 4)) return 3;
if (getBit(c, 7) && getBit(c, 6) && getBit(c, 5) && getBit(c, 4) && !getBit(c, 3)) return 4; if (getBit(c, 7) && getBit(c, 6) && getBit(c, 5) && getBit(c, 4) && !getBit(c, 3)) return 4;
return 0; return 0;
} }
@@ -68,13 +73,16 @@ String fixUtf8(String str){
} }
else { else {
ok = true; ok = true;
for (int j = 1; j < len && ok; j++) { for (int j = 1; j < len && ok; j++) {
ok = utf8Part(str.charAt(i + j)); // if following char is compliant or not ok = utf8Part(str.charAt(i + j)); // if following char is compliant or not
} }
if (ok) result += c; // everything is ok, add char and continue if (ok) result += c; // everything is ok, add char and continue
else { // utf8 char is broken else { // utf8 char is broken
for (int j = 1; j < len; j++) { // go through the next bytes for (int j = 1; j < len; j++) { // go through the next bytes
c = str.charAt(i + j); c = str.charAt(i + j);
if (utf8(c) == 1) result += c; // when byte is ascii, add it :) if (utf8(c) == 1) result += c; // when byte is ascii, add it :)
} }
i += len - 1; // skip utf8 char because we already managed it i += len - 1; // skip utf8 char because we already managed it
@@ -117,9 +125,11 @@ int utf8Len(String str){
if (len <= 1) result++; // when 1 byte char, add 1 :) if (len <= 1) result++; // when 1 byte char, add 1 :)
else { else {
result++; result++;
for (int j = 1; j < len; j++) { for (int j = 1; j < len; j++) {
c = str.charAt(i + j); c = str.charAt(i + j);
if(!utf8Part(c) && utf8(c) == 1){
if (!utf8Part(c) && (utf8(c) == 1)) {
Serial.println(c, HEX); Serial.println(c, HEX);
result++; // if following char is compliant or not result++; // if following char is compliant or not
} }
@@ -158,6 +168,7 @@ String replaceUtf8(String str, String r){
// for reading Strings from the PROGMEM // for reading Strings from the PROGMEM
String str(const char* ptr) { String str(const char* ptr) {
char keyword[strlen_P(ptr)]; char keyword[strlen_P(ptr)];
strcpy_P(keyword, ptr); strcpy_P(keyword, ptr);
return String(keyword); return String(keyword);
} }
@@ -165,6 +176,7 @@ String str(const char* ptr){
// for converting keywords // for converting keywords
String keyword(const char* keywordPtr) { String keyword(const char* keywordPtr) {
char keyword[strlen_P(keywordPtr)]; char keyword[strlen_P(keywordPtr)];
strcpy_P(keyword, keywordPtr); strcpy_P(keyword, keywordPtr);
String str = ""; String str = "";
@@ -188,15 +200,20 @@ bool eqls(const char* str, const char* keywordPtr){
uint8_t lenStr = strlen(str); uint8_t lenStr = strlen(str);
uint8_t lenKeyword = strlen(keyword); uint8_t lenKeyword = strlen(keyword);
if(lenStr > lenKeyword) return false; // string can't be longer than keyword (but can be smaller because of '/' and ',')
if (lenStr > lenKeyword) return false; // string can't be longer than keyword (but can be smaller because of '/'
// and ',')
uint8_t a = 0; uint8_t a = 0;
uint8_t b = 0; uint8_t b = 0;
bool result = true; bool result = true;
while (a < lenStr && b < lenKeyword) { while (a < lenStr && b < lenKeyword) {
if(keyword[b] == SLASH || keyword[b] == COMMA) b++; if ((keyword[b] == SLASH) || (keyword[b] == COMMA)) b++;
if (tolower(str[a]) != tolower(keyword[b])) result = false; if (tolower(str[a]) != tolower(keyword[b])) result = false;
if((a == lenStr && !result) || !result){ // fast forward to next comma
if (((a == lenStr) && !result) || !result) { // fast forward to next comma
while (b < lenKeyword && keyword[b] != COMMA) b++; while (b < lenKeyword && keyword[b] != COMMA) b++;
result = true; result = true;
a = 0; a = 0;
@@ -220,7 +237,7 @@ String b2s(bool input){
// boolean to asterix * // boolean to asterix *
String b2a(bool input) { String b2a(bool input) {
return (input ? String(ASTERIX) : String(SPACE)); return input ? String(ASTERIX) : String(SPACE);
} }
// string to boolean // string to boolean
@@ -232,15 +249,19 @@ bool s2b(String input){
void prnt(String s) { void prnt(String s) {
Serial.print(s); Serial.print(s);
} }
void prnt(bool b) { void prnt(bool b) {
Serial.print(b2s(b)); Serial.print(b2s(b));
} }
void prnt(char c) { void prnt(char c) {
Serial.print(c); Serial.print(c);
} }
void prnt(const char* ptr) { void prnt(const char* ptr) {
Serial.print(FPSTR(ptr)); Serial.print(FPSTR(ptr));
} }
void prnt(int i) { void prnt(int i) {
Serial.print((String)i); Serial.print((String)i);
} }
@@ -248,25 +269,30 @@ void prnt(int i){
void prntln() { void prntln() {
Serial.println(); Serial.println();
} }
void prntln(String s) { void prntln(String s) {
Serial.println(s); Serial.println(s);
} }
void prntln(bool b) { void prntln(bool b) {
Serial.println(b2s(b)); Serial.println(b2s(b));
} }
void prntln(char c) { void prntln(char c) {
Serial.println(c); Serial.println(c);
} }
void prntln(const char* ptr) { void prntln(const char* ptr) {
Serial.println(FPSTR(ptr)); Serial.println(FPSTR(ptr));
} }
void prntln(int i) { void prntln(int i) {
Serial.println((String)i); Serial.println((String)i);
} }
/* ===== WiFi ===== */ /* ===== WiFi ===== */
void setWifiChannel(uint8_t ch) { void setWifiChannel(uint8_t ch) {
if(ch != wifi_channel && ch > 0 && ch < 15){ if ((ch != wifi_channel) && (ch > 0) && (ch < 15)) {
wifi_channel = ch; wifi_channel = ch;
wifi_set_channel(wifi_channel); wifi_set_channel(wifi_channel);
} }
@@ -287,23 +313,35 @@ void setOutputPower(float dBm) {
bool macBroadcast(uint8_t* mac) { bool macBroadcast(uint8_t* mac) {
for (uint8_t i = 0; i < 6; i++) for (uint8_t i = 0; i < 6; i++)
if (mac[i] != broadcast[i]) return false; if (mac[i] != broadcast[i]) return false;
return true; return true;
} }
bool macValid(uint8_t* mac) { bool macValid(uint8_t* mac) {
for (uint8_t i = 0; i < 6; i++) for (uint8_t i = 0; i < 6; i++)
if (mac[i] != 0x00) return true; if (mac[i] != 0x00) return true;
return false; return false;
} }
bool macMulticast(uint8_t* mac) { bool macMulticast(uint8_t* mac) {
// see https://en.wikipedia.org/wiki/Multicast_address // see https://en.wikipedia.org/wiki/Multicast_address
if (mac[0] == 0x33 && mac[1] == 0x33) return true; if ((mac[0] == 0x33) && (mac[1] == 0x33)) return true;
if (mac[0] == 0x01 && mac[1] == 0x80 && mac[2] == 0xC2) return true;
if (mac[0] == 0x01 && mac[1] == 0x00 && (mac[2] == 0x5E || mac[2] == 0x0C)) return true; if ((mac[0] == 0x01) && (mac[1] == 0x80) && (mac[2] == 0xC2)) return true;
if (mac[0] == 0x01 && mac[1] == 0x0C && mac[2] == 0xCD && (mac[3] == 0x01 || mac[3] == 0x02 || mac[3] == 0x04) && (mac[4] == 0x00 || mac[4] == 0x01)) return true;
if (mac[0] == 0x01 && mac[1] == 0x00 && mac[2] == 0x0C && mac[3] == 0xCC && mac[4] == 0xCC && (mac[5] == 0xCC || mac[5] == 0xCD)) return true; if ((mac[0] == 0x01) && (mac[1] == 0x00) && ((mac[2] == 0x5E) || (mac[2] == 0x0C))) return true;
if (mac[0] == 0x01 && mac[1] == 0x1B && mac[2] == 0x19 && mac[3] == 0x00 && mac[4] == 0x00 && mac[5] == 0x00) return true;
if ((mac[0] == 0x01) && (mac[1] == 0x0C) && (mac[2] == 0xCD) &&
((mac[3] == 0x01) || (mac[3] == 0x02) || (mac[3] == 0x04)) &&
((mac[4] == 0x00) || (mac[4] == 0x01))) return true;
if ((mac[0] == 0x01) && (mac[1] == 0x00) && (mac[2] == 0x0C) && (mac[3] == 0xCC) && (mac[4] == 0xCC) &&
((mac[5] == 0xCC) || (mac[5] == 0xCD))) return true;
if ((mac[0] == 0x01) && (mac[1] == 0x1B) && (mac[2] == 0x19) && (mac[3] == 0x00) && (mac[4] == 0x00) &&
(mac[5] == 0x00)) return true;
return false; return false;
} }
@@ -311,7 +349,9 @@ bool macMulticast(uint8_t* mac) {
void getRandomMac(uint8_t* mac) { void getRandomMac(uint8_t* mac) {
int num = random(sizeof(data_vendors) / 11 - 1); int num = random(sizeof(data_vendors) / 11 - 1);
uint8_t i; uint8_t i;
for (i = 0; i < 3; i++) mac[i] = pgm_read_byte_near(data_macs + num * 5 + i); for (i = 0; i < 3; i++) mac[i] = pgm_read_byte_near(data_macs + num * 5 + i);
for (i = 3; i < 6; i++) mac[i] = random(256); for (i = 3; i < 6; i++) mac[i] = random(256);
} }
@@ -321,7 +361,6 @@ int binSearchVendors(uint8_t* searchBytes, int lowerEnd, int upperEnd) {
int mid = (lowerEnd + upperEnd) / 2; int mid = (lowerEnd + upperEnd) / 2;
while (lowerEnd <= upperEnd) { while (lowerEnd <= upperEnd) {
listBytes[0] = pgm_read_byte_near(data_macs + mid * 5); listBytes[0] = pgm_read_byte_near(data_macs + mid * 5);
listBytes[1] = pgm_read_byte_near(data_macs + mid * 5 + 1); listBytes[1] = pgm_read_byte_near(data_macs + mid * 5 + 1);
listBytes[2] = pgm_read_byte_near(data_macs + mid * 5 + 2); listBytes[2] = pgm_read_byte_near(data_macs + mid * 5 + 2);
@@ -337,7 +376,6 @@ int binSearchVendors(uint8_t* searchBytes, int lowerEnd, int upperEnd) {
lowerEnd = mid + 1; lowerEnd = mid + 1;
mid = (lowerEnd + upperEnd) / 2; mid = (lowerEnd + upperEnd) / 2;
} }
} }
return -1; return -1;
@@ -350,8 +388,10 @@ String searchVendor(uint8_t* mac) {
if (pos >= 0) { if (pos >= 0) {
char tmp; char tmp;
for (int i = 0; i < 8; i++) { for (int i = 0; i < 8; i++) {
tmp = (char)pgm_read_byte_near(data_vendors + realPos * 8 + i); tmp = (char)pgm_read_byte_near(data_vendors + realPos * 8 + i);
if (tmp != ENDOFLINE) vendorName += tmp; if (tmp != ENDOFLINE) vendorName += tmp;
tmp += SPACE; tmp += SPACE;
} }
@@ -360,13 +400,14 @@ String searchVendor(uint8_t* mac) {
return vendorName; return vendorName;
} }
/* ===== STRING ===== */ /* ===== STRING ===== */
String bytesToStr(uint8_t* b, uint32_t size) { String bytesToStr(uint8_t* b, uint32_t size) {
String str; String str;
for (uint32_t i = 0; i < size; i++) { for (uint32_t i = 0; i < size; i++) {
if (b[i] < 0x10) str += ZERO; if (b[i] < 0x10) str += ZERO;
str += String(b[i], HEX); str += String(b[i], HEX);
if (i < size - 1) str += DOUBLEPOINT; if (i < size - 1) str += DOUBLEPOINT;
} }
return str; return str;
@@ -388,8 +429,7 @@ bool strToMac(String macStr, uint8_t* mac){
return false; return false;
} }
for (uint8_t i = 0; i < 6; i++) for (uint8_t i = 0; i < 6; i++) mac[i] = strtoul((macStr.substring(i * 2, i * 2 + 2)).c_str(), NULL, 16);
mac[i] = strtoul((macStr.substring(i * 2, i * 2 + 2)).c_str(), NULL, 16);
return true; return true;
} }
@@ -406,13 +446,13 @@ void strToColor(String str, uint8_t* buf){
return; return;
} }
for (uint8_t i = 0; i < 3; i++) for (uint8_t i = 0; i < 3; i++) buf[i] = strtoul((str.substring(i * 2, i * 2 + 2)).c_str(), NULL, 16);
buf[i] = strtoul((str.substring(i * 2, i * 2 + 2)).c_str(), NULL, 16);
} }
String buildString(String left, String right, int maxLen) { String buildString(String left, String right, int maxLen) {
String result = left; String result = left;
int spacesToAdd = maxLen - left.length() /*utf8Len(left)*/ - right.length() /*utf8Len(right)*/; int spacesToAdd = maxLen - left.length() /*utf8Len(left)*/ - right.length() /*utf8Len(right)*/;
for (int i = 0; i < spacesToAdd; i++) { for (int i = 0; i < spacesToAdd; i++) {
result += SPACE; result += SPACE;
} }
@@ -424,6 +464,7 @@ String buildString(String left, String right, int maxLen){
bool progmemToSpiffs(const char* adr, int len, String path) { bool progmemToSpiffs(const char* adr, int len, String path) {
prnt(str(SETUP_COPYING) + path + str(SETUP_PROGMEM_TO_SPIFFS)); prnt(str(SETUP_COPYING) + path + str(SETUP_PROGMEM_TO_SPIFFS));
File f = SPIFFS.open(path, "w+"); File f = SPIFFS.open(path, "w+");
if (!f) { if (!f) {
prntln(SETUP_ERROR); prntln(SETUP_ERROR);
return false; return false;
@@ -442,7 +483,9 @@ bool progmemToSpiffs(const char* adr, int len, String path) {
bool readFile(String path, String& buf) { bool readFile(String path, String& buf) {
if (path.charAt(0) != SLASH) path = String(SLASH) + path; if (path.charAt(0) != SLASH) path = String(SLASH) + path;
File f = SPIFFS.open(path, "r"); File f = SPIFFS.open(path, "r");
if (!f) return false; if (!f) return false;
if (f.size() == 0) return false; if (f.size() == 0) return false;
while (f.available()) buf += (char)f.read(); while (f.available()) buf += (char)f.read();
@@ -455,6 +498,7 @@ bool readFile(String path, String &buf) {
void readFileToSerial(String path, bool showLineNum) { void readFileToSerial(String path, bool showLineNum) {
if (path.charAt(0) != SLASH) path = String(SLASH) + path; if (path.charAt(0) != SLASH) path = String(SLASH) + path;
File f = SPIFFS.open(path, "r"); File f = SPIFFS.open(path, "r");
if (!f) { if (!f) {
prnt(F_ERROR_READING_FILE); prnt(F_ERROR_READING_FILE);
prntln(path); prntln(path);
@@ -463,6 +507,7 @@ void readFileToSerial(String path, bool showLineNum) {
uint32_t c = 0; uint32_t c = 0;
char tmp; char tmp;
if (showLineNum) { if (showLineNum) {
prnt(buildString(String(), (String)c + String(VERTICALBAR), 6)); prnt(buildString(String(), (String)c + String(VERTICALBAR), 6));
} }
@@ -470,7 +515,8 @@ void readFileToSerial(String path, bool showLineNum) {
while (f.available()) { while (f.available()) {
tmp = f.read(); tmp = f.read();
prnt(tmp); prnt(tmp);
if(tmp == NEWLINE && showLineNum){
if ((tmp == NEWLINE) && showLineNum) {
c++; c++;
prnt(buildString(String(), (String)c + String(VERTICALBAR), 6)); prnt(buildString(String(), (String)c + String(VERTICALBAR), 6));
} }
@@ -481,6 +527,7 @@ void readFileToSerial(String path, bool showLineNum) {
bool copyFile(String pathFrom, String pathTo) { bool copyFile(String pathFrom, String pathTo) {
if (pathFrom.charAt(0) != SLASH) pathFrom = String(SLASH) + pathFrom; if (pathFrom.charAt(0) != SLASH) pathFrom = String(SLASH) + pathFrom;
if (pathTo.charAt(0) != SLASH) pathTo = String(SLASH) + pathTo; if (pathTo.charAt(0) != SLASH) pathTo = String(SLASH) + pathTo;
if (!SPIFFS.exists(pathFrom)) { if (!SPIFFS.exists(pathFrom)) {
@@ -503,6 +550,7 @@ bool copyFile(String pathFrom, String pathTo){
bool renameFile(String pathFrom, String pathTo) { bool renameFile(String pathFrom, String pathTo) {
if (pathFrom.charAt(0) != SLASH) pathFrom = String(SLASH) + pathFrom; if (pathFrom.charAt(0) != SLASH) pathFrom = String(SLASH) + pathFrom;
if (pathTo.charAt(0) != SLASH) pathTo = String(SLASH) + pathTo; if (pathTo.charAt(0) != SLASH) pathTo = String(SLASH) + pathTo;
if (!SPIFFS.exists(pathFrom)) { if (!SPIFFS.exists(pathFrom)) {
@@ -518,11 +566,12 @@ bool renameFile(String pathFrom, String pathTo){
bool writeFile(String path, String& buf) { bool writeFile(String path, String& buf) {
if (path.charAt(0) != SLASH) path = String(SLASH) + path; if (path.charAt(0) != SLASH) path = String(SLASH) + path;
File f = SPIFFS.open(path, "w+"); File f = SPIFFS.open(path, "w+");
if (!f) return false; if (!f) return false;
uint32_t len = buf.length(); uint32_t len = buf.length();
for (uint32_t i = 0; i < len; i++)
f.write(buf.charAt(i)); for (uint32_t i = 0; i < len; i++) f.write(buf.charAt(i));
f.close(); f.close();
return true; return true;
@@ -531,11 +580,12 @@ bool writeFile(String path, String &buf) {
bool appendFile(String path, String& buf) { bool appendFile(String path, String& buf) {
if (path.charAt(0) != SLASH) path = String(SLASH) + path; if (path.charAt(0) != SLASH) path = String(SLASH) + path;
File f = SPIFFS.open(path, "a+"); File f = SPIFFS.open(path, "a+");
if (!f) return false; if (!f) return false;
uint32_t len = buf.length(); uint32_t len = buf.length();
for (uint32_t i = 0; i < len; i++)
f.write(buf[i]); for (uint32_t i = 0; i < len; i++) f.write(buf[i]);
f.close(); f.close();
return true; return true;
@@ -543,13 +593,14 @@ bool appendFile(String path, String &buf) {
void checkFile(String path, String data) { void checkFile(String path, String data) {
if (path.charAt(0) != SLASH) path = String(SLASH) + path; if (path.charAt(0) != SLASH) path = String(SLASH) + path;
if (!SPIFFS.exists(path))
writeFile(path, data); if (!SPIFFS.exists(path)) writeFile(path, data);
} }
bool removeLines(String path, int lineFrom, int lineTo) { bool removeLines(String path, int lineFrom, int lineTo) {
int c = 0; int c = 0;
char tmp; char tmp;
if (path.charAt(0) != SLASH) path = String(SLASH) + path; if (path.charAt(0) != SLASH) path = String(SLASH) + path;
String tmpPath = str(F_TMP) + path + str(F_COPY); String tmpPath = str(F_TMP) + path + str(F_COPY);
@@ -561,8 +612,9 @@ bool removeLines(String path, int lineFrom, int lineTo){
while (f.available()) { while (f.available()) {
tmp = f.read(); tmp = f.read();
if(c < lineFrom || c > lineTo)
f2.write(tmp); if ((c < lineFrom) || (c > lineTo)) f2.write(tmp);
if (tmp == NEWLINE) c++; if (tmp == NEWLINE) c++;
} }
@@ -577,6 +629,7 @@ bool removeLines(String path, int lineFrom, int lineTo){
bool replaceLine(String path, int line, String& buf) { bool replaceLine(String path, int line, String& buf) {
int c = 0; int c = 0;
char tmp; char tmp;
if (path.charAt(0) != SLASH) path = String(SLASH) + path; if (path.charAt(0) != SLASH) path = String(SLASH) + path;
String tmpPath = "/tmp" + path + "_copy"; String tmpPath = "/tmp" + path + "_copy";
@@ -588,13 +641,15 @@ bool replaceLine(String path, int line, String &buf){
while (f.available()) { while (f.available()) {
tmp = f.read(); tmp = f.read();
if(c != line)
f2.write(tmp); if (c != line) f2.write(tmp);
else { else {
f2.println(buf); f2.println(buf);
while (f.read() != NEWLINE && f.available()) {} while (f.read() != NEWLINE && f.available()) {}
c++; c++;
} }
if (tmp == NEWLINE) c++; if (tmp == NEWLINE) c++;
} }
@@ -689,7 +744,4 @@ String formatBytes(size_t bytes) {
else return String(bytes / 1024.0 / 1024.0 / 1024.0) + "GB"; else return String(bytes / 1024.0 / 1024.0 / 1024.0) + "GB";
} }
#endif #endif // ifndef functions_h

File diff suppressed because one or more lines are too long

View File

@@ -83,7 +83,7 @@ void stopAP() {
} }
void wifiUpdate() { void wifiUpdate() {
if (wifiMode != WIFI_MODE_OFF && !scan.isScanning()) { if ((wifiMode != WIFI_MODE_OFF) && !scan.isScanning()) {
server.handleClient(); server.handleClient();
dnsServer.processNextRequest(); dnsServer.processNextRequest();
} }
@@ -93,36 +93,51 @@ String getWifiMode() {
switch (wifiMode) { switch (wifiMode) {
case WIFI_MODE_OFF: case WIFI_MODE_OFF:
return W_MODE_OFF; return W_MODE_OFF;
break; break;
case WIFI_MODE_AP: case WIFI_MODE_AP:
return W_MODE_AP; return W_MODE_AP;
break; break;
case WIFI_MODE_STATION: case WIFI_MODE_STATION:
return W_MODE_ST; return W_MODE_ST;
break; break;
default: default:
return String(); return String();
} }
} }
String getContentType(String filename) { String getContentType(String filename) {
if (server.hasArg("download")) if (server.hasArg("download")) return String(F("application/octet-stream"));
return String(F("application/octet-stream"));
if (filename.endsWith(str(W_DOT_GZIP))) if (filename.endsWith(str(W_DOT_GZIP))) filename = filename.substring(0, filename.length() - 3);
filename = filename.substring(0, filename.length() - 3);
if (filename.endsWith(str(W_DOT_HTM))) return str(W_HTML); if (filename.endsWith(str(W_DOT_HTM))) return str(W_HTML);
if (filename.endsWith(str(W_DOT_HTML))) return str(W_HTML); if (filename.endsWith(str(W_DOT_HTML))) return str(W_HTML);
if (filename.endsWith(str(W_DOT_CSS))) return str(W_CSS); if (filename.endsWith(str(W_DOT_CSS))) return str(W_CSS);
if (filename.endsWith(str(W_DOT_JS))) return str(W_JS); if (filename.endsWith(str(W_DOT_JS))) return str(W_JS);
if (filename.endsWith(str(W_DOT_PNG))) return str(W_PNG); if (filename.endsWith(str(W_DOT_PNG))) return str(W_PNG);
if (filename.endsWith(str(W_DOT_GIF))) return str(W_GIF); if (filename.endsWith(str(W_DOT_GIF))) return str(W_GIF);
if (filename.endsWith(str(W_DOT_JPG))) return str(W_JPG); if (filename.endsWith(str(W_DOT_JPG))) return str(W_JPG);
if (filename.endsWith(str(W_DOT_ICON))) return str(W_ICON); if (filename.endsWith(str(W_DOT_ICON))) return str(W_ICON);
if (filename.endsWith(str(W_DOT_XML))) return str(W_XML); if (filename.endsWith(str(W_DOT_XML))) return str(W_XML);
if (filename.endsWith(str(W_DOT_PDF))) return str(W_XPDF); if (filename.endsWith(str(W_DOT_PDF))) return str(W_XPDF);
if (filename.endsWith(str(W_DOT_ZIP))) return str(W_XZIP); if (filename.endsWith(str(W_DOT_ZIP))) return str(W_XZIP);
if (filename.endsWith(str(W_DOT_JSON))) return str(W_JSON); if (filename.endsWith(str(W_DOT_JSON))) return str(W_JSON);
return str(W_TXT); return str(W_TXT);
@@ -133,6 +148,7 @@ bool handleFileRead(String path) {
prnt(path); prnt(path);
if (!path.charAt(0) == SLASH) path = String(SLASH) + path; if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
if (path.charAt(path.length() - 1) == SLASH) path += String(F("index.html")); if (path.charAt(path.length() - 1) == SLASH) path += String(F("index.html"));
String contentType = getContentType(path); String contentType = getContentType(path);
@@ -140,7 +156,8 @@ bool handleFileRead(String path) {
if (!SPIFFS.exists(path)) { if (!SPIFFS.exists(path)) {
if (SPIFFS.exists(path + str(W_DOT_GZIP))) path += str(W_DOT_GZIP); if (SPIFFS.exists(path + str(W_DOT_GZIP))) path += str(W_DOT_GZIP);
else if (SPIFFS.exists(wifi_config_path + path)) path = wifi_config_path + path; else if (SPIFFS.exists(wifi_config_path + path)) path = wifi_config_path + path;
else if (SPIFFS.exists(wifi_config_path + path + str(W_DOT_GZIP))) path = wifi_config_path + path + str(W_DOT_GZIP); else if (SPIFFS.exists(wifi_config_path + path + str(W_DOT_GZIP))) path = wifi_config_path + path + str(
W_DOT_GZIP);
else { else {
prntln(W_NOT_FOUND); prntln(W_NOT_FOUND);
return false; return false;
@@ -155,6 +172,7 @@ bool handleFileRead(String path) {
return true; return true;
} }
/* /*
void handleFileUpload() { void handleFileUpload() {
// only allow uploads on /edit address // only allow uploads on /edit address
@@ -181,6 +199,7 @@ void handleFileUpload() {
//Serial.println(upload.totalSize); //Serial.println(upload.totalSize);
} }
}*/ }*/
/* /*
void handleFileDelete() { void handleFileDelete() {
if (server.args() == 0) if (server.args() == 0)
@@ -195,6 +214,7 @@ void handleFileDelete() {
SPIFFS.remove(path); SPIFFS.remove(path);
server.send(200, str(W_TXT), String()); server.send(200, str(W_TXT), String());
}*/ }*/
/* /*
void handleFileCreate() { void handleFileCreate() {
if (server.args() == 0) if (server.args() == 0)
@@ -213,7 +233,6 @@ void handleFileCreate() {
return server.send(500, str(W_TXT), "CREATE FAILED"); return server.send(500, str(W_TXT), "CREATE FAILED");
server.send(200, str(W_TXT), ""); server.send(200, str(W_TXT), "");
}*/ }*/
void handleFileList() { void handleFileList() {
if (!server.hasArg("dir")) { if (!server.hasArg("dir")) {
server.send(500, str(W_TXT), str(W_BAD_ARGS)); server.send(500, str(W_TXT), str(W_BAD_ARGS));
@@ -227,13 +246,12 @@ void handleFileList() {
String output = String(OPEN_BRACKET); // { String output = String(OPEN_BRACKET); // {
File entry; File entry;
bool first = true; bool first = true;
while (dir.next()) { while (dir.next()) {
entry = dir.openFile("r"); entry = dir.openFile("r");
if(first) if (first) first = false;
first = false; else output += COMMA; // ,
else
output += COMMA; // ,
output += OPEN_BRACKET; // [ output += OPEN_BRACKET; // [
output += String(DOUBLEQUOTES) + entry.name() + String(DOUBLEQUOTES); // "filename" output += String(DOUBLEQUOTES) + entry.name() + String(DOUBLEQUOTES); // "filename"
@@ -252,7 +270,8 @@ void sendProgmem(const char* ptr, size_t size, const char* type) {
server.send_P(200, str(type).c_str(), ptr, size); server.send_P(200, str(type).c_str(), ptr, size);
} }
// path = folder of web files, ssid = name of network, password = password ("0" => no password), hidden = if the network is visible, captivePortal = enable a captive portal // path = folder of web files, ssid = name of network, password = password ("0" => no password), hidden = if the network
// is visible, captivePortal = enable a captive portal
void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal) { void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal) {
if (password.length() < 8) { if (password.length() < 8) {
prntln(W_ERROR_PASSWORD); prntln(W_ERROR_PASSWORD);
@@ -260,6 +279,7 @@ void startAP(String path, String ssid, String password, uint8_t ch, bool hidden,
} }
if (!path.charAt(0) == SLASH) path = String(SLASH) + path; if (!path.charAt(0) == SLASH) path = String(SLASH) + path;
if (password == String(ZERO)) password = String(NEWLINE); if (password == String(ZERO)) password = String(NEWLINE);
wifi_config_path = path; wifi_config_path = path;
@@ -347,7 +367,6 @@ server.on(String(F("/lang/ru.lang")).c_str(), HTTP_GET, [](){
server.on(String(F("/lang/tlh.lang")).c_str(), HTTP_GET, []() { server.on(String(F("/lang/tlh.lang")).c_str(), HTTP_GET, []() {
sendProgmem(tlhlang, sizeof(tlhlang), W_JSON); sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
}); });
} }
server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, []() { server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, []() {
if (!settings.getWebSpiffs()) { if (!settings.getWebSpiffs()) {
@@ -411,18 +430,20 @@ server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, [](){
printWifiStatus(); printWifiStatus();
} }
void printWifiStatus() { void printWifiStatus() {
prnt(String(F("[WiFi] Path: '"))); prnt(String(F("[WiFi] Path: '")));
prnt(wifi_config_path); prnt(wifi_config_path);
prnt(String(F("', Mode: '"))); prnt(String(F("', Mode: '")));
switch (wifiMode) { switch (wifiMode) {
case WIFI_MODE_OFF: case WIFI_MODE_OFF:
prnt(W_MODE_OFF); prnt(W_MODE_OFF);
break; break;
case WIFI_MODE_AP: case WIFI_MODE_AP:
prnt(W_AP); prnt(W_AP);
break; break;
case WIFI_MODE_STATION: case WIFI_MODE_STATION:
prnt(W_STATION); prnt(W_STATION);
break; break;
@@ -440,7 +461,8 @@ void printWifiStatus() {
} }
void startAP() { void startAP() {
startAP(wifi_config_path.c_str(), wifi_config_ssid.c_str(), wifi_config_password.c_str(), wifi_channel, wifi_config_hidden, wifi_config_captivePortal); startAP(wifi_config_path.c_str(), wifi_config_ssid.c_str(),
wifi_config_password.c_str(), wifi_channel, wifi_config_hidden, wifi_config_captivePortal);
} }
void startAP(String path) { void startAP(String path) {
@@ -466,5 +488,4 @@ void resumeAP() {
} }
} }
#endif #endif // ifndef WifiManager_h