summaryrefslogtreecommitdiff
path: root/libopie2
authormickeyl <mickeyl>2003-04-05 19:29:47 (UTC)
committer mickeyl <mickeyl>2003-04-05 19:29:47 (UTC)
commit30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca (patch) (side-by-side diff)
treeeca3cb8d01045773db7de60d8194ea85313d3e0a /libopie2
parent2bfd529736f1dcf008540be2199cd3887a53c75c (diff)
downloadopie-30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca.zip
opie-30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca.tar.gz
opie-30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca.tar.bz2
- setting the monitor mode on wireless cards via private ioctls is now much more reliable because we detect the appropriate ioctl number at runtime
- ONetworkInterface supports now the evil but handy feature to change MAC address on the fly (provided the driver supports this)
Diffstat (limited to 'libopie2') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp18
-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
5 files changed, 73 insertions, 34 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
index b010ac5..020fc23 100644
--- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -30,2 +30,4 @@ int main( int argc, char** argv )
+ /*
+
// first some wrong calls to check if this is working
@@ -36,2 +38,18 @@ int main( int argc, char** argv )
iface->setPrivate( "monitor", 2, 2, 3 );
+
+ */
+
+ // trying to set hw address to 12:34:56:AB:CD:EF
+
+ /*
+
+ OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" );
+ iface->setUp( false );
+ iface->setMacAddress( addr );
+ iface->setUp( true );
+ qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() );
+
+ */
+
+
}
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
@@ -64,3 +64,3 @@ OMacAddress::OMacAddress( unsigned char* p )
{
- memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek...
+ memcpy( _bytes, p, 6 );
}
@@ -85,2 +85,28 @@ 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
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
@@ -58,2 +58,5 @@ class OMacAddress
QString toString() const;
+ const unsigned char* native() const;
+
+ static OMacAddress fromString( const QString& );
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
@@ -226,2 +226,10 @@ QString ONetworkInterface::ipV4Address() const
+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
@@ -649,2 +657,9 @@ void OWirelessNetworkInterface::getPrivate( const QString& call )
{
+ qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
+}
+
+
+bool OWirelessNetworkInterface::hasPrivate( const QString& call )
+{
+ return child( (const char*) call );
}
@@ -836,13 +851,8 @@ void OHostAPMonitoringInterface::setEnabled( bool b )
+ //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 );
}
@@ -850,11 +860,3 @@ void OHostAPMonitoringInterface::setEnabled( bool b )
{
- #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 );
}
@@ -887,7 +889,3 @@ 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 );
}
@@ -903,7 +901,3 @@ void OOrinocoMonitoringInterface::setEnabled( bool b )
{
- // 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 );
}
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
@@ -65,6 +65,2 @@
-#ifndef SIOCIWFIRSTPRIV
-#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
-#endif
-
class ONetworkInterface;
@@ -127,2 +123,3 @@ class ONetworkInterface : public QObject
QString ipV4Address() const;
+ void setMacAddress( const OMacAddress& );
OMacAddress macAddress() const;
@@ -206,2 +203,3 @@ class OWirelessNetworkInterface : public ONetworkInterface
virtual void setPrivate( const QString&, int, ... );
+ virtual bool hasPrivate( const QString& );
virtual void getPrivate( const QString& );
@@ -251,3 +249,3 @@ class OMonitoringInterface
protected:
- const OWirelessNetworkInterface* _if;
+ OWirelessNetworkInterface* _if;