summaryrefslogtreecommitdiff
path: root/libopie2
Unidiff
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opiecore/odebugdemo/odebugdemo.pro3
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp37
-rw-r--r--libopie2/opienet/onetwork.cpp106
-rw-r--r--libopie2/opienet/onetwork.h16
4 files changed, 107 insertions, 55 deletions
diff --git a/libopie2/examples/opiecore/odebugdemo/odebugdemo.pro b/libopie2/examples/opiecore/odebugdemo/odebugdemo.pro
index c52cd02..aa37394 100644
--- a/libopie2/examples/opiecore/odebugdemo/odebugdemo.pro
+++ b/libopie2/examples/opiecore/odebugdemo/odebugdemo.pro
@@ -1,19 +1,20 @@
1TEMPLATE = app 1TEMPLATE = app
2CONFIG = qt warn_on debug 2CONFIG = qt warn_on debug
3HEADERS = 3HEADERS =
4SOURCES = odebugdemo.cpp 4SOURCES = odebugdemo.cpp
5INCLUDEPATH += $(OPIEDIR)/include 5INCLUDEPATH += $(OPIEDIR)/include
6DEPENDPATH += $(OPIEDIR)/include 6DEPENDPATH += $(OPIEDIR)/include
7LIBS += -lopiecore2 7LIBS += -lopiecore2
8TARGET = odebugdemo 8TARGET = odebugdemo
9 9
10MOC_DIR = moc
11OBJECTS_DIR = obj 10OBJECTS_DIR = obj
12 11
13!contains( platform, x11 ) { 12!contains( platform, x11 ) {
14 include ( $(OPIEDIR)/include.pro ) 13 include ( $(OPIEDIR)/include.pro )
15} 14}
16 15
17contains( platform, x11 ) { 16contains( platform, x11 ) {
18 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib 17 LIBS += -L$(OPIEDIR)/lib -Wl,-rpath,$(OPIEDIR)/lib
19} 18}
19
20MOC_DIR = moc
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
index 21026e1..06b8b19 100644
--- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -1,107 +1,142 @@
1#include <opie2/onetwork.h> 1#include <opie2/onetwork.h>
2#include <opie2/ostation.h> 2#include <opie2/ostation.h>
3#include <opie2/omanufacturerdb.h> 3#include <opie2/omanufacturerdb.h>
4 4
5#include <unistd.h>
6
5int main( int argc, char** argv ) 7int main( int argc, char** argv )
6{ 8{
7 qDebug( "OPIE Network Demo" ); 9 qDebug( "OPIE Network Demo" );
8 10
9 ONetwork* net = ONetwork::instance(); 11 ONetwork* net = ONetwork::instance();
10 12
11 ONetwork::InterfaceIterator it = net->iterator(); 13 ONetwork::InterfaceIterator it = net->iterator();
12 14
13 while ( it.current() ) 15 while ( it.current() )
14 { 16 {
15 qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() ); 17 qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() );
18 qDebug( "DEMO: Datalink code is '%d'", it.current()->dataLinkType() );
16 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() ); 19 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() );
17 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) ); 20 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString(true) );
18 qDebug( "DEMO: MAC Manufacturer seems to be '%s'", (const char*) it.current()->macAddress().manufacturer() ); 21 qDebug( "DEMO: MAC Manufacturer seems to be '%s'", (const char*) it.current()->macAddress().manufacturer() );
19 qDebug( "DEMO: Manufacturertest1 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "08:00:87" ) ); 22 qDebug( "DEMO: Manufacturertest1 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "08:00:87" ) );
20 qDebug( "DEMO: Manufacturertest2 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) ); 23 qDebug( "DEMO: Manufacturertest2 = '%s'", (const char*) OManufacturerDB::instance()->lookupExt( "E2:0C:0F" ) );
21 qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() ); 24 qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() );
22 if ( it.current()->isWireless() ) 25 if ( it.current()->isWireless() )
23 { 26 {
24 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() ); 27 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
25 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() ); 28 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() );
26 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() ); 29 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() );
27 qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() ); 30 qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() );
28 31
29 //if ( iface->mode() == OWirelessNetworkInterface::adhoc ) 32 //if ( iface->mode() == OWirelessNetworkInterface::adhoc )
30 //{ 33 //{
31 qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP().toString() ); 34 //qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP().toString() );
32 //} 35 //}
33 36
37 /*
38
34 // nickname 39 // nickname
35 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() ); 40 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
36 iface->setNickName( "MyNickName" ); 41 iface->setNickName( "MyNickName" );
37 if ( iface->nickName() != "MyNickName" ) 42 if ( iface->nickName() != "MyNickName" )
38 qDebug( "DEMO: Warning! Can't change nickname" ); 43 qDebug( "DEMO: Warning! Can't change nickname" );
39 else 44 else
40 qDebug( "DEMO: Nickname change successful." ); 45 qDebug( "DEMO: Nickname change successful." );
41 46
47 /*
48
42 // operation mode 49 // operation mode
43 qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() ); 50 qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() );
44 iface->setMode( "adhoc" ); 51 iface->setMode( "adhoc" );
45 if ( iface->mode() != "adhoc" ) 52 if ( iface->mode() != "adhoc" )
46 qDebug( "DEMO: Warning! Can't change operation mode" ); 53 qDebug( "DEMO: Warning! Can't change operation mode" );
47 else 54 else
48 qDebug( "DEMO: Operation Mode change successful." ); 55 qDebug( "DEMO: Operation Mode change successful." );
49 56
50 // RF channel 57 // RF channel
51 qDebug( "DEMO: Current Channel is '%d'", iface->channel() ); 58 qDebug( "DEMO: Current Channel is '%d'", iface->channel() );
52 iface->setChannel( 1 ); 59 iface->setChannel( 1 );
53 if ( iface->channel() != 1 ) 60 if ( iface->channel() != 1 )
54 qDebug( "DEMO: Warning! Can't change RF channel" ); 61 qDebug( "DEMO: Warning! Can't change RF channel" );
55 else 62 else
56 qDebug( "DEMO: RF channel change successful." ); 63 qDebug( "DEMO: RF channel change successful." );
57 64
58 iface->setMode( "managed" ); 65 iface->setMode( "managed" );
59 66
67 */
68
69 /*
70
60 // network scan 71 // network scan
61 72
62 OStationList* stations = iface->scanNetwork(); 73 OStationList* stations = iface->scanNetwork();
63 if ( stations ) 74 if ( stations )
64 { 75 {
65 qDebug( "DEMO: # of stations around = %d", stations->count() ); 76 qDebug( "DEMO: # of stations around = %d", stations->count() );
66 OStation* station; 77 OStation* station;
67 for ( station = stations->first(); station != 0; station = stations->next() ) 78 for ( station = stations->first(); station != 0; station = stations->next() )
68 { 79 {
69 qDebug( "DEMO: station dump following..." ); 80 qDebug( "DEMO: station dump following..." );
70 station->dump(); 81 station->dump();
71 } 82 }
72 } 83 }
73 84
74 else 85 else
75 { 86 {
76 qDebug( "DEMO: Warning! Scan didn't work!" ); 87 qDebug( "DEMO: Warning! Scan didn't work!" );
77 } 88 }
78 89
79 /* 90 /*
80 91
81 // first some wrong calls to check if this is working 92 // first some wrong calls to check if this is working
82 iface->setPrivate( "seppel", 10 ); 93 iface->setPrivate( "seppel", 10 );
83 iface->setPrivate( "monitor", 0 ); 94 iface->setPrivate( "monitor", 0 );
84 95
85 // now the real deal 96 // now the real deal
86 iface->setPrivate( "monitor", 2, 2, 3 ); 97 iface->setPrivate( "monitor", 2, 2, 3 );
87 98
88 // trying to set hw address to 12:34:56:AB:CD:EF 99 // trying to set hw address to 12:34:56:AB:CD:EF
89 100
90 /* 101 /*
91 102
92 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" ); 103 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" );
93 iface->setUp( false ); 104 iface->setUp( false );
94 iface->setMacAddress( addr ); 105 iface->setMacAddress( addr );
95 iface->setUp( true ); 106 iface->setUp( true );
96 qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() ); 107 qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() );
97 108
98 */ 109 */
99 110
111 // monitor test
112
113 /*
114
115 qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );
116 iface->setMode( "monitor" );
117 qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );
118
119 sleep( 1 ); */
120
121 iface->setMode( "master" );
122
123 //sleep( 1 );
124 qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );
125
126 /*iface->setMode( "adhoc" );
127 sleep( 1 );
128 qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );
129 iface->setMode( "managed" );
130 sleep( 1 );
131 qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );
132 iface->setMode( "master" );
133 sleep( 1 );
134 qDebug( "DEMO: current interface mode is '%s'", (const char*) iface->mode() );*/
100 135
101 } 136 }
102 ++it; 137 ++it;
103 } 138 }
104 139
105 return 0; 140 return 0;
106 141
107} 142}
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 50c6679..c329e9a 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -420,755 +420,773 @@ void OChannelHopper::setInterval( int interval )
420 if ( interval == _interval ) 420 if ( interval == _interval )
421 return; 421 return;
422 422
423 if ( _interval ) 423 if ( _interval )
424 killTimer( _tid ); 424 killTimer( _tid );
425 425
426 _tid = 0; 426 _tid = 0;
427 _interval = interval; 427 _interval = interval;
428 428
429 if ( _interval ) 429 if ( _interval )
430 { 430 {
431 _tid = startTimer( interval ); 431 _tid = startTimer( interval );
432 } 432 }
433} 433}
434 434
435 435
436int OChannelHopper::interval() const 436int OChannelHopper::interval() const
437{ 437{
438 return _interval; 438 return _interval;
439} 439}
440 440
441 441
442/*====================================================================================== 442/*======================================================================================
443 * OWirelessNetworkInterface 443 * OWirelessNetworkInterface
444 *======================================================================================*/ 444 *======================================================================================*/
445 445
446OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) 446OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name )
447 :ONetworkInterface( parent, name ), _hopper( 0 ) 447 :ONetworkInterface( parent, name ), _hopper( 0 )
448{ 448{
449 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 449 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
450 init(); 450 init();
451} 451}
452 452
453 453
454OWirelessNetworkInterface::~OWirelessNetworkInterface() 454OWirelessNetworkInterface::~OWirelessNetworkInterface()
455{ 455{
456} 456}
457 457
458 458
459struct iwreq& OWirelessNetworkInterface::iwr() const 459struct iwreq& OWirelessNetworkInterface::iwr() const
460{ 460{
461 return _iwr; 461 return _iwr;
462} 462}
463 463
464 464
465void OWirelessNetworkInterface::init() 465void OWirelessNetworkInterface::init()
466{ 466{
467 qDebug( "OWirelessNetworkInterface::init()" ); 467 qDebug( "OWirelessNetworkInterface::init()" );
468 memset( &_iwr, 0, sizeof( struct iwreq ) ); 468 memset( &_iwr, 0, sizeof( struct iwreq ) );
469 buildInformation(); 469 buildInformation();
470 buildPrivateList(); 470 buildPrivateList();
471 dumpInformation(); 471 dumpInformation();
472} 472}
473 473
474 474
475bool OWirelessNetworkInterface::isAssociated() const 475bool OWirelessNetworkInterface::isAssociated() const
476{ 476{
477 //FIXME: handle different modes 477 //FIXME: handle different modes
478 return !(associatedAP() == OMacAddress::unknown); 478 return !(associatedAP() == OMacAddress::unknown);
479} 479}
480 480
481 481
482OMacAddress OWirelessNetworkInterface::associatedAP() const 482OMacAddress OWirelessNetworkInterface::associatedAP() const
483{ 483{
484 if ( ioctl( SIOCGIWAP ) ) 484 if ( ioctl( SIOCGIWAP ) )
485 return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; 485 return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0];
486 else 486 else
487 return OMacAddress::unknown; 487 return OMacAddress::unknown;
488} 488}
489 489
490 490
491void OWirelessNetworkInterface::buildInformation() 491void OWirelessNetworkInterface::buildInformation()
492{ 492{
493 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 493 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
494 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 494 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
495 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 495 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
496 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 496 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
497 //ML: _too much_ space. This is damn shitty crap *sigh* 497 //ML: _too much_ space. This is damn shitty crap *sigh*
498 //ML: We allocate a large memory region in RAM and check whether the 498 //ML: We allocate a large memory region in RAM and check whether the
499 //ML: driver pollutes this extra space. The complaint will be made on stdout, 499 //ML: driver pollutes this extra space. The complaint will be made on stdout,
500 //ML: so please forward this... 500 //ML: so please forward this...
501 501
502 struct iwreq wrq; 502 struct iwreq wrq;
503 int len = sizeof( struct iw_range )*2; 503 int len = sizeof( struct iw_range )*2;
504 char *buffer = (char*) malloc( len ); 504 char *buffer = (char*) malloc( len );
505 //FIXME: Validate if we actually got the memory block 505 //FIXME: Validate if we actually got the memory block
506 memset( buffer, 0, len ); 506 memset( buffer, 0, len );
507 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 507 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
508 wrq.u.data.pointer = (caddr_t) buffer; 508 wrq.u.data.pointer = (caddr_t) buffer;
509 wrq.u.data.length = sizeof( struct iw_range ); 509 wrq.u.data.length = sizeof( struct iw_range );
510 wrq.u.data.flags = 0; 510 wrq.u.data.flags = 0;
511 511
512 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 512 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
513 { 513 {
514 qDebug( "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (%s) - using default values.", strerror( errno ) ); 514 qDebug( "OWirelessNetworkInterface::buildInformation(): SIOCGIWRANGE failed (%s) - using default values.", strerror( errno ) );
515 _channels.insert( 2412, 1 ); // 2.412 GHz 515 _channels.insert( 2412, 1 ); // 2.412 GHz
516 _channels.insert( 2417, 2 ); // 2.417 GHz 516 _channels.insert( 2417, 2 ); // 2.417 GHz
517 _channels.insert( 2422, 3 ); // 2.422 GHz 517 _channels.insert( 2422, 3 ); // 2.422 GHz
518 _channels.insert( 2427, 4 ); // 2.427 GHz 518 _channels.insert( 2427, 4 ); // 2.427 GHz
519 _channels.insert( 2432, 5 ); // 2.432 GHz 519 _channels.insert( 2432, 5 ); // 2.432 GHz
520 _channels.insert( 2437, 6 ); // 2.437 GHz 520 _channels.insert( 2437, 6 ); // 2.437 GHz
521 _channels.insert( 2442, 7 ); // 2.442 GHz 521 _channels.insert( 2442, 7 ); // 2.442 GHz
522 _channels.insert( 2447, 8 ); // 2.447 GHz 522 _channels.insert( 2447, 8 ); // 2.447 GHz
523 _channels.insert( 2452, 9 ); // 2.452 GHz 523 _channels.insert( 2452, 9 ); // 2.452 GHz
524 _channels.insert( 2457, 10 ); // 2.457 GHz 524 _channels.insert( 2457, 10 ); // 2.457 GHz
525 _channels.insert( 2462, 11 ); // 2.462 GHz 525 _channels.insert( 2462, 11 ); // 2.462 GHz
526 526
527 memset( &_range, 0, sizeof( struct iw_range ) ); 527 memset( &_range, 0, sizeof( struct iw_range ) );
528 } 528 }
529 else 529 else
530 { 530 {
531 // <check if the driver overwrites stuff> 531 // <check if the driver overwrites stuff>
532 int max = 0; 532 int max = 0;
533 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 533 for ( int r = sizeof( struct iw_range ); r < len; r++ )
534 if (buffer[r] != 0) 534 if (buffer[r] != 0)
535 max = r; 535 max = r;
536 if (max > 0) 536 if (max > 0)
537 { 537 {
538 qWarning( "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '%s' sucks!\n" 538 qWarning( "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '%s' sucks!\n"
539 "It overwrote the buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); 539 "It overwrote the buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
540 } 540 }
541 // </check if the driver overwrites stuff> 541 // </check if the driver overwrites stuff>
542 542
543 struct iw_range range; 543 struct iw_range range;
544 memcpy( &range, buffer, sizeof range ); 544 memcpy( &range, buffer, sizeof range );
545 545
546 qDebug( "OWirelessNetworkInterface::buildInformation(): Interface %s reported to have %d channels.", name(), range.num_frequency ); 546 qDebug( "OWirelessNetworkInterface::buildInformation(): Interface %s reported to have %d channels.", name(), range.num_frequency );
547 for ( int i = 0; i < range.num_frequency; ++i ) 547 for ( int i = 0; i < range.num_frequency; ++i )
548 { 548 {
549 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 549 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
550 _channels.insert( freq, i+1 ); 550 _channels.insert( freq, i+1 );
551 } 551 }
552 } 552 }
553 553
554 memcpy( &_range, buffer, sizeof( struct iw_range ) ); 554 memcpy( &_range, buffer, sizeof( struct iw_range ) );
555 qDebug( "OWirelessNetworkInterface::buildInformation(): Information block constructed." ); 555 qDebug( "OWirelessNetworkInterface::buildInformation(): Information block constructed." );
556 free(buffer); 556 free(buffer);
557} 557}
558 558
559 559
560void OWirelessNetworkInterface::buildPrivateList() 560void OWirelessNetworkInterface::buildPrivateList()
561{ 561{
562 qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); 562 qDebug( "OWirelessNetworkInterface::buildPrivateList()" );
563 563
564 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 564 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
565 565
566 _iwr.u.data.pointer = (char*) &priv; 566 _iwr.u.data.pointer = (char*) &priv;
567 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 567 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
568 _iwr.u.data.flags = 0; 568 _iwr.u.data.flags = 0;
569 569
570 if ( !wioctl( SIOCGIWPRIV ) ) 570 if ( !wioctl( SIOCGIWPRIV ) )
571 { 571 {
572 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); 572 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) );
573 return; 573 return;
574 } 574 }
575 575
576 for ( int i = 0; i < _iwr.u.data.length; ++i ) 576 for ( int i = 0; i < _iwr.u.data.length; ++i )
577 { 577 {
578 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 578 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
579 } 579 }
580 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); 580 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
581} 581}
582 582
583 583
584void OWirelessNetworkInterface::dumpInformation() const 584void OWirelessNetworkInterface::dumpInformation() const
585{ 585{
586 qDebug( "OWirelessNetworkInterface::() -------------- dumping information block ----------------" ); 586 qDebug( "OWirelessNetworkInterface::() -------------- dumping information block ----------------" );
587 587
588 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 ); 588 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 );
589 qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source ); 589 qDebug( " - driver for '%s' has been compiled against WE V%d (source=V%d)", name(), _range.we_version_compiled, _range.we_version_source );
590 590
591 qDebug( "OWirelessNetworkInterface::() ---------------------------------------------------------" ); 591 qDebug( "OWirelessNetworkInterface::() ---------------------------------------------------------" );
592} 592}
593 593
594 594
595int OWirelessNetworkInterface::channel() const 595int OWirelessNetworkInterface::channel() const
596{ 596{
597 //FIXME: When monitoring enabled, then use it 597 //FIXME: When monitoring enabled, then use it
598 //FIXME: to gather the current RF channel 598 //FIXME: to gather the current RF channel
599 //FIXME: Until then, get active channel from hopper. 599 //FIXME: Until then, get active channel from hopper.
600 if ( _hopper && _hopper->isActive() ) 600 if ( _hopper && _hopper->isActive() )
601 return _hopper->channel(); 601 return _hopper->channel();
602 602
603 if ( !wioctl( SIOCGIWFREQ ) ) 603 if ( !wioctl( SIOCGIWFREQ ) )
604 { 604 {
605 return -1; 605 return -1;
606 } 606 }
607 else 607 else
608 { 608 {
609 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 609 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
610 } 610 }
611} 611}
612 612
613 613
614void OWirelessNetworkInterface::setChannel( int c ) const 614void OWirelessNetworkInterface::setChannel( int c ) const
615{ 615{
616 if ( !c ) 616 if ( !c )
617 { 617 {
618 qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" ); 618 qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" );
619 return; 619 return;
620 } 620 }
621 621
622 if ( !_mon ) 622 if ( !_mon )
623 { 623 {
624 memset( &_iwr, 0, sizeof( struct iwreq ) ); 624 memset( &_iwr, 0, sizeof( struct iwreq ) );
625 _iwr.u.freq.m = c; 625 _iwr.u.freq.m = c;
626 _iwr.u.freq.e = 0; 626 _iwr.u.freq.e = 0;
627 wioctl( SIOCSIWFREQ ); 627 wioctl( SIOCSIWFREQ );
628 } 628 }
629 else 629 else
630 { 630 {
631 _mon->setChannel( c ); 631 _mon->setChannel( c );
632 } 632 }
633} 633}
634 634
635 635
636double OWirelessNetworkInterface::frequency() const 636double OWirelessNetworkInterface::frequency() const
637{ 637{
638 if ( !wioctl( SIOCGIWFREQ ) ) 638 if ( !wioctl( SIOCGIWFREQ ) )
639 { 639 {
640 return -1.0; 640 return -1.0;
641 } 641 }
642 else 642 else
643 { 643 {
644 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 644 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
645 } 645 }
646} 646}
647 647
648 648
649int OWirelessNetworkInterface::channels() const 649int OWirelessNetworkInterface::channels() const
650{ 650{
651 return _channels.count(); 651 return _channels.count();
652} 652}
653 653
654 654
655void OWirelessNetworkInterface::setChannelHopping( int interval ) 655void OWirelessNetworkInterface::setChannelHopping( int interval )
656{ 656{
657 if ( !_hopper ) _hopper = new OChannelHopper( this ); 657 if ( !_hopper ) _hopper = new OChannelHopper( this );
658 _hopper->setInterval( interval ); 658 _hopper->setInterval( interval );
659 //FIXME: When and by whom will the channel hopper be deleted? 659 //FIXME: When and by whom will the channel hopper be deleted?
660 //TODO: rely on QObject hierarchy 660 //TODO: rely on QObject hierarchy
661} 661}
662 662
663 663
664int OWirelessNetworkInterface::channelHopping() const 664int OWirelessNetworkInterface::channelHopping() const
665{ 665{
666 return _hopper->interval(); 666 return _hopper->interval();
667} 667}
668 668
669 669
670OChannelHopper* OWirelessNetworkInterface::channelHopper() const 670OChannelHopper* OWirelessNetworkInterface::channelHopper() const
671{ 671{
672 return _hopper; 672 return _hopper;
673} 673}
674 674
675 675
676void OWirelessNetworkInterface::setMode( const QString& mode ) 676void OWirelessNetworkInterface::commit() const
677{ 677{
678 _iwr.u.mode = stringToMode( mode ); 678 wioctl( SIOCSIWCOMMIT );
679 wioctl( SIOCSIWMODE );
680} 679}
681 680
682 681
683QString OWirelessNetworkInterface::mode() const 682void OWirelessNetworkInterface::setMode( const QString& newMode )
684{ 683{
685 if ( !wioctl( SIOCGIWMODE ) ) 684 #ifdef FINALIZE
685 QString currentMode = mode();
686 if ( currentMode == newMode ) return;
687 #endif
688
689 qDebug( "OWirelessNetworkInterface::setMode(): trying to set mode '%s' (%d)", (const char*) newMode, stringToMode( newMode ) );
690
691 _iwr.u.mode = stringToMode( newMode );
692
693 if ( _iwr.u.mode != IW_MODE_MONITOR )
686 { 694 {
687 return "<unknown>"; 695 // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP!
696 _iwr.u.mode = stringToMode( newMode );
697 wioctl( SIOCSIWMODE );
698
699 // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now)
700
701 if ( mode() == "monitor" )
702 {
703 qDebug( "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." );
704 if ( _mon )
705 _mon->setEnabled( false );
706 else
707 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
708 }
709
710 }
711 else // special iwpriv fallback for monitor mode
712 {
713 if ( wioctl( SIOCSIWMODE ) )
714 {
715 qDebug( "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" );
716 }
717 else
718 {
719 qDebug( "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." );
720
721 if ( _mon )
722 _mon->setEnabled( true );
723 else
724 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
725 }
688 } 726 }
689 return modeToString( _iwr.u.mode );
690} 727}
691 728
692 729
693void OWirelessNetworkInterface::setMonitorMode( bool b ) 730QString OWirelessNetworkInterface::mode() const
694{ 731{
695 if ( _mon ) 732 memset( &_iwr, 0, sizeof( struct iwreq ) );
696 _mon->setEnabled( b ); 733
697 else 734 if ( !wioctl( SIOCGIWMODE ) )
698 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 735 {
699} 736 return "<unknown>";
737 }
700 738
739 qDebug( "DEBUG: WE's idea of current mode seems to be '%s'", (const char*) modeToString( _iwr.u.mode ) );
701 740
702bool OWirelessNetworkInterface::monitorMode() const 741 // legacy compatible monitor mode check
703{
704 qDebug( "dataLinkType = %d", dataLinkType() );
705 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
706 //FIXME: 802 is the header type for PRISM - Linux support for this is pending...
707 //FIXME: What is 119, by the way?
708}
709 742
743 if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 )
744 {
745 return "monitor";
746 }
747 else
748 {
749 return modeToString( _iwr.u.mode );
750 }
751}
710 752
711void OWirelessNetworkInterface::setNickName( const QString& nickname ) 753void OWirelessNetworkInterface::setNickName( const QString& nickname )
712{ 754{
713 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); 755 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
714 _iwr.u.essid.length = nickname.length(); 756 _iwr.u.essid.length = nickname.length();
715 wioctl( SIOCSIWNICKN ); 757 wioctl( SIOCSIWNICKN );
716} 758}
717 759
718 760
719QString OWirelessNetworkInterface::nickName() const 761QString OWirelessNetworkInterface::nickName() const
720{ 762{
721 char str[IW_ESSID_MAX_SIZE]; 763 char str[IW_ESSID_MAX_SIZE];
722 _iwr.u.data.pointer = &str[0]; 764 _iwr.u.data.pointer = &str[0];
723 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 765 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
724 if ( !wioctl( SIOCGIWNICKN ) ) 766 if ( !wioctl( SIOCGIWNICKN ) )
725 { 767 {
726 return "<unknown>"; 768 return "<unknown>";
727 } 769 }
728 else 770 else
729 { 771 {
730 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 772 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
731 return str; 773 return str;
732 } 774 }
733} 775}
734 776
735 777
736void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 778void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
737{ 779{
738 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 780 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
739 if ( !priv ) 781 if ( !priv )
740 { 782 {
741 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); 783 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
742 return; 784 return;
743 } 785 }
744 if ( priv->numberSetArgs() != numargs ) 786 if ( priv->numberSetArgs() != numargs )
745 { 787 {
746 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); 788 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs );
747 return; 789 return;
748 } 790 }
749 791
750 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); 792 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() );
751 memset( &_iwr, 0, sizeof _iwr ); 793 memset( &_iwr, 0, sizeof _iwr );
752 va_list argp; 794 va_list argp;
753 va_start( argp, numargs ); 795 va_start( argp, numargs );
754 for ( int i = 0; i < numargs; ++i ) 796 for ( int i = 0; i < numargs; ++i )
755 { 797 {
756 priv->setParameter( i, va_arg( argp, int ) ); 798 priv->setParameter( i, va_arg( argp, int ) );
757 } 799 }
758 va_end( argp ); 800 va_end( argp );
759 priv->invoke(); 801 priv->invoke();
760} 802}
761 803
762 804
763void OWirelessNetworkInterface::getPrivate( const QString& call ) 805void OWirelessNetworkInterface::getPrivate( const QString& call )
764{ 806{
765 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); 807 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
766} 808}
767 809
768 810
769bool OWirelessNetworkInterface::hasPrivate( const QString& call ) 811bool OWirelessNetworkInterface::hasPrivate( const QString& call )
770{ 812{
771 return child( (const char*) call ); 813 return child( (const char*) call );
772} 814}
773 815
774 816
775QString OWirelessNetworkInterface::SSID() const 817QString OWirelessNetworkInterface::SSID() const
776{ 818{
777 char str[IW_ESSID_MAX_SIZE]; 819 char str[IW_ESSID_MAX_SIZE];
778 _iwr.u.essid.pointer = &str[0]; 820 _iwr.u.essid.pointer = &str[0];
779 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 821 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
780 if ( !wioctl( SIOCGIWESSID ) ) 822 if ( !wioctl( SIOCGIWESSID ) )
781 { 823 {
782 return "<unknown>"; 824 return "<unknown>";
783 } 825 }
784 else 826 else
785 { 827 {
786 return str; 828 return str;
787 } 829 }
788} 830}
789 831
790 832
791void OWirelessNetworkInterface::setSSID( const QString& ssid ) 833void OWirelessNetworkInterface::setSSID( const QString& ssid )
792{ 834{
793 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 835 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
794 _iwr.u.essid.length = ssid.length(); 836 _iwr.u.essid.length = ssid.length();
795 wioctl( SIOCSIWESSID ); 837 wioctl( SIOCSIWESSID );
796} 838}
797 839
798 840
799OStationList* OWirelessNetworkInterface::scanNetwork() 841OStationList* OWirelessNetworkInterface::scanNetwork()
800{ 842{
801 _iwr.u.param.flags = IW_SCAN_DEFAULT; 843 _iwr.u.param.flags = IW_SCAN_DEFAULT;
802 _iwr.u.param.value = 0; 844 _iwr.u.param.value = 0;
803 if ( !wioctl( SIOCSIWSCAN ) ) 845 if ( !wioctl( SIOCSIWSCAN ) )
804 { 846 {
805 return 0; 847 return 0;
806 } 848 }
807 849
808 OStationList* stations = new OStationList(); 850 OStationList* stations = new OStationList();
809 851
810 int timeout = 1000000; 852 int timeout = 1000000;
811 853
812 qDebug( "ONetworkInterface::scanNetwork() - scan started." ); 854 qDebug( "ONetworkInterface::scanNetwork() - scan started." );
813 855
814 bool results = false; 856 bool results = false;
815 struct timeval tv; 857 struct timeval tv;
816 tv.tv_sec = 0; 858 tv.tv_sec = 0;
817 tv.tv_usec = 250000; // initial timeout ~ 250ms 859 tv.tv_usec = 250000; // initial timeout ~ 250ms
818 char buffer[IW_SCAN_MAX_DATA]; 860 char buffer[IW_SCAN_MAX_DATA];
819 861
820 while ( !results && timeout > 0 ) 862 while ( !results && timeout > 0 )
821 { 863 {
822 timeout -= tv.tv_usec; 864 timeout -= tv.tv_usec;
823 select( 0, 0, 0, 0, &tv ); 865 select( 0, 0, 0, 0, &tv );
824 866
825 _iwr.u.data.pointer = &buffer[0]; 867 _iwr.u.data.pointer = &buffer[0];
826 _iwr.u.data.flags = 0; 868 _iwr.u.data.flags = 0;
827 _iwr.u.data.length = sizeof buffer; 869 _iwr.u.data.length = sizeof buffer;
828 if ( wioctl( SIOCGIWSCAN ) ) 870 if ( wioctl( SIOCGIWSCAN ) )
829 { 871 {
830 results = true; 872 results = true;
831 continue; 873 continue;
832 } 874 }
833 else if ( errno == EAGAIN) 875 else if ( errno == EAGAIN)
834 { 876 {
835 qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." ); 877 qDebug( "ONetworkInterface::scanNetwork() - scan in progress..." );
836 #if 0 878 #if 0
837 if ( qApp ) 879 if ( qApp )
838 { 880 {
839 qApp->processEvents( 100 ); 881 qApp->processEvents( 100 );
840 continue; 882 continue;
841 } 883 }
842 #endif 884 #endif
843 tv.tv_sec = 0; 885 tv.tv_sec = 0;
844 tv.tv_usec = 100000; 886 tv.tv_usec = 100000;
845 continue; 887 continue;
846 } 888 }
847 } 889 }
848 890
849 qDebug( "ONetworkInterface::scanNetwork() - scan finished." ); 891 qDebug( "ONetworkInterface::scanNetwork() - scan finished." );
850 892
851 if ( results ) 893 if ( results )
852 { 894 {
853 qDebug( " - result length = %d", _iwr.u.data.length ); 895 qDebug( " - result length = %d", _iwr.u.data.length );
854 if ( !_iwr.u.data.length ) 896 if ( !_iwr.u.data.length )
855 { 897 {
856 qDebug( " - no results (empty neighbourhood)" ); 898 qDebug( " - no results (empty neighbourhood)" );
857 return stations; 899 return stations;
858 } 900 }
859 901
860 qDebug( " - results are in!" ); 902 qDebug( " - results are in!" );
861 dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); 903 dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length );
862 904
863 // parse results 905 // parse results
864 906
865 int offset = 0; 907 int offset = 0;
866 struct iw_event* we = (struct iw_event*) &buffer[0]; 908 struct iw_event* we = (struct iw_event*) &buffer[0];
867 909
868 while ( offset < _iwr.u.data.length ) 910 while ( offset < _iwr.u.data.length )
869 { 911 {
870 //const char* cmd = *(*_ioctlmap)[we->cmd]; 912 //const char* cmd = *(*_ioctlmap)[we->cmd];
871 //if ( !cmd ) cmd = "<unknown>"; 913 //if ( !cmd ) cmd = "<unknown>";
872 qDebug( "reading next event... cmd=%d, len=%d", we->cmd, we->len ); 914 qDebug( "reading next event... cmd=%d, len=%d", we->cmd, we->len );
873 switch (we->cmd) 915 switch (we->cmd)
874 { 916 {
875 case SIOCGIWAP: 917 case SIOCGIWAP:
876 { 918 {
877 qDebug( "SIOCGIWAP" ); 919 qDebug( "SIOCGIWAP" );
878 stations->append( new OStation() ); 920 stations->append( new OStation() );
879 stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; 921 stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0];
880 break; 922 break;
881 } 923 }
882 case SIOCGIWMODE: 924 case SIOCGIWMODE:
883 { 925 {
884 qDebug( "SIOCGIWMODE" ); 926 qDebug( "SIOCGIWMODE" );
885 stations->last()->type = modeToString( we->u.mode ); 927 stations->last()->type = modeToString( we->u.mode );
886 break; 928 break;
887 } 929 }
888 case SIOCGIWFREQ: 930 case SIOCGIWFREQ:
889 { 931 {
890 qDebug( "SIOCGIWFREQ" ); 932 qDebug( "SIOCGIWFREQ" );
891 stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; 933 stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ];
892 break; 934 break;
893 } 935 }
894 case SIOCGIWESSID: 936 case SIOCGIWESSID:
895 { 937 {
896 qDebug( "SIOCGIWESSID" ); 938 qDebug( "SIOCGIWESSID" );
897 stations->last()->ssid = we->u.essid.pointer; 939 stations->last()->ssid = we->u.essid.pointer;
898 break; 940 break;
899 } 941 }
900 case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break; 942 case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break;
901 case SIOCGIWENCODE: qDebug( "SIOCGIWENCODE" ); break; 943 case SIOCGIWENCODE: qDebug( "SIOCGIWENCODE" ); break;
902 case IWEVTXDROP: qDebug( "IWEVTXDROP" ); break; /* Packet dropped to excessive retry */ 944 case IWEVTXDROP: qDebug( "IWEVTXDROP" ); break; /* Packet dropped to excessive retry */
903 case IWEVQUAL: qDebug( "IWEVQUAL" ); break; /* Quality part of statistics (scan) */ 945 case IWEVQUAL: qDebug( "IWEVQUAL" ); break; /* Quality part of statistics (scan) */
904 case IWEVCUSTOM: qDebug( "IWEVCUSTOM" ); break; /* Driver specific ascii string */ 946 case IWEVCUSTOM: qDebug( "IWEVCUSTOM" ); break; /* Driver specific ascii string */
905 case IWEVREGISTERED: qDebug( "IWEVREGISTERED" ); break; /* Discovered a new node (AP mode) */ 947 case IWEVREGISTERED: qDebug( "IWEVREGISTERED" ); break; /* Discovered a new node (AP mode) */
906 case IWEVEXPIRED: qDebug( "IWEVEXPIRED" ); break; /* Expired a node (AP mode) */ 948 case IWEVEXPIRED: qDebug( "IWEVEXPIRED" ); break; /* Expired a node (AP mode) */
907 default: qDebug( "unhandled event" ); 949 default: qDebug( "unhandled event" );
908 } 950 }
909 951
910 offset += we->len; 952 offset += we->len;
911 we = (struct iw_event*) &buffer[offset]; 953 we = (struct iw_event*) &buffer[offset];
912 } 954 }
913 955
914 return stations; 956 return stations;
915 957
916 } 958 }
917 else 959 else
918 { 960 {
919 qDebug( " - no results (timeout) :(" ); 961 qDebug( " - no results (timeout) :(" );
920 return stations; 962 return stations;
921 } 963 }
922} 964}
923 965
924 966
925bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 967bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
926{ 968{
927 #ifndef NODEBUG 969 #ifndef NODEBUG
928 int result = ::ioctl( _sfd, call, &iwreq ); 970 int result = ::ioctl( _sfd, call, &iwreq );
929 if ( result == -1 ) 971 if ( result == -1 )
930 qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) *(*_ioctlmap)[call], call, result, strerror( errno ) ); 972 qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Failed: %d (%s)", name(), (const char*) *(*_ioctlmap)[call], call, result, strerror( errno ) );
931 else 973 else
932 qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) *(*_ioctlmap)[call], call ); 974 qDebug( "ONetworkInterface::wioctl (%s) call %s (0x%04X) - Status: Ok.", name(), (const char*) *(*_ioctlmap)[call], call );
933 return ( result != -1 ); 975 return ( result != -1 );
934 #else 976 #else
935 return ::ioctl( _sfd, call, &iwreq ) != -1; 977 return ::ioctl( _sfd, call, &iwreq ) != -1;
936 #endif 978 #endif
937} 979}
938 980
939 981
940bool OWirelessNetworkInterface::wioctl( int call ) const 982bool OWirelessNetworkInterface::wioctl( int call ) const
941{ 983{
942 strcpy( _iwr.ifr_name, name() ); 984 strcpy( _iwr.ifr_name, name() );
943 return wioctl( call, _iwr ); 985 return wioctl( call, _iwr );
944} 986}
945 987
946 988
947/*====================================================================================== 989/*======================================================================================
948 * OMonitoringInterface 990 * OMonitoringInterface
949 *======================================================================================*/ 991 *======================================================================================*/
950 992
951OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 993OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
952 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) 994 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader )
953{ 995{
954} 996}
955 997
956 998
957OMonitoringInterface::~OMonitoringInterface() 999OMonitoringInterface::~OMonitoringInterface()
958{ 1000{
959} 1001}
960 1002
961 1003
962void OMonitoringInterface::setChannel( int c ) 1004void OMonitoringInterface::setChannel( int c )
963{ 1005{
964 // use standard WE channel switching protocol 1006 // use standard WE channel switching protocol
965 memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); 1007 memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
966 _if->_iwr.u.freq.m = c; 1008 _if->_iwr.u.freq.m = c;
967 _if->_iwr.u.freq.e = 0; 1009 _if->_iwr.u.freq.e = 0;
968 _if->wioctl( SIOCSIWFREQ ); 1010 _if->wioctl( SIOCSIWFREQ );
969} 1011}
970 1012
971 1013
972bool OMonitoringInterface::enabled() const
973{
974 return _if->monitorMode();
975}
976
977
978void OMonitoringInterface::setEnabled( bool b ) 1014void OMonitoringInterface::setEnabled( bool b )
979{ 1015{
980} 1016}
981 1017
982 1018
983/*====================================================================================== 1019/*======================================================================================
984 * OCiscoMonitoringInterface 1020 * OCiscoMonitoringInterface
985 *======================================================================================*/ 1021 *======================================================================================*/
986 1022
987OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1023OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
988 :OMonitoringInterface( iface, prismHeader ) 1024 :OMonitoringInterface( iface, prismHeader )
989{ 1025{
990 iface->setMonitoring( this ); 1026 iface->setMonitoring( this );
991} 1027}
992 1028
993 1029
994OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 1030OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
995{ 1031{
996} 1032}
997 1033
998 1034
999void OCiscoMonitoringInterface::setEnabled( bool b ) 1035void OCiscoMonitoringInterface::setEnabled( bool b )
1000{ 1036{
1001 QString fname; 1037 QString fname;
1002 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 1038 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
1003 QFile f( fname ); 1039 QFile f( fname );
1004 if ( !f.exists() ) return; 1040 if ( !f.exists() ) return;
1005 1041
1006 if ( f.open( IO_WriteOnly ) ) 1042 if ( f.open( IO_WriteOnly ) )
1007 { 1043 {
1008 QTextStream s( &f ); 1044 QTextStream s( &f );
1009 s << "Mode: r"; 1045 s << "Mode: r";
1010 s << "Mode: y"; 1046 s << "Mode: y";
1011 s << "XmitPower: 1"; 1047 s << "XmitPower: 1";
1012 } 1048 }
1013 1049
1014 // flushing and closing will be done automatically when f goes out of scope 1050 // flushing and closing will be done automatically when f goes out of scope
1015} 1051}
1016 1052
1017 1053
1018QString OCiscoMonitoringInterface::name() const 1054QString OCiscoMonitoringInterface::name() const
1019{ 1055{
1020 return "cisco"; 1056 return "cisco";
1021} 1057}
1022 1058
1023 1059
1024void OCiscoMonitoringInterface::setChannel( int ) 1060void OCiscoMonitoringInterface::setChannel( int )
1025{ 1061{
1026 // cisco devices automatically switch channels when in monitor mode 1062 // cisco devices automatically switch channels when in monitor mode
1027} 1063}
1028 1064
1029 1065
1030/*====================================================================================== 1066/*======================================================================================
1031 * OWlanNGMonitoringInterface 1067 * OWlanNGMonitoringInterface
1032 *======================================================================================*/ 1068 *======================================================================================*/
1033 1069
1034 1070
1035OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1071OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
1036 :OMonitoringInterface( iface, prismHeader ) 1072 :OMonitoringInterface( iface, prismHeader )
1037{ 1073{
1038 iface->setMonitoring( this ); 1074 iface->setMonitoring( this );
1039} 1075}
1040 1076
1041 1077
1042OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 1078OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
1043{ 1079{
1044} 1080}
1045 1081
1046 1082
1047void OWlanNGMonitoringInterface::setEnabled( bool b ) 1083void OWlanNGMonitoringInterface::setEnabled( bool b )
1048{ 1084{
1049 //FIXME: do nothing if its already in the same mode 1085 //FIXME: do nothing if its already in the same mode
1050 1086
1051 QString enable = b ? "true" : "false"; 1087 QString enable = b ? "true" : "false";
1052 QString prism = _prismHeader ? "true" : "false"; 1088 QString prism = _prismHeader ? "true" : "false";
1053 QString cmd; 1089 QString cmd;
1054 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", 1090 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
1055 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); 1091 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism );
1056 system( cmd ); 1092 system( cmd );
1057} 1093}
1058 1094
1059 1095
1060QString OWlanNGMonitoringInterface::name() const 1096QString OWlanNGMonitoringInterface::name() const
1061{ 1097{
1062 return "wlan-ng"; 1098 return "wlan-ng";
1063} 1099}
1064 1100
1065 1101
1066void OWlanNGMonitoringInterface::setChannel( int c ) 1102void OWlanNGMonitoringInterface::setChannel( int c )
1067{ 1103{
1068 //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. 1104 //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't.
1069 1105
1070 QString enable = "true"; //_if->monitorMode() ? "true" : "false"; 1106 QString enable = "true"; //_if->monitorMode() ? "true" : "false";
1071 QString prism = _prismHeader ? "true" : "false"; 1107 QString prism = _prismHeader ? "true" : "false";
1072 QString cmd; 1108 QString cmd;
1073 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", 1109 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
1074 (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); 1110 (const char*) _if->name(), c, (const char*) enable, (const char*) prism );
1075 system( cmd ); 1111 system( cmd );
1076} 1112}
1077 1113
1078 1114
1079/*====================================================================================== 1115/*======================================================================================
1080 * OHostAPMonitoringInterface 1116 * OHostAPMonitoringInterface
1081 *======================================================================================*/ 1117 *======================================================================================*/
1082 1118
1083OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1119OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
1084 :OMonitoringInterface( iface, prismHeader ) 1120 :OMonitoringInterface( iface, prismHeader )
1085{ 1121{
1086 iface->setMonitoring( this ); 1122 iface->setMonitoring( this );
1087} 1123}
1088 1124
1089OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 1125OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
1090{ 1126{
1091} 1127}
1092 1128
1093void OHostAPMonitoringInterface::setEnabled( bool b ) 1129void OHostAPMonitoringInterface::setEnabled( bool b )
1094{ 1130{
1095 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
1096 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
1097
1098 #if WIRELESS_EXT > 14
1099 if ( b )
1100 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header
1101 else
1102 _if->setMode( "managed" );
1103 #else
1104 int monitorCode = _prismHeader ? 1 : 2; 1131 int monitorCode = _prismHeader ? 1 : 2;
1105 if ( b ) 1132 if ( b )
1106 { 1133 {
1107 _if->setPrivate( "monitor", 1, monitorCode ); 1134 _if->setPrivate( "monitor", 1, monitorCode );
1108 } 1135 }
1109 else 1136 else
1110 { 1137 {
1111 _if->setPrivate( "monitor", 1, 0 ); 1138 _if->setPrivate( "monitor", 1, 0 );
1112 } 1139 }
1113 #endif
1114} 1140}
1115 1141
1116 1142
1117QString OHostAPMonitoringInterface::name() const 1143QString OHostAPMonitoringInterface::name() const
1118{ 1144{
1119 return "hostap"; 1145 return "hostap";
1120} 1146}
1121 1147
1122 1148
1123/*====================================================================================== 1149/*======================================================================================
1124 * OOrinocoNetworkInterface 1150 * OOrinocoNetworkInterface
1125 *======================================================================================*/ 1151 *======================================================================================*/
1126 1152
1127OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1153OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
1128 :OMonitoringInterface( iface, prismHeader ) 1154 :OMonitoringInterface( iface, prismHeader )
1129{ 1155{
1130 iface->setMonitoring( this ); 1156 iface->setMonitoring( this );
1131} 1157}
1132 1158
1133 1159
1134OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 1160OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
1135{ 1161{
1136} 1162}
1137 1163
1138 1164
1139void OOrinocoMonitoringInterface::setChannel( int c ) 1165void OOrinocoMonitoringInterface::setChannel( int c )
1140{ 1166{
1141 int monitorCode = _prismHeader ? 1 : 2; 1167 int monitorCode = _prismHeader ? 1 : 2;
1142 _if->setPrivate( "monitor", 2, monitorCode, c ); 1168 _if->setPrivate( "monitor", 2, monitorCode, c );
1143} 1169}
1144 1170
1145 1171
1146void OOrinocoMonitoringInterface::setEnabled( bool b ) 1172void OOrinocoMonitoringInterface::setEnabled( bool b )
1147{ 1173{
1148 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 1174 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
1149 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 1175 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
1150 // However, as of recent orinoco drivers, IW_MODE_MONITOR is still not supported 1176 // However, as of recent orinoco drivers, IW_MODE_MONITOR is still not supported
1151 1177
1152 #if 0
1153 //#if WIRELESS_EXT > 14
1154 if ( b )
1155 _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header
1156 else
1157 _if->setMode( "managed" );
1158 #else
1159 if ( b ) 1178 if ( b )
1160 { 1179 {
1161 setChannel( 1 ); 1180 setChannel( 1 );
1162 } 1181 }
1163 else 1182 else
1164 { 1183 {
1165 _if->setPrivate( "monitor", 2, 0, 0 ); 1184 _if->setPrivate( "monitor", 2, 0, 0 );
1166 } 1185 }
1167 #endif
1168} 1186}
1169 1187
1170 1188
1171QString OOrinocoMonitoringInterface::name() const 1189QString OOrinocoMonitoringInterface::name() const
1172{ 1190{
1173 return "orinoco"; 1191 return "orinoco";
1174} 1192}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index 0eb4542..eb6c86e 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -96,449 +96,447 @@ class ONetwork : public QObject
96 */ 96 */
97 ONetworkInterface* interface( const QString& interface ) const; 97 ONetworkInterface* interface( const QString& interface ) const;
98 /** 98 /**
99 * @internal Rebuild the internal interface database 99 * @internal Rebuild the internal interface database
100 * @note Sometimes it might be useful to call this from client code, 100 * @note Sometimes it might be useful to call this from client code,
101 * e.g. after issuing a cardctl insert 101 * e.g. after issuing a cardctl insert
102 */ 102 */
103 void synchronize(); 103 void synchronize();
104 /** 104 /**
105 * @returns the wireless extension version used at compile time. 105 * @returns the wireless extension version used at compile time.
106 **/ 106 **/
107 static short wirelessExtensionVersion(); 107 static short wirelessExtensionVersion();
108 108
109 protected: 109 protected:
110 ONetwork(); 110 ONetwork();
111 111
112 private: 112 private:
113 static ONetwork* _instance; 113 static ONetwork* _instance;
114 InterfaceMap _interfaces; 114 InterfaceMap _interfaces;
115}; 115};
116 116
117 117
118/*====================================================================================== 118/*======================================================================================
119 * ONetworkInterface 119 * ONetworkInterface
120 *======================================================================================*/ 120 *======================================================================================*/
121 121
122/** 122/**
123 * @brief A network interface wrapper. 123 * @brief A network interface wrapper.
124 * 124 *
125 * This class provides a wrapper for a network interface. All the cumbersume details of 125 * This class provides a wrapper for a network interface. All the cumbersume details of
126 * Linux ioctls are hidden under a convenient high-level interface. 126 * Linux ioctls are hidden under a convenient high-level interface.
127 * @warning Most of the setting methods contained in this class require the appropriate 127 * @warning Most of the setting methods contained in this class require the appropriate
128 * process permissions to work. 128 * process permissions to work.
129 * 129 *
130 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 130 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
131 */ 131 */
132class ONetworkInterface : public QObject 132class ONetworkInterface : public QObject
133{ 133{
134 friend class OMonitoringInterface; 134 friend class OMonitoringInterface;
135 friend class OCiscoMonitoringInterface; 135 friend class OCiscoMonitoringInterface;
136 friend class OWlanNGMonitoringInterface; 136 friend class OWlanNGMonitoringInterface;
137 friend class OHostAPMonitoringInterface; 137 friend class OHostAPMonitoringInterface;
138 friend class OOrinocoMonitoringInterface; 138 friend class OOrinocoMonitoringInterface;
139 139
140 public: 140 public:
141 /** 141 /**
142 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, 142 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself,
143 * but access them via @ref ONetwork::interface(). 143 * but access them via @ref ONetwork::interface().
144 */ 144 */
145 ONetworkInterface( QObject* parent, const char* name ); 145 ONetworkInterface( QObject* parent, const char* name );
146 /** 146 /**
147 * Destructor. 147 * Destructor.
148 */ 148 */
149 virtual ~ONetworkInterface(); 149 virtual ~ONetworkInterface();
150 /** 150 /**
151 * Associates a @a monitoring interface with this network interface. 151 * Associates a @a monitoring interface with this network interface.
152 * @note This is currently only useful with @ref OWirelessNetworkInterface objects. 152 * @note This is currently only useful with @ref OWirelessNetworkInterface objects.
153 */ 153 */
154 void setMonitoring( OMonitoringInterface* monitoring ); 154 void setMonitoring( OMonitoringInterface* monitoring );
155 /** 155 /**
156 * @returns the currently associated monitoring interface or 0, if no monitoring is associated. 156 * @returns the currently associated monitoring interface or 0, if no monitoring is associated.
157 */ 157 */
158 OMonitoringInterface* monitoring() const; 158 OMonitoringInterface* monitoring() const;
159 /** 159 /**
160 * Setting an interface to promiscuous mode enables the device to receive 160 * Setting an interface to promiscuous mode enables the device to receive
161 * all packets on the shared medium - as opposed to packets which are addressed to this interface. 161 * all packets on the shared medium - as opposed to packets which are addressed to this interface.
162 */ 162 */
163 bool setPromiscuousMode( bool ); 163 bool setPromiscuousMode( bool );
164 /** 164 /**
165 * @returns true if the interface is set to promiscuous mode. 165 * @returns true if the interface is set to promiscuous mode.
166 */ 166 */
167 bool promiscuousMode() const; 167 bool promiscuousMode() const;
168 /** 168 /**
169 * Setting an interface to up enables it to receive packets. 169 * Setting an interface to up enables it to receive packets.
170 */ 170 */
171 bool setUp( bool ); 171 bool setUp( bool );
172 /** 172 /**
173 * @returns true if the interface is up. 173 * @returns true if the interface is up.
174 */ 174 */
175 bool isUp() const; 175 bool isUp() const;
176 /** 176 /**
177 * @returns true if the interface is a loopback interface. 177 * @returns true if the interface is a loopback interface.
178 */ 178 */
179 bool isLoopback() const; 179 bool isLoopback() const;
180 /** 180 /**
181 * @returns true if the interface is featuring supports the wireless extension protocol. 181 * @returns true if the interface is featuring supports the wireless extension protocol.
182 */ 182 */
183 bool isWireless() const; 183 bool isWireless() const;
184 /** 184 /**
185 * Associate the IP address @ addr with the interface. 185 * Associate the IP address @ addr with the interface.
186 */ 186 */
187 void setIPV4Address( const QHostAddress& addr ); 187 void setIPV4Address( const QHostAddress& addr );
188 /** 188 /**
189 * @returns the IPv4 address associated with the interface. 189 * @returns the IPv4 address associated with the interface.
190 */ 190 */
191 QString ipV4Address() const; //TODO: make this return an OHostAddress 191 QString ipV4Address() const; //TODO: make this return an OHostAddress
192 /** 192 /**
193 * Associate the MAC address @a addr with the interface. 193 * Associate the MAC address @a addr with the interface.
194 * @note It can be necessary to shut down the interface prior to calling this method. 194 * @note It can be necessary to shut down the interface prior to calling this method.
195 * @warning This is not supported by all drivers. 195 * @warning This is not supported by all drivers.
196 */ 196 */
197 void setMacAddress( const OMacAddress& addr ); 197 void setMacAddress( const OMacAddress& addr );
198 /** 198 /**
199 * @returns the MAC address associated with the interface. 199 * @returns the MAC address associated with the interface.
200 */ 200 */
201 OMacAddress macAddress() const; 201 OMacAddress macAddress() const;
202 /** 202 /**
203 * Associate the IPv4 @a netmask with the interface. 203 * Associate the IPv4 @a netmask with the interface.
204 */ 204 */
205 void setIPV4Netmask( const QHostAddress& netmask ); 205 void setIPV4Netmask( const QHostAddress& netmask );
206 /** 206 /**
207 * @returns the IPv4 netmask associated with the interface. 207 * @returns the IPv4 netmask associated with the interface.
208 */ 208 */
209 QString ipV4Netmask() const; //TODO: make this return an OHostAddress 209 QString ipV4Netmask() const; //TODO: make this return an OHostAddress
210 /** 210 /**
211 * @returns the data link type currently associated with the interface. 211 * @returns the data link type currently associated with the interface.
212 * @see #include <net/if_arp.h> for possible values. 212 * @see #include <net/if_arp.h> for possible values.
213 */ 213 */
214 int dataLinkType() const; 214 int dataLinkType() const;
215 215
216 protected: 216 protected:
217 const int _sfd; 217 const int _sfd;
218 mutable ifreq _ifr; 218 mutable ifreq _ifr;
219 OMonitoringInterface* _mon; 219 OMonitoringInterface* _mon;
220 220
221 protected: 221 protected:
222 struct ifreq& ifr() const; 222 struct ifreq& ifr() const;
223 virtual void init(); 223 virtual void init();
224 bool ioctl( int call ) const; 224 bool ioctl( int call ) const;
225 bool ioctl( int call, struct ifreq& ) const; 225 bool ioctl( int call, struct ifreq& ) const;
226}; 226};
227 227
228/*====================================================================================== 228/*======================================================================================
229 * OChannelHopper 229 * OChannelHopper
230 *======================================================================================*/ 230 *======================================================================================*/
231 231
232/** 232/**
233 * @brief A radio frequency channel hopper. 233 * @brief A radio frequency channel hopper.
234 * 234 *
235 * This class provides a channel hopper for radio frequencies. A channel hopper frequently 235 * This class provides a channel hopper for radio frequencies. A channel hopper frequently
236 * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. 236 * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface.
237 * This is necessary when in monitoring mode and scanning for other devices, because 237 * This is necessary when in monitoring mode and scanning for other devices, because
238 * the radio frequency hardware can only detect packets sent on the same frequency. 238 * the radio frequency hardware can only detect packets sent on the same frequency.
239 * 239 *
240 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 240 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
241 */ 241 */
242class OChannelHopper : public QObject 242class OChannelHopper : public QObject
243{ 243{
244 Q_OBJECT 244 Q_OBJECT
245 245
246 public: 246 public:
247 /** 247 /**
248 * Constructor. 248 * Constructor.
249 */ 249 */
250 OChannelHopper( OWirelessNetworkInterface* ); 250 OChannelHopper( OWirelessNetworkInterface* );
251 /** 251 /**
252 * Destructor. 252 * Destructor.
253 */ 253 */
254 virtual ~OChannelHopper(); 254 virtual ~OChannelHopper();
255 /** 255 /**
256 * @returns true, if the channel hopper is hopping channels 256 * @returns true, if the channel hopper is hopping channels
257 */ 257 */
258 bool isActive() const; 258 bool isActive() const;
259 /** 259 /**
260 * @returns the last hopped channel 260 * @returns the last hopped channel
261 */ 261 */
262 int channel() const; 262 int channel() const;
263 /** 263 /**
264 * Set the channel hopping @a interval. 264 * Set the channel hopping @a interval.
265 * An interval of 0 deactivates the channel hopper. 265 * An interval of 0 deactivates the channel hopper.
266 */ 266 */
267 void setInterval( int interval ); 267 void setInterval( int interval );
268 /** 268 /**
269 * @returns the channel hopping interval 269 * @returns the channel hopping interval
270 */ 270 */
271 int interval() const; 271 int interval() const;
272 272
273 signals: 273 signals:
274 /** 274 /**
275 * This signal is emitted right after the channel hopper performed a hop 275 * This signal is emitted right after the channel hopper performed a hop
276 */ 276 */
277 void hopped( int ); 277 void hopped( int );
278 278
279 protected: 279 protected:
280 virtual void timerEvent( QTimerEvent* ); 280 virtual void timerEvent( QTimerEvent* );
281 281
282 private: 282 private:
283 OWirelessNetworkInterface* _iface; 283 OWirelessNetworkInterface* _iface;
284 int _interval; 284 int _interval;
285 int _tid; 285 int _tid;
286 QValueList<int> _channels; 286 QValueList<int> _channels;
287 QValueList<int>::Iterator _channel; 287 QValueList<int>::Iterator _channel;
288}; 288};
289 289
290 290
291/*====================================================================================== 291/*======================================================================================
292 * OWirelessNetworkInterface 292 * OWirelessNetworkInterface
293 *======================================================================================*/ 293 *======================================================================================*/
294 294
295/** 295/**
296 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. 296 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol.
297 * 297 *
298 * This class provides a high-level encapsulation of the Linux wireless extension API. 298 * This class provides a high-level encapsulation of the Linux wireless extension API.
299 * 299 *
300 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 300 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
301 */ 301 */
302class OWirelessNetworkInterface : public ONetworkInterface 302class OWirelessNetworkInterface : public ONetworkInterface
303{ 303{
304 friend class OMonitoringInterface; 304 friend class OMonitoringInterface;
305 friend class OCiscoMonitoringInterface; 305 friend class OCiscoMonitoringInterface;
306 friend class OWlanNGMonitoringInterface; 306 friend class OWlanNGMonitoringInterface;
307 friend class OHostAPMonitoringInterface; 307 friend class OHostAPMonitoringInterface;
308 friend class OOrinocoMonitoringInterface; 308 friend class OOrinocoMonitoringInterface;
309 309
310 friend class OPrivateIOCTL; 310 friend class OPrivateIOCTL;
311 311
312 public: 312 public:
313 /** 313 /**
314 * Constructor. 314 * Constructor.
315 */ 315 */
316 OWirelessNetworkInterface( QObject* parent, const char* name ); 316 OWirelessNetworkInterface( QObject* parent, const char* name );
317 /** 317 /**
318 * Destructor. 318 * Destructor.
319 */ 319 */
320 virtual ~OWirelessNetworkInterface(); 320 virtual ~OWirelessNetworkInterface();
321 /** 321 /**
322 * Setting the @a channel of the interface changes the radio frequency (RF) 322 * Setting the @a channel of the interface changes the radio frequency (RF)
323 * of the corresponding wireless network device. 323 * of the corresponding wireless network device.
324 * @note Common channel range is within [1-14]. A value of 0 is not allowed. 324 * @note Common channel range is within [1-14]. A value of 0 is not allowed.
325 * @see channels() 325 * @see channels()
326 */ 326 */
327 virtual void setChannel( int channel ) const; 327 virtual void setChannel( int channel ) const;
328 /** 328 /**
329 * @returns the channel index of the current radio frequency. 329 * @returns the channel index of the current radio frequency.
330 */ 330 */
331 virtual int channel() const; 331 virtual int channel() const;
332 /** 332 /**
333 * @returns the current radio frequency (in MHz). 333 * @returns the current radio frequency (in MHz).
334 */ 334 */
335 virtual double frequency() const; 335 virtual double frequency() const;
336 /** 336 /**
337 * @returns the number of radio frequency channels for the 337 * @returns the number of radio frequency channels for the
338 * corresponding wireless network device. 338 * corresponding wireless network device.
339 * @note European devices usually have 14 channels, while American typically feature 11 channels. 339 * @note European devices usually have 14 channels, while American typically feature 11 channels.
340 */ 340 */
341 virtual int channels() const; 341 virtual int channels() const;
342 /** 342 /**
343 * Set the IEEE 802.11 operation @a mode. 343 * Set the IEEE 802.11 operation @a mode.
344 * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master 344 * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master
345 * @warning Not all drivers support the all modes. 345 * @warning Not all drivers support the all modes.
346 * @note You might have to change the SSID to get the operation mode change into effect. 346 * @note You might have to change the SSID to get the operation mode change into effect.
347 */ 347 */
348 virtual void setMode( const QString& mode ); 348 virtual void setMode( const QString& mode );
349 /** 349 /**
350 * @returns the current IEEE 802.11 operation mode. 350 * @returns the current IEEE 802.11 operation mode.
351 * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown 351 * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown
352 */ 352 *
353 virtual QString mode() const; 353 * @note: Important note concerning the 'monitor' mode:
354 /**
355 * Setting the monitor mode on a wireless network interface enables 354 * Setting the monitor mode on a wireless network interface enables
356 * listening to IEEE 802.11 data and management frames which normally 355 * listening to IEEE 802.11 data and management frames which normally
357 * are handled by the device firmware. This can be used to detect 356 * are handled by the device firmware. This can be used to detect
358 * other wireless network devices, e.g. Access Points or Ad-hoc stations. 357 * other wireless network devices, e.g. Access Points or Ad-hoc stations.
359 * @warning Standard wireless network drives don't support the monitor mode. 358 * @warning Standard wireless network drives don't support the monitor mode.
360 * @warning You need a patched driver for this to work. 359 * @warning You need a patched driver for this to work.
361 * @note Enabling the monitor mode is highly driver dependent and requires 360 * @note Enabling the monitor mode is highly driver dependent and requires
362 * the proper @ref OMonitoringInterface to be associated with the interface. 361 * the proper @ref OMonitoringInterface to be associated with the interface.
363 * @see OMonitoringInterface 362 * @see OMonitoringInterface
364 */ 363 */
365 virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); Use IW_MONITOR first, if this doesn't work, then use iwpriv! 364 virtual QString mode() const;
366 /**
367 * @returns true if the device is listening in IEEE 802.11 monitor mode
368 */
369 virtual bool monitorMode() const; //FIXME: ==> mode()
370 /** 365 /**
371 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. 366 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping.
372 * @see OChannelHopper 367 * @see OChannelHopper
373 */ 368 */
374 virtual void setChannelHopping( int interval = 0 ); 369 virtual void setChannelHopping( int interval = 0 );
375 /** 370 /**
376 * @returns the channel hopping interval or 0, if channel hopping is disabled. 371 * @returns the channel hopping interval or 0, if channel hopping is disabled.
377 */ 372 */
378 virtual int channelHopping() const; 373 virtual int channelHopping() const;
379 /** 374 /**
380 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before 375 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before
381 */ 376 */
382 virtual OChannelHopper* channelHopper() const; 377 virtual OChannelHopper* channelHopper() const;
383 /** 378 /**
384 * Set the station @a nickname. 379 * Set the station @a nickname.
385 */ 380 */
386 virtual void setNickName( const QString& nickname ); 381 virtual void setNickName( const QString& nickname );
387 /** 382 /**
388 * @returns the current station nickname. 383 * @returns the current station nickname.
389 */ 384 */
390 virtual QString nickName() const; 385 virtual QString nickName() const;
391 /** 386 /**
392 * Invoke the private IOCTL @a command with a @number of parameters on the network interface. 387 * Invoke the private IOCTL @a command with a @number of parameters on the network interface.
393 * @see OPrivateIOCTL 388 * @see OPrivateIOCTL
394 */ 389 */
395 virtual void setPrivate( const QString& command, int number, ... ); 390 virtual void setPrivate( const QString& command, int number, ... );
396 /** 391 /**
397 * @returns true if the interface is featuring the private IOCTL @command. 392 * @returns true if the interface is featuring the private IOCTL @command.
398 */ 393 */
399 virtual bool hasPrivate( const QString& command ); 394 virtual bool hasPrivate( const QString& command );
400 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this 395 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this
401 /** 396 /**
402 * @returns true if the interface is associated to an access point 397 * @returns true if the interface is associated to an access point
403 * @note: This information is only valid if the interface is in managed mode. 398 * @note: This information is only valid if the interface is in managed mode.
404 */ 399 */
405 virtual bool isAssociated() const; 400 virtual bool isAssociated() const;
406 /** 401 /**
407 * @returns the MAC address of the Access Point if the device is in infrastructure mode. 402 * @returns the MAC address of the Access Point if the device is in infrastructure mode.
408 * @returns a (more or less random) cell ID address if the device is in adhoc mode. 403 * @returns a (more or less random) cell ID address if the device is in adhoc mode.
409 */ 404 */
410 virtual OMacAddress associatedAP() const; 405 virtual OMacAddress associatedAP() const;
411 /** 406 /**
412 * Set the @a ssid (Service Set ID) string. This is used to decide 407 * Set the @a ssid (Service Set ID) string. This is used to decide
413 * which network to associate with (use "any" to let the driver decide). 408 * which network to associate with (use "any" to let the driver decide).
414 */ 409 */
415 virtual void setSSID( const QString& ssid ); 410 virtual void setSSID( const QString& ssid );
416 /** 411 /**
417 * @returns the current SSID (Service Set ID). 412 * @returns the current SSID (Service Set ID).
418 */ 413 */
419 virtual QString SSID() const; 414 virtual QString SSID() const;
420 /** 415 /**
421 * Perform scanning the wireless network neighbourhood. 416 * Perform scanning the wireless network neighbourhood.
422 * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! 417 * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE!
423 */ 418 */
424 virtual OStationList* scanNetwork(); 419 virtual OStationList* scanNetwork();
420 /** @internal commit pending changes to the driver
421 *
422 */
423 void commit() const;
425 424
426 protected: 425 protected:
427 void buildInformation(); 426 void buildInformation();
428 void buildPrivateList(); 427 void buildPrivateList();
429 void dumpInformation() const; 428 void dumpInformation() const;
430 virtual void init(); 429 virtual void init();
431 struct iwreq& iwr() const; 430 struct iwreq& iwr() const;
432 bool wioctl( int call ) const; 431 bool wioctl( int call ) const;
433 bool wioctl( int call, struct iwreq& ) const; 432 bool wioctl( int call, struct iwreq& ) const;
434 433
435 protected: 434 protected:
436 mutable struct iwreq _iwr; 435 mutable struct iwreq _iwr;
437 QMap<int,int> _channels; 436 QMap<int,int> _channels;
438 struct iw_range _range; 437 struct iw_range _range;
439 438
440 private: 439 private:
441 OChannelHopper* _hopper; 440 OChannelHopper* _hopper;
442}; 441};
443 442
444 443
445/*====================================================================================== 444/*======================================================================================
446 * OMonitoringInterface 445 * OMonitoringInterface
447 *======================================================================================*/ 446 *======================================================================================*/
448 447
449 448
450class OMonitoringInterface 449class OMonitoringInterface
451{ 450{
452 public: 451 public:
453 OMonitoringInterface(); 452 OMonitoringInterface();
454 OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 453 OMonitoringInterface( ONetworkInterface*, bool _prismHeader );
455 virtual ~OMonitoringInterface(); 454 virtual ~OMonitoringInterface();
456 455
457 public: 456 public:
458 virtual void setEnabled( bool ); 457 virtual void setEnabled( bool );
459 virtual bool enabled() const;
460 virtual void setChannel( int ); 458 virtual void setChannel( int );
461 459
462 virtual QString name() const = 0; 460 virtual QString name() const = 0;
463 461
464 protected: 462 protected:
465 OWirelessNetworkInterface* _if; 463 OWirelessNetworkInterface* _if;
466 bool _prismHeader; 464 bool _prismHeader;
467 465
468}; 466};
469 467
470 468
471/*====================================================================================== 469/*======================================================================================
472 * OCiscoMonitoring 470 * OCiscoMonitoring
473 *======================================================================================*/ 471 *======================================================================================*/
474 472
475 473
476class OCiscoMonitoringInterface : public OMonitoringInterface 474class OCiscoMonitoringInterface : public OMonitoringInterface
477{ 475{
478 public: 476 public:
479 OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 477 OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader );
480 virtual ~OCiscoMonitoringInterface(); 478 virtual ~OCiscoMonitoringInterface();
481 479
482 virtual void setEnabled( bool ); 480 virtual void setEnabled( bool );
483 virtual QString name() const; 481 virtual QString name() const;
484 virtual void setChannel( int ); 482 virtual void setChannel( int );
485 483
486}; 484};
487 485
488 486
489/*====================================================================================== 487/*======================================================================================
490 * OWlanNGMonitoringInterface 488 * OWlanNGMonitoringInterface
491 *======================================================================================*/ 489 *======================================================================================*/
492 490
493 491
494class OWlanNGMonitoringInterface : public OMonitoringInterface 492class OWlanNGMonitoringInterface : public OMonitoringInterface
495{ 493{
496 public: 494 public:
497 OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 495 OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader );
498 virtual ~OWlanNGMonitoringInterface(); 496 virtual ~OWlanNGMonitoringInterface();
499 497
500 public: 498 public:
501 virtual void setEnabled( bool ); 499 virtual void setEnabled( bool );
502 virtual QString name() const; 500 virtual QString name() const;
503 virtual void setChannel( int ); 501 virtual void setChannel( int );
504 502
505}; 503};
506 504
507 505
508/*====================================================================================== 506/*======================================================================================
509 * OHostAPMonitoringInterface 507 * OHostAPMonitoringInterface
510 *======================================================================================*/ 508 *======================================================================================*/
511 509
512 510
513class OHostAPMonitoringInterface : public OMonitoringInterface 511class OHostAPMonitoringInterface : public OMonitoringInterface
514{ 512{
515 public: 513 public:
516 OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 514 OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader );
517 virtual ~OHostAPMonitoringInterface(); 515 virtual ~OHostAPMonitoringInterface();
518 516
519 public: 517 public:
520 virtual void setEnabled( bool ); 518 virtual void setEnabled( bool );
521 virtual QString name() const; 519 virtual QString name() const;
522 }; 520 };
523 521
524 522
525/*====================================================================================== 523/*======================================================================================
526 * OOrinocoMonitoringInterface 524 * OOrinocoMonitoringInterface
527 *======================================================================================*/ 525 *======================================================================================*/
528 526
529 527
530class OOrinocoMonitoringInterface : public OMonitoringInterface 528class OOrinocoMonitoringInterface : public OMonitoringInterface
531{ 529{
532 public: 530 public:
533 OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 531 OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader );
534 virtual ~OOrinocoMonitoringInterface(); 532 virtual ~OOrinocoMonitoringInterface();
535 533
536 public: 534 public:
537 virtual void setChannel( int ); 535 virtual void setChannel( int );
538 virtual void setEnabled( bool ); 536 virtual void setEnabled( bool );
539 virtual QString name() const; 537 virtual QString name() const;
540 538
541}; 539};
542 540
543#endif // ONETWORK_H 541#endif // ONETWORK_H
544 542