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
@@ -219,49 +219,49 @@ QString ONetworkInterface::ipV4Address() const
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{
@@ -270,77 +270,94 @@ bool ONetworkInterface::setPromiscuousMode( bool b )
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;
@@ -360,58 +377,64 @@ OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name )
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
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
@@ -15,48 +15,49 @@
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
@@ -141,51 +142,52 @@ class ONetworkInterface
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;