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