aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/frontend/qt_sdl/LocalMP.cpp49
-rw-r--r--src/vsr.h8
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;
}
}
diff --git a/src/vsr.h b/src/vsr.h
index 1db1f22..ec57f47 100644
--- a/src/vsr.h
+++ b/src/vsr.h
@@ -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