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.cpp40
1 files changed, 29 insertions, 11 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 1d3b9fe..25c70e0 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -290,9 +290,10 @@ bool ONetworkInterface::isWireless() const
*======================================================================================*/
OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
:QObject( 0, "Mickey's funky hopper" ),
- _iface( iface ), _interval( 0 ), _channel( 0 ), _tid( 0 )
+ _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ),
+ _maxChannel( iface->channels()+1 )
{
}
@@ -300,12 +301,23 @@ OChannelHopper::~OChannelHopper()
{
}
+bool OChannelHopper::isActive() const
+{
+ return _tid;
+}
+
+
+int OChannelHopper::channel() const
+{
+ return _channel;
+}
+
+
void OChannelHopper::timerEvent( QTimerEvent* )
{
- //FIXME: Get available channels from OWirelessNetworkInterface
- if ( --_channel < 0 ) _channel = 13;
+ if ( !--_channel ) _channel = _maxChannel;
_iface->setChannel( _channel );
qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
_channel, (const char*) _iface->name() );
}
@@ -318,8 +330,9 @@ void OChannelHopper::setInterval( int interval )
if ( _interval )
killTimer( _tid );
+ _tid = 0;
_interval = interval;
if ( _interval )
{
@@ -338,9 +351,9 @@ int OChannelHopper::interval() const
* OWirelessNetworkInterface
*======================================================================================*/
OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name )
- :ONetworkInterface( name ), _hopper( this )
+ :ONetworkInterface( name ), _hopper( 0 )
{
qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
init();
}
@@ -375,15 +388,12 @@ void OWirelessNetworkInterface::init()
qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) );
return;
}
- //TODO: Find out what the difference between num_channel and
- // num_frequency is about.
-
for ( int i = 0; i < range.num_frequency; ++i )
{
int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 );
- _channels.insert( freq, i );
+ _channels.insert( freq, i+1 );
}
}
@@ -411,15 +421,20 @@ QString OWirelessNetworkInterface::associatedAP() const
int OWirelessNetworkInterface::channel() const
{
+ //FIXME: When monitoring enabled, then use it
+ //FIXME: to gather the current RF channel
+ //FIXME: Until then, get active channel from hopper.
+ if ( _hopper && _hopper->isActive() )
+ return _hopper->channel();
+
if ( !wioctl( SIOCGIWFREQ ) )
{
return -1;
}
else
{
- //FIXME: This is off-by-one !? Why?
return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ];
}
}
@@ -460,15 +475,17 @@ int OWirelessNetworkInterface::channels() const
void OWirelessNetworkInterface::setChannelHopping( int interval )
{
- _hopper.setInterval( interval );
+ if ( !_hopper ) _hopper = new OChannelHopper( this );
+ _hopper->setInterval( interval );
+ //FIXME: When and by whom will the channel hopper be deleted?
}
int OWirelessNetworkInterface::channelHopping() const
{
- return _hopper.interval();
+ return _hopper->interval();
}
void OWirelessNetworkInterface::setMonitorMode( bool b )
@@ -478,8 +495,9 @@ void OWirelessNetworkInterface::setMonitorMode( bool b )
else
qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
}
+
bool OWirelessNetworkInterface::monitorMode() const
{
return _mon ? _mon->enabled() : false;
}