summaryrefslogtreecommitdiff
path: root/libopie2/opienet
Side-by-side diff
Diffstat (limited to 'libopie2/opienet') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetutils.cpp28
-rw-r--r--libopie2/opienet/onetutils.h3
-rw-r--r--libopie2/opienet/onetwork.cpp50
-rw-r--r--libopie2/opienet/onetwork.h8
4 files changed, 55 insertions, 34 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index b317810..0fb21ff 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -59,13 +59,13 @@ const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown );
//TODO: Incorporate Ethernet Manufacturer database here!
OMacAddress::OMacAddress( unsigned char* p )
{
- memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek...
+ memcpy( _bytes, p, 6 );
}
OMacAddress::OMacAddress( const unsigned char* p )
{
memcpy( _bytes, p, 6 );
@@ -80,12 +80,38 @@ OMacAddress::OMacAddress( struct ifreq& ifr )
OMacAddress::~OMacAddress()
{
}
+#ifdef QT_NO_DEBUG
+inline
+#endif
+const unsigned char* OMacAddress::native() const
+{
+ return (const unsigned char*) &_bytes;
+}
+
+
+OMacAddress OMacAddress::fromString( const QString& str )
+{
+ QString addr( str );
+ unsigned char buf[6];
+ bool ok = true;
+ int index = 14;
+ for ( int i = 5; i >= 0; --i )
+ {
+ buf[i] = addr.right( 2 ).toUShort( &ok, 16 );
+ if ( !ok ) return OMacAddress::unknown;
+ addr.truncate( index );
+ index -= 3;
+ }
+ return (const unsigned char*) &buf;
+}
+
+
QString OMacAddress::toString() const
{
QString s;
s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
_bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff,
_bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff );
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h
index 8be042b..73d52cc 100644
--- a/libopie2/opienet/onetutils.h
+++ b/libopie2/opienet/onetutils.h
@@ -53,12 +53,15 @@ class OMacAddress
OMacAddress( unsigned char* );
OMacAddress( const unsigned char* );
OMacAddress( struct ifreq& );
~OMacAddress();
QString toString() const;
+ const unsigned char* native() const;
+
+ static OMacAddress fromString( const QString& );
public:
static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff
static const OMacAddress& unknown; // 44:44:44:44:44:44
private:
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index f52279a..e916c44 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -221,12 +221,20 @@ QString ONetworkInterface::ipV4Address() const
}
else
return "<unknown>";
}
+void ONetworkInterface::setMacAddress( const OMacAddress& addr )
+{
+ _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
+ memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
+ ioctl( SIOCSIFHWADDR );
+}
+
+
OMacAddress ONetworkInterface::macAddress() const
{
if ( ioctl( SIOCGIFHWADDR ) )
{
return OMacAddress( _ifr );
}
@@ -644,12 +652,19 @@ void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ..
priv->invoke();
}
void OWirelessNetworkInterface::getPrivate( const QString& call )
{
+ qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
+}
+
+
+bool OWirelessNetworkInterface::hasPrivate( const QString& call )
+{
+ return child( (const char*) call );
}
QString OWirelessNetworkInterface::SSID() const
{
char str[IW_ESSID_MAX_SIZE];
@@ -831,35 +846,22 @@ OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
void OHostAPMonitoringInterface::setEnabled( bool b )
{
// IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
// Wireless Extensions < Version 15 need iwpriv commandos for monitoring
+ //TODO: check wireless extensions version on runtime and use
+ //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15
+
if ( b )
{
- #if WIRELESS_EXT > 14
- _if->_iwr.u.mode = IW_MODE_MONITOR;
- _if->wioctl( SIOCSIWMODE );
- #else
- int* args = (int*) &_if->_iwr.u.name;
- args[0] = 2;
- args[1] = 0;
- _if->wioctl( SIOCDEVPRIVATE );
- #endif
+ _if->setPrivate( "monitor", 1, 2 );
}
else
{
- #if WIRELESS_EXT > 14
- _if->_iwr.u.mode = IW_MODE_INFRA;
- _if->wioctl( SIOCSIWMODE );
- #else
- int* args = (int*) &_if->_iwr.u.name;
- args[0] = 0;
- args[1] = 0;
- _if->wioctl( SIOCDEVPRIVATE );
- #endif
+ _if->setPrivate( "monitor", 1, 0 );
}
}
QString OHostAPMonitoringInterface::name() const
{
@@ -882,33 +884,25 @@ OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
{
}
void OOrinocoMonitoringInterface::setChannel( int c )
{
- // call iwpriv <device> monitor 2 <channel>
- int* args = (int*) &_if->_iwr.u.name;
- args[0] = 2;
- args[1] = c;
- _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
+ _if->setPrivate( "monitor", 2, 2, c );
}
void OOrinocoMonitoringInterface::setEnabled( bool b )
{
if ( b )
{
setChannel( 1 );
}
else
{
- // call iwpriv <device> monitor 0 0
- int* args = (int*) &_if->_iwr.u.name;
- args[0] = 0;
- args[1] = 0;
- _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
+ _if->setPrivate( "monitor", 2, 0, 0 );
}
}
QString OOrinocoMonitoringInterface::name() const
{
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index 4cadbeb..e249aee 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -60,16 +60,12 @@
// ML: I will drop Jean an mail on that subject
#include <net/if.h>
#define _LINUX_IF_H
#include <linux/wireless.h>
-#ifndef SIOCIWFIRSTPRIV
-#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
-#endif
-
class ONetworkInterface;
class OWirelessNetworkInterface;
class OChannelHopper;
class OMonitoringInterface;
/*======================================================================================
@@ -122,12 +118,13 @@ class ONetworkInterface : public QObject
bool promiscuousMode() const;
bool setUp( bool );
bool isUp() const;
bool isLoopback() const;
bool isWireless() const;
QString ipV4Address() const;
+ void setMacAddress( const OMacAddress& );
OMacAddress macAddress() const;
int dataLinkType() const;
protected:
const int _sfd;
mutable ifreq _ifr;
@@ -201,12 +198,13 @@ class OWirelessNetworkInterface : public ONetworkInterface
virtual int channelHopping() const;
virtual void setNickName( const QString& ) {};
virtual QString nickName() const;
virtual void setPrivate( const QString&, int, ... );
+ virtual bool hasPrivate( const QString& );
virtual void getPrivate( const QString& );
virtual bool isAssociated() const {};
virtual QString associatedAP() const;
virtual void setSSID( const QString& );
@@ -246,13 +244,13 @@ class OMonitoringInterface
virtual bool enabled() const;
virtual void setChannel( int );
virtual QString name() const = 0;
protected:
- const OWirelessNetworkInterface* _if;
+ OWirelessNetworkInterface* _if;
};
/*======================================================================================
* OCiscoMonitoring