author | mickeyl <mickeyl> | 2003-04-07 22:06:01 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-07 22:06:01 (UTC) |
commit | eee5531d24fdb17011debaa7acd42683330e55b6 (patch) (side-by-side diff) | |
tree | 5e82bb5e7c39b1bdb1240eff47dbbe13adcf18cb | |
parent | c32ffdaa4cac3cbe60d4bb6f72e0444a6f9e323f (diff) | |
download | opie-eee5531d24fdb17011debaa7acd42683330e55b6.zip opie-eee5531d24fdb17011debaa7acd42683330e55b6.tar.gz opie-eee5531d24fdb17011debaa7acd42683330e55b6.tar.bz2 |
New feature! Finally, non-AP stations in an infrastructure network show up.
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.cpp | 85 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.h | 1 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/wellenreiter.cpp | 88 |
3 files changed, 138 insertions, 36 deletions
diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp index 34c69f5..1525934 100644 --- a/noncore/net/wellenreiter/gui/scanlist.cpp +++ b/noncore/net/wellenreiter/gui/scanlist.cpp @@ -1,239 +1,292 @@ /********************************************************************** ** 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 <assert.h> #include "manufacturers.h" #include <qdatetime.h> #include <qtextstream.h> #ifdef QWS #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_manuf = 6; +const int col_firstseen = 7; +const int col_lastseen = 8; + MScanListView::MScanListView( QWidget* parent, const char* name ) :OListView( parent, name ), _manufacturerdb( 0 ) { setFrameShape( QListView::StyledPanel ); setFrameShadow( QListView::Sunken ); addColumn( tr( "Net/Station" ) ); setColumnAlignment( 0, AlignLeft || AlignVCenter ); addColumn( tr( "B" ) ); setColumnAlignment( 1, AlignCenter ); addColumn( tr( "AP" ) ); setColumnAlignment( 2, AlignCenter ); addColumn( tr( "Chn" ) ); setColumnAlignment( 3, AlignCenter ); addColumn( tr( "W" ) ); setColumnAlignment( 4, AlignCenter ); addColumn( tr( "T" ) ); setColumnAlignment( 5, AlignCenter ); addColumn( tr( "Manufacturer" ) ); setColumnAlignment( 6, AlignCenter ); addColumn( tr( "First Seen" ) ); setColumnAlignment( 7, AlignCenter ); addColumn( tr( "Last Seen" ) ); setColumnAlignment( 8, AlignCenter ); setRootIsDecorated( true ); setAllColumnsShowFocus( true ); }; 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::setManufacturerDB( ManufacturerDB* manufacturerdb ) { _manufacturerdb = manufacturerdb; } void MScanListView::addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ) { // FIXME: scanlistitem needs a proper encapsulation and not such a damn dealing with text(...) qDebug( "MScanList::addNewItem( %s / %s / %s [%d]", (const char*) type, (const char*) essid, (const char*) macaddr, channel ); // search, if we already have seen this net QString s; MScanListItem* network; MScanListItem* item = static_cast<MScanListItem*> ( firstChild() ); while ( item && ( item->text( 0 ) != essid ) ) { qDebug( "itemtext: %s", (const char*) item->text( 0 ) ); item = static_cast<MScanListItem*> ( item->itemBelow() ); } if ( item ) { // animate the item - + /* const QPixmap* pixmap = item->pixmap( 0 ); const QPixmap* nextpixmap = ani2; if ( pixmap == ani1 ) nextpixmap = ani2; else if ( pixmap == ani2 ) nextpixmap = ani3; else if ( pixmap == ani3 ) nextpixmap = ani4; else if ( pixmap == ani4 ) nextpixmap = ani1; item->setPixmap( 0, *nextpixmap ); */ //qDebug( "current pixmap %d, next %d", pixmap, nextpixmap ); // 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( 2 ) != macaddr ) ) { qDebug( "subitemtext: %s", (const char*) item->text( 2 ) ); item = static_cast<MScanListItem*> ( item->itemBelow() ); } 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: '%s'", (const char*) essid ); network = new MScanListItem( this, "networks", 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!? qDebug( "inserting new station %s", (const char*) macaddr ); MScanListItem* station = new MScanListItem( network, type, "", macaddr, wep, channel, signal ); if ( _manufacturerdb ) station->setManufacturer( _manufacturerdb->lookup( macaddr ) ); if ( type == "managed" ) { s.sprintf( "(i) new AP in '%s' [%d]", (const char*) essid, channel ); } else { s.sprintf( "(i) new adhoc station in '%s' [%d]", (const char*) essid, channel ); } } -#ifdef QWS -#include <qpe/resource.h> -#else -#include "resource.h" -#endif +void MScanListView::traffic( QString type, QString from, QString to, QString via, QString additional ) +{ + if ( type != "toDS" ) return; -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_manuf = 6; -const int col_firstseen = 7; -const int col_lastseen = 8; + qDebug( "MScanList::traffic( [%s] | %s -> %s (via %s)", + (const char*) type, (const char*) from, + (const char*) to, (const char*) via ); + + QString s; + MScanListItem* network; + + QListViewItemIterator it( this ); + while ( it.current() && it.current()->text( col_ap ) != via ) ++it; + + MScanListItem* item = static_cast<MScanListItem*>( it.current() ); + + if ( item ) // AP has been shown up, so just add our new "from" - station + { + network = static_cast<MScanListItem*>( item->parent() ); + MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() ); + + while ( subitem && ( subitem->text( col_ap ) != from ) ) + { + qDebug( "subitemtext: %s", (const char*) subitem->text( col_ap ) ); + subitem = static_cast<MScanListItem*> ( subitem->itemBelow() ); + } + + if ( subitem ) + { + // we have already seen this item, it's a dupe + #ifdef DEBUG + qDebug( "%s is a dupe - ignoring...", (const char*) from ); + #endif + subitem->receivedBeacon(); //FIXME: sent data bit + return; + } + + // Hey, it seems to be a new item :-D + MScanListItem* station = new MScanListItem( item->parent(), "adhoc", /* network->text( col_essid ) */ "", from, false, -1, -1 ); + if ( _manufacturerdb ) + station->setManufacturer( _manufacturerdb->lookup( from ) ); + } + else + { + qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in alpha-4 version :-D" ); + } +} + +//============================================================ +// 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 ) { qDebug( "creating scanlist item" ); if ( WellenreiterConfigWindow::instance() && type == "networks" ) 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 ) { qDebug( "creating scanlist item" ); decorateItem( type, essid, macaddr, wep, channel, signal ); } OListViewItem* MScanListItem::childFactory() { return new MScanListItem( this ); } void MScanListItem::serializeTo( QDataStream& s ) const { qDebug( "serializing MScanListItem" ); OListViewItem::serializeTo( s ); s << _type; s << (Q_UINT8) _wep; } void MScanListItem::serializeFrom( QDataStream& s ) { qDebug( "serializing MScanListItem" ); OListViewItem::serializeFrom( s ); s >> _type; s >> (Q_UINT8) _wep; 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! diff --git a/noncore/net/wellenreiter/gui/scanlist.h b/noncore/net/wellenreiter/gui/scanlist.h index 01db172..bed69f1 100644 --- a/noncore/net/wellenreiter/gui/scanlist.h +++ b/noncore/net/wellenreiter/gui/scanlist.h @@ -1,89 +1,90 @@ /********************************************************************** ** 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 <opie2/olistview.h> #include <qtextstream.h> class QString; class ManufacturerDB; class MScanListView: public OListView { Q_OBJECT public: MScanListView( QWidget* parent = 0, const char* name = 0 ); virtual ~MScanListView(); void setManufacturerDB( ManufacturerDB* manufacturerdb ); virtual OListViewItem* childFactory(); virtual void serializeTo( QDataStream& s ) const; virtual void serializeFrom( QDataStream& s ); public slots: void addNewItem( QString type, QString essid, QString macaddr, bool wep, int channel, int signal ); + void traffic( QString type, QString from, QString to, QString via, QString additional = QString::null ); private: ManufacturerDB* _manufacturerdb; }; //****************************** 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() { return _essid; }; 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 ); diff --git a/noncore/net/wellenreiter/gui/wellenreiter.cpp b/noncore/net/wellenreiter/gui/wellenreiter.cpp index aa33158..8d18f73 100644 --- a/noncore/net/wellenreiter/gui/wellenreiter.cpp +++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp @@ -68,118 +68,166 @@ Wellenreiter::Wellenreiter( QWidget* parent ) #ifdef QWS manufile.sprintf( "%s/share/wellenreiter/manufacturers.dat", (const char*) QPEApplication::qpeDir() ); #else manufile.sprintf( "/usr/local/share/wellenreiter/manufacturers.dat" ); #endif manufacturerdb = new ManufacturerDB( manufile ); 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 // setup GUI netview->setColumnWidthMode( 1, QListView::Manual ); if ( manufacturerdb ) netview->setManufacturerDB( manufacturerdb ); pcap = new OPacketCapturer(); } Wellenreiter::~Wellenreiter() { // no need to delete child widgets, Qt does it all for us delete manufacturerdb; delete pcap; } void Wellenreiter::setConfigWindow( WellenreiterConfigWindow* cw ) { configwindow = cw; } void Wellenreiter::receivePacket(OPacket* p) { hexWindow()->log( p->dump( 8 ) ); // check if we received a beacon frame - // static_cast is justified here OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) ); - if ( !beacon ) return; - QString type; - - //FIXME: Can stations in ESS mode can be distinguished from APs? - //FIXME: Apparently yes, but not by listening to beacons, because - //FIXME: they simply don't send beacons in infrastructure mode. - //FIXME: so we also have to listen to data packets - - if ( beacon->canIBSS() ) - type = "adhoc"; - else - type = "managed"; - - 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; + if ( beacon ) + { + QString type; + if ( beacon->canIBSS() ) + type = "adhoc"; + else + type = "managed"; + + 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" ) ); + netView()->addNewItem( type, essid, header->macAddress2().toString(), header->usesWep(), channel, 0 ); + return; + } - OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); - netView()->addNewItem( type, essid, header->macAddress2().toString(), header->usesWep(), channel, 0 ); + // check for a data frame + OWaveLanDataPacket* data = static_cast<OWaveLanDataPacket*>( p->child( "802.11 Data" ) ); + if ( data ) + { + OWaveLanPacket* wlan = (OWaveLanPacket*) p->child( "802.11" ); + if ( wlan->fromDS() && !wlan->toDS() ) + { + qDebug( "FromDS traffic: '%s' -> '%s' via '%s'", + (const char*) wlan->macAddress3().toString(true), + (const char*) wlan->macAddress1().toString(true), + (const char*) wlan->macAddress2().toString(true) ); + netView()->traffic( "fromDS", wlan->macAddress3().toString(), + wlan->macAddress1().toString(), + wlan->macAddress2().toString() ); + } + else + if ( !wlan->fromDS() && wlan->toDS() ) + { + qDebug( "ToDS traffic: '%s' -> '%s' via '%s'", + (const char*) wlan->macAddress2().toString(true), + (const char*) wlan->macAddress3().toString(true), + (const char*) wlan->macAddress1().toString(true) ); + netView()->traffic( "toDS", wlan->macAddress2().toString(), + wlan->macAddress3().toString(), + wlan->macAddress1().toString() ); + } + else + if ( wlan->fromDS() && wlan->toDS() ) + { + qDebug( "WSD(bridge) traffic: '%s' -> '%s' via '%s' and '%s'", + (const char*) wlan->macAddress4().toString(true), + (const char*) wlan->macAddress3().toString(true), + (const char*) wlan->macAddress1().toString(true), + (const char*) wlan->macAddress2().toString(true) ); + netView()->traffic( "WSD", wlan->macAddress4().toString(), + wlan->macAddress3().toString(), + wlan->macAddress1().toString(), + wlan->macAddress2().toString() ); + } + else + { + qDebug( "IBSS(AdHoc) traffic: '%s' -> '%s' (Cell: '%s')'", + (const char*) wlan->macAddress2().toString(true), + (const char*) wlan->macAddress1().toString(true), + (const char*) wlan->macAddress3().toString(true) ); + netView()->traffic( "fromDS", wlan->macAddress2().toString(), + wlan->macAddress1().toString(), + wlan->macAddress3().toString() ); + } + return; + } } void Wellenreiter::startStopClicked() { if ( sniffing ) { disconnect( SIGNAL( receivedPacket(OPacket*) ), this, SLOT( receivePacket(OPacket*) ) ); iface->setChannelHopping(); // stop hopping channels pcap->close(); sniffing = false; #ifdef QWS oApp->setTitle(); #else qApp->mainWidget()->setCaption( "Wellenreiter II" ); #endif // get interface name from config window const QString& interface = configwindow->interfaceName->currentText(); ONetwork* net = ONetwork::instance(); iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // switch off monitor mode iface->setMonitorMode( false ); // switch off promisc flag iface->setPromiscuousMode( false ); system( "cardctl reset; sleep 1" ); //FIXME: Use OProcess logwindow->log( "(i) Stopped Scanning." ); // message the user QMessageBox::information( this, "Wellenreiter II", "Your wireless card\nshould now be usable again." ); } else { // get configuration from config window const QString& interface = configwindow->interfaceName->currentText(); const int cardtype = configwindow->daemonDeviceType(); const int interval = configwindow->daemonHopInterval(); if ( ( interface == "" ) || ( cardtype == 0 ) ) { QMessageBox::information( this, "Wellenreiter II", "Your device is not\nproperly configured. Please reconfigure!" ); return; } |