summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-01 15:03:49 (UTC)
committer mickeyl <mickeyl>2003-04-01 15:03:49 (UTC)
commita7ad29eb41163eec88b3bd835108bd80140ff086 (patch) (side-by-side diff)
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) (show 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
@@ -239,9 +239,9 @@ OMacAddress ONetworkInterface::macAddress() const
void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
{
_mon = m;
- qDebug( "ONetwork::setMonitoring(): Installed monitoring interface '%s'", (const char*) m->name() );
+ qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), (const char*) _name );
}
OMonitoringInterface* ONetworkInterface::monitoring() const
@@ -290,11 +290,28 @@ bool ONetworkInterface::isWireless() const
*======================================================================================*/
OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
:QObject( 0, "Mickey's funky hopper" ),
- _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ),
- _maxChannel( iface->channels()+1 )
+ _iface( iface ), _interval( 0 ), _tid( 0 )
{
+ int _maxChannel = iface->channels()+1;
+ // generate fancy hopping sequence honoring the device capabilities
+ if ( _maxChannel >= 1 ) _channels.append( 1 );
+ if ( _maxChannel >= 7 ) _channels.append( 7 );
+ if ( _maxChannel >= 13 ) _channels.append( 13 );
+ if ( _maxChannel >= 2 ) _channels.append( 2 );
+ if ( _maxChannel >= 8 ) _channels.append( 8 );
+ if ( _maxChannel >= 3 ) _channels.append( 3 );
+ if ( _maxChannel >= 14 ) _channels.append( 14 );
+ if ( _maxChannel >= 9 ) _channels.append( 9 );
+ if ( _maxChannel >= 4 ) _channels.append( 4 );
+ if ( _maxChannel >= 10 ) _channels.append( 10 );
+ if ( _maxChannel >= 5 ) _channels.append( 5 );
+ if ( _maxChannel >= 11 ) _channels.append( 11 );
+ if ( _maxChannel >= 6 ) _channels.append( 6 );
+ if ( _maxChannel >= 12 ) _channels.append( 12 );
+ _channel = _channels.begin();
+
}
OChannelHopper::~OChannelHopper()
@@ -309,18 +326,18 @@ bool OChannelHopper::isActive() const
int OChannelHopper::channel() const
{
- return _channel;
+ return *_channel;
}
void OChannelHopper::timerEvent( QTimerEvent* )
{
- if ( !--_channel ) _channel = _maxChannel;
- _iface->setChannel( _channel );
+ _iface->setChannel( *_channel );
qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
- _channel, (const char*) _iface->name() );
+ *_channel, (const char*) _iface->name() );
+ if ( ++_channel == _channels.end() ) _channel = _channels.begin();
}
void OChannelHopper::setInterval( int interval )
@@ -380,18 +397,24 @@ void OWirelessNetworkInterface::init()
iwrangestruct range;
//ML: work around an ugly HostAP bug, which needs
//ML: extra space or will complain with "invalid argument length"... :-(
- char __extraBufferForBuggyDrivers[sizeof range];
+ //ML: But don't allocate too much or prism2_usb will segfault *sigh*
+ char __extraBufferForBuggyDrivers[20];
+
+ qDebug( "sizeof(iwrangestruct)=%d, sizeof range=%d, sizeof range*2=%d", sizeof(iwrangestruct), sizeof range, (sizeof range)*2 );
+
_iwr.u.data.pointer = (char*) &range;
- _iwr.u.data.length = (sizeof range) * 2;
+ _iwr.u.data.length = sizeof(iwrangestruct)+20;
_iwr.u.data.flags = 0;
if ( !wioctl( SIOCGIWRANGE ) )
{
qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) );
return;
}
+ qDebug( "OWirelessNetworkInterface::init(): Interface %s reported to have %d channels.", (const char*) _name, range.num_frequency );
+
for ( int i = 0; i < range.num_frequency; ++i )
{
int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
_channels.insert( freq, i+1 );
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
@@ -35,8 +35,9 @@
#define ONETWORK_H
/* QT */
+#include <qvaluelist.h>
#include <qdict.h>
#include <qmap.h>
#include <qobject.h>
#include <qhostaddress.h>
@@ -161,11 +162,12 @@ class OChannelHopper : public QObject
private:
OWirelessNetworkInterface* _iface;
int _interval;
- int _channel;
int _tid;
- int _maxChannel;
+ QValueList<int> _channels;
+ QValueList<int>::Iterator _channel;
+
};
/*======================================================================================