summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-10-03 13:44:35 (UTC)
committer mickeyl <mickeyl>2003-10-03 13:44:35 (UTC)
commit120b0fe68c1352ba03ad6e73d26bcbe8452ef6ed (patch) (unidiff)
tree253c82439683b8fc2352de0859c92671568fdaff
parent9450f41ce6109fb9d22fca7b1c72c606fd37f5a7 (diff)
downloadopie-120b0fe68c1352ba03ad6e73d26bcbe8452ef6ed.zip
opie-120b0fe68c1352ba03ad6e73d26bcbe8452ef6ed.tar.gz
opie-120b0fe68c1352ba03ad6e73d26bcbe8452ef6ed.tar.bz2
fix a few SIGSEGVs related to not checking the value of iface, if we
are capturing from a file (DEVTYPE_FILE)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/wellenreiter.cpp18
1 files changed, 10 insertions, 8 deletions
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp
index 14f251a..405eda8 100644
--- a/noncore/net/wellenreiter/gui/wellenreiter.cpp
+++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp
@@ -1,584 +1,586 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved. 2** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
3** 3**
4** This file is part of Opie Environment. 4** This file is part of Opie Environment.
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// Local 16// Local
17 17
18#include "gps.h" 18#include "gps.h"
19#include "wellenreiter.h" 19#include "wellenreiter.h"
20#include "scanlist.h" 20#include "scanlist.h"
21#include "logwindow.h" 21#include "logwindow.h"
22#include "hexwindow.h" 22#include "hexwindow.h"
23#include "configwindow.h" 23#include "configwindow.h"
24#include "statwindow.h" 24#include "statwindow.h"
25#include "graphwindow.h" 25#include "graphwindow.h"
26#include "protolistview.h" 26#include "protolistview.h"
27 27
28// Opie 28// Opie
29 29
30#ifdef QWS 30#ifdef QWS
31#include <opie/odevice.h> 31#include <opie/odevice.h>
32#include <qpe/qcopenvelope_qws.h> 32#include <qpe/qcopenvelope_qws.h>
33using namespace Opie; 33using namespace Opie;
34#endif 34#endif
35 35
36#ifdef QWS 36#ifdef QWS
37#include <opie2/oapplication.h> 37#include <opie2/oapplication.h>
38#else 38#else
39#include <qapplication.h> 39#include <qapplication.h>
40#endif 40#endif
41#include <opie2/onetwork.h> 41#include <opie2/onetwork.h>
42#include <opie2/opcap.h> 42#include <opie2/opcap.h>
43 43
44// Qt 44// Qt
45 45
46#include <qcheckbox.h> 46#include <qcheckbox.h>
47#include <qcombobox.h> 47#include <qcombobox.h>
48#include <qdatetime.h> 48#include <qdatetime.h>
49#include <qpushbutton.h> 49#include <qpushbutton.h>
50#include <qlineedit.h> 50#include <qlineedit.h>
51#include <qmessagebox.h> 51#include <qmessagebox.h>
52#include <qobjectlist.h> 52#include <qobjectlist.h>
53#include <qregexp.h> 53#include <qregexp.h>
54#include <qspinbox.h> 54#include <qspinbox.h>
55#include <qtoolbutton.h> 55#include <qtoolbutton.h>
56#include <qmainwindow.h> 56#include <qmainwindow.h>
57 57
58// Standard 58// Standard
59 59
60#include <assert.h> 60#include <assert.h>
61#include <errno.h> 61#include <errno.h>
62#include <unistd.h> 62#include <unistd.h>
63#include <string.h> 63#include <string.h>
64#include <sys/types.h> 64#include <sys/types.h>
65#include <stdlib.h> 65#include <stdlib.h>
66 66
67Wellenreiter::Wellenreiter( QWidget* parent ) 67Wellenreiter::Wellenreiter( QWidget* parent )
68 : WellenreiterBase( parent, 0, 0 ), 68 : WellenreiterBase( parent, 0, 0 ),
69 sniffing( false ), iface( 0 ), configwindow( 0 ) 69 sniffing( false ), iface( 0 ), configwindow( 0 )
70{ 70{
71 71
72 logwindow->log( "(i) Wellenreiter has been started." ); 72 logwindow->log( "(i) Wellenreiter has been started." );
73 73
74 // 74 //
75 // detect operating system 75 // detect operating system
76 // 76 //
77 77
78 #ifdef QWS 78 #ifdef QWS
79 QString sys; 79 QString sys;
80 sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() ); 80 sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() );
81 _system = ODevice::inst()->system(); 81 _system = ODevice::inst()->system();
82 logwindow->log( sys ); 82 logwindow->log( sys );
83 #endif 83 #endif
84 84
85 netview->setColumnWidthMode( 1, QListView::Manual ); 85 netview->setColumnWidthMode( 1, QListView::Manual );
86 connect( netview, SIGNAL( joinNetwork(const QString&,const QString&,int,const QString&) ), 86 connect( netview, SIGNAL( joinNetwork(const QString&,const QString&,int,const QString&) ),
87 this, SLOT( joinNetwork(const QString&,const QString&,int,const QString&) ) ); 87 this, SLOT( joinNetwork(const QString&,const QString&,int,const QString&) ) );
88 pcap = new OPacketCapturer(); 88 pcap = new OPacketCapturer();
89 89
90 gps = new GPS( this ); 90 gps = new GPS( this );
91} 91}
92 92
93 93
94Wellenreiter::~Wellenreiter() 94Wellenreiter::~Wellenreiter()
95{ 95{
96 delete pcap; 96 delete pcap;
97} 97}
98 98
99 99
100void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw ) 100void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw )
101{ 101{
102 configwindow = cw; 102 configwindow = cw;
103} 103}
104 104
105 105
106void Wellenreiter::channelHopped(int c) 106void Wellenreiter::channelHopped(int c)
107{ 107{
108 QString title = "Wellenreiter II -scan- ["; 108 QString title = "Wellenreiter II -scan- [";
109 QString left; 109 QString left;
110 if ( c > 1 ) left.fill( '.', c-1 ); 110 if ( c > 1 ) left.fill( '.', c-1 );
111 title.append( left ); 111 title.append( left );
112 title.append( '|' ); 112 title.append( '|' );
113 if ( c < iface->channels() ) 113 if ( c < iface->channels() )
114 { 114 {
115 QString right; 115 QString right;
116 right.fill( '.', iface->channels()-c ); 116 right.fill( '.', iface->channels()-c );
117 title.append( right ); 117 title.append( right );
118 } 118 }
119 title.append( "]" ); 119 title.append( "]" );
120 //title.append( QString().sprintf( " %02d", c ) ); 120 //title.append( QString().sprintf( " %02d", c ) );
121 assert( parent() ); 121 assert( parent() );
122 ( (QMainWindow*) parent() )->setCaption( title ); 122 ( (QMainWindow*) parent() )->setCaption( title );
123} 123}
124 124
125 125
126void Wellenreiter::handleNotification( OPacket* p ) 126void Wellenreiter::handleNotification( OPacket* p )
127{ 127{
128 QObjectList* l = p->queryList(); 128 QObjectList* l = p->queryList();
129 QObjectListIt it( *l ); 129 QObjectListIt it( *l );
130 QObject* o; 130 QObject* o;
131 131
132 while ( (o = it.current()) != 0 ) 132 while ( (o = it.current()) != 0 )
133 { 133 {
134 QString name = it.current()->name(); 134 QString name = it.current()->name();
135 if ( configwindow->parsePackets->isProtocolChecked( name ) ) 135 if ( configwindow->parsePackets->isProtocolChecked( name ) )
136 { 136 {
137 QString action = configwindow->parsePackets->protocolAction( name ); 137 QString action = configwindow->parsePackets->protocolAction( name );
138 qDebug( "parsePacket-action for '%s' seems to be '%s'", (const char*) name, (const char*) action ); 138 qDebug( "parsePacket-action for '%s' seems to be '%s'", (const char*) name, (const char*) action );
139 doAction( action, name, p ); 139 doAction( action, name, p );
140 } 140 }
141 else 141 else
142 { 142 {
143 qDebug( "protocol '%s' not checked in parsePackets.", (const char*) name ); 143 qDebug( "protocol '%s' not checked in parsePackets.", (const char*) name );
144 } 144 }
145 ++it; 145 ++it;
146 } 146 }
147} 147}
148 148
149 149
150void Wellenreiter::handleBeacon( OPacket* p, OWaveLanManagementPacket* beacon ) 150void Wellenreiter::handleBeacon( OPacket* p, OWaveLanManagementPacket* beacon )
151{ 151{
152 QString type; 152 QString type;
153 if ( beacon->canIBSS() ) 153 if ( beacon->canIBSS() )
154 { 154 {
155 type = "adhoc"; 155 type = "adhoc";
156 } 156 }
157 else if ( beacon->canESS() ) 157 else if ( beacon->canESS() )
158 { 158 {
159 type = "managed"; 159 type = "managed";
160 } 160 }
161 else 161 else
162 { 162 {
163 qWarning( "Wellenreiter::invalid frame [possibly noise] detected!" ); 163 qWarning( "Wellenreiter::invalid frame [possibly noise] detected!" );
164 return; 164 return;
165 } 165 }
166 166
167 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); 167 OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
168 QString essid = ssid ? ssid->ID() : QString("<unknown>"); 168 QString essid = ssid ? ssid->ID() : QString("<unknown>");
169 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); 169 OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
170 int channel = ds ? ds->channel() : -1; 170 int channel = ds ? ds->channel() : -1;
171 171
172 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); 172 OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
173 173
174 GpsLocation loc( 0, 0 ); 174 GpsLocation loc( 0, 0 );
175 if ( configwindow->enableGPS->isChecked() ) 175 if ( configwindow->enableGPS->isChecked() )
176 { 176 {
177 // TODO: add check if GPS is working!? 177 // TODO: add check if GPS is working!?
178 qDebug( "Wellenreiter::gathering GPS data..." ); 178 qDebug( "Wellenreiter::gathering GPS data..." );
179 loc = gps->position(); 179 loc = gps->position();
180 qDebug( "Wellenreiter::GPS data received is ( %f , %f )", loc.latitude, loc.longitude ); 180 qDebug( "Wellenreiter::GPS data received is ( %f , %f )", loc.latitude, loc.longitude );
181 } 181 }
182 182
183 netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc ); 183 netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc );
184 184
185 // update graph window 185 // update graph window
186 if ( ds ) 186 if ( ds )
187 { 187 {
188 OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) ); 188 OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) );
189 if ( prism ) 189 if ( prism )
190 graphwindow->traffic( ds->channel(), prism->signalStrength() ); 190 graphwindow->traffic( ds->channel(), prism->signalStrength() );
191 else 191 else
192 graphwindow->traffic( ds->channel(), 95 ); 192 graphwindow->traffic( ds->channel(), 95 );
193 } 193 }
194} 194}
195 195
196 196
197void Wellenreiter::handleData( OPacket* p, OWaveLanDataPacket* data ) 197void Wellenreiter::handleData( OPacket* p, OWaveLanDataPacket* data )
198{ 198{
199 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); 199 OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" );
200 if ( wlan->fromDS() && !wlan->toDS() ) 200 if ( wlan->fromDS() && !wlan->toDS() )
201 { 201 {
202 netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() ); 202 netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
203 } 203 }
204 else if ( !wlan->fromDS() && wlan->toDS() ) 204 else if ( !wlan->fromDS() && wlan->toDS() )
205 { 205 {
206 netView()->toDStraffic( wlan->macAddress2(), wlan->macAddress3(), wlan->macAddress1() ); 206 netView()->toDStraffic( wlan->macAddress2(), wlan->macAddress3(), wlan->macAddress1() );
207 } 207 }
208 else if ( wlan->fromDS() && wlan->toDS() ) 208 else if ( wlan->fromDS() && wlan->toDS() )
209 { 209 {
210 netView()->WDStraffic( wlan->macAddress4(), wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() ); 210 netView()->WDStraffic( wlan->macAddress4(), wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
211 } 211 }
212 else 212 else
213 { 213 {
214 netView()->IBSStraffic( wlan->macAddress2(), wlan->macAddress1(), wlan->macAddress3() ); 214 netView()->IBSStraffic( wlan->macAddress2(), wlan->macAddress1(), wlan->macAddress3() );
215 } 215 }
216 216
217 OARPPacket* arp = (OARPPacket*) p->child( "ARP" ); 217 OARPPacket* arp = (OARPPacket*) p->child( "ARP" );
218 if ( arp ) 218 if ( arp )
219 { 219 {
220 qDebug( "Received ARP traffic (type '%s'): ", (const char*) arp->type() ); 220 qDebug( "Received ARP traffic (type '%s'): ", (const char*) arp->type() );
221 if ( arp->type() == "REQUEST" ) 221 if ( arp->type() == "REQUEST" )
222 { 222 {
223 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() ); 223 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
224 } 224 }
225 else if ( arp->type() == "REPLY" ) 225 else if ( arp->type() == "REPLY" )
226 { 226 {
227 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() ); 227 netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
228 netView()->identify( arp->targetMacAddress(), arp->targetIPV4Address().toString() ); 228 netView()->identify( arp->targetMacAddress(), arp->targetIPV4Address().toString() );
229 } 229 }
230 } 230 }
231 231
232 OIPPacket* ip = (OIPPacket*) p->child( "IP" ); 232 OIPPacket* ip = (OIPPacket*) p->child( "IP" );
233 if ( ip ) 233 if ( ip )
234 { 234 {
235 qDebug( "Received IP packet." ); 235 qDebug( "Received IP packet." );
236 } 236 }
237} 237}
238 238
239 239
240QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol ) 240QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol )
241{ 241{
242 if ( configwindow->parsePackets->isProtocolChecked( protocol ) ) 242 if ( configwindow->parsePackets->isProtocolChecked( protocol ) )
243 if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" ) 243 if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" )
244 return 0; 244 return 0;
245 245
246 return p->child( protocol ); 246 return p->child( protocol );
247} 247}
248 248
249 249
250bool Wellenreiter::checkDumpPacket( OPacket* p ) 250bool Wellenreiter::checkDumpPacket( OPacket* p )
251{ 251{
252 // go through all child packets and see if one is inside the child hierarchy for p 252 // go through all child packets and see if one is inside the child hierarchy for p
253 // if so, do what the user requested (protocolAction), e.g. pass or discard 253 // if so, do what the user requested (protocolAction), e.g. pass or discard
254 if ( !configwindow->writeCaptureFile->isChecked() ) 254 if ( !configwindow->writeCaptureFile->isChecked() )
255 return false; 255 return false;
256 256
257 QObjectList* l = p->queryList(); 257 QObjectList* l = p->queryList();
258 QObjectListIt it( *l ); 258 QObjectListIt it( *l );
259 QObject* o; 259 QObject* o;
260 260
261 while ( (o = it.current()) != 0 ) 261 while ( (o = it.current()) != 0 )
262 { 262 {
263 QString name = it.current()->name(); 263 QString name = it.current()->name();
264 if ( configwindow->capturePackets->isProtocolChecked( name ) ) 264 if ( configwindow->capturePackets->isProtocolChecked( name ) )
265 { 265 {
266 QString action = configwindow->capturePackets->protocolAction( name ); 266 QString action = configwindow->capturePackets->protocolAction( name );
267 qDebug( "capturePackets-action for '%s' seems to be '%s'", (const char*) name, (const char*) action ); 267 qDebug( "capturePackets-action for '%s' seems to be '%s'", (const char*) name, (const char*) action );
268 if ( action == "Discard" ) 268 if ( action == "Discard" )
269 { 269 {
270 logwindow->log( QString().sprintf( "(i) dump-discarding of '%s' packet requested.", (const char*) name ) ); 270 logwindow->log( QString().sprintf( "(i) dump-discarding of '%s' packet requested.", (const char*) name ) );
271 return false; 271 return false;
272 } 272 }
273 } 273 }
274 else 274 else
275 { 275 {
276 qDebug( "protocol '%s' not checked in capturePackets.", (const char*) name ); 276 qDebug( "protocol '%s' not checked in capturePackets.", (const char*) name );
277 } 277 }
278 ++it; 278 ++it;
279 } 279 }
280 return true; 280 return true;
281} 281}
282 282
283 283
284void Wellenreiter::receivePacket( OPacket* p ) 284void Wellenreiter::receivePacket( OPacket* p )
285{ 285{
286 hexWindow()->log( p->dump( 8 ) ); 286 hexWindow()->log( p->dump( 8 ) );
287 287
288 if ( checkDumpPacket( p ) ) 288 if ( checkDumpPacket( p ) )
289 { 289 {
290 pcap->dump( p ); 290 pcap->dump( p );
291 } 291 }
292 292
293 // check if we received a beacon frame 293 // check if we received a beacon frame
294 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( childIfToParse( p, "802.11 Management" ) ); 294 OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( childIfToParse( p, "802.11 Management" ) );
295 if ( beacon && beacon->managementType() == "Beacon" ) 295 if ( beacon && beacon->managementType() == "Beacon" )
296 { 296 {
297 handleBeacon( p, beacon ); 297 handleBeacon( p, beacon );
298 return; 298 return;
299 } 299 }
300 300
301 //TODO: WEP check here 301 //TODO: WEP check here
302 302
303 // check for a data frame 303 // check for a data frame
304 OWaveLanDataPacket* data = static_cast<OWaveLanDataPacket*>( childIfToParse( p, "802.11 Data" ) ); 304 OWaveLanDataPacket* data = static_cast<OWaveLanDataPacket*>( childIfToParse( p, "802.11 Data" ) );
305 if ( data ) 305 if ( data )
306 { 306 {
307 handleData( p, data ); 307 handleData( p, data );
308 } 308 }
309 309
310 handleNotification( p ); 310 handleNotification( p );
311 311
312} 312}
313 313
314 314
315void Wellenreiter::stopClicked() 315void Wellenreiter::stopClicked()
316{ 316{
317 if ( iface ) 317 if ( iface )
318 { 318 {
319 disconnect( SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); 319 disconnect( SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
320 disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) ); 320 disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
321 iface->setChannelHopping(); // stop hopping channels 321 iface->setChannelHopping(); // stop hopping channels
322 } 322 }
323 else 323 else
324 killTimers(); 324 killTimers();
325 325
326 pcap->close(); 326 pcap->close();
327 sniffing = false; 327 sniffing = false;
328 328
329 if ( iface ) 329 if ( iface )
330 { 330 {
331 // switch off monitor mode 331 // switch off monitor mode
332 iface->setMonitorMode( false ); 332 iface->setMonitorMode( false );
333 // switch off promisc flag 333 // switch off promisc flag
334 iface->setPromiscuousMode( false ); 334 iface->setPromiscuousMode( false );
335 335
336 system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess 336 system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess
337 } 337 }
338 338
339 logwindow->log( "(i) Stopped Scanning." ); 339 logwindow->log( "(i) Stopped Scanning." );
340 assert( parent() ); 340 assert( parent() );
341 ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" ); 341 ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" );
342 342
343 // message the user 343 // message the user
344 QMessageBox::information( this, "Wellenreiter II", 344 QMessageBox::information( this, "Wellenreiter II",
345 tr( "Your wireless card\nshould now be usable again." ) ); 345 tr( "Your wireless card\nshould now be usable again." ) );
346 346
347 sniffing = false; 347 sniffing = false;
348 emit( stoppedSniffing() ); 348 emit( stoppedSniffing() );
349 349
350 #ifdef QWS 350 #ifdef QWS
351 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() ) 351 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() )
352 { 352 {
353 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable; 353 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
354 } 354 }
355 #else 355 #else
356 #warning FIXME: setScreenSaverMode is not operational on the X11 build 356 #warning FIXME: setScreenSaverMode is not operational on the X11 build
357 #endif 357 #endif
358 358
359 // print out statistics 359 // print out statistics
360 for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it ) 360 for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it )
361 statwindow->updateCounter( it.key(), it.data() ); 361 statwindow->updateCounter( it.key(), it.data() );
362} 362}
363 363
364 364
365void Wellenreiter::startClicked() 365void Wellenreiter::startClicked()
366{ 366{
367 // get configuration from config window 367 // get configuration from config window
368 368
369 const QString& interface = configwindow->interfaceName->currentText(); 369 const QString& interface = configwindow->interfaceName->currentText();
370 const int cardtype = configwindow->driverType(); 370 const int cardtype = configwindow->driverType();
371 const int interval = configwindow->hoppingInterval(); 371 const int interval = configwindow->hoppingInterval();
372 372
373 if ( ( interface == "" ) || ( cardtype == 0 ) ) 373 if ( ( interface == "" ) || ( cardtype == 0 ) )
374 { 374 {
375 QMessageBox::information( this, "Wellenreiter II", 375 QMessageBox::information( this, "Wellenreiter II",
376 tr( "Your device is not\nproperly configured. Please reconfigure!" ) ); 376 tr( "Your device is not\nproperly configured. Please reconfigure!" ) );
377 return; 377 return;
378 } 378 }
379 379
380 // configure device 380 // configure device
381 ONetwork* net = ONetwork::instance(); 381 ONetwork* net = ONetwork::instance();
382 382
383 // TODO: check if interface is wireless and support sniffing for non-wireless interfaces 383 // TODO: check if interface is wireless and support sniffing for non-wireless interfaces
384 384
385 iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // fails if network is not wireless! 385 iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // fails if network is not wireless!
386 386
387 // bring device UP 387 // bring device UP
388 iface->setUp( true ); 388 if ( cardtype != DEVTYPE_FILE )
389 if ( !iface->isUp() )
390 { 389 {
391 QMessageBox::warning( this, "Wellenreiter II", 390 iface->setUp( true );
392 tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) ); 391 if ( !iface->isUp() )
393 return; 392 {
393 QMessageBox::warning( this, "Wellenreiter II",
394 tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) );
395 return;
396 }
394 } 397 }
395
396 // set monitor mode 398 // set monitor mode
397 bool usePrism = configwindow->usePrismHeader(); 399 bool usePrism = configwindow->usePrismHeader();
398 400
399 switch ( cardtype ) 401 switch ( cardtype )
400 { 402 {
401 case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break; 403 case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break;
402 case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break; 404 case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break;
403 case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break; 405 case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break;
404 case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break; 406 case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break;
405 case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", tr( "Bring your device into\nmonitor mode now." ) ); break; 407 case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", tr( "Bring your device into\nmonitor mode now." ) ); break;
406 case DEVTYPE_FILE: qDebug( "Wellenreiter: Capturing from file '%s'", (const char*) interface ); break; 408 case DEVTYPE_FILE: qDebug( "Wellenreiter: Capturing from file '%s'", (const char*) interface ); break;
407 default: assert( 0 ); // shouldn't reach this 409 default: assert( 0 ); // shouldn't reach this
408 } 410 }
409 411
410 // switch device into monitor mode 412 // switch device into monitor mode
411 if ( cardtype < DEVTYPE_FILE ) 413 if ( cardtype < DEVTYPE_FILE )
412 { 414 {
413 if ( cardtype != DEVTYPE_MANUAL ) 415 if ( cardtype != DEVTYPE_MANUAL )
414 iface->setMonitorMode( true ); 416 iface->setMonitorMode( true );
415 if ( !iface->monitorMode() ) 417 if ( !iface->monitorMode() )
416 { 418 {
417 if ( QMessageBox::warning( this, "Wellenreiter II", 419 if ( QMessageBox::warning( this, "Wellenreiter II",
418 tr( "Can't set interface '%1'\ninto monitor mode:\n" ).arg( iface->name() ) + strerror( errno ) + 420 tr( "Can't set interface '%1'\ninto monitor mode:\n" ).arg( iface->name() ) + strerror( errno ) +
419 tr( "\nContinue with limited functionality?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No ) 421 tr( "\nContinue with limited functionality?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
420 return; 422 return;
421 } 423 }
422 } 424 }
423 425
424 // open GPS device 426 // open GPS device
425 if ( configwindow->enableGPS->isChecked() ) 427 if ( configwindow->enableGPS->isChecked() )
426 { 428 {
427 qDebug( "Wellenreiter:GPS enabled @ %s:%d", (const char*) configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() ); 429 qDebug( "Wellenreiter:GPS enabled @ %s:%d", (const char*) configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() );
428 gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() ); 430 gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() );
429 } 431 }
430 432
431 // open pcap and start sniffing 433 // open pcap and start sniffing
432 if ( cardtype != DEVTYPE_FILE ) 434 if ( cardtype != DEVTYPE_FILE )
433 { 435 {
434 pcap->open( interface ); 436 pcap->open( interface );
435 437
436 if ( configwindow->writeCaptureFile->isChecked() ) 438 if ( configwindow->writeCaptureFile->isChecked() )
437 { 439 {
438 QString dumpname( configwindow->captureFileName->text() ); 440 QString dumpname( configwindow->captureFileName->text() );
439 if ( dumpname.isEmpty() ) dumpname = "captureFile"; 441 if ( dumpname.isEmpty() ) dumpname = "captureFile";
440 dumpname.append( '-' ); 442 dumpname.append( '-' );
441 dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) ); 443 dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) );
442 dumpname.append( ".wellenreiter" ); 444 dumpname.append( ".wellenreiter" );
443 pcap->openDumpFile( dumpname ); 445 pcap->openDumpFile( dumpname );
444 } 446 }
445 else 447 else
446 { 448 {
447 pcap->open( interface ); 449 pcap->open( interface );
448 } 450 }
449 } 451 }
450 else 452 else
451 { 453 {
452 pcap->open( QFile( interface ) ); 454 pcap->open( QFile( interface ) );
453 } 455 }
454 456
455 if ( !pcap->isOpen() ) 457 if ( !pcap->isOpen() )
456 { 458 {
457 QMessageBox::warning( this, "Wellenreiter II", 459 QMessageBox::warning( this, "Wellenreiter II", tr( "Can't open packet capturer for\n'%1':\n" ).arg(
458 tr( "Can't open packet capturer for '%1':\n" ).arg( iface->name() ) + QString(strerror( errno ) )); 460 cardtype == DEVTYPE_FILE ? (const char*) interface : iface->name() ) + QString(strerror( errno ) ));
459 return; 461 return;
460 } 462 }
461 463
462 // set capturer to non-blocking mode 464 // set capturer to non-blocking mode
463 pcap->setBlocking( false ); 465 pcap->setBlocking( false );
464 466
465 // start channel hopper 467 // start channel hopper
466 if ( cardtype != DEVTYPE_FILE ) 468 if ( cardtype != DEVTYPE_FILE )
467 { 469 {
468 logwindow->log( QString().sprintf( "(i) Starting channel hopper (d=%d ms)", configwindow->hopInterval->value() ) ); 470 logwindow->log( QString().sprintf( "(i) Starting channel hopper (d=%d ms)", configwindow->hopInterval->value() ) );
469 iface->setChannelHopping( configwindow->hopInterval->value() ); //use interval from config window 471 iface->setChannelHopping( configwindow->hopInterval->value() ); //use interval from config window
470 } 472 }
471 473
472 if ( cardtype != DEVTYPE_FILE ) 474 if ( cardtype != DEVTYPE_FILE )
473 { 475 {
474 // connect socket notifier and start channel hopper 476 // connect socket notifier and start channel hopper
475 connect( pcap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); 477 connect( pcap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
476 connect( iface->channelHopper(), SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) ); 478 connect( iface->channelHopper(), SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
477 } 479 }
478 else 480 else
479 { 481 {
480 // start timer for reading packets 482 // start timer for reading packets
481 startTimer( 100 ); 483 startTimer( 100 );
482 } 484 }
483 485
484 logwindow->log( "(i) Started Scanning." ); 486 logwindow->log( "(i) Started Scanning." );
485 sniffing = true; 487 sniffing = true;
486 488
487 #ifdef QWS 489 #ifdef QWS
488 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() ) 490 if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() )
489 { 491 {
490 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable; 492 QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable;
491 } 493 }
492 #else 494 #else
493 #warning FIXME: setScreenSaverMode is not operational on the X11 build 495 #warning FIXME: setScreenSaverMode is not operational on the X11 build
494 #endif 496 #endif
495 497
496 emit( startedSniffing() ); 498 emit( startedSniffing() );
497 if ( cardtype != DEVTYPE_FILE ) channelHopped( 6 ); // set title 499 if ( cardtype != DEVTYPE_FILE ) channelHopped( 6 ); // set title
498 else 500 else
499 { 501 {
500 assert( parent() ); 502 assert( parent() );
501 ( (QMainWindow*) parent() )->setCaption( tr( "Wellenreiter II - replaying capture file..." ) ); 503 ( (QMainWindow*) parent() )->setCaption( tr( "Wellenreiter II - replaying capture file..." ) );
502 } 504 }
503} 505}
504 506
505 507
506void Wellenreiter::timerEvent( QTimerEvent* ) 508void Wellenreiter::timerEvent( QTimerEvent* )
507{ 509{
508 qDebug( "Wellenreiter::timerEvent()" ); 510 qDebug( "Wellenreiter::timerEvent()" );
509 OPacket* p = pcap->next(); 511 OPacket* p = pcap->next();
510 if ( !p ) // no more packets available 512 if ( !p ) // no more packets available
511 { 513 {
512 stopClicked(); 514 stopClicked();
513 } 515 }
514 else 516 else
515 { 517 {
516 receivePacket( p ); 518 receivePacket( p );
517 delete p; 519 delete p;
518 } 520 }
519} 521}
520 522
521 523
522void Wellenreiter::doAction( const QString& action, const QString& protocol, OPacket* p ) 524void Wellenreiter::doAction( const QString& action, const QString& protocol, OPacket* p )
523{ 525{
524 #ifdef QWS 526 #ifdef QWS
525 if ( action == "TouchSound" ) 527 if ( action == "TouchSound" )
526 ODevice::inst()->touchSound(); 528 ODevice::inst()->touchSound();
527 else if ( action == "AlarmSound" ) 529 else if ( action == "AlarmSound" )
528 ODevice::inst()->alarmSound(); 530 ODevice::inst()->alarmSound();
529 else if ( action == "KeySound" ) 531 else if ( action == "KeySound" )
530 ODevice::inst()->keySound(); 532 ODevice::inst()->keySound();
531 else if ( action == "LedOn" ) 533 else if ( action == "LedOn" )
532 ODevice::inst()->setLedState( Led_Mail, Led_On ); 534 ODevice::inst()->setLedState( Led_Mail, Led_On );
533 else if ( action == "LedOff" ) 535 else if ( action == "LedOff" )
534 ODevice::inst()->setLedState( Led_Mail, Led_Off ); 536 ODevice::inst()->setLedState( Led_Mail, Led_Off );
535 else if ( action == "LogMessage" ) 537 else if ( action == "LogMessage" )
536 logwindow->log( QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) ); 538 logwindow->log( QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) );
537 else if ( action == "MessageBox" ) 539 else if ( action == "MessageBox" )
538 QMessageBox::information( this, "Notification!", 540 QMessageBox::information( this, "Notification!",
539 QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) ); 541 QString().sprintf( "Got packet with protocol '%s'", (const char*) protocol ) );
540 #else 542 #else
541 #warning Actions do not work with Qt/X11 yet 543 #warning Actions do not work with Qt/X11 yet
542 #endif 544 #endif
543} 545}
544 546
545void Wellenreiter::joinNetwork(const QString& type, const QString& essid, int channel, const QString& macaddr) 547void Wellenreiter::joinNetwork(const QString& type, const QString& essid, int channel, const QString& macaddr)
546{ 548{
547 #ifdef QWS 549 #ifdef QWS
548 if ( !iface ) 550 if ( !iface )
549 { 551 {
550 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "No wireless\ninterface available." ) ); 552 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "No wireless\ninterface available." ) );
551 return; 553 return;
552 } 554 }
553 555
554 if ( sniffing ) 556 if ( sniffing )
555 { 557 {
556 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Stop sniffing before\njoining a net." ) ); 558 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Stop sniffing before\njoining a net." ) );
557 return; 559 return;
558 } 560 }
559 561
560 qDebug( "joinNetwork() with Interface %s: %s, %s, %d, %s", 562 qDebug( "joinNetwork() with Interface %s: %s, %s, %d, %s",
561 (const char*) iface->name(), 563 (const char*) iface->name(),
562 (const char*) type, 564 (const char*) type,
563 (const char*) essid, 565 (const char*) essid,
564 channel, 566 channel,
565 (const char*) macaddr ); 567 (const char*) macaddr );
566 568
567 QCopEnvelope msg( "QPE/Application/networksettings", "wlan(QString,QString,QString)" ); 569 QCopEnvelope msg( "QPE/Application/networksettings", "wlan(QString,QString,QString)" );
568 int count = 3; 570 int count = 3;
569 qDebug("sending %d messages",count); 571 qDebug("sending %d messages",count);
570 msg << QString("count") << QString::number(count); 572 msg << QString("count") << QString::number(count);
571 qDebug("msg >%s< Mode >%s<", iface->name(),type.latin1() ); 573 qDebug("msg >%s< Mode >%s<", iface->name(),type.latin1() );
572 msg << QString(iface->name()) << QString("Mode") << type; 574 msg << QString(iface->name()) << QString("Mode") << type;
573 qDebug("msg >%s< essid >%s<", iface->name(),essid.latin1()); 575 qDebug("msg >%s< essid >%s<", iface->name(),essid.latin1());
574 msg << QString(iface->name()) << QString("ESSID") << essid; 576 msg << QString(iface->name()) << QString("ESSID") << essid;
575 qDebug("msg >%s< channel >%d<", iface->name(),channel); 577 qDebug("msg >%s< channel >%d<", iface->name(),channel);
576 msg << QString(iface->name()) << QString("Channel") << channel; 578 msg << QString(iface->name()) << QString("Channel") << channel;
577// qDebug("msg >%s< mac >%s<", iface->name(),macaddr); 579// qDebug("msg >%s< mac >%s<", iface->name(),macaddr);
578// msg << QString(iface->name()) << QString("MacAddr") << macaddr; 580// msg << QString(iface->name()) << QString("MacAddr") << macaddr;
579 #else 581 #else
580 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Function only available on Embedded build" ) ); 582 QMessageBox::warning( this, tr( "Can't do that!" ), tr( "Function only available on Embedded build" ) );
581 #endif 583 #endif
582 584
583} 585}
584 586