-rw-r--r-- | libopie2/opienet/onetwork.cpp | 28 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 8 |
2 files changed, 29 insertions, 7 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 6cef5cf..751d841 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,1013 +1,1033 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003 by the Wellenreiter team: | 3 | Copyright (C) 2003 by the Wellenreiter team: |
4 | Martin J. Muench <mjm@remote-exploit.org> | 4 | Martin J. Muench <mjm@remote-exploit.org> |
5 | Max Moser <mmo@remote-exploit.org | 5 | Max Moser <mmo@remote-exploit.org |
6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 6 | Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
7 | =. | 7 | =. |
8 | .=l. | 8 | .=l. |
9 | .>+-= | 9 | .>+-= |
10 | _;:, .> :=|. This program is free software; you can | 10 | _;:, .> :=|. This program is free software; you can |
11 | .> <`_, > . <= redistribute it and/or modify it under | 11 | .> <`_, > . <= redistribute it and/or modify it under |
12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 12 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
13 | .="- .-=="i, .._ License as published by the Free Software | 13 | .="- .-=="i, .._ License as published by the Free Software |
14 | - . .-<_> .<> Foundation; either version 2 of the License, | 14 | - . .-<_> .<> Foundation; either version 2 of the License, |
15 | ._= =} : or (at your option) any later version. | 15 | ._= =} : or (at your option) any later version. |
16 | .%`+i> _;_. | 16 | .%`+i> _;_. |
17 | .i_,=:_. -<s. This program is distributed in the hope that | 17 | .i_,=:_. -<s. This program is distributed in the hope that |
18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 18 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
19 | : .. .:, . . . without even the implied warranty of | 19 | : .. .:, . . . without even the implied warranty of |
20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 20 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 21 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
22 | ..}^=.= = ; Library General Public License for more | 22 | ..}^=.= = ; Library General Public License for more |
23 | ++= -. .` .: details. | 23 | ++= -. .` .: details. |
24 | : = ...= . :.=- | 24 | : = ...= . :.=- |
25 | -. .:....=;==+<; You should have received a copy of the GNU | 25 | -. .:....=;==+<; You should have received a copy of the GNU |
26 | -_. . . )=. = Library General Public License along with | 26 | -_. . . )=. = Library General Public License along with |
27 | -- :-=` this library; see the file COPYING.LIB. | 27 | -- :-=` this library; see the file COPYING.LIB. |
28 | If not, write to the Free Software Foundation, | 28 | If not, write to the Free Software Foundation, |
29 | Inc., 59 Temple Place - Suite 330, | 29 | Inc., 59 Temple Place - Suite 330, |
30 | Boston, MA 02111-1307, USA. | 30 | Boston, MA 02111-1307, USA. |
31 | 31 | ||
32 | */ | 32 | */ |
33 | 33 | ||
34 | /* OPIE */ | 34 | /* OPIE */ |
35 | 35 | ||
36 | #include <opie2/onetwork.h> | 36 | #include <opie2/onetwork.h> |
37 | 37 | ||
38 | /* QT */ | 38 | /* QT */ |
39 | 39 | ||
40 | #include <qfile.h> | 40 | #include <qfile.h> |
41 | #include <qtextstream.h> | 41 | #include <qtextstream.h> |
42 | 42 | ||
43 | /* UNIX */ | 43 | /* UNIX */ |
44 | 44 | ||
45 | #include <assert.h> | 45 | #include <assert.h> |
46 | #include <arpa/inet.h> | 46 | #include <arpa/inet.h> |
47 | #include <cerrno> | 47 | #include <cerrno> |
48 | #include <cstring> | 48 | #include <cstring> |
49 | #include <cstdlib> | 49 | #include <cstdlib> |
50 | #include <math.h> | 50 | #include <math.h> |
51 | #include <sys/ioctl.h> | 51 | #include <sys/ioctl.h> |
52 | #include <sys/socket.h> | 52 | #include <sys/socket.h> |
53 | #include <sys/types.h> | 53 | #include <sys/types.h> |
54 | #include <unistd.h> | 54 | #include <unistd.h> |
55 | #include <linux/sockios.h> | 55 | #include <linux/sockios.h> |
56 | #include <net/if_arp.h> | 56 | #include <net/if_arp.h> |
57 | #include <stdarg.h> | 57 | #include <stdarg.h> |
58 | 58 | ||
59 | using namespace std; | 59 | using namespace std; |
60 | 60 | ||
61 | /*====================================================================================== | 61 | /*====================================================================================== |
62 | * ONetwork | 62 | * ONetwork |
63 | *======================================================================================*/ | 63 | *======================================================================================*/ |
64 | 64 | ||
65 | ONetwork* ONetwork::_instance = 0; | 65 | ONetwork* ONetwork::_instance = 0; |
66 | 66 | ||
67 | ONetwork::ONetwork() | 67 | ONetwork::ONetwork() |
68 | { | 68 | { |
69 | qDebug( "ONetwork::ONetwork()" ); | 69 | qDebug( "ONetwork::ONetwork()" ); |
70 | qDebug( "ONetwork: This code has been compiled against Wireless Extensions V%d", WIRELESS_EXT ); | ||
70 | synchronize(); | 71 | synchronize(); |
71 | } | 72 | } |
72 | 73 | ||
73 | void ONetwork::synchronize() | 74 | void ONetwork::synchronize() |
74 | { | 75 | { |
75 | // gather available interfaces by inspecting /proc/net/dev | 76 | // gather available interfaces by inspecting /proc/net/dev |
76 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 77 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
77 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 78 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
78 | 79 | ||
79 | _interfaces.clear(); | 80 | _interfaces.clear(); |
80 | QString str; | 81 | QString str; |
81 | QFile f( "/proc/net/dev" ); | 82 | QFile f( "/proc/net/dev" ); |
82 | bool hasFile = f.open( IO_ReadOnly ); | 83 | bool hasFile = f.open( IO_ReadOnly ); |
83 | if ( !hasFile ) | 84 | if ( !hasFile ) |
84 | { | 85 | { |
85 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); | 86 | qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); |
86 | return; | 87 | return; |
87 | } | 88 | } |
88 | QTextStream s( &f ); | 89 | QTextStream s( &f ); |
89 | s.readLine(); | 90 | s.readLine(); |
90 | s.readLine(); | 91 | s.readLine(); |
91 | while ( !s.atEnd() ) | 92 | while ( !s.atEnd() ) |
92 | { | 93 | { |
93 | s >> str; | 94 | s >> str; |
94 | str.truncate( str.find( ':' ) ); | 95 | str.truncate( str.find( ':' ) ); |
95 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); | 96 | qDebug( "ONetwork: found interface '%s'", (const char*) str ); |
96 | ONetworkInterface* iface; | 97 | ONetworkInterface* iface; |
97 | if ( isWirelessInterface( str ) ) | 98 | if ( isWirelessInterface( str ) ) |
98 | { | 99 | { |
99 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 100 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
100 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); | 101 | qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); |
101 | } | 102 | } |
102 | else | 103 | else |
103 | { | 104 | { |
104 | iface = new ONetworkInterface( this, (const char*) str ); | 105 | iface = new ONetworkInterface( this, (const char*) str ); |
105 | } | 106 | } |
106 | _interfaces.insert( str, iface ); | 107 | _interfaces.insert( str, iface ); |
107 | s.readLine(); | 108 | s.readLine(); |
108 | } | 109 | } |
109 | } | 110 | } |
110 | 111 | ||
111 | 112 | ||
113 | short ONetwork::wirelessExtensionVersion() | ||
114 | { | ||
115 | return WIRELESS_EXT; | ||
116 | } | ||
117 | |||
118 | |||
112 | int ONetwork::count() const | 119 | int ONetwork::count() const |
113 | { | 120 | { |
114 | return _interfaces.count(); | 121 | return _interfaces.count(); |
115 | } | 122 | } |
116 | 123 | ||
117 | 124 | ||
118 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 125 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
119 | { | 126 | { |
120 | return _interfaces[iface]; | 127 | return _interfaces[iface]; |
121 | } | 128 | } |
122 | 129 | ||
123 | 130 | ||
124 | ONetwork* ONetwork::instance() | 131 | ONetwork* ONetwork::instance() |
125 | { | 132 | { |
126 | if ( !_instance ) _instance = new ONetwork(); | 133 | if ( !_instance ) _instance = new ONetwork(); |
127 | return _instance; | 134 | return _instance; |
128 | } | 135 | } |
129 | 136 | ||
130 | 137 | ||
131 | ONetwork::InterfaceIterator ONetwork::iterator() const | 138 | ONetwork::InterfaceIterator ONetwork::iterator() const |
132 | { | 139 | { |
133 | return ONetwork::InterfaceIterator( _interfaces ); | 140 | return ONetwork::InterfaceIterator( _interfaces ); |
134 | } | 141 | } |
135 | 142 | ||
136 | 143 | ||
137 | bool ONetwork::isWirelessInterface( const char* name ) const | 144 | bool ONetwork::isWirelessInterface( const char* name ) const |
138 | { | 145 | { |
139 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 146 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
140 | struct iwreq iwr; | 147 | struct iwreq iwr; |
141 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 148 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
142 | strcpy( (char*) &iwr.ifr_name, name ); | 149 | strcpy( (char*) &iwr.ifr_name, name ); |
143 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 150 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
144 | return result != -1; | 151 | return result != -1; |
145 | } | 152 | } |
146 | 153 | ||
147 | /*====================================================================================== | 154 | /*====================================================================================== |
148 | * ONetworkInterface | 155 | * ONetworkInterface |
149 | *======================================================================================*/ | 156 | *======================================================================================*/ |
150 | 157 | ||
151 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 158 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
152 | :QObject( parent, name ), | 159 | :QObject( parent, name ), |
153 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 160 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
154 | { | 161 | { |
155 | qDebug( "ONetworkInterface::ONetworkInterface()" ); | 162 | qDebug( "ONetworkInterface::ONetworkInterface()" ); |
156 | init(); | 163 | init(); |
157 | } | 164 | } |
158 | 165 | ||
159 | 166 | ||
160 | struct ifreq& ONetworkInterface::ifr() const | 167 | struct ifreq& ONetworkInterface::ifr() const |
161 | { | 168 | { |
162 | return _ifr; | 169 | return _ifr; |
163 | } | 170 | } |
164 | 171 | ||
165 | 172 | ||
166 | void ONetworkInterface::init() | 173 | void ONetworkInterface::init() |
167 | { | 174 | { |
168 | qDebug( "ONetworkInterface::init()" ); | 175 | qDebug( "ONetworkInterface::init()" ); |
169 | 176 | ||
170 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 177 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
171 | 178 | ||
172 | if ( _sfd == -1 ) | 179 | if ( _sfd == -1 ) |
173 | { | 180 | { |
174 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); | 181 | qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); |
175 | return; | 182 | return; |
176 | } | 183 | } |
177 | } | 184 | } |
178 | 185 | ||
179 | 186 | ||
180 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 187 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
181 | { | 188 | { |
182 | int result = ::ioctl( _sfd, call, &ifreq ); | 189 | int result = ::ioctl( _sfd, call, &ifreq ); |
183 | if ( result == -1 ) | 190 | if ( result == -1 ) |
184 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 191 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); |
185 | else | 192 | else |
186 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); | 193 | qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); |
187 | return ( result != -1 ); | 194 | return ( result != -1 ); |
188 | } | 195 | } |
189 | 196 | ||
190 | 197 | ||
191 | bool ONetworkInterface::ioctl( int call ) const | 198 | bool ONetworkInterface::ioctl( int call ) const |
192 | { | 199 | { |
193 | strcpy( _ifr.ifr_name, name() ); | 200 | strcpy( _ifr.ifr_name, name() ); |
194 | return ioctl( call, _ifr ); | 201 | return ioctl( call, _ifr ); |
195 | } | 202 | } |
196 | 203 | ||
197 | 204 | ||
198 | bool ONetworkInterface::isLoopback() const | 205 | bool ONetworkInterface::isLoopback() const |
199 | { | 206 | { |
200 | ioctl( SIOCGIFFLAGS ); | 207 | ioctl( SIOCGIFFLAGS ); |
201 | return _ifr.ifr_flags & IFF_LOOPBACK; | 208 | return _ifr.ifr_flags & IFF_LOOPBACK; |
202 | } | 209 | } |
203 | 210 | ||
204 | 211 | ||
205 | bool ONetworkInterface::setUp( bool b ) | 212 | bool ONetworkInterface::setUp( bool b ) |
206 | { | 213 | { |
207 | ioctl( SIOCGIFFLAGS ); | 214 | ioctl( SIOCGIFFLAGS ); |
208 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 215 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
209 | else _ifr.ifr_flags &= (~IFF_UP); | 216 | else _ifr.ifr_flags &= (~IFF_UP); |
210 | return ioctl( SIOCSIFFLAGS ); | 217 | return ioctl( SIOCSIFFLAGS ); |
211 | } | 218 | } |
212 | 219 | ||
213 | 220 | ||
214 | bool ONetworkInterface::isUp() const | 221 | bool ONetworkInterface::isUp() const |
215 | { | 222 | { |
216 | ioctl( SIOCGIFFLAGS ); | 223 | ioctl( SIOCGIFFLAGS ); |
217 | return _ifr.ifr_flags & IFF_UP; | 224 | return _ifr.ifr_flags & IFF_UP; |
218 | } | 225 | } |
219 | 226 | ||
220 | 227 | ||
221 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) | 228 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) |
222 | { | 229 | { |
223 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 230 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
224 | sa->sin_family = AF_INET; | 231 | sa->sin_family = AF_INET; |
225 | sa->sin_port = 0; | 232 | sa->sin_port = 0; |
226 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 233 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
227 | ioctl( SIOCSIFADDR ); | 234 | ioctl( SIOCSIFADDR ); |
228 | } | 235 | } |
229 | 236 | ||
230 | 237 | ||
231 | QString ONetworkInterface::ipV4Address() const | 238 | QString ONetworkInterface::ipV4Address() const |
232 | { | 239 | { |
233 | if ( ioctl( SIOCGIFADDR ) ) | 240 | if ( ioctl( SIOCGIFADDR ) ) |
234 | { | 241 | { |
235 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 242 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
236 | //FIXME: Use QHostAddress here | 243 | //FIXME: Use QHostAddress here |
237 | return QString( inet_ntoa( sa->sin_addr ) ); | 244 | return QString( inet_ntoa( sa->sin_addr ) ); |
238 | } | 245 | } |
239 | else | 246 | else |
240 | return "<unknown>"; | 247 | return "<unknown>"; |
241 | } | 248 | } |
242 | 249 | ||
243 | 250 | ||
244 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) | 251 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) |
245 | { | 252 | { |
246 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | 253 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
247 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); | 254 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); |
248 | ioctl( SIOCSIFHWADDR ); | 255 | ioctl( SIOCSIFHWADDR ); |
249 | } | 256 | } |
250 | 257 | ||
251 | 258 | ||
252 | OMacAddress ONetworkInterface::macAddress() const | 259 | OMacAddress ONetworkInterface::macAddress() const |
253 | { | 260 | { |
254 | if ( ioctl( SIOCGIFHWADDR ) ) | 261 | if ( ioctl( SIOCGIFHWADDR ) ) |
255 | { | 262 | { |
256 | return OMacAddress( _ifr ); | 263 | return OMacAddress( _ifr ); |
257 | } | 264 | } |
258 | else | 265 | else |
259 | { | 266 | { |
260 | return OMacAddress::unknown; | 267 | return OMacAddress::unknown; |
261 | } | 268 | } |
262 | } | 269 | } |
263 | 270 | ||
264 | 271 | ||
265 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) | 272 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) |
266 | { | 273 | { |
267 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 274 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
268 | sa->sin_family = AF_INET; | 275 | sa->sin_family = AF_INET; |
269 | sa->sin_port = 0; | 276 | sa->sin_port = 0; |
270 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 277 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
271 | ioctl( SIOCSIFNETMASK ); | 278 | ioctl( SIOCSIFNETMASK ); |
272 | } | 279 | } |
273 | 280 | ||
274 | 281 | ||
275 | QString ONetworkInterface::ipV4Netmask() const | 282 | QString ONetworkInterface::ipV4Netmask() const |
276 | { | 283 | { |
277 | if ( ioctl( SIOCGIFNETMASK ) ) | 284 | if ( ioctl( SIOCGIFNETMASK ) ) |
278 | { | 285 | { |
279 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 286 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
280 | //FIXME: Use QHostAddress here | 287 | //FIXME: Use QHostAddress here |
281 | return QString( inet_ntoa( sa->sin_addr ) ); | 288 | return QString( inet_ntoa( sa->sin_addr ) ); |
282 | } | 289 | } |
283 | else | 290 | else |
284 | return "<unknown>"; | 291 | return "<unknown>"; |
285 | } | 292 | } |
286 | 293 | ||
287 | 294 | ||
288 | int ONetworkInterface::dataLinkType() const | 295 | int ONetworkInterface::dataLinkType() const |
289 | { | 296 | { |
290 | if ( ioctl( SIOCGIFHWADDR ) ) | 297 | if ( ioctl( SIOCGIFHWADDR ) ) |
291 | { | 298 | { |
292 | return _ifr.ifr_hwaddr.sa_family; | 299 | return _ifr.ifr_hwaddr.sa_family; |
293 | } | 300 | } |
294 | else | 301 | else |
295 | { | 302 | { |
296 | return -1; | 303 | return -1; |
297 | } | 304 | } |
298 | } | 305 | } |
299 | 306 | ||
300 | 307 | ||
301 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 308 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
302 | { | 309 | { |
303 | _mon = m; | 310 | _mon = m; |
304 | 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() ); |
305 | } | 312 | } |
306 | 313 | ||
307 | 314 | ||
308 | OMonitoringInterface* ONetworkInterface::monitoring() const | 315 | OMonitoringInterface* ONetworkInterface::monitoring() const |
309 | { | 316 | { |
310 | return _mon; | 317 | return _mon; |
311 | } | 318 | } |
312 | 319 | ||
313 | 320 | ||
314 | ONetworkInterface::~ONetworkInterface() | 321 | ONetworkInterface::~ONetworkInterface() |
315 | { | 322 | { |
316 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); | 323 | qDebug( "ONetworkInterface::~ONetworkInterface()" ); |
317 | if ( _sfd != -1 ) ::close( _sfd ); | 324 | if ( _sfd != -1 ) ::close( _sfd ); |
318 | } | 325 | } |
319 | 326 | ||
320 | 327 | ||
321 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 328 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
322 | { | 329 | { |
323 | ioctl( SIOCGIFFLAGS ); | 330 | ioctl( SIOCGIFFLAGS ); |
324 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 331 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
325 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 332 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
326 | return ioctl( SIOCSIFFLAGS ); | 333 | return ioctl( SIOCSIFFLAGS ); |
327 | } | 334 | } |
328 | 335 | ||
329 | 336 | ||
330 | bool ONetworkInterface::promiscuousMode() const | 337 | bool ONetworkInterface::promiscuousMode() const |
331 | { | 338 | { |
332 | ioctl( SIOCGIFFLAGS ); | 339 | ioctl( SIOCGIFFLAGS ); |
333 | return _ifr.ifr_flags & IFF_PROMISC; | 340 | return _ifr.ifr_flags & IFF_PROMISC; |
334 | } | 341 | } |
335 | 342 | ||
336 | 343 | ||
337 | bool ONetworkInterface::isWireless() const | 344 | bool ONetworkInterface::isWireless() const |
338 | { | 345 | { |
339 | return ioctl( SIOCGIWNAME ); | 346 | return ioctl( SIOCGIWNAME ); |
340 | } | 347 | } |
341 | 348 | ||
342 | 349 | ||
343 | /*====================================================================================== | 350 | /*====================================================================================== |
344 | * OChannelHopper | 351 | * OChannelHopper |
345 | *======================================================================================*/ | 352 | *======================================================================================*/ |
346 | 353 | ||
347 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 354 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
348 | :QObject( 0, "Mickey's funky hopper" ), | 355 | :QObject( 0, "Mickey's funky hopper" ), |
349 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 356 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
350 | { | 357 | { |
351 | int _maxChannel = iface->channels()+1; | 358 | int _maxChannel = iface->channels()+1; |
352 | // generate fancy hopping sequence honoring the device capabilities | 359 | // generate fancy hopping sequence honoring the device capabilities |
353 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 360 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
354 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 361 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
355 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 362 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
356 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 363 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
357 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 364 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
358 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 365 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
359 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 366 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
360 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 367 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
361 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 368 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
362 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 369 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
363 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 370 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
364 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 371 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
365 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 372 | if ( _maxChannel >= 6 ) _channels.append( 6 ); |
366 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 373 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
367 | _channel = _channels.begin(); | 374 | _channel = _channels.begin(); |
368 | 375 | ||
369 | } | 376 | } |
370 | 377 | ||
371 | 378 | ||
372 | OChannelHopper::~OChannelHopper() | 379 | OChannelHopper::~OChannelHopper() |
373 | { | 380 | { |
374 | } | 381 | } |
375 | 382 | ||
376 | 383 | ||
377 | bool OChannelHopper::isActive() const | 384 | bool OChannelHopper::isActive() const |
378 | { | 385 | { |
379 | return _tid; | 386 | return _tid; |
380 | } | 387 | } |
381 | 388 | ||
382 | 389 | ||
383 | int OChannelHopper::channel() const | 390 | int OChannelHopper::channel() const |
384 | { | 391 | { |
385 | return *_channel; | 392 | return *_channel; |
386 | } | 393 | } |
387 | 394 | ||
388 | 395 | ||
389 | void OChannelHopper::timerEvent( QTimerEvent* ) | 396 | void OChannelHopper::timerEvent( QTimerEvent* ) |
390 | { | 397 | { |
391 | _iface->setChannel( *_channel ); | 398 | _iface->setChannel( *_channel ); |
392 | emit( hopped( *_channel ) ); | 399 | emit( hopped( *_channel ) ); |
393 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", | 400 | qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", |
394 | *_channel, (const char*) _iface->name() ); | 401 | *_channel, (const char*) _iface->name() ); |
395 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 402 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
396 | } | 403 | } |
397 | 404 | ||
398 | 405 | ||
399 | void OChannelHopper::setInterval( int interval ) | 406 | void OChannelHopper::setInterval( int interval ) |
400 | { | 407 | { |
401 | if ( interval == _interval ) | 408 | if ( interval == _interval ) |
402 | return; | 409 | return; |
403 | 410 | ||
404 | if ( _interval ) | 411 | if ( _interval ) |
405 | killTimer( _tid ); | 412 | killTimer( _tid ); |
406 | 413 | ||
407 | _tid = 0; | 414 | _tid = 0; |
408 | _interval = interval; | 415 | _interval = interval; |
409 | 416 | ||
410 | if ( _interval ) | 417 | if ( _interval ) |
411 | { | 418 | { |
412 | _tid = startTimer( interval ); | 419 | _tid = startTimer( interval ); |
413 | } | 420 | } |
414 | } | 421 | } |
415 | 422 | ||
416 | 423 | ||
417 | int OChannelHopper::interval() const | 424 | int OChannelHopper::interval() const |
418 | { | 425 | { |
419 | return _interval; | 426 | return _interval; |
420 | } | 427 | } |
421 | 428 | ||
422 | 429 | ||
423 | /*====================================================================================== | 430 | /*====================================================================================== |
424 | * OWirelessNetworkInterface | 431 | * OWirelessNetworkInterface |
425 | *======================================================================================*/ | 432 | *======================================================================================*/ |
426 | 433 | ||
427 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 434 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
428 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 435 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
429 | { | 436 | { |
430 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); | 437 | qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); |
431 | init(); | 438 | init(); |
432 | } | 439 | } |
433 | 440 | ||
434 | 441 | ||
435 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 442 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
436 | { | 443 | { |
437 | } | 444 | } |
438 | 445 | ||
439 | 446 | ||
440 | struct iwreq& OWirelessNetworkInterface::iwr() const | 447 | struct iwreq& OWirelessNetworkInterface::iwr() const |
441 | { | 448 | { |
442 | return _iwr; | 449 | return _iwr; |
443 | } | 450 | } |
444 | 451 | ||
445 | 452 | ||
446 | void OWirelessNetworkInterface::init() | 453 | void OWirelessNetworkInterface::init() |
447 | { | 454 | { |
448 | qDebug( "OWirelessNetworkInterface::init()" ); | 455 | qDebug( "OWirelessNetworkInterface::init()" ); |
449 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 456 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
450 | buildChannelList(); | 457 | buildChannelList(); |
451 | buildPrivateList(); | 458 | buildPrivateList(); |
452 | } | 459 | } |
453 | 460 | ||
454 | 461 | ||
455 | QString OWirelessNetworkInterface::associatedAP() const | 462 | QString OWirelessNetworkInterface::associatedAP() const |
456 | { | 463 | { |
457 | //FIXME: use OMacAddress | 464 | //FIXME: use OMacAddress |
458 | QString mac; | 465 | QString mac; |
459 | 466 | ||
460 | if ( ioctl( SIOCGIWAP ) ) | 467 | if ( ioctl( SIOCGIWAP ) ) |
461 | { | 468 | { |
462 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 469 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
463 | _ifr.ifr_hwaddr.sa_data[0]&0xff, | 470 | _ifr.ifr_hwaddr.sa_data[0]&0xff, |
464 | _ifr.ifr_hwaddr.sa_data[1]&0xff, | 471 | _ifr.ifr_hwaddr.sa_data[1]&0xff, |
465 | _ifr.ifr_hwaddr.sa_data[2]&0xff, | 472 | _ifr.ifr_hwaddr.sa_data[2]&0xff, |
466 | _ifr.ifr_hwaddr.sa_data[3]&0xff, | 473 | _ifr.ifr_hwaddr.sa_data[3]&0xff, |
467 | _ifr.ifr_hwaddr.sa_data[4]&0xff, | 474 | _ifr.ifr_hwaddr.sa_data[4]&0xff, |
468 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); | 475 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); |
469 | } | 476 | } |
470 | else | 477 | else |
471 | { | 478 | { |
472 | mac = "<Unknown>"; | 479 | mac = "<Unknown>"; |
473 | } | 480 | } |
474 | return mac; | 481 | return mac; |
475 | } | 482 | } |
476 | 483 | ||
477 | 484 | ||
478 | void OWirelessNetworkInterface::buildChannelList() | 485 | void OWirelessNetworkInterface::buildChannelList() |
479 | { | 486 | { |
480 | //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 |
481 | //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 |
482 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 489 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
483 | //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 |
484 | //ML: _too much_ space. This is damn shitty crap *sigh* | 491 | //ML: _too much_ space. This is damn shitty crap *sigh* |
485 | //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 |
486 | //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, |
487 | //ML: so please forward this... | 494 | //ML: so please forward this... |
488 | 495 | ||
489 | struct iwreq wrq; | 496 | struct iwreq wrq; |
490 | int len = sizeof( struct iw_range )*2; | 497 | int len = sizeof( struct iw_range )*2; |
491 | char *buffer = (char*) malloc( len ); | 498 | char *buffer = (char*) malloc( len ); |
492 | //FIXME: Validate if we actually got the memory block | 499 | //FIXME: Validate if we actually got the memory block |
493 | memset( buffer, 0, len ); | 500 | memset( buffer, 0, len ); |
494 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | 501 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); |
495 | wrq.u.data.pointer = (caddr_t) buffer; | 502 | wrq.u.data.pointer = (caddr_t) buffer; |
496 | wrq.u.data.length = sizeof( struct iw_range ); | 503 | wrq.u.data.length = sizeof( struct iw_range ); |
497 | wrq.u.data.flags = 0; | 504 | wrq.u.data.flags = 0; |
498 | 505 | ||
499 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 506 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
500 | { | 507 | { |
501 | 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 ) ); |
502 | _channels.insert( 2412, 1 ); // 2.412 GHz | 509 | _channels.insert( 2412, 1 ); // 2.412 GHz |
503 | _channels.insert( 2417, 2 ); // 2.417 GHz | 510 | _channels.insert( 2417, 2 ); // 2.417 GHz |
504 | _channels.insert( 2422, 3 ); // 2.422 GHz | 511 | _channels.insert( 2422, 3 ); // 2.422 GHz |
505 | _channels.insert( 2427, 4 ); // 2.427 GHz | 512 | _channels.insert( 2427, 4 ); // 2.427 GHz |
506 | _channels.insert( 2432, 5 ); // 2.432 GHz | 513 | _channels.insert( 2432, 5 ); // 2.432 GHz |
507 | _channels.insert( 2437, 6 ); // 2.437 GHz | 514 | _channels.insert( 2437, 6 ); // 2.437 GHz |
508 | _channels.insert( 2442, 7 ); // 2.442 GHz | 515 | _channels.insert( 2442, 7 ); // 2.442 GHz |
509 | _channels.insert( 2447, 8 ); // 2.447 GHz | 516 | _channels.insert( 2447, 8 ); // 2.447 GHz |
510 | _channels.insert( 2452, 9 ); // 2.452 GHz | 517 | _channels.insert( 2452, 9 ); // 2.452 GHz |
511 | _channels.insert( 2457, 10 ); // 2.457 GHz | 518 | _channels.insert( 2457, 10 ); // 2.457 GHz |
512 | _channels.insert( 2462, 11 ); // 2.462 GHz | 519 | _channels.insert( 2462, 11 ); // 2.462 GHz |
513 | } | 520 | } |
514 | else | 521 | else |
515 | { | 522 | { |
516 | // <check if the driver overwrites stuff> | 523 | // <check if the driver overwrites stuff> |
517 | int max = 0; | 524 | int max = 0; |
518 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 525 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
519 | if (buffer[r] != 0) | 526 | if (buffer[r] != 0) |
520 | max = r; | 527 | max = r; |
521 | if (max > 0) | 528 | if (max > 0) |
522 | { | 529 | { |
523 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" | 530 | qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" |
524 | "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 ) ); |
525 | } | 532 | } |
526 | // </check if the driver overwrites stuff> | 533 | // </check if the driver overwrites stuff> |
527 | 534 | ||
528 | struct iw_range range; | 535 | struct iw_range range; |
529 | memcpy( &range, buffer, sizeof range ); | 536 | memcpy( &range, buffer, sizeof range ); |
530 | 537 | ||
531 | 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 ); |
532 | for ( int i = 0; i < range.num_frequency; ++i ) | 539 | for ( int i = 0; i < range.num_frequency; ++i ) |
533 | { | 540 | { |
534 | 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 ); |
535 | _channels.insert( freq, i+1 ); | 542 | _channels.insert( freq, i+1 ); |
536 | } | 543 | } |
537 | } | 544 | } |
538 | 545 | ||
539 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); | 546 | qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); |
540 | free(buffer); | 547 | free(buffer); |
541 | } | 548 | } |
542 | 549 | ||
543 | 550 | ||
544 | void OWirelessNetworkInterface::buildPrivateList() | 551 | void OWirelessNetworkInterface::buildPrivateList() |
545 | { | 552 | { |
546 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); | 553 | qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); |
547 | 554 | ||
548 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 555 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
549 | 556 | ||
550 | _iwr.u.data.pointer = (char*) &priv; | 557 | _iwr.u.data.pointer = (char*) &priv; |
551 | _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 |
552 | _iwr.u.data.flags = 0; | 559 | _iwr.u.data.flags = 0; |
553 | 560 | ||
554 | if ( !wioctl( SIOCGIWPRIV ) ) | 561 | if ( !wioctl( SIOCGIWPRIV ) ) |
555 | { | 562 | { |
556 | 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 ) ); |
557 | return; | 564 | return; |
558 | } | 565 | } |
559 | 566 | ||
560 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 567 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
561 | { | 568 | { |
562 | 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 ); |
563 | } | 570 | } |
564 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); | 571 | qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); |
565 | } | 572 | } |
566 | 573 | ||
567 | 574 | ||
568 | int OWirelessNetworkInterface::channel() const | 575 | int OWirelessNetworkInterface::channel() const |
569 | { | 576 | { |
570 | //FIXME: When monitoring enabled, then use it | 577 | //FIXME: When monitoring enabled, then use it |
571 | //FIXME: to gather the current RF channel | 578 | //FIXME: to gather the current RF channel |
572 | //FIXME: Until then, get active channel from hopper. | 579 | //FIXME: Until then, get active channel from hopper. |
573 | if ( _hopper && _hopper->isActive() ) | 580 | if ( _hopper && _hopper->isActive() ) |
574 | return _hopper->channel(); | 581 | return _hopper->channel(); |
575 | 582 | ||
576 | if ( !wioctl( SIOCGIWFREQ ) ) | 583 | if ( !wioctl( SIOCGIWFREQ ) ) |
577 | { | 584 | { |
578 | return -1; | 585 | return -1; |
579 | } | 586 | } |
580 | else | 587 | else |
581 | { | 588 | { |
582 | 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) ]; |
583 | } | 590 | } |
584 | } | 591 | } |
585 | 592 | ||
586 | 593 | ||
587 | void OWirelessNetworkInterface::setChannel( int c ) const | 594 | void OWirelessNetworkInterface::setChannel( int c ) const |
588 | { | 595 | { |
589 | if ( !_mon ) | 596 | if ( !_mon ) |
590 | { | 597 | { |
591 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 598 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
592 | _iwr.u.freq.m = c; | 599 | _iwr.u.freq.m = c; |
593 | _iwr.u.freq.e = 0; | 600 | _iwr.u.freq.e = 0; |
594 | wioctl( SIOCSIWFREQ ); | 601 | wioctl( SIOCSIWFREQ ); |
595 | } | 602 | } |
596 | else | 603 | else |
597 | { | 604 | { |
598 | _mon->setChannel( c ); | 605 | _mon->setChannel( c ); |
599 | } | 606 | } |
600 | } | 607 | } |
601 | 608 | ||
602 | 609 | ||
603 | double OWirelessNetworkInterface::frequency() const | 610 | double OWirelessNetworkInterface::frequency() const |
604 | { | 611 | { |
605 | if ( !wioctl( SIOCGIWFREQ ) ) | 612 | if ( !wioctl( SIOCGIWFREQ ) ) |
606 | { | 613 | { |
607 | return -1.0; | 614 | return -1.0; |
608 | } | 615 | } |
609 | else | 616 | else |
610 | { | 617 | { |
611 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 618 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
612 | } | 619 | } |
613 | } | 620 | } |
614 | 621 | ||
615 | 622 | ||
616 | int OWirelessNetworkInterface::channels() const | 623 | int OWirelessNetworkInterface::channels() const |
617 | { | 624 | { |
618 | return _channels.count(); | 625 | return _channels.count(); |
619 | } | 626 | } |
620 | 627 | ||
621 | 628 | ||
622 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 629 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
623 | { | 630 | { |
624 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 631 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
625 | _hopper->setInterval( interval ); | 632 | _hopper->setInterval( interval ); |
626 | //FIXME: When and by whom will the channel hopper be deleted? | 633 | //FIXME: When and by whom will the channel hopper be deleted? |
627 | //TODO: rely on QObject hierarchy | 634 | //TODO: rely on QObject hierarchy |
628 | } | 635 | } |
629 | 636 | ||
630 | 637 | ||
631 | int OWirelessNetworkInterface::channelHopping() const | 638 | int OWirelessNetworkInterface::channelHopping() const |
632 | { | 639 | { |
633 | return _hopper->interval(); | 640 | return _hopper->interval(); |
634 | } | 641 | } |
635 | 642 | ||
636 | 643 | ||
637 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const | 644 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const |
638 | { | 645 | { |
639 | return _hopper; | 646 | return _hopper; |
640 | } | 647 | } |
641 | 648 | ||
642 | 649 | ||
643 | void OWirelessNetworkInterface::setMode( const QString& mode ) | 650 | void OWirelessNetworkInterface::setMode( const QString& mode ) |
644 | { | 651 | { |
645 | if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; | 652 | if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; |
646 | else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; | 653 | else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; |
647 | else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; | 654 | else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; |
648 | else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; | 655 | else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; |
649 | else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; | 656 | else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; |
650 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; | 657 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; |
651 | #if WIRELESS_EXT > 14 | 658 | #if WIRELESS_EXT > 14 |
652 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; | 659 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; |
653 | #endif | 660 | #endif |
654 | else | 661 | else |
655 | { | 662 | { |
656 | qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); | 663 | qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); |
657 | return; | 664 | return; |
658 | } | 665 | } |
659 | wioctl( SIOCSIWMODE ); | 666 | wioctl( SIOCSIWMODE ); |
660 | } | 667 | } |
661 | 668 | ||
662 | 669 | ||
663 | QString OWirelessNetworkInterface::mode() const | 670 | QString OWirelessNetworkInterface::mode() const |
664 | { | 671 | { |
665 | if ( !wioctl( SIOCGIWMODE ) ) | 672 | if ( !wioctl( SIOCGIWMODE ) ) |
666 | { | 673 | { |
667 | return "<unknown>"; | 674 | return "<unknown>"; |
668 | } | 675 | } |
669 | switch ( _iwr.u.mode ) | 676 | switch ( _iwr.u.mode ) |
670 | { | 677 | { |
671 | case IW_MODE_AUTO: return "auto"; | 678 | case IW_MODE_AUTO: return "auto"; |
672 | case IW_MODE_ADHOC: return "adhoc"; | 679 | case IW_MODE_ADHOC: return "adhoc"; |
673 | case IW_MODE_INFRA: return "managed"; | 680 | case IW_MODE_INFRA: return "managed"; |
674 | case IW_MODE_MASTER: return "master"; | 681 | case IW_MODE_MASTER: return "master"; |
675 | case IW_MODE_REPEAT: return "repeater"; | 682 | case IW_MODE_REPEAT: return "repeater"; |
676 | case IW_MODE_SECOND: return "secondary"; | 683 | case IW_MODE_SECOND: return "secondary"; |
677 | #if WIRELESS_EXT > 14 | 684 | #if WIRELESS_EXT > 14 |
678 | case IW_MODE_MONITOR: return "monitor"; | 685 | case IW_MODE_MONITOR: return "monitor"; |
679 | #endif | 686 | #endif |
680 | default: assert( 0 ); // shouldn't happen | 687 | default: assert( 0 ); // shouldn't happen |
681 | } | 688 | } |
682 | } | 689 | } |
683 | 690 | ||
684 | 691 | ||
685 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 692 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
686 | { | 693 | { |
687 | if ( _mon ) | 694 | if ( _mon ) |
688 | _mon->setEnabled( b ); | 695 | _mon->setEnabled( b ); |
689 | else | 696 | else |
690 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); | 697 | qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); |
691 | } | 698 | } |
692 | 699 | ||
693 | 700 | ||
694 | bool OWirelessNetworkInterface::monitorMode() const | 701 | bool OWirelessNetworkInterface::monitorMode() const |
695 | { | 702 | { |
696 | qDebug( "dataLinkType = %d", dataLinkType() ); | 703 | qDebug( "dataLinkType = %d", dataLinkType() ); |
697 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); | 704 | return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); |
698 | // 802 is the header type for PRISM - Linux support for this is pending... | 705 | // 802 is the header type for PRISM - Linux support for this is pending... |
699 | } | 706 | } |
700 | 707 | ||
701 | 708 | ||
702 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) | 709 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) |
703 | { | 710 | { |
704 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); | 711 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); |
705 | _iwr.u.essid.length = nickname.length(); | 712 | _iwr.u.essid.length = nickname.length(); |
706 | wioctl( SIOCSIWNICKN ); | 713 | wioctl( SIOCSIWNICKN ); |
707 | } | 714 | } |
708 | 715 | ||
709 | 716 | ||
710 | QString OWirelessNetworkInterface::nickName() const | 717 | QString OWirelessNetworkInterface::nickName() const |
711 | { | 718 | { |
712 | char str[IW_ESSID_MAX_SIZE]; | 719 | char str[IW_ESSID_MAX_SIZE]; |
713 | _iwr.u.data.pointer = &str[0]; | 720 | _iwr.u.data.pointer = &str[0]; |
714 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 721 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
715 | if ( !wioctl( SIOCGIWNICKN ) ) | 722 | if ( !wioctl( SIOCGIWNICKN ) ) |
716 | { | 723 | { |
717 | return "<unknown>"; | 724 | return "<unknown>"; |
718 | } | 725 | } |
719 | else | 726 | else |
720 | { | 727 | { |
721 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 728 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
722 | return str; | 729 | return str; |
723 | } | 730 | } |
724 | } | 731 | } |
725 | 732 | ||
726 | 733 | ||
727 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 734 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
728 | { | 735 | { |
729 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 736 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
730 | if ( !priv ) | 737 | if ( !priv ) |
731 | { | 738 | { |
732 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); | 739 | qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); |
733 | return; | 740 | return; |
734 | } | 741 | } |
735 | if ( priv->numberSetArgs() != numargs ) | 742 | if ( priv->numberSetArgs() != numargs ) |
736 | { | 743 | { |
737 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); | 744 | qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); |
738 | return; | 745 | return; |
739 | } | 746 | } |
740 | 747 | ||
741 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); | 748 | qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); |
742 | memset( &_iwr, 0, sizeof _iwr ); | 749 | memset( &_iwr, 0, sizeof _iwr ); |
743 | va_list argp; | 750 | va_list argp; |
744 | va_start( argp, numargs ); | 751 | va_start( argp, numargs ); |
745 | for ( int i = 0; i < numargs; ++i ) | 752 | for ( int i = 0; i < numargs; ++i ) |
746 | { | 753 | { |
747 | priv->setParameter( i, va_arg( argp, int ) ); | 754 | priv->setParameter( i, va_arg( argp, int ) ); |
748 | } | 755 | } |
749 | va_end( argp ); | 756 | va_end( argp ); |
750 | priv->invoke(); | 757 | priv->invoke(); |
751 | } | 758 | } |
752 | 759 | ||
753 | 760 | ||
754 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 761 | void OWirelessNetworkInterface::getPrivate( const QString& call ) |
755 | { | 762 | { |
756 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); | 763 | qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); |
757 | } | 764 | } |
758 | 765 | ||
759 | 766 | ||
760 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | 767 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) |
761 | { | 768 | { |
762 | return child( (const char*) call ); | 769 | return child( (const char*) call ); |
763 | } | 770 | } |
764 | 771 | ||
765 | 772 | ||
766 | QString OWirelessNetworkInterface::SSID() const | 773 | QString OWirelessNetworkInterface::SSID() const |
767 | { | 774 | { |
768 | char str[IW_ESSID_MAX_SIZE]; | 775 | char str[IW_ESSID_MAX_SIZE]; |
769 | _iwr.u.essid.pointer = &str[0]; | 776 | _iwr.u.essid.pointer = &str[0]; |
770 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 777 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
771 | if ( !wioctl( SIOCGIWESSID ) ) | 778 | if ( !wioctl( SIOCGIWESSID ) ) |
772 | { | 779 | { |
773 | return "<unknown>"; | 780 | return "<unknown>"; |
774 | } | 781 | } |
775 | else | 782 | else |
776 | { | 783 | { |
777 | return str; | 784 | return str; |
778 | } | 785 | } |
779 | } | 786 | } |
780 | 787 | ||
781 | 788 | ||
782 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 789 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
783 | { | 790 | { |
784 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 791 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
785 | _iwr.u.essid.length = ssid.length(); | 792 | _iwr.u.essid.length = ssid.length(); |
786 | wioctl( SIOCSIWESSID ); | 793 | wioctl( SIOCSIWESSID ); |
787 | } | 794 | } |
788 | 795 | ||
789 | 796 | ||
790 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 797 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
791 | { | 798 | { |
792 | int result = ::ioctl( _sfd, call, &iwreq ); | 799 | int result = ::ioctl( _sfd, call, &iwreq ); |
793 | if ( result == -1 ) | 800 | if ( result == -1 ) |
794 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); | 801 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); |
795 | else | 802 | else |
796 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); | 803 | qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); |
797 | return ( result != -1 ); | 804 | return ( result != -1 ); |
798 | } | 805 | } |
799 | 806 | ||
800 | 807 | ||
801 | bool OWirelessNetworkInterface::wioctl( int call ) const | 808 | bool OWirelessNetworkInterface::wioctl( int call ) const |
802 | { | 809 | { |
803 | strcpy( _iwr.ifr_name, name() ); | 810 | strcpy( _iwr.ifr_name, name() ); |
804 | return wioctl( call, _iwr ); | 811 | return wioctl( call, _iwr ); |
805 | } | 812 | } |
806 | 813 | ||
807 | 814 | ||
808 | /*====================================================================================== | 815 | /*====================================================================================== |
809 | * OMonitoringInterface | 816 | * OMonitoringInterface |
810 | *======================================================================================*/ | 817 | *======================================================================================*/ |
811 | 818 | ||
812 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 819 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
813 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) | 820 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) |
814 | { | 821 | { |
815 | } | 822 | } |
816 | 823 | ||
817 | 824 | ||
818 | OMonitoringInterface::~OMonitoringInterface() | 825 | OMonitoringInterface::~OMonitoringInterface() |
819 | { | 826 | { |
820 | } | 827 | } |
821 | 828 | ||
822 | 829 | ||
823 | void OMonitoringInterface::setChannel( int c ) | 830 | void OMonitoringInterface::setChannel( int c ) |
824 | { | 831 | { |
825 | // use standard WE channel switching protocol | 832 | // use standard WE channel switching protocol |
826 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 833 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
827 | _if->_iwr.u.freq.m = c; | 834 | _if->_iwr.u.freq.m = c; |
828 | _if->_iwr.u.freq.e = 0; | 835 | _if->_iwr.u.freq.e = 0; |
829 | _if->wioctl( SIOCSIWFREQ ); | 836 | _if->wioctl( SIOCSIWFREQ ); |
830 | } | 837 | } |
831 | 838 | ||
832 | 839 | ||
833 | bool OMonitoringInterface::enabled() const | 840 | bool OMonitoringInterface::enabled() const |
834 | { | 841 | { |
835 | return _if->monitorMode(); | 842 | return _if->monitorMode(); |
836 | } | 843 | } |
837 | 844 | ||
838 | 845 | ||
839 | void OMonitoringInterface::setEnabled( bool b ) | 846 | void OMonitoringInterface::setEnabled( bool b ) |
840 | { | 847 | { |
841 | } | 848 | } |
842 | 849 | ||
843 | 850 | ||
844 | /*====================================================================================== | 851 | /*====================================================================================== |
845 | * OCiscoMonitoringInterface | 852 | * OCiscoMonitoringInterface |
846 | *======================================================================================*/ | 853 | *======================================================================================*/ |
847 | 854 | ||
848 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 855 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
849 | :OMonitoringInterface( iface, prismHeader ) | 856 | :OMonitoringInterface( iface, prismHeader ) |
850 | { | 857 | { |
851 | iface->setMonitoring( this ); | 858 | iface->setMonitoring( this ); |
852 | } | 859 | } |
853 | 860 | ||
854 | 861 | ||
855 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 862 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
856 | { | 863 | { |
857 | } | 864 | } |
858 | 865 | ||
859 | 866 | ||
860 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 867 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
861 | { | 868 | { |
862 | QString fname; | 869 | QString fname; |
863 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 870 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
864 | QFile f( fname ); | 871 | QFile f( fname ); |
865 | if ( !f.exists() ) return; | 872 | if ( !f.exists() ) return; |
866 | 873 | ||
867 | if ( f.open( IO_WriteOnly ) ) | 874 | if ( f.open( IO_WriteOnly ) ) |
868 | { | 875 | { |
869 | QTextStream s( &f ); | 876 | QTextStream s( &f ); |
870 | s << "Mode: r"; | 877 | s << "Mode: r"; |
871 | s << "Mode: y"; | 878 | s << "Mode: y"; |
872 | s << "XmitPower: 1"; | 879 | s << "XmitPower: 1"; |
873 | } | 880 | } |
874 | 881 | ||
875 | // flushing and closing will be done automatically when f goes out of scope | 882 | // flushing and closing will be done automatically when f goes out of scope |
876 | } | 883 | } |
877 | 884 | ||
878 | 885 | ||
879 | QString OCiscoMonitoringInterface::name() const | 886 | QString OCiscoMonitoringInterface::name() const |
880 | { | 887 | { |
881 | return "cisco"; | 888 | return "cisco"; |
882 | } | 889 | } |
883 | 890 | ||
884 | 891 | ||
885 | void OCiscoMonitoringInterface::setChannel( int ) | 892 | void OCiscoMonitoringInterface::setChannel( int ) |
886 | { | 893 | { |
887 | // cisco devices automatically switch channels when in monitor mode | 894 | // cisco devices automatically switch channels when in monitor mode |
888 | } | 895 | } |
889 | 896 | ||
890 | 897 | ||
891 | /*====================================================================================== | 898 | /*====================================================================================== |
892 | * OWlanNGMonitoringInterface | 899 | * OWlanNGMonitoringInterface |
893 | *======================================================================================*/ | 900 | *======================================================================================*/ |
894 | 901 | ||
895 | 902 | ||
896 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 903 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
897 | :OMonitoringInterface( iface, prismHeader ) | 904 | :OMonitoringInterface( iface, prismHeader ) |
898 | { | 905 | { |
899 | iface->setMonitoring( this ); | 906 | iface->setMonitoring( this ); |
900 | } | 907 | } |
901 | 908 | ||
902 | 909 | ||
903 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 910 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
904 | { | 911 | { |
905 | } | 912 | } |
906 | 913 | ||
907 | 914 | ||
908 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 915 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
909 | { | 916 | { |
910 | //FIXME: do nothing if its already in the same mode | 917 | //FIXME: do nothing if its already in the same mode |
911 | 918 | ||
912 | QString enable = b ? "true" : "false"; | 919 | QString enable = b ? "true" : "false"; |
913 | QString prism = _prismHeader ? "true" : "false"; | 920 | QString prism = _prismHeader ? "true" : "false"; |
914 | QString cmd; | 921 | QString cmd; |
915 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 922 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
916 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); | 923 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); |
917 | system( cmd ); | 924 | system( cmd ); |
918 | } | 925 | } |
919 | 926 | ||
920 | 927 | ||
921 | QString OWlanNGMonitoringInterface::name() const | 928 | QString OWlanNGMonitoringInterface::name() const |
922 | { | 929 | { |
923 | return "wlan-ng"; | 930 | return "wlan-ng"; |
924 | } | 931 | } |
925 | 932 | ||
926 | 933 | ||
927 | void OWlanNGMonitoringInterface::setChannel( int ) | 934 | void OWlanNGMonitoringInterface::setChannel( int ) |
928 | { | 935 | { |
929 | // wlan-ng devices automatically switch channels when in monitor mode | 936 | // wlan-ng devices automatically switch channels when in monitor mode |
930 | } | 937 | } |
931 | 938 | ||
932 | 939 | ||
933 | /*====================================================================================== | 940 | /*====================================================================================== |
934 | * OHostAPMonitoringInterface | 941 | * OHostAPMonitoringInterface |
935 | *======================================================================================*/ | 942 | *======================================================================================*/ |
936 | 943 | ||
937 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 944 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
938 | :OMonitoringInterface( iface, prismHeader ) | 945 | :OMonitoringInterface( iface, prismHeader ) |
939 | { | 946 | { |
940 | iface->setMonitoring( this ); | 947 | iface->setMonitoring( this ); |
941 | } | 948 | } |
942 | 949 | ||
943 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 950 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
944 | { | 951 | { |
945 | } | 952 | } |
946 | 953 | ||
947 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 954 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
948 | { | 955 | { |
949 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | 956 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 |
950 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | 957 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring |
951 | 958 | ||
952 | //TODO: check wireless extensions version on runtime and use | 959 | #if WIRELESS_EXT > 14 |
953 | //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15 | 960 | if ( b ) |
954 | 961 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header | |
962 | else | ||
963 | _if->setMode( "managed" ); | ||
964 | #else | ||
955 | int monitorCode = _prismHeader ? 1 : 2; | 965 | int monitorCode = _prismHeader ? 1 : 2; |
956 | |||
957 | if ( b ) | 966 | if ( b ) |
958 | { | 967 | { |
959 | _if->setPrivate( "monitor", 1, monitorCode ); | 968 | _if->setPrivate( "monitor", 1, monitorCode ); |
960 | } | 969 | } |
961 | else | 970 | else |
962 | { | 971 | { |
963 | _if->setPrivate( "monitor", 1, 0 ); | 972 | _if->setPrivate( "monitor", 1, 0 ); |
964 | } | 973 | } |
974 | #endif | ||
965 | } | 975 | } |
966 | 976 | ||
967 | 977 | ||
968 | QString OHostAPMonitoringInterface::name() const | 978 | QString OHostAPMonitoringInterface::name() const |
969 | { | 979 | { |
970 | return "hostap"; | 980 | return "hostap"; |
971 | } | 981 | } |
972 | 982 | ||
973 | 983 | ||
974 | /*====================================================================================== | 984 | /*====================================================================================== |
975 | * OOrinocoNetworkInterface | 985 | * OOrinocoNetworkInterface |
976 | *======================================================================================*/ | 986 | *======================================================================================*/ |
977 | 987 | ||
978 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 988 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
979 | :OMonitoringInterface( iface, prismHeader ) | 989 | :OMonitoringInterface( iface, prismHeader ) |
980 | { | 990 | { |
981 | iface->setMonitoring( this ); | 991 | iface->setMonitoring( this ); |
982 | } | 992 | } |
983 | 993 | ||
984 | 994 | ||
985 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 995 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
986 | { | 996 | { |
987 | } | 997 | } |
988 | 998 | ||
989 | 999 | ||
990 | void OOrinocoMonitoringInterface::setChannel( int c ) | 1000 | void OOrinocoMonitoringInterface::setChannel( int c ) |
991 | { | 1001 | { |
992 | int monitorCode = _prismHeader ? 1 : 2; | 1002 | int monitorCode = _prismHeader ? 1 : 2; |
993 | _if->setPrivate( "monitor", 2, monitorCode, c ); | 1003 | _if->setPrivate( "monitor", 2, monitorCode, c ); |
994 | } | 1004 | } |
995 | 1005 | ||
996 | 1006 | ||
997 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 1007 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
998 | { | 1008 | { |
1009 | // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 | ||
1010 | // Wireless Extensions < Version 15 need iwpriv commandos for monitoring | ||
1011 | |||
1012 | #if WIRELESS_EXT > 14 | ||
1013 | if ( b ) | ||
1014 | _if->setMode( "monitor" ); // IW_MODE_MONITOR doesn't support prism header | ||
1015 | else | ||
1016 | _if->setMode( "managed" ); | ||
1017 | #else | ||
999 | if ( b ) | 1018 | if ( b ) |
1000 | { | 1019 | { |
1001 | setChannel( 1 ); | 1020 | setChannel( 1 ); |
1002 | } | 1021 | } |
1003 | else | 1022 | else |
1004 | { | 1023 | { |
1005 | _if->setPrivate( "monitor", 2, 0, 0 ); | 1024 | _if->setPrivate( "monitor", 2, 0, 0 ); |
1006 | } | 1025 | } |
1026 | #endif | ||
1007 | } | 1027 | } |
1008 | 1028 | ||
1009 | 1029 | ||
1010 | QString OOrinocoMonitoringInterface::name() const | 1030 | QString OOrinocoMonitoringInterface::name() const |
1011 | { | 1031 | { |
1012 | return "orinoco"; | 1032 | return "orinoco"; |
1013 | } | 1033 | } |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index cfb999d..2553a61 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -1,540 +1,542 @@ | |||
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 | // FIXME QString? -zecke | ||
108 | bool isWirelessInterface( const char* interface ) const; | 107 | bool isWirelessInterface( const char* interface ) const; |
109 | /** | 108 | /** |
110 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found | 109 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. |
111 | * @see ONetworkInterface | 110 | * @see ONetworkInterface |
112 | */ | 111 | */ |
113 | // FIXME: const QString& is prefered over QString!!! -zecke | ||
114 | ONetworkInterface* interface( const QString& interface ) const; | 112 | ONetworkInterface* interface( const QString& interface ) const; |
115 | /** | 113 | /** |
116 | * @internal Rebuild the internal interface database | 114 | * @internal Rebuild the internal interface database |
117 | * @note Sometimes it might be useful to call this from client code, | 115 | * @note Sometimes it might be useful to call this from client code, |
118 | * e.g. after issuing a cardctl insert | 116 | * e.g. after issuing a cardctl insert |
119 | */ | 117 | */ |
120 | void synchronize(); | 118 | void synchronize(); |
119 | /** | ||
120 | * @returns the wireless extension version used at compile time. | ||
121 | **/ | ||
122 | static short wirelessExtensionVersion(); | ||
121 | 123 | ||
122 | protected: | 124 | protected: |
123 | ONetwork(); | 125 | ONetwork(); |
124 | 126 | ||
125 | private: | 127 | private: |
126 | static ONetwork* _instance; | 128 | static ONetwork* _instance; |
127 | InterfaceMap _interfaces; | 129 | InterfaceMap _interfaces; |
128 | }; | 130 | }; |
129 | 131 | ||
130 | 132 | ||
131 | /*====================================================================================== | 133 | /*====================================================================================== |
132 | * ONetworkInterface | 134 | * ONetworkInterface |
133 | *======================================================================================*/ | 135 | *======================================================================================*/ |
134 | 136 | ||
135 | /** | 137 | /** |
136 | * @brief A network interface wrapper. | 138 | * @brief A network interface wrapper. |
137 | * | 139 | * |
138 | * This class provides a wrapper for a network interface. All the cumbersume details of | 140 | * This class provides a wrapper for a network interface. All the cumbersume details of |
139 | * Linux ioctls are hidden under a convenient high-level interface. | 141 | * Linux ioctls are hidden under a convenient high-level interface. |
140 | * @warning Most of the setting methods contained in this class require the appropriate | 142 | * @warning Most of the setting methods contained in this class require the appropriate |
141 | * process permissions to work. | 143 | * process permissions to work. |
142 | * | 144 | * |
143 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 145 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
144 | */ | 146 | */ |
145 | class ONetworkInterface : public QObject | 147 | class ONetworkInterface : public QObject |
146 | { | 148 | { |
147 | friend class OMonitoringInterface; | 149 | friend class OMonitoringInterface; |
148 | friend class OCiscoMonitoringInterface; | 150 | friend class OCiscoMonitoringInterface; |
149 | friend class OWlanNGMonitoringInterface; | 151 | friend class OWlanNGMonitoringInterface; |
150 | friend class OHostAPMonitoringInterface; | 152 | friend class OHostAPMonitoringInterface; |
151 | friend class OOrinocoMonitoringInterface; | 153 | friend class OOrinocoMonitoringInterface; |
152 | 154 | ||
153 | public: | 155 | public: |
154 | /** | 156 | /** |
155 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, | 157 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, |
156 | * but access them via @ref ONetwork::interface(). | 158 | * but access them via @ref ONetwork::interface(). |
157 | */ | 159 | */ |
158 | ONetworkInterface( QObject* parent, const char* name ); | 160 | ONetworkInterface( QObject* parent, const char* name ); |
159 | /** | 161 | /** |
160 | * Destructor. | 162 | * Destructor. |
161 | */ | 163 | */ |
162 | virtual ~ONetworkInterface(); | 164 | virtual ~ONetworkInterface(); |
163 | /** | 165 | /** |
164 | * Associates a @a monitoring interface with this network interface. | 166 | * Associates a @a monitoring interface with this network interface. |
165 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. | 167 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. |
166 | */ | 168 | */ |
167 | void setMonitoring( OMonitoringInterface* monitoring ); | 169 | void setMonitoring( OMonitoringInterface* monitoring ); |
168 | /** | 170 | /** |
169 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. | 171 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. |
170 | */ | 172 | */ |
171 | OMonitoringInterface* monitoring() const; | 173 | OMonitoringInterface* monitoring() const; |
172 | /** | 174 | /** |
173 | * Setting an interface to promiscuous mode enables the device to receive | 175 | * Setting an interface to promiscuous mode enables the device to receive |
174 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. | 176 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. |
175 | */ | 177 | */ |
176 | bool setPromiscuousMode( bool ); | 178 | bool setPromiscuousMode( bool ); |
177 | /** | 179 | /** |
178 | * @returns true if the interface is set to promiscuous mode. | 180 | * @returns true if the interface is set to promiscuous mode. |
179 | */ | 181 | */ |
180 | bool promiscuousMode() const; | 182 | bool promiscuousMode() const; |
181 | /** | 183 | /** |
182 | * Setting an interface to up enables it to receive packets. | 184 | * Setting an interface to up enables it to receive packets. |
183 | */ | 185 | */ |
184 | bool setUp( bool ); | 186 | bool setUp( bool ); |
185 | /** | 187 | /** |
186 | * @returns true if the interface is up. | 188 | * @returns true if the interface is up. |
187 | */ | 189 | */ |
188 | bool isUp() const; | 190 | bool isUp() const; |
189 | /** | 191 | /** |
190 | * @returns true if the interface is a loopback interface. | 192 | * @returns true if the interface is a loopback interface. |
191 | */ | 193 | */ |
192 | bool isLoopback() const; | 194 | bool isLoopback() const; |
193 | /** | 195 | /** |
194 | * @returns true if the interface is featuring supports the wireless extension protocol. | 196 | * @returns true if the interface is featuring supports the wireless extension protocol. |
195 | */ | 197 | */ |
196 | bool isWireless() const; | 198 | bool isWireless() const; |
197 | /** | 199 | /** |
198 | * Associate the IP address @ addr with the interface. | 200 | * Associate the IP address @ addr with the interface. |
199 | */ | 201 | */ |
200 | void setIPV4Address( const QHostAddress& addr ); | 202 | void setIPV4Address( const QHostAddress& addr ); |
201 | /** | 203 | /** |
202 | * @returns the IPv4 address associated with the interface. | 204 | * @returns the IPv4 address associated with the interface. |
203 | */ | 205 | */ |
204 | QString ipV4Address() const; //TODO: make this return an OHostAddress | 206 | QString ipV4Address() const; //TODO: make this return an OHostAddress |
205 | /** | 207 | /** |
206 | * Associate the MAC address @a addr with the interface. | 208 | * Associate the MAC address @a addr with the interface. |
207 | * @note It can be necessary to shut down the interface prior to calling this method. | 209 | * @note It can be necessary to shut down the interface prior to calling this method. |
208 | * @warning This is not supported by all drivers. | 210 | * @warning This is not supported by all drivers. |
209 | */ | 211 | */ |
210 | void setMacAddress( const OMacAddress& addr ); | 212 | void setMacAddress( const OMacAddress& addr ); |
211 | /** | 213 | /** |
212 | * @returns the MAC address associated with the interface. | 214 | * @returns the MAC address associated with the interface. |
213 | */ | 215 | */ |
214 | OMacAddress macAddress() const; | 216 | OMacAddress macAddress() const; |
215 | /** | 217 | /** |
216 | * Associate the IPv4 @a netmask with the interface. | 218 | * Associate the IPv4 @a netmask with the interface. |
217 | */ | 219 | */ |
218 | void setIPV4Netmask( const QHostAddress& netmask ); | 220 | void setIPV4Netmask( const QHostAddress& netmask ); |
219 | /** | 221 | /** |
220 | * @returns the IPv4 netmask associated with the interface. | 222 | * @returns the IPv4 netmask associated with the interface. |
221 | */ | 223 | */ |
222 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress | 224 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress |
223 | /** | 225 | /** |
224 | * @returns the data link type currently associated with the interface. | 226 | * @returns the data link type currently associated with the interface. |
225 | * @see #include <net/if_arp.h> for possible values. | 227 | * @see #include <net/if_arp.h> for possible values. |
226 | */ | 228 | */ |
227 | int dataLinkType() const; | 229 | int dataLinkType() const; |
228 | 230 | ||
229 | protected: | 231 | protected: |
230 | const int _sfd; | 232 | const int _sfd; |
231 | mutable ifreq _ifr; | 233 | mutable ifreq _ifr; |
232 | OMonitoringInterface* _mon; | 234 | OMonitoringInterface* _mon; |
233 | 235 | ||
234 | protected: | 236 | protected: |
235 | struct ifreq& ifr() const; | 237 | struct ifreq& ifr() const; |
236 | virtual void init(); | 238 | virtual void init(); |
237 | bool ioctl( int call ) const; | 239 | bool ioctl( int call ) const; |
238 | bool ioctl( int call, struct ifreq& ) const; | 240 | bool ioctl( int call, struct ifreq& ) const; |
239 | }; | 241 | }; |
240 | 242 | ||
241 | /*====================================================================================== | 243 | /*====================================================================================== |
242 | * OChannelHopper | 244 | * OChannelHopper |
243 | *======================================================================================*/ | 245 | *======================================================================================*/ |
244 | 246 | ||
245 | /** | 247 | /** |
246 | * @brief A radio frequency channel hopper. | 248 | * @brief A radio frequency channel hopper. |
247 | * | 249 | * |
248 | * 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 |
249 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. | 251 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. |
250 | * 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 |
251 | * 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. |
252 | * | 254 | * |
253 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 255 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
254 | */ | 256 | */ |
255 | class OChannelHopper : public QObject | 257 | class OChannelHopper : public QObject |
256 | { | 258 | { |
257 | Q_OBJECT | 259 | Q_OBJECT |
258 | 260 | ||
259 | public: | 261 | public: |
260 | /** | 262 | /** |
261 | * Constructor. | 263 | * Constructor. |
262 | */ | 264 | */ |
263 | OChannelHopper( OWirelessNetworkInterface* ); | 265 | OChannelHopper( OWirelessNetworkInterface* ); |
264 | /** | 266 | /** |
265 | * Destructor. | 267 | * Destructor. |
266 | */ | 268 | */ |
267 | virtual ~OChannelHopper(); | 269 | virtual ~OChannelHopper(); |
268 | /** | 270 | /** |
269 | * @returns true, if the channel hopper is hopping channels | 271 | * @returns true, if the channel hopper is hopping channels |
270 | */ | 272 | */ |
271 | bool isActive() const; | 273 | bool isActive() const; |
272 | /** | 274 | /** |
273 | * @returns the last hopped channel | 275 | * @returns the last hopped channel |
274 | */ | 276 | */ |
275 | int channel() const; | 277 | int channel() const; |
276 | /** | 278 | /** |
277 | * Set the channel hopping @a interval. | 279 | * Set the channel hopping @a interval. |
278 | * An interval of 0 deactivates the channel hopper. | 280 | * An interval of 0 deactivates the channel hopper. |
279 | */ | 281 | */ |
280 | void setInterval( int interval ); | 282 | void setInterval( int interval ); |
281 | /** | 283 | /** |
282 | * @returns the channel hopping interval | 284 | * @returns the channel hopping interval |
283 | */ | 285 | */ |
284 | int interval() const; | 286 | int interval() const; |
285 | 287 | ||
286 | signals: | 288 | signals: |
287 | /** | 289 | /** |
288 | * 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 |
289 | */ | 291 | */ |
290 | void hopped( int ); | 292 | void hopped( int ); |
291 | 293 | ||
292 | protected: | 294 | protected: |
293 | virtual void timerEvent( QTimerEvent* ); | 295 | virtual void timerEvent( QTimerEvent* ); |
294 | 296 | ||
295 | private: | 297 | private: |
296 | OWirelessNetworkInterface* _iface; | 298 | OWirelessNetworkInterface* _iface; |
297 | int _interval; | 299 | int _interval; |
298 | int _tid; | 300 | int _tid; |
299 | QValueList<int> _channels; | 301 | QValueList<int> _channels; |
300 | QValueList<int>::Iterator _channel; | 302 | QValueList<int>::Iterator _channel; |
301 | }; | 303 | }; |
302 | 304 | ||
303 | 305 | ||
304 | /*====================================================================================== | 306 | /*====================================================================================== |
305 | * OWirelessNetworkInterface | 307 | * OWirelessNetworkInterface |
306 | *======================================================================================*/ | 308 | *======================================================================================*/ |
307 | 309 | ||
308 | /** | 310 | /** |
309 | * @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. |
310 | * | 312 | * |
311 | * 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. |
312 | * | 314 | * |
313 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> | 315 | * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> |
314 | */ | 316 | */ |
315 | class OWirelessNetworkInterface : public ONetworkInterface | 317 | class OWirelessNetworkInterface : public ONetworkInterface |
316 | { | 318 | { |
317 | friend class OMonitoringInterface; | 319 | friend class OMonitoringInterface; |
318 | friend class OCiscoMonitoringInterface; | 320 | friend class OCiscoMonitoringInterface; |
319 | friend class OWlanNGMonitoringInterface; | 321 | friend class OWlanNGMonitoringInterface; |
320 | friend class OHostAPMonitoringInterface; | 322 | friend class OHostAPMonitoringInterface; |
321 | friend class OOrinocoMonitoringInterface; | 323 | friend class OOrinocoMonitoringInterface; |
322 | 324 | ||
323 | friend class OPrivateIOCTL; | 325 | friend class OPrivateIOCTL; |
324 | 326 | ||
325 | public: | 327 | public: |
326 | /** | 328 | /** |
327 | * Constructor. | 329 | * Constructor. |
328 | */ | 330 | */ |
329 | OWirelessNetworkInterface( QObject* parent, const char* name ); | 331 | OWirelessNetworkInterface( QObject* parent, const char* name ); |
330 | /** | 332 | /** |
331 | * Destructor. | 333 | * Destructor. |
332 | */ | 334 | */ |
333 | virtual ~OWirelessNetworkInterface(); | 335 | virtual ~OWirelessNetworkInterface(); |
334 | /** | 336 | /** |
335 | * 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) |
336 | * of the corresponding wireless network device. | 338 | * of the corresponding wireless network device. |
337 | */ | 339 | */ |
338 | virtual void setChannel( int channel ) const; | 340 | virtual void setChannel( int channel ) const; |
339 | /** | 341 | /** |
340 | * @returns the channel index of the current radio frequency. | 342 | * @returns the channel index of the current radio frequency. |
341 | */ | 343 | */ |
342 | virtual int channel() const; | 344 | virtual int channel() const; |
343 | /** | 345 | /** |
344 | * @returns the current radio frequency (in MHz). | 346 | * @returns the current radio frequency (in MHz). |
345 | */ | 347 | */ |
346 | virtual double frequency() const; | 348 | virtual double frequency() const; |
347 | /** | 349 | /** |
348 | * @returns the number of radio frequency channels for the | 350 | * @returns the number of radio frequency channels for the |
349 | * corresponding wireless network device. | 351 | * corresponding wireless network device. |
350 | * @note European devices usually have 14 channels, while American typically feature 11 channels. | 352 | * @note European devices usually have 14 channels, while American typically feature 11 channels. |
351 | */ | 353 | */ |
352 | virtual int channels() const; | 354 | virtual int channels() const; |
353 | /** | 355 | /** |
354 | * Set the IEEE 802.11 operation @a mode. | 356 | * Set the IEEE 802.11 operation @a mode. |
355 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master | 357 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master |
356 | * @warning Not all drivers support the all modes. | 358 | * @warning Not all drivers support the all modes. |
357 | * @note You might have to change the SSID to get the operation mode change into effect. | 359 | * @note You might have to change the SSID to get the operation mode change into effect. |
358 | */ | 360 | */ |
359 | virtual void setMode( const QString& mode ); | 361 | virtual void setMode( const QString& mode ); |
360 | /** | 362 | /** |
361 | * @returns the current IEEE 802.11 operation mode. | 363 | * @returns the current IEEE 802.11 operation mode. |
362 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown | 364 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown |
363 | */ | 365 | */ |
364 | virtual QString mode() const; | 366 | virtual QString mode() const; |
365 | /** | 367 | /** |
366 | * Setting the monitor mode on a wireless network interface enables | 368 | * Setting the monitor mode on a wireless network interface enables |
367 | * listening to IEEE 802.11 data and management frames which normally | 369 | * listening to IEEE 802.11 data and management frames which normally |
368 | * are handled by the device firmware. This can be used to detect | 370 | * are handled by the device firmware. This can be used to detect |
369 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. | 371 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. |
370 | * @warning Standard wireless network drives don't support the monitor mode. | 372 | * @warning Standard wireless network drives don't support the monitor mode. |
371 | * @warning You need a patched driver for this to work. | 373 | * @warning You need a patched driver for this to work. |
372 | * @note Enabling the monitor mode is highly driver dependent and requires | 374 | * @note Enabling the monitor mode is highly driver dependent and requires |
373 | * the proper @ref OMonitoringInterface to be associated with the interface. | 375 | * the proper @ref OMonitoringInterface to be associated with the interface. |
374 | * @see OMonitoringInterface | 376 | * @see OMonitoringInterface |
375 | */ | 377 | */ |
376 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); | 378 | virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" ); |
377 | /** | 379 | /** |
378 | * @returns true if the device is listening in IEEE 802.11 monitor mode | 380 | * @returns true if the device is listening in IEEE 802.11 monitor mode |
379 | */ | 381 | */ |
380 | virtual bool monitorMode() const; //FIXME: ==> mode() | 382 | virtual bool monitorMode() const; //FIXME: ==> mode() |
381 | /** | 383 | /** |
382 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. | 384 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. |
383 | * @see OChannelHopper | 385 | * @see OChannelHopper |
384 | */ | 386 | */ |
385 | virtual void setChannelHopping( int interval = 0 ); | 387 | virtual void setChannelHopping( int interval = 0 ); |
386 | /** | 388 | /** |
387 | * @returns the channel hopping interval or 0, if channel hopping is disabled. | 389 | * @returns the channel hopping interval or 0, if channel hopping is disabled. |
388 | */ | 390 | */ |
389 | virtual int channelHopping() const; | 391 | virtual int channelHopping() const; |
390 | /** | 392 | /** |
391 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before | 393 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before |
392 | */ | 394 | */ |
393 | virtual OChannelHopper* channelHopper() const; | 395 | virtual OChannelHopper* channelHopper() const; |
394 | /** | 396 | /** |
395 | * Set the station @a nickname. | 397 | * Set the station @a nickname. |
396 | */ | 398 | */ |
397 | virtual void setNickName( const QString& nickname ); | 399 | virtual void setNickName( const QString& nickname ); |
398 | /** | 400 | /** |
399 | * @returns the current station nickname. | 401 | * @returns the current station nickname. |
400 | */ | 402 | */ |
401 | virtual QString nickName() const; | 403 | virtual QString nickName() const; |
402 | /** | 404 | /** |
403 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. | 405 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. |
404 | * @see OPrivateIOCTL | 406 | * @see OPrivateIOCTL |
405 | */ | 407 | */ |
406 | virtual void setPrivate( const QString& command, int number, ... ); | 408 | virtual void setPrivate( const QString& command, int number, ... ); |
407 | /** | 409 | /** |
408 | * @returns true if the interface is featuring the private IOCTL @command. | 410 | * @returns true if the interface is featuring the private IOCTL @command. |
409 | */ | 411 | */ |
410 | virtual bool hasPrivate( const QString& command ); | 412 | virtual bool hasPrivate( const QString& command ); |
411 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this | 413 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this |
412 | 414 | ||
413 | virtual bool isAssociated() const {}; //FIXME: Implement and document this | 415 | virtual bool isAssociated() const {}; //FIXME: Implement and document this |
414 | /** | 416 | /** |
415 | * @returns the MAC address of the Access Point if the | 417 | * @returns the MAC address of the Access Point if the |
416 | * device is in infrastructure mode. @returns a (more or less random) CELL | 418 | * device is in infrastructure mode. @returns a (more or less random) CELL |
417 | * address if the device is in adhoc mode. | 419 | * address if the device is in adhoc mode. |
418 | */ | 420 | */ |
419 | virtual QString associatedAP() const; | 421 | virtual QString associatedAP() const; |
420 | /** | 422 | /** |
421 | * Set the @a ssid (Service Set ID) string. This is used to decide | 423 | * Set the @a ssid (Service Set ID) string. This is used to decide |
422 | * which network to associate with (use "any" to let the driver decide). | 424 | * which network to associate with (use "any" to let the driver decide). |
423 | */ | 425 | */ |
424 | virtual void setSSID( const QString& ssid ); | 426 | virtual void setSSID( const QString& ssid ); |
425 | /** | 427 | /** |
426 | * @returns the current SSID (Service Set ID). | 428 | * @returns the current SSID (Service Set ID). |
427 | */ | 429 | */ |
428 | virtual QString SSID() const; | 430 | virtual QString SSID() const; |
429 | 431 | ||
430 | protected: | 432 | protected: |
431 | void buildChannelList(); | 433 | void buildChannelList(); |
432 | void buildPrivateList(); | 434 | void buildPrivateList(); |
433 | virtual void init(); | 435 | virtual void init(); |
434 | struct iwreq& iwr() const; | 436 | struct iwreq& iwr() const; |
435 | bool wioctl( int call ) const; | 437 | bool wioctl( int call ) const; |
436 | bool wioctl( int call, struct iwreq& ) const; | 438 | bool wioctl( int call, struct iwreq& ) const; |
437 | 439 | ||
438 | protected: | 440 | protected: |
439 | mutable struct iwreq _iwr; | 441 | mutable struct iwreq _iwr; |
440 | QMap<int,int> _channels; | 442 | QMap<int,int> _channels; |
441 | 443 | ||
442 | private: | 444 | private: |
443 | OChannelHopper* _hopper; | 445 | OChannelHopper* _hopper; |
444 | }; | 446 | }; |
445 | 447 | ||
446 | 448 | ||
447 | /*====================================================================================== | 449 | /*====================================================================================== |
448 | * OMonitoringInterface | 450 | * OMonitoringInterface |
449 | *======================================================================================*/ | 451 | *======================================================================================*/ |
450 | 452 | ||
451 | 453 | ||
452 | class OMonitoringInterface | 454 | class OMonitoringInterface |
453 | { | 455 | { |
454 | public: | 456 | public: |
455 | OMonitoringInterface(); | 457 | OMonitoringInterface(); |
456 | OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 458 | OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
457 | virtual ~OMonitoringInterface(); | 459 | virtual ~OMonitoringInterface(); |
458 | 460 | ||
459 | public: | 461 | public: |
460 | virtual void setEnabled( bool ); | 462 | virtual void setEnabled( bool ); |
461 | virtual bool enabled() const; | 463 | virtual bool enabled() const; |
462 | virtual void setChannel( int ); | 464 | virtual void setChannel( int ); |
463 | 465 | ||
464 | virtual QString name() const = 0; | 466 | virtual QString name() const = 0; |
465 | 467 | ||
466 | protected: | 468 | protected: |
467 | OWirelessNetworkInterface* _if; | 469 | OWirelessNetworkInterface* _if; |
468 | bool _prismHeader; | 470 | bool _prismHeader; |
469 | 471 | ||
470 | }; | 472 | }; |
471 | 473 | ||
472 | 474 | ||
473 | /*====================================================================================== | 475 | /*====================================================================================== |
474 | * OCiscoMonitoring | 476 | * OCiscoMonitoring |
475 | *======================================================================================*/ | 477 | *======================================================================================*/ |
476 | 478 | ||
477 | 479 | ||
478 | class OCiscoMonitoringInterface : public OMonitoringInterface | 480 | class OCiscoMonitoringInterface : public OMonitoringInterface |
479 | { | 481 | { |
480 | public: | 482 | public: |
481 | OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 483 | OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
482 | virtual ~OCiscoMonitoringInterface(); | 484 | virtual ~OCiscoMonitoringInterface(); |
483 | 485 | ||
484 | virtual void setEnabled( bool ); | 486 | virtual void setEnabled( bool ); |
485 | virtual QString name() const; | 487 | virtual QString name() const; |
486 | virtual void setChannel( int ); | 488 | virtual void setChannel( int ); |
487 | 489 | ||
488 | }; | 490 | }; |
489 | 491 | ||
490 | /*====================================================================================== | 492 | /*====================================================================================== |
491 | * OWlanNGMonitoringInterface | 493 | * OWlanNGMonitoringInterface |
492 | *======================================================================================*/ | 494 | *======================================================================================*/ |
493 | 495 | ||
494 | class OWlanNGMonitoringInterface : public OMonitoringInterface | 496 | class OWlanNGMonitoringInterface : public OMonitoringInterface |
495 | { | 497 | { |
496 | public: | 498 | public: |
497 | OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 499 | OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
498 | virtual ~OWlanNGMonitoringInterface(); | 500 | virtual ~OWlanNGMonitoringInterface(); |
499 | 501 | ||
500 | public: | 502 | public: |
501 | virtual void setEnabled( bool ); | 503 | virtual void setEnabled( bool ); |
502 | virtual QString name() const; | 504 | virtual QString name() const; |
503 | virtual void setChannel( int ); | 505 | virtual void setChannel( int ); |
504 | 506 | ||
505 | }; | 507 | }; |
506 | 508 | ||
507 | /*====================================================================================== | 509 | /*====================================================================================== |
508 | * OHostAPMonitoringInterface | 510 | * OHostAPMonitoringInterface |
509 | *======================================================================================*/ | 511 | *======================================================================================*/ |
510 | 512 | ||
511 | class OHostAPMonitoringInterface : public OMonitoringInterface | 513 | class OHostAPMonitoringInterface : public OMonitoringInterface |
512 | { | 514 | { |
513 | public: | 515 | public: |
514 | OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 516 | OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
515 | virtual ~OHostAPMonitoringInterface(); | 517 | virtual ~OHostAPMonitoringInterface(); |
516 | 518 | ||
517 | public: | 519 | public: |
518 | virtual void setEnabled( bool ); | 520 | virtual void setEnabled( bool ); |
519 | virtual QString name() const; | 521 | virtual QString name() const; |
520 | }; | 522 | }; |
521 | 523 | ||
522 | /*====================================================================================== | 524 | /*====================================================================================== |
523 | * OOrinocoMonitoringInterface | 525 | * OOrinocoMonitoringInterface |
524 | *======================================================================================*/ | 526 | *======================================================================================*/ |
525 | 527 | ||
526 | class OOrinocoMonitoringInterface : public OMonitoringInterface | 528 | class OOrinocoMonitoringInterface : public OMonitoringInterface |
527 | { | 529 | { |
528 | public: | 530 | public: |
529 | OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 531 | OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
530 | virtual ~OOrinocoMonitoringInterface(); | 532 | virtual ~OOrinocoMonitoringInterface(); |
531 | 533 | ||
532 | public: | 534 | public: |
533 | virtual void setChannel( int ); | 535 | virtual void setChannel( int ); |
534 | virtual void setEnabled( bool ); | 536 | virtual void setEnabled( bool ); |
535 | virtual QString name() const; | 537 | virtual QString name() const; |
536 | 538 | ||
537 | }; | 539 | }; |
538 | 540 | ||
539 | #endif // ONETWORK_H | 541 | #endif // ONETWORK_H |
540 | 542 | ||