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,27 +11,24 @@
// =========================== // // =========================== //
// ===================== 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!
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
#define DIGITAL_LED #define DIGITAL_LED
//#define RGB_LED // #define RGB_LED
//#define NEOPIXEL_LED // #define NEOPIXEL_LED
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
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
@@ -63,28 +50,27 @@
#define BUTTON_DOWN 12 #define BUTTON_DOWN 12
#define BUTTON_A 13 #define BUTTON_A 13
//#define BUTTON_LEFT 12 // #define BUTTON_LEFT 12
//#define BUTTON_RIGHT 13 // #define BUTTON_RIGHT 13
//#define BUTTON_B 10 // #define BUTTON_B 10
/* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
Uncomment the type of display you're using Uncomment the type of display you're using
Only one of them can be defined at a time! Only one of them can be defined at a time!
= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
*/ */
#define DEAUTHER_DISPLAY SSD1306Wire display = SSD1306Wire(0x3c, 5, 4); // for 0.96" OLED #define DEAUTHER_DISPLAY SSD1306Wire display = SSD1306Wire(0x3c, 5, 4); // for 0.96" OLED
//#define DEAUTHER_DISPLAY SH1106Wire display = SH1106Wire(0x3c, 5, 4); // for 1.3" OLED // #define DEAUTHER_DISPLAY SH1106Wire display = SH1106Wire(0x3c, 5, 4); // for 1.3" OLED
/* RST = GPIO 5 (D1) /* RST = GPIO 5 (D1)
DC = GPIO 4 (D2) DC = GPIO 4 (D2)
CS = GPIO 15 (D8) or GND CS = GPIO 15 (D8) or GND
SCK/SCL = GPIO 14 (D5) SCK/SCL = GPIO 14 (D5)
SDA/MOSI = GPIO 13 (D7) */ SDA/MOSI = GPIO 13 (D7) */
//#define DEAUTHER_DISPLAY SSD1306Spi display = SSD1306Spi display = SSD1306Spi(5, 4, 15); // for 0.96" OLED with SPI // #define DEAUTHER_DISPLAY SSD1306Spi display = SSD1306Spi display = SSD1306Spi(5, 4, 15); // for 0.96" OLED with SPI
//#define DEAUTHER_DISPLAY SH1106Spi display = SH1106Spi(5, 4, 15); // for 1.3" OLED with SPI // #define DEAUTHER_DISPLAY SH1106Spi display = SH1106Spi(5, 4, 15); // for 1.3" OLED with SPI
//#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

@@ -5,43 +5,44 @@ Accesspoints::Accesspoints() {
} }
void Accesspoints::sort() { void Accesspoints::sort() {
list->sort([](AP &a, AP &b) -> bool{ list->sort([](AP& a, AP& b) -> bool {
return WiFi.RSSI(a.id) < WiFi.RSSI(b.id); return WiFi.RSSI(a.id) < WiFi.RSSI(b.id);
}); });
changed = true; changed = true;
} }
void Accesspoints::sortAfterChannel() { void Accesspoints::sortAfterChannel() {
list->sort([](AP &a, AP &b) -> bool{ list->sort([](AP& a, AP& b) -> bool {
return WiFi.channel(a.id) > WiFi.channel(b.id); return WiFi.channel(a.id) > WiFi.channel(b.id);
}); });
changed = true; changed = true;
} }
void Accesspoints::add(uint8_t id, bool selected) { void Accesspoints::add(uint8_t id, bool selected) {
list->add(AP{id, selected}); list->add(AP{ id, selected });
changed = true; changed = true;
} }
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,11 +57,12 @@ 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);
} }
prnt(buildString(String(),(String)num, 2)); prnt(buildString(String(), (String)num, 2));
prnt(buildString(String(SPACE) + getSSID(num), String(), 33)); prnt(buildString(String(SPACE) + getSSID(num), String(), 33));
prnt(buildString(String(SPACE) + getNameStr(num), String(), 17)); prnt(buildString(String(SPACE) + getNameStr(num), String(), 17));
prnt(buildString(String(SPACE), (String)getCh(num), 3)); prnt(buildString(String(SPACE), (String)getCh(num), 3));
@@ -77,11 +79,12 @@ 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 {
String ssid = WiFi.SSID(getID(num)); String ssid = WiFi.SSID(getID(num));
ssid = ssid.substring(0,32); ssid = ssid.substring(0, 32);
ssid = fixUtf8(ssid); ssid = fixUtf8(ssid);
return ssid; return ssid;
} }
@@ -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++){
if(list->get(i).id == id) for (int i = 0; i < s; i++) {
return i; if (list->get(i).id == id) 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;
@@ -249,14 +271,13 @@ bool Accesspoints::internal_check(int num) {
} }
void Accesspoints::internal_select(int num) { void Accesspoints::internal_select(int num) {
list->replace(num,AP{list->get(num).id,true}); list->replace(num, AP{ list->get(num).id, true });
} }
void Accesspoints::internal_deselect(int num) { void Accesspoints::internal_deselect(int num) {
list->replace(num,AP{list->get(num).id,false}); list->replace(num, AP{ list->get(num).id, false });
} }
void Accesspoints::internal_remove(int num) { void Accesspoints::internal_remove(int num) {
list->remove(num); list->remove(num);
} }

View File

@@ -17,7 +17,7 @@ extern String buildString(String left, String right, int maxLen);
extern String fixUtf8(String str); extern String fixUtf8(String str);
extern String bytesToStr(uint8_t* b, uint32_t size); extern String bytesToStr(uint8_t* b, uint32_t size);
struct AP{ struct AP {
uint8_t id; uint8_t id;
bool selected; bool selected;
}; };
@@ -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;
} }
} }
@@ -263,7 +277,7 @@ bool Attack::deauthName(int num) {
bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_t ch) { bool Attack::deauthDevice(uint8_t* apMac, uint8_t* stMac, uint8_t reason, uint8_t ch) {
if (!stMac) return false; // exit when station mac is null if (!stMac) return false; // exit when station mac is null
//Serial.println("Deauthing "+macToStr(apMac)+" -> "+macToStr(stMac)); // for debugging // Serial.println("Deauthing "+macToStr(apMac)+" -> "+macToStr(stMac)); // for debugging
bool success = false; bool success = false;
@@ -276,14 +290,16 @@ 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++;
} }
// 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,21 +313,22 @@ 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++;
} }
// 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,7 +350,8 @@ 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);
memcpy(&beaconPacket[16], mac, 6); memcpy(&beaconPacket[16], mac, 6);
@@ -359,7 +377,8 @@ 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);
memcpy(&probePacket[26], ssid, ssidLen); memcpy(&probePacket[26], ssid, ssidLen);
@@ -374,7 +393,7 @@ bool Attack::sendProbe(uint8_t* mac, const char* ssid, uint8_t ch) {
} }
bool Attack::sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries) { bool Attack::sendPacket(uint8_t* packet, uint16_t packetSize, uint8_t ch, uint16_t tries) {
//Serial.println(bytesToStr(packet, packetSize)); // Serial.println(bytesToStr(packet, packetSize));
// set channel // set channel
setWifiChannel(ch); setWifiChannel(ch);
@@ -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;
} }
@@ -426,6 +443,6 @@ uint32_t Attack::getProbeMaxPkts() {
return probe.maxPkts; return probe.maxPkts;
} }
uint32_t Attack::getPacketRate(){ uint32_t Attack::getPacketRate() {
return packetRate; return packetRate;
} }

View File

@@ -29,8 +29,8 @@ extern void setOutputPower(float dBm);
extern String macToStr(uint8_t* mac); extern String macToStr(uint8_t* mac);
extern String bytesToStr(uint8_t* b, uint32_t size); extern String bytesToStr(uint8_t* b, uint32_t size);
extern void setWifiChannel(uint8_t ch); extern void setWifiChannel(uint8_t ch);
extern bool writeFile(String path, String &buf); extern bool writeFile(String path, String& buf);
extern int8_t free80211_send(uint8_t *buffer, uint16_t len); extern int8_t free80211_send(uint8_t* buffer, uint16_t len);
class Attack { class Attack {
public: public:
@@ -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();
@@ -80,7 +81,7 @@ class Attack {
bool running = false; bool running = false;
bool output = true; bool output = true;
struct AttackType{ struct AttackType {
bool active = false; // if attack is activated bool active = false; // if attack is activated
uint16_t packetCounter = 0; // how many packets are sent per second uint16_t packetCounter = 0; // how many packets are sent per second
uint16_t maxPkts = 0; // how many packets should be sent per second uint16_t maxPkts = 0; // how many packets should be sent per second
@@ -112,16 +113,16 @@ class Attack {
uint32_t timeout = 0; uint32_t timeout = 0;
// random mac address for making the beacon packets // random mac address for making the beacon packets
uint8_t mac[6] = {0xAA,0xBB,0xCC,0x00,0x11,0x22}; uint8_t mac[6] = { 0xAA, 0xBB, 0xCC, 0x00, 0x11, 0x22 };
uint8_t deauthPacket[26] = { uint8_t deauthPacket[26] = {
/* 0 - 1 */ 0xC0, 0x00, //type, subtype c0: deauth (a0: disassociate) /* 0 - 1 */ 0xC0, 0x00, // type, subtype c0: deauth (a0: disassociate)
/* 2 - 3 */ 0x00, 0x00, //duration (SDK takes care of that) /* 2 - 3 */ 0x00, 0x00, // duration (SDK takes care of that)
/* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,//reciever (target) /* 4 - 9 */ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, // reciever (target)
/* 10 - 15 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, //source (ap) /* 10 - 15 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, // source (ap)
/* 16 - 21 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, //BSSID (ap) /* 16 - 21 */ 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, 0xCC, // BSSID (ap)
/* 22 - 23 */ 0x00, 0x00, //fragment & squence number /* 22 - 23 */ 0x00, 0x00, // fragment & squence number
/* 24 - 25 */ 0x01, 0x00 //reason code (1 = unspecified reason) /* 24 - 25 */ 0x01, 0x00 // reason code (1 = unspecified reason)
}; };
uint8_t probePacket[68] = { uint8_t probePacket[68] = {
@@ -140,7 +141,7 @@ class Attack {
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
/* 58 - 59 */ 0x01, 0x04, //Tag Number: Supported Rates (1), Tag length: 4 /* 58 - 59 */ 0x01, 0x04, // Tag Number: Supported Rates (1), Tag length: 4
/* 60 */ 0x82, // 1(B) /* 60 */ 0x82, // 1(B)
/* 61 */ 0x84, // 2(B) /* 61 */ 0x84, // 2(B)
/* 62 */ 0x8b, // 5.5(B) /* 62 */ 0x8b, // 5.5(B)
@@ -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;
g = g>0;
b = b>0;
}else{
r = !(r>0);
g = !(g>0);
b = !(b>0);
}
if(LED_ENABLE_R) digitalWrite(LED_PIN_R, r); if (bPin < 255) digitalWrite(bPin, b > 0);
if(LED_ENABLE_G) digitalWrite(LED_PIN_G, g); } else {
if(LED_ENABLE_B) digitalWrite(LED_PIN_B, b); if (rPin < 255) digitalWrite(rPin, r == 0);
// ====================== //
// debug output if (gPin < 255) digitalWrite(gPin, g == 0);
if (output){
char s[30]; if (bPin < 255) digitalWrite(bPin, b == 0);
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
@@ -137,7 +136,7 @@ void DisplayUI::setupButtons() {
}; };
buttonB.setup = [this]() { buttonB.setup = [this]() {
if (buttonB.gpio != 2 ) pinMode(buttonB.gpio, INPUT_PULLUP); if (buttonB.gpio != 2) pinMode(buttonB.gpio, INPUT_PULLUP);
buttonB.time = currentTime; buttonB.time = currentTime;
}; };
buttonB.read = [this]() { buttonB.read = [this]() {
@@ -155,7 +154,8 @@ 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,18 +222,20 @@ void DisplayUI::setup() {
buttonRight.release = [this]() { buttonRight.release = [this]() {
if (!buttonRight.pushed) return; if (!buttonRight.pushed) return;
buttonRight.pushed = false; buttonRight.pushed = false;
}; };
// === BUTTON A === // // === BUTTON A === //
buttonA.push = [this]() { buttonA.push = [this]() {
if(!buttonA.pushed){ // first push if (!buttonA.pushed) { // first push
buttonA.pushed = true; buttonA.pushed = true;
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;
@@ -266,10 +277,11 @@ void DisplayUI::setup() {
buttonB.release = [this]() { buttonB.release = [this]() {
if (!buttonB.pushed) return; if (!buttonB.pushed) return;
switch(mode){ switch (mode) {
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 ===== //
@@ -321,16 +338,16 @@ void DisplayUI::setup() {
// SHOW MENU // SHOW MENU
createMenu(&showMenu, &mainMenu, [this]() { createMenu(&showMenu, &mainMenu, [this]() {
addMenuNode(&showMenu, []() { // Accesspoints 0 [0] addMenuNode(&showMenu, []() { // Accesspoints 0 [0]
return buildString(str(D_ACCESSPOINTS),(String)accesspoints.count(),CHARS_PER_LINE); return buildString(str(D_ACCESSPOINTS), (String)accesspoints.count(), CHARS_PER_LINE);
}, &apListMenu); }, &apListMenu);
addMenuNode(&showMenu, []() { // Stations 0 [0] addMenuNode(&showMenu, []() { // Stations 0 [0]
return buildString(str(D_STATIONS),(String)stations.count(),CHARS_PER_LINE); return buildString(str(D_STATIONS), (String)stations.count(), CHARS_PER_LINE);
}, &stationListMenu); }, &stationListMenu);
addMenuNode(&showMenu, []() { // Names 0 [0] addMenuNode(&showMenu, []() { // Names 0 [0]
return buildString(str(D_NAMES),(String)names.count(),CHARS_PER_LINE); return buildString(str(D_NAMES), (String)names.count(), CHARS_PER_LINE);
}, &nameListMenu); }, &nameListMenu);
addMenuNode(&showMenu, []() { // SSIDs 0 addMenuNode(&showMenu, []() { // SSIDs 0
return buildString(str(D_SSIDS),(String)ssids.count(),CHARS_PER_LINE); return buildString(str(D_SSIDS), (String)ssids.count(), CHARS_PER_LINE);
}, &ssidListMenu); }, &ssidListMenu);
}); });
@@ -338,12 +355,13 @@ 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);
}, [this, i]() { }, [this, i]() {
accesspoints.getSelected(i) ? accesspoints.deselect(i) : accesspoints.select(i); accesspoints.getSelected(i) ? accesspoints.deselect(i) : accesspoints.select(i);
}, [this, i](){ }, [this, i]() {
selectedID = i; selectedID = i;
changeMenu(&apMenu); changeMenu(&apMenu);
}); });
@@ -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);
@@ -426,16 +447,17 @@ void DisplayUI::setup() {
changeMenu(&ssidListMenu); changeMenu(&ssidListMenu);
ssids.save(false); ssids.save(false);
}); });
addMenuNode(&ssidListMenu, [this](){ addMenuNode(&ssidListMenu, [this]() {
return b2a(ssids.getRandom()) + str(D_RANDOM_MODE); // *RANDOM MODE return b2a(ssids.getRandom()) + str(D_RANDOM_MODE); // *RANDOM MODE
}, [this]() { }, [this]() {
if(ssids.getRandom()) ssids.disableRandom(); if (ssids.getRandom()) ssids.disableRandom();
else ssids.enableRandom(10); else ssids.enableRandom(10);
changeMenu(&ssidListMenu); changeMenu(&ssidListMenu);
}); });
// 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,7 +535,8 @@ 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);
} }
@@ -573,7 +598,7 @@ void DisplayUI::setup() {
// SSID MENU // SSID MENU
createMenu(&ssidMenu, &ssidListMenu, [this]() { createMenu(&ssidMenu, &ssidListMenu, [this]() {
addMenuNode(&ssidMenu, [this]() { addMenuNode(&ssidMenu, [this]() {
return ssids.getName(selectedID).substring(0,ssids.getLen(selectedID)); return ssids.getName(selectedID).substring(0, ssids.getLen(selectedID));
}, NULL); // SSID }, NULL); // SSID
addMenuNode(&ssidMenu, [this]() { addMenuNode(&ssidMenu, [this]() {
return str(D_ENCRYPTION) + ssids.getEncStr(selectedID); // WPA2 return str(D_ENCRYPTION) + ssids.getEncStr(selectedID); // WPA2
@@ -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),
else return buildString(b2a(deauthSelected) + str(D_DEAUTH) , (String)scan.countSelected(), CHARS_PER_LINE); (String)attack.getDeauthPkts() + SLASH +
(String)attack.getDeauthMaxPkts(), 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);
}); });
}); });
@@ -637,7 +676,7 @@ void DisplayUI::update() {
// when display is off // when display is off
if (mode == SCREEN_MODE_OFF) { if (mode == SCREEN_MODE_OFF) {
if (updateButton(&buttonA)){ if (updateButton(&buttonA)) {
on(); on();
buttonA.hold = true; // to make sure you don't double click buttonA.hold = true; // to make sure you don't double click
} }
@@ -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,17 +722,22 @@ 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;
} }
drawIntro(); drawIntro();
@@ -706,18 +752,23 @@ void DisplayUI::draw() {
void DisplayUI::drawString(int x, int y, String str) { void DisplayUI::drawString(int x, int y, String str) {
// ===== adjustable ===== // // ===== adjustable ===== //
display.drawString(x, y, replaceUtf8(str,String(QUESTIONMARK))); display.drawString(x, y, replaceUtf8(str, String(QUESTIONMARK)));
// ====================== // // ====================== //
} }
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(buttonLeft.enabled) display.drawString(0, 18, str(D_LEFT) + b2s(buttonLeft.pushed)); if (buttonDown.enabled) display.drawString(0, 9, str(D_DOWN) + b2s(buttonDown.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 (buttonLeft.enabled) display.drawString(0, 18, str(D_LEFT) + b2s(buttonLeft.pushed));
if(buttonB.enabled) display.drawString(0, 45, str(D_B) + b2s(buttonB.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 (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;
} }
@@ -750,12 +802,14 @@ void DisplayUI::drawMenu() {
void DisplayUI::drawLoadingScan() { 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());
}else{ // Scanning for APs } else { // Scanning for APs
display.drawString(2, 10, str(D_LOADING_SCREEN_3)); display.drawString(2, 10, str(D_LOADING_SCREEN_3));
display.drawString(2, 24, str(D_LOADING_SCREEN_4)); display.drawString(2, 24, str(D_LOADING_SCREEN_4));
} }
@@ -769,21 +823,23 @@ 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);
display.drawLine(i + 1, 64, i + 1, 64 - scan.getPackets(i / 2)*scale); display.drawLine(i + 1, 64, i + 1, 64 - scan.getPackets(i / 2) * scale);
} }
} }
// ====================== // // ====================== //
} }
void DisplayUI::drawIntro(){ void DisplayUI::drawIntro() {
// ===== adjustable ===== // // ===== adjustable ===== //
display.setTextAlignment(TEXT_ALIGN_CENTER); display.setTextAlignment(TEXT_ALIGN_CENTER);
display.drawString(64, 6, String(F("ESP8266 Deauther"))); display.drawString(64, 6, String(F("ESP8266 Deauther")));
@@ -798,10 +854,10 @@ bool DisplayUI::updateButton(Button* button) {
if (!button->enabled || !button->read) return false; if (!button->enabled || !button->read) return false;
// read pin // read pin
if(button->read()){ if (button->read()) {
if(button->push) button->push(); if (button->push) button->push();
}else{ } else {
if(button->release) button->release(); if (button->release) button->release();
} }
return button->pushed; return button->pushed;
@@ -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();
} }
} }
@@ -838,28 +898,29 @@ void DisplayUI::goBack() {
if (currentMenu->parentMenu) changeMenu(currentMenu->parentMenu); if (currentMenu->parentMenu) changeMenu(currentMenu->parentMenu);
} }
void DisplayUI::createMenu(Menu* menu, Menu* parent, std::function<void()> build) { void DisplayUI::createMenu(Menu* menu, Menu* parent, std::function<void()>build) {
menu->list = new SimpleList<MenuNode>; menu->list = new SimpleList<MenuNode>;
menu->parentMenu = parent; menu->parentMenu = parent;
menu->selected = 0; menu->selected = 0;
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,
menu->list->add(MenuNode{getStr, click, hold}); std::function<void()>hold) {
menu->list->add(MenuNode{ getStr, click, hold });
} }
void DisplayUI::addMenuNode(Menu* menu, std::function<String()> getStr, std::function<void()> click) { void DisplayUI::addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click) {
addMenuNode(menu, getStr, click, NULL); addMenuNode(menu, getStr, click, NULL);
} }
void DisplayUI::addMenuNode(Menu* menu, std::function<String()> getStr, Menu* next) { void DisplayUI::addMenuNode(Menu* menu, std::function<String()>getStr, Menu* next) {
addMenuNode(menu, getStr, [this, next]() { addMenuNode(menu, getStr, [this, next]() {
changeMenu(next); changeMenu(next);
}); });
} }
void DisplayUI::addMenuNode(Menu* menu, const char* ptr, std::function<void()> click) { void DisplayUI::addMenuNode(Menu* menu, const char* ptr, std::function<void()>click) {
addMenuNode(menu, [ptr]() { addMenuNode(menu, [ptr]() {
return str(ptr); return str(ptr);
}, click); }, click);
@@ -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;
@@ -55,21 +54,21 @@ struct Button {
bool pushed; // currently pushed bool pushed; // currently pushed
bool hold; // if button was hold (only used for buttonA at the moment) bool hold; // if button was hold (only used for buttonA at the moment)
uint32_t time; // last time it was pushed uint32_t time; // last time it was pushed
std::function<bool()> read; // function to return if button is pushed std::function<bool()>read; // function to return if button is pushed
std::function<void()> setup; // function to enable/setup the button, if needed std::function<void()>setup; // function to enable/setup the button, if needed
std::function<void()> push; // function that is executed when button is pushed std::function<void()>push; // function that is executed when button is pushed
std::function<void()> release; // function that is executed when button is released std::function<void()>release; // function that is executed when button is released
}; };
struct Menu { struct Menu {
SimpleList<MenuNode>* list; SimpleList<MenuNode>* list;
Menu* parentMenu; Menu * parentMenu;
uint8_t selected; uint8_t selected;
std::function<void()> build; // function that is executed when button is clicked std::function<void()> build; // function that is executed when button is clicked
}; };
struct MenuNode { struct MenuNode {
std::function<String()> getStr; // function used to create the displayed string std::function<String()>getStr; // function used to create the displayed string
std::function<void()> click; // function that is executed when node is clicked std::function<void()> click; // function that is executed when node is clicked
std::function<void()> hold; // function that is executed when node is pressed for > 800ms std::function<void()> hold; // function that is executed when node is pressed for > 800ms
}; };
@@ -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
@@ -123,12 +123,13 @@ class DisplayUI {
// menu functions // menu functions
void changeMenu(Menu* menu); void changeMenu(Menu* menu);
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,
void addMenuNode(Menu* menu, std::function<String()> getStr, std::function<void()> click); std::function<void()>hold);
void addMenuNode(Menu* menu, std::function<String()> getStr, Menu* next); void addMenuNode(Menu* menu, std::function<String()>getStr, std::function<void()>click);
void addMenuNode(Menu* menu, const char* ptr, std::function<void()> click); 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, Menu* next); void addMenuNode(Menu* menu, const char* ptr, Menu* next);
// menus // menus
@@ -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

@@ -10,11 +10,12 @@ void Names::load() {
DynamicJsonBuffer jsonBuffer(4000); DynamicJsonBuffer jsonBuffer(4000);
checkFile(FILE_PATH, String(OPEN_BRACKET) + String(CLOSE_BRACKET)); checkFile(FILE_PATH, String(OPEN_BRACKET) + String(CLOSE_BRACKET));
JsonArray &arr = parseJSONFile(FILE_PATH, jsonBuffer); JsonArray& arr = parseJSONFile(FILE_PATH, jsonBuffer);
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,9 +60,10 @@ 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(buf.length() >= 1024){ if (i < c - 1) buf += COMMA; // ,
if (buf.length() >= 1024) {
if (!appendFile(FILE_PATH, buf)) { if (!appendFile(FILE_PATH, buf)) {
prnt(F_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
@@ -85,13 +89,14 @@ 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;
} }
void Names::sort() { void Names::sort() {
list->sort([](Device & a, Device & b) -> bool{ list->sort([](Device& a, Device& b) -> bool {
return memcmp(a.mac, b.mac, 6) > 0; return memcmp(a.mac, b.mac, 6) > 0;
}); });
} }
@@ -104,23 +109,23 @@ 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;
} }
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;
@@ -214,8 +216,9 @@ void Names::add(String macStr, String name, String bssidStr, uint8_t ch, bool se
changed = true; changed = true;
} }
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,20 +492,17 @@ 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);
} }
void Names::internal_removeAll() { 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"
@@ -15,9 +15,9 @@ extern "C" {
#define NAME_MAX_LENGTH 16 #define NAME_MAX_LENGTH 16
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);
extern bool writeFile(String path, String &buf); extern bool writeFile(String path, String& buf);
extern bool appendFile(String path, String &buf); extern bool appendFile(String path, String& buf);
extern bool strToMac(String macStr, uint8_t* mac); extern bool strToMac(String macStr, uint8_t* mac);
extern String searchVendor(uint8_t* mac); extern String searchVendor(uint8_t* mac);
extern String fixUtf8(String str); extern String fixUtf8(String str);
@@ -32,7 +32,7 @@ class Names {
void load(); void load();
void load(String filepath); void load(String filepath);
void save(bool force); void save(bool force);
void save(bool force,String filepath); void save(bool force, String filepath);
void sort(); void sort();
String find(uint8_t* mac); String find(uint8_t* mac);
@@ -76,13 +76,14 @@ 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;
struct Device{ struct Device {
uint8_t* mac; // mac address uint8_t* mac; // mac address
char* name; // name of saved device char * name; // name of saved device
uint8_t* apBssid; // mac address of AP (if saved device is a station) uint8_t* apBssid; // mac address of AP (if saved device is a station)
uint8_t ch; // Wi-Fi channel of Device uint8_t ch; // Wi-Fi channel of Device
bool selected; // select for attacking bool selected; // select for attacking
@@ -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 ===== //
if (brightness > 0 && brightness < 100) {
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;
}
for(uint16_t i=0;i<LED_NEOPIXEL_NUM;i++){
strip.setPixelColor(i,strip.Color(r,g,b,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 NeopixelLED::setColor(uint8_t r, uint8_t g, uint8_t b) {
void Neopixel::setMode(uint8_t mode, bool force) { int num = strip->numPixels();
// ===== adjustable ===== //
if (mode != Neopixel::mode || force) { for (uint16_t i = 0; i < num; i++) strip->setPixelColor(i, strip->Color(r, g, b));
Neopixel::mode = mode; strip->show();
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() { void NeopixelLED::setBrightness(uint8_t brightness) {
tempEnabled = true; if (brightness > 100) brightness = 100;
prntln(L_ENABLED); strip->setBrightness(brightness);
} }
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

@@ -9,11 +9,11 @@ void SSIDs::load() {
DynamicJsonBuffer jsonBuffer(4000); DynamicJsonBuffer jsonBuffer(4000);
checkFile(FILE_PATH, str(SS_JSON_DEFAULT)); checkFile(FILE_PATH, str(SS_JSON_DEFAULT));
JsonObject &obj = parseJSONFile(FILE_PATH, jsonBuffer); JsonObject& obj = parseJSONFile(FILE_PATH, jsonBuffer);
JsonArray &arr = obj.get<JsonArray>(str(SS_JSON_SSIDS)); JsonArray & arr = obj.get<JsonArray>(str(SS_JSON_SSIDS));
for (uint32_t i = 0; i < arr.size() && i < SSID_LIST_SIZE; i++) { for (uint32_t i = 0; i < arr.size() && i < SSID_LIST_SIZE; i++) {
JsonArray &tmpArray = arr.get<JsonVariant>(i); JsonArray& tmpArray = arr.get<JsonVariant>(i);
internal_add(tmpArray.get<String>(0), tmpArray.get<bool>(1), tmpArray.get<int>(2)); internal_add(tmpArray.get<String>(0), tmpArray.get<bool>(1), tmpArray.get<int>(2));
} }
@@ -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,9 +60,10 @@ 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(buf.length() >= 1024){ if (i < c - 1) buf += COMMA; // ,
if (buf.length() >= 1024) {
if (!appendFile(FILE_PATH, buf)) { if (!appendFile(FILE_PATH, buf)) {
prnt(F_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
@@ -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;
@@ -92,26 +97,23 @@ void SSIDs::save(bool force, String filepath) {
void SSIDs::update() { void SSIDs::update() {
if (randomMode) { if (randomMode) {
if (currentTime - randomTime > randomInterval*1000) { if (currentTime - randomTime > randomInterval * 1000) {
prntln(SS_RANDOM_INFO); prntln(SS_RANDOM_INFO);
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;
@@ -128,12 +130,13 @@ bool SSIDs::getWPA2(int num) {
return check(num) ? list->get(num).wpa2 : false; return check(num) ? list->get(num).wpa2 : false;
} }
int SSIDs::getLen(int num){ int SSIDs::getLen(int num) {
return check(num) ? list->get(num).len : 0; return check(num) ? list->get(num).len : 0;
} }
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);
} }
@@ -196,35 +204,36 @@ void SSIDs::add(String name, bool wpa2, int clones, bool force) {
changed = true; changed = true;
} }
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++){
if(accesspoints.getSelected(i)) for (int i = 0; i < apCount; i++) {
add(accesspoints.getSSID(i), accesspoints.getEnc(i) != 0, clones, force); if (accesspoints.getSelected(i)) add(accesspoints.getSSID(i), accesspoints.getEnc(i) != 0, clones, force);
} }
} }
} }
bool SSIDs::getRandom(){ bool SSIDs::getRandom() {
return randomMode; return randomMode;
} }
void SSIDs::replace(int num, String name, bool wpa2){ 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;
newSSID.len = (uint8_t)len; newSSID.len = (uint8_t)len;
list->replace(num,newSSID); list->replace(num, newSSID);
prnt(SS_REPLACED); prnt(SS_REPLACED);
prntln(name); prntln(name);
@@ -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() {
@@ -281,8 +290,8 @@ void SSIDs::disableRandom() {
} }
void SSIDs::internal_add(String name, bool wpa2, int len) { void SSIDs::internal_add(String name, bool wpa2, int len) {
if(len > 32) { if (len > 32) {
name = name.substring(0,32); name = name.substring(0, 32);
len = 32; len = 32;
} else if (len < 32) { } else if (len < 32) {
name = randomize(name); name = randomize(name);
@@ -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"
@@ -20,9 +20,9 @@ extern uint32_t currentTime;
extern Accesspoints accesspoints; extern Accesspoints accesspoints;
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);
extern bool appendFile(String path, String &buf); extern bool appendFile(String path, String& buf);
extern bool writeFile(String path, String &buf); extern bool writeFile(String path, String& buf);
extern void readFileToSerial(String path); extern void readFileToSerial(String path);
extern String fixUtf8(String str); extern String fixUtf8(String str);
extern String buildString(String left, String right, int maxLen); extern String buildString(String left, String right, int maxLen);
@@ -59,13 +59,14 @@ class SSIDs {
void removeAll(); void removeAll();
int count(); int count();
private: private:
bool changed = false; bool changed = false;
bool randomMode = false; bool randomMode = false;
uint32_t randomInterval = 2000; uint32_t randomInterval = 2000;
uint32_t randomTime = 0; uint32_t randomTime = 0;
struct SSID{ struct SSID {
String name; // SSID String name; // SSID
bool wpa2; // WPA2 encrypted or not bool wpa2; // WPA2 encrypted or not
uint8_t len; // original length (before editing it to be 32 characters) uint8_t len; // original length (before editing it to be 32 characters)
@@ -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,8 +52,9 @@ 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,
if(mode != SCAN_MODE_OFF) stop(); uint8_t channel) {
if (mode != SCAN_MODE_OFF) stop();
setWifiChannel(channel); setWifiChannel(channel);
Scan::continueStartTime = currentTime; Scan::continueStartTime = currentTime;
@@ -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();
@@ -81,14 +86,16 @@ void Scan::start(uint8_t mode, uint32_t time, uint8_t nextmode, uint32_t continu
// start station scan // start station scan
if (accesspoints.count() < 1) { if (accesspoints.count() < 1) {
start(SCAN_MODE_ALL); start(SCAN_MODE_ALL);
//Serial.println(str(SC_ERROR_NO_AP)); // Serial.println(str(SC_ERROR_NO_AP));
return; return;
} }
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,10 +111,11 @@ 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);
prntln(channelHop ? str(SC_ONE_TO) +(String)settings.getMaxCh() : (String)wifi_channel); prntln(channelHop ? str(SC_ONE_TO) + (String)settings.getMaxCh() : (String)wifi_channel);
// enable sniffer // enable sniffer
stopAP(); stopAP();
@@ -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));
@@ -145,12 +155,13 @@ void Scan::update() {
} }
// sniffer // sniffer
if(isSniffing()){ if (isSniffing()) {
// update packet list every 1s // update packet list every 1s
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;
packets = 0; packets = 0;
@@ -159,33 +170,37 @@ 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){
sprintf(s,str(SC_OUTPUT_A).c_str(), getPercentage(), packets, stations.count(), deauths); if (sniffTime > 0) {
} else{ sprintf(s, str(SC_OUTPUT_A).c_str(), getPercentage(), packets, stations.count(), deauths);
sprintf(s,str(SC_OUTPUT_B).c_str(), packets, stations.count(), deauths); } else {
sprintf(s, str(SC_OUTPUT_B).c_str(), packets, stations.count(), deauths);
} }
prnt(String(s)); prnt(String(s));
snifferOutputTime = currentTime; snifferOutputTime = currentTime;
} }
// 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,9 +209,10 @@ 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();
} }
@@ -204,7 +220,7 @@ void Scan::update() {
} }
} }
void Scan::setup(){ void Scan::setup() {
save(true); save(true);
} }
@@ -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,23 +254,26 @@ 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;
} }
void Scan::save(bool force) { 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);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
@@ -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,10 +292,11 @@ 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(buf.length() >= 1024){ if (i < apCount - 1) buf += String(COMMA); // ,
if(!appendFile(FILE_PATH, buf)) {
if (buf.length() >= 1024) {
if (!appendFile(FILE_PATH, buf)) {
prnt(F_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
@@ -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,10 +321,11 @@ 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(buf.length() >= 1024){ if (i < stationCount - 1) buf += String(COMMA); // ,
if(!appendFile(FILE_PATH, buf)) {
if (buf.length() >= 1024) {
if (!appendFile(FILE_PATH, buf)) {
prnt(F_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
@@ -311,7 +337,7 @@ void Scan::save(bool force) {
buf += String(CLOSE_BRACKET) + String(CLOSE_CURLY_BRACKET); // ]} buf += String(CLOSE_BRACKET) + String(CLOSE_CURLY_BRACKET); // ]}
if(!appendFile(FILE_PATH, buf)) { if (!appendFile(FILE_PATH, buf)) {
prnt(F_ERROR_SAVING); prnt(F_ERROR_SAVING);
prntln(FILE_PATH); prntln(FILE_PATH);
return; return;
@@ -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() {
@@ -339,8 +365,9 @@ bool Scan::isSniffing() {
return scanMode == SCAN_MODE_STATIONS || scanMode == SCAN_MODE_SNIFFER; return scanMode == SCAN_MODE_STATIONS || scanMode == SCAN_MODE_SNIFFER;
} }
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);
} }
@@ -369,30 +396,31 @@ void Scan::printSelected() {
names.printSelected(); names.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);
} }
} }
double Scan::getScaleFactor(uint8_t height){ double Scan::getScaleFactor(uint8_t height) {
return (double)height/(double)getMaxPacket(); return (double)height / (double)getMaxPacket();
} }
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++){
if(list->get(i) > max) max = list->get(i); for (uint8_t i = 0; i < list->size(); i++) {
if (list->get(i) > max) max = list->get(i);
} }
return max; return max;
} }
uint32_t Scan::getPacketRate(){ uint32_t Scan::getPacketRate() {
return list->get(list->size()-1); return list->get(list->size() - 1);
} }

View File

@@ -27,8 +27,8 @@ extern Settings settings;
extern uint8_t wifiMode; extern uint8_t wifiMode;
extern void setWifiChannel(uint8_t ch); extern void setWifiChannel(uint8_t ch);
extern bool appendFile(String path, String &buf); extern bool appendFile(String path, String& buf);
extern bool writeFile(String path, String &buf); extern bool writeFile(String path, String& buf);
extern void readFileToSerial(const String path); extern void readFileToSerial(const String path);
extern void resumeAP(); extern void resumeAP();
extern void stopAP(); extern void stopAP();
@@ -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,12 +4,15 @@
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!
*/ */
SerialInterface::SerialInterface() { SerialInterface::SerialInterface() {
list = new SimpleList<String>; list = new SimpleList<String>;
@@ -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();
@@ -113,16 +117,15 @@ void SerialInterface::update() {
f.close(); f.close();
executing = false; executing = false;
if(continuously) prntln(CLI_SCRIPT_DONE_CONTINUE); if (continuously) prntln(CLI_SCRIPT_DONE_CONTINUE);
else prntln(CLI_SCRIPT_DONE); else prntln(CLI_SCRIPT_DONE);
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,28 +161,31 @@ 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);
tmp = String(); // reset tmp string tmp = String(); // reset tmp string
} }
} }
// 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
@@ -199,7 +207,7 @@ void SerialInterface::runCommand(String input) {
return; return;
} }
if(settings.getSerialEcho()){ if (settings.getSerialEcho()) {
// print command // print command
prnt(CLI_INPUT_PREFIX); prnt(CLI_INPUT_PREFIX);
prntln(input); prntln(input);
@@ -286,7 +294,8 @@ 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,17 +379,16 @@ 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);
ssids.cloneSelected(force); ssids.cloneSelected(force);
} }
// add ssid <ssid> [-wpa2] [-cl <clones>] [-f] // add ssid <ssid> [-wpa2] [-cl <clones>] [-f]
// add ssid -ap <id> [-cl <clones>] [-f] // add ssid -ap <id> [-cl <clones>] [-f]
else{ else {
String ssid = list->get(2); String ssid = list->get(2);
bool wpa2 = false; bool wpa2 = false;
bool force = false; bool force = false;
@@ -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;
@@ -427,10 +435,10 @@ void SerialInterface::runCommand(String input) {
} }
else if (eqlsCMD(i, CLI_CHANNEL)) channel = (uint8_t)list->get(i + 1).toInt(); else if (eqlsCMD(i, CLI_CHANNEL)) channel = (uint8_t)list->get(i + 1).toInt();
else if (eqlsCMD(i, CLI_BSSID)) bssid = list->get(i + 1); else if (eqlsCMD(i, CLI_BSSID)) bssid = list->get(i + 1);
else if (eqlsCMD(i, CLI_SELECT)){ else if (eqlsCMD(i, CLI_SELECT)) {
selected = true; selected = true;
i--; i--;
} else if (eqlsCMD(i, CLI_FORCE)){ } else if (eqlsCMD(i, CLI_FORCE)) {
force = true; force = true;
i--; i--;
} else { } else {
@@ -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);
@@ -466,7 +474,7 @@ void SerialInterface::runCommand(String input) {
else if (eqlsCMD(i, CLI_MAC)) mac = list->get(i + 1); else if (eqlsCMD(i, CLI_MAC)) mac = list->get(i + 1);
else if (eqlsCMD(i, CLI_CHANNEL)) channel = (uint8_t)list->get(i + 1).toInt(); else if (eqlsCMD(i, CLI_CHANNEL)) channel = (uint8_t)list->get(i + 1).toInt();
else if (eqlsCMD(i, CLI_BSSID)) bssid = list->get(i + 1); else if (eqlsCMD(i, CLI_BSSID)) bssid = list->get(i + 1);
else if (eqlsCMD(i, CLI_SELECT)){ else if (eqlsCMD(i, CLI_SELECT)) {
selected = true; selected = true;
i--; i--;
} else { } else {
@@ -476,32 +484,32 @@ void SerialInterface::runCommand(String input) {
i++; i++;
} }
names.replace(id,mac, name, bssid, channel, selected); names.replace(id, mac, name, bssid, channel, selected);
} }
// 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;
for (int i = 3; i < list->size(); i++) { for (int i = 3; i < list->size(); i++) {
if (eqlsCMD(i, CLI_NAME)){ if (eqlsCMD(i, CLI_NAME)) {
name = list->get(i + 1); name = list->get(i + 1);
i++; i++;
}else if(eqlsCMD(i, CLI_WPA2)){ } else if (eqlsCMD(i, CLI_WPA2)) {
wpa2 = true; wpa2 = true;
} }
} }
ssids.replace(id,name, wpa2); ssids.replace(id, name, wpa2);
} }
// ===== 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,14 +587,15 @@ 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,33 +790,35 @@ 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 {
prntln(CLI_ERROR_COPYING); prntln(CLI_ERROR_COPYING);
} }
} }
// ===== 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 {
prntln(CLI_ERROR_RENAMING_FILE); prntln(CLI_ERROR_RENAMING_FILE);
} }
} }
// ===== 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,22 +856,25 @@ 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;
} }
} }
} }
// ===== 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,65 +943,55 @@ 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);
counter++; counter++;
} else{ } else {
prntln(CLI_CUSTOM_FAILED); prntln(CLI_CUSTOM_FAILED);
} }
} }
// ===== 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,10 +1033,14 @@ 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(),
else if (i == 0) sprintf(s,str(CLI_DRAW_OUTPUT).c_str(), 0); scan.getMaxPacket() > (uint32_t)height ? scan.getMaxPacket() : (uint32_t)height);
else{ 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 {
s[0] = SPACE; s[0] = SPACE;
s[1] = SPACE; s[1] = SPACE;
s[2] = SPACE; s[2] = SPACE;
@@ -1030,8 +1050,9 @@ 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);
} else { } else {
for (int k = 0; k < width; k++) prnt(SPACE); for (int k = 0; k < width; k++) prnt(SPACE);
@@ -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);
else if(j==SCAN_PACKET_LIST_SIZE/2) sprintf(s,helper.c_str(),SCAN_PACKET_LIST_SIZE/2); if (j == 0) sprintf(s, helper.c_str(), SCAN_PACKET_LIST_SIZE - 1);
else if(j==SCAN_PACKET_LIST_SIZE-1) sprintf(s,helper.c_str(),0); else if (j == SCAN_PACKET_LIST_SIZE / 2) sprintf(s, helper.c_str(), SCAN_PACKET_LIST_SIZE / 2);
else{ else if (j == SCAN_PACKET_LIST_SIZE - 1) sprintf(s, helper.c_str(), 0);
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)) {
@@ -1099,27 +1123,27 @@ void SerialInterface::runCommand(String input) {
startAP(path, ssid, password, ch, hidden, captivePortal); startAP(path, ssid, password, ch, hidden, captivePortal);
} }
//stopap // stopap
else if (eqlsCMD(0, CLI_STOPAP)) { else if (eqlsCMD(0, CLI_STOPAP)) {
stopAP(); stopAP();
} }
// ===== SCREEN ===== // // ===== SCREEN ===== //
// screen mode <menu/packetmonitor/buttontest/loading> // screen mode <menu/packetmonitor/buttontest/loading>
else if(eqlsCMD(0, CLI_SCREEN) && eqlsCMD(1,CLI_MODE)){ else if (eqlsCMD(0, CLI_SCREEN) && eqlsCMD(1, CLI_MODE)) {
if(eqlsCMD(2,CLI_MODE_BUTTONTEST)) displayUI.mode = SCREEN_MODE_BUTTON_TEST; if (eqlsCMD(2, CLI_MODE_BUTTONTEST)) displayUI.mode = SCREEN_MODE_BUTTON_TEST;
else if(eqlsCMD(2,CLI_MODE_PACKETMONITOR)) displayUI.mode = SCREEN_MODE_PACKETMONITOR; else if (eqlsCMD(2, CLI_MODE_PACKETMONITOR)) displayUI.mode = SCREEN_MODE_PACKETMONITOR;
else if(eqlsCMD(2,CLI_MODE_LOADINGSCREEN)) displayUI.mode = SCREEN_MODE_LOADSCAN; else if (eqlsCMD(2, CLI_MODE_LOADINGSCREEN)) displayUI.mode = SCREEN_MODE_LOADSCAN;
else if(eqlsCMD(2,CLI_MODE_MENU)) displayUI.mode = SCREEN_MODE_MENU; else if (eqlsCMD(2, CLI_MODE_MENU)) displayUI.mode = SCREEN_MODE_MENU;
else parameterError(list->get(2)); else parameterError(list->get(2));
prntln(CLI_CHANGED_SCREEN); prntln(CLI_CHANGED_SCREEN);
} }
// screen <on/off> // screen <on/off>
else if(eqlsCMD(0, CLI_SCREEN) && (eqlsCMD(1,CLI_ON) || eqlsCMD(1,CLI_OFF))){ else if (eqlsCMD(0, CLI_SCREEN) && (eqlsCMD(1, CLI_ON) || eqlsCMD(1, CLI_OFF))) {
if(eqlsCMD(1,CLI_ON)){ if (eqlsCMD(1, CLI_ON)) {
displayUI.on(); displayUI.on();
} else if(eqlsCMD(1,CLI_OFF)){ } else if (eqlsCMD(1, CLI_OFF)) {
displayUI.off(); displayUI.off();
} }
} }
@@ -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;
@@ -49,9 +36,9 @@ extern void readFileToSerial(String path, bool showLineNum);
extern bool removeFile(String path); extern bool removeFile(String path);
extern bool copyFile(String pathFrom, String pathTo); extern bool copyFile(String pathFrom, String pathTo);
extern bool renameFile(String pathFrom, String pathTo); extern bool renameFile(String pathFrom, String pathTo);
extern bool appendFile(String path, String &buf); extern bool appendFile(String path, String& buf);
extern bool removeLines(String path, int lineFrom, int lineTo); extern bool removeLines(String path, int lineFrom, int lineTo);
extern bool replaceLine(String path, int line, String &buf); extern bool replaceLine(String path, int line, String& buf);
extern bool equalsKeyword(const char* str, const char* keyword); extern bool equalsKeyword(const char* str, const char* keyword);
extern void printWifiStatus(); extern void printWifiStatus();
extern void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal); extern void startAP(String path, String ssid, String password, uint8_t ch, bool hidden, bool captivePortal);
@@ -82,7 +69,7 @@ class SerialInterface {
uint32_t loopTime = 0; uint32_t loopTime = 0;
String execPath = "/autostart.txt"; String execPath = "/autostart.txt";
struct Keyword{ struct Keyword {
const char* name; const char* name;
const char* shortName; const char* shortName;
const char* alt; const char* alt;
@@ -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,48 +10,72 @@ 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);
// VERSION // VERSION
version = data.get<String>("version"); version = data.get<String>("version");
// 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_CHANNEL))) setChannel(data.get<uint8_t>(keyword(S_CHANNEL))); if (data.containsKey(keyword(S_PASSWORD))) setPassword(data.get<String>(keyword(S_PASSWORD)));
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_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_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_DISPLAY_TIMEOUT))) setDisplayTimeout(data.get<uint32_t>(keyword(S_DISPLAY_TIMEOUT))); if (data.containsKey(keyword(S_DISPLAYINTERFACE))) setDisplayInterface(data.get<bool>(keyword(S_DISPLAYINTERFACE)));
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_DISPLAY_TIMEOUT))) setDisplayTimeout(data.get<uint32_t>(keyword(S_DISPLAY_TIMEOUT)));
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_SERIALINTERFACE))) setSerialInterface(data.get<bool>(keyword(S_SERIALINTERFACE)));
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_SERIAL_ECHO))) setSerialEcho(data.get<bool>(keyword(S_SERIAL_ECHO)));
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_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_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_MACAP))) setMacAP(data.get<String>(keyword(S_MACAP)));
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_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_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_RANDOMTX))) setRandomTX(data.get<bool>(keyword(S_RANDOMTX)));
if(data.containsKey(keyword(S_PROBESPERSSID))) setProbesPerSSID(data.get<uint8_t>(keyword(S_PROBESPERSSID)));
if (version != VERSION){ if (data.containsKey(keyword(S_FORCEPACKETS))) setForcePackets(data.get<uint8_t>(keyword(S_FORCEPACKETS)));
//reset();
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_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_RANDOMTX))) setRandomTX(data.get<bool>(keyword(S_RANDOMTX)));
if (data.containsKey(keyword(S_PROBESPERSSID))) setProbesPerSSID(data.get<uint8_t>(keyword(S_PROBESPERSSID)));
if (version != VERSION) {
// reset();
copyWebFiles(true); copyWebFiles(true);
version = VERSION; version = VERSION;
changed = true; changed = true;
@@ -61,14 +85,16 @@ void Settings::load() {
prntln(FILE_PATH); prntln(FILE_PATH);
// 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
} }
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;
@@ -119,7 +145,7 @@ void Settings::reset() {
String Settings::getJsonStr() { String Settings::getJsonStr() {
DynamicJsonBuffer jsonBuffer(4000); DynamicJsonBuffer jsonBuffer(4000);
JsonObject &data = jsonBuffer.createObject(); JsonObject& data = jsonBuffer.createObject();
// Version // Version
data.set("version", VERSION); data.set("version", VERSION);
@@ -169,11 +195,12 @@ 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);
changed = false; changed = false;
}else{ } else {
prnt(F("ERROR: saving ")); prnt(F("ERROR: saving "));
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");
@@ -230,7 +259,7 @@ void Settings::set(const char* str, String value) {
else if (eqls(str, S_PASSWORD)) setPassword(value); else if (eqls(str, S_PASSWORD)) setPassword(value);
else if (eqls(str, S_MACAP)) setMacAP(value); else if (eqls(str, S_MACAP)) setMacAP(value);
else if (eqls(str, S_MACST)) setMacSt(value); else if (eqls(str, S_MACST)) setMacSt(value);
else if (eqls(str, S_MAC) && value.equalsIgnoreCase("random")){ else if (eqls(str, S_MAC) && value.equalsIgnoreCase("random")) {
setMacSt(value); setMacSt(value);
setMacAP(value); setMacAP(value);
} }
@@ -390,23 +419,23 @@ bool Settings::getCaptivePortal() {
return captivePortal; return captivePortal;
} }
uint16_t Settings::getMinDeauths(){ uint16_t Settings::getMinDeauths() {
return minDeauths; return minDeauths;
} }
uint32_t Settings::getDisplayTimeout(){ uint32_t Settings::getDisplayTimeout() {
return displayTimeout; return displayTimeout;
} }
String Settings::getLang(){ String Settings::getLang() {
return lang; return lang;
} }
bool Settings::getSerialEcho(){ bool Settings::getSerialEcho() {
return serialEcho; return serialEcho;
} }
bool Settings::getWebSpiffs(){ bool Settings::getWebSpiffs() {
return webSpiffs; return webSpiffs;
} }
@@ -428,7 +457,7 @@ void Settings::setBeaconChannel(bool beaconChannel) {
} }
void Settings::setForcePackets(uint8_t forcePackets) { void Settings::setForcePackets(uint8_t forcePackets) {
if(forcePackets > 0){ if (forcePackets > 0) {
Settings::forcePackets = forcePackets; Settings::forcePackets = forcePackets;
changed = true; changed = true;
} }
@@ -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,16 +539,14 @@ 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);
} }
bool Settings::setMacSt(uint8_t* macSt){ bool Settings::setMacSt(uint8_t* macSt) {
if(macSt[0] % 2 == 0){ if (macSt[0] % 2 == 0) {
memcpy(Settings::macSt, macSt, 6); memcpy(Settings::macSt, macSt, 6);
changed = true; changed = true;
return true; return true;
@@ -527,19 +554,17 @@ bool Settings::setMacSt(uint8_t* macSt){
return false; return false;
} }
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);
} }
bool Settings::setMacAP(uint8_t* macAP){ bool Settings::setMacAP(uint8_t* macAP) {
if(macAP[0] % 2 == 0){ if (macAP[0] % 2 == 0) {
memcpy(Settings::macAP, macAP, 6); memcpy(Settings::macAP, macAP, 6);
changed = true; changed = true;
return true; return true;
@@ -547,12 +572,12 @@ bool Settings::setMacAP(uint8_t* macAP){
return false; return false;
} }
void Settings::setRandomTX(bool randomTX){ void Settings::setRandomTX(bool randomTX) {
Settings::randomTX = randomTX; Settings::randomTX = randomTX;
changed = true; changed = true;
} }
void Settings::setAttackTimeout(uint32_t attackTimeout){ void Settings::setAttackTimeout(uint32_t attackTimeout) {
Settings::attackTimeout = attackTimeout; Settings::attackTimeout = attackTimeout;
changed = true; changed = true;
} }
@@ -563,7 +588,7 @@ void Settings::setLedEnabled(bool ledEnabled) {
} }
void Settings::setProbesPerSSID(uint8_t probesPerSSID) { void Settings::setProbesPerSSID(uint8_t probesPerSSID) {
if(probesPerSSID > 0){ if (probesPerSSID > 0) {
Settings::probesPerSSID = probesPerSSID; Settings::probesPerSSID = probesPerSSID;
changed = true; changed = true;
} }
@@ -574,33 +599,32 @@ void Settings::setHidden(bool hidden) {
changed = true; changed = true;
} }
void Settings::setCaptivePortal(bool captivePortal){ void Settings::setCaptivePortal(bool captivePortal) {
Settings::captivePortal = captivePortal; Settings::captivePortal = captivePortal;
changed = true; changed = true;
} }
void Settings::setMinDeauths(uint16_t minDeauths){ void Settings::setMinDeauths(uint16_t minDeauths) {
Settings::minDeauths = minDeauths; Settings::minDeauths = minDeauths;
changed = true; changed = true;
} }
void Settings::setDisplayTimeout(uint32_t displayTimeout){ void Settings::setDisplayTimeout(uint32_t displayTimeout) {
Settings::displayTimeout = displayTimeout; Settings::displayTimeout = displayTimeout;
changed = true; changed = true;
} }
void Settings::setLang(String lang){ void Settings::setLang(String lang) {
Settings::lang = lang; Settings::lang = lang;
changed = true; changed = true;
} }
void Settings::setSerialEcho(bool serialEcho){ void Settings::setSerialEcho(bool serialEcho) {
Settings::serialEcho = serialEcho; Settings::serialEcho = serialEcho;
changed = true; changed = true;
} }
void Settings::setWebSpiffs(bool webSpiffs){ void Settings::setWebSpiffs(bool webSpiffs) {
Settings::webSpiffs = webSpiffs; Settings::webSpiffs = webSpiffs;
changed = true; changed = true;
} }

View File

@@ -6,16 +6,16 @@
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);
extern bool writeFile(String path, String &buf); extern bool writeFile(String path, String& buf);
extern void saveJSONFile(String path, JsonObject &root); extern void saveJSONFile(String path, JsonObject& root);
extern String macToStr(uint8_t* mac); extern String macToStr(uint8_t* mac);
extern void getRandomMac(uint8_t* mac); extern void getRandomMac(uint8_t* mac);
extern bool strToMac(String macStr, uint8_t* mac); extern bool strToMac(String macStr, uint8_t* mac);
@@ -30,7 +30,7 @@ class Settings {
void load(); void load();
void load(String filepath); void load(String filepath);
void save(bool force); void save(bool force);
void save(bool force,String filepath); void save(bool force, String filepath);
void reset(); void reset();
void print(); void print();
@@ -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

@@ -7,11 +7,11 @@
template<class T> template<class T>
struct Node { struct Node {
T data; T data;
Node<T> *next; Node<T>* next;
}; };
template<typename T> template<typename T>
class SimpleList{ class SimpleList {
public: public:
SimpleList(); SimpleList();
~SimpleList(); ~SimpleList();
@@ -24,14 +24,15 @@ class SimpleList{
virtual T shift(); virtual T shift();
virtual T pop(); virtual T pop();
virtual T get(int index); virtual T get(int index);
virtual int search(std::function<bool(T &a)> cmp); virtual int search(std::function<bool(T& a)>cmp);
virtual int searchNext(std::function<bool(T &a)> cmp); virtual int searchNext(std::function<bool(T& a)>cmp);
virtual int binSearch(std::function<int(T &a)> cmp, int lowerEnd, int upperEnd); virtual int binSearch(std::function<int(T& a)>cmp, int lowerEnd, int upperEnd);
virtual int binSearch(std::function<int(T &a)> cmp); virtual int binSearch(std::function<int(T& a)>cmp);
virtual int count(std::function<bool(T &a)> cmp); virtual int count(std::function<bool(T& a)>cmp);
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;
@@ -46,7 +47,7 @@ class SimpleList{
}; };
template<typename T> template<typename T>
SimpleList<T>::SimpleList(){ SimpleList<T>::SimpleList() {
listBegin = NULL; listBegin = NULL;
listEnd = NULL; listEnd = NULL;
listSize = 0; listSize = 0;
@@ -58,7 +59,7 @@ SimpleList<T>::SimpleList(){
// Clear Nodes and free Memory // Clear Nodes and free Memory
template<typename T> template<typename T>
SimpleList<T>::~SimpleList(){ SimpleList<T>::~SimpleList() {
clear(); clear();
listBegin = NULL; listBegin = NULL;
listEnd = NULL; listEnd = NULL;
@@ -70,24 +71,23 @@ 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;
} }
while(hNode != NULL && c < index){ while (hNode != NULL && c < index) {
hNode = hNode->next; hNode = hNode->next;
c++; c++;
} }
if(hNode){ if (hNode) {
isCached = true; isCached = true;
lastIndexGot = c; lastIndexGot = c;
lastNodeGot = hNode; lastNodeGot = hNode;
@@ -97,20 +97,19 @@ Node<T>* SimpleList<T>::getNode(int index){
} }
template<typename T> template<typename T>
int SimpleList<T>::size(){ int SimpleList<T>::size() {
return listSize; return listSize;
} }
template<typename T> template<typename T>
void SimpleList<T>::add(T obj){ void SimpleList<T>::add(T obj) {
Node<T> *node = new Node<T>(); Node<T>* node = new Node<T>();
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;
listEnd = node; listEnd = node;
} else { } else {
@@ -121,19 +120,18 @@ 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;
} }
Node<T> *nodeNew = new Node<T>(); Node<T>* nodeNew = new Node<T>();
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;
nodePrev->next = nodeNew; nodePrev->next = nodeNew;
@@ -143,26 +141,25 @@ 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);
if(index == 0) { if (index == 0) {
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;
@@ -173,18 +170,19 @@ 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);
while(!found && i < listSize){ while (!found && i < listSize) {
i++; i++;
hNode = getNode(i); hNode = getNode(i);
found = cmp(hNode->data); found = cmp(hNode->data);
@@ -194,12 +192,13 @@ 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);
while(!found && i < listSize){ while (!found && i < listSize) {
i++; i++;
hNode = getNode(i); hNode = getNode(i);
found = cmp(hNode->data); found = cmp(hNode->data);
@@ -209,9 +208,10 @@ int SimpleList<T>::searchNext(std::function<bool(T &a)> cmp){
} }
template<typename T> 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;
@@ -240,15 +240,15 @@ int SimpleList<T>::binSearch(std::function<int(T &a)> cmp, int lowerEnd, int upp
} }
template<typename T> template<typename T>
int SimpleList<T>::binSearch(std::function<int(T &a)> cmp){ int SimpleList<T>::binSearch(std::function<int(T& a)>cmp) {
return binSearch(cmp,0,listSize-1); return binSearch(cmp, 0, listSize - 1);
} }
template<typename T> template<typename T>
int SimpleList<T>::count(std::function<bool(T &a)> cmp){ int SimpleList<T>::count(std::function<bool(T& a)>cmp) {
int c = 0; int c = 0;
for(int i=0;i<listSize;i++){ for (int i = 0; i < listSize; i++) {
c += cmp(getNode(i)->data); c += cmp(getNode(i)->data);
} }
@@ -256,19 +256,17 @@ 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);
return data; return data;
} }
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);
@@ -276,23 +274,22 @@ 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;
y = h; y = h;
} }
// When data is small, copy it // When data is small, copy it
if(sizeof(T) < 24){ if (sizeof(T) < 24) {
Node<T>* nodeA = getNode(x); Node<T>* nodeA = getNode(x);
Node<T>* nodeB = getNode(y); Node<T>* nodeB = getNode(y);
T h = nodeA->data; T h = nodeA->data;
@@ -312,45 +309,45 @@ 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
nodeG->next = nodeB; nodeG->next = nodeB;
} }
} }
} }
template<typename T> template<typename T>
void SimpleList<T>::sort(std::function<bool(T &a, T &b)> cmp) { void SimpleList<T>::sort(std::function<bool(T& a, T& b)>cmp) {
// selection sort // selection sort
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
for(int i=0; i<listSize-1; i++){ for (int i = 0; i < listSize - 1; i++) {
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

@@ -9,7 +9,7 @@ void Stations::add(uint8_t* mac, int accesspointNum) {
if (stationNum < 0) { if (stationNum < 0) {
internal_add(mac, accesspointNum); internal_add(mac, accesspointNum);
//print(list->size() - 1, list->size() == 1, false); // print(list->size() - 1, list->size() == 1, false);
} else { } else {
*getPkts(stationNum) += 1; *getPkts(stationNum) += 1;
*getTime(stationNum) = currentTime; *getTime(stationNum) = currentTime;
@@ -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,75 +97,86 @@ 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);
} }
prnt(buildString(String(),(String)num, 2)); prnt(buildString(String(), (String)num, 2));
prnt(buildString(String(SPACE) + getMacStr(num), String(), 18)); prnt(buildString(String(SPACE) + getMacStr(num), String(), 18));
prnt(buildString(String(SPACE), (String)getCh(num), 3)); prnt(buildString(String(SPACE), (String)getCh(num), 3));
prnt(buildString(String(SPACE) + getNameStr(num), String(), 17)); prnt(buildString(String(SPACE) + getNameStr(num), String(), 17));
prnt(buildString(String(SPACE) + getVendorStr(num), String(), 9)); prnt(buildString(String(SPACE) + getVendorStr(num), String(), 9));
prnt(buildString(String(SPACE), (String)*getPkts(num), 9)); prnt(buildString(String(SPACE), (String) * getPkts(num), 9));
prnt(buildString(String(SPACE) + getAPStr(num), String(), 33)); prnt(buildString(String(SPACE) + getAPStr(num), String(), 33));
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,15 +268,16 @@ 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;
} }
bool Stations::check(int num) { bool Stations::check(int num) {
if (internal_check(num)){ if (internal_check(num)) {
return true; return true;
} else{ } else {
prnt(ST_ERROR_ID); prnt(ST_ERROR_ID);
prntln(num); prntln(num);
return false; return false;
@@ -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

@@ -31,7 +31,7 @@ class Stations {
void select(int num); void select(int num);
void deselect(int num); void deselect(int num);
void add(uint8_t* mac,int accesspointNum); void add(uint8_t* mac, int accesspointNum);
void selectAll(); void selectAll();
void deselectAll(); void deselectAll();
@@ -66,11 +66,12 @@ 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;
uint8_t ch; uint8_t ch;
uint8_t* mac; uint8_t * mac;
uint32_t* pkts; uint32_t* pkts;
uint32_t* time; uint32_t* time;
bool selected; bool selected;
@@ -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

@@ -1,9 +1,9 @@
/* /*
=========================================== ===========================================
Copyright (c) 2018 Stefan Kremser Copyright (c) 2018 Stefan Kremser
github.com/spacehuhn github.com/spacehuhn
=========================================== ===========================================
*/ */
extern "C" { extern "C" {
#include "user_interface.h" #include "user_interface.h"
} }
@@ -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,11 +59,12 @@ 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();
prntln(SETUP_OK); prntln(SETUP_OK);
}else{ } else {
EEPROM.write(0, bootCounter + 1); // add 1 to the boot counter EEPROM.write(0, bootCounter + 1); // add 1 to the boot counter
EEPROM.commit(); EEPROM.commit();
} }
@@ -103,7 +89,7 @@ void setup() {
wifi_set_macaddr(STATION_IF, settings.getMacSt()); wifi_set_macaddr(STATION_IF, settings.getMacSt());
// start display // start display
if (settings.getDisplayInterface()){ if (settings.getDisplayInterface()) {
displayUI.setup(); displayUI.setup();
displayUI.mode = SCREEN_MODE_INTRO; displayUI.mode = SCREEN_MODE_INTRO;
} }
@@ -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,27 +144,20 @@ 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);
settings.save(false); settings.save(false);
} }
if(!booted){ if (!booted) {
// reset boot counter // reset boot counter
EEPROM.write(0, 0); EEPROM.write(0, 0);
EEPROM.commit(); EEPROM.commit();
booted = true; booted = true;
} }
} }

View File

@@ -6,49 +6,54 @@
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.
They are used globally via an 'extern' reference in every class. They are used globally via an 'extern' reference in every class.
Making everything static will lead to problems with the Arduino ESP8266 2.0.0 SDK, Making everything static will lead to problems with the Arduino ESP8266 2.0.0 SDK,
there were some fixed in later version but we need to use the old version for injecting deauth packets. there were some fixed in later version but we need to use the old version for injecting deauth packets.
*/ */
uint8_t broadcast[6] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; uint8_t broadcast[6] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
uint8_t wifi_channel = 1; uint8_t wifi_channel = 1;
// ===== UTF8 FIX ===== // // ===== UTF8 FIX ===== //
String escape(String str){ String escape(String str) {
str.replace(String(BACKSLASH), String(BACKSLASH) + String(BACKSLASH)); str.replace(String(BACKSLASH), String(BACKSLASH) + String(BACKSLASH));
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;
} }
bool printableAscii(char c){ bool printableAscii(char c) {
return c >= 32 && c <= 126; return c >= 32 && c <= 126;
} }
bool getBit(uint8_t b, uint8_t n){ bool getBit(uint8_t b, uint8_t n) {
return (b >> n) % 2 != 0; return (b >> n) % 2 != 0;
} }
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) && !getBit(c,4)) return 3; 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) && !getBit(c,3)) return 4;
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;
return 0; return 0;
} }
bool utf8Part(uint8_t c){ bool utf8Part(uint8_t c) {
return getBit(c,7) && !getBit(c,6); return getBit(c, 7) && !getBit(c, 6);
} }
String fixUtf8(String str){ String fixUtf8(String str) {
int size = str.length(); int size = str.length();
String result = String(); String result = String();
@@ -56,26 +61,29 @@ String fixUtf8(String str){
uint8_t len; uint8_t len;
bool ok; bool ok;
for(int i=0;i<size;i++){ for (int i = 0; i < size; i++) {
c = str.charAt(i); // get character c = str.charAt(i); // get character
len = utf8(c); // get utf8 char len len = utf8(c); // get utf8 char len
if(len <= 1){ if (len <= 1) {
result += c; // when 1 byte char, add it :) result += c; // when 1 byte char, add it :)
} }
else if(i + len > size){ // when char bigger than remaining string, end loop else if (i + len > size) { // when char bigger than remaining string, end loop
i = size+1; i = size + 1;
} }
else{ else {
ok = true; ok = true;
for(int j=1;j<len && ok;j++){
ok = utf8Part(str.charAt(i+j)); // if following char is compliant or not for (int j = 1; j < len && ok; j++) {
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
} }
@@ -84,7 +92,7 @@ String fixUtf8(String str){
return result; return result;
} }
String removeUtf8(String str){ String removeUtf8(String str) {
str = fixUtf8(str); // fix it in case a utf char is broken str = fixUtf8(str); // fix it in case a utf char is broken
int size = str.length(); int size = str.length();
@@ -92,34 +100,36 @@ String removeUtf8(String str){
char c; char c;
uint8_t len; uint8_t len;
for(int i=0;i<size;i++){ for (int i = 0; i < size; i++) {
c = str.charAt(i); // get character c = str.charAt(i); // get character
len = utf8(c); // get utf8 char len len = utf8(c); // get utf8 char len
if(len <= 1) result += c; // when 1 byte char, add it :) if (len <= 1) result += c; // when 1 byte char, add it :)
else i += len-1; // skip other chars else i += len - 1; // skip other chars
} }
return result; return result;
} }
int utf8Len(String str){ int utf8Len(String str) {
int size = str.length(); int size = str.length();
int result = 0; int result = 0;
char c; char c;
uint8_t len; uint8_t len;
for(int i=0;i<size;i++){ for (int i = 0; i < size; i++) {
c = str.charAt(i); // get character c = str.charAt(i); // get character
len = utf8(c); // get utf8 char len len = utf8(c); // get utf8 char len
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++){
c = str.charAt(i+j); for (int j = 1; j < len; j++) {
if(!utf8Part(c) && utf8(c) == 1){ c = str.charAt(i + j);
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
} }
@@ -131,7 +141,7 @@ int utf8Len(String str){
return result; return result;
} }
String replaceUtf8(String str, String r){ String replaceUtf8(String str, String r) {
str = fixUtf8(str); // fix it in case a utf char is broken str = fixUtf8(str); // fix it in case a utf char is broken
int size = str.length(); int size = str.length();
@@ -139,14 +149,14 @@ String replaceUtf8(String str, String r){
char c; char c;
uint8_t len; uint8_t len;
for(int i=0;i<size;i++){ for (int i = 0; i < size; i++) {
c = str.charAt(i); // get character c = str.charAt(i); // get character
len = utf8(c); // get utf8 char len len = utf8(c); // get utf8 char len
if(len <= 1) result += c; // when 1 byte char, add it :) if (len <= 1) result += c; // when 1 byte char, add it :)
else{ else {
result += r; result += r;
i += len-1; // skip other chars i += len - 1; // skip other chars
} }
} }
@@ -156,22 +166,24 @@ String replaceUtf8(String str, String r){
// ===== LANGUAGE STRING FUNCTIONS ===== // // ===== LANGUAGE STRING FUNCTIONS ===== //
// 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);
} }
// 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 = "";
uint8_t len = strlen(keyword); uint8_t len = strlen(keyword);
uint8_t i = 0; uint8_t i = 0;
while(i<len && keyword[i] != SLASH && keyword[i] != COMMA){ while (i < len && keyword[i] != SLASH && keyword[i] != COMMA) {
str += keyword[i]; str += keyword[i];
i++; i++;
} }
@@ -180,24 +192,29 @@ String keyword(const char* keywordPtr){
} }
// equals function // equals function
bool eqls(const char* str, const char* keywordPtr){ bool eqls(const char* str, const char* keywordPtr) {
if(strlen(str) > 255) return false; // when string too long if (strlen(str) > 255) return false; // when string too long
char keyword[strlen_P(keywordPtr) + 1]; char keyword[strlen_P(keywordPtr) + 1];
strcpy_P(keyword, keywordPtr); strcpy_P(keyword, 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){
if(keyword[b] == SLASH || keyword[b] == COMMA) b++; while (a < lenStr && b < lenKeyword) {
if(tolower(str[a]) != tolower(keyword[b])) result = false; if ((keyword[b] == SLASH) || (keyword[b] == COMMA)) b++;
if((a == lenStr && !result) || !result){ // fast forward to next comma
while(b < lenKeyword && keyword[b] != COMMA) b++; if (tolower(str[a]) != tolower(keyword[b])) result = false;
if (((a == lenStr) && !result) || !result) { // fast forward to next comma
while (b < lenKeyword && keyword[b] != COMMA) b++;
result = true; result = true;
a = 0; a = 0;
} else { } else {
@@ -209,64 +226,73 @@ bool eqls(const char* str, const char* keywordPtr){
return result && a == lenStr && (keyword[b] == COMMA || keyword[b] == SLASH || keyword[b] == ENDOFLINE); return result && a == lenStr && (keyword[b] == COMMA || keyword[b] == SLASH || keyword[b] == ENDOFLINE);
} }
bool eqls(String str, const char* keywordPtr){ bool eqls(String str, const char* keywordPtr) {
return eqls(str.c_str(), keywordPtr); return eqls(str.c_str(), keywordPtr);
} }
// boolean to string // boolean to string
String b2s(bool input){ String b2s(bool input) {
return str(input ? STR_TRUE : STR_FALSE); return str(input ? STR_TRUE : STR_FALSE);
} }
// 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
bool s2b(String input){ bool s2b(String input) {
return eqls(input, STR_TRUE); return eqls(input, STR_TRUE);
} }
// ===== PRINT FUNCTIONS ===== // // ===== PRINT FUNCTIONS ===== //
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);
} }
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;
@@ -346,13 +384,15 @@ int binSearchVendors(uint8_t* searchBytes, int lowerEnd, int upperEnd) {
String searchVendor(uint8_t* mac) { String searchVendor(uint8_t* mac) {
String vendorName = String(); String vendorName = String();
int pos = binSearchVendors(mac, 0, sizeof(data_macs) / 5 - 1); int pos = binSearchVendors(mac, 0, sizeof(data_macs) / 5 - 1);
int realPos = pgm_read_byte_near(data_macs + pos*5 + 3) | pgm_read_byte_near(data_macs + pos*5 + 4) << 8; int realPos = pgm_read_byte_near(data_macs + pos * 5 + 3) | pgm_read_byte_near(data_macs + pos * 5 + 4) << 8;
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,14 +400,15 @@ 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;
} }
@@ -376,44 +417,43 @@ String macToStr(uint8_t* mac) {
return bytesToStr(mac, 6); return bytesToStr(mac, 6);
} }
bool strToMac(String macStr, uint8_t* mac){ bool strToMac(String macStr, uint8_t* mac) {
macStr.replace(String(DOUBLEPOINT), String()); // ":" -> "" macStr.replace(String(DOUBLEPOINT), String()); // ":" -> ""
macStr.replace("0x", String()); // "0x" -> "" macStr.replace("0x", String()); // "0x" -> ""
macStr.replace(String(COMMA), String()); // "," -> "" macStr.replace(String(COMMA), String()); // "," -> ""
macStr.replace(String(DOUBLEQUOTES), String()); // "\"" -> "" macStr.replace(String(DOUBLEQUOTES), String()); // "\"" -> ""
macStr.toUpperCase(); macStr.toUpperCase();
if(macStr.length() != 12){ if (macStr.length() != 12) {
prntln(F_ERROR_MAC); prntln(F_ERROR_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;
} }
void strToColor(String str, uint8_t* buf){ void strToColor(String str, uint8_t* buf) {
str.replace(":", ""); str.replace(":", "");
str.replace("0x", ""); str.replace("0x", "");
str.replace(",", ""); str.replace(",", "");
str.replace("#", ""); str.replace("#", "");
str.toUpperCase(); str.toUpperCase();
if(str.length() != 6){ if (str.length() != 6) {
prntln(F_COLOR_INVALID); prntln(F_COLOR_INVALID);
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;
} }
result += right; result += right;
@@ -424,7 +464,8 @@ 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;
} }
@@ -439,10 +480,12 @@ bool progmemToSpiffs(const char* adr, int len, String path) {
return true; return true;
} }
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,27 +507,30 @@ void readFileToSerial(String path, bool showLineNum) {
uint32_t c = 0; uint32_t c = 0;
char tmp; char tmp;
if(showLineNum){
prnt(buildString(String(),(String)c + String(VERTICALBAR),6)); if (showLineNum) {
prnt(buildString(String(), (String)c + String(VERTICALBAR), 6));
} }
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));
} }
} }
f.close(); f.close();
} }
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(!SPIFFS.exists(pathFrom)){ if (pathTo.charAt(0) != SLASH) pathTo = String(SLASH) + pathTo;
if (!SPIFFS.exists(pathFrom)) {
prnt(F_ERROR_FILE); prnt(F_ERROR_FILE);
prntln(pathFrom); prntln(pathFrom);
return false; return false;
@@ -492,20 +539,21 @@ bool copyFile(String pathFrom, String pathTo){
File f1 = SPIFFS.open(pathFrom, "r"); File f1 = SPIFFS.open(pathFrom, "r");
File f2 = SPIFFS.open(pathTo, "w+"); File f2 = SPIFFS.open(pathTo, "w+");
if(!f1 || !f2) return false; if (!f1 || !f2) return false;
while (f1.available()){ while (f1.available()) {
f2.write(f1.read()); f2.write(f1.read());
} }
return true; return true;
} }
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(!SPIFFS.exists(pathFrom)){ if (pathTo.charAt(0) != SLASH) pathTo = String(SLASH) + pathTo;
if (!SPIFFS.exists(pathFrom)) {
prnt(F_ERROR_FILE); prnt(F_ERROR_FILE);
prntln(pathFrom); prntln(pathFrom);
return false; return false;
@@ -515,27 +563,29 @@ bool renameFile(String pathFrom, String pathTo){
return true; return true;
} }
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;
} }
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,27 +593,29 @@ 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);
File f = SPIFFS.open(path, "r"); File f = SPIFFS.open(path, "r");
File f2 = SPIFFS.open(tmpPath, "w"); File f2 = SPIFFS.open(tmpPath, "w");
if (!f || !f2) return false; if (!f || !f2) return false;
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++;
} }
f.close(); f.close();
@@ -574,28 +626,31 @@ bool removeLines(String path, int lineFrom, int lineTo){
return true; return true;
} }
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";
File f = SPIFFS.open(path, "r"); File f = SPIFFS.open(path, "r");
File f2 = SPIFFS.open(tmpPath, "w"); File f2 = SPIFFS.open(tmpPath, "w");
if (!f || !f2) return false; if (!f || !f2) return false;
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++;
} }
f.close(); f.close();
@@ -606,26 +661,26 @@ bool replaceLine(String path, int line, String &buf){
return true; return true;
} }
JsonVariant parseJSONFile(String path, DynamicJsonBuffer &jsonBuffer) { JsonVariant parseJSONFile(String path, DynamicJsonBuffer& jsonBuffer) {
if (path.charAt(0) != SLASH) path = String(SLASH) + path; if (path.charAt(0) != SLASH) path = String(SLASH) + path;
//create JSON Variant // create JSON Variant
JsonVariant root; JsonVariant root;
//create buffer // create buffer
String buf = ""; String buf = "";
//read file into buffer // read file into buffer
if (!readFile(path, buf)) { //if file couldn't be opened, send 404 error if (!readFile(path, buf)) { // if file couldn't be opened, send 404 error
prnt(F_ERROR_OPEN); prnt(F_ERROR_OPEN);
prntln(path); prntln(path);
buf = "{}"; buf = "{}";
} }
//parse file-buffer into a JSON Variant // parse file-buffer into a JSON Variant
root = jsonBuffer.parse(buf); root = jsonBuffer.parse(buf);
//if parsing unsuccessful // if parsing unsuccessful
if (!root.success()) { if (!root.success()) {
prnt(F_ERROR_PARSING_JSON); prnt(F_ERROR_PARSING_JSON);
prntln(path); prntln(path);
@@ -640,45 +695,45 @@ bool removeFile(String path) {
return SPIFFS.remove(path); return SPIFFS.remove(path);
} }
void saveJSONFile(String path, JsonObject &root) { void saveJSONFile(String path, JsonObject& root) {
if (path.charAt(0) != SLASH) path = String(SLASH) + path; if (path.charAt(0) != SLASH) path = String(SLASH) + path;
//create buffer // create buffer
String buf; String buf;
//convert JSON object into string and write it into buffer // convert JSON object into string and write it into buffer
root.printTo(buf); root.printTo(buf);
//if buffer too big // if buffer too big
if (buf.length() > 2048) { if (buf.length() > 2048) {
prntln(F_ERROR_TO_BIG ); prntln(F_ERROR_TO_BIG);
prntln(path); prntln(path);
prntln(buf); prntln(buf);
return; return;
} }
//write buffer into SPIFFS file // write buffer into SPIFFS file
writeFile(path, buf); writeFile(path, buf);
} }
void saveJSONFile(String path, JsonArray &root) { void saveJSONFile(String path, JsonArray& root) {
if (path.charAt(0) != SLASH) path = String(SLASH) + path; if (path.charAt(0) != SLASH) path = String(SLASH) + path;
//create buffer // create buffer
String buf; String buf;
//convert JSON object into string and write it into buffer // convert JSON object into string and write it into buffer
root.printTo(buf); root.printTo(buf);
//if buffer too big // if buffer too big
if (buf.length() > 2048) { if (buf.length() > 2048) {
prntln(F_ERROR_TO_BIG ); prntln(F_ERROR_TO_BIG);
prntln(path); prntln(path);
prntln(buf); prntln(buf);
return; return;
} }
//write buffer into SPIFFS file // write buffer into SPIFFS file
writeFile(path, buf); writeFile(path, buf);
} }
@@ -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

@@ -19,7 +19,7 @@ extern "C" {
/* /*
This file contains all necessary functions for hosting and connecting to an access point. This file contains all necessary functions for hosting and connecting to an access point.
For compatibility and simplicity, all those functions are global. For compatibility and simplicity, all those functions are global.
*/ */
// Important strings // Important strings
const char W_DEAUTHER[] PROGMEM = "deauth.me"; // captive portal domain (alternative to 192.168.4.1) const char W_DEAUTHER[] PROGMEM = "deauth.me"; // captive portal domain (alternative to 192.168.4.1)
@@ -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,8 +172,9 @@ bool handleFileRead(String path) {
return true; return true;
} }
/* /*
void handleFileUpload() { void handleFileUpload() {
// only allow uploads on /edit address // only allow uploads on /edit address
if (server.uri() != "/edit") if (server.uri() != "/edit")
return; return;
@@ -180,9 +198,10 @@ void handleFileUpload() {
//Serial.print("handleFileUpload Size: "); //Serial.print("handleFileUpload Size: ");
//Serial.println(upload.totalSize); //Serial.println(upload.totalSize);
} }
}*/ }*/
/* /*
void handleFileDelete() { void handleFileDelete() {
if (server.args() == 0) if (server.args() == 0)
return server.send(500, str(W_TXT), str(W_BAD_ARGS)); return server.send(500, str(W_TXT), str(W_BAD_ARGS));
@@ -194,9 +213,10 @@ void handleFileDelete() {
return server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND)); return server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND));
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)
return server.send(500, str(W_TXT), str(W_BAD_ARGS)); return server.send(500, str(W_TXT), str(W_BAD_ARGS));
@@ -212,8 +232,7 @@ void handleFileCreate() {
else else
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));
@@ -221,19 +240,18 @@ void handleFileList() {
} }
String path = server.arg("dir"); String path = server.arg("dir");
//Serial.println("handleFileList: " + path); // Serial.println("handleFileList: " + path);
Dir dir = SPIFFS.openDir(path); Dir dir = SPIFFS.openDir(path);
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;
@@ -277,96 +297,95 @@ void startAP(String path, String ssid, String password, uint8_t ch, bool hidden,
MDNS.begin(str(W_DEAUTHER).c_str()); MDNS.begin(str(W_DEAUTHER).c_str());
server.on(String(F("/list")).c_str(), HTTP_GET, handleFileList); //list directory server.on(String(F("/list")).c_str(), HTTP_GET, handleFileList); // list directory
// ================================================================ // ================================================================
// post here the output of the webConverter.py // post here the output of the webConverter.py
if(!settings.getWebSpiffs()){ if (!settings.getWebSpiffs()) {
server.on(String(SLASH).c_str(), HTTP_GET, [](){ server.on(String(SLASH).c_str(), HTTP_GET, []() {
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML); sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
}); });
server.on(String(F("/attack.html")).c_str(), HTTP_GET, [](){ server.on(String(F("/attack.html")).c_str(), HTTP_GET, []() {
sendProgmem(attackhtml, sizeof(attackhtml), W_HTML); sendProgmem(attackhtml, sizeof(attackhtml), W_HTML);
}); });
server.on(String(F("/index.html")).c_str(), HTTP_GET, [](){ server.on(String(F("/index.html")).c_str(), HTTP_GET, []() {
sendProgmem(indexhtml, sizeof(indexhtml), W_HTML); sendProgmem(indexhtml, sizeof(indexhtml), W_HTML);
}); });
server.on(String(F("/info.html")).c_str(), HTTP_GET, [](){ server.on(String(F("/info.html")).c_str(), HTTP_GET, []() {
sendProgmem(infohtml, sizeof(infohtml), W_HTML); sendProgmem(infohtml, sizeof(infohtml), W_HTML);
}); });
server.on(String(F("/scan.html")).c_str(), HTTP_GET, [](){ server.on(String(F("/scan.html")).c_str(), HTTP_GET, []() {
sendProgmem(scanhtml, sizeof(scanhtml), W_HTML); sendProgmem(scanhtml, sizeof(scanhtml), W_HTML);
}); });
server.on(String(F("/settings.html")).c_str(), HTTP_GET, [](){ server.on(String(F("/settings.html")).c_str(), HTTP_GET, []() {
sendProgmem(settingshtml, sizeof(settingshtml), W_HTML); sendProgmem(settingshtml, sizeof(settingshtml), W_HTML);
}); });
server.on(String(F("/ssids.html")).c_str(), HTTP_GET, [](){ server.on(String(F("/ssids.html")).c_str(), HTTP_GET, []() {
sendProgmem(ssidshtml, sizeof(ssidshtml), W_HTML); sendProgmem(ssidshtml, sizeof(ssidshtml), W_HTML);
}); });
server.on(String(F("/style.css")).c_str(), HTTP_GET, [](){ server.on(String(F("/style.css")).c_str(), HTTP_GET, []() {
sendProgmem(stylecss, sizeof(stylecss), W_CSS); sendProgmem(stylecss, sizeof(stylecss), W_CSS);
}); });
server.on(String(F("/js/attack.js")).c_str(), HTTP_GET, [](){ server.on(String(F("/js/attack.js")).c_str(), HTTP_GET, []() {
sendProgmem(attackjs, sizeof(attackjs), W_JS); sendProgmem(attackjs, sizeof(attackjs), W_JS);
}); });
server.on(String(F("/js/scan.js")).c_str(), HTTP_GET, [](){ server.on(String(F("/js/scan.js")).c_str(), HTTP_GET, []() {
sendProgmem(scanjs, sizeof(scanjs), W_JS); sendProgmem(scanjs, sizeof(scanjs), W_JS);
}); });
server.on(String(F("/js/settings.js")).c_str(), HTTP_GET, [](){ server.on(String(F("/js/settings.js")).c_str(), HTTP_GET, []() {
sendProgmem(settingsjs, sizeof(settingsjs), W_JS); sendProgmem(settingsjs, sizeof(settingsjs), W_JS);
}); });
server.on(String(F("/js/site.js")).c_str(), HTTP_GET, [](){ server.on(String(F("/js/site.js")).c_str(), HTTP_GET, []() {
sendProgmem(sitejs, sizeof(sitejs), W_JS); sendProgmem(sitejs, sizeof(sitejs), W_JS);
}); });
server.on(String(F("/js/ssids.js")).c_str(), HTTP_GET, [](){ server.on(String(F("/js/ssids.js")).c_str(), HTTP_GET, []() {
sendProgmem(ssidsjs, sizeof(ssidsjs), W_JS); sendProgmem(ssidsjs, sizeof(ssidsjs), W_JS);
}); });
server.on(String(F("/lang/cn.lang")).c_str(), HTTP_GET, [](){ server.on(String(F("/lang/cn.lang")).c_str(), HTTP_GET, []() {
sendProgmem(cnlang, sizeof(cnlang), W_JSON); sendProgmem(cnlang, sizeof(cnlang), W_JSON);
}); });
server.on(String(F("/lang/cs.lang")).c_str(), HTTP_GET, [](){ server.on(String(F("/lang/cs.lang")).c_str(), HTTP_GET, []() {
sendProgmem(cslang, sizeof(cslang), W_JSON); sendProgmem(cslang, sizeof(cslang), W_JSON);
}); });
server.on(String(F("/lang/de.lang")).c_str(), HTTP_GET, [](){ server.on(String(F("/lang/de.lang")).c_str(), HTTP_GET, []() {
sendProgmem(delang, sizeof(delang), W_JSON); sendProgmem(delang, sizeof(delang), W_JSON);
}); });
server.on(String(F("/lang/en.lang")).c_str(), HTTP_GET, [](){ server.on(String(F("/lang/en.lang")).c_str(), HTTP_GET, []() {
sendProgmem(enlang, sizeof(enlang), W_JSON); sendProgmem(enlang, sizeof(enlang), W_JSON);
}); });
server.on(String(F("/lang/fr.lang")).c_str(), HTTP_GET, [](){ server.on(String(F("/lang/fr.lang")).c_str(), HTTP_GET, []() {
sendProgmem(frlang, sizeof(frlang), W_JSON); sendProgmem(frlang, sizeof(frlang), W_JSON);
}); });
server.on(String(F("/lang/it.lang")).c_str(), HTTP_GET, [](){ server.on(String(F("/lang/it.lang")).c_str(), HTTP_GET, []() {
sendProgmem(itlang, sizeof(itlang), W_JSON); sendProgmem(itlang, sizeof(itlang), W_JSON);
}); });
server.on(String(F("/lang/ru.lang")).c_str(), HTTP_GET, [](){ server.on(String(F("/lang/ru.lang")).c_str(), HTTP_GET, []() {
sendProgmem(rulang, sizeof(rulang), W_JSON); sendProgmem(rulang, sizeof(rulang), W_JSON);
}); });
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, [](){
if(!settings.getWebSpiffs()){
if(settings.getLang() == String(F("cn"))) sendProgmem(cnlang, sizeof(cnlang), W_JSON);
else if(settings.getLang() == String(F("cs"))) sendProgmem(cslang, sizeof(cslang), W_JSON);
else if(settings.getLang() == String(F("de"))) sendProgmem(delang, sizeof(delang), W_JSON);
else if(settings.getLang() == String(F("en"))) sendProgmem(enlang, sizeof(enlang), W_JSON);
else if(settings.getLang() == String(F("fr"))) sendProgmem(frlang, sizeof(frlang), W_JSON);
else if(settings.getLang() == String(F("it"))) sendProgmem(itlang, sizeof(itlang), W_JSON);
else if(settings.getLang() == String(F("ru"))) sendProgmem(rulang, sizeof(rulang), W_JSON);
else if(settings.getLang() == String(F("tlh"))) sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
else handleFileRead(String(F("/web/lang/"))+settings.getLang()+String(F(".lang")));
} else {
handleFileRead(String(F("/web/lang/"))+settings.getLang()+String(F(".lang")));
} }
}); server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, []() {
if (!settings.getWebSpiffs()) {
if (settings.getLang() == String(F("cn"))) sendProgmem(cnlang, sizeof(cnlang), W_JSON);
else if (settings.getLang() == String(F("cs"))) sendProgmem(cslang, sizeof(cslang), W_JSON);
else if (settings.getLang() == String(F("de"))) sendProgmem(delang, sizeof(delang), W_JSON);
else if (settings.getLang() == String(F("en"))) sendProgmem(enlang, sizeof(enlang), W_JSON);
else if (settings.getLang() == String(F("fr"))) sendProgmem(frlang, sizeof(frlang), W_JSON);
else if (settings.getLang() == String(F("it"))) sendProgmem(itlang, sizeof(itlang), W_JSON);
else if (settings.getLang() == String(F("ru"))) sendProgmem(rulang, sizeof(rulang), W_JSON);
else if (settings.getLang() == String(F("tlh"))) sendProgmem(tlhlang, sizeof(tlhlang), W_JSON);
// ================================================================ else handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
} else {
handleFileRead(String(F("/web/lang/")) + settings.getLang() + String(F(".lang")));
}
});
// ================================================================
server.on(String(F("/run")).c_str(), HTTP_GET, []() { server.on(String(F("/run")).c_str(), HTTP_GET, []() {
server.send(200, str(W_TXT), str(W_OK).c_str()); server.send(200, str(W_TXT), str(W_OK).c_str());
@@ -396,8 +415,8 @@ server.on(str(W_DEFAULT_LANG).c_str(), HTTP_GET, [](){
// aggressively caching static assets // aggressively caching static assets
server.serveStatic("/js", SPIFFS, String(wifi_config_path + "/js").c_str(), "max-age=86400"); server.serveStatic("/js", SPIFFS, String(wifi_config_path + "/js").c_str(), "max-age=86400");
//called when the url is not defined here // called when the url is not defined here
//use it to load content from SPIFFS // use it to load content from SPIFFS
server.onNotFound([]() { server.onNotFound([]() {
if (!handleFileRead(server.uri())) { if (!handleFileRead(server.uri())) {
server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND)); server.send(404, str(W_TXT), str(W_FILE_NOT_FOUND));
@@ -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;
@@ -439,8 +460,9 @@ void printWifiStatus() {
prntln(b2s(wifi_config_captivePortal)); prntln(b2s(wifi_config_captivePortal));
} }
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