-rw-r--r-- | libopie2/opienet/onetwork.cpp | 40 |
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 | |||
@@ -292,5 +292,6 @@ bool ONetworkInterface::isWireless() const | |||
292 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 292 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
293 | :QObject( 0, "Mickey's funky hopper" ), | 293 | :QObject( 0, "Mickey's funky hopper" ), |
294 | _iface( iface ), _interval( 0 ), _channel( 0 ), _tid( 0 ) | 294 | _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ), |
295 | _maxChannel( iface->channels()+1 ) | ||
295 | { | 296 | { |
296 | } | 297 | } |
@@ -302,8 +303,19 @@ OChannelHopper::~OChannelHopper() | |||
302 | 303 | ||
303 | 304 | ||
305 | bool OChannelHopper::isActive() const | ||
306 | { | ||
307 | return _tid; | ||
308 | } | ||
309 | |||
310 | |||
311 | int OChannelHopper::channel() const | ||
312 | { | ||
313 | return _channel; | ||
314 | } | ||
315 | |||
316 | |||
304 | void OChannelHopper::timerEvent( QTimerEvent* ) | 317 | void OChannelHopper::timerEvent( QTimerEvent* ) |
305 | { | 318 | { |
306 | //FIXME: Get available channels from OWirelessNetworkInterface | 319 | if ( !--_channel ) _channel = _maxChannel; |
307 | if ( --_channel < 0 ) _channel = 13; | ||
308 | _iface->setChannel( _channel ); | 320 | _iface->setChannel( _channel ); |
309 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 321 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", |
@@ -320,4 +332,5 @@ void OChannelHopper::setInterval( int interval ) | |||
320 | killTimer( _tid ); | 332 | killTimer( _tid ); |
321 | 333 | ||
334 | _tid = 0; | ||
322 | _interval = interval; | 335 | _interval = interval; |
323 | 336 | ||
@@ -340,5 +353,5 @@ int OChannelHopper::interval() const | |||
340 | 353 | ||
341 | OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) | 354 | OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) |
342 | :ONetworkInterface( name ), _hopper( this ) | 355 | :ONetworkInterface( name ), _hopper( 0 ) |
343 | { | 356 | { |
344 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 357 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); |
@@ -377,11 +390,8 @@ void OWirelessNetworkInterface::init() | |||
377 | } | 390 | } |
378 | 391 | ||
379 | //TODO: Find out what the difference between num_channel and | ||
380 | // num_frequency is about. | ||
381 | |||
382 | for ( int i = 0; i < range.num_frequency; ++i ) | 392 | for ( int i = 0; i < range.num_frequency; ++i ) |
383 | { | 393 | { |
384 | int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 ); | 394 | int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 ); |
385 | _channels.insert( freq, i ); | 395 | _channels.insert( freq, i+1 ); |
386 | } | 396 | } |
387 | } | 397 | } |
@@ -413,4 +423,10 @@ QString OWirelessNetworkInterface::associatedAP() const | |||
413 | int OWirelessNetworkInterface::channel() const | 423 | int OWirelessNetworkInterface::channel() const |
414 | { | 424 | { |
425 | //FIXME: When monitoring enabled, then use it | ||
426 | //FIXME: to gather the current RF channel | ||
427 | //FIXME: Until then, get active channel from hopper. | ||
428 | if ( _hopper && _hopper->isActive() ) | ||
429 | return _hopper->channel(); | ||
430 | |||
415 | if ( !wioctl( SIOCGIWFREQ ) ) | 431 | if ( !wioctl( SIOCGIWFREQ ) ) |
416 | { | 432 | { |
@@ -419,5 +435,4 @@ int OWirelessNetworkInterface::channel() const | |||
419 | else | 435 | else |
420 | { | 436 | { |
421 | //FIXME: This is off-by-one !? Why? | ||
422 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ]; | 437 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ]; |
423 | } | 438 | } |
@@ -462,5 +477,7 @@ int OWirelessNetworkInterface::channels() const | |||
462 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 477 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
463 | { | 478 | { |
464 | _hopper.setInterval( interval ); | 479 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
480 | _hopper->setInterval( interval ); | ||
481 | //FIXME: When and by whom will the channel hopper be deleted? | ||
465 | } | 482 | } |
466 | 483 | ||
@@ -468,5 +485,5 @@ void OWirelessNetworkInterface::setChannelHopping( int interval ) | |||
468 | int OWirelessNetworkInterface::channelHopping() const | 485 | int OWirelessNetworkInterface::channelHopping() const |
469 | { | 486 | { |
470 | return _hopper.interval(); | 487 | return _hopper->interval(); |
471 | } | 488 | } |
472 | 489 | ||
@@ -480,4 +497,5 @@ void OWirelessNetworkInterface::setMonitorMode( bool b ) | |||
480 | } | 497 | } |
481 | 498 | ||
499 | |||
482 | bool OWirelessNetworkInterface::monitorMode() const | 500 | bool OWirelessNetworkInterface::monitorMode() const |
483 | { | 501 | { |