summaryrefslogtreecommitdiff
path: root/libopie2/opienet
authormickeyl <mickeyl>2003-05-01 00:59:20 (UTC)
committer mickeyl <mickeyl>2003-05-01 00:59:20 (UTC)
commit1d721ddb247e9000e29fba3150e0cce5f59f543e (patch) (unidiff)
tree70b659b209395c8aff25442afaa4fc57c29679e6 /libopie2/opienet
parent30c685f9da06d19c993e9bdb74f349dabbde063e (diff)
downloadopie-1d721ddb247e9000e29fba3150e0cce5f59f543e.zip
opie-1d721ddb247e9000e29fba3150e0cce5f59f543e.tar.gz
opie-1d721ddb247e9000e29fba3150e0cce5f59f543e.tar.bz2
implement and document a bunch of missing methods
Diffstat (limited to 'libopie2/opienet') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp51
-rw-r--r--libopie2/opienet/onetwork.h58
2 files changed, 88 insertions, 21 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 95e7043..2dfff1d 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,957 +1,1008 @@
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 <assert.h>
45#include <arpa/inet.h> 46#include <arpa/inet.h>
46#include <cerrno> 47#include <cerrno>
47#include <cstring> 48#include <cstring>
48#include <cstdlib> 49#include <cstdlib>
49#include <math.h> 50#include <math.h>
50#include <sys/ioctl.h> 51#include <sys/ioctl.h>
51#include <sys/socket.h> 52#include <sys/socket.h>
52#include <sys/types.h> 53#include <sys/types.h>
53#include <unistd.h> 54#include <unistd.h>
54#include <linux/sockios.h> 55#include <linux/sockios.h>
55#include <net/if_arp.h> 56#include <net/if_arp.h>
56#include <stdarg.h> 57#include <stdarg.h>
57 58
58using namespace std; 59using namespace std;
59 60
60/*====================================================================================== 61/*======================================================================================
61 * ONetwork 62 * ONetwork
62 *======================================================================================*/ 63 *======================================================================================*/
63 64
64ONetwork* ONetwork::_instance = 0; 65ONetwork* ONetwork::_instance = 0;
65 66
66ONetwork::ONetwork() 67ONetwork::ONetwork()
67{ 68{
68 qDebug( "ONetwork::ONetwork()" ); 69 qDebug( "ONetwork::ONetwork()" );
69 synchronize(); 70 synchronize();
70} 71}
71 72
72void ONetwork::synchronize() 73void ONetwork::synchronize()
73{ 74{
74 // gather available interfaces by inspecting /proc/net/dev 75 // 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 76 //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 77 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
77 78
78 _interfaces.clear(); 79 _interfaces.clear();
79 QString str; 80 QString str;
80 QFile f( "/proc/net/dev" ); 81 QFile f( "/proc/net/dev" );
81 bool hasFile = f.open( IO_ReadOnly ); 82 bool hasFile = f.open( IO_ReadOnly );
82 if ( !hasFile ) 83 if ( !hasFile )
83 { 84 {
84 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" ); 85 qDebug( "ONetwork: /proc/net/dev not existing. No network devices available" );
85 return; 86 return;
86 } 87 }
87 QTextStream s( &f ); 88 QTextStream s( &f );
88 s.readLine(); 89 s.readLine();
89 s.readLine(); 90 s.readLine();
90 while ( !s.atEnd() ) 91 while ( !s.atEnd() )
91 { 92 {
92 s >> str; 93 s >> str;
93 str.truncate( str.find( ':' ) ); 94 str.truncate( str.find( ':' ) );
94 qDebug( "ONetwork: found interface '%s'", (const char*) str ); 95 qDebug( "ONetwork: found interface '%s'", (const char*) str );
95 ONetworkInterface* iface; 96 ONetworkInterface* iface;
96 if ( isWirelessInterface( str ) ) 97 if ( isWirelessInterface( str ) )
97 { 98 {
98 iface = new OWirelessNetworkInterface( this, (const char*) str ); 99 iface = new OWirelessNetworkInterface( this, (const char*) str );
99 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str ); 100 qDebug( "ONetwork: interface '%s' has Wireless Extensions", (const char*) str );
100 } 101 }
101 else 102 else
102 { 103 {
103 iface = new ONetworkInterface( this, (const char*) str ); 104 iface = new ONetworkInterface( this, (const char*) str );
104 } 105 }
105 _interfaces.insert( str, iface ); 106 _interfaces.insert( str, iface );
106 s.readLine(); 107 s.readLine();
107 } 108 }
108} 109}
109 110
110 111
111int ONetwork::count() const 112int ONetwork::count() const
112{ 113{
113 return _interfaces.count(); 114 return _interfaces.count();
114} 115}
115 116
116 117
117ONetworkInterface* ONetwork::interface( const QString& iface ) const 118ONetworkInterface* ONetwork::interface( const QString& iface ) const
118{ 119{
119 return _interfaces[iface]; 120 return _interfaces[iface];
120} 121}
121 122
122 123
123ONetwork* ONetwork::instance() 124ONetwork* ONetwork::instance()
124{ 125{
125 if ( !_instance ) _instance = new ONetwork(); 126 if ( !_instance ) _instance = new ONetwork();
126 return _instance; 127 return _instance;
127} 128}
128 129
129 130
130ONetwork::InterfaceIterator ONetwork::iterator() const 131ONetwork::InterfaceIterator ONetwork::iterator() const
131{ 132{
132 return ONetwork::InterfaceIterator( _interfaces ); 133 return ONetwork::InterfaceIterator( _interfaces );
133} 134}
134 135
135 136
136bool ONetwork::isWirelessInterface( const char* name ) const 137bool ONetwork::isWirelessInterface( const char* name ) const
137{ 138{
138 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 139 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
139 struct iwreq iwr; 140 struct iwreq iwr;
140 memset( &iwr, 0, sizeof( struct iwreq ) ); 141 memset( &iwr, 0, sizeof( struct iwreq ) );
141 strcpy( (char*) &iwr.ifr_name, name ); 142 strcpy( (char*) &iwr.ifr_name, name );
142 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 143 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
143 return result != -1; 144 return result != -1;
144} 145}
145 146
146/*====================================================================================== 147/*======================================================================================
147 * ONetworkInterface 148 * ONetworkInterface
148 *======================================================================================*/ 149 *======================================================================================*/
149 150
150ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) 151ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
151 :QObject( parent, name ), 152 :QObject( parent, name ),
152 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 153 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
153{ 154{
154 qDebug( "ONetworkInterface::ONetworkInterface()" ); 155 qDebug( "ONetworkInterface::ONetworkInterface()" );
155 init(); 156 init();
156} 157}
157 158
158 159
159struct ifreq& ONetworkInterface::ifr() const 160struct ifreq& ONetworkInterface::ifr() const
160{ 161{
161 return _ifr; 162 return _ifr;
162} 163}
163 164
164 165
165void ONetworkInterface::init() 166void ONetworkInterface::init()
166{ 167{
167 qDebug( "ONetworkInterface::init()" ); 168 qDebug( "ONetworkInterface::init()" );
168 169
169 memset( &_ifr, 0, sizeof( struct ifreq ) ); 170 memset( &_ifr, 0, sizeof( struct ifreq ) );
170 171
171 if ( _sfd == -1 ) 172 if ( _sfd == -1 )
172 { 173 {
173 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() ); 174 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", name() );
174 return; 175 return;
175 } 176 }
176} 177}
177 178
178 179
179bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const 180bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
180{ 181{
181 int result = ::ioctl( _sfd, call, &ifreq ); 182 int result = ::ioctl( _sfd, call, &ifreq );
182 if ( result == -1 ) 183 if ( result == -1 )
183 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 184 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
184 else 185 else
185 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call ); 186 qDebug( "ONetworkInterface::ioctl (%s) call %d - Status: Ok.", name(), call );
186 return ( result != -1 ); 187 return ( result != -1 );
187} 188}
188 189
189 190
190bool ONetworkInterface::ioctl( int call ) const 191bool ONetworkInterface::ioctl( int call ) const
191{ 192{
192 strcpy( _ifr.ifr_name, name() ); 193 strcpy( _ifr.ifr_name, name() );
193 return ioctl( call, _ifr ); 194 return ioctl( call, _ifr );
194} 195}
195 196
196 197
197bool ONetworkInterface::isLoopback() const 198bool ONetworkInterface::isLoopback() const
198{ 199{
199 ioctl( SIOCGIFFLAGS ); 200 ioctl( SIOCGIFFLAGS );
200 return _ifr.ifr_flags & IFF_LOOPBACK; 201 return _ifr.ifr_flags & IFF_LOOPBACK;
201} 202}
202 203
203 204
204bool ONetworkInterface::setUp( bool b ) 205bool ONetworkInterface::setUp( bool b )
205{ 206{
206 ioctl( SIOCGIFFLAGS ); 207 ioctl( SIOCGIFFLAGS );
207 if ( b ) _ifr.ifr_flags |= IFF_UP; 208 if ( b ) _ifr.ifr_flags |= IFF_UP;
208 else _ifr.ifr_flags &= (~IFF_UP); 209 else _ifr.ifr_flags &= (~IFF_UP);
209 return ioctl( SIOCSIFFLAGS ); 210 return ioctl( SIOCSIFFLAGS );
210} 211}
211 212
212 213
213bool ONetworkInterface::isUp() const 214bool ONetworkInterface::isUp() const
214{ 215{
215 ioctl( SIOCGIFFLAGS ); 216 ioctl( SIOCGIFFLAGS );
216 return _ifr.ifr_flags & IFF_UP; 217 return _ifr.ifr_flags & IFF_UP;
217} 218}
218 219
219 220
220void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) 221void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
221{ 222{
222 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 223 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
223 sa->sin_family = AF_INET; 224 sa->sin_family = AF_INET;
224 sa->sin_port = 0; 225 sa->sin_port = 0;
225 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 226 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
226 ioctl( SIOCSIFADDR ); 227 ioctl( SIOCSIFADDR );
227} 228}
228 229
229 230
230QString ONetworkInterface::ipV4Address() const 231QString ONetworkInterface::ipV4Address() const
231{ 232{
232 if ( ioctl( SIOCGIFADDR ) ) 233 if ( ioctl( SIOCGIFADDR ) )
233 { 234 {
234 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; 235 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
235 //FIXME: Use QHostAddress here 236 //FIXME: Use QHostAddress here
236 return QString( inet_ntoa( sa->sin_addr ) ); 237 return QString( inet_ntoa( sa->sin_addr ) );
237 } 238 }
238 else 239 else
239 return "<unknown>"; 240 return "<unknown>";
240} 241}
241 242
242 243
243void ONetworkInterface::setMacAddress( const OMacAddress& addr ) 244void ONetworkInterface::setMacAddress( const OMacAddress& addr )
244{ 245{
245 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 246 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
246 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); 247 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
247 ioctl( SIOCSIFHWADDR ); 248 ioctl( SIOCSIFHWADDR );
248} 249}
249 250
250 251
251OMacAddress ONetworkInterface::macAddress() const 252OMacAddress ONetworkInterface::macAddress() const
252{ 253{
253 if ( ioctl( SIOCGIFHWADDR ) ) 254 if ( ioctl( SIOCGIFHWADDR ) )
254 { 255 {
255 return OMacAddress( _ifr ); 256 return OMacAddress( _ifr );
256 } 257 }
257 else 258 else
258 { 259 {
259 return OMacAddress::unknown; 260 return OMacAddress::unknown;
260 } 261 }
261} 262}
262 263
263 264
264void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) 265void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr )
265{ 266{
266 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 267 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
267 sa->sin_family = AF_INET; 268 sa->sin_family = AF_INET;
268 sa->sin_port = 0; 269 sa->sin_port = 0;
269 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 270 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
270 ioctl( SIOCSIFNETMASK ); 271 ioctl( SIOCSIFNETMASK );
271} 272}
272 273
273 274
274QString ONetworkInterface::ipV4Netmask() const 275QString ONetworkInterface::ipV4Netmask() const
275{ 276{
276 if ( ioctl( SIOCGIFNETMASK ) ) 277 if ( ioctl( SIOCGIFNETMASK ) )
277 { 278 {
278 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; 279 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
279 //FIXME: Use QHostAddress here 280 //FIXME: Use QHostAddress here
280 return QString( inet_ntoa( sa->sin_addr ) ); 281 return QString( inet_ntoa( sa->sin_addr ) );
281 } 282 }
282 else 283 else
283 return "<unknown>"; 284 return "<unknown>";
284} 285}
285 286
286 287
287int ONetworkInterface::dataLinkType() const 288int ONetworkInterface::dataLinkType() const
288{ 289{
289 if ( ioctl( SIOCGIFHWADDR ) ) 290 if ( ioctl( SIOCGIFHWADDR ) )
290 { 291 {
291 return _ifr.ifr_hwaddr.sa_family; 292 return _ifr.ifr_hwaddr.sa_family;
292 } 293 }
293 else 294 else
294 { 295 {
295 return -1; 296 return -1;
296 } 297 }
297} 298}
298 299
299 300
300void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 301void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
301{ 302{
302 _mon = m; 303 _mon = m;
303 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() ); 304 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), name() );
304} 305}
305 306
306 307
307OMonitoringInterface* ONetworkInterface::monitoring() const 308OMonitoringInterface* ONetworkInterface::monitoring() const
308{ 309{
309 return _mon; 310 return _mon;
310} 311}
311 312
312 313
313ONetworkInterface::~ONetworkInterface() 314ONetworkInterface::~ONetworkInterface()
314{ 315{
315 qDebug( "ONetworkInterface::~ONetworkInterface()" ); 316 qDebug( "ONetworkInterface::~ONetworkInterface()" );
316 if ( _sfd != -1 ) ::close( _sfd ); 317 if ( _sfd != -1 ) ::close( _sfd );
317} 318}
318 319
319 320
320bool ONetworkInterface::setPromiscuousMode( bool b ) 321bool ONetworkInterface::setPromiscuousMode( bool b )
321{ 322{
322 ioctl( SIOCGIFFLAGS ); 323 ioctl( SIOCGIFFLAGS );
323 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 324 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
324 else _ifr.ifr_flags &= (~IFF_PROMISC); 325 else _ifr.ifr_flags &= (~IFF_PROMISC);
325 return ioctl( SIOCSIFFLAGS ); 326 return ioctl( SIOCSIFFLAGS );
326} 327}
327 328
328 329
329bool ONetworkInterface::promiscuousMode() const 330bool ONetworkInterface::promiscuousMode() const
330{ 331{
331 ioctl( SIOCGIFFLAGS ); 332 ioctl( SIOCGIFFLAGS );
332 return _ifr.ifr_flags & IFF_PROMISC; 333 return _ifr.ifr_flags & IFF_PROMISC;
333} 334}
334 335
335 336
336bool ONetworkInterface::isWireless() const 337bool ONetworkInterface::isWireless() const
337{ 338{
338 return ioctl( SIOCGIWNAME ); 339 return ioctl( SIOCGIWNAME );
339} 340}
340 341
341 342
342/*====================================================================================== 343/*======================================================================================
343 * OChannelHopper 344 * OChannelHopper
344 *======================================================================================*/ 345 *======================================================================================*/
345 346
346OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 347OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
347 :QObject( 0, "Mickey's funky hopper" ), 348 :QObject( 0, "Mickey's funky hopper" ),
348 _iface( iface ), _interval( 0 ), _tid( 0 ) 349 _iface( iface ), _interval( 0 ), _tid( 0 )
349{ 350{
350 int _maxChannel = iface->channels()+1; 351 int _maxChannel = iface->channels()+1;
351 // generate fancy hopping sequence honoring the device capabilities 352 // generate fancy hopping sequence honoring the device capabilities
352 if ( _maxChannel >= 1 ) _channels.append( 1 ); 353 if ( _maxChannel >= 1 ) _channels.append( 1 );
353 if ( _maxChannel >= 7 ) _channels.append( 7 ); 354 if ( _maxChannel >= 7 ) _channels.append( 7 );
354 if ( _maxChannel >= 13 ) _channels.append( 13 ); 355 if ( _maxChannel >= 13 ) _channels.append( 13 );
355 if ( _maxChannel >= 2 ) _channels.append( 2 ); 356 if ( _maxChannel >= 2 ) _channels.append( 2 );
356 if ( _maxChannel >= 8 ) _channels.append( 8 ); 357 if ( _maxChannel >= 8 ) _channels.append( 8 );
357 if ( _maxChannel >= 3 ) _channels.append( 3 ); 358 if ( _maxChannel >= 3 ) _channels.append( 3 );
358 if ( _maxChannel >= 14 ) _channels.append( 14 ); 359 if ( _maxChannel >= 14 ) _channels.append( 14 );
359 if ( _maxChannel >= 9 ) _channels.append( 9 ); 360 if ( _maxChannel >= 9 ) _channels.append( 9 );
360 if ( _maxChannel >= 4 ) _channels.append( 4 ); 361 if ( _maxChannel >= 4 ) _channels.append( 4 );
361 if ( _maxChannel >= 10 ) _channels.append( 10 ); 362 if ( _maxChannel >= 10 ) _channels.append( 10 );
362 if ( _maxChannel >= 5 ) _channels.append( 5 ); 363 if ( _maxChannel >= 5 ) _channels.append( 5 );
363 if ( _maxChannel >= 11 ) _channels.append( 11 ); 364 if ( _maxChannel >= 11 ) _channels.append( 11 );
364 if ( _maxChannel >= 6 ) _channels.append( 6 ); 365 if ( _maxChannel >= 6 ) _channels.append( 6 );
365 if ( _maxChannel >= 12 ) _channels.append( 12 ); 366 if ( _maxChannel >= 12 ) _channels.append( 12 );
366 _channel = _channels.begin(); 367 _channel = _channels.begin();
367 368
368} 369}
369 370
370 371
371OChannelHopper::~OChannelHopper() 372OChannelHopper::~OChannelHopper()
372{ 373{
373} 374}
374 375
375 376
376bool OChannelHopper::isActive() const 377bool OChannelHopper::isActive() const
377{ 378{
378 return _tid; 379 return _tid;
379} 380}
380 381
381 382
382int OChannelHopper::channel() const 383int OChannelHopper::channel() const
383{ 384{
384 return *_channel; 385 return *_channel;
385} 386}
386 387
387 388
388void OChannelHopper::timerEvent( QTimerEvent* ) 389void OChannelHopper::timerEvent( QTimerEvent* )
389{ 390{
390 _iface->setChannel( *_channel ); 391 _iface->setChannel( *_channel );
391 emit( hopped( *_channel ) ); 392 emit( hopped( *_channel ) );
392 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", 393 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
393 *_channel, (const char*) _iface->name() ); 394 *_channel, (const char*) _iface->name() );
394 if ( ++_channel == _channels.end() ) _channel = _channels.begin(); 395 if ( ++_channel == _channels.end() ) _channel = _channels.begin();
395} 396}
396 397
397 398
398void OChannelHopper::setInterval( int interval ) 399void OChannelHopper::setInterval( int interval )
399{ 400{
400 if ( interval == _interval ) 401 if ( interval == _interval )
401 return; 402 return;
402 403
403 if ( _interval ) 404 if ( _interval )
404 killTimer( _tid ); 405 killTimer( _tid );
405 406
406 _tid = 0; 407 _tid = 0;
407 _interval = interval; 408 _interval = interval;
408 409
409 if ( _interval ) 410 if ( _interval )
410 { 411 {
411 _tid = startTimer( interval ); 412 _tid = startTimer( interval );
412 } 413 }
413} 414}
414 415
415 416
416int OChannelHopper::interval() const 417int OChannelHopper::interval() const
417{ 418{
418 return _interval; 419 return _interval;
419} 420}
420 421
421 422
422/*====================================================================================== 423/*======================================================================================
423 * OWirelessNetworkInterface 424 * OWirelessNetworkInterface
424 *======================================================================================*/ 425 *======================================================================================*/
425 426
426OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) 427OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name )
427 :ONetworkInterface( parent, name ), _hopper( 0 ) 428 :ONetworkInterface( parent, name ), _hopper( 0 )
428{ 429{
429 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 430 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
430 init(); 431 init();
431} 432}
432 433
433 434
434OWirelessNetworkInterface::~OWirelessNetworkInterface() 435OWirelessNetworkInterface::~OWirelessNetworkInterface()
435{ 436{
436} 437}
437 438
438 439
439struct iwreq& OWirelessNetworkInterface::iwr() const 440struct iwreq& OWirelessNetworkInterface::iwr() const
440{ 441{
441 return _iwr; 442 return _iwr;
442} 443}
443 444
444 445
445void OWirelessNetworkInterface::init() 446void OWirelessNetworkInterface::init()
446{ 447{
447 qDebug( "OWirelessNetworkInterface::init()" ); 448 qDebug( "OWirelessNetworkInterface::init()" );
448 memset( &_iwr, 0, sizeof( struct iwreq ) ); 449 memset( &_iwr, 0, sizeof( struct iwreq ) );
449 buildChannelList(); 450 buildChannelList();
450 buildPrivateList(); 451 buildPrivateList();
451} 452}
452 453
453 454
454QString OWirelessNetworkInterface::associatedAP() const 455QString OWirelessNetworkInterface::associatedAP() const
455{ 456{
456 //FIXME: use OMacAddress 457 //FIXME: use OMacAddress
457 QString mac; 458 QString mac;
458 459
459 if ( ioctl( SIOCGIWAP ) ) 460 if ( ioctl( SIOCGIWAP ) )
460 { 461 {
461 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 462 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
462 _ifr.ifr_hwaddr.sa_data[0]&0xff, 463 _ifr.ifr_hwaddr.sa_data[0]&0xff,
463 _ifr.ifr_hwaddr.sa_data[1]&0xff, 464 _ifr.ifr_hwaddr.sa_data[1]&0xff,
464 _ifr.ifr_hwaddr.sa_data[2]&0xff, 465 _ifr.ifr_hwaddr.sa_data[2]&0xff,
465 _ifr.ifr_hwaddr.sa_data[3]&0xff, 466 _ifr.ifr_hwaddr.sa_data[3]&0xff,
466 _ifr.ifr_hwaddr.sa_data[4]&0xff, 467 _ifr.ifr_hwaddr.sa_data[4]&0xff,
467 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 468 _ifr.ifr_hwaddr.sa_data[5]&0xff );
468 } 469 }
469 else 470 else
470 { 471 {
471 mac = "<Unknown>"; 472 mac = "<Unknown>";
472 } 473 }
473 return mac; 474 return mac;
474} 475}
475 476
476 477
477void OWirelessNetworkInterface::buildChannelList() 478void OWirelessNetworkInterface::buildChannelList()
478{ 479{
479 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 480 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
480 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 481 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
481 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 482 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
482 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 483 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
483 //ML: _too much_ space. This is damn shitty crap *sigh* 484 //ML: _too much_ space. This is damn shitty crap *sigh*
484 //ML: We allocate a large memory region in RAM and check whether the 485 //ML: We allocate a large memory region in RAM and check whether the
485 //ML: driver pollutes this extra space. The complaint will be made on stdout, 486 //ML: driver pollutes this extra space. The complaint will be made on stdout,
486 //ML: so please forward this... 487 //ML: so please forward this...
487 488
488 struct iwreq wrq; 489 struct iwreq wrq;
489 int len = sizeof( struct iw_range )*2; 490 int len = sizeof( struct iw_range )*2;
490 char *buffer = (char*) malloc( len ); 491 char *buffer = (char*) malloc( len );
491 //FIXME: Validate if we actually got the memory block 492 //FIXME: Validate if we actually got the memory block
492 memset( buffer, 0, len ); 493 memset( buffer, 0, len );
493 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 494 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
494 wrq.u.data.pointer = (caddr_t) buffer; 495 wrq.u.data.pointer = (caddr_t) buffer;
495 wrq.u.data.length = sizeof( struct iw_range ); 496 wrq.u.data.length = sizeof( struct iw_range );
496 wrq.u.data.flags = 0; 497 wrq.u.data.flags = 0;
497 498
498 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 499 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
499 { 500 {
500 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) ); 501 qDebug( "OWirelessNetworkInterface::buildChannelList(): SIOCGIWRANGE failed (%s) - defaulting to 11 channels", strerror( errno ) );
501 _channels.insert( 2412, 1 ); // 2.412 GHz 502 _channels.insert( 2412, 1 ); // 2.412 GHz
502 _channels.insert( 2417, 2 ); // 2.417 GHz 503 _channels.insert( 2417, 2 ); // 2.417 GHz
503 _channels.insert( 2422, 3 ); // 2.422 GHz 504 _channels.insert( 2422, 3 ); // 2.422 GHz
504 _channels.insert( 2427, 4 ); // 2.427 GHz 505 _channels.insert( 2427, 4 ); // 2.427 GHz
505 _channels.insert( 2432, 5 ); // 2.432 GHz 506 _channels.insert( 2432, 5 ); // 2.432 GHz
506 _channels.insert( 2437, 6 ); // 2.437 GHz 507 _channels.insert( 2437, 6 ); // 2.437 GHz
507 _channels.insert( 2442, 7 ); // 2.442 GHz 508 _channels.insert( 2442, 7 ); // 2.442 GHz
508 _channels.insert( 2447, 8 ); // 2.447 GHz 509 _channels.insert( 2447, 8 ); // 2.447 GHz
509 _channels.insert( 2452, 9 ); // 2.452 GHz 510 _channels.insert( 2452, 9 ); // 2.452 GHz
510 _channels.insert( 2457, 10 ); // 2.457 GHz 511 _channels.insert( 2457, 10 ); // 2.457 GHz
511 _channels.insert( 2462, 11 ); // 2.462 GHz 512 _channels.insert( 2462, 11 ); // 2.462 GHz
512 } 513 }
513 else 514 else
514 { 515 {
515 // <check if the driver overwrites stuff> 516 // <check if the driver overwrites stuff>
516 int max = 0; 517 int max = 0;
517 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 518 for ( int r = sizeof( struct iw_range ); r < len; r++ )
518 if (buffer[r] != 0) 519 if (buffer[r] != 0)
519 max = r; 520 max = r;
520 if (max > 0) 521 if (max > 0)
521 { 522 {
522 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'" 523 qWarning( "OWirelessNetworkInterface::buildChannelList(): Driver for wireless interface '%s'"
523 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) ); 524 "overwrote buffer end with at least %i bytes!\n", name(), max - sizeof( struct iw_range ) );
524 } 525 }
525 // </check if the driver overwrites stuff> 526 // </check if the driver overwrites stuff>
526 527
527 struct iw_range range; 528 struct iw_range range;
528 memcpy( &range, buffer, sizeof range ); 529 memcpy( &range, buffer, sizeof range );
529 530
530 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency ); 531 qDebug( "OWirelessNetworkInterface::buildChannelList(): Interface %s reported to have %d channels.", name(), range.num_frequency );
531 for ( int i = 0; i < range.num_frequency; ++i ) 532 for ( int i = 0; i < range.num_frequency; ++i )
532 { 533 {
533 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 534 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
534 _channels.insert( freq, i+1 ); 535 _channels.insert( freq, i+1 );
535 } 536 }
536 } 537 }
537 538
538 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." ); 539 qDebug( "OWirelessNetworkInterface::buildChannelList(): Channel list constructed." );
539 free(buffer); 540 free(buffer);
540} 541}
541 542
542 543
543void OWirelessNetworkInterface::buildPrivateList() 544void OWirelessNetworkInterface::buildPrivateList()
544{ 545{
545 qDebug( "OWirelessNetworkInterface::buildPrivateList()" ); 546 qDebug( "OWirelessNetworkInterface::buildPrivateList()" );
546 547
547 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 548 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
548 549
549 _iwr.u.data.pointer = (char*) &priv; 550 _iwr.u.data.pointer = (char*) &priv;
550 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 551 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
551 _iwr.u.data.flags = 0; 552 _iwr.u.data.flags = 0;
552 553
553 if ( !wioctl( SIOCGIWPRIV ) ) 554 if ( !wioctl( SIOCGIWPRIV ) )
554 { 555 {
555 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) ); 556 qDebug( "OWirelessNetworkInterface::buildPrivateList(): SIOCGIWPRIV failed (%s) - can't get private ioctl information.", strerror( errno ) );
556 return; 557 return;
557 } 558 }
558 559
559 for ( int i = 0; i < _iwr.u.data.length; ++i ) 560 for ( int i = 0; i < _iwr.u.data.length; ++i )
560 { 561 {
561 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 562 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
562 } 563 }
563 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." ); 564 qDebug( "OWirelessNetworkInterface::buildPrivateList(): Private IOCTL list constructed." );
564} 565}
565 566
566 567
567int OWirelessNetworkInterface::channel() const 568int OWirelessNetworkInterface::channel() const
568{ 569{
569 //FIXME: When monitoring enabled, then use it 570 //FIXME: When monitoring enabled, then use it
570 //FIXME: to gather the current RF channel 571 //FIXME: to gather the current RF channel
571 //FIXME: Until then, get active channel from hopper. 572 //FIXME: Until then, get active channel from hopper.
572 if ( _hopper && _hopper->isActive() ) 573 if ( _hopper && _hopper->isActive() )
573 return _hopper->channel(); 574 return _hopper->channel();
574 575
575 if ( !wioctl( SIOCGIWFREQ ) ) 576 if ( !wioctl( SIOCGIWFREQ ) )
576 { 577 {
577 return -1; 578 return -1;
578 } 579 }
579 else 580 else
580 { 581 {
581 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 582 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
582 } 583 }
583} 584}
584 585
585 586
586void OWirelessNetworkInterface::setChannel( int c ) const 587void OWirelessNetworkInterface::setChannel( int c ) const
587{ 588{
588 if ( !_mon ) 589 if ( !_mon )
589 { 590 {
590 memset( &_iwr, 0, sizeof( struct iwreq ) ); 591 memset( &_iwr, 0, sizeof( struct iwreq ) );
591 _iwr.u.freq.m = c; 592 _iwr.u.freq.m = c;
592 _iwr.u.freq.e = 0; 593 _iwr.u.freq.e = 0;
593 wioctl( SIOCSIWFREQ ); 594 wioctl( SIOCSIWFREQ );
594 } 595 }
595 else 596 else
596 { 597 {
597 _mon->setChannel( c ); 598 _mon->setChannel( c );
598 } 599 }
599} 600}
600 601
601 602
602double OWirelessNetworkInterface::frequency() const 603double OWirelessNetworkInterface::frequency() const
603{ 604{
604 if ( !wioctl( SIOCGIWFREQ ) ) 605 if ( !wioctl( SIOCGIWFREQ ) )
605 { 606 {
606 return -1.0; 607 return -1.0;
607 } 608 }
608 else 609 else
609 { 610 {
610 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 611 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
611 } 612 }
612} 613}
613 614
614 615
615int OWirelessNetworkInterface::channels() const 616int OWirelessNetworkInterface::channels() const
616{ 617{
617 return _channels.count(); 618 return _channels.count();
618} 619}
619 620
620 621
621void OWirelessNetworkInterface::setChannelHopping( int interval ) 622void OWirelessNetworkInterface::setChannelHopping( int interval )
622{ 623{
623 if ( !_hopper ) _hopper = new OChannelHopper( this ); 624 if ( !_hopper ) _hopper = new OChannelHopper( this );
624 _hopper->setInterval( interval ); 625 _hopper->setInterval( interval );
625 //FIXME: When and by whom will the channel hopper be deleted? 626 //FIXME: When and by whom will the channel hopper be deleted?
626 //TODO: rely on QObject hierarchy 627 //TODO: rely on QObject hierarchy
627} 628}
628 629
629 630
630int OWirelessNetworkInterface::channelHopping() const 631int OWirelessNetworkInterface::channelHopping() const
631{ 632{
632 return _hopper->interval(); 633 return _hopper->interval();
633} 634}
634 635
635 636
636OChannelHopper* OWirelessNetworkInterface::channelHopper() const 637OChannelHopper* OWirelessNetworkInterface::channelHopper() const
637{ 638{
638 return _hopper; 639 return _hopper;
639} 640}
640 641
641 642
643void OWirelessNetworkInterface::setMode( const QString& mode )
644{
645 if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO;
646 else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC;
647 else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA;
648 else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER;
649 else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT;
650 else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND;
651 #if WIRELESS_EXT > 14
652 else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR;
653 #endif
654 else
655 {
656 qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode );
657 return;
658 }
659 wioctl( SIOCSIWMODE );
660}
661
662
663QString OWirelessNetworkInterface::mode() const
664{
665 if ( !wioctl( SIOCGIWMODE ) )
666 {
667 return "<unknown>";
668 }
669 switch ( _iwr.u.mode )
670 {
671 case IW_MODE_AUTO: return "auto";
672 case IW_MODE_ADHOC: return "adhoc";
673 case IW_MODE_INFRA: return "managed";
674 case IW_MODE_MASTER: return "master";
675 case IW_MODE_REPEAT: return "repeater";
676 case IW_MODE_SECOND: return "secondary";
677 #if WIRELESS_EXT > 14
678 case IW_MODE_MONITOR: return "monitor";
679 #endif
680 default: assert( 0 ); // shouldn't happen
681 }
682}
683
684
642void OWirelessNetworkInterface::setMonitorMode( bool b ) 685void OWirelessNetworkInterface::setMonitorMode( bool b )
643{ 686{
644 if ( _mon ) 687 if ( _mon )
645 _mon->setEnabled( b ); 688 _mon->setEnabled( b );
646 else 689 else
647 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 690 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
648} 691}
649 692
650 693
651bool OWirelessNetworkInterface::monitorMode() const 694bool OWirelessNetworkInterface::monitorMode() const
652{ 695{
653 qDebug( "dataLinkType = %d", dataLinkType() ); 696 qDebug( "dataLinkType = %d", dataLinkType() );
654 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ); 697 return ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 );
655 // 802 is the header type for PRISM - Linux support for this is pending... 698 // 802 is the header type for PRISM - Linux support for this is pending...
656} 699}
657 700
658 701
702void OWirelessNetworkInterface::setNickName( const QString& nickname )
703{
704 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
705 _iwr.u.essid.length = nickname.length();
706 wioctl( SIOCSIWNICKN );
707}
708
709
659QString OWirelessNetworkInterface::nickName() const 710QString OWirelessNetworkInterface::nickName() const
660{ 711{
661 char str[IW_ESSID_MAX_SIZE]; 712 char str[IW_ESSID_MAX_SIZE];
662 _iwr.u.data.pointer = &str[0]; 713 _iwr.u.data.pointer = &str[0];
663 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 714 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
664 if ( !wioctl( SIOCGIWNICKN ) ) 715 if ( !wioctl( SIOCGIWNICKN ) )
665 { 716 {
666 return "<unknown>"; 717 return "<unknown>";
667 } 718 }
668 else 719 else
669 { 720 {
670 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 721 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
671 return str; 722 return str;
672 } 723 }
673} 724}
674 725
675 726
676void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 727void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
677{ 728{
678 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 729 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
679 if ( !priv ) 730 if ( !priv )
680 { 731 {
681 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call ); 732 qDebug( "OWirelessNetworkInterface::setPrivate(): interface '%s' does not support private ioctl '%s'", name(), (const char*) call );
682 return; 733 return;
683 } 734 }
684 if ( priv->numberSetArgs() != numargs ) 735 if ( priv->numberSetArgs() != numargs )
685 { 736 {
686 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs ); 737 qDebug( "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '%s' expects %d arguments, but got %d", (const char*) call, priv->numberSetArgs(), numargs );
687 return; 738 return;
688 } 739 }
689 740
690 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() ); 741 qDebug( "OWirelessNetworkInterface::setPrivate(): about to call '%s' on interface '%s'", (const char*) call, name() );
691 memset( &_iwr, 0, sizeof _iwr ); 742 memset( &_iwr, 0, sizeof _iwr );
692 va_list argp; 743 va_list argp;
693 va_start( argp, numargs ); 744 va_start( argp, numargs );
694 for ( int i = 0; i < numargs; ++i ) 745 for ( int i = 0; i < numargs; ++i )
695 { 746 {
696 priv->setParameter( i, va_arg( argp, int ) ); 747 priv->setParameter( i, va_arg( argp, int ) );
697 } 748 }
698 va_end( argp ); 749 va_end( argp );
699 priv->invoke(); 750 priv->invoke();
700} 751}
701 752
702 753
703void OWirelessNetworkInterface::getPrivate( const QString& call ) 754void OWirelessNetworkInterface::getPrivate( const QString& call )
704{ 755{
705 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." ); 756 qWarning( "OWirelessNetworkInterface::getPrivate() is not implemented yet." );
706} 757}
707 758
708 759
709bool OWirelessNetworkInterface::hasPrivate( const QString& call ) 760bool OWirelessNetworkInterface::hasPrivate( const QString& call )
710{ 761{
711 return child( (const char*) call ); 762 return child( (const char*) call );
712} 763}
713 764
714 765
715QString OWirelessNetworkInterface::SSID() const 766QString OWirelessNetworkInterface::SSID() const
716{ 767{
717 char str[IW_ESSID_MAX_SIZE]; 768 char str[IW_ESSID_MAX_SIZE];
718 _iwr.u.essid.pointer = &str[0]; 769 _iwr.u.essid.pointer = &str[0];
719 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 770 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
720 if ( !wioctl( SIOCGIWESSID ) ) 771 if ( !wioctl( SIOCGIWESSID ) )
721 { 772 {
722 return "<unknown>"; 773 return "<unknown>";
723 } 774 }
724 else 775 else
725 { 776 {
726 return str; 777 return str;
727 } 778 }
728} 779}
729 780
730 781
731void OWirelessNetworkInterface::setSSID( const QString& ssid ) 782void OWirelessNetworkInterface::setSSID( const QString& ssid )
732{ 783{
733 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 784 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
734 _iwr.u.essid.length = ssid.length(); 785 _iwr.u.essid.length = ssid.length();
735 wioctl( SIOCSIWESSID ); 786 wioctl( SIOCSIWESSID );
736} 787}
737 788
738 789
739bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 790bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
740{ 791{
741 int result = ::ioctl( _sfd, call, &iwreq ); 792 int result = ::ioctl( _sfd, call, &iwreq );
742 if ( result == -1 ) 793 if ( result == -1 )
743 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) ); 794 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Failed: %d (%s)", name(), call, result, strerror( errno ) );
744 else 795 else
745 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call ); 796 qDebug( "ONetworkInterface::wioctl (%s) call %d - Status: Ok.", name(), call );
746 return ( result != -1 ); 797 return ( result != -1 );
747} 798}
748 799
749 800
750bool OWirelessNetworkInterface::wioctl( int call ) const 801bool OWirelessNetworkInterface::wioctl( int call ) const
751{ 802{
752 strcpy( _iwr.ifr_name, name() ); 803 strcpy( _iwr.ifr_name, name() );
753 return wioctl( call, _iwr ); 804 return wioctl( call, _iwr );
754} 805}
755 806
756 807
757/*====================================================================================== 808/*======================================================================================
758 * OMonitoringInterface 809 * OMonitoringInterface
759 *======================================================================================*/ 810 *======================================================================================*/
760 811
761OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface ) 812OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface )
762 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ) 813 :_if( static_cast<OWirelessNetworkInterface*>( iface ) )
763{ 814{
764} 815}
765 816
766 817
767OMonitoringInterface::~OMonitoringInterface() 818OMonitoringInterface::~OMonitoringInterface()
768{ 819{
769} 820}
770 821
771 822
772void OMonitoringInterface::setChannel( int c ) 823void OMonitoringInterface::setChannel( int c )
773{ 824{
774 // use standard WE channel switching protocol 825 // use standard WE channel switching protocol
775 memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); 826 memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
776 _if->_iwr.u.freq.m = c; 827 _if->_iwr.u.freq.m = c;
777 _if->_iwr.u.freq.e = 0; 828 _if->_iwr.u.freq.e = 0;
778 _if->wioctl( SIOCSIWFREQ ); 829 _if->wioctl( SIOCSIWFREQ );
779} 830}
780 831
781 832
782bool OMonitoringInterface::enabled() const 833bool OMonitoringInterface::enabled() const
783{ 834{
784 return _if->monitorMode(); 835 return _if->monitorMode();
785} 836}
786 837
787 838
788void OMonitoringInterface::setEnabled( bool b ) 839void OMonitoringInterface::setEnabled( bool b )
789{ 840{
790} 841}
791 842
792 843
793/*====================================================================================== 844/*======================================================================================
794 * OCiscoMonitoringInterface 845 * OCiscoMonitoringInterface
795 *======================================================================================*/ 846 *======================================================================================*/
796 847
797OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface ) 848OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface )
798 :OMonitoringInterface( iface ) 849 :OMonitoringInterface( iface )
799{ 850{
800 iface->setMonitoring( this ); 851 iface->setMonitoring( this );
801} 852}
802 853
803 854
804OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 855OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
805{ 856{
806} 857}
807 858
808 859
809void OCiscoMonitoringInterface::setEnabled( bool b ) 860void OCiscoMonitoringInterface::setEnabled( bool b )
810{ 861{
811 QString fname; 862 QString fname;
812 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 863 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
813 QFile f( fname ); 864 QFile f( fname );
814 if ( !f.exists() ) return; 865 if ( !f.exists() ) return;
815 866
816 if ( f.open( IO_WriteOnly ) ) 867 if ( f.open( IO_WriteOnly ) )
817 { 868 {
818 QTextStream s( &f ); 869 QTextStream s( &f );
819 s << "Mode: r"; 870 s << "Mode: r";
820 s << "Mode: y"; 871 s << "Mode: y";
821 s << "XmitPower: 1"; 872 s << "XmitPower: 1";
822 } 873 }
823 874
824 // flushing and closing will be done automatically when f goes out of scope 875 // flushing and closing will be done automatically when f goes out of scope
825} 876}
826 877
827 878
828QString OCiscoMonitoringInterface::name() const 879QString OCiscoMonitoringInterface::name() const
829{ 880{
830 return "cisco"; 881 return "cisco";
831} 882}
832 883
833 884
834void OCiscoMonitoringInterface::setChannel( int ) 885void OCiscoMonitoringInterface::setChannel( int )
835{ 886{
836 // cisco devices automatically switch channels when in monitor mode 887 // cisco devices automatically switch channels when in monitor mode
837} 888}
838 889
839 890
840/*====================================================================================== 891/*======================================================================================
841 * OWlanNGMonitoringInterface 892 * OWlanNGMonitoringInterface
842 *======================================================================================*/ 893 *======================================================================================*/
843 894
844 895
845OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface ) 896OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface )
846 :OMonitoringInterface( iface ) 897 :OMonitoringInterface( iface )
847{ 898{
848 iface->setMonitoring( this ); 899 iface->setMonitoring( this );
849} 900}
850 901
851 902
852OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 903OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
853{ 904{
854} 905}
855 906
856 907
857void OWlanNGMonitoringInterface::setEnabled( bool b ) 908void OWlanNGMonitoringInterface::setEnabled( bool b )
858{ 909{
859 //FIXME: do nothing if its already in the same mode 910 //FIXME: do nothing if its already in the same mode
860 911
861 QString enable = b ? "true" : "false"; 912 QString enable = b ? "true" : "false";
862 QString cmd; 913 QString cmd;
863 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable ); 914 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s", (const char*) _if->name(), 1, (const char*) enable );
864 system( cmd ); 915 system( cmd );
865} 916}
866 917
867 918
868QString OWlanNGMonitoringInterface::name() const 919QString OWlanNGMonitoringInterface::name() const
869{ 920{
870 return "wlan-ng"; 921 return "wlan-ng";
871} 922}
872 923
873 924
874void OWlanNGMonitoringInterface::setChannel( int ) 925void OWlanNGMonitoringInterface::setChannel( int )
875{ 926{
876 // wlan-ng devices automatically switch channels when in monitor mode 927 // wlan-ng devices automatically switch channels when in monitor mode
877} 928}
878 929
879 930
880/*====================================================================================== 931/*======================================================================================
881 * OHostAPMonitoringInterface 932 * OHostAPMonitoringInterface
882 *======================================================================================*/ 933 *======================================================================================*/
883 934
884OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface ) 935OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface )
885 :OMonitoringInterface( iface ) 936 :OMonitoringInterface( iface )
886{ 937{
887 iface->setMonitoring( this ); 938 iface->setMonitoring( this );
888} 939}
889 940
890OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 941OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
891{ 942{
892} 943}
893 944
894void OHostAPMonitoringInterface::setEnabled( bool b ) 945void OHostAPMonitoringInterface::setEnabled( bool b )
895{ 946{
896 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15 947 // IW_MODE_MONITOR was introduced in Wireless Extensions Version 15
897 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring 948 // Wireless Extensions < Version 15 need iwpriv commandos for monitoring
898 949
899 //TODO: check wireless extensions version on runtime and use 950 //TODO: check wireless extensions version on runtime and use
900 //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15 951 //TODO: SIOCSIWMODE( IW_MODE_MONITOR ) if running on WE >= 15
901 952
902 if ( b ) 953 if ( b )
903 { 954 {
904 _if->setPrivate( "monitor", 1, 2 ); 955 _if->setPrivate( "monitor", 1, 2 );
905 } 956 }
906 else 957 else
907 { 958 {
908 _if->setPrivate( "monitor", 1, 0 ); 959 _if->setPrivate( "monitor", 1, 0 );
909 } 960 }
910} 961}
911 962
912 963
913QString OHostAPMonitoringInterface::name() const 964QString OHostAPMonitoringInterface::name() const
914{ 965{
915 return "hostap"; 966 return "hostap";
916} 967}
917 968
918 969
919/*====================================================================================== 970/*======================================================================================
920 * OOrinocoNetworkInterface 971 * OOrinocoNetworkInterface
921 *======================================================================================*/ 972 *======================================================================================*/
922 973
923OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface ) 974OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface )
924 :OMonitoringInterface( iface ) 975 :OMonitoringInterface( iface )
925{ 976{
926 iface->setMonitoring( this ); 977 iface->setMonitoring( this );
927} 978}
928 979
929 980
930OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 981OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
931{ 982{
932} 983}
933 984
934 985
935void OOrinocoMonitoringInterface::setChannel( int c ) 986void OOrinocoMonitoringInterface::setChannel( int c )
936{ 987{
937 _if->setPrivate( "monitor", 2, 1, c ); 988 _if->setPrivate( "monitor", 2, 1, c );
938} 989}
939 990
940 991
941void OOrinocoMonitoringInterface::setEnabled( bool b ) 992void OOrinocoMonitoringInterface::setEnabled( bool b )
942{ 993{
943 if ( b ) 994 if ( b )
944 { 995 {
945 setChannel( 1 ); 996 setChannel( 1 );
946 } 997 }
947 else 998 else
948 { 999 {
949 _if->setPrivate( "monitor", 2, 0, 0 ); 1000 _if->setPrivate( "monitor", 2, 0, 0 );
950 } 1001 }
951} 1002}
952 1003
953 1004
954QString OOrinocoMonitoringInterface::name() const 1005QString OOrinocoMonitoringInterface::name() const
955{ 1006{
956 return "orinoco"; 1007 return "orinoco";
957} 1008}
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index f052317..a29b29d 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -1,517 +1,533 @@
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/* OPIE */
38
39#include <opie2/onetutils.h>
40
37/* QT */ 41/* QT */
38 42
39#include <qvaluelist.h> 43#include <qvaluelist.h>
40#include <qdict.h> 44#include <qdict.h>
41#include <qmap.h> 45#include <qmap.h>
42#include <qobject.h> 46#include <qobject.h>
43#include <qhostaddress.h> 47#include <qhostaddress.h>
44 48
45/* OPIE */
46
47#include <opie2/onetutils.h>
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 need a user header for the Wireless Extensions, something like <net/wireless.h> 59// ML: We really need a user header for the Wireless Extensions, something like <net/wireless.h>
60// ML: I will drop Jean a mail on that subject 60// ML: I will drop Jean a 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
66class ONetworkInterface; 66class ONetworkInterface;
67class OWirelessNetworkInterface; 67class OWirelessNetworkInterface;
68class OChannelHopper; 68class OChannelHopper;
69class OMonitoringInterface; 69class OMonitoringInterface;
70 70
71/*====================================================================================== 71/*======================================================================================
72 * ONetwork 72 * ONetwork
73 *======================================================================================*/ 73 *======================================================================================*/
74 74
75/** 75/**
76 * @brief A container class for all network interfaces 76 * @brief A container class for all network interfaces
77 * 77 *
78 * This class provides access to all available network interfaces of your computer. 78 * This class provides access to all available network interfaces of your computer.
79 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 79 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
80 */ 80 */
81class ONetwork : public QObject 81class ONetwork : public QObject
82{ 82{
83 Q_OBJECT 83 Q_OBJECT
84 84
85 public: 85 public:
86 typedef QDict<ONetworkInterface> InterfaceMap; 86 typedef QDict<ONetworkInterface> InterfaceMap;
87 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 87 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
88 88
89 public: 89 public:
90 /** 90 /**
91 * @returns the number of available interfaces 91 * @returns the number of available interfaces
92 */ 92 */
93 int count() const; 93 int count() const;
94 /** 94 /**
95 * @returns a pointer to the (one and only) @ref ONetwork instance. 95 * @returns a pointer to the (one and only) @ref ONetwork instance.
96 */ 96 */
97 static ONetwork* instance(); 97 static ONetwork* instance();
98 /** 98 /**
99 * @returns an iterator usable for iterating through all network interfaces. 99 * @returns an iterator usable for iterating through all network interfaces.
100 */ 100 */
101 InterfaceIterator iterator() const; 101 InterfaceIterator iterator() const;
102 /** 102 /**
103 * @returns true, if the @p interface supports the wireless extension protocol. 103 * @returns true, if the @a interface supports the wireless extension protocol.
104 */ 104 */
105 // FIXME QString? -zecke 105 // FIXME QString? -zecke
106 bool isWirelessInterface( const char* interface ) const; 106 bool isWirelessInterface( const char* interface ) const;
107 /** 107 /**
108 * @returns a pointer to the @ref ONetworkInterface object for the specified @p interface or 0, if not found 108 * @returns a pointer to the @ref ONetworkInterface object for the specified @a interface or 0, if not found
109 * @see ONetworkInterface 109 * @see ONetworkInterface
110 */ 110 */
111 // FIXME: const QString& is prefered over QString!!! -zecke 111 // FIXME: const QString& is prefered over QString!!! -zecke
112 ONetworkInterface* interface( const QString& interface ) const; 112 ONetworkInterface* interface( const QString& interface ) const;
113 /** 113 /**
114 * @internal Rebuild the internal interface database 114 * @internal Rebuild the internal interface database
115 * @note Sometimes it might be useful to call this from client code, 115 * @note Sometimes it might be useful to call this from client code,
116 * e.g. after issuing a cardctl insert 116 * e.g. after issuing a cardctl insert
117 */ 117 */
118 void synchronize(); 118 void synchronize();
119 119
120 protected: 120 protected:
121 ONetwork(); 121 ONetwork();
122 122
123 private: 123 private:
124 static ONetwork* _instance; 124 static ONetwork* _instance;
125 InterfaceMap _interfaces; 125 InterfaceMap _interfaces;
126}; 126};
127 127
128 128
129/*====================================================================================== 129/*======================================================================================
130 * ONetworkInterface 130 * ONetworkInterface
131 *======================================================================================*/ 131 *======================================================================================*/
132 132
133/** 133/**
134 * @brief A network interface wrapper. 134 * @brief A network interface wrapper.
135 * 135 *
136 * This class provides a wrapper for a network interface. All the cumbersume details of 136 * This class provides a wrapper for a network interface. All the cumbersume details of
137 * Linux ioctls are hidden under a convenient high-level interface. 137 * Linux ioctls are hidden under a convenient high-level interface.
138 * @warning Most of the setting methods contained in this class require the appropriate 138 * @warning Most of the setting methods contained in this class require the appropriate
139 * process permissions to work. 139 * process permissions to work.
140 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 140 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
141 */ 141 */
142class ONetworkInterface : public QObject 142class ONetworkInterface : public QObject
143{ 143{
144 friend class OMonitoringInterface; 144 friend class OMonitoringInterface;
145 friend class OCiscoMonitoringInterface; 145 friend class OCiscoMonitoringInterface;
146 friend class OWlanNGMonitoringInterface; 146 friend class OWlanNGMonitoringInterface;
147 friend class OHostAPMonitoringInterface; 147 friend class OHostAPMonitoringInterface;
148 friend class OOrinocoMonitoringInterface; 148 friend class OOrinocoMonitoringInterface;
149 149
150 public: 150 public:
151 /** 151 /**
152 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself, 152 * Constructor. Normally you don't create @ref ONetworkInterface objects yourself,
153 * but access them via @ref ONetwork::interface(). 153 * but access them via @ref ONetwork::interface().
154 */ 154 */
155 ONetworkInterface( QObject* parent, const char* name ); 155 ONetworkInterface( QObject* parent, const char* name );
156 /** 156 /**
157 * Destructor. 157 * Destructor.
158 */ 158 */
159 virtual ~ONetworkInterface(); 159 virtual ~ONetworkInterface();
160 /** 160 /**
161 * Associates a @a monitoring interface with this network interface. 161 * Associates a @a monitoring interface with this network interface.
162 * @note This is currently only useful with @ref OWirelessNetworkInterface objects. 162 * @note This is currently only useful with @ref OWirelessNetworkInterface objects.
163 */ 163 */
164 void setMonitoring( OMonitoringInterface* monitoring ); 164 void setMonitoring( OMonitoringInterface* monitoring );
165 /** 165 /**
166 * @returns the currently associated monitoring interface or 0, if no monitoring is associated. 166 * @returns the currently associated monitoring interface or 0, if no monitoring is associated.
167 */ 167 */
168 OMonitoringInterface* monitoring() const; 168 OMonitoringInterface* monitoring() const;
169 /** 169 /**
170 * Setting an interface to promiscuous mode enables the device to receive 170 * Setting an interface to promiscuous mode enables the device to receive
171 * all packets on the shared medium - as opposed to packets which are addressed to this interface. 171 * all packets on the shared medium - as opposed to packets which are addressed to this interface.
172 */ 172 */
173 bool setPromiscuousMode( bool ); 173 bool setPromiscuousMode( bool );
174 /** 174 /**
175 * @returns true if the interface is set to promiscuous mode. 175 * @returns true if the interface is set to promiscuous mode.
176 */ 176 */
177 bool promiscuousMode() const; 177 bool promiscuousMode() const;
178 /** 178 /**
179 * Setting an interface to up enables it to receive packets. 179 * Setting an interface to up enables it to receive packets.
180 */ 180 */
181 bool setUp( bool ); 181 bool setUp( bool );
182 /** 182 /**
183 * @returns true if the interface is up. 183 * @returns true if the interface is up.
184 */ 184 */
185 bool isUp() const; 185 bool isUp() const;
186 /** 186 /**
187 * @returns true if the interface is a loopback interface. 187 * @returns true if the interface is a loopback interface.
188 */ 188 */
189 bool isLoopback() const; 189 bool isLoopback() const;
190 /** 190 /**
191 * @returns true if the interface is featuring supports the wireless extension protocol. 191 * @returns true if the interface is featuring supports the wireless extension protocol.
192 */ 192 */
193 bool isWireless() const; 193 bool isWireless() const;
194 /** 194 /**
195 * Associate the IP address @ addr with the interface. 195 * Associate the IP address @ addr with the interface.
196 */ 196 */
197 void setIPV4Address( const QHostAddress& addr ); 197 void setIPV4Address( const QHostAddress& addr );
198 /** 198 /**
199 * @returns the IPv4 address associated with the interface. 199 * @returns the IPv4 address associated with the interface.
200 */ 200 */
201 QString ipV4Address() const; 201 QString ipV4Address() const; //TODO: make this return an OHostAddress
202 /** 202 /**
203 * Associate the MAC address @a addr with the interface. 203 * Associate the MAC address @a addr with the interface.
204 * @note It can be necessary to shut down the interface prior to calling this method. 204 * @note It can be necessary to shut down the interface prior to calling this method.
205 * @warning This is not supported by all drivers. 205 * @warning This is not supported by all drivers.
206 */ 206 */
207 void setMacAddress( const OMacAddress& addr ); 207 void setMacAddress( const OMacAddress& addr );
208 /** 208 /**
209 * @returns the MAC address associated with the interface. 209 * @returns the MAC address associated with the interface.
210 */ 210 */
211 OMacAddress macAddress() const; 211 OMacAddress macAddress() const;
212 /** 212 /**
213 * Associate the IPv4 @a netmask with the interface. 213 * Associate the IPv4 @a netmask with the interface.
214 */ 214 */
215 void setIPV4Netmask( const QHostAddress& netmask ); 215 void setIPV4Netmask( const QHostAddress& netmask );
216 /** 216 /**
217 * @returns the IPv4 netmask associated with the interface. 217 * @returns the IPv4 netmask associated with the interface.
218 */ 218 */
219 QString ipV4Netmask() const; 219 QString ipV4Netmask() const; //TODO: make this return an OHostAddress
220 /** 220 /**
221 * @returns the data link type currently associated with the interface. 221 * @returns the data link type currently associated with the interface.
222 * @see #include <net/if_arp.h> for possible values. 222 * @see #include <net/if_arp.h> for possible values.
223 */ 223 */
224 int dataLinkType() const; 224 int dataLinkType() const;
225 225
226 protected: 226 protected:
227 const int _sfd; 227 const int _sfd;
228 mutable ifreq _ifr; 228 mutable ifreq _ifr;
229 OMonitoringInterface* _mon; 229 OMonitoringInterface* _mon;
230 230
231 protected: 231 protected:
232 struct ifreq& ifr() const; 232 struct ifreq& ifr() const;
233 virtual void init(); 233 virtual void init();
234 bool ioctl( int call ) const; 234 bool ioctl( int call ) const;
235 bool ioctl( int call, struct ifreq& ) const; 235 bool ioctl( int call, struct ifreq& ) const;
236}; 236};
237 237
238/*====================================================================================== 238/*======================================================================================
239 * OChannelHopper 239 * OChannelHopper
240 *======================================================================================*/ 240 *======================================================================================*/
241 241
242/** 242/**
243 * @brief A radio frequency channel hopper. 243 * @brief A radio frequency channel hopper.
244 * 244 *
245 * This class provides a channel hopper for radio frequencies. A channel hopper frequently 245 * This class provides a channel hopper for radio frequencies. A channel hopper frequently
246 * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface. 246 * changes the radio frequency channel of its associated @ref OWirelessNetworkInterface.
247 * This is necessary when in monitoring mode and scanning for other devices, because 247 * This is necessary when in monitoring mode and scanning for other devices, because
248 * the radio frequency hardware can only detect packets sent on the same frequency. 248 * the radio frequency hardware can only detect packets sent on the same frequency.
249 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 249 * @author Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
250 */ 250 */
251class OChannelHopper : public QObject 251class OChannelHopper : public QObject
252{ 252{
253 Q_OBJECT 253 Q_OBJECT
254 254
255 public: 255 public:
256 /** 256 /**
257 * Constructor. 257 * Constructor.
258 */ 258 */
259 OChannelHopper( OWirelessNetworkInterface* ); 259 OChannelHopper( OWirelessNetworkInterface* );
260 /** 260 /**
261 * Destructor. 261 * Destructor.
262 */ 262 */
263 virtual ~OChannelHopper(); 263 virtual ~OChannelHopper();
264 /** 264 /**
265 * @returns true, if the channel hopper is hopping channels 265 * @returns true, if the channel hopper is hopping channels
266 */ 266 */
267 bool isActive() const; 267 bool isActive() const;
268 /** 268 /**
269 * @returns the last hopped channel 269 * @returns the last hopped channel
270 */ 270 */
271 int channel() const; 271 int channel() const;
272 /** 272 /**
273 * Set the channel hopping @a interval. 273 * Set the channel hopping @a interval.
274 * An interval of 0 deactivates the channel hopper. 274 * An interval of 0 deactivates the channel hopper.
275 */ 275 */
276 void setInterval( int interval ); 276 void setInterval( int interval );
277 /** 277 /**
278 * @returns the channel hopping interval 278 * @returns the channel hopping interval
279 */ 279 */
280 int interval() const; 280 int interval() const;
281 281
282 signals: 282 signals:
283 /** 283 /**
284 * This signal is emitted right after the channel hopper performed a hop 284 * This signal is emitted right after the channel hopper performed a hop
285 */ 285 */
286 void hopped( int ); 286 void hopped( int );
287 287
288 protected: 288 protected:
289 virtual void timerEvent( QTimerEvent* ); 289 virtual void timerEvent( QTimerEvent* );
290 290
291 private: 291 private:
292 OWirelessNetworkInterface* _iface; 292 OWirelessNetworkInterface* _iface;
293 int _interval; 293 int _interval;
294 int _tid; 294 int _tid;
295 QValueList<int> _channels; 295 QValueList<int> _channels;
296 QValueList<int>::Iterator _channel; 296 QValueList<int>::Iterator _channel;
297}; 297};
298 298
299 299
300/*====================================================================================== 300/*======================================================================================
301 * OWirelessNetworkInterface 301 * OWirelessNetworkInterface
302 *======================================================================================*/ 302 *======================================================================================*/
303 303
304/** 304/**
305 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol. 305 * @brief A network interface wrapper for interfaces supporting the wireless extensions protocol.
306 * 306 *
307 * This class provides a high-level encapsulation of the Linux wireless extension API. 307 * This class provides a high-level encapsulation of the Linux wireless extension API.
308 */ 308 */
309class OWirelessNetworkInterface : public ONetworkInterface 309class OWirelessNetworkInterface : public ONetworkInterface
310{ 310{
311 friend class OMonitoringInterface; 311 friend class OMonitoringInterface;
312 friend class OCiscoMonitoringInterface; 312 friend class OCiscoMonitoringInterface;
313 friend class OWlanNGMonitoringInterface; 313 friend class OWlanNGMonitoringInterface;
314 friend class OHostAPMonitoringInterface; 314 friend class OHostAPMonitoringInterface;
315 friend class OOrinocoMonitoringInterface; 315 friend class OOrinocoMonitoringInterface;
316 316
317 friend class OPrivateIOCTL; 317 friend class OPrivateIOCTL;
318 318
319 public: 319 public:
320 enum Mode { AdHoc, Managed, Monitor };
321
322 /** 320 /**
323 * Constructor. 321 * Constructor.
324 */ 322 */
325 OWirelessNetworkInterface( QObject* parent, const char* name ); 323 OWirelessNetworkInterface( QObject* parent, const char* name );
326 /** 324 /**
327 * Destructor. 325 * Destructor.
328 */ 326 */
329 virtual ~OWirelessNetworkInterface(); 327 virtual ~OWirelessNetworkInterface();
330 /** 328 /**
331 * Setting the @a channel of the interface changes the radio frequency (RF) 329 * Setting the @a channel of the interface changes the radio frequency (RF)
332 * of the corresponding wireless network device. 330 * of the corresponding wireless network device.
333 */ 331 */
334 virtual void setChannel( int channel ) const; 332 virtual void setChannel( int channel ) const;
335 /** 333 /**
336 * @returns the channel index of the current radio frequency. 334 * @returns the channel index of the current radio frequency.
337 */ 335 */
338 virtual int channel() const; 336 virtual int channel() const;
339 /** 337 /**
340 * @returns the current radio frequency (in MHz). 338 * @returns the current radio frequency (in MHz).
341 */ 339 */
342 virtual double frequency() const; 340 virtual double frequency() const;
343 /** 341 /**
344 * @returns the number of radio frequency channels for the 342 * @returns the number of radio frequency channels for the
345 * corresponding wireless network device. 343 * corresponding wireless network device.
346 * @note European devices usually have 14 channels, while American typically feature 11 channels. 344 * @note European devices usually have 14 channels, while American typically feature 11 channels.
347 */ 345 */
348 virtual int channels() const; 346 virtual int channels() const;
349 //virtual double frequency(int) const; 347 /**
350 348 * Set the IEEE 802.11 operation @a mode.
351 virtual void setMode( Mode ) {}; //FIXME: Implement and document this 349 * Valid values are <ul><li>adhoc<li>managed<li>monitor<li>master
352 virtual bool mode() const {}; //FIXME: Implement and document this 350 * @warning Not all drivers support the all modes.
353 351 * @note You might have to change the SSID to get the operation mode change into effect.
352 */
353 virtual void setMode( const QString& mode );
354 /**
355 * @returns the current IEEE 802.11 operation mode.
356 * Possible values are <ul><li>adhoc<li>managed<li>monitor<li>master or <li>unknown
357 */
358 virtual QString mode() const;
354 /** 359 /**
355 * Setting the monitor mode on a wireless network interface enables 360 * Setting the monitor mode on a wireless network interface enables
356 * listening to IEEE 802.11 data and management frames which normally 361 * listening to IEEE 802.11 data and management frames which normally
357 * are handled by the device firmware. This can be used to detect 362 * are handled by the device firmware. This can be used to detect
358 * other wireless network devices, e.g. Access Points or Ad-hoc stations. 363 * other wireless network devices, e.g. Access Points or Ad-hoc stations.
359 * @warning Standard wireless network drives don't support the monitor mode. 364 * @warning Standard wireless network drives don't support the monitor mode.
360 * @warning You need a patched driver for this to work. 365 * @warning You need a patched driver for this to work.
361 * @note Enabling the monitor mode is highly driver dependent and requires 366 * @note Enabling the monitor mode is highly driver dependent and requires
362 * the proper @ref OMonitoringInterface to be associated with the interface. 367 * the proper @ref OMonitoringInterface to be associated with the interface.
363 * @see OMonitoringInterface 368 * @see OMonitoringInterface
364 */ 369 */
365 virtual void setMonitorMode( bool ); 370 virtual void setMonitorMode( bool ); //FIXME: ==> setMode( "monitor" );
366 /** 371 /**
367 * @returns true if the device is listening in IEEE 802.11 monitor mode 372 * @returns true if the device is listening in IEEE 802.11 monitor mode
368 */ 373 */
369 virtual bool monitorMode() const; 374 virtual bool monitorMode() const; //FIXME: ==> mode()
370 /** 375 /**
371 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping. 376 * Set the channel hopping @a interval. An @a interval of 0 disables channel hopping.
372 * @see OChannelHopper 377 * @see OChannelHopper
373 */ 378 */
374 virtual void setChannelHopping( int interval = 0 ); 379 virtual void setChannelHopping( int interval = 0 );
375 /** 380 /**
376 * @returns the channel hopping interval or 0, if channel hopping is disabled. 381 * @returns the channel hopping interval or 0, if channel hopping is disabled.
377 */ 382 */
378 virtual int channelHopping() const; 383 virtual int channelHopping() const;
379 /** 384 /**
380 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before 385 * @returns the @ref OChannelHopper of this interface or 0, if channel hopping has not been activated before
381 */ 386 */
382 virtual OChannelHopper* channelHopper() const; 387 virtual OChannelHopper* channelHopper() const;
383 /** 388 /**
384 * Set the station @a nickname. 389 * Set the station @a nickname.
385 */ 390 */
386 virtual void setNickName( const QString& nickname ) {}; //FIXME: Implement this 391 virtual void setNickName( const QString& nickname );
387 /** 392 /**
388 * @returns the current station nickname. 393 * @returns the current station nickname.
389 */ 394 */
390 virtual QString nickName() const; 395 virtual QString nickName() const;
391 /** 396 /**
392 * Invoke the private IOCTL @a command with a @number of parameters on the network interface. 397 * Invoke the private IOCTL @a command with a @number of parameters on the network interface.
393 * @see OPrivateIOCTL 398 * @see OPrivateIOCTL
394 */ 399 */
395 virtual void setPrivate( const QString& command, int number, ... ); 400 virtual void setPrivate( const QString& command, int number, ... );
396 /** 401 /**
397 * @returns true if the interface is featuring the private IOCTL @command. 402 * @returns true if the interface is featuring the private IOCTL @command.
398 */ 403 */
399 virtual bool hasPrivate( const QString& command ); 404 virtual bool hasPrivate( const QString& command );
400 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this 405 virtual void getPrivate( const QString& command ); //FIXME: Implement and document this
401 406
402 virtual bool isAssociated() const {}; //FIXME: Implement and document this 407 virtual bool isAssociated() const {}; //FIXME: Implement and document this
403 virtual QString associatedAP() const; //FIXME: Implement and document this 408 /**
404 409 * @returns the MAC address of the Access Point if the
405 virtual void setSSID( const QString& ); 410 * device is in infrastructure mode. @returns a (more or less random) CELL
411 * address if the device is in adhoc mode.
412 */
413 virtual QString associatedAP() const;
414 /**
415 * Set the @a ssid (Service Set ID) string. This is used to decide
416 * which network to associate with (use "any" to let the driver decide).
417 */
418 virtual void setSSID( const QString& ssid );
419 /**
420 * @returns the current SSID (Service Set ID).
421 */
406 virtual QString SSID() const; 422 virtual QString SSID() const;
407 423
408 protected: 424 protected:
409 void buildChannelList(); 425 void buildChannelList();
410 void buildPrivateList(); 426 void buildPrivateList();
411 virtual void init(); 427 virtual void init();
412 struct iwreq& iwr() const; 428 struct iwreq& iwr() const;
413 bool wioctl( int call ) const; 429 bool wioctl( int call ) const;
414 bool wioctl( int call, struct iwreq& ) const; 430 bool wioctl( int call, struct iwreq& ) const;
415 431
416 protected: 432 protected:
417 mutable struct iwreq _iwr; 433 mutable struct iwreq _iwr;
418 QMap<int,int> _channels; 434 QMap<int,int> _channels;
419 435
420 private: 436 private:
421 OChannelHopper* _hopper; 437 OChannelHopper* _hopper;
422}; 438};
423 439
424 440
425/*====================================================================================== 441/*======================================================================================
426 * OMonitoringInterface 442 * OMonitoringInterface
427 *======================================================================================*/ 443 *======================================================================================*/
428 444
429 445
430class OMonitoringInterface 446class OMonitoringInterface
431{ 447{
432 public: 448 public:
433 OMonitoringInterface(); 449 OMonitoringInterface();
434 OMonitoringInterface( ONetworkInterface* ); 450 OMonitoringInterface( ONetworkInterface* );
435 virtual ~OMonitoringInterface(); 451 virtual ~OMonitoringInterface();
436 452
437 public: 453 public:
438 virtual void setEnabled( bool ); 454 virtual void setEnabled( bool );
439 virtual bool enabled() const; 455 virtual bool enabled() const;
440 virtual void setChannel( int ); 456 virtual void setChannel( int );
441 457
442 virtual QString name() const = 0; 458 virtual QString name() const = 0;
443 459
444 protected: 460 protected:
445 OWirelessNetworkInterface* _if; 461 OWirelessNetworkInterface* _if;
446 462
447}; 463};
448 464
449 465
450/*====================================================================================== 466/*======================================================================================
451 * OCiscoMonitoring 467 * OCiscoMonitoring
452 *======================================================================================*/ 468 *======================================================================================*/
453 469
454 470
455class OCiscoMonitoringInterface : public OMonitoringInterface 471class OCiscoMonitoringInterface : public OMonitoringInterface
456{ 472{
457 public: 473 public:
458 OCiscoMonitoringInterface( ONetworkInterface* ); 474 OCiscoMonitoringInterface( ONetworkInterface* );
459 virtual ~OCiscoMonitoringInterface(); 475 virtual ~OCiscoMonitoringInterface();
460 476
461 virtual void setEnabled( bool ); 477 virtual void setEnabled( bool );
462 virtual QString name() const; 478 virtual QString name() const;
463 virtual void setChannel( int ); 479 virtual void setChannel( int );
464 480
465}; 481};
466 482
467/*====================================================================================== 483/*======================================================================================
468 * OWlanNGMonitoringInterface 484 * OWlanNGMonitoringInterface
469 *======================================================================================*/ 485 *======================================================================================*/
470 486
471class OWlanNGMonitoringInterface : public OMonitoringInterface 487class OWlanNGMonitoringInterface : public OMonitoringInterface
472{ 488{
473 public: 489 public:
474 OWlanNGMonitoringInterface( ONetworkInterface* ); 490 OWlanNGMonitoringInterface( ONetworkInterface* );
475 virtual ~OWlanNGMonitoringInterface(); 491 virtual ~OWlanNGMonitoringInterface();
476 492
477 public: 493 public:
478 virtual void setEnabled( bool ); 494 virtual void setEnabled( bool );
479 virtual QString name() const; 495 virtual QString name() const;
480 virtual void setChannel( int ); 496 virtual void setChannel( int );
481 497
482}; 498};
483 499
484/*====================================================================================== 500/*======================================================================================
485 * OHostAPMonitoringInterface 501 * OHostAPMonitoringInterface
486 *======================================================================================*/ 502 *======================================================================================*/
487 503
488class OHostAPMonitoringInterface : public OMonitoringInterface 504class OHostAPMonitoringInterface : public OMonitoringInterface
489{ 505{
490 public: 506 public:
491 OHostAPMonitoringInterface( ONetworkInterface* ); 507 OHostAPMonitoringInterface( ONetworkInterface* );
492 virtual ~OHostAPMonitoringInterface(); 508 virtual ~OHostAPMonitoringInterface();
493 509
494 public: 510 public:
495 virtual void setEnabled( bool ); 511 virtual void setEnabled( bool );
496 virtual QString name() const; 512 virtual QString name() const;
497 }; 513 };
498 514
499/*====================================================================================== 515/*======================================================================================
500 * OOrinocoMonitoringInterface 516 * OOrinocoMonitoringInterface
501 *======================================================================================*/ 517 *======================================================================================*/
502 518
503class OOrinocoMonitoringInterface : public OMonitoringInterface 519class OOrinocoMonitoringInterface : public OMonitoringInterface
504{ 520{
505 public: 521 public:
506 OOrinocoMonitoringInterface( ONetworkInterface* ); 522 OOrinocoMonitoringInterface( ONetworkInterface* );
507 virtual ~OOrinocoMonitoringInterface(); 523 virtual ~OOrinocoMonitoringInterface();
508 524
509 public: 525 public:
510 virtual void setChannel( int ); 526 virtual void setChannel( int );
511 virtual void setEnabled( bool ); 527 virtual void setEnabled( bool );
512 virtual QString name() const; 528 virtual QString name() const;
513 529
514}; 530};
515 531
516#endif // ONETWORK_H 532#endif // ONETWORK_H
517 533