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