summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp21
-rw-r--r--libopie2/opienet/onetwork.cpp51
-rw-r--r--libopie2/opienet/onetwork.h58
3 files changed, 105 insertions, 25 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
index f801b15..fd68772 100644
--- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -20,5 +20,4 @@ int main( int argc, char** argv )
qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() );
qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() );
- qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() );
@@ -28,5 +27,21 @@ int main( int argc, char** argv )
//}
- // try to set monitor mode
+ // nickname
+ qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
+ iface->setNickName( "MyNickName" );
+ if ( iface->nickName() != "MyNickName" )
+ qDebug( "DEMO: Warning! Can't change nickname" );
+ else
+ qDebug( "DEMO: Nickname change successful." );
+
+ // operation mode
+ qDebug( "DEMO: Current OperationMode is '%s'", (const char*) iface->mode() );
+ iface->setMode( "adhoc" );
+ if ( iface->mode() != "adhoc" )
+ qDebug( "DEMO: Warning! Can't change operation mode" );
+ else
+ qDebug( "DEMO: Operation Mode change successful." );
+
+ iface->setMode( "managed" );
/*
@@ -39,6 +54,4 @@ int main( int argc, char** argv )
iface->setPrivate( "monitor", 2, 2, 3 );
- */
-
// trying to set hw address to 12:34:56:AB:CD:EF
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 95e7043..2dfff1d 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -43,4 +43,5 @@
/* UNIX */
+#include <assert.h>
#include <arpa/inet.h>
#include <cerrno>
@@ -640,4 +641,46 @@ 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;
+ #if WIRELESS_EXT > 14
+ else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
+ #endif
+ else
+ {
+ qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
+ return;
+ }
+ wioctl( SIOCSIWMODE );
+}
+
+
+QString OWirelessNetworkInterface::mode() const
+{
+ if ( !wioctl( SIOCGIWMODE ) )
+ {
+ 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";
+ #if WIRELESS_EXT > 14
+ case IW_MODE_MONITOR: return "monitor";
+ #endif
+ default: assert( 0 ); // shouldn't happen
+ }
+}
+
+
void OWirelessNetworkInterface::setMonitorMode( bool b )
{
@@ -657,4 +700,12 @@ bool OWirelessNetworkInterface::monitorMode() const
+void OWirelessNetworkInterface::setNickName( const QString& nickname )
+{
+ _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
+ _iwr.u.essid.length = nickname.length();
+ wioctl( SIOCSIWNICKN );
+}
+
+
QString OWirelessNetworkInterface::nickName() const
{
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index f052317..a29b29d 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -35,4 +35,8 @@
#define ONETWORK_H
+/* OPIE */
+
+#include <opie2/onetutils.h>
+
/* QT */
@@ -43,8 +47,4 @@
#include <qhostaddress.h>
-/* OPIE */
-
-#include <opie2/onetutils.h>
-
#ifndef IFNAMSIZ
#define IFNAMSIZ 16
@@ -101,10 +101,10 @@ class ONetwork : public QObject
InterfaceIterator iterator() const;
/**
- * @returns true, if the @p interface supports the wireless extension protocol.
+ * @returns true, if the @a interface supports the wireless extension protocol.
*/
// FIXME QString? -zecke
bool isWirelessInterface( const char* interface ) const;
/**
- * @returns a pointer to the @ref ONetworkInterface object for the specified @p interface or 0, if not found
+ * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found
* @see ONetworkInterface
*/
@@ -199,5 +199,5 @@ class ONetworkInterface : public QObject
* @returns the IPv4 address associated with the interface.
*/
- QString ipV4Address() const;
+ QString ipV4Address() const; //TODO: make this return an OHostAddress
/**
* Associate the MAC address @a addr with the interface.
@@ -217,5 +217,5 @@ class ONetworkInterface : public QObject
* @returns the IPv4 netmask associated with the interface.
*/
- QString ipV4Netmask() const;
+ QString ipV4Netmask() const; //TODO: make this return an OHostAddress
/**
* @returns the data link type currently associated with the interface.
@@ -318,6 +318,4 @@ class OWirelessNetworkInterface : public ONetworkInterface
public:
- enum Mode { AdHoc, Managed, Monitor };
-
/**
* Constructor.
@@ -347,9 +345,16 @@ class OWirelessNetworkInterface : public ONetworkInterface
*/
virtual int channels() const;
- //virtual double frequency(int) const;
-
- virtual void setMode( Mode ) {}; //FIXME: Implement and document this
- virtual bool mode() const {}; //FIXME: Implement and document this
-
+ /**
+ * Set the IEEE 802.11 operation @a mode.
+ * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master
+ * @warning Not all drivers support the all modes.
+ * @note You might have to change the SSID to get the operation mode change into effect.
+ */
+ virtual void setMode( const QString& mode );
+ /**
+ * @returns the current IEEE 802.11 operation mode.
+ * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown
+ */
+ virtual QString mode() const;
/**
* Setting the monitor mode on a wireless network interface enables
@@ -363,9 +368,9 @@ class OWirelessNetworkInterface : public ONetworkInterface
* @see OMonitoringInterface
*/
- virtual void setMonitorMode( bool );
+ virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" );
/**
* @returns true if the device is listening in IEEE 802.11 monitor mode
*/
- virtual bool monitorMode() const;
+ virtual bool monitorMode() const; //FIXME: ==> mode()
/**
* Set the channel hopping @a interval. An @a interval of 0 disables channel hopping.
@@ -384,5 +389,5 @@ class OWirelessNetworkInterface : public ONetworkInterface
* Set the station @a nickname.
*/
- virtual void setNickName( const QString& nickname ) {}; //FIXME: Implement this
+ virtual void setNickName( const QString& nickname );
/**
* @returns the current station nickname.
@@ -401,7 +406,18 @@ class OWirelessNetworkInterface : public ONetworkInterface
virtual bool isAssociated() const {}; //FIXME: Implement and document this
- virtual QString associatedAP() const; //FIXME: Implement and document this
-
- virtual void setSSID( const QString& );
+ /**
+ * @returns the MAC address of the Access Point if the
+ * device is in infrastructure mode. @returns a (more or less random) CELL
+ * address if the device is in adhoc mode.
+ */
+ virtual QString 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).
+ */
+ virtual void setSSID( const QString& ssid );
+ /**
+ * @returns the current SSID (Service Set ID).
+ */
virtual QString SSID() const;