summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-04 10:31:26 (UTC)
committer mickeyl <mickeyl>2003-04-04 10:31:26 (UTC)
commit089385bb8ab768fbf6f394f326e565e3589163fc (patch) (unidiff)
tree23891b81b11310186c43179612531bc92e52ae65
parent7da7e9cbfb52988ce801310f66b1336e0809db28 (diff)
downloadopie-089385bb8ab768fbf6f394f326e565e3589163fc.zip
opie-089385bb8ab768fbf6f394f326e565e3589163fc.tar.gz
opie-089385bb8ab768fbf6f394f326e565e3589163fc.tar.bz2
low-level network programming is sick. some wlan-drivers don't honor struct sizes
and simply write bytes _after_ the struct... this patch makes calling SIOCGIWRANGE more failure-proof.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetutils.cpp1
-rw-r--r--libopie2/opienet/onetwork.cpp57
-rw-r--r--libopie2/opienet/onetwork.h19
3 files changed, 47 insertions, 30 deletions
diff --git a/libopie2/opienet/onetutils.cpp b/libopie2/opienet/onetutils.cpp
index fd8f9e9..b317810 100644
--- a/libopie2/opienet/onetutils.cpp
+++ b/libopie2/opienet/onetutils.cpp
@@ -1,185 +1,186 @@
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 ); // D'OH! memcpy in my sources... eeek...
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
86QString OMacAddress::toString() const 86QString OMacAddress::toString() const
87{ 87{
88 QString s; 88 QString s;
89 s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 89 s.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
90 _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff, 90 _bytes[0]&0xff, _bytes[1]&0xff, _bytes[2]&0xff,
91 _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff ); 91 _bytes[3]&0xff, _bytes[4]&0xff, _bytes[5]&0xff );
92 return s; 92 return s;
93} 93}
94 94
95 95
96bool operator==( const OMacAddress &m1, const OMacAddress &m2 ) 96bool operator==( const OMacAddress &m1, const OMacAddress &m2 )
97{ 97{
98 return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0; 98 return memcmp( &m1._bytes, &m2._bytes, 6 ) == 0;
99} 99}
100 100
101 101
102/*====================================================================================== 102/*======================================================================================
103 * OHostAddress 103 * OHostAddress
104 *======================================================================================*/ 104 *======================================================================================*/
105 105
106 106
107/*====================================================================================== 107/*======================================================================================
108 * OPrivateIOCTL 108 * OPrivateIOCTL
109 *======================================================================================*/ 109 *======================================================================================*/
110 110
111OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs ) 111OPrivateIOCTL::OPrivateIOCTL( QObject* parent, const char* name, int cmd, int getargs, int setargs )
112 :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs ) 112 :QObject( parent, name ), _ioctl( cmd ), _getargs( getargs ), _setargs( setargs )
113{ 113{
114} 114}
115 115
116 116
117OPrivateIOCTL::~OPrivateIOCTL() 117OPrivateIOCTL::~OPrivateIOCTL()
118{ 118{
119} 119}
120 120
121 121
122#ifdef QT_NO_DEBUG 122#ifdef QT_NO_DEBUG
123inline 123inline
124#endif 124#endif
125int OPrivateIOCTL::numberGetArgs() const 125int OPrivateIOCTL::numberGetArgs() const
126{ 126{
127 return _getargs & IW_PRIV_SIZE_MASK; 127 return _getargs & IW_PRIV_SIZE_MASK;
128} 128}
129 129
130 130
131#ifdef QT_NO_DEBUG 131#ifdef QT_NO_DEBUG
132inline 132inline
133#endif 133#endif
134int OPrivateIOCTL::typeGetArgs() const 134int OPrivateIOCTL::typeGetArgs() const
135{ 135{
136 return _getargs & IW_PRIV_TYPE_MASK >> 12; 136 return _getargs & IW_PRIV_TYPE_MASK >> 12;
137} 137}
138 138
139 139
140#ifdef QT_NO_DEBUG 140#ifdef QT_NO_DEBUG
141inline 141inline
142#endif 142#endif
143int OPrivateIOCTL::numberSetArgs() const 143int OPrivateIOCTL::numberSetArgs() const
144{ 144{
145 return _setargs & IW_PRIV_SIZE_MASK; 145 return _setargs & IW_PRIV_SIZE_MASK;
146} 146}
147 147
148 148
149#ifdef QT_NO_DEBUG 149#ifdef QT_NO_DEBUG
150inline 150inline
151#endif 151#endif
152int OPrivateIOCTL::typeSetArgs() const 152int OPrivateIOCTL::typeSetArgs() const
153{ 153{
154 return _setargs & IW_PRIV_TYPE_MASK >> 12; 154 return _setargs & IW_PRIV_TYPE_MASK >> 12;
155} 155}
156 156
157 157
158void OPrivateIOCTL::invoke() const 158void OPrivateIOCTL::invoke() const
159{ 159{
160 ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl ); 160 ( (OWirelessNetworkInterface*) parent() )->wioctl( _ioctl );
161} 161}
162 162
163 163
164void OPrivateIOCTL::setParameter( int num, u_int32_t value ) 164void OPrivateIOCTL::setParameter( int num, u_int32_t value )
165{ 165{
166 u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name; 166 u_int32_t* arglist = (u_int32_t*) &( (OWirelessNetworkInterface*) parent() )->_iwr.u.name;
167 arglist[num] = value; 167 arglist[num] = value;
168} 168}
169 169
170/*====================================================================================== 170/*======================================================================================
171 * assorted functions 171 * assorted functions
172 *======================================================================================*/ 172 *======================================================================================*/
173 173
174void dumpBytes( const unsigned char* data, int num ) 174void dumpBytes( const unsigned char* data, int num )
175{ 175{
176 printf( "Dumping %d bytes @ %0x", num, data ); 176 printf( "Dumping %d bytes @ %0x", num, data );
177 printf( "-------------------------------------------\n" ); 177 printf( "-------------------------------------------\n" );
178 178
179 for ( int i = 0; i < num; ++i ) 179 for ( int i = 0; i < num; ++i )
180 { 180 {
181 printf( "%02x ", data[i] ); 181 printf( "%02x ", data[i] );
182 if ( !((i+1) % 32) ) printf( "\n" ); 182 if ( !((i+1) % 32) ) printf( "\n" );
183 } 183 }
184 printf( "\n\n" ); 184 printf( "\n\n" );
185} 185}
186
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 66fa215..789e8ca 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,902 +1,925 @@
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 <stdarg.h> 55#include <stdarg.h>
56 56
57using namespace std; 57using namespace std;
58 58
59/*====================================================================================== 59/*======================================================================================
60 * ONetwork 60 * ONetwork
61 *======================================================================================*/ 61 *======================================================================================*/
62 62
63ONetwork* ONetwork::_instance = 0; 63ONetwork* ONetwork::_instance = 0;
64 64
65ONetwork::ONetwork() 65ONetwork::ONetwork()
66{ 66{
67 qDebug( "ONetwork::ONetwork()" ); 67 qDebug( "ONetwork::ONetwork()" );
68 synchronize(); 68 synchronize();
69} 69}
70 70
71void ONetwork::synchronize() 71void ONetwork::synchronize()
72{ 72{
73 // gather available interfaces by inspecting /proc/net/dev 73 // gather available interfaces by inspecting /proc/net/dev
74 // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 74 // we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
75 75
76 _interfaces.clear(); 76 _interfaces.clear();
77 QString str; 77 QString str;
78 QFile f( "/proc/net/dev" ); 78 QFile f( "/proc/net/dev" );
79 bool hasFile = f.open( IO_ReadOnly ); 79 bool hasFile = f.open( IO_ReadOnly );
80 if ( !hasFile ) 80 if ( !hasFile )
81 { 81 {
82 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); 82 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
83 return; 83 return;
84 } 84 }
85 QTextStream s( &f ); 85 QTextStream s( &f );
86 s.readLine(); 86 s.readLine();
87 s.readLine(); 87 s.readLine();
88 while ( !s.atEnd() ) 88 while ( !s.atEnd() )
89 { 89 {
90 s >> str; 90 s >> str;
91 str.truncate( str.find( ':' ) ); 91 str.truncate( str.find( ':' ) );
92 qDebug( "ONetwork: found interface '%s'", (const char*) str ); 92 qDebug( "ONetwork: found interface '%s'", (const char*) str );
93 ONetworkInterface* iface; 93 ONetworkInterface* iface;
94 if ( isWirelessInterface( str ) ) 94 if ( isWirelessInterface( str ) )
95 { 95 {
96 iface = new OWirelessNetworkInterface( this, str ); 96 iface = new OWirelessNetworkInterface( this, str );
97 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); 97 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str );
98 } 98 }
99 else 99 else
100 { 100 {
101 iface = new ONetworkInterface( this, str ); 101 iface = new ONetworkInterface( this, str );
102 } 102 }
103 _interfaces.insert( str, iface ); 103 _interfaces.insert( str, iface );
104 s.readLine(); 104 s.readLine();
105 } 105 }
106} 106}
107 107
108 108
109ONetworkInterface* ONetwork::interface( QString iface ) const 109ONetworkInterface* ONetwork::interface( QString iface ) const
110{ 110{
111 return _interfaces[iface]; 111 return _interfaces[iface];
112} 112}
113 113
114 114
115ONetwork* ONetwork::instance() 115ONetwork* ONetwork::instance()
116{ 116{
117 if ( !_instance ) _instance = new ONetwork(); 117 if ( !_instance ) _instance = new ONetwork();
118 return _instance; 118 return _instance;
119} 119}
120 120
121 121
122ONetwork::InterfaceIterator ONetwork::iterator() const 122ONetwork::InterfaceIterator ONetwork::iterator() const
123{ 123{
124 return ONetwork::InterfaceIterator( _interfaces ); 124 return ONetwork::InterfaceIterator( _interfaces );
125} 125}
126 126
127 127
128bool ONetwork::isWirelessInterface( const char* name ) const 128bool ONetwork::isWirelessInterface( const char* name ) const
129{ 129{
130 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 130 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
131 iwreqstruct iwr; 131 struct iwreq iwr;
132 memset( &iwr, 0, sizeof( iwreqstruct ) ); 132 memset( &iwr, 0, sizeof( struct iwreq ) );
133 strcpy( (char*) &iwr.ifr_name, name ); 133 strcpy( (char*) &iwr.ifr_name, name );
134 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 134 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
135 if ( result == -1 ) 135 if ( result == -1 )
136 qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); 136 qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) );
137 else 137 else
138 qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); 138 qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." );
139 return ( result != -1 ); 139 return ( result != -1 );
140} 140}
141 141
142/*====================================================================================== 142/*======================================================================================
143 * ONetworkInterface 143 * ONetworkInterface
144 *======================================================================================*/ 144 *======================================================================================*/
145 145
146ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) 146ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
147 :QObject( parent, name ), 147 :QObject( parent, name ),
148 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 148 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
149{ 149{
150 qDebug( "ONetworkInterface::ONetworkInterface()" ); 150 qDebug( "ONetworkInterface::ONetworkInterface()" );
151 init(); 151 init();
152} 152}
153 153
154 154
155ifreqstruct& ONetworkInterface::ifr() const 155struct ifreq& ONetworkInterface::ifr() const
156{ 156{
157 return _ifr; 157 return _ifr;
158} 158}
159 159
160 160
161void ONetworkInterface::init() 161void ONetworkInterface::init()
162{ 162{
163 qDebug( "ONetworkInterface::init()" ); 163 qDebug( "ONetworkInterface::init()" );
164 164
165 memset( &_ifr, 0, sizeof( struct ifreq ) ); 165 memset( &_ifr, 0, sizeof( struct ifreq ) );
166 166
167 if ( _sfd == -1 ) 167 if ( _sfd == -1 )
168 { 168 {
169 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); 169 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() );
170 return; 170 return;
171 } 171 }
172} 172}
173 173
174 174
175bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const 175bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
176{ 176{
177 int result = ::ioctl( _sfd, call, &ifreq ); 177 int result = ::ioctl( _sfd, call, &ifreq );
178 if ( result == -1 ) 178 if ( result == -1 )
179 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 179 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) );
180 else 180 else
181 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); 181 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call );
182 return ( result != -1 ); 182 return ( result != -1 );
183} 183}
184 184
185 185
186bool ONetworkInterface::ioctl( int call ) const 186bool ONetworkInterface::ioctl( int call ) const
187{ 187{
188 strcpy( _ifr.ifr_name, name() ); 188 strcpy( _ifr.ifr_name, name() );
189 return ioctl( call, _ifr ); 189 return ioctl( call, _ifr );
190} 190}
191 191
192 192
193bool ONetworkInterface::isLoopback() const 193bool ONetworkInterface::isLoopback() const
194{ 194{
195 ioctl( SIOCGIFFLAGS ); 195 ioctl( SIOCGIFFLAGS );
196 return _ifr.ifr_flags & IFF_LOOPBACK; 196 return _ifr.ifr_flags & IFF_LOOPBACK;
197} 197}
198 198
199 199
200bool ONetworkInterface::setUp( bool b ) 200bool ONetworkInterface::setUp( bool b )
201{ 201{
202 ioctl( SIOCGIFFLAGS ); 202 ioctl( SIOCGIFFLAGS );
203 if ( b ) _ifr.ifr_flags |= IFF_UP; 203 if ( b ) _ifr.ifr_flags |= IFF_UP;
204 else _ifr.ifr_flags &= (~IFF_UP); 204 else _ifr.ifr_flags &= (~IFF_UP);
205 return ioctl( SIOCSIFFLAGS ); 205 return ioctl( SIOCSIFFLAGS );
206} 206}
207 207
208 208
209bool ONetworkInterface::isUp() const 209bool ONetworkInterface::isUp() const
210{ 210{
211 ioctl( SIOCGIFFLAGS ); 211 ioctl( SIOCGIFFLAGS );
212 return _ifr.ifr_flags & IFF_UP; 212 return _ifr.ifr_flags & IFF_UP;
213} 213}
214 214
215 215
216QString ONetworkInterface::ipV4Address() const 216QString ONetworkInterface::ipV4Address() const
217{ 217{
218 if ( ioctl( SIOCGIFADDR ) ) 218 if ( ioctl( SIOCGIFADDR ) )
219 { 219 {
220 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 220 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
221 //FIXME: Use QHostAddress here 221 //FIXME: Use QHostAddress here
222 return QString( inet_ntoa( sa->sin_addr ) ); 222 return QString( inet_ntoa( sa->sin_addr ) );
223 } 223 }
224 else 224 else
225 return "<unknown>"; 225 return "<unknown>";
226} 226}
227 227
228 228
229OMacAddress ONetworkInterface::macAddress() const 229OMacAddress ONetworkInterface::macAddress() const
230{ 230{
231 if ( ioctl( SIOCGIFHWADDR ) ) 231 if ( ioctl( SIOCGIFHWADDR ) )
232 { 232 {
233 return OMacAddress( _ifr ); 233 return OMacAddress( _ifr );
234 } 234 }
235 else 235 else
236 { 236 {
237 return OMacAddress::unknown; 237 return OMacAddress::unknown;
238 } 238 }
239} 239}
240 240
241 241
242void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 242void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
243{ 243{
244 _mon = m; 244 _mon = m;
245 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); 245 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() );
246} 246}
247 247
248 248
249OMonitoringInterface* ONetworkInterface::monitoring() const 249OMonitoringInterface* ONetworkInterface::monitoring() const
250{ 250{
251 return _mon; 251 return _mon;
252} 252}
253 253
254 254
255ONetworkInterface::~ONetworkInterface() 255ONetworkInterface::~ONetworkInterface()
256{ 256{
257 qDebug( "ONetworkInterface::~ONetworkInterface()" ); 257 qDebug( "ONetworkInterface::~ONetworkInterface()" );
258 if ( _sfd != -1 ) ::close( _sfd ); 258 if ( _sfd != -1 ) ::close( _sfd );
259} 259}
260 260
261 261
262bool ONetworkInterface::setPromiscuousMode( bool b ) 262bool ONetworkInterface::setPromiscuousMode( bool b )
263{ 263{
264 ioctl( SIOCGIFFLAGS ); 264 ioctl( SIOCGIFFLAGS );
265 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 265 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
266 else _ifr.ifr_flags &= (~IFF_PROMISC); 266 else _ifr.ifr_flags &= (~IFF_PROMISC);
267 return ioctl( SIOCSIFFLAGS ); 267 return ioctl( SIOCSIFFLAGS );
268} 268}
269 269
270 270
271bool ONetworkInterface::promiscuousMode() const 271bool ONetworkInterface::promiscuousMode() const
272{ 272{
273 ioctl( SIOCGIFFLAGS ); 273 ioctl( SIOCGIFFLAGS );
274 return _ifr.ifr_flags & IFF_PROMISC; 274 return _ifr.ifr_flags & IFF_PROMISC;
275} 275}
276 276
277 277
278bool ONetworkInterface::isWireless() const 278bool ONetworkInterface::isWireless() const
279{ 279{
280 return ioctl( SIOCGIWNAME ); 280 return ioctl( SIOCGIWNAME );
281} 281}
282 282
283 283
284/*====================================================================================== 284/*======================================================================================
285 * OChannelHopper 285 * OChannelHopper
286 *======================================================================================*/ 286 *======================================================================================*/
287 287
288OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 288OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
289 :QObject( 0, "Mickey's funky hopper" ), 289 :QObject( 0, "Mickey's funky hopper" ),
290 _iface( iface ), _interval( 0 ), _tid( 0 ) 290 _iface( iface ), _interval( 0 ), _tid( 0 )
291{ 291{
292 int _maxChannel = iface->channels()+1; 292 int _maxChannel = iface->channels()+1;
293 // generate fancy hopping sequence honoring the device capabilities 293 // generate fancy hopping sequence honoring the device capabilities
294 if ( _maxChannel >= 1 ) _channels.append( 1 ); 294 if ( _maxChannel >= 1 ) _channels.append( 1 );
295 if ( _maxChannel >= 7 ) _channels.append( 7 ); 295 if ( _maxChannel >= 7 ) _channels.append( 7 );
296 if ( _maxChannel >= 13 ) _channels.append( 13 ); 296 if ( _maxChannel >= 13 ) _channels.append( 13 );
297 if ( _maxChannel >= 2 ) _channels.append( 2 ); 297 if ( _maxChannel >= 2 ) _channels.append( 2 );
298 if ( _maxChannel >= 8 ) _channels.append( 8 ); 298 if ( _maxChannel >= 8 ) _channels.append( 8 );
299 if ( _maxChannel >= 3 ) _channels.append( 3 ); 299 if ( _maxChannel >= 3 ) _channels.append( 3 );
300 if ( _maxChannel >= 14 ) _channels.append( 14 ); 300 if ( _maxChannel >= 14 ) _channels.append( 14 );
301 if ( _maxChannel >= 9 ) _channels.append( 9 ); 301 if ( _maxChannel >= 9 ) _channels.append( 9 );
302 if ( _maxChannel >= 4 ) _channels.append( 4 ); 302 if ( _maxChannel >= 4 ) _channels.append( 4 );
303 if ( _maxChannel >= 10 ) _channels.append( 10 ); 303 if ( _maxChannel >= 10 ) _channels.append( 10 );
304 if ( _maxChannel >= 5 ) _channels.append( 5 ); 304 if ( _maxChannel >= 5 ) _channels.append( 5 );
305 if ( _maxChannel >= 11 ) _channels.append( 11 ); 305 if ( _maxChannel >= 11 ) _channels.append( 11 );
306 if ( _maxChannel >= 6 ) _channels.append( 6 ); 306 if ( _maxChannel >= 6 ) _channels.append( 6 );
307 if ( _maxChannel >= 12 ) _channels.append( 12 ); 307 if ( _maxChannel >= 12 ) _channels.append( 12 );
308 _channel = _channels.begin(); 308 _channel = _channels.begin();
309 309
310} 310}
311 311
312 312
313OChannelHopper::~OChannelHopper() 313OChannelHopper::~OChannelHopper()
314{ 314{
315} 315}
316 316
317 317
318bool OChannelHopper::isActive() const 318bool OChannelHopper::isActive() const
319{ 319{
320 return _tid; 320 return _tid;
321} 321}
322 322
323 323
324int OChannelHopper::channel() const 324int OChannelHopper::channel() const
325{ 325{
326 return *_channel; 326 return *_channel;
327} 327}
328 328
329 329
330void OChannelHopper::timerEvent( QTimerEvent* ) 330void OChannelHopper::timerEvent( QTimerEvent* )
331{ 331{
332 _iface->setChannel( *_channel ); 332 _iface->setChannel( *_channel );
333 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", 333 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
334 *_channel, (const char*) _iface->name() ); 334 *_channel, (const char*) _iface->name() );
335 if ( ++_channel == _channels.end() ) _channel = _channels.begin(); 335 if ( ++_channel == _channels.end() ) _channel = _channels.begin();
336} 336}
337 337
338 338
339void OChannelHopper::setInterval( int interval ) 339void OChannelHopper::setInterval( int interval )
340{ 340{
341 if ( interval == _interval ) 341 if ( interval == _interval )
342 return; 342 return;
343 343
344 if ( _interval ) 344 if ( _interval )
345 killTimer( _tid ); 345 killTimer( _tid );
346 346
347 _tid = 0; 347 _tid = 0;
348 _interval = interval; 348 _interval = interval;
349 349
350 if ( _interval ) 350 if ( _interval )
351 { 351 {
352 _tid = startTimer( interval ); 352 _tid = startTimer( interval );
353 } 353 }
354} 354}
355 355
356 356
357int OChannelHopper::interval() const 357int OChannelHopper::interval() const
358{ 358{
359 return _interval; 359 return _interval;
360} 360}
361 361
362 362
363/*====================================================================================== 363/*======================================================================================
364 * OWirelessNetworkInterface 364 * OWirelessNetworkInterface
365 *======================================================================================*/ 365 *======================================================================================*/
366 366
367OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) 367OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name )
368 :ONetworkInterface( parent, name ), _hopper( 0 ) 368 :ONetworkInterface( parent, name ), _hopper( 0 )
369{ 369{
370 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 370 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
371 init(); 371 init();
372} 372}
373 373
374 374
375OWirelessNetworkInterface::~OWirelessNetworkInterface() 375OWirelessNetworkInterface::~OWirelessNetworkInterface()
376{ 376{
377} 377}
378 378
379 379
380iwreqstruct& OWirelessNetworkInterface::iwr() const 380struct iwreq& OWirelessNetworkInterface::iwr() const
381{ 381{
382 return _iwr; 382 return _iwr;
383} 383}
384 384
385 385
386void OWirelessNetworkInterface::init() 386void OWirelessNetworkInterface::init()
387{ 387{
388 qDebug( "OWirelessNetworkInterface::init()" ); 388 qDebug( "OWirelessNetworkInterface::init()" );
389 memset( &_iwr, 0, sizeof( struct iwreq ) ); 389 memset( &_iwr, 0, sizeof( struct iwreq ) );
390 buildChannelList(); 390 buildChannelList();
391 buildPrivateList(); 391 buildPrivateList();
392} 392}
393 393
394 394
395QString OWirelessNetworkInterface::associatedAP() const 395QString OWirelessNetworkInterface::associatedAP() const
396{ 396{
397 //FIXME: use OMacAddress 397 //FIXME: use OMacAddress
398 QString mac; 398 QString mac;
399 399
400 if ( ioctl( SIOCGIWAP ) ) 400 if ( ioctl( SIOCGIWAP ) )
401 { 401 {
402 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 402 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
403 _ifr.ifr_hwaddr.sa_data[0]&0xff, 403 _ifr.ifr_hwaddr.sa_data[0]&0xff,
404 _ifr.ifr_hwaddr.sa_data[1]&0xff, 404 _ifr.ifr_hwaddr.sa_data[1]&0xff,
405 _ifr.ifr_hwaddr.sa_data[2]&0xff, 405 _ifr.ifr_hwaddr.sa_data[2]&0xff,
406 _ifr.ifr_hwaddr.sa_data[3]&0xff, 406 _ifr.ifr_hwaddr.sa_data[3]&0xff,
407 _ifr.ifr_hwaddr.sa_data[4]&0xff, 407 _ifr.ifr_hwaddr.sa_data[4]&0xff,
408 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 408 _ifr.ifr_hwaddr.sa_data[5]&0xff );
409 } 409 }
410 else 410 else
411 { 411 {
412 mac = "<Unknown>"; 412 mac = "<Unknown>";
413 } 413 }
414 return mac; 414 return mac;
415} 415}
416 416
417 417
418void OWirelessNetworkInterface::buildChannelList() 418void OWirelessNetworkInterface::buildChannelList()
419{ 419{
420 // IEEE802.11(b) radio frequency channels
421 struct iw_range range;
422
423 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 420 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
424 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 421 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
425 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 422 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
426 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 423 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
427 //ML: _too much_ space. This is damn shitty crap *sigh* 424 //ML: _too much_ space. This is damn shitty crap *sigh*
428 425 //ML: We allocate a large memory region in RAM and check whether the
429 _iwr.u.data.pointer = (char*) &range; 426 //ML: driver pollutes this extra space. The complaint will be made on stdout,
430 _iwr.u.data.length = IW_MAX_FREQUENCIES; //sizeof range; 427 //ML: so please forward this...
431 _iwr.u.data.flags = 0; 428
432 429 struct iwreq wrq;
433 if ( !wioctl( SIOCGIWRANGE ) ) 430 int len = sizeof( struct iw_range )*2;
431 char *buffer = (char*) malloc( len );
432 //FIXME: Validate if we actually got the memory block
433 memset( buffer, 0, len );
434 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
435 wrq.u.data.pointer = (caddr_t) buffer;
436 wrq.u.data.length = sizeof( struct iw_range );
437 wrq.u.data.flags = 0;
438
439 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
434 { 440 {
435 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); 441 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) );
436 _channels.insert( 2412, 1 ); // 2.412 GHz 442 _channels.insert( 2412, 1 ); // 2.412 GHz
437 _channels.insert( 2417, 2 ); // 2.417 GHz 443 _channels.insert( 2417, 2 ); // 2.417 GHz
438 _channels.insert( 2422, 3 ); // 2.422 GHz 444 _channels.insert( 2422, 3 ); // 2.422 GHz
439 _channels.insert( 2427, 4 ); // 2.427 GHz 445 _channels.insert( 2427, 4 ); // 2.427 GHz
440 _channels.insert( 2432, 5 ); // 2.432 GHz 446 _channels.insert( 2432, 5 ); // 2.432 GHz
441 _channels.insert( 2437, 6 ); // 2.437 GHz 447 _channels.insert( 2437, 6 ); // 2.437 GHz
442 _channels.insert( 2442, 7 ); // 2.442 GHz 448 _channels.insert( 2442, 7 ); // 2.442 GHz
443 _channels.insert( 2447, 8 ); // 2.447 GHz 449 _channels.insert( 2447, 8 ); // 2.447 GHz
444 _channels.insert( 2452, 9 ); // 2.452 GHz 450 _channels.insert( 2452, 9 ); // 2.452 GHz
445 _channels.insert( 2457, 10 ); // 2.457 GHz 451 _channels.insert( 2457, 10 ); // 2.457 GHz
446 _channels.insert( 2462, 11 ); // 2.462 GHz 452 _channels.insert( 2462, 11 ); // 2.462 GHz
447 } 453 }
448 else 454 else
449 { 455 {
456 // <check if the driver overwrites stuff>
457 int max = 0;
458 for ( int r = sizeof( struct iw_range ); r < len; r++ )
459 if (buffer[r] != 0)
460 max = r;
461 if (max > 0)
462 {
463 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'"
464 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
465 }
466 // </check if the driver overwrites stuff>
467
468 struct iw_range range;
469 memcpy( &range, buffer, sizeof range );
470
450 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); 471 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency );
451 for ( int i = 0; i < range.num_frequency; ++i ) 472 for ( int i = 0; i < range.num_frequency; ++i )
452 { 473 {
453 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 474 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
454 _channels.insert( freq, i+1 ); 475 _channels.insert( freq, i+1 );
455 } 476 }
456 } 477 }
478
457 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); 479 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." );
480 free(buffer);
458} 481}
459 482
460 483
461void OWirelessNetworkInterface::buildPrivateList() 484void OWirelessNetworkInterface::buildPrivateList()
462{ 485{
463 qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); 486 qDebug( "OWirelessNetworkInterface::buildPrivateList()" );
464 487
465 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 488 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
466 489
467 _iwr.u.data.pointer = (char*) &priv; 490 _iwr.u.data.pointer = (char*) &priv;
468 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 491 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
469 _iwr.u.data.flags = 0; 492 _iwr.u.data.flags = 0;
470 493
471 if ( !wioctl( SIOCGIWPRIV ) ) 494 if ( !wioctl( SIOCGIWPRIV ) )
472 { 495 {
473 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); 496 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) );
474 return; 497 return;
475 } 498 }
476 499
477 for ( int i = 0; i < _iwr.u.data.length; ++i ) 500 for ( int i = 0; i < _iwr.u.data.length; ++i )
478 { 501 {
479 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 502 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
480 } 503 }
481 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); 504 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
482} 505}
483 506
484 507
485int OWirelessNetworkInterface::channel() const 508int OWirelessNetworkInterface::channel() const
486{ 509{
487 //FIXME: When monitoring enabled, then use it 510 //FIXME: When monitoring enabled, then use it
488 //FIXME: to gather the current RF channel 511 //FIXME: to gather the current RF channel
489 //FIXME: Until then, get active channel from hopper. 512 //FIXME: Until then, get active channel from hopper.
490 if ( _hopper && _hopper->isActive() ) 513 if ( _hopper && _hopper->isActive() )
491 return _hopper->channel(); 514 return _hopper->channel();
492 515
493 if ( !wioctl( SIOCGIWFREQ ) ) 516 if ( !wioctl( SIOCGIWFREQ ) )
494 { 517 {
495 return -1; 518 return -1;
496 } 519 }
497 else 520 else
498 { 521 {
499 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 522 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
500 } 523 }
501} 524}
502 525
503 526
504void OWirelessNetworkInterface::setChannel( int c ) const 527void OWirelessNetworkInterface::setChannel( int c ) const
505{ 528{
506 if ( !_mon ) 529 if ( !_mon )
507 { 530 {
508 memset( &_iwr, 0, sizeof( iwreqstruct ) ); 531 memset( &_iwr, 0, sizeof( struct iwreq ) );
509 _iwr.u.freq.m = c; 532 _iwr.u.freq.m = c;
510 _iwr.u.freq.e = 0; 533 _iwr.u.freq.e = 0;
511 wioctl( SIOCSIWFREQ ); 534 wioctl( SIOCSIWFREQ );
512 } 535 }
513 else 536 else
514 { 537 {
515 _mon->setChannel( c ); 538 _mon->setChannel( c );
516 } 539 }
517} 540}
518 541
519 542
520double OWirelessNetworkInterface::frequency() const 543double OWirelessNetworkInterface::frequency() const
521{ 544{
522 if ( !wioctl( SIOCGIWFREQ ) ) 545 if ( !wioctl( SIOCGIWFREQ ) )
523 { 546 {
524 return -1.0; 547 return -1.0;
525 } 548 }
526 else 549 else
527 { 550 {
528 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 551 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
529 } 552 }
530} 553}
531 554
532 555
533int OWirelessNetworkInterface::channels() const 556int OWirelessNetworkInterface::channels() const
534{ 557{
535 return _channels.count(); 558 return _channels.count();
536} 559}
537 560
538 561
539void OWirelessNetworkInterface::setChannelHopping( int interval ) 562void OWirelessNetworkInterface::setChannelHopping( int interval )
540{ 563{
541 if ( !_hopper ) _hopper = new OChannelHopper( this ); 564 if ( !_hopper ) _hopper = new OChannelHopper( this );
542 _hopper->setInterval( interval ); 565 _hopper->setInterval( interval );
543 //FIXME: When and by whom will the channel hopper be deleted? 566 //FIXME: When and by whom will the channel hopper be deleted?
544 //TODO: rely on QObject hierarchy 567 //TODO: rely on QObject hierarchy
545} 568}
546 569
547 570
548int OWirelessNetworkInterface::channelHopping() const 571int OWirelessNetworkInterface::channelHopping() const
549{ 572{
550 return _hopper->interval(); 573 return _hopper->interval();
551} 574}
552 575
553 576
554void OWirelessNetworkInterface::setMonitorMode( bool b ) 577void OWirelessNetworkInterface::setMonitorMode( bool b )
555{ 578{
556 if ( _mon ) 579 if ( _mon )
557 _mon->setEnabled( b ); 580 _mon->setEnabled( b );
558 else 581 else
559 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 582 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
560} 583}
561 584
562 585
563bool OWirelessNetworkInterface::monitorMode() const 586bool OWirelessNetworkInterface::monitorMode() const
564{ 587{
565 return _mon ? _mon->enabled() : false; 588 return _mon ? _mon->enabled() : false;
566} 589}
567 590
568 591
569QString OWirelessNetworkInterface::nickName() const 592QString OWirelessNetworkInterface::nickName() const
570{ 593{
571 char str[IW_ESSID_MAX_SIZE]; 594 char str[IW_ESSID_MAX_SIZE];
572 _iwr.u.data.pointer = &str[0]; 595 _iwr.u.data.pointer = &str[0];
573 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 596 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
574 if ( !wioctl( SIOCGIWNICKN ) ) 597 if ( !wioctl( SIOCGIWNICKN ) )
575 { 598 {
576 return "<unknown>"; 599 return "<unknown>";
577 } 600 }
578 else 601 else
579 { 602 {
580 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 603 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
581 return str; 604 return str;
582 } 605 }
583} 606}
584 607
585 608
586void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 609void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
587{ 610{
588 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 611 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
589 if ( !priv ) 612 if ( !priv )
590 { 613 {
591 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); 614 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
592 return; 615 return;
593 } 616 }
594 if ( priv->numberSetArgs() != numargs ) 617 if ( priv->numberSetArgs() != numargs )
595 { 618 {
596 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); 619 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs );
597 return; 620 return;
598 } 621 }
599 622
600 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); 623 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() );
601 memset( &_iwr, 0, sizeof _iwr ); 624 memset( &_iwr, 0, sizeof _iwr );
602 va_list argp; 625 va_list argp;
603 va_start( argp, numargs ); 626 va_start( argp, numargs );
604 for ( int i = 0; i < numargs; ++i ) 627 for ( int i = 0; i < numargs; ++i )
605 { 628 {
606 priv->setParameter( i, va_arg( argp, int ) ); 629 priv->setParameter( i, va_arg( argp, int ) );
607 } 630 }
608 va_end( argp ); 631 va_end( argp );
609 priv->invoke(); 632 priv->invoke();
610} 633}
611 634
612 635
613void OWirelessNetworkInterface::getPrivate( const QString& call ) 636void OWirelessNetworkInterface::getPrivate( const QString& call )
614{ 637{
615} 638}
616 639
617 640
618QString OWirelessNetworkInterface::SSID() const 641QString OWirelessNetworkInterface::SSID() const
619{ 642{
620 char str[IW_ESSID_MAX_SIZE]; 643 char str[IW_ESSID_MAX_SIZE];
621 _iwr.u.essid.pointer = &str[0]; 644 _iwr.u.essid.pointer = &str[0];
622 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 645 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
623 if ( !wioctl( SIOCGIWESSID ) ) 646 if ( !wioctl( SIOCGIWESSID ) )
624 { 647 {
625 return "<unknown>"; 648 return "<unknown>";
626 } 649 }
627 else 650 else
628 { 651 {
629 return str; 652 return str;
630 } 653 }
631} 654}
632 655
633 656
634void OWirelessNetworkInterface::setSSID( const QString& ssid ) 657void OWirelessNetworkInterface::setSSID( const QString& ssid )
635{ 658{
636 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 659 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
637 _iwr.u.essid.length = ssid.length(); 660 _iwr.u.essid.length = ssid.length();
638 wioctl( SIOCSIWESSID ); 661 wioctl( SIOCSIWESSID );
639} 662}
640 663
641 664
642bool OWirelessNetworkInterface::wioctl( int call, iwreqstruct& iwreq ) const 665bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
643{ 666{
644 int result = ::ioctl( _sfd, call, &iwreq ); 667 int result = ::ioctl( _sfd, call, &iwreq );
645 if ( result == -1 ) 668 if ( result == -1 )
646 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 669 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) );
647 else 670 else
648 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call ); 671 qDebug( "ONetworkInterface::wioctl(): Call %d - Status: Ok.", call );
649 return ( result != -1 ); 672 return ( result != -1 );
650} 673}
651 674
652 675
653bool OWirelessNetworkInterface::wioctl( int call ) const 676bool OWirelessNetworkInterface::wioctl( int call ) const
654{ 677{
655 strcpy( _iwr.ifr_name, name() ); 678 strcpy( _iwr.ifr_name, name() );
656 return wioctl( call, _iwr ); 679 return wioctl( call, _iwr );
657} 680}
658 681
659 682
660/*====================================================================================== 683/*======================================================================================
661 * OMonitoringInterface 684 * OMonitoringInterface
662 *======================================================================================*/ 685 *======================================================================================*/
663 686
664OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) 687OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface )
665 :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) ) 688 :_enabled( false ), _if( static_cast<OWirelessNetworkInterface*>( iface ) )
666{ 689{
667} 690}
668 691
669 692
670OMonitoringInterface::~OMonitoringInterface() 693OMonitoringInterface::~OMonitoringInterface()
671{ 694{
672} 695}
673 696
674 697
675void OMonitoringInterface::setChannel( int c ) 698void OMonitoringInterface::setChannel( int c )
676{ 699{
677 // use standard WE channel switching protocol 700 // use standard WE channel switching protocol
678 memset( &_if->_iwr, 0, sizeof( iwreqstruct ) ); 701 memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
679 _if->_iwr.u.freq.m = c; 702 _if->_iwr.u.freq.m = c;
680 _if->_iwr.u.freq.e = 0; 703 _if->_iwr.u.freq.e = 0;
681 _if->wioctl( SIOCSIWFREQ ); 704 _if->wioctl( SIOCSIWFREQ );
682} 705}
683 706
684 707
685bool OMonitoringInterface::enabled() const 708bool OMonitoringInterface::enabled() const
686{ 709{
687 return _enabled; 710 return _enabled;
688} 711}
689 712
690void OMonitoringInterface::setEnabled( bool b ) 713void OMonitoringInterface::setEnabled( bool b )
691{ 714{
692 // open a packet capturer here or leave this to 715 // open a packet capturer here or leave this to
693 // the client code? 716 // the client code?
694 717
695 /* 718 /*
696 719
697 if ( b ) 720 if ( b )
698 { 721 {
699 OPacketCapturer* opcap = new OPacketCapturer(); 722 OPacketCapturer* opcap = new OPacketCapturer();
700 opcap->open( _if->name() ); 723 opcap->open( _if->name() );
701 } 724 }
702 */ 725 */
703 726
704 _enabled = b; 727 _enabled = b;
705 728
706} 729}
707 730
708/*====================================================================================== 731/*======================================================================================
709 * OCiscoMonitoringInterface 732 * OCiscoMonitoringInterface
710 *======================================================================================*/ 733 *======================================================================================*/
711 734
712OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) 735OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface )
713 :OMonitoringInterface( iface ) 736 :OMonitoringInterface( iface )
714{ 737{
715 iface->setMonitoring( this ); 738 iface->setMonitoring( this );
716} 739}
717 740
718 741
719OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 742OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
720{ 743{
721} 744}
722 745
723 746
724void OCiscoMonitoringInterface::setEnabled( bool b ) 747void OCiscoMonitoringInterface::setEnabled( bool b )
725{ 748{
726 QString fname; 749 QString fname;
727 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 750 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
728 QFile f( fname ); 751 QFile f( fname );
729 if ( !f.exists() ) return; 752 if ( !f.exists() ) return;
730 753
731 if ( f.open( IO_WriteOnly ) ) 754 if ( f.open( IO_WriteOnly ) )
732 { 755 {
733 QTextStream s( &f ); 756 QTextStream s( &f );
734 s << "Mode: r"; 757 s << "Mode: r";
735 s << "Mode: y"; 758 s << "Mode: y";
736 s << "XmitPower: 1"; 759 s << "XmitPower: 1";
737 760
738 OMonitoringInterface::setEnabled( b ); 761 OMonitoringInterface::setEnabled( b );
739 762
740 } 763 }
741 764
742 // flushing and closing will be done automatically when f goes out of scope 765 // flushing and closing will be done automatically when f goes out of scope
743} 766}
744 767
745 768
746QString OCiscoMonitoringInterface::name() const 769QString OCiscoMonitoringInterface::name() const
747{ 770{
748 return "cisco"; 771 return "cisco";
749} 772}
750 773
751 774
752void OCiscoMonitoringInterface::setChannel( int ) 775void OCiscoMonitoringInterface::setChannel( int )
753{ 776{
754 // cisco devices automatically switch channels when in monitor mode 777 // cisco devices automatically switch channels when in monitor mode
755} 778}
756 779
757 780
758/*====================================================================================== 781/*======================================================================================
759 * OWlanNGMonitoringInterface 782 * OWlanNGMonitoringInterface
760 *======================================================================================*/ 783 *======================================================================================*/
761 784
762 785
763OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) 786OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface )
764 :OMonitoringInterface( iface ) 787 :OMonitoringInterface( iface )
765{ 788{
766 iface->setMonitoring( this ); 789 iface->setMonitoring( this );
767} 790}
768 791
769 792
770OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 793OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
771{ 794{
772} 795}
773 796
774 797
775void OWlanNGMonitoringInterface::setEnabled( bool b ) 798void OWlanNGMonitoringInterface::setEnabled( bool b )
776{ 799{
777 //FIXME: do nothing if its already in the same mode 800 //FIXME: do nothing if its already in the same mode
778 801
779 QString enable = b ? "true" : "false"; 802 QString enable = b ? "true" : "false";
780 QString cmd; 803 QString cmd;
781 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); 804 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable );
782 system( cmd ); 805 system( cmd );
783 806
784 OMonitoringInterface::setEnabled( b ); 807 OMonitoringInterface::setEnabled( b );
785} 808}
786 809
787 810
788QString OWlanNGMonitoringInterface::name() const 811QString OWlanNGMonitoringInterface::name() const
789{ 812{
790 return "wlan-ng"; 813 return "wlan-ng";
791} 814}
792 815
793 816
794void OWlanNGMonitoringInterface::setChannel( int ) 817void OWlanNGMonitoringInterface::setChannel( int )
795{ 818{
796 // wlan-ng devices automatically switch channels when in monitor mode 819 // wlan-ng devices automatically switch channels when in monitor mode
797} 820}
798 821
799 822
800/*====================================================================================== 823/*======================================================================================
801 * OHostAPMonitoringInterface 824 * OHostAPMonitoringInterface
802 *======================================================================================*/ 825 *======================================================================================*/
803 826
804OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) 827OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface )
805 :OMonitoringInterface( iface ) 828 :OMonitoringInterface( iface )
806{ 829{
807 iface->setMonitoring( this ); 830 iface->setMonitoring( this );
808} 831}
809 832
810OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 833OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
811{ 834{
812} 835}
813 836
814void OHostAPMonitoringInterface::setEnabled( bool b ) 837void OHostAPMonitoringInterface::setEnabled( bool b )
815{ 838{
816 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 839 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
817 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 840 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
818 841
819 if ( b ) 842 if ( b )
820 { 843 {
821 #if WIRELESS_EXT > 14 844 #if WIRELESS_EXT > 14
822 _if->_iwr.u.mode = IW_MODE_MONITOR; 845 _if->_iwr.u.mode = IW_MODE_MONITOR;
823 _if->wioctl( SIOCSIWMODE ); 846 _if->wioctl( SIOCSIWMODE );
824 #else 847 #else
825 int* args = (int*) &_if->_iwr.u.name; 848 int* args = (int*) &_if->_iwr.u.name;
826 args[0] = 2; 849 args[0] = 2;
827 args[1] = 0; 850 args[1] = 0;
828 _if->wioctl( SIOCDEVPRIVATE ); 851 _if->wioctl( SIOCDEVPRIVATE );
829 #endif 852 #endif
830 } 853 }
831 else 854 else
832 { 855 {
833 #if WIRELESS_EXT > 14 856 #if WIRELESS_EXT > 14
834 _if->_iwr.u.mode = IW_MODE_INFRA; 857 _if->_iwr.u.mode = IW_MODE_INFRA;
835 _if->wioctl( SIOCSIWMODE ); 858 _if->wioctl( SIOCSIWMODE );
836 #else 859 #else
837 int* args = (int*) &_if->_iwr.u.name; 860 int* args = (int*) &_if->_iwr.u.name;
838 args[0] = 0; 861 args[0] = 0;
839 args[1] = 0; 862 args[1] = 0;
840 _if->wioctl( SIOCDEVPRIVATE ); 863 _if->wioctl( SIOCDEVPRIVATE );
841 #endif 864 #endif
842 } 865 }
843 866
844 OMonitoringInterface::setEnabled( b ); 867 OMonitoringInterface::setEnabled( b );
845} 868}
846 869
847 870
848QString OHostAPMonitoringInterface::name() const 871QString OHostAPMonitoringInterface::name() const
849{ 872{
850 return "hostap"; 873 return "hostap";
851} 874}
852 875
853 876
854/*====================================================================================== 877/*======================================================================================
855 * OOrinocoNetworkInterface 878 * OOrinocoNetworkInterface
856 *======================================================================================*/ 879 *======================================================================================*/
857 880
858OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) 881OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface )
859 :OMonitoringInterface( iface ) 882 :OMonitoringInterface( iface )
860{ 883{
861 iface->setMonitoring( this ); 884 iface->setMonitoring( this );
862} 885}
863 886
864 887
865OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 888OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
866{ 889{
867} 890}
868 891
869 892
870void OOrinocoMonitoringInterface::setChannel( int c ) 893void OOrinocoMonitoringInterface::setChannel( int c )
871{ 894{
872 // call iwpriv <device> monitor 2 <channel> 895 // call iwpriv <device> monitor 2 <channel>
873 int* args = (int*) &_if->_iwr.u.name; 896 int* args = (int*) &_if->_iwr.u.name;
874 args[0] = 2; 897 args[0] = 2;
875 args[1] = c; 898 args[1] = c;
876 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); 899 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
877} 900}
878 901
879 902
880void OOrinocoMonitoringInterface::setEnabled( bool b ) 903void OOrinocoMonitoringInterface::setEnabled( bool b )
881{ 904{
882 if ( b ) 905 if ( b )
883 { 906 {
884 setChannel( 1 ); 907 setChannel( 1 );
885 } 908 }
886 else 909 else
887 { 910 {
888 // call iwpriv <device> monitor 0 0 911 // call iwpriv <device> monitor 0 0
889 int* args = (int*) &_if->_iwr.u.name; 912 int* args = (int*) &_if->_iwr.u.name;
890 args[0] = 0; 913 args[0] = 0;
891 args[1] = 0; 914 args[1] = 0;
892 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 ); 915 _if->wioctl( SIOCIWFIRSTPRIV + 0x8 );
893 } 916 }
894 917
895 OMonitoringInterface::setEnabled( b ); 918 OMonitoringInterface::setEnabled( b );
896} 919}
897 920
898 921
899QString OOrinocoMonitoringInterface::name() const 922QString OOrinocoMonitoringInterface::name() const
900{ 923{
901 return "orinoco"; 924 return "orinoco";
902} 925}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index 7c70873..509c3db 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -1,331 +1,324 @@
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 66#ifndef SIOCIWFIRSTPRIV
67#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE 67#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
68#endif 68#endif
69 69
70class ONetworkInterface; 70class ONetworkInterface;
71class OWirelessNetworkInterface; 71class OWirelessNetworkInterface;
72class OChannelHopper; 72class OChannelHopper;
73class OMonitoringInterface; 73class OMonitoringInterface;
74 74
75typedef struct ifreq ifreqstruct;
76typedef struct iwreq iwreqstruct;
77typedef struct iw_event iweventstruct;
78typedef struct iw_freq iwfreqstruct;
79typedef struct iw_priv_args iwprivargsstruct;
80typedef struct iw_range iwrangestruct;
81
82/*====================================================================================== 75/*======================================================================================
83 * ONetwork 76 * ONetwork
84 *======================================================================================*/ 77 *======================================================================================*/
85 78
86class ONetwork : public QObject 79class ONetwork : public QObject
87{ 80{
88 Q_OBJECT 81 Q_OBJECT
89 82
90 public: 83 public:
91 typedef QDict<ONetworkInterface> InterfaceMap; 84 typedef QDict<ONetworkInterface> InterfaceMap;
92 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 85 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
93 86
94 public: 87 public:
95 static ONetwork* instance(); 88 static ONetwork* instance();
96 InterfaceIterator iterator() const; 89 InterfaceIterator iterator() const;
97 bool isWirelessInterface( const char* ) const; 90 bool isWirelessInterface( const char* ) const;
98 ONetworkInterface* interface( QString ) const; 91 ONetworkInterface* interface( QString ) const;
99 92
100 protected: 93 protected:
101 ONetwork(); 94 ONetwork();
102 void synchronize(); 95 void synchronize();
103 96
104 private: 97 private:
105 static ONetwork* _instance; 98 static ONetwork* _instance;
106 InterfaceMap _interfaces; 99 InterfaceMap _interfaces;
107}; 100};
108 101
109 102
110/*====================================================================================== 103/*======================================================================================
111 * ONetworkInterface 104 * ONetworkInterface
112 *======================================================================================*/ 105 *======================================================================================*/
113 106
114class ONetworkInterface : public QObject 107class ONetworkInterface : public QObject
115{ 108{
116 friend class OMonitoringInterface; 109 friend class OMonitoringInterface;
117 friend class OCiscoMonitoringInterface; 110 friend class OCiscoMonitoringInterface;
118 friend class OWlanNGMonitoringInterface; 111 friend class OWlanNGMonitoringInterface;
119 friend class OHostAPMonitoringInterface; 112 friend class OHostAPMonitoringInterface;
120 friend class OOrinocoMonitoringInterface; 113 friend class OOrinocoMonitoringInterface;
121 114
122 public: 115 public:
123 ONetworkInterface( QObject* parent, const char* name ); 116 ONetworkInterface( QObject* parent, const char* name );
124 virtual ~ONetworkInterface(); 117 virtual ~ONetworkInterface();
125 118
126 void setMonitoring( OMonitoringInterface* ); 119 void setMonitoring( OMonitoringInterface* );
127 OMonitoringInterface* monitoring() const; 120 OMonitoringInterface* monitoring() const;
128 bool setPromiscuousMode( bool ); 121 bool setPromiscuousMode( bool );
129 bool promiscuousMode() const; 122 bool promiscuousMode() const;
130 bool setUp( bool ); 123 bool setUp( bool );
131 bool isUp() const; 124 bool isUp() const;
132 bool isLoopback() const; 125 bool isLoopback() const;
133 bool isWireless() const; 126 bool isWireless() const;
134 QString ipV4Address() const; 127 QString ipV4Address() const;
135 OMacAddress macAddress() const; 128 OMacAddress macAddress() const;
136 129
137 protected: 130 protected:
138 const int _sfd; 131 const int _sfd;
139 mutable ifreqstruct _ifr; 132 mutable ifreq _ifr;
140 OMonitoringInterface* _mon; 133 OMonitoringInterface* _mon;
141 134
142 protected: 135 protected:
143 ifreqstruct& ifr() const; 136 struct ifreq& ifr() const;
144 virtual void init(); 137 virtual void init();
145 bool ioctl( int call ) const; 138 bool ioctl( int call ) const;
146 bool ioctl( int call, ifreqstruct& ) const; 139 bool ioctl( int call, struct ifreq& ) const;
147}; 140};
148 141
149/*====================================================================================== 142/*======================================================================================
150 * OChannelHopper 143 * OChannelHopper
151 *======================================================================================*/ 144 *======================================================================================*/
152 145
153class OChannelHopper : public QObject 146class OChannelHopper : public QObject
154{ 147{
155 public: 148 public:
156 OChannelHopper( OWirelessNetworkInterface* ); 149 OChannelHopper( OWirelessNetworkInterface* );
157 virtual ~OChannelHopper(); 150 virtual ~OChannelHopper();
158 bool isActive() const; 151 bool isActive() const;
159 int channel() const; 152 int channel() const;
160 virtual void timerEvent( QTimerEvent* ); 153 virtual void timerEvent( QTimerEvent* );
161 void setInterval( int ); 154 void setInterval( int );
162 int interval() const; 155 int interval() const;
163 156
164 private: 157 private:
165 OWirelessNetworkInterface* _iface; 158 OWirelessNetworkInterface* _iface;
166 int _interval; 159 int _interval;
167 int _tid; 160 int _tid;
168 QValueList<int> _channels; 161 QValueList<int> _channels;
169 QValueList<int>::Iterator _channel; 162 QValueList<int>::Iterator _channel;
170 163
171}; 164};
172 165
173 166
174/*====================================================================================== 167/*======================================================================================
175 * OWirelessNetworkInterface 168 * OWirelessNetworkInterface
176 *======================================================================================*/ 169 *======================================================================================*/
177 170
178class OWirelessNetworkInterface : public ONetworkInterface 171class OWirelessNetworkInterface : public ONetworkInterface
179{ 172{
180 friend class OMonitoringInterface; 173 friend class OMonitoringInterface;
181 friend class OCiscoMonitoringInterface; 174 friend class OCiscoMonitoringInterface;
182 friend class OWlanNGMonitoringInterface; 175 friend class OWlanNGMonitoringInterface;
183 friend class OHostAPMonitoringInterface; 176 friend class OHostAPMonitoringInterface;
184 friend class OOrinocoMonitoringInterface; 177 friend class OOrinocoMonitoringInterface;
185 178
186 friend class OPrivateIOCTL; 179 friend class OPrivateIOCTL;
187 180
188 public: 181 public:
189 enum Mode { AdHoc, Managed, Monitor }; 182 enum Mode { AdHoc, Managed, Monitor };
190 183
191 OWirelessNetworkInterface( QObject* parent, const char* name ); 184 OWirelessNetworkInterface( QObject* parent, const char* name );
192 virtual ~OWirelessNetworkInterface(); 185 virtual ~OWirelessNetworkInterface();
193 186
194 virtual void setChannel( int ) const; 187 virtual void setChannel( int ) const;
195 virtual int channel() const; 188 virtual int channel() const;
196 virtual double frequency() const; 189 virtual double frequency() const;
197 virtual int channels() const; 190 virtual int channels() const;
198 //virtual double frequency(int) const; 191 //virtual double frequency(int) const;
199 192
200 virtual void setMode( Mode ) {}; 193 virtual void setMode( Mode ) {};
201 virtual bool mode() const {}; 194 virtual bool mode() const {};
202 195
203 virtual void setMonitorMode( bool ); 196 virtual void setMonitorMode( bool );
204 virtual bool monitorMode() const; 197 virtual bool monitorMode() const;
205 198
206 virtual void setChannelHopping( int interval = 0 ); 199 virtual void setChannelHopping( int interval = 0 );
207 virtual int channelHopping() const; 200 virtual int channelHopping() const;
208 201
209 virtual void setNickName( const QString& ) {}; 202 virtual void setNickName( const QString& ) {};
210 virtual QString nickName() const; 203 virtual QString nickName() const;
211 204
212 virtual void setPrivate( const QString&, int, ... ); 205 virtual void setPrivate( const QString&, int, ... );
213 virtual void getPrivate( const QString& ); 206 virtual void getPrivate( const QString& );
214 207
215 virtual bool isAssociated() const {}; 208 virtual bool isAssociated() const {};
216 virtual QString associatedAP() const; 209 virtual QString associatedAP() const;
217 210
218 virtual void setSSID( const QString& ); 211 virtual void setSSID( const QString& );
219 virtual QString SSID() const; 212 virtual QString SSID() const;
220 213
221 protected: 214 protected:
222 void buildChannelList(); 215 void buildChannelList();
223 void buildPrivateList(); 216 void buildPrivateList();
224 virtual void init(); 217 virtual void init();
225 iwreqstruct& iwr() const; 218 struct iwreq& iwr() const;
226 bool wioctl( int call ) const; 219 bool wioctl( int call ) const;
227 bool wioctl( int call, iwreqstruct& ) const; 220 bool wioctl( int call, struct iwreq& ) const;
228 221
229 protected: 222 protected:
230 mutable iwreqstruct _iwr; 223 mutable struct iwreq _iwr;
231 QMap<int,int> _channels; 224 QMap<int,int> _channels;
232 225
233 private: 226 private:
234 OChannelHopper* _hopper; 227 OChannelHopper* _hopper;
235}; 228};
236 229
237 230
238/*====================================================================================== 231/*======================================================================================
239 * OMonitoringInterface 232 * OMonitoringInterface
240 *======================================================================================*/ 233 *======================================================================================*/
241 234
242 235
243class OMonitoringInterface 236class OMonitoringInterface
244{ 237{
245 public: 238 public:
246 OMonitoringInterface(); 239 OMonitoringInterface();
247 OMonitoringInterface( ONetworkInterface* ); 240 OMonitoringInterface( ONetworkInterface* );
248 virtual ~OMonitoringInterface(); 241 virtual ~OMonitoringInterface();
249 242
250 public: 243 public:
251 virtual void setEnabled( bool ); 244 virtual void setEnabled( bool );
252 virtual bool enabled() const; 245 virtual bool enabled() const;
253 virtual void setChannel( int ); 246 virtual void setChannel( int );
254 247
255 virtual QString name() const = 0; 248 virtual QString name() const = 0;
256 249
257 protected: 250 protected:
258 bool _enabled; 251 bool _enabled;
259 const OWirelessNetworkInterface* _if; 252 const OWirelessNetworkInterface* _if;
260 253
261}; 254};
262 255
263 256
264/*====================================================================================== 257/*======================================================================================
265 * OCiscoMonitoring 258 * OCiscoMonitoring
266 *======================================================================================*/ 259 *======================================================================================*/
267 260
268 261
269class OCiscoMonitoringInterface : public OMonitoringInterface 262class OCiscoMonitoringInterface : public OMonitoringInterface
270{ 263{
271 public: 264 public:
272 OCiscoMonitoringInterface( ONetworkInterface* ); 265 OCiscoMonitoringInterface( ONetworkInterface* );
273 virtual ~OCiscoMonitoringInterface(); 266 virtual ~OCiscoMonitoringInterface();
274 267
275 virtual void setEnabled( bool ); 268 virtual void setEnabled( bool );
276 virtual QString name() const; 269 virtual QString name() const;
277 virtual void setChannel( int ); 270 virtual void setChannel( int );
278 271
279}; 272};
280 273
281/*====================================================================================== 274/*======================================================================================
282 * OWlanNGMonitoringInterface 275 * OWlanNGMonitoringInterface
283 *======================================================================================*/ 276 *======================================================================================*/
284 277
285class OWlanNGMonitoringInterface : public OMonitoringInterface 278class OWlanNGMonitoringInterface : public OMonitoringInterface
286{ 279{
287 public: 280 public:
288 OWlanNGMonitoringInterface( ONetworkInterface* ); 281 OWlanNGMonitoringInterface( ONetworkInterface* );
289 virtual ~OWlanNGMonitoringInterface(); 282 virtual ~OWlanNGMonitoringInterface();
290 283
291 public: 284 public:
292 virtual void setEnabled( bool ); 285 virtual void setEnabled( bool );
293 virtual QString name() const; 286 virtual QString name() const;
294 virtual void setChannel( int ); 287 virtual void setChannel( int );
295 288
296}; 289};
297 290
298/*====================================================================================== 291/*======================================================================================
299 * OHostAPMonitoringInterface 292 * OHostAPMonitoringInterface
300 *======================================================================================*/ 293 *======================================================================================*/
301 294
302class OHostAPMonitoringInterface : public OMonitoringInterface 295class OHostAPMonitoringInterface : public OMonitoringInterface
303{ 296{
304 public: 297 public:
305 OHostAPMonitoringInterface( ONetworkInterface* ); 298 OHostAPMonitoringInterface( ONetworkInterface* );
306 virtual ~OHostAPMonitoringInterface(); 299 virtual ~OHostAPMonitoringInterface();
307 300
308 public: 301 public:
309 virtual void setEnabled( bool ); 302 virtual void setEnabled( bool );
310 virtual QString name() const; 303 virtual QString name() const;
311 }; 304 };
312 305
313/*====================================================================================== 306/*======================================================================================
314 * OOrinocoMonitoringInterface 307 * OOrinocoMonitoringInterface
315 *======================================================================================*/ 308 *======================================================================================*/
316 309
317class OOrinocoMonitoringInterface : public OMonitoringInterface 310class OOrinocoMonitoringInterface : public OMonitoringInterface
318{ 311{
319 public: 312 public:
320 OOrinocoMonitoringInterface( ONetworkInterface* ); 313 OOrinocoMonitoringInterface( ONetworkInterface* );
321 virtual ~OOrinocoMonitoringInterface(); 314 virtual ~OOrinocoMonitoringInterface();
322 315
323 public: 316 public:
324 virtual void setChannel( int ); 317 virtual void setChannel( int );
325 virtual void setEnabled( bool ); 318 virtual void setEnabled( bool );
326 virtual QString name() const; 319 virtual QString name() const;
327 320
328}; 321};
329 322
330#endif // ONETWORK_H 323#endif // ONETWORK_H
331 324