author | mickeyl <mickeyl> | 2003-04-03 14:17:03 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-03 14:17:03 (UTC) |
commit | f62005c53c93148eaa13eac50ea6814a41afb216 (patch) (side-by-side diff) | |
tree | 93e7e626205fd9d06b5ac7c29e78be52ce749e5d /libopie2/opienet | |
parent | e9eeb493c75bfe6078f40952e85e859fb71fe970 (diff) | |
download | opie-f62005c53c93148eaa13eac50ea6814a41afb216.zip opie-f62005c53c93148eaa13eac50ea6814a41afb216.tar.gz opie-f62005c53c93148eaa13eac50ea6814a41afb216.tar.bz2 |
- ONetworkInterfaces are now QObjects
- add support for private IOCTLS
- make buildChannelList() more safe in case of faulty drivers
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 59 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.h | 25 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 127 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 21 |
4 files changed, 178 insertions, 54 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp index 8006f41..3e11b53 100644 --- a/libopie2/opienet/onetutils.cpp +++ b/libopie2/opienet/onetutils.cpp @@ -37,4 +37,14 @@ using namespace std; +#define IW_PRIV_TYPE_MASK 0x7000 +#define IW_PRIV_TYPE_NONE 0x0000 +#define IW_PRIV_TYPE_BYTE 0x1000 +#define IW_PRIV_TYPE_CHAR 0x2000 +#define IW_PRIV_TYPE_INT 0x4000 +#define IW_PRIV_TYPE_FLOAT 0x5000 +#define IW_PRIV_TYPE_ADDR 0x6000 +#define IW_PRIV_SIZE_FIXED 0x0800 +#define IW_PRIV_SIZE_MASK 0x07FF + /*====================================================================================== * OMacAddress @@ -88,4 +98,53 @@ bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) } + +/*====================================================================================== + * OHostAddress + *======================================================================================*/ + + +/*====================================================================================== + * OPrivateIOCTL + *======================================================================================*/ + +OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) + :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) +{ +} + + +OPrivateIOCTL::~OPrivateIOCTL() +{ +} + + +inline int OPrivateIOCTL::numberGetArgs() const +{ + return _getargs & IW_PRIV_SIZE_MASK; +} + + +inline int OPrivateIOCTL::typeGetArgs() const +{ + return _getargs & IW_PRIV_TYPE_MASK >> 12; +} + + +inline int OPrivateIOCTL::numberSetArgs() const +{ + return _setargs & IW_PRIV_SIZE_MASK; +} + + +inline int OPrivateIOCTL::typeSetArgs() const +{ + return _setargs & IW_PRIV_TYPE_MASK >> 12; +} + + +/*====================================================================================== + * assorted functions + *======================================================================================*/ + void dumpBytes( const unsigned char* data, int num ) { diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h index 0dabe8d..6640515 100644 --- a/libopie2/opienet/onetutils.h +++ b/libopie2/opienet/onetutils.h @@ -37,6 +37,10 @@ #include <qstring.h> #include <qhostaddress.h> +#include <qobject.h> + +#include <sys/types.h> struct ifreq; +class OWirelessNetworkInterface; /*====================================================================================== @@ -81,4 +85,25 @@ class OHostAddress : public QHostAddress /*====================================================================================== + * OPrivateIOCTL + *======================================================================================*/ + +class OPrivateIOCTL : public QObject +{ + public: + OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ); + ~OPrivateIOCTL(); + + int numberGetArgs() const; + int typeGetArgs() const; + int numberSetArgs() const; + int typeSetArgs() const; + + private: + u_int32_t _ioctl; + u_int16_t _getargs; + u_int16_t _setargs; +}; + + /*====================================================================================== * Miscellaneous *======================================================================================*/ diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index ac2857a..2548a04 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp @@ -93,10 +93,10 @@ void ONetwork::synchronize() if ( isWirelessInterface( str ) ) { - iface = new OWirelessNetworkInterface( str ); + iface = new OWirelessNetworkInterface( this, str ); qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); } else { - iface = new ONetworkInterface( str ); + iface = new ONetworkInterface( this, str ); } _interfaces.insert( str, iface ); @@ -127,5 +127,5 @@ ONetwork::InterfaceIterator ONetwork::iterator() const bool ONetwork::isWirelessInterface( const char* name ) const { - int sfd = socket( AF_INET, SOCK_DGRAM, 0 ); + int sfd = socket( AF_INET, SOCK_STREAM, 0 ); iwreqstruct iwr; memset( &iwr, 0, sizeof( iwreqstruct ) ); @@ -143,6 +143,7 @@ bool ONetwork::isWirelessInterface( const char* name ) const *======================================================================================*/ -ONetworkInterface::ONetworkInterface( const QString& name ) - :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) +ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) + :QObject( parent, name ), + _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) { qDebug( "ONetworkInterface::ONetworkInterface()" ); @@ -165,5 +166,5 @@ void ONetworkInterface::init() if ( _sfd == -1 ) { - qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name ); + qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); return; } @@ -184,5 +185,5 @@ bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const bool ONetworkInterface::ioctl( int call ) const { - strcpy( _ifr.ifr_name, (const char*) _name ); + strcpy( _ifr.ifr_name, name() ); return ioctl( call, _ifr ); } @@ -241,5 +242,5 @@ void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) { _mon = m; - qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), (const char*) _name ); + qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); } @@ -251,10 +252,4 @@ OMonitoringInterface* ONetworkInterface::monitoring() const -const QString& ONetworkInterface::name() const -{ - return _name; -} - - ONetworkInterface::~ONetworkInterface() { @@ -369,6 +364,6 @@ int OChannelHopper::interval() const *======================================================================================*/ -OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) - :ONetworkInterface( name ), _hopper( 0 ) +OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) + :ONetworkInterface( parent, name ), _hopper( 0 ) { qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); @@ -391,33 +386,7 @@ void OWirelessNetworkInterface::init() { qDebug( "OWirelessNetworkInterface::init()" ); - memset( &_iwr, 0, sizeof( struct iwreq ) ); - - // IEEE802.11(b) radio frequency channels - - iwrangestruct range; - //ML: work around an ugly HostAP bug, which needs - //ML: extra space or will complain with "invalid argument length"... :-( - //ML: But don't allocate too much or prism2_usb will segfault *sigh* - char __extraBufferForBuggyDrivers[20]; - - qDebug( "sizeof(iwrangestruct)=%d, sizeof range=%d, sizeof range*2=%d", sizeof(iwrangestruct), sizeof range, (sizeof range)*2 ); - - _iwr.u.data.pointer = (char*) ⦥ - _iwr.u.data.length = sizeof(iwrangestruct)+20; - _iwr.u.data.flags = 0; - if ( !wioctl( SIOCGIWRANGE ) ) - { - qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); - return; - } - - qDebug( "OWirelessNetworkInterface::init(): Interface %s reported to have %d channels.", (const char*) _name, range.num_frequency ); - - for ( int i = 0; i < range.num_frequency; ++i ) - { - int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); - _channels.insert( freq, i+1 ); - } + buildChannelList(); + buildPrivateList(); } @@ -446,4 +415,71 @@ QString OWirelessNetworkInterface::associatedAP() const +void OWirelessNetworkInterface::buildChannelList() +{ + // IEEE802.11(b) radio frequency channels + struct iw_range range; + + //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck + //ML: The HostAP drivers need more than sizeof struct_iw range to complete + //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". + //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate + //ML: _too much_ space. This is damn shitty crap *sigh* + + _iwr.u.data.pointer = (char*) ⦥ + _iwr.u.data.length = IW_MAX_FREQUENCIES; //sizeof range; + _iwr.u.data.flags = 0; + + if ( !wioctl( SIOCGIWRANGE ) ) + { + qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); + _channels.insert( 2412, 1 ); // 2.412 GHz + _channels.insert( 2417, 2 ); // 2.417 GHz + _channels.insert( 2422, 3 ); // 2.422 GHz + _channels.insert( 2427, 4 ); // 2.427 GHz + _channels.insert( 2432, 5 ); // 2.432 GHz + _channels.insert( 2437, 6 ); // 2.437 GHz + _channels.insert( 2442, 7 ); // 2.442 GHz + _channels.insert( 2447, 8 ); // 2.447 GHz + _channels.insert( 2452, 9 ); // 2.452 GHz + _channels.insert( 2457, 10 ); // 2.457 GHz + _channels.insert( 2462, 11 ); // 2.462 GHz + } + else + { + qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); + for ( int i = 0; i < range.num_frequency; ++i ) + { + int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); + _channels.insert( freq, i+1 ); + } + } + qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); +} + + +void OWirelessNetworkInterface::buildPrivateList() +{ + qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); + + struct iw_priv_args priv[IW_MAX_PRIV_DEF]; + + _iwr.u.data.pointer = (char*) &priv; + _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself + _iwr.u.data.flags = 0; + + if ( !wioctl( SIOCGIWPRIV ) ) + { + qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); + return; + } + + for ( int i = 0; i < _iwr.u.data.length; ++i ) + { + new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); + } + qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); +} + + int OWirelessNetworkInterface::channel() const { @@ -505,4 +541,5 @@ void OWirelessNetworkInterface::setChannelHopping( int interval ) _hopper->setInterval( interval ); //FIXME: When and by whom will the channel hopper be deleted? + //TODO: rely on QObject hierarchy } @@ -583,5 +620,5 @@ bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const bool OWirelessNetworkInterface::wioctl( int call ) const { - strcpy( _iwr.ifr_name, (const char*) _name ); + strcpy( _iwr.ifr_name, name() ); return wioctl( call, _iwr ); } diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index b57ac3f..acf2f69 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h @@ -50,4 +50,7 @@ #define IFNAMSIZ 16 #endif +#ifndef IW_MAX_PRIV_DEF +#define IW_MAX_PRIV_DEF 128 +#endif // ML: Yeah, I hate to include kernel headers, but it's necessary here @@ -109,5 +112,5 @@ class ONetwork : public QObject *======================================================================================*/ -class ONetworkInterface +class ONetworkInterface : public QObject { friend class OMonitoringInterface; @@ -118,8 +121,7 @@ class ONetworkInterface public: - ONetworkInterface( const QString& name ); + ONetworkInterface( QObject* parent, const char* name ); virtual ~ONetworkInterface(); - const QString& name() const; void setMonitoring( OMonitoringInterface* ); OMonitoringInterface* monitoring() const; @@ -134,5 +136,4 @@ class ONetworkInterface protected: - const QString _name; const int _sfd; mutable ifreqstruct _ifr; @@ -186,5 +187,5 @@ class OWirelessNetworkInterface : public ONetworkInterface enum Mode { AdHoc, Managed, Monitor }; - OWirelessNetworkInterface( const QString& name ); + OWirelessNetworkInterface( QObject* parent, const char* name ); virtual ~OWirelessNetworkInterface(); @@ -214,8 +215,6 @@ class OWirelessNetworkInterface : public ONetworkInterface protected: - mutable iwreqstruct _iwr; - QMap<int,int> _channels; - - protected: + void buildChannelList(); + void buildPrivateList(); virtual void init(); iwreqstruct& iwr() const; @@ -223,4 +222,8 @@ class OWirelessNetworkInterface : public ONetworkInterface bool wioctl( int call, iwreqstruct& ) const; + protected: + mutable iwreqstruct _iwr; + QMap<int,int> _channels; + private: OChannelHopper* _hopper; |