Files
cute-handshake-capture/handshake-capture-c6/HandshakeCapture.h
drjones 804e71e175 handshake-capture-c6: production SD gating (SD_IsReady), v1.0.1
- Gate capture on SD_IsReady() after successful SD_Init; avoid false
  'insert SD' when SD.cardType() lies after WiFi on shared SPI with LCD
- SD_Init: LCD CS high, SD.end() on empty card; HandshakeCapture save path
  retries SD_Init before discard
- FAT filename sanitize, discard deadlocks, WPA3 scan labels, docs (README,
  PRODUCTION, IMPROVEMENTS), firmware version 1.0.1

Made-with: Cursor
2026-03-21 01:12:12 -07:00

88 lines
2.1 KiB
C

#pragma once
#include <Arduino.h>
#include <WiFi.h>
#include "esp_wifi.h"
#include <SD.h>
/** Semantic version (Serial banner + support). */
#define HANDSHAKE_FIRMWARE_VERSION "1.0.1"
/** SD write only after this many EAPOL-Key frames (full WPA/WPA2 4-way). */
#define HANDSHAKE_EAPOL_FRAMES 4
// Two APs at once: less on-air contention, more time per target before rotating.
#define MAX_SLOTS 2
#define MAX_NETWORKS 20
#define MAX_CLIENTS_PER_SLOT 8
#define PCAP_MAX_SIZE 4096
typedef struct {
uint32_t magic_number;
uint16_t version_major;
uint16_t version_minor;
int32_t thiszone;
uint32_t sigfigs;
uint32_t snaplen;
uint32_t network;
} __attribute__((packed)) pcap_global_header_t;
typedef struct {
uint32_t ts_sec;
uint32_t ts_usec;
uint32_t incl_len;
uint32_t orig_len;
} __attribute__((packed)) pcap_record_header_t;
typedef struct {
String ssid;
uint8_t bssid[6];
int ch;
int rssi;
String encryption;
bool handshake_captured;
} WifiNetwork;
typedef struct {
uint8_t mac[6];
uint32_t last_seen;
} ClientInfo;
typedef struct {
uint8_t bssid[6];
char ssid[33];
int network_index;
bool beacon_captured;
uint8_t eapol_count;
uint8_t pcap_buffer[PCAP_MAX_SIZE];
size_t pcap_size;
bool active;
ClientInfo clients[MAX_CLIENTS_PER_SLOT];
uint8_t client_count;
} CaptureSlot;
// Phase 3 (deauth burst) is transient — no dedicated state needed
enum CapturePhase : uint8_t {
PHASE_OBSERVING, // Phase 2: passive client mapping (RX only)
PHASE_CAPTURING // Phase 4: EAPOL capture (RX only)
};
extern WifiNetwork networks[MAX_NETWORKS];
extern CaptureSlot slots[MAX_SLOTS];
extern volatile int pending_save_slots[MAX_SLOTS];
extern volatile uint8_t latest_eapol_count[MAX_SLOTS];
extern bool is_capturing;
extern int current_channel;
extern CapturePhase capturePhase;
void handshakeCaptureInit();
void handshakeCaptureProcessPending();
void refillSlots();
bool wasBssidCaptured(const uint8_t* bssid);
void scanNetworksSortedByRSSI();
void startMultiCapture();
void stopCapture();
bool isCaptureable(int index);
void handshakeCaptureLoop();
int getCaptureableCount();