author | mickeyl <mickeyl> | 2003-03-30 14:48:08 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-03-30 14:48:08 (UTC) |
commit | f921599651459b393e6a9846a1ecf7551323f4c2 (patch) (unidiff) | |
tree | 1fe6c881d29597c289a2dbbc30ad020996faac91 | |
parent | 9e3dc048e171af6d88f0cc3f16ad0c9fb6a15ce2 (diff) | |
download | opie-f921599651459b393e6a9846a1ecf7551323f4c2.zip opie-f921599651459b393e6a9846a1ecf7551323f4c2.tar.gz opie-f921599651459b393e6a9846a1ecf7551323f4c2.tar.bz2 |
- implement switching monitor mode on hostap
- work around damn buggy hostap drivers needing more space for SIOCGIWRANGE than defined by sizeof(struct iw_range)...
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 21fa390..cd36f16 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,792 +1,809 @@ | |||
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 <arpa/inet.h> | 45 | #include <arpa/inet.h> |
46 | #include <cerrno> | 46 | #include <cerrno> |
47 | #include <cstring> | 47 | #include <cstring> |
48 | #include <cstdlib> | 48 | #include <cstdlib> |
49 | #include <math.h> | 49 | #include <math.h> |
50 | #include <sys/ioctl.h> | 50 | #include <sys/ioctl.h> |
51 | #include <sys/socket.h> | 51 | #include <sys/socket.h> |
52 | #include <sys/types.h> | 52 | #include <sys/types.h> |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #include <linux/sockios.h> | 54 | #include <linux/sockios.h> |
55 | 55 | ||
56 | using namespace std; | 56 | using namespace std; |
57 | 57 | ||
58 | /*====================================================================================== | 58 | /*====================================================================================== |
59 | * ONetwork | 59 | * ONetwork |
60 | *======================================================================================*/ | 60 | *======================================================================================*/ |
61 | 61 | ||
62 | ONetwork* ONetwork::_instance = 0; | 62 | ONetwork* ONetwork::_instance = 0; |
63 | 63 | ||
64 | ONetwork::ONetwork() | 64 | ONetwork::ONetwork() |
65 | { | 65 | { |
66 | qDebug( "ONetwork::ONetwork()" ); | 66 | qDebug( "ONetwork::ONetwork()" ); |
67 | synchronize(); | 67 | synchronize(); |
68 | } | 68 | } |
69 | 69 | ||
70 | void ONetwork::synchronize() | 70 | void ONetwork::synchronize() |
71 | { | 71 | { |
72 | // gather available interfaces by inspecting /proc/net/dev | 72 | // gather available interfaces by inspecting /proc/net/dev |
73 | // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 73 | // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
74 | 74 | ||
75 | _interfaces.clear(); | 75 | _interfaces.clear(); |
76 | QString str; | 76 | QString str; |
77 | QFile f( "/proc/net/dev" ); | 77 | QFile f( "/proc/net/dev" ); |
78 | bool hasFile = f.open( IO_ReadOnly ); | 78 | bool hasFile = f.open( IO_ReadOnly ); |
79 | if ( !hasFile ) | 79 | if ( !hasFile ) |
80 | { | 80 | { |
81 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); | 81 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); |
82 | return; | 82 | return; |
83 | } | 83 | } |
84 | QTextStream s( &f ); | 84 | QTextStream s( &f ); |
85 | s.readLine(); | 85 | s.readLine(); |
86 | s.readLine(); | 86 | s.readLine(); |
87 | while ( !s.atEnd() ) | 87 | while ( !s.atEnd() ) |
88 | { | 88 | { |
89 | s >> str; | 89 | s >> str; |
90 | str.truncate( str.find( ':' ) ); | 90 | str.truncate( str.find( ':' ) ); |
91 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); | 91 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); |
92 | ONetworkInterface* iface; | 92 | ONetworkInterface* iface; |
93 | if ( isWirelessInterface( str ) ) | 93 | if ( isWirelessInterface( str ) ) |
94 | { | 94 | { |
95 | iface = new OWirelessNetworkInterface( str ); | 95 | iface = new OWirelessNetworkInterface( str ); |
96 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 96 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); |
97 | } | 97 | } |
98 | else | 98 | else |
99 | { | 99 | { |
100 | iface = new ONetworkInterface( str ); | 100 | iface = new ONetworkInterface( str ); |
101 | } | 101 | } |
102 | _interfaces.insert( str, iface ); | 102 | _interfaces.insert( str, iface ); |
103 | s.readLine(); | 103 | s.readLine(); |
104 | } | 104 | } |
105 | } | 105 | } |
106 | 106 | ||
107 | 107 | ||
108 | ONetworkInterface* ONetwork::interface( QString iface ) const | 108 | ONetworkInterface* ONetwork::interface( QString iface ) const |
109 | { | 109 | { |
110 | return _interfaces[iface]; | 110 | return _interfaces[iface]; |
111 | } | 111 | } |
112 | 112 | ||
113 | 113 | ||
114 | ONetwork* ONetwork::instance() | 114 | ONetwork* ONetwork::instance() |
115 | { | 115 | { |
116 | if ( !_instance ) _instance = new ONetwork(); | 116 | if ( !_instance ) _instance = new ONetwork(); |
117 | return _instance; | 117 | return _instance; |
118 | } | 118 | } |
119 | 119 | ||
120 | 120 | ||
121 | ONetwork::InterfaceIterator ONetwork::iterator() const | 121 | ONetwork::InterfaceIterator ONetwork::iterator() const |
122 | { | 122 | { |
123 | return ONetwork::InterfaceIterator( _interfaces ); | 123 | return ONetwork::InterfaceIterator( _interfaces ); |
124 | } | 124 | } |
125 | 125 | ||
126 | 126 | ||
127 | bool ONetwork::isWirelessInterface( const char* name ) const | 127 | bool ONetwork::isWirelessInterface( const char* name ) const |
128 | { | 128 | { |
129 | int sfd = socket( AF_INET, SOCK_DGRAM, 0 ); | 129 | int sfd = socket( AF_INET, SOCK_DGRAM, 0 ); |
130 | iwreqstruct iwr; | 130 | iwreqstruct iwr; |
131 | memset( &iwr, 0, sizeof( iwreqstruct ) ); | 131 | memset( &iwr, 0, sizeof( iwreqstruct ) ); |
132 | strcpy( (char*) &iwr.ifr_name, name ); | 132 | strcpy( (char*) &iwr.ifr_name, name ); |
133 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 133 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
134 | if ( result == -1 ) | 134 | if ( result == -1 ) |
135 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); | 135 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); |
136 | else | 136 | else |
137 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); | 137 | qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); |
138 | return ( result != -1 ); | 138 | return ( result != -1 ); |
139 | } | 139 | } |
140 | 140 | ||
141 | /*====================================================================================== | 141 | /*====================================================================================== |
142 | * ONetworkInterface | 142 | * ONetworkInterface |
143 | *======================================================================================*/ | 143 | *======================================================================================*/ |
144 | 144 | ||
145 | ONetworkInterface::ONetworkInterface( const QString& name ) | 145 | ONetworkInterface::ONetworkInterface( const QString& name ) |
146 | :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 146 | :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
147 | { | 147 | { |
148 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 148 | qDebug( "ONetworkInterface::ONetworkInterface()" ); |
149 | init(); | 149 | init(); |
150 | } | 150 | } |
151 | 151 | ||
152 | 152 | ||
153 | ifreqstruct& ONetworkInterface::ifr() const | 153 | ifreqstruct& ONetworkInterface::ifr() const |
154 | { | 154 | { |
155 | return _ifr; | 155 | return _ifr; |
156 | } | 156 | } |
157 | 157 | ||
158 | 158 | ||
159 | void ONetworkInterface::init() | 159 | void ONetworkInterface::init() |
160 | { | 160 | { |
161 | qDebug( "ONetworkInterface::init()" ); | 161 | qDebug( "ONetworkInterface::init()" ); |
162 | 162 | ||
163 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 163 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
164 | 164 | ||
165 | if ( _sfd == -1 ) | 165 | if ( _sfd == -1 ) |
166 | { | 166 | { |
167 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name ); | 167 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name ); |
168 | return; | 168 | return; |
169 | } | 169 | } |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||
173 | bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const | 173 | bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const |
174 | { | 174 | { |
175 | int result = ::ioctl( _sfd, call, &ifreq ); | 175 | int result = ::ioctl( _sfd, call, &ifreq ); |
176 | if ( result == -1 ) | 176 | if ( result == -1 ) |
177 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); | 177 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); |
178 | else | 178 | else |
179 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); | 179 | qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); |
180 | return ( result != -1 ); | 180 | return ( result != -1 ); |
181 | } | 181 | } |
182 | 182 | ||
183 | 183 | ||
184 | bool ONetworkInterface::ioctl( int call ) const | 184 | bool ONetworkInterface::ioctl( int call ) const |
185 | { | 185 | { |
186 | strcpy( _ifr.ifr_name, (const char*) _name ); | 186 | strcpy( _ifr.ifr_name, (const char*) _name ); |
187 | return ioctl( call, _ifr ); | 187 | return ioctl( call, _ifr ); |
188 | } | 188 | } |
189 | 189 | ||
190 | 190 | ||
191 | bool ONetworkInterface::isLoopback() const | 191 | bool ONetworkInterface::isLoopback() const |
192 | { | 192 | { |
193 | ioctl( SIOCGIFFLAGS ); | 193 | ioctl( SIOCGIFFLAGS ); |
194 | return _ifr.ifr_flags & IFF_LOOPBACK; | 194 | return _ifr.ifr_flags & IFF_LOOPBACK; |
195 | } | 195 | } |
196 | 196 | ||
197 | 197 | ||
198 | bool ONetworkInterface::setUp( bool b ) | 198 | bool ONetworkInterface::setUp( bool b ) |
199 | { | 199 | { |
200 | ioctl( SIOCGIFFLAGS ); | 200 | ioctl( SIOCGIFFLAGS ); |
201 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 201 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
202 | else _ifr.ifr_flags &= (~IFF_UP); | 202 | else _ifr.ifr_flags &= (~IFF_UP); |
203 | return ioctl( SIOCSIFFLAGS ); | 203 | return ioctl( SIOCSIFFLAGS ); |
204 | } | 204 | } |
205 | 205 | ||
206 | 206 | ||
207 | bool ONetworkInterface::isUp() const | 207 | bool ONetworkInterface::isUp() const |
208 | { | 208 | { |
209 | ioctl( SIOCGIFFLAGS ); | 209 | ioctl( SIOCGIFFLAGS ); |
210 | return _ifr.ifr_flags & IFF_UP; | 210 | return _ifr.ifr_flags & IFF_UP; |
211 | } | 211 | } |
212 | 212 | ||
213 | 213 | ||
214 | QString ONetworkInterface::ipV4Address() const | 214 | QString ONetworkInterface::ipV4Address() const |
215 | { | 215 | { |
216 | if ( ioctl( SIOCGIFADDR ) ) | 216 | if ( ioctl( SIOCGIFADDR ) ) |
217 | { | 217 | { |
218 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 218 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
219 | //FIXME: Use QHostAddress here | 219 | //FIXME: Use QHostAddress here |
220 | return QString( inet_ntoa( sa->sin_addr ) ); | 220 | return QString( inet_ntoa( sa->sin_addr ) ); |
221 | } | 221 | } |
222 | else | 222 | else |
223 | return "<unknown>"; | 223 | return "<unknown>"; |
224 | } | 224 | } |
225 | 225 | ||
226 | 226 | ||
227 | OMacAddress ONetworkInterface::macAddress() const | 227 | OMacAddress ONetworkInterface::macAddress() const |
228 | { | 228 | { |
229 | if ( ioctl( SIOCGIFHWADDR ) ) | 229 | if ( ioctl( SIOCGIFHWADDR ) ) |
230 | { | 230 | { |
231 | return OMacAddress( _ifr ); | 231 | return OMacAddress( _ifr ); |
232 | } | 232 | } |
233 | else | 233 | else |
234 | { | 234 | { |
235 | return OMacAddress::unknown; | 235 | return OMacAddress::unknown; |
236 | } | 236 | } |
237 | } | 237 | } |
238 | 238 | ||
239 | 239 | ||
240 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 240 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
241 | { | 241 | { |
242 | _mon = m; | 242 | _mon = m; |
243 | qDebug( "ONetwork::setMonitoring(): Installed monitoring interface '%s'", (const char*) m->name() ); | 243 | qDebug( "ONetwork::setMonitoring(): Installed monitoring interface '%s'", (const char*) m->name() ); |
244 | } | 244 | } |
245 | 245 | ||
246 | 246 | ||
247 | OMonitoringInterface* ONetworkInterface::monitoring() const | 247 | OMonitoringInterface* ONetworkInterface::monitoring() const |
248 | { | 248 | { |
249 | return _mon; | 249 | return _mon; |
250 | } | 250 | } |
251 | 251 | ||
252 | 252 | ||
253 | const QString& ONetworkInterface::name() const | 253 | const QString& ONetworkInterface::name() const |
254 | { | 254 | { |
255 | return _name; | 255 | return _name; |
256 | } | 256 | } |
257 | 257 | ||
258 | 258 | ||
259 | ONetworkInterface::~ONetworkInterface() | 259 | ONetworkInterface::~ONetworkInterface() |
260 | { | 260 | { |
261 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); | 261 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); |
262 | if ( _sfd != -1 ) ::close( _sfd ); | 262 | if ( _sfd != -1 ) ::close( _sfd ); |
263 | } | 263 | } |
264 | 264 | ||
265 | 265 | ||
266 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 266 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
267 | { | 267 | { |
268 | ioctl( SIOCGIFFLAGS ); | 268 | ioctl( SIOCGIFFLAGS ); |
269 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 269 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
270 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 270 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
271 | return ioctl( SIOCSIFFLAGS ); | 271 | return ioctl( SIOCSIFFLAGS ); |
272 | } | 272 | } |
273 | 273 | ||
274 | 274 | ||
275 | bool ONetworkInterface::promiscuousMode() const | 275 | bool ONetworkInterface::promiscuousMode() const |
276 | { | 276 | { |
277 | ioctl( SIOCGIFFLAGS ); | 277 | ioctl( SIOCGIFFLAGS ); |
278 | return _ifr.ifr_flags & IFF_PROMISC; | 278 | return _ifr.ifr_flags & IFF_PROMISC; |
279 | } | 279 | } |
280 | 280 | ||
281 | 281 | ||
282 | bool ONetworkInterface::isWireless() const | 282 | bool ONetworkInterface::isWireless() const |
283 | { | 283 | { |
284 | return ioctl( SIOCGIWNAME ); | 284 | return ioctl( SIOCGIWNAME ); |
285 | } | 285 | } |
286 | 286 | ||
287 | 287 | ||
288 | /*====================================================================================== | 288 | /*====================================================================================== |
289 | * OChannelHopper | 289 | * OChannelHopper |
290 | *======================================================================================*/ | 290 | *======================================================================================*/ |
291 | 291 | ||
292 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 292 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
293 | :QObject( 0, "Mickey's funky hopper" ), | 293 | :QObject( 0, "Mickey's funky hopper" ), |
294 | _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ), | 294 | _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ), |
295 | _maxChannel( iface->channels()+1 ) | 295 | _maxChannel( iface->channels()+1 ) |
296 | { | 296 | { |
297 | } | 297 | } |
298 | 298 | ||
299 | 299 | ||
300 | OChannelHopper::~OChannelHopper() | 300 | OChannelHopper::~OChannelHopper() |
301 | { | 301 | { |
302 | } | 302 | } |
303 | 303 | ||
304 | 304 | ||
305 | bool OChannelHopper::isActive() const | 305 | bool OChannelHopper::isActive() const |
306 | { | 306 | { |
307 | return _tid; | 307 | return _tid; |
308 | } | 308 | } |
309 | 309 | ||
310 | 310 | ||
311 | int OChannelHopper::channel() const | 311 | int OChannelHopper::channel() const |
312 | { | 312 | { |
313 | return _channel; | 313 | return _channel; |
314 | } | 314 | } |
315 | 315 | ||
316 | 316 | ||
317 | void OChannelHopper::timerEvent( QTimerEvent* ) | 317 | void OChannelHopper::timerEvent( QTimerEvent* ) |
318 | { | 318 | { |
319 | if ( !--_channel ) _channel = _maxChannel; | 319 | if ( !--_channel ) _channel = _maxChannel; |
320 | _iface->setChannel( _channel ); | 320 | _iface->setChannel( _channel ); |
321 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 321 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", |
322 | _channel, (const char*) _iface->name() ); | 322 | _channel, (const char*) _iface->name() ); |
323 | } | 323 | } |
324 | 324 | ||
325 | 325 | ||
326 | void OChannelHopper::setInterval( int interval ) | 326 | void OChannelHopper::setInterval( int interval ) |
327 | { | 327 | { |
328 | if ( interval == _interval ) | 328 | if ( interval == _interval ) |
329 | return; | 329 | return; |
330 | 330 | ||
331 | if ( _interval ) | 331 | if ( _interval ) |
332 | killTimer( _tid ); | 332 | killTimer( _tid ); |
333 | 333 | ||
334 | _tid = 0; | 334 | _tid = 0; |
335 | _interval = interval; | 335 | _interval = interval; |
336 | 336 | ||
337 | if ( _interval ) | 337 | if ( _interval ) |
338 | { | 338 | { |
339 | _tid = startTimer( interval ); | 339 | _tid = startTimer( interval ); |
340 | } | 340 | } |
341 | } | 341 | } |
342 | 342 | ||
343 | 343 | ||
344 | int OChannelHopper::interval() const | 344 | int OChannelHopper::interval() const |
345 | { | 345 | { |
346 | return _interval; | 346 | return _interval; |
347 | } | 347 | } |
348 | 348 | ||
349 | 349 | ||
350 | /*====================================================================================== | 350 | /*====================================================================================== |
351 | * OWirelessNetworkInterface | 351 | * OWirelessNetworkInterface |
352 | *======================================================================================*/ | 352 | *======================================================================================*/ |
353 | 353 | ||
354 | OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) | 354 | OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) |
355 | :ONetworkInterface( name ), _hopper( 0 ) | 355 | :ONetworkInterface( name ), _hopper( 0 ) |
356 | { | 356 | { |
357 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 357 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); |
358 | init(); | 358 | init(); |
359 | } | 359 | } |
360 | 360 | ||
361 | 361 | ||
362 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 362 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
363 | { | 363 | { |
364 | } | 364 | } |
365 | 365 | ||
366 | 366 | ||
367 | iwreqstruct& OWirelessNetworkInterface::iwr() const | 367 | iwreqstruct& OWirelessNetworkInterface::iwr() const |
368 | { | 368 | { |
369 | return _iwr; | 369 | return _iwr; |
370 | } | 370 | } |
371 | 371 | ||
372 | 372 | ||
373 | void OWirelessNetworkInterface::init() | 373 | void OWirelessNetworkInterface::init() |
374 | { | 374 | { |
375 | qDebug( "OWirelessNetworkInterface::init()" ); | 375 | qDebug( "OWirelessNetworkInterface::init()" ); |
376 | 376 | ||
377 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 377 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
378 | 378 | ||
379 | // IEEE802.11(b) radio frequency channels | 379 | // IEEE802.11(b) radio frequency channels |
380 | //FIXME: get these directly from the interface | ||
381 | //FIXME: check if these channels are off-by-one | ||
382 | 380 | ||
383 | iwrangestruct range; | 381 | iwrangestruct range; |
382 | //ML: work around an ugly HostAP bug, which needs | ||
383 | //ML: extra space or will complain with "invalid argument length"... :-( | ||
384 | char __extraBufferForBuggyDrivers[sizeof range]; | ||
384 | _iwr.u.data.pointer = (char*) ⦥ | 385 | _iwr.u.data.pointer = (char*) ⦥ |
385 | _iwr.u.data.length = sizeof( iwrangestruct ); | 386 | _iwr.u.data.length = (sizeof range) * 2; |
387 | _iwr.u.data.flags = 0; | ||
386 | if ( !wioctl( SIOCGIWRANGE ) ) | 388 | if ( !wioctl( SIOCGIWRANGE ) ) |
387 | { | 389 | { |
388 | qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); | 390 | qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); |
389 | return; | 391 | return; |
390 | } | 392 | } |
391 | 393 | ||
392 | for ( int i = 0; i < range.num_frequency; ++i ) | 394 | for ( int i = 0; i < range.num_frequency; ++i ) |
393 | { | 395 | { |
394 | int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 ); | 396 | int freq = (int) ( double( range.freq[i].m ) * pow( 10, range.freq[i].e ) / 1000000.0 ); |
395 | _channels.insert( freq, i+1 ); | 397 | _channels.insert( freq, i+1 ); |
396 | } | 398 | } |
397 | } | 399 | } |
398 | 400 | ||
399 | 401 | ||
400 | QString OWirelessNetworkInterface::associatedAP() const | 402 | QString OWirelessNetworkInterface::associatedAP() const |
401 | { | 403 | { |
402 | //FIXME: use OMacAddress | 404 | //FIXME: use OMacAddress |
403 | QString mac; | 405 | QString mac; |
404 | 406 | ||
405 | if ( ioctl( SIOCGIWAP ) ) | 407 | if ( ioctl( SIOCGIWAP ) ) |
406 | { | 408 | { |
407 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 409 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
408 | _ifr.ifr_hwaddr.sa_data[0]&0xff, | 410 | _ifr.ifr_hwaddr.sa_data[0]&0xff, |
409 | _ifr.ifr_hwaddr.sa_data[1]&0xff, | 411 | _ifr.ifr_hwaddr.sa_data[1]&0xff, |
410 | _ifr.ifr_hwaddr.sa_data[2]&0xff, | 412 | _ifr.ifr_hwaddr.sa_data[2]&0xff, |
411 | _ifr.ifr_hwaddr.sa_data[3]&0xff, | 413 | _ifr.ifr_hwaddr.sa_data[3]&0xff, |
412 | _ifr.ifr_hwaddr.sa_data[4]&0xff, | 414 | _ifr.ifr_hwaddr.sa_data[4]&0xff, |
413 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); | 415 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); |
414 | } | 416 | } |
415 | else | 417 | else |
416 | { | 418 | { |
417 | mac = "<Unknown>"; | 419 | mac = "<Unknown>"; |
418 | } | 420 | } |
419 | return mac; | 421 | return mac; |
420 | } | 422 | } |
421 | 423 | ||
422 | 424 | ||
423 | int OWirelessNetworkInterface::channel() const | 425 | int OWirelessNetworkInterface::channel() const |
424 | { | 426 | { |
425 | //FIXME: When monitoring enabled, then use it | 427 | //FIXME: When monitoring enabled, then use it |
426 | //FIXME: to gather the current RF channel | 428 | //FIXME: to gather the current RF channel |
427 | //FIXME: Until then, get active channel from hopper. | 429 | //FIXME: Until then, get active channel from hopper. |
428 | if ( _hopper && _hopper->isActive() ) | 430 | if ( _hopper && _hopper->isActive() ) |
429 | return _hopper->channel(); | 431 | return _hopper->channel(); |
430 | 432 | ||
431 | if ( !wioctl( SIOCGIWFREQ ) ) | 433 | if ( !wioctl( SIOCGIWFREQ ) ) |
432 | { | 434 | { |
433 | return -1; | 435 | return -1; |
434 | } | 436 | } |
435 | else | 437 | else |
436 | { | 438 | { |
437 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ]; | 439 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000) ]; |
438 | } | 440 | } |
439 | } | 441 | } |
440 | 442 | ||
441 | 443 | ||
442 | void OWirelessNetworkInterface::setChannel( int c ) const | 444 | void OWirelessNetworkInterface::setChannel( int c ) const |
443 | { | 445 | { |
444 | if ( !_mon ) | 446 | if ( !_mon ) |
445 | { | 447 | { |
446 | memset( &_iwr, 0, sizeof( iwreqstruct ) ); | 448 | memset( &_iwr, 0, sizeof( iwreqstruct ) ); |
447 | _iwr.u.freq.m = c; | 449 | _iwr.u.freq.m = c; |
448 | _iwr.u.freq.e = 0; | 450 | _iwr.u.freq.e = 0; |
449 | wioctl( SIOCSIWFREQ ); | 451 | wioctl( SIOCSIWFREQ ); |
450 | } | 452 | } |
451 | else | 453 | else |
452 | { | 454 | { |
453 | _mon->setChannel( c ); | 455 | _mon->setChannel( c ); |
454 | } | 456 | } |
455 | } | 457 | } |
456 | 458 | ||
457 | 459 | ||
458 | double OWirelessNetworkInterface::frequency() const | 460 | double OWirelessNetworkInterface::frequency() const |
459 | { | 461 | { |
460 | if ( !wioctl( SIOCGIWFREQ ) ) | 462 | if ( !wioctl( SIOCGIWFREQ ) ) |
461 | { | 463 | { |
462 | return -1.0; | 464 | return -1.0; |
463 | } | 465 | } |
464 | else | 466 | else |
465 | { | 467 | { |
466 | return double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000000.0; | 468 | return double( _iwr.u.freq.m ) * pow( 10, _iwr.u.freq.e ) / 1000000000.0; |
467 | } | 469 | } |
468 | } | 470 | } |
469 | 471 | ||
470 | 472 | ||
471 | int OWirelessNetworkInterface::channels() const | 473 | int OWirelessNetworkInterface::channels() const |
472 | { | 474 | { |
473 | return _channels.count(); | 475 | return _channels.count(); |
474 | } | 476 | } |
475 | 477 | ||
476 | 478 | ||
477 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 479 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
478 | { | 480 | { |
479 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 481 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
480 | _hopper->setInterval( interval ); | 482 | _hopper->setInterval( interval ); |
481 | //FIXME: When and by whom will the channel hopper be deleted? | 483 | //FIXME: When and by whom will the channel hopper be deleted? |
482 | } | 484 | } |
483 | 485 | ||
484 | 486 | ||
485 | int OWirelessNetworkInterface::channelHopping() const | 487 | int OWirelessNetworkInterface::channelHopping() const |
486 | { | 488 | { |
487 | return _hopper->interval(); | 489 | return _hopper->interval(); |
488 | } | 490 | } |
489 | 491 | ||
490 | 492 | ||
491 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 493 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
492 | { | 494 | { |
493 | if ( _mon ) | 495 | if ( _mon ) |
494 | _mon->setEnabled( b ); | 496 | _mon->setEnabled( b ); |
495 | else | 497 | else |
496 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 498 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
497 | } | 499 | } |
498 | 500 | ||
499 | 501 | ||
500 | bool OWirelessNetworkInterface::monitorMode() const | 502 | bool OWirelessNetworkInterface::monitorMode() const |
501 | { | 503 | { |
502 | return _mon ? _mon->enabled() : false; | 504 | return _mon ? _mon->enabled() : false; |
503 | } | 505 | } |
504 | 506 | ||
505 | 507 | ||
506 | QString OWirelessNetworkInterface::nickName() const | 508 | QString OWirelessNetworkInterface::nickName() const |
507 | { | 509 | { |
508 | char str[IW_ESSID_MAX_SIZE]; | 510 | char str[IW_ESSID_MAX_SIZE]; |
509 | _iwr.u.data.pointer = &str[0]; | 511 | _iwr.u.data.pointer = &str[0]; |
510 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 512 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
511 | if ( !wioctl( SIOCGIWNICKN ) ) | 513 | if ( !wioctl( SIOCGIWNICKN ) ) |
512 | { | 514 | { |
513 | return "<unknown>"; | 515 | return "<unknown>"; |
514 | } | 516 | } |
515 | else | 517 | else |
516 | { | 518 | { |
517 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 519 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
518 | return str; | 520 | return str; |
519 | } | 521 | } |
520 | } | 522 | } |
521 | 523 | ||
522 | 524 | ||
523 | QString OWirelessNetworkInterface::SSID() const | 525 | QString OWirelessNetworkInterface::SSID() const |
524 | { | 526 | { |
525 | char str[IW_ESSID_MAX_SIZE]; | 527 | char str[IW_ESSID_MAX_SIZE]; |
526 | _iwr.u.essid.pointer = &str[0]; | 528 | _iwr.u.essid.pointer = &str[0]; |
527 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 529 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
528 | if ( !wioctl( SIOCGIWESSID ) ) | 530 | if ( !wioctl( SIOCGIWESSID ) ) |
529 | { | 531 | { |
530 | return "<unknown>"; | 532 | return "<unknown>"; |
531 | } | 533 | } |
532 | else | 534 | else |
533 | { | 535 | { |
534 | return str; | 536 | return str; |
535 | } | 537 | } |
536 | } | 538 | } |
537 | 539 | ||
538 | 540 | ||
539 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 541 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
540 | { | 542 | { |
541 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 543 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
542 | _iwr.u.essid.length = ssid.length(); | 544 | _iwr.u.essid.length = ssid.length(); |
543 | wioctl( SIOCSIWESSID ); | 545 | wioctl( SIOCSIWESSID ); |
544 | } | 546 | } |
545 | 547 | ||
546 | 548 | ||
547 | bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const | 549 | bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const |
548 | { | 550 | { |
549 | int result = ::ioctl( _sfd, call, &iwreq ); | 551 | int result = ::ioctl( _sfd, call, &iwreq ); |
550 | if ( result == -1 ) | 552 | if ( result == -1 ) |
551 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); | 553 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); |
552 | else | 554 | else |
553 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); | 555 | qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); |
554 | return ( result != -1 ); | 556 | return ( result != -1 ); |
555 | } | 557 | } |
556 | 558 | ||
557 | 559 | ||
558 | bool OWirelessNetworkInterface::wioctl( int call ) const | 560 | bool OWirelessNetworkInterface::wioctl( int call ) const |
559 | { | 561 | { |
560 | strcpy( _iwr.ifr_name, (const char*) _name ); | 562 | strcpy( _iwr.ifr_name, (const char*) _name ); |
561 | return wioctl( call, _iwr ); | 563 | return wioctl( call, _iwr ); |
562 | } | 564 | } |
563 | 565 | ||
564 | 566 | ||
565 | /*====================================================================================== | 567 | /*====================================================================================== |
566 | * OMonitoringInterface | 568 | * OMonitoringInterface |
567 | *======================================================================================*/ | 569 | *======================================================================================*/ |
568 | 570 | ||
569 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) | 571 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) |
570 | :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) | 572 | :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) |
571 | { | 573 | { |
572 | } | 574 | } |
573 | 575 | ||
574 | 576 | ||
575 | OMonitoringInterface::~OMonitoringInterface() | 577 | OMonitoringInterface::~OMonitoringInterface() |
576 | { | 578 | { |
577 | } | 579 | } |
578 | 580 | ||
579 | 581 | ||
580 | void OMonitoringInterface::setChannel( int c ) | 582 | void OMonitoringInterface::setChannel( int c ) |
581 | { | 583 | { |
582 | // use standard WE channel switching protocol | 584 | // use standard WE channel switching protocol |
583 | memset( &_if->_iwr, 0, sizeof( iwreqstruct ) ); | 585 | memset( &_if->_iwr, 0, sizeof( iwreqstruct ) ); |
584 | _if->_iwr.u.freq.m = c; | 586 | _if->_iwr.u.freq.m = c; |
585 | _if->_iwr.u.freq.e = 0; | 587 | _if->_iwr.u.freq.e = 0; |
586 | _if->wioctl( SIOCSIWFREQ ); | 588 | _if->wioctl( SIOCSIWFREQ ); |
587 | } | 589 | } |
588 | 590 | ||
589 | 591 | ||
590 | bool OMonitoringInterface::enabled() const | 592 | bool OMonitoringInterface::enabled() const |
591 | { | 593 | { |
592 | return _enabled; | 594 | return _enabled; |
593 | } | 595 | } |
594 | 596 | ||
595 | void OMonitoringInterface::setEnabled( bool b ) | 597 | void OMonitoringInterface::setEnabled( bool b ) |
596 | { | 598 | { |
597 | // open a packet capturer here or leave this to | 599 | // open a packet capturer here or leave this to |
598 | // the client code? | 600 | // the client code? |
599 | 601 | ||
600 | /* | 602 | /* |
601 | 603 | ||
602 | if ( b ) | 604 | if ( b ) |
603 | { | 605 | { |
604 | OPacketCapturer* opcap = new OPacketCapturer(); | 606 | OPacketCapturer* opcap = new OPacketCapturer(); |
605 | opcap->open( _if->name() ); | 607 | opcap->open( _if->name() ); |
606 | } | 608 | } |
607 | */ | 609 | */ |
608 | 610 | ||
609 | _enabled = b; | 611 | _enabled = b; |
610 | 612 | ||
611 | } | 613 | } |
612 | 614 | ||
613 | /*====================================================================================== | 615 | /*====================================================================================== |
614 | * OCiscoMonitoringInterface | 616 | * OCiscoMonitoringInterface |
615 | *======================================================================================*/ | 617 | *======================================================================================*/ |
616 | 618 | ||
617 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) | 619 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) |
618 | :OMonitoringInterface( iface ) | 620 | :OMonitoringInterface( iface ) |
619 | { | 621 | { |
620 | iface->setMonitoring( this ); | 622 | iface->setMonitoring( this ); |
621 | } | 623 | } |
622 | 624 | ||
623 | 625 | ||
624 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 626 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
625 | { | 627 | { |
626 | } | 628 | } |
627 | 629 | ||
628 | 630 | ||
629 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 631 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
630 | { | 632 | { |
631 | QString fname; | 633 | QString fname; |
632 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 634 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
633 | QFile f( fname ); | 635 | QFile f( fname ); |
634 | if ( !f.exists() ) return; | 636 | if ( !f.exists() ) return; |
635 | 637 | ||
636 | if ( f.open( IO_WriteOnly ) ) | 638 | if ( f.open( IO_WriteOnly ) ) |
637 | { | 639 | { |
638 | QTextStream s( &f ); | 640 | QTextStream s( &f ); |
639 | s << "Mode: r"; | 641 | s << "Mode: r"; |
640 | s << "Mode: y"; | 642 | s << "Mode: y"; |
641 | s << "XmitPower: 1"; | 643 | s << "XmitPower: 1"; |
642 | 644 | ||
643 | OMonitoringInterface::setEnabled( b ); | 645 | OMonitoringInterface::setEnabled( b ); |
644 | 646 | ||
645 | } | 647 | } |
646 | 648 | ||
647 | // flushing and closing will be done automatically when f goes out of scope | 649 | // flushing and closing will be done automatically when f goes out of scope |
648 | } | 650 | } |
649 | 651 | ||
650 | 652 | ||
651 | QString OCiscoMonitoringInterface::name() const | 653 | QString OCiscoMonitoringInterface::name() const |
652 | { | 654 | { |
653 | return "cisco"; | 655 | return "cisco"; |
654 | } | 656 | } |
655 | 657 | ||
656 | 658 | ||
657 | void OCiscoMonitoringInterface::setChannel( int ) | 659 | void OCiscoMonitoringInterface::setChannel( int ) |
658 | { | 660 | { |
659 | // cisco devices automatically switch channels when in monitor mode | 661 | // cisco devices automatically switch channels when in monitor mode |
660 | } | 662 | } |
661 | 663 | ||
662 | 664 | ||
663 | /*====================================================================================== | 665 | /*====================================================================================== |
664 | * OWlanNGMonitoringInterface | 666 | * OWlanNGMonitoringInterface |
665 | *======================================================================================*/ | 667 | *======================================================================================*/ |
666 | 668 | ||
667 | 669 | ||
668 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) | 670 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) |
669 | :OMonitoringInterface( iface ) | 671 | :OMonitoringInterface( iface ) |
670 | { | 672 | { |
671 | iface->setMonitoring( this ); | 673 | iface->setMonitoring( this ); |
672 | } | 674 | } |
673 | 675 | ||
674 | 676 | ||
675 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 677 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
676 | { | 678 | { |
677 | } | 679 | } |
678 | 680 | ||
679 | 681 | ||
680 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 682 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
681 | { | 683 | { |
682 | //FIXME: do nothing if its already in the same mode | 684 | //FIXME: do nothing if its already in the same mode |
683 | 685 | ||
684 | QString enable = b ? "true" : "false"; | 686 | QString enable = b ? "true" : "false"; |
685 | QString cmd; | 687 | QString cmd; |
686 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); | 688 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); |
687 | system( cmd ); | 689 | system( cmd ); |
688 | 690 | ||
689 | OMonitoringInterface::setEnabled( b ); | 691 | OMonitoringInterface::setEnabled( b ); |
690 | } | 692 | } |
691 | 693 | ||
692 | 694 | ||
693 | QString OWlanNGMonitoringInterface::name() const | 695 | QString OWlanNGMonitoringInterface::name() const |
694 | { | 696 | { |
695 | return "wlan-ng"; | 697 | return "wlan-ng"; |
696 | } | 698 | } |
697 | 699 | ||
698 | 700 | ||
699 | void OWlanNGMonitoringInterface::setChannel( int ) | 701 | void OWlanNGMonitoringInterface::setChannel( int ) |
700 | { | 702 | { |
701 | // wlan-ng devices automatically switch channels when in monitor mode | 703 | // wlan-ng devices automatically switch channels when in monitor mode |
702 | } | 704 | } |
703 | 705 | ||
704 | 706 | ||
705 | /*====================================================================================== | 707 | /*====================================================================================== |
706 | * OHostAPMonitoringInterface | 708 | * OHostAPMonitoringInterface |
707 | *======================================================================================*/ | 709 | *======================================================================================*/ |
708 | 710 | ||
709 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) | 711 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) |
710 | :OMonitoringInterface( iface ) | 712 | :OMonitoringInterface( iface ) |
711 | { | 713 | { |
712 | iface->setMonitoring( this ); | 714 | iface->setMonitoring( this ); |
713 | } | 715 | } |
714 | 716 | ||
715 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 717 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
716 | { | 718 | { |
717 | } | 719 | } |
718 | 720 | ||
719 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 721 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
720 | { | 722 | { |
721 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 723 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
722 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 724 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
723 | 725 | ||
724 | #if WIRELESS_EXT > 14 | 726 | if ( b ) |
725 | _if->_iwr.u.mode = IW_MODE_MONITOR; | 727 | { |
726 | _if->wioctl( SIOCSIWMODE ); | 728 | #if WIRELESS_EXT > 14 |
727 | #else | 729 | _if->_iwr.u.mode = IW_MODE_MONITOR; |
728 | int* args = (int*) &_if->_iwr.u.name; | 730 | _if->wioctl( SIOCSIWMODE ); |
729 | args[0] = 2; | 731 | #else |
730 | args[1] = 0; | 732 | int* args = (int*) &_if->_iwr.u.name; |
731 | _if->wioctl( SIOCDEVPRIVATE ); | 733 | args[0] = 2; |
732 | #endif | 734 | args[1] = 0; |
735 | _if->wioctl( SIOCDEVPRIVATE ); | ||
736 | #endif | ||
737 | } | ||
738 | else | ||
739 | { | ||
740 | #if WIRELESS_EXT > 14 | ||
741 | _if->_iwr.u.mode = IW_MODE_INFRA; | ||
742 | _if->wioctl( SIOCSIWMODE ); | ||
743 | #else | ||
744 | int* args = (int*) &_if->_iwr.u.name; | ||
745 | args[0] = 0; | ||
746 | args[1] = 0; | ||
747 | _if->wioctl( SIOCDEVPRIVATE ); | ||
748 | #endif | ||
749 | } | ||
733 | 750 | ||
734 | OMonitoringInterface::setEnabled( b ); | 751 | OMonitoringInterface::setEnabled( b ); |
735 | } | 752 | } |
736 | 753 | ||
737 | 754 | ||
738 | QString OHostAPMonitoringInterface::name() const | 755 | QString OHostAPMonitoringInterface::name() const |
739 | { | 756 | { |
740 | return "hostap"; | 757 | return "hostap"; |
741 | } | 758 | } |
742 | 759 | ||
743 | 760 | ||
744 | /*====================================================================================== | 761 | /*====================================================================================== |
745 | * OOrinocoNetworkInterface | 762 | * OOrinocoNetworkInterface |
746 | *======================================================================================*/ | 763 | *======================================================================================*/ |
747 | 764 | ||
748 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) | 765 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) |
749 | :OMonitoringInterface( iface ) | 766 | :OMonitoringInterface( iface ) |
750 | { | 767 | { |
751 | iface->setMonitoring( this ); | 768 | iface->setMonitoring( this ); |
752 | } | 769 | } |
753 | 770 | ||
754 | 771 | ||
755 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 772 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
756 | { | 773 | { |
757 | } | 774 | } |
758 | 775 | ||
759 | 776 | ||
760 | void OOrinocoMonitoringInterface::setChannel( int c ) | 777 | void OOrinocoMonitoringInterface::setChannel( int c ) |
761 | { | 778 | { |
762 | // call iwpriv <device> monitor 2 <channel> | 779 | // call iwpriv <device> monitor 2 <channel> |
763 | int* args = (int*) &_if->_iwr.u.name; | 780 | int* args = (int*) &_if->_iwr.u.name; |
764 | args[0] = 2; | 781 | args[0] = 2; |
765 | args[1] = c; | 782 | args[1] = c; |
766 | _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); | 783 | _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); |
767 | } | 784 | } |
768 | 785 | ||
769 | 786 | ||
770 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 787 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
771 | { | 788 | { |
772 | if ( b ) | 789 | if ( b ) |
773 | { | 790 | { |
774 | setChannel( 1 ); | 791 | setChannel( 1 ); |
775 | } | 792 | } |
776 | else | 793 | else |
777 | { | 794 | { |
778 | // call iwpriv <device> monitor 0 0 | 795 | // call iwpriv <device> monitor 0 0 |
779 | int* args = (int*) &_if->_iwr.u.name; | 796 | int* args = (int*) &_if->_iwr.u.name; |
780 | args[0] = 0; | 797 | args[0] = 0; |
781 | args[1] = 0; | 798 | args[1] = 0; |
782 | _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); | 799 | _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); |
783 | } | 800 | } |
784 | 801 | ||
785 | OMonitoringInterface::setEnabled( b ); | 802 | OMonitoringInterface::setEnabled( b ); |
786 | } | 803 | } |
787 | 804 | ||
788 | 805 | ||
789 | QString OOrinocoMonitoringInterface::name() const | 806 | QString OOrinocoMonitoringInterface::name() const |
790 | { | 807 | { |
791 | return "orinoco"; | 808 | return "orinoco"; |
792 | } | 809 | } |