-rw-r--r-- | libopie2/opienet/onetwork.cpp | 128 |
1 files changed, 68 insertions, 60 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 6a9280f..d918193 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -29,12 +29,13 @@ | |||
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | 32 | ||
33 | #include <opie2/onetwork.h> | 33 | #include <opie2/onetwork.h> |
34 | #include <opie2/ostation.h> | 34 | #include <opie2/ostation.h> |
35 | #include <opie2/odebug.h> | ||
35 | 36 | ||
36 | /* QT */ | 37 | /* QT */ |
37 | 38 | ||
38 | #include <qfile.h> | 39 | #include <qfile.h> |
39 | #include <qtextstream.h> | 40 | #include <qtextstream.h> |
40 | 41 | ||
@@ -64,14 +65,14 @@ DebugMapper* debugmapper = new DebugMapper(); | |||
64 | *======================================================================================*/ | 65 | *======================================================================================*/ |
65 | 66 | ||
66 | ONetwork* ONetwork::_instance = 0; | 67 | ONetwork* ONetwork::_instance = 0; |
67 | 68 | ||
68 | ONetwork::ONetwork() | 69 | ONetwork::ONetwork() |
69 | { | 70 | { |
70 | qDebug( "ONetwork::ONetwork()" ); | 71 | odebug << "ONetwork::ONetwork()" << oendl; |
71 | qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT ); | 72 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; |
72 | synchronize(); | 73 | synchronize(); |
73 | } | 74 | } |
74 | 75 | ||
75 | void ONetwork::synchronize() | 76 | void ONetwork::synchronize() |
76 | { | 77 | { |
77 | // gather available interfaces by inspecting /proc/net/dev | 78 | // gather available interfaces by inspecting /proc/net/dev |
@@ -82,28 +83,28 @@ void ONetwork::synchronize() | |||
82 | _interfaces.clear(); | 83 | _interfaces.clear(); |
83 | QString str; | 84 | QString str; |
84 | QFile f( "/proc/net/dev" ); | 85 | QFile f( "/proc/net/dev" ); |
85 | bool hasFile = f.open( IO_ReadOnly ); | 86 | bool hasFile = f.open( IO_ReadOnly ); |
86 | if ( !hasFile ) | 87 | if ( !hasFile ) |
87 | { | 88 | { |
88 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); | 89 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; |
89 | return; | 90 | return; |
90 | } | 91 | } |
91 | QTextStream s( &f ); | 92 | QTextStream s( &f ); |
92 | s.readLine(); | 93 | s.readLine(); |
93 | s.readLine(); | 94 | s.readLine(); |
94 | while ( !s.atEnd() ) | 95 | while ( !s.atEnd() ) |
95 | { | 96 | { |
96 | s >> str; | 97 | s >> str; |
97 | str.truncate( str.find( ':' ) ); | 98 | str.truncate( str.find( ':' ) ); |
98 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); | 99 | odebug << "ONetwork: found interface '" << str << "'" << oendl; |
99 | ONetworkInterface* iface; | 100 | ONetworkInterface* iface; |
100 | if ( isWirelessInterface( str ) ) | 101 | if ( isWirelessInterface( str ) ) |
101 | { | 102 | { |
102 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 103 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
103 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 104 | odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; |
104 | } | 105 | } |
105 | else | 106 | else |
106 | { | 107 | { |
107 | iface = new ONetworkInterface( this, (const char*) str ); | 108 | iface = new ONetworkInterface( this, (const char*) str ); |
108 | } | 109 | } |
109 | _interfaces.insert( str, iface ); | 110 | _interfaces.insert( str, iface ); |
@@ -158,45 +159,47 @@ bool ONetwork::isWirelessInterface( const char* name ) const | |||
158 | *======================================================================================*/ | 159 | *======================================================================================*/ |
159 | 160 | ||
160 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 161 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
161 | :QObject( parent, name ), | 162 | :QObject( parent, name ), |
162 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 163 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
163 | { | 164 | { |
164 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 165 | odebug << "ONetworkInterface::ONetworkInterface()" << oendl; |
165 | init(); | 166 | init(); |
166 | } | 167 | } |
167 | 168 | ||
168 | 169 | ||
169 | struct ifreq& ONetworkInterface::ifr() const | 170 | struct ifreq& ONetworkInterface::ifr() const |
170 | { | 171 | { |
171 | return _ifr; | 172 | return _ifr; |
172 | } | 173 | } |
173 | 174 | ||
174 | 175 | ||
175 | void ONetworkInterface::init() | 176 | void ONetworkInterface::init() |
176 | { | 177 | { |
177 | qDebug( "ONetworkInterface::init()" ); | 178 | odebug << "ONetworkInterface::init()" << oendl; |
178 | 179 | ||
179 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 180 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
180 | 181 | ||
181 | if ( _sfd == -1 ) | 182 | if ( _sfd == -1 ) |
182 | { | 183 | { |
183 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); | 184 | odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; |
184 | return; | 185 | return; |
185 | } | 186 | } |
186 | } | 187 | } |
187 | 188 | ||
188 | 189 | ||
189 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 190 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
190 | { | 191 | { |
191 | #ifndef NODEBUG | 192 | #ifndef NODEBUG |
192 | int result = ::ioctl( _sfd, call, &ifreq ); | 193 | int result = ::ioctl( _sfd, call, &ifreq ); |
193 | if ( result == -1 ) | 194 | if ( result == -1 ) |
194 | qDebug( "ONetworkInterface::ioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) debugmapper->map( call ), call, result, strerror( errno ) ); | 195 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) |
196 | << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; | ||
195 | else | 197 | else |
196 | qDebug( "ONetworkInterface::ioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) debugmapper->map( call ), call ); | 198 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) |
199 | << "' - Status: Ok." << oendl; | ||
197 | return ( result != -1 ); | 200 | return ( result != -1 ); |
198 | #else | 201 | #else |
199 | return ::ioctl( _sfd, call, &ifreq ) != -1; | 202 | return ::ioctl( _sfd, call, &ifreq ) != -1; |
200 | #endif | 203 | #endif |
201 | } | 204 | } |
202 | 205 | ||
@@ -312,25 +315,25 @@ int ONetworkInterface::dataLinkType() const | |||
312 | } | 315 | } |
313 | 316 | ||
314 | 317 | ||
315 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 318 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
316 | { | 319 | { |
317 | _mon = m; | 320 | _mon = m; |
318 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); | 321 | odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl; |
319 | } | 322 | } |
320 | 323 | ||
321 | 324 | ||
322 | OMonitoringInterface* ONetworkInterface::monitoring() const | 325 | OMonitoringInterface* ONetworkInterface::monitoring() const |
323 | { | 326 | { |
324 | return _mon; | 327 | return _mon; |
325 | } | 328 | } |
326 | 329 | ||
327 | 330 | ||
328 | ONetworkInterface::~ONetworkInterface() | 331 | ONetworkInterface::~ONetworkInterface() |
329 | { | 332 | { |
330 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); | 333 | odebug << "ONetworkInterface::~ONetworkInterface()" << oendl; |
331 | if ( _sfd != -1 ) ::close( _sfd ); | 334 | if ( _sfd != -1 ) ::close( _sfd ); |
332 | } | 335 | } |
333 | 336 | ||
334 | 337 | ||
335 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 338 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
336 | { | 339 | { |
@@ -401,14 +404,13 @@ int OChannelHopper::channel() const | |||
401 | 404 | ||
402 | 405 | ||
403 | void OChannelHopper::timerEvent( QTimerEvent* ) | 406 | void OChannelHopper::timerEvent( QTimerEvent* ) |
404 | { | 407 | { |
405 | _iface->setChannel( *_channel ); | 408 | _iface->setChannel( *_channel ); |
406 | emit( hopped( *_channel ) ); | 409 | emit( hopped( *_channel ) ); |
407 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 410 | odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl; |
408 | *_channel, (const char*) _iface->name() ); | ||
409 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 411 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
410 | } | 412 | } |
411 | 413 | ||
412 | 414 | ||
413 | void OChannelHopper::setInterval( int interval ) | 415 | void OChannelHopper::setInterval( int interval ) |
414 | { | 416 | { |
@@ -438,13 +440,13 @@ int OChannelHopper::interval() const | |||
438 | * OWirelessNetworkInterface | 440 | * OWirelessNetworkInterface |
439 | *======================================================================================*/ | 441 | *======================================================================================*/ |
440 | 442 | ||
441 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 443 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
442 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 444 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
443 | { | 445 | { |
444 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 446 | odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl; |
445 | init(); | 447 | init(); |
446 | } | 448 | } |
447 | 449 | ||
448 | 450 | ||
449 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 451 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
450 | { | 452 | { |
@@ -456,13 +458,13 @@ struct iwreq& OWirelessNetworkInterface::iwr() const | |||
456 | return _iwr; | 458 | return _iwr; |
457 | } | 459 | } |
458 | 460 | ||
459 | 461 | ||
460 | void OWirelessNetworkInterface::init() | 462 | void OWirelessNetworkInterface::init() |
461 | { | 463 | { |
462 | qDebug( "OWirelessNetworkInterface::init()" ); | 464 | odebug << "OWirelessNetworkInterface::init()" << oendl; |
463 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 465 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
464 | buildInformation(); | 466 | buildInformation(); |
465 | buildPrivateList(); | 467 | buildPrivateList(); |
466 | dumpInformation(); | 468 | dumpInformation(); |
467 | } | 469 | } |
468 | 470 | ||
@@ -503,13 +505,13 @@ void OWirelessNetworkInterface::buildInformation() | |||
503 | wrq.u.data.pointer = (caddr_t) buffer; | 505 | wrq.u.data.pointer = (caddr_t) buffer; |
504 | wrq.u.data.length = sizeof( struct iw_range ); | 506 | wrq.u.data.length = sizeof( struct iw_range ); |
505 | wrq.u.data.flags = 0; | 507 | wrq.u.data.flags = 0; |
506 | 508 | ||
507 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 509 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
508 | { | 510 | { |
509 | qDebug( "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (%s) - using default values.", strerror( errno ) ); | 511 | owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl; |
510 | _channels.insert( 2412, 1 ); // 2.412 GHz | 512 | _channels.insert( 2412, 1 ); // 2.412 GHz |
511 | _channels.insert( 2417, 2 ); // 2.417 GHz | 513 | _channels.insert( 2417, 2 ); // 2.417 GHz |
512 | _channels.insert( 2422, 3 ); // 2.422 GHz | 514 | _channels.insert( 2422, 3 ); // 2.422 GHz |
513 | _channels.insert( 2427, 4 ); // 2.427 GHz | 515 | _channels.insert( 2427, 4 ); // 2.427 GHz |
514 | _channels.insert( 2432, 5 ); // 2.432 GHz | 516 | _channels.insert( 2432, 5 ); // 2.432 GHz |
515 | _channels.insert( 2437, 6 ); // 2.437 GHz | 517 | _channels.insert( 2437, 6 ); // 2.437 GHz |
@@ -527,66 +529,66 @@ void OWirelessNetworkInterface::buildInformation() | |||
527 | int max = 0; | 529 | int max = 0; |
528 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 530 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
529 | if (buffer[r] != 0) | 531 | if (buffer[r] != 0) |
530 | max = r; | 532 | max = r; |
531 | if (max > 0) | 533 | if (max > 0) |
532 | { | 534 | { |
533 | qWarning( "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '%s' sucks!\n" | 535 | owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() |
534 | "It overwrote the buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); | 536 | << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; |
535 | } | 537 | } |
536 | // </check if the driver overwrites stuff> | 538 | // </check if the driver overwrites stuff> |
537 | 539 | ||
538 | struct iw_range range; | 540 | struct iw_range range; |
539 | memcpy( &range, buffer, sizeof range ); | 541 | memcpy( &range, buffer, sizeof range ); |
540 | 542 | ||
541 | qDebug( "OWirelessNetworkInterface::buildInformation(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | 543 | odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; |
542 | for ( int i = 0; i < range.num_frequency; ++i ) | 544 | for ( int i = 0; i < range.num_frequency; ++i ) |
543 | { | 545 | { |
544 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 546 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
545 | _channels.insert( freq, i+1 ); | 547 | _channels.insert( freq, i+1 ); |
546 | } | 548 | } |
547 | } | 549 | } |
548 | 550 | ||
549 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); | 551 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); |
550 | qDebug( "OWirelessNetworkInterface::buildInformation(): Information block constructed." ); | 552 | odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; |
551 | free(buffer); | 553 | free(buffer); |
552 | } | 554 | } |
553 | 555 | ||
554 | 556 | ||
555 | void OWirelessNetworkInterface::buildPrivateList() | 557 | void OWirelessNetworkInterface::buildPrivateList() |
556 | { | 558 | { |
557 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | 559 | odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; |
558 | 560 | ||
559 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 561 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
560 | 562 | ||
561 | _iwr.u.data.pointer = (char*) &priv; | 563 | _iwr.u.data.pointer = (char*) &priv; |
562 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | 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 |
563 | _iwr.u.data.flags = 0; | 565 | _iwr.u.data.flags = 0; |
564 | 566 | ||
565 | if ( !wioctl( SIOCGIWPRIV ) ) | 567 | if ( !wioctl( SIOCGIWPRIV ) ) |
566 | { | 568 | { |
567 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); | 569 | owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; |
568 | return; | 570 | return; |
569 | } | 571 | } |
570 | 572 | ||
571 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 573 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
572 | { | 574 | { |
573 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 575 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
574 | } | 576 | } |
575 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); | 577 | odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; |
576 | } | 578 | } |
577 | 579 | ||
578 | 580 | ||
579 | void OWirelessNetworkInterface::dumpInformation() const | 581 | void OWirelessNetworkInterface::dumpInformation() const |
580 | { | 582 | { |
581 | qDebug( "OWirelessNetworkInterface::() -------------- dumping information block ----------------" ); | 583 | odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; |
582 | 584 | ||
583 | 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 ); | 585 | 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 ); |
584 | qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source ); | 586 | qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source ); |
585 | 587 | ||
586 | qDebug( "OWirelessNetworkInterface::() ---------------------------------------------------------" ); | 588 | odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; |
587 | } | 589 | } |
588 | 590 | ||
589 | 591 | ||
590 | int OWirelessNetworkInterface::channel() const | 592 | int OWirelessNetworkInterface::channel() const |
591 | { | 593 | { |
592 | //FIXME: When monitoring enabled, then use it | 594 | //FIXME: When monitoring enabled, then use it |
@@ -607,13 +609,13 @@ int OWirelessNetworkInterface::channel() const | |||
607 | 609 | ||
608 | 610 | ||
609 | void OWirelessNetworkInterface::setChannel( int c ) const | 611 | void OWirelessNetworkInterface::setChannel( int c ) const |
610 | { | 612 | { |
611 | if ( !c ) | 613 | if ( !c ) |
612 | { | 614 | { |
613 | qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" ); | 615 | oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl; |
614 | return; | 616 | return; |
615 | } | 617 | } |
616 | 618 | ||
617 | if ( !_mon ) | 619 | if ( !_mon ) |
618 | { | 620 | { |
619 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 621 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
@@ -678,13 +680,13 @@ void OWirelessNetworkInterface::setMode( const QString& newMode ) | |||
678 | { | 680 | { |
679 | #ifdef FINALIZE | 681 | #ifdef FINALIZE |
680 | QString currentMode = mode(); | 682 | QString currentMode = mode(); |
681 | if ( currentMode == newMode ) return; | 683 | if ( currentMode == newMode ) return; |
682 | #endif | 684 | #endif |
683 | 685 | ||
684 | qDebug( "OWirelessNetworkInterface::setMode(): trying to set mode '%s' (%d)", (const char*) newMode, stringToMode( newMode ) ); | 686 | odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl; |
685 | 687 | ||
686 | _iwr.u.mode = stringToMode( newMode ); | 688 | _iwr.u.mode = stringToMode( newMode ); |
687 | 689 | ||
688 | if ( _iwr.u.mode != IW_MODE_MONITOR ) | 690 | if ( _iwr.u.mode != IW_MODE_MONITOR ) |
689 | { | 691 | { |
690 | // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! | 692 | // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! |
@@ -692,34 +694,34 @@ void OWirelessNetworkInterface::setMode( const QString& newMode ) | |||
692 | wioctl( SIOCSIWMODE ); | 694 | wioctl( SIOCSIWMODE ); |
693 | 695 | ||
694 | // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) | 696 | // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) |
695 | 697 | ||
696 | if ( mode() == "monitor" ) | 698 | if ( mode() == "monitor" ) |
697 | { | 699 | { |
698 | qDebug( "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." ); | 700 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl; |
699 | if ( _mon ) | 701 | if ( _mon ) |
700 | _mon->setEnabled( false ); | 702 | _mon->setEnabled( false ); |
701 | else | 703 | else |
702 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 704 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; |
703 | } | 705 | } |
704 | 706 | ||
705 | } | 707 | } |
706 | else // special iwpriv fallback for monitor mode | 708 | else // special iwpriv fallback for monitor mode |
707 | { | 709 | { |
708 | if ( wioctl( SIOCSIWMODE ) ) | 710 | if ( wioctl( SIOCSIWMODE ) ) |
709 | { | 711 | { |
710 | qDebug( "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" ); | 712 | odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl; |
711 | } | 713 | } |
712 | else | 714 | else |
713 | { | 715 | { |
714 | qDebug( "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." ); | 716 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl; |
715 | 717 | ||
716 | if ( _mon ) | 718 | if ( _mon ) |
717 | _mon->setEnabled( true ); | 719 | _mon->setEnabled( true ); |
718 | else | 720 | else |
719 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 721 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; |
720 | } | 722 | } |
721 | } | 723 | } |
722 | } | 724 | } |
723 | 725 | ||
724 | 726 | ||
725 | QString OWirelessNetworkInterface::mode() const | 727 | QString OWirelessNetworkInterface::mode() const |
@@ -728,13 +730,13 @@ QString OWirelessNetworkInterface::mode() const | |||
728 | 730 | ||
729 | if ( !wioctl( SIOCGIWMODE ) ) | 731 | if ( !wioctl( SIOCGIWMODE ) ) |
730 | { | 732 | { |
731 | return "<unknown>"; | 733 | return "<unknown>"; |
732 | } | 734 | } |
733 | 735 | ||
734 | qDebug( "DEBUG: WE's idea of current mode seems to be '%s'", (const char*) modeToString( _iwr.u.mode ) ); | 736 | odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl; |
735 | 737 | ||
736 | // legacy compatible monitor mode check | 738 | // legacy compatible monitor mode check |
737 | 739 | ||
738 | if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) | 740 | if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) |
739 | { | 741 | { |
740 | return "monitor"; | 742 | return "monitor"; |
@@ -772,22 +774,24 @@ QString OWirelessNetworkInterface::nickName() const | |||
772 | 774 | ||
773 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 775 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
774 | { | 776 | { |
775 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 777 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
776 | if ( !priv ) | 778 | if ( !priv ) |
777 | { | 779 | { |
778 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); | 780 | owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name() |
781 | << "' does not support private ioctl '" << call << "'" << oendl; | ||
779 | return; | 782 | return; |
780 | } | 783 | } |
781 | if ( priv->numberSetArgs() != numargs ) | 784 | if ( priv->numberSetArgs() != numargs ) |
782 | { | 785 | { |
783 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); | 786 | owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '" |
787 | << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl; | ||
784 | return; | 788 | return; |
785 | } | 789 | } |
786 | 790 | ||
787 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); | 791 | odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl; |
788 | memset( &_iwr, 0, sizeof _iwr ); | 792 | memset( &_iwr, 0, sizeof _iwr ); |
789 | va_list argp; | 793 | va_list argp; |
790 | va_start( argp, numargs ); | 794 | va_start( argp, numargs ); |
791 | for ( int i = 0; i < numargs; ++i ) | 795 | for ( int i = 0; i < numargs; ++i ) |
792 | { | 796 | { |
793 | priv->setParameter( i, va_arg( argp, int ) ); | 797 | priv->setParameter( i, va_arg( argp, int ) ); |
@@ -796,13 +800,13 @@ void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, .. | |||
796 | priv->invoke(); | 800 | priv->invoke(); |
797 | } | 801 | } |
798 | 802 | ||
799 | 803 | ||
800 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 804 | void OWirelessNetworkInterface::getPrivate( const QString& call ) |
801 | { | 805 | { |
802 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); | 806 | oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl; |
803 | } | 807 | } |
804 | 808 | ||
805 | 809 | ||
806 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | 810 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) |
807 | { | 811 | { |
808 | return child( (const char*) call ); | 812 | return child( (const char*) call ); |
@@ -843,13 +847,13 @@ OStationList* OWirelessNetworkInterface::scanNetwork() | |||
843 | } | 847 | } |
844 | 848 | ||
845 | OStationList* stations = new OStationList(); | 849 | OStationList* stations = new OStationList(); |
846 | 850 | ||
847 | int timeout = 1000000; | 851 | int timeout = 1000000; |
848 | 852 | ||
849 | qDebug( "ONetworkInterface::scanNetwork() - scan started." ); | 853 | odebug << "ONetworkInterface::scanNetwork() - scan started." << oendl; |
850 | 854 | ||
851 | bool results = false; | 855 | bool results = false; |
852 | struct timeval tv; | 856 | struct timeval tv; |
853 | tv.tv_sec = 0; | 857 | tv.tv_sec = 0; |
854 | tv.tv_usec = 250000; // initial timeout ~ 250ms | 858 | tv.tv_usec = 250000; // initial timeout ~ 250ms |
855 | char buffer[IW_SCAN_MAX_DATA]; | 859 | char buffer[IW_SCAN_MAX_DATA]; |
@@ -866,13 +870,13 @@ OStationList* OWirelessNetworkInterface::scanNetwork() | |||
866 | { | 870 | { |
867 | results = true; | 871 | results = true; |
868 | continue; | 872 | continue; |
869 | } | 873 | } |
870 | else if ( errno == EAGAIN) | 874 | else if ( errno == EAGAIN) |
871 | { | 875 | { |
872 | qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." ); | 876 | odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl; |
873 | #if 0 | 877 | #if 0 |
874 | if ( qApp ) | 878 | if ( qApp ) |
875 | { | 879 | { |
876 | qApp->processEvents( 100 ); | 880 | qApp->processEvents( 100 ); |
877 | continue; | 881 | continue; |
878 | } | 882 | } |
@@ -880,97 +884,101 @@ OStationList* OWirelessNetworkInterface::scanNetwork() | |||
880 | tv.tv_sec = 0; | 884 | tv.tv_sec = 0; |
881 | tv.tv_usec = 100000; | 885 | tv.tv_usec = 100000; |
882 | continue; | 886 | continue; |
883 | } | 887 | } |
884 | } | 888 | } |
885 | 889 | ||
886 | qDebug( "ONetworkInterface::scanNetwork() - scan finished." ); | 890 | odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; |
887 | 891 | ||
888 | if ( results ) | 892 | if ( results ) |
889 | { | 893 | { |
890 | qDebug( " - result length = %d", _iwr.u.data.length ); | 894 | odebug << " - result length = " << _iwr.u.data.length << oendl; |
891 | if ( !_iwr.u.data.length ) | 895 | if ( !_iwr.u.data.length ) |
892 | { | 896 | { |
893 | qDebug( " - no results (empty neighbourhood)" ); | 897 | odebug << " - no results (empty neighbourhood)" << oendl; |
894 | return stations; | 898 | return stations; |
895 | } | 899 | } |
896 | 900 | ||
897 | qDebug( " - results are in!" ); | 901 | odebug << " - results are in!" << oendl; |
898 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); | 902 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); |
899 | 903 | ||
900 | // parse results | 904 | // parse results |
901 | 905 | ||
902 | int offset = 0; | 906 | int offset = 0; |
903 | struct iw_event* we = (struct iw_event*) &buffer[0]; | 907 | struct iw_event* we = (struct iw_event*) &buffer[0]; |
904 | 908 | ||
905 | while ( offset < _iwr.u.data.length ) | 909 | while ( offset < _iwr.u.data.length ) |
906 | { | 910 | { |
907 | //const char* cmd = *(*_ioctlmap)[we->cmd]; | 911 | //const char* cmd = *(*_ioctlmap)[we->cmd]; |
908 | //if ( !cmd ) cmd = "<unknown>"; | 912 | //if ( !cmd ) cmd = "<unknown>"; |
909 | qDebug( "reading next event... cmd=%d, len=%d", we->cmd, we->len ); | 913 | odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl; |
910 | switch (we->cmd) | 914 | switch (we->cmd) |
911 | { | 915 | { |
912 | case SIOCGIWAP: | 916 | case SIOCGIWAP: |
913 | { | 917 | { |
914 | qDebug( "SIOCGIWAP" ); | 918 | odebug << "SIOCGIWAP" << oendl; |
915 | stations->append( new OStation() ); | 919 | stations->append( new OStation() ); |
916 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; | 920 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; |
917 | break; | 921 | break; |
918 | } | 922 | } |
919 | case SIOCGIWMODE: | 923 | case SIOCGIWMODE: |
920 | { | 924 | { |
921 | qDebug( "SIOCGIWMODE" ); | 925 | odebug << "SIOCGIWMODE" << oendl; |
922 | stations->last()->type = modeToString( we->u.mode ); | 926 | stations->last()->type = modeToString( we->u.mode ); |
923 | break; | 927 | break; |
924 | } | 928 | } |
925 | case SIOCGIWFREQ: | 929 | case SIOCGIWFREQ: |
926 | { | 930 | { |
927 | qDebug( "SIOCGIWFREQ" ); | 931 | odebug << "SIOCGIWFREQ" << oendl; |
928 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; | 932 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; |
929 | break; | 933 | break; |
930 | } | 934 | } |
931 | case SIOCGIWESSID: | 935 | case SIOCGIWESSID: |
932 | { | 936 | { |
933 | qDebug( "SIOCGIWESSID" ); | 937 | odebug << "SIOCGIWESSID" << oendl; |
934 | stations->last()->ssid = we->u.essid.pointer; | 938 | stations->last()->ssid = we->u.essid.pointer; |
935 | break; | 939 | break; |
936 | } | 940 | } |
937 | case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break; | 941 | case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; |
938 | case SIOCGIWENCODE: qDebug( "SIOCGIWENCODE" ); break; | 942 | case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break; |
939 | case IWEVTXDROP: qDebug( "IWEVTXDROP" ); break; /* Packet dropped to excessive retry */ | 943 | case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ |
940 | case IWEVQUAL: qDebug( "IWEVQUAL" ); break; /* Quality part of statistics (scan) */ | 944 | case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */ |
941 | case IWEVCUSTOM: qDebug( "IWEVCUSTOM" ); break; /* Driver specific ascii string */ | 945 | case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ |
942 | case IWEVREGISTERED: qDebug( "IWEVREGISTERED" ); break; /* Discovered a new node (AP mode) */ | 946 | case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ |
943 | case IWEVEXPIRED: qDebug( "IWEVEXPIRED" ); break; /* Expired a node (AP mode) */ | 947 | case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ |
944 | default: qDebug( "unhandled event" ); | 948 | default: odebug << "unhandled event" << oendl; |
945 | } | 949 | } |
946 | 950 | ||
947 | offset += we->len; | 951 | offset += we->len; |
948 | we = (struct iw_event*) &buffer[offset]; | 952 | we = (struct iw_event*) &buffer[offset]; |
949 | } | 953 | } |
950 | return stations; | 954 | return stations; |
951 | 955 | ||
952 | return stations; | 956 | return stations; |
953 | 957 | ||
954 | } | 958 | } |
955 | else | 959 | else |
956 | { | 960 | { |
957 | qDebug( " - no results (timeout) :(" ); | 961 | odebug << " - no results (timeout) :(" << oendl; |
958 | return stations; | 962 | return stations; |
959 | } | 963 | } |
960 | } | 964 | } |
961 | 965 | ||
962 | 966 | ||
963 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 967 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
964 | { | 968 | { |
965 | #ifndef NODEBUG | 969 | #ifndef NODEBUG |
966 | int result = ::ioctl( _sfd, call, &iwreq ); | 970 | int result = ::ioctl( _sfd, call, &iwreq ); |
971 | |||
967 | if ( result == -1 ) | 972 | if ( result == -1 ) |
968 | qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) debugmapper->map( call ), call, result, strerror( errno ) ); | 973 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
974 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; | ||
969 | else | 975 | else |
970 | qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) debugmapper->map( call ), call ); | 976 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
977 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; | ||
978 | |||
971 | return ( result != -1 ); | 979 | return ( result != -1 ); |
972 | #else | 980 | #else |
973 | return ::ioctl( _sfd, call, &iwreq ) != -1; | 981 | return ::ioctl( _sfd, call, &iwreq ) != -1; |
974 | #endif | 982 | #endif |
975 | } | 983 | } |
976 | 984 | ||