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