13
0
Fork 1

big enhancements on dectshark

git-svn-id: https://dedected.org/svn/trunk@81 8d8ab74c-27aa-4a3d-9bde-523a2bc1f624
This commit is contained in:
krater 2009-02-25 18:21:00 +00:00
parent 9daae2ceaa
commit 4f5fd297ca
16 changed files with 1028 additions and 362 deletions

View File

@ -1,6 +1,6 @@
CPPFLAGS=-Wall -O2 -I../.. -lcurses -lpthread
dectshark: dectshark.o gui.o foundinfo.o
g++ $(CPPFLAGS) dectshark.cpp gui.cpp foundinfo.cpp -o dectshark
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
clean:
rm *.o dectshark
rm *.o *~ dectshark

View File

@ -1,23 +1,73 @@
#if !defined(CONFIG_H)
#define CONFIG_H
#define DEV "/dev/coa"
//TODO: make threadsafe
#define SNIFFMODE_SCAN 0
#define SNIFFMODE_SYNC 1
#define SCANMODE_FP 0
#define SCANMODE_PP 1
#define SYNC_SEARCH 0
#define SYNC_FOUND 1
#define SYNC_SYNCED 2
struct sharkconfig
{
bool hop;
int mode;
int channel;
int scanmode;
int sniffmode;
int wantchannel;
unsigned char rfpi[5];
int sync;
int stop;
int restart;
};
class config
{
public:
config() {cfg.hop=1;}
~config() {}
config() {cfg.hop=1;cfg.channel=0;cfg.scanmode=0;cfg.stop=0;cfg.restart=0;}
~config() {}
void sethop(bool hop) {cfg.hop=hop;}
bool hop() {;return cfg.hop;}
void sethop(bool hop) {cfg.hop=hop;}
bool hop() {return cfg.hop;}
void setchannel(int chn) {cfg.channel=chn;}
int getchannel() {return cfg.channel;}
void channelinc() {cfg.channel=(cfg.channel+1)%10;}
void setscanmode(int mode) {cfg.scanmode=mode;cfg.sniffmode=SNIFFMODE_SCAN;}
void setsyncmode() {cfg.sniffmode=SNIFFMODE_SYNC;}
int getscanmode() {return cfg.scanmode;}
int getsniffmode() {return cfg.sniffmode;}
void setrfpi(unsigned char *rfpi) {memcpy(cfg.rfpi,rfpi,5);}
unsigned char *getrfpi() {return (unsigned char*)&cfg.rfpi;}
void setwantchannel(int chn) {cfg.wantchannel=chn;}
int getwantchannel() {return cfg.wantchannel;}
void setsync(int sync) {cfg.sync=sync;}
int getsync() {return cfg.sync;}
void restart() {cfg.restart=1;}
void restarted() {cfg.restart=0;}
int shouldrestart() {return cfg.restart;}
void stop() {cfg.stop=1;}
void stopped() {cfg.stop=0;}
int shouldstop() {return cfg.stop;};
private:
sharkconfig cfg;

View File

@ -1,51 +1,17 @@
#include <ncurses.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "com_on_air_user.h"
#include "foundinfo.h"
#include "dectshark.h"
#include "gui.h"
#include "config.h"
#define DEV "/dev/coa"
void *pcap_threadmain(void *threadid);
void *show_threadmain(void *threadid);
config cfg;
print_gui gui;
found_dects founds;
print_gui gui;
pthread_t pcap_thread;
pthread_t show_thread;
void set_channel(int dev,int channel);
int scan_type = 0;
int main(int argc, char *argv[])
{
int ch;
if ( argc > 1 ) {
if ( strcmp( argv[1], "--help" ) == 0 ) {
if ( argc > 1 )
{
if ( strcmp( argv[1], "--help" ) == 0 )
{
printf("Usage: %s [--fp|--pp]\n", argv[0]);
printf(" --fp Scan Fixed Part (DECT Basestation)\n");
printf(" --pp Scan Portable Part (DECT Handset)\n");
@ -54,19 +20,18 @@ int main(int argc, char *argv[])
printf("\n");
return 0;
}
if ( strcmp( argv[1], "--fp" ) == 0 ) {
scan_type = 0;
if ( strcmp( argv[1], "--fp" ) == 0 )
{
cfg.setscanmode(SCANMODE_FP);
}
if ( strcmp( argv[1], "--pp" ) == 0 ) {
scan_type = 1;
if ( strcmp( argv[1], "--pp" ) == 0 )
{
cfg.setscanmode(SCANMODE_PP);
}
}
pthread_create(&pcap_thread, NULL, pcap_threadmain, (void *)0);
// pthread_create(&show_thread, NULL, show_threadmain, (void *)0);
// while(1);
gui.work();
return 0;
@ -76,79 +41,4 @@ int main(int argc, char *argv[])
void *pcap_threadmain(void *threadid)
{
int tid;
int chn=0,channeltime=0;
int dev;
dev = open(DEV, O_RDONLY);
if (dev<0){
printf("couldn't open(\"%s\"): %s\n", DEV, strerror(errno));
}
uint16_t val;
if ( scan_type == 0 ) {
val = COA_MODE_SNIFF|COA_SUBMODE_SNIFF_SCANFP; // scan fixed part
} else {
val = COA_MODE_SNIFF|COA_SUBMODE_SNIFF_SCANPP; // scan portable part
}
if (ioctl(dev, COA_IOCTL_MODE, &val)){
printf("couldn't set sniff mode\n");
}
while(0xDEC + 't') // ;)
{
dect_found found;
unsigned char buf[7];
while (7 == (read(dev, buf, 7)))
{
memcpy(found.RFPI,buf+2,5);
found.channel=buf[0];
found.type=DECT_FOUND_FP;
found.rssi=buf[1];
founds.AddDect(found);
}
usleep(100000);
channeltime++;
if(channeltime == 5)
{
if(cfg.hop())
{
chn++;
chn %= 10;
set_channel(dev,chn);
}
channeltime = 0;
}
}
pthread_exit(NULL);
}
void set_channel(int dev,int channel)
{
if (ioctl(dev, COA_IOCTL_CHAN, &channel)){
printf("couldn't set channel\n");
}
gui.setchannel(channel);
}
void *show_threadmain(void *threadid)
{
gui.work();
pthread_exit(NULL);
}

View File

@ -0,0 +1,26 @@
#include <ncurses.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/select.h>
#include <ncurses.h>
#include <unistd.h>
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>
#include <string.h>
#include <errno.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/select.h>
#include <fcntl.h>
#include "com_on_air_user.h"
#include "config.h"
extern config cfg;

View File

@ -88,7 +88,7 @@ dect_listentry found_dects::GetListEntry(unsigned int entry)
}
}
int found_dects::GetListLength()
unsigned int found_dects::GetListLength()
{
int tlen;

View File

@ -1,10 +1,8 @@
#include <pthread.h>
#include <malloc.h>
#include <string.h>
#if !defined(FOUNDINFO_H)
#define FOUNDINFO_H
#include "dectshark.h"
#define DECT_FOUND_FP 0
#define DECT_FOUND_PP 1
@ -41,12 +39,12 @@ public:
void AddDect(dect_found found);
void ClearList();
dect_listentry GetListEntry(unsigned int entry);
int GetListLength();
unsigned int GetListLength();
protected:
int listlen;
unsigned int listlen;
dect_listentry *list;
pthread_mutex_t mutex;

View File

@ -2,248 +2,101 @@
print_gui::print_gui()
{
selected=startpos=displaypos=0;
}
print_gui::~print_gui()
{
delete gui;
endwin();
}
void print_gui::up()
{
pthread_mutex_lock(&mutex);
if(founds.GetListLength()<=(SH-7))
{
if(displaypos>0)
{
displaypos--;
selected--;
}
}
else
{
if(displaypos>0)
{
displaypos--;
selected--;
}
else if(startpos>0)
{
selected--;
startpos--;
}
}
pthread_mutex_unlock(&mutex);
}
void print_gui::down()
{
pthread_mutex_lock(&mutex);
if(founds.GetListLength()<=(SH-7))
{
if(displaypos<(founds.GetListLength()-1))
{
displaypos++;
selected++;
}
}
else
{
if(displaypos<(SH-8))
{
displaypos++;
selected++;
}
else if(startpos<=(founds.GetListLength()-1-(SH-7)))
{
selected++;
startpos++;
}
}
pthread_mutex_unlock(&mutex);
}
int print_gui::getselected()
{
pthread_mutex_lock(&mutex);
return selected;
pthread_mutex_unlock(&mutex);
}
void print_gui::work()
{
InitCurses();
initcurses();
while(1)
{
{
if(kbhit_wait(300000))
{
int ch=wgetch(mainwin);
int key=wgetch(gui->getmainwin());
switch(ch)
key=gui->keypressed(key);
switch(key)
{
case KEY_LEFT:
break;
case KEY_RIGHT:
break;
case KEY_UP:
up();
break;
case KEY_DOWN:
down();
break;
case 'l':
//SetLockMode();
break;
case 'o':
//SetOverviewMode();
break;
case 'h':
cfg.sethop(!cfg.hop());
case 'q':
cfg.stop();
goto end;
break;
}
}
pthread_mutex_lock(&mutex);
gui->tick();
PrintFounds(startpos,SH-7,selected);
PrintStatus(startpos,founds.GetListLength(),channel);
if(cfg.shouldrestart())
{
while(cfg.shouldstop())
usleep(100000);
pthread_mutex_unlock(&mutex);
delete gui;
cfg.setchannel(cfg.getwantchannel());
cfg.restarted();
switch(cfg.getsniffmode())
{
case SNIFFMODE_SCAN:
break;
case SNIFFMODE_SYNC:
gui=new syncmode_gui(SW,SH);
break;
}
}
}
end: return;
}
void print_gui::InitCurses()
void print_gui::initcurses()
{
initscr();
start_color();
init_pair(1,COLOR_GREEN,COLOR_BLACK);
init_pair(2,COLOR_YELLOW,COLOR_BLACK);
init_pair(3,COLOR_WHITE,COLOR_BLACK);
init_pair(4,COLOR_RED,COLOR_BLACK);
init_pair(5,COLOR_YELLOW,COLOR_GREEN);
init_pair(6,COLOR_RED,COLOR_GREEN);
mainwin = newwin(SH-4,SW-20,0,0);
statuswin = newwin(SH,20,0,SW-20);
msgwin = newwin(4,SW-20,SH-4,0);
// cbreak();
noecho();
keypad(mainwin,TRUE);
wbkgdset(mainwin,(COLOR_PAIR(1)|A_BOLD));
wbkgdset(statuswin,(COLOR_PAIR(1)|A_BOLD));
wbkgdset(msgwin,(COLOR_PAIR(1)|A_BOLD));
box(mainwin,0,0);
wattron(mainwin,COLOR_PAIR(3));
mvwprintw(mainwin,1,1,"RFPI");
mvwprintw(mainwin,1,13,"Ch");
mvwprintw(mainwin,1,31,"FP-Pkt");
mvwprintw(mainwin,1,53,"RSSI");
wnoutrefresh(mainwin);
box(statuswin,0,0);
wattron(statuswin,COLOR_PAIR(2));
mvwprintw(statuswin,1,1,"Station Packets:");
mvwprintw(statuswin,4,1,"Phone Packets:");
mvwprintw(statuswin,SH-3,1,"Channel:");
wnoutrefresh(statuswin);
box(msgwin,0,0);
wnoutrefresh(msgwin);
doupdate();
gui=new scanmode_gui(SW,SH);
}
void print_gui::RefreshScreen()
void print_gui::refreshscreen()
{
wnoutrefresh(mainwin);
wnoutrefresh(statuswin);
wnoutrefresh(msgwin);
doupdate();
gui->refreshscreen();
}
void print_gui::PrintFounds(int start,int num,int selected)
{
int i,y;
y=2;
for(i=start;i<(start+num);i++)
{
if(i==selected)
wattron(mainwin,COLOR_PAIR(5));
else
wattron(mainwin,COLOR_PAIR(2));
dect_listentry entry=founds.GetListEntry(i);
if(entry.valid)
{
mvwprintw(mainwin,y,1,"%.2x%.2x%.2x%.2x%.2x ",entry.RFPI[0],entry.RFPI[1],entry.RFPI[2],entry.RFPI[3],entry.RFPI[4]);
mvwprintw(mainwin,y,13,"%.2i %12u %12u",entry.channel,entry.fppackets,entry.rssi);
y++;
}
}
wrefresh(mainwin);
}
void print_gui::PrintStatus(unsigned int PP,unsigned int FP,int channel)
{
wattron(statuswin,COLOR_PAIR(3));
mvwprintw(statuswin,2,1,"%17u",FP);
mvwprintw(statuswin,5,1,"%17u",PP);
mvwprintw(statuswin,SH-2,16,"%2u",channel);
wrefresh(statuswin);
}
void print_gui::setchannel(int chn)
{
pthread_mutex_lock(&mutex);
channel=chn;
pthread_mutex_unlock(&mutex);
}
int print_gui::kbhit_wait(int time)
{
struct timeval tv;
fd_set read_fd;
struct timeval tv;
fd_set read_fd;
tv.tv_sec=0;
tv.tv_usec=time;
tv.tv_sec=0;
tv.tv_usec=time;
FD_ZERO(&read_fd);
FD_SET(0,&read_fd);
FD_ZERO(&read_fd);
FD_SET(0,&read_fd);
if(select(1,&read_fd,NULL,NULL,&tv)==-1)
return 0;
if(select(1,&read_fd,NULL,NULL,&tv)==-1)
return 0;
if(FD_ISSET(0,&read_fd))
return 1;
if(FD_ISSET(0,&read_fd))
return 1;
return 0;
return 0;
}

View File

@ -1,20 +1,14 @@
#include <ncurses.h>
#include <unistd.h>
#include <pthread.h>
#include <sys/select.h>
#include "foundinfo.h"
#include "config.h"
#if !defined(GUI_H)
#define GUI_H
#include "dectshark.h"
#include "mode_gui.h"
#include "scanmode_gui.h"
#include "syncmode_gui.h"
#define SW 80
#define SH 25
extern found_dects founds;
extern config cfg;
class print_gui
{
@ -24,29 +18,16 @@ public:
void work();
void up();
void down();
int getselected();
void setchannel(int channel);
protected:
void InitCurses();
void RefreshScreen();
void PrintFounds(int start,int num,int selected);
void PrintStatus(unsigned int PP,unsigned int FP,int channel);
void initcurses();
void refreshscreen();
int kbhit_wait(int time);
pthread_mutex_t mutex;
int selected,startpos,displaypos;
mode_gui *gui;
WINDOW *mainwin;
WINDOW *statuswin;
WINDOW *msgwin;
int channel;
};
#endif

View File

@ -0,0 +1,24 @@
#if !defined(MODE_GUI_H)
#define MODE_GUI_H
#include "dectshark.h"
class mode_gui
{
public:
mode_gui() {printf("ARRRR1!\n");}
mode_gui(int x,int y) {printf("ARRRR2!\n");}
virtual ~mode_gui() {printf("ARRRR3!\n");}
virtual WINDOW *getmainwin() {printf("ARRRR4!\n");return NULL;}
virtual void tick() {printf("ARRRR5!\n");}
virtual unsigned int keypressed(int key) {printf("ARRRR6!\n");return 0;}
virtual void refreshscreen() {printf("ARRRR7!\n");}
protected:
};
#endif

View File

@ -0,0 +1,70 @@
#include "packetparser.h"
#define DECT_A_TA 0xe0
#define DECT_A_Q1 0x10
#define DECT_A_BA 0x0e
#define DECT_A_Q2 0x01
#define DECT_Q_TYPE 0x80
#define DECT_N_TYPE 0x60
#define DECT_P_TYPE 0xe0
packetparser::packetparser()
{
int i;
for(i=0;i<24;i++)
{
syncinfo.slot[i].channel=0;
syncinfo.slot[i].afields=0;
syncinfo.slot[i].bfields=0;
syncinfo.slot[i].berrors=0;
syncinfo.slot[i].lastrssi=0;
}
}
packetparser::~packetparser()
{
}
void packetparser::parsepacket(sniffed_packet packet)
{
unsigned int slot=packet.slot;
if(slot<24)
{
syncinfo.slot[slot].afields++;
if(bfieldactive(packet))
syncinfo.slot[slot].bfields++;
syncinfo.slot[slot].channel=packet.channel;
syncinfo.slot[slot].lastrssi=packet.rssi;
processrfpi(packet);
}
}
slotinfo_str packetparser::getslotinfo(unsigned int slot)
{
return syncinfo.slot[slot];
}
int packetparser::bfieldactive(sniffed_packet packet)
{
if ((packet.data[5] & 0x0e) != 0x0e)
return 1;
return 0;
}
void packetparser::processrfpi(sniffed_packet packet)
{
/*
if ((packet.data[5] & DECT_A_TA) == DECT_N_TYPE)
return 1;
return 0;*/
}

View File

@ -0,0 +1,54 @@
#if !defined(PACKETPARSER_H)
#define PACKETPARSER_H
#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
{
unsigned int channel;
unsigned int afields;
unsigned int bfields;
unsigned int berrors;
unsigned int lastrssi;
unsigned char rfpi[5][5];
};
struct syncinfo_str
{
slotinfo_str slot[24];
};
class packetparser
{
public:
packetparser();
~packetparser();
void parsepacket(sniffed_packet packet);
slotinfo_str getslotinfo(unsigned int slot);
protected:
syncinfo_str syncinfo;
int bfieldactive(sniffed_packet packet);
void processrfpi(sniffed_packet packet);
};
#endif

View File

@ -0,0 +1,302 @@
#include "scanmode_gui.h"
found_dects founds;
scanmode_gui::scanmode_gui(int x,int y)
{
selected=startpos=displaypos=0;
scrw=x;
scrh=y;
mainwin = newwin(scrh,scrw-20,0,0);
statuswin = newwin(scrh,20,0,scrw-20);
noecho();
keypad(mainwin,TRUE);
wbkgdset(mainwin,(COLOR_PAIR(1)|A_BOLD));
wbkgdset(statuswin,(COLOR_PAIR(1)|A_BOLD));
box(mainwin,0,0);
wattron(mainwin,COLOR_PAIR(3));
mvwprintw(mainwin,1,1,"RFPI");
mvwprintw(mainwin,1,13,"Ch");
mvwprintw(mainwin,1,34,"Pkt");
mvwprintw(mainwin,1,53,"RSSI");
wnoutrefresh(mainwin);
box(statuswin,0,0);
wattron(statuswin,COLOR_PAIR(2));
mvwprintw(statuswin,1,1,"Founds:");
mvwprintw(statuswin,4,1,"Packets:");
mvwprintw(statuswin,scrh-3,1,"Channel:");
wnoutrefresh(statuswin);
doupdate();
pthread_create(&workthread, NULL, scanthread, (void *)0);
}
scanmode_gui::~scanmode_gui()
{
}
WINDOW *scanmode_gui::getmainwin()
{
return mainwin;
}
unsigned int scanmode_gui::keypressed(int key)
{
if((key>'0')&&(key<'9'))
{
cfg.stop();
cfg.setwantchannel(key-0x30);
cfg.restart();
return 0;
}
switch(key)
{
case KEY_LEFT:
break;
case KEY_RIGHT:
break;
case KEY_UP:
up();
break;
case KEY_DOWN:
down();
break;
case 'h':
cfg.sethop(!cfg.hop());
break;
case 's':
{
dect_listentry entry=founds.GetListEntry(selected);
if(entry.valid)
{
cfg.stop();
cfg.setrfpi(entry.RFPI);
cfg.setwantchannel(entry.channel);
cfg.setsyncmode();
cfg.restart();
return 0;
}
}
break;
default:
return key;
}
return 0;
}
void scanmode_gui::tick()
{
pthread_mutex_lock(&mutex);
printfounds();
printstatus(startpos,founds.GetListLength());
pthread_mutex_unlock(&mutex);
}
void scanmode_gui::refreshscreen()
{
wnoutrefresh(mainwin);
wnoutrefresh(statuswin);
doupdate();
}
void scanmode_gui::printfounds()
{
int i,y;
y=2;
for(i=startpos;i<(startpos+scrh-3);i++)
{
dect_listentry entry=founds.GetListEntry(i);
if(i==selected)
{
if(entry.RFPI[4]&0x07)
wattron(mainwin,COLOR_PAIR(6));
else
wattron(mainwin,COLOR_PAIR(5));
}
else
{
if(entry.RFPI[4]&0x07)
wattron(mainwin,COLOR_PAIR(4));
else
wattron(mainwin,COLOR_PAIR(2));
}
if(entry.valid)
{
mvwprintw(mainwin,y,1,"%.2x%.2x%.2x%.2x%.2x ",entry.RFPI[0],entry.RFPI[1],entry.RFPI[2],entry.RFPI[3],entry.RFPI[4]);
mvwprintw(mainwin,y,13,"%.2i %12u %12u",entry.channel,entry.fppackets,entry.rssi);
y++;
}
}
wrefresh(mainwin);
}
void scanmode_gui::printstatus(unsigned int PP,unsigned int FP)
{
wattron(statuswin,COLOR_PAIR(3));
mvwprintw(statuswin,2,1,"%17u",FP);
mvwprintw(statuswin,5,1,"%17u",PP);
mvwprintw(statuswin,scrh-2,16,"%2u",cfg.getchannel());
wrefresh(statuswin);
}
void scanmode_gui::up()
{
pthread_mutex_lock(&mutex);
if(founds.GetListLength()<=(scrh-3))
{
if(displaypos>0)
{
displaypos--;
selected--;
}
}
else
{
if(displaypos>0)
{
displaypos--;
selected--;
}
else if(startpos>0)
{
selected--;
startpos--;
}
}
pthread_mutex_unlock(&mutex);
}
void scanmode_gui::down()
{
pthread_mutex_lock(&mutex);
if(founds.GetListLength()<=(scrh-3))
{
if(displaypos<(founds.GetListLength()-1))
{
displaypos++;
selected++;
}
}
else
{
if(displaypos<(scrh-4))
{
displaypos++;
selected++;
}
else if(startpos<=(founds.GetListLength()-1-(scrh-3)))
{
selected++;
startpos++;
}
}
pthread_mutex_unlock(&mutex);
}
/**********************************
**** worker thread ****
*********************************/
void *scanthread(void *threadid)
{
int channeltime=0;
int dev;
dev = open(DEV, O_RDONLY);
if (dev<0)
{
printf("couldn't open(\"%s\"): %s\n", DEV, strerror(errno));
}
uint16_t val;
if (cfg.getscanmode() == SCANMODE_FP)
{
val = COA_MODE_SNIFF|COA_SUBMODE_SNIFF_SCANFP; // scan fixed part
}
else
{
val = COA_MODE_SNIFF|COA_SUBMODE_SNIFF_SCANPP; // scan portable part
}
if (ioctl(dev, COA_IOCTL_MODE, &val))
{
printf("couldn't set sniff mode\n");
}
while(0xDEC + 'T') // ;)
{
dect_found found;
unsigned char buf[7];
while (7 == (read(dev, buf, 7)))
{
memcpy(found.RFPI,buf+2,5);
found.channel=buf[0];
found.type=DECT_FOUND_FP;
found.rssi=buf[1];
founds.AddDect(found);
}
usleep(100000);
if(cfg.shouldstop())
{
close(dev);
cfg.stopped();
pthread_exit(NULL);
}
channeltime++;
if(channeltime == 5)
{
if(cfg.hop())
{
cfg.channelinc();
int channel=cfg.getchannel();
if (ioctl(dev, COA_IOCTL_CHAN, &channel))
printf("couldn't set channel\n");
}
channeltime = 0;
}
}
}

View File

@ -0,0 +1,44 @@
#if !defined(SCANMODE_GUI_H)
#define SCANMODE_GUI_H
#include "dectshark.h"
#include "foundinfo.h"
#include "mode_gui.h"
extern config cfg;
void *scanthread(void *threadid);
class scanmode_gui : public mode_gui
{
public:
scanmode_gui(int x,int y);
~scanmode_gui();
WINDOW *getmainwin();
void tick();
unsigned int keypressed(int key);
void refreshscreen();
protected:
void printfounds();
void printstatus(unsigned int PP,unsigned int FP);
void up();
void down();
pthread_mutex_t mutex;
unsigned int selected,startpos,displaypos,scrw,scrh;
WINDOW *mainwin;
WINDOW *statuswin;
WINDOW *msgwin;
pthread_t workthread;
};
#endif

View File

@ -0,0 +1,25 @@
--------------------------------------------------------------------------------
|Slot Ch FP PP || |
| A B Err R A B Err R || |
| 0 01 523 23 0 22 0 0 0 0 || |
| 1 05 0 0 0 9 0 0 0 0 || |
| 2 00 0 0 0 0 0 0 0 0 || |
| 3 00 0 0 0 0 0 0 0 0 || |
| 4 00 0 0 0 0 0 0 0 0 || |
| 5 09 0 0 0 0 0 0 0 0 || |
| 6 00 0 0 0 0 0 0 0 0 || |
| 7 00 0 0 0 0 0 0 0 0 || |
| 8 00 0 0 0 0 0 0 0 0 || |
| 9 00 0 0 0 0 0 0 0 0 || |
|10 00 0 0 0 0 0 0 0 0 || |
|11 00 0 0 0 0 0 0 0 0 || |
|12 00 0 0 0 0 0 0 0 0 || |
| || |
| || |
| || |
| || |
------------------------------------------------------------| |
|-----------------------------------------------------------| |
| | |
| | |
--------------------------------------------------------------------------------

View File

@ -0,0 +1,307 @@
#include "syncmode_gui.h"
packetparser pparser;
syncmode_gui::syncmode_gui(int x,int y)
{
int i;
selx=sely=0;
scrw=x;
scrh=y;
mainwin = newwin(scrh-4,scrw-20,0,0);
statuswin = newwin(scrh,20,0,scrw-20);
msgwin = newwin(4,scrw-20,scrh-4,0);
noecho();
wbkgdset(mainwin,(COLOR_PAIR(1)|A_BOLD));
wbkgdset(statuswin,(COLOR_PAIR(1)|A_BOLD));
wbkgdset(msgwin,(COLOR_PAIR(1)|A_BOLD));
box(mainwin,0,0);
wattron(mainwin,COLOR_PAIR(3));
mvwprintw(mainwin,1,1,"Slot");
mvwprintw(mainwin,1,6,"Ch");
mvwprintw(mainwin,1,22,"FP");
mvwprintw(mainwin,1,46,"PP");
wattron(mainwin,COLOR_PAIR(2));
for(i=0;i<25;i+=24)
{
mvwprintw(mainwin,2,15+i,"A");
mvwprintw(mainwin,2,22+i,"B");
mvwprintw(mainwin,2,25+i,"Err");
mvwprintw(mainwin,2,31+i,"R");
}
wnoutrefresh(mainwin);
box(statuswin,0,0);
wattron(statuswin,COLOR_PAIR(2));
mvwprintw(statuswin,1,1,"Founds:");
mvwprintw(statuswin,4,1,"Packets:");
mvwprintw(statuswin,scrh-3,1,"Channel:");
wnoutrefresh(statuswin);
box(msgwin,0,0);
wnoutrefresh(msgwin);
//starting search
cfg.setsync(SYNC_SEARCH);
popupwin = newwin(3,42,(scrh/2)-2,(scrw/2)-21);
keypad(popupwin,TRUE);
wbkgdset(popupwin,(COLOR_PAIR(4)|A_BOLD));
box(popupwin,0,0);
wattron(popupwin,COLOR_PAIR(2));
unsigned char *RFPI=cfg.getrfpi();
mvwprintw(popupwin,1,1," Trying to sync to RFPI %.2x%.2x%.2x%.2x%.2x ... ",RFPI[0],RFPI[1],RFPI[2],RFPI[3],RFPI[4]);
wnoutrefresh(popupwin);
doupdate();
pthread_create(&workthread, NULL, syncthread, (void *)0);
}
syncmode_gui::~syncmode_gui()
{
delwin(mainwin);
delwin(statuswin);
delwin(msgwin);
}
WINDOW *syncmode_gui::getmainwin()
{
return mainwin;
}
unsigned int syncmode_gui::keypressed(int key)
{
if(cfg.getsync()==SYNC_SYNCED)
{
switch(key)
{
case KEY_LEFT:
selx=0;
break;
case KEY_RIGHT:
selx=1;
break;
case KEY_UP:
if(sely>0)
sely--;
break;
case KEY_DOWN:
if(sely<11)
sely++;
break;
default:
return key;
}
printfounds();
}
else
{
return key;
}
return 0;
}
void syncmode_gui::tick()
{
pthread_mutex_lock(&mutex);
switch(cfg.getsync())
{
case SYNC_SYNCED:
printfounds();
printstatus(selx,sely);
break;
case SYNC_FOUND:
delwin(popupwin);
wbkgdset(mainwin,(COLOR_PAIR(1)|A_BOLD));
wbkgdset(statuswin,(COLOR_PAIR(1)|A_BOLD));
wbkgdset(msgwin,(COLOR_PAIR(1)|A_BOLD));
box(mainwin,0,0);
box(statuswin,0,0);
box(msgwin,0,0);
keypad(mainwin,TRUE);
doupdate();
cfg.setsync(SYNC_SYNCED);
break;
case SYNC_SEARCH:
break;
}
pthread_mutex_unlock(&mutex);
}
void syncmode_gui::refreshscreen()
{
if(cfg.getsync()==SYNC_SYNCED)
{
wnoutrefresh(mainwin);
wnoutrefresh(statuswin);
wnoutrefresh(msgwin);
}
else
{
wnoutrefresh(popupwin);
}
doupdate();
}
void syncmode_gui::printfounds()
{
int i;
slotinfo_str slotinfo;
wattron(mainwin,COLOR_PAIR(1));
for(i=0;i<12;i++)
{
slotinfo=pparser.getslotinfo(i);
wattron(mainwin,COLOR_PAIR(1));
mvwprintw(mainwin,i+3,1,"%2u %.2u",i,slotinfo.channel);
if((sely==i)&&(selx==0))
wattron(mainwin,COLOR_PAIR(5));
else
wattron(mainwin,COLOR_PAIR(1));
mvwprintw(mainwin,i+3,8,"%8u%7u%5u %2u",slotinfo.afields,slotinfo.bfields,slotinfo.berrors,slotinfo.lastrssi);
slotinfo=pparser.getslotinfo(i+12);
if((sely==i)&&(selx==1))
wattron(mainwin,COLOR_PAIR(5));
else
wattron(mainwin,COLOR_PAIR(1));
mvwprintw(mainwin,i+3,32,"%8u%7u%5u %2u",slotinfo.afields,slotinfo.bfields,slotinfo.berrors,slotinfo.lastrssi);
}
wrefresh(mainwin);
}
void syncmode_gui::printstatus(unsigned int PP,unsigned int FP)
{
wattron(statuswin,COLOR_PAIR(3));
mvwprintw(statuswin,2,1,"%17u",FP);
mvwprintw(statuswin,5,1,"%17u",PP);
mvwprintw(statuswin,scrh-2,16,"%2u",cfg.getchannel());
wrefresh(statuswin);
}
/**********************************
**** worker thread ****
*********************************/
void process_dect_data(int dev);
void *syncthread(void *threadid)
{
fd_set rfd;
fd_set efd;
struct timeval tv;
int ret;
int dev;
dev = open(DEV, O_RDONLY);
if (dev<0)
printf("couldn't open(\"%s\"): %s\n", DEV, strerror(errno));
uint16_t val;
val=COA_MODE_SNIFF|COA_SUBMODE_SNIFF_SYNC;
if (ioctl(dev, COA_IOCTL_MODE, &val))
printf("couldn't set mode()\n");
unsigned char *RFPI=cfg.getrfpi();
if(ioctl(dev, COA_IOCTL_SETRFPI, RFPI))
printf("couldn't set rfpi\n");
int channel=cfg.getchannel();
if (ioctl(dev, COA_IOCTL_CHAN, &channel))
printf("couldn't set channel\n");
while (0xDEC + 'T')
{
tv.tv_sec = 1;
tv.tv_usec = 0;
FD_ZERO(&rfd);
FD_ZERO(&efd);
FD_SET(dev, &rfd);
FD_SET(dev, &efd);
ret = select(dev+1, &rfd, NULL, &efd, &tv);
if (ret < 0)
printf("select() read error\n");
if (FD_ISSET(dev, &efd))
printf("select() exception\n");
if (FD_ISSET(dev, &rfd))
{
if(cfg.getsync()==SYNC_SEARCH)
cfg.setsync(SYNC_FOUND);
process_dect_data(dev);
}
}
}
void process_dect_data(int dev)
{
sniffed_packet packet;
while ( sizeof(packet) == read(dev, &packet, sizeof(packet)))
{
pparser.parsepacket(packet);
}
}

View File

@ -0,0 +1,42 @@
#if !defined(SYNCMODE_GUI_H)
#define SYNCMODE_GUI_H
#include "dectshark.h"
#include "mode_gui.h"
#include "packetparser.h"
void *syncthread(void *threadid);
class syncmode_gui: public mode_gui
{
public:
syncmode_gui(int x,int y);
~syncmode_gui();
WINDOW *getmainwin();
void tick();
unsigned int keypressed(int key);
void refreshscreen();
protected:
void printfounds();
void printstatus(unsigned int PP,unsigned int FP);
pthread_mutex_t mutex;
unsigned int selx,sely,scrw,scrh;
WINDOW *mainwin;
WINDOW *statuswin;
WINDOW *msgwin;
WINDOW *popupwin;
pthread_t workthread;
};
#endif