Skip to content

Commit

Permalink
Fixed malformed packed on sniffer pcap
Browse files Browse the repository at this point in the history
  • Loading branch information
pr3y committed Aug 4, 2024
1 parent 423caa5 commit 2d92e43
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions src/modules/wifi/sniffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,13 +77,19 @@ bool openFile(FS &Fs){
/* will be executed on every packet the ESP32 gets while beeing in promiscuous mode */
void sniffer(void *buf, wifi_promiscuous_pkt_type_t type){

if(fileOpen){
if(fileOpen){
wifi_promiscuous_pkt_t* pkt = (wifi_promiscuous_pkt_t*)buf;
wifi_pkt_rx_ctrl_t ctrl = (wifi_pkt_rx_ctrl_t)pkt->rx_ctrl;

uint32_t timestamp = now(); //current timestamp
uint32_t microseconds = (unsigned int)(micros() - millis() * 1000); //micro seconds offset (0 - 999)
newPacketSD(timestamp, microseconds, ctrl.sig_len, pkt->payload); //write packet to file
uint32_t timestamp = now(); // current timestamp
uint32_t microseconds = (unsigned int)(micros() - millis() * 1000); // microseconds offset (0 - 999)

uint32_t len = ctrl.sig_len;
if(type == WIFI_PKT_MGMT) {
len -= 4; // Need to remove last 4 bits (for checksum) or packet gets malformed # https://github.com/espressif/esp-idf/issues/886
}

newPacketSD(timestamp, microseconds, len, pkt->payload); // write packet to file

}

Expand Down Expand Up @@ -227,4 +233,4 @@ void sniffer_loop(FS &Fs) {
}
Exit:
delay(1); // just to Exit Work
}
}

0 comments on commit 2d92e43

Please sign in to comment.