summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-05 19:29:47 (UTC)
committer mickeyl <mickeyl>2003-04-05 19:29:47 (UTC)
commit30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca (patch) (unidiff)
treeeca3cb8d01045773db7de60d8194ea85313d3e0a
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 (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
@@ -28,12 +28,30 @@ int main( int argc, char** argv )
28 28
29 // try to set monitor mode 29 // try to set monitor mode
30 30
31 /*
32
31 // first some wrong calls to check if this is working 33 // first some wrong calls to check if this is working
32 iface->setPrivate( "seppel", 10 ); 34 iface->setPrivate( "seppel", 10 );
33 iface->setPrivate( "monitor", 0 ); 35 iface->setPrivate( "monitor", 0 );
34 36
35 // now the real deal 37 // now the real deal
36 iface->setPrivate( "monitor", 2, 2, 3 ); 38 iface->setPrivate( "monitor", 2, 2, 3 );
39
40 */
41
42 // trying to set hw address to 12:34:56:AB:CD:EF
43
44 /*
45
46 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" );
47 iface->setUp( false );
48 iface->setMacAddress( addr );
49 iface->setUp( true );
50 qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() );
51
52 */
53
54
37 } 55 }
38 ++it; 56 ++it;
39 } 57 }
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
@@ -62,7 +62,7 @@ const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown );
62 62
63OMacAddress::OMacAddress( unsigned char* p ) 63OMacAddress::OMacAddress( unsigned char* p )
64{ 64{
65 memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek... 65 memcpy( _bytes, p, 6 );
66} 66}
67 67
68 68
@@ -83,6 +83,32 @@ OMacAddress::~OMacAddress()
83} 83}
84 84
85 85
86#ifdef QT_NO_DEBUG
87inline
88#endif
89const unsigned char* OMacAddress::native() const
90{
91 return (const unsigned char*) &_bytes;
92}
93
94
95OMacAddress OMacAddress::fromString( const QString& str )
96{
97 QString addr( str );
98 unsigned char buf[6];
99 bool ok = true;
100 int index = 14;
101 for ( int i = 5; i >= 0; --i )
102 {
103 buf[i] = addr.right( 2 ).toUShort( &ok, 16 );
104 if ( !ok ) return OMacAddress::unknown;
105 addr.truncate( index );
106 index -= 3;
107 }
108 return (const unsigned char*) &buf;
109}
110
111
86QString OMacAddress::toString() const 112QString OMacAddress::toString() const
87{ 113{
88 QString s; 114 QString s;
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
@@ -56,6 +56,9 @@ class OMacAddress
56 ~OMacAddress(); 56 ~OMacAddress();
57 57
58 QString toString() const; 58 QString toString() const;
59 const unsigned char* native() const;
60
61 static OMacAddress fromString( const QString& );
59 62
60 public: 63 public:
61 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff 64 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff
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
@@ -224,6 +224,14 @@ QString ONetworkInterface::ipV4Address() const
224} 224}
225 225
226 226
227void ONetworkInterface::setMacAddress( const OMacAddress& addr )
228{
229 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
230 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
231 ioctl( SIOCSIFHWADDR );
232}
233
234
227OMacAddress ONetworkInterface::macAddress() const 235OMacAddress ONetworkInterface::macAddress() const
228{ 236{
229 if ( ioctl( SIOCGIFHWADDR ) ) 237 if ( ioctl( SIOCGIFHWADDR ) )
@@ -647,6 +655,13 @@ void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ..
647 655
648void OWirelessNetworkInterface::getPrivate( const QString& call ) 656void OWirelessNetworkInterface::getPrivate( const QString& call )
649{ 657{
658 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
659}
660
661
662bool OWirelessNetworkInterface::hasPrivate( const QString& call )
663{
664 return child( (const char*) call );
650} 665}
651 666
652 667
@@ -834,29 +849,16 @@ void OHostAPMonitoringInterface::setEnabled( bool b )
834 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 849 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
835 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 850 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
836 851
852 //TODO: check wireless extensions version on runtime and use
853 //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15
854
837 if ( b ) 855 if ( b )
838 { 856 {
839 #if WIRELESS_EXT > 14 857 _if->setPrivate( "monitor", 1, 2 );
840 _if->_iwr.u.mode = IW_MODE_MONITOR;
841 _if->wioctl( SIOCSIWMODE );
842 #else
843 int* args = (int*) &_if->_iwr.u.name;
844 args[0] = 2;
845 args[1] = 0;
846 _if->wioctl( SIOCDEVPRIVATE );
847 #endif
848 } 858 }
849 else 859 else
850 { 860 {
851 #if WIRELESS_EXT > 14 861 _if->setPrivate( "monitor", 1, 0 );
852 _if->_iwr.u.mode = IW_MODE_INFRA;
853 _if->wioctl( SIOCSIWMODE );
854 #else
855 int* args = (int*) &_if->_iwr.u.name;
856 args[0] = 0;
857 args[1] = 0;
858 _if->wioctl( SIOCDEVPRIVATE );
859 #endif
860 } 862 }
861} 863}
862 864
@@ -885,11 +887,7 @@ OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
885 887
886void OOrinocoMonitoringInterface::setChannel( int c ) 888void OOrinocoMonitoringInterface::setChannel( int c )
887{ 889{
888 // call iwpriv <device> monitor 2 <channel> 890 _if->setPrivate( "monitor", 2, 2, c );
889 int* args = (int*) &_if->_iwr.u.name;
890 args[0] = 2;
891 args[1] = c;
892 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
893} 891}
894 892
895 893
@@ -901,11 +899,7 @@ void OOrinocoMonitoringInterface::setEnabled( bool b )
901 } 899 }
902 else 900 else
903 { 901 {
904 // call iwpriv <device> monitor 0 0 902 _if->setPrivate( "monitor", 2, 0, 0 );
905 int* args = (int*) &_if->_iwr.u.name;
906 args[0] = 0;
907 args[1] = 0;
908 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
909 } 903 }
910} 904}
911 905
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
@@ -63,10 +63,6 @@
63#define _LINUX_IF_H 63#define _LINUX_IF_H
64#include <linux/wireless.h> 64#include <linux/wireless.h>
65 65
66#ifndef SIOCIWFIRSTPRIV
67#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
68#endif
69
70class ONetworkInterface; 66class ONetworkInterface;
71class OWirelessNetworkInterface; 67class OWirelessNetworkInterface;
72class OChannelHopper; 68class OChannelHopper;
@@ -125,6 +121,7 @@ class ONetworkInterface : public QObject
125 bool isLoopback() const; 121 bool isLoopback() const;
126 bool isWireless() const; 122 bool isWireless() const;
127 QString ipV4Address() const; 123 QString ipV4Address() const;
124 void setMacAddress( const OMacAddress& );
128 OMacAddress macAddress() const; 125 OMacAddress macAddress() const;
129 int dataLinkType() const; 126 int dataLinkType() const;
130 127
@@ -204,6 +201,7 @@ class OWirelessNetworkInterface : public ONetworkInterface
204 virtual QString nickName() const; 201 virtual QString nickName() const;
205 202
206 virtual void setPrivate( const QString&, int, ... ); 203 virtual void setPrivate( const QString&, int, ... );
204 virtual bool hasPrivate( const QString& );
207 virtual void getPrivate( const QString& ); 205 virtual void getPrivate( const QString& );
208 206
209 virtual bool isAssociated() const {}; 207 virtual bool isAssociated() const {};
@@ -249,7 +247,7 @@ class OMonitoringInterface
249 virtual QString name() const = 0; 247 virtual QString name() const = 0;
250 248
251 protected: 249 protected:
252 const OWirelessNetworkInterface* _if; 250 OWirelessNetworkInterface* _if;
253 251
254}; 252};
255 253