-rw-r--r-- | libopie2/opienet/onetwork.cpp | 23 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 4 |
2 files changed, 21 insertions, 6 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 915814d..e5b091f 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -1,1228 +1,1239 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer | 3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer |
4 | =. <mickey@Vanille.de> | 4 | =. <mickey@Vanille.de> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | /* OPIE */ | 31 | /* OPIE */ |
32 | 32 | ||
33 | #include <opie2/onetwork.h> | 33 | #include <opie2/onetwork.h> |
34 | #include <opie2/ostation.h> | 34 | #include <opie2/ostation.h> |
35 | #include <opie2/odebug.h> | 35 | #include <opie2/odebug.h> |
36 | 36 | ||
37 | /* QT */ | 37 | /* QT */ |
38 | 38 | ||
39 | #include <qfile.h> | 39 | #include <qfile.h> |
40 | #include <qtextstream.h> | 40 | #include <qtextstream.h> |
41 | 41 | ||
42 | /* UNIX */ | 42 | /* UNIX */ |
43 | 43 | ||
44 | #include <assert.h> | 44 | #include <assert.h> |
45 | #include <arpa/inet.h> | 45 | #include <arpa/inet.h> |
46 | #include <errno.h> | 46 | #include <errno.h> |
47 | #include <string.h> | 47 | #include <string.h> |
48 | #include <stdlib.h> | 48 | #include <stdlib.h> |
49 | #include <math.h> | 49 | #include <math.h> |
50 | #include <sys/ioctl.h> | 50 | #include <sys/ioctl.h> |
51 | #include <sys/socket.h> | 51 | #include <sys/socket.h> |
52 | #include <sys/types.h> | 52 | #include <sys/types.h> |
53 | #include <unistd.h> | 53 | #include <unistd.h> |
54 | #include <linux/sockios.h> | 54 | #include <linux/sockios.h> |
55 | #include <net/if_arp.h> | 55 | #include <net/if_arp.h> |
56 | #include <stdarg.h> | 56 | #include <stdarg.h> |
57 | 57 | ||
58 | #ifndef NODEBUG | 58 | #ifndef NODEBUG |
59 | #include <opie2/odebugmapper.h> | 59 | #include <opie2/odebugmapper.h> |
60 | DebugMapper* debugmapper = new DebugMapper(); | 60 | DebugMapper* debugmapper = new DebugMapper(); |
61 | #endif | 61 | #endif |
62 | 62 | ||
63 | /*====================================================================================== | 63 | /*====================================================================================== |
64 | * ONetwork | 64 | * ONetwork |
65 | *======================================================================================*/ | 65 | *======================================================================================*/ |
66 | 66 | ||
67 | ONetwork* ONetwork::_instance = 0; | 67 | ONetwork* ONetwork::_instance = 0; |
68 | 68 | ||
69 | ONetwork::ONetwork() | 69 | ONetwork::ONetwork() |
70 | { | 70 | { |
71 | odebug << "ONetwork::ONetwork()" << oendl; | 71 | odebug << "ONetwork::ONetwork()" << oendl; |
72 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; | 72 | odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; |
73 | synchronize(); | 73 | synchronize(); |
74 | } | 74 | } |
75 | 75 | ||
76 | void ONetwork::synchronize() | 76 | void ONetwork::synchronize() |
77 | { | 77 | { |
78 | // gather available interfaces by inspecting /proc/net/dev | 78 | // gather available interfaces by inspecting /proc/net/dev |
79 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices | 79 | //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices |
80 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices | 80 | //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices |
81 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev | 81 | //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev |
82 | 82 | ||
83 | _interfaces.clear(); | 83 | _interfaces.clear(); |
84 | QString str; | 84 | QString str; |
85 | QFile f( "/proc/net/dev" ); | 85 | QFile f( "/proc/net/dev" ); |
86 | bool hasFile = f.open( IO_ReadOnly ); | 86 | bool hasFile = f.open( IO_ReadOnly ); |
87 | if ( !hasFile ) | 87 | if ( !hasFile ) |
88 | { | 88 | { |
89 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; | 89 | odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; |
90 | return; | 90 | return; |
91 | } | 91 | } |
92 | QTextStream s( &f ); | 92 | QTextStream s( &f ); |
93 | s.readLine(); | 93 | s.readLine(); |
94 | s.readLine(); | 94 | s.readLine(); |
95 | while ( !s.atEnd() ) | 95 | while ( !s.atEnd() ) |
96 | { | 96 | { |
97 | s >> str; | 97 | s >> str; |
98 | str.truncate( str.find( ':' ) ); | 98 | str.truncate( str.find( ':' ) ); |
99 | odebug << "ONetwork: found interface '" << str << "'" << oendl; | 99 | odebug << "ONetwork: found interface '" << str << "'" << oendl; |
100 | ONetworkInterface* iface; | 100 | ONetworkInterface* iface; |
101 | if ( isWirelessInterface( str ) ) | 101 | if ( isWirelessInterface( str ) ) |
102 | { | 102 | { |
103 | iface = new OWirelessNetworkInterface( this, (const char*) str ); | 103 | iface = new OWirelessNetworkInterface( this, (const char*) str ); |
104 | odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; | 104 | odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; |
105 | } | 105 | } |
106 | else | 106 | else |
107 | { | 107 | { |
108 | iface = new ONetworkInterface( this, (const char*) str ); | 108 | iface = new ONetworkInterface( this, (const char*) str ); |
109 | } | 109 | } |
110 | _interfaces.insert( str, iface ); | 110 | _interfaces.insert( str, iface ); |
111 | s.readLine(); | 111 | s.readLine(); |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | 115 | ||
116 | short ONetwork::wirelessExtensionVersion() | 116 | short ONetwork::wirelessExtensionVersion() |
117 | { | 117 | { |
118 | return WIRELESS_EXT; | 118 | return WIRELESS_EXT; |
119 | } | 119 | } |
120 | 120 | ||
121 | 121 | ||
122 | int ONetwork::count() const | 122 | int ONetwork::count() const |
123 | { | 123 | { |
124 | return _interfaces.count(); | 124 | return _interfaces.count(); |
125 | } | 125 | } |
126 | 126 | ||
127 | 127 | ||
128 | ONetworkInterface* ONetwork::interface( const QString& iface ) const | 128 | ONetworkInterface* ONetwork::interface( const QString& iface ) const |
129 | { | 129 | { |
130 | return _interfaces[iface]; | 130 | return _interfaces[iface]; |
131 | } | 131 | } |
132 | 132 | ||
133 | 133 | ||
134 | ONetwork* ONetwork::instance() | 134 | ONetwork* ONetwork::instance() |
135 | { | 135 | { |
136 | if ( !_instance ) _instance = new ONetwork(); | 136 | if ( !_instance ) _instance = new ONetwork(); |
137 | return _instance; | 137 | return _instance; |
138 | } | 138 | } |
139 | 139 | ||
140 | 140 | ||
141 | ONetwork::InterfaceIterator ONetwork::iterator() const | 141 | ONetwork::InterfaceIterator ONetwork::iterator() const |
142 | { | 142 | { |
143 | return ONetwork::InterfaceIterator( _interfaces ); | 143 | return ONetwork::InterfaceIterator( _interfaces ); |
144 | } | 144 | } |
145 | 145 | ||
146 | 146 | ||
147 | bool ONetwork::isPresent( const char* name ) const | ||
148 | { | ||
149 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | ||
150 | struct ifreq ifr; | ||
151 | memset( &ifr, 0, sizeof( struct ifreq ) ); | ||
152 | strcpy( (char*) &ifr.ifr_name, name ); | ||
153 | int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr ); | ||
154 | return result != -1; | ||
155 | } | ||
156 | |||
157 | |||
147 | bool ONetwork::isWirelessInterface( const char* name ) const | 158 | bool ONetwork::isWirelessInterface( const char* name ) const |
148 | { | 159 | { |
149 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); | 160 | int sfd = socket( AF_INET, SOCK_STREAM, 0 ); |
150 | struct iwreq iwr; | 161 | struct iwreq iwr; |
151 | memset( &iwr, 0, sizeof( struct iwreq ) ); | 162 | memset( &iwr, 0, sizeof( struct iwreq ) ); |
152 | strcpy( (char*) &iwr.ifr_name, name ); | 163 | strcpy( (char*) &iwr.ifr_name, name ); |
153 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); | 164 | int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); |
154 | return result != -1; | 165 | return result != -1; |
155 | } | 166 | } |
156 | 167 | ||
157 | /*====================================================================================== | 168 | /*====================================================================================== |
158 | * ONetworkInterface | 169 | * ONetworkInterface |
159 | *======================================================================================*/ | 170 | *======================================================================================*/ |
160 | 171 | ||
161 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) | 172 | ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) |
162 | :QObject( parent, name ), | 173 | :QObject( parent, name ), |
163 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) | 174 | _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) |
164 | { | 175 | { |
165 | odebug << "ONetworkInterface::ONetworkInterface()" << oendl; | 176 | odebug << "ONetworkInterface::ONetworkInterface()" << oendl; |
166 | init(); | 177 | init(); |
167 | } | 178 | } |
168 | 179 | ||
169 | 180 | ||
170 | struct ifreq& ONetworkInterface::ifr() const | 181 | struct ifreq& ONetworkInterface::ifr() const |
171 | { | 182 | { |
172 | return _ifr; | 183 | return _ifr; |
173 | } | 184 | } |
174 | 185 | ||
175 | 186 | ||
176 | void ONetworkInterface::init() | 187 | void ONetworkInterface::init() |
177 | { | 188 | { |
178 | odebug << "ONetworkInterface::init()" << oendl; | 189 | odebug << "ONetworkInterface::init()" << oendl; |
179 | 190 | ||
180 | memset( &_ifr, 0, sizeof( struct ifreq ) ); | 191 | memset( &_ifr, 0, sizeof( struct ifreq ) ); |
181 | 192 | ||
182 | if ( _sfd == -1 ) | 193 | if ( _sfd == -1 ) |
183 | { | 194 | { |
184 | odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; | 195 | odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; |
185 | return; | 196 | return; |
186 | } | 197 | } |
187 | } | 198 | } |
188 | 199 | ||
189 | 200 | ||
190 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const | 201 | bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const |
191 | { | 202 | { |
192 | #ifndef NODEBUG | 203 | #ifndef NODEBUG |
193 | int result = ::ioctl( _sfd, call, &ifreq ); | 204 | int result = ::ioctl( _sfd, call, &ifreq ); |
194 | if ( result == -1 ) | 205 | if ( result == -1 ) |
195 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) | 206 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) |
196 | << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; | 207 | << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; |
197 | else | 208 | else |
198 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) | 209 | odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) |
199 | << "' - Status: Ok." << oendl; | 210 | << "' - Status: Ok." << oendl; |
200 | return ( result != -1 ); | 211 | return ( result != -1 ); |
201 | #else | 212 | #else |
202 | return ::ioctl( _sfd, call, &ifreq ) != -1; | 213 | return ::ioctl( _sfd, call, &ifreq ) != -1; |
203 | #endif | 214 | #endif |
204 | } | 215 | } |
205 | 216 | ||
206 | 217 | ||
207 | bool ONetworkInterface::ioctl( int call ) const | 218 | bool ONetworkInterface::ioctl( int call ) const |
208 | { | 219 | { |
209 | strcpy( _ifr.ifr_name, name() ); | 220 | strcpy( _ifr.ifr_name, name() ); |
210 | return ioctl( call, _ifr ); | 221 | return ioctl( call, _ifr ); |
211 | } | 222 | } |
212 | 223 | ||
213 | 224 | ||
214 | bool ONetworkInterface::isLoopback() const | 225 | bool ONetworkInterface::isLoopback() const |
215 | { | 226 | { |
216 | ioctl( SIOCGIFFLAGS ); | 227 | ioctl( SIOCGIFFLAGS ); |
217 | return _ifr.ifr_flags & IFF_LOOPBACK; | 228 | return _ifr.ifr_flags & IFF_LOOPBACK; |
218 | } | 229 | } |
219 | 230 | ||
220 | 231 | ||
221 | bool ONetworkInterface::setUp( bool b ) | 232 | bool ONetworkInterface::setUp( bool b ) |
222 | { | 233 | { |
223 | ioctl( SIOCGIFFLAGS ); | 234 | ioctl( SIOCGIFFLAGS ); |
224 | if ( b ) _ifr.ifr_flags |= IFF_UP; | 235 | if ( b ) _ifr.ifr_flags |= IFF_UP; |
225 | else _ifr.ifr_flags &= (~IFF_UP); | 236 | else _ifr.ifr_flags &= (~IFF_UP); |
226 | return ioctl( SIOCSIFFLAGS ); | 237 | return ioctl( SIOCSIFFLAGS ); |
227 | } | 238 | } |
228 | 239 | ||
229 | 240 | ||
230 | bool ONetworkInterface::isUp() const | 241 | bool ONetworkInterface::isUp() const |
231 | { | 242 | { |
232 | ioctl( SIOCGIFFLAGS ); | 243 | ioctl( SIOCGIFFLAGS ); |
233 | return _ifr.ifr_flags & IFF_UP; | 244 | return _ifr.ifr_flags & IFF_UP; |
234 | } | 245 | } |
235 | 246 | ||
236 | 247 | ||
237 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) | 248 | void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) |
238 | { | 249 | { |
239 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 250 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
240 | sa->sin_family = AF_INET; | 251 | sa->sin_family = AF_INET; |
241 | sa->sin_port = 0; | 252 | sa->sin_port = 0; |
242 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 253 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
243 | ioctl( SIOCSIFADDR ); | 254 | ioctl( SIOCSIFADDR ); |
244 | } | 255 | } |
245 | 256 | ||
246 | 257 | ||
247 | QString ONetworkInterface::ipV4Address() const | 258 | QString ONetworkInterface::ipV4Address() const |
248 | { | 259 | { |
249 | if ( ioctl( SIOCGIFADDR ) ) | 260 | if ( ioctl( SIOCGIFADDR ) ) |
250 | { | 261 | { |
251 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 262 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
252 | //FIXME: Use QHostAddress here | 263 | //FIXME: Use QHostAddress here |
253 | return QString( inet_ntoa( sa->sin_addr ) ); | 264 | return QString( inet_ntoa( sa->sin_addr ) ); |
254 | } | 265 | } |
255 | else | 266 | else |
256 | return "<unknown>"; | 267 | return "<unknown>"; |
257 | 268 | ||
258 | } | 269 | } |
259 | 270 | ||
260 | 271 | ||
261 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) | 272 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) |
262 | { | 273 | { |
263 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | 274 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
264 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); | 275 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); |
265 | ioctl( SIOCSIFHWADDR ); | 276 | ioctl( SIOCSIFHWADDR ); |
266 | } | 277 | } |
267 | 278 | ||
268 | 279 | ||
269 | OMacAddress ONetworkInterface::macAddress() const | 280 | OMacAddress ONetworkInterface::macAddress() const |
270 | { | 281 | { |
271 | if ( ioctl( SIOCGIFHWADDR ) ) | 282 | if ( ioctl( SIOCGIFHWADDR ) ) |
272 | { | 283 | { |
273 | return OMacAddress( _ifr ); | 284 | return OMacAddress( _ifr ); |
274 | } | 285 | } |
275 | else | 286 | else |
276 | { | 287 | { |
277 | return OMacAddress::unknown; | 288 | return OMacAddress::unknown; |
278 | } | 289 | } |
279 | } | 290 | } |
280 | 291 | ||
281 | 292 | ||
282 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) | 293 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) |
283 | { | 294 | { |
284 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 295 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
285 | sa->sin_family = AF_INET; | 296 | sa->sin_family = AF_INET; |
286 | sa->sin_port = 0; | 297 | sa->sin_port = 0; |
287 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 298 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
288 | ioctl( SIOCSIFNETMASK ); | 299 | ioctl( SIOCSIFNETMASK ); |
289 | } | 300 | } |
290 | 301 | ||
291 | 302 | ||
292 | QString ONetworkInterface::ipV4Netmask() const | 303 | QString ONetworkInterface::ipV4Netmask() const |
293 | { | 304 | { |
294 | if ( ioctl( SIOCGIFNETMASK ) ) | 305 | if ( ioctl( SIOCGIFNETMASK ) ) |
295 | { | 306 | { |
296 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 307 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
297 | //FIXME: Use QHostAddress here | 308 | //FIXME: Use QHostAddress here |
298 | return QString( inet_ntoa( sa->sin_addr ) ); | 309 | return QString( inet_ntoa( sa->sin_addr ) ); |
299 | } | 310 | } |
300 | else | 311 | else |
301 | return "<unknown>"; | 312 | return "<unknown>"; |
302 | } | 313 | } |
303 | 314 | ||
304 | 315 | ||
305 | int ONetworkInterface::dataLinkType() const | 316 | int ONetworkInterface::dataLinkType() const |
306 | { | 317 | { |
307 | if ( ioctl( SIOCGIFHWADDR ) ) | 318 | if ( ioctl( SIOCGIFHWADDR ) ) |
308 | { | 319 | { |
309 | return _ifr.ifr_hwaddr.sa_family; | 320 | return _ifr.ifr_hwaddr.sa_family; |
310 | } | 321 | } |
311 | else | 322 | else |
312 | { | 323 | { |
313 | return -1; | 324 | return -1; |
314 | } | 325 | } |
315 | } | 326 | } |
316 | 327 | ||
317 | 328 | ||
318 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 329 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
319 | { | 330 | { |
320 | _mon = m; | 331 | _mon = m; |
321 | odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl; | 332 | odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl; |
322 | } | 333 | } |
323 | 334 | ||
324 | 335 | ||
325 | OMonitoringInterface* ONetworkInterface::monitoring() const | 336 | OMonitoringInterface* ONetworkInterface::monitoring() const |
326 | { | 337 | { |
327 | return _mon; | 338 | return _mon; |
328 | } | 339 | } |
329 | 340 | ||
330 | 341 | ||
331 | ONetworkInterface::~ONetworkInterface() | 342 | ONetworkInterface::~ONetworkInterface() |
332 | { | 343 | { |
333 | odebug << "ONetworkInterface::~ONetworkInterface()" << oendl; | 344 | odebug << "ONetworkInterface::~ONetworkInterface()" << oendl; |
334 | if ( _sfd != -1 ) ::close( _sfd ); | 345 | if ( _sfd != -1 ) ::close( _sfd ); |
335 | } | 346 | } |
336 | 347 | ||
337 | 348 | ||
338 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 349 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
339 | { | 350 | { |
340 | ioctl( SIOCGIFFLAGS ); | 351 | ioctl( SIOCGIFFLAGS ); |
341 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 352 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
342 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 353 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
343 | return ioctl( SIOCSIFFLAGS ); | 354 | return ioctl( SIOCSIFFLAGS ); |
344 | } | 355 | } |
345 | 356 | ||
346 | 357 | ||
347 | bool ONetworkInterface::promiscuousMode() const | 358 | bool ONetworkInterface::promiscuousMode() const |
348 | { | 359 | { |
349 | ioctl( SIOCGIFFLAGS ); | 360 | ioctl( SIOCGIFFLAGS ); |
350 | return _ifr.ifr_flags & IFF_PROMISC; | 361 | return _ifr.ifr_flags & IFF_PROMISC; |
351 | } | 362 | } |
352 | 363 | ||
353 | 364 | ||
354 | bool ONetworkInterface::isWireless() const | 365 | bool ONetworkInterface::isWireless() const |
355 | { | 366 | { |
356 | return ioctl( SIOCGIWNAME ); | 367 | return ioctl( SIOCGIWNAME ); |
357 | } | 368 | } |
358 | 369 | ||
359 | 370 | ||
360 | /*====================================================================================== | 371 | /*====================================================================================== |
361 | * OChannelHopper | 372 | * OChannelHopper |
362 | *======================================================================================*/ | 373 | *======================================================================================*/ |
363 | 374 | ||
364 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 375 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
365 | :QObject( 0, "Mickey's funky hopper" ), | 376 | :QObject( 0, "Mickey's funky hopper" ), |
366 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 377 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
367 | { | 378 | { |
368 | int _maxChannel = iface->channels()+1; | 379 | int _maxChannel = iface->channels()+1; |
369 | // generate fancy hopping sequence honoring the device capabilities | 380 | // generate fancy hopping sequence honoring the device capabilities |
370 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 381 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
371 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 382 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
372 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 383 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
373 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 384 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
374 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 385 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
375 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 386 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
376 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 387 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
377 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 388 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
378 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 389 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
379 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 390 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
380 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 391 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
381 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 392 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
382 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 393 | if ( _maxChannel >= 6 ) _channels.append( 6 ); |
383 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 394 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
384 | _channel = _channels.begin(); | 395 | _channel = _channels.begin(); |
385 | 396 | ||
386 | } | 397 | } |
387 | 398 | ||
388 | 399 | ||
389 | OChannelHopper::~OChannelHopper() | 400 | OChannelHopper::~OChannelHopper() |
390 | { | 401 | { |
391 | } | 402 | } |
392 | 403 | ||
393 | 404 | ||
394 | bool OChannelHopper::isActive() const | 405 | bool OChannelHopper::isActive() const |
395 | { | 406 | { |
396 | return _tid; | 407 | return _tid; |
397 | } | 408 | } |
398 | 409 | ||
399 | 410 | ||
400 | int OChannelHopper::channel() const | 411 | int OChannelHopper::channel() const |
401 | { | 412 | { |
402 | return *_channel; | 413 | return *_channel; |
403 | } | 414 | } |
404 | 415 | ||
405 | 416 | ||
406 | void OChannelHopper::timerEvent( QTimerEvent* ) | 417 | void OChannelHopper::timerEvent( QTimerEvent* ) |
407 | { | 418 | { |
408 | _iface->setChannel( *_channel ); | 419 | _iface->setChannel( *_channel ); |
409 | emit( hopped( *_channel ) ); | 420 | emit( hopped( *_channel ) ); |
410 | odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl; | 421 | odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl; |
411 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 422 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
412 | } | 423 | } |
413 | 424 | ||
414 | 425 | ||
415 | void OChannelHopper::setInterval( int interval ) | 426 | void OChannelHopper::setInterval( int interval ) |
416 | { | 427 | { |
417 | if ( interval == _interval ) | 428 | if ( interval == _interval ) |
418 | return; | 429 | return; |
419 | 430 | ||
420 | if ( _interval ) | 431 | if ( _interval ) |
421 | killTimer( _tid ); | 432 | killTimer( _tid ); |
422 | 433 | ||
423 | _tid = 0; | 434 | _tid = 0; |
424 | _interval = interval; | 435 | _interval = interval; |
425 | 436 | ||
426 | if ( _interval ) | 437 | if ( _interval ) |
427 | { | 438 | { |
428 | _tid = startTimer( interval ); | 439 | _tid = startTimer( interval ); |
429 | } | 440 | } |
430 | } | 441 | } |
431 | 442 | ||
432 | 443 | ||
433 | int OChannelHopper::interval() const | 444 | int OChannelHopper::interval() const |
434 | { | 445 | { |
435 | return _interval; | 446 | return _interval; |
436 | } | 447 | } |
437 | 448 | ||
438 | 449 | ||
439 | /*====================================================================================== | 450 | /*====================================================================================== |
440 | * OWirelessNetworkInterface | 451 | * OWirelessNetworkInterface |
441 | *======================================================================================*/ | 452 | *======================================================================================*/ |
442 | 453 | ||
443 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 454 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
444 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 455 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
445 | { | 456 | { |
446 | odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl; | 457 | odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl; |
447 | init(); | 458 | init(); |
448 | } | 459 | } |
449 | 460 | ||
450 | 461 | ||
451 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 462 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
452 | { | 463 | { |
453 | } | 464 | } |
454 | 465 | ||
455 | 466 | ||
456 | struct iwreq& OWirelessNetworkInterface::iwr() const | 467 | struct iwreq& OWirelessNetworkInterface::iwr() const |
457 | { | 468 | { |
458 | return _iwr; | 469 | return _iwr; |
459 | } | 470 | } |
460 | 471 | ||
461 | 472 | ||
462 | void OWirelessNetworkInterface::init() | 473 | void OWirelessNetworkInterface::init() |
463 | { | 474 | { |
464 | odebug << "OWirelessNetworkInterface::init()" << oendl; | 475 | odebug << "OWirelessNetworkInterface::init()" << oendl; |
465 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 476 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
466 | buildInformation(); | 477 | buildInformation(); |
467 | buildPrivateList(); | 478 | buildPrivateList(); |
468 | dumpInformation(); | 479 | dumpInformation(); |
469 | } | 480 | } |
470 | 481 | ||
471 | 482 | ||
472 | bool OWirelessNetworkInterface::isAssociated() const | 483 | bool OWirelessNetworkInterface::isAssociated() const |
473 | { | 484 | { |
474 | //FIXME: handle different modes | 485 | //FIXME: handle different modes |
475 | return !(associatedAP() == OMacAddress::unknown); | 486 | return !(associatedAP() == OMacAddress::unknown); |
476 | } | 487 | } |
477 | 488 | ||
478 | 489 | ||
479 | OMacAddress OWirelessNetworkInterface::associatedAP() const | 490 | OMacAddress OWirelessNetworkInterface::associatedAP() const |
480 | { | 491 | { |
481 | if ( ioctl( SIOCGIWAP ) ) | 492 | if ( ioctl( SIOCGIWAP ) ) |
482 | return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; | 493 | return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; |
483 | else | 494 | else |
484 | return OMacAddress::unknown; | 495 | return OMacAddress::unknown; |
485 | } | 496 | } |
486 | 497 | ||
487 | 498 | ||
488 | void OWirelessNetworkInterface::buildInformation() | 499 | void OWirelessNetworkInterface::buildInformation() |
489 | { | 500 | { |
490 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 501 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
491 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | 502 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete |
492 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 503 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
493 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | 504 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate |
494 | //ML: _too much_ space. This is damn shitty crap *sigh* | 505 | //ML: _too much_ space. This is damn shitty crap *sigh* |
495 | //ML: We allocate a large memory region in RAM and check whether the | 506 | //ML: We allocate a large memory region in RAM and check whether the |
496 | //ML: driver pollutes this extra space. The complaint will be made on stdout, | 507 | //ML: driver pollutes this extra space. The complaint will be made on stdout, |
497 | //ML: so please forward this... | 508 | //ML: so please forward this... |
498 | 509 | ||
499 | struct iwreq wrq; | 510 | struct iwreq wrq; |
500 | int len = sizeof( struct iw_range )*2; | 511 | int len = sizeof( struct iw_range )*2; |
501 | char *buffer = (char*) malloc( len ); | 512 | char *buffer = (char*) malloc( len ); |
502 | //FIXME: Validate if we actually got the memory block | 513 | //FIXME: Validate if we actually got the memory block |
503 | memset( buffer, 0, len ); | 514 | memset( buffer, 0, len ); |
504 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | 515 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); |
505 | wrq.u.data.pointer = (caddr_t) buffer; | 516 | wrq.u.data.pointer = (caddr_t) buffer; |
506 | wrq.u.data.length = sizeof( struct iw_range ); | 517 | wrq.u.data.length = sizeof( struct iw_range ); |
507 | wrq.u.data.flags = 0; | 518 | wrq.u.data.flags = 0; |
508 | 519 | ||
509 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 520 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
510 | { | 521 | { |
511 | owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl; | 522 | owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl; |
512 | _channels.insert( 2412, 1 ); // 2.412 GHz | 523 | _channels.insert( 2412, 1 ); // 2.412 GHz |
513 | _channels.insert( 2417, 2 ); // 2.417 GHz | 524 | _channels.insert( 2417, 2 ); // 2.417 GHz |
514 | _channels.insert( 2422, 3 ); // 2.422 GHz | 525 | _channels.insert( 2422, 3 ); // 2.422 GHz |
515 | _channels.insert( 2427, 4 ); // 2.427 GHz | 526 | _channels.insert( 2427, 4 ); // 2.427 GHz |
516 | _channels.insert( 2432, 5 ); // 2.432 GHz | 527 | _channels.insert( 2432, 5 ); // 2.432 GHz |
517 | _channels.insert( 2437, 6 ); // 2.437 GHz | 528 | _channels.insert( 2437, 6 ); // 2.437 GHz |
518 | _channels.insert( 2442, 7 ); // 2.442 GHz | 529 | _channels.insert( 2442, 7 ); // 2.442 GHz |
519 | _channels.insert( 2447, 8 ); // 2.447 GHz | 530 | _channels.insert( 2447, 8 ); // 2.447 GHz |
520 | _channels.insert( 2452, 9 ); // 2.452 GHz | 531 | _channels.insert( 2452, 9 ); // 2.452 GHz |
521 | _channels.insert( 2457, 10 ); // 2.457 GHz | 532 | _channels.insert( 2457, 10 ); // 2.457 GHz |
522 | _channels.insert( 2462, 11 ); // 2.462 GHz | 533 | _channels.insert( 2462, 11 ); // 2.462 GHz |
523 | 534 | ||
524 | memset( &_range, 0, sizeof( struct iw_range ) ); | 535 | memset( &_range, 0, sizeof( struct iw_range ) ); |
525 | } | 536 | } |
526 | else | 537 | else |
527 | { | 538 | { |
528 | // <check if the driver overwrites stuff> | 539 | // <check if the driver overwrites stuff> |
529 | int max = 0; | 540 | int max = 0; |
530 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 541 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
531 | if (buffer[r] != 0) | 542 | if (buffer[r] != 0) |
532 | max = r; | 543 | max = r; |
533 | if (max > 0) | 544 | if (max > 0) |
534 | { | 545 | { |
535 | owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() | 546 | owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() |
536 | << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; | 547 | << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; |
537 | } | 548 | } |
538 | // </check if the driver overwrites stuff> | 549 | // </check if the driver overwrites stuff> |
539 | 550 | ||
540 | struct iw_range range; | 551 | struct iw_range range; |
541 | memcpy( &range, buffer, sizeof range ); | 552 | memcpy( &range, buffer, sizeof range ); |
542 | 553 | ||
543 | odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; | 554 | odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; |
544 | for ( int i = 0; i < range.num_frequency; ++i ) | 555 | for ( int i = 0; i < range.num_frequency; ++i ) |
545 | { | 556 | { |
546 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 557 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
547 | _channels.insert( freq, i+1 ); | 558 | _channels.insert( freq, i+1 ); |
548 | } | 559 | } |
549 | } | 560 | } |
550 | 561 | ||
551 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); | 562 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); |
552 | odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; | 563 | odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; |
553 | free(buffer); | 564 | free(buffer); |
554 | } | 565 | } |
555 | 566 | ||
556 | 567 | ||
557 | void OWirelessNetworkInterface::buildPrivateList() | 568 | void OWirelessNetworkInterface::buildPrivateList() |
558 | { | 569 | { |
559 | odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; | 570 | odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; |
560 | 571 | ||
561 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 572 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
562 | 573 | ||
563 | _iwr.u.data.pointer = (char*) &priv; | 574 | _iwr.u.data.pointer = (char*) &priv; |
564 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | 575 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself |
565 | _iwr.u.data.flags = 0; | 576 | _iwr.u.data.flags = 0; |
566 | 577 | ||
567 | if ( !wioctl( SIOCGIWPRIV ) ) | 578 | if ( !wioctl( SIOCGIWPRIV ) ) |
568 | { | 579 | { |
569 | owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; | 580 | owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; |
570 | return; | 581 | return; |
571 | } | 582 | } |
572 | 583 | ||
573 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 584 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
574 | { | 585 | { |
575 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 586 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
576 | } | 587 | } |
577 | odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; | 588 | odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; |
578 | } | 589 | } |
579 | 590 | ||
580 | 591 | ||
581 | void OWirelessNetworkInterface::dumpInformation() const | 592 | void OWirelessNetworkInterface::dumpInformation() const |
582 | { | 593 | { |
583 | odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; | 594 | odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; |
584 | 595 | ||
585 | qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", | 596 | qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", |
586 | _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ); | 597 | _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ); |
587 | qDebug( " - driver for '%s' (V%d) has been compiled against WE V%d", | 598 | qDebug( " - driver for '%s' (V%d) has been compiled against WE V%d", |
588 | name(), _range.we_version_source, _range.we_version_compiled ); | 599 | name(), _range.we_version_source, _range.we_version_compiled ); |
589 | 600 | ||
590 | if ( _range.we_version_compiled != WIRELESS_EXT ) | 601 | if ( _range.we_version_compiled != WIRELESS_EXT ) |
591 | { | 602 | { |
592 | owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; | 603 | owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; |
593 | } | 604 | } |
594 | 605 | ||
595 | odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; | 606 | odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; |
596 | } | 607 | } |
597 | 608 | ||
598 | 609 | ||
599 | int OWirelessNetworkInterface::channel() const | 610 | int OWirelessNetworkInterface::channel() const |
600 | { | 611 | { |
601 | //FIXME: When monitoring enabled, then use it | 612 | //FIXME: When monitoring enabled, then use it |
602 | //FIXME: to gather the current RF channel | 613 | //FIXME: to gather the current RF channel |
603 | //FIXME: Until then, get active channel from hopper. | 614 | //FIXME: Until then, get active channel from hopper. |
604 | if ( _hopper && _hopper->isActive() ) | 615 | if ( _hopper && _hopper->isActive() ) |
605 | return _hopper->channel(); | 616 | return _hopper->channel(); |
606 | 617 | ||
607 | if ( !wioctl( SIOCGIWFREQ ) ) | 618 | if ( !wioctl( SIOCGIWFREQ ) ) |
608 | { | 619 | { |
609 | return -1; | 620 | return -1; |
610 | } | 621 | } |
611 | else | 622 | else |
612 | { | 623 | { |
613 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; | 624 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; |
614 | } | 625 | } |
615 | } | 626 | } |
616 | 627 | ||
617 | 628 | ||
618 | void OWirelessNetworkInterface::setChannel( int c ) const | 629 | void OWirelessNetworkInterface::setChannel( int c ) const |
619 | { | 630 | { |
620 | if ( !c ) | 631 | if ( !c ) |
621 | { | 632 | { |
622 | oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl; | 633 | oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl; |
623 | return; | 634 | return; |
624 | } | 635 | } |
625 | 636 | ||
626 | if ( !_mon ) | 637 | if ( !_mon ) |
627 | { | 638 | { |
628 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 639 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
629 | _iwr.u.freq.m = c; | 640 | _iwr.u.freq.m = c; |
630 | _iwr.u.freq.e = 0; | 641 | _iwr.u.freq.e = 0; |
631 | wioctl( SIOCSIWFREQ ); | 642 | wioctl( SIOCSIWFREQ ); |
632 | } | 643 | } |
633 | else | 644 | else |
634 | { | 645 | { |
635 | _mon->setChannel( c ); | 646 | _mon->setChannel( c ); |
636 | } | 647 | } |
637 | } | 648 | } |
638 | 649 | ||
639 | 650 | ||
640 | double OWirelessNetworkInterface::frequency() const | 651 | double OWirelessNetworkInterface::frequency() const |
641 | { | 652 | { |
642 | if ( !wioctl( SIOCGIWFREQ ) ) | 653 | if ( !wioctl( SIOCGIWFREQ ) ) |
643 | { | 654 | { |
644 | return -1.0; | 655 | return -1.0; |
645 | } | 656 | } |
646 | else | 657 | else |
647 | { | 658 | { |
648 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 659 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
649 | } | 660 | } |
650 | } | 661 | } |
651 | 662 | ||
652 | 663 | ||
653 | int OWirelessNetworkInterface::channels() const | 664 | int OWirelessNetworkInterface::channels() const |
654 | { | 665 | { |
655 | return _channels.count(); | 666 | return _channels.count(); |
656 | } | 667 | } |
657 | 668 | ||
658 | 669 | ||
659 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 670 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
660 | { | 671 | { |
661 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 672 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
662 | _hopper->setInterval( interval ); | 673 | _hopper->setInterval( interval ); |
663 | //FIXME: When and by whom will the channel hopper be deleted? | 674 | //FIXME: When and by whom will the channel hopper be deleted? |
664 | //TODO: rely on QObject hierarchy | 675 | //TODO: rely on QObject hierarchy |
665 | } | 676 | } |
666 | 677 | ||
667 | 678 | ||
668 | int OWirelessNetworkInterface::channelHopping() const | 679 | int OWirelessNetworkInterface::channelHopping() const |
669 | { | 680 | { |
670 | return _hopper->interval(); | 681 | return _hopper->interval(); |
671 | } | 682 | } |
672 | 683 | ||
673 | 684 | ||
674 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const | 685 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const |
675 | { | 686 | { |
676 | return _hopper; | 687 | return _hopper; |
677 | } | 688 | } |
678 | 689 | ||
679 | 690 | ||
680 | void OWirelessNetworkInterface::commit() const | 691 | void OWirelessNetworkInterface::commit() const |
681 | { | 692 | { |
682 | wioctl( SIOCSIWCOMMIT ); | 693 | wioctl( SIOCSIWCOMMIT ); |
683 | } | 694 | } |
684 | 695 | ||
685 | 696 | ||
686 | void OWirelessNetworkInterface::setMode( const QString& newMode ) | 697 | void OWirelessNetworkInterface::setMode( const QString& newMode ) |
687 | { | 698 | { |
688 | #ifdef FINALIZE | 699 | #ifdef FINALIZE |
689 | QString currentMode = mode(); | 700 | QString currentMode = mode(); |
690 | if ( currentMode == newMode ) return; | 701 | if ( currentMode == newMode ) return; |
691 | #endif | 702 | #endif |
692 | 703 | ||
693 | odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl; | 704 | odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl; |
694 | 705 | ||
695 | _iwr.u.mode = stringToMode( newMode ); | 706 | _iwr.u.mode = stringToMode( newMode ); |
696 | 707 | ||
697 | if ( _iwr.u.mode != IW_MODE_MONITOR ) | 708 | if ( _iwr.u.mode != IW_MODE_MONITOR ) |
698 | { | 709 | { |
699 | // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! | 710 | // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! |
700 | _iwr.u.mode = stringToMode( newMode ); | 711 | _iwr.u.mode = stringToMode( newMode ); |
701 | wioctl( SIOCSIWMODE ); | 712 | wioctl( SIOCSIWMODE ); |
702 | 713 | ||
703 | // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) | 714 | // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) |
704 | 715 | ||
705 | if ( mode() == "monitor" ) | 716 | if ( mode() == "monitor" ) |
706 | { | 717 | { |
707 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl; | 718 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl; |
708 | if ( _mon ) | 719 | if ( _mon ) |
709 | _mon->setEnabled( false ); | 720 | _mon->setEnabled( false ); |
710 | else | 721 | else |
711 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; | 722 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; |
712 | } | 723 | } |
713 | 724 | ||
714 | } | 725 | } |
715 | else // special iwpriv fallback for monitor mode | 726 | else // special iwpriv fallback for monitor mode |
716 | { | 727 | { |
717 | if ( wioctl( SIOCSIWMODE ) ) | 728 | if ( wioctl( SIOCSIWMODE ) ) |
718 | { | 729 | { |
719 | odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl; | 730 | odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl; |
720 | } | 731 | } |
721 | else | 732 | else |
722 | { | 733 | { |
723 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl; | 734 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl; |
724 | 735 | ||
725 | if ( _mon ) | 736 | if ( _mon ) |
726 | _mon->setEnabled( true ); | 737 | _mon->setEnabled( true ); |
727 | else | 738 | else |
728 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; | 739 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; |
729 | } | 740 | } |
730 | } | 741 | } |
731 | } | 742 | } |
732 | 743 | ||
733 | 744 | ||
734 | QString OWirelessNetworkInterface::mode() const | 745 | QString OWirelessNetworkInterface::mode() const |
735 | { | 746 | { |
736 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 747 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
737 | 748 | ||
738 | if ( !wioctl( SIOCGIWMODE ) ) | 749 | if ( !wioctl( SIOCGIWMODE ) ) |
739 | { | 750 | { |
740 | return "<unknown>"; | 751 | return "<unknown>"; |
741 | } | 752 | } |
742 | 753 | ||
743 | odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl; | 754 | odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl; |
744 | 755 | ||
745 | // legacy compatible monitor mode check | 756 | // legacy compatible monitor mode check |
746 | 757 | ||
747 | if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) | 758 | if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) |
748 | { | 759 | { |
749 | return "monitor"; | 760 | return "monitor"; |
750 | } | 761 | } |
751 | else | 762 | else |
752 | { | 763 | { |
753 | return modeToString( _iwr.u.mode ); | 764 | return modeToString( _iwr.u.mode ); |
754 | } | 765 | } |
755 | } | 766 | } |
756 | 767 | ||
757 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) | 768 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) |
758 | { | 769 | { |
759 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); | 770 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); |
760 | _iwr.u.essid.length = nickname.length(); | 771 | _iwr.u.essid.length = nickname.length(); |
761 | wioctl( SIOCSIWNICKN ); | 772 | wioctl( SIOCSIWNICKN ); |
762 | } | 773 | } |
763 | 774 | ||
764 | 775 | ||
765 | QString OWirelessNetworkInterface::nickName() const | 776 | QString OWirelessNetworkInterface::nickName() const |
766 | { | 777 | { |
767 | char str[IW_ESSID_MAX_SIZE]; | 778 | char str[IW_ESSID_MAX_SIZE]; |
768 | _iwr.u.data.pointer = &str[0]; | 779 | _iwr.u.data.pointer = &str[0]; |
769 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 780 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
770 | if ( !wioctl( SIOCGIWNICKN ) ) | 781 | if ( !wioctl( SIOCGIWNICKN ) ) |
771 | { | 782 | { |
772 | return "<unknown>"; | 783 | return "<unknown>"; |
773 | } | 784 | } |
774 | else | 785 | else |
775 | { | 786 | { |
776 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string | 787 | str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string |
777 | return str; | 788 | return str; |
778 | } | 789 | } |
779 | } | 790 | } |
780 | 791 | ||
781 | 792 | ||
782 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 793 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
783 | { | 794 | { |
784 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 795 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
785 | if ( !priv ) | 796 | if ( !priv ) |
786 | { | 797 | { |
787 | owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name() | 798 | owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name() |
788 | << "' does not support private ioctl '" << call << "'" << oendl; | 799 | << "' does not support private ioctl '" << call << "'" << oendl; |
789 | return; | 800 | return; |
790 | } | 801 | } |
791 | if ( priv->numberSetArgs() != numargs ) | 802 | if ( priv->numberSetArgs() != numargs ) |
792 | { | 803 | { |
793 | owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '" | 804 | owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '" |
794 | << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl; | 805 | << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl; |
795 | return; | 806 | return; |
796 | } | 807 | } |
797 | 808 | ||
798 | odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl; | 809 | odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl; |
799 | memset( &_iwr, 0, sizeof _iwr ); | 810 | memset( &_iwr, 0, sizeof _iwr ); |
800 | va_list argp; | 811 | va_list argp; |
801 | va_start( argp, numargs ); | 812 | va_start( argp, numargs ); |
802 | for ( int i = 0; i < numargs; ++i ) | 813 | for ( int i = 0; i < numargs; ++i ) |
803 | { | 814 | { |
804 | priv->setParameter( i, va_arg( argp, int ) ); | 815 | priv->setParameter( i, va_arg( argp, int ) ); |
805 | } | 816 | } |
806 | va_end( argp ); | 817 | va_end( argp ); |
807 | priv->invoke(); | 818 | priv->invoke(); |
808 | } | 819 | } |
809 | 820 | ||
810 | 821 | ||
811 | void OWirelessNetworkInterface::getPrivate( const QString& call ) | 822 | void OWirelessNetworkInterface::getPrivate( const QString& call ) |
812 | { | 823 | { |
813 | oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl; | 824 | oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl; |
814 | } | 825 | } |
815 | 826 | ||
816 | 827 | ||
817 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | 828 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) |
818 | { | 829 | { |
819 | return child( (const char*) call ); | 830 | return child( (const char*) call ); |
820 | } | 831 | } |
821 | 832 | ||
822 | 833 | ||
823 | QString OWirelessNetworkInterface::SSID() const | 834 | QString OWirelessNetworkInterface::SSID() const |
824 | { | 835 | { |
825 | char str[IW_ESSID_MAX_SIZE]; | 836 | char str[IW_ESSID_MAX_SIZE]; |
826 | _iwr.u.essid.pointer = &str[0]; | 837 | _iwr.u.essid.pointer = &str[0]; |
827 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 838 | _iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
828 | if ( !wioctl( SIOCGIWESSID ) ) | 839 | if ( !wioctl( SIOCGIWESSID ) ) |
829 | { | 840 | { |
830 | return "<unknown>"; | 841 | return "<unknown>"; |
831 | } | 842 | } |
832 | else | 843 | else |
833 | { | 844 | { |
834 | return str; | 845 | return str; |
835 | } | 846 | } |
836 | } | 847 | } |
837 | 848 | ||
838 | 849 | ||
839 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) | 850 | void OWirelessNetworkInterface::setSSID( const QString& ssid ) |
840 | { | 851 | { |
841 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 852 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
842 | _iwr.u.essid.length = ssid.length(); | 853 | _iwr.u.essid.length = ssid.length(); |
843 | wioctl( SIOCSIWESSID ); | 854 | wioctl( SIOCSIWESSID ); |
844 | } | 855 | } |
845 | 856 | ||
846 | 857 | ||
847 | OStationList* OWirelessNetworkInterface::scanNetwork() | 858 | OStationList* OWirelessNetworkInterface::scanNetwork() |
848 | { | 859 | { |
849 | _iwr.u.param.flags = IW_SCAN_DEFAULT; | 860 | _iwr.u.param.flags = IW_SCAN_DEFAULT; |
850 | _iwr.u.param.value = 0; | 861 | _iwr.u.param.value = 0; |
851 | if ( !wioctl( SIOCSIWSCAN ) ) | 862 | if ( !wioctl( SIOCSIWSCAN ) ) |
852 | { | 863 | { |
853 | return 0; | 864 | return 0; |
854 | } | 865 | } |
855 | 866 | ||
856 | OStationList* stations = new OStationList(); | 867 | OStationList* stations = new OStationList(); |
857 | 868 | ||
858 | int timeout = 1000000; | 869 | int timeout = 1000000; |
859 | 870 | ||
860 | odebug << "ONetworkInterface::scanNetwork() - scan started." << oendl; | 871 | odebug << "ONetworkInterface::scanNetwork() - scan started." << oendl; |
861 | 872 | ||
862 | bool results = false; | 873 | bool results = false; |
863 | struct timeval tv; | 874 | struct timeval tv; |
864 | tv.tv_sec = 0; | 875 | tv.tv_sec = 0; |
865 | tv.tv_usec = 250000; // initial timeout ~ 250ms | 876 | tv.tv_usec = 250000; // initial timeout ~ 250ms |
866 | char buffer[IW_SCAN_MAX_DATA]; | 877 | char buffer[IW_SCAN_MAX_DATA]; |
867 | 878 | ||
868 | while ( !results && timeout > 0 ) | 879 | while ( !results && timeout > 0 ) |
869 | { | 880 | { |
870 | timeout -= tv.tv_usec; | 881 | timeout -= tv.tv_usec; |
871 | select( 0, 0, 0, 0, &tv ); | 882 | select( 0, 0, 0, 0, &tv ); |
872 | 883 | ||
873 | _iwr.u.data.pointer = &buffer[0]; | 884 | _iwr.u.data.pointer = &buffer[0]; |
874 | _iwr.u.data.flags = 0; | 885 | _iwr.u.data.flags = 0; |
875 | _iwr.u.data.length = sizeof buffer; | 886 | _iwr.u.data.length = sizeof buffer; |
876 | if ( wioctl( SIOCGIWSCAN ) ) | 887 | if ( wioctl( SIOCGIWSCAN ) ) |
877 | { | 888 | { |
878 | results = true; | 889 | results = true; |
879 | continue; | 890 | continue; |
880 | } | 891 | } |
881 | else if ( errno == EAGAIN) | 892 | else if ( errno == EAGAIN) |
882 | { | 893 | { |
883 | odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl; | 894 | odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl; |
884 | #if 0 | 895 | #if 0 |
885 | if ( qApp ) | 896 | if ( qApp ) |
886 | { | 897 | { |
887 | qApp->processEvents( 100 ); | 898 | qApp->processEvents( 100 ); |
888 | continue; | 899 | continue; |
889 | } | 900 | } |
890 | #endif | 901 | #endif |
891 | tv.tv_sec = 0; | 902 | tv.tv_sec = 0; |
892 | tv.tv_usec = 100000; | 903 | tv.tv_usec = 100000; |
893 | continue; | 904 | continue; |
894 | } | 905 | } |
895 | } | 906 | } |
896 | 907 | ||
897 | odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; | 908 | odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; |
898 | 909 | ||
899 | if ( results ) | 910 | if ( results ) |
900 | { | 911 | { |
901 | odebug << " - result length = " << _iwr.u.data.length << oendl; | 912 | odebug << " - result length = " << _iwr.u.data.length << oendl; |
902 | if ( !_iwr.u.data.length ) | 913 | if ( !_iwr.u.data.length ) |
903 | { | 914 | { |
904 | odebug << " - no results (empty neighbourhood)" << oendl; | 915 | odebug << " - no results (empty neighbourhood)" << oendl; |
905 | return stations; | 916 | return stations; |
906 | } | 917 | } |
907 | 918 | ||
908 | odebug << " - results are in!" << oendl; | 919 | odebug << " - results are in!" << oendl; |
909 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); | 920 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); |
910 | 921 | ||
911 | // parse results | 922 | // parse results |
912 | 923 | ||
913 | int offset = 0; | 924 | int offset = 0; |
914 | struct iw_event* we = (struct iw_event*) &buffer[0]; | 925 | struct iw_event* we = (struct iw_event*) &buffer[0]; |
915 | 926 | ||
916 | while ( offset < _iwr.u.data.length ) | 927 | while ( offset < _iwr.u.data.length ) |
917 | { | 928 | { |
918 | //const char* cmd = *(*_ioctlmap)[we->cmd]; | 929 | //const char* cmd = *(*_ioctlmap)[we->cmd]; |
919 | //if ( !cmd ) cmd = "<unknown>"; | 930 | //if ( !cmd ) cmd = "<unknown>"; |
920 | odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl; | 931 | odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl; |
921 | switch (we->cmd) | 932 | switch (we->cmd) |
922 | { | 933 | { |
923 | case SIOCGIWAP: | 934 | case SIOCGIWAP: |
924 | { | 935 | { |
925 | odebug << "SIOCGIWAP" << oendl; | 936 | odebug << "SIOCGIWAP" << oendl; |
926 | stations->append( new OStation() ); | 937 | stations->append( new OStation() ); |
927 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; | 938 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; |
928 | break; | 939 | break; |
929 | } | 940 | } |
930 | case SIOCGIWMODE: | 941 | case SIOCGIWMODE: |
931 | { | 942 | { |
932 | odebug << "SIOCGIWMODE" << oendl; | 943 | odebug << "SIOCGIWMODE" << oendl; |
933 | stations->last()->type = modeToString( we->u.mode ); | 944 | stations->last()->type = modeToString( we->u.mode ); |
934 | break; | 945 | break; |
935 | } | 946 | } |
936 | case SIOCGIWFREQ: | 947 | case SIOCGIWFREQ: |
937 | { | 948 | { |
938 | odebug << "SIOCGIWFREQ" << oendl; | 949 | odebug << "SIOCGIWFREQ" << oendl; |
939 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; | 950 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; |
940 | break; | 951 | break; |
941 | } | 952 | } |
942 | case SIOCGIWESSID: | 953 | case SIOCGIWESSID: |
943 | { | 954 | { |
944 | odebug << "SIOCGIWESSID" << oendl; | 955 | odebug << "SIOCGIWESSID" << oendl; |
945 | stations->last()->ssid = we->u.essid.pointer; | 956 | stations->last()->ssid = we->u.essid.pointer; |
946 | break; | 957 | break; |
947 | } | 958 | } |
948 | case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; | 959 | case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; |
949 | case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break; | 960 | case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break; |
950 | case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ | 961 | case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ |
951 | case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */ | 962 | case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */ |
952 | case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ | 963 | case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ |
953 | case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ | 964 | case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ |
954 | case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ | 965 | case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ |
955 | default: odebug << "unhandled event" << oendl; | 966 | default: odebug << "unhandled event" << oendl; |
956 | } | 967 | } |
957 | 968 | ||
958 | offset += we->len; | 969 | offset += we->len; |
959 | we = (struct iw_event*) &buffer[offset]; | 970 | we = (struct iw_event*) &buffer[offset]; |
960 | } | 971 | } |
961 | return stations; | 972 | return stations; |
962 | 973 | ||
963 | return stations; | 974 | return stations; |
964 | 975 | ||
965 | } | 976 | } |
966 | else | 977 | else |
967 | { | 978 | { |
968 | odebug << " - no results (timeout) :(" << oendl; | 979 | odebug << " - no results (timeout) :(" << oendl; |
969 | return stations; | 980 | return stations; |
970 | } | 981 | } |
971 | } | 982 | } |
972 | 983 | ||
973 | 984 | ||
974 | int OWirelessNetworkInterface::signalStrength() const | 985 | int OWirelessNetworkInterface::signalStrength() const |
975 | { | 986 | { |
976 | iw_statistics stat; | 987 | iw_statistics stat; |
977 | ::memset( &stat, 0, sizeof stat ); | 988 | ::memset( &stat, 0, sizeof stat ); |
978 | _iwr.u.data.pointer = (char*) &stat; | 989 | _iwr.u.data.pointer = (char*) &stat; |
979 | _iwr.u.data.flags = 0; | 990 | _iwr.u.data.flags = 0; |
980 | _iwr.u.data.length = sizeof stat; | 991 | _iwr.u.data.length = sizeof stat; |
981 | 992 | ||
982 | if ( !wioctl( SIOCGIWSTATS ) ) | 993 | if ( !wioctl( SIOCGIWSTATS ) ) |
983 | { | 994 | { |
984 | return -1; | 995 | return -1; |
985 | } | 996 | } |
986 | 997 | ||
987 | int max = _range.max_qual.qual; | 998 | int max = _range.max_qual.qual; |
988 | int cur = stat.qual.qual; | 999 | int cur = stat.qual.qual; |
989 | int lev = stat.qual.level; //FIXME: Do something with them? | 1000 | int lev = stat.qual.level; //FIXME: Do something with them? |
990 | int noi = stat.qual.noise; //FIXME: Do something with them? | 1001 | int noi = stat.qual.noise; //FIXME: Do something with them? |
991 | 1002 | ||
992 | return cur*100/max; | 1003 | return cur*100/max; |
993 | } | 1004 | } |
994 | 1005 | ||
995 | 1006 | ||
996 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 1007 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
997 | { | 1008 | { |
998 | #ifndef NODEBUG | 1009 | #ifndef NODEBUG |
999 | int result = ::ioctl( _sfd, call, &iwreq ); | 1010 | int result = ::ioctl( _sfd, call, &iwreq ); |
1000 | 1011 | ||
1001 | if ( result == -1 ) | 1012 | if ( result == -1 ) |
1002 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1013 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1003 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; | 1014 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; |
1004 | else | 1015 | else |
1005 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1016 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1006 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; | 1017 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; |
1007 | 1018 | ||
1008 | return ( result != -1 ); | 1019 | return ( result != -1 ); |
1009 | #else | 1020 | #else |
1010 | return ::ioctl( _sfd, call, &iwreq ) != -1; | 1021 | return ::ioctl( _sfd, call, &iwreq ) != -1; |
1011 | #endif | 1022 | #endif |
1012 | } | 1023 | } |
1013 | 1024 | ||
1014 | 1025 | ||
1015 | bool OWirelessNetworkInterface::wioctl( int call ) const | 1026 | bool OWirelessNetworkInterface::wioctl( int call ) const |
1016 | { | 1027 | { |
1017 | strcpy( _iwr.ifr_name, name() ); | 1028 | strcpy( _iwr.ifr_name, name() ); |
1018 | return wioctl( call, _iwr ); | 1029 | return wioctl( call, _iwr ); |
1019 | } | 1030 | } |
1020 | 1031 | ||
1021 | 1032 | ||
1022 | /*====================================================================================== | 1033 | /*====================================================================================== |
1023 | * OMonitoringInterface | 1034 | * OMonitoringInterface |
1024 | *======================================================================================*/ | 1035 | *======================================================================================*/ |
1025 | 1036 | ||
1026 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1037 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1027 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) | 1038 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) |
1028 | { | 1039 | { |
1029 | } | 1040 | } |
1030 | 1041 | ||
1031 | 1042 | ||
1032 | OMonitoringInterface::~OMonitoringInterface() | 1043 | OMonitoringInterface::~OMonitoringInterface() |
1033 | { | 1044 | { |
1034 | } | 1045 | } |
1035 | 1046 | ||
1036 | 1047 | ||
1037 | void OMonitoringInterface::setChannel( int c ) | 1048 | void OMonitoringInterface::setChannel( int c ) |
1038 | { | 1049 | { |
1039 | // use standard WE channel switching protocol | 1050 | // use standard WE channel switching protocol |
1040 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 1051 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
1041 | _if->_iwr.u.freq.m = c; | 1052 | _if->_iwr.u.freq.m = c; |
1042 | _if->_iwr.u.freq.e = 0; | 1053 | _if->_iwr.u.freq.e = 0; |
1043 | _if->wioctl( SIOCSIWFREQ ); | 1054 | _if->wioctl( SIOCSIWFREQ ); |
1044 | } | 1055 | } |
1045 | 1056 | ||
1046 | 1057 | ||
1047 | void OMonitoringInterface::setEnabled( bool b ) | 1058 | void OMonitoringInterface::setEnabled( bool b ) |
1048 | { | 1059 | { |
1049 | } | 1060 | } |
1050 | 1061 | ||
1051 | 1062 | ||
1052 | /*====================================================================================== | 1063 | /*====================================================================================== |
1053 | * OCiscoMonitoringInterface | 1064 | * OCiscoMonitoringInterface |
1054 | *======================================================================================*/ | 1065 | *======================================================================================*/ |
1055 | 1066 | ||
1056 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1067 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1057 | :OMonitoringInterface( iface, prismHeader ) | 1068 | :OMonitoringInterface( iface, prismHeader ) |
1058 | { | 1069 | { |
1059 | iface->setMonitoring( this ); | 1070 | iface->setMonitoring( this ); |
1060 | } | 1071 | } |
1061 | 1072 | ||
1062 | 1073 | ||
1063 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 1074 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
1064 | { | 1075 | { |
1065 | } | 1076 | } |
1066 | 1077 | ||
1067 | 1078 | ||
1068 | void OCiscoMonitoringInterface::setEnabled( bool b ) | 1079 | void OCiscoMonitoringInterface::setEnabled( bool b ) |
1069 | { | 1080 | { |
1070 | QString fname; | 1081 | QString fname; |
1071 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 1082 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
1072 | QFile f( fname ); | 1083 | QFile f( fname ); |
1073 | if ( !f.exists() ) return; | 1084 | if ( !f.exists() ) return; |
1074 | 1085 | ||
1075 | if ( f.open( IO_WriteOnly ) ) | 1086 | if ( f.open( IO_WriteOnly ) ) |
1076 | { | 1087 | { |
1077 | QTextStream s( &f ); | 1088 | QTextStream s( &f ); |
1078 | s << "Mode: r"; | 1089 | s << "Mode: r"; |
1079 | s << "Mode: y"; | 1090 | s << "Mode: y"; |
1080 | s << "XmitPower: 1"; | 1091 | s << "XmitPower: 1"; |
1081 | } | 1092 | } |
1082 | 1093 | ||
1083 | // flushing and closing will be done automatically when f goes out of scope | 1094 | // flushing and closing will be done automatically when f goes out of scope |
1084 | } | 1095 | } |
1085 | 1096 | ||
1086 | 1097 | ||
1087 | QString OCiscoMonitoringInterface::name() const | 1098 | QString OCiscoMonitoringInterface::name() const |
1088 | { | 1099 | { |
1089 | return "cisco"; | 1100 | return "cisco"; |
1090 | } | 1101 | } |
1091 | 1102 | ||
1092 | 1103 | ||
1093 | void OCiscoMonitoringInterface::setChannel( int ) | 1104 | void OCiscoMonitoringInterface::setChannel( int ) |
1094 | { | 1105 | { |
1095 | // cisco devices automatically switch channels when in monitor mode | 1106 | // cisco devices automatically switch channels when in monitor mode |
1096 | } | 1107 | } |
1097 | 1108 | ||
1098 | 1109 | ||
1099 | /*====================================================================================== | 1110 | /*====================================================================================== |
1100 | * OWlanNGMonitoringInterface | 1111 | * OWlanNGMonitoringInterface |
1101 | *======================================================================================*/ | 1112 | *======================================================================================*/ |
1102 | 1113 | ||
1103 | 1114 | ||
1104 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1115 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1105 | :OMonitoringInterface( iface, prismHeader ) | 1116 | :OMonitoringInterface( iface, prismHeader ) |
1106 | { | 1117 | { |
1107 | iface->setMonitoring( this ); | 1118 | iface->setMonitoring( this ); |
1108 | } | 1119 | } |
1109 | 1120 | ||
1110 | 1121 | ||
1111 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 1122 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
1112 | { | 1123 | { |
1113 | } | 1124 | } |
1114 | 1125 | ||
1115 | 1126 | ||
1116 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 1127 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
1117 | { | 1128 | { |
1118 | //FIXME: do nothing if its already in the same mode | 1129 | //FIXME: do nothing if its already in the same mode |
1119 | 1130 | ||
1120 | QString enable = b ? "true" : "false"; | 1131 | QString enable = b ? "true" : "false"; |
1121 | QString prism = _prismHeader ? "true" : "false"; | 1132 | QString prism = _prismHeader ? "true" : "false"; |
1122 | QString cmd; | 1133 | QString cmd; |
1123 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 1134 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
1124 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); | 1135 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); |
1125 | system( cmd ); | 1136 | system( cmd ); |
1126 | } | 1137 | } |
1127 | 1138 | ||
1128 | 1139 | ||
1129 | QString OWlanNGMonitoringInterface::name() const | 1140 | QString OWlanNGMonitoringInterface::name() const |
1130 | { | 1141 | { |
1131 | return "wlan-ng"; | 1142 | return "wlan-ng"; |
1132 | } | 1143 | } |
1133 | 1144 | ||
1134 | 1145 | ||
1135 | void OWlanNGMonitoringInterface::setChannel( int c ) | 1146 | void OWlanNGMonitoringInterface::setChannel( int c ) |
1136 | { | 1147 | { |
1137 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. | 1148 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. |
1138 | 1149 | ||
1139 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; | 1150 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; |
1140 | QString prism = _prismHeader ? "true" : "false"; | 1151 | QString prism = _prismHeader ? "true" : "false"; |
1141 | QString cmd; | 1152 | QString cmd; |
1142 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 1153 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
1143 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); | 1154 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); |
1144 | system( cmd ); | 1155 | system( cmd ); |
1145 | } | 1156 | } |
1146 | 1157 | ||
1147 | 1158 | ||
1148 | /*====================================================================================== | 1159 | /*====================================================================================== |
1149 | * OHostAPMonitoringInterface | 1160 | * OHostAPMonitoringInterface |
1150 | *======================================================================================*/ | 1161 | *======================================================================================*/ |
1151 | 1162 | ||
1152 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1163 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1153 | :OMonitoringInterface( iface, prismHeader ) | 1164 | :OMonitoringInterface( iface, prismHeader ) |
1154 | { | 1165 | { |
1155 | iface->setMonitoring( this ); | 1166 | iface->setMonitoring( this ); |
1156 | } | 1167 | } |
1157 | 1168 | ||
1158 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 1169 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
1159 | { | 1170 | { |
1160 | } | 1171 | } |
1161 | 1172 | ||
1162 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 1173 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
1163 | { | 1174 | { |
1164 | int monitorCode = _prismHeader ? 1 : 2; | 1175 | int monitorCode = _prismHeader ? 1 : 2; |
1165 | if ( b ) | 1176 | if ( b ) |
1166 | { | 1177 | { |
1167 | _if->setPrivate( "monitor", 1, monitorCode ); | 1178 | _if->setPrivate( "monitor", 1, monitorCode ); |
1168 | } | 1179 | } |
1169 | else | 1180 | else |
1170 | { | 1181 | { |
1171 | _if->setPrivate( "monitor", 1, 0 ); | 1182 | _if->setPrivate( "monitor", 1, 0 ); |
1172 | } | 1183 | } |
1173 | } | 1184 | } |
1174 | 1185 | ||
1175 | 1186 | ||
1176 | QString OHostAPMonitoringInterface::name() const | 1187 | QString OHostAPMonitoringInterface::name() const |
1177 | { | 1188 | { |
1178 | return "hostap"; | 1189 | return "hostap"; |
1179 | } | 1190 | } |
1180 | 1191 | ||
1181 | 1192 | ||
1182 | /*====================================================================================== | 1193 | /*====================================================================================== |
1183 | * OOrinocoNetworkInterface | 1194 | * OOrinocoNetworkInterface |
1184 | *======================================================================================*/ | 1195 | *======================================================================================*/ |
1185 | 1196 | ||
1186 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1197 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1187 | :OMonitoringInterface( iface, prismHeader ) | 1198 | :OMonitoringInterface( iface, prismHeader ) |
1188 | { | 1199 | { |
1189 | iface->setMonitoring( this ); | 1200 | iface->setMonitoring( this ); |
1190 | } | 1201 | } |
1191 | 1202 | ||
1192 | 1203 | ||
1193 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 1204 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
1194 | { | 1205 | { |
1195 | } | 1206 | } |
1196 | 1207 | ||
1197 | 1208 | ||
1198 | void OOrinocoMonitoringInterface::setChannel( int c ) | 1209 | void OOrinocoMonitoringInterface::setChannel( int c ) |
1199 | { | 1210 | { |
1200 | if ( !_if->hasPrivate( "monitor" ) ) | 1211 | if ( !_if->hasPrivate( "monitor" ) ) |
1201 | { | 1212 | { |
1202 | this->OMonitoringInterface::setChannel( c ); | 1213 | this->OMonitoringInterface::setChannel( c ); |
1203 | } | 1214 | } |
1204 | else | 1215 | else |
1205 | { | 1216 | { |
1206 | int monitorCode = _prismHeader ? 1 : 2; | 1217 | int monitorCode = _prismHeader ? 1 : 2; |
1207 | _if->setPrivate( "monitor", 2, monitorCode, c ); | 1218 | _if->setPrivate( "monitor", 2, monitorCode, c ); |
1208 | } | 1219 | } |
1209 | } | 1220 | } |
1210 | 1221 | ||
1211 | 1222 | ||
1212 | void OOrinocoMonitoringInterface::setEnabled( bool b ) | 1223 | void OOrinocoMonitoringInterface::setEnabled( bool b ) |
1213 | { | 1224 | { |
1214 | if ( b ) | 1225 | if ( b ) |
1215 | { | 1226 | { |
1216 | setChannel( 1 ); | 1227 | setChannel( 1 ); |
1217 | } | 1228 | } |
1218 | else | 1229 | else |
1219 | { | 1230 | { |
1220 | _if->setPrivate( "monitor", 2, 0, 0 ); | 1231 | _if->setPrivate( "monitor", 2, 0, 0 ); |
1221 | } | 1232 | } |
1222 | } | 1233 | } |
1223 | 1234 | ||
1224 | 1235 | ||
1225 | QString OOrinocoMonitoringInterface::name() const | 1236 | QString OOrinocoMonitoringInterface::name() const |
1226 | { | 1237 | { |
1227 | return "orinoco"; | 1238 | return "orinoco"; |
1228 | } | 1239 | } |
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 0a51108..93b129f 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h | |||
@@ -1,555 +1,559 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer | 3 | Copyright (C) 2003-2004 by Michael 'Mickey' Lauer |
4 | =. <mickey@Vanille.de> | 4 | =. <mickey@Vanille.de> |
5 | .=l. | 5 | .=l. |
6 | .>+-= | 6 | .>+-= |
7 | _;:, .> :=|. This program is free software; you can | 7 | _;:, .> :=|. This program is free software; you can |
8 | .> <`_, > . <= redistribute it and/or modify it under | 8 | .> <`_, > . <= redistribute it and/or modify it under |
9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 9 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
10 | .="- .-=="i, .._ License as published by the Free Software | 10 | .="- .-=="i, .._ License as published by the Free Software |
11 | - . .-<_> .<> Foundation; either version 2 of the License, | 11 | - . .-<_> .<> Foundation; either version 2 of the License, |
12 | ._= =} : or (at your option) any later version. | 12 | ._= =} : or (at your option) any later version. |
13 | .%`+i> _;_. | 13 | .%`+i> _;_. |
14 | .i_,=:_. -<s. This program is distributed in the hope that | 14 | .i_,=:_. -<s. This program is distributed in the hope that |
15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 15 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
16 | : .. .:, . . . without even the implied warranty of | 16 | : .. .:, . . . without even the implied warranty of |
17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 17 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 18 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
19 | ..}^=.= = ; Library General Public License for more | 19 | ..}^=.= = ; Library General Public License for more |
20 | ++= -. .` .: details. | 20 | ++= -. .` .: details. |
21 | : = ...= . :.=- | 21 | : = ...= . :.=- |
22 | -. .:....=;==+<; You should have received a copy of the GNU | 22 | -. .:....=;==+<; You should have received a copy of the GNU |
23 | -_. . . )=. = Library General Public License along with | 23 | -_. . . )=. = Library General Public License along with |
24 | -- :-=` this library; see the file COPYING.LIB. | 24 | -- :-=` this library; see the file COPYING.LIB. |
25 | If not, write to the Free Software Foundation, | 25 | If not, write to the Free Software Foundation, |
26 | Inc., 59 Temple Place - Suite 330, | 26 | Inc., 59 Temple Place - Suite 330, |
27 | Boston, MA 02111-1307, USA. | 27 | Boston, MA 02111-1307, USA. |
28 | 28 | ||
29 | */ | 29 | */ |
30 | 30 | ||
31 | #ifndef ONETWORK_H | 31 | #ifndef ONETWORK_H |
32 | #define ONETWORK_H | 32 | #define ONETWORK_H |
33 | 33 | ||
34 | #if !defined( OPIE_WE_VERSION ) | 34 | #if !defined( OPIE_WE_VERSION ) |
35 | #error Need to define a wireless extension version to build against! | 35 | #error Need to define a wireless extension version to build against! |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #if OPIE_WE_VERSION == 15 | 38 | #if OPIE_WE_VERSION == 15 |
39 | #include "wireless.15.h" | 39 | #include "wireless.15.h" |
40 | #endif | 40 | #endif |
41 | 41 | ||
42 | #if OPIE_WE_VERSION == 16 | 42 | #if OPIE_WE_VERSION == 16 |
43 | #include "wireless.16.h" | 43 | #include "wireless.16.h" |
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | /* OPIE */ | 46 | /* OPIE */ |
47 | 47 | ||
48 | #include <opie2/onetutils.h> | 48 | #include <opie2/onetutils.h> |
49 | #include <opie2/ostation.h> | 49 | #include <opie2/ostation.h> |
50 | 50 | ||
51 | /* QT */ | 51 | /* QT */ |
52 | 52 | ||
53 | #include <qvaluelist.h> | 53 | #include <qvaluelist.h> |
54 | #include <qdict.h> | 54 | #include <qdict.h> |
55 | #include <qmap.h> | 55 | #include <qmap.h> |
56 | #include <qobject.h> | 56 | #include <qobject.h> |
57 | #include <qhostaddress.h> | 57 | #include <qhostaddress.h> |
58 | 58 | ||
59 | class ONetworkInterface; | 59 | class ONetworkInterface; |
60 | class OWirelessNetworkInterface; | 60 | class OWirelessNetworkInterface; |
61 | class OChannelHopper; | 61 | class OChannelHopper; |
62 | class OMonitoringInterface; | 62 | class OMonitoringInterface; |
63 | 63 | ||
64 | /*====================================================================================== | 64 | /*====================================================================================== |
65 | * ONetwork | 65 | * ONetwork |
66 | *======================================================================================*/ | 66 | *======================================================================================*/ |
67 | 67 | ||
68 | /** | 68 | /** |
69 | * @brief A container class for all network interfaces | 69 | * @brief A container class for all network interfaces |
70 | * | 70 | * |
71 | * This class provides access to all available network interfaces of your computer. | 71 | * This class provides access to all available network interfaces of your computer. |
72 | * | 72 | * |
73 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> | 73 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> |
74 | */ | 74 | */ |
75 | class ONetwork : public QObject | 75 | class ONetwork : public QObject |
76 | { | 76 | { |
77 | Q_OBJECT | 77 | Q_OBJECT |
78 | 78 | ||
79 | public: | 79 | public: |
80 | typedef QDict<ONetworkInterface> InterfaceMap; | 80 | typedef QDict<ONetworkInterface> InterfaceMap; |
81 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; | 81 | typedef QDictIterator<ONetworkInterface> InterfaceIterator; |
82 | 82 | ||
83 | public: | 83 | public: |
84 | /** | 84 | /** |
85 | * @returns the number of available interfaces | 85 | * @returns the number of available interfaces |
86 | */ | 86 | */ |
87 | int count() const; | 87 | int count() const; |
88 | /** | 88 | /** |
89 | * @returns a pointer to the (one and only) @ref ONetwork instance. | 89 | * @returns a pointer to the (one and only) @ref ONetwork instance. |
90 | */ | 90 | */ |
91 | static ONetwork* instance(); | 91 | static ONetwork* instance(); |
92 | /** | 92 | /** |
93 | * @returns an iterator usable for iterating through all network interfaces. | 93 | * @returns an iterator usable for iterating through all network interfaces. |
94 | */ | 94 | */ |
95 | InterfaceIterator iterator() const; | 95 | InterfaceIterator iterator() const; |
96 | /** | 96 | /** |
97 | * @returns true, if the @a interface is present. | ||
98 | */ | ||
99 | bool isPresent( const char* interface ) const; | ||
100 | /** | ||
97 | * @returns true, if the @a interface supports the wireless extension protocol. | 101 | * @returns true, if the @a interface supports the wireless extension protocol. |
98 | */ | 102 | */ |
99 | bool isWirelessInterface( const char* interface ) const; | 103 | bool isWirelessInterface( const char* interface ) const; |
100 | /** | 104 | /** |
101 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. | 105 | * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found. |
102 | * @see ONetworkInterface | 106 | * @see ONetworkInterface |
103 | */ | 107 | */ |
104 | ONetworkInterface* interface( const QString& interface ) const; | 108 | ONetworkInterface* interface( const QString& interface ) const; |
105 | /** | 109 | /** |
106 | * @internal Rebuild the internal interface database | 110 | * @internal Rebuild the internal interface database |
107 | * @note Sometimes it might be useful to call this from client code, | 111 | * @note Sometimes it might be useful to call this from client code, |
108 | * e.g. after issuing a cardctl insert | 112 | * e.g. after issuing a cardctl insert |
109 | */ | 113 | */ |
110 | void synchronize(); | 114 | void synchronize(); |
111 | /** | 115 | /** |
112 | * @returns the wireless extension version used at compile time. | 116 | * @returns the wireless extension version used at compile time. |
113 | **/ | 117 | **/ |
114 | static short wirelessExtensionVersion(); | 118 | static short wirelessExtensionVersion(); |
115 | 119 | ||
116 | protected: | 120 | protected: |
117 | ONetwork(); | 121 | ONetwork(); |
118 | 122 | ||
119 | private: | 123 | private: |
120 | static ONetwork* _instance; | 124 | static ONetwork* _instance; |
121 | InterfaceMap _interfaces; | 125 | InterfaceMap _interfaces; |
122 | }; | 126 | }; |
123 | 127 | ||
124 | 128 | ||
125 | /*====================================================================================== | 129 | /*====================================================================================== |
126 | * ONetworkInterface | 130 | * ONetworkInterface |
127 | *======================================================================================*/ | 131 | *======================================================================================*/ |
128 | 132 | ||
129 | /** | 133 | /** |
130 | * @brief A network interface wrapper. | 134 | * @brief A network interface wrapper. |
131 | * | 135 | * |
132 | * This class provides a wrapper for a network interface. All the cumbersume details of | 136 | * This class provides a wrapper for a network interface. All the cumbersume details of |
133 | * Linux ioctls are hidden under a convenient high-level interface. | 137 | * Linux ioctls are hidden under a convenient high-level interface. |
134 | * @warning Most of the setting methods contained in this class require the appropriate | 138 | * @warning Most of the setting methods contained in this class require the appropriate |
135 | * process permissions to work. | 139 | * process permissions to work. |
136 | * | 140 | * |
137 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> | 141 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> |
138 | */ | 142 | */ |
139 | class ONetworkInterface : public QObject | 143 | class ONetworkInterface : public QObject |
140 | { | 144 | { |
141 | friend class OMonitoringInterface; | 145 | friend class OMonitoringInterface; |
142 | friend class OCiscoMonitoringInterface; | 146 | friend class OCiscoMonitoringInterface; |
143 | friend class OWlanNGMonitoringInterface; | 147 | friend class OWlanNGMonitoringInterface; |
144 | friend class OHostAPMonitoringInterface; | 148 | friend class OHostAPMonitoringInterface; |
145 | friend class OOrinocoMonitoringInterface; | 149 | friend class OOrinocoMonitoringInterface; |
146 | 150 | ||
147 | public: | 151 | public: |
148 | /** | 152 | /** |
149 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, | 153 | * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, |
150 | * but access them via @ref ONetwork::interface(). | 154 | * but access them via @ref ONetwork::interface(). |
151 | */ | 155 | */ |
152 | ONetworkInterface( QObject* parent, const char* name ); | 156 | ONetworkInterface( QObject* parent, const char* name ); |
153 | /** | 157 | /** |
154 | * Destructor. | 158 | * Destructor. |
155 | */ | 159 | */ |
156 | virtual ~ONetworkInterface(); | 160 | virtual ~ONetworkInterface(); |
157 | /** | 161 | /** |
158 | * Associates a @a monitoring interface with this network interface. | 162 | * Associates a @a monitoring interface with this network interface. |
159 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. | 163 | * @note This is currently only useful with @ref OWirelessNetworkInterface objects. |
160 | */ | 164 | */ |
161 | void setMonitoring( OMonitoringInterface* monitoring ); | 165 | void setMonitoring( OMonitoringInterface* monitoring ); |
162 | /** | 166 | /** |
163 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. | 167 | * @returns the currently associated monitoring interface or 0, if no monitoring is associated. |
164 | */ | 168 | */ |
165 | OMonitoringInterface* monitoring() const; | 169 | OMonitoringInterface* monitoring() const; |
166 | /** | 170 | /** |
167 | * Setting an interface to promiscuous mode enables the device to receive | 171 | * Setting an interface to promiscuous mode enables the device to receive |
168 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. | 172 | * all packets on the shared medium - as opposed to packets which are addressed to this interface. |
169 | */ | 173 | */ |
170 | bool setPromiscuousMode( bool ); | 174 | bool setPromiscuousMode( bool ); |
171 | /** | 175 | /** |
172 | * @returns true if the interface is set to promiscuous mode. | 176 | * @returns true if the interface is set to promiscuous mode. |
173 | */ | 177 | */ |
174 | bool promiscuousMode() const; | 178 | bool promiscuousMode() const; |
175 | /** | 179 | /** |
176 | * Setting an interface to up enables it to receive packets. | 180 | * Setting an interface to up enables it to receive packets. |
177 | */ | 181 | */ |
178 | bool setUp( bool ); | 182 | bool setUp( bool ); |
179 | /** | 183 | /** |
180 | * @returns true if the interface is up. | 184 | * @returns true if the interface is up. |
181 | */ | 185 | */ |
182 | bool isUp() const; | 186 | bool isUp() const; |
183 | /** | 187 | /** |
184 | * @returns true if the interface is a loopback interface. | 188 | * @returns true if the interface is a loopback interface. |
185 | */ | 189 | */ |
186 | bool isLoopback() const; | 190 | bool isLoopback() const; |
187 | /** | 191 | /** |
188 | * @returns true if the interface is featuring supports the wireless extension protocol. | 192 | * @returns true if the interface is featuring supports the wireless extension protocol. |
189 | */ | 193 | */ |
190 | bool isWireless() const; | 194 | bool isWireless() const; |
191 | /** | 195 | /** |
192 | * Associate the IP address @ addr with the interface. | 196 | * Associate the IP address @ addr with the interface. |
193 | */ | 197 | */ |
194 | void setIPV4Address( const QHostAddress& addr ); | 198 | void setIPV4Address( const QHostAddress& addr ); |
195 | /** | 199 | /** |
196 | * @returns the IPv4 address associated with the interface. | 200 | * @returns the IPv4 address associated with the interface. |
197 | */ | 201 | */ |
198 | QString ipV4Address() const; //TODO: make this return an OHostAddress | 202 | QString ipV4Address() const; //TODO: make this return an OHostAddress |
199 | /** | 203 | /** |
200 | * Associate the MAC address @a addr with the interface. | 204 | * Associate the MAC address @a addr with the interface. |
201 | * @note It can be necessary to shut down the interface prior to calling this method. | 205 | * @note It can be necessary to shut down the interface prior to calling this method. |
202 | * @warning This is not supported by all drivers. | 206 | * @warning This is not supported by all drivers. |
203 | */ | 207 | */ |
204 | void setMacAddress( const OMacAddress& addr ); | 208 | void setMacAddress( const OMacAddress& addr ); |
205 | /** | 209 | /** |
206 | * @returns the MAC address associated with the interface. | 210 | * @returns the MAC address associated with the interface. |
207 | */ | 211 | */ |
208 | OMacAddress macAddress() const; | 212 | OMacAddress macAddress() const; |
209 | /** | 213 | /** |
210 | * Associate the IPv4 @a netmask with the interface. | 214 | * Associate the IPv4 @a netmask with the interface. |
211 | */ | 215 | */ |
212 | void setIPV4Netmask( const QHostAddress& netmask ); | 216 | void setIPV4Netmask( const QHostAddress& netmask ); |
213 | /** | 217 | /** |
214 | * @returns the IPv4 netmask associated with the interface. | 218 | * @returns the IPv4 netmask associated with the interface. |
215 | */ | 219 | */ |
216 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress | 220 | QString ipV4Netmask() const; //TODO: make this return an OHostAddress |
217 | /** | 221 | /** |
218 | * @returns the data link type currently associated with the interface. | 222 | * @returns the data link type currently associated with the interface. |
219 | * @see #include <net/if_arp.h> for possible values. | 223 | * @see #include <net/if_arp.h> for possible values. |
220 | */ | 224 | */ |
221 | int dataLinkType() const; | 225 | int dataLinkType() const; |
222 | 226 | ||
223 | protected: | 227 | protected: |
224 | const int _sfd; | 228 | const int _sfd; |
225 | mutable ifreq _ifr; | 229 | mutable ifreq _ifr; |
226 | OMonitoringInterface* _mon; | 230 | OMonitoringInterface* _mon; |
227 | 231 | ||
228 | protected: | 232 | protected: |
229 | struct ifreq& ifr() const; | 233 | struct ifreq& ifr() const; |
230 | virtual void init(); | 234 | virtual void init(); |
231 | bool ioctl( int call ) const; | 235 | bool ioctl( int call ) const; |
232 | bool ioctl( int call, struct ifreq& ) const; | 236 | bool ioctl( int call, struct ifreq& ) const; |
233 | }; | 237 | }; |
234 | 238 | ||
235 | /*====================================================================================== | 239 | /*====================================================================================== |
236 | * OChannelHopper | 240 | * OChannelHopper |
237 | *======================================================================================*/ | 241 | *======================================================================================*/ |
238 | 242 | ||
239 | /** | 243 | /** |
240 | * @brief A radio frequency channel hopper. | 244 | * @brief A radio frequency channel hopper. |
241 | * | 245 | * |
242 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently | 246 | * This class provides a channel hopper for radio frequencies. A channel hopper frequently |
243 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. | 247 | * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. |
244 | * This is necessary when in monitoring mode and scanning for other devices, because | 248 | * This is necessary when in monitoring mode and scanning for other devices, because |
245 | * the radio frequency hardware can only detect packets sent on the same frequency. | 249 | * the radio frequency hardware can only detect packets sent on the same frequency. |
246 | * | 250 | * |
247 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> | 251 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> |
248 | */ | 252 | */ |
249 | class OChannelHopper : public QObject | 253 | class OChannelHopper : public QObject |
250 | { | 254 | { |
251 | Q_OBJECT | 255 | Q_OBJECT |
252 | 256 | ||
253 | public: | 257 | public: |
254 | /** | 258 | /** |
255 | * Constructor. | 259 | * Constructor. |
256 | */ | 260 | */ |
257 | OChannelHopper( OWirelessNetworkInterface* ); | 261 | OChannelHopper( OWirelessNetworkInterface* ); |
258 | /** | 262 | /** |
259 | * Destructor. | 263 | * Destructor. |
260 | */ | 264 | */ |
261 | virtual ~OChannelHopper(); | 265 | virtual ~OChannelHopper(); |
262 | /** | 266 | /** |
263 | * @returns true, if the channel hopper is hopping channels | 267 | * @returns true, if the channel hopper is hopping channels |
264 | */ | 268 | */ |
265 | bool isActive() const; | 269 | bool isActive() const; |
266 | /** | 270 | /** |
267 | * @returns the last hopped channel | 271 | * @returns the last hopped channel |
268 | */ | 272 | */ |
269 | int channel() const; | 273 | int channel() const; |
270 | /** | 274 | /** |
271 | * Set the channel hopping @a interval. | 275 | * Set the channel hopping @a interval. |
272 | * An interval of 0 deactivates the channel hopper. | 276 | * An interval of 0 deactivates the channel hopper. |
273 | */ | 277 | */ |
274 | void setInterval( int interval ); | 278 | void setInterval( int interval ); |
275 | /** | 279 | /** |
276 | * @returns the channel hopping interval | 280 | * @returns the channel hopping interval |
277 | */ | 281 | */ |
278 | int interval() const; | 282 | int interval() const; |
279 | 283 | ||
280 | signals: | 284 | signals: |
281 | /** | 285 | /** |
282 | * This signal is emitted right after the channel hopper performed a hop | 286 | * This signal is emitted right after the channel hopper performed a hop |
283 | */ | 287 | */ |
284 | void hopped( int ); | 288 | void hopped( int ); |
285 | 289 | ||
286 | protected: | 290 | protected: |
287 | virtual void timerEvent( QTimerEvent* ); | 291 | virtual void timerEvent( QTimerEvent* ); |
288 | 292 | ||
289 | private: | 293 | private: |
290 | OWirelessNetworkInterface* _iface; | 294 | OWirelessNetworkInterface* _iface; |
291 | int _interval; | 295 | int _interval; |
292 | int _tid; | 296 | int _tid; |
293 | QValueList<int> _channels; | 297 | QValueList<int> _channels; |
294 | QValueList<int>::Iterator _channel; | 298 | QValueList<int>::Iterator _channel; |
295 | }; | 299 | }; |
296 | 300 | ||
297 | 301 | ||
298 | /*====================================================================================== | 302 | /*====================================================================================== |
299 | * OWirelessNetworkInterface | 303 | * OWirelessNetworkInterface |
300 | *======================================================================================*/ | 304 | *======================================================================================*/ |
301 | 305 | ||
302 | /** | 306 | /** |
303 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. | 307 | * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. |
304 | * | 308 | * |
305 | * This class provides a high-level encapsulation of the Linux wireless extension API. | 309 | * This class provides a high-level encapsulation of the Linux wireless extension API. |
306 | * | 310 | * |
307 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> | 311 | * @author Michael 'Mickey' Lauer <mickey@vanille.de> |
308 | */ | 312 | */ |
309 | class OWirelessNetworkInterface : public ONetworkInterface | 313 | class OWirelessNetworkInterface : public ONetworkInterface |
310 | { | 314 | { |
311 | friend class OMonitoringInterface; | 315 | friend class OMonitoringInterface; |
312 | friend class OCiscoMonitoringInterface; | 316 | friend class OCiscoMonitoringInterface; |
313 | friend class OWlanNGMonitoringInterface; | 317 | friend class OWlanNGMonitoringInterface; |
314 | friend class OHostAPMonitoringInterface; | 318 | friend class OHostAPMonitoringInterface; |
315 | friend class OOrinocoMonitoringInterface; | 319 | friend class OOrinocoMonitoringInterface; |
316 | 320 | ||
317 | friend class OPrivateIOCTL; | 321 | friend class OPrivateIOCTL; |
318 | 322 | ||
319 | public: | 323 | public: |
320 | /** | 324 | /** |
321 | * Constructor. | 325 | * Constructor. |
322 | */ | 326 | */ |
323 | OWirelessNetworkInterface( QObject* parent, const char* name ); | 327 | OWirelessNetworkInterface( QObject* parent, const char* name ); |
324 | /** | 328 | /** |
325 | * Destructor. | 329 | * Destructor. |
326 | */ | 330 | */ |
327 | virtual ~OWirelessNetworkInterface(); | 331 | virtual ~OWirelessNetworkInterface(); |
328 | /** | 332 | /** |
329 | * Setting the @a channel of the interface changes the radio frequency (RF) | 333 | * Setting the @a channel of the interface changes the radio frequency (RF) |
330 | * of the corresponding wireless network device. | 334 | * of the corresponding wireless network device. |
331 | * @note Common channel range is within [1-14]. A value of 0 is not allowed. | 335 | * @note Common channel range is within [1-14]. A value of 0 is not allowed. |
332 | * @see channels() | 336 | * @see channels() |
333 | */ | 337 | */ |
334 | virtual void setChannel( int channel ) const; | 338 | virtual void setChannel( int channel ) const; |
335 | /** | 339 | /** |
336 | * @returns the channel index of the current radio frequency. | 340 | * @returns the channel index of the current radio frequency. |
337 | */ | 341 | */ |
338 | virtual int channel() const; | 342 | virtual int channel() const; |
339 | /** | 343 | /** |
340 | * @returns the current radio frequency (in MHz). | 344 | * @returns the current radio frequency (in MHz). |
341 | */ | 345 | */ |
342 | virtual double frequency() const; | 346 | virtual double frequency() const; |
343 | /** | 347 | /** |
344 | * @returns the number of radio frequency channels for the | 348 | * @returns the number of radio frequency channels for the |
345 | * corresponding wireless network device. | 349 | * corresponding wireless network device. |
346 | * @note European devices usually have 14 channels, while American typically feature 11 channels. | 350 | * @note European devices usually have 14 channels, while American typically feature 11 channels. |
347 | */ | 351 | */ |
348 | virtual int channels() const; | 352 | virtual int channels() const; |
349 | /** | 353 | /** |
350 | * Set the IEEE 802.11 operation @a mode. | 354 | * Set the IEEE 802.11 operation @a mode. |
351 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master | 355 | * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master |
352 | * @warning Not all drivers support the all modes. | 356 | * @warning Not all drivers support the all modes. |
353 | * @note You might have to change the SSID to get the operation mode change into effect. | 357 | * @note You might have to change the SSID to get the operation mode change into effect. |
354 | */ | 358 | */ |
355 | virtual void setMode( const QString& mode ); | 359 | virtual void setMode( const QString& mode ); |
356 | /** | 360 | /** |
357 | * @returns the current IEEE 802.11 operation mode. | 361 | * @returns the current IEEE 802.11 operation mode. |
358 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown | 362 | * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown |
359 | * | 363 | * |
360 | * @note: Important note concerning the 'monitor' mode: | 364 | * @note: Important note concerning the 'monitor' mode: |
361 | * Setting the monitor mode on a wireless network interface enables | 365 | * Setting the monitor mode on a wireless network interface enables |
362 | * listening to IEEE 802.11 data and management frames which normally | 366 | * listening to IEEE 802.11 data and management frames which normally |
363 | * are handled by the device firmware. This can be used to detect | 367 | * are handled by the device firmware. This can be used to detect |
364 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. | 368 | * other wireless network devices, e.g. Access Points or Ad-hoc stations. |
365 | * @warning Standard wireless network drives don't support the monitor mode. | 369 | * @warning Standard wireless network drives don't support the monitor mode. |
366 | * @warning You need a patched driver for this to work. | 370 | * @warning You need a patched driver for this to work. |
367 | * @note Enabling the monitor mode is highly driver dependent and requires | 371 | * @note Enabling the monitor mode is highly driver dependent and requires |
368 | * the proper @ref OMonitoringInterface to be associated with the interface. | 372 | * the proper @ref OMonitoringInterface to be associated with the interface. |
369 | * @see OMonitoringInterface | 373 | * @see OMonitoringInterface |
370 | */ | 374 | */ |
371 | virtual QString mode() const; | 375 | virtual QString mode() const; |
372 | /** | 376 | /** |
373 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. | 377 | * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. |
374 | * @see OChannelHopper | 378 | * @see OChannelHopper |
375 | */ | 379 | */ |
376 | virtual void setChannelHopping( int interval = 0 ); | 380 | virtual void setChannelHopping( int interval = 0 ); |
377 | /** | 381 | /** |
378 | * @returns the channel hopping interval or 0, if channel hopping is disabled. | 382 | * @returns the channel hopping interval or 0, if channel hopping is disabled. |
379 | */ | 383 | */ |
380 | virtual int channelHopping() const; | 384 | virtual int channelHopping() const; |
381 | /** | 385 | /** |
382 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before | 386 | * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before |
383 | */ | 387 | */ |
384 | virtual OChannelHopper* channelHopper() const; | 388 | virtual OChannelHopper* channelHopper() const; |
385 | /** | 389 | /** |
386 | * Set the station @a nickname. | 390 | * Set the station @a nickname. |
387 | */ | 391 | */ |
388 | virtual void setNickName( const QString& nickname ); | 392 | virtual void setNickName( const QString& nickname ); |
389 | /** | 393 | /** |
390 | * @returns the current station nickname. | 394 | * @returns the current station nickname. |
391 | */ | 395 | */ |
392 | virtual QString nickName() const; | 396 | virtual QString nickName() const; |
393 | /** | 397 | /** |
394 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. | 398 | * Invoke the private IOCTL @a command with a @number of parameters on the network interface. |
395 | * @see OPrivateIOCTL | 399 | * @see OPrivateIOCTL |
396 | */ | 400 | */ |
397 | virtual void setPrivate( const QString& command, int number, ... ); | 401 | virtual void setPrivate( const QString& command, int number, ... ); |
398 | /** | 402 | /** |
399 | * @returns true if the interface is featuring the private IOCTL @command. | 403 | * @returns true if the interface is featuring the private IOCTL @command. |
400 | */ | 404 | */ |
401 | virtual bool hasPrivate( const QString& command ); | 405 | virtual bool hasPrivate( const QString& command ); |
402 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this | 406 | virtual void getPrivate( const QString& command ); //FIXME: Implement and document this |
403 | /** | 407 | /** |
404 | * @returns true if the interface is associated to an access point | 408 | * @returns true if the interface is associated to an access point |
405 | * @note: This information is only valid if the interface is in managed mode. | 409 | * @note: This information is only valid if the interface is in managed mode. |
406 | */ | 410 | */ |
407 | virtual bool isAssociated() const; | 411 | virtual bool isAssociated() const; |
408 | /** | 412 | /** |
409 | * @returns the MAC address of the Access Point if the device is in infrastructure mode. | 413 | * @returns the MAC address of the Access Point if the device is in infrastructure mode. |
410 | * @returns a (more or less random) cell ID address if the device is in adhoc mode. | 414 | * @returns a (more or less random) cell ID address if the device is in adhoc mode. |
411 | */ | 415 | */ |
412 | virtual OMacAddress associatedAP() const; | 416 | virtual OMacAddress associatedAP() const; |
413 | /** | 417 | /** |
414 | * Set the @a ssid (Service Set ID) string. This is used to decide | 418 | * Set the @a ssid (Service Set ID) string. This is used to decide |
415 | * which network to associate with (use "any" to let the driver decide). | 419 | * which network to associate with (use "any" to let the driver decide). |
416 | */ | 420 | */ |
417 | virtual void setSSID( const QString& ssid ); | 421 | virtual void setSSID( const QString& ssid ); |
418 | /** | 422 | /** |
419 | * @returns the current SSID (Service Set ID). | 423 | * @returns the current SSID (Service Set ID). |
420 | */ | 424 | */ |
421 | virtual QString SSID() const; | 425 | virtual QString SSID() const; |
422 | /** | 426 | /** |
423 | * Perform scanning the wireless network neighbourhood. | 427 | * Perform scanning the wireless network neighbourhood. |
424 | * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! | 428 | * @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE! |
425 | */ | 429 | */ |
426 | virtual OStationList* scanNetwork(); | 430 | virtual OStationList* scanNetwork(); |
427 | /** | 431 | /** |
428 | * @return signal strength to associated neighbour (in percent). | 432 | * @return signal strength to associated neighbour (in percent). |
429 | * In infrastructure mode, this is the signal strength of the Access Point. | 433 | * In infrastructure mode, this is the signal strength of the Access Point. |
430 | * In other modes the result is driver dependent. | 434 | * In other modes the result is driver dependent. |
431 | */ | 435 | */ |
432 | virtual int signalStrength() const; | 436 | virtual int signalStrength() const; |
433 | /** @internal commit pending changes to the driver | 437 | /** @internal commit pending changes to the driver |
434 | * | 438 | * |
435 | */ | 439 | */ |
436 | void commit() const; | 440 | void commit() const; |
437 | 441 | ||
438 | protected: | 442 | protected: |
439 | void buildInformation(); | 443 | void buildInformation(); |
440 | void buildPrivateList(); | 444 | void buildPrivateList(); |
441 | void dumpInformation() const; | 445 | void dumpInformation() const; |
442 | virtual void init(); | 446 | virtual void init(); |
443 | struct iwreq& iwr() const; | 447 | struct iwreq& iwr() const; |
444 | bool wioctl( int call ) const; | 448 | bool wioctl( int call ) const; |
445 | bool wioctl( int call, struct iwreq& ) const; | 449 | bool wioctl( int call, struct iwreq& ) const; |
446 | 450 | ||
447 | protected: | 451 | protected: |
448 | mutable struct iwreq _iwr; | 452 | mutable struct iwreq _iwr; |
449 | QMap<int,int> _channels; | 453 | QMap<int,int> _channels; |
450 | struct iw_range _range; | 454 | struct iw_range _range; |
451 | 455 | ||
452 | private: | 456 | private: |
453 | OChannelHopper* _hopper; | 457 | OChannelHopper* _hopper; |
454 | }; | 458 | }; |
455 | 459 | ||
456 | 460 | ||
457 | /*====================================================================================== | 461 | /*====================================================================================== |
458 | * OMonitoringInterface | 462 | * OMonitoringInterface |
459 | *======================================================================================*/ | 463 | *======================================================================================*/ |
460 | 464 | ||
461 | 465 | ||
462 | class OMonitoringInterface | 466 | class OMonitoringInterface |
463 | { | 467 | { |
464 | public: | 468 | public: |
465 | OMonitoringInterface(); | 469 | OMonitoringInterface(); |
466 | OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 470 | OMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
467 | virtual ~OMonitoringInterface(); | 471 | virtual ~OMonitoringInterface(); |
468 | 472 | ||
469 | public: | 473 | public: |
470 | virtual void setEnabled( bool ); | 474 | virtual void setEnabled( bool ); |
471 | virtual void setChannel( int ); | 475 | virtual void setChannel( int ); |
472 | 476 | ||
473 | virtual QString name() const = 0; | 477 | virtual QString name() const = 0; |
474 | 478 | ||
475 | protected: | 479 | protected: |
476 | OWirelessNetworkInterface* _if; | 480 | OWirelessNetworkInterface* _if; |
477 | bool _prismHeader; | 481 | bool _prismHeader; |
478 | 482 | ||
479 | }; | 483 | }; |
480 | 484 | ||
481 | 485 | ||
482 | /*====================================================================================== | 486 | /*====================================================================================== |
483 | * OCiscoMonitoring | 487 | * OCiscoMonitoring |
484 | *======================================================================================*/ | 488 | *======================================================================================*/ |
485 | 489 | ||
486 | 490 | ||
487 | class OCiscoMonitoringInterface : public OMonitoringInterface | 491 | class OCiscoMonitoringInterface : public OMonitoringInterface |
488 | { | 492 | { |
489 | public: | 493 | public: |
490 | OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 494 | OCiscoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
491 | virtual ~OCiscoMonitoringInterface(); | 495 | virtual ~OCiscoMonitoringInterface(); |
492 | 496 | ||
493 | virtual void setEnabled( bool ); | 497 | virtual void setEnabled( bool ); |
494 | virtual QString name() const; | 498 | virtual QString name() const; |
495 | virtual void setChannel( int ); | 499 | virtual void setChannel( int ); |
496 | 500 | ||
497 | }; | 501 | }; |
498 | 502 | ||
499 | 503 | ||
500 | /*====================================================================================== | 504 | /*====================================================================================== |
501 | * OWlanNGMonitoringInterface | 505 | * OWlanNGMonitoringInterface |
502 | *======================================================================================*/ | 506 | *======================================================================================*/ |
503 | 507 | ||
504 | 508 | ||
505 | class OWlanNGMonitoringInterface : public OMonitoringInterface | 509 | class OWlanNGMonitoringInterface : public OMonitoringInterface |
506 | { | 510 | { |
507 | public: | 511 | public: |
508 | OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 512 | OWlanNGMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
509 | virtual ~OWlanNGMonitoringInterface(); | 513 | virtual ~OWlanNGMonitoringInterface(); |
510 | 514 | ||
511 | public: | 515 | public: |
512 | virtual void setEnabled( bool ); | 516 | virtual void setEnabled( bool ); |
513 | virtual QString name() const; | 517 | virtual QString name() const; |
514 | virtual void setChannel( int ); | 518 | virtual void setChannel( int ); |
515 | 519 | ||
516 | }; | 520 | }; |
517 | 521 | ||
518 | 522 | ||
519 | /*====================================================================================== | 523 | /*====================================================================================== |
520 | * OHostAPMonitoringInterface | 524 | * OHostAPMonitoringInterface |
521 | *======================================================================================*/ | 525 | *======================================================================================*/ |
522 | 526 | ||
523 | 527 | ||
524 | class OHostAPMonitoringInterface : public OMonitoringInterface | 528 | class OHostAPMonitoringInterface : public OMonitoringInterface |
525 | { | 529 | { |
526 | public: | 530 | public: |
527 | OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 531 | OHostAPMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
528 | virtual ~OHostAPMonitoringInterface(); | 532 | virtual ~OHostAPMonitoringInterface(); |
529 | 533 | ||
530 | public: | 534 | public: |
531 | virtual void setEnabled( bool ); | 535 | virtual void setEnabled( bool ); |
532 | virtual QString name() const; | 536 | virtual QString name() const; |
533 | }; | 537 | }; |
534 | 538 | ||
535 | 539 | ||
536 | /*====================================================================================== | 540 | /*====================================================================================== |
537 | * OOrinocoMonitoringInterface | 541 | * OOrinocoMonitoringInterface |
538 | *======================================================================================*/ | 542 | *======================================================================================*/ |
539 | 543 | ||
540 | 544 | ||
541 | class OOrinocoMonitoringInterface : public OMonitoringInterface | 545 | class OOrinocoMonitoringInterface : public OMonitoringInterface |
542 | { | 546 | { |
543 | public: | 547 | public: |
544 | OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); | 548 | OOrinocoMonitoringInterface( ONetworkInterface*, bool _prismHeader ); |
545 | virtual ~OOrinocoMonitoringInterface(); | 549 | virtual ~OOrinocoMonitoringInterface(); |
546 | 550 | ||
547 | public: | 551 | public: |
548 | virtual void setChannel( int ); | 552 | virtual void setChannel( int ); |
549 | virtual void setEnabled( bool ); | 553 | virtual void setEnabled( bool ); |
550 | virtual QString name() const; | 554 | virtual QString name() const; |
551 | 555 | ||
552 | }; | 556 | }; |
553 | 557 | ||
554 | #endif // ONETWORK_H | 558 | #endif // ONETWORK_H |
555 | 559 | ||