Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-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 | |||
@@ -288,26 +288,38 @@ bool ONetworkInterface::isWireless() const | |||
288 | /*====================================================================================== | 288 | /*====================================================================================== |
289 | * OChannelHopper | 289 | * OChannelHopper |
290 | *======================================================================================*/ | 290 | *======================================================================================*/ |
291 | 291 | ||
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 | } |
297 | 298 | ||
298 | 299 | ||
299 | OChannelHopper::~OChannelHopper() | 300 | OChannelHopper::~OChannelHopper() |
300 | { | 301 | { |
301 | } | 302 | } |
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'", |
310 | _channel, (const char*) _iface->name() ); | 322 | _channel, (const char*) _iface->name() ); |
311 | } | 323 | } |
312 | 324 | ||
313 | 325 | ||
@@ -316,12 +328,13 @@ void OChannelHopper::setInterval( int interval ) | |||
316 | if ( interval == _interval ) | 328 | if ( interval == _interval ) |
317 | return; | 329 | return; |
318 | 330 | ||
319 | if ( _interval ) | 331 | if ( _interval ) |
320 | killTimer( _tid ); | 332 | killTimer( _tid ); |
321 | 333 | ||
334 | _tid = 0; | ||
322 | _interval = interval; | 335 | _interval = interval; |
323 | 336 | ||
324 | if ( _interval ) | 337 | if ( _interval ) |
325 | { | 338 | { |
326 | _tid = startTimer( interval ); | 339 | _tid = startTimer( interval ); |
327 | } | 340 | } |
@@ -336,13 +349,13 @@ int OChannelHopper::interval() const | |||
336 | 349 | ||
337 | /*====================================================================================== | 350 | /*====================================================================================== |
338 | * OWirelessNetworkInterface | 351 | * OWirelessNetworkInterface |
339 | *======================================================================================*/ | 352 | *======================================================================================*/ |
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()" ); |
345 | init(); | 358 | init(); |
346 | } | 359 | } |
347 | 360 | ||
348 | 361 | ||
@@ -373,19 +386,16 @@ void OWirelessNetworkInterface::init() | |||
373 | if ( !wioctl( SIOCGIWRANGE ) ) | 386 | if ( !wioctl( SIOCGIWRANGE ) ) |
374 | { | 387 | { |
375 | qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); | 388 | qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); |
376 | return; | 389 | return; |
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 | } |
388 | 398 | ||
389 | 399 | ||
390 | QString OWirelessNetworkInterface::associatedAP() const | 400 | QString OWirelessNetworkInterface::associatedAP() const |
391 | { | 401 | { |
@@ -409,19 +419,24 @@ QString OWirelessNetworkInterface::associatedAP() const | |||
409 | return mac; | 419 | return mac; |
410 | } | 420 | } |
411 | 421 | ||
412 | 422 | ||
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 | { |
417 | return -1; | 433 | return -1; |
418 | } | 434 | } |
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 | } |
424 | } | 439 | } |
425 | 440 | ||
426 | 441 | ||
427 | void OWirelessNetworkInterface::setChannel( int c ) const | 442 | void OWirelessNetworkInterface::setChannel( int c ) const |
@@ -458,30 +473,33 @@ int OWirelessNetworkInterface::channels() const | |||
458 | return _channels.count(); | 473 | return _channels.count(); |
459 | } | 474 | } |
460 | 475 | ||
461 | 476 | ||
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 | ||
467 | 484 | ||
468 | int OWirelessNetworkInterface::channelHopping() const | 485 | int OWirelessNetworkInterface::channelHopping() const |
469 | { | 486 | { |
470 | return _hopper.interval(); | 487 | return _hopper->interval(); |
471 | } | 488 | } |
472 | 489 | ||
473 | 490 | ||
474 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 491 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
475 | { | 492 | { |
476 | if ( _mon ) | 493 | if ( _mon ) |
477 | _mon->setEnabled( b ); | 494 | _mon->setEnabled( b ); |
478 | else | 495 | else |
479 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 496 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
480 | } | 497 | } |
481 | 498 | ||
499 | |||
482 | bool OWirelessNetworkInterface::monitorMode() const | 500 | bool OWirelessNetworkInterface::monitorMode() const |
483 | { | 501 | { |
484 | return _mon ? _mon->enabled() : false; | 502 | return _mon ? _mon->enabled() : false; |
485 | } | 503 | } |
486 | 504 | ||
487 | 505 | ||