summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-02-24 22:56:24 (UTC)
committer mickeyl <mickeyl>2004-02-24 22:56:24 (UTC)
commit96ba6fcf27c785282c3fe05557df8b384df06852 (patch) (unidiff)
tree9b25648f8518c8d152d4774ac05f81548828f3d5
parenta1a6a1013eae9a4ca4607f2d656c98821a30f431 (diff)
downloadopie-96ba6fcf27c785282c3fe05557df8b384df06852.zip
opie-96ba6fcf27c785282c3fe05557df8b384df06852.tar.gz
opie-96ba6fcf27c785282c3fe05557df8b384df06852.tar.bz2
API extension: ONetwork::isPresent( const char* name )
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp23
-rw-r--r--libopie2/opienet/onetwork.h4
2 files changed, 21 insertions, 6 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 915814d..e5b091f 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -83,128 +83,139 @@ void ONetwork::synchronize()
83 _interfaces.clear(); 83 _interfaces.clear();
84 QString str; 84 QString str;
85 QFile f( "/proc/net/dev" ); 85 QFile f( "/proc/net/dev" );
86 bool hasFile = f.open( IO_ReadOnly ); 86 bool hasFile = f.open( IO_ReadOnly );
87 if ( !hasFile ) 87 if ( !hasFile )
88 { 88 {
89 odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; 89 odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl;
90 return; 90 return;
91 } 91 }
92 QTextStream s( &f ); 92 QTextStream s( &f );
93 s.readLine(); 93 s.readLine();
94 s.readLine(); 94 s.readLine();
95 while ( !s.atEnd() ) 95 while ( !s.atEnd() )
96 { 96 {
97 s >> str; 97 s >> str;
98 str.truncate( str.find( ':' ) ); 98 str.truncate( str.find( ':' ) );
99 odebug << "ONetwork: found interface '" << str << "'" << oendl; 99 odebug << "ONetwork: found interface '" << str << "'" << oendl;
100 ONetworkInterface* iface; 100 ONetworkInterface* iface;
101 if ( isWirelessInterface( str ) ) 101 if ( isWirelessInterface( str ) )
102 { 102 {
103 iface = new OWirelessNetworkInterface( this, (const char*) str ); 103 iface = new OWirelessNetworkInterface( this, (const char*) str );
104 odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; 104 odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl;
105 } 105 }
106 else 106 else
107 { 107 {
108 iface = new ONetworkInterface( this, (const char*) str ); 108 iface = new ONetworkInterface( this, (const char*) str );
109 } 109 }
110 _interfaces.insert( str, iface ); 110 _interfaces.insert( str, iface );
111 s.readLine(); 111 s.readLine();
112 } 112 }
113} 113}
114 114
115 115
116short ONetwork::wirelessExtensionVersion() 116short ONetwork::wirelessExtensionVersion()
117{ 117{
118 return WIRELESS_EXT; 118 return WIRELESS_EXT;
119} 119}
120 120
121 121
122int ONetwork::count() const 122int ONetwork::count() const
123{ 123{
124 return _interfaces.count(); 124 return _interfaces.count();
125} 125}
126 126
127 127
128ONetworkInterface* ONetwork::interface( const QString& iface ) const 128ONetworkInterface* ONetwork::interface( const QString& iface ) const
129{ 129{
130 return _interfaces[iface]; 130 return _interfaces[iface];
131} 131}
132 132
133 133
134ONetwork* ONetwork::instance() 134ONetwork* ONetwork::instance()
135{ 135{
136 if ( !_instance ) _instance = new ONetwork(); 136 if ( !_instance ) _instance = new ONetwork();
137 return _instance; 137 return _instance;
138} 138}
139 139
140 140
141ONetwork::InterfaceIterator ONetwork::iterator() const 141ONetwork::InterfaceIterator ONetwork::iterator() const
142{ 142{
143 return ONetwork::InterfaceIterator( _interfaces ); 143 return ONetwork::InterfaceIterator( _interfaces );
144} 144}
145 145
146 146
147bool ONetwork::isPresent( const char* name ) const
148{
149 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
150 struct ifreq ifr;
151 memset( &ifr, 0, sizeof( struct ifreq ) );
152 strcpy( (char*) &ifr.ifr_name, name );
153 int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr );
154 return result != -1;
155}
156
157
147bool ONetwork::isWirelessInterface( const char* name ) const 158bool ONetwork::isWirelessInterface( const char* name ) const
148{ 159{
149 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 160 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
150 struct iwreq iwr; 161 struct iwreq iwr;
151 memset( &iwr, 0, sizeof( struct iwreq ) ); 162 memset( &iwr, 0, sizeof( struct iwreq ) );
152 strcpy( (char*) &iwr.ifr_name, name ); 163 strcpy( (char*) &iwr.ifr_name, name );
153 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 164 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
154 return result != -1; 165 return result != -1;
155} 166}
156 167
157/*====================================================================================== 168/*======================================================================================
158 * ONetworkInterface 169 * ONetworkInterface
159 *======================================================================================*/ 170 *======================================================================================*/
160 171
161ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) 172ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
162 :QObject( parent, name ), 173 :QObject( parent, name ),
163 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 174 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
164{ 175{
165 odebug << "ONetworkInterface::ONetworkInterface()" << oendl; 176 odebug << "ONetworkInterface::ONetworkInterface()" << oendl;
166 init(); 177 init();
167} 178}
168 179
169 180
170struct ifreq& ONetworkInterface::ifr() const 181struct ifreq& ONetworkInterface::ifr() const
171{ 182{
172 return _ifr; 183 return _ifr;
173} 184}
174 185
175 186
176void ONetworkInterface::init() 187void ONetworkInterface::init()
177{ 188{
178 odebug << "ONetworkInterface::init()" << oendl; 189 odebug << "ONetworkInterface::init()" << oendl;
179 190
180 memset( &_ifr, 0, sizeof( struct ifreq ) ); 191 memset( &_ifr, 0, sizeof( struct ifreq ) );
181 192
182 if ( _sfd == -1 ) 193 if ( _sfd == -1 )
183 { 194 {
184 odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; 195 odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl;
185 return; 196 return;
186 } 197 }
187} 198}
188 199
189 200
190bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const 201bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
191{ 202{
192 #ifndef NODEBUG 203 #ifndef NODEBUG
193 int result = ::ioctl( _sfd, call, &ifreq ); 204 int result = ::ioctl( _sfd, call, &ifreq );
194 if ( result == -1 ) 205 if ( result == -1 )
195 odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) 206 odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call )
196 << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; 207 << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl;
197 else 208 else
198 odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) 209 odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call )
199 << "' - Status: Ok." << oendl; 210 << "' - Status: Ok." << oendl;
200 return ( result != -1 ); 211 return ( result != -1 );
201 #else 212 #else
202 return ::ioctl( _sfd, call, &ifreq ) != -1; 213 return ::ioctl( _sfd, call, &ifreq ) != -1;
203 #endif 214 #endif
204} 215}
205 216
206 217
207bool ONetworkInterface::ioctl( int call ) const 218bool ONetworkInterface::ioctl( int call ) const
208{ 219{
209 strcpy( _ifr.ifr_name, name() ); 220 strcpy( _ifr.ifr_name, name() );
210 return ioctl( call, _ifr ); 221 return ioctl( call, _ifr );
@@ -521,133 +532,133 @@ void OWirelessNetworkInterface::buildInformation()
521 _channels.insert( 2457, 10 ); // 2.457 GHz 532 _channels.insert( 2457, 10 ); // 2.457 GHz
522 _channels.insert( 2462, 11 ); // 2.462 GHz 533 _channels.insert( 2462, 11 ); // 2.462 GHz
523 534
524 memset( &_range, 0, sizeof( struct iw_range ) ); 535 memset( &_range, 0, sizeof( struct iw_range ) );
525 } 536 }
526 else 537 else
527 { 538 {
528 // <check if the driver overwrites stuff> 539 // <check if the driver overwrites stuff>
529 int max = 0; 540 int max = 0;
530 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 541 for ( int r = sizeof( struct iw_range ); r < len; r++ )
531 if (buffer[r] != 0) 542 if (buffer[r] != 0)
532 max = r; 543 max = r;
533 if (max > 0) 544 if (max > 0)
534 { 545 {
535 owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() 546 owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name()
536 << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; 547 << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl;
537 } 548 }
538 // </check if the driver overwrites stuff> 549 // </check if the driver overwrites stuff>
539 550
540 struct iw_range range; 551 struct iw_range range;
541 memcpy( &range, buffer, sizeof range ); 552 memcpy( &range, buffer, sizeof range );
542 553
543 odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; 554 odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl;
544 for ( int i = 0; i < range.num_frequency; ++i ) 555 for ( int i = 0; i < range.num_frequency; ++i )
545 { 556 {
546 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 557 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
547 _channels.insert( freq, i+1 ); 558 _channels.insert( freq, i+1 );
548 } 559 }
549 } 560 }
550 561
551 memcpy( &_range, buffer, sizeof( struct iw_range ) ); 562 memcpy( &_range, buffer, sizeof( struct iw_range ) );
552 odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; 563 odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl;
553 free(buffer); 564 free(buffer);
554} 565}
555 566
556 567
557void OWirelessNetworkInterface::buildPrivateList() 568void OWirelessNetworkInterface::buildPrivateList()
558{ 569{
559 odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; 570 odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl;
560 571
561 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 572 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
562 573
563 _iwr.u.data.pointer = (char*) &priv; 574 _iwr.u.data.pointer = (char*) &priv;
564 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 575 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
565 _iwr.u.data.flags = 0; 576 _iwr.u.data.flags = 0;
566 577
567 if ( !wioctl( SIOCGIWPRIV ) ) 578 if ( !wioctl( SIOCGIWPRIV ) )
568 { 579 {
569 owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; 580 owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl;
570 return; 581 return;
571 } 582 }
572 583
573 for ( int i = 0; i < _iwr.u.data.length; ++i ) 584 for ( int i = 0; i < _iwr.u.data.length; ++i )
574 { 585 {
575 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 586 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
576 } 587 }
577 odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; 588 odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl;
578} 589}
579 590
580 591
581void OWirelessNetworkInterface::dumpInformation() const 592void OWirelessNetworkInterface::dumpInformation() const
582{ 593{
583 odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; 594 odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl;
584 595
585 qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", 596 qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s",
586 _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ); 597 _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 );
587 qDebug( " - driver for '%s' (V%d) has been compiled against WE V%d", 598 qDebug( " - driver for '%s' (V%d) has been compiled against WE V%d",
588 name(), _range.we_version_source, _range.we_version_compiled ); 599 name(), _range.we_version_source, _range.we_version_compiled );
589 600
590 if ( _range.we_version_compiled != WIRELESS_EXT ) 601 if ( _range.we_version_compiled != WIRELESS_EXT )
591 { 602 {
592 owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; 603 owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl;
593 } 604 }
594 605
595 odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; 606 odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl;
596} 607}
597 608
598 609
599int OWirelessNetworkInterface::channel() const 610int OWirelessNetworkInterface::channel() const
600{ 611{
601 //FIXME: When monitoring enabled, then use it 612 //FIXME: When monitoring enabled, then use it
602 //FIXME: to gather the current RF channel 613 //FIXME: to gather the current RF channel
603 //FIXME: Until then, get active channel from hopper. 614 //FIXME: Until then, get active channel from hopper.
604 if ( _hopper && _hopper->isActive() ) 615 if ( _hopper && _hopper->isActive() )
605 return _hopper->channel(); 616 return _hopper->channel();
606 617
607 if ( !wioctl( SIOCGIWFREQ ) ) 618 if ( !wioctl( SIOCGIWFREQ ) )
608 { 619 {
609 return -1; 620 return -1;
610 } 621 }
611 else 622 else
612 { 623 {
613 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 624 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
614 } 625 }
615} 626}
616 627
617 628
618void OWirelessNetworkInterface::setChannel( int c ) const 629void OWirelessNetworkInterface::setChannel( int c ) const
619{ 630{
620 if ( !c ) 631 if ( !c )
621 { 632 {
622 oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl; 633 oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl;
623 return; 634 return;
624 } 635 }
625 636
626 if ( !_mon ) 637 if ( !_mon )
627 { 638 {
628 memset( &_iwr, 0, sizeof( struct iwreq ) ); 639 memset( &_iwr, 0, sizeof( struct iwreq ) );
629 _iwr.u.freq.m = c; 640 _iwr.u.freq.m = c;
630 _iwr.u.freq.e = 0; 641 _iwr.u.freq.e = 0;
631 wioctl( SIOCSIWFREQ ); 642 wioctl( SIOCSIWFREQ );
632 } 643 }
633 else 644 else
634 { 645 {
635 _mon->setChannel( c ); 646 _mon->setChannel( c );
636 } 647 }
637} 648}
638 649
639 650
640double OWirelessNetworkInterface::frequency() const 651double OWirelessNetworkInterface::frequency() const
641{ 652{
642 if ( !wioctl( SIOCGIWFREQ ) ) 653 if ( !wioctl( SIOCGIWFREQ ) )
643 { 654 {
644 return -1.0; 655 return -1.0;
645 } 656 }
646 else 657 else
647 { 658 {
648 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 659 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
649 } 660 }
650} 661}
651 662
652 663
653int OWirelessNetworkInterface::channels() const 664int OWirelessNetworkInterface::channels() const
@@ -911,145 +922,145 @@ OStationList* OWirelessNetworkInterface::scanNetwork()
911 // parse results 922 // parse results
912 923
913 int offset = 0; 924 int offset = 0;
914 struct iw_event* we = (struct iw_event*) &buffer[0]; 925 struct iw_event* we = (struct iw_event*) &buffer[0];
915 926
916 while ( offset < _iwr.u.data.length ) 927 while ( offset < _iwr.u.data.length )
917 { 928 {
918 //const char* cmd = *(*_ioctlmap)[we->cmd]; 929 //const char* cmd = *(*_ioctlmap)[we->cmd];
919 //if ( !cmd ) cmd = "<unknown>"; 930 //if ( !cmd ) cmd = "<unknown>";
920 odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl; 931 odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl;
921 switch (we->cmd) 932 switch (we->cmd)
922 { 933 {
923 case SIOCGIWAP: 934 case SIOCGIWAP:
924 { 935 {
925 odebug << "SIOCGIWAP" << oendl; 936 odebug << "SIOCGIWAP" << oendl;
926 stations->append( new OStation() ); 937 stations->append( new OStation() );
927 stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; 938 stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0];
928 break; 939 break;
929 } 940 }
930 case SIOCGIWMODE: 941 case SIOCGIWMODE:
931 { 942 {
932 odebug << "SIOCGIWMODE" << oendl; 943 odebug << "SIOCGIWMODE" << oendl;
933 stations->last()->type = modeToString( we->u.mode ); 944 stations->last()->type = modeToString( we->u.mode );
934 break; 945 break;
935 } 946 }
936 case SIOCGIWFREQ: 947 case SIOCGIWFREQ:
937 { 948 {
938 odebug << "SIOCGIWFREQ" << oendl; 949 odebug << "SIOCGIWFREQ" << oendl;
939 stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; 950 stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ];
940 break; 951 break;
941 } 952 }
942 case SIOCGIWESSID: 953 case SIOCGIWESSID:
943 { 954 {
944 odebug << "SIOCGIWESSID" << oendl; 955 odebug << "SIOCGIWESSID" << oendl;
945 stations->last()->ssid = we->u.essid.pointer; 956 stations->last()->ssid = we->u.essid.pointer;
946 break; 957 break;
947 } 958 }
948 case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; 959 case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break;
949 case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break; 960 case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break;
950 case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ 961 case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */
951 case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */ 962 case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */
952 case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ 963 case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */
953 case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ 964 case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */
954 case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ 965 case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */
955 default: odebug << "unhandled event" << oendl; 966 default: odebug << "unhandled event" << oendl;
956 } 967 }
957 968
958 offset += we->len; 969 offset += we->len;
959 we = (struct iw_event*) &buffer[offset]; 970 we = (struct iw_event*) &buffer[offset];
960 } 971 }
961 return stations; 972 return stations;
962 973
963 return stations; 974 return stations;
964 975
965 } 976 }
966 else 977 else
967 { 978 {
968 odebug << " - no results (timeout) :(" << oendl; 979 odebug << " - no results (timeout) :(" << oendl;
969 return stations; 980 return stations;
970 } 981 }
971} 982}
972 983
973 984
974int OWirelessNetworkInterface::signalStrength() const 985int OWirelessNetworkInterface::signalStrength() const
975{ 986{
976 iw_statistics stat; 987 iw_statistics stat;
977 ::memset( &stat, 0, sizeof stat ); 988 ::memset( &stat, 0, sizeof stat );
978 _iwr.u.data.pointer = (char*) &stat; 989 _iwr.u.data.pointer = (char*) &stat;
979 _iwr.u.data.flags = 0; 990 _iwr.u.data.flags = 0;
980 _iwr.u.data.length = sizeof stat; 991 _iwr.u.data.length = sizeof stat;
981 992
982 if ( !wioctl( SIOCGIWSTATS ) ) 993 if ( !wioctl( SIOCGIWSTATS ) )
983 { 994 {
984 return -1; 995 return -1;
985 } 996 }
986 997
987 int max = _range.max_qual.qual; 998 int max = _range.max_qual.qual;
988 int cur = stat.qual.qual; 999 int cur = stat.qual.qual;
989 int lev = stat.qual.level; //FIXME: Do something with them? 1000 int lev = stat.qual.level; //FIXME: Do something with them?
990 int noi = stat.qual.noise; //FIXME: Do something with them? 1001 int noi = stat.qual.noise; //FIXME: Do something with them?
991 1002
992 return cur*100/max; 1003 return cur*100/max;
993} 1004}
994 1005
995 1006
996bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 1007bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
997{ 1008{
998 #ifndef NODEBUG 1009 #ifndef NODEBUG
999 int result = ::ioctl( _sfd, call, &iwreq ); 1010 int result = ::ioctl( _sfd, call, &iwreq );
1000 1011
1001 if ( result == -1 ) 1012 if ( result == -1 )
1002 odebug << "ONetworkInterface::wioctl (" << name() << ") call '" 1013 odebug << "ONetworkInterface::wioctl (" << name() << ") call '"
1003 << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; 1014 << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl;
1004 else 1015 else
1005 odebug << "ONetworkInterface::wioctl (" << name() << ") call '" 1016 odebug << "ONetworkInterface::wioctl (" << name() << ") call '"
1006 << debugmapper->map( call ) << "' - Status: Ok." << oendl; 1017 << debugmapper->map( call ) << "' - Status: Ok." << oendl;
1007 1018
1008 return ( result != -1 ); 1019 return ( result != -1 );
1009 #else 1020 #else
1010 return ::ioctl( _sfd, call, &iwreq ) != -1; 1021 return ::ioctl( _sfd, call, &iwreq ) != -1;
1011 #endif 1022 #endif
1012} 1023}
1013 1024
1014 1025
1015bool OWirelessNetworkInterface::wioctl( int call ) const 1026bool OWirelessNetworkInterface::wioctl( int call ) const
1016{ 1027{
1017 strcpy( _iwr.ifr_name, name() ); 1028 strcpy( _iwr.ifr_name, name() );
1018 return wioctl( call, _iwr ); 1029 return wioctl( call, _iwr );
1019} 1030}
1020 1031
1021 1032
1022/*====================================================================================== 1033/*======================================================================================
1023 * OMonitoringInterface 1034 * OMonitoringInterface
1024 *======================================================================================*/ 1035 *======================================================================================*/
1025 1036
1026OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1037OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
1027 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) 1038 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader )
1028{ 1039{
1029} 1040}
1030 1041
1031 1042
1032OMonitoringInterface::~OMonitoringInterface() 1043OMonitoringInterface::~OMonitoringInterface()
1033{ 1044{
1034} 1045}
1035 1046
1036 1047
1037void OMonitoringInterface::setChannel( int c ) 1048void OMonitoringInterface::setChannel( int c )
1038{ 1049{
1039 // use standard WE channel switching protocol 1050 // use standard WE channel switching protocol
1040 memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); 1051 memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
1041 _if->_iwr.u.freq.m = c; 1052 _if->_iwr.u.freq.m = c;
1042 _if->_iwr.u.freq.e = 0; 1053 _if->_iwr.u.freq.e = 0;
1043 _if->wioctl( SIOCSIWFREQ ); 1054 _if->wioctl( SIOCSIWFREQ );
1044} 1055}
1045 1056
1046 1057
1047void OMonitoringInterface::setEnabled( bool b ) 1058void OMonitoringInterface::setEnabled( bool b )
1048{ 1059{
1049} 1060}
1050 1061
1051 1062
1052/*====================================================================================== 1063/*======================================================================================
1053 * OCiscoMonitoringInterface 1064 * OCiscoMonitoringInterface
1054 *======================================================================================*/ 1065 *======================================================================================*/
1055 1066
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index 0a51108..93b129f 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -33,128 +33,132 @@
33 33
34#if !defined( OPIE_WE_VERSION ) 34#if !defined( OPIE_WE_VERSION )
35#error Need to define a wireless extension version to build against! 35#error Need to define a wireless extension version to build against!
36#endif 36#endif
37 37
38#if OPIE_WE_VERSION == 15 38#if OPIE_WE_VERSION == 15
39#include "wireless.15.h" 39#include "wireless.15.h"
40#endif 40#endif
41 41
42#if OPIE_WE_VERSION == 16 42#if OPIE_WE_VERSION == 16
43#include "wireless.16.h" 43#include "wireless.16.h"
44#endif 44#endif
45 45
46/* OPIE */ 46/* OPIE */
47 47
48#include <opie2/onetutils.h> 48#include <opie2/onetutils.h>
49#include <opie2/ostation.h> 49#include <opie2/ostation.h>
50 50
51/* QT */ 51/* QT */
52 52
53#include <qvaluelist.h> 53#include <qvaluelist.h>
54#include <qdict.h> 54#include <qdict.h>
55#include <qmap.h> 55#include <qmap.h>
56#include <qobject.h> 56#include <qobject.h>
57#include <qhostaddress.h> 57#include <qhostaddress.h>
58 58
59class ONetworkInterface; 59class ONetworkInterface;
60class OWirelessNetworkInterface; 60class OWirelessNetworkInterface;
61class OChannelHopper; 61class OChannelHopper;
62class OMonitoringInterface; 62class OMonitoringInterface;
63 63
64/*====================================================================================== 64/*======================================================================================
65 * ONetwork 65 * ONetwork
66 *======================================================================================*/ 66 *======================================================================================*/
67 67
68/** 68/**
69 * @brief A container class for all network interfaces 69 * @brief A container class for all network interfaces
70 * 70 *
71 * This class provides access to all available network interfaces of your computer. 71 * This class provides access to all available network interfaces of your computer.
72 * 72 *
73 * @author Michael 'Mickey' Lauer <mickey@vanille.de> 73 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
74 */ 74 */
75class ONetwork : public QObject 75class ONetwork : public QObject
76{ 76{
77 Q_OBJECT 77 Q_OBJECT
78 78
79 public: 79 public:
80 typedef QDict<ONetworkInterface> InterfaceMap; 80 typedef QDict<ONetworkInterface> InterfaceMap;
81 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 81 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
82 82
83 public: 83 public:
84 /** 84 /**
85 * @returns the number of available interfaces 85 * @returns the number of available interfaces
86 */ 86 */
87 int count() const; 87 int count() const;
88 /** 88 /**
89 * @returns a pointer to the (one and only) @ref ONetwork instance. 89 * @returns a pointer to the (one and only) @ref ONetwork instance.
90 */ 90 */
91 static ONetwork* instance(); 91 static ONetwork* instance();
92 /** 92 /**
93 * @returns an iterator usable for iterating through all network interfaces. 93 * @returns an iterator usable for iterating through all network interfaces.
94 */ 94 */
95 InterfaceIterator iterator() const; 95 InterfaceIterator iterator() const;
96 /** 96 /**
97 * @returns true, if the @a interface is present.
98 */
99 bool isPresent( const char* interface ) const;
100 /**
97 * @returns true, if the @a interface supports the wireless extension protocol. 101 * @returns true, if the @a interface supports the wireless extension protocol.
98 */ 102 */
99 bool isWirelessInterface( const char* interface ) const; 103 bool isWirelessInterface( const char* interface ) const;
100 /** 104 /**
101 * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. 105 * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found.
102 * @see ONetworkInterface 106 * @see ONetworkInterface
103 */ 107 */
104 ONetworkInterface* interface( const QString& interface ) const; 108 ONetworkInterface* interface( const QString& interface ) const;
105 /** 109 /**
106 * @internal Rebuild the internal interface database 110 * @internal Rebuild the internal interface database
107 * @note Sometimes it might be useful to call this from client code, 111 * @note Sometimes it might be useful to call this from client code,
108 * e.g. after issuing a cardctl insert 112 * e.g. after issuing a cardctl insert
109 */ 113 */
110 void synchronize(); 114 void synchronize();
111 /** 115 /**
112 * @returns the wireless extension version used at compile time. 116 * @returns the wireless extension version used at compile time.
113 **/ 117 **/
114 static short wirelessExtensionVersion(); 118 static short wirelessExtensionVersion();
115 119
116 protected: 120 protected:
117 ONetwork(); 121 ONetwork();
118 122
119 private: 123 private:
120 static ONetwork* _instance; 124 static ONetwork* _instance;
121 InterfaceMap _interfaces; 125 InterfaceMap _interfaces;
122}; 126};
123 127
124 128
125/*====================================================================================== 129/*======================================================================================
126 * ONetworkInterface 130 * ONetworkInterface
127 *======================================================================================*/ 131 *======================================================================================*/
128 132
129/** 133/**
130 * @brief A network interface wrapper. 134 * @brief A network interface wrapper.
131 * 135 *
132 * This class provides a wrapper for a network interface. All the cumbersume details of 136 * This class provides a wrapper for a network interface. All the cumbersume details of
133 * Linux ioctls are hidden under a convenient high-level interface. 137 * Linux ioctls are hidden under a convenient high-level interface.
134 * @warning Most of the setting methods contained in this class require the appropriate 138 * @warning Most of the setting methods contained in this class require the appropriate
135 * process permissions to work. 139 * process permissions to work.
136 * 140 *
137 * @author Michael 'Mickey' Lauer <mickey@vanille.de> 141 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
138 */ 142 */
139class ONetworkInterface : public QObject 143class ONetworkInterface : public QObject
140{ 144{
141 friend class OMonitoringInterface; 145 friend class OMonitoringInterface;
142 friend class OCiscoMonitoringInterface; 146 friend class OCiscoMonitoringInterface;
143 friend class OWlanNGMonitoringInterface; 147 friend class OWlanNGMonitoringInterface;
144 friend class OHostAPMonitoringInterface; 148 friend class OHostAPMonitoringInterface;
145 friend class OOrinocoMonitoringInterface; 149 friend class OOrinocoMonitoringInterface;
146 150
147 public: 151 public:
148 /** 152 /**
149 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, 153 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself,
150 * but access them via @ref ONetwork::interface(). 154 * but access them via @ref ONetwork::interface().
151 */ 155 */
152 ONetworkInterface( QObject* parent, const char* name ); 156 ONetworkInterface( QObject* parent, const char* name );
153 /** 157 /**
154 * Destructor. 158 * Destructor.
155 */ 159 */
156 virtual ~ONetworkInterface(); 160 virtual ~ONetworkInterface();
157 /** 161 /**
158 * Associates a @a monitoring interface with this network interface. 162 * Associates a @a monitoring interface with this network interface.
159 * @note This is currently only useful with @ref OWirelessNetworkInterface objects. 163 * @note This is currently only useful with @ref OWirelessNetworkInterface objects.
160 */ 164 */