author | mickeyl <mickeyl> | 2003-05-02 22:27:24 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-05-02 22:27:24 (UTC) |
commit | 9325b8e82d2cf1df1233bcfb21d91f61f8e444a3 (patch) (side-by-side diff) | |
tree | d9d32a0b47abeefe2f7d576db82ed45a1227caf3 | |
parent | 0a7f622dd6e9b37a52c7a4b2382d4c3486326c3f (diff) | |
download | opie-9325b8e82d2cf1df1233bcfb21d91f61f8e444a3.zip opie-9325b8e82d2cf1df1233bcfb21d91f61f8e444a3.tar.gz opie-9325b8e82d2cf1df1233bcfb21d91f61f8e444a3.tar.bz2 |
start to parse and interpretate WDS (bridging) data and thus additionally display stationary systems
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.cpp | 90 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/scanlist.h | 10 | ||||
-rw-r--r-- | noncore/net/wellenreiter/gui/wellenreiter.cpp | 28 |
3 files changed, 85 insertions, 43 deletions
diff --git a/noncore/net/wellenreiter/gui/scanlist.cpp b/noncore/net/wellenreiter/gui/scanlist.cpp index a8cadd8..7733934 100644 --- a/noncore/net/wellenreiter/gui/scanlist.cpp +++ b/noncore/net/wellenreiter/gui/scanlist.cpp @@ -98,240 +98,274 @@ 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, "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!? 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 ); } } -void MScanListView::traffic( QString type, QString from, QString to, QString via, QString additional ) + +void MScanListView::addIfNotExisting( MScanListItem* network, QString addr ) { - if ( type != "toDS" ) return; + MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() ); + + while ( subitem && ( subitem->text( col_ap ) != addr ) ) + { + 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*) addr ); + #endif + subitem->receivedBeacon(); //FIXME: sent data bit + return; + } + + // Hey, it seems to be a new item :-D + MScanListItem* station = new MScanListItem( network, "station", /* network->text( col_essid ) */ "", addr, false, -1, -1 ); + if ( _manufacturerdb ) + station->setManufacturer( _manufacturerdb->lookup( addr ) ); +} - qDebug( "MScanList::traffic( [%s] | %s -> %s (via %s)", - (const char*) type, (const char*) from, - (const char*) to, (const char*) via ); +void MScanListView::WDStraffic( QString from, QString to, QString viaFrom, QString viaTo ) +{ QString s; MScanListItem* network; QListViewItemIterator it( this ); - while ( it.current() && it.current()->text( col_ap ) != via ) ++it; + while ( it.current() && + it.current()->text( col_ap ) != viaFrom && + it.current()->text( col_ap ) != viaTo ) ++it; MScanListItem* item = static_cast<MScanListItem*>( it.current() ); - if ( item ) // AP has been shown up, so just add our new "from" - station + 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 { - network = static_cast<MScanListItem*>( item->parent() ); - MScanListItem* subitem = static_cast<MScanListItem*>( network->firstChild() ); + qDebug( "D'Oh! Stations without AP... ignoring for now... will handle this in 1.1 version :-D" ); + } +} - 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; - } +void MScanListView::toDStraffic( QString from, QString to, QString 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() ); - // 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 ) ); + if ( item ) // AP has shown up yet, so just add our new "from" - station + { + addIfNotExisting( static_cast<MScanListItem*>(item->parent()), from ); } else { - qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in alpha-4 version :-D" ); + qDebug( "D'Oh! Station without AP... ignoring for now... will handle this in 1.1 :-D" ); } } +void MScanListView::fromDStraffic( QString from, QString to, QString via ) +{ + qWarning( "D'oh! Not yet implemented..." ); +} + +void MScanListView::IBSStraffic( QString from, QString to, QString via ) +{ + qWarning( "D'oh! Not yet implemented..." ); +} + //============================================================ // 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 == "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 ) { 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 ? 'y' : 'n' ); } void MScanListItem::serializeFrom( QDataStream& s ) { qDebug( "serializing MScanListItem" ); 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 ) { qDebug( "decorating scanlist item %s / %s / %s [%d]", (const char*) type, (const char*) essid, (const char*) macaddr, channel ); // 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; } void MScanListItem::setManufacturer( const QString& manufacturer ) diff --git a/noncore/net/wellenreiter/gui/scanlist.h b/noncore/net/wellenreiter/gui/scanlist.h index bed69f1..a14d426 100644 --- a/noncore/net/wellenreiter/gui/scanlist.h +++ b/noncore/net/wellenreiter/gui/scanlist.h @@ -1,125 +1,133 @@ /********************************************************************** ** 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 MScanListItem; + 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 ); + void fromDStraffic( QString from, QString to, QString via ); // NYI + void toDStraffic( QString from, QString to, QString via ); + void WDStraffic( QString from, QString to, QString viaFrom, QString viaTo ); + void IBSStraffic( QString from, QString to, QString via ); // NYI + + protected: + void addIfNotExisting( MScanListItem* parent, QString addr ); 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 ); 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 5ec9ee4..4b82c9a 100644 --- a/noncore/net/wellenreiter/gui/wellenreiter.cpp +++ b/noncore/net/wellenreiter/gui/wellenreiter.cpp @@ -87,229 +87,229 @@ Wellenreiter::Wellenreiter( QWidget* parent ) 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::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::receivePacket(OPacket* p) { hexWindow()->log( p->dump( 8 ) ); // check if we received a beacon frame OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) ); if ( beacon && beacon->managementType() == "Beacon" ) { QString type; if ( beacon->canIBSS() ) { type = "adhoc"; } else if ( beacon->canESS() ) { type = "managed"; } else { qDebug( "Wellenreiter::invalid frame detected: '%s'", (const char*) p->dump( 16 ) ); 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" ) ); netView()->addNewItem( type, essid, header->macAddress2().toString(), beacon->canPrivacy(), channel, 0 ); return; } // 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() ); + netView()->fromDStraffic( 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() ); + netView()->toDStraffic( 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'", + qDebug( "WDS(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() ); + netView()->WDStraffic( 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( "IBSS", wlan->macAddress2().toString(), - wlan->macAddress1().toString(), - wlan->macAddress3().toString() ); + netView()->IBSStraffic( wlan->macAddress2().toString(), + wlan->macAddress1().toString(), + wlan->macAddress3().toString() ); } return; } } 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->setMonitorMode( false ); // 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", "Your wireless card\nshould now be usable again." ); sniffing = false; emit( stoppedSniffing() ); // 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->daemonDeviceType(); const int interval = configwindow->daemonHopInterval(); if ( ( interface == "" ) || ( cardtype == 0 ) ) { QMessageBox::information( this, "Wellenreiter II", "Your device is not\nproperly configured. Please reconfigure!" ); return; } // configure device ONetwork* net = ONetwork::instance(); iface = static_cast<OWirelessNetworkInterface*>(net->interface( interface )); // set monitor mode switch ( cardtype ) { case DEVTYPE_CISCO: iface->setMonitoring( new OCiscoMonitoringInterface( iface ) ); break; case DEVTYPE_WLAN_NG: iface->setMonitoring( new OWlanNGMonitoringInterface( iface ) ); break; case DEVTYPE_HOSTAP: iface->setMonitoring( new OHostAPMonitoringInterface( iface ) ); break; case DEVTYPE_ORINOCO: iface->setMonitoring( new OOrinocoMonitoringInterface( iface ) ); break; case DEVTYPE_MANUAL: QMessageBox::information( this, "Wellenreiter II", "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->setMonitorMode( true ); if ( !iface->monitorMode() ) { QMessageBox::warning( this, "Wellenreiter II", "Can't set device into monitor mode." ); return; } } // open pcap and start sniffing if ( cardtype != DEVTYPE_FILE ) { if ( configwindow->writeCaptureFile->isEnabled() ) { QString dumpname( configwindow->captureFileName->text() ); |