-rw-r--r-- | libopie2/opienet/onetwork.cpp | 12 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 10 | ||||
-rw-r--r-- | libopie2/opienet/opcap.cpp | 4 |
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 | |||
@@ -106,33 +106,33 @@ void ONetwork::synchronize() | |||
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 | ||
122 | short ONetwork::wirelessExtensionVersion() | 122 | short ONetwork::wirelessExtensionCompileVersion() |
123 | { | 123 | { |
124 | return WIRELESS_EXT; | 124 | return WIRELESS_EXT; |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | int ONetwork::count() const | 128 | int ONetwork::count() const |
129 | { | 129 | { |
130 | return _interfaces.count(); | 130 | return _interfaces.count(); |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 134 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
135 | { | 135 | { |
136 | return _interfaces[iface]; | 136 | return _interfaces[iface]; |
137 | } | 137 | } |
138 | 138 | ||
@@ -369,50 +369,49 @@ bool ONetworkInterface::promiscuousMode() const | |||
369 | 369 | ||
370 | 370 | ||
371 | bool ONetworkInterface::isWireless() const | 371 | bool 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 | ||
381 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 381 | OChannelHopper::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 | ||
406 | OChannelHopper::~OChannelHopper() | 405 | OChannelHopper::~OChannelHopper() |
407 | { | 406 | { |
408 | } | 407 | } |
409 | 408 | ||
410 | 409 | ||
411 | bool OChannelHopper::isActive() const | 410 | bool OChannelHopper::isActive() const |
412 | { | 411 | { |
413 | return _tid; | 412 | return _tid; |
414 | } | 413 | } |
415 | 414 | ||
416 | 415 | ||
417 | int OChannelHopper::channel() const | 416 | int OChannelHopper::channel() const |
418 | { | 417 | { |
@@ -548,42 +547,49 @@ void OWirelessNetworkInterface::buildInformation() | |||
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 | ||
574 | short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const | ||
575 | { | ||
576 | return _range.we_version_compiled; | ||
577 | } | ||
578 | |||
579 | |||
574 | void OWirelessNetworkInterface::buildPrivateList() | 580 | void 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 | ||
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 | |||
@@ -112,33 +112,33 @@ class ONetwork : public QObject | |||
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 | ||
@@ -438,34 +438,38 @@ class OWirelessNetworkInterface : public ONetworkInterface | |||
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; |
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 | |||
@@ -45,35 +45,35 @@ using namespace Opie::Core; | |||
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 | ||
50 | namespace Opie { | 50 | namespace Opie { |
51 | namespace Net { | 51 | namespace Net { |
52 | 52 | ||
53 | /*====================================================================================== | 53 | /*====================================================================================== |
54 | * OPacket | 54 | * OPacket |
55 | *======================================================================================*/ | 55 | *======================================================================================*/ |
56 | 56 | ||
57 | OPacket::OPacket( int datalink, packetheaderstruct header, const unsigned char* data, QObject* parent ) | 57 | OPacket::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; |