summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-03 23:46:04 (UTC)
committer mickeyl <mickeyl>2003-04-03 23:46:04 (UTC)
commit487971af0c1b70babcc39fd549dc0d8142cd4865 (patch) (side-by-side diff)
treee317df1359a20686ba35b17309a8b82386108fb3
parent934e4d81bc078c704a39f02663607a6c16a5b29f (diff)
downloadopie-487971af0c1b70babcc39fd549dc0d8142cd4865.zip
opie-487971af0c1b70babcc39fd549dc0d8142cd4865.tar.gz
opie-487971af0c1b70babcc39fd549dc0d8142cd4865.tar.bz2
first part of private IOCTL API for OWirelessNetworkInterface implemented
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp8
-rw-r--r--libopie2/opienet/onetutils.cpp33
-rw-r--r--libopie2/opienet/onetutils.h4
-rw-r--r--libopie2/opienet/onetwork.cpp33
-rw-r--r--libopie2/opienet/onetwork.h5
5 files changed, 79 insertions, 4 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
index 7703b4c..b010ac5 100644
--- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -17,19 +17,27 @@ int main( int argc, char** argv )
{
OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
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() );
//if ( iface->mode() == OWirelessNetworkInterface::adhoc )
//{
qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() );
//}
+ // try to set monitor mode
+
+ // first some wrong calls to check if this is working
+ iface->setPrivate( "seppel", 10 );
+ iface->setPrivate( "monitor", 0 );
+
+ // now the real deal
+ iface->setPrivate( "monitor", 2, 2, 3 );
}
++it;
}
return 0;
}
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index 3e11b53..fd8f9e9 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -21,24 +21,25 @@
++=   -.     .`     .: details.
 :     =  ...= . :.=-
 -.   .:....=;==+<; You should have received a copy of the GNU
  -_. . .   )=.  = Library General Public License along with
    --        :-=` this library; see the file COPYING.LIB.
If not, write to the Free Software Foundation,
Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
*/
#include <opie2/onetutils.h>
+#include <opie2/onetwork.h>
#include <net/if.h>
#include <cstdio>
using namespace std;
#define IW_PRIV_TYPE_MASK 0x7000
#define IW_PRIV_TYPE_NONE 0x0000
#define IW_PRIV_TYPE_BYTE 0x1000
#define IW_PRIV_TYPE_CHAR 0x2000
#define IW_PRIV_TYPE_INT 0x4000
#define IW_PRIV_TYPE_FLOAT 0x5000
@@ -109,48 +110,72 @@ bool operator==( const OMacAddress &m1, const OMacAddress &m2 )
OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs )
:QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs )
{
}
OPrivateIOCTL::~OPrivateIOCTL()
{
}
-inline int OPrivateIOCTL::numberGetArgs() const
+#ifdef QT_NO_DEBUG
+inline
+#endif
+int OPrivateIOCTL::numberGetArgs() const
{
return _getargs & IW_PRIV_SIZE_MASK;
}
-inline int OPrivateIOCTL::typeGetArgs() const
+#ifdef QT_NO_DEBUG
+inline
+#endif
+int OPrivateIOCTL::typeGetArgs() const
{
return _getargs & IW_PRIV_TYPE_MASK >> 12;
}
-inline int OPrivateIOCTL::numberSetArgs() const
+#ifdef QT_NO_DEBUG
+inline
+#endif
+int OPrivateIOCTL::numberSetArgs() const
{
return _setargs & IW_PRIV_SIZE_MASK;
}
-inline int OPrivateIOCTL::typeSetArgs() const
+#ifdef QT_NO_DEBUG
+inline
+#endif
+int OPrivateIOCTL::typeSetArgs() const
{
return _setargs & IW_PRIV_TYPE_MASK >> 12;
}
+void OPrivateIOCTL::invoke() const
+{
+ ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl );
+}
+
+
+void OPrivateIOCTL::setParameter( int num, u_int32_t value )
+{
+ u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name;
+ arglist[num] = value;
+}
+
/*======================================================================================
* assorted functions
*======================================================================================*/
void dumpBytes( const unsigned char* data, int num )
{
printf( "Dumping %d bytes @ %0x", num, data );
printf( "-------------------------------------------\n" );
for ( int i = 0; i < num; ++i )
{
printf( "%02x ", data[i] );
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h
index 6640515..8be042b 100644
--- a/libopie2/opienet/onetutils.h
+++ b/libopie2/opienet/onetutils.h
@@ -89,28 +89,32 @@ class OHostAddress : public QHostAddress
class OPrivateIOCTL : public QObject
{
public:
OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs );
~OPrivateIOCTL();
int numberGetArgs() const;
int typeGetArgs() const;
int numberSetArgs() const;
int typeSetArgs() const;
+ void invoke() const;
+ void setParameter( int, u_int32_t );
+
private:
u_int32_t _ioctl;
u_int16_t _getargs;
u_int16_t _setargs;
+
};
/*======================================================================================
* Miscellaneous
*======================================================================================*/
/* dump bytes */
void dumpBytes( const unsigned char* data, int num );
/* Network to host order macros */
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 2548a04..66fa215 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -43,24 +43,25 @@
/* UNIX */
#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 <stdarg.h>
using namespace std;
/*======================================================================================
* ONetwork
*======================================================================================*/
ONetwork* ONetwork::_instance = 0;
ONetwork::ONetwork()
{
qDebug( "ONetwork::ONetwork()" );
@@ -573,24 +574,56 @@ QString OWirelessNetworkInterface::nickName() const
if ( !wioctl( SIOCGIWNICKN ) )
{
return "<unknown>";
}
else
{
str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
return str;
}
}
+void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
+{
+ OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
+ if ( !priv )
+ {
+ qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
+ return;
+ }
+ if ( priv->numberSetArgs() != numargs )
+ {
+ qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs );
+ return;
+ }
+
+ qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() );
+ memset( &_iwr, 0, sizeof _iwr );
+ va_list argp;
+ va_start( argp, numargs );
+ for ( int i = 0; i < numargs; ++i )
+ {
+ priv->setParameter( i, va_arg( argp, int ) );
+ }
+ va_end( argp );
+ priv->invoke();
+}
+
+
+void OWirelessNetworkInterface::getPrivate( const QString& call )
+{
+}
+
+
QString OWirelessNetworkInterface::SSID() const
{
char str[IW_ESSID_MAX_SIZE];
_iwr.u.essid.pointer = &str[0];
_iwr.u.essid.length = IW_ESSID_MAX_SIZE;
if ( !wioctl( SIOCGIWESSID ) )
{
return "<unknown>";
}
else
{
return str;
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index acf2f69..7c70873 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -174,48 +174,53 @@ class OChannelHopper : public QObject
/*======================================================================================
* OWirelessNetworkInterface
*======================================================================================*/
class OWirelessNetworkInterface : public ONetworkInterface
{
friend class OMonitoringInterface;
friend class OCiscoMonitoringInterface;
friend class OWlanNGMonitoringInterface;
friend class OHostAPMonitoringInterface;
friend class OOrinocoMonitoringInterface;
+ friend class OPrivateIOCTL;
+
public:
enum Mode { AdHoc, Managed, Monitor };
OWirelessNetworkInterface( QObject* parent, const char* name );
virtual ~OWirelessNetworkInterface();
virtual void setChannel( int ) const;
virtual int channel() const;
virtual double frequency() const;
virtual int channels() const;
//virtual double frequency(int) const;
virtual void setMode( Mode ) {};
virtual bool mode() const {};
virtual void setMonitorMode( bool );
virtual bool monitorMode() const;
virtual void setChannelHopping( int interval = 0 );
virtual int channelHopping() const;
virtual void setNickName( const QString& ) {};
virtual QString nickName() const;
+ virtual void setPrivate( const QString&, int, ... );
+ virtual void getPrivate( const QString& );
+
virtual bool isAssociated() const {};
virtual QString associatedAP() const;
virtual void setSSID( const QString& );
virtual QString SSID() const;
protected:
void buildChannelList();
void buildPrivateList();
virtual void init();
iwreqstruct& iwr() const;
bool wioctl( int call ) const;