-rw-r--r-- | libopie2/examples/opiecore/odebugdemo/odebugdemo.pro | 3 | ||||
-rw-r--r-- | libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp | 37 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 98 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 16 |
4 files changed, 103 insertions, 51 deletions
diff --git a/libopie2/examples/opiecore/odebugdemo/odebugdemo.pro b/libopie2/examples/opiecore/odebugdemo/odebugdemo.pro index c52cd02..aa37394 100644 --- a/libopie2/examples/opiecore/odebugdemo/odebugdemo.pro +++ b/libopie2/examples/opiecore/odebugdemo/odebugdemo.pro @@ -1,19 +1,20 @@ TEMPLATE = app CONFIG = qt warn_on debug HEADERS = SOURCES = odebugdemo.cpp INCLUDEPATH += $(OPIEDIR)/include DEPENDPATH += $(OPIEDIR)/include LIBS += -lopiecore2 TARGET = odebugdemo -MOC_DIR = moc OBJECTS_DIR = obj !contains( platform, x11 ) { include ( $(OPIEDIR)/include.pro ) } contains( platform, x11 ) { LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib } + +MOC_DIR = moc diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp index 21026e1..06b8b19 100644 --- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp +++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp @@ -1,71 +1,82 @@ #include <opie2/onetwork.h> #include <opie2/ostation.h> #include <opie2/omanufacturerdb.h> +#include <unistd.h> + int main( int argc, char** argv ) { qDebug( "OPIE Network Demo" ); ONetwork* net = ONetwork::instance(); ONetwork::InterfaceIterator it = net->iterator(); while ( it.current() ) { qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() ); + qDebug( "DEMO: Datalink code is '%d'", it.current()->dataLinkType() ); qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() ); qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) ); qDebug( "DEMO: MAC Manufacturer seems to be '%s'", (const char*) it.current()->macAddress().manufacturer() ); qDebug( "DEMO: Manufacturertest1 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "08:00:87" ) ); qDebug( "DEMO: Manufacturertest2 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) ); qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() ); if ( it.current()->isWireless() ) { OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() ); qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() ); qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() ); qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() ); //if ( iface->mode() == OWirelessNetworkInterface::adhoc ) //{ - qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP().toString() ); + //qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP().toString() ); //} + /* + // nickname qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() ); iface->setNickName( "MyNickName" ); if ( iface->nickName() != "MyNickName" ) qDebug( "DEMO: Warning! Can't change nickname" ); else qDebug( "DEMO: Nickname change successful." ); + /* + // operation mode qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() ); iface->setMode( "adhoc" ); if ( iface->mode() != "adhoc" ) qDebug( "DEMO: Warning! Can't change operation mode" ); else qDebug( "DEMO: Operation Mode change successful." ); // RF channel qDebug( "DEMO: Current Channel is '%d'", iface->channel() ); iface->setChannel( 1 ); if ( iface->channel() != 1 ) qDebug( "DEMO: Warning! Can't change RF channel" ); else qDebug( "DEMO: RF channel change successful." ); iface->setMode( "managed" ); + */ + + /* + // network scan OStationList* stations = iface->scanNetwork(); if ( stations ) { qDebug( "DEMO: # of stations around = %d", stations->count() ); OStation* station; for ( station = stations->first(); station != 0; station = stations->next() ) { qDebug( "DEMO: station dump following..." ); station->dump(); } @@ -88,20 +99,44 @@ int main( int argc, char** argv ) // trying to set hw address to 12:34:56:AB:CD:EF /* OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" ); iface->setUp( false ); iface->setMacAddress( addr ); iface->setUp( true ); qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() ); */ + // monitor test + + /* + + qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() ); + iface->setMode( "monitor" ); + qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() ); + + sleep( 1 ); */ + + iface->setMode( "master" ); + + //sleep( 1 ); + qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() ); + + /*iface->setMode( "adhoc" ); + sleep( 1 ); + qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() ); + iface->setMode( "managed" ); + sleep( 1 ); + qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() ); + iface->setMode( "master" ); + sleep( 1 ); + qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );*/ } ++it; } return 0; } diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 50c6679..c329e9a 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp @@ -664,58 +664,100 @@ void OWirelessNetworkInterface::setChannelHopping( int interval ) int OWirelessNetworkInterface::channelHopping() const { return _hopper->interval(); } OChannelHopper* OWirelessNetworkInterface::channelHopper() const { return _hopper; } -void OWirelessNetworkInterface::setMode( const QString& mode ) +void OWirelessNetworkInterface::commit() const { - _iwr.u.mode = stringToMode( mode ); - wioctl( SIOCSIWMODE ); + wioctl( SIOCSIWCOMMIT ); } -QString OWirelessNetworkInterface::mode() const +void OWirelessNetworkInterface::setMode( const QString& newMode ) { - if ( !wioctl( SIOCGIWMODE ) ) + #ifdef FINALIZE + QString currentMode = mode(); + if ( currentMode == newMode ) return; + #endif + + qDebug( "OWirelessNetworkInterface::setMode(): trying to set mode '%s' (%d)", (const char*) newMode, stringToMode( newMode ) ); + + _iwr.u.mode = stringToMode( newMode ); + + if ( _iwr.u.mode != IW_MODE_MONITOR ) { - return "<unknown>"; - } - return modeToString( _iwr.u.mode ); -} + // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! + _iwr.u.mode = stringToMode( newMode ); + wioctl( SIOCSIWMODE ); + // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) -void OWirelessNetworkInterface::setMonitorMode( bool b ) + if ( mode() == "monitor" ) { + qDebug( "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." ); if ( _mon ) - _mon->setEnabled( b ); + _mon->setEnabled( false ); else qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); } + } + else // special iwpriv fallback for monitor mode + { + if ( wioctl( SIOCSIWMODE ) ) + { + qDebug( "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" ); + } + else + { + qDebug( "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." ); + + if ( _mon ) + _mon->setEnabled( true ); + else + qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); + } + } +} + -bool OWirelessNetworkInterface::monitorMode() const +QString OWirelessNetworkInterface::mode() const { - qDebug( "dataLinkType = %d", dataLinkType() ); - return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); - //FIXME: 802 is the header type for PRISM - Linux support for this is pending... - //FIXME: What is 119, by the way? + memset( &_iwr, 0, sizeof( struct iwreq ) ); + + if ( !wioctl( SIOCGIWMODE ) ) + { + return "<unknown>"; } + qDebug( "DEBUG: WE's idea of current mode seems to be '%s'", (const char*) modeToString( _iwr.u.mode ) ); + + // legacy compatible monitor mode check + + if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) + { + return "monitor"; + } + else + { + return modeToString( _iwr.u.mode ); + } +} void OWirelessNetworkInterface::setNickName( const QString& nickname ) { _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); _iwr.u.essid.length = nickname.length(); wioctl( SIOCSIWNICKN ); } QString OWirelessNetworkInterface::nickName() const { char str[IW_ESSID_MAX_SIZE]; @@ -960,30 +1002,24 @@ OMonitoringInterface::~OMonitoringInterface() void OMonitoringInterface::setChannel( int c ) { // use standard WE channel switching protocol memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); _if->_iwr.u.freq.m = c; _if->_iwr.u.freq.e = 0; _if->wioctl( SIOCSIWFREQ ); } -bool OMonitoringInterface::enabled() const -{ - return _if->monitorMode(); -} - - void OMonitoringInterface::setEnabled( bool b ) { } /*====================================================================================== * OCiscoMonitoringInterface *======================================================================================*/ OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) :OMonitoringInterface( iface, prismHeader ) { @@ -1083,43 +1119,33 @@ void OWlanNGMonitoringInterface::setChannel( int c ) OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) :OMonitoringInterface( iface, prismHeader ) { iface->setMonitoring( this ); } OHostAPMonitoringInterface::~OHostAPMonitoringInterface() { } void OHostAPMonitoringInterface::setEnabled( bool b ) { - // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 - // Wireless Extensions < Version 15 need iwpriv commandos for monitoring - - #if WIRELESS_EXT > 14 - if ( b ) - _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header - else - _if->setMode( "managed" ); - #else int monitorCode = _prismHeader ? 1 : 2; if ( b ) { _if->setPrivate( "monitor", 1, monitorCode ); } else { _if->setPrivate( "monitor", 1, 0 ); } - #endif } QString OHostAPMonitoringInterface::name() const { return "hostap"; } /*====================================================================================== * OOrinocoNetworkInterface *======================================================================================*/ @@ -1140,35 +1166,27 @@ void OOrinocoMonitoringInterface::setChannel( int c ) { int monitorCode = _prismHeader ? 1 : 2; _if->setPrivate( "monitor", 2, monitorCode, c ); } void OOrinocoMonitoringInterface::setEnabled( bool b ) { // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring // However, as of recent orinoco drivers, IW_MODE_MONITOR is still not supported - #if 0 - //#if WIRELESS_EXT > 14 - if ( b ) - _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header - else - _if->setMode( "managed" ); - #else if ( b ) { setChannel( 1 ); } else { _if->setPrivate( "monitor", 2, 0, 0 ); } - #endif } QString OOrinocoMonitoringInterface::name() const { return "orinoco"; } diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 0eb4542..eb6c86e 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h @@ -340,42 +340,37 @@ class OWirelessNetworkInterface : public ONetworkInterface */ virtual int channels() const; /** * Set the IEEE 802.11 operation @a mode. * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master * @warning Not all drivers support the all modes. * @note You might have to change the SSID to get the operation mode change into effect. */ virtual void setMode( const QString& mode ); /** * @returns the current IEEE 802.11 operation mode. * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown - */ - virtual QString mode() const; - /** + * + * @note: Important note concerning the 'monitor' mode: * Setting the monitor mode on a wireless network interface enables * listening to IEEE 802.11 data and management frames which normally * are handled by the device firmware. This can be used to detect * other wireless network devices, e.g. Access Points or Ad-hoc stations. * @warning Standard wireless network drives don't support the monitor mode. * @warning You need a patched driver for this to work. * @note Enabling the monitor mode is highly driver dependent and requires * the proper @ref OMonitoringInterface to be associated with the interface. * @see OMonitoringInterface */ - virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); Use IW_MONITOR first, if this doesn't work, then use iwpriv! - /** - * @returns true if the device is listening in IEEE 802.11 monitor mode - */ - virtual bool monitorMode() const; //FIXME: ==> mode() + virtual QString mode() const; /** * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. * @see OChannelHopper */ virtual void setChannelHopping( int interval = 0 ); /** * @returns the channel hopping interval or 0, if channel hopping is disabled. */ virtual int channelHopping() const; /** * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before */ @@ -413,24 +408,28 @@ class OWirelessNetworkInterface : public ONetworkInterface * which network to associate with (use "any" to let the driver decide). */ virtual void setSSID( const QString& ssid ); /** * @returns the current SSID (Service Set ID). */ virtual QString SSID() const; /** * Perform scanning the wireless network neighbourhood. * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! */ virtual OStationList* scanNetwork(); + /** @internal commit pending changes to the driver + * + */ + void commit() const; protected: void buildInformation(); void buildPrivateList(); void dumpInformation() const; virtual void init(); struct iwreq& iwr() const; bool wioctl( int call ) const; bool wioctl( int call, struct iwreq& ) const; protected: mutable struct iwreq _iwr; @@ -447,25 +446,24 @@ class OWirelessNetworkInterface : public ONetworkInterface *======================================================================================*/ class OMonitoringInterface { public: OMonitoringInterface(); OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); virtual ~OMonitoringInterface(); public: virtual void setEnabled( bool ); - virtual bool enabled() const; virtual void setChannel( int ); virtual QString name() const = 0; protected: OWirelessNetworkInterface* _if; bool _prismHeader; }; /*====================================================================================== |