author | mickeyl <mickeyl> | 2003-10-02 19:52:17 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-02 19:52:17 (UTC) |
commit | 0a9b6ef6ef6fd8d06d420fc25e8a67545815dc39 (patch) (unidiff) | |
tree | 31d9aa2694b2275303cea430934924cd8748dfa5 | |
parent | a5622a23c3083e1ff8a526713aed6a36aaf7a5bd (diff) | |
download | opie-0a9b6ef6ef6fd8d06d420fc25e8a67545815dc39.zip opie-0a9b6ef6ef6fd8d06d420fc25e8a67545815dc39.tar.gz opie-0a9b6ef6ef6fd8d06d420fc25e8a67545815dc39.tar.bz2 |
add note to self to look about automatic channel switching with wlan-ng devices
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 751d841..1f529d2 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,1033 +1,1034 @@ | |||
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 | qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT ); |
71 | synchronize(); | 71 | synchronize(); |
72 | } | 72 | } |
73 | 73 | ||
74 | void ONetwork::synchronize() | 74 | void ONetwork::synchronize() |
75 | { | 75 | { |
76 | // gather available interfaces by inspecting /proc/net/dev | 76 | // gather available interfaces by inspecting /proc/net/dev |
77 | //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 |
78 | //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 |
79 | 79 | ||
80 | _interfaces.clear(); | 80 | _interfaces.clear(); |
81 | QString str; | 81 | QString str; |
82 | QFile f( "/proc/net/dev" ); | 82 | QFile f( "/proc/net/dev" ); |
83 | bool hasFile = f.open( IO_ReadOnly ); | 83 | bool hasFile = f.open( IO_ReadOnly ); |
84 | if ( !hasFile ) | 84 | if ( !hasFile ) |
85 | { | 85 | { |
86 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); | 86 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); |
87 | return; | 87 | return; |
88 | } | 88 | } |
89 | QTextStream s( &f ); | 89 | QTextStream s( &f ); |
90 | s.readLine(); | 90 | s.readLine(); |
91 | s.readLine(); | 91 | s.readLine(); |
92 | while ( !s.atEnd() ) | 92 | while ( !s.atEnd() ) |
93 | { | 93 | { |
94 | s >> str; | 94 | s >> str; |
95 | str.truncate( str.find( ':' ) ); | 95 | str.truncate( str.find( ':' ) ); |
96 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); | 96 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); |
97 | ONetworkInterface* iface; | 97 | ONetworkInterface* iface; |
98 | if ( isWirelessInterface( str ) ) | 98 | if ( isWirelessInterface( str ) ) |
99 | { | 99 | { |
100 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 100 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
101 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 101 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); |
102 | } | 102 | } |
103 | else | 103 | else |
104 | { | 104 | { |
105 | iface = new ONetworkInterface( this, (const char*) str ); | 105 | iface = new ONetworkInterface( this, (const char*) str ); |
106 | } | 106 | } |
107 | _interfaces.insert( str, iface ); | 107 | _interfaces.insert( str, iface ); |
108 | s.readLine(); | 108 | s.readLine(); |
109 | } | 109 | } |
110 | } | 110 | } |
111 | 111 | ||
112 | 112 | ||
113 | short ONetwork::wirelessExtensionVersion() | 113 | short ONetwork::wirelessExtensionVersion() |
114 | { | 114 | { |
115 | return WIRELESS_EXT; | 115 | return WIRELESS_EXT; |
116 | } | 116 | } |
117 | 117 | ||
118 | 118 | ||
119 | int ONetwork::count() const | 119 | int ONetwork::count() const |
120 | { | 120 | { |
121 | return _interfaces.count(); | 121 | return _interfaces.count(); |
122 | } | 122 | } |
123 | 123 | ||
124 | 124 | ||
125 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 125 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
126 | { | 126 | { |
127 | return _interfaces[iface]; | 127 | return _interfaces[iface]; |
128 | } | 128 | } |
129 | 129 | ||
130 | 130 | ||
131 | ONetwork* ONetwork::instance() | 131 | ONetwork* ONetwork::instance() |
132 | { | 132 | { |
133 | if ( !_instance ) _instance = new ONetwork(); | 133 | if ( !_instance ) _instance = new ONetwork(); |
134 | return _instance; | 134 | return _instance; |
135 | } | 135 | } |
136 | 136 | ||
137 | 137 | ||
138 | ONetwork::InterfaceIterator ONetwork::iterator() const | 138 | ONetwork::InterfaceIterator ONetwork::iterator() const |
139 | { | 139 | { |
140 | return ONetwork::InterfaceIterator( _interfaces ); | 140 | return ONetwork::InterfaceIterator( _interfaces ); |
141 | } | 141 | } |
142 | 142 | ||
143 | 143 | ||
144 | bool ONetwork::isWirelessInterface( const char* name ) const | 144 | bool ONetwork::isWirelessInterface( const char* name ) const |
145 | { | 145 | { |
146 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 146 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
147 | struct iwreq iwr; | 147 | struct iwreq iwr; |
148 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 148 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
149 | strcpy( (char*) &iwr.ifr_name, name ); | 149 | strcpy( (char*) &iwr.ifr_name, name ); |
150 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 150 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
151 | return result != -1; | 151 | return result != -1; |
152 | } | 152 | } |
153 | 153 | ||
154 | /*====================================================================================== | 154 | /*====================================================================================== |
155 | * ONetworkInterface | 155 | * ONetworkInterface |
156 | *======================================================================================*/ | 156 | *======================================================================================*/ |
157 | 157 | ||
158 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 158 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
159 | :QObject( parent, name ), | 159 | :QObject( parent, name ), |
160 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 160 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
161 | { | 161 | { |
162 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 162 | qDebug( "ONetworkInterface::ONetworkInterface()" ); |
163 | init(); | 163 | init(); |
164 | } | 164 | } |
165 | 165 | ||
166 | 166 | ||
167 | struct ifreq& ONetworkInterface::ifr() const | 167 | struct ifreq& ONetworkInterface::ifr() const |
168 | { | 168 | { |
169 | return _ifr; | 169 | return _ifr; |
170 | } | 170 | } |
171 | 171 | ||
172 | 172 | ||
173 | void ONetworkInterface::init() | 173 | void ONetworkInterface::init() |
174 | { | 174 | { |
175 | qDebug( "ONetworkInterface::init()" ); | 175 | qDebug( "ONetworkInterface::init()" ); |
176 | 176 | ||
177 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 177 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
178 | 178 | ||
179 | if ( _sfd == -1 ) | 179 | if ( _sfd == -1 ) |
180 | { | 180 | { |
181 | 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() ); |
182 | return; | 182 | return; |
183 | } | 183 | } |
184 | } | 184 | } |
185 | 185 | ||
186 | 186 | ||
187 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 187 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
188 | { | 188 | { |
189 | int result = ::ioctl( _sfd, call, &ifreq ); | 189 | int result = ::ioctl( _sfd, call, &ifreq ); |
190 | if ( result == -1 ) | 190 | if ( result == -1 ) |
191 | 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 ) ); |
192 | else | 192 | else |
193 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); | 193 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); |
194 | return ( result != -1 ); | 194 | return ( result != -1 ); |
195 | } | 195 | } |
196 | 196 | ||
197 | 197 | ||
198 | bool ONetworkInterface::ioctl( int call ) const | 198 | bool ONetworkInterface::ioctl( int call ) const |
199 | { | 199 | { |
200 | strcpy( _ifr.ifr_name, name() ); | 200 | strcpy( _ifr.ifr_name, name() ); |
201 | return ioctl( call, _ifr ); | 201 | return ioctl( call, _ifr ); |
202 | } | 202 | } |
203 | 203 | ||
204 | 204 | ||
205 | bool ONetworkInterface::isLoopback() const | 205 | bool ONetworkInterface::isLoopback() const |
206 | { | 206 | { |
207 | ioctl( SIOCGIFFLAGS ); | 207 | ioctl( SIOCGIFFLAGS ); |
208 | return _ifr.ifr_flags & IFF_LOOPBACK; | 208 | return _ifr.ifr_flags & IFF_LOOPBACK; |
209 | } | 209 | } |
210 | 210 | ||
211 | 211 | ||
212 | bool ONetworkInterface::setUp( bool b ) | 212 | bool ONetworkInterface::setUp( bool b ) |
213 | { | 213 | { |
214 | ioctl( SIOCGIFFLAGS ); | 214 | ioctl( SIOCGIFFLAGS ); |
215 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 215 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
216 | else _ifr.ifr_flags &= (~IFF_UP); | 216 | else _ifr.ifr_flags &= (~IFF_UP); |
217 | return ioctl( SIOCSIFFLAGS ); | 217 | return ioctl( SIOCSIFFLAGS ); |
218 | } | 218 | } |
219 | 219 | ||
220 | 220 | ||
221 | bool ONetworkInterface::isUp() const | 221 | bool ONetworkInterface::isUp() const |
222 | { | 222 | { |
223 | ioctl( SIOCGIFFLAGS ); | 223 | ioctl( SIOCGIFFLAGS ); |
224 | return _ifr.ifr_flags & IFF_UP; | 224 | return _ifr.ifr_flags & IFF_UP; |
225 | } | 225 | } |
226 | 226 | ||
227 | 227 | ||
228 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) | 228 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) |
229 | { | 229 | { |
230 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 230 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
231 | sa->sin_family = AF_INET; | 231 | sa->sin_family = AF_INET; |
232 | sa->sin_port = 0; | 232 | sa->sin_port = 0; |
233 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 233 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
234 | ioctl( SIOCSIFADDR ); | 234 | ioctl( SIOCSIFADDR ); |
235 | } | 235 | } |
236 | 236 | ||
237 | 237 | ||
238 | QString ONetworkInterface::ipV4Address() const | 238 | QString ONetworkInterface::ipV4Address() const |
239 | { | 239 | { |
240 | if ( ioctl( SIOCGIFADDR ) ) | 240 | if ( ioctl( SIOCGIFADDR ) ) |
241 | { | 241 | { |
242 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 242 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
243 | //FIXME: Use QHostAddress here | 243 | //FIXME: Use QHostAddress here |
244 | return QString( inet_ntoa( sa->sin_addr ) ); | 244 | return QString( inet_ntoa( sa->sin_addr ) ); |
245 | } | 245 | } |
246 | else | 246 | else |
247 | return "<unknown>"; | 247 | return "<unknown>"; |
248 | } | 248 | } |
249 | 249 | ||
250 | 250 | ||
251 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) | 251 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) |
252 | { | 252 | { |
253 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | 253 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
254 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); | 254 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); |
255 | ioctl( SIOCSIFHWADDR ); | 255 | ioctl( SIOCSIFHWADDR ); |
256 | } | 256 | } |
257 | 257 | ||
258 | 258 | ||
259 | OMacAddress ONetworkInterface::macAddress() const | 259 | OMacAddress ONetworkInterface::macAddress() const |
260 | { | 260 | { |
261 | if ( ioctl( SIOCGIFHWADDR ) ) | 261 | if ( ioctl( SIOCGIFHWADDR ) ) |
262 | { | 262 | { |
263 | return OMacAddress( _ifr ); | 263 | return OMacAddress( _ifr ); |
264 | } | 264 | } |
265 | else | 265 | else |
266 | { | 266 | { |
267 | return OMacAddress::unknown; | 267 | return OMacAddress::unknown; |
268 | } | 268 | } |
269 | } | 269 | } |
270 | 270 | ||
271 | 271 | ||
272 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) | 272 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) |
273 | { | 273 | { |
274 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 274 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
275 | sa->sin_family = AF_INET; | 275 | sa->sin_family = AF_INET; |
276 | sa->sin_port = 0; | 276 | sa->sin_port = 0; |
277 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 277 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
278 | ioctl( SIOCSIFNETMASK ); | 278 | ioctl( SIOCSIFNETMASK ); |
279 | } | 279 | } |
280 | 280 | ||
281 | 281 | ||
282 | QString ONetworkInterface::ipV4Netmask() const | 282 | QString ONetworkInterface::ipV4Netmask() const |
283 | { | 283 | { |
284 | if ( ioctl( SIOCGIFNETMASK ) ) | 284 | if ( ioctl( SIOCGIFNETMASK ) ) |
285 | { | 285 | { |
286 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 286 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
287 | //FIXME: Use QHostAddress here | 287 | //FIXME: Use QHostAddress here |
288 | return QString( inet_ntoa( sa->sin_addr ) ); | 288 | return QString( inet_ntoa( sa->sin_addr ) ); |
289 | } | 289 | } |
290 | else | 290 | else |
291 | return "<unknown>"; | 291 | return "<unknown>"; |
292 | } | 292 | } |
293 | 293 | ||
294 | 294 | ||
295 | int ONetworkInterface::dataLinkType() const | 295 | int ONetworkInterface::dataLinkType() const |
296 | { | 296 | { |
297 | if ( ioctl( SIOCGIFHWADDR ) ) | 297 | if ( ioctl( SIOCGIFHWADDR ) ) |
298 | { | 298 | { |
299 | return _ifr.ifr_hwaddr.sa_family; | 299 | return _ifr.ifr_hwaddr.sa_family; |
300 | } | 300 | } |
301 | else | 301 | else |
302 | { | 302 | { |
303 | return -1; | 303 | return -1; |
304 | } | 304 | } |
305 | } | 305 | } |
306 | 306 | ||
307 | 307 | ||
308 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 308 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
309 | { | 309 | { |
310 | _mon = m; | 310 | _mon = m; |
311 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); | 311 | qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); |
312 | } | 312 | } |
313 | 313 | ||
314 | 314 | ||
315 | OMonitoringInterface* ONetworkInterface::monitoring() const | 315 | OMonitoringInterface* ONetworkInterface::monitoring() const |
316 | { | 316 | { |
317 | return _mon; | 317 | return _mon; |
318 | } | 318 | } |
319 | 319 | ||
320 | 320 | ||
321 | ONetworkInterface::~ONetworkInterface() | 321 | ONetworkInterface::~ONetworkInterface() |
322 | { | 322 | { |
323 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); | 323 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); |
324 | if ( _sfd != -1 ) ::close( _sfd ); | 324 | if ( _sfd != -1 ) ::close( _sfd ); |
325 | } | 325 | } |
326 | 326 | ||
327 | 327 | ||
328 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 328 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
329 | { | 329 | { |
330 | ioctl( SIOCGIFFLAGS ); | 330 | ioctl( SIOCGIFFLAGS ); |
331 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 331 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
332 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 332 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
333 | return ioctl( SIOCSIFFLAGS ); | 333 | return ioctl( SIOCSIFFLAGS ); |
334 | } | 334 | } |
335 | 335 | ||
336 | 336 | ||
337 | bool ONetworkInterface::promiscuousMode() const | 337 | bool ONetworkInterface::promiscuousMode() const |
338 | { | 338 | { |
339 | ioctl( SIOCGIFFLAGS ); | 339 | ioctl( SIOCGIFFLAGS ); |
340 | return _ifr.ifr_flags & IFF_PROMISC; | 340 | return _ifr.ifr_flags & IFF_PROMISC; |
341 | } | 341 | } |
342 | 342 | ||
343 | 343 | ||
344 | bool ONetworkInterface::isWireless() const | 344 | bool ONetworkInterface::isWireless() const |
345 | { | 345 | { |
346 | return ioctl( SIOCGIWNAME ); | 346 | return ioctl( SIOCGIWNAME ); |
347 | } | 347 | } |
348 | 348 | ||
349 | 349 | ||
350 | /*====================================================================================== | 350 | /*====================================================================================== |
351 | * OChannelHopper | 351 | * OChannelHopper |
352 | *======================================================================================*/ | 352 | *======================================================================================*/ |
353 | 353 | ||
354 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 354 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
355 | :QObject( 0, "Mickey's funky hopper" ), | 355 | :QObject( 0, "Mickey's funky hopper" ), |
356 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 356 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
357 | { | 357 | { |
358 | int _maxChannel = iface->channels()+1; | 358 | int _maxChannel = iface->channels()+1; |
359 | // generate fancy hopping sequence honoring the device capabilities | 359 | // generate fancy hopping sequence honoring the device capabilities |
360 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 360 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
361 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 361 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
362 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 362 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
363 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 363 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
364 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 364 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
365 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 365 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
366 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 366 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
367 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 367 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
368 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 368 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
369 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 369 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
370 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 370 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
371 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 371 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
372 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 372 | if ( _maxChannel >= 6 ) _channels.append( 6 ); |
373 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 373 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
374 | _channel = _channels.begin(); | 374 | _channel = _channels.begin(); |
375 | 375 | ||
376 | } | 376 | } |
377 | 377 | ||
378 | 378 | ||
379 | OChannelHopper::~OChannelHopper() | 379 | OChannelHopper::~OChannelHopper() |
380 | { | 380 | { |
381 | } | 381 | } |
382 | 382 | ||
383 | 383 | ||
384 | bool OChannelHopper::isActive() const | 384 | bool OChannelHopper::isActive() const |
385 | { | 385 | { |
386 | return _tid; | 386 | return _tid; |
387 | } | 387 | } |
388 | 388 | ||
389 | 389 | ||
390 | int OChannelHopper::channel() const | 390 | int OChannelHopper::channel() const |
391 | { | 391 | { |
392 | return *_channel; | 392 | return *_channel; |
393 | } | 393 | } |
394 | 394 | ||
395 | 395 | ||
396 | void OChannelHopper::timerEvent( QTimerEvent* ) | 396 | void OChannelHopper::timerEvent( QTimerEvent* ) |
397 | { | 397 | { |
398 | _iface->setChannel( *_channel ); | 398 | _iface->setChannel( *_channel ); |
399 | emit( hopped( *_channel ) ); | 399 | emit( hopped( *_channel ) ); |
400 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 400 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", |
401 | *_channel, (const char*) _iface->name() ); | 401 | *_channel, (const char*) _iface->name() ); |
402 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 402 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
403 | } | 403 | } |
404 | 404 | ||
405 | 405 | ||
406 | void OChannelHopper::setInterval( int interval ) | 406 | void OChannelHopper::setInterval( int interval ) |
407 | { | 407 | { |
408 | if ( interval == _interval ) | 408 | if ( interval == _interval ) |
409 | return; | 409 | return; |
410 | 410 | ||
411 | if ( _interval ) | 411 | if ( _interval ) |
412 | killTimer( _tid ); | 412 | killTimer( _tid ); |
413 | 413 | ||
414 | _tid = 0; | 414 | _tid = 0; |
415 | _interval = interval; | 415 | _interval = interval; |
416 | 416 | ||
417 | if ( _interval ) | 417 | if ( _interval ) |
418 | { | 418 | { |
419 | _tid = startTimer( interval ); | 419 | _tid = startTimer( interval ); |
420 | } | 420 | } |
421 | } | 421 | } |
422 | 422 | ||
423 | 423 | ||
424 | int OChannelHopper::interval() const | 424 | int OChannelHopper::interval() const |
425 | { | 425 | { |
426 | return _interval; | 426 | return _interval; |
427 | } | 427 | } |
428 | 428 | ||
429 | 429 | ||
430 | /*====================================================================================== | 430 | /*====================================================================================== |
431 | * OWirelessNetworkInterface | 431 | * OWirelessNetworkInterface |
432 | *======================================================================================*/ | 432 | *======================================================================================*/ |
433 | 433 | ||
434 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 434 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
435 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 435 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
436 | { | 436 | { |
437 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 437 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); |
438 | init(); | 438 | init(); |
439 | } | 439 | } |
440 | 440 | ||
441 | 441 | ||
442 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 442 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
443 | { | 443 | { |
444 | } | 444 | } |
445 | 445 | ||
446 | 446 | ||
447 | struct iwreq& OWirelessNetworkInterface::iwr() const | 447 | struct iwreq& OWirelessNetworkInterface::iwr() const |
448 | { | 448 | { |
449 | return _iwr; | 449 | return _iwr; |
450 | } | 450 | } |
451 | 451 | ||
452 | 452 | ||
453 | void OWirelessNetworkInterface::init() | 453 | void OWirelessNetworkInterface::init() |
454 | { | 454 | { |
455 | qDebug( "OWirelessNetworkInterface::init()" ); | 455 | qDebug( "OWirelessNetworkInterface::init()" ); |
456 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 456 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
457 | buildChannelList(); | 457 | buildChannelList(); |
458 | buildPrivateList(); | 458 | buildPrivateList(); |
459 | } | 459 | } |
460 | 460 | ||
461 | 461 | ||
462 | QString OWirelessNetworkInterface::associatedAP() const | 462 | QString OWirelessNetworkInterface::associatedAP() const |
463 | { | 463 | { |
464 | //FIXME: use OMacAddress | 464 | //FIXME: use OMacAddress |
465 | QString mac; | 465 | QString mac; |
466 | 466 | ||
467 | if ( ioctl( SIOCGIWAP ) ) | 467 | if ( ioctl( SIOCGIWAP ) ) |
468 | { | 468 | { |
469 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 469 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
470 | _ifr.ifr_hwaddr.sa_data[0]&0xff, | 470 | _ifr.ifr_hwaddr.sa_data[0]&0xff, |
471 | _ifr.ifr_hwaddr.sa_data[1]&0xff, | 471 | _ifr.ifr_hwaddr.sa_data[1]&0xff, |
472 | _ifr.ifr_hwaddr.sa_data[2]&0xff, | 472 | _ifr.ifr_hwaddr.sa_data[2]&0xff, |
473 | _ifr.ifr_hwaddr.sa_data[3]&0xff, | 473 | _ifr.ifr_hwaddr.sa_data[3]&0xff, |
474 | _ifr.ifr_hwaddr.sa_data[4]&0xff, | 474 | _ifr.ifr_hwaddr.sa_data[4]&0xff, |
475 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); | 475 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); |
476 | } | 476 | } |
477 | else | 477 | else |
478 | { | 478 | { |
479 | mac = "<Unknown>"; | 479 | mac = "<Unknown>"; |
480 | } | 480 | } |
481 | return mac; | 481 | return mac; |
482 | } | 482 | } |
483 | 483 | ||
484 | 484 | ||
485 | void OWirelessNetworkInterface::buildChannelList() | 485 | void OWirelessNetworkInterface::buildChannelList() |
486 | { | 486 | { |
487 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 487 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
488 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | 488 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete |
489 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 489 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
490 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | 490 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate |
491 | //ML: _too much_ space. This is damn shitty crap *sigh* | 491 | //ML: _too much_ space. This is damn shitty crap *sigh* |
492 | //ML: We allocate a large memory region in RAM and check whether the | 492 | //ML: We allocate a large memory region in RAM and check whether the |
493 | //ML: driver pollutes this extra space. The complaint will be made on stdout, | 493 | //ML: driver pollutes this extra space. The complaint will be made on stdout, |
494 | //ML: so please forward this... | 494 | //ML: so please forward this... |
495 | 495 | ||
496 | struct iwreq wrq; | 496 | struct iwreq wrq; |
497 | int len = sizeof( struct iw_range )*2; | 497 | int len = sizeof( struct iw_range )*2; |
498 | char *buffer = (char*) malloc( len ); | 498 | char *buffer = (char*) malloc( len ); |
499 | //FIXME: Validate if we actually got the memory block | 499 | //FIXME: Validate if we actually got the memory block |
500 | memset( buffer, 0, len ); | 500 | memset( buffer, 0, len ); |
501 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | 501 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); |
502 | wrq.u.data.pointer = (caddr_t) buffer; | 502 | wrq.u.data.pointer = (caddr_t) buffer; |
503 | wrq.u.data.length = sizeof( struct iw_range ); | 503 | wrq.u.data.length = sizeof( struct iw_range ); |
504 | wrq.u.data.flags = 0; | 504 | wrq.u.data.flags = 0; |
505 | 505 | ||
506 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 506 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
507 | { | 507 | { |
508 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); | 508 | qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); |
509 | _channels.insert( 2412, 1 ); // 2.412 GHz | 509 | _channels.insert( 2412, 1 ); // 2.412 GHz |
510 | _channels.insert( 2417, 2 ); // 2.417 GHz | 510 | _channels.insert( 2417, 2 ); // 2.417 GHz |
511 | _channels.insert( 2422, 3 ); // 2.422 GHz | 511 | _channels.insert( 2422, 3 ); // 2.422 GHz |
512 | _channels.insert( 2427, 4 ); // 2.427 GHz | 512 | _channels.insert( 2427, 4 ); // 2.427 GHz |
513 | _channels.insert( 2432, 5 ); // 2.432 GHz | 513 | _channels.insert( 2432, 5 ); // 2.432 GHz |
514 | _channels.insert( 2437, 6 ); // 2.437 GHz | 514 | _channels.insert( 2437, 6 ); // 2.437 GHz |
515 | _channels.insert( 2442, 7 ); // 2.442 GHz | 515 | _channels.insert( 2442, 7 ); // 2.442 GHz |
516 | _channels.insert( 2447, 8 ); // 2.447 GHz | 516 | _channels.insert( 2447, 8 ); // 2.447 GHz |
517 | _channels.insert( 2452, 9 ); // 2.452 GHz | 517 | _channels.insert( 2452, 9 ); // 2.452 GHz |
518 | _channels.insert( 2457, 10 ); // 2.457 GHz | 518 | _channels.insert( 2457, 10 ); // 2.457 GHz |
519 | _channels.insert( 2462, 11 ); // 2.462 GHz | 519 | _channels.insert( 2462, 11 ); // 2.462 GHz |
520 | } | 520 | } |
521 | else | 521 | else |
522 | { | 522 | { |
523 | // <check if the driver overwrites stuff> | 523 | // <check if the driver overwrites stuff> |
524 | int max = 0; | 524 | int max = 0; |
525 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 525 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
526 | if (buffer[r] != 0) | 526 | if (buffer[r] != 0) |
527 | max = r; | 527 | max = r; |
528 | if (max > 0) | 528 | if (max > 0) |
529 | { | 529 | { |
530 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" | 530 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" |
531 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); | 531 | "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); |
532 | } | 532 | } |
533 | // </check if the driver overwrites stuff> | 533 | // </check if the driver overwrites stuff> |
534 | 534 | ||
535 | struct iw_range range; | 535 | struct iw_range range; |
536 | memcpy( &range, buffer, sizeof range ); | 536 | memcpy( &range, buffer, sizeof range ); |
537 | 537 | ||
538 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); | 538 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); |
539 | for ( int i = 0; i < range.num_frequency; ++i ) | 539 | for ( int i = 0; i < range.num_frequency; ++i ) |
540 | { | 540 | { |
541 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 541 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
542 | _channels.insert( freq, i+1 ); | 542 | _channels.insert( freq, i+1 ); |
543 | } | 543 | } |
544 | } | 544 | } |
545 | 545 | ||
546 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); | 546 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); |
547 | free(buffer); | 547 | free(buffer); |
548 | } | 548 | } |
549 | 549 | ||
550 | 550 | ||
551 | void OWirelessNetworkInterface::buildPrivateList() | 551 | void OWirelessNetworkInterface::buildPrivateList() |
552 | { | 552 | { |
553 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | 553 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); |
554 | 554 | ||
555 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 555 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
556 | 556 | ||
557 | _iwr.u.data.pointer = (char*) &priv; | 557 | _iwr.u.data.pointer = (char*) &priv; |
558 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | 558 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself |
559 | _iwr.u.data.flags = 0; | 559 | _iwr.u.data.flags = 0; |
560 | 560 | ||
561 | if ( !wioctl( SIOCGIWPRIV ) ) | 561 | if ( !wioctl( SIOCGIWPRIV ) ) |
562 | { | 562 | { |
563 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); | 563 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); |
564 | return; | 564 | return; |
565 | } | 565 | } |
566 | 566 | ||
567 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 567 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
568 | { | 568 | { |
569 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 569 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
570 | } | 570 | } |
571 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); | 571 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); |
572 | } | 572 | } |
573 | 573 | ||
574 | 574 | ||
575 | int OWirelessNetworkInterface::channel() const | 575 | int OWirelessNetworkInterface::channel() const |
576 | { | 576 | { |
577 | //FIXME: When monitoring enabled, then use it | 577 | //FIXME: When monitoring enabled, then use it |
578 | //FIXME: to gather the current RF channel | 578 | //FIXME: to gather the current RF channel |
579 | //FIXME: Until then, get active channel from hopper. | 579 | //FIXME: Until then, get active channel from hopper. |
580 | if ( _hopper && _hopper->isActive() ) | 580 | if ( _hopper && _hopper->isActive() ) |
581 | return _hopper->channel(); | 581 | return _hopper->channel(); |
582 | 582 | ||
583 | if ( !wioctl( SIOCGIWFREQ ) ) | 583 | if ( !wioctl( SIOCGIWFREQ ) ) |
584 | { | 584 | { |
585 | return -1; | 585 | return -1; |
586 | } | 586 | } |
587 | else | 587 | else |
588 | { | 588 | { |
589 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; | 589 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; |
590 | } | 590 | } |
591 | } | 591 | } |
592 | 592 | ||
593 | 593 | ||
594 | void OWirelessNetworkInterface::setChannel( int c ) const | 594 | void OWirelessNetworkInterface::setChannel( int c ) const |
595 | { | 595 | { |
596 | if ( !_mon ) | 596 | if ( !_mon ) |
597 | { | 597 | { |
598 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 598 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
599 | _iwr.u.freq.m = c; | 599 | _iwr.u.freq.m = c; |
600 | _iwr.u.freq.e = 0; | 600 | _iwr.u.freq.e = 0; |
601 | wioctl( SIOCSIWFREQ ); | 601 | wioctl( SIOCSIWFREQ ); |
602 | } | 602 | } |
603 | else | 603 | else |
604 | { | 604 | { |
605 | _mon->setChannel( c ); | 605 | _mon->setChannel( c ); |
606 | } | 606 | } |
607 | } | 607 | } |
608 | 608 | ||
609 | 609 | ||
610 | double OWirelessNetworkInterface::frequency() const | 610 | double OWirelessNetworkInterface::frequency() const |
611 | { | 611 | { |
612 | if ( !wioctl( SIOCGIWFREQ ) ) | 612 | if ( !wioctl( SIOCGIWFREQ ) ) |
613 | { | 613 | { |
614 | return -1.0; | 614 | return -1.0; |
615 | } | 615 | } |
616 | else | 616 | else |
617 | { | 617 | { |
618 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 618 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
619 | } | 619 | } |
620 | } | 620 | } |
621 | 621 | ||
622 | 622 | ||
623 | int OWirelessNetworkInterface::channels() const | 623 | int OWirelessNetworkInterface::channels() const |
624 | { | 624 | { |
625 | return _channels.count(); | 625 | return _channels.count(); |
626 | } | 626 | } |
627 | 627 | ||
628 | 628 | ||
629 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 629 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
630 | { | 630 | { |
631 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 631 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
632 | _hopper->setInterval( interval ); | 632 | _hopper->setInterval( interval ); |
633 | //FIXME: When and by whom will the channel hopper be deleted? | 633 | //FIXME: When and by whom will the channel hopper be deleted? |
634 | //TODO: rely on QObject hierarchy | 634 | //TODO: rely on QObject hierarchy |
635 | } | 635 | } |
636 | 636 | ||
637 | 637 | ||
638 | int OWirelessNetworkInterface::channelHopping() const | 638 | int OWirelessNetworkInterface::channelHopping() const |
639 | { | 639 | { |
640 | return _hopper->interval(); | 640 | return _hopper->interval(); |
641 | } | 641 | } |
642 | 642 | ||
643 | 643 | ||
644 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const | 644 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const |
645 | { | 645 | { |
646 | return _hopper; | 646 | return _hopper; |
647 | } | 647 | } |
648 | 648 | ||
649 | 649 | ||
650 | void OWirelessNetworkInterface::setMode( const QString& mode ) | 650 | void OWirelessNetworkInterface::setMode( const QString& mode ) |
651 | { | 651 | { |
652 | if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; | 652 | if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; |
653 | else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; | 653 | else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; |
654 | else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; | 654 | else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; |
655 | else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; | 655 | else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; |
656 | else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; | 656 | else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; |
657 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; | 657 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; |
658 | #if WIRELESS_EXT > 14 | 658 | #if WIRELESS_EXT > 14 |
659 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; | 659 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; |
660 | #endif | 660 | #endif |
661 | else | 661 | else |
662 | { | 662 | { |
663 | qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); | 663 | qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); |
664 | return; | 664 | return; |
665 | } | 665 | } |
666 | wioctl( SIOCSIWMODE ); | 666 | wioctl( SIOCSIWMODE ); |
667 | } | 667 | } |
668 | 668 | ||
669 | 669 | ||
670 | QString OWirelessNetworkInterface::mode() const | 670 | QString OWirelessNetworkInterface::mode() const |
671 | { | 671 | { |
672 | if ( !wioctl( SIOCGIWMODE ) ) | 672 | if ( !wioctl( SIOCGIWMODE ) ) |
673 | { | 673 | { |
674 | return "<unknown>"; | 674 | return "<unknown>"; |
675 | } | 675 | } |
676 | switch ( _iwr.u.mode ) | 676 | switch ( _iwr.u.mode ) |
677 | { | 677 | { |
678 | case IW_MODE_AUTO: return "auto"; | 678 | case IW_MODE_AUTO: return "auto"; |
679 | case IW_MODE_ADHOC: return "adhoc"; | 679 | case IW_MODE_ADHOC: return "adhoc"; |
680 | case IW_MODE_INFRA: return "managed"; | 680 | case IW_MODE_INFRA: return "managed"; |
681 | case IW_MODE_MASTER: return "master"; | 681 | case IW_MODE_MASTER: return "master"; |
682 | case IW_MODE_REPEAT: return "repeater"; | 682 | case IW_MODE_REPEAT: return "repeater"; |
683 | case IW_MODE_SECOND: return "secondary"; | 683 | case IW_MODE_SECOND: return "secondary"; |
684 | #if WIRELESS_EXT > 14 | 684 | #if WIRELESS_EXT > 14 |
685 | case IW_MODE_MONITOR: return "monitor"; | 685 | case IW_MODE_MONITOR: return "monitor"; |
686 | #endif | 686 | #endif |
687 | default: assert( 0 ); // shouldn't happen | 687 | default: assert( 0 ); // shouldn't happen |
688 | } | 688 | } |
689 | } | 689 | } |
690 | 690 | ||
691 | 691 | ||
692 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 692 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
693 | { | 693 | { |
694 | if ( _mon ) | 694 | if ( _mon ) |
695 | _mon->setEnabled( b ); | 695 | _mon->setEnabled( b ); |
696 | else | 696 | else |
697 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 697 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
698 | } | 698 | } |
699 | 699 | ||
700 | 700 | ||
701 | bool OWirelessNetworkInterface::monitorMode() const | 701 | bool OWirelessNetworkInterface::monitorMode() const |
702 | { | 702 | { |
703 | qDebug( "dataLinkType = %d", dataLinkType() ); | 703 | qDebug( "dataLinkType = %d", dataLinkType() ); |
704 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); | 704 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); |
705 | // 802 is the header type for PRISM - Linux support for this is pending... | 705 | // 802 is the header type for PRISM - Linux support for this is pending... |
706 | } | 706 | } |
707 | 707 | ||
708 | 708 | ||
709 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) | 709 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) |
710 | { | 710 | { |
711 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); | 711 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); |
712 | _iwr.u.essid.length = nickname.length(); | 712 | _iwr.u.essid.length = nickname.length(); |
713 | wioctl( SIOCSIWNICKN ); | 713 | wioctl( SIOCSIWNICKN ); |
714 | } | 714 | } |
715 | 715 | ||
716 | 716 | ||
717 | QString OWirelessNetworkInterface::nickName() const | 717 | QString OWirelessNetworkInterface::nickName() const |
718 | { | 718 | { |
719 | char str[IW_ESSID_MAX_SIZE]; | 719 | char str[IW_ESSID_MAX_SIZE]; |
720 | _iwr.u.data.pointer = &str[0]; | 720 | _iwr.u.data.pointer = &str[0]; |
721 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 721 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
722 | if ( !wioctl( SIOCGIWNICKN ) ) | 722 | if ( !wioctl( SIOCGIWNICKN ) ) |
723 | { | 723 | { |
724 | return "<unknown>"; | 724 | return "<unknown>"; |
725 | } | 725 | } |
726 | else | 726 | else |
727 | { | 727 | { |
728 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 728 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
729 | return str; | 729 | return str; |
730 | } | 730 | } |
731 | } | 731 | } |
732 | 732 | ||
733 | 733 | ||
734 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 734 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
735 | { | 735 | { |
736 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 736 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
737 | if ( !priv ) | 737 | if ( !priv ) |
738 | { | 738 | { |
739 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); | 739 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); |
740 | return; | 740 | return; |
741 | } | 741 | } |
742 | if ( priv->numberSetArgs() != numargs ) | 742 | if ( priv->numberSetArgs() != numargs ) |
743 | { | 743 | { |
744 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); | 744 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); |
745 | return; | 745 | return; |
746 | } | 746 | } |
747 | 747 | ||
748 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); | 748 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); |
749 | memset( &_iwr, 0, sizeof _iwr ); | 749 | memset( &_iwr, 0, sizeof _iwr ); |
750 | va_list argp; | 750 | va_list argp; |
751 | va_start( argp, numargs ); | 751 | va_start( argp, numargs ); |
752 | for ( int i = 0; i < numargs; ++i ) | 752 | for ( int i = 0; i < numargs; ++i ) |
753 | { | 753 | { |
754 | priv->setParameter( i, va_arg( argp, int ) ); | 754 | priv->setParameter( i, va_arg( argp, int ) ); |
755 | } | 755 | } |
756 | va_end( argp ); | 756 | va_end( argp ); |
757 | priv->invoke(); | 757 | priv->invoke(); |
758 | } | 758 | } |
759 | 759 | ||
760 | 760 | ||
761 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 761 | void OWirelessNetworkInterface::getPrivate( const QString& call ) |
762 | { | 762 | { |
763 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); | 763 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); |
764 | } | 764 | } |
765 | 765 | ||
766 | 766 | ||
767 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | 767 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) |
768 | { | 768 | { |
769 | return child( (const char*) call ); | 769 | return child( (const char*) call ); |
770 | } | 770 | } |
771 | 771 | ||
772 | 772 | ||
773 | QString OWirelessNetworkInterface::SSID() const | 773 | QString OWirelessNetworkInterface::SSID() const |
774 | { | 774 | { |
775 | char str[IW_ESSID_MAX_SIZE]; | 775 | char str[IW_ESSID_MAX_SIZE]; |
776 | _iwr.u.essid.pointer = &str[0]; | 776 | _iwr.u.essid.pointer = &str[0]; |
777 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 777 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
778 | if ( !wioctl( SIOCGIWESSID ) ) | 778 | if ( !wioctl( SIOCGIWESSID ) ) |
779 | { | 779 | { |
780 | return "<unknown>"; | 780 | return "<unknown>"; |
781 | } | 781 | } |
782 | else | 782 | else |
783 | { | 783 | { |
784 | return str; | 784 | return str; |
785 | } | 785 | } |
786 | } | 786 | } |
787 | 787 | ||
788 | 788 | ||
789 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 789 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
790 | { | 790 | { |
791 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 791 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
792 | _iwr.u.essid.length = ssid.length(); | 792 | _iwr.u.essid.length = ssid.length(); |
793 | wioctl( SIOCSIWESSID ); | 793 | wioctl( SIOCSIWESSID ); |
794 | } | 794 | } |
795 | 795 | ||
796 | 796 | ||
797 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 797 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
798 | { | 798 | { |
799 | int result = ::ioctl( _sfd, call, &iwreq ); | 799 | int result = ::ioctl( _sfd, call, &iwreq ); |
800 | if ( result == -1 ) | 800 | if ( result == -1 ) |
801 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 801 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); |
802 | else | 802 | else |
803 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); | 803 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); |
804 | return ( result != -1 ); | 804 | return ( result != -1 ); |
805 | } | 805 | } |
806 | 806 | ||
807 | 807 | ||
808 | bool OWirelessNetworkInterface::wioctl( int call ) const | 808 | bool OWirelessNetworkInterface::wioctl( int call ) const |
809 | { | 809 | { |
810 | strcpy( _iwr.ifr_name, name() ); | 810 | strcpy( _iwr.ifr_name, name() ); |
811 | return wioctl( call, _iwr ); | 811 | return wioctl( call, _iwr ); |
812 | } | 812 | } |
813 | 813 | ||
814 | 814 | ||
815 | /*====================================================================================== | 815 | /*====================================================================================== |
816 | * OMonitoringInterface | 816 | * OMonitoringInterface |
817 | *======================================================================================*/ | 817 | *======================================================================================*/ |
818 | 818 | ||
819 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 819 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
820 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) | 820 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) |
821 | { | 821 | { |
822 | } | 822 | } |
823 | 823 | ||
824 | 824 | ||
825 | OMonitoringInterface::~OMonitoringInterface() | 825 | OMonitoringInterface::~OMonitoringInterface() |
826 | { | 826 | { |
827 | } | 827 | } |
828 | 828 | ||
829 | 829 | ||
830 | void OMonitoringInterface::setChannel( int c ) | 830 | void OMonitoringInterface::setChannel( int c ) |
831 | { | 831 | { |
832 | // use standard WE channel switching protocol | 832 | // use standard WE channel switching protocol |
833 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 833 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
834 | _if->_iwr.u.freq.m = c; | 834 | _if->_iwr.u.freq.m = c; |
835 | _if->_iwr.u.freq.e = 0; | 835 | _if->_iwr.u.freq.e = 0; |
836 | _if->wioctl( SIOCSIWFREQ ); | 836 | _if->wioctl( SIOCSIWFREQ ); |
837 | } | 837 | } |
838 | 838 | ||
839 | 839 | ||
840 | bool OMonitoringInterface::enabled() const | 840 | bool OMonitoringInterface::enabled() const |
841 | { | 841 | { |
842 | return _if->monitorMode(); | 842 | return _if->monitorMode(); |
843 | } | 843 | } |
844 | 844 | ||
845 | 845 | ||
846 | void OMonitoringInterface::setEnabled( bool b ) | 846 | void OMonitoringInterface::setEnabled( bool b ) |
847 | { | 847 | { |
848 | } | 848 | } |
849 | 849 | ||
850 | 850 | ||
851 | /*====================================================================================== | 851 | /*====================================================================================== |
852 | * OCiscoMonitoringInterface | 852 | * OCiscoMonitoringInterface |
853 | *======================================================================================*/ | 853 | *======================================================================================*/ |
854 | 854 | ||
855 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 855 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
856 | :OMonitoringInterface( iface, prismHeader ) | 856 | :OMonitoringInterface( iface, prismHeader ) |
857 | { | 857 | { |
858 | iface->setMonitoring( this ); | 858 | iface->setMonitoring( this ); |
859 | } | 859 | } |
860 | 860 | ||
861 | 861 | ||
862 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 862 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
863 | { | 863 | { |
864 | } | 864 | } |
865 | 865 | ||
866 | 866 | ||
867 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 867 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
868 | { | 868 | { |
869 | QString fname; | 869 | QString fname; |
870 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 870 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
871 | QFile f( fname ); | 871 | QFile f( fname ); |
872 | if ( !f.exists() ) return; | 872 | if ( !f.exists() ) return; |
873 | 873 | ||
874 | if ( f.open( IO_WriteOnly ) ) | 874 | if ( f.open( IO_WriteOnly ) ) |
875 | { | 875 | { |
876 | QTextStream s( &f ); | 876 | QTextStream s( &f ); |
877 | s << "Mode: r"; | 877 | s << "Mode: r"; |
878 | s << "Mode: y"; | 878 | s << "Mode: y"; |
879 | s << "XmitPower: 1"; | 879 | s << "XmitPower: 1"; |
880 | } | 880 | } |
881 | 881 | ||
882 | // 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 |
883 | } | 883 | } |
884 | 884 | ||
885 | 885 | ||
886 | QString OCiscoMonitoringInterface::name() const | 886 | QString OCiscoMonitoringInterface::name() const |
887 | { | 887 | { |
888 | return "cisco"; | 888 | return "cisco"; |
889 | } | 889 | } |
890 | 890 | ||
891 | 891 | ||
892 | void OCiscoMonitoringInterface::setChannel( int ) | 892 | void OCiscoMonitoringInterface::setChannel( int ) |
893 | { | 893 | { |
894 | // cisco devices automatically switch channels when in monitor mode | 894 | // cisco devices automatically switch channels when in monitor mode |
895 | } | 895 | } |
896 | 896 | ||
897 | 897 | ||
898 | /*====================================================================================== | 898 | /*====================================================================================== |
899 | * OWlanNGMonitoringInterface | 899 | * OWlanNGMonitoringInterface |
900 | *======================================================================================*/ | 900 | *======================================================================================*/ |
901 | 901 | ||
902 | 902 | ||
903 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 903 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
904 | :OMonitoringInterface( iface, prismHeader ) | 904 | :OMonitoringInterface( iface, prismHeader ) |
905 | { | 905 | { |
906 | iface->setMonitoring( this ); | 906 | iface->setMonitoring( this ); |
907 | } | 907 | } |
908 | 908 | ||
909 | 909 | ||
910 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 910 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
911 | { | 911 | { |
912 | } | 912 | } |
913 | 913 | ||
914 | 914 | ||
915 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 915 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
916 | { | 916 | { |
917 | //FIXME: do nothing if its already in the same mode | 917 | //FIXME: do nothing if its already in the same mode |
918 | 918 | ||
919 | QString enable = b ? "true" : "false"; | 919 | QString enable = b ? "true" : "false"; |
920 | QString prism = _prismHeader ? "true" : "false"; | 920 | QString prism = _prismHeader ? "true" : "false"; |
921 | QString cmd; | 921 | QString cmd; |
922 | 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", |
923 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); | 923 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); |
924 | system( cmd ); | 924 | system( cmd ); |
925 | } | 925 | } |
926 | 926 | ||
927 | 927 | ||
928 | QString OWlanNGMonitoringInterface::name() const | 928 | QString OWlanNGMonitoringInterface::name() const |
929 | { | 929 | { |
930 | return "wlan-ng"; | 930 | return "wlan-ng"; |
931 | } | 931 | } |
932 | 932 | ||
933 | 933 | ||
934 | void OWlanNGMonitoringInterface::setChannel( int ) | 934 | void OWlanNGMonitoringInterface::setChannel( int ) |
935 | { | 935 | { |
936 | // wlan-ng devices automatically switch channels when in monitor mode | 936 | // wlan-ng devices automatically switch channels when in monitor mode |
937 | // NOTE: The above note no longer seems to be true for recent driver versions! | ||
937 | } | 938 | } |
938 | 939 | ||
939 | 940 | ||
940 | /*====================================================================================== | 941 | /*====================================================================================== |
941 | * OHostAPMonitoringInterface | 942 | * OHostAPMonitoringInterface |
942 | *======================================================================================*/ | 943 | *======================================================================================*/ |
943 | 944 | ||
944 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 945 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
945 | :OMonitoringInterface( iface, prismHeader ) | 946 | :OMonitoringInterface( iface, prismHeader ) |
946 | { | 947 | { |
947 | iface->setMonitoring( this ); | 948 | iface->setMonitoring( this ); |
948 | } | 949 | } |
949 | 950 | ||
950 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 951 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
951 | { | 952 | { |
952 | } | 953 | } |
953 | 954 | ||
954 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 955 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
955 | { | 956 | { |
956 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 957 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
957 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 958 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
958 | 959 | ||
959 | #if WIRELESS_EXT > 14 | 960 | #if WIRELESS_EXT > 14 |
960 | if ( b ) | 961 | if ( b ) |
961 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header | 962 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header |
962 | else | 963 | else |
963 | _if->setMode( "managed" ); | 964 | _if->setMode( "managed" ); |
964 | #else | 965 | #else |
965 | int monitorCode = _prismHeader ? 1 : 2; | 966 | int monitorCode = _prismHeader ? 1 : 2; |
966 | if ( b ) | 967 | if ( b ) |
967 | { | 968 | { |
968 | _if->setPrivate( "monitor", 1, monitorCode ); | 969 | _if->setPrivate( "monitor", 1, monitorCode ); |
969 | } | 970 | } |
970 | else | 971 | else |
971 | { | 972 | { |
972 | _if->setPrivate( "monitor", 1, 0 ); | 973 | _if->setPrivate( "monitor", 1, 0 ); |
973 | } | 974 | } |
974 | #endif | 975 | #endif |
975 | } | 976 | } |
976 | 977 | ||
977 | 978 | ||
978 | QString OHostAPMonitoringInterface::name() const | 979 | QString OHostAPMonitoringInterface::name() const |
979 | { | 980 | { |
980 | return "hostap"; | 981 | return "hostap"; |
981 | } | 982 | } |
982 | 983 | ||
983 | 984 | ||
984 | /*====================================================================================== | 985 | /*====================================================================================== |
985 | * OOrinocoNetworkInterface | 986 | * OOrinocoNetworkInterface |
986 | *======================================================================================*/ | 987 | *======================================================================================*/ |
987 | 988 | ||
988 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 989 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
989 | :OMonitoringInterface( iface, prismHeader ) | 990 | :OMonitoringInterface( iface, prismHeader ) |
990 | { | 991 | { |
991 | iface->setMonitoring( this ); | 992 | iface->setMonitoring( this ); |
992 | } | 993 | } |
993 | 994 | ||
994 | 995 | ||
995 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 996 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
996 | { | 997 | { |
997 | } | 998 | } |
998 | 999 | ||
999 | 1000 | ||
1000 | void OOrinocoMonitoringInterface::setChannel( int c ) | 1001 | void OOrinocoMonitoringInterface::setChannel( int c ) |
1001 | { | 1002 | { |
1002 | int monitorCode = _prismHeader ? 1 : 2; | 1003 | int monitorCode = _prismHeader ? 1 : 2; |
1003 | _if->setPrivate( "monitor", 2, monitorCode, c ); | 1004 | _if->setPrivate( "monitor", 2, monitorCode, c ); |
1004 | } | 1005 | } |
1005 | 1006 | ||
1006 | 1007 | ||
1007 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 1008 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
1008 | { | 1009 | { |
1009 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 1010 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
1010 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 1011 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
1011 | 1012 | ||
1012 | #if WIRELESS_EXT > 14 | 1013 | #if WIRELESS_EXT > 14 |
1013 | if ( b ) | 1014 | if ( b ) |
1014 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header | 1015 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header |
1015 | else | 1016 | else |
1016 | _if->setMode( "managed" ); | 1017 | _if->setMode( "managed" ); |
1017 | #else | 1018 | #else |
1018 | if ( b ) | 1019 | if ( b ) |
1019 | { | 1020 | { |
1020 | setChannel( 1 ); | 1021 | setChannel( 1 ); |
1021 | } | 1022 | } |
1022 | else | 1023 | else |
1023 | { | 1024 | { |
1024 | _if->setPrivate( "monitor", 2, 0, 0 ); | 1025 | _if->setPrivate( "monitor", 2, 0, 0 ); |
1025 | } | 1026 | } |
1026 | #endif | 1027 | #endif |
1027 | } | 1028 | } |
1028 | 1029 | ||
1029 | 1030 | ||
1030 | QString OOrinocoMonitoringInterface::name() const | 1031 | QString OOrinocoMonitoringInterface::name() const |
1031 | { | 1032 | { |
1032 | return "orinoco"; | 1033 | return "orinoco"; |
1033 | } | 1034 | } |