author | mickeyl <mickeyl> | 2003-04-05 19:29:47 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-05 19:29:47 (UTC) |
commit | 30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca (patch) (unidiff) | |
tree | eca3cb8d01045773db7de60d8194ea85313d3e0a | |
parent | 2bfd529736f1dcf008540be2199cd3887a53c75c (diff) | |
download | opie-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)
-rw-r--r-- | libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp | 18 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.cpp | 28 | ||||
-rw-r--r-- | libopie2/opienet/onetutils.h | 3 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 50 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 8 |
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 | |||
@@ -29,4 +29,6 @@ int main( int argc, char** argv ) | |||
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 ); |
@@ -35,4 +37,20 @@ int main( int argc, char** argv ) | |||
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; |
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 | |||
@@ -63,5 +63,5 @@ const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); | |||
63 | OMacAddress::OMacAddress( unsigned char* p ) | 63 | OMacAddress::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 | ||
@@ -84,4 +84,30 @@ OMacAddress::~OMacAddress() | |||
84 | 84 | ||
85 | 85 | ||
86 | #ifdef QT_NO_DEBUG | ||
87 | inline | ||
88 | #endif | ||
89 | const unsigned char* OMacAddress::native() const | ||
90 | { | ||
91 | return (const unsigned char*) &_bytes; | ||
92 | } | ||
93 | |||
94 | |||
95 | OMacAddress 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 | |||
86 | QString OMacAddress::toString() const | 112 | QString OMacAddress::toString() const |
87 | { | 113 | { |
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 | |||
@@ -57,4 +57,7 @@ class 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: |
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 | |||
@@ -225,4 +225,12 @@ QString ONetworkInterface::ipV4Address() const | |||
225 | 225 | ||
226 | 226 | ||
227 | void 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 | |||
227 | OMacAddress ONetworkInterface::macAddress() const | 235 | OMacAddress ONetworkInterface::macAddress() const |
228 | { | 236 | { |
@@ -648,4 +656,11 @@ void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, .. | |||
648 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 656 | void OWirelessNetworkInterface::getPrivate( const QString& call ) |
649 | { | 657 | { |
658 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); | ||
659 | } | ||
660 | |||
661 | |||
662 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | ||
663 | { | ||
664 | return child( (const char*) call ); | ||
650 | } | 665 | } |
651 | 666 | ||
@@ -835,27 +850,14 @@ void OHostAPMonitoringInterface::setEnabled( bool b ) | |||
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 | } |
@@ -886,9 +888,5 @@ OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | |||
886 | void OOrinocoMonitoringInterface::setChannel( int c ) | 888 | void 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 | ||
@@ -902,9 +900,5 @@ void OOrinocoMonitoringInterface::setEnabled( bool b ) | |||
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 | } |
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 | |||
@@ -64,8 +64,4 @@ | |||
64 | #include <linux/wireless.h> | 64 | #include <linux/wireless.h> |
65 | 65 | ||
66 | #ifndef SIOCIWFIRSTPRIV | ||
67 | #define SIOCIWFIRSTPRIV SIOCDEVPRIVATE | ||
68 | #endif | ||
69 | |||
70 | class ONetworkInterface; | 66 | class ONetworkInterface; |
71 | class OWirelessNetworkInterface; | 67 | class OWirelessNetworkInterface; |
@@ -126,4 +122,5 @@ class ONetworkInterface : public QObject | |||
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; |
@@ -205,4 +202,5 @@ class OWirelessNetworkInterface : public ONetworkInterface | |||
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 | ||
@@ -250,5 +248,5 @@ class OMonitoringInterface | |||
250 | 248 | ||
251 | protected: | 249 | protected: |
252 | const OWirelessNetworkInterface* _if; | 250 | OWirelessNetworkInterface* _if; |
253 | 251 | ||
254 | }; | 252 | }; |