summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-01-03 18:27:07 (UTC)
committer mickeyl <mickeyl>2004-01-03 18:27:07 (UTC)
commit3889c8f853aa2d128f54389b17f08fc7b9150788 (patch) (side-by-side diff)
tree692bf0541e19d19f9ac93059463e4c4eb2e43e5f
parentc69a2abd7718d8acddb4ce96a1909b33056e2dcd (diff)
downloadopie-3889c8f853aa2d128f54389b17f08fc7b9150788.zip
opie-3889c8f853aa2d128f54389b17f08fc7b9150788.tar.gz
opie-3889c8f853aa2d128f54389b17f08fc7b9150788.tar.bz2
show GPS coordinates in the more common DMS format
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/wellenreiter/gui/gps.cpp66
-rw-r--r--noncore/net/wellenreiter/gui/gps.h13
-rw-r--r--noncore/net/wellenreiter/gui/mainwindow.cpp8
-rw-r--r--noncore/net/wellenreiter/gui/scanlist.cpp9
-rw-r--r--noncore/net/wellenreiter/gui/scanlist.h2
-rw-r--r--noncore/net/wellenreiter/gui/wellenreiter.cpp2
6 files changed, 82 insertions, 18 deletions
diff --git a/noncore/net/wellenreiter/gui/gps.cpp b/noncore/net/wellenreiter/gui/gps.cpp
index 288afee..31f95ce 100644
--- a/noncore/net/wellenreiter/gui/gps.cpp
+++ b/noncore/net/wellenreiter/gui/gps.cpp
@@ -1,69 +1,131 @@
/**********************************************************************
** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
**
** This file is part of Opie Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
#include "gps.h"
-#include <unistd.h>
+/* QT */
#include <qtextstream.h>
+/* STD */
+#include <stdlib.h>
+#include <unistd.h>
+
GPS::GPS( QObject* parent, const char * name )
:QObject( parent, name )
{
qDebug( "GPS::GPS()" );
_socket = new QSocket( this, "gpsd commsock" );
}
GPS::~GPS()
{
qDebug( "GPS::~GPS()" );
}
bool GPS::open( const QString& host, int port )
{
_socket->connectToHost( host, port );
}
GpsLocation GPS::position() const
{
char buf[256];
int result = _socket->writeBlock( "p\r\n", 3 );
_socket->flush();
if ( result )
{
int numAvail = _socket->bytesAvailable();
qDebug( "GPS write succeeded, %d bytes available for reading...", numAvail );
if ( numAvail )
{
QTextStream stream( _socket );
QString str;
stream.readRawBytes( &buf[0], 7 );
float lat = -111.111;
stream >> lat;
stream.skipWhiteSpace();
float lon = -111.111;
stream >> lon;
stream.readRawBytes( &buf[0], 200 ); // read and discard the stuff until EOF
return GpsLocation( lat, lon );
}
}
- return GpsLocation( -1.0, -1.0 );
+ return GpsLocation( -111.111, -111.111 );
}
+
+QString GpsLocation::dmsPosition() const
+{
+ if ( _latitude == -111.111 || _longitude == -111.11 )
+ return "N/A";
+ if ( _latitude == 0.0 && _longitude == 0.0 )
+ return "NULL";
+
+ /* compute latitude */
+
+ QString dms = "N";
+ if ( _latitude >= 0 ) dms.append( "+" );
+
+ int trunc = int( _latitude );
+ float rest = _latitude - trunc;
+
+ float minf = rest * 60;
+ int minutes = int( minf );
+
+ rest = minf - minutes;
+ int seconds = int( rest * 60 );
+
+ dms.append( QString::number( trunc ) );
+ dms.append( "° " );
+ dms.append( QString::number( ::abs( minutes ) ) );
+ dms.append( "' " );
+ dms.append( QString::number( ::abs( seconds ) ) );
+ dms.append( "'' " );
+
+ /* compute longitude */
+
+ dms.append( " | W" );
+ if ( _longitude > 0 ) dms.append( "+" );
+
+ trunc = int( _longitude );
+ rest = _longitude - trunc;
+
+ minf = rest * 60;
+ minutes = int( minf );
+
+ rest = minf - minutes;
+ seconds = int( rest * 60 );
+
+ dms.append( QString::number( trunc ) );
+ dms.append( "° " );
+ dms.append( QString::number( ::abs( minutes ) ) );
+ dms.append( "' " );
+ dms.append( QString::number( ::abs( seconds ) ) );
+ dms.append( "'' " );
+
+ return dms;
+}
+
+
+
+
+
+
diff --git a/noncore/net/wellenreiter/gui/gps.h b/noncore/net/wellenreiter/gui/gps.h
index 8143fe4..cfe1cdb 100644
--- a/noncore/net/wellenreiter/gui/gps.h
+++ b/noncore/net/wellenreiter/gui/gps.h
@@ -1,46 +1,51 @@
/**********************************************************************
** Copyright (C) 2003 Michael 'Mickey' Lauer. All rights reserved.
**
** This file is part of Opie Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
#ifndef GPS_H
#define GPS_H
#include <qobject.h>
#include <qsocket.h>
-struct GpsLocation
+class GpsLocation
{
- GpsLocation( const float& lat, const float& lon ) : latitude(lat), longitude(lon) {};
+ public:
+ GpsLocation( const float& lat, const float& lon ) : _latitude(lat), _longitude(lon) {};
~GpsLocation() {};
- float latitude;
- float longitude;
+ float latitude() const { return _latitude; };
+ float longitude() const { return _longitude; };
+ QString dmsPosition() const;
+ private:
+ float _latitude;
+ float _longitude;
};
class GPS : public QObject
{
Q_OBJECT
public:
GPS( QObject* parent = 0, const char * name = "GPS" );
~GPS();
bool open( const QString& host = "localhost", int port = 2947 );
GpsLocation position() const;
private:
QSocket* _socket;
};
#endif // GPS_H
diff --git a/noncore/net/wellenreiter/gui/mainwindow.cpp b/noncore/net/wellenreiter/gui/mainwindow.cpp
index ca9851c..d4e3279 100644
--- a/noncore/net/wellenreiter/gui/mainwindow.cpp
+++ b/noncore/net/wellenreiter/gui/mainwindow.cpp
@@ -1,541 +1,541 @@
/**********************************************************************
** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
**
** This file is part of Opie Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
#include "configwindow.h"
#include "gps.h"
#include "logwindow.h"
#include "hexwindow.h"
#include "mainwindow.h"
#include "wellenreiter.h"
#include "scanlist.h"
#include <qcombobox.h>
#include <qdatastream.h>
#include <qfile.h>
#include <qfileinfo.h>
#include <qlabel.h>
#include <qlayout.h>
#include <qlineedit.h>
#include <qiconset.h>
#include <qmenubar.h>
#include <qmessagebox.h>
#include <qpopupmenu.h>
#include <qpushbutton.h>
#include <qstatusbar.h>
#include <qtextstream.h>
#include <qtoolbutton.h>
#ifdef QWS
#include <qpe/resource.h>
#include <opie/ofiledialog.h>
#else
#include "resource.h"
#include <qapplication.h>
#include <qfiledialog.h>
#endif
WellenreiterMainWindow::WellenreiterMainWindow( QWidget * parent, const char * name, WFlags f )
:QMainWindow( parent, name, f )
{
cw = new WellenreiterConfigWindow( this );
mw = new Wellenreiter( this );
mw->setConfigWindow( cw );
setCentralWidget( mw );
// setup application icon
#ifndef QWS
setIcon( Resource::loadPixmap( "wellenreiter/appicon-trans" ) );
setIconText( "Wellenreiter/X11" );
#endif
// setup tool buttons
startButton = new QToolButton( 0 );
#ifdef QWS
startButton->setAutoRaise( true );
#endif
startButton->setIconSet( Resource::loadIconSet( "wellenreiter/SearchIcon" ) );
startButton->setEnabled( false );
connect( startButton, SIGNAL( clicked() ), mw, SLOT( startClicked() ) );
stopButton = new QToolButton( 0 );
#ifdef QWS
stopButton->setAutoRaise( true );
#endif
stopButton->setIconSet( Resource::loadIconSet( "wellenreiter/CancelIcon" ) );
stopButton->setEnabled( false );
connect( stopButton, SIGNAL( clicked() ), mw, SLOT( stopClicked() ) );
QToolButton* d = new QToolButton( 0 );
#ifdef QWS
d->setAutoRaise( true );
#endif
d->setIconSet( Resource::loadIconSet( "wellenreiter/SettingsIcon" ) );
connect( d, SIGNAL( clicked() ), this, SLOT( showConfigure() ) );
uploadButton = new QToolButton( 0 );
#ifdef QWS
uploadButton->setAutoRaise( true );
#endif
uploadButton->setIconSet( Resource::loadIconSet( "up" ) );
uploadButton->setEnabled( false );
//uploadButton->setEnabled( true ); // DEBUGGING
connect( uploadButton, SIGNAL( clicked() ), this, SLOT( uploadSession() ) );
// setup menu bar
int id;
QMenuBar* mb = menuBar();
QPopupMenu* fileSave = new QPopupMenu( mb );
fileSave->insertItem( tr( "&Session..." ), this, SLOT( fileSaveSession() ) );
fileSave->insertItem( tr( "&Text Log..." ), this, SLOT( fileSaveLog() ) );
fileSave->insertItem( tr( "&Hex Log..." ), this, SLOT( fileSaveHex() ) );
QPopupMenu* fileLoad = new QPopupMenu( mb );
fileLoad->insertItem( tr( "&Session..." ), this, SLOT( fileLoadSession() ) );
//fileLoad->insertItem( "&Log", this, SLOT( fileLoadLog() ) );
QPopupMenu* file = new QPopupMenu( mb );
file->insertItem( tr( "&New" ), this, SLOT( fileNew() ) );
id = file->insertItem( tr( "&Load" ), fileLoad );
file->insertItem( tr( "&Save" ), fileSave );
file->insertSeparator();
uploadID = file->insertItem( tr( "&Upload Session" ), this, SLOT( uploadSession() ) );
file->insertSeparator();
file->insertItem( tr( "&Exit" ), qApp, SLOT( quit() ) );
QPopupMenu* view = new QPopupMenu( mb );
view->insertItem( tr( "&Configure..." ) );
QPopupMenu* sniffer = new QPopupMenu( mb );
sniffer->insertItem( tr( "&Configure..." ), this, SLOT( showConfigure() ) );
sniffer->insertSeparator();
startID = sniffer->insertItem( tr( "&Start" ), mw, SLOT( startClicked() ) );
sniffer->setItemEnabled( startID, false );
stopID = sniffer->insertItem( tr( "Sto&p" ), mw, SLOT( stopClicked() ) );
sniffer->setItemEnabled( stopID, false );
QPopupMenu* demo = new QPopupMenu( mb );
demo->insertItem( tr( "&Add something" ), this, SLOT( demoAddStations() ) );
id = mb->insertItem( tr( "&File" ), file );
//id = mb->insertItem( tr( "&View" ), view );
//mb->setItemEnabled( id, false );
id = mb->insertItem( tr( "&Sniffer" ), sniffer );
id = mb->insertItem( tr( "&Demo" ), demo );
mb->setItemEnabled( id, true );
mb->setItemEnabled( uploadID, false );
#ifdef QWS
mb->insertItem( startButton );
mb->insertItem( stopButton );
mb->insertItem( uploadButton );
mb->insertItem( d );
#else // Qt3 changed the insertion order. It's now totally random :(
mb->insertItem( d );
mb->insertItem( uploadButton );
mb->insertItem( stopButton );
mb->insertItem( startButton );
#endif
updateToolButtonState();
// setup status bar (for now only on X11)
#ifndef QWS
statusBar()->message( tr( "Ready." ) );
#endif
connect( mw, SIGNAL( startedSniffing() ), this, SLOT( changedSniffingState() ) );
connect( mw, SIGNAL( stoppedSniffing() ), this, SLOT( changedSniffingState() ) );
};
void WellenreiterMainWindow::showConfigure()
{
qDebug( "show configure..." );
cw->setCaption( tr( "Configure" ) );
#ifdef QWS
cw->showMaximized();
#endif
int result = cw->exec();
if ( result ) updateToolButtonState();
}
void WellenreiterMainWindow::updateToolButtonState()
{
const QString& interface = cw->interfaceName->currentText();
const int cardtype = cw->driverType();
if ( ( interface != "<select>" ) && ( cardtype != 0 ) )
{
startButton->setEnabled( true );
menuBar()->setItemEnabled( startID, true );
}
else
{
startButton->setEnabled( false );
menuBar()->setItemEnabled( startID, false );
}
}
void WellenreiterMainWindow::changedSniffingState()
{
startButton->setEnabled( !mw->sniffing );
menuBar()->setItemEnabled( startID, !mw->sniffing );
stopButton->setEnabled( mw->sniffing );
menuBar()->setItemEnabled( stopID, mw->sniffing );
if ( !mw->sniffing )
{
menuBar()->setItemEnabled( uploadID, true );
uploadButton->setEnabled( true );
}
}
WellenreiterMainWindow::~WellenreiterMainWindow()
{
qDebug( "Wellenreiter:: bye." );
};
void WellenreiterMainWindow::demoAddStations()
{
//mw = 0; // test SIGSGV handling
- mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:00:20:EF:A6:43"), true, 6, 80, GpsLocation( 10.10, 20.20 ) );
+ mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:00:20:EF:A6:43"), true, 6, 80, GpsLocation( 39.8794, -94.0936) );
mw->netView()->addNewItem( "managed", "Vanille", OMacAddress::fromString("00:30:6D:EF:A6:23"), true, 11, 10, GpsLocation( 0.0, 0.0 ) );
- mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:A0:F8:E7:16:22"), false, 3, 10, GpsLocation( 5.5, 2.3 ) );
- mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:AA:01:E7:56:62"), false, 3, 15, GpsLocation( 2.3, 5.5 ) );
- mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:B0:8E:E7:56:E2"), false, 3, 20, GpsLocation( -10.0, -20.5 ) );
+ mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:03:F8:E7:16:22"), false, 3, 10, GpsLocation( 5.5, 2.3 ) );
+ mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:04:01:E7:56:62"), false, 3, 15, GpsLocation( 2.3, 5.5 ) );
+ mw->netView()->addNewItem( "adhoc", "ELAN", OMacAddress::fromString("00:05:8E:E7:56:E2"), false, 3, 20, GpsLocation( -10.0, -20.5 ) );
}
QString WellenreiterMainWindow::getFileName( bool save )
{
QMap<QString, QStringList> map;
map.insert( tr("All"), QStringList() );
QStringList text;
text << "text/*";
map.insert( tr("Text"), text );
text << "*";
map.insert( tr("All"), text );
QString str;
if ( save )
{
#ifdef QWS
str = OFileDialog::getSaveFileName( 2, "/", QString::null, map );
#else
str = QFileDialog::getSaveFileName();
#endif
if ( str.isEmpty() /*|| QFileInfo(str).isDir()*/ )
return "";
}
else
{
#ifdef QWS
str = OFileDialog::getOpenFileName( 2, "/", QString::null, map );
#else
str = QFileDialog::getOpenFileName();
#endif
if ( str.isEmpty() || !QFile(str).exists() || QFileInfo(str).isDir() )
return "";
}
return str;
}
void WellenreiterMainWindow::fileSaveLog()
{
QString fname = getFileName( true );
if ( !fname.isEmpty() )
{
QFile f( fname );
if ( f.open(IO_WriteOnly) )
{
QTextStream t( &f );
t << mw->logWindow()->getLog();
f.close();
qDebug( "Saved log to file '%s'", (const char*) fname );
}
else
{
qDebug( "Problem saving log to file '%s'", (const char*) fname );
}
}
}
void WellenreiterMainWindow::fileSaveSession()
{
QString fname = getFileName( true );
if ( !fname.isEmpty() )
{
QFile f( fname );
if ( f.open(IO_WriteOnly) )
{
QDataStream t( &f );
t << *mw->netView();
f.close();
qDebug( "Saved session to file '%s'", (const char*) fname );
}
else
{
qDebug( "Problem saving session to file '%s'", (const char*) fname );
}
}
}
void WellenreiterMainWindow::fileSaveHex()
{
QString fname = getFileName( true );
if ( !fname.isEmpty() )
{
QFile f( fname );
if ( f.open(IO_WriteOnly) )
{
QTextStream t( &f );
t << mw->hexWindow()->getLog();
f.close();
qDebug( "Saved hex log to file '%s'", (const char*) fname );
}
else
{
qDebug( "Problem saving hex log to file '%s'", (const char*) fname );
}
}
}
void WellenreiterMainWindow::fileLoadSession()
{
QString fname = getFileName( false );
if ( !fname.isEmpty() )
{
QFile f( fname );
if ( f.open(IO_ReadOnly) )
{
QDataStream t( &f );
t >> *mw->netView();
f.close();
qDebug( "Loaded session from file '%s'", (const char*) fname );
}
else
{
qDebug( "Problem loading session from file '%s'", (const char*) fname );
}
}
}
void WellenreiterMainWindow::fileNew()
{
mw->netView()->clear();
mw->logWindow()->clear();
mw->hexWindow()->clear();
}
void WellenreiterMainWindow::closeEvent( QCloseEvent* e )
{
if ( mw->isDaemonRunning() )
{
QMessageBox::warning( this, "Wellenreiter/Opie",
tr( "Sniffing in progress!\nPlease stop sniffing before closing." ) );
e->ignore();
}
else
{
QMainWindow::closeEvent( e );
}
}
static const char* CAP_hostname = "www.vanille.de";
#include <netdb.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
void WellenreiterMainWindow::uploadSession()
{
QLineEdit* from;
QLineEdit* location;
QLineEdit* comments;
QPushButton* accept;
QPushButton* reject;
QDialog* d = new QDialog( 0, "session upload", true );
d->setCaption( tr( "Upload Session" ) );
QGridLayout* g = new QGridLayout( d, 4, 2, 3 );
g->addWidget( new QLabel( tr( "From: " ), d ), 0, 0 );
g->addWidget( from = new QLineEdit( d ), 0, 1 );
g->addWidget( new QLabel( tr( "Location: " ), d ), 1, 0 );
g->addWidget( location = new QLineEdit( d ), 1, 1 );
g->addWidget( new QLabel( tr( "Comments: " ), d ), 2, 0 );
g->addWidget( comments = new QLineEdit( d ), 2, 1 );
g->addWidget( accept = new QPushButton( tr( "&Ok" ), d ), 3, 0 );
g->addWidget( reject = new QPushButton( tr( "&Cancel" ), d ), 3, 1 );
accept->setDefault( true );
accept->setAutoDefault( true );
from->setText( "WL II User" );
location->setText( "WL II Location" );
comments->setText( "No Comments." );
connect( accept, SIGNAL( clicked() ), d, SLOT( accept() ) );
connect( reject, SIGNAL( clicked() ), d, SLOT( reject() ) );
int result = d->exec();
if ( !result )
{
qDebug( "Session upload cancelled :(" );
return;
}
qDebug( "Starting upload..." );
struct sockaddr_in raddr;
struct hostent *rhost_info;
int sock = -1;
bool ok = false;
rhost_info = (struct hostent *) ::gethostbyname( CAP_hostname );
if ( rhost_info )
{
if ( !QFile::exists( mw->captureFileName() ) )
{
QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Logfile '%1' doesn't exist</p>").arg( mw->captureFileName() ) );
return;
}
QFile f( mw->captureFileName() );
if ( !f.open( IO_ReadOnly ) )
{
QMessageBox::warning( 0, tr( "Error" ), tr( "<p>Can't open Logfile '%1'</p>").arg( mw->captureFileName() ) );
return;
}
int content_length = f.size();
::memset( &raddr, 0, sizeof (struct sockaddr_in) );
::memcpy( &raddr. sin_addr, rhost_info-> h_addr, rhost_info-> h_length );
raddr.sin_family = rhost_info-> h_addrtype;
raddr.sin_port = htons ( 80 );
sock = ::socket( AF_INET, SOCK_STREAM, 0 );
if ( sock >= 0 )
{
if ( ::connect ( sock, (struct sockaddr *) & raddr, sizeof (struct sockaddr)) >= 0 )
{
QString header;
QString content;
QString preambel;
header = ""
"POST /projects/capturedump.spy HTTP/1.1\r\n"
"Host: www.vanille.de\r\n"
"User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.5) Gecko/20031010 Galeon/1.3.10\r\n"
"Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,image/jpeg,image/gif;q=0.2,*/*;q=0.1\r\n"
"Accept-Language: en\r\n"
"Accept-Encoding: gzip, deflate, compress;q=0.9\r\n"
"Accept-Charset: us-ascii,utf-8;q=0.7,*;q=0.7\r\n"
"Keep-Alive: 300\r\n"
"Connection: keep-alive\r\n"
"Referer: http://www.vanille.de/projects/capturedump.spy\r\n"
"Content-Type: multipart/form-data; boundary=---------------------------97267758015830030481215568065\r\n"
"Content-Length: %1\r\n"
"\r\n";
content = ""
"-----------------------------97267758015830030481215568065\r\n"
"Content-Disposition: form-data; name=\"Name\"\r\n"
"\r\n"
"%1\r\n"
"-----------------------------97267758015830030481215568065\r\n"
"Content-Disposition: form-data; name=\"Location\"\r\n"
"\r\n"
"%2\r\n"
"-----------------------------97267758015830030481215568065\r\n"
"Content-Disposition: form-data; name=\"Comments\"\r\n"
"\r\n"
"%3\r\n"
"-----------------------------97267758015830030481215568065\r\n"
"Content-Disposition: form-data; name=\"upfile\"; filename=\"%4\"\r\n"
"Content-Type: application/octet-stream\r\n"
"\r\n";
preambel = ""
"\r\n-----------------------------97267758015830030481215568065--\r\n";
content = content.arg( from->text().isEmpty() ? QString( "Anonymous Wellenreiter II User" ) : from->text() );
content = content.arg( location->text().isEmpty() ? QString( "Anonymous Wellenreiter II Location" ) : location->text() );
content = content.arg( comments->text().isEmpty() ? QString( "Anonymous Wellenreiter II Comments" ) : comments->text() );
content = content.arg( mw->captureFileName() );
header = header.arg( QString::number( content.length() + f.size() + preambel.length() ) );
// write header
const char* ascii = header.latin1();
uint ascii_len = ::strlen( ascii );
::write ( sock, ascii, ascii_len );
// write fixed content
ascii = content.latin1();
ascii_len = ::strlen( ascii );
::write ( sock, ascii, ascii_len );
// write variable content
char ch;
while ( !f.atEnd() )
{
f.readBlock( &ch, 1 );
::write ( sock, &ch, 1 );
}
// write preambel
ascii = preambel.latin1();
ascii_len = ::strlen( ascii );
::write ( sock, ascii, ascii_len );
// done!
ok = true;
}
}
::close ( sock );
}
if ( ok )
QMessageBox::information( 0, tr( "Success" ),
QString ( "<p>%1</p>" ).arg( tr( "Capture Dump was uploaded to %1" ) ).arg( CAP_hostname ) );
else
QMessageBox::warning( 0, tr( "Error" ),
QString ( "<p>%1</p>" ).arg ( tr( "Connection to %1 failed" ) ).arg( CAP_hostname ) );
}
diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp
index 1cca507..d89c71f 100644
--- a/noncore/net/wellenreiter/gui/scanlist.cpp
+++ b/noncore/net/wellenreiter/gui/scanlist.cpp
@@ -1,569 +1,566 @@
/**********************************************************************
** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
**
** This file is part of Opie Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
#include "scanlist.h"
#include "configwindow.h"
#include "logwindow.h"
#include <assert.h>
#include <qcursor.h>
#include <qdatetime.h>
#include <qtextstream.h>
#include <qpopupmenu.h>
#include <qcheckbox.h>
#ifdef QWS
#include <qpe/qpeapplication.h>
#include <opie/odevice.h>
using namespace Opie;
#endif
#ifdef QWS
#include <qpe/resource.h>
#else
#include "resource.h"
#endif
const int col_type = 0;
const int col_essid = 0;
const int col_sig = 1;
const int col_ap = 2;
const int col_channel = 3;
const int col_wep = 4;
const int col_traffic = 5;
const int col_ip = 6;
const int col_manuf = 7;
const int col_firstseen = 8;
const int col_lastseen = 9;
const int col_location = 10;
MScanListView::MScanListView( QWidget* parent, const char* name )
:OListView( parent, name )
{
setFrameShape( QListView::StyledPanel );
setFrameShadow( QListView::Sunken );
addColumn( tr( "Net/Station" ) );
setColumnAlignment( col_essid, AlignLeft || AlignVCenter );
addColumn( tr( "#" ) );
setColumnAlignment( col_sig, AlignCenter );
addColumn( tr( "MAC" ) );
setColumnAlignment( col_ap, AlignCenter );
addColumn( tr( "Chn" ) );
setColumnAlignment( col_channel, AlignCenter );
addColumn( tr( "W" ) );
setColumnAlignment( col_wep, AlignCenter );
addColumn( tr( "T" ) );
setColumnAlignment( col_traffic, AlignCenter );
addColumn( tr( "IP" ) );
setColumnAlignment( col_ip, AlignCenter );
addColumn( tr( "Manufacturer" ) );
setColumnAlignment( col_manuf, AlignCenter );
addColumn( tr( "First Seen" ) );
setColumnAlignment( col_firstseen, AlignCenter );
addColumn( tr( "Last Seen" ) );
setColumnAlignment( col_lastseen, AlignCenter );
addColumn( tr( "Location" ) );
setColumnAlignment( col_location, AlignCenter );
setRootIsDecorated( true );
setAllColumnsShowFocus( true );
connect( this, SIGNAL( rightButtonClicked(QListViewItem*,const QPoint&,int) ),
this, SLOT( contextMenuRequested(QListViewItem*,const QPoint&,int) ) );
#ifdef QWS
QPEApplication::setStylusOperation( viewport(), QPEApplication::RightOnHold );
#endif
};
MScanListView::~MScanListView()
{
};
OListViewItem* MScanListView::childFactory()
{
return new MScanListItem( this );
}
void MScanListView::serializeTo( QDataStream& s) const
{
qDebug( "serializing MScanListView" );
OListView::serializeTo( s );
}
void MScanListView::serializeFrom( QDataStream& s)
{
qDebug( "serializing MScanListView" );
OListView::serializeFrom( s );
}
void MScanListView::addNewItem( const QString& type,
const QString& essid,
const OMacAddress& mac,
bool wep,
int channel,
int signal,
const GpsLocation& loc )
{
QString macaddr = mac.toString(true);
#ifdef DEBUG
qDebug( "MScanList::addNewItem( %s / %s / %s [%d]", (const char*) type,
(const char*) essid, (const char*) macaddr, channel );
#endif
// search, if we already have seen this net
QString s;
MScanListItem* network;
MScanListItem* item = static_cast<MScanListItem*> ( firstChild() );
while ( item && ( item->text( col_essid ) != essid ) )
{
#ifdef DEBUG
qDebug( "itemtext: %s", (const char*) item->text( col_essid ) );
#endif
item = static_cast<MScanListItem*> ( item->nextSibling() );
}
if ( item )
{
// we have already seen this net, check all childs if MAC exists
network = item;
item = static_cast<MScanListItem*> ( item->firstChild() );
assert( item ); // this shouldn't fail
while ( item && ( item->text( col_ap ) != macaddr ) )
{
#ifdef DEBUG
qDebug( "subitemtext: %s", (const char*) item->text( col_ap ) );
#endif
item = static_cast<MScanListItem*> ( item->nextSibling() );
}
if ( item )
{
// we have already seen this item, it's a dupe
#ifdef DEBUG
qDebug( "%s is a dupe - ignoring...", (const char*) macaddr );
#endif
item->receivedBeacon();
return;
}
}
else
{
s.sprintf( "(i) New network: ESSID '%s'", (const char*) essid );
MLogWindow::logwindow()->log( s );
network = new MScanListItem( this, "network", essid, QString::null, 0, 0, 0 );
}
// insert new station as child from network
// no essid to reduce clutter, maybe later we have a nick or stationname to display!?
#ifdef DEBUG
qDebug( "inserting new station %s", (const char*) macaddr );
#endif
MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal );
station->setManufacturer( mac.manufacturer() );
- station->setLocation( loc.latitude, loc.longitude );
+ station->setLocation( loc.dmsPosition() );
if ( type == "managed" )
{
s.sprintf( "(i) New Access Point in '%s' [%d]", (const char*) essid, channel );
}
else
{
s.sprintf( "(i) New AdHoc station in '%s' [%d]", (const char*) essid, channel );
}
MLogWindow::logwindow()->log( s );
}
void MScanListView::addIfNotExisting( MScanListItem* network, const OMacAddress& addr, const QString& type )
{
MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() );
while ( subitem && ( subitem->text( col_ap ) != addr.toString(true) ) )
{
#ifdef DEBUG
qDebug( "subitemtext: %s", (const char*) subitem->text( col_ap ) );
#endif
subitem = static_cast<MScanListItem*> ( subitem->nextSibling() );
}
if ( subitem )
{
// we have already seen this item, it's a dupe
#ifdef DEBUG
qDebug( "%s is a dupe - ignoring...", (const char*) addr.toString(true) );
#endif
subitem->receivedBeacon(); //FIXME: sent data bit
return;
}
// Hey, it seems to be a new item :-D
MScanListItem* station = new MScanListItem( network, type, /* network->text( col_essid ) */ "", addr.toString(true), false, -1, -1 );
station->setManufacturer( addr.manufacturer() );
QString s;
if ( type == "station" )
{
s.sprintf( "(i) New Station in '%s' [xx]", (const char*) network->text( col_essid ) );
}
else
{
s.sprintf( "(i) New Wireless Station in '%s' [xx]", (const char*) network->text( col_essid ) );
}
MLogWindow::logwindow()->log( s );
}
void MScanListView::WDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& viaFrom, const OMacAddress& viaTo )
{
QString s;
MScanListItem* network;
QListViewItemIterator it( this );
while ( it.current() &&
it.current()->text( col_ap ) != viaFrom.toString(true) &&
it.current()->text( col_ap ) != viaTo.toString(true) ) ++it;
MScanListItem* item = static_cast<MScanListItem*>( it.current() );
if ( item ) // Either viaFrom or viaTo AP has shown up yet, so just add our two new stations
{
addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from );
addIfNotExisting( static_cast<MScanListItem*>(item->parent()), to );
}
else
{
qDebug( "D'Oh! Stations without AP... ignoring for now... will handle this in 1.1 version :-D" );
MLogWindow::logwindow()->log( "WARNING: Unhandled WSD traffic!" );
}
}
void MScanListView::toDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
{
QString s;
MScanListItem* network;
QListViewItemIterator it( this );
while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it;
MScanListItem* item = static_cast<MScanListItem*>( it.current() );
if ( item ) // AP has shown up yet, so just add our new "from" - station
{
addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "adhoc" );
}
else
{
qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" );
MLogWindow::logwindow()->log( "WARNING: Unhandled toDS traffic!" );
}
}
void MScanListView::fromDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
{
QString s;
MScanListItem* network;
QListViewItemIterator it( this );
while ( it.current() && it.current()->text( col_ap ) != via.toString(true) ) ++it;
MScanListItem* item = static_cast<MScanListItem*>( it.current() );
if ( item ) // AP has shown up yet, so just add our new "from" - station
{
addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from, "station" );
}
else
{
qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" );
MLogWindow::logwindow()->log( "WARNING: Unhandled fromDS traffic!" );
}
}
void MScanListView::IBSStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via )
{
qWarning( "D'oh! Not yet implemented..." );
MLogWindow::logwindow()->log( "WARNING: Unhandled IBSS traffic!" );
}
void MScanListView::identify( const OMacAddress& macaddr, const QString& ip )
{
qDebug( "identify %s = %s", (const char*) macaddr.toString(), (const char*) ip );
QListViewItemIterator it( this );
for ( ; it.current(); ++it )
{
if ( it.current()->text( col_ap ) == macaddr.toString(true) )
{
it.current()->setText( col_ip, ip );
return;
}
}
qDebug( "D'oh! Received identification, but item not yet in list... ==> Handle this!" );
MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled identification %s = %s!",
(const char*) macaddr.toString(), (const char*) ip ) );
}
void MScanListView::addService( const QString& name, const OMacAddress& macaddr, const QString& ip )
{
qDebug( "addService '%s', Server = %s = %s", (const char*) name, (const char*) macaddr.toString(), (const char*) ip );
//TODO: Refactor that out, we need it all over the place.
// Best to do it in a more comfortable abstraction in OListView
// (Hmm, didn't I already start something in this direction?)
QListViewItemIterator it( this );
for ( ; it.current(); ++it )
{
if ( it.current()->text( col_ap ) == macaddr.toString(true) )
{
MScanListItem* subitem = static_cast<MScanListItem*>( it.current()->firstChild() );
while ( subitem && ( subitem->text( col_essid ) != name ) )
{
#ifdef DEBUG
qDebug( "subitemtext: %s", (const char*) subitem->text( col_essid ) );
#endif
subitem = static_cast<MScanListItem*> ( subitem->nextSibling() );
}
if ( subitem )
{
// we have already seen this item, it's a dupe
#ifdef DEBUG
qDebug( "%s is a dupe - ignoring...", (const char*) name );
#endif
subitem->receivedBeacon(); //FIXME: sent data bit
return;
}
// never seen that - add new item
MScanListItem* item = new MScanListItem( it.current(), "service", "N/A", " ", false, -1, -1 );
item->setText( col_essid, name );
return;
}
}
qDebug( "D'oh! Received identification, but item not yet in list... ==> Handle this!" );
MLogWindow::logwindow()->log( QString().sprintf( "WARNING: Unhandled service addition %s = %s!",
(const char*) macaddr.toString(), (const char*) ip ) );
}
void MScanListView::contextMenuRequested( QListViewItem* item, const QPoint&, int col )
{
if ( !item ) return;
MScanListItem* itm = static_cast<MScanListItem*>( item );
qDebug( "contextMenuRequested on item '%s' (%s) in column: '%d'",
(const char*) itm->text(0), (const char*) itm->type, col );
if ( itm->type == "adhoc" || itm->type == "managed" )
{
QString entry = QString().sprintf( "&Join %s Net '%s'...", (const char*) itm->type, (const char*) itm->essid() );
QPopupMenu m( this );
m.insertItem( entry, 37773, 0 );
int result = m.exec( QCursor::pos() );
if ( result == 37773 )
emit joinNetwork( itm->type, itm->essid(), itm->channel(), itm->macaddr() );
}
}
//============================================================
// MScanListItem
//============================================================
MScanListItem::MScanListItem( QListView* parent, QString type, QString essid, QString macaddr,
bool wep, int channel, int signal )
:OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null ),
_type( type ), _essid( essid ), _macaddr( macaddr ), _wep( wep ),
_channel( channel ), _signal( signal ), _beacons( 1 )
{
#ifdef DEBUG
qDebug( "creating scanlist item" );
#endif
if ( WellenreiterConfigWindow::instance() && type == "network" )
playSound( WellenreiterConfigWindow::instance()->soundOnNetwork() );
decorateItem( type, essid, macaddr, wep, channel, signal );
}
MScanListItem::MScanListItem( QListViewItem* parent, QString type, QString essid, QString macaddr,
bool wep, int channel, int signal )
:OListViewItem( parent, essid, QString::null, macaddr, QString::null, QString::null )
{
#ifdef DEBUG
qDebug( "creating scanlist item" );
#endif
decorateItem( type, essid, macaddr, wep, channel, signal );
}
const QString& MScanListItem::essid() const
{
if ( type == "network" )
return _essid;
else
return ( (MScanListItem*) parent() )->essid();
}
OListViewItem* MScanListItem::childFactory()
{
return new MScanListItem( this );
}
void MScanListItem::serializeTo( QDataStream& s ) const
{
#ifdef DEBUG
qDebug( "serializing MScanListItem" );
#endif
OListViewItem::serializeTo( s );
s << _type;
s << (Q_UINT8) ( _wep ? 'y' : 'n' );
}
void MScanListItem::serializeFrom( QDataStream& s )
{
#ifdef DEBUG
qDebug( "serializing MScanListItem" );
#endif
OListViewItem::serializeFrom( s );
char wep;
s >> _type;
s >> (Q_UINT8) wep;
_wep = (wep == 'y');
QString name;
name.sprintf( "wellenreiter/%s", (const char*) _type );
setPixmap( col_type, Resource::loadPixmap( name ) );
if ( _wep )
setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap!
listView()->triggerUpdate();
}
void MScanListItem::decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal )
{
#ifdef DEBUG
qDebug( "decorating scanlist item %s / %s / %s [%d]",
(const char*) type,
(const char*) essid,
(const char*) macaddr,
channel );
#endif
// set icon for managed or adhoc mode
QString name;
name.sprintf( "wellenreiter/%s", (const char*) type );
setPixmap( col_type, Resource::loadPixmap( name ) );
// set icon for wep (wireless encryption protocol)
if ( wep )
setPixmap( col_wep, Resource::loadPixmap( "wellenreiter/cracked" ) ); //FIXME: rename the pixmap!
// set channel and signal text
if ( signal != -1 )
setText( col_sig, QString::number( signal ) );
if ( channel != -1 )
setText( col_channel, QString::number( channel ) );
setText( col_firstseen, QTime::currentTime().toString() );
//setText( col_lastseen, QTime::currentTime().toString() );
listView()->triggerUpdate();
this->type = type;
_type = type;
_essid = essid;
_macaddr = macaddr;
_channel = channel;
_beacons = 1;
_signal = 0;
if ( WellenreiterConfigWindow::instance()->openTree->isChecked() )
{
listView()->ensureItemVisible( this );
}
}
void MScanListItem::setManufacturer( const QString& manufacturer )
{
setText( col_manuf, manufacturer );
}
-void MScanListItem::setLocation( const float& latitude, const float& longitude )
+void MScanListItem::setLocation( const QString& location )
{
- if ( latitude == 0.0 || longitude == 0.0 )
- setText( col_location, "N/A" );
- else
- setText( col_location, QString().sprintf( "%.2f / %.2f", latitude, longitude ) );
+ setText( col_location, location );
}
void MScanListItem::playSound( const QString& sound ) const
{
#ifdef QWS
if ( sound == "Ignore" ) return;
else if ( sound == "Touch" ) ODevice::inst()->touchSound();
else if ( sound == "Key" ) ODevice::inst()->keySound();
else if ( sound == "Alarm" ) ODevice::inst()->alarmSound();
#endif
}
void MScanListItem::receivedBeacon()
{
_beacons++;
#ifdef DEBUG
qDebug( "MScanListItem %s: received beacon #%d", (const char*) _macaddr, _beacons );
#endif
setText( col_sig, QString::number( _beacons ) );
setText( col_lastseen, QTime::currentTime().toString() );
MScanListItem* p = (MScanListItem*) parent();
if ( p ) p->receivedBeacon();
}
diff --git a/noncore/net/wellenreiter/gui/scanlist.h b/noncore/net/wellenreiter/gui/scanlist.h
index a9b74f1..6cd8fc0 100644
--- a/noncore/net/wellenreiter/gui/scanlist.h
+++ b/noncore/net/wellenreiter/gui/scanlist.h
@@ -1,142 +1,142 @@
/**********************************************************************
** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
**
** This file is part of Opie Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
**********************************************************************/
#ifndef SCANLIST_H
#define SCANLIST_H
#include "gps.h"
/* OPIE */
#include <opie2/olistview.h>
#include <opie2/onetutils.h>
/* QT */
#include <qtextstream.h>
class QString;
class MScanListItem;
class MScanListView: public OListView
{
Q_OBJECT
public:
MScanListView( QWidget* parent = 0, const char* name = 0 );
virtual ~MScanListView();
virtual OListViewItem* childFactory();
virtual void serializeTo( QDataStream& s ) const;
virtual void serializeFrom( QDataStream& s );
public slots:
void addNewItem( const QString& type, const QString& essid, const OMacAddress& macaddr, bool wep, int channel, int signal, const GpsLocation& location );
void addService( const QString& name, const OMacAddress& macaddr, const QString& ip );
void fromDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via );
void toDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via );
void WDStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& viaFrom, const OMacAddress& viaTo );
void IBSStraffic( const OMacAddress& from, const OMacAddress& to, const OMacAddress& via );
void identify( const OMacAddress&, const QString& ipaddr );
void contextMenuRequested( QListViewItem* item, const QPoint&, int );
signals:
void rightButtonClicked(QListViewItem*,const QPoint&,int);
void joinNetwork( const QString&, const QString&, int, const QString& );
protected:
void addIfNotExisting( MScanListItem* parent, const OMacAddress& addr, const QString& type = "station" );
};
//****************************** MScanListItem ****************************************************************
class MScanListItem: public OListViewItem
{
public:
MScanListItem::MScanListItem( QListView* parent,
QString type = "unknown",
QString essid = "unknown",
QString macaddr = "unknown",
bool wep = false,
int channel = 0,
int signal = 0 );
MScanListItem::MScanListItem( QListViewItem* parent,
QString type = "unknown",
QString essid = "unknown",
QString macaddr = "unknown",
bool wep = false,
int channel = 0,
int signal = 0 );
protected:
virtual void decorateItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal );
public:
QString type;
public:
//const QString& type() { return _type; };
const QString& essid() const;
const QString& macaddr() { return _macaddr; };
bool wep() { return _wep; };
int channel() { return _channel; };
int signal() { return _signal; };
int beacons() { return _beacons; };
void setSignal( int signal ) { /* TODO */ };
void receivedBeacon();
void setManufacturer( const QString& manufacturer );
- void setLocation( const float& latitude, const float& longitude );
+ void setLocation( const QString& location );
virtual OListViewItem* childFactory();
virtual void serializeTo( QDataStream& s ) const;
virtual void serializeFrom( QDataStream& s );
protected:
void playSound( const QString& ) const;
private:
QString _type;
QString _essid;
QString _macaddr;
bool _wep;
int _channel;
int _signal;
int _beacons;
};
//****************************** MScanListViewFactory ****************************************************************
/*
class MScanListViewFactory : public OListViewFactory
{
public:
virtual QListView* listViewFactory();
virtual QListViewItem* listViewItemFactory( QListView* lv );
virtual QListViewItem* listViewItemFactory( QListViewItem* lvi );
virtual void setColumnText( int depth, QListViewItem* lvi, int column, const QString& text );
virtual void setCustomData( int depth, QListViewItem* lvi, const QString& text );
}
*/
#endif
diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp
index 9255a6d..5575d6e 100644
--- a/noncore/net/wellenreiter/gui/wellenreiter.cpp
+++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp
@@ -1,576 +1,576 @@
/**********************************************************************
** Copyright (C) 2002 Michael 'Mickey' Lauer. All rights reserved.
**
** This file is part of Opie Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.
**
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
**
***********************************************************************/
// Local
#include "gps.h"
#include "wellenreiter.h"
#include "scanlist.h"
#include "logwindow.h"
#include "hexwindow.h"
#include "configwindow.h"
#include "statwindow.h"
#include "graphwindow.h"
#include "protolistview.h"
// Opie
#ifdef QWS
#include <opie/odevice.h>
#include <qpe/qcopenvelope_qws.h>
using namespace Opie;
#endif
#ifdef QWS
#include <opie2/oapplication.h>
#else
#include <qapplication.h>
#endif
#include <opie2/omanufacturerdb.h>
#include <opie2/onetwork.h>
#include <opie2/opcap.h>
// Qt
#include <qcheckbox.h>
#include <qcombobox.h>
#include <qdatetime.h>
#include <qpushbutton.h>
#include <qlineedit.h>
#include <qmessagebox.h>
#include <qobjectlist.h>
#include <qregexp.h>
#include <qspinbox.h>
#include <qtimer.h>
#include <qtoolbutton.h>
#include <qmainwindow.h>
// Standard
#include <assert.h>
#include <errno.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <stdlib.h>
Wellenreiter::Wellenreiter( QWidget* parent )
: WellenreiterBase( parent, 0, 0 ),
sniffing( false ), iface( 0 ), configwindow( 0 )
{
logwindow->log( "(i) Wellenreiter has been started." );
//
// detect operating system
//
#ifdef QWS
QString sys;
sys.sprintf( "(i) Running on '%s'.", (const char*) ODevice::inst()->systemString() );
_system = ODevice::inst()->system();
logwindow->log( sys );
#endif
netview->setColumnWidthMode( 1, QListView::Manual );
connect( netview, SIGNAL( joinNetwork(const QString&,const QString&,int,const QString&) ),
this, SLOT( joinNetwork(const QString&,const QString&,int,const QString&) ) );
pcap = new OPacketCapturer();
gps = new GPS( this );
QTimer::singleShot( 1000, this, SLOT( initialTimer() ) );
}
Wellenreiter::~Wellenreiter()
{
delete pcap;
}
void Wellenreiter::initialTimer()
{
qDebug( "Wellenreiter::preloading manufacturer database..." );
OManufacturerDB::instance();
}
void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw )
{
configwindow = cw;
}
void Wellenreiter::channelHopped(int c)
{
QString title = "Wellenreiter II -scan- [";
QString left;
if ( c > 1 ) left.fill( '.', c-1 );
title.append( left );
title.append( '|' );
if ( c < iface->channels() )
{
QString right;
right.fill( '.', iface->channels()-c );
title.append( right );
}
title.append( "]" );
//title.append( QString().sprintf( " %02d", c ) );
assert( parent() );
( (QMainWindow*) parent() )->setCaption( title );
}
void Wellenreiter::handleNotification( OPacket* p )
{
QObjectList* l = p->queryList();
QObjectListIt it( *l );
QObject* o;
while ( (o = it.current()) != 0 )
{
QString name = it.current()->name();
if ( configwindow->parsePackets->isProtocolChecked( name ) )
{
QString action = configwindow->parsePackets->protocolAction( name );
qDebug( "parsePacket-action for '%s' seems to be '%s'", (const char*) name, (const char*) action );
doAction( action, name, p );
}
else
{
qDebug( "protocol '%s' not checked in parsePackets.", (const char*) name );
}
++it;
}
}
void Wellenreiter::handleBeacon( OPacket* p, OWaveLanManagementPacket* beacon )
{
QString type;
if ( beacon->canIBSS() )
{
type = "adhoc";
}
else if ( beacon->canESS() )
{
type = "managed";
}
else
{
qWarning( "Wellenreiter::invalid frame [possibly noise] detected!" );
return;
}
OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) );
QString essid = ssid ? ssid->ID() : QString("<unknown>");
OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) );
int channel = ds ? ds->channel() : -1;
OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) );
GpsLocation loc( 0, 0 );
if ( configwindow->enableGPS->isChecked() )
{
// TODO: add check if GPS is working!?
qDebug( "Wellenreiter::gathering GPS data..." );
loc = gps->position();
- qDebug( "Wellenreiter::GPS data received is ( %f , %f )", loc.latitude, loc.longitude );
+ qDebug( "Wellenreiter::GPS data received is ( %f , %f ) - dms string = '%s'", loc.latitude(), loc.longitude(), loc.dmsPosition().latin1() );
}
netView()->addNewItem( type, essid, header->macAddress2(), beacon->canPrivacy(), channel, 0, loc );
// update graph window
if ( ds )
{
OPrismHeaderPacket* prism = static_cast<OPrismHeaderPacket*>( p->child( "Prism" ) );
if ( prism )
graphwindow->traffic( ds->channel(), prism->signalStrength() );
else
graphwindow->traffic( ds->channel(), 95 );
}
}
void Wellenreiter::handleWlanData( OPacket* p, OWaveLanDataPacket* data, OMacAddress& from, OMacAddress& to )
{
OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" );
if ( wlan->fromDS() && !wlan->toDS() )
{
netView()->fromDStraffic( wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
from = wlan->macAddress3();
to = wlan->macAddress2();
}
else if ( !wlan->fromDS() && wlan->toDS() )
{
netView()->toDStraffic( wlan->macAddress2(), wlan->macAddress3(), wlan->macAddress1() );
from = wlan->macAddress2();
to = wlan->macAddress3();
}
else if ( wlan->fromDS() && wlan->toDS() )
{
netView()->WDStraffic( wlan->macAddress4(), wlan->macAddress3(), wlan->macAddress1(), wlan->macAddress2() );
from = wlan->macAddress4();
to = wlan->macAddress3();
}
else
{
netView()->IBSStraffic( wlan->macAddress2(), wlan->macAddress1(), wlan->macAddress3() );
from = wlan->macAddress2();
to = wlan->macAddress1();
}
}
void Wellenreiter::handleEthernetData( OPacket* p, OEthernetPacket* data, OMacAddress& from, OMacAddress& to )
{
from = data->sourceAddress();
to = data->destinationAddress();
netView()->addNewItem( "station", "<wired>", from, false, -1, 0, GpsLocation( 0, 0 ) );
}
void Wellenreiter::handleARPData( OPacket* p, OARPPacket*, OMacAddress& source, OMacAddress& dest )
{
OARPPacket* arp = (OARPPacket*) p->child( "ARP" );
if ( arp )
{
qDebug( "Received ARP traffic (type '%s'): ", (const char*) arp->type() );
if ( arp->type() == "REQUEST" )
{
netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
}
else if ( arp->type() == "REPLY" )
{
netView()->identify( arp->senderMacAddress(), arp->senderIPV4Address().toString() );
netView()->identify( arp->targetMacAddress(), arp->targetIPV4Address().toString() );
}
}
}
void Wellenreiter::handleIPData( OPacket* p, OIPPacket* ip, OMacAddress& source, OMacAddress& dest )
{
//TODO: Implement more IP based protocols
ODHCPPacket* dhcp = (ODHCPPacket*) p->child( "DHCP" );
if ( dhcp )
{
qDebug( "Received DHCP '%s' packet", (const char*) dhcp->type() );
if ( dhcp->type() == "OFFER" )
{
qDebug( "DHCP: '%s' ('%s') seems to be a DHCP server.", (const char*) source.toString(), (const char*) dhcp->serverAddress().toString() );
netView()->identify( source, dhcp->serverAddress().toString() );
netView()->addService( "DHCP", source, dhcp->serverAddress().toString() );
}
else if ( dhcp->type() == "ACK" )
{
qDebug( "DHCP: '%s' ('%s') accepted the offered DHCP address.", (const char*) dhcp->clientMacAddress().toString(), (const char*) dhcp->yourAddress().toString() );
netView()->identify( dhcp->clientMacAddress(), dhcp->yourAddress().toString() );
}
}
}
QObject* Wellenreiter::childIfToParse( OPacket* p, const QString& protocol )
{
if ( configwindow->parsePackets->isProtocolChecked( protocol ) )
if ( configwindow->parsePackets->protocolAction( protocol ) == "Discard!" )
return 0;
return p->child( protocol );
}
bool Wellenreiter::checkDumpPacket( OPacket* p )
{
// go through all child packets and see if one is inside the child hierarchy for p
// if so, do what the user requested (protocolAction), e.g. pass or discard
if ( !configwindow->writeCaptureFile->isChecked() )
return true; // semantic change - we're logging anyway now to /tmp/wellenreiter
QObjectList* l = p->queryList();
QObjectListIt it( *l );
QObject* o;
while ( (o = it.current()) != 0 )
{
QString name = it.current()->name();
if ( configwindow->capturePackets->isProtocolChecked( name ) )
{
QString action = configwindow->capturePackets->protocolAction( name );
qDebug( "capturePackets-action for '%s' seems to be '%s'", (const char*) name, (const char*) action );
if ( action == "Discard" )
{
logwindow->log( QString().sprintf( "(i) dump-discarding of '%s' packet requested.", (const char*) name ) );
return false;
}
}
else
{
qDebug( "protocol '%s' not checked in capturePackets.", (const char*) name );
}
++it;
}
return true;
}
void Wellenreiter::receivePacket( OPacket* p )
{
hexWindow()->log( p->dump( 8 ) );
if ( checkDumpPacket( p ) )
{
pcap->dump( p );
}
// check if we received a beacon frame
OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( childIfToParse( p, "802.11 Management" ) );
if ( beacon && beacon->managementType() == "Beacon" )
{
handleBeacon( p, beacon );
return;
}
OMacAddress source;
OMacAddress dest;
//TODO: WEP check here
// check for a wireless data frame
OWaveLanDataPacket* wlan = static_cast<OWaveLanDataPacket*>( childIfToParse( p, "802.11 Data" ) );
if ( wlan )
{
handleWlanData( p, wlan, source, dest );
}
// check for a wired data frame
OEthernetPacket* eth = static_cast<OEthernetPacket*>( childIfToParse( p, "Ethernet" ) );
if ( eth )
{
handleEthernetData( p, eth, source, dest );
}
// check for an arp frame since arp frames come in two flavours:
// 802.11 encapsulates ARP data within IP packets while wired ethernet doesn't.
OARPPacket* arp = static_cast<OARPPacket*>( childIfToParse( p, "ARP" ) );
if ( arp )
{
handleARPData( p, arp, source, dest );
}
// check for a ip frame
OIPPacket* ip = static_cast<OIPPacket*>( childIfToParse( p, "IP" ) );
if ( ip )
{
handleIPData( p, ip, source, dest );
}
//handleNotification( p );
}
void Wellenreiter::stopClicked()
{
if ( iface )
{
disconnect( SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
disconnect( SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
iface->setChannelHopping(); // stop hopping channels
}
else
killTimers();
pcap->close();
sniffing = false;
if ( iface )
{
// switch off monitor mode
iface->setMode( "managed" );
// switch off promisc flag
iface->setPromiscuousMode( false );
system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess
}
logwindow->log( "(i) Stopped Scanning." );
assert( parent() );
( (QMainWindow*) parent() )->setCaption( "Wellenreiter II" );
// message the user
QMessageBox::information( this, "Wellenreiter II",
tr( "Your wireless card\nshould now be usable again." ) );
sniffing = false;
emit( stoppedSniffing() );
#ifdef QWS
if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() )
{
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Enable;
}
#else
#warning FIXME: setScreenSaverMode is not operational on the X11 build
#endif
// print out statistics
for( QMap<QString,int>::ConstIterator it = pcap->statistics().begin(); it != pcap->statistics().end(); ++it )
statwindow->updateCounter( it.key(), it.data() );
}
void Wellenreiter::startClicked()
{
// get configuration from config window
const QString& interface = configwindow->interfaceName->currentText();
const int cardtype = configwindow->driverType();
const int interval = configwindow->hoppingInterval();
if ( ( interface == "" ) || ( cardtype == 0 ) )
{
QMessageBox::information( this, "Wellenreiter II",
tr( "Your device is not\nproperly configured. Please reconfigure!" ) );
return;
}
// configure device
ONetwork* net = ONetwork::instance();
// TODO: check if interface is wireless and support sniffing for non-wireless interfaces
iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // fails if network is not wireless!
// bring device UP
if ( cardtype != DEVTYPE_FILE )
{
iface->setUp( true );
if ( !iface->isUp() )
{
QMessageBox::warning( this, "Wellenreiter II",
tr( "Can't bring interface '%1' up:\n" ).arg( iface->name() ) + strerror( errno ) );
return;
}
}
// set monitor mode
bool usePrism = configwindow->usePrismHeader();
switch ( cardtype )
{
case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface, usePrism ) ); break;
case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface, usePrism ) ); break;
case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface, usePrism ) ); break;
case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface, usePrism ) ); break;
case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", tr( "Bring your device into\nmonitor mode now." ) ); break;
case DEVTYPE_FILE: qDebug( "Wellenreiter: Capturing from file '%s'", (const char*) interface ); break;
default: assert( 0 ); // shouldn't reach this
}
// switch device into monitor mode
if ( cardtype < DEVTYPE_FILE )
{
if ( cardtype != DEVTYPE_MANUAL )
iface->setMode( "monitor" );
if ( iface->mode() != "monitor" )
{
if ( QMessageBox::warning( this, "Wellenreiter II",
tr( "Can't set interface '%1'\ninto monitor mode:\n" ).arg( iface->name() ) + strerror( errno ) +
tr( "\nContinue with limited functionality?" ), QMessageBox::Yes, QMessageBox::No ) == QMessageBox::No )
return;
}
}
// open GPS device
if ( configwindow->enableGPS->isChecked() )
{
qDebug( "Wellenreiter:GPS enabled @ %s:%d", (const char*) configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() );
gps->open( configwindow->gpsdHost->currentText(), configwindow->gpsdPort->value() );
}
// open pcap and start sniffing
if ( configwindow->writeCaptureFile->isChecked() ) // write to a user specified capture file?
{
dumpname = configwindow->captureFileName->text();
if ( dumpname.isEmpty() ) dumpname = "captureFile";
dumpname.append( '-' );
dumpname.append( QTime::currentTime().toString().replace( QRegExp( ":" ), "-" ) );
dumpname.append( ".wellenreiter" );
}
else // write it anyway ;)
{
dumpname = "/var/log/dump.wellenreiter";
}
if ( cardtype != DEVTYPE_FILE )
pcap->open( interface );
else
pcap->open( QFile( interface ) );
qDebug( "Wellenreiter:: dumping to %s", (const char*) dumpname );
pcap->openDumpFile( dumpname );
if ( !pcap->isOpen() )
{
QMessageBox::warning( this, "Wellenreiter II", tr( "Can't open packet capturer for\n'%1':\n" ).arg(
cardtype == DEVTYPE_FILE ? (const char*) interface : iface->name() ) + QString(strerror( errno ) ));
return;
}
// set capturer to non-blocking mode
pcap->setBlocking( false );
// start channel hopper
if ( cardtype != DEVTYPE_FILE )
{
logwindow->log( QString().sprintf( "(i) Starting channel hopper (d=%d ms)", configwindow->hopInterval->value() ) );
iface->setChannelHopping( configwindow->hopInterval->value() ); //use interval from config window
}
if ( cardtype != DEVTYPE_FILE )
{
// connect socket notifier and start channel hopper
connect( pcap, SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) );
connect( iface->channelHopper(), SIGNAL( hopped(int) ), this, SLOT( channelHopped(int) ) );
}
else
{
// start timer for reading packets
startTimer( 100 );
}
logwindow->log( "(i) Started Scanning." );
sniffing = true;
#ifdef QWS
if ( WellenreiterConfigWindow::instance()->disablePM->isChecked() )
{
QCopEnvelope( "QPE/System", "setScreenSaverMode(int)" ) << QPEApplication::Disable;
}
#else
#warning FIXME: setScreenSaverMode is not operational on the X11 build
#endif
emit( startedSniffing() );
if ( cardtype != DEVTYPE_FILE ) channelHopped( 6 ); // set title
else
{
assert( parent() );