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