author | mickeyl <mickeyl> | 2003-10-09 16:01:08 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-10-09 16:01:08 (UTC) |
commit | 802c9ab6b89fd10f709aa012e8ff075e9b4a5d7f (patch) (unidiff) | |
tree | c6a33ab027752ca04d0d98a2e71a238aa954978d | |
parent | c5c5c9f9fc6cab574f35f8be21076ac81f8c0369 (diff) | |
download | opie-802c9ab6b89fd10f709aa012e8ff075e9b4a5d7f.zip opie-802c9ab6b89fd10f709aa012e8ff075e9b4a5d7f.tar.gz opie-802c9ab6b89fd10f709aa012e8ff075e9b4a5d7f.tar.bz2 |
- fix monitor mode on orinoco. Although WE > 14 define the standard mode
"MONITOR", the orinoco monitor patch for 0.13e still does not use that...
- add documentation, a warning, and a runtime check for setChannel(0)
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 12 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 2 |
2 files changed, 12 insertions, 2 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 45ee4c0..767651e 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,1040 +1,1048 @@ | |||
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 ( c ) | ||
597 | { | ||
598 | qWarning( "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" ); | ||
599 | return; | ||
600 | } | ||
601 | |||
596 | if ( !_mon ) | 602 | if ( !_mon ) |
597 | { | 603 | { |
598 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 604 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
599 | _iwr.u.freq.m = c; | 605 | _iwr.u.freq.m = c; |
600 | _iwr.u.freq.e = 0; | 606 | _iwr.u.freq.e = 0; |
601 | wioctl( SIOCSIWFREQ ); | 607 | wioctl( SIOCSIWFREQ ); |
602 | } | 608 | } |
603 | else | 609 | else |
604 | { | 610 | { |
605 | _mon->setChannel( c ); | 611 | _mon->setChannel( c ); |
606 | } | 612 | } |
607 | } | 613 | } |
608 | 614 | ||
609 | 615 | ||
610 | double OWirelessNetworkInterface::frequency() const | 616 | double OWirelessNetworkInterface::frequency() const |
611 | { | 617 | { |
612 | if ( !wioctl( SIOCGIWFREQ ) ) | 618 | if ( !wioctl( SIOCGIWFREQ ) ) |
613 | { | 619 | { |
614 | return -1.0; | 620 | return -1.0; |
615 | } | 621 | } |
616 | else | 622 | else |
617 | { | 623 | { |
618 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 624 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
619 | } | 625 | } |
620 | } | 626 | } |
621 | 627 | ||
622 | 628 | ||
623 | int OWirelessNetworkInterface::channels() const | 629 | int OWirelessNetworkInterface::channels() const |
624 | { | 630 | { |
625 | return _channels.count(); | 631 | return _channels.count(); |
626 | } | 632 | } |
627 | 633 | ||
628 | 634 | ||
629 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 635 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
630 | { | 636 | { |
631 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 637 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
632 | _hopper->setInterval( interval ); | 638 | _hopper->setInterval( interval ); |
633 | //FIXME: When and by whom will the channel hopper be deleted? | 639 | //FIXME: When and by whom will the channel hopper be deleted? |
634 | //TODO: rely on QObject hierarchy | 640 | //TODO: rely on QObject hierarchy |
635 | } | 641 | } |
636 | 642 | ||
637 | 643 | ||
638 | int OWirelessNetworkInterface::channelHopping() const | 644 | int OWirelessNetworkInterface::channelHopping() const |
639 | { | 645 | { |
640 | return _hopper->interval(); | 646 | return _hopper->interval(); |
641 | } | 647 | } |
642 | 648 | ||
643 | 649 | ||
644 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const | 650 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const |
645 | { | 651 | { |
646 | return _hopper; | 652 | return _hopper; |
647 | } | 653 | } |
648 | 654 | ||
649 | 655 | ||
650 | void OWirelessNetworkInterface::setMode( const QString& mode ) | 656 | void OWirelessNetworkInterface::setMode( const QString& mode ) |
651 | { | 657 | { |
652 | if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; | 658 | if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; |
653 | else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; | 659 | else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; |
654 | else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; | 660 | else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; |
655 | else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; | 661 | else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; |
656 | else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; | 662 | else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; |
657 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; | 663 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; |
658 | #if WIRELESS_EXT > 14 | 664 | #if WIRELESS_EXT > 14 |
659 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; | 665 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; |
660 | #endif | 666 | #endif |
661 | else | 667 | else |
662 | { | 668 | { |
663 | qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); | 669 | qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); |
664 | return; | 670 | return; |
665 | } | 671 | } |
666 | wioctl( SIOCSIWMODE ); | 672 | wioctl( SIOCSIWMODE ); |
667 | } | 673 | } |
668 | 674 | ||
669 | 675 | ||
670 | QString OWirelessNetworkInterface::mode() const | 676 | QString OWirelessNetworkInterface::mode() const |
671 | { | 677 | { |
672 | if ( !wioctl( SIOCGIWMODE ) ) | 678 | if ( !wioctl( SIOCGIWMODE ) ) |
673 | { | 679 | { |
674 | return "<unknown>"; | 680 | return "<unknown>"; |
675 | } | 681 | } |
676 | switch ( _iwr.u.mode ) | 682 | switch ( _iwr.u.mode ) |
677 | { | 683 | { |
678 | case IW_MODE_AUTO: return "auto"; | 684 | case IW_MODE_AUTO: return "auto"; |
679 | case IW_MODE_ADHOC: return "adhoc"; | 685 | case IW_MODE_ADHOC: return "adhoc"; |
680 | case IW_MODE_INFRA: return "managed"; | 686 | case IW_MODE_INFRA: return "managed"; |
681 | case IW_MODE_MASTER: return "master"; | 687 | case IW_MODE_MASTER: return "master"; |
682 | case IW_MODE_REPEAT: return "repeater"; | 688 | case IW_MODE_REPEAT: return "repeater"; |
683 | case IW_MODE_SECOND: return "secondary"; | 689 | case IW_MODE_SECOND: return "secondary"; |
684 | #if WIRELESS_EXT > 14 | 690 | #if WIRELESS_EXT > 14 |
685 | case IW_MODE_MONITOR: return "monitor"; | 691 | case IW_MODE_MONITOR: return "monitor"; |
686 | #endif | 692 | #endif |
687 | default: assert( 0 ); // shouldn't happen | 693 | default: assert( 0 ); // shouldn't happen |
688 | } | 694 | } |
689 | } | 695 | } |
690 | 696 | ||
691 | 697 | ||
692 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 698 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
693 | { | 699 | { |
694 | if ( _mon ) | 700 | if ( _mon ) |
695 | _mon->setEnabled( b ); | 701 | _mon->setEnabled( b ); |
696 | else | 702 | else |
697 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 703 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
698 | } | 704 | } |
699 | 705 | ||
700 | 706 | ||
701 | bool OWirelessNetworkInterface::monitorMode() const | 707 | bool OWirelessNetworkInterface::monitorMode() const |
702 | { | 708 | { |
703 | qDebug( "dataLinkType = %d", dataLinkType() ); | 709 | qDebug( "dataLinkType = %d", dataLinkType() ); |
704 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); | 710 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); |
705 | // 802 is the header type for PRISM - Linux support for this is pending... | 711 | // 802 is the header type for PRISM - Linux support for this is pending... |
706 | } | 712 | } |
707 | 713 | ||
708 | 714 | ||
709 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) | 715 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) |
710 | { | 716 | { |
711 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); | 717 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); |
712 | _iwr.u.essid.length = nickname.length(); | 718 | _iwr.u.essid.length = nickname.length(); |
713 | wioctl( SIOCSIWNICKN ); | 719 | wioctl( SIOCSIWNICKN ); |
714 | } | 720 | } |
715 | 721 | ||
716 | 722 | ||
717 | QString OWirelessNetworkInterface::nickName() const | 723 | QString OWirelessNetworkInterface::nickName() const |
718 | { | 724 | { |
719 | char str[IW_ESSID_MAX_SIZE]; | 725 | char str[IW_ESSID_MAX_SIZE]; |
720 | _iwr.u.data.pointer = &str[0]; | 726 | _iwr.u.data.pointer = &str[0]; |
721 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 727 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
722 | if ( !wioctl( SIOCGIWNICKN ) ) | 728 | if ( !wioctl( SIOCGIWNICKN ) ) |
723 | { | 729 | { |
724 | return "<unknown>"; | 730 | return "<unknown>"; |
725 | } | 731 | } |
726 | else | 732 | else |
727 | { | 733 | { |
728 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 734 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
729 | return str; | 735 | return str; |
730 | } | 736 | } |
731 | } | 737 | } |
732 | 738 | ||
733 | 739 | ||
734 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 740 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
735 | { | 741 | { |
736 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 742 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
737 | if ( !priv ) | 743 | if ( !priv ) |
738 | { | 744 | { |
739 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); | 745 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); |
740 | return; | 746 | return; |
741 | } | 747 | } |
742 | if ( priv->numberSetArgs() != numargs ) | 748 | if ( priv->numberSetArgs() != numargs ) |
743 | { | 749 | { |
744 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); | 750 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); |
745 | return; | 751 | return; |
746 | } | 752 | } |
747 | 753 | ||
748 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); | 754 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); |
749 | memset( &_iwr, 0, sizeof _iwr ); | 755 | memset( &_iwr, 0, sizeof _iwr ); |
750 | va_list argp; | 756 | va_list argp; |
751 | va_start( argp, numargs ); | 757 | va_start( argp, numargs ); |
752 | for ( int i = 0; i < numargs; ++i ) | 758 | for ( int i = 0; i < numargs; ++i ) |
753 | { | 759 | { |
754 | priv->setParameter( i, va_arg( argp, int ) ); | 760 | priv->setParameter( i, va_arg( argp, int ) ); |
755 | } | 761 | } |
756 | va_end( argp ); | 762 | va_end( argp ); |
757 | priv->invoke(); | 763 | priv->invoke(); |
758 | } | 764 | } |
759 | 765 | ||
760 | 766 | ||
761 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 767 | void OWirelessNetworkInterface::getPrivate( const QString& call ) |
762 | { | 768 | { |
763 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); | 769 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); |
764 | } | 770 | } |
765 | 771 | ||
766 | 772 | ||
767 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | 773 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) |
768 | { | 774 | { |
769 | return child( (const char*) call ); | 775 | return child( (const char*) call ); |
770 | } | 776 | } |
771 | 777 | ||
772 | 778 | ||
773 | QString OWirelessNetworkInterface::SSID() const | 779 | QString OWirelessNetworkInterface::SSID() const |
774 | { | 780 | { |
775 | char str[IW_ESSID_MAX_SIZE]; | 781 | char str[IW_ESSID_MAX_SIZE]; |
776 | _iwr.u.essid.pointer = &str[0]; | 782 | _iwr.u.essid.pointer = &str[0]; |
777 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 783 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
778 | if ( !wioctl( SIOCGIWESSID ) ) | 784 | if ( !wioctl( SIOCGIWESSID ) ) |
779 | { | 785 | { |
780 | return "<unknown>"; | 786 | return "<unknown>"; |
781 | } | 787 | } |
782 | else | 788 | else |
783 | { | 789 | { |
784 | return str; | 790 | return str; |
785 | } | 791 | } |
786 | } | 792 | } |
787 | 793 | ||
788 | 794 | ||
789 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 795 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
790 | { | 796 | { |
791 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 797 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
792 | _iwr.u.essid.length = ssid.length(); | 798 | _iwr.u.essid.length = ssid.length(); |
793 | wioctl( SIOCSIWESSID ); | 799 | wioctl( SIOCSIWESSID ); |
794 | } | 800 | } |
795 | 801 | ||
796 | 802 | ||
797 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 803 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
798 | { | 804 | { |
799 | int result = ::ioctl( _sfd, call, &iwreq ); | 805 | int result = ::ioctl( _sfd, call, &iwreq ); |
800 | if ( result == -1 ) | 806 | if ( result == -1 ) |
801 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 807 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); |
802 | else | 808 | else |
803 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); | 809 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); |
804 | return ( result != -1 ); | 810 | return ( result != -1 ); |
805 | } | 811 | } |
806 | 812 | ||
807 | 813 | ||
808 | bool OWirelessNetworkInterface::wioctl( int call ) const | 814 | bool OWirelessNetworkInterface::wioctl( int call ) const |
809 | { | 815 | { |
810 | strcpy( _iwr.ifr_name, name() ); | 816 | strcpy( _iwr.ifr_name, name() ); |
811 | return wioctl( call, _iwr ); | 817 | return wioctl( call, _iwr ); |
812 | } | 818 | } |
813 | 819 | ||
814 | 820 | ||
815 | /*====================================================================================== | 821 | /*====================================================================================== |
816 | * OMonitoringInterface | 822 | * OMonitoringInterface |
817 | *======================================================================================*/ | 823 | *======================================================================================*/ |
818 | 824 | ||
819 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 825 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
820 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) | 826 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) |
821 | { | 827 | { |
822 | } | 828 | } |
823 | 829 | ||
824 | 830 | ||
825 | OMonitoringInterface::~OMonitoringInterface() | 831 | OMonitoringInterface::~OMonitoringInterface() |
826 | { | 832 | { |
827 | } | 833 | } |
828 | 834 | ||
829 | 835 | ||
830 | void OMonitoringInterface::setChannel( int c ) | 836 | void OMonitoringInterface::setChannel( int c ) |
831 | { | 837 | { |
832 | // use standard WE channel switching protocol | 838 | // use standard WE channel switching protocol |
833 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 839 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
834 | _if->_iwr.u.freq.m = c; | 840 | _if->_iwr.u.freq.m = c; |
835 | _if->_iwr.u.freq.e = 0; | 841 | _if->_iwr.u.freq.e = 0; |
836 | _if->wioctl( SIOCSIWFREQ ); | 842 | _if->wioctl( SIOCSIWFREQ ); |
837 | } | 843 | } |
838 | 844 | ||
839 | 845 | ||
840 | bool OMonitoringInterface::enabled() const | 846 | bool OMonitoringInterface::enabled() const |
841 | { | 847 | { |
842 | return _if->monitorMode(); | 848 | return _if->monitorMode(); |
843 | } | 849 | } |
844 | 850 | ||
845 | 851 | ||
846 | void OMonitoringInterface::setEnabled( bool b ) | 852 | void OMonitoringInterface::setEnabled( bool b ) |
847 | { | 853 | { |
848 | } | 854 | } |
849 | 855 | ||
850 | 856 | ||
851 | /*====================================================================================== | 857 | /*====================================================================================== |
852 | * OCiscoMonitoringInterface | 858 | * OCiscoMonitoringInterface |
853 | *======================================================================================*/ | 859 | *======================================================================================*/ |
854 | 860 | ||
855 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 861 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
856 | :OMonitoringInterface( iface, prismHeader ) | 862 | :OMonitoringInterface( iface, prismHeader ) |
857 | { | 863 | { |
858 | iface->setMonitoring( this ); | 864 | iface->setMonitoring( this ); |
859 | } | 865 | } |
860 | 866 | ||
861 | 867 | ||
862 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 868 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
863 | { | 869 | { |
864 | } | 870 | } |
865 | 871 | ||
866 | 872 | ||
867 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 873 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
868 | { | 874 | { |
869 | QString fname; | 875 | QString fname; |
870 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 876 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
871 | QFile f( fname ); | 877 | QFile f( fname ); |
872 | if ( !f.exists() ) return; | 878 | if ( !f.exists() ) return; |
873 | 879 | ||
874 | if ( f.open( IO_WriteOnly ) ) | 880 | if ( f.open( IO_WriteOnly ) ) |
875 | { | 881 | { |
876 | QTextStream s( &f ); | 882 | QTextStream s( &f ); |
877 | s << "Mode: r"; | 883 | s << "Mode: r"; |
878 | s << "Mode: y"; | 884 | s << "Mode: y"; |
879 | s << "XmitPower: 1"; | 885 | s << "XmitPower: 1"; |
880 | } | 886 | } |
881 | 887 | ||
882 | // flushing and closing will be done automatically when f goes out of scope | 888 | // flushing and closing will be done automatically when f goes out of scope |
883 | } | 889 | } |
884 | 890 | ||
885 | 891 | ||
886 | QString OCiscoMonitoringInterface::name() const | 892 | QString OCiscoMonitoringInterface::name() const |
887 | { | 893 | { |
888 | return "cisco"; | 894 | return "cisco"; |
889 | } | 895 | } |
890 | 896 | ||
891 | 897 | ||
892 | void OCiscoMonitoringInterface::setChannel( int ) | 898 | void OCiscoMonitoringInterface::setChannel( int ) |
893 | { | 899 | { |
894 | // cisco devices automatically switch channels when in monitor mode | 900 | // cisco devices automatically switch channels when in monitor mode |
895 | } | 901 | } |
896 | 902 | ||
897 | 903 | ||
898 | /*====================================================================================== | 904 | /*====================================================================================== |
899 | * OWlanNGMonitoringInterface | 905 | * OWlanNGMonitoringInterface |
900 | *======================================================================================*/ | 906 | *======================================================================================*/ |
901 | 907 | ||
902 | 908 | ||
903 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 909 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
904 | :OMonitoringInterface( iface, prismHeader ) | 910 | :OMonitoringInterface( iface, prismHeader ) |
905 | { | 911 | { |
906 | iface->setMonitoring( this ); | 912 | iface->setMonitoring( this ); |
907 | } | 913 | } |
908 | 914 | ||
909 | 915 | ||
910 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 916 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
911 | { | 917 | { |
912 | } | 918 | } |
913 | 919 | ||
914 | 920 | ||
915 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 921 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
916 | { | 922 | { |
917 | //FIXME: do nothing if its already in the same mode | 923 | //FIXME: do nothing if its already in the same mode |
918 | 924 | ||
919 | QString enable = b ? "true" : "false"; | 925 | QString enable = b ? "true" : "false"; |
920 | QString prism = _prismHeader ? "true" : "false"; | 926 | QString prism = _prismHeader ? "true" : "false"; |
921 | QString cmd; | 927 | QString cmd; |
922 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 928 | 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 ); | 929 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); |
924 | system( cmd ); | 930 | system( cmd ); |
925 | } | 931 | } |
926 | 932 | ||
927 | 933 | ||
928 | QString OWlanNGMonitoringInterface::name() const | 934 | QString OWlanNGMonitoringInterface::name() const |
929 | { | 935 | { |
930 | return "wlan-ng"; | 936 | return "wlan-ng"; |
931 | } | 937 | } |
932 | 938 | ||
933 | 939 | ||
934 | void OWlanNGMonitoringInterface::setChannel( int c ) | 940 | void OWlanNGMonitoringInterface::setChannel( int c ) |
935 | { | 941 | { |
936 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. | 942 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. |
937 | 943 | ||
938 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; | 944 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; |
939 | QString prism = _prismHeader ? "true" : "false"; | 945 | QString prism = _prismHeader ? "true" : "false"; |
940 | QString cmd; | 946 | QString cmd; |
941 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 947 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
942 | (const char*) _if->name(), c+1, (const char*) enable, (const char*) prism ); | 948 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); |
943 | system( cmd ); | 949 | system( cmd ); |
944 | } | 950 | } |
945 | 951 | ||
946 | 952 | ||
947 | /*====================================================================================== | 953 | /*====================================================================================== |
948 | * OHostAPMonitoringInterface | 954 | * OHostAPMonitoringInterface |
949 | *======================================================================================*/ | 955 | *======================================================================================*/ |
950 | 956 | ||
951 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 957 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
952 | :OMonitoringInterface( iface, prismHeader ) | 958 | :OMonitoringInterface( iface, prismHeader ) |
953 | { | 959 | { |
954 | iface->setMonitoring( this ); | 960 | iface->setMonitoring( this ); |
955 | } | 961 | } |
956 | 962 | ||
957 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 963 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
958 | { | 964 | { |
959 | } | 965 | } |
960 | 966 | ||
961 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 967 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
962 | { | 968 | { |
963 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 969 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
964 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 970 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
965 | 971 | ||
966 | #if WIRELESS_EXT > 14 | 972 | #if WIRELESS_EXT > 14 |
967 | if ( b ) | 973 | if ( b ) |
968 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header | 974 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header |
969 | else | 975 | else |
970 | _if->setMode( "managed" ); | 976 | _if->setMode( "managed" ); |
971 | #else | 977 | #else |
972 | int monitorCode = _prismHeader ? 1 : 2; | 978 | int monitorCode = _prismHeader ? 1 : 2; |
973 | if ( b ) | 979 | if ( b ) |
974 | { | 980 | { |
975 | _if->setPrivate( "monitor", 1, monitorCode ); | 981 | _if->setPrivate( "monitor", 1, monitorCode ); |
976 | } | 982 | } |
977 | else | 983 | else |
978 | { | 984 | { |
979 | _if->setPrivate( "monitor", 1, 0 ); | 985 | _if->setPrivate( "monitor", 1, 0 ); |
980 | } | 986 | } |
981 | #endif | 987 | #endif |
982 | } | 988 | } |
983 | 989 | ||
984 | 990 | ||
985 | QString OHostAPMonitoringInterface::name() const | 991 | QString OHostAPMonitoringInterface::name() const |
986 | { | 992 | { |
987 | return "hostap"; | 993 | return "hostap"; |
988 | } | 994 | } |
989 | 995 | ||
990 | 996 | ||
991 | /*====================================================================================== | 997 | /*====================================================================================== |
992 | * OOrinocoNetworkInterface | 998 | * OOrinocoNetworkInterface |
993 | *======================================================================================*/ | 999 | *======================================================================================*/ |
994 | 1000 | ||
995 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1001 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
996 | :OMonitoringInterface( iface, prismHeader ) | 1002 | :OMonitoringInterface( iface, prismHeader ) |
997 | { | 1003 | { |
998 | iface->setMonitoring( this ); | 1004 | iface->setMonitoring( this ); |
999 | } | 1005 | } |
1000 | 1006 | ||
1001 | 1007 | ||
1002 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 1008 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
1003 | { | 1009 | { |
1004 | } | 1010 | } |
1005 | 1011 | ||
1006 | 1012 | ||
1007 | void OOrinocoMonitoringInterface::setChannel( int c ) | 1013 | void OOrinocoMonitoringInterface::setChannel( int c ) |
1008 | { | 1014 | { |
1009 | int monitorCode = _prismHeader ? 1 : 2; | 1015 | int monitorCode = _prismHeader ? 1 : 2; |
1010 | _if->setPrivate( "monitor", 2, monitorCode, c ); | 1016 | _if->setPrivate( "monitor", 2, monitorCode, c ); |
1011 | } | 1017 | } |
1012 | 1018 | ||
1013 | 1019 | ||
1014 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 1020 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
1015 | { | 1021 | { |
1016 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 1022 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
1017 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 1023 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
1024 | // However, as of recent orinoco drivers, IW_MODE_MONITOR is still not supported | ||
1018 | 1025 | ||
1019 | #if WIRELESS_EXT > 14 | 1026 | #if 0 |
1027 | //#if WIRELESS_EXT > 14 | ||
1020 | if ( b ) | 1028 | if ( b ) |
1021 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header | 1029 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header |
1022 | else | 1030 | else |
1023 | _if->setMode( "managed" ); | 1031 | _if->setMode( "managed" ); |
1024 | #else | 1032 | #else |
1025 | if ( b ) | 1033 | if ( b ) |
1026 | { | 1034 | { |
1027 | setChannel( 1 ); | 1035 | setChannel( 1 ); |
1028 | } | 1036 | } |
1029 | else | 1037 | else |
1030 | { | 1038 | { |
1031 | _if->setPrivate( "monitor", 2, 0, 0 ); | 1039 | _if->setPrivate( "monitor", 2, 0, 0 ); |
1032 | } | 1040 | } |
1033 | #endif | 1041 | #endif |
1034 | } | 1042 | } |
1035 | 1043 | ||
1036 | 1044 | ||
1037 | QString OOrinocoMonitoringInterface::name() const | 1045 | QString OOrinocoMonitoringInterface::name() const |
1038 | { | 1046 | { |
1039 | return "orinoco"; | 1047 | return "orinoco"; |
1040 | } | 1048 | } |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 2553a61..00d1ebb 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -1,542 +1,544 @@ | |||
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 | #ifndef ONETWORK_H | 34 | #ifndef ONETWORK_H |
35 | #define ONETWORK_H | 35 | #define ONETWORK_H |
36 | 36 | ||
37 | /* OPIE */ | 37 | /* OPIE */ |
38 | 38 | ||
39 | #include <opie2/onetutils.h> | 39 | #include <opie2/onetutils.h> |
40 | 40 | ||
41 | /* QT */ | 41 | /* QT */ |
42 | 42 | ||
43 | #include <qvaluelist.h> | 43 | #include <qvaluelist.h> |
44 | #include <qdict.h> | 44 | #include <qdict.h> |
45 | #include <qmap.h> | 45 | #include <qmap.h> |
46 | #include <qobject.h> | 46 | #include <qobject.h> |
47 | #include <qhostaddress.h> | 47 | #include <qhostaddress.h> |
48 | 48 | ||
49 | // ML: Yeah, I hate to include kernel headers, but it's necessary here | 49 | // ML: Yeah, I hate to include kernel headers, but it's necessary here |
50 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> | 50 | // ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> |
51 | // ML: which conflicts with the user header <net/if.h> | 51 | // ML: which conflicts with the user header <net/if.h> |
52 | // ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h> | 52 | // ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h> |
53 | // ML: I will drop Jean a mail on that subject | 53 | // ML: I will drop Jean a mail on that subject |
54 | 54 | ||
55 | #include <net/if.h> | 55 | #include <net/if.h> |
56 | 56 | ||
57 | #ifndef IFNAMSIZ | 57 | #ifndef IFNAMSIZ |
58 | #define IFNAMSIZ 16 | 58 | #define IFNAMSIZ 16 |
59 | #endif | 59 | #endif |
60 | #ifndef IW_MAX_PRIV_DEF | 60 | #ifndef IW_MAX_PRIV_DEF |
61 | #define IW_MAX_PRIV_DEF 128 | 61 | #define IW_MAX_PRIV_DEF 128 |
62 | #endif | 62 | #endif |
63 | 63 | ||
64 | #define _LINUX_IF_H | 64 | #define _LINUX_IF_H |
65 | #include <linux/wireless.h> | 65 | #include <linux/wireless.h> |
66 | 66 | ||
67 | class ONetworkInterface; | 67 | class ONetworkInterface; |
68 | class OWirelessNetworkInterface; | 68 | class OWirelessNetworkInterface; |
69 | class OChannelHopper; | 69 | class OChannelHopper; |
70 | class OMonitoringInterface; | 70 | class OMonitoringInterface; |
71 | 71 | ||
72 | /*====================================================================================== | 72 | /*====================================================================================== |
73 | * ONetwork | 73 | * ONetwork |
74 | *======================================================================================*/ | 74 | *======================================================================================*/ |
75 | 75 | ||
76 | /** | 76 | /** |
77 | * @brief A container class for all network interfaces | 77 | * @brief A container class for all network interfaces |
78 | * | 78 | * |
79 | * This class provides access to all available network interfaces of your computer. | 79 | * This class provides access to all available network interfaces of your computer. |
80 | * | 80 | * |
81 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 81 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
82 | */ | 82 | */ |
83 | class ONetwork : public QObject | 83 | class ONetwork : public QObject |
84 | { | 84 | { |
85 | Q_OBJECT | 85 | Q_OBJECT |
86 | 86 | ||
87 | public: | 87 | public: |
88 | typedef QDict<ONetworkInterface> InterfaceMap; | 88 | typedef QDict<ONetworkInterface> InterfaceMap; |
89 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; | 89 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; |
90 | 90 | ||
91 | public: | 91 | public: |
92 | /** | 92 | /** |
93 | * @returns the number of available interfaces | 93 | * @returns the number of available interfaces |
94 | */ | 94 | */ |
95 | int count() const; | 95 | int count() const; |
96 | /** | 96 | /** |
97 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 97 | * @returns a pointer to the (one and only) @ref ONetwork instance. |
98 | */ | 98 | */ |
99 | static ONetwork* instance(); | 99 | static ONetwork* instance(); |
100 | /** | 100 | /** |
101 | * @returns an iterator usable for iterating through all network interfaces. | 101 | * @returns an iterator usable for iterating through all network interfaces. |
102 | */ | 102 | */ |
103 | InterfaceIterator iterator() const; | 103 | InterfaceIterator iterator() const; |
104 | /** | 104 | /** |
105 | * @returns true, if the @a interface supports the wireless extension protocol. | 105 | * @returns true, if the @a interface supports the wireless extension protocol. |
106 | */ | 106 | */ |
107 | bool isWirelessInterface( const char* interface ) const; | 107 | bool isWirelessInterface( const char* interface ) const; |
108 | /** | 108 | /** |
109 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. | 109 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. |
110 | * @see ONetworkInterface | 110 | * @see ONetworkInterface |
111 | */ | 111 | */ |
112 | ONetworkInterface* interface( const QString& interface ) const; | 112 | ONetworkInterface* interface( const QString& interface ) const; |
113 | /** | 113 | /** |
114 | * @internal Rebuild the internal interface database | 114 | * @internal Rebuild the internal interface database |
115 | * @note Sometimes it might be useful to call this from client code, | 115 | * @note Sometimes it might be useful to call this from client code, |
116 | * e.g. after issuing a cardctl insert | 116 | * e.g. after issuing a cardctl insert |
117 | */ | 117 | */ |
118 | void synchronize(); | 118 | void synchronize(); |
119 | /** | 119 | /** |
120 | * @returns the wireless extension version used at compile time. | 120 | * @returns the wireless extension version used at compile time. |
121 | **/ | 121 | **/ |
122 | static short wirelessExtensionVersion(); | 122 | static short wirelessExtensionVersion(); |
123 | 123 | ||
124 | protected: | 124 | protected: |
125 | ONetwork(); | 125 | ONetwork(); |
126 | 126 | ||
127 | private: | 127 | private: |
128 | static ONetwork* _instance; | 128 | static ONetwork* _instance; |
129 | InterfaceMap _interfaces; | 129 | InterfaceMap _interfaces; |
130 | }; | 130 | }; |
131 | 131 | ||
132 | 132 | ||
133 | /*====================================================================================== | 133 | /*====================================================================================== |
134 | * ONetworkInterface | 134 | * ONetworkInterface |
135 | *======================================================================================*/ | 135 | *======================================================================================*/ |
136 | 136 | ||
137 | /** | 137 | /** |
138 | * @brief A network interface wrapper. | 138 | * @brief A network interface wrapper. |
139 | * | 139 | * |
140 | * This class provides a wrapper for a network interface. All the cumbersume details of | 140 | * This class provides a wrapper for a network interface. All the cumbersume details of |
141 | * Linux ioctls are hidden under a convenient high-level interface. | 141 | * Linux ioctls are hidden under a convenient high-level interface. |
142 | * @warning Most of the setting methods contained in this class require the appropriate | 142 | * @warning Most of the setting methods contained in this class require the appropriate |
143 | * process permissions to work. | 143 | * process permissions to work. |
144 | * | 144 | * |
145 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 145 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
146 | */ | 146 | */ |
147 | class ONetworkInterface : public QObject | 147 | class ONetworkInterface : public QObject |
148 | { | 148 | { |
149 | friend class OMonitoringInterface; | 149 | friend class OMonitoringInterface; |
150 | friend class OCiscoMonitoringInterface; | 150 | friend class OCiscoMonitoringInterface; |
151 | friend class OWlanNGMonitoringInterface; | 151 | friend class OWlanNGMonitoringInterface; |
152 | friend class OHostAPMonitoringInterface; | 152 | friend class OHostAPMonitoringInterface; |
153 | friend class OOrinocoMonitoringInterface; | 153 | friend class OOrinocoMonitoringInterface; |
154 | 154 | ||
155 | public: | 155 | public: |
156 | /** | 156 | /** |
157 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, | 157 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, |
158 | * but access them via @ref ONetwork::interface(). | 158 | * but access them via @ref ONetwork::interface(). |
159 | */ | 159 | */ |
160 | ONetworkInterface( QObject* parent, const char* name ); | 160 | ONetworkInterface( QObject* parent, const char* name ); |
161 | /** | 161 | /** |
162 | * Destructor. | 162 | * Destructor. |
163 | */ | 163 | */ |
164 | virtual ~ONetworkInterface(); | 164 | virtual ~ONetworkInterface(); |
165 | /** | 165 | /** |
166 | * Associates a @a monitoring interface with this network interface. | 166 | * Associates a @a monitoring interface with this network interface. |
167 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. | 167 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. |
168 | */ | 168 | */ |
169 | void setMonitoring( OMonitoringInterface* monitoring ); | 169 | void setMonitoring( OMonitoringInterface* monitoring ); |
170 | /** | 170 | /** |
171 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. | 171 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. |
172 | */ | 172 | */ |
173 | OMonitoringInterface* monitoring() const; | 173 | OMonitoringInterface* monitoring() const; |
174 | /** | 174 | /** |
175 | * Setting an interface to promiscuous mode enables the device to receive | 175 | * Setting an interface to promiscuous mode enables the device to receive |
176 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. | 176 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. |
177 | */ | 177 | */ |
178 | bool setPromiscuousMode( bool ); | 178 | bool setPromiscuousMode( bool ); |
179 | /** | 179 | /** |
180 | * @returns true if the interface is set to promiscuous mode. | 180 | * @returns true if the interface is set to promiscuous mode. |
181 | */ | 181 | */ |
182 | bool promiscuousMode() const; | 182 | bool promiscuousMode() const; |
183 | /** | 183 | /** |
184 | * Setting an interface to up enables it to receive packets. | 184 | * Setting an interface to up enables it to receive packets. |
185 | */ | 185 | */ |
186 | bool setUp( bool ); | 186 | bool setUp( bool ); |
187 | /** | 187 | /** |
188 | * @returns true if the interface is up. | 188 | * @returns true if the interface is up. |
189 | */ | 189 | */ |
190 | bool isUp() const; | 190 | bool isUp() const; |
191 | /** | 191 | /** |
192 | * @returns true if the interface is a loopback interface. | 192 | * @returns true if the interface is a loopback interface. |
193 | */ | 193 | */ |
194 | bool isLoopback() const; | 194 | bool isLoopback() const; |
195 | /** | 195 | /** |
196 | * @returns true if the interface is featuring supports the wireless extension protocol. | 196 | * @returns true if the interface is featuring supports the wireless extension protocol. |
197 | */ | 197 | */ |
198 | bool isWireless() const; | 198 | bool isWireless() const; |
199 | /** | 199 | /** |
200 | * Associate the IP address @ addr with the interface. | 200 | * Associate the IP address @ addr with the interface. |
201 | */ | 201 | */ |
202 | void setIPV4Address( const QHostAddress& addr ); | 202 | void setIPV4Address( const QHostAddress& addr ); |
203 | /** | 203 | /** |
204 | * @returns the IPv4 address associated with the interface. | 204 | * @returns the IPv4 address associated with the interface. |
205 | */ | 205 | */ |
206 | QString ipV4Address() const; //TODO: make this return an OHostAddress | 206 | QString ipV4Address() const; //TODO: make this return an OHostAddress |
207 | /** | 207 | /** |
208 | * Associate the MAC address @a addr with the interface. | 208 | * Associate the MAC address @a addr with the interface. |
209 | * @note It can be necessary to shut down the interface prior to calling this method. | 209 | * @note It can be necessary to shut down the interface prior to calling this method. |
210 | * @warning This is not supported by all drivers. | 210 | * @warning This is not supported by all drivers. |
211 | */ | 211 | */ |
212 | void setMacAddress( const OMacAddress& addr ); | 212 | void setMacAddress( const OMacAddress& addr ); |
213 | /** | 213 | /** |
214 | * @returns the MAC address associated with the interface. | 214 | * @returns the MAC address associated with the interface. |
215 | */ | 215 | */ |
216 | OMacAddress macAddress() const; | 216 | OMacAddress macAddress() const; |
217 | /** | 217 | /** |
218 | * Associate the IPv4 @a netmask with the interface. | 218 | * Associate the IPv4 @a netmask with the interface. |
219 | */ | 219 | */ |
220 | void setIPV4Netmask( const QHostAddress& netmask ); | 220 | void setIPV4Netmask( const QHostAddress& netmask ); |
221 | /** | 221 | /** |
222 | * @returns the IPv4 netmask associated with the interface. | 222 | * @returns the IPv4 netmask associated with the interface. |
223 | */ | 223 | */ |
224 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress | 224 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress |
225 | /** | 225 | /** |
226 | * @returns the data link type currently associated with the interface. | 226 | * @returns the data link type currently associated with the interface. |
227 | * @see #include <net/if_arp.h> for possible values. | 227 | * @see #include <net/if_arp.h> for possible values. |
228 | */ | 228 | */ |
229 | int dataLinkType() const; | 229 | int dataLinkType() const; |
230 | 230 | ||
231 | protected: | 231 | protected: |
232 | const int _sfd; | 232 | const int _sfd; |
233 | mutable ifreq _ifr; | 233 | mutable ifreq _ifr; |
234 | OMonitoringInterface* _mon; | 234 | OMonitoringInterface* _mon; |
235 | 235 | ||
236 | protected: | 236 | protected: |
237 | struct ifreq& ifr() const; | 237 | struct ifreq& ifr() const; |
238 | virtual void init(); | 238 | virtual void init(); |
239 | bool ioctl( int call ) const; | 239 | bool ioctl( int call ) const; |
240 | bool ioctl( int call, struct ifreq& ) const; | 240 | bool ioctl( int call, struct ifreq& ) const; |
241 | }; | 241 | }; |
242 | 242 | ||
243 | /*====================================================================================== | 243 | /*====================================================================================== |
244 | * OChannelHopper | 244 | * OChannelHopper |
245 | *======================================================================================*/ | 245 | *======================================================================================*/ |
246 | 246 | ||
247 | /** | 247 | /** |
248 | * @brief A radio frequency channel hopper. | 248 | * @brief A radio frequency channel hopper. |
249 | * | 249 | * |
250 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently | 250 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently |
251 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. | 251 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. |
252 | * This is necessary when in monitoring mode and scanning for other devices, because | 252 | * This is necessary when in monitoring mode and scanning for other devices, because |
253 | * the radio frequency hardware can only detect packets sent on the same frequency. | 253 | * the radio frequency hardware can only detect packets sent on the same frequency. |
254 | * | 254 | * |
255 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 255 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
256 | */ | 256 | */ |
257 | class OChannelHopper : public QObject | 257 | class OChannelHopper : public QObject |
258 | { | 258 | { |
259 | Q_OBJECT | 259 | Q_OBJECT |
260 | 260 | ||
261 | public: | 261 | public: |
262 | /** | 262 | /** |
263 | * Constructor. | 263 | * Constructor. |
264 | */ | 264 | */ |
265 | OChannelHopper( OWirelessNetworkInterface* ); | 265 | OChannelHopper( OWirelessNetworkInterface* ); |
266 | /** | 266 | /** |
267 | * Destructor. | 267 | * Destructor. |
268 | */ | 268 | */ |
269 | virtual ~OChannelHopper(); | 269 | virtual ~OChannelHopper(); |
270 | /** | 270 | /** |
271 | * @returns true, if the channel hopper is hopping channels | 271 | * @returns true, if the channel hopper is hopping channels |
272 | */ | 272 | */ |
273 | bool isActive() const; | 273 | bool isActive() const; |
274 | /** | 274 | /** |
275 | * @returns the last hopped channel | 275 | * @returns the last hopped channel |
276 | */ | 276 | */ |
277 | int channel() const; | 277 | int channel() const; |
278 | /** | 278 | /** |
279 | * Set the channel hopping @a interval. | 279 | * Set the channel hopping @a interval. |
280 | * An interval of 0 deactivates the channel hopper. | 280 | * An interval of 0 deactivates the channel hopper. |
281 | */ | 281 | */ |
282 | void setInterval( int interval ); | 282 | void setInterval( int interval ); |
283 | /** | 283 | /** |
284 | * @returns the channel hopping interval | 284 | * @returns the channel hopping interval |
285 | */ | 285 | */ |
286 | int interval() const; | 286 | int interval() const; |
287 | 287 | ||
288 | signals: | 288 | signals: |
289 | /** | 289 | /** |
290 | * This signal is emitted right after the channel hopper performed a hop | 290 | * This signal is emitted right after the channel hopper performed a hop |
291 | */ | 291 | */ |
292 | void hopped( int ); | 292 | void hopped( int ); |
293 | 293 | ||
294 | protected: | 294 | protected: |
295 | virtual void timerEvent( QTimerEvent* ); | 295 | virtual void timerEvent( QTimerEvent* ); |
296 | 296 | ||
297 | private: | 297 | private: |
298 | OWirelessNetworkInterface* _iface; | 298 | OWirelessNetworkInterface* _iface; |
299 | int _interval; | 299 | int _interval; |
300 | int _tid; | 300 | int _tid; |
301 | QValueList<int> _channels; | 301 | QValueList<int> _channels; |
302 | QValueList<int>::Iterator _channel; | 302 | QValueList<int>::Iterator _channel; |
303 | }; | 303 | }; |
304 | 304 | ||
305 | 305 | ||
306 | /*====================================================================================== | 306 | /*====================================================================================== |
307 | * OWirelessNetworkInterface | 307 | * OWirelessNetworkInterface |
308 | *======================================================================================*/ | 308 | *======================================================================================*/ |
309 | 309 | ||
310 | /** | 310 | /** |
311 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. | 311 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. |
312 | * | 312 | * |
313 | * This class provides a high-level encapsulation of the Linux wireless extension API. | 313 | * This class provides a high-level encapsulation of the Linux wireless extension API. |
314 | * | 314 | * |
315 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 315 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
316 | */ | 316 | */ |
317 | class OWirelessNetworkInterface : public ONetworkInterface | 317 | class OWirelessNetworkInterface : public ONetworkInterface |
318 | { | 318 | { |
319 | friend class OMonitoringInterface; | 319 | friend class OMonitoringInterface; |
320 | friend class OCiscoMonitoringInterface; | 320 | friend class OCiscoMonitoringInterface; |
321 | friend class OWlanNGMonitoringInterface; | 321 | friend class OWlanNGMonitoringInterface; |
322 | friend class OHostAPMonitoringInterface; | 322 | friend class OHostAPMonitoringInterface; |
323 | friend class OOrinocoMonitoringInterface; | 323 | friend class OOrinocoMonitoringInterface; |
324 | 324 | ||
325 | friend class OPrivateIOCTL; | 325 | friend class OPrivateIOCTL; |
326 | 326 | ||
327 | public: | 327 | public: |
328 | /** | 328 | /** |
329 | * Constructor. | 329 | * Constructor. |
330 | */ | 330 | */ |
331 | OWirelessNetworkInterface( QObject* parent, const char* name ); | 331 | OWirelessNetworkInterface( QObject* parent, const char* name ); |
332 | /** | 332 | /** |
333 | * Destructor. | 333 | * Destructor. |
334 | */ | 334 | */ |
335 | virtual ~OWirelessNetworkInterface(); | 335 | virtual ~OWirelessNetworkInterface(); |
336 | /** | 336 | /** |
337 | * Setting the @a channel of the interface changes the radio frequency (RF) | 337 | * Setting the @a channel of the interface changes the radio frequency (RF) |
338 | * of the corresponding wireless network device. | 338 | * of the corresponding wireless network device. |
339 | * @note Common channel range is within [1-14]. A value of 0 is not allowed. | ||
340 | * @see channels() | ||
339 | */ | 341 | */ |
340 | virtual void setChannel( int channel ) const; | 342 | virtual void setChannel( int channel ) const; |
341 | /** | 343 | /** |
342 | * @returns the channel index of the current radio frequency. | 344 | * @returns the channel index of the current radio frequency. |
343 | */ | 345 | */ |
344 | virtual int channel() const; | 346 | virtual int channel() const; |
345 | /** | 347 | /** |
346 | * @returns the current radio frequency (in MHz). | 348 | * @returns the current radio frequency (in MHz). |
347 | */ | 349 | */ |
348 | virtual double frequency() const; | 350 | virtual double frequency() const; |
349 | /** | 351 | /** |
350 | * @returns the number of radio frequency channels for the | 352 | * @returns the number of radio frequency channels for the |
351 | * corresponding wireless network device. | 353 | * corresponding wireless network device. |
352 | * @note European devices usually have 14 channels, while American typically feature 11 channels. | 354 | * @note European devices usually have 14 channels, while American typically feature 11 channels. |
353 | */ | 355 | */ |
354 | virtual int channels() const; | 356 | virtual int channels() const; |
355 | /** | 357 | /** |
356 | * Set the IEEE 802.11 operation @a mode. | 358 | * Set the IEEE 802.11 operation @a mode. |
357 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master | 359 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master |
358 | * @warning Not all drivers support the all modes. | 360 | * @warning Not all drivers support the all modes. |
359 | * @note You might have to change the SSID to get the operation mode change into effect. | 361 | * @note You might have to change the SSID to get the operation mode change into effect. |
360 | */ | 362 | */ |
361 | virtual void setMode( const QString& mode ); | 363 | virtual void setMode( const QString& mode ); |
362 | /** | 364 | /** |
363 | * @returns the current IEEE 802.11 operation mode. | 365 | * @returns the current IEEE 802.11 operation mode. |
364 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown | 366 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown |
365 | */ | 367 | */ |
366 | virtual QString mode() const; | 368 | virtual QString mode() const; |
367 | /** | 369 | /** |
368 | * Setting the monitor mode on a wireless network interface enables | 370 | * Setting the monitor mode on a wireless network interface enables |
369 | * listening to IEEE 802.11 data and management frames which normally | 371 | * listening to IEEE 802.11 data and management frames which normally |
370 | * are handled by the device firmware. This can be used to detect | 372 | * are handled by the device firmware. This can be used to detect |
371 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. | 373 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. |
372 | * @warning Standard wireless network drives don't support the monitor mode. | 374 | * @warning Standard wireless network drives don't support the monitor mode. |
373 | * @warning You need a patched driver for this to work. | 375 | * @warning You need a patched driver for this to work. |
374 | * @note Enabling the monitor mode is highly driver dependent and requires | 376 | * @note Enabling the monitor mode is highly driver dependent and requires |
375 | * the proper @ref OMonitoringInterface to be associated with the interface. | 377 | * the proper @ref OMonitoringInterface to be associated with the interface. |
376 | * @see OMonitoringInterface | 378 | * @see OMonitoringInterface |
377 | */ | 379 | */ |
378 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); | 380 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); |
379 | /** | 381 | /** |
380 | * @returns true if the device is listening in IEEE 802.11 monitor mode | 382 | * @returns true if the device is listening in IEEE 802.11 monitor mode |
381 | */ | 383 | */ |
382 | virtual bool monitorMode() const; //FIXME: ==> mode() | 384 | virtual bool monitorMode() const; //FIXME: ==> mode() |
383 | /** | 385 | /** |
384 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. | 386 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. |
385 | * @see OChannelHopper | 387 | * @see OChannelHopper |
386 | */ | 388 | */ |
387 | virtual void setChannelHopping( int interval = 0 ); | 389 | virtual void setChannelHopping( int interval = 0 ); |
388 | /** | 390 | /** |
389 | * @returns the channel hopping interval or 0, if channel hopping is disabled. | 391 | * @returns the channel hopping interval or 0, if channel hopping is disabled. |
390 | */ | 392 | */ |
391 | virtual int channelHopping() const; | 393 | virtual int channelHopping() const; |
392 | /** | 394 | /** |
393 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before | 395 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before |
394 | */ | 396 | */ |
395 | virtual OChannelHopper* channelHopper() const; | 397 | virtual OChannelHopper* channelHopper() const; |
396 | /** | 398 | /** |
397 | * Set the station @a nickname. | 399 | * Set the station @a nickname. |
398 | */ | 400 | */ |
399 | virtual void setNickName( const QString& nickname ); | 401 | virtual void setNickName( const QString& nickname ); |
400 | /** | 402 | /** |
401 | * @returns the current station nickname. | 403 | * @returns the current station nickname. |
402 | */ | 404 | */ |
403 | virtual QString nickName() const; | 405 | virtual QString nickName() const; |
404 | /** | 406 | /** |
405 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. | 407 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. |
406 | * @see OPrivateIOCTL | 408 | * @see OPrivateIOCTL |
407 | */ | 409 | */ |
408 | virtual void setPrivate( const QString& command, int number, ... ); | 410 | virtual void setPrivate( const QString& command, int number, ... ); |
409 | /** | 411 | /** |
410 | * @returns true if the interface is featuring the private IOCTL @command. | 412 | * @returns true if the interface is featuring the private IOCTL @command. |
411 | */ | 413 | */ |
412 | virtual bool hasPrivate( const QString& command ); | 414 | virtual bool hasPrivate( const QString& command ); |
413 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this | 415 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this |
414 | 416 | ||
415 | virtual bool isAssociated() const {}; //FIXME: Implement and document this | 417 | virtual bool isAssociated() const {}; //FIXME: Implement and document this |
416 | /** | 418 | /** |
417 | * @returns the MAC address of the Access Point if the | 419 | * @returns the MAC address of the Access Point if the |
418 | * device is in infrastructure mode. @returns a (more or less random) CELL | 420 | * device is in infrastructure mode. @returns a (more or less random) CELL |
419 | * address if the device is in adhoc mode. | 421 | * address if the device is in adhoc mode. |
420 | */ | 422 | */ |
421 | virtual QString associatedAP() const; | 423 | virtual QString associatedAP() const; |
422 | /** | 424 | /** |
423 | * Set the @a ssid (Service Set ID) string. This is used to decide | 425 | * Set the @a ssid (Service Set ID) string. This is used to decide |
424 | * which network to associate with (use "any" to let the driver decide). | 426 | * which network to associate with (use "any" to let the driver decide). |
425 | */ | 427 | */ |
426 | virtual void setSSID( const QString& ssid ); | 428 | virtual void setSSID( const QString& ssid ); |
427 | /** | 429 | /** |
428 | * @returns the current SSID (Service Set ID). | 430 | * @returns the current SSID (Service Set ID). |
429 | */ | 431 | */ |
430 | virtual QString SSID() const; | 432 | virtual QString SSID() const; |
431 | 433 | ||
432 | protected: | 434 | protected: |
433 | void buildChannelList(); | 435 | void buildChannelList(); |
434 | void buildPrivateList(); | 436 | void buildPrivateList(); |
435 | virtual void init(); | 437 | virtual void init(); |
436 | struct iwreq& iwr() const; | 438 | struct iwreq& iwr() const; |
437 | bool wioctl( int call ) const; | 439 | bool wioctl( int call ) const; |
438 | bool wioctl( int call, struct iwreq& ) const; | 440 | bool wioctl( int call, struct iwreq& ) const; |
439 | 441 | ||
440 | protected: | 442 | protected: |
441 | mutable struct iwreq _iwr; | 443 | mutable struct iwreq _iwr; |
442 | QMap<int,int> _channels; | 444 | QMap<int,int> _channels; |
443 | 445 | ||
444 | private: | 446 | private: |
445 | OChannelHopper* _hopper; | 447 | OChannelHopper* _hopper; |
446 | }; | 448 | }; |
447 | 449 | ||
448 | 450 | ||
449 | /*====================================================================================== | 451 | /*====================================================================================== |
450 | * OMonitoringInterface | 452 | * OMonitoringInterface |
451 | *======================================================================================*/ | 453 | *======================================================================================*/ |
452 | 454 | ||
453 | 455 | ||
454 | class OMonitoringInterface | 456 | class OMonitoringInterface |
455 | { | 457 | { |
456 | public: | 458 | public: |
457 | OMonitoringInterface(); | 459 | OMonitoringInterface(); |
458 | OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 460 | OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
459 | virtual ~OMonitoringInterface(); | 461 | virtual ~OMonitoringInterface(); |
460 | 462 | ||
461 | public: | 463 | public: |
462 | virtual void setEnabled( bool ); | 464 | virtual void setEnabled( bool ); |
463 | virtual bool enabled() const; | 465 | virtual bool enabled() const; |
464 | virtual void setChannel( int ); | 466 | virtual void setChannel( int ); |
465 | 467 | ||
466 | virtual QString name() const = 0; | 468 | virtual QString name() const = 0; |
467 | 469 | ||
468 | protected: | 470 | protected: |
469 | OWirelessNetworkInterface* _if; | 471 | OWirelessNetworkInterface* _if; |
470 | bool _prismHeader; | 472 | bool _prismHeader; |
471 | 473 | ||
472 | }; | 474 | }; |
473 | 475 | ||
474 | 476 | ||
475 | /*====================================================================================== | 477 | /*====================================================================================== |
476 | * OCiscoMonitoring | 478 | * OCiscoMonitoring |
477 | *======================================================================================*/ | 479 | *======================================================================================*/ |
478 | 480 | ||
479 | 481 | ||
480 | class OCiscoMonitoringInterface : public OMonitoringInterface | 482 | class OCiscoMonitoringInterface : public OMonitoringInterface |
481 | { | 483 | { |
482 | public: | 484 | public: |
483 | OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 485 | OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
484 | virtual ~OCiscoMonitoringInterface(); | 486 | virtual ~OCiscoMonitoringInterface(); |
485 | 487 | ||
486 | virtual void setEnabled( bool ); | 488 | virtual void setEnabled( bool ); |
487 | virtual QString name() const; | 489 | virtual QString name() const; |
488 | virtual void setChannel( int ); | 490 | virtual void setChannel( int ); |
489 | 491 | ||
490 | }; | 492 | }; |
491 | 493 | ||
492 | /*====================================================================================== | 494 | /*====================================================================================== |
493 | * OWlanNGMonitoringInterface | 495 | * OWlanNGMonitoringInterface |
494 | *======================================================================================*/ | 496 | *======================================================================================*/ |
495 | 497 | ||
496 | class OWlanNGMonitoringInterface : public OMonitoringInterface | 498 | class OWlanNGMonitoringInterface : public OMonitoringInterface |
497 | { | 499 | { |
498 | public: | 500 | public: |
499 | OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 501 | OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
500 | virtual ~OWlanNGMonitoringInterface(); | 502 | virtual ~OWlanNGMonitoringInterface(); |
501 | 503 | ||
502 | public: | 504 | public: |
503 | virtual void setEnabled( bool ); | 505 | virtual void setEnabled( bool ); |
504 | virtual QString name() const; | 506 | virtual QString name() const; |
505 | virtual void setChannel( int ); | 507 | virtual void setChannel( int ); |
506 | 508 | ||
507 | }; | 509 | }; |
508 | 510 | ||
509 | /*====================================================================================== | 511 | /*====================================================================================== |
510 | * OHostAPMonitoringInterface | 512 | * OHostAPMonitoringInterface |
511 | *======================================================================================*/ | 513 | *======================================================================================*/ |
512 | 514 | ||
513 | class OHostAPMonitoringInterface : public OMonitoringInterface | 515 | class OHostAPMonitoringInterface : public OMonitoringInterface |
514 | { | 516 | { |
515 | public: | 517 | public: |
516 | OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 518 | OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
517 | virtual ~OHostAPMonitoringInterface(); | 519 | virtual ~OHostAPMonitoringInterface(); |
518 | 520 | ||
519 | public: | 521 | public: |
520 | virtual void setEnabled( bool ); | 522 | virtual void setEnabled( bool ); |
521 | virtual QString name() const; | 523 | virtual QString name() const; |
522 | }; | 524 | }; |
523 | 525 | ||
524 | /*====================================================================================== | 526 | /*====================================================================================== |
525 | * OOrinocoMonitoringInterface | 527 | * OOrinocoMonitoringInterface |
526 | *======================================================================================*/ | 528 | *======================================================================================*/ |
527 | 529 | ||
528 | class OOrinocoMonitoringInterface : public OMonitoringInterface | 530 | class OOrinocoMonitoringInterface : public OMonitoringInterface |
529 | { | 531 | { |
530 | public: | 532 | public: |
531 | OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 533 | OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
532 | virtual ~OOrinocoMonitoringInterface(); | 534 | virtual ~OOrinocoMonitoringInterface(); |
533 | 535 | ||
534 | public: | 536 | public: |
535 | virtual void setChannel( int ); | 537 | virtual void setChannel( int ); |
536 | virtual void setEnabled( bool ); | 538 | virtual void setEnabled( bool ); |
537 | virtual QString name() const; | 539 | virtual QString name() const; |
538 | 540 | ||
539 | }; | 541 | }; |
540 | 542 | ||
541 | #endif // ONETWORK_H | 543 | #endif // ONETWORK_H |
542 | 544 | ||