Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

wellenreiter.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2002-2004 Michael 'Mickey' Lauer.  All rights reserved.
00003 **
00004 ** This file may be distributed and/or modified under the terms of the
00005 ** GNU General Public License version 2 as published by the Free Software
00006 ** Foundation and appearing in the file LICENSE.GPL included in the
00007 ** packaging of this file.
00008 **
00009 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00010 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00011 **
00012 ***********************************************************************/
00013 
00014 #include "gps.h"
00015 #include "wellenreiter.h"
00016 #include "scanlist.h"
00017 #include "logwindow.h"
00018 #include "packetview.h"
00019 #include "configwindow.h"
00020 #include "statwindow.h"
00021 #include "graphwindow.h"
00022 #include "protolistview.h"
00023 
00024 /* OPIE */
00025 #ifdef QWS
00026 #include <opie2/oapplication.h>
00027 #include <opie2/odebug.h>
00028 #include <opie2/odevice.h>
00029 #else
00030 #include <qapplication.h>
00031 #endif
00032 #include <opie2/omanufacturerdb.h>
00033 #include <opie2/onetwork.h>
00034 #include <opie2/opcap.h>
00035 #include <qpe/qcopenvelope_qws.h>
00036 
00037 /* QT */
00038 #include <qcheckbox.h>
00039 #include <qcombobox.h>
00040 #include <qdatetime.h>
00041 #include <qpushbutton.h>
00042 #include <qlineedit.h>
00043 #include <qmessagebox.h>
00044 #include <qobjectlist.h>
00045 #include <qregexp.h>
00046 #include <qspinbox.h>
00047 #include <qtimer.h>
00048 #include <qtoolbutton.h>
00049 #include <qmainwindow.h>
00050 
00051 /* STD */
00052 #include <assert.h>
00053 #include <errno.h>
00054 #include <unistd.h>
00055 #include <string.h>
00056 #include <sys/types.h>
00057 #include <stdlib.h>
00058 #include <signal.h>
00059 
00060 
00061 using namespace Opie::Core;
00062 using namespace Opie::Net;
00063 using namespace Opie::Ui;
00064 
00065 Wellenreiter* Wellenreiter::instance = 0;
00066 
00067 Wellenreiter::Wellenreiter( QWidget* parent )
00068     : WellenreiterBase( parent, 0, 0 ),
00069       sniffing( false ), iface( 0 ), configwindow( 0 )
00070 {
00071 
00072     logwindow->log( "(i) Wellenreiter has been started." );
00073 
00074     //
00075     // detect operating system
00076     //
00077 
00078     #ifdef QWS
00079     QString sys = QString( "(i) Running on '%1'.").arg( ODevice::inst()->systemString() );
00080     _system = ODevice::inst()->system();
00081     logwindow->log( sys );
00082     #endif
00083 
00084     netview->setColumnWidthMode( 1, QListView::Manual );
00085     pcap = new OPacketCapturer();
00086     pcap->setAutoDelete( false );
00087 
00088     gps = new GPS( this );
00089 
00090     QTimer::singleShot( 1000, this, SLOT( initialTimer() ) );
00091 
00092     registerSignalHandler();
00093 }
00094 
00095 
00096 Wellenreiter::~Wellenreiter()
00097 {
00098     delete pcap;
00099     //unregisterSignalHandler();
00100 }
00101 
00102 
00103 void Wellenreiter::initialTimer()
00104 {
00105     odebug << "preloading manufacturer database..." << oendl;
00106     OManufacturerDB::instance();
00107 }
00108 
00109 
00110 void Wellenreiter::signalHandler( int sig )
00111 {
00112     Q_UNUSED( sig )
00113     oerr << "Aye! Received SIGSEGV or SIGBUS! Trying to exit gracefully..." << oendl;
00114     if ( Wellenreiter::instance->sniffing )
00115     {
00116         Wellenreiter::instance->pcap->closeDumpFile();
00117         Wellenreiter::instance->pcap->close();
00118         Wellenreiter::instance->stopClicked();
00119     }
00120     oerr << "Phew. Seemed to work." << oendl;
00121     ::exit( -1 );
00122 }
00123 
00124 
00125 void Wellenreiter::registerSignalHandler()
00126 {
00127     Wellenreiter::instance = this;
00128     struct sigaction action;
00129 
00130     action.sa_handler = Wellenreiter::signalHandler;
00131     if (sigemptyset(&action.sa_mask))
00132         oerr << "sigemptyset() failure:" << strerror( errno ) << oendl;
00133     if (sigaction(SIGSEGV, &action, NULL))
00134         oerr << "can't set up a signal handler for SIGSEGV:" << strerror( errno ) << oendl;
00135     if (sigaction(SIGBUS, &action, NULL))
00136         oerr << "can't set up a signal handler for SIGBUS:" << strerror( errno ) << oendl;
00137     odebug << "signal handlers setup." << oendl;
00138 }
00139 
00140 
00141 void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw )
00142 {
00143     configwindow = cw;
00144 }
00145 
00146 
00147 void Wellenreiter::channelHopped(int c)
00148 {
00149     QString title = "Wellenreiter II -scan- [";
00150     QString left;
00151     if ( c > 1 ) left.fill( '.', c-1 );
00152     title.append( left );
00153     title.append( '|' );
00154     if ( c < iface->channels() )
00155     {
00156         QString right;
00157         right.fill( '.', iface->channels()-c );
00158         title.append( right );
00159     }
00160     title.append( "]" );
00161     //title.append( QString().sprintf( " %02d", c ) );
00162     assert( parent() );
00163     ( (QMainWindow*) parent() )->setCaption( title );
00164 }
00165 
00166 
00167 void Wellenreiter::handleNotification( OPacket* p )
00168 {
00169     QObjectList* l = p->queryList();
00170     QObjectListIt it( *l );
00171     QObject* o;
00172 
00173     while ( (o = it.current()) != 0 )
00174     {
00175         QString name = it.current()->name();
00176         if ( configwindow->parsePackets->isProtocolChecked( name ) )
00177         {
00178             QString action = configwindow->parsePackets->protocolAction( name );
00179             odebug << "parsePacket-action for '" << name << "' seems to be '" << action << "'" << oendl;
00180             doAction( action, name, p );
00181         }
00182         else
00183         {
00184             odebug << "protocol '" << name << "' not checked in parsePackets." << oendl;
00185         }
00186     ++it;
00187     }
00188 }
00189 
00190 
00191 void Wellenreiter::handleManagementFrame( OPacket* p, OWaveLanManagementPacket* manage )
00192 {
00193     if ( manage->managementType() == "Beacon" ) handleManagementFrameBeacon( p, manage );
00194     else if ( manage->managementType() == "ProbeRequest" ) handleManagementFrameProbeRequest( p, manage );
00195     else if ( manage->managementType() == "ProbeResponse" ) handleManagementFrameProbeResponse( p, manage );
00196     else owarn << "Wellenreiter::handleManagementFrame(): '" << manage->managementType() << "' - please handle me!" << oendl;
00197 }
00198 
00199 
00200 void Wellenreiter::handleManagementFrameProbeRequest( OPacket* p, OWaveLanManagementPacket* /* request */ )
00201 {
00202     OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
00203     QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>");
00204 //    OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
00205 //    int channel = ds ? ds->channel() : -1;
00206     OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
00207 
00208     GpsLocation loc( -111, -111 );
00209     if ( configwindow->enableGPS->isChecked() )
00210     {
00211         // TODO: add check if GPS is working!?
00212         odebug << "Wellenreiter::gathering GPS data..." << oendl;
00213         loc = gps->position();
00214         odebug << "Wellenreiter::GPS data received is ( " << loc.latitude() << " , " << loc.longitude() << " ) - dms string = '" << loc.dmsPosition().latin1() << "'" << oendl;
00215     }
00216 
00217     if ( essid.length() )
00218         netView()->addNewItem( "adhoc", essid, header->macAddress2(), false /* should check FrameControl field */, -1, 0, loc, true /* only probed */ );
00219     odebug << "Wellenreiter::invalid frame [possibly noise] detected!" << oendl;
00220 }
00221 
00222 
00223 void Wellenreiter::handleManagementFrameProbeResponse( OPacket* /* p */, OWaveLanManagementPacket* /* response */ )
00224 {
00225 }
00226 
00227 
00228 void Wellenreiter::handleManagementFrameBeacon( OPacket* p, OWaveLanManagementPacket* beacon  )
00229 {
00230     QString type;
00231     if ( beacon->canIBSS() )
00232     {
00233         type = "adhoc";
00234     }
00235     else if ( beacon->canESS() )
00236     {
00237         type = "managed";
00238     }
00239     else
00240     {
00241         owarn << "Wellenreiter::invalid frame [possibly noise] detected!" << oendl;
00242         return;
00243     }
00244 
00245     OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
00246     QString essid = ssid ? ssid->ID( true /* decloak */ ) : QString("<unknown>");
00247     OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
00248     int channel = ds ? ds->channel() : -1;
00249 
00250     OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
00251 
00252     GpsLocation loc( -111, -111 );
00253     if ( configwindow->enableGPS->isChecked() )
00254     {
00255         // TODO: add check if GPS is working!?
00256         odebug << "Wellenreiter::gathering GPS data..." << oendl;
00257         loc = gps->position();
00258         odebug << "Wellenreiter::GPS data received is ( " << loc.latitude() << " , " << loc.longitude() << " ) - dms string = '" << loc.dmsPosition().latin1() << "'" << oendl;
00259     }
00260 
00261     netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc );
00262 
00263     // update graph window
00264     if ( ds )
00265     {
00266         OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) );
00267         if ( prism )
00268             graphwindow->traffic( ds->channel(), prism->signalStrength() );
00269         else
00270             graphwindow->traffic( ds->channel(), 95 );
00271     }
00272 }
00273 
00274 
00275 void Wellenreiter::handleControlFrame( OPacket* p, OWaveLanControlPacket* control )
00276 {
00277     OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
00278 
00279     if ( control->controlType() == "Acknowledge" )
00280     {
00281         netView()->addNewItem( "adhoc", "<unknown>", header->macAddress1(), false, -1, 0, GpsLocation( -111, -111 ) );
00282     }
00283     else
00284     {
00285         odebug << "Wellenreiter::handleControlFrame - please handle " << control->controlType() << " in a future version! :D" << oendl;
00286     }
00287 }
00288 
00289 
00290 void Wellenreiter::handleWlanData( OPacket* p, OWaveLanDataPacket* /* data */ , OMacAddress& from, OMacAddress& to )
00291 {
00292     OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" );
00293     if ( wlan->fromDS() && !wlan->toDS() )
00294     {
00295         netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
00296         from = wlan->macAddress3();
00297         to = wlan->macAddress2();
00298     }
00299     else if ( !wlan->fromDS() && wlan->toDS() )
00300     {
00301         netView()->toDStraffic( wlan->macAddress2(), wlan->macAddress3(), wlan->macAddress1() );
00302         from = wlan->macAddress2();
00303         to = wlan->macAddress3();
00304     }
00305     else if ( wlan->fromDS() && wlan->toDS() )
00306     {
00307         netView()->WDStraffic( wlan->macAddress4(), wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
00308         from = wlan->macAddress4();
00309         to = wlan->macAddress3();
00310     }
00311     else
00312     {
00313         netView()->IBSStraffic( wlan->macAddress2(), wlan->macAddress1(), wlan->macAddress3() );
00314         from = wlan->macAddress2();
00315         to = wlan->macAddress1();
00316     }
00317 }
00318 
00319 
00320 void Wellenreiter::handleEthernetData( OPacket* /* p */, OEthernetPacket* data, OMacAddress& from, OMacAddress& to )
00321 {
00322     from = data->sourceAddress();
00323     to = data->destinationAddress();
00324 
00325     netView()->addNewItem( "station", "<wired>", from, false, -1, 0, GpsLocation( -111, -111 ) );
00326 }
00327 
00328 
00329 void Wellenreiter::handleARPData( OPacket* p, OARPPacket*, OMacAddress& /* source */, OMacAddress& /* dest */ )
00330 {
00331     OARPPacket* arp = (OARPPacket*) p->child( "ARP" );
00332     if ( arp )
00333     {
00334         odebug << "Received ARP traffic (type '" << arp->type() << "'): " << oendl;
00335         if ( arp->type() == "REQUEST" )
00336         {
00337             netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
00338         }
00339         else if ( arp->type() == "REPLY" )
00340         {
00341             netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
00342             netView()->identify( arp->targetMacAddress(), arp->targetIPV4Address().toString() );
00343         }
00344     }
00345 }
00346 
00347 
00348 void Wellenreiter::handleIPData( OPacket* p, OIPPacket* /* ip */, OMacAddress& source, OMacAddress& /* dest */ )
00349 {
00350     //TODO: Implement more IP based protocols
00351 
00352     ODHCPPacket* dhcp = (ODHCPPacket*) p->child( "DHCP" );
00353     if ( dhcp )
00354     {
00355         odebug << "Received DHCP '" << dhcp->type() << "' packet" << oendl;
00356         if ( dhcp->type() == "OFFER" )
00357         {
00358             odebug << "DHCP: '" << source.toString() << "' ('" << dhcp->serverAddress().toString() << "') seems to be a DHCP server." << oendl;
00359             netView()->identify( source, dhcp->serverAddress().toString() );
00360             netView()->addService( "DHCP", source, dhcp->serverAddress().toString() );
00361         }
00362         else if ( dhcp->type() == "ACK" )
00363         {
00364             odebug << "DHCP: '" << dhcp->clientMacAddress().toString() << "' ('" << dhcp->yourAddress().toString() << "') accepted the offered DHCP address." << oendl;
00365             netView()->identify( dhcp->clientMacAddress(), dhcp->yourAddress().toString() );
00366         }
00367     }
00368 }
00369 
00370 
00371 QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol )
00372 {
00373     if ( configwindow->parsePackets->isProtocolChecked( protocol ) )
00374         if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" )
00375             return 0;
00376 
00377     return p->child( protocol );
00378 }
00379 
00380 
00381 bool Wellenreiter::checkDumpPacket( OPacket* p )
00382 {
00383     // go through all child packets and see if one is inside the child hierarchy for p
00384     // if so, do what the user requested (protocolAction), e.g. pass or discard
00385     if ( !configwindow->writeCaptureFile->isChecked() )
00386         return true; // semantic change - we're logging anyway now to /tmp/wellenreiter
00387 
00388     QObjectList* l = p->queryList();
00389     QObjectListIt it( *l );
00390     QObject* o;
00391 
00392     while ( (o = it.current()) != 0 )
00393     {
00394         QString name = it.current()->name();
00395         if ( configwindow->capturePackets->isProtocolChecked( name ) )
00396         {
00397             QString action = configwindow->capturePackets->protocolAction( name );
00398             odebug << "capturePackets-action for '" << name << "' seems to be '" << action << "'" << oendl;
00399             if ( action == "Discard" )
00400             {
00401                 logwindow->log( QString("(i) dump-discarding of '%1' packet requested." ).arg( name ) );
00402                 return false;
00403             }
00404         }
00405         else
00406         {
00407             odebug << "protocol '" << name << "' not checked in capturePackets." << oendl;
00408         }
00409     ++it;
00410     }
00411     return true;
00412 }
00413 
00414 
00415 void Wellenreiter::receivePacket( OPacket* p )
00416 {
00417     hexWindow()->add( p, configwindow->hexViewBuffer() );
00418 
00419     if ( checkDumpPacket( p ) )
00420     {
00421         pcap->dump( p );
00422     }
00423 
00424     // check for a management frame
00425     OWaveLanManagementPacket* manage = static_cast<OWaveLanManagementPacket*>( childIfToParse( p, "802.11 Management" ) );
00426     if ( manage )
00427     {
00428         handleManagementFrame( p, manage );
00429         return;
00430     }
00431 
00432     // check for a control frame
00433     OWaveLanControlPacket* control = static_cast<OWaveLanControlPacket*>( childIfToParse( p, "802.11 Control" ) );
00434     if ( control )
00435     {
00436         handleControlFrame( p, control );
00437         return;
00438     }
00439 
00440     OMacAddress source;
00441     OMacAddress dest;
00442 
00443     //TODO: WEP check here
00444 
00445     // check for a wireless data frame
00446     OWaveLanDataPacket* wlan = static_cast<OWaveLanDataPacket*>( childIfToParse( p, "802.11 Data" ) );
00447     if ( wlan )
00448     {
00449         handleWlanData( p, wlan, source, dest );
00450     }
00451 
00452     // check for a wired data frame
00453     OEthernetPacket* eth = static_cast<OEthernetPacket*>( childIfToParse( p, "Ethernet" ) );
00454     if ( eth )
00455     {
00456         handleEthernetData( p, eth, source, dest );
00457     }
00458 
00459     // check for an arp frame since arp frames come in two flavours:
00460     // 802.11 encapsulates ARP data within IP packets while wired ethernet doesn't.
00461     OARPPacket* arp = static_cast<OARPPacket*>( childIfToParse( p, "ARP" ) );
00462     if ( arp )
00463     {
00464         handleARPData( p, arp, source, dest );
00465     }
00466 
00467     // check for a ip frame
00468     OIPPacket* ip = static_cast<OIPPacket*>( childIfToParse( p, "IP" ) );
00469     if ( ip )
00470     {
00471         handleIPData( p, ip, source, dest );
00472     }
00473 
00474     //handleNotification( p );
00475 
00476 }
00477 
00478 
00479 void Wellenreiter::stopClicked()
00480 {
00481     if ( iface )
00482     {
00483         disconnect( SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) );
00484         disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
00485         iface->setChannelHopping(); // stop hopping channels
00486     }
00487     else
00488         killTimers();
00489 
00490     pcap->close();
00491     sniffing = false;
00492 
00493     if ( iface )
00494     {
00495         // switch off monitor mode
00496         iface->setMode( "managed" );
00497         // switch off promisc flag
00498         iface->setPromiscuousMode( false );
00499 
00500         system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess
00501     }
00502 
00503     logwindow->log( "(i) Stopped Scanning." );
00504     assert( parent() );
00505     ( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" );
00506 
00507     // message the user
00508     QMessageBox::information( this, "Wellenreiter II",
00509                               tr( "Your wireless card\nshould now be usable again." ) );
00510 
00511     sniffing = false;
00512     emit( stoppedSniffing() );
00513 
00514     #ifdef QWS
00515     if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() )
00516     {
00517         QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
00518     }
00519     #else
00520         #warning FIXME: setScreenSaverMode is not operational on the X11 build
00521     #endif
00522 
00523     updateStatistics();
00524 }
00525 
00526 
00527 void Wellenreiter::startClicked()
00528 {
00529     // get configuration from config window
00530 
00531     const QString& interface = configwindow->interfaceName->currentText();
00532     const int cardtype = configwindow->driverType();
00533 //    const int interval = configwindow->hoppingInterval();
00534 
00535     if ( ( interface == "" ) || ( cardtype == 0 ) )
00536     {
00537         QMessageBox::information( this, "Wellenreiter II",
00538                                   tr( "No device configured.\nPlease reconfigure!" ) );
00539         return;
00540     }
00541 
00542     // configure device
00543     ONetwork* net = ONetwork::instance();
00544 
00545     // TODO: check if interface is wireless and support sniffing for non-wireless interfaces
00546 
00547     if ( cardtype != DEVTYPE_FILE )
00548     {
00549 
00550         if ( !net->isPresent( interface ) )
00551         {
00552             QMessageBox::information( this, "Wellenreiter II",
00553                                     tr( "The configured device (%1)\nis not available on this system\n. Please reconfigure!" ).arg( interface ) );
00554             return;
00555         }
00556 
00557         iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // fails if network is not wireless!
00558         assert( iface );
00559 
00560         // bring device UP
00561         iface->setUp( true );
00562         if ( !iface->isUp() )
00563         {
00564             QMessageBox::warning( this, "Wellenreiter II",
00565                                 tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) );
00566             return;
00567         }
00568 
00569         // check if wireless extension version matches
00570         if ( ONetwork::wirelessExtensionCompileVersion() != iface->wirelessExtensionDriverVersion()
00571              && ( ONetwork::wirelessExtensionCompileVersion() <= 15 || iface->wirelessExtensionDriverVersion() <= 15 ) )
00572         {
00573             QMessageBox::critical( this, "Wellenreiter II", tr( "<p>The Wireless Extension Versions<br>do not match!<p>"
00574                                     "  Wellenreiter II : WE V%1<br>Interface driver: WE V%2" )
00575                                     .arg( QString::number( ONetwork::wirelessExtensionCompileVersion() ) )
00576                                     .arg( QString::number( iface->wirelessExtensionDriverVersion() ) ) );
00577             return;
00578         }
00579     }
00580     // set monitor mode
00581     bool usePrism = configwindow->usePrismHeader();
00582 
00583     switch ( cardtype )
00584     {
00585         case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break;
00586         case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break;
00587         case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break;
00588         case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break;
00589         case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", tr( "Bring your device into\nmonitor mode now." ) ); break;
00590         case DEVTYPE_FILE: odebug << "Wellenreiter: Capturing from file '" << interface << "'" << oendl;  break;
00591         default: assert( 0 ); // shouldn't reach this
00592     }
00593 
00594     // switch device into monitor mode
00595     if ( cardtype < DEVTYPE_FILE )
00596     {
00597         if ( cardtype != DEVTYPE_MANUAL )
00598             iface->setMode( "monitor" );
00599         if ( iface->mode() != "monitor" )
00600         {
00601             if ( QMessageBox::warning( this, "Wellenreiter II",
00602                                   tr( "Can't set interface '%1'\ninto monitor mode:\n" ).arg( iface->name() ) + strerror( errno ) +
00603                                   tr( "\nContinue with limited functionality?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
00604                 return;
00605         }
00606     }
00607 
00608     // open GPS device
00609     if ( configwindow->enableGPS->isChecked() )
00610     {
00611         odebug << "Wellenreiter:GPS enabled @ " << configwindow->gpsdHost->currentText() << ":" << configwindow->gpsdPort->value() << "" << oendl;
00612         gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() );
00613     }
00614 
00615     // open pcap and start sniffing
00616 
00617     if ( configwindow->writeCaptureFile->isChecked() ) // write to a user specified capture file?
00618     {
00619         dumpname = configwindow->captureFileName->text();
00620         if ( dumpname.isEmpty() ) dumpname = "captureFile";
00621         dumpname.append( '-' );
00622         dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) );
00623         dumpname.append( ".wellenreiter" );
00624     }
00625 
00626     if ( cardtype != DEVTYPE_FILE )
00627         pcap->open( interface );
00628     else
00629         pcap->openCaptureFile( interface );
00630 
00631     if ( configwindow->writeCaptureFile->isChecked() )
00632     {
00633         odebug << "Wellenreiter:: dumping to " << dumpname << oendl;
00634         pcap->openDumpFile( dumpname );
00635     }
00636 
00637     if ( !pcap->isOpen() )
00638     {
00639         QMessageBox::warning( this, "Wellenreiter II", tr( "Can't open packet capturer for\n'%1':\n" ).arg(
00640                               cardtype == DEVTYPE_FILE ? (const char*) interface : iface->name() ) + QString(strerror( errno ) ));
00641         return;
00642     }
00643 
00644     // set capturer to non-blocking mode
00645     pcap->setBlocking( false );
00646 
00647     // start channel hopper
00648     if ( cardtype != DEVTYPE_FILE )
00649     {
00650         logwindow->log( QString().sprintf( "(i) Starting channel hopper (d=%d ms)", configwindow->hopInterval->value() ) );
00651         iface->setChannelHopping( configwindow->hopInterval->value() ); //use interval from config window
00652     }
00653 
00654     if ( cardtype != DEVTYPE_FILE )
00655     {
00656         // connect socket notifier and start channel hopper
00657         connect( pcap, SIGNAL( receivedPacket(Opie::Net::OPacket*) ), this, SLOT( receivePacket(Opie::Net::OPacket*) ) );
00658         connect( iface->channelHopper(), SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
00659     }
00660     else
00661     {
00662         // start timer for reading packets
00663         startTimer( 100 );
00664     }
00665 
00666     logwindow->log( "(i) Started Scanning." );
00667     sniffing = true;
00668 
00669     #ifdef QWS
00670     if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() )
00671     {
00672         QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable;
00673     }
00674     #else
00675         #warning FIXME: setScreenSaverMode is not operational on the X11 build
00676     #endif
00677 
00678     emit( startedSniffing() );
00679     if ( cardtype != DEVTYPE_FILE ) channelHopped( 6 ); // set title
00680     else
00681     {
00682         assert( parent() );
00683         ( (QMainWindow*) parent() )->setCaption( tr( "Wellenreiter II - replaying capture file..." ) );
00684     }
00685 }
00686 
00687 
00688 void Wellenreiter::timerEvent( QTimerEvent* )
00689 {
00690     odebug << "Wellenreiter::timerEvent()" << oendl;
00691     OPacket* p = pcap->next();
00692     if ( !p ) // no more packets available
00693     {
00694         stopClicked();
00695     }
00696     else
00697     {
00698         receivePacket( p );
00699         // We no longer delete packets here. Ownership of the packets is
00700         // transferred to the PacketView.
00701         //delete p;
00702     }
00703 }
00704 
00705 
00706 void Wellenreiter::doAction( const QString& action, const QString& protocol, OPacket* /* p */ )
00707 {
00708     #ifdef QWS
00709     if ( action == "TouchSound" )
00710         ODevice::inst()->playTouchSound();
00711     else if ( action == "AlarmSound" )
00712         ODevice::inst()->playAlarmSound();
00713     else if ( action == "KeySound" )
00714         ODevice::inst()->playKeySound();
00715     else if ( action == "LedOn" )
00716         ODevice::inst()->setLedState( Led_Mail, Led_On );
00717     else if ( action == "LedOff" )
00718         ODevice::inst()->setLedState( Led_Mail, Led_Off );
00719     else if ( action == "LogMessage" )
00720         logwindow->log( QString(tr("Got packet with protocol '%1'","Protocol Name" ) ).arg( protocol ) );
00721     else if ( action == "MessageBox" )
00722         QMessageBox::information( this, "Notification!",
00723         QString(tr( "Got packet with protocol '%1'", "Protocol Name" ) ).arg( protocol ) );
00724     #else
00725     #warning Actions do not work with Qt/X11 yet
00726     #endif
00727 }
00728 
00729 void Wellenreiter::updateStatistics()
00730 {
00731     // print out statistics
00732     for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it )
00733        statwindow->updateCounter( it.key(), it.data() );
00734 }
00735 
00736 void Wellenreiter::slotTabChanged( QWidget* wid )
00737 {
00738     if ( wid == statwindow )
00739         updateStatistics();
00740 }

Generated on Sat Nov 5 16:17:45 2005 for OPIE by  doxygen 1.4.2