author | mickeyl <mickeyl> | 2003-04-01 15:03:49 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2003-04-01 15:03:49 (UTC) |
commit | a7ad29eb41163eec88b3bd835108bd80140ff086 (patch) (unidiff) | |
tree | 8fa122e07d475014d8343be06d99f53759af0582 /libopie2 | |
parent | 14d3e700f80f8e26f3f3cceaa7174d5f1c445bd7 (diff) | |
download | opie-a7ad29eb41163eec88b3bd835108bd80140ff086.zip opie-a7ad29eb41163eec88b3bd835108bd80140ff086.tar.gz opie-a7ad29eb41163eec88b3bd835108bd80140ff086.tar.bz2 |
introduce a more sophisticated channel hopping scheme
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 41 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 6 |
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 | |||
@@ -237,13 +237,13 @@ OMacAddress ONetworkInterface::macAddress() const | |||
237 | } | 237 | } |
238 | 238 | ||
239 | 239 | ||
240 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 240 | void 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 | ||
247 | OMonitoringInterface* ONetworkInterface::monitoring() const | 247 | OMonitoringInterface* ONetworkInterface::monitoring() const |
248 | { | 248 | { |
249 | return _mon; | 249 | return _mon; |
@@ -288,15 +288,32 @@ bool ONetworkInterface::isWireless() const | |||
288 | /*====================================================================================== | 288 | /*====================================================================================== |
289 | * OChannelHopper | 289 | * OChannelHopper |
290 | *======================================================================================*/ | 290 | *======================================================================================*/ |
291 | 291 | ||
292 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 292 | OChannelHopper::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 | ||
300 | OChannelHopper::~OChannelHopper() | 317 | OChannelHopper::~OChannelHopper() |
301 | { | 318 | { |
302 | } | 319 | } |
@@ -307,22 +324,22 @@ bool OChannelHopper::isActive() const | |||
307 | return _tid; | 324 | return _tid; |
308 | } | 325 | } |
309 | 326 | ||
310 | 327 | ||
311 | int OChannelHopper::channel() const | 328 | int OChannelHopper::channel() const |
312 | { | 329 | { |
313 | return _channel; | 330 | return *_channel; |
314 | } | 331 | } |
315 | 332 | ||
316 | 333 | ||
317 | void OChannelHopper::timerEvent( QTimerEvent* ) | 334 | void 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 | ||
326 | void OChannelHopper::setInterval( int interval ) | 343 | void OChannelHopper::setInterval( int interval ) |
327 | { | 344 | { |
328 | if ( interval == _interval ) | 345 | if ( interval == _interval ) |
@@ -378,22 +395,28 @@ void OWirelessNetworkInterface::init() | |||
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*) ⦥ | 406 | _iwr.u.data.pointer = (char*) ⦥ |
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 | } |
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 | |||
@@ -33,12 +33,13 @@ | |||
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 */ |
@@ -159,15 +160,16 @@ class OChannelHopper : public QObject | |||
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 | *======================================================================================*/ |