diff options
author | lonkaars <loek@pipeframe.xyz> | 2024-05-03 17:25:09 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2024-05-03 17:25:09 +0200 |
commit | 30de08bbf3be9011b56f9dc3d2322f492d6ec5c8 (patch) | |
tree | b46a05b19a57f5285878c5223dc87253de95f280 | |
parent | dcc3a747360382857b1fbae05a06061f44e64033 (diff) |
dump all packets again
-rw-r--r-- | src/frontend/qt_sdl/LocalMP.cpp | 49 | ||||
-rw-r--r-- | src/vsr.h | 8 |
2 files changed, 36 insertions, 21 deletions
diff --git a/src/frontend/qt_sdl/LocalMP.cpp b/src/frontend/qt_sdl/LocalMP.cpp index 32f08c8..906f4d4 100644 --- a/src/frontend/qt_sdl/LocalMP.cpp +++ b/src/frontend/qt_sdl/LocalMP.cpp @@ -42,6 +42,10 @@ #include <stdint.h> #include "../../vsr.h" +// utility: osdAddMessage +#include "Window.h" +extern MainWindow* mainWindow; + #ifdef VSR_DUMP_MESSAGES #include <pcap/pcap.h> #include <vector> @@ -49,9 +53,7 @@ pcap_dumper_t* dumper; #endif #ifdef VSR_MESSAGE_FIDDLING -#include "Window.h" #include <time.h> -extern MainWindow* mainWindow; bool fiddle = false; #endif @@ -249,13 +251,6 @@ void SemReset(int num) bool Init() { -#ifdef VSR_DUMP_MESSAGES - pcap_t* handle = pcap_open_dead(DLT_USER0, 1 << 16); - char filename[80]; - snprintf(filename, 79, "melon_%lu.pcap", time(NULL)); - dumper = pcap_dump_open(handle, filename); -#endif - MPQueue = new QSharedMemory("melonNIFI"); if (!MPQueue->attach()) @@ -312,6 +307,14 @@ bool Init() RecvTimeout = 25; +#ifdef VSR_DUMP_MESSAGES + pcap_t* handle = pcap_open_dead(DLT_USER0, 1 << 16); + char filename[80]; + snprintf(filename, 79, "melon_%lu_instance_%d.pcap", time(NULL), InstanceID); + mainWindow->osdAddMessage(0xffffff, "started dumping to %s", filename); + dumper = pcap_dump_open(handle, filename); +#endif + return true; } @@ -404,14 +407,6 @@ void FIFORead(int fifo, void* buf, int len) if (fifo == 0) PacketReadOffset = offset; else ReplyReadOffset = offset; - - // WIP: temporarily capture sent packets only, capture is done on both - // sides anyways, so who cares - // struct pcap_pkthdr p; - // p.len = len; - // p.caplen = len; - // gettimeofday(&p.ts, NULL); - // pcap_dump((u_char*) dumper, &p, (u_char*) buf); } void FIFOWrite(int fifo, void* buf, int len) @@ -555,6 +550,10 @@ int SendPacketGeneric(u32 type, u8* packet, int len, u64 timestamp) int RecvPacketGeneric(u8* packet, bool block, u64* timestamp) { +#ifdef VSR_DUMP_MESSAGES + std::vector<uint8_t> buf; +#endif + if (!MPQueue) return 0; for (;;) { @@ -590,10 +589,18 @@ int RecvPacketGeneric(u8* packet, bool block, u64* timestamp) continue; } +#ifdef VSR_DUMP_MESSAGES + buf.insert(buf.end(), (uint8_t*) &pktheader, (uint8_t*) &pktheader + sizeof(pktheader)); +#endif + if (pktheader.Length) { FIFORead(0, packet, pktheader.Length); +#ifdef VSR_DUMP_MESSAGES + buf.insert(buf.end(), (uint8_t*) packet, (uint8_t*) packet + pktheader.Length); +#endif + if (pktheader.Type == 1) LastHostID = pktheader.SenderID; } @@ -601,6 +608,14 @@ int RecvPacketGeneric(u8* packet, bool block, u64* timestamp) if (timestamp) *timestamp = pktheader.Timestamp; MPQueue->unlock(); +#ifdef VSR_DUMP_MESSAGES + struct pcap_pkthdr p; + p.len = buf.size(); + p.caplen = buf.size(); + gettimeofday(&p.ts, NULL); + pcap_dump((u_char*) dumper, &p, buf.data()); +#endif + return pktheader.Length; } } @@ -2,12 +2,12 @@ /** This is a central file for contolling VSR-specific experiments */ -// corrupt instance=0's messages after 20 seconds -#define VSR_MESSAGE_FIDDLING - // dump all sent Ni-Fi packets // #define VSR_DUMP_MESSAGES // add "Inject" menu bar item -// #define VSR_INJECTION +#define VSR_INJECTION + +// add "Fiddle" menu bar item +#define VSR_MESSAGE_FIDDLING |