13
0
Fork 1

dectshark now saves pcaps

git-svn-id: https://dedected.org/svn/trunk@87 8d8ab74c-27aa-4a3d-9bde-523a2bc1f624
This commit is contained in:
krater 2009-03-29 03:45:05 +00:00
parent 4819d4375e
commit 7f1c82655b
12 changed files with 192 additions and 24 deletions

View File

@ -494,9 +494,10 @@ void sniffer_sniff_sync_irq(struct coa_info *dev, int irq)
if ( (SC14421_READ(1+memofs) & 0xc0) == 0xc0) /* Checksum ok */
{
unsigned char bfok = ((SC14421_READ(1+memofs) & 0x03) == 0x03)<<7; /* BField Checksum ok */
struct sniffed_packet packet;
packet.rssi = SC14421_READ(memofs);
//packet.bfok = ((SC14421_READ(1+memofs) & 0x03) == 0x03);
packet.channel = config->slottable[a].channel;
packet.slot = a;
memcpy(packet.data,fppacket,5);
@ -523,9 +524,9 @@ void sniffer_sniff_sync_irq(struct coa_info *dev, int irq)
/* if (dev->open) */
{
if(config->framenumber)
packet.framenumber = config->framenumber-1;
packet.frameflags = (config->framenumber-1)|bfok;
else
packet.framenumber = 7;
packet.frameflags = 7|bfok;
packet.timestamp = dev->irq_timestamp;
ret = kfifo_put(dev->rx_fifo, (unsigned char*) &packet, sizeof(struct sniffed_packet));
@ -593,10 +594,10 @@ void sniffer_sniff_sync_irq(struct coa_info *dev, int irq)
if ( (SC14421_READ(1+memofs) & 0xc0) == 0xc0) /* Checksum ok */
{
struct sniffed_packet packet;
unsigned char bfok = ((SC14421_READ(1+memofs) & 0x03) == 0x03)<<7; /* BField Checksum ok */
struct sniffed_packet packet;
packet.rssi = SC14421_READ(memofs);
//packet.bfok = ((SC14421_READ(1+memofs) & 0x03) == 0x03);
packet.channel = config->slottable[a].channel;
packet.slot = a;
memcpy(packet.data, pppacket, 5);
@ -610,9 +611,9 @@ void sniffer_sniff_sync_irq(struct coa_info *dev, int irq)
/* if (dev->open) */
{
if(config->framenumber)
packet.framenumber = config->framenumber-1;
packet.frameflags = (config->framenumber-1)|bfok;
else
packet.framenumber = 7;
packet.frameflags = 7|bfok;
packet.timestamp = dev->irq_timestamp;
ret = kfifo_put(

View File

@ -56,8 +56,7 @@ struct sniffed_packet
unsigned char rssi;
unsigned char channel;
unsigned char slot;
unsigned char framenumber;
// unsigned char bfok;
unsigned char frameflags;
struct timespec timestamp;
unsigned char data[53];
};

View File

@ -858,7 +858,7 @@ void process_dect_data()
pcap_packet[15] = cli.packet.channel;
pcap_packet[16] = 0x00;
pcap_packet[17] = cli.packet.slot;
pcap_packet[18] = cli.packet.framenumber;
pcap_packet[18] = cli.packet.frameflags&0x0f;
pcap_packet[19] = cli.packet.rssi;
memcpy(&pcap_packet[20], cli.packet.data, 53);

View File

@ -41,8 +41,7 @@ struct sniffed_packet
unsigned char rssi;
unsigned char channel;
unsigned char slot;
unsigned char framenumber;
// unsigned char bfok;
unsigned char frameflags;
struct timespec timestamp;
unsigned char data[53];
};

View File

@ -1,6 +1,6 @@
CPPFLAGS=-Wall -O2 -I../..
dectshark: dectshark.o gui.o foundinfo.o scanmode_gui.o syncmode_gui.o packetparser.o
g++ $(CPPFLAGS) dectshark.o gui.o scanmode_gui.o syncmode_gui.o foundinfo.o packetparser.o -o dectshark -lcurses -lpthread
dectshark: dectshark.o gui.o foundinfo.o scanmode_gui.o syncmode_gui.o packetparser.o packetsaver.o
g++ $(CPPFLAGS) dectshark.o gui.o scanmode_gui.o syncmode_gui.o foundinfo.o packetparser.o packetsaver.o -o dectshark -lcurses -lpthread -lpcap
clean:
rm *.o *~ dectshark

View File

@ -1,3 +1,6 @@
#if !defined(DECTSHARK_GUI_H)
#define DECTSHARK_GUI_H
#include <ncurses.h>
#include <unistd.h>
#include <pthread.h>
@ -18,6 +21,7 @@
#include <sys/stat.h>
#include <sys/select.h>
#include <fcntl.h>
#include <pcap.h>
#include "com_on_air_user.h"
@ -34,3 +38,17 @@ void printnil(char *,...);
#else
#define LOG printnil
#endif
struct sniffed_packet
{
unsigned char rssi;
unsigned char channel;
unsigned char slot;
unsigned char frameflags;
struct timespec timestamp;
unsigned char data[53];
};
#endif

View File

@ -36,8 +36,13 @@ void packetparser::parsepacket(sniffed_packet packet)
syncinfo.slot[slot].afields++;
if(bfieldactive(packet))
{
syncinfo.slot[slot].bfields++;
if(!bfieldok(packet))
syncinfo.slot[slot].berrors++;
}
syncinfo.slot[slot].channel=packet.channel;
syncinfo.slot[slot].lastrssi=packet.rssi;
@ -58,6 +63,14 @@ int packetparser::bfieldactive(sniffed_packet packet)
return 0;
}
int packetparser::bfieldok(sniffed_packet packet)
{
if(packet.frameflags&0xf0)
return 1;
return 0;
}
void packetparser::processrfpi(sniffed_packet packet)
{
/*

View File

@ -3,16 +3,6 @@
#include "dectshark.h"
struct sniffed_packet
{
unsigned char rssi;
unsigned char channel;
unsigned char slot;
unsigned char framenumber;
// unsigned char bfok;
struct timespec timestamp;
unsigned char data[53];
};
struct slotinfo_str
@ -45,6 +35,7 @@ protected:
syncinfo_str syncinfo;
int bfieldactive(sniffed_packet packet);
int bfieldok(sniffed_packet packet);
void processrfpi(sniffed_packet packet);
};

View File

@ -0,0 +1,102 @@
#include "packetsaver.h"
packetsaver::packetsaver()
{
pcap=NULL;
}
packetsaver::~packetsaver()
{
closefile();
}
int packetsaver::openfilerfpi(unsigned char *RFPI)
{
char fn[512];
char ftime[256];
time_t rawtime;
struct tm *timeinfo;
time (&rawtime);
timeinfo = localtime(&rawtime);
strftime(ftime, sizeof(ftime), "%Y-%m-%d_%H_%M_%S", timeinfo);
sprintf(fn, "dump_%s_RFPI_%.2x_%.2x_%.2x_%.2x_%.2x.pcap",ftime,
RFPI[0],RFPI[1],RFPI[2],RFPI[3],RFPI[4]);
LOG("### dumping to %s\n", fn);
return openfile(fn);
}
int packetsaver::openfile(char *fn)
{
pcap = pcap_open_dead(DLT_EN10MB, 74);
if (!pcap)
{
LOG("!!! couldn't pcap_open_dead(\"%s\")\n", fn);
return 0;
}
pcap_d = pcap_dump_open(pcap, fn);
if (!pcap_d)
{
LOG("!!! couldn't pcap_dump_open(\"%s\")\n", fn);
return 0;
}
return 1;
}
void packetsaver::closefile()
{
if (pcap)
{
pcap_dump_close(pcap_d);
pcap_close(pcap);
pcap_d = NULL;
pcap = NULL;
}
}
void packetsaver::savepacket(sniffed_packet packet)
{
struct pcap_pkthdr pcap_hdr;
int ret,length;
if(pcap_d)
{
if ((packet.data[5] & 0x0e) != 0x0e)
length = 74;
else
length = 33;
pcap_hdr.caplen = length;
pcap_hdr.len = length;
ret = gettimeofday(&pcap_hdr.ts, NULL);
if (ret)
{
LOG("!!! couldn't gettimeofday(): %s\n",
strerror(errno));
exit(1);
}
uint8_t pcap_packet[74];
memset(pcap_packet, 0, 74);
pcap_packet[12] = 0x23;
pcap_packet[13] = 0x23;
pcap_packet[14] = 0x00; /* decttype (receive) */
pcap_packet[15] = packet.channel;
pcap_packet[16] = 0x00;
pcap_packet[17] = packet.slot;
pcap_packet[18] = packet.frameflags&0x0f;
pcap_packet[19] = packet.rssi;
memcpy(&pcap_packet[20], packet.data, 53);
pcap_packet[73] = 0x00;
pcap_dump((u_char*)pcap_d, &pcap_hdr, pcap_packet);
}
}

View File

@ -0,0 +1,41 @@
#if !defined(PACKETSAVER_H)
#define PACKETSAVER_H
#include "dectshark.h"
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <sys/ioctl.h>
#include <time.h>
#include <limits.h>
#include <signal.h>
#include <ctype.h>
class packetsaver
{
public:
packetsaver();
~packetsaver();
int openfilerfpi(unsigned char *RFPI);
int openfile(char *fn);
void closefile();
void savepacket(sniffed_packet packet);
protected:
char errbuf[PCAP_ERRBUF_SIZE];
pcap_t *pcap;
pcap_dumper_t *pcap_d;
};
#endif

View File

@ -2,6 +2,7 @@
packetparser pparser;
packetsaver psaver;
@ -258,6 +259,7 @@ void *syncthread(void *threadid)
if (ioctl(dev, COA_IOCTL_CHAN, &channel))
printf("couldn't set channel\n");
psaver.openfilerfpi(RFPI);
while (0xDEC + 'T')
{
@ -298,6 +300,7 @@ void process_dect_data(int dev)
while ( sizeof(packet) == read(dev, &packet, sizeof(packet)))
{
psaver.savepacket(packet);
pparser.parsepacket(packet);
}
}

View File

@ -4,6 +4,7 @@
#include "dectshark.h"
#include "mode_gui.h"
#include "packetparser.h"
#include "packetsaver.h"
void *syncthread(void *threadid);