fixup preprocessor directives

This commit is contained in:
tracedgod
2023-06-09 23:10:21 -04:00
parent 9c51a562b8
commit 8bf1402a99
5 changed files with 263 additions and 228 deletions

View File

@@ -270,13 +270,16 @@ void CommandLine::runCommand(String input) {
#endif #endif
} }
// ls command // ls command
#ifdef HAS_SD
else if (cmd_args.get(0) == LS_CMD) { else if (cmd_args.get(0) == LS_CMD) {
if (cmd_args.size() > 1) #ifdef HAS_SD
sd_obj.listDir(cmd_args.get(1)); if (cmd_args.size() > 1)
else sd_obj.listDir(cmd_args.get(1));
Serial.println("You did not provide a dir to list"); else
} Serial.println("You did not provide a dir to list");
#else
Serial.println("SD support disabled, cannot use command");
return;
}
#endif #endif
// Channel command // Channel command
@@ -666,16 +669,21 @@ void CommandLine::runCommand(String input) {
} }
// Update via SD // Update via SD
else if (sd_sw != -1) { else if (sd_sw != -1) {
#ifndef WRITE_PACKETS_SERIAL #ifdef HAS_SD
if (!sd_obj.supported) { #ifndef WRITE_PACKETS_SERIAL
Serial.println("SD card is not connected. Cannot perform SD Update"); if (!sd_obj.supported) {
return; Serial.println("SD card is not connected. Cannot perform SD Update");
} return;
wifi_scan_obj.currentScanMode = OTA_UPDATE; }
sd_obj.runUpdate(); wifi_scan_obj.currentScanMode = OTA_UPDATE;
#else sd_obj.runUpdate();
Serial.println("SD card not initialized. Cannot perform SD Update"); #else
#endif Serial.println("SD card not initialized. Cannot perform SD Update");
#endif
#else
Serial.println("SD card support disabled. Cannot perform SD Update");
return;
#endif
} }
} }
} }

View File

@@ -1,11 +1,10 @@
#ifdef HAS_SD #include "SDInterface.h"
#include "lang_var.h"
#include "SDInterface.h" bool SDInterface::initSD() {
#include "lang_var.h" #ifdef HAS_SD
bool SDInterface::initSD() {
String display_string = ""; String display_string = "";
#ifdef KIT #ifdef KIT
pinMode(SD_DET, INPUT); pinMode(SD_DET, INPUT);
if (digitalRead(SD_DET) == LOW) { if (digitalRead(SD_DET) == LOW) {
@@ -17,11 +16,11 @@
return false; return false;
} }
#endif #endif
pinMode(SD_CS, OUTPUT); pinMode(SD_CS, OUTPUT);
delay(10); delay(10);
if (!SD.begin(SD_CS)) { if (!SD.begin(SD_CS)) {
Serial.println(F("Failed to mount SD Card")); Serial.println(F("Failed to mount SD Card"));
this->supported = false; this->supported = false;
@@ -38,221 +37,224 @@
// Serial.println(F("SD: SDHC Mounted")); // Serial.println(F("SD: SDHC Mounted"));
//else //else
// Serial.println(F("SD: UNKNOWN Card Mounted")); // Serial.println(F("SD: UNKNOWN Card Mounted"));
this->cardSizeMB = SD.cardSize() / (1024 * 1024); this->cardSizeMB = SD.cardSize() / (1024 * 1024);
//Serial.printf("SD Card Size: %lluMB\n", this->cardSizeMB); //Serial.printf("SD Card Size: %lluMB\n", this->cardSizeMB);
if (this->supported) { if (this->supported) {
const int NUM_DIGITS = log10(this->cardSizeMB) + 1; const int NUM_DIGITS = log10(this->cardSizeMB) + 1;
char sz[NUM_DIGITS + 1]; char sz[NUM_DIGITS + 1];
sz[NUM_DIGITS] = 0; sz[NUM_DIGITS] = 0;
for ( size_t i = NUM_DIGITS; i--; this->cardSizeMB /= 10) for ( size_t i = NUM_DIGITS; i--; this->cardSizeMB /= 10)
{ {
sz[i] = '0' + (this->cardSizeMB % 10); sz[i] = '0' + (this->cardSizeMB % 10);
display_string.concat((String)sz[i]); display_string.concat((String)sz[i]);
} }
this->card_sz = sz; this->card_sz = sz;
} }
buffer_obj = Buffer(); buffer_obj = Buffer();
if (!SD.exists("/SCRIPTS")) { if (!SD.exists("/SCRIPTS")) {
Serial.println("/SCRIPTS does not exist. Creating..."); Serial.println("/SCRIPTS does not exist. Creating...");
SD.mkdir("/SCRIPTS"); SD.mkdir("/SCRIPTS");
Serial.println("/SCRIPTS created"); Serial.println("/SCRIPTS created");
} }
return true;
}
}
void SDInterface::listDir(String str_dir){
if (this->supported) {
File dir = SD.open(str_dir);
while (true)
{
File entry = dir.openNextFile();
if (! entry)
{
break;
}
//for (uint8_t i = 0; i < numTabs; i++)
//{
// Serial.print('\t');
//}
Serial.print(entry.name());
Serial.print("\t");
Serial.println(entry.size());
entry.close();
}
}
}
void SDInterface::addPacket(uint8_t* buf, uint32_t len) {
if ((this->supported) && (this->do_save)) {
buffer_obj.addPacket(buf, len);
}
}
void SDInterface::openCapture(String file_name) {
bool save_pcap = settings_obj.loadSetting<bool>("SavePCAP");
if ((this->supported) && (save_pcap)) {
buffer_obj.createPcapFile(&SD, file_name);
buffer_obj.open();
}
}
void SDInterface::runUpdate() {
#ifdef HAS_SCREEN
display_obj.tft.setTextWrap(false);
display_obj.tft.setFreeFont(NULL);
display_obj.tft.setCursor(0, 100);
display_obj.tft.setTextSize(1);
display_obj.tft.setTextColor(TFT_WHITE);
display_obj.tft.println(F(text15)); return true;
#endif }
File updateBin = SD.open("/update.bin");
if (updateBin) { #else
if(updateBin.isDirectory()){ Serial.println("SD support disabled, skipping init");
#ifdef HAS_SCREEN return false;
display_obj.tft.setTextColor(TFT_RED); #endif
display_obj.tft.println(F(text_table2[0])); }
#endif
Serial.println(F("Error, could not find \"update.bin\"")); void SDInterface::listDir(String str_dir){
#ifdef HAS_SCREEN if (this->supported) {
display_obj.tft.setTextColor(TFT_WHITE); File dir = SD.open(str_dir);
#endif while (true)
updateBin.close(); {
return; File entry = dir.openNextFile();
if (! entry)
{
break;
} }
//for (uint8_t i = 0; i < numTabs; i++)
//{
// Serial.print('\t');
//}
Serial.print(entry.name());
Serial.print("\t");
Serial.println(entry.size());
entry.close();
}
}
}
void SDInterface::addPacket(uint8_t* buf, uint32_t len) {
if ((this->supported) && (this->do_save)) {
buffer_obj.addPacket(buf, len);
}
}
void SDInterface::openCapture(String file_name) {
bool save_pcap = settings_obj.loadSetting<bool>("SavePCAP");
if ((this->supported) && (save_pcap)) {
buffer_obj.createPcapFile(&SD, file_name);
buffer_obj.open();
}
}
void SDInterface::runUpdate() {
#ifdef HAS_SCREEN
display_obj.tft.setTextWrap(false);
display_obj.tft.setFreeFont(NULL);
display_obj.tft.setCursor(0, 100);
display_obj.tft.setTextSize(1);
display_obj.tft.setTextColor(TFT_WHITE);
size_t updateSize = updateBin.size(); display_obj.tft.println(F(text15));
#endif
if (updateSize > 0) { File updateBin = SD.open("/update.bin");
#ifdef HAS_SCREEN if (updateBin) {
display_obj.tft.println(F(text_table2[1])); if(updateBin.isDirectory()){
#endif
Serial.println(F("Starting update over SD. Please wait..."));
this->performUpdate(updateBin, updateSize);
}
else {
#ifdef HAS_SCREEN
display_obj.tft.setTextColor(TFT_RED);
display_obj.tft.println(F(text_table2[2]));
#endif
Serial.println(F("Error, file is empty"));
#ifdef HAS_SCREEN
display_obj.tft.setTextColor(TFT_WHITE);
#endif
return;
}
updateBin.close();
// whe finished remove the binary from sd card to indicate end of the process
#ifdef HAS_SCREEN #ifdef HAS_SCREEN
display_obj.tft.println(F(text_table2[3])); display_obj.tft.setTextColor(TFT_RED);
display_obj.tft.println(F(text_table2[0]));
#endif #endif
Serial.println(F("rebooting...")); Serial.println(F("Error, could not find \"update.bin\""));
//SD.remove("/update.bin"); #ifdef HAS_SCREEN
delay(1000); display_obj.tft.setTextColor(TFT_WHITE);
ESP.restart(); #endif
updateBin.close();
return;
}
size_t updateSize = updateBin.size();
if (updateSize > 0) {
#ifdef HAS_SCREEN
display_obj.tft.println(F(text_table2[1]));
#endif
Serial.println(F("Starting update over SD. Please wait..."));
this->performUpdate(updateBin, updateSize);
} }
else { else {
#ifdef HAS_SCREEN #ifdef HAS_SCREEN
display_obj.tft.setTextColor(TFT_RED); display_obj.tft.setTextColor(TFT_RED);
display_obj.tft.println(F(text_table2[4])); display_obj.tft.println(F(text_table2[2]));
#endif #endif
Serial.println(F("Could not load update.bin from sd root")); Serial.println(F("Error, file is empty"));
#ifdef HAS_SCREEN #ifdef HAS_SCREEN
display_obj.tft.setTextColor(TFT_WHITE); display_obj.tft.setTextColor(TFT_WHITE);
#endif #endif
return;
} }
}
void SDInterface::performUpdate(Stream &updateSource, size_t updateSize) {
if (Update.begin(updateSize)) {
#ifdef HAS_SCREEN
display_obj.tft.println(text_table2[5] + String(updateSize));
display_obj.tft.println(F(text_table2[6]));
#endif
size_t written = Update.writeStream(updateSource);
if (written == updateSize) {
#ifdef HAS_SCREEN
display_obj.tft.println(text_table2[7] + String(written) + text_table2[10]);
#endif
Serial.println("Written : " + String(written) + " successfully");
}
else {
#ifdef HAS_SCREEN
display_obj.tft.println(text_table2[8] + String(written) + "/" + String(updateSize) + text_table2[9]);
#endif
Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?");
}
if (Update.end()) {
Serial.println("OTA done!");
if (Update.isFinished()) {
#ifdef HAS_SCREEN
display_obj.tft.println(F(text_table2[11]));
#endif
Serial.println(F("Update successfully completed. Rebooting."));
}
else {
#ifdef HAS_SCREEN
display_obj.tft.setTextColor(TFT_RED);
display_obj.tft.println(text_table2[12]);
#endif
Serial.println("Update not finished? Something went wrong!");
#ifdef HAS_SCREEN
display_obj.tft.setTextColor(TFT_WHITE);
#endif
}
}
else {
#ifdef HAS_SCREEN
display_obj.tft.println(text_table2[13] + String(Update.getError()));
#endif
Serial.println("Error Occurred. Error #: " + String(Update.getError()));
}
}
else
{
#ifdef HAS_SCREEN
display_obj.tft.println(text_table2[14]);
#endif
Serial.println("Not enough space to begin OTA");
}
}
bool SDInterface::checkDetectPin() {
#ifdef KIT
if (digitalRead(SD_DET) == LOW)
return true;
else
return false;
#endif
return false;
}
void SDInterface::main() {
if ((this->supported) && (this->do_save)) {
//Serial.println("Saving packet...");
buffer_obj.forceSave(&SD);
}
else if (!this->supported) {
if (checkDetectPin()) {
delay(100);
this->initSD();
}
}
}
#endif updateBin.close();
// whe finished remove the binary from sd card to indicate end of the process
#ifdef HAS_SCREEN
display_obj.tft.println(F(text_table2[3]));
#endif
Serial.println(F("rebooting..."));
//SD.remove("/update.bin");
delay(1000);
ESP.restart();
}
else {
#ifdef HAS_SCREEN
display_obj.tft.setTextColor(TFT_RED);
display_obj.tft.println(F(text_table2[4]));
#endif
Serial.println(F("Could not load update.bin from sd root"));
#ifdef HAS_SCREEN
display_obj.tft.setTextColor(TFT_WHITE);
#endif
}
}
void SDInterface::performUpdate(Stream &updateSource, size_t updateSize) {
if (Update.begin(updateSize)) {
#ifdef HAS_SCREEN
display_obj.tft.println(text_table2[5] + String(updateSize));
display_obj.tft.println(F(text_table2[6]));
#endif
size_t written = Update.writeStream(updateSource);
if (written == updateSize) {
#ifdef HAS_SCREEN
display_obj.tft.println(text_table2[7] + String(written) + text_table2[10]);
#endif
Serial.println("Written : " + String(written) + " successfully");
}
else {
#ifdef HAS_SCREEN
display_obj.tft.println(text_table2[8] + String(written) + "/" + String(updateSize) + text_table2[9]);
#endif
Serial.println("Written only : " + String(written) + "/" + String(updateSize) + ". Retry?");
}
if (Update.end()) {
Serial.println("OTA done!");
if (Update.isFinished()) {
#ifdef HAS_SCREEN
display_obj.tft.println(F(text_table2[11]));
#endif
Serial.println(F("Update successfully completed. Rebooting."));
}
else {
#ifdef HAS_SCREEN
display_obj.tft.setTextColor(TFT_RED);
display_obj.tft.println(text_table2[12]);
#endif
Serial.println("Update not finished? Something went wrong!");
#ifdef HAS_SCREEN
display_obj.tft.setTextColor(TFT_WHITE);
#endif
}
}
else {
#ifdef HAS_SCREEN
display_obj.tft.println(text_table2[13] + String(Update.getError()));
#endif
Serial.println("Error Occurred. Error #: " + String(Update.getError()));
}
}
else
{
#ifdef HAS_SCREEN
display_obj.tft.println(text_table2[14]);
#endif
Serial.println("Not enough space to begin OTA");
}
}
bool SDInterface::checkDetectPin() {
#ifdef KIT
if (digitalRead(SD_DET) == LOW)
return true;
else
return false;
#endif
return false;
}
void SDInterface::main() {
if ((this->supported) && (this->do_save)) {
//Serial.println("Saving packet...");
buffer_obj.forceSave(&SD);
}
else if (!this->supported) {
if (checkDetectPin()) {
delay(100);
this->initSD();
}
}
}

View File

@@ -580,8 +580,10 @@ void WiFiScan::RunAPScan(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.open(); buffer_obj.open();
#else #elif defined(HAS_SD)
sd_obj.openCapture("ap"); sd_obj.openCapture("ap");
#else
return;
#endif #endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
@@ -809,7 +811,7 @@ void WiFiScan::RunInfo()
#ifdef HAS_SCREEN #ifdef HAS_SCREEN
display_obj.tft.println(text_table4[48]); display_obj.tft.println(text_table4[48]);
#endif #endif
#else #elif defined(HAS_SD)
if (sd_obj.supported) { if (sd_obj.supported) {
#ifdef HAS_SCREEN #ifdef HAS_SCREEN
display_obj.tft.println(text_table4[28]); display_obj.tft.println(text_table4[28]);
@@ -823,6 +825,8 @@ void WiFiScan::RunInfo()
display_obj.tft.println(text_table4[31]); display_obj.tft.println(text_table4[31]);
#endif #endif
} }
#else
return;
#endif #endif
#ifdef HAS_BATTERY #ifdef HAS_BATTERY
@@ -848,8 +852,10 @@ void WiFiScan::RunInfo()
void WiFiScan::RunEspressifScan(uint8_t scan_mode, uint16_t color) { void WiFiScan::RunEspressifScan(uint8_t scan_mode, uint16_t color) {
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.open(); buffer_obj.open();
#else #elif defined(HAS_SD)
sd_obj.openCapture("espressif"); sd_obj.openCapture("espressif");
#else
return;
#endif #endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
@@ -901,8 +907,10 @@ void WiFiScan::RunPacketMonitor(uint8_t scan_mode, uint16_t color)
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.open(); buffer_obj.open();
#else #elif defined(HAS_SD)
sd_obj.openCapture("packet_monitor"); sd_obj.openCapture("packet_monitor");
#else
return;
#endif #endif
#ifdef HAS_ILI9341 #ifdef HAS_ILI9341
@@ -1020,8 +1028,10 @@ void WiFiScan::RunEapolScan(uint8_t scan_mode, uint16_t color)
#else #else
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.open(); buffer_obj.open();
#else #elif defined(HAS_SD)
sd_obj.openCapture("eapol"); sd_obj.openCapture("eapol");
#else
return;
#endif #endif
#ifdef HAS_SCREEN #ifdef HAS_SCREEN
@@ -1119,8 +1129,10 @@ void WiFiScan::RunPwnScan(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.open(); buffer_obj.open();
#else #elif defined(HAS_SD)
sd_obj.openCapture("pwnagotchi"); sd_obj.openCapture("pwnagotchi");
#else
return;
#endif #endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
@@ -1165,8 +1177,10 @@ void WiFiScan::RunBeaconScan(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.open(); buffer_obj.open();
#else #elif defined(HAS_SD)
sd_obj.openCapture("beacon"); sd_obj.openCapture("beacon");
#else
return;
#endif #endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
@@ -1210,8 +1224,10 @@ void WiFiScan::RunStationScan(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.open(); buffer_obj.open();
#else #elif defined(HAS_SD)
sd_obj.openCapture("station"); sd_obj.openCapture("station");
#else
return;
#endif #endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
@@ -1255,9 +1271,11 @@ void WiFiScan::RunRawScan(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.open(); buffer_obj.open();
#else #elif defined(HAS_SD)
if (scan_mode != WIFI_SCAN_SIG_STREN) if (scan_mode != WIFI_SCAN_SIG_STREN)
sd_obj.openCapture("raw"); sd_obj.openCapture("raw");
#else
return;
#endif #endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
@@ -1304,8 +1322,10 @@ void WiFiScan::RunDeauthScan(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.open(); buffer_obj.open();
#else #elif defined(HAS_SD)
sd_obj.openCapture("deauth"); sd_obj.openCapture("deauth");
#else
return;
#endif #endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
@@ -1351,8 +1371,10 @@ void WiFiScan::RunProbeScan(uint8_t scan_mode, uint16_t color)
{ {
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.open(); buffer_obj.open();
#else #elif defined(HAS_SD)
sd_obj.openCapture("probe"); sd_obj.openCapture("probe");
#else
return;
#endif #endif
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
@@ -3209,8 +3231,10 @@ void WiFiScan::addPacket(wifi_promiscuous_pkt_t *snifferPacket, int len) {
if (save_packet) { if (save_packet) {
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.addPacket(snifferPacket->payload, len); buffer_obj.addPacket(snifferPacket->payload, len);
#else #elif defined(HAS_SD)
sd_obj.addPacket(snifferPacket->payload, len); sd_obj.addPacket(snifferPacket->payload, len);
#else
return;
#endif #endif
} }
} }

View File

@@ -38,11 +38,9 @@
#include "Assets.h" #include "Assets.h"
#ifdef MARAUDER_FLIPPER #ifdef MARAUDER_FLIPPER
#include "flipperLED.h" #include "flipperLED.h"
#endif #elif defined(XIAO_ESP32_S3)
#ifdef XIAO_ESP32_S3
#include "xiaoLED.h" #include "xiaoLED.h"
#endif #else
#ifndef MARAUDER_FLIPPER || XIAO_ESP32_S3
#include "LedInterface.h" #include "LedInterface.h"
#endif #endif
//#include "MenuFunctions.h" //#include "MenuFunctions.h"

View File

@@ -116,7 +116,6 @@ CommandLine cli_obj;
#endif #endif
const String PROGMEM version_number = MARAUDER_VERSION; const String PROGMEM version_number = MARAUDER_VERSION;
const String PROGMEM board_target = MARAUDER_TARGET;
#ifdef HAS_NEOPIXEL_LED #ifdef HAS_NEOPIXEL_LED
Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixels, PIN, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel strip = Adafruit_NeoPixel(Pixels, PIN, NEO_GRB + NEO_KHZ800);
@@ -267,7 +266,7 @@ void setup()
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj = Buffer(); buffer_obj = Buffer();
#else #elif defined(HAS_SD)
// Do some SD stuff // Do some SD stuff
if(sd_obj.initSD()) { if(sd_obj.initSD()) {
#ifdef HAS_SCREEN #ifdef HAS_SCREEN
@@ -281,6 +280,8 @@ void setup()
display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK); display_obj.tft.setTextColor(TFT_CYAN, TFT_BLACK);
#endif #endif
} }
#else
return;
#endif #endif
#ifdef HAS_BATTERY #ifdef HAS_BATTERY
@@ -374,8 +375,10 @@ void loop()
#ifdef WRITE_PACKETS_SERIAL #ifdef WRITE_PACKETS_SERIAL
buffer_obj.forceSaveSerial(); buffer_obj.forceSaveSerial();
#else #elif defined(HAS_SD)
sd_obj.main(); sd_obj.main();
#else
return;
#endif #endif
#ifdef HAS_BATTERY #ifdef HAS_BATTERY