-rw-r--r-- | libopie2/opienet/onetutils.cpp | 1 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 57 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 19 |
3 files changed, 47 insertions, 30 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index fd8f9e9..b317810 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp | |||
@@ -178,8 +178,9 @@ void dumpBytes( const unsigned char* data, int num ) | |||
178 | 178 | ||
179 | for ( int i = 0; i < num; ++i ) | 179 | for ( int i = 0; i < num; ++i ) |
180 | { | 180 | { |
181 | printf( "%02x ", data[i] ); | 181 | printf( "%02x ", data[i] ); |
182 | if ( !((i+1) % 32) ) printf( "\n" ); | 182 | if ( !((i+1) % 32) ) printf( "\n" ); |
183 | } | 183 | } |
184 | printf( "\n\n" ); | 184 | printf( "\n\n" ); |
185 | } | 185 | } |
186 | |||
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 66fa215..789e8ca 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -123,18 +123,18 @@ ONetwork::InterfaceIterator ONetwork::iterator() const | |||
123 | { | 123 | { |
124 | return ONetwork::InterfaceIterator( _interfaces ); | 124 | return ONetwork::InterfaceIterator( _interfaces ); |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | bool ONetwork::isWirelessInterface( const char* name ) const | 128 | bool ONetwork::isWirelessInterface( const char* name ) const |
129 | { | 129 | { |
130 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 130 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
131 | iwreqstruct iwr; | 131 | struct iwreq iwr; |
132 | memset( &iwr, 0, sizeof( iwreqstruct ) ); | 132 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
133 | strcpy( (char*) &iwr.ifr_name, name ); | 133 | strcpy( (char*) &iwr.ifr_name, name ); |
134 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 134 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
135 | if ( result == -1 ) | 135 | if ( result == -1 ) |
136 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); | 136 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); |
137 | else | 137 | else |
138 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); | 138 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); |
139 | return ( result != -1 ); | 139 | return ( result != -1 ); |
140 | } | 140 | } |
@@ -147,17 +147,17 @@ ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | |||
147 | :QObject( parent, name ), | 147 | :QObject( parent, name ), |
148 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 148 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
149 | { | 149 | { |
150 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 150 | qDebug( "ONetworkInterface::ONetworkInterface()" ); |
151 | init(); | 151 | init(); |
152 | } | 152 | } |
153 | 153 | ||
154 | 154 | ||
155 | ifreqstruct& ONetworkInterface::ifr() const | 155 | struct ifreq& ONetworkInterface::ifr() const |
156 | { | 156 | { |
157 | return _ifr; | 157 | return _ifr; |
158 | } | 158 | } |
159 | 159 | ||
160 | 160 | ||
161 | void ONetworkInterface::init() | 161 | void ONetworkInterface::init() |
162 | { | 162 | { |
163 | qDebug( "ONetworkInterface::init()" ); | 163 | qDebug( "ONetworkInterface::init()" ); |
@@ -167,17 +167,17 @@ void ONetworkInterface::init() | |||
167 | if ( _sfd == -1 ) | 167 | if ( _sfd == -1 ) |
168 | { | 168 | { |
169 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); | 169 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); |
170 | return; | 170 | return; |
171 | } | 171 | } |
172 | } | 172 | } |
173 | 173 | ||
174 | 174 | ||
175 | bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const | 175 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
176 | { | 176 | { |
177 | int result = ::ioctl( _sfd, call, &ifreq ); | 177 | int result = ::ioctl( _sfd, call, &ifreq ); |
178 | if ( result == -1 ) | 178 | if ( result == -1 ) |
179 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); | 179 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); |
180 | else | 180 | else |
181 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); | 181 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); |
182 | return ( result != -1 ); | 182 | return ( result != -1 ); |
183 | } | 183 | } |
@@ -372,17 +372,17 @@ OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const cha | |||
372 | } | 372 | } |
373 | 373 | ||
374 | 374 | ||
375 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 375 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
376 | { | 376 | { |
377 | } | 377 | } |
378 | 378 | ||
379 | 379 | ||
380 | iwreqstruct& OWirelessNetworkInterface::iwr() const | 380 | struct iwreq& OWirelessNetworkInterface::iwr() const |
381 | { | 381 | { |
382 | return _iwr; | 382 | return _iwr; |
383 | } | 383 | } |
384 | 384 | ||
385 | 385 | ||
386 | void OWirelessNetworkInterface::init() | 386 | void OWirelessNetworkInterface::init() |
387 | { | 387 | { |
388 | qDebug( "OWirelessNetworkInterface::init()" ); | 388 | qDebug( "OWirelessNetworkInterface::init()" ); |
@@ -412,54 +412,77 @@ QString OWirelessNetworkInterface::associatedAP() const | |||
412 | mac = "<Unknown>"; | 412 | mac = "<Unknown>"; |
413 | } | 413 | } |
414 | return mac; | 414 | return mac; |
415 | } | 415 | } |
416 | 416 | ||
417 | 417 | ||
418 | void OWirelessNetworkInterface::buildChannelList() | 418 | void OWirelessNetworkInterface::buildChannelList() |
419 | { | 419 | { |
420 | // IEEE802.11(b) radio frequency channels | ||
421 | struct iw_range range; | ||
422 | |||
423 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 420 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
424 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | 421 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete |
425 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 422 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
426 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | 423 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate |
427 | //ML: _too much_ space. This is damn shitty crap *sigh* | 424 | //ML: _too much_ space. This is damn shitty crap *sigh* |
428 | 425 | //ML: We allocate a large memory region in RAM and check whether the | |
429 | _iwr.u.data.pointer = (char*) ⦥ | 426 | //ML: driver pollutes this extra space. The complaint will be made on stdout, |
430 | _iwr.u.data.length = IW_MAX_FREQUENCIES; //sizeof range; | 427 | //ML: so please forward this... |
431 | _iwr.u.data.flags = 0; | 428 | |
432 | 429 | struct iwreq wrq; | |
433 | if ( !wioctl( SIOCGIWRANGE ) ) | 430 | int len = sizeof( struct iw_range )*2; |
431 | char *buffer = (char*) malloc( len ); | ||
432 | //FIXME: Validate if we actually got the memory block | ||
433 | memset( buffer, 0, len ); | ||
434 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | ||
435 | wrq.u.data.pointer = (caddr_t) buffer; | ||
436 | wrq.u.data.length = sizeof( struct iw_range ); | ||
437 | wrq.u.data.flags = 0; | ||
438 | |||
439 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | ||
434 | { | 440 | { |
435 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); | 441 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); |
436 | _channels.insert( 2412, 1 ); // 2.412 GHz | 442 | _channels.insert( 2412, 1 ); // 2.412 GHz |
437 | _channels.insert( 2417, 2 ); // 2.417 GHz | 443 | _channels.insert( 2417, 2 ); // 2.417 GHz |
438 | _channels.insert( 2422, 3 ); // 2.422 GHz | 444 | _channels.insert( 2422, 3 ); // 2.422 GHz |
439 | _channels.insert( 2427, 4 ); // 2.427 GHz | 445 | _channels.insert( 2427, 4 ); // 2.427 GHz |
440 | _channels.insert( 2432, 5 ); // 2.432 GHz | 446 | _channels.insert( 2432, 5 ); // 2.432 GHz |
441 | _channels.insert( 2437, 6 ); // 2.437 GHz | 447 | _channels.insert( 2437, 6 ); // 2.437 GHz |
442 | _channels.insert( 2442, 7 ); // 2.442 GHz | 448 | _channels.insert( 2442, 7 ); // 2.442 GHz |
443 | _channels.insert( 2447, 8 ); // 2.447 GHz | 449 | _channels.insert( 2447, 8 ); // 2.447 GHz |
444 | _channels.insert( 2452, 9 ); // 2.452 GHz | 450 | _channels.insert( 2452, 9 ); // 2.452 GHz |
445 | _channels.insert( 2457, 10 ); // 2.457 GHz | 451 | _channels.insert( 2457, 10 ); // 2.457 GHz |
446 | _channels.insert( 2462, 11 ); // 2.462 GHz | 452 | _channels.insert( 2462, 11 ); // 2.462 GHz |
447 | } | 453 | } |
448 | else | 454 | else |
449 | { | 455 | { |
456 | // <check if the driver overwrites stuff> | ||
457 | int max = 0; | ||
458 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | ||
459 | if (buffer[r] != 0) | ||
460 | max = r; | ||
461 | if (max > 0) | ||
462 | { | ||
463 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" | ||
464 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); | ||
465 | } | ||
466 | // </check if the driver overwrites stuff> | ||
467 | |||
468 | struct iw_range range; | ||
469 | memcpy( &range, buffer, sizeof range ); | ||
470 | |||
450 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | 471 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); |
451 | for ( int i = 0; i < range.num_frequency; ++i ) | 472 | for ( int i = 0; i < range.num_frequency; ++i ) |
452 | { | 473 | { |
453 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 474 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
454 | _channels.insert( freq, i+1 ); | 475 | _channels.insert( freq, i+1 ); |
455 | } | 476 | } |
456 | } | 477 | } |
478 | |||
457 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); | 479 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); |
480 | free(buffer); | ||
458 | } | 481 | } |
459 | 482 | ||
460 | 483 | ||
461 | void OWirelessNetworkInterface::buildPrivateList() | 484 | void OWirelessNetworkInterface::buildPrivateList() |
462 | { | 485 | { |
463 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | 486 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); |
464 | 487 | ||
465 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 488 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
@@ -500,17 +523,17 @@ int OWirelessNetworkInterface::channel() const | |||
500 | } | 523 | } |
501 | } | 524 | } |
502 | 525 | ||
503 | 526 | ||
504 | void OWirelessNetworkInterface::setChannel( int c ) const | 527 | void OWirelessNetworkInterface::setChannel( int c ) const |
505 | { | 528 | { |
506 | if ( !_mon ) | 529 | if ( !_mon ) |
507 | { | 530 | { |
508 | memset( &_iwr, 0, sizeof( iwreqstruct ) ); | 531 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
509 | _iwr.u.freq.m = c; | 532 | _iwr.u.freq.m = c; |
510 | _iwr.u.freq.e = 0; | 533 | _iwr.u.freq.e = 0; |
511 | wioctl( SIOCSIWFREQ ); | 534 | wioctl( SIOCSIWFREQ ); |
512 | } | 535 | } |
513 | else | 536 | else |
514 | { | 537 | { |
515 | _mon->setChannel( c ); | 538 | _mon->setChannel( c ); |
516 | } | 539 | } |
@@ -634,17 +657,17 @@ QString OWirelessNetworkInterface::SSID() const | |||
634 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 657 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
635 | { | 658 | { |
636 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 659 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
637 | _iwr.u.essid.length = ssid.length(); | 660 | _iwr.u.essid.length = ssid.length(); |
638 | wioctl( SIOCSIWESSID ); | 661 | wioctl( SIOCSIWESSID ); |
639 | } | 662 | } |
640 | 663 | ||
641 | 664 | ||
642 | bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const | 665 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
643 | { | 666 | { |
644 | int result = ::ioctl( _sfd, call, &iwreq ); | 667 | int result = ::ioctl( _sfd, call, &iwreq ); |
645 | if ( result == -1 ) | 668 | if ( result == -1 ) |
646 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); | 669 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); |
647 | else | 670 | else |
648 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); | 671 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); |
649 | return ( result != -1 ); | 672 | return ( result != -1 ); |
650 | } | 673 | } |
@@ -670,17 +693,17 @@ OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) | |||
670 | OMonitoringInterface::~OMonitoringInterface() | 693 | OMonitoringInterface::~OMonitoringInterface() |
671 | { | 694 | { |
672 | } | 695 | } |
673 | 696 | ||
674 | 697 | ||
675 | void OMonitoringInterface::setChannel( int c ) | 698 | void OMonitoringInterface::setChannel( int c ) |
676 | { | 699 | { |
677 | // use standard WE channel switching protocol | 700 | // use standard WE channel switching protocol |
678 | memset( &_if->_iwr, 0, sizeof( iwreqstruct ) ); | 701 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
679 | _if->_iwr.u.freq.m = c; | 702 | _if->_iwr.u.freq.m = c; |
680 | _if->_iwr.u.freq.e = 0; | 703 | _if->_iwr.u.freq.e = 0; |
681 | _if->wioctl( SIOCSIWFREQ ); | 704 | _if->wioctl( SIOCSIWFREQ ); |
682 | } | 705 | } |
683 | 706 | ||
684 | 707 | ||
685 | bool OMonitoringInterface::enabled() const | 708 | bool OMonitoringInterface::enabled() const |
686 | { | 709 | { |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 7c70873..509c3db 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -67,23 +67,16 @@ | |||
67 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE | 67 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE |
68 | #endif | 68 | #endif |
69 | 69 | ||
70 | class ONetworkInterface; | 70 | class ONetworkInterface; |
71 | class OWirelessNetworkInterface; | 71 | class OWirelessNetworkInterface; |
72 | class OChannelHopper; | 72 | class OChannelHopper; |
73 | class OMonitoringInterface; | 73 | class OMonitoringInterface; |
74 | 74 | ||
75 | typedef struct ifreq ifreqstruct; | ||
76 | typedef struct iwreq iwreqstruct; | ||
77 | typedef struct iw_event iweventstruct; | ||
78 | typedef struct iw_freq iwfreqstruct; | ||
79 | typedef struct iw_priv_args iwprivargsstruct; | ||
80 | typedef struct iw_range iwrangestruct; | ||
81 | |||
82 | /*====================================================================================== | 75 | /*====================================================================================== |
83 | * ONetwork | 76 | * ONetwork |
84 | *======================================================================================*/ | 77 | *======================================================================================*/ |
85 | 78 | ||
86 | class ONetwork : public QObject | 79 | class ONetwork : public QObject |
87 | { | 80 | { |
88 | Q_OBJECT | 81 | Q_OBJECT |
89 | 82 | ||
@@ -131,24 +124,24 @@ class ONetworkInterface : public QObject | |||
131 | bool isUp() const; | 124 | bool isUp() const; |
132 | bool isLoopback() const; | 125 | bool isLoopback() const; |
133 | bool isWireless() const; | 126 | bool isWireless() const; |
134 | QString ipV4Address() const; | 127 | QString ipV4Address() const; |
135 | OMacAddress macAddress() const; | 128 | OMacAddress macAddress() const; |
136 | 129 | ||
137 | protected: | 130 | protected: |
138 | const int _sfd; | 131 | const int _sfd; |
139 | mutable ifreqstruct _ifr; | 132 | mutable ifreq _ifr; |
140 | OMonitoringInterface* _mon; | 133 | OMonitoringInterface* _mon; |
141 | 134 | ||
142 | protected: | 135 | protected: |
143 | ifreqstruct& ifr() const; | 136 | struct ifreq& ifr() const; |
144 | virtual void init(); | 137 | virtual void init(); |
145 | bool ioctl( int call ) const; | 138 | bool ioctl( int call ) const; |
146 | bool ioctl( int call, ifreqstruct& ) const; | 139 | bool ioctl( int call, struct ifreq& ) const; |
147 | }; | 140 | }; |
148 | 141 | ||
149 | /*====================================================================================== | 142 | /*====================================================================================== |
150 | * OChannelHopper | 143 | * OChannelHopper |
151 | *======================================================================================*/ | 144 | *======================================================================================*/ |
152 | 145 | ||
153 | class OChannelHopper : public QObject | 146 | class OChannelHopper : public QObject |
154 | { | 147 | { |
@@ -217,22 +210,22 @@ class OWirelessNetworkInterface : public ONetworkInterface | |||
217 | 210 | ||
218 | virtual void setSSID( const QString& ); | 211 | virtual void setSSID( const QString& ); |
219 | virtual QString SSID() const; | 212 | virtual QString SSID() const; |
220 | 213 | ||
221 | protected: | 214 | protected: |
222 | void buildChannelList(); | 215 | void buildChannelList(); |
223 | void buildPrivateList(); | 216 | void buildPrivateList(); |
224 | virtual void init(); | 217 | virtual void init(); |
225 | iwreqstruct& iwr() const; | 218 | struct iwreq& iwr() const; |
226 | bool wioctl( int call ) const; | 219 | bool wioctl( int call ) const; |
227 | bool wioctl( int call, iwreqstruct& ) const; | 220 | bool wioctl( int call, struct iwreq& ) const; |
228 | 221 | ||
229 | protected: | 222 | protected: |
230 | mutable iwreqstruct _iwr; | 223 | mutable struct iwreq _iwr; |
231 | QMap<int,int> _channels; | 224 | QMap<int,int> _channels; |
232 | 225 | ||
233 | private: | 226 | private: |
234 | OChannelHopper* _hopper; | 227 | OChannelHopper* _hopper; |
235 | }; | 228 | }; |
236 | 229 | ||
237 | 230 | ||
238 | /*====================================================================================== | 231 | /*====================================================================================== |