author | mickeyl <mickeyl> | 2003-04-03 14:17:03 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-03 14:17:03 (UTC) |
commit | f62005c53c93148eaa13eac50ea6814a41afb216 (patch) (unidiff) | |
tree | 93e7e626205fd9d06b5ac7c29e78be52ce749e5d /libopie2/opienet/onetwork.cpp | |
parent | e9eeb493c75bfe6078f40952e85e859fb71fe970 (diff) | |
download | opie-f62005c53c93148eaa13eac50ea6814a41afb216.zip opie-f62005c53c93148eaa13eac50ea6814a41afb216.tar.gz opie-f62005c53c93148eaa13eac50ea6814a41afb216.tar.bz2 |
- ONetworkInterfaces are now QObjects
- add support for private IOCTLS
- make buildChannelList() more safe in case of faulty drivers
Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 127 |
1 files changed, 82 insertions, 45 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index ac2857a..2548a04 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -94,3 +94,3 @@ void ONetwork::synchronize() | |||
94 | { | 94 | { |
95 | iface = new OWirelessNetworkInterface( str ); | 95 | iface = new OWirelessNetworkInterface( this, str ); |
96 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 96 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); |
@@ -99,3 +99,3 @@ void ONetwork::synchronize() | |||
99 | { | 99 | { |
100 | iface = new ONetworkInterface( str ); | 100 | iface = new ONetworkInterface( this, str ); |
101 | } | 101 | } |
@@ -128,3 +128,3 @@ bool ONetwork::isWirelessInterface( const char* name ) const | |||
128 | { | 128 | { |
129 | int sfd = socket( AF_INET, SOCK_DGRAM, 0 ); | 129 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
130 | iwreqstruct iwr; | 130 | iwreqstruct iwr; |
@@ -144,4 +144,5 @@ bool ONetwork::isWirelessInterface( const char* name ) const | |||
144 | 144 | ||
145 | ONetworkInterface::ONetworkInterface( const QString& name ) | 145 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
146 | :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 146 | :QObject( parent, name ), |
147 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | ||
147 | { | 148 | { |
@@ -166,3 +167,3 @@ void ONetworkInterface::init() | |||
166 | { | 167 | { |
167 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name ); | 168 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); |
168 | return; | 169 | return; |
@@ -185,3 +186,3 @@ bool ONetworkInterface::ioctl( int call ) const | |||
185 | { | 186 | { |
186 | strcpy( _ifr.ifr_name, (const char*) _name ); | 187 | strcpy( _ifr.ifr_name, name() ); |
187 | return ioctl( call, _ifr ); | 188 | return ioctl( call, _ifr ); |
@@ -242,3 +243,3 @@ void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | |||
242 | _mon = m; | 243 | _mon = m; |
243 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), (const char*) _name ); | 244 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); |
244 | } | 245 | } |
@@ -252,8 +253,2 @@ OMonitoringInterface* ONetworkInterface::monitoring() const | |||
252 | 253 | ||
253 | const QString& ONetworkInterface::name() const | ||
254 | { | ||
255 | return _name; | ||
256 | } | ||
257 | |||
258 | |||
259 | ONetworkInterface::~ONetworkInterface() | 254 | ONetworkInterface::~ONetworkInterface() |
@@ -370,4 +365,4 @@ int OChannelHopper::interval() const | |||
370 | 365 | ||
371 | OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) | 366 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
372 | :ONetworkInterface( name ), _hopper( 0 ) | 367 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
373 | { | 368 | { |
@@ -392,31 +387,5 @@ void OWirelessNetworkInterface::init() | |||
392 | qDebug( "OWirelessNetworkInterface::init()" ); | 387 | qDebug( "OWirelessNetworkInterface::init()" ); |
393 | |||
394 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 388 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
395 | 389 | buildChannelList(); | |
396 | // IEEE802.11(b) radio frequency channels | 390 | buildPrivateList(); |
397 | |||
398 | iwrangestruct range; | ||
399 | //ML: work around an ugly HostAP bug, which needs | ||
400 | //ML: extra space or will complain with "invalid argument length"... :-( | ||
401 | //ML: But don't allocate too much or prism2_usb will segfault *sigh* | ||
402 | char __extraBufferForBuggyDrivers[20]; | ||
403 | |||
404 | qDebug( "sizeof(iwrangestruct)=%d, sizeof range=%d, sizeof range*2=%d", sizeof(iwrangestruct), sizeof range, (sizeof range)*2 ); | ||
405 | |||
406 | _iwr.u.data.pointer = (char*) ⦥ | ||
407 | _iwr.u.data.length = sizeof(iwrangestruct)+20; | ||
408 | _iwr.u.data.flags = 0; | ||
409 | if ( !wioctl( SIOCGIWRANGE ) ) | ||
410 | { | ||
411 | qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); | ||
412 | return; | ||
413 | } | ||
414 | |||
415 | qDebug( "OWirelessNetworkInterface::init(): Interface %s reported to have %d channels.", (const char*) _name, range.num_frequency ); | ||
416 | |||
417 | for ( int i = 0; i < range.num_frequency; ++i ) | ||
418 | { | ||
419 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | ||
420 | _channels.insert( freq, i+1 ); | ||
421 | } | ||
422 | } | 391 | } |
@@ -447,2 +416,69 @@ QString OWirelessNetworkInterface::associatedAP() const | |||
447 | 416 | ||
417 | void OWirelessNetworkInterface::buildChannelList() | ||
418 | { | ||
419 | // IEEE802.11(b) radio frequency channels | ||
420 | struct iw_range range; | ||
421 | |||
422 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | ||
423 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | ||
424 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | ||
425 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | ||
426 | //ML: _too much_ space. This is damn shitty crap *sigh* | ||
427 | |||
428 | _iwr.u.data.pointer = (char*) ⦥ | ||
429 | _iwr.u.data.length = IW_MAX_FREQUENCIES; //sizeof range; | ||
430 | _iwr.u.data.flags = 0; | ||
431 | |||
432 | if ( !wioctl( SIOCGIWRANGE ) ) | ||
433 | { | ||
434 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); | ||
435 | _channels.insert( 2412, 1 ); // 2.412 GHz | ||
436 | _channels.insert( 2417, 2 ); // 2.417 GHz | ||
437 | _channels.insert( 2422, 3 ); // 2.422 GHz | ||
438 | _channels.insert( 2427, 4 ); // 2.427 GHz | ||
439 | _channels.insert( 2432, 5 ); // 2.432 GHz | ||
440 | _channels.insert( 2437, 6 ); // 2.437 GHz | ||
441 | _channels.insert( 2442, 7 ); // 2.442 GHz | ||
442 | _channels.insert( 2447, 8 ); // 2.447 GHz | ||
443 | _channels.insert( 2452, 9 ); // 2.452 GHz | ||
444 | _channels.insert( 2457, 10 ); // 2.457 GHz | ||
445 | _channels.insert( 2462, 11 ); // 2.462 GHz | ||
446 | } | ||
447 | else | ||
448 | { | ||
449 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | ||
450 | for ( int i = 0; i < range.num_frequency; ++i ) | ||
451 | { | ||
452 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | ||
453 | _channels.insert( freq, i+1 ); | ||
454 | } | ||
455 | } | ||
456 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); | ||
457 | } | ||
458 | |||
459 | |||
460 | void OWirelessNetworkInterface::buildPrivateList() | ||
461 | { | ||
462 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | ||
463 | |||
464 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | ||
465 | |||
466 | _iwr.u.data.pointer = (char*) &priv; | ||
467 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | ||
468 | _iwr.u.data.flags = 0; | ||
469 | |||
470 | if ( !wioctl( SIOCGIWPRIV ) ) | ||
471 | { | ||
472 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); | ||
473 | return; | ||
474 | } | ||
475 | |||
476 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | ||
477 | { | ||
478 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | ||
479 | } | ||
480 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); | ||
481 | } | ||
482 | |||
483 | |||
448 | int OWirelessNetworkInterface::channel() const | 484 | int OWirelessNetworkInterface::channel() const |
@@ -506,2 +542,3 @@ void OWirelessNetworkInterface::setChannelHopping( int interval ) | |||
506 | //FIXME: When and by whom will the channel hopper be deleted? | 542 | //FIXME: When and by whom will the channel hopper be deleted? |
543 | //TODO: rely on QObject hierarchy | ||
507 | } | 544 | } |
@@ -584,3 +621,3 @@ bool OWirelessNetworkInterface::wioctl( int call ) const | |||
584 | { | 621 | { |
585 | strcpy( _iwr.ifr_name, (const char*) _name ); | 622 | strcpy( _iwr.ifr_name, name() ); |
586 | return wioctl( call, _iwr ); | 623 | return wioctl( call, _iwr ); |