5#include <Preferences.h>
27 bool isNew = !fs.exists(path);
29 fs::File check = fs.open(path, FILE_READ);
31 isNew = (check.size() == 0);
36 fs::File file = fs.open(path, FILE_APPEND);
37 if (!file)
return false;
66 static bool appendPacket(fs::FS &fs,
const char* path,
const uint8_t* payload, uint16_t len, int8_t rssi, uint32_t ts_usec) {
67 bool isNew = !fs.exists(path);
69 fs::File check = fs.open(path, FILE_READ);
71 isNew = (check.size() == 0);
76 fs::File file = fs.open(path, FILE_APPEND);
77 if (!file)
return false;
88 file.write(buf, wlen);
110 fs::File file = fs.open(path, FILE_APPEND);
111 if (!file)
return false;
114 if (str.length() > 0) {
144 float lat,
float lon,
float alt = 0.0,
float acc = 10.0) {
145 bool isNew = !fs.exists(path);
147 fs::File check = fs.open(path, FILE_READ);
149 isNew = (check.size() == 0);
154 fs::File file = fs.open(path, FILE_APPEND);
155 if (!file)
return false;
159 file.println(
"WigleWifi-1.4,appRelease=1.0,model=Politician,release=1.0,device=ESP32,display=1.0,board=ESP32,brand=Espressif");
160 file.println(
"MAC,SSID,AuthMode,FirstSeen,Channel,RSSI,CurrentLatitude,CurrentLongitude,AltitudeMeters,AccuracyMeters,Type");
166 const char* authStr =
"[WPA2-PSK-CCMP][ESS]";
171 snprintf(line,
sizeof(line),
"%02X:%02X:%02X:%02X:%02X:%02X,%s,%s,1970-01-01 00:00:00,%d,%d,%.6f,%.6f,%.1f,%.1f,WIFI",
189 bool isNew = !fs.exists(path);
191 fs::File file = fs.open(path, FILE_APPEND);
192 if (!file)
return false;
195 file.println(
"Enterprise BSSID,Client MAC,Plaintext Identity,Channel,RSSI");
199 snprintf(line,
sizeof(line),
"%02X:%02X:%02X:%02X:%02X:%02X,%02X:%02X:%02X:%02X:%02X:%02X,%s,%d,%d",
218 static const int MAX_STORED = 128;
219 uint8_t _cache[MAX_STORED][6];
224 memset(_cache, 0,
sizeof(_cache));
231 _prefs.begin(_ns.c_str(),
false);
232 size_t bytes = _prefs.getBytes(
"bssids", _cache,
sizeof(_cache));
234 if (_count > MAX_STORED) _count = MAX_STORED;
242 for (
size_t i = 0; i < _count; i++) {
243 engine.markCaptured(_cache[i]);
252 bool add(
const uint8_t* bssid) {
253 for (
size_t i = 0; i < _count; i++) {
254 if (memcmp(_cache[i], bssid, 6) == 0)
return false;
256 if (_count >= MAX_STORED)
return false;
258 memcpy(_cache[_count], bssid, 6);
262 _prefs.putBytes(
"bssids", _cache, _count * 6);
271 _prefs.remove(
"bssids");
The core WiFi handshake capturing engine.
Helper for logging harvested 802.1X Enterprise Credentials.
static bool append(fs::FS &fs, const char *path, const EapIdentityRecord &rec)
Helper for writing HandshakeRecords to an HC22000 text file.
static bool append(fs::FS &fs, const char *path, const HandshakeRecord &rec)
Appends a HandshakeRecord to a file as an HC22000 string.
Helper for persistently storing captured BSSIDs in NVS memory.
NvsBssidCache(const char *ns="wardrive")
bool add(const uint8_t *bssid)
Adds a newly captured BSSID to the cache and saves it to NVS.
void loadInto(Politician &engine)
Feeds the loaded BSSIDs into the Politician engine so it knows to ignore them.
void begin()
Initializes the NVS memory and loads the cached BSSIDs into RAM.
void clear()
Clears the entire cache from NVS.
Helper for writing HandshakeRecords to a standard PCAPNG file.
static bool append(fs::FS &fs, const char *path, const HandshakeRecord &rec)
Appends a HandshakeRecord to a file as PCAPNG.
static bool appendPacket(fs::FS &fs, const char *path, const uint8_t *payload, uint16_t len, int8_t rssi, uint32_t ts_usec)
Appends a raw 802.11 sniffer frame to a PCAPNG file (used for intel gathering).
Helper for writing precise GPS location coordinates to a Wigle.net compatible CSV file.
static bool append(fs::FS &fs, const char *path, const HandshakeRecord &rec, float lat, float lon, float alt=0.0, float acc=10.0)
Appends a HandshakeRecord's details alongside GPS coordinates to a Wigle CSV.