summaryrefslogtreecommitdiff
path: root/libopie2/opienet/onetwork.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp106
1 files changed, 62 insertions, 44 deletions
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
@@ -644,98 +644,140 @@ double OWirelessNetworkInterface::frequency() const
return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
}
}
int OWirelessNetworkInterface::channels() const
{
return _channels.count();
}
void OWirelessNetworkInterface::setChannelHopping( int interval )
{
if ( !_hopper ) _hopper = new OChannelHopper( this );
_hopper->setInterval( interval );
//FIXME: When and by whom will the channel hopper be deleted?
//TODO: rely on QObject hierarchy
}
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>";
+ // 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)
+
+ if ( mode() == "monitor" )
+ {
+ qDebug( "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." );
+ if ( _mon )
+ _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" );
+ }
}
- return modeToString( _iwr.u.mode );
}
-void OWirelessNetworkInterface::setMonitorMode( bool b )
+QString OWirelessNetworkInterface::mode() const
{
- if ( _mon )
- _mon->setEnabled( b );
- else
- qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
-}
+ 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 ) );
-bool OWirelessNetworkInterface::monitorMode() 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?
-}
+ // 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];
_iwr.u.data.pointer = &str[0];
_iwr.u.data.length = IW_ESSID_MAX_SIZE;
if ( !wioctl( SIOCGIWNICKN ) )
{
return "<unknown>";
}
else
{
str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
return str;
}
}
void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
{
OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
if ( !priv )
{
qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
@@ -940,70 +982,64 @@ bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
bool OWirelessNetworkInterface::wioctl( int call ) const
{
strcpy( _iwr.ifr_name, name() );
return wioctl( call, _iwr );
}
/*======================================================================================
* OMonitoringInterface
*======================================================================================*/
OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
:_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader )
{
}
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 )
{
iface->setMonitoring( this );
}
OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
{
}
void OCiscoMonitoringInterface::setEnabled( bool b )
{
QString fname;
fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
QFile f( fname );
if ( !f.exists() ) return;
if ( f.open( IO_WriteOnly ) )
{
QTextStream s( &f );
s << "Mode: r";
@@ -1063,112 +1099,94 @@ QString OWlanNGMonitoringInterface::name() const
}
void OWlanNGMonitoringInterface::setChannel( int c )
{
//NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't.
QString enable = "true"; //_if->monitorMode() ? "true" : "false";
QString prism = _prismHeader ? "true" : "false";
QString cmd;
cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
(const char*) _if->name(), c, (const char*) enable, (const char*) prism );
system( cmd );
}
/*======================================================================================
* OHostAPMonitoringInterface
*======================================================================================*/
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
*======================================================================================*/
OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
:OMonitoringInterface( iface, prismHeader )
{
iface->setMonitoring( this );
}
OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
{
}
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";
}