diff --git a/src/modules/wifi/PCAP.h b/src/modules/wifi/PCAP.h deleted file mode 100644 index d3d4f178..00000000 --- a/src/modules/wifi/PCAP.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - =========================================== - Copyright (c) 2017 Stefan Kremser - github.com/spacehuhn - =========================================== -*/ - -#ifndef PCAP_h -#define PCAP_h - -#include -#include "SPI.h" -#include "core/mykeyboard.h" -#include "sniffer.h" -#if defined(ESP32) - #include "FS.h" - //#include "SD.h" -#else - #include - #include -#endif - - -//String filename; -File file; - -/* converts a 32 bit integer into 4 bytes */ -void escape32(uint32_t n, uint8_t* buf){ - buf[0] = n; - buf[1] = n >> 8; - buf[2] = n >> 16; - buf[3] = n >> 24; -} - -/* converts a 16 bit integer into 2 bytes */ -void escape16(uint16_t n, uint8_t* buf){ - buf[0] = n; - buf[1] = n >> 8; -} - -/* writes a 32 bit integer onto the SD card */ -void filewrite_32(uint32_t n){ - uint8_t _buf[4]; - escape32(n, _buf); - file.write(_buf, 4); -} - -/* writes a 16 bit integer onto the SD card */ -void filewrite_16(uint16_t n){ - uint8_t _buf[2]; - escape16(n, _buf); - file.write(_buf, 2); -} - -/* writes a 32 bit integer to Serial */ -void serialwrite_32(uint32_t n){ - uint8_t _buf[4]; - escape32(n, _buf); - Serial.write(_buf, 4); -} - -/* writes a 16 bit integer to Serial */ -void serialwrite_16(uint16_t n){ - uint8_t _buf[2]; - escape16(n, _buf); - Serial.write(_buf, 2); -} - - -/* write packet to file */ -void newPacketSD(uint32_t ts_sec, uint32_t ts_usec, uint32_t len, uint8_t* buf){ - if(file){ - - uint32_t orig_len = len; - uint32_t incl_len = len; - //if(incl_len > snaplen) incl_len = snaplen; /* safty check that the packet isn't too big (I ran into problems here) */ - - filewrite_32(ts_sec); - filewrite_32(ts_usec); - filewrite_32(incl_len); - filewrite_32(orig_len); - - file.write(buf, incl_len); - } -} - - -/* write packet to Serial */ -void newPacketSerial(uint32_t ts_sec, uint32_t ts_usec, uint32_t len, uint8_t* buf){ - uint32_t orig_len = len; - uint32_t incl_len = len; - uint32_t snaplen = 2500; -#if defined(ESP32) - if(incl_len > snaplen) incl_len = snaplen; /* safty check that the packet isn't too big (I ran into problems with the ESP8266 here) */ -#endif - serialwrite_32(ts_sec); - serialwrite_32(ts_usec); - serialwrite_32(incl_len); - serialwrite_32(orig_len); - - Serial.write(buf, incl_len); -} - -class PCAP -{ - - void startSerial(); -#if defined(ESP32) - bool openFile(fs::FS &fs); - // bool removeFile(fs::FS &fs); -#else - bool openFile(SdFat &SD); - // bool removeFile(SdFat &SD); -#endif - - void flushFile(); - void closeFile(); - - void newPacketSerial(uint32_t ts_sec, uint32_t ts_usec, uint32_t len, uint8_t* buf); - - String filename = "/raw.cap"; - - uint32_t magic_number = 0xa1b2c3d4; - uint16_t version_major = 2; - uint16_t version_minor = 4; - uint32_t thiszone = 0; - uint32_t sigfigs = 0; - uint32_t snaplen = 2500; - uint32_t network = 105; - - private: - //File file; - - void escape32(uint32_t n, uint8_t* buf); - void escape16(uint16_t n, uint8_t* buf); - - void filewrite_16(uint16_t n); - void filewrite_32(uint32_t n); - - void serialwrite_16(uint16_t n); - void serialwrite_32(uint32_t n); -}; - -#endif - diff --git a/src/modules/wifi/sniffer.cpp b/src/modules/wifi/sniffer.cpp index a73d22ca..6f6972c9 100644 --- a/src/modules/wifi/sniffer.cpp +++ b/src/modules/wifi/sniffer.cpp @@ -5,7 +5,6 @@ =========================================== */ - /* include all necessary libraries */ #include "freertos/FreeRTOS.h" #include "esp_wifi.h" @@ -20,13 +19,18 @@ #include #include #include "FS.h" -#include "PCAP.h" #include "core/display.h" #include "core/globals.h" #include "core/sd_functions.h" #include "core/wifi_common.h" - - +#include "core/mykeyboard.h" +#if defined(ESP32) + #include "FS.h" + //#include "SD.h" +#else + #include + #include +#endif //===== SETTINGS =====// #define CHANNEL 1 @@ -46,36 +50,53 @@ bool fileOpen = false; bool isLittleFS = true; uint32_t package_counter = 0; -//PCAP pcap = PCAP(); -PCAP pcap; +File file; + String filename = "/BrucePCAP/" + (String)FILENAME + ".pcap"; //===== FUNCTIONS =====// -bool openFile(FS &Fs){ - uint32_t magic_number = 0xa1b2c3d4; - uint16_t version_major = 2; - uint16_t version_minor = 4; - uint32_t thiszone = 0; - uint32_t sigfigs = 0; - uint32_t snaplen = 2500; - uint32_t network = 105; - - file = Fs.open(filename, FILE_WRITE); - if(file) { - - filewrite_32(magic_number); - filewrite_16(version_major); - filewrite_16(version_minor); - filewrite_32(thiszone); - filewrite_32(sigfigs); - filewrite_32(snaplen); - filewrite_32(network); - return true; - } - return false; - } +/* write packet to file */ +void newPacketSD(uint32_t ts_sec, uint32_t ts_usec, uint32_t len, uint8_t* buf){ + if(file){ + + uint32_t orig_len = len; + uint32_t incl_len = len; + //if(incl_len > snaplen) incl_len = snaplen; /* safty check that the packet isn't too big (I ran into problems here) */ + + file.write((uint8_t*)&ts_sec, sizeof(ts_sec)); + file.write((uint8_t*)&ts_usec, sizeof(ts_usec)); + file.write((uint8_t*)&incl_len, sizeof(incl_len)); + file.write((uint8_t*)&orig_len, sizeof(orig_len)); + file.write(buf, incl_len); + } +} + +bool openFile(FS &Fs){ + uint32_t magic_number = 0xa1b2c3d4; + uint16_t version_major = 2; + uint16_t version_minor = 4; + uint32_t thiszone = 0; + uint32_t sigfigs = 0; + uint32_t snaplen = 2500; + uint32_t network = 105; + + file = Fs.open(filename, FILE_WRITE); + if(file) { + + file.write((uint8_t*)&magic_number, sizeof(magic_number)); + file.write((uint8_t*)&version_major, sizeof(version_major)); + file.write((uint8_t*)&version_minor, sizeof(version_minor)); + file.write((uint8_t*)&thiszone, sizeof(thiszone)); + file.write((uint8_t*)&sigfigs, sizeof(sigfigs)); + file.write((uint8_t*)&snaplen, sizeof(snaplen)); + file.write((uint8_t*)&network, sizeof(network)); + + return true; + } + return false; +} /* will be executed on every packet the ESP32 gets while beeing in promiscuous mode */ void sniffer(void *buf, wifi_promiscuous_pkt_type_t type){ @@ -147,7 +168,6 @@ void openFile2(FS &Fs){ counter = 0; } - //===== SETUP =====// void sniffer_setup() { FS* Fs; @@ -218,41 +238,32 @@ void sniffer_setup() { counter++; //add 1 to counter } - /* when counter > 30s interval */ - if(counter > SAVE_INTERVAL){ - //closeFile(); //save & close the file + if(checkEscPress()) { // Apertar o botão power dos sticks + delay(200); + file.flush(); //save file file.close(); fileOpen = false; //update flag Serial.println("=================="); Serial.println(filename + " saved!"); Serial.println("=================="); tft.setTextSize(FP); - tft.setTextColor(FGCOLOR, BGCOLOR); + tft.setTextColor(FGCOLOR, BGCOLOR); tft.setCursor(10, 30); - tft.println("RAW SNIFFER"); + tft.println("RAW SNIFFER"); tft.setCursor(10, 30); tft.println("RAW SNIFFER"); tft.setCursor(10, tft.getCursorY()+3); tft.println("Saved file into " + FileSys); displayRedStripe(filename, TFT_WHITE, FGCOLOR); - // tft.println(filename); - tft.setTextColor(FGCOLOR, BGCOLOR); - openFile2(*Fs); //open new file - } - // } - - if(checkEscPress()) { // Apertar o botão power dos sticks - tft.fillScreen(BGCOLOR); - file.flush(); //save file - file.close(); + delay(5000); returnToMenu=true; - break; - //goto Exit; + goto Exit; } } + Exit: esp_wifi_set_promiscuous(false); wifiDisconnect(); - delay(1); + delay(1); } diff --git a/src/modules/wifi/sniffer.h b/src/modules/wifi/sniffer.h index db96afb4..2a3b3aac 100644 --- a/src/modules/wifi/sniffer.h +++ b/src/modules/wifi/sniffer.h @@ -1,8 +1,9 @@ +void newPacketSD(uint32_t ts_sec, uint32_t ts_usec, uint32_t len, uint8_t* buf); -void sniffer_setup(); +bool openFile(FS &Fs); void openFile2(FS &Fs); -void sniffer(void *buf, wifi_promiscuous_pkt_type_t type); +void sniffer_setup(); -bool openFile(FS &Fs); \ No newline at end of file +void sniffer(void *buf, wifi_promiscuous_pkt_type_t type); \ No newline at end of file diff --git a/src/modules/wifi/wifi_atks.cpp b/src/modules/wifi/wifi_atks.cpp index ba722f1a..11c63f81 100644 --- a/src/modules/wifi/wifi_atks.cpp +++ b/src/modules/wifi/wifi_atks.cpp @@ -40,11 +40,23 @@ wifi_ap_record_t ap_record; void send_raw_frame(const uint8_t *frame_buffer, int size) { esp_wifi_80211_tx(WIFI_IF_AP, frame_buffer, size, false); - delayMicroseconds(100); + #if defined(STICK_C_PLUS2) || defined(STICK_C_PLUS) + delay(1); + #else + delayMicroseconds(100); + #endif esp_wifi_80211_tx(WIFI_IF_AP, frame_buffer, size, false); - delayMicroseconds(100); + #if defined(STICK_C_PLUS2) || defined(STICK_C_PLUS) + delay(1); + #else + delayMicroseconds(100); + #endif esp_wifi_80211_tx(WIFI_IF_AP, frame_buffer, size, false); - delayMicroseconds(100); + #if defined(STICK_C_PLUS2) || defined(STICK_C_PLUS) + delay(1); + #else + delayMicroseconds(100); + #endif } /***************************************************************************************