summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-05-01 16:13:43 (UTC)
committer mickeyl <mickeyl>2004-05-01 16:13:43 (UTC)
commitd5abd7878f553f5ac0a41966b27f4c09389d3cfd (patch) (unidiff)
tree3140d1d1fe012c03c6c26bc587faeea5501f0b28
parent5a64ec5a21bb254c0e6a57e379cd1afc25259f19 (diff)
downloadopie-d5abd7878f553f5ac0a41966b27f4c09389d3cfd.zip
opie-d5abd7878f553f5ac0a41966b27f4c09389d3cfd.tar.gz
opie-d5abd7878f553f5ac0a41966b27f4c09389d3cfd.tar.bz2
- fix off-by-one bug in OChannelHopper
- fix bug in OPacket which broke everything using it - expose both wireless extension versions (runtime + compile time) through API
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp12
-rw-r--r--libopie2/opienet/onetwork.h10
-rw-r--r--libopie2/opienet/opcap.cpp4
3 files changed, 18 insertions, 8 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index b6c9876..e141097 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -74,97 +74,97 @@ ONetwork* ONetwork::_instance = 0;
74 74
75ONetwork::ONetwork() 75ONetwork::ONetwork()
76{ 76{
77 odebug << "ONetwork::ONetwork()" << oendl; 77 odebug << "ONetwork::ONetwork()" << oendl;
78 odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; 78 odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl;
79 synchronize(); 79 synchronize();
80} 80}
81 81
82void ONetwork::synchronize() 82void ONetwork::synchronize()
83{ 83{
84 // gather available interfaces by inspecting /proc/net/dev 84 // gather available interfaces by inspecting /proc/net/dev
85 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 85 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
86 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 86 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
87 //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev 87 //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev
88 88
89 _interfaces.clear(); 89 _interfaces.clear();
90 QString str; 90 QString str;
91 QFile f( "/proc/net/dev" ); 91 QFile f( "/proc/net/dev" );
92 bool hasFile = f.open( IO_ReadOnly ); 92 bool hasFile = f.open( IO_ReadOnly );
93 if ( !hasFile ) 93 if ( !hasFile )
94 { 94 {
95 odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; 95 odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl;
96 return; 96 return;
97 } 97 }
98 QTextStream s( &f ); 98 QTextStream s( &f );
99 s.readLine(); 99 s.readLine();
100 s.readLine(); 100 s.readLine();
101 while ( !s.atEnd() ) 101 while ( !s.atEnd() )
102 { 102 {
103 s >> str; 103 s >> str;
104 str.truncate( str.find( ':' ) ); 104 str.truncate( str.find( ':' ) );
105 odebug << "ONetwork: found interface '" << str << "'" << oendl; 105 odebug << "ONetwork: found interface '" << str << "'" << oendl;
106 ONetworkInterface* iface = 0; 106 ONetworkInterface* iface = 0;
107 if ( isWirelessInterface( str ) ) 107 if ( isWirelessInterface( str ) )
108 { 108 {
109 iface = new OWirelessNetworkInterface( this, (const char*) str ); 109 iface = new OWirelessNetworkInterface( this, (const char*) str );
110 odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; 110 odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl;
111 } 111 }
112 else 112 else
113 { 113 {
114 iface = new ONetworkInterface( this, (const char*) str ); 114 iface = new ONetworkInterface( this, (const char*) str );
115 } 115 }
116 _interfaces.insert( str, iface ); 116 _interfaces.insert( str, iface );
117 s.readLine(); 117 s.readLine();
118 } 118 }
119} 119}
120 120
121 121
122short ONetwork::wirelessExtensionVersion() 122short ONetwork::wirelessExtensionCompileVersion()
123{ 123{
124 return WIRELESS_EXT; 124 return WIRELESS_EXT;
125} 125}
126 126
127 127
128int ONetwork::count() const 128int ONetwork::count() const
129{ 129{
130 return _interfaces.count(); 130 return _interfaces.count();
131} 131}
132 132
133 133
134ONetworkInterface* ONetwork::interface( const QString& iface ) const 134ONetworkInterface* ONetwork::interface( const QString& iface ) const
135{ 135{
136 return _interfaces[iface]; 136 return _interfaces[iface];
137} 137}
138 138
139 139
140ONetwork* ONetwork::instance() 140ONetwork* ONetwork::instance()
141{ 141{
142 if ( !_instance ) _instance = new ONetwork(); 142 if ( !_instance ) _instance = new ONetwork();
143 return _instance; 143 return _instance;
144} 144}
145 145
146 146
147ONetwork::InterfaceIterator ONetwork::iterator() const 147ONetwork::InterfaceIterator ONetwork::iterator() const
148{ 148{
149 return ONetwork::InterfaceIterator( _interfaces ); 149 return ONetwork::InterfaceIterator( _interfaces );
150} 150}
151 151
152 152
153bool ONetwork::isPresent( const char* name ) const 153bool ONetwork::isPresent( const char* name ) const
154{ 154{
155 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 155 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
156 struct ifreq ifr; 156 struct ifreq ifr;
157 memset( &ifr, 0, sizeof( struct ifreq ) ); 157 memset( &ifr, 0, sizeof( struct ifreq ) );
158 strcpy( (char*) &ifr.ifr_name, name ); 158 strcpy( (char*) &ifr.ifr_name, name );
159 int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr ); 159 int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr );
160 return result != -1; 160 return result != -1;
161} 161}
162 162
163 163
164bool ONetwork::isWirelessInterface( const char* name ) const 164bool ONetwork::isWirelessInterface( const char* name ) const
165{ 165{
166 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 166 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
167 struct iwreq iwr; 167 struct iwreq iwr;
168 memset( &iwr, 0, sizeof( struct iwreq ) ); 168 memset( &iwr, 0, sizeof( struct iwreq ) );
169 strcpy( (char*) &iwr.ifr_name, name ); 169 strcpy( (char*) &iwr.ifr_name, name );
170 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 170 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
@@ -337,114 +337,113 @@ void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
337 _mon = m; 337 _mon = m;
338 odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl; 338 odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl;
339} 339}
340 340
341 341
342OMonitoringInterface* ONetworkInterface::monitoring() const 342OMonitoringInterface* ONetworkInterface::monitoring() const
343{ 343{
344 return _mon; 344 return _mon;
345} 345}
346 346
347 347
348ONetworkInterface::~ONetworkInterface() 348ONetworkInterface::~ONetworkInterface()
349{ 349{
350 odebug << "ONetworkInterface::~ONetworkInterface()" << oendl; 350 odebug << "ONetworkInterface::~ONetworkInterface()" << oendl;
351 if ( _sfd != -1 ) ::close( _sfd ); 351 if ( _sfd != -1 ) ::close( _sfd );
352} 352}
353 353
354 354
355bool ONetworkInterface::setPromiscuousMode( bool b ) 355bool ONetworkInterface::setPromiscuousMode( bool b )
356{ 356{
357 ioctl( SIOCGIFFLAGS ); 357 ioctl( SIOCGIFFLAGS );
358 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 358 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
359 else _ifr.ifr_flags &= (~IFF_PROMISC); 359 else _ifr.ifr_flags &= (~IFF_PROMISC);
360 return ioctl( SIOCSIFFLAGS ); 360 return ioctl( SIOCSIFFLAGS );
361} 361}
362 362
363 363
364bool ONetworkInterface::promiscuousMode() const 364bool ONetworkInterface::promiscuousMode() const
365{ 365{
366 ioctl( SIOCGIFFLAGS ); 366 ioctl( SIOCGIFFLAGS );
367 return _ifr.ifr_flags & IFF_PROMISC; 367 return _ifr.ifr_flags & IFF_PROMISC;
368} 368}
369 369
370 370
371bool ONetworkInterface::isWireless() const 371bool ONetworkInterface::isWireless() const
372{ 372{
373 return ioctl( SIOCGIWNAME ); 373 return ioctl( SIOCGIWNAME );
374} 374}
375 375
376 376
377/*====================================================================================== 377/*======================================================================================
378 * OChannelHopper 378 * OChannelHopper
379 *======================================================================================*/ 379 *======================================================================================*/
380 380
381OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 381OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
382 :QObject( 0, "Mickey's funky hopper" ), 382 :QObject( 0, "Mickey's funky hopper" ),
383 _iface( iface ), _interval( 0 ), _tid( 0 ) 383 _iface( iface ), _interval( 0 ), _tid( 0 )
384{ 384{
385 int _maxChannel = iface->channels()+1; 385 int _maxChannel = iface->channels();
386 // generate fancy hopping sequence honoring the device capabilities 386 // generate fancy hopping sequence honoring the device capabilities
387 if ( _maxChannel >= 1 ) _channels.append( 1 ); 387 if ( _maxChannel >= 1 ) _channels.append( 1 );
388 if ( _maxChannel >= 7 ) _channels.append( 7 ); 388 if ( _maxChannel >= 7 ) _channels.append( 7 );
389 if ( _maxChannel >= 13 ) _channels.append( 13 ); 389 if ( _maxChannel >= 13 ) _channels.append( 13 );
390 if ( _maxChannel >= 2 ) _channels.append( 2 ); 390 if ( _maxChannel >= 2 ) _channels.append( 2 );
391 if ( _maxChannel >= 8 ) _channels.append( 8 ); 391 if ( _maxChannel >= 8 ) _channels.append( 8 );
392 if ( _maxChannel >= 3 ) _channels.append( 3 ); 392 if ( _maxChannel >= 3 ) _channels.append( 3 );
393 if ( _maxChannel >= 14 ) _channels.append( 14 ); 393 if ( _maxChannel >= 14 ) _channels.append( 14 );
394 if ( _maxChannel >= 9 ) _channels.append( 9 ); 394 if ( _maxChannel >= 9 ) _channels.append( 9 );
395 if ( _maxChannel >= 4 ) _channels.append( 4 ); 395 if ( _maxChannel >= 4 ) _channels.append( 4 );
396 if ( _maxChannel >= 10 ) _channels.append( 10 ); 396 if ( _maxChannel >= 10 ) _channels.append( 10 );
397 if ( _maxChannel >= 5 ) _channels.append( 5 ); 397 if ( _maxChannel >= 5 ) _channels.append( 5 );
398 if ( _maxChannel >= 11 ) _channels.append( 11 ); 398 if ( _maxChannel >= 11 ) _channels.append( 11 );
399 if ( _maxChannel >= 6 ) _channels.append( 6 ); 399 if ( _maxChannel >= 6 ) _channels.append( 6 );
400 if ( _maxChannel >= 12 ) _channels.append( 12 ); 400 if ( _maxChannel >= 12 ) _channels.append( 12 );
401 _channel = _channels.begin(); 401 _channel = _channels.begin();
402
403} 402}
404 403
405 404
406OChannelHopper::~OChannelHopper() 405OChannelHopper::~OChannelHopper()
407{ 406{
408} 407}
409 408
410 409
411bool OChannelHopper::isActive() const 410bool OChannelHopper::isActive() const
412{ 411{
413 return _tid; 412 return _tid;
414} 413}
415 414
416 415
417int OChannelHopper::channel() const 416int OChannelHopper::channel() const
418{ 417{
419 return *_channel; 418 return *_channel;
420} 419}
421 420
422 421
423void OChannelHopper::timerEvent( QTimerEvent* ) 422void OChannelHopper::timerEvent( QTimerEvent* )
424{ 423{
425 _iface->setChannel( *_channel ); 424 _iface->setChannel( *_channel );
426 emit( hopped( *_channel ) ); 425 emit( hopped( *_channel ) );
427 odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl; 426 odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl;
428 if ( ++_channel == _channels.end() ) _channel = _channels.begin(); 427 if ( ++_channel == _channels.end() ) _channel = _channels.begin();
429} 428}
430 429
431 430
432void OChannelHopper::setInterval( int interval ) 431void OChannelHopper::setInterval( int interval )
433{ 432{
434 if ( interval == _interval ) 433 if ( interval == _interval )
435 return; 434 return;
436 435
437 if ( _interval ) 436 if ( _interval )
438 killTimer( _tid ); 437 killTimer( _tid );
439 438
440 _tid = 0; 439 _tid = 0;
441 _interval = interval; 440 _interval = interval;
442 441
443 if ( _interval ) 442 if ( _interval )
444 { 443 {
445 _tid = startTimer( interval ); 444 _tid = startTimer( interval );
446 } 445 }
447} 446}
448 447
449 448
450int OChannelHopper::interval() const 449int OChannelHopper::interval() const
@@ -516,106 +515,113 @@ void OWirelessNetworkInterface::buildInformation()
516 struct iwreq wrq; 515 struct iwreq wrq;
517 int len = sizeof( struct iw_range )*2; 516 int len = sizeof( struct iw_range )*2;
518 char *buffer = (char*) malloc( len ); 517 char *buffer = (char*) malloc( len );
519 //FIXME: Validate if we actually got the memory block 518 //FIXME: Validate if we actually got the memory block
520 memset( buffer, 0, len ); 519 memset( buffer, 0, len );
521 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 520 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
522 wrq.u.data.pointer = (caddr_t) buffer; 521 wrq.u.data.pointer = (caddr_t) buffer;
523 wrq.u.data.length = sizeof( struct iw_range ); 522 wrq.u.data.length = sizeof( struct iw_range );
524 wrq.u.data.flags = 0; 523 wrq.u.data.flags = 0;
525 524
526 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 525 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
527 { 526 {
528 owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl; 527 owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl;
529 _channels.insert( 2412, 1 ); // 2.412 GHz 528 _channels.insert( 2412, 1 ); // 2.412 GHz
530 _channels.insert( 2417, 2 ); // 2.417 GHz 529 _channels.insert( 2417, 2 ); // 2.417 GHz
531 _channels.insert( 2422, 3 ); // 2.422 GHz 530 _channels.insert( 2422, 3 ); // 2.422 GHz
532 _channels.insert( 2427, 4 ); // 2.427 GHz 531 _channels.insert( 2427, 4 ); // 2.427 GHz
533 _channels.insert( 2432, 5 ); // 2.432 GHz 532 _channels.insert( 2432, 5 ); // 2.432 GHz
534 _channels.insert( 2437, 6 ); // 2.437 GHz 533 _channels.insert( 2437, 6 ); // 2.437 GHz
535 _channels.insert( 2442, 7 ); // 2.442 GHz 534 _channels.insert( 2442, 7 ); // 2.442 GHz
536 _channels.insert( 2447, 8 ); // 2.447 GHz 535 _channels.insert( 2447, 8 ); // 2.447 GHz
537 _channels.insert( 2452, 9 ); // 2.452 GHz 536 _channels.insert( 2452, 9 ); // 2.452 GHz
538 _channels.insert( 2457, 10 ); // 2.457 GHz 537 _channels.insert( 2457, 10 ); // 2.457 GHz
539 _channels.insert( 2462, 11 ); // 2.462 GHz 538 _channels.insert( 2462, 11 ); // 2.462 GHz
540 539
541 memset( &_range, 0, sizeof( struct iw_range ) ); 540 memset( &_range, 0, sizeof( struct iw_range ) );
542 } 541 }
543 else 542 else
544 { 543 {
545 // <check if the driver overwrites stuff> 544 // <check if the driver overwrites stuff>
546 int max = 0; 545 int max = 0;
547 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 546 for ( int r = sizeof( struct iw_range ); r < len; r++ )
548 if (buffer[r] != 0) 547 if (buffer[r] != 0)
549 max = r; 548 max = r;
550 if (max > 0) 549 if (max > 0)
551 { 550 {
552 owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() 551 owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name()
553 << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; 552 << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl;
554 } 553 }
555 // </check if the driver overwrites stuff> 554 // </check if the driver overwrites stuff>
556 555
557 struct iw_range range; 556 struct iw_range range;
558 memcpy( &range, buffer, sizeof range ); 557 memcpy( &range, buffer, sizeof range );
559 558
560 odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; 559 odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl;
561 for ( int i = 0; i < range.num_frequency; ++i ) 560 for ( int i = 0; i < range.num_frequency; ++i )
562 { 561 {
563 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 562 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
563 odebug << "OWirelessNetworkInterface::buildInformation: Adding frequency " << freq << " as channel " << i+1 << oendl;
564 _channels.insert( freq, i+1 ); 564 _channels.insert( freq, i+1 );
565 } 565 }
566 } 566 }
567 567
568 memcpy( &_range, buffer, sizeof( struct iw_range ) ); 568 memcpy( &_range, buffer, sizeof( struct iw_range ) );
569 odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; 569 odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl;
570 free(buffer); 570 free(buffer);
571} 571}
572 572
573 573
574short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const
575{
576 return _range.we_version_compiled;
577}
578
579
574void OWirelessNetworkInterface::buildPrivateList() 580void OWirelessNetworkInterface::buildPrivateList()
575{ 581{
576 odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; 582 odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl;
577 583
578 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 584 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
579 585
580 _iwr.u.data.pointer = (char*) &priv; 586 _iwr.u.data.pointer = (char*) &priv;
581 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 587 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
582 _iwr.u.data.flags = 0; 588 _iwr.u.data.flags = 0;
583 589
584 if ( !wioctl( SIOCGIWPRIV ) ) 590 if ( !wioctl( SIOCGIWPRIV ) )
585 { 591 {
586 owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; 592 owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl;
587 return; 593 return;
588 } 594 }
589 595
590 for ( int i = 0; i < _iwr.u.data.length; ++i ) 596 for ( int i = 0; i < _iwr.u.data.length; ++i )
591 { 597 {
592 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 598 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
593 } 599 }
594 odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; 600 odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl;
595} 601}
596 602
597 603
598void OWirelessNetworkInterface::dumpInformation() const 604void OWirelessNetworkInterface::dumpInformation() const
599{ 605{
600 odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; 606 odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl;
601 607
602 qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", 608 qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s",
603 _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ); 609 _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 );
604 qDebug( " - driver for '%s' (V%d) has been compiled against WE V%d", 610 qDebug( " - driver for '%s' (V%d) has been compiled against WE V%d",
605 name(), _range.we_version_source, _range.we_version_compiled ); 611 name(), _range.we_version_source, _range.we_version_compiled );
606 612
607 if ( _range.we_version_compiled != WIRELESS_EXT ) 613 if ( _range.we_version_compiled != WIRELESS_EXT )
608 { 614 {
609 owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; 615 owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl;
610 } 616 }
611 617
612 odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; 618 odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl;
613} 619}
614 620
615 621
616int OWirelessNetworkInterface::channel() const 622int OWirelessNetworkInterface::channel() const
617{ 623{
618 //FIXME: When monitoring enabled, then use it 624 //FIXME: When monitoring enabled, then use it
619 //FIXME: to gather the current RF channel 625 //FIXME: to gather the current RF channel
620 //FIXME: Until then, get active channel from hopper. 626 //FIXME: Until then, get active channel from hopper.
621 if ( _hopper && _hopper->isActive() ) 627 if ( _hopper && _hopper->isActive() )
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index f5fbe1d..a49c8fb 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -80,97 +80,97 @@ class OMonitoringInterface;
80 * 80 *
81 * This class provides access to all available network interfaces of your computer. 81 * This class provides access to all available network interfaces of your computer.
82 * 82 *
83 * @author Michael 'Mickey' Lauer <mickey@vanille.de> 83 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
84 */ 84 */
85class ONetwork : public QObject 85class ONetwork : public QObject
86{ 86{
87 Q_OBJECT 87 Q_OBJECT
88 88
89 public: 89 public:
90 typedef QDict<ONetworkInterface> InterfaceMap; 90 typedef QDict<ONetworkInterface> InterfaceMap;
91 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 91 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
92 92
93 public: 93 public:
94 /** 94 /**
95 * @returns the number of available interfaces 95 * @returns the number of available interfaces
96 */ 96 */
97 int count() const; 97 int count() const;
98 /** 98 /**
99 * @returns a pointer to the (one and only) @ref ONetwork instance. 99 * @returns a pointer to the (one and only) @ref ONetwork instance.
100 */ 100 */
101 static ONetwork* instance(); 101 static ONetwork* instance();
102 /** 102 /**
103 * @returns an iterator usable for iterating through all network interfaces. 103 * @returns an iterator usable for iterating through all network interfaces.
104 */ 104 */
105 InterfaceIterator iterator() const; 105 InterfaceIterator iterator() const;
106 /** 106 /**
107 * @returns true, if the @a interface is present. 107 * @returns true, if the @a interface is present.
108 */ 108 */
109 bool isPresent( const char* interface ) const; 109 bool isPresent( const char* interface ) const;
110 /** 110 /**
111 * @returns true, if the @a interface supports the wireless extension protocol. 111 * @returns true, if the @a interface supports the wireless extension protocol.
112 */ 112 */
113 bool isWirelessInterface( const char* interface ) const; 113 bool isWirelessInterface( const char* interface ) const;
114 /** 114 /**
115 * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. 115 * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found.
116 * @see ONetworkInterface 116 * @see ONetworkInterface
117 */ 117 */
118 ONetworkInterface* interface( const QString& interface ) const; 118 ONetworkInterface* interface( const QString& interface ) const;
119 /** 119 /**
120 * @internal Rebuild the internal interface database 120 * @internal Rebuild the internal interface database
121 * @note Sometimes it might be useful to call this from client code, 121 * @note Sometimes it might be useful to call this from client code,
122 * e.g. after issuing a cardctl insert 122 * e.g. after issuing a cardctl insert
123 */ 123 */
124 void synchronize(); 124 void synchronize();
125 /** 125 /**
126 * @returns the wireless extension version used at compile time. 126 * @returns the wireless extension version used at compile time.
127 **/ 127 **/
128 static short wirelessExtensionVersion(); 128 static short wirelessExtensionCompileVersion();
129 129
130 protected: 130 protected:
131 ONetwork(); 131 ONetwork();
132 132
133 private: 133 private:
134 static ONetwork* _instance; 134 static ONetwork* _instance;
135 InterfaceMap _interfaces; 135 InterfaceMap _interfaces;
136 class Private; 136 class Private;
137 Private *d; 137 Private *d;
138}; 138};
139 139
140 140
141/*====================================================================================== 141/*======================================================================================
142 * ONetworkInterface 142 * ONetworkInterface
143 *======================================================================================*/ 143 *======================================================================================*/
144 144
145/** 145/**
146 * @brief A network interface wrapper. 146 * @brief A network interface wrapper.
147 * 147 *
148 * This class provides a wrapper for a network interface. All the cumbersume details of 148 * This class provides a wrapper for a network interface. All the cumbersume details of
149 * Linux ioctls are hidden under a convenient high-level interface. 149 * Linux ioctls are hidden under a convenient high-level interface.
150 * @warning Most of the setting methods contained in this class require the appropriate 150 * @warning Most of the setting methods contained in this class require the appropriate
151 * process permissions to work. 151 * process permissions to work.
152 * 152 *
153 * @author Michael 'Mickey' Lauer <mickey@vanille.de> 153 * @author Michael 'Mickey' Lauer <mickey@vanille.de>
154 */ 154 */
155class ONetworkInterface : public QObject 155class ONetworkInterface : public QObject
156{ 156{
157 friend class OMonitoringInterface; 157 friend class OMonitoringInterface;
158 friend class OCiscoMonitoringInterface; 158 friend class OCiscoMonitoringInterface;
159 friend class OWlanNGMonitoringInterface; 159 friend class OWlanNGMonitoringInterface;
160 friend class OHostAPMonitoringInterface; 160 friend class OHostAPMonitoringInterface;
161 friend class OOrinocoMonitoringInterface; 161 friend class OOrinocoMonitoringInterface;
162 162
163 public: 163 public:
164 /** 164 /**
165 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, 165 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself,
166 * but access them via @ref ONetwork::interface(). 166 * but access them via @ref ONetwork::interface().
167 */ 167 */
168 ONetworkInterface( QObject* parent, const char* name ); 168 ONetworkInterface( QObject* parent, const char* name );
169 /** 169 /**
170 * Destructor. 170 * Destructor.
171 */ 171 */
172 virtual ~ONetworkInterface(); 172 virtual ~ONetworkInterface();
173 /** 173 /**
174 * Associates a @a monitoring interface with this network interface. 174 * Associates a @a monitoring interface with this network interface.
175 * @note This is currently only useful with @ref OWirelessNetworkInterface objects. 175 * @note This is currently only useful with @ref OWirelessNetworkInterface objects.
176 */ 176 */
@@ -406,98 +406,102 @@ class OWirelessNetworkInterface : public ONetworkInterface
406 /** 406 /**
407 * Set the station @a nickname. 407 * Set the station @a nickname.
408 */ 408 */
409 virtual void setNickName( const QString& nickname ); 409 virtual void setNickName( const QString& nickname );
410 /** 410 /**
411 * @returns the current station nickname. 411 * @returns the current station nickname.
412 */ 412 */
413 virtual QString nickName() const; 413 virtual QString nickName() const;
414 /** 414 /**
415 * Invoke the private IOCTL @a command with a @number of parameters on the network interface. 415 * Invoke the private IOCTL @a command with a @number of parameters on the network interface.
416 * @see OPrivateIOCTL 416 * @see OPrivateIOCTL
417 */ 417 */
418 virtual void setPrivate( const QString& command, int number, ... ); 418 virtual void setPrivate( const QString& command, int number, ... );
419 /** 419 /**
420 * @returns true if the interface is featuring the private IOCTL @command. 420 * @returns true if the interface is featuring the private IOCTL @command.
421 */ 421 */
422 virtual bool hasPrivate( const QString& command ); 422 virtual bool hasPrivate( const QString& command );
423 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this 423 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this
424 /** 424 /**
425 * @returns true if the interface is associated to an access point 425 * @returns true if the interface is associated to an access point
426 * @note: This information is only valid if the interface is in managed mode. 426 * @note: This information is only valid if the interface is in managed mode.
427 */ 427 */
428 virtual bool isAssociated() const; 428 virtual bool isAssociated() const;
429 /** 429 /**
430 * @returns the MAC address of the Access Point if the device is in infrastructure mode. 430 * @returns the MAC address of the Access Point if the device is in infrastructure mode.
431 * @returns a (more or less random) cell ID address if the device is in adhoc mode. 431 * @returns a (more or less random) cell ID address if the device is in adhoc mode.
432 */ 432 */
433 virtual OMacAddress associatedAP() const; 433 virtual OMacAddress associatedAP() const;
434 /** 434 /**
435 * Set the @a ssid (Service Set ID) string. This is used to decide 435 * Set the @a ssid (Service Set ID) string. This is used to decide
436 * which network to associate with (use "any" to let the driver decide). 436 * which network to associate with (use "any" to let the driver decide).
437 */ 437 */
438 virtual void setSSID( const QString& ssid ); 438 virtual void setSSID( const QString& ssid );
439 /** 439 /**
440 * @returns the current SSID (Service Set ID). 440 * @returns the current SSID (Service Set ID).
441 */ 441 */
442 virtual QString SSID() const; 442 virtual QString SSID() const;
443 /** 443 /**
444 * Perform scanning the wireless network neighbourhood. 444 * Perform scanning the wireless network neighbourhood.
445 * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! 445 * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE!
446 */ 446 */
447 virtual OStationList* scanNetwork(); 447 virtual OStationList* scanNetwork();
448 /** 448 /**
449 * @return signal strength to associated neighbour (in percent). 449 * @return signal strength to associated neighbour (in percent).
450 * In infrastructure mode, this is the signal strength of the Access Point. 450 * In infrastructure mode, this is the signal strength of the Access Point.
451 * In other modes the result is driver dependent. 451 * In other modes the result is driver dependent.
452 */ 452 */
453 virtual int signalStrength() const; 453 virtual int signalStrength() const;
454 /** @internal commit pending changes to the driver 454 /**
455 * 455 * @returns the wireless extension version used by the interface driver.
456 **/
457 short wirelessExtensionDriverVersion() const;
458 /**
459 * @internal commit pending changes to the driver
456 */ 460 */
457 void commit() const; 461 void commit() const;
458 462
459 protected: 463 protected:
460 void buildInformation(); 464 void buildInformation();
461 void buildPrivateList(); 465 void buildPrivateList();
462 void dumpInformation() const; 466 void dumpInformation() const;
463 virtual void init(); 467 virtual void init();
464 struct iwreq& iwr() const; 468 struct iwreq& iwr() const;
465 bool wioctl( int call ) const; 469 bool wioctl( int call ) const;
466 bool wioctl( int call, struct iwreq& ) const; 470 bool wioctl( int call, struct iwreq& ) const;
467 471
468 protected: 472 protected:
469 mutable struct iwreq _iwr; 473 mutable struct iwreq _iwr;
470 QMap<int,int> _channels; 474 QMap<int,int> _channels;
471 struct iw_range _range; 475 struct iw_range _range;
472 476
473 private: 477 private:
474 OChannelHopper* _hopper; 478 OChannelHopper* _hopper;
475 class Private; 479 class Private;
476 Private *d; 480 Private *d;
477}; 481};
478 482
479 483
480/*====================================================================================== 484/*======================================================================================
481 * OMonitoringInterface 485 * OMonitoringInterface
482 *======================================================================================*/ 486 *======================================================================================*/
483 487
484 488
485class OMonitoringInterface 489class OMonitoringInterface
486{ 490{
487 public: 491 public:
488 OMonitoringInterface(); 492 OMonitoringInterface();
489 OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); 493 OMonitoringInterface( ONetworkInterface*, bool _prismHeader );
490 virtual ~OMonitoringInterface(); 494 virtual ~OMonitoringInterface();
491 495
492 public: 496 public:
493 virtual void setEnabled( bool ); 497 virtual void setEnabled( bool );
494 virtual void setChannel( int ); 498 virtual void setChannel( int );
495 499
496 virtual QString name() const = 0; 500 virtual QString name() const = 0;
497 501
498 protected: 502 protected:
499 OWirelessNetworkInterface* _if; 503 OWirelessNetworkInterface* _if;
500 bool _prismHeader; 504 bool _prismHeader;
501 private: 505 private:
502 class Private; 506 class Private;
503 Private *d; 507 Private *d;
diff --git a/libopie2/opienet/opcap.cpp b/libopie2/opienet/opcap.cpp
index f8ebe6b..a9dc577 100644
--- a/libopie2/opienet/opcap.cpp
+++ b/libopie2/opienet/opcap.cpp
@@ -13,99 +13,99 @@
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#include "udp_ports.h" 31#include "udp_ports.h"
32#include "opcap.h" 32#include "opcap.h"
33 33
34/* OPIE */ 34/* OPIE */
35#include <opie2/odebug.h> 35#include <opie2/odebug.h>
36using namespace Opie::Core; 36using namespace Opie::Core;
37 37
38/* QT */ 38/* QT */
39#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects) 39#include <qapplication.h> // don't use oapplication here (will decrease reusability in other projects)
40#include <qsocketnotifier.h> 40#include <qsocketnotifier.h>
41#include <qobjectlist.h> 41#include <qobjectlist.h>
42 42
43/* STD */ 43/* STD */
44#include <sys/time.h> 44#include <sys/time.h>
45#include <sys/types.h> 45#include <sys/types.h>
46#include <assert.h> 46#include <assert.h>
47#include <unistd.h> 47#include <unistd.h>
48#include <string.h> 48#include <string.h>
49 49
50namespace Opie { 50namespace Opie {
51namespace Net { 51namespace Net {
52 52
53/*====================================================================================== 53/*======================================================================================
54 * OPacket 54 * OPacket
55 *======================================================================================*/ 55 *======================================================================================*/
56 56
57OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) 57OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent )
58 :QObject( parent, "Generic" ), _hdr( header ), _data( 0 ) 58 :QObject( parent, "Generic" ), _hdr( header ), _data( 0 )
59{ 59{
60 60
61 _data = new unsigned char[sizeof data]; 61 _data = new unsigned char[ header.len ];
62 assert( _data ); 62 assert( _data );
63 memcpy( const_cast<unsigned char*>(_data), data, sizeof data ); 63 memcpy( const_cast<unsigned char*>(_data), data, header.len );
64 // We have to copy the data structure here, because the 'data' pointer handed by libpcap 64 // We have to copy the data structure here, because the 'data' pointer handed by libpcap
65 // points to an internal region which is reused by lipcap. 65 // points to an internal region which is reused by lipcap.
66 odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl; 66 odebug << "OPacket: Length = " << header.len << ", Caplen = " << header.caplen << oendl;
67 _end = (unsigned char*) _data + header.len; 67 _end = (unsigned char*) _data + header.len;
68 68
69 switch ( datalink ) 69 switch ( datalink )
70 { 70 {
71 case DLT_EN10MB: 71 case DLT_EN10MB:
72 odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl; 72 odebug << "OPacket::OPacket(): Received Packet. Datalink = ETHERNET" << oendl;
73 new OEthernetPacket( _end, (const struct ether_header*) _data, this ); 73 new OEthernetPacket( _end, (const struct ether_header*) _data, this );
74 break; 74 break;
75 75
76 case DLT_IEEE802_11: 76 case DLT_IEEE802_11:
77 odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl; 77 odebug << "OPacket::OPacket(): Received Packet. Datalink = IEEE802.11" << oendl;
78 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this ); 78 new OWaveLanPacket( _end, (const struct ieee_802_11_header*) _data, this );
79 break; 79 break;
80 80
81 case DLT_PRISM_HEADER: 81 case DLT_PRISM_HEADER:
82 odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl; 82 odebug << "OPacket::OPacket(): Received Packet. Datalink = PRISM_HEADER" << oendl;
83 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this ); 83 new OPrismHeaderPacket( _end, (const struct prism_hdr*) (unsigned char*) _data, this );
84 break; 84 break;
85 85
86 default: 86 default:
87 owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl; 87 owarn << "OPacket::OPacket(): Received Packet over unsupported datalink, type " << datalink << "!" << oendl;
88 } 88 }
89} 89}
90 90
91 91
92OPacket::~OPacket() 92OPacket::~OPacket()
93{ 93{
94 odebug << "~OPacket( " << name() << " )" << oendl; 94 odebug << "~OPacket( " << name() << " )" << oendl;
95 delete _data; 95 delete _data;
96} 96}
97 97
98 98
99timevalstruct OPacket::timeval() const 99timevalstruct OPacket::timeval() const
100{ 100{
101 return _hdr.ts; 101 return _hdr.ts;
102} 102}
103 103
104 104
105int OPacket::caplen() const 105int OPacket::caplen() const
106{ 106{
107 return _hdr.caplen; 107 return _hdr.caplen;
108} 108}
109 109
110 110
111void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l ) 111void OPacket::updateStats( QMap<QString,int>& stats, QObjectList* l )