summaryrefslogtreecommitdiff
path: root/libopie2/opienet/onetwork.cpp
Side-by-side diff
Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp51
1 files changed, 51 insertions, 0 deletions
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
@@ -33,24 +33,25 @@
/* OPIE */
#include <opie2/onetwork.h>
/* QT */
#include <qfile.h>
#include <qtextstream.h>
/* UNIX */
+#include <assert.h>
#include <arpa/inet.h>
#include <cerrno>
#include <cstring>
#include <cstdlib>
#include <math.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#include <linux/sockios.h>
#include <net/if_arp.h>
#include <stdarg.h>
@@ -630,41 +631,91 @@ void OWirelessNetworkInterface::setChannelHopping( int interval )
int OWirelessNetworkInterface::channelHopping() const
{
return _hopper->interval();
}
OChannelHopper* OWirelessNetworkInterface::channelHopper() const
{
return _hopper;
}
+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 )
{
if ( _mon )
_mon->setEnabled( b );
else
qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
}
bool OWirelessNetworkInterface::monitorMode() const
{
qDebug( "dataLinkType = %d", dataLinkType() );
return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
// 802 is the header type for PRISM - Linux support for this is pending...
}
+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
{
char str[IW_ESSID_MAX_SIZE];
_iwr.u.data.pointer = &str[0];
_iwr.u.data.length = IW_ESSID_MAX_SIZE;
if ( !wioctl( SIOCGIWNICKN ) )
{
return "<unknown>";
}
else
{
str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string