summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-01 15:03:49 (UTC)
committer mickeyl <mickeyl>2003-04-01 15:03:49 (UTC)
commita7ad29eb41163eec88b3bd835108bd80140ff086 (patch) (unidiff)
tree8fa122e07d475014d8343be06d99f53759af0582
parent14d3e700f80f8e26f3f3cceaa7174d5f1c445bd7 (diff)
downloadopie-a7ad29eb41163eec88b3bd835108bd80140ff086.zip
opie-a7ad29eb41163eec88b3bd835108bd80140ff086.tar.gz
opie-a7ad29eb41163eec88b3bd835108bd80140ff086.tar.bz2
introduce a more sophisticated channel hopping scheme
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp41
-rw-r--r--libopie2/opienet/onetwork.h6
2 files changed, 36 insertions, 11 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 50d67bb..ac2857a 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,809 +1,832 @@
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 the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/onetwork.h> 36#include <opie2/onetwork.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qfile.h> 40#include <qfile.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42 42
43/* UNIX */ 43/* UNIX */
44 44
45#include <arpa/inet.h> 45#include <arpa/inet.h>
46#include <cerrno> 46#include <cerrno>
47#include <cstring> 47#include <cstring>
48#include <cstdlib> 48#include <cstdlib>
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 55
56using namespace std; 56using namespace std;
57 57
58/*====================================================================================== 58/*======================================================================================
59 * ONetwork 59 * ONetwork
60 *======================================================================================*/ 60 *======================================================================================*/
61 61
62ONetwork* ONetwork::_instance = 0; 62ONetwork* ONetwork::_instance = 0;
63 63
64ONetwork::ONetwork() 64ONetwork::ONetwork()
65{ 65{
66 qDebug( "ONetwork::ONetwork()" ); 66 qDebug( "ONetwork::ONetwork()" );
67 synchronize(); 67 synchronize();
68} 68}
69 69
70void ONetwork::synchronize() 70void ONetwork::synchronize()
71{ 71{
72 // gather available interfaces by inspecting /proc/net/dev 72 // gather available interfaces by inspecting /proc/net/dev
73 // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 73 // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
74 74
75 _interfaces.clear(); 75 _interfaces.clear();
76 QString str; 76 QString str;
77 QFile f( "/proc/net/dev" ); 77 QFile f( "/proc/net/dev" );
78 bool hasFile = f.open( IO_ReadOnly ); 78 bool hasFile = f.open( IO_ReadOnly );
79 if ( !hasFile ) 79 if ( !hasFile )
80 { 80 {
81 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); 81 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
82 return; 82 return;
83 } 83 }
84 QTextStream s( &f ); 84 QTextStream s( &f );
85 s.readLine(); 85 s.readLine();
86 s.readLine(); 86 s.readLine();
87 while ( !s.atEnd() ) 87 while ( !s.atEnd() )
88 { 88 {
89 s >> str; 89 s >> str;
90 str.truncate( str.find( ':' ) ); 90 str.truncate( str.find( ':' ) );
91 qDebug( "ONetwork: found interface '%s'", (const char*) str ); 91 qDebug( "ONetwork: found interface '%s'", (const char*) str );
92 ONetworkInterface* iface; 92 ONetworkInterface* iface;
93 if ( isWirelessInterface( str ) ) 93 if ( isWirelessInterface( str ) )
94 { 94 {
95 iface = new OWirelessNetworkInterface( str ); 95 iface = new OWirelessNetworkInterface( str );
96 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); 96 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str );
97 } 97 }
98 else 98 else
99 { 99 {
100 iface = new ONetworkInterface( str ); 100 iface = new ONetworkInterface( str );
101 } 101 }
102 _interfaces.insert( str, iface ); 102 _interfaces.insert( str, iface );
103 s.readLine(); 103 s.readLine();
104 } 104 }
105} 105}
106 106
107 107
108ONetworkInterface* ONetwork::interface( QString iface ) const 108ONetworkInterface* ONetwork::interface( QString iface ) const
109{ 109{
110 return _interfaces[iface]; 110 return _interfaces[iface];
111} 111}
112 112
113 113
114ONetwork* ONetwork::instance() 114ONetwork* ONetwork::instance()
115{ 115{
116 if ( !_instance ) _instance = new ONetwork(); 116 if ( !_instance ) _instance = new ONetwork();
117 return _instance; 117 return _instance;
118} 118}
119 119
120 120
121ONetwork::InterfaceIterator ONetwork::iterator() const 121ONetwork::InterfaceIterator ONetwork::iterator() const
122{ 122{
123 return ONetwork::InterfaceIterator( _interfaces ); 123 return ONetwork::InterfaceIterator( _interfaces );
124} 124}
125 125
126 126
127bool ONetwork::isWirelessInterface( const char* name ) const 127bool ONetwork::isWirelessInterface( const char* name ) const
128{ 128{
129 int sfd = socket( AF_INET, SOCK_DGRAM, 0 ); 129 int sfd = socket( AF_INET, SOCK_DGRAM, 0 );
130 iwreqstruct iwr; 130 iwreqstruct iwr;
131 memset( &iwr, 0, sizeof( iwreqstruct ) ); 131 memset( &iwr, 0, sizeof( iwreqstruct ) );
132 strcpy( (char*) &iwr.ifr_name, name ); 132 strcpy( (char*) &iwr.ifr_name, name );
133 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 133 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
134 if ( result == -1 ) 134 if ( result == -1 )
135 qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); 135 qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) );
136 else 136 else
137 qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); 137 qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." );
138 return ( result != -1 ); 138 return ( result != -1 );
139} 139}
140 140
141/*====================================================================================== 141/*======================================================================================
142 * ONetworkInterface 142 * ONetworkInterface
143 *======================================================================================*/ 143 *======================================================================================*/
144 144
145ONetworkInterface::ONetworkInterface( const QString& name ) 145ONetworkInterface::ONetworkInterface( const QString& name )
146 :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 146 :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
147{ 147{
148 qDebug( "ONetworkInterface::ONetworkInterface()" ); 148 qDebug( "ONetworkInterface::ONetworkInterface()" );
149 init(); 149 init();
150} 150}
151 151
152 152
153ifreqstruct& ONetworkInterface::ifr() const 153ifreqstruct& ONetworkInterface::ifr() const
154{ 154{
155 return _ifr; 155 return _ifr;
156} 156}
157 157
158 158
159void ONetworkInterface::init() 159void ONetworkInterface::init()
160{ 160{
161 qDebug( "ONetworkInterface::init()" ); 161 qDebug( "ONetworkInterface::init()" );
162 162
163 memset( &_ifr, 0, sizeof( struct ifreq ) ); 163 memset( &_ifr, 0, sizeof( struct ifreq ) );
164 164
165 if ( _sfd == -1 ) 165 if ( _sfd == -1 )
166 { 166 {
167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name ); 167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name );
168 return; 168 return;
169 } 169 }
170} 170}
171 171
172 172
173bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const 173bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const
174{ 174{
175 int result = ::ioctl( _sfd, call, &ifreq ); 175 int result = ::ioctl( _sfd, call, &ifreq );
176 if ( result == -1 ) 176 if ( result == -1 )
177 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 177 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) );
178 else 178 else
179 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); 179 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call );
180 return ( result != -1 ); 180 return ( result != -1 );
181} 181}
182 182
183 183
184bool ONetworkInterface::ioctl( int call ) const 184bool ONetworkInterface::ioctl( int call ) const
185{ 185{
186 strcpy( _ifr.ifr_name, (const char*) _name ); 186 strcpy( _ifr.ifr_name, (const char*) _name );
187 return ioctl( call, _ifr ); 187 return ioctl( call, _ifr );
188} 188}
189 189
190 190
191bool ONetworkInterface::isLoopback() const 191bool ONetworkInterface::isLoopback() const
192{ 192{
193 ioctl( SIOCGIFFLAGS ); 193 ioctl( SIOCGIFFLAGS );
194 return _ifr.ifr_flags & IFF_LOOPBACK; 194 return _ifr.ifr_flags & IFF_LOOPBACK;
195} 195}
196 196
197 197
198bool ONetworkInterface::setUp( bool b ) 198bool ONetworkInterface::setUp( bool b )
199{ 199{
200 ioctl( SIOCGIFFLAGS ); 200 ioctl( SIOCGIFFLAGS );
201 if ( b ) _ifr.ifr_flags |= IFF_UP; 201 if ( b ) _ifr.ifr_flags |= IFF_UP;
202 else _ifr.ifr_flags &= (~IFF_UP); 202 else _ifr.ifr_flags &= (~IFF_UP);
203 return ioctl( SIOCSIFFLAGS ); 203 return ioctl( SIOCSIFFLAGS );
204} 204}
205 205
206 206
207bool ONetworkInterface::isUp() const 207bool ONetworkInterface::isUp() const
208{ 208{
209 ioctl( SIOCGIFFLAGS ); 209 ioctl( SIOCGIFFLAGS );
210 return _ifr.ifr_flags & IFF_UP; 210 return _ifr.ifr_flags & IFF_UP;
211} 211}
212 212
213 213
214QString ONetworkInterface::ipV4Address() const 214QString ONetworkInterface::ipV4Address() const
215{ 215{
216 if ( ioctl( SIOCGIFADDR ) ) 216 if ( ioctl( SIOCGIFADDR ) )
217 { 217 {
218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
219 //FIXME: Use QHostAddress here 219 //FIXME: Use QHostAddress here
220 return QString( inet_ntoa( sa->sin_addr ) ); 220 return QString( inet_ntoa( sa->sin_addr ) );
221 } 221 }
222 else 222 else
223 return "<unknown>"; 223 return "<unknown>";
224} 224}
225 225
226 226
227OMacAddress ONetworkInterface::macAddress() const 227OMacAddress ONetworkInterface::macAddress() const
228{ 228{
229 if ( ioctl( SIOCGIFHWADDR ) ) 229 if ( ioctl( SIOCGIFHWADDR ) )
230 { 230 {
231 return OMacAddress( _ifr ); 231 return OMacAddress( _ifr );
232 } 232 }
233 else 233 else
234 { 234 {
235 return OMacAddress::unknown; 235 return OMacAddress::unknown;
236 } 236 }
237} 237}
238 238
239 239
240void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 240void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
241{ 241{
242 _mon = m; 242 _mon = m;
243 qDebug( "ONetwork::setMonitoring(): Installed monitoring interface '%s'", (const char*) m->name() ); 243 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), (const char*) _name );
244} 244}
245 245
246 246
247OMonitoringInterface* ONetworkInterface::monitoring() const 247OMonitoringInterface* ONetworkInterface::monitoring() const
248{ 248{
249 return _mon; 249 return _mon;
250} 250}
251 251
252 252
253const QString& ONetworkInterface::name() const 253const QString& ONetworkInterface::name() const
254{ 254{
255 return _name; 255 return _name;
256} 256}
257 257
258 258
259ONetworkInterface::~ONetworkInterface() 259ONetworkInterface::~ONetworkInterface()
260{ 260{
261 qDebug( "ONetworkInterface::~ONetworkInterface()" ); 261 qDebug( "ONetworkInterface::~ONetworkInterface()" );
262 if ( _sfd != -1 ) ::close( _sfd ); 262 if ( _sfd != -1 ) ::close( _sfd );
263} 263}
264 264
265 265
266bool ONetworkInterface::setPromiscuousMode( bool b ) 266bool ONetworkInterface::setPromiscuousMode( bool b )
267{ 267{
268 ioctl( SIOCGIFFLAGS ); 268 ioctl( SIOCGIFFLAGS );
269 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 269 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
270 else _ifr.ifr_flags &= (~IFF_PROMISC); 270 else _ifr.ifr_flags &= (~IFF_PROMISC);
271 return ioctl( SIOCSIFFLAGS ); 271 return ioctl( SIOCSIFFLAGS );
272} 272}
273 273
274 274
275bool ONetworkInterface::promiscuousMode() const 275bool ONetworkInterface::promiscuousMode() const
276{ 276{
277 ioctl( SIOCGIFFLAGS ); 277 ioctl( SIOCGIFFLAGS );
278 return _ifr.ifr_flags & IFF_PROMISC; 278 return _ifr.ifr_flags & IFF_PROMISC;
279} 279}
280 280
281 281
282bool ONetworkInterface::isWireless() const 282bool ONetworkInterface::isWireless() const
283{ 283{
284 return ioctl( SIOCGIWNAME ); 284 return ioctl( SIOCGIWNAME );
285} 285}
286 286
287 287
288/*====================================================================================== 288/*======================================================================================
289 * OChannelHopper 289 * OChannelHopper
290 *======================================================================================*/ 290 *======================================================================================*/
291 291
292OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 292OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
293 :QObject( 0, "Mickey's funky hopper" ), 293 :QObject( 0, "Mickey's funky hopper" ),
294 _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ), 294 _iface( iface ), _interval( 0 ), _tid( 0 )
295 _maxChannel( iface->channels()+1 )
296{ 295{
296 int _maxChannel = iface->channels()+1;
297 // generate fancy hopping sequence honoring the device capabilities
298 if ( _maxChannel >= 1 ) _channels.append( 1 );
299 if ( _maxChannel >= 7 ) _channels.append( 7 );
300 if ( _maxChannel >= 13 ) _channels.append( 13 );
301 if ( _maxChannel >= 2 ) _channels.append( 2 );
302 if ( _maxChannel >= 8 ) _channels.append( 8 );
303 if ( _maxChannel >= 3 ) _channels.append( 3 );
304 if ( _maxChannel >= 14 ) _channels.append( 14 );
305 if ( _maxChannel >= 9 ) _channels.append( 9 );
306 if ( _maxChannel >= 4 ) _channels.append( 4 );
307 if ( _maxChannel >= 10 ) _channels.append( 10 );
308 if ( _maxChannel >= 5 ) _channels.append( 5 );
309 if ( _maxChannel >= 11 ) _channels.append( 11 );
310 if ( _maxChannel >= 6 ) _channels.append( 6 );
311 if ( _maxChannel >= 12 ) _channels.append( 12 );
312 _channel = _channels.begin();
313
297} 314}
298 315
299 316
300OChannelHopper::~OChannelHopper() 317OChannelHopper::~OChannelHopper()
301{ 318{
302} 319}
303 320
304 321
305bool OChannelHopper::isActive() const 322bool OChannelHopper::isActive() const
306{ 323{
307 return _tid; 324 return _tid;
308} 325}
309 326
310 327
311int OChannelHopper::channel() const 328int OChannelHopper::channel() const
312{ 329{
313 return _channel; 330 return *_channel;
314} 331}
315 332
316 333
317void OChannelHopper::timerEvent( QTimerEvent* ) 334void OChannelHopper::timerEvent( QTimerEvent* )
318{ 335{
319 if ( !--_channel ) _channel = _maxChannel; 336 _iface->setChannel( *_channel );
320 _iface->setChannel( _channel );
321 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", 337 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
322 _channel, (const char*) _iface->name() ); 338 *_channel, (const char*) _iface->name() );
339 if ( ++_channel == _channels.end() ) _channel = _channels.begin();
323} 340}
324 341
325 342
326void OChannelHopper::setInterval( int interval ) 343void OChannelHopper::setInterval( int interval )
327{ 344{
328 if ( interval == _interval ) 345 if ( interval == _interval )
329 return; 346 return;
330 347
331 if ( _interval ) 348 if ( _interval )
332 killTimer( _tid ); 349 killTimer( _tid );
333 350
334 _tid = 0; 351 _tid = 0;
335 _interval = interval; 352 _interval = interval;
336 353
337 if ( _interval ) 354 if ( _interval )
338 { 355 {
339 _tid = startTimer( interval ); 356 _tid = startTimer( interval );
340 } 357 }
341} 358}
342 359
343 360
344int OChannelHopper::interval() const 361int OChannelHopper::interval() const
345{ 362{
346 return _interval; 363 return _interval;
347} 364}
348 365
349 366
350/*====================================================================================== 367/*======================================================================================
351 * OWirelessNetworkInterface 368 * OWirelessNetworkInterface
352 *======================================================================================*/ 369 *======================================================================================*/
353 370
354OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) 371OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name )
355 :ONetworkInterface( name ), _hopper( 0 ) 372 :ONetworkInterface( name ), _hopper( 0 )
356{ 373{
357 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 374 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
358 init(); 375 init();
359} 376}
360 377
361 378
362OWirelessNetworkInterface::~OWirelessNetworkInterface() 379OWirelessNetworkInterface::~OWirelessNetworkInterface()
363{ 380{
364} 381}
365 382
366 383
367iwreqstruct& OWirelessNetworkInterface::iwr() const 384iwreqstruct& OWirelessNetworkInterface::iwr() const
368{ 385{
369 return _iwr; 386 return _iwr;
370} 387}
371 388
372 389
373void OWirelessNetworkInterface::init() 390void OWirelessNetworkInterface::init()
374{ 391{
375 qDebug( "OWirelessNetworkInterface::init()" ); 392 qDebug( "OWirelessNetworkInterface::init()" );
376 393
377 memset( &_iwr, 0, sizeof( struct iwreq ) ); 394 memset( &_iwr, 0, sizeof( struct iwreq ) );
378 395
379 // IEEE802.11(b) radio frequency channels 396 // IEEE802.11(b) radio frequency channels
380 397
381 iwrangestruct range; 398 iwrangestruct range;
382 //ML: work around an ugly HostAP bug, which needs 399 //ML: work around an ugly HostAP bug, which needs
383 //ML: extra space or will complain with "invalid argument length"... :-( 400 //ML: extra space or will complain with "invalid argument length"... :-(
384 char __extraBufferForBuggyDrivers[sizeof range]; 401 //ML: But don't allocate too much or prism2_usb will segfault *sigh*
402 char __extraBufferForBuggyDrivers[20];
403
404 qDebug( "sizeof(iwrangestruct)=%d, sizeof range=%d, sizeof range*2=%d", sizeof(iwrangestruct), sizeof range, (sizeof range)*2 );
405
385 _iwr.u.data.pointer = (char*) &range; 406 _iwr.u.data.pointer = (char*) &range;
386 _iwr.u.data.length = (sizeof range) * 2; 407 _iwr.u.data.length = sizeof(iwrangestruct)+20;
387 _iwr.u.data.flags = 0; 408 _iwr.u.data.flags = 0;
388 if ( !wioctl( SIOCGIWRANGE ) ) 409 if ( !wioctl( SIOCGIWRANGE ) )
389 { 410 {
390 qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); 411 qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) );
391 return; 412 return;
392 } 413 }
393 414
415 qDebug( "OWirelessNetworkInterface::init(): Interface %s reported to have %d channels.", (const char*) _name, range.num_frequency );
416
394 for ( int i = 0; i < range.num_frequency; ++i ) 417 for ( int i = 0; i < range.num_frequency; ++i )
395 { 418 {
396 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 419 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
397 _channels.insert( freq, i+1 ); 420 _channels.insert( freq, i+1 );
398 } 421 }
399} 422}
400 423
401 424
402QString OWirelessNetworkInterface::associatedAP() const 425QString OWirelessNetworkInterface::associatedAP() const
403{ 426{
404 //FIXME: use OMacAddress 427 //FIXME: use OMacAddress
405 QString mac; 428 QString mac;
406 429
407 if ( ioctl( SIOCGIWAP ) ) 430 if ( ioctl( SIOCGIWAP ) )
408 { 431 {
409 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 432 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
410 _ifr.ifr_hwaddr.sa_data[0]&0xff, 433 _ifr.ifr_hwaddr.sa_data[0]&0xff,
411 _ifr.ifr_hwaddr.sa_data[1]&0xff, 434 _ifr.ifr_hwaddr.sa_data[1]&0xff,
412 _ifr.ifr_hwaddr.sa_data[2]&0xff, 435 _ifr.ifr_hwaddr.sa_data[2]&0xff,
413 _ifr.ifr_hwaddr.sa_data[3]&0xff, 436 _ifr.ifr_hwaddr.sa_data[3]&0xff,
414 _ifr.ifr_hwaddr.sa_data[4]&0xff, 437 _ifr.ifr_hwaddr.sa_data[4]&0xff,
415 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 438 _ifr.ifr_hwaddr.sa_data[5]&0xff );
416 } 439 }
417 else 440 else
418 { 441 {
419 mac = "<Unknown>"; 442 mac = "<Unknown>";
420 } 443 }
421 return mac; 444 return mac;
422} 445}
423 446
424 447
425int OWirelessNetworkInterface::channel() const 448int OWirelessNetworkInterface::channel() const
426{ 449{
427 //FIXME: When monitoring enabled, then use it 450 //FIXME: When monitoring enabled, then use it
428 //FIXME: to gather the current RF channel 451 //FIXME: to gather the current RF channel
429 //FIXME: Until then, get active channel from hopper. 452 //FIXME: Until then, get active channel from hopper.
430 if ( _hopper && _hopper->isActive() ) 453 if ( _hopper && _hopper->isActive() )
431 return _hopper->channel(); 454 return _hopper->channel();
432 455
433 if ( !wioctl( SIOCGIWFREQ ) ) 456 if ( !wioctl( SIOCGIWFREQ ) )
434 { 457 {
435 return -1; 458 return -1;
436 } 459 }
437 else 460 else
438 { 461 {
439 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 462 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
440 } 463 }
441} 464}
442 465
443 466
444void OWirelessNetworkInterface::setChannel( int c ) const 467void OWirelessNetworkInterface::setChannel( int c ) const
445{ 468{
446 if ( !_mon ) 469 if ( !_mon )
447 { 470 {
448 memset( &_iwr, 0, sizeof( iwreqstruct ) ); 471 memset( &_iwr, 0, sizeof( iwreqstruct ) );
449 _iwr.u.freq.m = c; 472 _iwr.u.freq.m = c;
450 _iwr.u.freq.e = 0; 473 _iwr.u.freq.e = 0;
451 wioctl( SIOCSIWFREQ ); 474 wioctl( SIOCSIWFREQ );
452 } 475 }
453 else 476 else
454 { 477 {
455 _mon->setChannel( c ); 478 _mon->setChannel( c );
456 } 479 }
457} 480}
458 481
459 482
460double OWirelessNetworkInterface::frequency() const 483double OWirelessNetworkInterface::frequency() const
461{ 484{
462 if ( !wioctl( SIOCGIWFREQ ) ) 485 if ( !wioctl( SIOCGIWFREQ ) )
463 { 486 {
464 return -1.0; 487 return -1.0;
465 } 488 }
466 else 489 else
467 { 490 {
468 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 491 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
469 } 492 }
470} 493}
471 494
472 495
473int OWirelessNetworkInterface::channels() const 496int OWirelessNetworkInterface::channels() const
474{ 497{
475 return _channels.count(); 498 return _channels.count();
476} 499}
477 500
478 501
479void OWirelessNetworkInterface::setChannelHopping( int interval ) 502void OWirelessNetworkInterface::setChannelHopping( int interval )
480{ 503{
481 if ( !_hopper ) _hopper = new OChannelHopper( this ); 504 if ( !_hopper ) _hopper = new OChannelHopper( this );
482 _hopper->setInterval( interval ); 505 _hopper->setInterval( interval );
483 //FIXME: When and by whom will the channel hopper be deleted? 506 //FIXME: When and by whom will the channel hopper be deleted?
484} 507}
485 508
486 509
487int OWirelessNetworkInterface::channelHopping() const 510int OWirelessNetworkInterface::channelHopping() const
488{ 511{
489 return _hopper->interval(); 512 return _hopper->interval();
490} 513}
491 514
492 515
493void OWirelessNetworkInterface::setMonitorMode( bool b ) 516void OWirelessNetworkInterface::setMonitorMode( bool b )
494{ 517{
495 if ( _mon ) 518 if ( _mon )
496 _mon->setEnabled( b ); 519 _mon->setEnabled( b );
497 else 520 else
498 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 521 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
499} 522}
500 523
501 524
502bool OWirelessNetworkInterface::monitorMode() const 525bool OWirelessNetworkInterface::monitorMode() const
503{ 526{
504 return _mon ? _mon->enabled() : false; 527 return _mon ? _mon->enabled() : false;
505} 528}
506 529
507 530
508QString OWirelessNetworkInterface::nickName() const 531QString OWirelessNetworkInterface::nickName() const
509{ 532{
510 char str[IW_ESSID_MAX_SIZE]; 533 char str[IW_ESSID_MAX_SIZE];
511 _iwr.u.data.pointer = &str[0]; 534 _iwr.u.data.pointer = &str[0];
512 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 535 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
513 if ( !wioctl( SIOCGIWNICKN ) ) 536 if ( !wioctl( SIOCGIWNICKN ) )
514 { 537 {
515 return "<unknown>"; 538 return "<unknown>";
516 } 539 }
517 else 540 else
518 { 541 {
519 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 542 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
520 return str; 543 return str;
521 } 544 }
522} 545}
523 546
524 547
525QString OWirelessNetworkInterface::SSID() const 548QString OWirelessNetworkInterface::SSID() const
526{ 549{
527 char str[IW_ESSID_MAX_SIZE]; 550 char str[IW_ESSID_MAX_SIZE];
528 _iwr.u.essid.pointer = &str[0]; 551 _iwr.u.essid.pointer = &str[0];
529 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 552 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
530 if ( !wioctl( SIOCGIWESSID ) ) 553 if ( !wioctl( SIOCGIWESSID ) )
531 { 554 {
532 return "<unknown>"; 555 return "<unknown>";
533 } 556 }
534 else 557 else
535 { 558 {
536 return str; 559 return str;
537 } 560 }
538} 561}
539 562
540 563
541void OWirelessNetworkInterface::setSSID( const QString& ssid ) 564void OWirelessNetworkInterface::setSSID( const QString& ssid )
542{ 565{
543 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 566 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
544 _iwr.u.essid.length = ssid.length(); 567 _iwr.u.essid.length = ssid.length();
545 wioctl( SIOCSIWESSID ); 568 wioctl( SIOCSIWESSID );
546} 569}
547 570
548 571
549bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const 572bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const
550{ 573{
551 int result = ::ioctl( _sfd, call, &iwreq ); 574 int result = ::ioctl( _sfd, call, &iwreq );
552 if ( result == -1 ) 575 if ( result == -1 )
553 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 576 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) );
554 else 577 else
555 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); 578 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call );
556 return ( result != -1 ); 579 return ( result != -1 );
557} 580}
558 581
559 582
560bool OWirelessNetworkInterface::wioctl( int call ) const 583bool OWirelessNetworkInterface::wioctl( int call ) const
561{ 584{
562 strcpy( _iwr.ifr_name, (const char*) _name ); 585 strcpy( _iwr.ifr_name, (const char*) _name );
563 return wioctl( call, _iwr ); 586 return wioctl( call, _iwr );
564} 587}
565 588
566 589
567/*====================================================================================== 590/*======================================================================================
568 * OMonitoringInterface 591 * OMonitoringInterface
569 *======================================================================================*/ 592 *======================================================================================*/
570 593
571OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) 594OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface )
572 :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) 595 :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) )
573{ 596{
574} 597}
575 598
576 599
577OMonitoringInterface::~OMonitoringInterface() 600OMonitoringInterface::~OMonitoringInterface()
578{ 601{
579} 602}
580 603
581 604
582void OMonitoringInterface::setChannel( int c ) 605void OMonitoringInterface::setChannel( int c )
583{ 606{
584 // use standard WE channel switching protocol 607 // use standard WE channel switching protocol
585 memset( &_if->_iwr, 0, sizeof( iwreqstruct ) ); 608 memset( &_if->_iwr, 0, sizeof( iwreqstruct ) );
586 _if->_iwr.u.freq.m = c; 609 _if->_iwr.u.freq.m = c;
587 _if->_iwr.u.freq.e = 0; 610 _if->_iwr.u.freq.e = 0;
588 _if->wioctl( SIOCSIWFREQ ); 611 _if->wioctl( SIOCSIWFREQ );
589} 612}
590 613
591 614
592bool OMonitoringInterface::enabled() const 615bool OMonitoringInterface::enabled() const
593{ 616{
594 return _enabled; 617 return _enabled;
595} 618}
596 619
597void OMonitoringInterface::setEnabled( bool b ) 620void OMonitoringInterface::setEnabled( bool b )
598{ 621{
599 // open a packet capturer here or leave this to 622 // open a packet capturer here or leave this to
600 // the client code? 623 // the client code?
601 624
602 /* 625 /*
603 626
604 if ( b ) 627 if ( b )
605 { 628 {
606 OPacketCapturer* opcap = new OPacketCapturer(); 629 OPacketCapturer* opcap = new OPacketCapturer();
607 opcap->open( _if->name() ); 630 opcap->open( _if->name() );
608 } 631 }
609 */ 632 */
610 633
611 _enabled = b; 634 _enabled = b;
612 635
613} 636}
614 637
615/*====================================================================================== 638/*======================================================================================
616 * OCiscoMonitoringInterface 639 * OCiscoMonitoringInterface
617 *======================================================================================*/ 640 *======================================================================================*/
618 641
619OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) 642OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface )
620 :OMonitoringInterface( iface ) 643 :OMonitoringInterface( iface )
621{ 644{
622 iface->setMonitoring( this ); 645 iface->setMonitoring( this );
623} 646}
624 647
625 648
626OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 649OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
627{ 650{
628} 651}
629 652
630 653
631void OCiscoMonitoringInterface::setEnabled( bool b ) 654void OCiscoMonitoringInterface::setEnabled( bool b )
632{ 655{
633 QString fname; 656 QString fname;
634 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 657 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
635 QFile f( fname ); 658 QFile f( fname );
636 if ( !f.exists() ) return; 659 if ( !f.exists() ) return;
637 660
638 if ( f.open( IO_WriteOnly ) ) 661 if ( f.open( IO_WriteOnly ) )
639 { 662 {
640 QTextStream s( &f ); 663 QTextStream s( &f );
641 s << "Mode: r"; 664 s << "Mode: r";
642 s << "Mode: y"; 665 s << "Mode: y";
643 s << "XmitPower: 1"; 666 s << "XmitPower: 1";
644 667
645 OMonitoringInterface::setEnabled( b ); 668 OMonitoringInterface::setEnabled( b );
646 669
647 } 670 }
648 671
649 // flushing and closing will be done automatically when f goes out of scope 672 // flushing and closing will be done automatically when f goes out of scope
650} 673}
651 674
652 675
653QString OCiscoMonitoringInterface::name() const 676QString OCiscoMonitoringInterface::name() const
654{ 677{
655 return "cisco"; 678 return "cisco";
656} 679}
657 680
658 681
659void OCiscoMonitoringInterface::setChannel( int ) 682void OCiscoMonitoringInterface::setChannel( int )
660{ 683{
661 // cisco devices automatically switch channels when in monitor mode 684 // cisco devices automatically switch channels when in monitor mode
662} 685}
663 686
664 687
665/*====================================================================================== 688/*======================================================================================
666 * OWlanNGMonitoringInterface 689 * OWlanNGMonitoringInterface
667 *======================================================================================*/ 690 *======================================================================================*/
668 691
669 692
670OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) 693OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface )
671 :OMonitoringInterface( iface ) 694 :OMonitoringInterface( iface )
672{ 695{
673 iface->setMonitoring( this ); 696 iface->setMonitoring( this );
674} 697}
675 698
676 699
677OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 700OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
678{ 701{
679} 702}
680 703
681 704
682void OWlanNGMonitoringInterface::setEnabled( bool b ) 705void OWlanNGMonitoringInterface::setEnabled( bool b )
683{ 706{
684 //FIXME: do nothing if its already in the same mode 707 //FIXME: do nothing if its already in the same mode
685 708
686 QString enable = b ? "true" : "false"; 709 QString enable = b ? "true" : "false";
687 QString cmd; 710 QString cmd;
688 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); 711 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable );
689 system( cmd ); 712 system( cmd );
690 713
691 OMonitoringInterface::setEnabled( b ); 714 OMonitoringInterface::setEnabled( b );
692} 715}
693 716
694 717
695QString OWlanNGMonitoringInterface::name() const 718QString OWlanNGMonitoringInterface::name() const
696{ 719{
697 return "wlan-ng"; 720 return "wlan-ng";
698} 721}
699 722
700 723
701void OWlanNGMonitoringInterface::setChannel( int ) 724void OWlanNGMonitoringInterface::setChannel( int )
702{ 725{
703 // wlan-ng devices automatically switch channels when in monitor mode 726 // wlan-ng devices automatically switch channels when in monitor mode
704} 727}
705 728
706 729
707/*====================================================================================== 730/*======================================================================================
708 * OHostAPMonitoringInterface 731 * OHostAPMonitoringInterface
709 *======================================================================================*/ 732 *======================================================================================*/
710 733
711OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) 734OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface )
712 :OMonitoringInterface( iface ) 735 :OMonitoringInterface( iface )
713{ 736{
714 iface->setMonitoring( this ); 737 iface->setMonitoring( this );
715} 738}
716 739
717OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 740OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
718{ 741{
719} 742}
720 743
721void OHostAPMonitoringInterface::setEnabled( bool b ) 744void OHostAPMonitoringInterface::setEnabled( bool b )
722{ 745{
723 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 746 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
724 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 747 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
725 748
726 if ( b ) 749 if ( b )
727 { 750 {
728 #if WIRELESS_EXT > 14 751 #if WIRELESS_EXT > 14
729 _if->_iwr.u.mode = IW_MODE_MONITOR; 752 _if->_iwr.u.mode = IW_MODE_MONITOR;
730 _if->wioctl( SIOCSIWMODE ); 753 _if->wioctl( SIOCSIWMODE );
731 #else 754 #else
732 int* args = (int*) &_if->_iwr.u.name; 755 int* args = (int*) &_if->_iwr.u.name;
733 args[0] = 2; 756 args[0] = 2;
734 args[1] = 0; 757 args[1] = 0;
735 _if->wioctl( SIOCDEVPRIVATE ); 758 _if->wioctl( SIOCDEVPRIVATE );
736 #endif 759 #endif
737 } 760 }
738 else 761 else
739 { 762 {
740 #if WIRELESS_EXT > 14 763 #if WIRELESS_EXT > 14
741 _if->_iwr.u.mode = IW_MODE_INFRA; 764 _if->_iwr.u.mode = IW_MODE_INFRA;
742 _if->wioctl( SIOCSIWMODE ); 765 _if->wioctl( SIOCSIWMODE );
743 #else 766 #else
744 int* args = (int*) &_if->_iwr.u.name; 767 int* args = (int*) &_if->_iwr.u.name;
745 args[0] = 0; 768 args[0] = 0;
746 args[1] = 0; 769 args[1] = 0;
747 _if->wioctl( SIOCDEVPRIVATE ); 770 _if->wioctl( SIOCDEVPRIVATE );
748 #endif 771 #endif
749 } 772 }
750 773
751 OMonitoringInterface::setEnabled( b ); 774 OMonitoringInterface::setEnabled( b );
752} 775}
753 776
754 777
755QString OHostAPMonitoringInterface::name() const 778QString OHostAPMonitoringInterface::name() const
756{ 779{
757 return "hostap"; 780 return "hostap";
758} 781}
759 782
760 783
761/*====================================================================================== 784/*======================================================================================
762 * OOrinocoNetworkInterface 785 * OOrinocoNetworkInterface
763 *======================================================================================*/ 786 *======================================================================================*/
764 787
765OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) 788OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface )
766 :OMonitoringInterface( iface ) 789 :OMonitoringInterface( iface )
767{ 790{
768 iface->setMonitoring( this ); 791 iface->setMonitoring( this );
769} 792}
770 793
771 794
772OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 795OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
773{ 796{
774} 797}
775 798
776 799
777void OOrinocoMonitoringInterface::setChannel( int c ) 800void OOrinocoMonitoringInterface::setChannel( int c )
778{ 801{
779 // call iwpriv <device> monitor 2 <channel> 802 // call iwpriv <device> monitor 2 <channel>
780 int* args = (int*) &_if->_iwr.u.name; 803 int* args = (int*) &_if->_iwr.u.name;
781 args[0] = 2; 804 args[0] = 2;
782 args[1] = c; 805 args[1] = c;
783 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); 806 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
784} 807}
785 808
786 809
787void OOrinocoMonitoringInterface::setEnabled( bool b ) 810void OOrinocoMonitoringInterface::setEnabled( bool b )
788{ 811{
789 if ( b ) 812 if ( b )
790 { 813 {
791 setChannel( 1 ); 814 setChannel( 1 );
792 } 815 }
793 else 816 else
794 { 817 {
795 // call iwpriv <device> monitor 0 0 818 // call iwpriv <device> monitor 0 0
796 int* args = (int*) &_if->_iwr.u.name; 819 int* args = (int*) &_if->_iwr.u.name;
797 args[0] = 0; 820 args[0] = 0;
798 args[1] = 0; 821 args[1] = 0;
799 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); 822 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
800 } 823 }
801 824
802 OMonitoringInterface::setEnabled( b ); 825 OMonitoringInterface::setEnabled( b );
803} 826}
804 827
805 828
806QString OOrinocoMonitoringInterface::name() const 829QString OOrinocoMonitoringInterface::name() const
807{ 830{
808 return "orinoco"; 831 return "orinoco";
809} 832}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index c544454..b57ac3f 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -1,321 +1,323 @@
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 the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef ONETWORK_H 34#ifndef ONETWORK_H
35#define ONETWORK_H 35#define ONETWORK_H
36 36
37/* QT */ 37/* QT */
38 38
39#include <qvaluelist.h>
39#include <qdict.h> 40#include <qdict.h>
40#include <qmap.h> 41#include <qmap.h>
41#include <qobject.h> 42#include <qobject.h>
42#include <qhostaddress.h> 43#include <qhostaddress.h>
43 44
44/* OPIE */ 45/* OPIE */
45 46
46#include <opie2/onetutils.h> 47#include <opie2/onetutils.h>
47 48
48#ifndef IFNAMSIZ 49#ifndef IFNAMSIZ
49#define IFNAMSIZ 16 50#define IFNAMSIZ 16
50#endif 51#endif
51 52
52// ML: Yeah, I hate to include kernel headers, but it's necessary here 53// ML: Yeah, I hate to include kernel headers, but it's necessary here
53// ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> 54// ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h>
54// ML: which conflicts with the user header <net/if.h> 55// ML: which conflicts with the user header <net/if.h>
55// ML: We really a user header for the Wireless Extensions, something like <net/wireless.h> 56// ML: We really a user header for the Wireless Extensions, something like <net/wireless.h>
56// ML: I will drop Jean an mail on that subject 57// ML: I will drop Jean an mail on that subject
57 58
58#include <net/if.h> 59#include <net/if.h>
59#define _LINUX_IF_H 60#define _LINUX_IF_H
60#include <linux/wireless.h> 61#include <linux/wireless.h>
61 62
62#ifndef SIOCIWFIRSTPRIV 63#ifndef SIOCIWFIRSTPRIV
63#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE 64#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
64#endif 65#endif
65 66
66class ONetworkInterface; 67class ONetworkInterface;
67class OWirelessNetworkInterface; 68class OWirelessNetworkInterface;
68class OChannelHopper; 69class OChannelHopper;
69class OMonitoringInterface; 70class OMonitoringInterface;
70 71
71typedef struct ifreq ifreqstruct; 72typedef struct ifreq ifreqstruct;
72typedef struct iwreq iwreqstruct; 73typedef struct iwreq iwreqstruct;
73typedef struct iw_event iweventstruct; 74typedef struct iw_event iweventstruct;
74typedef struct iw_freq iwfreqstruct; 75typedef struct iw_freq iwfreqstruct;
75typedef struct iw_priv_args iwprivargsstruct; 76typedef struct iw_priv_args iwprivargsstruct;
76typedef struct iw_range iwrangestruct; 77typedef struct iw_range iwrangestruct;
77 78
78/*====================================================================================== 79/*======================================================================================
79 * ONetwork 80 * ONetwork
80 *======================================================================================*/ 81 *======================================================================================*/
81 82
82class ONetwork : public QObject 83class ONetwork : public QObject
83{ 84{
84 Q_OBJECT 85 Q_OBJECT
85 86
86 public: 87 public:
87 typedef QDict<ONetworkInterface> InterfaceMap; 88 typedef QDict<ONetworkInterface> InterfaceMap;
88 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 89 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
89 90
90 public: 91 public:
91 static ONetwork* instance(); 92 static ONetwork* instance();
92 InterfaceIterator iterator() const; 93 InterfaceIterator iterator() const;
93 bool isWirelessInterface( const char* ) const; 94 bool isWirelessInterface( const char* ) const;
94 ONetworkInterface* interface( QString ) const; 95 ONetworkInterface* interface( QString ) const;
95 96
96 protected: 97 protected:
97 ONetwork(); 98 ONetwork();
98 void synchronize(); 99 void synchronize();
99 100
100 private: 101 private:
101 static ONetwork* _instance; 102 static ONetwork* _instance;
102 InterfaceMap _interfaces; 103 InterfaceMap _interfaces;
103}; 104};
104 105
105 106
106/*====================================================================================== 107/*======================================================================================
107 * ONetworkInterface 108 * ONetworkInterface
108 *======================================================================================*/ 109 *======================================================================================*/
109 110
110class ONetworkInterface 111class ONetworkInterface
111{ 112{
112 friend class OMonitoringInterface; 113 friend class OMonitoringInterface;
113 friend class OCiscoMonitoringInterface; 114 friend class OCiscoMonitoringInterface;
114 friend class OWlanNGMonitoringInterface; 115 friend class OWlanNGMonitoringInterface;
115 friend class OHostAPMonitoringInterface; 116 friend class OHostAPMonitoringInterface;
116 friend class OOrinocoMonitoringInterface; 117 friend class OOrinocoMonitoringInterface;
117 118
118 public: 119 public:
119 ONetworkInterface( const QString& name ); 120 ONetworkInterface( const QString& name );
120 virtual ~ONetworkInterface(); 121 virtual ~ONetworkInterface();
121 122
122 const QString& name() const; 123 const QString& name() const;
123 void setMonitoring( OMonitoringInterface* ); 124 void setMonitoring( OMonitoringInterface* );
124 OMonitoringInterface* monitoring() const; 125 OMonitoringInterface* monitoring() const;
125 bool setPromiscuousMode( bool ); 126 bool setPromiscuousMode( bool );
126 bool promiscuousMode() const; 127 bool promiscuousMode() const;
127 bool setUp( bool ); 128 bool setUp( bool );
128 bool isUp() const; 129 bool isUp() const;
129 bool isLoopback() const; 130 bool isLoopback() const;
130 bool isWireless() const; 131 bool isWireless() const;
131 QString ipV4Address() const; 132 QString ipV4Address() const;
132 OMacAddress macAddress() const; 133 OMacAddress macAddress() const;
133 134
134 protected: 135 protected:
135 const QString _name; 136 const QString _name;
136 const int _sfd; 137 const int _sfd;
137 mutable ifreqstruct _ifr; 138 mutable ifreqstruct _ifr;
138 OMonitoringInterface* _mon; 139 OMonitoringInterface* _mon;
139 140
140 protected: 141 protected:
141 ifreqstruct& ifr() const; 142 ifreqstruct& ifr() const;
142 virtual void init(); 143 virtual void init();
143 bool ioctl( int call ) const; 144 bool ioctl( int call ) const;
144 bool ioctl( int call, ifreqstruct& ) const; 145 bool ioctl( int call, ifreqstruct& ) const;
145}; 146};
146 147
147/*====================================================================================== 148/*======================================================================================
148 * OChannelHopper 149 * OChannelHopper
149 *======================================================================================*/ 150 *======================================================================================*/
150 151
151class OChannelHopper : public QObject 152class OChannelHopper : public QObject
152{ 153{
153 public: 154 public:
154 OChannelHopper( OWirelessNetworkInterface* ); 155 OChannelHopper( OWirelessNetworkInterface* );
155 virtual ~OChannelHopper(); 156 virtual ~OChannelHopper();
156 bool isActive() const; 157 bool isActive() const;
157 int channel() const; 158 int channel() const;
158 virtual void timerEvent( QTimerEvent* ); 159 virtual void timerEvent( QTimerEvent* );
159 void setInterval( int ); 160 void setInterval( int );
160 int interval() const; 161 int interval() const;
161 162
162 private: 163 private:
163 OWirelessNetworkInterface* _iface; 164 OWirelessNetworkInterface* _iface;
164 int _interval; 165 int _interval;
165 int _channel;
166 int _tid; 166 int _tid;
167 int _maxChannel; 167 QValueList<int> _channels;
168 QValueList<int>::Iterator _channel;
169
168}; 170};
169 171
170 172
171/*====================================================================================== 173/*======================================================================================
172 * OWirelessNetworkInterface 174 * OWirelessNetworkInterface
173 *======================================================================================*/ 175 *======================================================================================*/
174 176
175class OWirelessNetworkInterface : public ONetworkInterface 177class OWirelessNetworkInterface : public ONetworkInterface
176{ 178{
177 friend class OMonitoringInterface; 179 friend class OMonitoringInterface;
178 friend class OCiscoMonitoringInterface; 180 friend class OCiscoMonitoringInterface;
179 friend class OWlanNGMonitoringInterface; 181 friend class OWlanNGMonitoringInterface;
180 friend class OHostAPMonitoringInterface; 182 friend class OHostAPMonitoringInterface;
181 friend class OOrinocoMonitoringInterface; 183 friend class OOrinocoMonitoringInterface;
182 184
183 public: 185 public:
184 enum Mode { AdHoc, Managed, Monitor }; 186 enum Mode { AdHoc, Managed, Monitor };
185 187
186 OWirelessNetworkInterface( const QString& name ); 188 OWirelessNetworkInterface( const QString& name );
187 virtual ~OWirelessNetworkInterface(); 189 virtual ~OWirelessNetworkInterface();
188 190
189 virtual void setChannel( int ) const; 191 virtual void setChannel( int ) const;
190 virtual int channel() const; 192 virtual int channel() const;
191 virtual double frequency() const; 193 virtual double frequency() const;
192 virtual int channels() const; 194 virtual int channels() const;
193 //virtual double frequency(int) const; 195 //virtual double frequency(int) const;
194 196
195 virtual void setMode( Mode ) {}; 197 virtual void setMode( Mode ) {};
196 virtual bool mode() const {}; 198 virtual bool mode() const {};
197 199
198 virtual void setMonitorMode( bool ); 200 virtual void setMonitorMode( bool );
199 virtual bool monitorMode() const; 201 virtual bool monitorMode() const;
200 202
201 virtual void setChannelHopping( int interval = 0 ); 203 virtual void setChannelHopping( int interval = 0 );
202 virtual int channelHopping() const; 204 virtual int channelHopping() const;
203 205
204 virtual void setNickName( const QString& ) {}; 206 virtual void setNickName( const QString& ) {};
205 virtual QString nickName() const; 207 virtual QString nickName() const;
206 208
207 virtual bool isAssociated() const {}; 209 virtual bool isAssociated() const {};
208 virtual QString associatedAP() const; 210 virtual QString associatedAP() const;
209 211
210 virtual void setSSID( const QString& ); 212 virtual void setSSID( const QString& );
211 virtual QString SSID() const; 213 virtual QString SSID() const;
212 214
213 protected: 215 protected:
214 mutable iwreqstruct _iwr; 216 mutable iwreqstruct _iwr;
215 QMap<int,int> _channels; 217 QMap<int,int> _channels;
216 218
217 protected: 219 protected:
218 virtual void init(); 220 virtual void init();
219 iwreqstruct& iwr() const; 221 iwreqstruct& iwr() const;
220 bool wioctl( int call ) const; 222 bool wioctl( int call ) const;
221 bool wioctl( int call, iwreqstruct& ) const; 223 bool wioctl( int call, iwreqstruct& ) const;
222 224
223 private: 225 private:
224 OChannelHopper* _hopper; 226 OChannelHopper* _hopper;
225}; 227};
226 228
227 229
228/*====================================================================================== 230/*======================================================================================
229 * OMonitoringInterface 231 * OMonitoringInterface
230 *======================================================================================*/ 232 *======================================================================================*/
231 233
232 234
233class OMonitoringInterface 235class OMonitoringInterface
234{ 236{
235 public: 237 public:
236 OMonitoringInterface(); 238 OMonitoringInterface();
237 OMonitoringInterface( ONetworkInterface* ); 239 OMonitoringInterface( ONetworkInterface* );
238 virtual ~OMonitoringInterface(); 240 virtual ~OMonitoringInterface();
239 241
240 public: 242 public:
241 virtual void setEnabled( bool ); 243 virtual void setEnabled( bool );
242 virtual bool enabled() const; 244 virtual bool enabled() const;
243 virtual void setChannel( int ); 245 virtual void setChannel( int );
244 246
245 virtual QString name() const = 0; 247 virtual QString name() const = 0;
246 248
247 protected: 249 protected:
248 bool _enabled; 250 bool _enabled;
249 const OWirelessNetworkInterface* _if; 251 const OWirelessNetworkInterface* _if;
250 252
251}; 253};
252 254
253 255
254/*====================================================================================== 256/*======================================================================================
255 * OCiscoMonitoring 257 * OCiscoMonitoring
256 *======================================================================================*/ 258 *======================================================================================*/
257 259
258 260
259class OCiscoMonitoringInterface : public OMonitoringInterface 261class OCiscoMonitoringInterface : public OMonitoringInterface
260{ 262{
261 public: 263 public:
262 OCiscoMonitoringInterface( ONetworkInterface* ); 264 OCiscoMonitoringInterface( ONetworkInterface* );
263 virtual ~OCiscoMonitoringInterface(); 265 virtual ~OCiscoMonitoringInterface();
264 266
265 virtual void setEnabled( bool ); 267 virtual void setEnabled( bool );
266 virtual QString name() const; 268 virtual QString name() const;
267 virtual void setChannel( int ); 269 virtual void setChannel( int );
268 270
269}; 271};
270 272
271/*====================================================================================== 273/*======================================================================================
272 * OWlanNGMonitoringInterface 274 * OWlanNGMonitoringInterface
273 *======================================================================================*/ 275 *======================================================================================*/
274 276
275class OWlanNGMonitoringInterface : public OMonitoringInterface 277class OWlanNGMonitoringInterface : public OMonitoringInterface
276{ 278{
277 public: 279 public:
278 OWlanNGMonitoringInterface( ONetworkInterface* ); 280 OWlanNGMonitoringInterface( ONetworkInterface* );
279 virtual ~OWlanNGMonitoringInterface(); 281 virtual ~OWlanNGMonitoringInterface();
280 282
281 public: 283 public:
282 virtual void setEnabled( bool ); 284 virtual void setEnabled( bool );
283 virtual QString name() const; 285 virtual QString name() const;
284 virtual void setChannel( int ); 286 virtual void setChannel( int );
285 287
286}; 288};
287 289
288/*====================================================================================== 290/*======================================================================================
289 * OHostAPMonitoringInterface 291 * OHostAPMonitoringInterface
290 *======================================================================================*/ 292 *======================================================================================*/
291 293
292class OHostAPMonitoringInterface : public OMonitoringInterface 294class OHostAPMonitoringInterface : public OMonitoringInterface
293{ 295{
294 public: 296 public:
295 OHostAPMonitoringInterface( ONetworkInterface* ); 297 OHostAPMonitoringInterface( ONetworkInterface* );
296 virtual ~OHostAPMonitoringInterface(); 298 virtual ~OHostAPMonitoringInterface();
297 299
298 public: 300 public:
299 virtual void setEnabled( bool ); 301 virtual void setEnabled( bool );
300 virtual QString name() const; 302 virtual QString name() const;
301 }; 303 };
302 304
303/*====================================================================================== 305/*======================================================================================
304 * OOrinocoMonitoringInterface 306 * OOrinocoMonitoringInterface
305 *======================================================================================*/ 307 *======================================================================================*/
306 308
307class OOrinocoMonitoringInterface : public OMonitoringInterface 309class OOrinocoMonitoringInterface : public OMonitoringInterface
308{ 310{
309 public: 311 public:
310 OOrinocoMonitoringInterface( ONetworkInterface* ); 312 OOrinocoMonitoringInterface( ONetworkInterface* );
311 virtual ~OOrinocoMonitoringInterface(); 313 virtual ~OOrinocoMonitoringInterface();
312 314
313 public: 315 public:
314 virtual void setChannel( int ); 316 virtual void setChannel( int );
315 virtual void setEnabled( bool ); 317 virtual void setEnabled( bool );
316 virtual QString name() const; 318 virtual QString name() const;
317 319
318}; 320};
319 321
320#endif // ONETWORK_H 322#endif // ONETWORK_H
321 323