summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-05 19:29:47 (UTC)
committer mickeyl <mickeyl>2003-04-05 19:29:47 (UTC)
commit30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca (patch) (unidiff)
treeeca3cb8d01045773db7de60d8194ea85313d3e0a
parent2bfd529736f1dcf008540be2199cd3887a53c75c (diff)
downloadopie-30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca.zip
opie-30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca.tar.gz
opie-30e5401a945ebdfd92eedb9f3def9a6acd0fc6ca.tar.bz2
- setting the monitor mode on wireless cards via private ioctls is now much more reliable because we detect the appropriate ioctl number at runtime
- ONetworkInterface supports now the evil but handy feature to change MAC address on the fly (provided the driver supports this)
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp18
-rw-r--r--libopie2/opienet/onetutils.cpp28
-rw-r--r--libopie2/opienet/onetutils.h3
-rw-r--r--libopie2/opienet/onetwork.cpp50
-rw-r--r--libopie2/opienet/onetwork.h8
5 files changed, 73 insertions, 34 deletions
diff --git a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
index b010ac5..020fc23 100644
--- a/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
+++ b/libopie2/examples/opienet/onetworkdemo/onetworkdemo.cpp
@@ -1,43 +1,61 @@
1#include <opie2/onetwork.h> 1#include <opie2/onetwork.h>
2 2
3int main( int argc, char** argv ) 3int main( int argc, char** argv )
4{ 4{
5 qDebug( "OPIE Network Demo" ); 5 qDebug( "OPIE Network Demo" );
6 6
7 ONetwork* net = ONetwork::instance(); 7 ONetwork* net = ONetwork::instance();
8 8
9 ONetwork::InterfaceIterator it = net->iterator(); 9 ONetwork::InterfaceIterator it = net->iterator();
10 10
11 while ( it.current() ) 11 while ( it.current() )
12 { 12 {
13 qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() ); 13 qDebug( "DEMO: ONetwork contains Interface '%s'", (const char*) it.current()->name() );
14 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() ); 14 qDebug( "DEMO: MAC Address is '%s'", (const char*) it.current()->macAddress().toString() );
15 qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() ); 15 qDebug( "Demo: IPv4 Address is '%s'", (const char*) it.current()->ipV4Address() );
16 if ( it.current()->isWireless() ) 16 if ( it.current()->isWireless() )
17 { 17 {
18 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() ); 18 OWirelessNetworkInterface* iface = static_cast<OWirelessNetworkInterface*>( it.current() );
19 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() ); 19 qDebug( "DEMO: '%s' seems to feature the wireless extensions.", (const char*) iface->name() );
20 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() ); 20 qDebug( "DEMO: Current SSID is '%s'", (const char*) iface->SSID() );
21 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() ); 21 qDebug( "DEMO: Current NickName is '%s'", (const char*) iface->nickName() );
22 qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() ); 22 qDebug( "DEMO: Antenna is tuned to '%f', that is channel %d", iface->frequency(), iface->channel() );
23 23
24 //if ( iface->mode() == OWirelessNetworkInterface::adhoc ) 24 //if ( iface->mode() == OWirelessNetworkInterface::adhoc )
25 //{ 25 //{
26 qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() ); 26 qDebug( "DEMO: Associated AP has MAC Address '%s'", (const char*) iface->associatedAP() );
27 //} 27 //}
28 28
29 // try to set monitor mode 29 // try to set monitor mode
30 30
31 /*
32
31 // first some wrong calls to check if this is working 33 // first some wrong calls to check if this is working
32 iface->setPrivate( "seppel", 10 ); 34 iface->setPrivate( "seppel", 10 );
33 iface->setPrivate( "monitor", 0 ); 35 iface->setPrivate( "monitor", 0 );
34 36
35 // now the real deal 37 // now the real deal
36 iface->setPrivate( "monitor", 2, 2, 3 ); 38 iface->setPrivate( "monitor", 2, 2, 3 );
39
40 */
41
42 // trying to set hw address to 12:34:56:AB:CD:EF
43
44 /*
45
46 OMacAddress addr = OMacAddress::fromString( "12:34:56:AB:CD:EF" );
47 iface->setUp( false );
48 iface->setMacAddress( addr );
49 iface->setUp( true );
50 qDebug( "DEMO: MAC Address now is '%s'", (const char*) iface->macAddress().toString() );
51
52 */
53
54
37 } 55 }
38 ++it; 56 ++it;
39 } 57 }
40 58
41 return 0; 59 return 0;
42 60
43} 61}
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index b317810..0fb21ff 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -1,186 +1,212 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#include <opie2/onetutils.h> 32#include <opie2/onetutils.h>
33#include <opie2/onetwork.h> 33#include <opie2/onetwork.h>
34 34
35#include <net/if.h> 35#include <net/if.h>
36 36
37#include <cstdio> 37#include <cstdio>
38using namespace std; 38using namespace std;
39 39
40#define IW_PRIV_TYPE_MASK 0x7000 40#define IW_PRIV_TYPE_MASK 0x7000
41#define IW_PRIV_TYPE_NONE 0x0000 41#define IW_PRIV_TYPE_NONE 0x0000
42#define IW_PRIV_TYPE_BYTE 0x1000 42#define IW_PRIV_TYPE_BYTE 0x1000
43#define IW_PRIV_TYPE_CHAR 0x2000 43#define IW_PRIV_TYPE_CHAR 0x2000
44#define IW_PRIV_TYPE_INT 0x4000 44#define IW_PRIV_TYPE_INT 0x4000
45#define IW_PRIV_TYPE_FLOAT 0x5000 45#define IW_PRIV_TYPE_FLOAT 0x5000
46#define IW_PRIV_TYPE_ADDR 0x6000 46#define IW_PRIV_TYPE_ADDR 0x6000
47#define IW_PRIV_SIZE_FIXED 0x0800 47#define IW_PRIV_SIZE_FIXED 0x0800
48#define IW_PRIV_SIZE_MASK 0x07FF 48#define IW_PRIV_SIZE_MASK 0x07FF
49 49
50/*====================================================================================== 50/*======================================================================================
51 * OMacAddress 51 * OMacAddress
52 *======================================================================================*/ 52 *======================================================================================*/
53 53
54// static initializer for broadcast and unknown MAC Adresses 54// static initializer for broadcast and unknown MAC Adresses
55const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 55const unsigned char __broadcast[6] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
56const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast ); 56const OMacAddress& OMacAddress::broadcast = OMacAddress( __broadcast );
57const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 }; 57const unsigned char __unknown[6] = { 0x44, 0x44, 0x44, 0x44, 0x44, 0x44 };
58const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown ); 58const OMacAddress& OMacAddress::unknown = OMacAddress( __unknown );
59 59
60 60
61//TODO: Incorporate Ethernet Manufacturer database here! 61//TODO: Incorporate Ethernet Manufacturer database here!
62 62
63OMacAddress::OMacAddress( unsigned char* p ) 63OMacAddress::OMacAddress( unsigned char* p )
64{ 64{
65 memcpy( _bytes, p, 6 ); // D'OH! memcpy in my sources... eeek... 65 memcpy( _bytes, p, 6 );
66} 66}
67 67
68 68
69OMacAddress::OMacAddress( const unsigned char* p ) 69OMacAddress::OMacAddress( const unsigned char* p )
70{ 70{
71 memcpy( _bytes, p, 6 ); 71 memcpy( _bytes, p, 6 );
72} 72}
73 73
74 74
75OMacAddress::OMacAddress( struct ifreq& ifr ) 75OMacAddress::OMacAddress( struct ifreq& ifr )
76{ 76{
77 memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 ); 77 memcpy( _bytes, ifr.ifr_hwaddr.sa_data, 6 );
78} 78}
79 79
80 80
81OMacAddress::~OMacAddress() 81OMacAddress::~OMacAddress()
82{ 82{
83} 83}
84 84
85 85
86#ifdef QT_NO_DEBUG
87inline
88#endif
89const unsigned char* OMacAddress::native() const
90{
91 return (const unsigned char*) &_bytes;
92}
93
94
95OMacAddress OMacAddress::fromString( const QString& str )
96{
97 QString addr( str );
98 unsigned char buf[6];
99 bool ok = true;
100 int index = 14;
101 for ( int i = 5; i >= 0; --i )
102 {
103 buf[i] = addr.right( 2 ).toUShort( &ok, 16 );
104 if ( !ok ) return OMacAddress::unknown;
105 addr.truncate( index );
106 index -= 3;
107 }
108 return (const unsigned char*) &buf;
109}
110
111
86QString OMacAddress::toString() const 112QString OMacAddress::toString() const
87{ 113{
88 QString s; 114 QString s;
89 s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 115 s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
90 _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, 116 _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff,
91 _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); 117 _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff );
92 return s; 118 return s;
93} 119}
94 120
95 121
96bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) 122bool operator==( const OMacAddress &m1, const OMacAddress &m2 )
97{ 123{
98 return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; 124 return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0;
99} 125}
100 126
101 127
102/*====================================================================================== 128/*======================================================================================
103 * OHostAddress 129 * OHostAddress
104 *======================================================================================*/ 130 *======================================================================================*/
105 131
106 132
107/*====================================================================================== 133/*======================================================================================
108 * OPrivateIOCTL 134 * OPrivateIOCTL
109 *======================================================================================*/ 135 *======================================================================================*/
110 136
111OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) 137OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs )
112 :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) 138 :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs )
113{ 139{
114} 140}
115 141
116 142
117OPrivateIOCTL::~OPrivateIOCTL() 143OPrivateIOCTL::~OPrivateIOCTL()
118{ 144{
119} 145}
120 146
121 147
122#ifdef QT_NO_DEBUG 148#ifdef QT_NO_DEBUG
123inline 149inline
124#endif 150#endif
125int OPrivateIOCTL::numberGetArgs() const 151int OPrivateIOCTL::numberGetArgs() const
126{ 152{
127 return _getargs & IW_PRIV_SIZE_MASK; 153 return _getargs & IW_PRIV_SIZE_MASK;
128} 154}
129 155
130 156
131#ifdef QT_NO_DEBUG 157#ifdef QT_NO_DEBUG
132inline 158inline
133#endif 159#endif
134int OPrivateIOCTL::typeGetArgs() const 160int OPrivateIOCTL::typeGetArgs() const
135{ 161{
136 return _getargs & IW_PRIV_TYPE_MASK >> 12; 162 return _getargs & IW_PRIV_TYPE_MASK >> 12;
137} 163}
138 164
139 165
140#ifdef QT_NO_DEBUG 166#ifdef QT_NO_DEBUG
141inline 167inline
142#endif 168#endif
143int OPrivateIOCTL::numberSetArgs() const 169int OPrivateIOCTL::numberSetArgs() const
144{ 170{
145 return _setargs & IW_PRIV_SIZE_MASK; 171 return _setargs & IW_PRIV_SIZE_MASK;
146} 172}
147 173
148 174
149#ifdef QT_NO_DEBUG 175#ifdef QT_NO_DEBUG
150inline 176inline
151#endif 177#endif
152int OPrivateIOCTL::typeSetArgs() const 178int OPrivateIOCTL::typeSetArgs() const
153{ 179{
154 return _setargs & IW_PRIV_TYPE_MASK >> 12; 180 return _setargs & IW_PRIV_TYPE_MASK >> 12;
155} 181}
156 182
157 183
158void OPrivateIOCTL::invoke() const 184void OPrivateIOCTL::invoke() const
159{ 185{
160 ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl ); 186 ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl );
161} 187}
162 188
163 189
164void OPrivateIOCTL::setParameter( int num, u_int32_t value ) 190void OPrivateIOCTL::setParameter( int num, u_int32_t value )
165{ 191{
166 u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; 192 u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name;
167 arglist[num] = value; 193 arglist[num] = value;
168} 194}
169 195
170/*====================================================================================== 196/*======================================================================================
171 * assorted functions 197 * assorted functions
172 *======================================================================================*/ 198 *======================================================================================*/
173 199
174void dumpBytes( const unsigned char* data, int num ) 200void dumpBytes( const unsigned char* data, int num )
175{ 201{
176 printf( "Dumping %d bytes @ %0x", num, data ); 202 printf( "Dumping %d bytes @ %0x", num, data );
177 printf( "-------------------------------------------\n" ); 203 printf( "-------------------------------------------\n" );
178 204
179 for ( int i = 0; i < num; ++i ) 205 for ( int i = 0; i < num; ++i )
180 { 206 {
181 printf( "%02x ", data[i] ); 207 printf( "%02x ", data[i] );
182 if ( !((i+1) % 32) ) printf( "\n" ); 208 if ( !((i+1) % 32) ) printf( "\n" );
183 } 209 }
184 printf( "\n\n" ); 210 printf( "\n\n" );
185} 211}
186 212
diff --git a/libopie2/opienet/onetutils.h b/libopie2/opienet/onetutils.h
index 8be042b..73d52cc 100644
--- a/libopie2/opienet/onetutils.h
+++ b/libopie2/opienet/onetutils.h
@@ -1,154 +1,157 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3 3
4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 4              (C) 2003 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
5 =. 5 =.
6 .=l. 6 .=l.
7           .>+-= 7           .>+-=
8 _;:,     .>    :=|. This program is free software; you can 8 _;:,     .>    :=|. This program is free software; you can
9.> <`_,   >  .   <= redistribute it and/or modify it under 9.> <`_,   >  .   <= redistribute it and/or modify it under
10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 10:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
11.="- .-=="i,     .._ License as published by the Free Software 11.="- .-=="i,     .._ License as published by the Free Software
12 - .   .-<_>     .<> Foundation; either version 2 of the License, 12 - .   .-<_>     .<> Foundation; either version 2 of the License,
13     ._= =}       : or (at your option) any later version. 13     ._= =}       : or (at your option) any later version.
14    .%`+i>       _;_. 14    .%`+i>       _;_.
15    .i_,=:_.      -<s. This program is distributed in the hope that 15    .i_,=:_.      -<s. This program is distributed in the hope that
16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 16     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
17    : ..    .:,     . . . without even the implied warranty of 17    : ..    .:,     . . . without even the implied warranty of
18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 18    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 19  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
20..}^=.=       =       ; Library General Public License for more 20..}^=.=       =       ; Library General Public License for more
21++=   -.     .`     .: details. 21++=   -.     .`     .: details.
22 :     =  ...= . :.=- 22 :     =  ...= . :.=-
23 -.   .:....=;==+<; You should have received a copy of the GNU 23 -.   .:....=;==+<; You should have received a copy of the GNU
24  -_. . .   )=.  = Library General Public License along with 24  -_. . .   )=.  = Library General Public License along with
25    --        :-=` this library; see the file COPYING.LIB. 25    --        :-=` this library; see the file COPYING.LIB.
26 If not, write to the Free Software Foundation, 26 If not, write to the Free Software Foundation,
27 Inc., 59 Temple Place - Suite 330, 27 Inc., 59 Temple Place - Suite 330,
28 Boston, MA 02111-1307, USA. 28 Boston, MA 02111-1307, USA.
29 29
30*/ 30*/
31 31
32#ifndef ONETUTILS_H 32#ifndef ONETUTILS_H
33#define ONETUTILS_H 33#define ONETUTILS_H
34 34
35#include <qdict.h> 35#include <qdict.h>
36#include <qmap.h> 36#include <qmap.h>
37#include <qstring.h> 37#include <qstring.h>
38#include <qhostaddress.h> 38#include <qhostaddress.h>
39#include <qobject.h> 39#include <qobject.h>
40 40
41#include <sys/types.h> 41#include <sys/types.h>
42 42
43struct ifreq; 43struct ifreq;
44class OWirelessNetworkInterface; 44class OWirelessNetworkInterface;
45 45
46/*====================================================================================== 46/*======================================================================================
47 * OMacAddress 47 * OMacAddress
48 *======================================================================================*/ 48 *======================================================================================*/
49 49
50class OMacAddress 50class OMacAddress
51{ 51{
52 public: 52 public:
53 OMacAddress( unsigned char* ); 53 OMacAddress( unsigned char* );
54 OMacAddress( const unsigned char* ); 54 OMacAddress( const unsigned char* );
55 OMacAddress( struct ifreq& ); 55 OMacAddress( struct ifreq& );
56 ~OMacAddress(); 56 ~OMacAddress();
57 57
58 QString toString() const; 58 QString toString() const;
59 const unsigned char* native() const;
60
61 static OMacAddress fromString( const QString& );
59 62
60 public: 63 public:
61 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff 64 static const OMacAddress& broadcast; // ff:ff:ff:ff:ff:ff
62 static const OMacAddress& unknown; // 44:44:44:44:44:44 65 static const OMacAddress& unknown; // 44:44:44:44:44:44
63 66
64 private: 67 private:
65 unsigned char _bytes[6]; 68 unsigned char _bytes[6];
66 69
67 friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); 70 friend bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
68 71
69}; 72};
70 73
71bool operator==( const OMacAddress &m1, const OMacAddress &m2 ); 74bool operator==( const OMacAddress &m1, const OMacAddress &m2 );
72 75
73 76
74/*====================================================================================== 77/*======================================================================================
75 * OHostAddress 78 * OHostAddress
76 *======================================================================================*/ 79 *======================================================================================*/
77 80
78class OHostAddress : public QHostAddress 81class OHostAddress : public QHostAddress
79{ 82{
80 public: 83 public:
81 OHostAddress(); 84 OHostAddress();
82 ~OHostAddress(); 85 ~OHostAddress();
83}; 86};
84 87
85 88
86/*====================================================================================== 89/*======================================================================================
87 * OPrivateIOCTL 90 * OPrivateIOCTL
88 *======================================================================================*/ 91 *======================================================================================*/
89 92
90class OPrivateIOCTL : public QObject 93class OPrivateIOCTL : public QObject
91{ 94{
92 public: 95 public:
93 OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ); 96 OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs );
94 ~OPrivateIOCTL(); 97 ~OPrivateIOCTL();
95 98
96 int numberGetArgs() const; 99 int numberGetArgs() const;
97 int typeGetArgs() const; 100 int typeGetArgs() const;
98 int numberSetArgs() const; 101 int numberSetArgs() const;
99 int typeSetArgs() const; 102 int typeSetArgs() const;
100 103
101 void invoke() const; 104 void invoke() const;
102 void setParameter( int, u_int32_t ); 105 void setParameter( int, u_int32_t );
103 106
104 private: 107 private:
105 u_int32_t _ioctl; 108 u_int32_t _ioctl;
106 u_int16_t _getargs; 109 u_int16_t _getargs;
107 u_int16_t _setargs; 110 u_int16_t _setargs;
108 111
109}; 112};
110 113
111 /*====================================================================================== 114 /*======================================================================================
112 * Miscellaneous 115 * Miscellaneous
113 *======================================================================================*/ 116 *======================================================================================*/
114 117
115/* dump bytes */ 118/* dump bytes */
116 119
117void dumpBytes( const unsigned char* data, int num ); 120void dumpBytes( const unsigned char* data, int num );
118 121
119/* Network to host order macros */ 122/* Network to host order macros */
120 123
121#ifdef LBL_ALIGN 124#ifdef LBL_ALIGN
122#define EXTRACT_16BITS(p) \ 125#define EXTRACT_16BITS(p) \
123 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \ 126 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 0) << 8 | \
124 (u_int16_t)*((const u_int8_t *)(p) + 1))) 127 (u_int16_t)*((const u_int8_t *)(p) + 1)))
125#define EXTRACT_32BITS(p) \ 128#define EXTRACT_32BITS(p) \
126 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \ 129 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 24 | \
127 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \ 130 (u_int32_t)*((const u_int8_t *)(p) + 1) << 16 | \
128 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \ 131 (u_int32_t)*((const u_int8_t *)(p) + 2) << 8 | \
129 (u_int32_t)*((const u_int8_t *)(p) + 3))) 132 (u_int32_t)*((const u_int8_t *)(p) + 3)))
130#else 133#else
131#define EXTRACT_16BITS(p) \ 134#define EXTRACT_16BITS(p) \
132 ((u_int16_t)ntohs(*(const u_int16_t *)(p))) 135 ((u_int16_t)ntohs(*(const u_int16_t *)(p)))
133#define EXTRACT_32BITS(p) \ 136#define EXTRACT_32BITS(p) \
134 ((u_int32_t)ntohl(*(const u_int32_t *)(p))) 137 ((u_int32_t)ntohl(*(const u_int32_t *)(p)))
135#endif 138#endif
136 139
137#define EXTRACT_24BITS(p) \ 140#define EXTRACT_24BITS(p) \
138 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \ 141 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 0) << 16 | \
139 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ 142 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
140 (u_int32_t)*((const u_int8_t *)(p) + 2))) 143 (u_int32_t)*((const u_int8_t *)(p) + 2)))
141 144
142/* Little endian protocol host order macros */ 145/* Little endian protocol host order macros */
143#define EXTRACT_LE_8BITS(p) (*(p)) 146#define EXTRACT_LE_8BITS(p) (*(p))
144#define EXTRACT_LE_16BITS(p) \ 147#define EXTRACT_LE_16BITS(p) \
145 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \ 148 ((u_int16_t)((u_int16_t)*((const u_int8_t *)(p) + 1) << 8 | \
146 (u_int16_t)*((const u_int8_t *)(p) + 0))) 149 (u_int16_t)*((const u_int8_t *)(p) + 0)))
147#define EXTRACT_LE_32BITS(p) \ 150#define EXTRACT_LE_32BITS(p) \
148 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \ 151 ((u_int32_t)((u_int32_t)*((const u_int8_t *)(p) + 3) << 24 | \
149 (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \ 152 (u_int32_t)*((const u_int8_t *)(p) + 2) << 16 | \
150 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \ 153 (u_int32_t)*((const u_int8_t *)(p) + 1) << 8 | \
151 (u_int32_t)*((const u_int8_t *)(p) + 0))) 154 (u_int32_t)*((const u_int8_t *)(p) + 0)))
152 155
153#endif // ONETUTILS_H 156#endif // ONETUTILS_H
154 157
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index f52279a..e916c44 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,916 +1,910 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34/* OPIE */ 34/* OPIE */
35 35
36#include <opie2/onetwork.h> 36#include <opie2/onetwork.h>
37 37
38/* QT */ 38/* QT */
39 39
40#include <qfile.h> 40#include <qfile.h>
41#include <qtextstream.h> 41#include <qtextstream.h>
42 42
43/* UNIX */ 43/* UNIX */
44 44
45#include <arpa/inet.h> 45#include <arpa/inet.h>
46#include <cerrno> 46#include <cerrno>
47#include <cstring> 47#include <cstring>
48#include <cstdlib> 48#include <cstdlib>
49#include <math.h> 49#include <math.h>
50#include <sys/ioctl.h> 50#include <sys/ioctl.h>
51#include <sys/socket.h> 51#include <sys/socket.h>
52#include <sys/types.h> 52#include <sys/types.h>
53#include <unistd.h> 53#include <unistd.h>
54#include <linux/sockios.h> 54#include <linux/sockios.h>
55#include <net/if_arp.h> 55#include <net/if_arp.h>
56#include <stdarg.h> 56#include <stdarg.h>
57 57
58using namespace std; 58using namespace std;
59 59
60/*====================================================================================== 60/*======================================================================================
61 * ONetwork 61 * ONetwork
62 *======================================================================================*/ 62 *======================================================================================*/
63 63
64ONetwork* ONetwork::_instance = 0; 64ONetwork* ONetwork::_instance = 0;
65 65
66ONetwork::ONetwork() 66ONetwork::ONetwork()
67{ 67{
68 qDebug( "ONetwork::ONetwork()" ); 68 qDebug( "ONetwork::ONetwork()" );
69 synchronize(); 69 synchronize();
70} 70}
71 71
72void ONetwork::synchronize() 72void ONetwork::synchronize()
73{ 73{
74 // gather available interfaces by inspecting /proc/net/dev 74 // gather available interfaces by inspecting /proc/net/dev
75 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 75 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
76 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 76 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
77 77
78 _interfaces.clear(); 78 _interfaces.clear();
79 QString str; 79 QString str;
80 QFile f( "/proc/net/dev" ); 80 QFile f( "/proc/net/dev" );
81 bool hasFile = f.open( IO_ReadOnly ); 81 bool hasFile = f.open( IO_ReadOnly );
82 if ( !hasFile ) 82 if ( !hasFile )
83 { 83 {
84 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); 84 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
85 return; 85 return;
86 } 86 }
87 QTextStream s( &f ); 87 QTextStream s( &f );
88 s.readLine(); 88 s.readLine();
89 s.readLine(); 89 s.readLine();
90 while ( !s.atEnd() ) 90 while ( !s.atEnd() )
91 { 91 {
92 s >> str; 92 s >> str;
93 str.truncate( str.find( ':' ) ); 93 str.truncate( str.find( ':' ) );
94 qDebug( "ONetwork: found interface '%s'", (const char*) str ); 94 qDebug( "ONetwork: found interface '%s'", (const char*) str );
95 ONetworkInterface* iface; 95 ONetworkInterface* iface;
96 if ( isWirelessInterface( str ) ) 96 if ( isWirelessInterface( str ) )
97 { 97 {
98 iface = new OWirelessNetworkInterface( this, (const char*) str ); 98 iface = new OWirelessNetworkInterface( this, (const char*) str );
99 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); 99 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str );
100 } 100 }
101 else 101 else
102 { 102 {
103 iface = new ONetworkInterface( this, (const char*) str ); 103 iface = new ONetworkInterface( this, (const char*) str );
104 } 104 }
105 _interfaces.insert( str, iface ); 105 _interfaces.insert( str, iface );
106 s.readLine(); 106 s.readLine();
107 } 107 }
108} 108}
109 109
110 110
111ONetworkInterface* ONetwork::interface( QString iface ) const 111ONetworkInterface* ONetwork::interface( QString iface ) const
112{ 112{
113 return _interfaces[iface]; 113 return _interfaces[iface];
114} 114}
115 115
116 116
117ONetwork* ONetwork::instance() 117ONetwork* ONetwork::instance()
118{ 118{
119 if ( !_instance ) _instance = new ONetwork(); 119 if ( !_instance ) _instance = new ONetwork();
120 return _instance; 120 return _instance;
121} 121}
122 122
123 123
124ONetwork::InterfaceIterator ONetwork::iterator() const 124ONetwork::InterfaceIterator ONetwork::iterator() const
125{ 125{
126 return ONetwork::InterfaceIterator( _interfaces ); 126 return ONetwork::InterfaceIterator( _interfaces );
127} 127}
128 128
129 129
130bool ONetwork::isWirelessInterface( const char* name ) const 130bool ONetwork::isWirelessInterface( const char* name ) const
131{ 131{
132 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 132 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
133 struct iwreq iwr; 133 struct iwreq iwr;
134 memset( &iwr, 0, sizeof( struct iwreq ) ); 134 memset( &iwr, 0, sizeof( struct iwreq ) );
135 strcpy( (char*) &iwr.ifr_name, name ); 135 strcpy( (char*) &iwr.ifr_name, name );
136 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 136 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
137 return result != -1; 137 return result != -1;
138} 138}
139 139
140/*====================================================================================== 140/*======================================================================================
141 * ONetworkInterface 141 * ONetworkInterface
142 *======================================================================================*/ 142 *======================================================================================*/
143 143
144ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) 144ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
145 :QObject( parent, name ), 145 :QObject( parent, name ),
146 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 146 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
147{ 147{
148 qDebug( "ONetworkInterface::ONetworkInterface()" ); 148 qDebug( "ONetworkInterface::ONetworkInterface()" );
149 init(); 149 init();
150} 150}
151 151
152 152
153struct ifreq& ONetworkInterface::ifr() const 153struct ifreq& ONetworkInterface::ifr() const
154{ 154{
155 return _ifr; 155 return _ifr;
156} 156}
157 157
158 158
159void ONetworkInterface::init() 159void ONetworkInterface::init()
160{ 160{
161 qDebug( "ONetworkInterface::init()" ); 161 qDebug( "ONetworkInterface::init()" );
162 162
163 memset( &_ifr, 0, sizeof( struct ifreq ) ); 163 memset( &_ifr, 0, sizeof( struct ifreq ) );
164 164
165 if ( _sfd == -1 ) 165 if ( _sfd == -1 )
166 { 166 {
167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); 167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() );
168 return; 168 return;
169 } 169 }
170} 170}
171 171
172 172
173bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const 173bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
174{ 174{
175 int result = ::ioctl( _sfd, call, &ifreq ); 175 int result = ::ioctl( _sfd, call, &ifreq );
176 if ( result == -1 ) 176 if ( result == -1 )
177 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 177 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
178 else 178 else
179 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); 179 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call );
180 return ( result != -1 ); 180 return ( result != -1 );
181} 181}
182 182
183 183
184bool ONetworkInterface::ioctl( int call ) const 184bool ONetworkInterface::ioctl( int call ) const
185{ 185{
186 strcpy( _ifr.ifr_name, name() ); 186 strcpy( _ifr.ifr_name, name() );
187 return ioctl( call, _ifr ); 187 return ioctl( call, _ifr );
188} 188}
189 189
190 190
191bool ONetworkInterface::isLoopback() const 191bool ONetworkInterface::isLoopback() const
192{ 192{
193 ioctl( SIOCGIFFLAGS ); 193 ioctl( SIOCGIFFLAGS );
194 return _ifr.ifr_flags & IFF_LOOPBACK; 194 return _ifr.ifr_flags & IFF_LOOPBACK;
195} 195}
196 196
197 197
198bool ONetworkInterface::setUp( bool b ) 198bool ONetworkInterface::setUp( bool b )
199{ 199{
200 ioctl( SIOCGIFFLAGS ); 200 ioctl( SIOCGIFFLAGS );
201 if ( b ) _ifr.ifr_flags |= IFF_UP; 201 if ( b ) _ifr.ifr_flags |= IFF_UP;
202 else _ifr.ifr_flags &= (~IFF_UP); 202 else _ifr.ifr_flags &= (~IFF_UP);
203 return ioctl( SIOCSIFFLAGS ); 203 return ioctl( SIOCSIFFLAGS );
204} 204}
205 205
206 206
207bool ONetworkInterface::isUp() const 207bool ONetworkInterface::isUp() const
208{ 208{
209 ioctl( SIOCGIFFLAGS ); 209 ioctl( SIOCGIFFLAGS );
210 return _ifr.ifr_flags & IFF_UP; 210 return _ifr.ifr_flags & IFF_UP;
211} 211}
212 212
213 213
214QString ONetworkInterface::ipV4Address() const 214QString ONetworkInterface::ipV4Address() const
215{ 215{
216 if ( ioctl( SIOCGIFADDR ) ) 216 if ( ioctl( SIOCGIFADDR ) )
217 { 217 {
218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
219 //FIXME: Use QHostAddress here 219 //FIXME: Use QHostAddress here
220 return QString( inet_ntoa( sa->sin_addr ) ); 220 return QString( inet_ntoa( sa->sin_addr ) );
221 } 221 }
222 else 222 else
223 return "<unknown>"; 223 return "<unknown>";
224} 224}
225 225
226 226
227void ONetworkInterface::setMacAddress( const OMacAddress& addr )
228{
229 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
230 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
231 ioctl( SIOCSIFHWADDR );
232}
233
234
227OMacAddress ONetworkInterface::macAddress() const 235OMacAddress ONetworkInterface::macAddress() const
228{ 236{
229 if ( ioctl( SIOCGIFHWADDR ) ) 237 if ( ioctl( SIOCGIFHWADDR ) )
230 { 238 {
231 return OMacAddress( _ifr ); 239 return OMacAddress( _ifr );
232 } 240 }
233 else 241 else
234 { 242 {
235 return OMacAddress::unknown; 243 return OMacAddress::unknown;
236 } 244 }
237} 245}
238 246
239 247
240int ONetworkInterface::dataLinkType() const 248int ONetworkInterface::dataLinkType() const
241{ 249{
242 if ( ioctl( SIOCGIFHWADDR ) ) 250 if ( ioctl( SIOCGIFHWADDR ) )
243 { 251 {
244 return _ifr.ifr_hwaddr.sa_family; 252 return _ifr.ifr_hwaddr.sa_family;
245 } 253 }
246 else 254 else
247 { 255 {
248 return -1; 256 return -1;
249 } 257 }
250} 258}
251 259
252 260
253void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 261void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
254{ 262{
255 _mon = m; 263 _mon = m;
256 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); 264 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() );
257} 265}
258 266
259 267
260OMonitoringInterface* ONetworkInterface::monitoring() const 268OMonitoringInterface* ONetworkInterface::monitoring() const
261{ 269{
262 return _mon; 270 return _mon;
263} 271}
264 272
265 273
266ONetworkInterface::~ONetworkInterface() 274ONetworkInterface::~ONetworkInterface()
267{ 275{
268 qDebug( "ONetworkInterface::~ONetworkInterface()" ); 276 qDebug( "ONetworkInterface::~ONetworkInterface()" );
269 if ( _sfd != -1 ) ::close( _sfd ); 277 if ( _sfd != -1 ) ::close( _sfd );
270} 278}
271 279
272 280
273bool ONetworkInterface::setPromiscuousMode( bool b ) 281bool ONetworkInterface::setPromiscuousMode( bool b )
274{ 282{
275 ioctl( SIOCGIFFLAGS ); 283 ioctl( SIOCGIFFLAGS );
276 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 284 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
277 else _ifr.ifr_flags &= (~IFF_PROMISC); 285 else _ifr.ifr_flags &= (~IFF_PROMISC);
278 return ioctl( SIOCSIFFLAGS ); 286 return ioctl( SIOCSIFFLAGS );
279} 287}
280 288
281 289
282bool ONetworkInterface::promiscuousMode() const 290bool ONetworkInterface::promiscuousMode() const
283{ 291{
284 ioctl( SIOCGIFFLAGS ); 292 ioctl( SIOCGIFFLAGS );
285 return _ifr.ifr_flags & IFF_PROMISC; 293 return _ifr.ifr_flags & IFF_PROMISC;
286} 294}
287 295
288 296
289bool ONetworkInterface::isWireless() const 297bool ONetworkInterface::isWireless() const
290{ 298{
291 return ioctl( SIOCGIWNAME ); 299 return ioctl( SIOCGIWNAME );
292} 300}
293 301
294 302
295/*====================================================================================== 303/*======================================================================================
296 * OChannelHopper 304 * OChannelHopper
297 *======================================================================================*/ 305 *======================================================================================*/
298 306
299OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 307OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
300 :QObject( 0, "Mickey's funky hopper" ), 308 :QObject( 0, "Mickey's funky hopper" ),
301 _iface( iface ), _interval( 0 ), _tid( 0 ) 309 _iface( iface ), _interval( 0 ), _tid( 0 )
302{ 310{
303 int _maxChannel = iface->channels()+1; 311 int _maxChannel = iface->channels()+1;
304 // generate fancy hopping sequence honoring the device capabilities 312 // generate fancy hopping sequence honoring the device capabilities
305 if ( _maxChannel >= 1 ) _channels.append( 1 ); 313 if ( _maxChannel >= 1 ) _channels.append( 1 );
306 if ( _maxChannel >= 7 ) _channels.append( 7 ); 314 if ( _maxChannel >= 7 ) _channels.append( 7 );
307 if ( _maxChannel >= 13 ) _channels.append( 13 ); 315 if ( _maxChannel >= 13 ) _channels.append( 13 );
308 if ( _maxChannel >= 2 ) _channels.append( 2 ); 316 if ( _maxChannel >= 2 ) _channels.append( 2 );
309 if ( _maxChannel >= 8 ) _channels.append( 8 ); 317 if ( _maxChannel >= 8 ) _channels.append( 8 );
310 if ( _maxChannel >= 3 ) _channels.append( 3 ); 318 if ( _maxChannel >= 3 ) _channels.append( 3 );
311 if ( _maxChannel >= 14 ) _channels.append( 14 ); 319 if ( _maxChannel >= 14 ) _channels.append( 14 );
312 if ( _maxChannel >= 9 ) _channels.append( 9 ); 320 if ( _maxChannel >= 9 ) _channels.append( 9 );
313 if ( _maxChannel >= 4 ) _channels.append( 4 ); 321 if ( _maxChannel >= 4 ) _channels.append( 4 );
314 if ( _maxChannel >= 10 ) _channels.append( 10 ); 322 if ( _maxChannel >= 10 ) _channels.append( 10 );
315 if ( _maxChannel >= 5 ) _channels.append( 5 ); 323 if ( _maxChannel >= 5 ) _channels.append( 5 );
316 if ( _maxChannel >= 11 ) _channels.append( 11 ); 324 if ( _maxChannel >= 11 ) _channels.append( 11 );
317 if ( _maxChannel >= 6 ) _channels.append( 6 ); 325 if ( _maxChannel >= 6 ) _channels.append( 6 );
318 if ( _maxChannel >= 12 ) _channels.append( 12 ); 326 if ( _maxChannel >= 12 ) _channels.append( 12 );
319 _channel = _channels.begin(); 327 _channel = _channels.begin();
320 328
321} 329}
322 330
323 331
324OChannelHopper::~OChannelHopper() 332OChannelHopper::~OChannelHopper()
325{ 333{
326} 334}
327 335
328 336
329bool OChannelHopper::isActive() const 337bool OChannelHopper::isActive() const
330{ 338{
331 return _tid; 339 return _tid;
332} 340}
333 341
334 342
335int OChannelHopper::channel() const 343int OChannelHopper::channel() const
336{ 344{
337 return *_channel; 345 return *_channel;
338} 346}
339 347
340 348
341void OChannelHopper::timerEvent( QTimerEvent* ) 349void OChannelHopper::timerEvent( QTimerEvent* )
342{ 350{
343 _iface->setChannel( *_channel ); 351 _iface->setChannel( *_channel );
344 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", 352 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
345 *_channel, (const char*) _iface->name() ); 353 *_channel, (const char*) _iface->name() );
346 if ( ++_channel == _channels.end() ) _channel = _channels.begin(); 354 if ( ++_channel == _channels.end() ) _channel = _channels.begin();
347} 355}
348 356
349 357
350void OChannelHopper::setInterval( int interval ) 358void OChannelHopper::setInterval( int interval )
351{ 359{
352 if ( interval == _interval ) 360 if ( interval == _interval )
353 return; 361 return;
354 362
355 if ( _interval ) 363 if ( _interval )
356 killTimer( _tid ); 364 killTimer( _tid );
357 365
358 _tid = 0; 366 _tid = 0;
359 _interval = interval; 367 _interval = interval;
360 368
361 if ( _interval ) 369 if ( _interval )
362 { 370 {
363 _tid = startTimer( interval ); 371 _tid = startTimer( interval );
364 } 372 }
365} 373}
366 374
367 375
368int OChannelHopper::interval() const 376int OChannelHopper::interval() const
369{ 377{
370 return _interval; 378 return _interval;
371} 379}
372 380
373 381
374/*====================================================================================== 382/*======================================================================================
375 * OWirelessNetworkInterface 383 * OWirelessNetworkInterface
376 *======================================================================================*/ 384 *======================================================================================*/
377 385
378OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) 386OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name )
379 :ONetworkInterface( parent, name ), _hopper( 0 ) 387 :ONetworkInterface( parent, name ), _hopper( 0 )
380{ 388{
381 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 389 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
382 init(); 390 init();
383} 391}
384 392
385 393
386OWirelessNetworkInterface::~OWirelessNetworkInterface() 394OWirelessNetworkInterface::~OWirelessNetworkInterface()
387{ 395{
388} 396}
389 397
390 398
391struct iwreq& OWirelessNetworkInterface::iwr() const 399struct iwreq& OWirelessNetworkInterface::iwr() const
392{ 400{
393 return _iwr; 401 return _iwr;
394} 402}
395 403
396 404
397void OWirelessNetworkInterface::init() 405void OWirelessNetworkInterface::init()
398{ 406{
399 qDebug( "OWirelessNetworkInterface::init()" ); 407 qDebug( "OWirelessNetworkInterface::init()" );
400 memset( &_iwr, 0, sizeof( struct iwreq ) ); 408 memset( &_iwr, 0, sizeof( struct iwreq ) );
401 buildChannelList(); 409 buildChannelList();
402 buildPrivateList(); 410 buildPrivateList();
403} 411}
404 412
405 413
406QString OWirelessNetworkInterface::associatedAP() const 414QString OWirelessNetworkInterface::associatedAP() const
407{ 415{
408 //FIXME: use OMacAddress 416 //FIXME: use OMacAddress
409 QString mac; 417 QString mac;
410 418
411 if ( ioctl( SIOCGIWAP ) ) 419 if ( ioctl( SIOCGIWAP ) )
412 { 420 {
413 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 421 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
414 _ifr.ifr_hwaddr.sa_data[0]&0xff, 422 _ifr.ifr_hwaddr.sa_data[0]&0xff,
415 _ifr.ifr_hwaddr.sa_data[1]&0xff, 423 _ifr.ifr_hwaddr.sa_data[1]&0xff,
416 _ifr.ifr_hwaddr.sa_data[2]&0xff, 424 _ifr.ifr_hwaddr.sa_data[2]&0xff,
417 _ifr.ifr_hwaddr.sa_data[3]&0xff, 425 _ifr.ifr_hwaddr.sa_data[3]&0xff,
418 _ifr.ifr_hwaddr.sa_data[4]&0xff, 426 _ifr.ifr_hwaddr.sa_data[4]&0xff,
419 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 427 _ifr.ifr_hwaddr.sa_data[5]&0xff );
420 } 428 }
421 else 429 else
422 { 430 {
423 mac = "<Unknown>"; 431 mac = "<Unknown>";
424 } 432 }
425 return mac; 433 return mac;
426} 434}
427 435
428 436
429void OWirelessNetworkInterface::buildChannelList() 437void OWirelessNetworkInterface::buildChannelList()
430{ 438{
431 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 439 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
432 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 440 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
433 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 441 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
434 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 442 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
435 //ML: _too much_ space. This is damn shitty crap *sigh* 443 //ML: _too much_ space. This is damn shitty crap *sigh*
436 //ML: We allocate a large memory region in RAM and check whether the 444 //ML: We allocate a large memory region in RAM and check whether the
437 //ML: driver pollutes this extra space. The complaint will be made on stdout, 445 //ML: driver pollutes this extra space. The complaint will be made on stdout,
438 //ML: so please forward this... 446 //ML: so please forward this...
439 447
440 struct iwreq wrq; 448 struct iwreq wrq;
441 int len = sizeof( struct iw_range )*2; 449 int len = sizeof( struct iw_range )*2;
442 char *buffer = (char*) malloc( len ); 450 char *buffer = (char*) malloc( len );
443 //FIXME: Validate if we actually got the memory block 451 //FIXME: Validate if we actually got the memory block
444 memset( buffer, 0, len ); 452 memset( buffer, 0, len );
445 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 453 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
446 wrq.u.data.pointer = (caddr_t) buffer; 454 wrq.u.data.pointer = (caddr_t) buffer;
447 wrq.u.data.length = sizeof( struct iw_range ); 455 wrq.u.data.length = sizeof( struct iw_range );
448 wrq.u.data.flags = 0; 456 wrq.u.data.flags = 0;
449 457
450 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 458 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
451 { 459 {
452 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); 460 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) );
453 _channels.insert( 2412, 1 ); // 2.412 GHz 461 _channels.insert( 2412, 1 ); // 2.412 GHz
454 _channels.insert( 2417, 2 ); // 2.417 GHz 462 _channels.insert( 2417, 2 ); // 2.417 GHz
455 _channels.insert( 2422, 3 ); // 2.422 GHz 463 _channels.insert( 2422, 3 ); // 2.422 GHz
456 _channels.insert( 2427, 4 ); // 2.427 GHz 464 _channels.insert( 2427, 4 ); // 2.427 GHz
457 _channels.insert( 2432, 5 ); // 2.432 GHz 465 _channels.insert( 2432, 5 ); // 2.432 GHz
458 _channels.insert( 2437, 6 ); // 2.437 GHz 466 _channels.insert( 2437, 6 ); // 2.437 GHz
459 _channels.insert( 2442, 7 ); // 2.442 GHz 467 _channels.insert( 2442, 7 ); // 2.442 GHz
460 _channels.insert( 2447, 8 ); // 2.447 GHz 468 _channels.insert( 2447, 8 ); // 2.447 GHz
461 _channels.insert( 2452, 9 ); // 2.452 GHz 469 _channels.insert( 2452, 9 ); // 2.452 GHz
462 _channels.insert( 2457, 10 ); // 2.457 GHz 470 _channels.insert( 2457, 10 ); // 2.457 GHz
463 _channels.insert( 2462, 11 ); // 2.462 GHz 471 _channels.insert( 2462, 11 ); // 2.462 GHz
464 } 472 }
465 else 473 else
466 { 474 {
467 // <check if the driver overwrites stuff> 475 // <check if the driver overwrites stuff>
468 int max = 0; 476 int max = 0;
469 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 477 for ( int r = sizeof( struct iw_range ); r < len; r++ )
470 if (buffer[r] != 0) 478 if (buffer[r] != 0)
471 max = r; 479 max = r;
472 if (max > 0) 480 if (max > 0)
473 { 481 {
474 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" 482 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'"
475 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); 483 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
476 } 484 }
477 // </check if the driver overwrites stuff> 485 // </check if the driver overwrites stuff>
478 486
479 struct iw_range range; 487 struct iw_range range;
480 memcpy( &range, buffer, sizeof range ); 488 memcpy( &range, buffer, sizeof range );
481 489
482 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); 490 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency );
483 for ( int i = 0; i < range.num_frequency; ++i ) 491 for ( int i = 0; i < range.num_frequency; ++i )
484 { 492 {
485 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 493 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
486 _channels.insert( freq, i+1 ); 494 _channels.insert( freq, i+1 );
487 } 495 }
488 } 496 }
489 497
490 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); 498 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." );
491 free(buffer); 499 free(buffer);
492} 500}
493 501
494 502
495void OWirelessNetworkInterface::buildPrivateList() 503void OWirelessNetworkInterface::buildPrivateList()
496{ 504{
497 qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); 505 qDebug( "OWirelessNetworkInterface::buildPrivateList()" );
498 506
499 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 507 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
500 508
501 _iwr.u.data.pointer = (char*) &priv; 509 _iwr.u.data.pointer = (char*) &priv;
502 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 510 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
503 _iwr.u.data.flags = 0; 511 _iwr.u.data.flags = 0;
504 512
505 if ( !wioctl( SIOCGIWPRIV ) ) 513 if ( !wioctl( SIOCGIWPRIV ) )
506 { 514 {
507 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); 515 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) );
508 return; 516 return;
509 } 517 }
510 518
511 for ( int i = 0; i < _iwr.u.data.length; ++i ) 519 for ( int i = 0; i < _iwr.u.data.length; ++i )
512 { 520 {
513 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 521 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
514 } 522 }
515 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); 523 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
516} 524}
517 525
518 526
519int OWirelessNetworkInterface::channel() const 527int OWirelessNetworkInterface::channel() const
520{ 528{
521 //FIXME: When monitoring enabled, then use it 529 //FIXME: When monitoring enabled, then use it
522 //FIXME: to gather the current RF channel 530 //FIXME: to gather the current RF channel
523 //FIXME: Until then, get active channel from hopper. 531 //FIXME: Until then, get active channel from hopper.
524 if ( _hopper && _hopper->isActive() ) 532 if ( _hopper && _hopper->isActive() )
525 return _hopper->channel(); 533 return _hopper->channel();
526 534
527 if ( !wioctl( SIOCGIWFREQ ) ) 535 if ( !wioctl( SIOCGIWFREQ ) )
528 { 536 {
529 return -1; 537 return -1;
530 } 538 }
531 else 539 else
532 { 540 {
533 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 541 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
534 } 542 }
535} 543}
536 544
537 545
538void OWirelessNetworkInterface::setChannel( int c ) const 546void OWirelessNetworkInterface::setChannel( int c ) const
539{ 547{
540 if ( !_mon ) 548 if ( !_mon )
541 { 549 {
542 memset( &_iwr, 0, sizeof( struct iwreq ) ); 550 memset( &_iwr, 0, sizeof( struct iwreq ) );
543 _iwr.u.freq.m = c; 551 _iwr.u.freq.m = c;
544 _iwr.u.freq.e = 0; 552 _iwr.u.freq.e = 0;
545 wioctl( SIOCSIWFREQ ); 553 wioctl( SIOCSIWFREQ );
546 } 554 }
547 else 555 else
548 { 556 {
549 _mon->setChannel( c ); 557 _mon->setChannel( c );
550 } 558 }
551} 559}
552 560
553 561
554double OWirelessNetworkInterface::frequency() const 562double OWirelessNetworkInterface::frequency() const
555{ 563{
556 if ( !wioctl( SIOCGIWFREQ ) ) 564 if ( !wioctl( SIOCGIWFREQ ) )
557 { 565 {
558 return -1.0; 566 return -1.0;
559 } 567 }
560 else 568 else
561 { 569 {
562 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 570 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
563 } 571 }
564} 572}
565 573
566 574
567int OWirelessNetworkInterface::channels() const 575int OWirelessNetworkInterface::channels() const
568{ 576{
569 return _channels.count(); 577 return _channels.count();
570} 578}
571 579
572 580
573void OWirelessNetworkInterface::setChannelHopping( int interval ) 581void OWirelessNetworkInterface::setChannelHopping( int interval )
574{ 582{
575 if ( !_hopper ) _hopper = new OChannelHopper( this ); 583 if ( !_hopper ) _hopper = new OChannelHopper( this );
576 _hopper->setInterval( interval ); 584 _hopper->setInterval( interval );
577 //FIXME: When and by whom will the channel hopper be deleted? 585 //FIXME: When and by whom will the channel hopper be deleted?
578 //TODO: rely on QObject hierarchy 586 //TODO: rely on QObject hierarchy
579} 587}
580 588
581 589
582int OWirelessNetworkInterface::channelHopping() const 590int OWirelessNetworkInterface::channelHopping() const
583{ 591{
584 return _hopper->interval(); 592 return _hopper->interval();
585} 593}
586 594
587 595
588void OWirelessNetworkInterface::setMonitorMode( bool b ) 596void OWirelessNetworkInterface::setMonitorMode( bool b )
589{ 597{
590 if ( _mon ) 598 if ( _mon )
591 _mon->setEnabled( b ); 599 _mon->setEnabled( b );
592 else 600 else
593 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 601 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
594} 602}
595 603
596 604
597bool OWirelessNetworkInterface::monitorMode() const 605bool OWirelessNetworkInterface::monitorMode() const
598{ 606{
599 qDebug( "dataLinkType = %d", dataLinkType() ); 607 qDebug( "dataLinkType = %d", dataLinkType() );
600 return dataLinkType() == ARPHRD_IEEE80211; 608 return dataLinkType() == ARPHRD_IEEE80211;
601} 609}
602 610
603 611
604QString OWirelessNetworkInterface::nickName() const 612QString OWirelessNetworkInterface::nickName() const
605{ 613{
606 char str[IW_ESSID_MAX_SIZE]; 614 char str[IW_ESSID_MAX_SIZE];
607 _iwr.u.data.pointer = &str[0]; 615 _iwr.u.data.pointer = &str[0];
608 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 616 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
609 if ( !wioctl( SIOCGIWNICKN ) ) 617 if ( !wioctl( SIOCGIWNICKN ) )
610 { 618 {
611 return "<unknown>"; 619 return "<unknown>";
612 } 620 }
613 else 621 else
614 { 622 {
615 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 623 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
616 return str; 624 return str;
617 } 625 }
618} 626}
619 627
620 628
621void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 629void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
622{ 630{
623 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 631 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
624 if ( !priv ) 632 if ( !priv )
625 { 633 {
626 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); 634 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
627 return; 635 return;
628 } 636 }
629 if ( priv->numberSetArgs() != numargs ) 637 if ( priv->numberSetArgs() != numargs )
630 { 638 {
631 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); 639 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs );
632 return; 640 return;
633 } 641 }
634 642
635 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); 643 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() );
636 memset( &_iwr, 0, sizeof _iwr ); 644 memset( &_iwr, 0, sizeof _iwr );
637 va_list argp; 645 va_list argp;
638 va_start( argp, numargs ); 646 va_start( argp, numargs );
639 for ( int i = 0; i < numargs; ++i ) 647 for ( int i = 0; i < numargs; ++i )
640 { 648 {
641 priv->setParameter( i, va_arg( argp, int ) ); 649 priv->setParameter( i, va_arg( argp, int ) );
642 } 650 }
643 va_end( argp ); 651 va_end( argp );
644 priv->invoke(); 652 priv->invoke();
645} 653}
646 654
647 655
648void OWirelessNetworkInterface::getPrivate( const QString& call ) 656void OWirelessNetworkInterface::getPrivate( const QString& call )
649{ 657{
658 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
659}
660
661
662bool OWirelessNetworkInterface::hasPrivate( const QString& call )
663{
664 return child( (const char*) call );
650} 665}
651 666
652 667
653QString OWirelessNetworkInterface::SSID() const 668QString OWirelessNetworkInterface::SSID() const
654{ 669{
655 char str[IW_ESSID_MAX_SIZE]; 670 char str[IW_ESSID_MAX_SIZE];
656 _iwr.u.essid.pointer = &str[0]; 671 _iwr.u.essid.pointer = &str[0];
657 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 672 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
658 if ( !wioctl( SIOCGIWESSID ) ) 673 if ( !wioctl( SIOCGIWESSID ) )
659 { 674 {
660 return "<unknown>"; 675 return "<unknown>";
661 } 676 }
662 else 677 else
663 { 678 {
664 return str; 679 return str;
665 } 680 }
666} 681}
667 682
668 683
669void OWirelessNetworkInterface::setSSID( const QString& ssid ) 684void OWirelessNetworkInterface::setSSID( const QString& ssid )
670{ 685{
671 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 686 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
672 _iwr.u.essid.length = ssid.length(); 687 _iwr.u.essid.length = ssid.length();
673 wioctl( SIOCSIWESSID ); 688 wioctl( SIOCSIWESSID );
674} 689}
675 690
676 691
677bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 692bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
678{ 693{
679 int result = ::ioctl( _sfd, call, &iwreq ); 694 int result = ::ioctl( _sfd, call, &iwreq );
680 if ( result == -1 ) 695 if ( result == -1 )
681 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 696 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
682 else 697 else
683 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); 698 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call );
684 return ( result != -1 ); 699 return ( result != -1 );
685} 700}
686 701
687 702
688bool OWirelessNetworkInterface::wioctl( int call ) const 703bool OWirelessNetworkInterface::wioctl( int call ) const
689{ 704{
690 strcpy( _iwr.ifr_name, name() ); 705 strcpy( _iwr.ifr_name, name() );
691 return wioctl( call, _iwr ); 706 return wioctl( call, _iwr );
692} 707}
693 708
694 709
695/*====================================================================================== 710/*======================================================================================
696 * OMonitoringInterface 711 * OMonitoringInterface
697 *======================================================================================*/ 712 *======================================================================================*/
698 713
699OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) 714OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface )
700 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) 715 :_if( static_cast<OWirelessNetworkInterface*>( iface ) )
701{ 716{
702} 717}
703 718
704 719
705OMonitoringInterface::~OMonitoringInterface() 720OMonitoringInterface::~OMonitoringInterface()
706{ 721{
707} 722}
708 723
709 724
710void OMonitoringInterface::setChannel( int c ) 725void OMonitoringInterface::setChannel( int c )
711{ 726{
712 // use standard WE channel switching protocol 727 // use standard WE channel switching protocol
713 memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); 728 memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
714 _if->_iwr.u.freq.m = c; 729 _if->_iwr.u.freq.m = c;
715 _if->_iwr.u.freq.e = 0; 730 _if->_iwr.u.freq.e = 0;
716 _if->wioctl( SIOCSIWFREQ ); 731 _if->wioctl( SIOCSIWFREQ );
717} 732}
718 733
719 734
720bool OMonitoringInterface::enabled() const 735bool OMonitoringInterface::enabled() const
721{ 736{
722 return _if->monitorMode(); 737 return _if->monitorMode();
723} 738}
724 739
725 740
726void OMonitoringInterface::setEnabled( bool b ) 741void OMonitoringInterface::setEnabled( bool b )
727{ 742{
728} 743}
729 744
730 745
731/*====================================================================================== 746/*======================================================================================
732 * OCiscoMonitoringInterface 747 * OCiscoMonitoringInterface
733 *======================================================================================*/ 748 *======================================================================================*/
734 749
735OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) 750OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface )
736 :OMonitoringInterface( iface ) 751 :OMonitoringInterface( iface )
737{ 752{
738 iface->setMonitoring( this ); 753 iface->setMonitoring( this );
739} 754}
740 755
741 756
742OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 757OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
743{ 758{
744} 759}
745 760
746 761
747void OCiscoMonitoringInterface::setEnabled( bool b ) 762void OCiscoMonitoringInterface::setEnabled( bool b )
748{ 763{
749 QString fname; 764 QString fname;
750 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 765 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
751 QFile f( fname ); 766 QFile f( fname );
752 if ( !f.exists() ) return; 767 if ( !f.exists() ) return;
753 768
754 if ( f.open( IO_WriteOnly ) ) 769 if ( f.open( IO_WriteOnly ) )
755 { 770 {
756 QTextStream s( &f ); 771 QTextStream s( &f );
757 s << "Mode: r"; 772 s << "Mode: r";
758 s << "Mode: y"; 773 s << "Mode: y";
759 s << "XmitPower: 1"; 774 s << "XmitPower: 1";
760 } 775 }
761 776
762 // flushing and closing will be done automatically when f goes out of scope 777 // flushing and closing will be done automatically when f goes out of scope
763} 778}
764 779
765 780
766QString OCiscoMonitoringInterface::name() const 781QString OCiscoMonitoringInterface::name() const
767{ 782{
768 return "cisco"; 783 return "cisco";
769} 784}
770 785
771 786
772void OCiscoMonitoringInterface::setChannel( int ) 787void OCiscoMonitoringInterface::setChannel( int )
773{ 788{
774 // cisco devices automatically switch channels when in monitor mode 789 // cisco devices automatically switch channels when in monitor mode
775} 790}
776 791
777 792
778/*====================================================================================== 793/*======================================================================================
779 * OWlanNGMonitoringInterface 794 * OWlanNGMonitoringInterface
780 *======================================================================================*/ 795 *======================================================================================*/
781 796
782 797
783OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) 798OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface )
784 :OMonitoringInterface( iface ) 799 :OMonitoringInterface( iface )
785{ 800{
786 iface->setMonitoring( this ); 801 iface->setMonitoring( this );
787} 802}
788 803
789 804
790OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 805OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
791{ 806{
792} 807}
793 808
794 809
795void OWlanNGMonitoringInterface::setEnabled( bool b ) 810void OWlanNGMonitoringInterface::setEnabled( bool b )
796{ 811{
797 //FIXME: do nothing if its already in the same mode 812 //FIXME: do nothing if its already in the same mode
798 813
799 QString enable = b ? "true" : "false"; 814 QString enable = b ? "true" : "false";
800 QString cmd; 815 QString cmd;
801 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); 816 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable );
802 system( cmd ); 817 system( cmd );
803} 818}
804 819
805 820
806QString OWlanNGMonitoringInterface::name() const 821QString OWlanNGMonitoringInterface::name() const
807{ 822{
808 return "wlan-ng"; 823 return "wlan-ng";
809} 824}
810 825
811 826
812void OWlanNGMonitoringInterface::setChannel( int ) 827void OWlanNGMonitoringInterface::setChannel( int )
813{ 828{
814 // wlan-ng devices automatically switch channels when in monitor mode 829 // wlan-ng devices automatically switch channels when in monitor mode
815} 830}
816 831
817 832
818/*====================================================================================== 833/*======================================================================================
819 * OHostAPMonitoringInterface 834 * OHostAPMonitoringInterface
820 *======================================================================================*/ 835 *======================================================================================*/
821 836
822OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) 837OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface )
823 :OMonitoringInterface( iface ) 838 :OMonitoringInterface( iface )
824{ 839{
825 iface->setMonitoring( this ); 840 iface->setMonitoring( this );
826} 841}
827 842
828OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 843OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
829{ 844{
830} 845}
831 846
832void OHostAPMonitoringInterface::setEnabled( bool b ) 847void OHostAPMonitoringInterface::setEnabled( bool b )
833{ 848{
834 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 849 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
835 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 850 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
836 851
852 //TODO: check wireless extensions version on runtime and use
853 //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15
854
837 if ( b ) 855 if ( b )
838 { 856 {
839 #if WIRELESS_EXT > 14 857 _if->setPrivate( "monitor", 1, 2 );
840 _if->_iwr.u.mode = IW_MODE_MONITOR;
841 _if->wioctl( SIOCSIWMODE );
842 #else
843 int* args = (int*) &_if->_iwr.u.name;
844 args[0] = 2;
845 args[1] = 0;
846 _if->wioctl( SIOCDEVPRIVATE );
847 #endif
848 } 858 }
849 else 859 else
850 { 860 {
851 #if WIRELESS_EXT > 14 861 _if->setPrivate( "monitor", 1, 0 );
852 _if->_iwr.u.mode = IW_MODE_INFRA;
853 _if->wioctl( SIOCSIWMODE );
854 #else
855 int* args = (int*) &_if->_iwr.u.name;
856 args[0] = 0;
857 args[1] = 0;
858 _if->wioctl( SIOCDEVPRIVATE );
859 #endif
860 } 862 }
861} 863}
862 864
863 865
864QString OHostAPMonitoringInterface::name() const 866QString OHostAPMonitoringInterface::name() const
865{ 867{
866 return "hostap"; 868 return "hostap";
867} 869}
868 870
869 871
870/*====================================================================================== 872/*======================================================================================
871 * OOrinocoNetworkInterface 873 * OOrinocoNetworkInterface
872 *======================================================================================*/ 874 *======================================================================================*/
873 875
874OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) 876OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface )
875 :OMonitoringInterface( iface ) 877 :OMonitoringInterface( iface )
876{ 878{
877 iface->setMonitoring( this ); 879 iface->setMonitoring( this );
878} 880}
879 881
880 882
881OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 883OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
882{ 884{
883} 885}
884 886
885 887
886void OOrinocoMonitoringInterface::setChannel( int c ) 888void OOrinocoMonitoringInterface::setChannel( int c )
887{ 889{
888 // call iwpriv <device> monitor 2 <channel> 890 _if->setPrivate( "monitor", 2, 2, c );
889 int* args = (int*) &_if->_iwr.u.name;
890 args[0] = 2;
891 args[1] = c;
892 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
893} 891}
894 892
895 893
896void OOrinocoMonitoringInterface::setEnabled( bool b ) 894void OOrinocoMonitoringInterface::setEnabled( bool b )
897{ 895{
898 if ( b ) 896 if ( b )
899 { 897 {
900 setChannel( 1 ); 898 setChannel( 1 );
901 } 899 }
902 else 900 else
903 { 901 {
904 // call iwpriv <device> monitor 0 0 902 _if->setPrivate( "monitor", 2, 0, 0 );
905 int* args = (int*) &_if->_iwr.u.name;
906 args[0] = 0;
907 args[1] = 0;
908 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
909 } 903 }
910} 904}
911 905
912 906
913QString OOrinocoMonitoringInterface::name() const 907QString OOrinocoMonitoringInterface::name() const
914{ 908{
915 return "orinoco"; 909 return "orinoco";
916} 910}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index 4cadbeb..e249aee 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -1,324 +1,322 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef ONETWORK_H 34#ifndef ONETWORK_H
35#define ONETWORK_H 35#define ONETWORK_H
36 36
37/* QT */ 37/* QT */
38 38
39#include <qvaluelist.h> 39#include <qvaluelist.h>
40#include <qdict.h> 40#include <qdict.h>
41#include <qmap.h> 41#include <qmap.h>
42#include <qobject.h> 42#include <qobject.h>
43#include <qhostaddress.h> 43#include <qhostaddress.h>
44 44
45/* OPIE */ 45/* OPIE */
46 46
47#include <opie2/onetutils.h> 47#include <opie2/onetutils.h>
48 48
49#ifndef IFNAMSIZ 49#ifndef IFNAMSIZ
50#define IFNAMSIZ 16 50#define IFNAMSIZ 16
51#endif 51#endif
52#ifndef IW_MAX_PRIV_DEF 52#ifndef IW_MAX_PRIV_DEF
53#define IW_MAX_PRIV_DEF 128 53#define IW_MAX_PRIV_DEF 128
54#endif 54#endif
55 55
56// ML: Yeah, I hate to include kernel headers, but it's necessary here 56// ML: Yeah, I hate to include kernel headers, but it's necessary here
57// ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> 57// ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h>
58// ML: which conflicts with the user header <net/if.h> 58// ML: which conflicts with the user header <net/if.h>
59// ML: We really a user header for the Wireless Extensions, something like <net/wireless.h> 59// ML: We really a user header for the Wireless Extensions, something like <net/wireless.h>
60// ML: I will drop Jean an mail on that subject 60// ML: I will drop Jean an mail on that subject
61 61
62#include <net/if.h> 62#include <net/if.h>
63#define _LINUX_IF_H 63#define _LINUX_IF_H
64#include <linux/wireless.h> 64#include <linux/wireless.h>
65 65
66#ifndef SIOCIWFIRSTPRIV
67#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
68#endif
69
70class ONetworkInterface; 66class ONetworkInterface;
71class OWirelessNetworkInterface; 67class OWirelessNetworkInterface;
72class OChannelHopper; 68class OChannelHopper;
73class OMonitoringInterface; 69class OMonitoringInterface;
74 70
75/*====================================================================================== 71/*======================================================================================
76 * ONetwork 72 * ONetwork
77 *======================================================================================*/ 73 *======================================================================================*/
78 74
79class ONetwork : public QObject 75class ONetwork : public QObject
80{ 76{
81 Q_OBJECT 77 Q_OBJECT
82 78
83 public: 79 public:
84 typedef QDict<ONetworkInterface> InterfaceMap; 80 typedef QDict<ONetworkInterface> InterfaceMap;
85 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 81 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
86 82
87 public: 83 public:
88 static ONetwork* instance(); 84 static ONetwork* instance();
89 InterfaceIterator iterator() const; 85 InterfaceIterator iterator() const;
90 bool isWirelessInterface( const char* ) const; 86 bool isWirelessInterface( const char* ) const;
91 ONetworkInterface* interface( QString ) const; 87 ONetworkInterface* interface( QString ) const;
92 88
93 protected: 89 protected:
94 ONetwork(); 90 ONetwork();
95 void synchronize(); 91 void synchronize();
96 92
97 private: 93 private:
98 static ONetwork* _instance; 94 static ONetwork* _instance;
99 InterfaceMap _interfaces; 95 InterfaceMap _interfaces;
100}; 96};
101 97
102 98
103/*====================================================================================== 99/*======================================================================================
104 * ONetworkInterface 100 * ONetworkInterface
105 *======================================================================================*/ 101 *======================================================================================*/
106 102
107class ONetworkInterface : public QObject 103class ONetworkInterface : public QObject
108{ 104{
109 friend class OMonitoringInterface; 105 friend class OMonitoringInterface;
110 friend class OCiscoMonitoringInterface; 106 friend class OCiscoMonitoringInterface;
111 friend class OWlanNGMonitoringInterface; 107 friend class OWlanNGMonitoringInterface;
112 friend class OHostAPMonitoringInterface; 108 friend class OHostAPMonitoringInterface;
113 friend class OOrinocoMonitoringInterface; 109 friend class OOrinocoMonitoringInterface;
114 110
115 public: 111 public:
116 ONetworkInterface( QObject* parent, const char* name ); 112 ONetworkInterface( QObject* parent, const char* name );
117 virtual ~ONetworkInterface(); 113 virtual ~ONetworkInterface();
118 114
119 void setMonitoring( OMonitoringInterface* ); 115 void setMonitoring( OMonitoringInterface* );
120 OMonitoringInterface* monitoring() const; 116 OMonitoringInterface* monitoring() const;
121 bool setPromiscuousMode( bool ); 117 bool setPromiscuousMode( bool );
122 bool promiscuousMode() const; 118 bool promiscuousMode() const;
123 bool setUp( bool ); 119 bool setUp( bool );
124 bool isUp() const; 120 bool isUp() const;
125 bool isLoopback() const; 121 bool isLoopback() const;
126 bool isWireless() const; 122 bool isWireless() const;
127 QString ipV4Address() const; 123 QString ipV4Address() const;
124 void setMacAddress( const OMacAddress& );
128 OMacAddress macAddress() const; 125 OMacAddress macAddress() const;
129 int dataLinkType() const; 126 int dataLinkType() const;
130 127
131 protected: 128 protected:
132 const int _sfd; 129 const int _sfd;
133 mutable ifreq _ifr; 130 mutable ifreq _ifr;
134 OMonitoringInterface* _mon; 131 OMonitoringInterface* _mon;
135 132
136 protected: 133 protected:
137 struct ifreq& ifr() const; 134 struct ifreq& ifr() const;
138 virtual void init(); 135 virtual void init();
139 bool ioctl( int call ) const; 136 bool ioctl( int call ) const;
140 bool ioctl( int call, struct ifreq& ) const; 137 bool ioctl( int call, struct ifreq& ) const;
141}; 138};
142 139
143/*====================================================================================== 140/*======================================================================================
144 * OChannelHopper 141 * OChannelHopper
145 *======================================================================================*/ 142 *======================================================================================*/
146 143
147class OChannelHopper : public QObject 144class OChannelHopper : public QObject
148{ 145{
149 public: 146 public:
150 OChannelHopper( OWirelessNetworkInterface* ); 147 OChannelHopper( OWirelessNetworkInterface* );
151 virtual ~OChannelHopper(); 148 virtual ~OChannelHopper();
152 bool isActive() const; 149 bool isActive() const;
153 int channel() const; 150 int channel() const;
154 virtual void timerEvent( QTimerEvent* ); 151 virtual void timerEvent( QTimerEvent* );
155 void setInterval( int ); 152 void setInterval( int );
156 int interval() const; 153 int interval() const;
157 154
158 private: 155 private:
159 OWirelessNetworkInterface* _iface; 156 OWirelessNetworkInterface* _iface;
160 int _interval; 157 int _interval;
161 int _tid; 158 int _tid;
162 QValueList<int> _channels; 159 QValueList<int> _channels;
163 QValueList<int>::Iterator _channel; 160 QValueList<int>::Iterator _channel;
164 161
165}; 162};
166 163
167 164
168/*====================================================================================== 165/*======================================================================================
169 * OWirelessNetworkInterface 166 * OWirelessNetworkInterface
170 *======================================================================================*/ 167 *======================================================================================*/
171 168
172class OWirelessNetworkInterface : public ONetworkInterface 169class OWirelessNetworkInterface : public ONetworkInterface
173{ 170{
174 friend class OMonitoringInterface; 171 friend class OMonitoringInterface;
175 friend class OCiscoMonitoringInterface; 172 friend class OCiscoMonitoringInterface;
176 friend class OWlanNGMonitoringInterface; 173 friend class OWlanNGMonitoringInterface;
177 friend class OHostAPMonitoringInterface; 174 friend class OHostAPMonitoringInterface;
178 friend class OOrinocoMonitoringInterface; 175 friend class OOrinocoMonitoringInterface;
179 176
180 friend class OPrivateIOCTL; 177 friend class OPrivateIOCTL;
181 178
182 public: 179 public:
183 enum Mode { AdHoc, Managed, Monitor }; 180 enum Mode { AdHoc, Managed, Monitor };
184 181
185 OWirelessNetworkInterface( QObject* parent, const char* name ); 182 OWirelessNetworkInterface( QObject* parent, const char* name );
186 virtual ~OWirelessNetworkInterface(); 183 virtual ~OWirelessNetworkInterface();
187 184
188 virtual void setChannel( int ) const; 185 virtual void setChannel( int ) const;
189 virtual int channel() const; 186 virtual int channel() const;
190 virtual double frequency() const; 187 virtual double frequency() const;
191 virtual int channels() const; 188 virtual int channels() const;
192 //virtual double frequency(int) const; 189 //virtual double frequency(int) const;
193 190
194 virtual void setMode( Mode ) {}; 191 virtual void setMode( Mode ) {};
195 virtual bool mode() const {}; 192 virtual bool mode() const {};
196 193
197 virtual void setMonitorMode( bool ); 194 virtual void setMonitorMode( bool );
198 virtual bool monitorMode() const; 195 virtual bool monitorMode() const;
199 196
200 virtual void setChannelHopping( int interval = 0 ); 197 virtual void setChannelHopping( int interval = 0 );
201 virtual int channelHopping() const; 198 virtual int channelHopping() const;
202 199
203 virtual void setNickName( const QString& ) {}; 200 virtual void setNickName( const QString& ) {};
204 virtual QString nickName() const; 201 virtual QString nickName() const;
205 202
206 virtual void setPrivate( const QString&, int, ... ); 203 virtual void setPrivate( const QString&, int, ... );
204 virtual bool hasPrivate( const QString& );
207 virtual void getPrivate( const QString& ); 205 virtual void getPrivate( const QString& );
208 206
209 virtual bool isAssociated() const {}; 207 virtual bool isAssociated() const {};
210 virtual QString associatedAP() const; 208 virtual QString associatedAP() const;
211 209
212 virtual void setSSID( const QString& ); 210 virtual void setSSID( const QString& );
213 virtual QString SSID() const; 211 virtual QString SSID() const;
214 212
215 protected: 213 protected:
216 void buildChannelList(); 214 void buildChannelList();
217 void buildPrivateList(); 215 void buildPrivateList();
218 virtual void init(); 216 virtual void init();
219 struct iwreq& iwr() const; 217 struct iwreq& iwr() const;
220 bool wioctl( int call ) const; 218 bool wioctl( int call ) const;
221 bool wioctl( int call, struct iwreq& ) const; 219 bool wioctl( int call, struct iwreq& ) const;
222 220
223 protected: 221 protected:
224 mutable struct iwreq _iwr; 222 mutable struct iwreq _iwr;
225 QMap<int,int> _channels; 223 QMap<int,int> _channels;
226 224
227 private: 225 private:
228 OChannelHopper* _hopper; 226 OChannelHopper* _hopper;
229}; 227};
230 228
231 229
232/*====================================================================================== 230/*======================================================================================
233 * OMonitoringInterface 231 * OMonitoringInterface
234 *======================================================================================*/ 232 *======================================================================================*/
235 233
236 234
237class OMonitoringInterface 235class OMonitoringInterface
238{ 236{
239 public: 237 public:
240 OMonitoringInterface(); 238 OMonitoringInterface();
241 OMonitoringInterface( ONetworkInterface* ); 239 OMonitoringInterface( ONetworkInterface* );
242 virtual ~OMonitoringInterface(); 240 virtual ~OMonitoringInterface();
243 241
244 public: 242 public:
245 virtual void setEnabled( bool ); 243 virtual void setEnabled( bool );
246 virtual bool enabled() const; 244 virtual bool enabled() const;
247 virtual void setChannel( int ); 245 virtual void setChannel( int );
248 246
249 virtual QString name() const = 0; 247 virtual QString name() const = 0;
250 248
251 protected: 249 protected:
252 const OWirelessNetworkInterface* _if; 250 OWirelessNetworkInterface* _if;
253 251
254}; 252};
255 253
256 254
257/*====================================================================================== 255/*======================================================================================
258 * OCiscoMonitoring 256 * OCiscoMonitoring
259 *======================================================================================*/ 257 *======================================================================================*/
260 258
261 259
262class OCiscoMonitoringInterface : public OMonitoringInterface 260class OCiscoMonitoringInterface : public OMonitoringInterface
263{ 261{
264 public: 262 public:
265 OCiscoMonitoringInterface( ONetworkInterface* ); 263 OCiscoMonitoringInterface( ONetworkInterface* );
266 virtual ~OCiscoMonitoringInterface(); 264 virtual ~OCiscoMonitoringInterface();
267 265
268 virtual void setEnabled( bool ); 266 virtual void setEnabled( bool );
269 virtual QString name() const; 267 virtual QString name() const;
270 virtual void setChannel( int ); 268 virtual void setChannel( int );
271 269
272}; 270};
273 271
274/*====================================================================================== 272/*======================================================================================
275 * OWlanNGMonitoringInterface 273 * OWlanNGMonitoringInterface
276 *======================================================================================*/ 274 *======================================================================================*/
277 275
278class OWlanNGMonitoringInterface : public OMonitoringInterface 276class OWlanNGMonitoringInterface : public OMonitoringInterface
279{ 277{
280 public: 278 public:
281 OWlanNGMonitoringInterface( ONetworkInterface* ); 279 OWlanNGMonitoringInterface( ONetworkInterface* );
282 virtual ~OWlanNGMonitoringInterface(); 280 virtual ~OWlanNGMonitoringInterface();
283 281
284 public: 282 public:
285 virtual void setEnabled( bool ); 283 virtual void setEnabled( bool );
286 virtual QString name() const; 284 virtual QString name() const;
287 virtual void setChannel( int ); 285 virtual void setChannel( int );
288 286
289}; 287};
290 288
291/*====================================================================================== 289/*======================================================================================
292 * OHostAPMonitoringInterface 290 * OHostAPMonitoringInterface
293 *======================================================================================*/ 291 *======================================================================================*/
294 292
295class OHostAPMonitoringInterface : public OMonitoringInterface 293class OHostAPMonitoringInterface : public OMonitoringInterface
296{ 294{
297 public: 295 public:
298 OHostAPMonitoringInterface( ONetworkInterface* ); 296 OHostAPMonitoringInterface( ONetworkInterface* );
299 virtual ~OHostAPMonitoringInterface(); 297 virtual ~OHostAPMonitoringInterface();
300 298
301 public: 299 public:
302 virtual void setEnabled( bool ); 300 virtual void setEnabled( bool );
303 virtual QString name() const; 301 virtual QString name() const;
304 }; 302 };
305 303
306/*====================================================================================== 304/*======================================================================================
307 * OOrinocoMonitoringInterface 305 * OOrinocoMonitoringInterface
308 *======================================================================================*/ 306 *======================================================================================*/
309 307
310class OOrinocoMonitoringInterface : public OMonitoringInterface 308class OOrinocoMonitoringInterface : public OMonitoringInterface
311{ 309{
312 public: 310 public:
313 OOrinocoMonitoringInterface( ONetworkInterface* ); 311 OOrinocoMonitoringInterface( ONetworkInterface* );
314 virtual ~OOrinocoMonitoringInterface(); 312 virtual ~OOrinocoMonitoringInterface();
315 313
316 public: 314 public:
317 virtual void setChannel( int ); 315 virtual void setChannel( int );
318 virtual void setEnabled( bool ); 316 virtual void setEnabled( bool );
319 virtual QString name() const; 317 virtual QString name() const;
320 318
321}; 319};
322 320
323#endif // ONETWORK_H 321#endif // ONETWORK_H
324 322