summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp16
-rw-r--r--libopie2/opienet/onetutils.cpp30
-rw-r--r--libopie2/opienet/onetutils.h7
-rw-r--r--libopie2/opienet/onetwork.cpp91
-rw-r--r--libopie2/opienet/onetwork.h5
-rw-r--r--libopie2/opienet/ostation.cpp15
-rw-r--r--libopie2/opienet/ostation.h17
7 files changed, 115 insertions, 66 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
index fc2026f..21026e1 100644
--- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -1,4 +1,5 @@
#include <opie2/onetwork.h>
+#include <opie2/ostation.h>
#include <opie2/omanufacturerdb.h>
int main( int argc, char** argv )
@@ -27,7 +28,7 @@ int main( int argc, char** argv )
//if ( iface->mode() == OWirelessNetworkInterface::adhoc )
//{
- qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() );
+ qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP().toString() );
//}
// nickname
@@ -58,11 +59,18 @@ int main( int argc, char** argv )
// network scan
- int stations = iface->scanNetwork();
- if ( stations != -1 )
+ OStationList* stations = iface->scanNetwork();
+ if ( stations )
{
- qDebug( "DEMO: # of stations around = %d", stations );
+ qDebug( "DEMO: # of stations around = %d", stations->count() );
+ OStation* station;
+ for ( station = stations->first(); station != 0; station = stations->next() )
+ {
+ qDebug( "DEMO: station dump following..." );
+ station->dump();
+ }
}
+
else
{
qDebug( "DEMO: Warning! Scan didn't work!" );
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index ad0e89d..ce147c5 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -34,7 +34,7 @@
#include <opie2/omanufacturerdb.h>
#include <net/if.h>
-
+#include <cassert>
#include <cstdio>
using namespace std;
@@ -213,3 +213,31 @@ void dumpBytes( const unsigned char* data, int num )
printf( "\n\n" );
}
+
+int stringToMode( const QString& mode )
+{
+ if ( mode == "auto" ) return IW_MODE_AUTO;
+ else if ( mode == "adhoc" ) return IW_MODE_ADHOC;
+ else if ( mode == "managed" ) return IW_MODE_INFRA;
+ else if ( mode == "master" ) return IW_MODE_MASTER;
+ else if ( mode == "repeater" ) return IW_MODE_REPEAT;
+ else if ( mode == "secondary" ) return IW_MODE_SECOND;
+ else if ( mode == "monitor" ) return IW_MODE_MONITOR;
+ else assert( 0 );
+}
+
+
+QString modeToString( int mode )
+{
+ switch ( mode )
+ {
+ case IW_MODE_AUTO: return "auto";
+ case IW_MODE_ADHOC: return "adhoc";
+ case IW_MODE_INFRA: return "managed";
+ case IW_MODE_MASTER: return "master";
+ case IW_MODE_REPEAT: return "repeater";
+ case IW_MODE_SECOND: return "second";
+ case IW_MODE_MONITOR: return "monitor";
+ default: assert( 0 );
+ }
+}
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h
index 18731ba..541c5ab 100644
--- a/libopie2/opienet/onetutils.h
+++ b/libopie2/opienet/onetutils.h
@@ -84,9 +84,10 @@ bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
class OHostAddress : public QHostAddress
{
- public:
+ /*public:
OHostAddress();
~OHostAddress();
+ */
};
@@ -120,9 +121,9 @@ class OPrivateIOCTL : public QObject
* Miscellaneous
*======================================================================================*/
-/* dump bytes */
-
void dumpBytes( const unsigned char* data, int num );
+QString modeToString( int );
+int stringToMode( const QString& );
/* Network to host order macros */
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index a85a510..50c6679 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -256,6 +256,7 @@ QString ONetworkInterface::ipV4Address() const
}
else
return "<unknown>";
+
}
@@ -474,30 +475,16 @@ void OWirelessNetworkInterface::init()
bool OWirelessNetworkInterface::isAssociated() const
{
//FIXME: handle different modes
- return associatedAP() != "44:44:44:44:44:44";
+ return !(associatedAP() == OMacAddress::unknown);
}
-QString OWirelessNetworkInterface::associatedAP() const
+OMacAddress OWirelessNetworkInterface::associatedAP() const
{
- //FIXME: use OMacAddress
- QString mac;
-
if ( ioctl( SIOCGIWAP ) )
- {
- mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
- _ifr.ifr_hwaddr.sa_data[0]&0xff,
- _ifr.ifr_hwaddr.sa_data[1]&0xff,
- _ifr.ifr_hwaddr.sa_data[2]&0xff,
- _ifr.ifr_hwaddr.sa_data[3]&0xff,
- _ifr.ifr_hwaddr.sa_data[4]&0xff,
- _ifr.ifr_hwaddr.sa_data[5]&0xff );
- }
+ return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0];
else
- {
- mac = "<Unknown>";
- }
- return mac;
+ return OMacAddress::unknown;
}
@@ -688,18 +675,7 @@ OChannelHopper* OWirelessNetworkInterface::channelHopper() const
void OWirelessNetworkInterface::setMode( const QString& mode )
{
- if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO;
- else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC;
- else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA;
- else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER;
- else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT;
- else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND;
- else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
- else
- {
- qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
- return;
- }
+ _iwr.u.mode = stringToMode( mode );
wioctl( SIOCSIWMODE );
}
@@ -710,17 +686,7 @@ QString OWirelessNetworkInterface::mode() const
{
return "<unknown>";
}
- switch ( _iwr.u.mode )
- {
- case IW_MODE_AUTO: return "auto";
- case IW_MODE_ADHOC: return "adhoc";
- case IW_MODE_INFRA: return "managed";
- case IW_MODE_MASTER: return "master";
- case IW_MODE_REPEAT: return "repeater";
- case IW_MODE_SECOND: return "secondary";
- case IW_MODE_MONITOR: return "monitor";
- default: assert( 0 ); // shouldn't happen
- }
+ return modeToString( _iwr.u.mode );
}
@@ -830,15 +796,17 @@ void OWirelessNetworkInterface::setSSID( const QString& ssid )
}
-int OWirelessNetworkInterface::scanNetwork()
+OStationList* OWirelessNetworkInterface::scanNetwork()
{
_iwr.u.param.flags = IW_SCAN_DEFAULT;
_iwr.u.param.value = 0;
if ( !wioctl( SIOCSIWSCAN ) )
{
- return -1;
+ return 0;
}
+ OStationList* stations = new OStationList();
+
int timeout = 1000000;
qDebug( "ONetworkInterface::scanNetwork() - scan started." );
@@ -886,14 +854,12 @@ int OWirelessNetworkInterface::scanNetwork()
if ( !_iwr.u.data.length )
{
qDebug( " - no results (empty neighbourhood)" );
- return 0;
+ return stations;
}
qDebug( " - results are in!" );
dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length );
- int stations = 0;
-
// parse results
int offset = 0;
@@ -906,10 +872,31 @@ int OWirelessNetworkInterface::scanNetwork()
qDebug( "reading next event... cmd=%d, len=%d", we->cmd, we->len );
switch (we->cmd)
{
- case SIOCGIWAP: qDebug( "SIOCGIWAP" ); stations++; break;
- case SIOCGIWMODE: qDebug( "SIOCGIWMODE" ); break;
- case SIOCGIWFREQ: qDebug( "SIOCGIWFREQ" ); break;
- case SIOCGIWESSID: qDebug( "SIOCGIWESSID" ); break;
+ case SIOCGIWAP:
+ {
+ qDebug( "SIOCGIWAP" );
+ stations->append( new OStation() );
+ stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0];
+ break;
+ }
+ case SIOCGIWMODE:
+ {
+ qDebug( "SIOCGIWMODE" );
+ stations->last()->type = modeToString( we->u.mode );
+ break;
+ }
+ case SIOCGIWFREQ:
+ {
+ qDebug( "SIOCGIWFREQ" );
+ stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ];
+ break;
+ }
+ case SIOCGIWESSID:
+ {
+ qDebug( "SIOCGIWESSID" );
+ stations->last()->ssid = we->u.essid.pointer;
+ break;
+ }
case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break;
case SIOCGIWENCODE: qDebug( "SIOCGIWENCODE" ); break;
case IWEVTXDROP: qDebug( "IWEVTXDROP" ); break; /* Packet dropped to excessive retry */
@@ -924,11 +911,13 @@ int OWirelessNetworkInterface::scanNetwork()
we = (struct iw_event*) &buffer[offset];
}
+ return stations;
+
}
else
{
qDebug( " - no results (timeout) :(" );
- return 0;
+ return stations;
}
}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index e1545dd..0eb4542 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -39,6 +39,7 @@
/* OPIE */
#include <opie2/onetutils.h>
+#include <opie2/ostation.h>
/* QT */
@@ -406,7 +407,7 @@ class OWirelessNetworkInterface : public ONetworkInterface
* @returns the MAC address of the Access Point if the device is in infrastructure mode.
* @returns a (more or less random) cell ID address if the device is in adhoc mode.
*/
- virtual QString associatedAP() const;
+ virtual OMacAddress associatedAP() const;
/**
* Set the @a ssid (Service Set ID) string. This is used to decide
* which network to associate with (use "any" to let the driver decide).
@@ -420,7 +421,7 @@ class OWirelessNetworkInterface : public ONetworkInterface
* Perform scanning the wireless network neighbourhood.
* @note: UNSTABLE API - UNDER CONSTRUCTION - DON'T USE!
*/
- virtual int scanNetwork();
+ virtual OStationList* scanNetwork();
protected:
void buildInformation();
diff --git a/libopie2/opienet/ostation.cpp b/libopie2/opienet/ostation.cpp
index 3817b31..ba1e4f6 100644
--- a/libopie2/opienet/ostation.cpp
+++ b/libopie2/opienet/ostation.cpp
@@ -38,6 +38,13 @@
OStation::OStation()
{
qDebug( "OStation::OStation()" );
+
+ type = "<unknown>";
+ macAddress = OMacAddress::unknown;
+ ssid = "<unknown>";
+ channel = 0;
+ apAddress = OMacAddress::unknown;
+
}
@@ -47,3 +54,11 @@ OStation::~OStation()
}
+void OStation::dump()
+{
+ qDebug( "------- OStation::dump() ------------" );
+ qDebug( "type: %s", (const char*) type );
+ qDebug( "mac: %s", (const char*) macAddress.toString() );
+ qDebug( "ap: %s", (const char*) apAddress.toString() );
+ qDebug( "ip: %s", (const char*) ipAddress.toString() );
+}
diff --git a/libopie2/opienet/ostation.h b/libopie2/opienet/ostation.h
index f61570b..a6956c9 100644
--- a/libopie2/opienet/ostation.h
+++ b/libopie2/opienet/ostation.h
@@ -34,8 +34,7 @@
#include <opie2/onetutils.h>
-#include <qdict.h>
-#include <qmap.h>
+#include <qlist.h>
#include <qstring.h>
#include <qhostaddress.h>
#include <qobject.h>
@@ -44,7 +43,7 @@
class OStation;
-typedef QDict<OStation> OStationDict;
+typedef QList<OStation> OStationList;
/*======================================================================================
* OStation
@@ -56,12 +55,20 @@ class OStation
OStation();
~OStation();
- private:
+ void dump();
+
+ /* Ethernet */
+ QString type;
OMacAddress macAddress;
QHostAddress ipAddress;
+
+ /* WaveLan */
QString ssid;
- QString type;
+ OMacAddress apAddress;
+ int channel;
+ bool encrypted;
};
+
#endif // OSTATION_H