summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/packetview.cpp70
-rw-r--r--noncore/net/wellenreiter/gui/packetview.h21
-rw-r--r--noncore/net/wellenreiter/gui/wellenreiter.cpp5
3 files changed, 80 insertions, 16 deletions
diff --git a/noncore/net/wellenreiter/gui/packetview.cpp b/noncore/net/wellenreiter/gui/packetview.cpp
index e0e626c..3d3aa18 100644
--- a/noncore/net/wellenreiter/gui/packetview.cpp
+++ b/noncore/net/wellenreiter/gui/packetview.cpp
@@ -1,69 +1,121 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Wellenreiter II. 4** This file is part of Wellenreiter II.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16#include "packetview.h" 16#include "packetview.h"
17 17
18/* OPIE */ 18/* OPIE */
19#include <opie2/opcap.h> 19#include <opie2/opcap.h>
20#include <opie2/odebug.h>
21#include <opie2/olistview.h>
20 22
21/* QT */ 23/* QT */
22#include <qtextview.h> 24#include <qfont.h>
23#include <qspinbox.h>
24#include <qlabel.h> 25#include <qlabel.h>
25#include <qlayout.h> 26#include <qlayout.h>
26#include <qlist.h> 27#include <qlist.h>
28#include <qlistview.h>
29#include <qobjectlist.h>
30#include <qspinbox.h>
31#include <qtextview.h>
27 32
28using namespace Opie::Net; 33using namespace Opie::Net;
34using namespace Opie::Core;
35using namespace Opie::Ui;
36
29PacketView::PacketView( QWidget * parent, const char * name, WFlags f ) 37PacketView::PacketView( QWidget * parent, const char * name, WFlags f )
30 :QFrame( parent, name, f ) 38 :QFrame( parent, name, f )
31{ 39{
32 _number = new QSpinBox( this ); 40 _number = new QSpinBox( this );
33 _number->setPrefix( "Packet # " ); 41 _number->setPrefix( "Packet # " );
34 _label = new QLabel( this ); 42 _label = new QLabel( this );
35 _label->setText( "eth0 2004/03/08 - 00:00:21" ); 43 _label->setText( "eth0 2004/03/08 - 00:00:21" );
36 _list = new QLabel( this ); 44
45 _list = new OListView( this );
46 _list->addColumn( "#" );
47 _list->addColumn( "Packet Type" );
48 _list->setColumnAlignment( 0, Qt::AlignCenter );
49 _list->setColumnAlignment( 1, Qt::AlignLeft );
50 _list->setAllColumnsShowFocus( true );
51 _list->setFont( QFont( "Fixed", 8 ) );
52
37 _hex = new QTextView( this ); 53 _hex = new QTextView( this );
54 _hex->setFont( QFont( "Fixed", 8 ) );
38 55
39 QVBoxLayout* vb = new QVBoxLayout( this, 2, 2 ); 56 QVBoxLayout* vb = new QVBoxLayout( this, 2, 2 );
40 QHBoxLayout* hb = new QHBoxLayout( vb, 2 ); 57 QHBoxLayout* hb = new QHBoxLayout( vb, 2 );
41 hb->addWidget( _label ); 58 hb->addWidget( _label );
42 hb->addWidget( _number ); 59 hb->addWidget( _number );
43 vb->addWidget( _list ); 60 vb->addWidget( _list );
44 vb->addWidget( _hex ); 61 vb->addWidget( _hex );
45 62
46 _packets.setAutoDelete( true ); 63 _packets.setAutoDelete( true );
64
65 connect( _number, SIGNAL( valueChanged( int ) ), this, SLOT( showPacket( int ) ) );
66}
47 67
48 _list->setText( "<b>[ 802.11 [ LLC [ IP [ UDP [ DHCP ] ] ] ] ]</b>" ); 68void PacketView::add( const OPacket* p )
49};
50
51void PacketView::add( OPacket* p )
52{ 69{
53 _packets.append( p ); 70 _packets.append( p );
54}; 71 // Add Circular Buffer and check for number of elements here
72}
73
74void PacketView::showPacket( int number )
75{
76 _list->clear();
77 _hex->setText("");
78 const OPacket* p = _packets.at( number );
79
80 if ( p )
81 {
82 _doSubPackets( const_cast<QObjectList*>( p->children() ), 0 );
83 _doHexPacket( p );
84 }
85 else
86 {
87 qDebug( "D'oh! No packet!" );
88 }
89}
90
91void PacketView::_doSubPackets( QObjectList* l, int counter )
92{
93 if (!l) return;
94 QObject* o = l->first();
95 while ( o )
96 {
97 new OListViewItem( _list, QString::number( counter++ ), o->name() );
98 _doSubPackets( const_cast<QObjectList*>( o->children() ), counter );
99 o = l->next();
100 }
101}
102
103void PacketView::_doHexPacket( const OPacket* p )
104{
105 _hex->setText( p->dump( 16 ) );
106}
55 107
56const QString PacketView::getLog() const 108const QString PacketView::getLog() const
57{ 109{
58} 110}
59 111
60void PacketView::clear() 112void PacketView::clear()
61{ 113{
62 _packets.clear(); 114 _packets.clear();
63 _number->setMinValue( 0 ); 115 _number->setMinValue( 0 );
64 _number->setMaxValue( 0 ); 116 _number->setMaxValue( 0 );
65 _label->setText( "---" ); 117 _label->setText( "---" );
66 _list->setText( " <b>-- no Packet available --</b> " ); 118 _list->clear();
67 _hex->setText( " <i>-- no Packet available --</i> " ); 119 _hex->setText( " <i>-- no Packet available --</i> " );
68} 120}
69 121
diff --git a/noncore/net/wellenreiter/gui/packetview.h b/noncore/net/wellenreiter/gui/packetview.h
index 938aa19..affedab 100644
--- a/noncore/net/wellenreiter/gui/packetview.h
+++ b/noncore/net/wellenreiter/gui/packetview.h
@@ -1,49 +1,58 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Wellenreiter II. 4** This file is part of Wellenreiter II.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14**********************************************************************/ 14**********************************************************************/
15 15
16#ifndef PACKETVIEW_H 16#ifndef PACKETVIEW_H
17#define PACKETVIEW_H 17#define PACKETVIEW_H
18 18
19#include <qlist.h> 19#include <qlist.h>
20#include <qframe.h> 20#include <qframe.h>
21 21
22class QLabel;
22class QString; 23class QString;
23class QSpinBox; 24class QSpinBox;
24class QLabel;
25class QTextView; 25class QTextView;
26class QObjectList;
26namespace Opie {namespace Net {class OPacket;}} 27namespace Opie {namespace Net {class OPacket;}}
28namespace Opie {namespace Ui {class OListView;}}
27 29
28class PacketView: public QFrame 30class PacketView: public QFrame
29{ 31{
30 32 Q_OBJECT
33
31 public: 34 public:
32 PacketView( QWidget * parent = 0, const char * name = "PacketView", WFlags f = 0 ); 35 PacketView( QWidget * parent = 0, const char * name = "PacketView", WFlags f = 0 );
33 36
34 void add( Opie::Net::OPacket* p ); 37 void add( const Opie::Net::OPacket* p );
35 const QString getLog() const; 38 const QString getLog() const;
36 void clear(); 39 void clear();
40
41 public slots:
42 void showPacket( int number );
37 43
38 protected: 44 protected:
39
40 QSpinBox* _number; 45 QSpinBox* _number;
41 QLabel* _label; 46 QLabel* _label;
42 QLabel* _list; 47 Opie::Ui::OListView* _list;
43 QTextView* _hex; 48 QTextView* _hex;
44 QList<Opie::Net::OPacket> _packets; 49 QList<const Opie::Net::OPacket> _packets;
50
51 protected:
52 void _doSubPackets( QObjectList*, int );
53 void _doHexPacket( const Opie::Net::OPacket* );
45 54
46}; 55};
47 56
48#endif 57#endif
49 58
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp
index c8d77a7..fff7c35 100644
--- a/noncore/net/wellenreiter/gui/wellenreiter.cpp
+++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp
@@ -1,730 +1,733 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002-2004 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file may be distributed and/or modified under the terms of the 4** This file may be distributed and/or modified under the terms of the
5** GNU General Public License version 2 as published by the Free Software 5** GNU General Public License version 2 as published by the Free Software
6** Foundation and appearing in the file LICENSE.GPL included in the 6** Foundation and appearing in the file LICENSE.GPL included in the
7** packaging of this file. 7** packaging of this file.
8** 8**
9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 9** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 10** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11** 11**
12***********************************************************************/ 12***********************************************************************/
13 13
14// Local 14// Local
15 15
16#include "gps.h" 16#include "gps.h"
17#include "wellenreiter.h" 17#include "wellenreiter.h"
18#include "scanlist.h" 18#include "scanlist.h"
19#include "logwindow.h" 19#include "logwindow.h"
20#include "packetview.h" 20#include "packetview.h"
21#include "configwindow.h" 21#include "configwindow.h"
22#include "statwindow.h" 22#include "statwindow.h"
23#include "graphwindow.h" 23#include "graphwindow.h"
24#include "protolistview.h" 24#include "protolistview.h"
25 25
26// Opie 26// Opie
27 27
28#ifdef QWS 28#ifdef QWS
29#include <opie2/oapplication.h> 29#include <opie2/oapplication.h>
30#include <opie2/odevice.h> 30#include <opie2/odevice.h>
31#else 31#else
32#include <qapplication.h> 32#include <qapplication.h>
33#endif 33#endif
34#include <opie2/omanufacturerdb.h> 34#include <opie2/omanufacturerdb.h>
35#include <opie2/onetwork.h> 35#include <opie2/onetwork.h>
36#include <opie2/opcap.h> 36#include <opie2/opcap.h>
37#include <qpe/qcopenvelope_qws.h> 37#include <qpe/qcopenvelope_qws.h>
38using namespace Opie; 38using namespace Opie;
39 39
40// Qt 40// Qt
41 41
42#include <qcheckbox.h> 42#include <qcheckbox.h>
43#include <qcombobox.h> 43#include <qcombobox.h>
44#include <qdatetime.h> 44#include <qdatetime.h>
45#include <qpushbutton.h> 45#include <qpushbutton.h>
46#include <qlineedit.h> 46#include <qlineedit.h>
47#include <qmessagebox.h> 47#include <qmessagebox.h>
48#include <qobjectlist.h> 48#include <qobjectlist.h>
49#include <qregexp.h> 49#include <qregexp.h>
50#include <qspinbox.h> 50#include <qspinbox.h>
51#include <qtimer.h> 51#include <qtimer.h>
52#include <qtoolbutton.h> 52#include <qtoolbutton.h>
53#include <qmainwindow.h> 53#include <qmainwindow.h>
54 54
55// Standard 55// Standard
56 56
57#include <assert.h> 57#include <assert.h>
58#include <errno.h> 58#include <errno.h>
59#include <unistd.h> 59#include <unistd.h>
60#include <string.h> 60#include <string.h>
61#include <sys/types.h> 61#include <sys/types.h>
62#include <stdlib.h> 62#include <stdlib.h>
63 63
64using namespace Opie::Core; 64using namespace Opie::Core;
65using namespace Opie::Net; 65using namespace Opie::Net;
66using namespace Opie::Net; 66using namespace Opie::Net;
67using namespace Opie::Core; 67using namespace Opie::Core;
68using namespace Opie::Net; 68using namespace Opie::Net;
69using namespace Opie::Core; 69using namespace Opie::Core;
70Wellenreiter::Wellenreiter( QWidget* parent ) 70Wellenreiter::Wellenreiter( QWidget* parent )
71 : WellenreiterBase( parent, 0, 0 ), 71 : WellenreiterBase( parent, 0, 0 ),
72 sniffing( false ), iface( 0 ), configwindow( 0 ) 72 sniffing( false ), iface( 0 ), configwindow( 0 )
73{ 73{
74 74
75 logwindow->log( "(i) Wellenreiter has been started." ); 75 logwindow->log( "(i) Wellenreiter has been started." );
76 76
77 // 77 //
78 // detect operating system 78 // detect operating system
79 // 79 //
80 80
81 #ifdef QWS 81 #ifdef QWS
82 QString sys; 82 QString sys;
83 sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() ); 83 sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() );
84 _system = ODevice::inst()->system(); 84 _system = ODevice::inst()->system();
85 logwindow->log( sys ); 85 logwindow->log( sys );
86 #endif 86 #endif
87 87
88 netview->setColumnWidthMode( 1, QListView::Manual ); 88 netview->setColumnWidthMode( 1, QListView::Manual );
89 connect( netview, SIGNAL( joinNetwork(const QString&,const QString&,int,const QString&) ), 89 connect( netview, SIGNAL( joinNetwork(const QString&,const QString&,int,const QString&) ),
90 this, SLOT( joinNetwork(const QString&,const QString&,int,const QString&) ) ); 90 this, SLOT( joinNetwork(const QString&,const QString&,int,const QString&) ) );
91 pcap = new OPacketCapturer(); 91 pcap = new OPacketCapturer();
92 pcap->setAutoDelete( false );
92 93
93 gps = new GPS( this ); 94 gps = new GPS( this );
94 95
95 QTimer::singleShot( 1000, this, SLOT( initialTimer() ) ); 96 QTimer::singleShot( 1000, this, SLOT( initialTimer() ) );
96 97
97} 98}
98 99
99 100
100Wellenreiter::~Wellenreiter() 101Wellenreiter::~Wellenreiter()
101{ 102{
102 delete pcap; 103 delete pcap;
103} 104}
104 105
105 106
106void Wellenreiter::initialTimer() 107void Wellenreiter::initialTimer()
107{ 108{
108 qDebug( "Wellenreiter::preloading manufacturer database..." ); 109 qDebug( "Wellenreiter::preloading manufacturer database..." );
109 OManufacturerDB::instance(); 110 OManufacturerDB::instance();
110} 111}
111 112
112 113
113void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw ) 114void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw )
114{ 115{
115 configwindow = cw; 116 configwindow = cw;
116} 117}
117 118
118 119
119void Wellenreiter::channelHopped(int c) 120void Wellenreiter::channelHopped(int c)
120{ 121{
121 QString title = "Wellenreiter II -scan- ["; 122 QString title = "Wellenreiter II -scan- [";
122 QString left; 123 QString left;
123 if ( c > 1 ) left.fill( '.', c-1 ); 124 if ( c > 1 ) left.fill( '.', c-1 );
124 title.append( left ); 125 title.append( left );
125 title.append( '|' ); 126 title.append( '|' );
126 if ( c < iface->channels() ) 127 if ( c < iface->channels() )
127 { 128 {
128 QString right; 129 QString right;
129 right.fill( '.', iface->channels()-c ); 130 right.fill( '.', iface->channels()-c );
130 title.append( right ); 131 title.append( right );
131 } 132 }
132 title.append( "]" ); 133 title.append( "]" );
133 //title.append( QString().sprintf( " %02d", c ) ); 134 //title.append( QString().sprintf( " %02d", c ) );
134 assert( parent() ); 135 assert( parent() );
135 ( (QMainWindow*) parent() )->setCaption( title ); 136 ( (QMainWindow*) parent() )->setCaption( title );
136} 137}
137 138
138 139
139void Wellenreiter::handleNotification( OPacket* p ) 140void Wellenreiter::handleNotification( OPacket* p )
140{ 141{
141 QObjectList* l = p->queryList(); 142 QObjectList* l = p->queryList();
142 QObjectListIt it( *l ); 143 QObjectListIt it( *l );
143 QObject* o; 144 QObject* o;
144 145
145 while ( (o = it.current()) != 0 ) 146 while ( (o = it.current()) != 0 )
146 { 147 {
147 QString name = it.current()->name(); 148 QString name = it.current()->name();
148 if ( configwindow->parsePackets->isProtocolChecked( name ) ) 149 if ( configwindow->parsePackets->isProtocolChecked( name ) )
149 { 150 {
150 QString action = configwindow->parsePackets->protocolAction( name ); 151 QString action = configwindow->parsePackets->protocolAction( name );
151 qDebug( "parsePacket-action for '%s' seems to be '%s'", (const char*) name, (const char*) action ); 152 qDebug( "parsePacket-action for '%s' seems to be '%s'", (const char*) name, (const char*) action );
152 doAction( action, name, p ); 153 doAction( action, name, p );
153 } 154 }
154 else 155 else
155 { 156 {
156 qDebug( "protocol '%s' not checked in parsePackets.", (const char*) name ); 157 qDebug( "protocol '%s' not checked in parsePackets.", (const char*) name );
157 } 158 }
158 ++it; 159 ++it;
159 } 160 }
160} 161}
161 162
162 163
163void Wellenreiter::handleManagementFrame( OPacket* p, OWaveLanManagementPacket* manage ) 164void Wellenreiter::handleManagementFrame( OPacket* p, OWaveLanManagementPacket* manage )
164{ 165{
165 if ( manage->managementType() == "Beacon" ) handleManagementFrameBeacon( p, manage ); 166 if ( manage->managementType() == "Beacon" ) handleManagementFrameBeacon( p, manage );
166 else if ( manage->managementType() == "ProbeRequest" ) handleManagementFrameProbeRequest( p, manage ); 167 else if ( manage->managementType() == "ProbeRequest" ) handleManagementFrameProbeRequest( p, manage );
167 else if ( manage->managementType() == "ProbeResponse" ) handleManagementFrameProbeResponse( p, manage ); 168 else if ( manage->managementType() == "ProbeResponse" ) handleManagementFrameProbeResponse( p, manage );
168 else qWarning( "Wellenreiter::handleManagementFrame(): '%s' - please handle me!", (const char*) manage->managementType() ); 169 else qWarning( "Wellenreiter::handleManagementFrame(): '%s' - please handle me!", (const char*) manage->managementType() );
169} 170}
170 171
171 172
172void Wellenreiter::handleManagementFrameProbeRequest( OPacket* p, OWaveLanManagementPacket* request ) 173void Wellenreiter::handleManagementFrameProbeRequest( OPacket* p, OWaveLanManagementPacket* request )
173{ 174{
174 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 175 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
175 QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>"); 176 QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>");
176 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); 177 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
177 int channel = ds ? ds->channel() : -1; 178 int channel = ds ? ds->channel() : -1;
178 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 179 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
179 180
180 GpsLocation loc( -111, -111 ); 181 GpsLocation loc( -111, -111 );
181 if ( configwindow->enableGPS->isChecked() ) 182 if ( configwindow->enableGPS->isChecked() )
182 { 183 {
183 // TODO: add check if GPS is working!? 184 // TODO: add check if GPS is working!?
184 qDebug( "Wellenreiter::gathering GPS data..." ); 185 qDebug( "Wellenreiter::gathering GPS data..." );
185 loc = gps->position(); 186 loc = gps->position();
186 qDebug( "Wellenreiter::GPS data received is ( %f , %f ) - dms string = '%s'", loc.latitude(), loc.longitude(), loc.dmsPosition().latin1() ); 187 qDebug( "Wellenreiter::GPS data received is ( %f , %f ) - dms string = '%s'", loc.latitude(), loc.longitude(), loc.dmsPosition().latin1() );
187 } 188 }
188 189
189 if ( essid.length() ) 190 if ( essid.length() )
190 netView()->addNewItem( "adhoc", essid, header->macAddress2(), false /* should check FrameControl field */, -1, 0, loc, true /* only probed */ ); 191 netView()->addNewItem( "adhoc", essid, header->macAddress2(), false /* should check FrameControl field */, -1, 0, loc, true /* only probed */ );
191 qDebug( "Wellenreiter::invalid frame [possibly noise] detected!" ); 192 qDebug( "Wellenreiter::invalid frame [possibly noise] detected!" );
192} 193}
193 194
194 195
195void Wellenreiter::handleManagementFrameProbeResponse( OPacket* p, OWaveLanManagementPacket* response ) 196void Wellenreiter::handleManagementFrameProbeResponse( OPacket* p, OWaveLanManagementPacket* response )
196{ 197{
197} 198}
198 199
199 200
200void Wellenreiter::handleManagementFrameBeacon( OPacket* p, OWaveLanManagementPacket* beacon ) 201void Wellenreiter::handleManagementFrameBeacon( OPacket* p, OWaveLanManagementPacket* beacon )
201{ 202{
202 QString type; 203 QString type;
203 if ( beacon->canIBSS() ) 204 if ( beacon->canIBSS() )
204 { 205 {
205 type = "adhoc"; 206 type = "adhoc";
206 } 207 }
207 else if ( beacon->canESS() ) 208 else if ( beacon->canESS() )
208 { 209 {
209 type = "managed"; 210 type = "managed";
210 } 211 }
211 else 212 else
212 { 213 {
213 qWarning( "Wellenreiter::invalid frame [possibly noise] detected!" ); 214 qWarning( "Wellenreiter::invalid frame [possibly noise] detected!" );
214 return; 215 return;
215 } 216 }
216 217
217 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 218 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
218 QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>"); 219 QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>");
219 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); 220 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
220 int channel = ds ? ds->channel() : -1; 221 int channel = ds ? ds->channel() : -1;
221 222
222 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 223 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
223 224
224 GpsLocation loc( -111, -111 ); 225 GpsLocation loc( -111, -111 );
225 if ( configwindow->enableGPS->isChecked() ) 226 if ( configwindow->enableGPS->isChecked() )
226 { 227 {
227 // TODO: add check if GPS is working!? 228 // TODO: add check if GPS is working!?
228 qDebug( "Wellenreiter::gathering GPS data..." ); 229 qDebug( "Wellenreiter::gathering GPS data..." );
229 loc = gps->position(); 230 loc = gps->position();
230 qDebug( "Wellenreiter::GPS data received is ( %f , %f ) - dms string = '%s'", loc.latitude(), loc.longitude(), loc.dmsPosition().latin1() ); 231 qDebug( "Wellenreiter::GPS data received is ( %f , %f ) - dms string = '%s'", loc.latitude(), loc.longitude(), loc.dmsPosition().latin1() );
231 } 232 }
232 233
233 netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc ); 234 netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc );
234 235
235 // update graph window 236 // update graph window
236 if ( ds ) 237 if ( ds )
237 { 238 {
238 OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) ); 239 OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) );
239 if ( prism ) 240 if ( prism )
240 graphwindow->traffic( ds->channel(), prism->signalStrength() ); 241 graphwindow->traffic( ds->channel(), prism->signalStrength() );
241 else 242 else
242 graphwindow->traffic( ds->channel(), 95 ); 243 graphwindow->traffic( ds->channel(), 95 );
243 } 244 }
244} 245}
245 246
246 247
247void Wellenreiter::handleControlFrame( OPacket* p, OWaveLanControlPacket* control ) 248void Wellenreiter::handleControlFrame( OPacket* p, OWaveLanControlPacket* control )
248{ 249{
249 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 250 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
250 251
251 if ( control->controlType() == "Acknowledge" ) 252 if ( control->controlType() == "Acknowledge" )
252 { 253 {
253 netView()->addNewItem( "adhoc", "<unknown>", header->macAddress1(), false, -1, 0, GpsLocation( -111, -111 ) ); 254 netView()->addNewItem( "adhoc", "<unknown>", header->macAddress1(), false, -1, 0, GpsLocation( -111, -111 ) );
254 } 255 }
255 else 256 else
256 { 257 {
257 qDebug( "Wellenreiter::handleControlFrame - please handle %s in a future version! :D", (const char*) control->controlType() ); 258 qDebug( "Wellenreiter::handleControlFrame - please handle %s in a future version! :D", (const char*) control->controlType() );
258 } 259 }
259} 260}
260 261
261 262
262void Wellenreiter::handleWlanData( OPacket* p, OWaveLanDataPacket* data, OMacAddress& from, OMacAddress& to ) 263void Wellenreiter::handleWlanData( OPacket* p, OWaveLanDataPacket* data, OMacAddress& from, OMacAddress& to )
263{ 264{
264 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); 265 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" );
265 if ( wlan->fromDS() && !wlan->toDS() ) 266 if ( wlan->fromDS() && !wlan->toDS() )
266 { 267 {
267 netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() ); 268 netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
268 from = wlan->macAddress3(); 269 from = wlan->macAddress3();
269 to = wlan->macAddress2(); 270 to = wlan->macAddress2();
270 } 271 }
271 else if ( !wlan->fromDS() && wlan->toDS() ) 272 else if ( !wlan->fromDS() && wlan->toDS() )
272 { 273 {
273 netView()->toDStraffic( wlan->macAddress2(), wlan->macAddress3(), wlan->macAddress1() ); 274 netView()->toDStraffic( wlan->macAddress2(), wlan->macAddress3(), wlan->macAddress1() );
274 from = wlan->macAddress2(); 275 from = wlan->macAddress2();
275 to = wlan->macAddress3(); 276 to = wlan->macAddress3();
276 } 277 }
277 else if ( wlan->fromDS() && wlan->toDS() ) 278 else if ( wlan->fromDS() && wlan->toDS() )
278 { 279 {
279 netView()->WDStraffic( wlan->macAddress4(), wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() ); 280 netView()->WDStraffic( wlan->macAddress4(), wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
280 from = wlan->macAddress4(); 281 from = wlan->macAddress4();
281 to = wlan->macAddress3(); 282 to = wlan->macAddress3();
282 } 283 }
283 else 284 else
284 { 285 {
285 netView()->IBSStraffic( wlan->macAddress2(), wlan->macAddress1(), wlan->macAddress3() ); 286 netView()->IBSStraffic( wlan->macAddress2(), wlan->macAddress1(), wlan->macAddress3() );
286 from = wlan->macAddress2(); 287 from = wlan->macAddress2();
287 to = wlan->macAddress1(); 288 to = wlan->macAddress1();
288 } 289 }
289} 290}
290 291
291 292
292void Wellenreiter::handleEthernetData( OPacket* p, OEthernetPacket* data, OMacAddress& from, OMacAddress& to ) 293void Wellenreiter::handleEthernetData( OPacket* p, OEthernetPacket* data, OMacAddress& from, OMacAddress& to )
293{ 294{
294 from = data->sourceAddress(); 295 from = data->sourceAddress();
295 to = data->destinationAddress(); 296 to = data->destinationAddress();
296 297
297 netView()->addNewItem( "station", "<wired>", from, false, -1, 0, GpsLocation( -111, -111 ) ); 298 netView()->addNewItem( "station", "<wired>", from, false, -1, 0, GpsLocation( -111, -111 ) );
298} 299}
299 300
300 301
301void Wellenreiter::handleARPData( OPacket* p, OARPPacket*, OMacAddress& source, OMacAddress& dest ) 302void Wellenreiter::handleARPData( OPacket* p, OARPPacket*, OMacAddress& source, OMacAddress& dest )
302{ 303{
303 OARPPacket* arp = (OARPPacket*) p->child( "ARP" ); 304 OARPPacket* arp = (OARPPacket*) p->child( "ARP" );
304 if ( arp ) 305 if ( arp )
305 { 306 {
306 qDebug( "Received ARP traffic (type '%s'): ", (const char*) arp->type() ); 307 qDebug( "Received ARP traffic (type '%s'): ", (const char*) arp->type() );
307 if ( arp->type() == "REQUEST" ) 308 if ( arp->type() == "REQUEST" )
308 { 309 {
309 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() ); 310 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
310 } 311 }
311 else if ( arp->type() == "REPLY" ) 312 else if ( arp->type() == "REPLY" )
312 { 313 {
313 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() ); 314 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
314 netView()->identify( arp->targetMacAddress(), arp->targetIPV4Address().toString() ); 315 netView()->identify( arp->targetMacAddress(), arp->targetIPV4Address().toString() );
315 } 316 }
316 } 317 }
317} 318}
318 319
319 320
320void Wellenreiter::handleIPData( OPacket* p, OIPPacket* ip, OMacAddress& source, OMacAddress& dest ) 321void Wellenreiter::handleIPData( OPacket* p, OIPPacket* ip, OMacAddress& source, OMacAddress& dest )
321{ 322{
322 //TODO: Implement more IP based protocols 323 //TODO: Implement more IP based protocols
323 324
324 ODHCPPacket* dhcp = (ODHCPPacket*) p->child( "DHCP" ); 325 ODHCPPacket* dhcp = (ODHCPPacket*) p->child( "DHCP" );
325 if ( dhcp ) 326 if ( dhcp )
326 { 327 {
327 qDebug( "Received DHCP '%s' packet", (const char*) dhcp->type() ); 328 qDebug( "Received DHCP '%s' packet", (const char*) dhcp->type() );
328 if ( dhcp->type() == "OFFER" ) 329 if ( dhcp->type() == "OFFER" )
329 { 330 {
330 qDebug( "DHCP: '%s' ('%s') seems to be a DHCP server.", (const char*) source.toString(), (const char*) dhcp->serverAddress().toString() ); 331 qDebug( "DHCP: '%s' ('%s') seems to be a DHCP server.", (const char*) source.toString(), (const char*) dhcp->serverAddress().toString() );
331 netView()->identify( source, dhcp->serverAddress().toString() ); 332 netView()->identify( source, dhcp->serverAddress().toString() );
332 netView()->addService( "DHCP", source, dhcp->serverAddress().toString() ); 333 netView()->addService( "DHCP", source, dhcp->serverAddress().toString() );
333 } 334 }
334 else if ( dhcp->type() == "ACK" ) 335 else if ( dhcp->type() == "ACK" )
335 { 336 {
336 qDebug( "DHCP: '%s' ('%s') accepted the offered DHCP address.", (const char*) dhcp->clientMacAddress().toString(), (const char*) dhcp->yourAddress().toString() ); 337 qDebug( "DHCP: '%s' ('%s') accepted the offered DHCP address.", (const char*) dhcp->clientMacAddress().toString(), (const char*) dhcp->yourAddress().toString() );
337 netView()->identify( dhcp->clientMacAddress(), dhcp->yourAddress().toString() ); 338 netView()->identify( dhcp->clientMacAddress(), dhcp->yourAddress().toString() );
338 } 339 }
339 } 340 }
340} 341}
341 342
342 343
343QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol ) 344QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol )
344{ 345{
345 if ( configwindow->parsePackets->isProtocolChecked( protocol ) ) 346 if ( configwindow->parsePackets->isProtocolChecked( protocol ) )
346 if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" ) 347 if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" )
347 return 0; 348 return 0;
348 349
349 return p->child( protocol ); 350 return p->child( protocol );
350} 351}
351 352
352 353
353bool Wellenreiter::checkDumpPacket( OPacket* p ) 354bool Wellenreiter::checkDumpPacket( OPacket* p )
354{ 355{
355 // go through all child packets and see if one is inside the child hierarchy for p 356 // go through all child packets and see if one is inside the child hierarchy for p
356 // if so, do what the user requested (protocolAction), e.g. pass or discard 357 // if so, do what the user requested (protocolAction), e.g. pass or discard
357 if ( !configwindow->writeCaptureFile->isChecked() ) 358 if ( !configwindow->writeCaptureFile->isChecked() )
358 return true; // semantic change - we're logging anyway now to /tmp/wellenreiter 359 return true; // semantic change - we're logging anyway now to /tmp/wellenreiter
359 360
360 QObjectList* l = p->queryList(); 361 QObjectList* l = p->queryList();
361 QObjectListIt it( *l ); 362 QObjectListIt it( *l );
362 QObject* o; 363 QObject* o;
363 364
364 while ( (o = it.current()) != 0 ) 365 while ( (o = it.current()) != 0 )
365 { 366 {
366 QString name = it.current()->name(); 367 QString name = it.current()->name();
367 if ( configwindow->capturePackets->isProtocolChecked( name ) ) 368 if ( configwindow->capturePackets->isProtocolChecked( name ) )
368 { 369 {
369 QString action = configwindow->capturePackets->protocolAction( name ); 370 QString action = configwindow->capturePackets->protocolAction( name );
370 qDebug( "capturePackets-action for '%s' seems to be '%s'", (const char*) name, (const char*) action ); 371 qDebug( "capturePackets-action for '%s' seems to be '%s'", (const char*) name, (const char*) action );
371 if ( action == "Discard" ) 372 if ( action == "Discard" )
372 { 373 {
373 logwindow->log( QString().sprintf( "(i) dump-discarding of '%s' packet requested.", (const char*) name ) ); 374 logwindow->log( QString().sprintf( "(i) dump-discarding of '%s' packet requested.", (const char*) name ) );
374 return false; 375 return false;
375 } 376 }
376 } 377 }
377 else 378 else
378 { 379 {
379 qDebug( "protocol '%s' not checked in capturePackets.", (const char*) name ); 380 qDebug( "protocol '%s' not checked in capturePackets.", (const char*) name );
380 } 381 }
381 ++it; 382 ++it;
382 } 383 }
383 return true; 384 return true;
384} 385}
385 386
386 387
387void Wellenreiter::receivePacket( OPacket* p ) 388void Wellenreiter::receivePacket( OPacket* p )
388{ 389{
389 hexWindow()->add( p ); 390 hexWindow()->add( p );
390 391
391 if ( checkDumpPacket( p ) ) 392 if ( checkDumpPacket( p ) )
392 { 393 {
393 pcap->dump( p ); 394 pcap->dump( p );
394 } 395 }
395 396
396 // check for a management frame 397 // check for a management frame
397 OWaveLanManagementPacket* manage = static_cast<OWaveLanManagementPacket*>( childIfToParse( p, "802.11 Management" ) ); 398 OWaveLanManagementPacket* manage = static_cast<OWaveLanManagementPacket*>( childIfToParse( p, "802.11 Management" ) );
398 if ( manage ) 399 if ( manage )
399 { 400 {
400 handleManagementFrame( p, manage ); 401 handleManagementFrame( p, manage );
401 return; 402 return;
402 } 403 }
403 404
404 // check for a control frame 405 // check for a control frame
405 OWaveLanControlPacket* control = static_cast<OWaveLanControlPacket*>( childIfToParse( p, "802.11 Control" ) ); 406 OWaveLanControlPacket* control = static_cast<OWaveLanControlPacket*>( childIfToParse( p, "802.11 Control" ) );
406 if ( control ) 407 if ( control )
407 { 408 {
408 handleControlFrame( p, control ); 409 handleControlFrame( p, control );
409 return; 410 return;
410 } 411 }
411 412
412 OMacAddress source; 413 OMacAddress source;
413 OMacAddress dest; 414 OMacAddress dest;
414 415
415 //TODO: WEP check here 416 //TODO: WEP check here
416 417
417 // check for a wireless data frame 418 // check for a wireless data frame
418 OWaveLanDataPacket* wlan = static_cast<OWaveLanDataPacket*>( childIfToParse( p, "802.11 Data" ) ); 419 OWaveLanDataPacket* wlan = static_cast<OWaveLanDataPacket*>( childIfToParse( p, "802.11 Data" ) );
419 if ( wlan ) 420 if ( wlan )
420 { 421 {
421 handleWlanData( p, wlan, source, dest ); 422 handleWlanData( p, wlan, source, dest );
422 } 423 }
423 424
424 // check for a wired data frame 425 // check for a wired data frame
425 OEthernetPacket* eth = static_cast<OEthernetPacket*>( childIfToParse( p, "Ethernet" ) ); 426 OEthernetPacket* eth = static_cast<OEthernetPacket*>( childIfToParse( p, "Ethernet" ) );
426 if ( eth ) 427 if ( eth )
427 { 428 {
428 handleEthernetData( p, eth, source, dest ); 429 handleEthernetData( p, eth, source, dest );
429 } 430 }
430 431
431 // check for an arp frame since arp frames come in two flavours: 432 // check for an arp frame since arp frames come in two flavours:
432 // 802.11 encapsulates ARP data within IP packets while wired ethernet doesn't. 433 // 802.11 encapsulates ARP data within IP packets while wired ethernet doesn't.
433 OARPPacket* arp = static_cast<OARPPacket*>( childIfToParse( p, "ARP" ) ); 434 OARPPacket* arp = static_cast<OARPPacket*>( childIfToParse( p, "ARP" ) );
434 if ( arp ) 435 if ( arp )
435 { 436 {
436 handleARPData( p, arp, source, dest ); 437 handleARPData( p, arp, source, dest );
437 } 438 }
438 439
439 // check for a ip frame 440 // check for a ip frame
440 OIPPacket* ip = static_cast<OIPPacket*>( childIfToParse( p, "IP" ) ); 441 OIPPacket* ip = static_cast<OIPPacket*>( childIfToParse( p, "IP" ) );
441 if ( ip ) 442 if ( ip )
442 { 443 {
443 handleIPData( p, ip, source, dest ); 444 handleIPData( p, ip, source, dest );
444 } 445 }
445 446
446 //handleNotification( p ); 447 //handleNotification( p );
447 448
448} 449}
449 450
450 451
451void Wellenreiter::stopClicked() 452void Wellenreiter::stopClicked()
452{ 453{
453 if ( iface ) 454 if ( iface )
454 { 455 {
455 disconnect( SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) ); 456 disconnect( SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) );
456 disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) ); 457 disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
457 iface->setChannelHopping(); // stop hopping channels 458 iface->setChannelHopping(); // stop hopping channels
458 } 459 }
459 else 460 else
460 killTimers(); 461 killTimers();
461 462
462 pcap->close(); 463 pcap->close();
463 sniffing = false; 464 sniffing = false;
464 465
465 if ( iface ) 466 if ( iface )
466 { 467 {
467 // switch off monitor mode 468 // switch off monitor mode
468 iface->setMode( "managed" ); 469 iface->setMode( "managed" );
469 // switch off promisc flag 470 // switch off promisc flag
470 iface->setPromiscuousMode( false ); 471 iface->setPromiscuousMode( false );
471 472
472 system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess 473 system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess
473 } 474 }
474 475
475 logwindow->log( "(i) Stopped Scanning." ); 476 logwindow->log( "(i) Stopped Scanning." );
476 assert( parent() ); 477 assert( parent() );
477 ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" ); 478 ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" );
478 479
479 // message the user 480 // message the user
480 QMessageBox::information( this, "Wellenreiter II", 481 QMessageBox::information( this, "Wellenreiter II",
481 tr( "Your wireless card\nshould now be usable again." ) ); 482 tr( "Your wireless card\nshould now be usable again." ) );
482 483
483 sniffing = false; 484 sniffing = false;
484 emit( stoppedSniffing() ); 485 emit( stoppedSniffing() );
485 486
486 #ifdef QWS 487 #ifdef QWS
487 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() ) 488 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() )
488 { 489 {
489 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 490 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
490 } 491 }
491 #else 492 #else
492 #warning FIXME: setScreenSaverMode is not operational on the X11 build 493 #warning FIXME: setScreenSaverMode is not operational on the X11 build
493 #endif 494 #endif
494 495
495 // print out statistics 496 // print out statistics
496 for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it ) 497 for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it )
497 statwindow->updateCounter( it.key(), it.data() ); 498 statwindow->updateCounter( it.key(), it.data() );
498} 499}
499 500
500 501
501void Wellenreiter::startClicked() 502void Wellenreiter::startClicked()
502{ 503{
503 // get configuration from config window 504 // get configuration from config window
504 505
505 const QString& interface = configwindow->interfaceName->currentText(); 506 const QString& interface = configwindow->interfaceName->currentText();
506 const int cardtype = configwindow->driverType(); 507 const int cardtype = configwindow->driverType();
507 const int interval = configwindow->hoppingInterval(); 508 const int interval = configwindow->hoppingInterval();
508 509
509 if ( ( interface == "" ) || ( cardtype == 0 ) ) 510 if ( ( interface == "" ) || ( cardtype == 0 ) )
510 { 511 {
511 QMessageBox::information( this, "Wellenreiter II", 512 QMessageBox::information( this, "Wellenreiter II",
512 tr( "Your device is not\nproperly configured. Please reconfigure!" ) ); 513 tr( "Your device is not\nproperly configured. Please reconfigure!" ) );
513 return; 514 return;
514 } 515 }
515 516
516 // configure device 517 // configure device
517 ONetwork* net = ONetwork::instance(); 518 ONetwork* net = ONetwork::instance();
518 519
519 // TODO: check if interface is wireless and support sniffing for non-wireless interfaces 520 // TODO: check if interface is wireless and support sniffing for non-wireless interfaces
520 521
521 if ( cardtype != DEVTYPE_FILE ) 522 if ( cardtype != DEVTYPE_FILE )
522 { 523 {
523 524
524 if ( !net->isPresent( interface ) ) 525 if ( !net->isPresent( interface ) )
525 { 526 {
526 QMessageBox::information( this, "Wellenreiter II", 527 QMessageBox::information( this, "Wellenreiter II",
527 tr( "The configured device (%1)\nis not available on this system\n. Please reconfigure!" ).arg( interface ) ); 528 tr( "The configured device (%1)\nis not available on this system\n. Please reconfigure!" ).arg( interface ) );
528 return; 529 return;
529 } 530 }
530 531
531 iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // fails if network is not wireless! 532 iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // fails if network is not wireless!
532 assert( iface ); 533 assert( iface );
533 534
534 // bring device UP 535 // bring device UP
535 iface->setUp( true ); 536 iface->setUp( true );
536 if ( !iface->isUp() ) 537 if ( !iface->isUp() )
537 { 538 {
538 QMessageBox::warning( this, "Wellenreiter II", 539 QMessageBox::warning( this, "Wellenreiter II",
539 tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) ); 540 tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) );
540 return; 541 return;
541 } 542 }
542 } 543 }
543 // set monitor mode 544 // set monitor mode
544 bool usePrism = configwindow->usePrismHeader(); 545 bool usePrism = configwindow->usePrismHeader();
545 546
546 switch ( cardtype ) 547 switch ( cardtype )
547 { 548 {
548 case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break; 549 case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break;
549 case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break; 550 case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break;
550 case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break; 551 case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break;
551 case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break; 552 case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break;
552 case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", tr( "Bring your device into\nmonitor mode now." ) ); break; 553 case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", tr( "Bring your device into\nmonitor mode now." ) ); break;
553 case DEVTYPE_FILE: qDebug( "Wellenreiter: Capturing from file '%s'", (const char*) interface ); break; 554 case DEVTYPE_FILE: qDebug( "Wellenreiter: Capturing from file '%s'", (const char*) interface ); break;
554 default: assert( 0 ); // shouldn't reach this 555 default: assert( 0 ); // shouldn't reach this
555 } 556 }
556 557
557 // switch device into monitor mode 558 // switch device into monitor mode
558 if ( cardtype < DEVTYPE_FILE ) 559 if ( cardtype < DEVTYPE_FILE )
559 { 560 {
560 if ( cardtype != DEVTYPE_MANUAL ) 561 if ( cardtype != DEVTYPE_MANUAL )
561 iface->setMode( "monitor" ); 562 iface->setMode( "monitor" );
562 if ( iface->mode() != "monitor" ) 563 if ( iface->mode() != "monitor" )
563 { 564 {
564 if ( QMessageBox::warning( this, "Wellenreiter II", 565 if ( QMessageBox::warning( this, "Wellenreiter II",
565 tr( "Can't set interface '%1'\ninto monitor mode:\n" ).arg( iface->name() ) + strerror( errno ) + 566 tr( "Can't set interface '%1'\ninto monitor mode:\n" ).arg( iface->name() ) + strerror( errno ) +
566 tr( "\nContinue with limited functionality?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No ) 567 tr( "\nContinue with limited functionality?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
567 return; 568 return;
568 } 569 }
569 } 570 }
570 571
571 // open GPS device 572 // open GPS device
572 if ( configwindow->enableGPS->isChecked() ) 573 if ( configwindow->enableGPS->isChecked() )
573 { 574 {
574 qDebug( "Wellenreiter:GPS enabled @ %s:%d", (const char*) configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() ); 575 qDebug( "Wellenreiter:GPS enabled @ %s:%d", (const char*) configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() );
575 gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() ); 576 gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() );
576 } 577 }
577 578
578 // open pcap and start sniffing 579 // open pcap and start sniffing
579 580
580 if ( configwindow->writeCaptureFile->isChecked() ) // write to a user specified capture file? 581 if ( configwindow->writeCaptureFile->isChecked() ) // write to a user specified capture file?
581 { 582 {
582 dumpname = configwindow->captureFileName->text(); 583 dumpname = configwindow->captureFileName->text();
583 if ( dumpname.isEmpty() ) dumpname = "captureFile"; 584 if ( dumpname.isEmpty() ) dumpname = "captureFile";
584 dumpname.append( '-' ); 585 dumpname.append( '-' );
585 dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) ); 586 dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) );
586 dumpname.append( ".wellenreiter" ); 587 dumpname.append( ".wellenreiter" );
587 } 588 }
588 else // write it anyway ;) 589 else // write it anyway ;)
589 { 590 {
590 dumpname = "/var/log/dump.wellenreiter"; 591 dumpname = "/var/log/dump.wellenreiter";
591 } 592 }
592 593
593 if ( cardtype != DEVTYPE_FILE ) 594 if ( cardtype != DEVTYPE_FILE )
594 pcap->open( interface ); 595 pcap->open( interface );
595 else 596 else
596 pcap->open( QFile( interface ) ); 597 pcap->open( QFile( interface ) );
597 598
598 qDebug( "Wellenreiter:: dumping to %s", (const char*) dumpname ); 599 qDebug( "Wellenreiter:: dumping to %s", (const char*) dumpname );
599 pcap->openDumpFile( dumpname ); 600 pcap->openDumpFile( dumpname );
600 601
601 if ( !pcap->isOpen() ) 602 if ( !pcap->isOpen() )
602 { 603 {
603 QMessageBox::warning( this, "Wellenreiter II", tr( "Can't open packet capturer for\n'%1':\n" ).arg( 604 QMessageBox::warning( this, "Wellenreiter II", tr( "Can't open packet capturer for\n'%1':\n" ).arg(
604 cardtype == DEVTYPE_FILE ? (const char*) interface : iface->name() ) + QString(strerror( errno ) )); 605 cardtype == DEVTYPE_FILE ? (const char*) interface : iface->name() ) + QString(strerror( errno ) ));
605 return; 606 return;
606 } 607 }
607 608
608 // set capturer to non-blocking mode 609 // set capturer to non-blocking mode
609 pcap->setBlocking( false ); 610 pcap->setBlocking( false );
610 611
611 // start channel hopper 612 // start channel hopper
612 if ( cardtype != DEVTYPE_FILE ) 613 if ( cardtype != DEVTYPE_FILE )
613 { 614 {
614 logwindow->log( QString().sprintf( "(i) Starting channel hopper (d=%d ms)", configwindow->hopInterval->value() ) ); 615 logwindow->log( QString().sprintf( "(i) Starting channel hopper (d=%d ms)", configwindow->hopInterval->value() ) );
615 iface->setChannelHopping( configwindow->hopInterval->value() ); //use interval from config window 616 iface->setChannelHopping( configwindow->hopInterval->value() ); //use interval from config window
616 } 617 }
617 618
618 if ( cardtype != DEVTYPE_FILE ) 619 if ( cardtype != DEVTYPE_FILE )
619 { 620 {
620 // connect socket notifier and start channel hopper 621 // connect socket notifier and start channel hopper
621 connect( pcap, SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) ); 622 connect( pcap, SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) );
622 connect( iface->channelHopper(), SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) ); 623 connect( iface->channelHopper(), SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
623 } 624 }
624 else 625 else
625 { 626 {
626 // start timer for reading packets 627 // start timer for reading packets
627 startTimer( 100 ); 628 startTimer( 100 );
628 } 629 }
629 630
630 logwindow->log( "(i) Started Scanning." ); 631 logwindow->log( "(i) Started Scanning." );
631 sniffing = true; 632 sniffing = true;
632 633
633 #ifdef QWS 634 #ifdef QWS
634 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() ) 635 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() )
635 { 636 {
636 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; 637 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable;
637 } 638 }
638 #else 639 #else
639 #warning FIXME: setScreenSaverMode is not operational on the X11 build 640 #warning FIXME: setScreenSaverMode is not operational on the X11 build
640 #endif 641 #endif
641 642
642 emit( startedSniffing() ); 643 emit( startedSniffing() );
643 if ( cardtype != DEVTYPE_FILE ) channelHopped( 6 ); // set title 644 if ( cardtype != DEVTYPE_FILE ) channelHopped( 6 ); // set title
644 else 645 else
645 { 646 {
646 assert( parent() ); 647 assert( parent() );
647 ( (QMainWindow*) parent() )->setCaption( tr( "Wellenreiter II - replaying capture file..." ) ); 648 ( (QMainWindow*) parent() )->setCaption( tr( "Wellenreiter II - replaying capture file..." ) );
648 } 649 }
649} 650}
650 651
651 652
652void Wellenreiter::timerEvent( QTimerEvent* ) 653void Wellenreiter::timerEvent( QTimerEvent* )
653{ 654{
654 qDebug( "Wellenreiter::timerEvent()" ); 655 qDebug( "Wellenreiter::timerEvent()" );
655 OPacket* p = pcap->next(); 656 OPacket* p = pcap->next();
656 if ( !p ) // no more packets available 657 if ( !p ) // no more packets available
657 { 658 {
658 stopClicked(); 659 stopClicked();
659 } 660 }
660 else 661 else
661 { 662 {
662 receivePacket( p ); 663 receivePacket( p );
663 delete p; 664 // We no longer delete packets here. Ownership of the packets is
665 // transferred to the PacketView.
666 //delete p;
664 } 667 }
665} 668}
666 669
667 670
668void Wellenreiter::doAction( const QString& action, const QString& protocol, OPacket* p ) 671void Wellenreiter::doAction( const QString& action, const QString& protocol, OPacket* p )
669{ 672{
670 #ifdef QWS 673 #ifdef QWS
671 if ( action == "TouchSound" ) 674 if ( action == "TouchSound" )
672 ODevice::inst()->playTouchSound(); 675 ODevice::inst()->playTouchSound();
673 else if ( action == "AlarmSound" ) 676 else if ( action == "AlarmSound" )
674 ODevice::inst()->playAlarmSound(); 677 ODevice::inst()->playAlarmSound();
675 else if ( action == "KeySound" ) 678 else if ( action == "KeySound" )
676 ODevice::inst()->playKeySound(); 679 ODevice::inst()->playKeySound();
677 else if ( action == "LedOn" ) 680 else if ( action == "LedOn" )
678 ODevice::inst()->setLedState( Led_Mail, Led_On ); 681 ODevice::inst()->setLedState( Led_Mail, Led_On );
679 else if ( action == "LedOff" ) 682 else if ( action == "LedOff" )
680 ODevice::inst()->setLedState( Led_Mail, Led_Off ); 683 ODevice::inst()->setLedState( Led_Mail, Led_Off );
681 else if ( action == "LogMessage" ) 684 else if ( action == "LogMessage" )
682 logwindow->log( QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) ); 685 logwindow->log( QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) );
683 else if ( action == "MessageBox" ) 686 else if ( action == "MessageBox" )
684 QMessageBox::information( this, "Notification!", 687 QMessageBox::information( this, "Notification!",
685 QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) ); 688 QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) );
686 #else 689 #else
687 #warning Actions do not work with Qt/X11 yet 690 #warning Actions do not work with Qt/X11 yet
688 #endif 691 #endif
689} 692}
690 693
691void Wellenreiter::joinNetwork(const QString& type, const QString& essid, int channel, const QString& macaddr) 694void Wellenreiter::joinNetwork(const QString& type, const QString& essid, int channel, const QString& macaddr)
692{ 695{
693 #ifdef QWS 696 #ifdef QWS
694 if ( !iface ) 697 if ( !iface )
695 { 698 {
696 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "No wireless\ninterface available." ) ); 699 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "No wireless\ninterface available." ) );
697 return; 700 return;
698 } 701 }
699 702
700 if ( sniffing ) 703 if ( sniffing )
701 { 704 {
702 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Stop sniffing before\njoining a net." ) ); 705 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Stop sniffing before\njoining a net." ) );
703 return; 706 return;
704 } 707 }
705 708
706 qDebug( "joinNetwork() with Interface %s: %s, %s, %d, %s", 709 qDebug( "joinNetwork() with Interface %s: %s, %s, %d, %s",
707 (const char*) iface->name(), 710 (const char*) iface->name(),
708 (const char*) type, 711 (const char*) type,
709 (const char*) essid, 712 (const char*) essid,
710 channel, 713 channel,
711 (const char*) macaddr ); 714 (const char*) macaddr );
712 715
713 QCopEnvelope msg( "QPE/Application/networksettings", "wlan(QString,QString,QString)" ); 716 QCopEnvelope msg( "QPE/Application/networksettings", "wlan(QString,QString,QString)" );
714 int count = 3; 717 int count = 3;
715 qDebug("sending %d messages",count); 718 qDebug("sending %d messages",count);
716 msg << QString("count") << QString::number(count); 719 msg << QString("count") << QString::number(count);
717 qDebug("msg >%s< Mode >%s<", iface->name(),type.latin1() ); 720 qDebug("msg >%s< Mode >%s<", iface->name(),type.latin1() );
718 msg << QString(iface->name()) << QString("Mode") << type; 721 msg << QString(iface->name()) << QString("Mode") << type;
719 qDebug("msg >%s< essid >%s<", iface->name(),essid.latin1()); 722 qDebug("msg >%s< essid >%s<", iface->name(),essid.latin1());
720 msg << QString(iface->name()) << QString("ESSID") << essid; 723 msg << QString(iface->name()) << QString("ESSID") << essid;
721 qDebug("msg >%s< channel >%d<", iface->name(),channel); 724 qDebug("msg >%s< channel >%d<", iface->name(),channel);
722 msg << QString(iface->name()) << QString("Channel") << channel; 725 msg << QString(iface->name()) << QString("Channel") << channel;
723// qDebug("msg >%s< mac >%s<", iface->name(),macaddr); 726// qDebug("msg >%s< mac >%s<", iface->name(),macaddr);
724// msg << QString(iface->name()) << QString("MacAddr") << macaddr; 727// msg << QString(iface->name()) << QString("MacAddr") << macaddr;
725 #else 728 #else
726 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Function only available on Embedded build" ) ); 729 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Function only available on Embedded build" ) );
727 #endif 730 #endif
728 731
729} 732}
730 733