author | mickeyl <mickeyl> | 2003-07-01 22:08:53 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-07-01 22:08:53 (UTC) |
commit | fbf388246a16c1cd36e209ba24731929b93c21c0 (patch) (unidiff) | |
tree | c6fd6bf3f6e341460feec4cca67355ac04f845ac | |
parent | d12216b371c89ee1142ade36e7e519041bcb8370 (diff) | |
download | opie-fbf388246a16c1cd36e209ba24731929b93c21c0.zip opie-fbf388246a16c1cd36e209ba24731929b93c21c0.tar.gz opie-fbf388246a16c1cd36e209ba24731929b93c21c0.tar.bz2 |
add monitor mode handling for recent kernels (WE>14)
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 28 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 8 |
2 files changed, 29 insertions, 7 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 6cef5cf..751d841 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,207 +1,214 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 by the Wellenreiter team: | 3 | Copyright (C) 2003 by the Wellenreiter team: |
4 | Martin J. Muench <mjm@remote-exploit.org> | 4 | Martin J. Muench <mjm@remote-exploit.org> |
5 | Max Moser <mmo@remote-exploit.org | 5 | Max Moser <mmo@remote-exploit.org |
6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | 35 | ||
36 | #include <opie2/onetwork.h> | 36 | #include <opie2/onetwork.h> |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | 39 | ||
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | 42 | ||
43 | /* UNIX */ | 43 | /* UNIX */ |
44 | 44 | ||
45 | #include <assert.h> | 45 | #include <assert.h> |
46 | #include <arpa/inet.h> | 46 | #include <arpa/inet.h> |
47 | #include <cerrno> | 47 | #include <cerrno> |
48 | #include <cstring> | 48 | #include <cstring> |
49 | #include <cstdlib> | 49 | #include <cstdlib> |
50 | #include <math.h> | 50 | #include <math.h> |
51 | #include <sys/ioctl.h> | 51 | #include <sys/ioctl.h> |
52 | #include <sys/socket.h> | 52 | #include <sys/socket.h> |
53 | #include <sys/types.h> | 53 | #include <sys/types.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | #include <linux/sockios.h> | 55 | #include <linux/sockios.h> |
56 | #include <net/if_arp.h> | 56 | #include <net/if_arp.h> |
57 | #include <stdarg.h> | 57 | #include <stdarg.h> |
58 | 58 | ||
59 | using namespace std; | 59 | using namespace std; |
60 | 60 | ||
61 | /*====================================================================================== | 61 | /*====================================================================================== |
62 | * ONetwork | 62 | * ONetwork |
63 | *======================================================================================*/ | 63 | *======================================================================================*/ |
64 | 64 | ||
65 | ONetwork* ONetwork::_instance = 0; | 65 | ONetwork* ONetwork::_instance = 0; |
66 | 66 | ||
67 | ONetwork::ONetwork() | 67 | ONetwork::ONetwork() |
68 | { | 68 | { |
69 | qDebug( "ONetwork::ONetwork()" ); | 69 | qDebug( "ONetwork::ONetwork()" ); |
70 | qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT ); | ||
70 | synchronize(); | 71 | synchronize(); |
71 | } | 72 | } |
72 | 73 | ||
73 | void ONetwork::synchronize() | 74 | void ONetwork::synchronize() |
74 | { | 75 | { |
75 | // gather available interfaces by inspecting /proc/net/dev | 76 | // gather available interfaces by inspecting /proc/net/dev |
76 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 77 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
77 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 78 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
78 | 79 | ||
79 | _interfaces.clear(); | 80 | _interfaces.clear(); |
80 | QString str; | 81 | QString str; |
81 | QFile f( "/proc/net/dev" ); | 82 | QFile f( "/proc/net/dev" ); |
82 | bool hasFile = f.open( IO_ReadOnly ); | 83 | bool hasFile = f.open( IO_ReadOnly ); |
83 | if ( !hasFile ) | 84 | if ( !hasFile ) |
84 | { | 85 | { |
85 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); | 86 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); |
86 | return; | 87 | return; |
87 | } | 88 | } |
88 | QTextStream s( &f ); | 89 | QTextStream s( &f ); |
89 | s.readLine(); | 90 | s.readLine(); |
90 | s.readLine(); | 91 | s.readLine(); |
91 | while ( !s.atEnd() ) | 92 | while ( !s.atEnd() ) |
92 | { | 93 | { |
93 | s >> str; | 94 | s >> str; |
94 | str.truncate( str.find( ':' ) ); | 95 | str.truncate( str.find( ':' ) ); |
95 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); | 96 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); |
96 | ONetworkInterface* iface; | 97 | ONetworkInterface* iface; |
97 | if ( isWirelessInterface( str ) ) | 98 | if ( isWirelessInterface( str ) ) |
98 | { | 99 | { |
99 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 100 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
100 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 101 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); |
101 | } | 102 | } |
102 | else | 103 | else |
103 | { | 104 | { |
104 | iface = new ONetworkInterface( this, (const char*) str ); | 105 | iface = new ONetworkInterface( this, (const char*) str ); |
105 | } | 106 | } |
106 | _interfaces.insert( str, iface ); | 107 | _interfaces.insert( str, iface ); |
107 | s.readLine(); | 108 | s.readLine(); |
108 | } | 109 | } |
109 | } | 110 | } |
110 | 111 | ||
111 | 112 | ||
113 | short ONetwork::wirelessExtensionVersion() | ||
114 | { | ||
115 | return WIRELESS_EXT; | ||
116 | } | ||
117 | |||
118 | |||
112 | int ONetwork::count() const | 119 | int ONetwork::count() const |
113 | { | 120 | { |
114 | return _interfaces.count(); | 121 | return _interfaces.count(); |
115 | } | 122 | } |
116 | 123 | ||
117 | 124 | ||
118 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 125 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
119 | { | 126 | { |
120 | return _interfaces[iface]; | 127 | return _interfaces[iface]; |
121 | } | 128 | } |
122 | 129 | ||
123 | 130 | ||
124 | ONetwork* ONetwork::instance() | 131 | ONetwork* ONetwork::instance() |
125 | { | 132 | { |
126 | if ( !_instance ) _instance = new ONetwork(); | 133 | if ( !_instance ) _instance = new ONetwork(); |
127 | return _instance; | 134 | return _instance; |
128 | } | 135 | } |
129 | 136 | ||
130 | 137 | ||
131 | ONetwork::InterfaceIterator ONetwork::iterator() const | 138 | ONetwork::InterfaceIterator ONetwork::iterator() const |
132 | { | 139 | { |
133 | return ONetwork::InterfaceIterator( _interfaces ); | 140 | return ONetwork::InterfaceIterator( _interfaces ); |
134 | } | 141 | } |
135 | 142 | ||
136 | 143 | ||
137 | bool ONetwork::isWirelessInterface( const char* name ) const | 144 | bool ONetwork::isWirelessInterface( const char* name ) const |
138 | { | 145 | { |
139 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 146 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
140 | struct iwreq iwr; | 147 | struct iwreq iwr; |
141 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 148 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
142 | strcpy( (char*) &iwr.ifr_name, name ); | 149 | strcpy( (char*) &iwr.ifr_name, name ); |
143 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 150 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
144 | return result != -1; | 151 | return result != -1; |
145 | } | 152 | } |
146 | 153 | ||
147 | /*====================================================================================== | 154 | /*====================================================================================== |
148 | * ONetworkInterface | 155 | * ONetworkInterface |
149 | *======================================================================================*/ | 156 | *======================================================================================*/ |
150 | 157 | ||
151 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 158 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
152 | :QObject( parent, name ), | 159 | :QObject( parent, name ), |
153 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 160 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
154 | { | 161 | { |
155 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 162 | qDebug( "ONetworkInterface::ONetworkInterface()" ); |
156 | init(); | 163 | init(); |
157 | } | 164 | } |
158 | 165 | ||
159 | 166 | ||
160 | struct ifreq& ONetworkInterface::ifr() const | 167 | struct ifreq& ONetworkInterface::ifr() const |
161 | { | 168 | { |
162 | return _ifr; | 169 | return _ifr; |
163 | } | 170 | } |
164 | 171 | ||
165 | 172 | ||
166 | void ONetworkInterface::init() | 173 | void ONetworkInterface::init() |
167 | { | 174 | { |
168 | qDebug( "ONetworkInterface::init()" ); | 175 | qDebug( "ONetworkInterface::init()" ); |
169 | 176 | ||
170 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 177 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
171 | 178 | ||
172 | if ( _sfd == -1 ) | 179 | if ( _sfd == -1 ) |
173 | { | 180 | { |
174 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); | 181 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); |
175 | return; | 182 | return; |
176 | } | 183 | } |
177 | } | 184 | } |
178 | 185 | ||
179 | 186 | ||
180 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 187 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
181 | { | 188 | { |
182 | int result = ::ioctl( _sfd, call, &ifreq ); | 189 | int result = ::ioctl( _sfd, call, &ifreq ); |
183 | if ( result == -1 ) | 190 | if ( result == -1 ) |
184 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 191 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); |
185 | else | 192 | else |
186 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); | 193 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); |
187 | return ( result != -1 ); | 194 | return ( result != -1 ); |
188 | } | 195 | } |
189 | 196 | ||
190 | 197 | ||
191 | bool ONetworkInterface::ioctl( int call ) const | 198 | bool ONetworkInterface::ioctl( int call ) const |
192 | { | 199 | { |
193 | strcpy( _ifr.ifr_name, name() ); | 200 | strcpy( _ifr.ifr_name, name() ); |
194 | return ioctl( call, _ifr ); | 201 | return ioctl( call, _ifr ); |
195 | } | 202 | } |
196 | 203 | ||
197 | 204 | ||
198 | bool ONetworkInterface::isLoopback() const | 205 | bool ONetworkInterface::isLoopback() const |
199 | { | 206 | { |
200 | ioctl( SIOCGIFFLAGS ); | 207 | ioctl( SIOCGIFFLAGS ); |
201 | return _ifr.ifr_flags & IFF_LOOPBACK; | 208 | return _ifr.ifr_flags & IFF_LOOPBACK; |
202 | } | 209 | } |
203 | 210 | ||
204 | 211 | ||
205 | bool ONetworkInterface::setUp( bool b ) | 212 | bool ONetworkInterface::setUp( bool b ) |
206 | { | 213 | { |
207 | ioctl( SIOCGIFFLAGS ); | 214 | ioctl( SIOCGIFFLAGS ); |
@@ -856,158 +863,171 @@ OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | |||
856 | { | 863 | { |
857 | } | 864 | } |
858 | 865 | ||
859 | 866 | ||
860 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 867 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
861 | { | 868 | { |
862 | QString fname; | 869 | QString fname; |
863 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 870 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
864 | QFile f( fname ); | 871 | QFile f( fname ); |
865 | if ( !f.exists() ) return; | 872 | if ( !f.exists() ) return; |
866 | 873 | ||
867 | if ( f.open( IO_WriteOnly ) ) | 874 | if ( f.open( IO_WriteOnly ) ) |
868 | { | 875 | { |
869 | QTextStream s( &f ); | 876 | QTextStream s( &f ); |
870 | s << "Mode: r"; | 877 | s << "Mode: r"; |
871 | s << "Mode: y"; | 878 | s << "Mode: y"; |
872 | s << "XmitPower: 1"; | 879 | s << "XmitPower: 1"; |
873 | } | 880 | } |
874 | 881 | ||
875 | // flushing and closing will be done automatically when f goes out of scope | 882 | // flushing and closing will be done automatically when f goes out of scope |
876 | } | 883 | } |
877 | 884 | ||
878 | 885 | ||
879 | QString OCiscoMonitoringInterface::name() const | 886 | QString OCiscoMonitoringInterface::name() const |
880 | { | 887 | { |
881 | return "cisco"; | 888 | return "cisco"; |
882 | } | 889 | } |
883 | 890 | ||
884 | 891 | ||
885 | void OCiscoMonitoringInterface::setChannel( int ) | 892 | void OCiscoMonitoringInterface::setChannel( int ) |
886 | { | 893 | { |
887 | // cisco devices automatically switch channels when in monitor mode | 894 | // cisco devices automatically switch channels when in monitor mode |
888 | } | 895 | } |
889 | 896 | ||
890 | 897 | ||
891 | /*====================================================================================== | 898 | /*====================================================================================== |
892 | * OWlanNGMonitoringInterface | 899 | * OWlanNGMonitoringInterface |
893 | *======================================================================================*/ | 900 | *======================================================================================*/ |
894 | 901 | ||
895 | 902 | ||
896 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 903 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
897 | :OMonitoringInterface( iface, prismHeader ) | 904 | :OMonitoringInterface( iface, prismHeader ) |
898 | { | 905 | { |
899 | iface->setMonitoring( this ); | 906 | iface->setMonitoring( this ); |
900 | } | 907 | } |
901 | 908 | ||
902 | 909 | ||
903 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 910 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
904 | { | 911 | { |
905 | } | 912 | } |
906 | 913 | ||
907 | 914 | ||
908 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 915 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
909 | { | 916 | { |
910 | //FIXME: do nothing if its already in the same mode | 917 | //FIXME: do nothing if its already in the same mode |
911 | 918 | ||
912 | QString enable = b ? "true" : "false"; | 919 | QString enable = b ? "true" : "false"; |
913 | QString prism = _prismHeader ? "true" : "false"; | 920 | QString prism = _prismHeader ? "true" : "false"; |
914 | QString cmd; | 921 | QString cmd; |
915 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 922 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
916 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); | 923 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); |
917 | system( cmd ); | 924 | system( cmd ); |
918 | } | 925 | } |
919 | 926 | ||
920 | 927 | ||
921 | QString OWlanNGMonitoringInterface::name() const | 928 | QString OWlanNGMonitoringInterface::name() const |
922 | { | 929 | { |
923 | return "wlan-ng"; | 930 | return "wlan-ng"; |
924 | } | 931 | } |
925 | 932 | ||
926 | 933 | ||
927 | void OWlanNGMonitoringInterface::setChannel( int ) | 934 | void OWlanNGMonitoringInterface::setChannel( int ) |
928 | { | 935 | { |
929 | // wlan-ng devices automatically switch channels when in monitor mode | 936 | // wlan-ng devices automatically switch channels when in monitor mode |
930 | } | 937 | } |
931 | 938 | ||
932 | 939 | ||
933 | /*====================================================================================== | 940 | /*====================================================================================== |
934 | * OHostAPMonitoringInterface | 941 | * OHostAPMonitoringInterface |
935 | *======================================================================================*/ | 942 | *======================================================================================*/ |
936 | 943 | ||
937 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 944 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
938 | :OMonitoringInterface( iface, prismHeader ) | 945 | :OMonitoringInterface( iface, prismHeader ) |
939 | { | 946 | { |
940 | iface->setMonitoring( this ); | 947 | iface->setMonitoring( this ); |
941 | } | 948 | } |
942 | 949 | ||
943 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 950 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
944 | { | 951 | { |
945 | } | 952 | } |
946 | 953 | ||
947 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 954 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
948 | { | 955 | { |
949 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 956 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
950 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 957 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
951 | 958 | ||
952 | //TODO: check wireless extensions version on runtime and use | 959 | #if WIRELESS_EXT > 14 |
953 | //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15 | 960 | if ( b ) |
954 | 961 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header | |
962 | else | ||
963 | _if->setMode( "managed" ); | ||
964 | #else | ||
955 | int monitorCode = _prismHeader ? 1 : 2; | 965 | int monitorCode = _prismHeader ? 1 : 2; |
956 | |||
957 | if ( b ) | 966 | if ( b ) |
958 | { | 967 | { |
959 | _if->setPrivate( "monitor", 1, monitorCode ); | 968 | _if->setPrivate( "monitor", 1, monitorCode ); |
960 | } | 969 | } |
961 | else | 970 | else |
962 | { | 971 | { |
963 | _if->setPrivate( "monitor", 1, 0 ); | 972 | _if->setPrivate( "monitor", 1, 0 ); |
964 | } | 973 | } |
974 | #endif | ||
965 | } | 975 | } |
966 | 976 | ||
967 | 977 | ||
968 | QString OHostAPMonitoringInterface::name() const | 978 | QString OHostAPMonitoringInterface::name() const |
969 | { | 979 | { |
970 | return "hostap"; | 980 | return "hostap"; |
971 | } | 981 | } |
972 | 982 | ||
973 | 983 | ||
974 | /*====================================================================================== | 984 | /*====================================================================================== |
975 | * OOrinocoNetworkInterface | 985 | * OOrinocoNetworkInterface |
976 | *======================================================================================*/ | 986 | *======================================================================================*/ |
977 | 987 | ||
978 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 988 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
979 | :OMonitoringInterface( iface, prismHeader ) | 989 | :OMonitoringInterface( iface, prismHeader ) |
980 | { | 990 | { |
981 | iface->setMonitoring( this ); | 991 | iface->setMonitoring( this ); |
982 | } | 992 | } |
983 | 993 | ||
984 | 994 | ||
985 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 995 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
986 | { | 996 | { |
987 | } | 997 | } |
988 | 998 | ||
989 | 999 | ||
990 | void OOrinocoMonitoringInterface::setChannel( int c ) | 1000 | void OOrinocoMonitoringInterface::setChannel( int c ) |
991 | { | 1001 | { |
992 | int monitorCode = _prismHeader ? 1 : 2; | 1002 | int monitorCode = _prismHeader ? 1 : 2; |
993 | _if->setPrivate( "monitor", 2, monitorCode, c ); | 1003 | _if->setPrivate( "monitor", 2, monitorCode, c ); |
994 | } | 1004 | } |
995 | 1005 | ||
996 | 1006 | ||
997 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 1007 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
998 | { | 1008 | { |
1009 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | ||
1010 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | ||
1011 | |||
1012 | #if WIRELESS_EXT > 14 | ||
1013 | if ( b ) | ||
1014 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header | ||
1015 | else | ||
1016 | _if->setMode( "managed" ); | ||
1017 | #else | ||
999 | if ( b ) | 1018 | if ( b ) |
1000 | { | 1019 | { |
1001 | setChannel( 1 ); | 1020 | setChannel( 1 ); |
1002 | } | 1021 | } |
1003 | else | 1022 | else |
1004 | { | 1023 | { |
1005 | _if->setPrivate( "monitor", 2, 0, 0 ); | 1024 | _if->setPrivate( "monitor", 2, 0, 0 ); |
1006 | } | 1025 | } |
1026 | #endif | ||
1007 | } | 1027 | } |
1008 | 1028 | ||
1009 | 1029 | ||
1010 | QString OOrinocoMonitoringInterface::name() const | 1030 | QString OOrinocoMonitoringInterface::name() const |
1011 | { | 1031 | { |
1012 | return "orinoco"; | 1032 | return "orinoco"; |
1013 | } | 1033 | } |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index cfb999d..2553a61 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -11,206 +11,208 @@ | |||
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | #ifndef ONETWORK_H | 34 | #ifndef ONETWORK_H |
35 | #define ONETWORK_H | 35 | #define ONETWORK_H |
36 | 36 | ||
37 | /* OPIE */ | 37 | /* OPIE */ |
38 | 38 | ||
39 | #include <opie2/onetutils.h> | 39 | #include <opie2/onetutils.h> |
40 | 40 | ||
41 | /* QT */ | 41 | /* QT */ |
42 | 42 | ||
43 | #include <qvaluelist.h> | 43 | #include <qvaluelist.h> |
44 | #include <qdict.h> | 44 | #include <qdict.h> |
45 | #include <qmap.h> | 45 | #include <qmap.h> |
46 | #include <qobject.h> | 46 | #include <qobject.h> |
47 | #include <qhostaddress.h> | 47 | #include <qhostaddress.h> |
48 | 48 | ||
49 | // ML: Yeah, I hate to include kernel headers, but it's necessary here | 49 | // ML: Yeah, I hate to include kernel headers, but it's necessary here |
50 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> | 50 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> |
51 | // ML: which conflicts with the user header <net/if.h> | 51 | // ML: which conflicts with the user header <net/if.h> |
52 | // ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h> | 52 | // ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h> |
53 | // ML: I will drop Jean a mail on that subject | 53 | // ML: I will drop Jean a mail on that subject |
54 | 54 | ||
55 | #include <net/if.h> | 55 | #include <net/if.h> |
56 | 56 | ||
57 | #ifndef IFNAMSIZ | 57 | #ifndef IFNAMSIZ |
58 | #define IFNAMSIZ 16 | 58 | #define IFNAMSIZ 16 |
59 | #endif | 59 | #endif |
60 | #ifndef IW_MAX_PRIV_DEF | 60 | #ifndef IW_MAX_PRIV_DEF |
61 | #define IW_MAX_PRIV_DEF 128 | 61 | #define IW_MAX_PRIV_DEF 128 |
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | #define _LINUX_IF_H | 64 | #define _LINUX_IF_H |
65 | #include <linux/wireless.h> | 65 | #include <linux/wireless.h> |
66 | 66 | ||
67 | class ONetworkInterface; | 67 | class ONetworkInterface; |
68 | class OWirelessNetworkInterface; | 68 | class OWirelessNetworkInterface; |
69 | class OChannelHopper; | 69 | class OChannelHopper; |
70 | class OMonitoringInterface; | 70 | class OMonitoringInterface; |
71 | 71 | ||
72 | /*====================================================================================== | 72 | /*====================================================================================== |
73 | * ONetwork | 73 | * ONetwork |
74 | *======================================================================================*/ | 74 | *======================================================================================*/ |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * @brief A container class for all network interfaces | 77 | * @brief A container class for all network interfaces |
78 | * | 78 | * |
79 | * This class provides access to all available network interfaces of your computer. | 79 | * This class provides access to all available network interfaces of your computer. |
80 | * | 80 | * |
81 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 81 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
82 | */ | 82 | */ |
83 | class ONetwork : public QObject | 83 | class ONetwork : public QObject |
84 | { | 84 | { |
85 | Q_OBJECT | 85 | Q_OBJECT |
86 | 86 | ||
87 | public: | 87 | public: |
88 | typedef QDict<ONetworkInterface> InterfaceMap; | 88 | typedef QDict<ONetworkInterface> InterfaceMap; |
89 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; | 89 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; |
90 | 90 | ||
91 | public: | 91 | public: |
92 | /** | 92 | /** |
93 | * @returns the number of available interfaces | 93 | * @returns the number of available interfaces |
94 | */ | 94 | */ |
95 | int count() const; | 95 | int count() const; |
96 | /** | 96 | /** |
97 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 97 | * @returns a pointer to the (one and only) @ref ONetwork instance. |
98 | */ | 98 | */ |
99 | static ONetwork* instance(); | 99 | static ONetwork* instance(); |
100 | /** | 100 | /** |
101 | * @returns an iterator usable for iterating through all network interfaces. | 101 | * @returns an iterator usable for iterating through all network interfaces. |
102 | */ | 102 | */ |
103 | InterfaceIterator iterator() const; | 103 | InterfaceIterator iterator() const; |
104 | /** | 104 | /** |
105 | * @returns true, if the @a interface supports the wireless extension protocol. | 105 | * @returns true, if the @a interface supports the wireless extension protocol. |
106 | */ | 106 | */ |
107 | // FIXME QString? -zecke | ||
108 | bool isWirelessInterface( const char* interface ) const; | 107 | bool isWirelessInterface( const char* interface ) const; |
109 | /** | 108 | /** |
110 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found | 109 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. |
111 | * @see ONetworkInterface | 110 | * @see ONetworkInterface |
112 | */ | 111 | */ |
113 | // FIXME: const QString& is prefered over QString!!! -zecke | ||
114 | ONetworkInterface* interface( const QString& interface ) const; | 112 | ONetworkInterface* interface( const QString& interface ) const; |
115 | /** | 113 | /** |
116 | * @internal Rebuild the internal interface database | 114 | * @internal Rebuild the internal interface database |
117 | * @note Sometimes it might be useful to call this from client code, | 115 | * @note Sometimes it might be useful to call this from client code, |
118 | * e.g. after issuing a cardctl insert | 116 | * e.g. after issuing a cardctl insert |
119 | */ | 117 | */ |
120 | void synchronize(); | 118 | void synchronize(); |
119 | /** | ||
120 | * @returns the wireless extension version used at compile time. | ||
121 | **/ | ||
122 | static short wirelessExtensionVersion(); | ||
121 | 123 | ||
122 | protected: | 124 | protected: |
123 | ONetwork(); | 125 | ONetwork(); |
124 | 126 | ||
125 | private: | 127 | private: |
126 | static ONetwork* _instance; | 128 | static ONetwork* _instance; |
127 | InterfaceMap _interfaces; | 129 | InterfaceMap _interfaces; |
128 | }; | 130 | }; |
129 | 131 | ||
130 | 132 | ||
131 | /*====================================================================================== | 133 | /*====================================================================================== |
132 | * ONetworkInterface | 134 | * ONetworkInterface |
133 | *======================================================================================*/ | 135 | *======================================================================================*/ |
134 | 136 | ||
135 | /** | 137 | /** |
136 | * @brief A network interface wrapper. | 138 | * @brief A network interface wrapper. |
137 | * | 139 | * |
138 | * This class provides a wrapper for a network interface. All the cumbersume details of | 140 | * This class provides a wrapper for a network interface. All the cumbersume details of |
139 | * Linux ioctls are hidden under a convenient high-level interface. | 141 | * Linux ioctls are hidden under a convenient high-level interface. |
140 | * @warning Most of the setting methods contained in this class require the appropriate | 142 | * @warning Most of the setting methods contained in this class require the appropriate |
141 | * process permissions to work. | 143 | * process permissions to work. |
142 | * | 144 | * |
143 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 145 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
144 | */ | 146 | */ |
145 | class ONetworkInterface : public QObject | 147 | class ONetworkInterface : public QObject |
146 | { | 148 | { |
147 | friend class OMonitoringInterface; | 149 | friend class OMonitoringInterface; |
148 | friend class OCiscoMonitoringInterface; | 150 | friend class OCiscoMonitoringInterface; |
149 | friend class OWlanNGMonitoringInterface; | 151 | friend class OWlanNGMonitoringInterface; |
150 | friend class OHostAPMonitoringInterface; | 152 | friend class OHostAPMonitoringInterface; |
151 | friend class OOrinocoMonitoringInterface; | 153 | friend class OOrinocoMonitoringInterface; |
152 | 154 | ||
153 | public: | 155 | public: |
154 | /** | 156 | /** |
155 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, | 157 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, |
156 | * but access them via @ref ONetwork::interface(). | 158 | * but access them via @ref ONetwork::interface(). |
157 | */ | 159 | */ |
158 | ONetworkInterface( QObject* parent, const char* name ); | 160 | ONetworkInterface( QObject* parent, const char* name ); |
159 | /** | 161 | /** |
160 | * Destructor. | 162 | * Destructor. |
161 | */ | 163 | */ |
162 | virtual ~ONetworkInterface(); | 164 | virtual ~ONetworkInterface(); |
163 | /** | 165 | /** |
164 | * Associates a @a monitoring interface with this network interface. | 166 | * Associates a @a monitoring interface with this network interface. |
165 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. | 167 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. |
166 | */ | 168 | */ |
167 | void setMonitoring( OMonitoringInterface* monitoring ); | 169 | void setMonitoring( OMonitoringInterface* monitoring ); |
168 | /** | 170 | /** |
169 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. | 171 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. |
170 | */ | 172 | */ |
171 | OMonitoringInterface* monitoring() const; | 173 | OMonitoringInterface* monitoring() const; |
172 | /** | 174 | /** |
173 | * Setting an interface to promiscuous mode enables the device to receive | 175 | * Setting an interface to promiscuous mode enables the device to receive |
174 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. | 176 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. |
175 | */ | 177 | */ |
176 | bool setPromiscuousMode( bool ); | 178 | bool setPromiscuousMode( bool ); |
177 | /** | 179 | /** |
178 | * @returns true if the interface is set to promiscuous mode. | 180 | * @returns true if the interface is set to promiscuous mode. |
179 | */ | 181 | */ |
180 | bool promiscuousMode() const; | 182 | bool promiscuousMode() const; |
181 | /** | 183 | /** |
182 | * Setting an interface to up enables it to receive packets. | 184 | * Setting an interface to up enables it to receive packets. |
183 | */ | 185 | */ |
184 | bool setUp( bool ); | 186 | bool setUp( bool ); |
185 | /** | 187 | /** |
186 | * @returns true if the interface is up. | 188 | * @returns true if the interface is up. |
187 | */ | 189 | */ |
188 | bool isUp() const; | 190 | bool isUp() const; |
189 | /** | 191 | /** |
190 | * @returns true if the interface is a loopback interface. | 192 | * @returns true if the interface is a loopback interface. |
191 | */ | 193 | */ |
192 | bool isLoopback() const; | 194 | bool isLoopback() const; |
193 | /** | 195 | /** |
194 | * @returns true if the interface is featuring supports the wireless extension protocol. | 196 | * @returns true if the interface is featuring supports the wireless extension protocol. |
195 | */ | 197 | */ |
196 | bool isWireless() const; | 198 | bool isWireless() const; |
197 | /** | 199 | /** |
198 | * Associate the IP address @ addr with the interface. | 200 | * Associate the IP address @ addr with the interface. |
199 | */ | 201 | */ |
200 | void setIPV4Address( const QHostAddress& addr ); | 202 | void setIPV4Address( const QHostAddress& addr ); |
201 | /** | 203 | /** |
202 | * @returns the IPv4 address associated with the interface. | 204 | * @returns the IPv4 address associated with the interface. |
203 | */ | 205 | */ |
204 | QString ipV4Address() const; //TODO: make this return an OHostAddress | 206 | QString ipV4Address() const; //TODO: make this return an OHostAddress |
205 | /** | 207 | /** |
206 | * Associate the MAC address @a addr with the interface. | 208 | * Associate the MAC address @a addr with the interface. |
207 | * @note It can be necessary to shut down the interface prior to calling this method. | 209 | * @note It can be necessary to shut down the interface prior to calling this method. |
208 | * @warning This is not supported by all drivers. | 210 | * @warning This is not supported by all drivers. |
209 | */ | 211 | */ |
210 | void setMacAddress( const OMacAddress& addr ); | 212 | void setMacAddress( const OMacAddress& addr ); |
211 | /** | 213 | /** |
212 | * @returns the MAC address associated with the interface. | 214 | * @returns the MAC address associated with the interface. |
213 | */ | 215 | */ |
214 | OMacAddress macAddress() const; | 216 | OMacAddress macAddress() const; |
215 | /** | 217 | /** |
216 | * Associate the IPv4 @a netmask with the interface. | 218 | * Associate the IPv4 @a netmask with the interface. |