summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (show whitespace changes)
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp12
-rw-r--r--libopie2/opienet/onetwork.cpp113
-rw-r--r--libopie2/opienet/onetwork.h29
3 files changed, 131 insertions, 23 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
index 607d8f1..fc2026f 100644
--- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -47,24 +47,36 @@ int main( int argc, char** argv )
47 qDebug( "DEMO: Operation Mode change successful." ); 47 qDebug( "DEMO: Operation Mode change successful." );
48 48
49 // RF channel 49 // RF channel
50 qDebug( "DEMO: Current Channel is '%d'", iface->channel() ); 50 qDebug( "DEMO: Current Channel is '%d'", iface->channel() );
51 iface->setChannel( 1 ); 51 iface->setChannel( 1 );
52 if ( iface->channel() != 1 ) 52 if ( iface->channel() != 1 )
53 qDebug( "DEMO: Warning! Can't change RF channel" ); 53 qDebug( "DEMO: Warning! Can't change RF channel" );
54 else 54 else
55 qDebug( "DEMO: RF channel change successful." ); 55 qDebug( "DEMO: RF channel change successful." );
56 56
57 iface->setMode( "managed" ); 57 iface->setMode( "managed" );
58 58
59 // network scan
60
61 int stations = iface->scanNetwork();
62 if ( stations != -1 )
63 {
64 qDebug( "DEMO: # of stations around = %d", stations );
65 }
66 else
67 {
68 qDebug( "DEMO: Warning! Scan didn't work!" );
69 }
70
59 /* 71 /*
60 72
61 // first some wrong calls to check if this is working 73 // first some wrong calls to check if this is working
62 iface->setPrivate( "seppel", 10 ); 74 iface->setPrivate( "seppel", 10 );
63 iface->setPrivate( "monitor", 0 ); 75 iface->setPrivate( "monitor", 0 );
64 76
65 // now the real deal 77 // now the real deal
66 iface->setPrivate( "monitor", 2, 2, 3 ); 78 iface->setPrivate( "monitor", 2, 2, 3 );
67 79
68 // trying to set hw address to 12:34:56:AB:CD:EF 80 // trying to set hw address to 12:34:56:AB:CD:EF
69 81
70 /* 82 /*
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index dc2e388..be45924 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -67,24 +67,25 @@ ONetwork* ONetwork::_instance = 0;
67ONetwork::ONetwork() 67ONetwork::ONetwork()
68{ 68{
69 qDebug( "ONetwork::ONetwork()" ); 69 qDebug( "ONetwork::ONetwork()" );
70 qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT ); 70 qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT );
71 synchronize(); 71 synchronize();
72} 72}
73 73
74void ONetwork::synchronize() 74void ONetwork::synchronize()
75{ 75{
76 // gather available interfaces by inspecting /proc/net/dev 76 // gather available interfaces by inspecting /proc/net/dev
77 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 77 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
78 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 78 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
79 //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev
79 80
80 _interfaces.clear(); 81 _interfaces.clear();
81 QString str; 82 QString str;
82 QFile f( "/proc/net/dev" ); 83 QFile f( "/proc/net/dev" );
83 bool hasFile = f.open( IO_ReadOnly ); 84 bool hasFile = f.open( IO_ReadOnly );
84 if ( !hasFile ) 85 if ( !hasFile )
85 { 86 {
86 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); 87 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
87 return; 88 return;
88 } 89 }
89 QTextStream s( &f ); 90 QTextStream s( &f );
90 s.readLine(); 91 s.readLine();
@@ -179,27 +180,27 @@ void ONetworkInterface::init()
179 if ( _sfd == -1 ) 180 if ( _sfd == -1 )
180 { 181 {
181 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); 182 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() );
182 return; 183 return;
183 } 184 }
184} 185}
185 186
186 187
187bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const 188bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
188{ 189{
189 int result = ::ioctl( _sfd, call, &ifreq ); 190 int result = ::ioctl( _sfd, call, &ifreq );
190 if ( result == -1 ) 191 if ( result == -1 )
191 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 192 qDebug( "ONetworkInterface::ioctl (%s) call %d (0x%04X) - Status: Failed: %d (%s)", name(), call, call, result, strerror( errno ) );
192 else 193 else
193 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); 194 qDebug( "ONetworkInterface::ioctl (%s) call %d (0x%04X) - Status: Ok.", name(), call, call );
194 return ( result != -1 ); 195 return ( result != -1 );
195} 196}
196 197
197 198
198bool ONetworkInterface::ioctl( int call ) const 199bool ONetworkInterface::ioctl( int call ) const
199{ 200{
200 strcpy( _ifr.ifr_name, name() ); 201 strcpy( _ifr.ifr_name, name() );
201 return ioctl( call, _ifr ); 202 return ioctl( call, _ifr );
202} 203}
203 204
204 205
205bool ONetworkInterface::isLoopback() const 206bool ONetworkInterface::isLoopback() const
@@ -445,26 +446,34 @@ OWirelessNetworkInterface::~OWirelessNetworkInterface()
445 446
446 447
447struct iwreq& OWirelessNetworkInterface::iwr() const 448struct iwreq& OWirelessNetworkInterface::iwr() const
448{ 449{
449 return _iwr; 450 return _iwr;
450} 451}
451 452
452 453
453void OWirelessNetworkInterface::init() 454void OWirelessNetworkInterface::init()
454{ 455{
455 qDebug( "OWirelessNetworkInterface::init()" ); 456 qDebug( "OWirelessNetworkInterface::init()" );
456 memset( &_iwr, 0, sizeof( struct iwreq ) ); 457 memset( &_iwr, 0, sizeof( struct iwreq ) );
457 buildChannelList(); 458 buildInformation();
458 buildPrivateList(); 459 buildPrivateList();
460 dumpInformation();
461}
462
463
464bool OWirelessNetworkInterface::isAssociated() const
465{
466 //FIXME: handle different modes
467 return associatedAP() != "44:44:44:44:44:44";
459} 468}
460 469
461 470
462QString OWirelessNetworkInterface::associatedAP() const 471QString OWirelessNetworkInterface::associatedAP() const
463{ 472{
464 //FIXME: use OMacAddress 473 //FIXME: use OMacAddress
465 QString mac; 474 QString mac;
466 475
467 if ( ioctl( SIOCGIWAP ) ) 476 if ( ioctl( SIOCGIWAP ) )
468 { 477 {
469 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 478 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
470 _ifr.ifr_hwaddr.sa_data[0]&0xff, 479 _ifr.ifr_hwaddr.sa_data[0]&0xff,
@@ -473,86 +482,89 @@ QString OWirelessNetworkInterface::associatedAP() const
473 _ifr.ifr_hwaddr.sa_data[3]&0xff, 482 _ifr.ifr_hwaddr.sa_data[3]&0xff,
474 _ifr.ifr_hwaddr.sa_data[4]&0xff, 483 _ifr.ifr_hwaddr.sa_data[4]&0xff,
475 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 484 _ifr.ifr_hwaddr.sa_data[5]&0xff );
476 } 485 }
477 else 486 else
478 { 487 {
479 mac = "<Unknown>"; 488 mac = "<Unknown>";
480 } 489 }
481 return mac; 490 return mac;
482} 491}
483 492
484 493
485void OWirelessNetworkInterface::buildChannelList() 494void OWirelessNetworkInterface::buildInformation()
486{ 495{
487 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 496 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
488 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 497 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
489 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 498 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
490 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 499 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
491 //ML: _too much_ space. This is damn shitty crap *sigh* 500 //ML: _too much_ space. This is damn shitty crap *sigh*
492 //ML: We allocate a large memory region in RAM and check whether the 501 //ML: We allocate a large memory region in RAM and check whether the
493 //ML: driver pollutes this extra space. The complaint will be made on stdout, 502 //ML: driver pollutes this extra space. The complaint will be made on stdout,
494 //ML: so please forward this... 503 //ML: so please forward this...
495 504
496 struct iwreq wrq; 505 struct iwreq wrq;
497 int len = sizeof( struct iw_range )*2; 506 int len = sizeof( struct iw_range )*2;
498 char *buffer = (char*) malloc( len ); 507 char *buffer = (char*) malloc( len );
499 //FIXME: Validate if we actually got the memory block 508 //FIXME: Validate if we actually got the memory block
500 memset( buffer, 0, len ); 509 memset( buffer, 0, len );
501 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 510 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
502 wrq.u.data.pointer = (caddr_t) buffer; 511 wrq.u.data.pointer = (caddr_t) buffer;
503 wrq.u.data.length = sizeof( struct iw_range ); 512 wrq.u.data.length = sizeof( struct iw_range );
504 wrq.u.data.flags = 0; 513 wrq.u.data.flags = 0;
505 514
506 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 515 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
507 { 516 {
508 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); 517 qDebug( "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (%s) - using default values.", strerror( errno ) );
509 _channels.insert( 2412, 1 ); // 2.412 GHz 518 _channels.insert( 2412, 1 ); // 2.412 GHz
510 _channels.insert( 2417, 2 ); // 2.417 GHz 519 _channels.insert( 2417, 2 ); // 2.417 GHz
511 _channels.insert( 2422, 3 ); // 2.422 GHz 520 _channels.insert( 2422, 3 ); // 2.422 GHz
512 _channels.insert( 2427, 4 ); // 2.427 GHz 521 _channels.insert( 2427, 4 ); // 2.427 GHz
513 _channels.insert( 2432, 5 ); // 2.432 GHz 522 _channels.insert( 2432, 5 ); // 2.432 GHz
514 _channels.insert( 2437, 6 ); // 2.437 GHz 523 _channels.insert( 2437, 6 ); // 2.437 GHz
515 _channels.insert( 2442, 7 ); // 2.442 GHz 524 _channels.insert( 2442, 7 ); // 2.442 GHz
516 _channels.insert( 2447, 8 ); // 2.447 GHz 525 _channels.insert( 2447, 8 ); // 2.447 GHz
517 _channels.insert( 2452, 9 ); // 2.452 GHz 526 _channels.insert( 2452, 9 ); // 2.452 GHz
518 _channels.insert( 2457, 10 ); // 2.457 GHz 527 _channels.insert( 2457, 10 ); // 2.457 GHz
519 _channels.insert( 2462, 11 ); // 2.462 GHz 528 _channels.insert( 2462, 11 ); // 2.462 GHz
529
530 memset( &_range, 0, sizeof( struct iw_range ) );
520 } 531 }
521 else 532 else
522 { 533 {
523 // <check if the driver overwrites stuff> 534 // <check if the driver overwrites stuff>
524 int max = 0; 535 int max = 0;
525 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 536 for ( int r = sizeof( struct iw_range ); r < len; r++ )
526 if (buffer[r] != 0) 537 if (buffer[r] != 0)
527 max = r; 538 max = r;
528 if (max > 0) 539 if (max > 0)
529 { 540 {
530 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" 541 qWarning( "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '%s' sucks!\n"
531 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); 542 "It overwrote the buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
532 } 543 }
533 // </check if the driver overwrites stuff> 544 // </check if the driver overwrites stuff>
534 545
535 struct iw_range range; 546 struct iw_range range;
536 memcpy( &range, buffer, sizeof range ); 547 memcpy( &range, buffer, sizeof range );
537 548
538 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); 549 qDebug( "OWirelessNetworkInterface::buildInformation(): Interface %s reported to have %d channels.", name(), range.num_frequency );
539 for ( int i = 0; i < range.num_frequency; ++i ) 550 for ( int i = 0; i < range.num_frequency; ++i )
540 { 551 {
541 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 552 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
542 _channels.insert( freq, i+1 ); 553 _channels.insert( freq, i+1 );
543 } 554 }
544 } 555 }
545 556
546 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); 557 memcpy( &_range, buffer, sizeof( struct iw_range ) );
558 qDebug( "OWirelessNetworkInterface::buildInformation(): Information block constructed." );
547 free(buffer); 559 free(buffer);
548} 560}
549 561
550 562
551void OWirelessNetworkInterface::buildPrivateList() 563void OWirelessNetworkInterface::buildPrivateList()
552{ 564{
553 qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); 565 qDebug( "OWirelessNetworkInterface::buildPrivateList()" );
554 566
555 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 567 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
556 568
557 _iwr.u.data.pointer = (char*) &priv; 569 _iwr.u.data.pointer = (char*) &priv;
558 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 570 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
@@ -563,24 +575,35 @@ void OWirelessNetworkInterface::buildPrivateList()
563 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); 575 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) );
564 return; 576 return;
565 } 577 }
566 578
567 for ( int i = 0; i < _iwr.u.data.length; ++i ) 579 for ( int i = 0; i < _iwr.u.data.length; ++i )
568 { 580 {
569 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 581 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
570 } 582 }
571 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); 583 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
572} 584}
573 585
574 586
587void OWirelessNetworkInterface::dumpInformation() const
588{
589 qDebug( "OWirelessNetworkInterface::() -------------- dumping information block ----------------" );
590
591 qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 );
592 qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source );
593
594 qDebug( "OWirelessNetworkInterface::() ---------------------------------------------------------" );
595}
596
597
575int OWirelessNetworkInterface::channel() const 598int OWirelessNetworkInterface::channel() const
576{ 599{
577 //FIXME: When monitoring enabled, then use it 600 //FIXME: When monitoring enabled, then use it
578 //FIXME: to gather the current RF channel 601 //FIXME: to gather the current RF channel
579 //FIXME: Until then, get active channel from hopper. 602 //FIXME: Until then, get active channel from hopper.
580 if ( _hopper && _hopper->isActive() ) 603 if ( _hopper && _hopper->isActive() )
581 return _hopper->channel(); 604 return _hopper->channel();
582 605
583 if ( !wioctl( SIOCGIWFREQ ) ) 606 if ( !wioctl( SIOCGIWFREQ ) )
584 { 607 {
585 return -1; 608 return -1;
586 } 609 }
@@ -652,72 +675,69 @@ OChannelHopper* OWirelessNetworkInterface::channelHopper() const
652 return _hopper; 675 return _hopper;
653} 676}
654 677
655 678
656void OWirelessNetworkInterface::setMode( const QString& mode ) 679void OWirelessNetworkInterface::setMode( const QString& mode )
657{ 680{
658 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; 681 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO;
659 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; 682 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC;
660 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; 683 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA;
661 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; 684 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER;
662 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; 685 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT;
663 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; 686 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND;
664 #if WIRELESS_EXT > 14
665 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; 687 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
666 #endif
667 else 688 else
668 { 689 {
669 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); 690 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
670 return; 691 return;
671 } 692 }
672 wioctl( SIOCSIWMODE ); 693 wioctl( SIOCSIWMODE );
673} 694}
674 695
675 696
676QString OWirelessNetworkInterface::mode() const 697QString OWirelessNetworkInterface::mode() const
677{ 698{
678 if ( !wioctl( SIOCGIWMODE ) ) 699 if ( !wioctl( SIOCGIWMODE ) )
679 { 700 {
680 return "<unknown>"; 701 return "<unknown>";
681 } 702 }
682 switch ( _iwr.u.mode ) 703 switch ( _iwr.u.mode )
683 { 704 {
684 case IW_MODE_AUTO: return "auto"; 705 case IW_MODE_AUTO: return "auto";
685 case IW_MODE_ADHOC: return "adhoc"; 706 case IW_MODE_ADHOC: return "adhoc";
686 case IW_MODE_INFRA: return "managed"; 707 case IW_MODE_INFRA: return "managed";
687 case IW_MODE_MASTER: return "master"; 708 case IW_MODE_MASTER: return "master";
688 case IW_MODE_REPEAT: return "repeater"; 709 case IW_MODE_REPEAT: return "repeater";
689 case IW_MODE_SECOND: return "secondary"; 710 case IW_MODE_SECOND: return "secondary";
690 #if WIRELESS_EXT > 14
691 case IW_MODE_MONITOR: return "monitor"; 711 case IW_MODE_MONITOR: return "monitor";
692 #endif
693 default: assert( 0 ); // shouldn't happen 712 default: assert( 0 ); // shouldn't happen
694 } 713 }
695} 714}
696 715
697 716
698void OWirelessNetworkInterface::setMonitorMode( bool b ) 717void OWirelessNetworkInterface::setMonitorMode( bool b )
699{ 718{
700 if ( _mon ) 719 if ( _mon )
701 _mon->setEnabled( b ); 720 _mon->setEnabled( b );
702 else 721 else
703 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 722 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
704} 723}
705 724
706 725
707bool OWirelessNetworkInterface::monitorMode() const 726bool OWirelessNetworkInterface::monitorMode() const
708{ 727{
709 qDebug( "dataLinkType = %d", dataLinkType() ); 728 qDebug( "dataLinkType = %d", dataLinkType() );
710 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); 729 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
711 // 802 is the header type for PRISM - Linux support for this is pending... 730 //FIXME: 802 is the header type for PRISM - Linux support for this is pending...
731 //FIXME: What is 119, by the way?
712} 732}
713 733
714 734
715void OWirelessNetworkInterface::setNickName( const QString& nickname ) 735void OWirelessNetworkInterface::setNickName( const QString& nickname )
716{ 736{
717 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); 737 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
718 _iwr.u.essid.length = nickname.length(); 738 _iwr.u.essid.length = nickname.length();
719 wioctl( SIOCSIWNICKN ); 739 wioctl( SIOCSIWNICKN );
720} 740}
721 741
722 742
723QString OWirelessNetworkInterface::nickName() const 743QString OWirelessNetworkInterface::nickName() const
@@ -791,31 +811,92 @@ QString OWirelessNetworkInterface::SSID() const
791 } 811 }
792} 812}
793 813
794 814
795void OWirelessNetworkInterface::setSSID( const QString& ssid ) 815void OWirelessNetworkInterface::setSSID( const QString& ssid )
796{ 816{
797 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 817 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
798 _iwr.u.essid.length = ssid.length(); 818 _iwr.u.essid.length = ssid.length();
799 wioctl( SIOCSIWESSID ); 819 wioctl( SIOCSIWESSID );
800} 820}
801 821
802 822
823int OWirelessNetworkInterface::scanNetwork()
824{
825 _iwr.u.param.flags = IW_SCAN_DEFAULT;
826 _iwr.u.param.value = 0;
827 if ( !wioctl( SIOCSIWSCAN ) )
828 {
829 return -1;
830 }
831
832 int timeout = 1000000;
833
834 qDebug( "ONetworkInterface::scanNetwork() - scan started." );
835
836 bool results = false;
837 struct timeval tv;
838 tv.tv_sec = 0;
839 tv.tv_usec = 250000; // initial timeout ~ 250ms
840 char buffer[IW_SCAN_MAX_DATA];
841
842 while ( !results && timeout > 0 )
843 {
844 timeout -= tv.tv_usec;
845 select( 0, 0, 0, 0, &tv );
846
847 _iwr.u.data.pointer = &buffer[0];
848 _iwr.u.data.flags = 0;
849 _iwr.u.data.length = sizeof buffer;
850 if ( wioctl( SIOCGIWSCAN ) )
851 {
852 results = true;
853 continue;
854 }
855 else if ( errno == EAGAIN)
856 {
857 qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." );
858 #if 0
859 if ( qApp )
860 {
861 qApp->processEvents( 100 );
862 continue;
863 }
864 #endif
865 tv.tv_sec = 0;
866 tv.tv_usec = 100000;
867 continue;
868 }
869 }
870
871 qDebug( "ONetworkInterface::scanNetwork() - scan finished." );
872
873 if ( results )
874 {
875 qDebug( " - results are in!" );
876 }
877 else
878 {
879 qDebug( " - no results :(" );
880 }
881}
882
883
803bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 884bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
804{ 885{
805 int result = ::ioctl( _sfd, call, &iwreq ); 886 int result = ::ioctl( _sfd, call, &iwreq );
806 if ( result == -1 ) 887 if ( result == -1 )
807 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 888 qDebug( "ONetworkInterface::wioctl (%s) call %d (0x%04X) - Status: Failed: %d (%s)", name(), call, call, result, strerror( errno ) );
808 else 889 else
809 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); 890 qDebug( "ONetworkInterface::wioctl (%s) call %d (0x%04X) - Status: Ok.", name(), call, call );
810 return ( result != -1 ); 891 return ( result != -1 );
811} 892}
812 893
813 894
814bool OWirelessNetworkInterface::wioctl( int call ) const 895bool OWirelessNetworkInterface::wioctl( int call ) const
815{ 896{
816 strcpy( _iwr.ifr_name, name() ); 897 strcpy( _iwr.ifr_name, name() );
817 return wioctl( call, _iwr ); 898 return wioctl( call, _iwr );
818} 899}
819 900
820 901
821/*====================================================================================== 902/*======================================================================================
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index b170ea2..e1545dd 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -352,25 +352,25 @@ class OWirelessNetworkInterface : public ONetworkInterface
352 virtual QString mode() const; 352 virtual QString mode() const;
353 /** 353 /**
354 * Setting the monitor mode on a wireless network interface enables 354 * Setting the monitor mode on a wireless network interface enables
355 * listening to IEEE 802.11 data and management frames which normally 355 * listening to IEEE 802.11 data and management frames which normally
356 * are handled by the device firmware. This can be used to detect 356 * are handled by the device firmware. This can be used to detect
357 * other wireless network devices, e.g. Access Points or Ad-hoc stations. 357 * other wireless network devices, e.g. Access Points or Ad-hoc stations.
358 * @warning Standard wireless network drives don't support the monitor mode. 358 * @warning Standard wireless network drives don't support the monitor mode.
359 * @warning You need a patched driver for this to work. 359 * @warning You need a patched driver for this to work.
360 * @note Enabling the monitor mode is highly driver dependent and requires 360 * @note Enabling the monitor mode is highly driver dependent and requires
361 * the proper @ref OMonitoringInterface to be associated with the interface. 361 * the proper @ref OMonitoringInterface to be associated with the interface.
362 * @see OMonitoringInterface 362 * @see OMonitoringInterface
363 */ 363 */
364 virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); 364 virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); Use IW_MONITOR first, if this doesn't work, then use iwpriv!
365 /** 365 /**
366 * @returns true if the device is listening in IEEE 802.11 monitor mode 366 * @returns true if the device is listening in IEEE 802.11 monitor mode
367 */ 367 */
368 virtual bool monitorMode() const; //FIXME: ==> mode() 368 virtual bool monitorMode() const; //FIXME: ==> mode()
369 /** 369 /**
370 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. 370 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping.
371 * @see OChannelHopper 371 * @see OChannelHopper
372 */ 372 */
373 virtual void setChannelHopping( int interval = 0 ); 373 virtual void setChannelHopping( int interval = 0 );
374 /** 374 /**
375 * @returns the channel hopping interval or 0, if channel hopping is disabled. 375 * @returns the channel hopping interval or 0, if channel hopping is disabled.
376 */ 376 */
@@ -388,53 +388,62 @@ class OWirelessNetworkInterface : public ONetworkInterface
388 */ 388 */
389 virtual QString nickName() const; 389 virtual QString nickName() const;
390 /** 390 /**
391 * Invoke the private IOCTL @a command with a @number of parameters on the network interface. 391 * Invoke the private IOCTL @a command with a @number of parameters on the network interface.
392 * @see OPrivateIOCTL 392 * @see OPrivateIOCTL
393 */ 393 */
394 virtual void setPrivate( const QString& command, int number, ... ); 394 virtual void setPrivate( const QString& command, int number, ... );
395 /** 395 /**
396 * @returns true if the interface is featuring the private IOCTL @command. 396 * @returns true if the interface is featuring the private IOCTL @command.
397 */ 397 */
398 virtual bool hasPrivate( const QString& command ); 398 virtual bool hasPrivate( const QString& command );
399 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this 399 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this
400
401 virtual bool isAssociated() const {}; //FIXME: Implement and document this
402 /** 400 /**
403 * @returns the MAC address of the Access Point if the 401 * @returns true if the interface is associated to an access point
404 * device is in infrastructure mode. @returns a (more or less random) CELL 402 * @note: This information is only valid if the interface is in managed mode.
405 * address if the device is in adhoc mode. 403 */
404 virtual bool isAssociated() const;
405 /**
406 * @returns the MAC address of the Access Point if the device is in infrastructure mode.
407 * @returns a (more or less random) cell ID address if the device is in adhoc mode.
406 */ 408 */
407 virtual QString associatedAP() const; 409 virtual QString associatedAP() const;
408 /** 410 /**
409 * Set the @a ssid (Service Set ID) string. This is used to decide 411 * Set the @a ssid (Service Set ID) string. This is used to decide
410 * which network to associate with (use "any" to let the driver decide). 412 * which network to associate with (use "any" to let the driver decide).
411 */ 413 */
412 virtual void setSSID( const QString& ssid ); 414 virtual void setSSID( const QString& ssid );
413 /** 415 /**
414 * @returns the current SSID (Service Set ID). 416 * @returns the current SSID (Service Set ID).
415 */ 417 */
416 virtual QString SSID() const; 418 virtual QString SSID() const;
419 /**
420 * Perform scanning the wireless network neighbourhood.
421 * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE!
422 */
423 virtual int scanNetwork();
417 424
418 protected: 425 protected:
419 void buildChannelList(); 426 void buildInformation();
420 void buildPrivateList(); 427 void buildPrivateList();
428 void dumpInformation() const;
421 virtual void init(); 429 virtual void init();
422 struct iwreq& iwr() const; 430 struct iwreq& iwr() const;
423 bool wioctl( int call ) const; 431 bool wioctl( int call ) const;
424 bool wioctl( int call, struct iwreq& ) const; 432 bool wioctl( int call, struct iwreq& ) const;
425 433
426 protected: 434 protected:
427 mutable struct iwreq _iwr; 435 mutable struct iwreq _iwr;
428 QMap<int,int> _channels; 436 QMap<int,int> _channels;
437 struct iw_range _range;
429 438
430 private: 439 private:
431 OChannelHopper* _hopper; 440 OChannelHopper* _hopper;
432}; 441};
433 442
434 443
435/*====================================================================================== 444/*======================================================================================
436 * OMonitoringInterface 445 * OMonitoringInterface
437 *======================================================================================*/ 446 *======================================================================================*/
438 447
439 448
440class OMonitoringInterface 449class OMonitoringInterface
@@ -466,60 +475,66 @@ class OMonitoringInterface
466class OCiscoMonitoringInterface : public OMonitoringInterface 475class OCiscoMonitoringInterface : public OMonitoringInterface
467{ 476{
468 public: 477 public:
469 OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 478 OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader );
470 virtual ~OCiscoMonitoringInterface(); 479 virtual ~OCiscoMonitoringInterface();
471 480
472 virtual void setEnabled( bool ); 481 virtual void setEnabled( bool );
473 virtual QString name() const; 482 virtual QString name() const;
474 virtual void setChannel( int ); 483 virtual void setChannel( int );
475 484
476}; 485};
477 486
487
478/*====================================================================================== 488/*======================================================================================
479 * OWlanNGMonitoringInterface 489 * OWlanNGMonitoringInterface
480 *======================================================================================*/ 490 *======================================================================================*/
481 491
492
482class OWlanNGMonitoringInterface : public OMonitoringInterface 493class OWlanNGMonitoringInterface : public OMonitoringInterface
483{ 494{
484 public: 495 public:
485 OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 496 OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader );
486 virtual ~OWlanNGMonitoringInterface(); 497 virtual ~OWlanNGMonitoringInterface();
487 498
488 public: 499 public:
489 virtual void setEnabled( bool ); 500 virtual void setEnabled( bool );
490 virtual QString name() const; 501 virtual QString name() const;
491 virtual void setChannel( int ); 502 virtual void setChannel( int );
492 503
493}; 504};
494 505
506
495/*====================================================================================== 507/*======================================================================================
496 * OHostAPMonitoringInterface 508 * OHostAPMonitoringInterface
497 *======================================================================================*/ 509 *======================================================================================*/
498 510
511
499class OHostAPMonitoringInterface : public OMonitoringInterface 512class OHostAPMonitoringInterface : public OMonitoringInterface
500{ 513{
501 public: 514 public:
502 OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 515 OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader );
503 virtual ~OHostAPMonitoringInterface(); 516 virtual ~OHostAPMonitoringInterface();
504 517
505 public: 518 public:
506 virtual void setEnabled( bool ); 519 virtual void setEnabled( bool );
507 virtual QString name() const; 520 virtual QString name() const;
508 }; 521 };
509 522
523
510/*====================================================================================== 524/*======================================================================================
511 * OOrinocoMonitoringInterface 525 * OOrinocoMonitoringInterface
512 *======================================================================================*/ 526 *======================================================================================*/
513 527
528
514class OOrinocoMonitoringInterface : public OMonitoringInterface 529class OOrinocoMonitoringInterface : public OMonitoringInterface
515{ 530{
516 public: 531 public:
517 OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 532 OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader );
518 virtual ~OOrinocoMonitoringInterface(); 533 virtual ~OOrinocoMonitoringInterface();
519 534
520 public: 535 public:
521 virtual void setChannel( int ); 536 virtual void setChannel( int );
522 virtual void setEnabled( bool ); 537 virtual void setEnabled( bool );
523 virtual QString name() const; 538 virtual QString name() const;
524 539
525}; 540};