From 215b9cbd3d1316887674b92268610c8f63a5caaf Mon Sep 17 00:00:00 2001 From: mickeyl Date: Thu, 08 May 2003 09:12:24 +0000 Subject: add fine tuning of parsing process - the semantics is not yet set in stone however... --- (limited to 'noncore/net/wellenreiter/gui') diff --git a/noncore/net/wellenreiter/gui/configbase.ui b/noncore/net/wellenreiter/gui/configbase.ui index 7504ebc..422826a 100644 --- a/noncore/net/wellenreiter/gui/configbase.ui +++ b/noncore/net/wellenreiter/gui/configbase.ui @@ -11,8 +11,8 @@ 0 0 - 209 - 287 + 261 + 280 @@ -95,21 +95,6 @@ Driver: - - QCheckBox - - name - hopChannels - - - text - Hop Channels - - - checked - true - - QCheckBox @@ -121,42 +106,7 @@ Use additional PRISM header - - QSpinBox - - name - hopInterval - - - enabled - true - - - suffix - ms - - - maxValue - 2000 - - - minValue - 100 - - - lineStep - 100 - - - value - 1000 - - - whatsThis - Choose the channel hop interval. - - - + QGroupBox name @@ -420,17 +370,6 @@ Choose the type of driver used for sniffing. - - QLabel - - name - TextLabel1 - - - text - every - - name @@ -452,6 +391,78 @@ + + QLabel + + name + TextLabel1 + + + text + every + + + + QCheckBox + + name + hopChannels + + + text + Hop Channels + + + checked + true + + + + QSpinBox + + name + hopInterval + + + enabled + true + + + suffix + ms + + + maxValue + 2000 + + + minValue + 100 + + + lineStep + 100 + + + value + 1000 + + + whatsThis + Choose the channel hop interval. + + + + QCheckBox + + name + adaptiveHopping + + + text + Use Adaptive(TM) Hop Scheme + + @@ -480,6 +491,10 @@ capturePackets + enabled + false + + sizePolicy 7 @@ -865,5 +880,11 @@ captureFileName setEnabled(bool) + + writeCaptureFile + toggled(bool) + capturePackets + setEnabled(bool) + diff --git a/noncore/net/wellenreiter/gui/graphwindow.cpp b/noncore/net/wellenreiter/gui/graphwindow.cpp index 7e1f378..b116b91 100644 --- a/noncore/net/wellenreiter/gui/graphwindow.cpp +++ b/noncore/net/wellenreiter/gui/graphwindow.cpp @@ -29,11 +29,25 @@ MFrequencySpectrum::MFrequencySpectrum( int channels, QWidget* parent, const cha _dirty[i] = true; } - // we draw everything alone + // we draw everything on our own setBackgroundMode( QWidget::NoBackground ); } +void MFrequencySpectrum::drawTopLine( QPainter* p, int x, int y, int width, const QColor& c ) +{ + p->setPen( c.light() ); + p->drawLine( x, y, x+width-1, y ); +} + + +void MFrequencySpectrum::drawBottomLine( QPainter* p, int x, int y, int width, const QColor& c ) +{ + p->setPen( c.dark() ); + p->drawLine( x, y, x+width-1, y ); +} + + void MFrequencySpectrum::drawLine( QPainter* p, int x, int y, int width, const QColor& c ) { p->setPen( c.light() ); @@ -61,12 +75,13 @@ void MFrequencySpectrum::drawBar( QPainter* p, int x, int y, int width, int heig int h = (h2-h1)*i/maxheight + h1; int s = (s2-s1)*i/maxheight + s1; int v = (v2-v1)*i/maxheight + v1; - drawLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) ); + if ( i == 0 ) + drawBottomLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) ); + else if ( i == height-1 ) + drawTopLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) ); + else + drawLine( p, x, y-i, width, QColor( h,s,v, QColor::Hsv ) ); } - - /*for ( int i = height; i < maxheight; ++i ) - drawLine( p, x, y-i, width, QColor( 47, 68, 76 ) );*/ - } @@ -98,6 +113,22 @@ void MFrequencySpectrum::paintEvent( QPaintEvent* e ) } +void MFrequencySpectrum::mousePressEvent( QMouseEvent* e ) +{ + int xmargin = 5; + int ymargin = 2; + int y = size().height() - 2 * ymargin; + int x = 0; + int width = ( size().width() - 2 * xmargin ) / _channels; + + QPoint pos = e->pos(); + int channel = ( pos.x()-xmargin ) / width; + int height = 100 - ( pos.y()-ymargin )*100/y; + if ( channel < 15 ) _values[channel] = height; + +} + + Legende::Legende( int channels, QWidget* parent, const char* name, WFlags f ) :QFrame( parent, name, f ), _channels( channels ) { @@ -125,10 +156,7 @@ MGraphWindow::MGraphWindow( QWidget* parent, const char* name, WFlags f ) { spectrum = new MFrequencySpectrum( 14, this ); legende = new Legende( 14, this ); - startTimer( 50 ); //FIXME: tweak - - //testGraph(); - + startTimer( 50 ); }; @@ -146,7 +174,7 @@ void MGraphWindow::timerEvent( QTimerEvent* e ) { for ( int i = 0; i < 14; i++ ) { - spectrum->decrease( i, 1 ); //TODO: make this customizable? + spectrum->decrease( i, 1 ); } spectrum->repaint(); } diff --git a/noncore/net/wellenreiter/gui/graphwindow.h b/noncore/net/wellenreiter/gui/graphwindow.h index 4050065..1e00ae7 100644 --- a/noncore/net/wellenreiter/gui/graphwindow.h +++ b/noncore/net/wellenreiter/gui/graphwindow.h @@ -43,8 +43,11 @@ class MFrequencySpectrum : public QWidget protected: virtual void paintEvent( QPaintEvent* ); + virtual void mousePressEvent( QMouseEvent* ); void drawLine( QPainter* p, int x, int y, int width, const QColor& c ); + void drawTopLine( QPainter* p, int x, int y, int width, const QColor& c ); + void drawBottomLine( QPainter* p, int x, int y, int width, const QColor& c ); void MFrequencySpectrum::drawBar( QPainter* p, int x, int y, int width, int height, int maxheight ); private: diff --git a/noncore/net/wellenreiter/gui/protolistview.cpp b/noncore/net/wellenreiter/gui/protolistview.cpp index d4b0dfe..f4b45d0 100644 --- a/noncore/net/wellenreiter/gui/protolistview.cpp +++ b/noncore/net/wellenreiter/gui/protolistview.cpp @@ -28,7 +28,7 @@ ProtocolListView::ProtocolListView( QWidget* parent, const char* name, WFlags f ) :QScrollView( parent, name, f ) { - actions = ( QString( "parsePackets" ) == QString( name ) ); + parse = ( QString( "parsePackets" ) == QString( name ) ); setMargins( 3, 3, 0, 0 ); viewport()->setBackgroundColor( QCheckBox(0).palette().color( QPalette::Active, QColorGroup::Background ) ); @@ -40,7 +40,7 @@ ProtocolListView::ProtocolListView( QWidget* parent, const char* name, WFlags f QHBox* hbox = new QHBox( vbox ); hbox->setSpacing( 40 ); new QLabel( tr( "Protocol Family" ), hbox ); - if ( actions ) new QLabel( tr( "Perform Action" ), hbox ); + new QLabel( tr( "Perform Action" ), hbox ); QFrame* frame = new QFrame( vbox ); frame->setFrameStyle( QFrame::HLine + QFrame::Sunken ); @@ -78,13 +78,14 @@ void ProtocolListView::addProtocol( const QString& name ) QHBox* hbox = new QHBox( vbox ); new QCheckBox( name, hbox, (const char*) name ); - if ( actions ) + if ( parse ) { QComboBox* combo = new QComboBox( hbox, (const char*) name ); #ifdef QWS combo->setFixedWidth( 75 ); #endif combo->insertItem( "Ignore" ); + combo->insertItem( "Discard!" ); combo->insertItem( "TouchSound" ); combo->insertItem( "AlarmSound" ); combo->insertItem( "KeySound" ); @@ -93,6 +94,15 @@ void ProtocolListView::addProtocol( const QString& name ) combo->insertItem( "LogMessage" ); combo->insertItem( "MessageBox" ); } + else + { + QComboBox* combo = new QComboBox( hbox, (const char*) name ); + #ifdef QWS + combo->setFixedWidth( 75 ); + #endif + combo->insertItem( "Pass" ); + combo->insertItem( "Discard!" ); + } } @@ -105,9 +115,6 @@ bool ProtocolListView::isProtocolChecked( const QString& name ) QString ProtocolListView::protocolAction( const QString& name ) { - //QObject * child ( const char * objName, const char * inheritsClass = 0, - // bool recursiveSearch = TRUE ) - QComboBox* combo = (QComboBox*) child( (const char*) name, "QComboBox" ); if ( combo ) return combo->currentText(); diff --git a/noncore/net/wellenreiter/gui/protolistview.h b/noncore/net/wellenreiter/gui/protolistview.h index 166b648..8b460cb 100644 --- a/noncore/net/wellenreiter/gui/protolistview.h +++ b/noncore/net/wellenreiter/gui/protolistview.h @@ -18,8 +18,6 @@ #include #include -//#include -//#include class QCheckBox; class QComboBox; @@ -39,7 +37,7 @@ class ProtocolListView : public QScrollView private: QVBox* vbox; - bool actions; + bool parse; }; diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp index edf7dcf..965f6b0 100644 --- a/noncore/net/wellenreiter/gui/wellenreiter.cpp +++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp @@ -151,12 +151,12 @@ void Wellenreiter::handleNotification( OPacket* p ) if ( configwindow->parsePackets->isProtocolChecked( name ) ) { QString action = configwindow->parsePackets->protocolAction( name ); - qDebug( "action for '%s' seems to be '%s'", (const char*) name, (const char*) action ); + qDebug( "parsePacket-action for '%s' seems to be '%s'", (const char*) name, (const char*) action ); doAction( action, name, p ); } else { - qDebug( "protocol '%s' not checked.", (const char*) name ); + qDebug( "protocol '%s' not checked in parsePackets.", (const char*) name ); } ++it; } @@ -271,9 +271,47 @@ void Wellenreiter::handleData( OPacket* p, OWaveLanDataPacket* data ) } -QObject* childIfToParse( OPacket* p, const QString& protocol ) +QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol ) { - //FIXME: Implement + if ( configwindow->parsePackets->isProtocolChecked( protocol ) ) + if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" ) + return 0; + + return p->child( protocol ); +} + + +bool Wellenreiter::checkDumpPacket( OPacket* p ) +{ + // go through all child packets and see if one is inside the child hierarchy for p + // if so, do what the user requested (protocolAction), e.g. pass or discard + if ( !configwindow->writeCaptureFile->isOn() ) + return false; + + QObjectList* l = p->queryList(); + QObjectListIt it( *l ); + QObject* o; + + while ( (o = it.current()) != 0 ) + { + QString name = it.current()->name(); + if ( configwindow->capturePackets->isProtocolChecked( name ) ) + { + QString action = configwindow->capturePackets->protocolAction( name ); + qDebug( "capturePackets-action for '%s' seems to be '%s'", (const char*) name, (const char*) action ); + if ( action == "Discard" ) + { + logwindow->log( QString().sprintf( "(i) dump-discarding of '%s' packet requested.", (const char*) name ) ); + return false; + } + } + else + { + qDebug( "protocol '%s' not checked in capturePackets.", (const char*) name ); + } + ++it; + } + return true; } @@ -281,10 +319,13 @@ void Wellenreiter::receivePacket( OPacket* p ) { hexWindow()->log( p->dump( 8 ) ); - handleNotification( p ); + if ( checkDumpPacket( p ) ) + { + pcap->dump( p ); + } // check if we received a beacon frame - OWaveLanManagementPacket* beacon = static_cast( p->child( "802.11 Management" ) ); + OWaveLanManagementPacket* beacon = static_cast( childIfToParse( p, "802.11 Management" ) ); if ( beacon && beacon->managementType() == "Beacon" ) { handleBeacon( p, beacon ); @@ -294,11 +335,14 @@ void Wellenreiter::receivePacket( OPacket* p ) //TODO: WEP check here // check for a data frame - OWaveLanDataPacket* data = static_cast( p->child( "802.11 Data" ) ); + OWaveLanDataPacket* data = static_cast( childIfToParse( p, "802.11 Data" ) ); if ( data ) { handleData( p, data ); } + + handleNotification( p ); + } @@ -394,13 +438,15 @@ void Wellenreiter::startClicked() // open pcap and start sniffing if ( cardtype != DEVTYPE_FILE ) { - if ( configwindow->writeCaptureFile->isEnabled() ) //FIXME: bug!? + pcap->open( interface ); + + if ( configwindow->writeCaptureFile->isOn() ) { QString dumpname( configwindow->captureFileName->text() ); dumpname.append( '-' ); dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) ); dumpname.append( ".wellenreiter" ); - pcap->open( interface, dumpname ); + pcap->openDumpFile( dumpname ); } else { diff --git a/noncore/net/wellenreiter/gui/wellenreiter.h b/noncore/net/wellenreiter/gui/wellenreiter.h index e227a24..37e692c 100644 --- a/noncore/net/wellenreiter/gui/wellenreiter.h +++ b/noncore/net/wellenreiter/gui/wellenreiter.h @@ -69,7 +69,8 @@ class Wellenreiter : public WellenreiterBase { void handleNotification( OPacket* p ); void doAction( const QString& action, const QString& protocol, OPacket* p ); QObject* childIfToParse( OPacket* p, const QString& protocol ); - + bool checkDumpPacket( OPacket* p ); + private: #ifdef QWS OSystem _system; // Opie Operating System identifier -- cgit v0.9.0.2