summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp6
1 files changed, 3 insertions, 3 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index cd36f16..50d67bb 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -300,265 +300,265 @@ OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
300OChannelHopper::~OChannelHopper() 300OChannelHopper::~OChannelHopper()
301{ 301{
302} 302}
303 303
304 304
305bool OChannelHopper::isActive() const 305bool OChannelHopper::isActive() const
306{ 306{
307 return _tid; 307 return _tid;
308} 308}
309 309
310 310
311int OChannelHopper::channel() const 311int OChannelHopper::channel() const
312{ 312{
313 return _channel; 313 return _channel;
314} 314}
315 315
316 316
317void OChannelHopper::timerEvent( QTimerEvent* ) 317void OChannelHopper::timerEvent( QTimerEvent* )
318{ 318{
319 if ( !--_channel ) _channel = _maxChannel; 319 if ( !--_channel ) _channel = _maxChannel;
320 _iface->setChannel( _channel ); 320 _iface->setChannel( _channel );
321 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", 321 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
322 _channel, (const char*) _iface->name() ); 322 _channel, (const char*) _iface->name() );
323} 323}
324 324
325 325
326void OChannelHopper::setInterval( int interval ) 326void OChannelHopper::setInterval( int interval )
327{ 327{
328 if ( interval == _interval ) 328 if ( interval == _interval )
329 return; 329 return;
330 330
331 if ( _interval ) 331 if ( _interval )
332 killTimer( _tid ); 332 killTimer( _tid );
333 333
334 _tid = 0; 334 _tid = 0;
335 _interval = interval; 335 _interval = interval;
336 336
337 if ( _interval ) 337 if ( _interval )
338 { 338 {
339 _tid = startTimer( interval ); 339 _tid = startTimer( interval );
340 } 340 }
341} 341}
342 342
343 343
344int OChannelHopper::interval() const 344int OChannelHopper::interval() const
345{ 345{
346 return _interval; 346 return _interval;
347} 347}
348 348
349 349
350/*====================================================================================== 350/*======================================================================================
351 * OWirelessNetworkInterface 351 * OWirelessNetworkInterface
352 *======================================================================================*/ 352 *======================================================================================*/
353 353
354OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) 354OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name )
355 :ONetworkInterface( name ), _hopper( 0 ) 355 :ONetworkInterface( name ), _hopper( 0 )
356{ 356{
357 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 357 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
358 init(); 358 init();
359} 359}
360 360
361 361
362OWirelessNetworkInterface::~OWirelessNetworkInterface() 362OWirelessNetworkInterface::~OWirelessNetworkInterface()
363{ 363{
364} 364}
365 365
366 366
367iwreqstruct& OWirelessNetworkInterface::iwr() const 367iwreqstruct& OWirelessNetworkInterface::iwr() const
368{ 368{
369 return _iwr; 369 return _iwr;
370} 370}
371 371
372 372
373void OWirelessNetworkInterface::init() 373void OWirelessNetworkInterface::init()
374{ 374{
375 qDebug( "OWirelessNetworkInterface::init()" ); 375 qDebug( "OWirelessNetworkInterface::init()" );
376 376
377 memset( &_iwr, 0, sizeof( struct iwreq ) ); 377 memset( &_iwr, 0, sizeof( struct iwreq ) );
378 378
379 // IEEE802.11(b) radio frequency channels 379 // IEEE802.11(b) radio frequency channels
380 380
381 iwrangestruct range; 381 iwrangestruct range;
382 //ML: work around an ugly HostAP bug, which needs 382 //ML: work around an ugly HostAP bug, which needs
383 //ML: extra space or will complain with "invalid argument length"... :-( 383 //ML: extra space or will complain with "invalid argument length"... :-(
384 char __extraBufferForBuggyDrivers[sizeof range]; 384 char __extraBufferForBuggyDrivers[sizeof range];
385 _iwr.u.data.pointer = (char*) ⦥ 385 _iwr.u.data.pointer = (char*) ⦥
386 _iwr.u.data.length = (sizeof range) * 2; 386 _iwr.u.data.length = (sizeof range) * 2;
387 _iwr.u.data.flags = 0; 387 _iwr.u.data.flags = 0;
388 if ( !wioctl( SIOCGIWRANGE ) ) 388 if ( !wioctl( SIOCGIWRANGE ) )
389 { 389 {
390 qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); 390 qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) );
391 return; 391 return;
392 } 392 }
393 393
394 for ( int i = 0; i < range.num_frequency; ++i ) 394 for ( int i = 0; i < range.num_frequency; ++i )
395 { 395 {
396 int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 ); 396 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
397 _channels.insert( freq, i+1 ); 397 _channels.insert( freq, i+1 );
398 } 398 }
399} 399}
400 400
401 401
402QString OWirelessNetworkInterface::associatedAP() const 402QString OWirelessNetworkInterface::associatedAP() const
403{ 403{
404 //FIXME: use OMacAddress 404 //FIXME: use OMacAddress
405 QString mac; 405 QString mac;
406 406
407 if ( ioctl( SIOCGIWAP ) ) 407 if ( ioctl( SIOCGIWAP ) )
408 { 408 {
409 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 409 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
410 _ifr.ifr_hwaddr.sa_data[0]&0xff, 410 _ifr.ifr_hwaddr.sa_data[0]&0xff,
411 _ifr.ifr_hwaddr.sa_data[1]&0xff, 411 _ifr.ifr_hwaddr.sa_data[1]&0xff,
412 _ifr.ifr_hwaddr.sa_data[2]&0xff, 412 _ifr.ifr_hwaddr.sa_data[2]&0xff,
413 _ifr.ifr_hwaddr.sa_data[3]&0xff, 413 _ifr.ifr_hwaddr.sa_data[3]&0xff,
414 _ifr.ifr_hwaddr.sa_data[4]&0xff, 414 _ifr.ifr_hwaddr.sa_data[4]&0xff,
415 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 415 _ifr.ifr_hwaddr.sa_data[5]&0xff );
416 } 416 }
417 else 417 else
418 { 418 {
419 mac = "<Unknown>"; 419 mac = "<Unknown>";
420 } 420 }
421 return mac; 421 return mac;
422} 422}
423 423
424 424
425int OWirelessNetworkInterface::channel() const 425int OWirelessNetworkInterface::channel() const
426{ 426{
427 //FIXME: When monitoring enabled, then use it 427 //FIXME: When monitoring enabled, then use it
428 //FIXME: to gather the current RF channel 428 //FIXME: to gather the current RF channel
429 //FIXME: Until then, get active channel from hopper. 429 //FIXME: Until then, get active channel from hopper.
430 if ( _hopper && _hopper->isActive() ) 430 if ( _hopper && _hopper->isActive() )
431 return _hopper->channel(); 431 return _hopper->channel();
432 432
433 if ( !wioctl( SIOCGIWFREQ ) ) 433 if ( !wioctl( SIOCGIWFREQ ) )
434 { 434 {
435 return -1; 435 return -1;
436 } 436 }
437 else 437 else
438 { 438 {
439 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ]; 439 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
440 } 440 }
441} 441}
442 442
443 443
444void OWirelessNetworkInterface::setChannel( int c ) const 444void OWirelessNetworkInterface::setChannel( int c ) const
445{ 445{
446 if ( !_mon ) 446 if ( !_mon )
447 { 447 {
448 memset( &_iwr, 0, sizeof( iwreqstruct ) ); 448 memset( &_iwr, 0, sizeof( iwreqstruct ) );
449 _iwr.u.freq.m = c; 449 _iwr.u.freq.m = c;
450 _iwr.u.freq.e = 0; 450 _iwr.u.freq.e = 0;
451 wioctl( SIOCSIWFREQ ); 451 wioctl( SIOCSIWFREQ );
452 } 452 }
453 else 453 else
454 { 454 {
455 _mon->setChannel( c ); 455 _mon->setChannel( c );
456 } 456 }
457} 457}
458 458
459 459
460double OWirelessNetworkInterface::frequency() const 460double OWirelessNetworkInterface::frequency() const
461{ 461{
462 if ( !wioctl( SIOCGIWFREQ ) ) 462 if ( !wioctl( SIOCGIWFREQ ) )
463 { 463 {
464 return -1.0; 464 return -1.0;
465 } 465 }
466 else 466 else
467 { 467 {
468 return double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000000.0; 468 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
469 } 469 }
470} 470}
471 471
472 472
473int OWirelessNetworkInterface::channels() const 473int OWirelessNetworkInterface::channels() const
474{ 474{
475 return _channels.count(); 475 return _channels.count();
476} 476}
477 477
478 478
479void OWirelessNetworkInterface::setChannelHopping( int interval ) 479void OWirelessNetworkInterface::setChannelHopping( int interval )
480{ 480{
481 if ( !_hopper ) _hopper = new OChannelHopper( this ); 481 if ( !_hopper ) _hopper = new OChannelHopper( this );
482 _hopper->setInterval( interval ); 482 _hopper->setInterval( interval );
483 //FIXME: When and by whom will the channel hopper be deleted? 483 //FIXME: When and by whom will the channel hopper be deleted?
484} 484}
485 485
486 486
487int OWirelessNetworkInterface::channelHopping() const 487int OWirelessNetworkInterface::channelHopping() const
488{ 488{
489 return _hopper->interval(); 489 return _hopper->interval();
490} 490}
491 491
492 492
493void OWirelessNetworkInterface::setMonitorMode( bool b ) 493void OWirelessNetworkInterface::setMonitorMode( bool b )
494{ 494{
495 if ( _mon ) 495 if ( _mon )
496 _mon->setEnabled( b ); 496 _mon->setEnabled( b );
497 else 497 else
498 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 498 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
499} 499}
500 500
501 501
502bool OWirelessNetworkInterface::monitorMode() const 502bool OWirelessNetworkInterface::monitorMode() const
503{ 503{
504 return _mon ? _mon->enabled() : false; 504 return _mon ? _mon->enabled() : false;
505} 505}
506 506
507 507
508QString OWirelessNetworkInterface::nickName() const 508QString OWirelessNetworkInterface::nickName() const
509{ 509{
510 char str[IW_ESSID_MAX_SIZE]; 510 char str[IW_ESSID_MAX_SIZE];
511 _iwr.u.data.pointer = &str[0]; 511 _iwr.u.data.pointer = &str[0];
512 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 512 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
513 if ( !wioctl( SIOCGIWNICKN ) ) 513 if ( !wioctl( SIOCGIWNICKN ) )
514 { 514 {
515 return "<unknown>"; 515 return "<unknown>";
516 } 516 }
517 else 517 else
518 { 518 {
519 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 519 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
520 return str; 520 return str;
521 } 521 }
522} 522}
523 523
524 524
525QString OWirelessNetworkInterface::SSID() const 525QString OWirelessNetworkInterface::SSID() const
526{ 526{
527 char str[IW_ESSID_MAX_SIZE]; 527 char str[IW_ESSID_MAX_SIZE];
528 _iwr.u.essid.pointer = &str[0]; 528 _iwr.u.essid.pointer = &str[0];
529 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 529 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
530 if ( !wioctl( SIOCGIWESSID ) ) 530 if ( !wioctl( SIOCGIWESSID ) )
531 { 531 {
532 return "<unknown>"; 532 return "<unknown>";
533 } 533 }
534 else 534 else
535 { 535 {
536 return str; 536 return str;
537 } 537 }
538} 538}
539 539
540 540
541void OWirelessNetworkInterface::setSSID( const QString& ssid ) 541void OWirelessNetworkInterface::setSSID( const QString& ssid )
542{ 542{
543 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 543 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
544 _iwr.u.essid.length = ssid.length(); 544 _iwr.u.essid.length = ssid.length();
545 wioctl( SIOCSIWESSID ); 545 wioctl( SIOCSIWESSID );
546} 546}
547 547
548 548
549bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const 549bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const
550{ 550{
551 int result = ::ioctl( _sfd, call, &iwreq ); 551 int result = ::ioctl( _sfd, call, &iwreq );
552 if ( result == -1 ) 552 if ( result == -1 )
553 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 553 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) );
554 else 554 else
555 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); 555 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call );
556 return ( result != -1 ); 556 return ( result != -1 );
557} 557}
558 558
559 559
560bool OWirelessNetworkInterface::wioctl( int call ) const 560bool OWirelessNetworkInterface::wioctl( int call ) const
561{ 561{
562 strcpy( _iwr.ifr_name, (const char*) _name ); 562 strcpy( _iwr.ifr_name, (const char*) _name );
563 return wioctl( call, _iwr ); 563 return wioctl( call, _iwr );
564} 564}