summaryrefslogtreecommitdiff
path: root/libopie2/opienet
authorar <ar>2004-06-01 21:38:07 (UTC)
committer ar <ar>2004-06-01 21:38:07 (UTC)
commitbaed1d5ab8589aef14440009bc4e7380bcc5a741 (patch) (unidiff)
treec636e892c5eec0df2b36d16cb601a7da41a2ef0f /libopie2/opienet
parent4438393d8eef624565e840b798429071829adea8 (diff)
downloadopie-baed1d5ab8589aef14440009bc4e7380bcc5a741.zip
opie-baed1d5ab8589aef14440009bc4e7380bcc5a741.tar.gz
opie-baed1d5ab8589aef14440009bc4e7380bcc5a741.tar.bz2
- convert to odebug framework
Diffstat (limited to 'libopie2/opienet') (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp11
-rw-r--r--libopie2/opienet/ostation.cpp8
2 files changed, 11 insertions, 8 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index e141097..67718ba 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -1,1255 +1,1258 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003-2004 by Michael 'Mickey' Lauer 3              Copyright (C) 2003-2004 by Michael 'Mickey' Lauer
4 =. <mickey@Vanille.de> 4 =. <mickey@Vanille.de>
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31/* OPIE */ 31/* OPIE */
32 32
33#include <opie2/onetwork.h> 33#include <opie2/onetwork.h>
34#include <opie2/ostation.h> 34#include <opie2/ostation.h>
35#include <opie2/odebug.h> 35#include <opie2/odebug.h>
36 36
37/* QT */ 37/* QT */
38 38
39#include <qfile.h> 39#include <qfile.h>
40#include <qtextstream.h> 40#include <qtextstream.h>
41 41
42/* UNIX */ 42/* UNIX */
43 43
44#include <assert.h> 44#include <assert.h>
45#include <arpa/inet.h> 45#include <arpa/inet.h>
46#include <errno.h> 46#include <errno.h>
47#include <string.h> 47#include <string.h>
48#include <stdlib.h> 48#include <stdlib.h>
49#include <math.h> 49#include <math.h>
50#include <sys/ioctl.h> 50#include <sys/ioctl.h>
51#include <sys/socket.h> 51#include <sys/socket.h>
52#include <sys/types.h> 52#include <sys/types.h>
53#include <unistd.h> 53#include <unistd.h>
54#include <linux/sockios.h> 54#include <linux/sockios.h>
55#include <net/if_arp.h> 55#include <net/if_arp.h>
56#include <stdarg.h> 56#include <stdarg.h>
57 57
58#ifndef NODEBUG 58#ifndef NODEBUG
59#include <opie2/odebugmapper.h> 59#include <opie2/odebugmapper.h>
60 60
61 61
62using namespace Opie::Core; 62using namespace Opie::Core;
63using namespace Opie::Net::Internal; 63using namespace Opie::Net::Internal;
64DebugMapper* debugmapper = new DebugMapper(); 64DebugMapper* debugmapper = new DebugMapper();
65#endif 65#endif
66 66
67/*====================================================================================== 67/*======================================================================================
68 * ONetwork 68 * ONetwork
69 *======================================================================================*/ 69 *======================================================================================*/
70 70
71namespace Opie { 71namespace Opie {
72namespace Net { 72namespace Net {
73ONetwork* ONetwork::_instance = 0; 73ONetwork* ONetwork::_instance = 0;
74 74
75ONetwork::ONetwork() 75ONetwork::ONetwork()
76{ 76{
77 odebug << "ONetwork::ONetwork()" << oendl; 77 odebug << "ONetwork::ONetwork()" << oendl;
78 odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl; 78 odebug << "ONetwork: This code has been compiled against Wireless Extensions V" << WIRELESS_EXT << oendl;
79 synchronize(); 79 synchronize();
80} 80}
81 81
82void ONetwork::synchronize() 82void ONetwork::synchronize()
83{ 83{
84 // gather available interfaces by inspecting /proc/net/dev 84 // gather available interfaces by inspecting /proc/net/dev
85 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices 85 //FIXME: we could use SIOCGIFCONF here, but we aren't interested in virtual (e.g. eth0:0) devices
86 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices 86 //FIXME: Use SIOCGIFCONF anway, because we can disable listing of aliased devices
87 //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev 87 //FIXME: Best is use SIOCGIFCONF and if this doesn't work (result=-1), then fallback to parsing /proc/net/dev
88 88
89 _interfaces.clear(); 89 _interfaces.clear();
90 QString str; 90 QString str;
91 QFile f( "/proc/net/dev" ); 91 QFile f( "/proc/net/dev" );
92 bool hasFile = f.open( IO_ReadOnly ); 92 bool hasFile = f.open( IO_ReadOnly );
93 if ( !hasFile ) 93 if ( !hasFile )
94 { 94 {
95 odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl; 95 odebug << "ONetwork: /proc/net/dev not existing. No network devices available" << oendl;
96 return; 96 return;
97 } 97 }
98 QTextStream s( &f ); 98 QTextStream s( &f );
99 s.readLine(); 99 s.readLine();
100 s.readLine(); 100 s.readLine();
101 while ( !s.atEnd() ) 101 while ( !s.atEnd() )
102 { 102 {
103 s >> str; 103 s >> str;
104 str.truncate( str.find( ':' ) ); 104 str.truncate( str.find( ':' ) );
105 odebug << "ONetwork: found interface '" << str << "'" << oendl; 105 odebug << "ONetwork: found interface '" << str << "'" << oendl;
106 ONetworkInterface* iface = 0; 106 ONetworkInterface* iface = 0;
107 if ( isWirelessInterface( str ) ) 107 if ( isWirelessInterface( str ) )
108 { 108 {
109 iface = new OWirelessNetworkInterface( this, (const char*) str ); 109 iface = new OWirelessNetworkInterface( this, (const char*) str );
110 odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl; 110 odebug << "ONetwork: interface '" << str << "' has Wireless Extensions" << oendl;
111 } 111 }
112 else 112 else
113 { 113 {
114 iface = new ONetworkInterface( this, (const char*) str ); 114 iface = new ONetworkInterface( this, (const char*) str );
115 } 115 }
116 _interfaces.insert( str, iface ); 116 _interfaces.insert( str, iface );
117 s.readLine(); 117 s.readLine();
118 } 118 }
119} 119}
120 120
121 121
122short ONetwork::wirelessExtensionCompileVersion() 122short ONetwork::wirelessExtensionCompileVersion()
123{ 123{
124 return WIRELESS_EXT; 124 return WIRELESS_EXT;
125} 125}
126 126
127 127
128int ONetwork::count() const 128int ONetwork::count() const
129{ 129{
130 return _interfaces.count(); 130 return _interfaces.count();
131} 131}
132 132
133 133
134ONetworkInterface* ONetwork::interface( const QString& iface ) const 134ONetworkInterface* ONetwork::interface( const QString& iface ) const
135{ 135{
136 return _interfaces[iface]; 136 return _interfaces[iface];
137} 137}
138 138
139 139
140ONetwork* ONetwork::instance() 140ONetwork* ONetwork::instance()
141{ 141{
142 if ( !_instance ) _instance = new ONetwork(); 142 if ( !_instance ) _instance = new ONetwork();
143 return _instance; 143 return _instance;
144} 144}
145 145
146 146
147ONetwork::InterfaceIterator ONetwork::iterator() const 147ONetwork::InterfaceIterator ONetwork::iterator() const
148{ 148{
149 return ONetwork::InterfaceIterator( _interfaces ); 149 return ONetwork::InterfaceIterator( _interfaces );
150} 150}
151 151
152 152
153bool ONetwork::isPresent( const char* name ) const 153bool ONetwork::isPresent( const char* name ) const
154{ 154{
155 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 155 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
156 struct ifreq ifr; 156 struct ifreq ifr;
157 memset( &ifr, 0, sizeof( struct ifreq ) ); 157 memset( &ifr, 0, sizeof( struct ifreq ) );
158 strcpy( (char*) &ifr.ifr_name, name ); 158 strcpy( (char*) &ifr.ifr_name, name );
159 int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr ); 159 int result = ::ioctl( sfd, SIOCGIFFLAGS, &ifr );
160 return result != -1; 160 return result != -1;
161} 161}
162 162
163 163
164bool ONetwork::isWirelessInterface( const char* name ) const 164bool ONetwork::isWirelessInterface( const char* name ) const
165{ 165{
166 int sfd = socket( AF_INET, SOCK_STREAM, 0 ); 166 int sfd = socket( AF_INET, SOCK_STREAM, 0 );
167 struct iwreq iwr; 167 struct iwreq iwr;
168 memset( &iwr, 0, sizeof( struct iwreq ) ); 168 memset( &iwr, 0, sizeof( struct iwreq ) );
169 strcpy( (char*) &iwr.ifr_name, name ); 169 strcpy( (char*) &iwr.ifr_name, name );
170 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 170 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
171 return result != -1; 171 return result != -1;
172} 172}
173 173
174/*====================================================================================== 174/*======================================================================================
175 * ONetworkInterface 175 * ONetworkInterface
176 *======================================================================================*/ 176 *======================================================================================*/
177 177
178ONetworkInterface::ONetworkInterface( QObject* parent, const char* name ) 178ONetworkInterface::ONetworkInterface( QObject* parent, const char* name )
179 :QObject( parent, name ), 179 :QObject( parent, name ),
180 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 180 _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
181{ 181{
182 odebug << "ONetworkInterface::ONetworkInterface()" << oendl; 182 odebug << "ONetworkInterface::ONetworkInterface()" << oendl;
183 init(); 183 init();
184} 184}
185 185
186 186
187struct ifreq& ONetworkInterface::ifr() const 187struct ifreq& ONetworkInterface::ifr() const
188{ 188{
189 return _ifr; 189 return _ifr;
190} 190}
191 191
192 192
193void ONetworkInterface::init() 193void ONetworkInterface::init()
194{ 194{
195 odebug << "ONetworkInterface::init()" << oendl; 195 odebug << "ONetworkInterface::init()" << oendl;
196 196
197 memset( &_ifr, 0, sizeof( struct ifreq ) ); 197 memset( &_ifr, 0, sizeof( struct ifreq ) );
198 198
199 if ( _sfd == -1 ) 199 if ( _sfd == -1 )
200 { 200 {
201 odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl; 201 odebug << "ONetworkInterface::init(): Warning - can't get socket for device '" << name() << "'" << oendl;
202 return; 202 return;
203 } 203 }
204} 204}
205 205
206 206
207bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const 207bool ONetworkInterface::ioctl( int call, struct ifreq& ifreq ) const
208{ 208{
209 #ifndef NODEBUG 209 #ifndef NODEBUG
210 int result = ::ioctl( _sfd, call, &ifreq ); 210 int result = ::ioctl( _sfd, call, &ifreq );
211 if ( result == -1 ) 211 if ( result == -1 )
212 odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) 212 odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call )
213 << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; 213 << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl;
214 else 214 else
215 odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call ) 215 odebug << "ONetworkInterface::ioctl (" << name() << ") call '" << debugmapper->map( call )
216 << "' - Status: Ok." << oendl; 216 << "' - Status: Ok." << oendl;
217 return ( result != -1 ); 217 return ( result != -1 );
218 #else 218 #else
219 return ::ioctl( _sfd, call, &ifreq ) != -1; 219 return ::ioctl( _sfd, call, &ifreq ) != -1;
220 #endif 220 #endif
221} 221}
222 222
223 223
224bool ONetworkInterface::ioctl( int call ) const 224bool ONetworkInterface::ioctl( int call ) const
225{ 225{
226 strcpy( _ifr.ifr_name, name() ); 226 strcpy( _ifr.ifr_name, name() );
227 return ioctl( call, _ifr ); 227 return ioctl( call, _ifr );
228} 228}
229 229
230 230
231bool ONetworkInterface::isLoopback() const 231bool ONetworkInterface::isLoopback() const
232{ 232{
233 ioctl( SIOCGIFFLAGS ); 233 ioctl( SIOCGIFFLAGS );
234 return _ifr.ifr_flags & IFF_LOOPBACK; 234 return _ifr.ifr_flags & IFF_LOOPBACK;
235} 235}
236 236
237 237
238bool ONetworkInterface::setUp( bool b ) 238bool ONetworkInterface::setUp( bool b )
239{ 239{
240 ioctl( SIOCGIFFLAGS ); 240 ioctl( SIOCGIFFLAGS );
241 if ( b ) _ifr.ifr_flags |= IFF_UP; 241 if ( b ) _ifr.ifr_flags |= IFF_UP;
242 else _ifr.ifr_flags &= (~IFF_UP); 242 else _ifr.ifr_flags &= (~IFF_UP);
243 return ioctl( SIOCSIFFLAGS ); 243 return ioctl( SIOCSIFFLAGS );
244} 244}
245 245
246 246
247bool ONetworkInterface::isUp() const 247bool ONetworkInterface::isUp() const
248{ 248{
249 ioctl( SIOCGIFFLAGS ); 249 ioctl( SIOCGIFFLAGS );
250 return _ifr.ifr_flags & IFF_UP; 250 return _ifr.ifr_flags & IFF_UP;
251} 251}
252 252
253 253
254void ONetworkInterface::setIPV4Address( const QHostAddress& addr ) 254void ONetworkInterface::setIPV4Address( const QHostAddress& addr )
255{ 255{
256 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 256 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
257 sa->sin_family = AF_INET; 257 sa->sin_family = AF_INET;
258 sa->sin_port = 0; 258 sa->sin_port = 0;
259 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 259 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
260 ioctl( SIOCSIFADDR ); 260 ioctl( SIOCSIFADDR );
261} 261}
262 262
263 263
264QString ONetworkInterface::ipV4Address() const 264QString ONetworkInterface::ipV4Address() const
265{ 265{
266 if ( ioctl( SIOCGIFADDR ) ) 266 if ( ioctl( SIOCGIFADDR ) )
267 { 267 {
268 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; 268 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
269 //FIXME: Use QHostAddress here 269 //FIXME: Use QHostAddress here
270 return QString( inet_ntoa( sa->sin_addr ) ); 270 return QString( inet_ntoa( sa->sin_addr ) );
271 } 271 }
272 else 272 else
273 return "<unknown>"; 273 return "<unknown>";
274 274
275} 275}
276 276
277 277
278void ONetworkInterface::setMacAddress( const OMacAddress& addr ) 278void ONetworkInterface::setMacAddress( const OMacAddress& addr )
279{ 279{
280 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; 280 _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER;
281 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); 281 memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 );
282 ioctl( SIOCSIFHWADDR ); 282 ioctl( SIOCSIFHWADDR );
283} 283}
284 284
285 285
286OMacAddress ONetworkInterface::macAddress() const 286OMacAddress ONetworkInterface::macAddress() const
287{ 287{
288 if ( ioctl( SIOCGIFHWADDR ) ) 288 if ( ioctl( SIOCGIFHWADDR ) )
289 { 289 {
290 return OMacAddress( _ifr ); 290 return OMacAddress( _ifr );
291 } 291 }
292 else 292 else
293 { 293 {
294 return OMacAddress::unknown; 294 return OMacAddress::unknown;
295 } 295 }
296} 296}
297 297
298 298
299void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) 299void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr )
300{ 300{
301 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 301 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
302 sa->sin_family = AF_INET; 302 sa->sin_family = AF_INET;
303 sa->sin_port = 0; 303 sa->sin_port = 0;
304 sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); 304 sa->sin_addr.s_addr = htonl( addr.ip4Addr() );
305 ioctl( SIOCSIFNETMASK ); 305 ioctl( SIOCSIFNETMASK );
306} 306}
307 307
308 308
309QString ONetworkInterface::ipV4Netmask() const 309QString ONetworkInterface::ipV4Netmask() const
310{ 310{
311 if ( ioctl( SIOCGIFNETMASK ) ) 311 if ( ioctl( SIOCGIFNETMASK ) )
312 { 312 {
313 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; 313 struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr;
314 //FIXME: Use QHostAddress here 314 //FIXME: Use QHostAddress here
315 return QString( inet_ntoa( sa->sin_addr ) ); 315 return QString( inet_ntoa( sa->sin_addr ) );
316 } 316 }
317 else 317 else
318 return "<unknown>"; 318 return "<unknown>";
319} 319}
320 320
321 321
322int ONetworkInterface::dataLinkType() const 322int ONetworkInterface::dataLinkType() const
323{ 323{
324 if ( ioctl( SIOCGIFHWADDR ) ) 324 if ( ioctl( SIOCGIFHWADDR ) )
325 { 325 {
326 return _ifr.ifr_hwaddr.sa_family; 326 return _ifr.ifr_hwaddr.sa_family;
327 } 327 }
328 else 328 else
329 { 329 {
330 return -1; 330 return -1;
331 } 331 }
332} 332}
333 333
334 334
335void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 335void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
336{ 336{
337 _mon = m; 337 _mon = m;
338 odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl; 338 odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl;
339} 339}
340 340
341 341
342OMonitoringInterface* ONetworkInterface::monitoring() const 342OMonitoringInterface* ONetworkInterface::monitoring() const
343{ 343{
344 return _mon; 344 return _mon;
345} 345}
346 346
347 347
348ONetworkInterface::~ONetworkInterface() 348ONetworkInterface::~ONetworkInterface()
349{ 349{
350 odebug << "ONetworkInterface::~ONetworkInterface()" << oendl; 350 odebug << "ONetworkInterface::~ONetworkInterface()" << oendl;
351 if ( _sfd != -1 ) ::close( _sfd ); 351 if ( _sfd != -1 ) ::close( _sfd );
352} 352}
353 353
354 354
355bool ONetworkInterface::setPromiscuousMode( bool b ) 355bool ONetworkInterface::setPromiscuousMode( bool b )
356{ 356{
357 ioctl( SIOCGIFFLAGS ); 357 ioctl( SIOCGIFFLAGS );
358 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 358 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
359 else _ifr.ifr_flags &= (~IFF_PROMISC); 359 else _ifr.ifr_flags &= (~IFF_PROMISC);
360 return ioctl( SIOCSIFFLAGS ); 360 return ioctl( SIOCSIFFLAGS );
361} 361}
362 362
363 363
364bool ONetworkInterface::promiscuousMode() const 364bool ONetworkInterface::promiscuousMode() const
365{ 365{
366 ioctl( SIOCGIFFLAGS ); 366 ioctl( SIOCGIFFLAGS );
367 return _ifr.ifr_flags & IFF_PROMISC; 367 return _ifr.ifr_flags & IFF_PROMISC;
368} 368}
369 369
370 370
371bool ONetworkInterface::isWireless() const 371bool ONetworkInterface::isWireless() const
372{ 372{
373 return ioctl( SIOCGIWNAME ); 373 return ioctl( SIOCGIWNAME );
374} 374}
375 375
376 376
377/*====================================================================================== 377/*======================================================================================
378 * OChannelHopper 378 * OChannelHopper
379 *======================================================================================*/ 379 *======================================================================================*/
380 380
381OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 381OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
382 :QObject( 0, "Mickey's funky hopper" ), 382 :QObject( 0, "Mickey's funky hopper" ),
383 _iface( iface ), _interval( 0 ), _tid( 0 ) 383 _iface( iface ), _interval( 0 ), _tid( 0 )
384{ 384{
385 int _maxChannel = iface->channels(); 385 int _maxChannel = iface->channels();
386 // generate fancy hopping sequence honoring the device capabilities 386 // generate fancy hopping sequence honoring the device capabilities
387 if ( _maxChannel >= 1 ) _channels.append( 1 ); 387 if ( _maxChannel >= 1 ) _channels.append( 1 );
388 if ( _maxChannel >= 7 ) _channels.append( 7 ); 388 if ( _maxChannel >= 7 ) _channels.append( 7 );
389 if ( _maxChannel >= 13 ) _channels.append( 13 ); 389 if ( _maxChannel >= 13 ) _channels.append( 13 );
390 if ( _maxChannel >= 2 ) _channels.append( 2 ); 390 if ( _maxChannel >= 2 ) _channels.append( 2 );
391 if ( _maxChannel >= 8 ) _channels.append( 8 ); 391 if ( _maxChannel >= 8 ) _channels.append( 8 );
392 if ( _maxChannel >= 3 ) _channels.append( 3 ); 392 if ( _maxChannel >= 3 ) _channels.append( 3 );
393 if ( _maxChannel >= 14 ) _channels.append( 14 ); 393 if ( _maxChannel >= 14 ) _channels.append( 14 );
394 if ( _maxChannel >= 9 ) _channels.append( 9 ); 394 if ( _maxChannel >= 9 ) _channels.append( 9 );
395 if ( _maxChannel >= 4 ) _channels.append( 4 ); 395 if ( _maxChannel >= 4 ) _channels.append( 4 );
396 if ( _maxChannel >= 10 ) _channels.append( 10 ); 396 if ( _maxChannel >= 10 ) _channels.append( 10 );
397 if ( _maxChannel >= 5 ) _channels.append( 5 ); 397 if ( _maxChannel >= 5 ) _channels.append( 5 );
398 if ( _maxChannel >= 11 ) _channels.append( 11 ); 398 if ( _maxChannel >= 11 ) _channels.append( 11 );
399 if ( _maxChannel >= 6 ) _channels.append( 6 ); 399 if ( _maxChannel >= 6 ) _channels.append( 6 );
400 if ( _maxChannel >= 12 ) _channels.append( 12 ); 400 if ( _maxChannel >= 12 ) _channels.append( 12 );
401 _channel = _channels.begin(); 401 _channel = _channels.begin();
402} 402}
403 403
404 404
405OChannelHopper::~OChannelHopper() 405OChannelHopper::~OChannelHopper()
406{ 406{
407} 407}
408 408
409 409
410bool OChannelHopper::isActive() const 410bool OChannelHopper::isActive() const
411{ 411{
412 return _tid; 412 return _tid;
413} 413}
414 414
415 415
416int OChannelHopper::channel() const 416int OChannelHopper::channel() const
417{ 417{
418 return *_channel; 418 return *_channel;
419} 419}
420 420
421 421
422void OChannelHopper::timerEvent( QTimerEvent* ) 422void OChannelHopper::timerEvent( QTimerEvent* )
423{ 423{
424 _iface->setChannel( *_channel ); 424 _iface->setChannel( *_channel );
425 emit( hopped( *_channel ) ); 425 emit( hopped( *_channel ) );
426 odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl; 426 odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl;
427 if ( ++_channel == _channels.end() ) _channel = _channels.begin(); 427 if ( ++_channel == _channels.end() ) _channel = _channels.begin();
428} 428}
429 429
430 430
431void OChannelHopper::setInterval( int interval ) 431void OChannelHopper::setInterval( int interval )
432{ 432{
433 if ( interval == _interval ) 433 if ( interval == _interval )
434 return; 434 return;
435 435
436 if ( _interval ) 436 if ( _interval )
437 killTimer( _tid ); 437 killTimer( _tid );
438 438
439 _tid = 0; 439 _tid = 0;
440 _interval = interval; 440 _interval = interval;
441 441
442 if ( _interval ) 442 if ( _interval )
443 { 443 {
444 _tid = startTimer( interval ); 444 _tid = startTimer( interval );
445 } 445 }
446} 446}
447 447
448 448
449int OChannelHopper::interval() const 449int OChannelHopper::interval() const
450{ 450{
451 return _interval; 451 return _interval;
452} 452}
453 453
454 454
455/*====================================================================================== 455/*======================================================================================
456 * OWirelessNetworkInterface 456 * OWirelessNetworkInterface
457 *======================================================================================*/ 457 *======================================================================================*/
458 458
459OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) 459OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name )
460 :ONetworkInterface( parent, name ), _hopper( 0 ) 460 :ONetworkInterface( parent, name ), _hopper( 0 )
461{ 461{
462 odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl; 462 odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl;
463 init(); 463 init();
464} 464}
465 465
466 466
467OWirelessNetworkInterface::~OWirelessNetworkInterface() 467OWirelessNetworkInterface::~OWirelessNetworkInterface()
468{ 468{
469} 469}
470 470
471 471
472struct iwreq& OWirelessNetworkInterface::iwr() const 472struct iwreq& OWirelessNetworkInterface::iwr() const
473{ 473{
474 return _iwr; 474 return _iwr;
475} 475}
476 476
477 477
478void OWirelessNetworkInterface::init() 478void OWirelessNetworkInterface::init()
479{ 479{
480 odebug << "OWirelessNetworkInterface::init()" << oendl; 480 odebug << "OWirelessNetworkInterface::init()" << oendl;
481 memset( &_iwr, 0, sizeof( struct iwreq ) ); 481 memset( &_iwr, 0, sizeof( struct iwreq ) );
482 buildInformation(); 482 buildInformation();
483 buildPrivateList(); 483 buildPrivateList();
484 dumpInformation(); 484 dumpInformation();
485} 485}
486 486
487 487
488bool OWirelessNetworkInterface::isAssociated() const 488bool OWirelessNetworkInterface::isAssociated() const
489{ 489{
490 //FIXME: handle different modes 490 //FIXME: handle different modes
491 return !(associatedAP() == OMacAddress::unknown); 491 return !(associatedAP() == OMacAddress::unknown);
492} 492}
493 493
494 494
495OMacAddress OWirelessNetworkInterface::associatedAP() const 495OMacAddress OWirelessNetworkInterface::associatedAP() const
496{ 496{
497 if ( ioctl( SIOCGIWAP ) ) 497 if ( ioctl( SIOCGIWAP ) )
498 return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; 498 return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0];
499 else 499 else
500 return OMacAddress::unknown; 500 return OMacAddress::unknown;
501} 501}
502 502
503 503
504void OWirelessNetworkInterface::buildInformation() 504void OWirelessNetworkInterface::buildInformation()
505{ 505{
506 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck 506 //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck
507 //ML: The HostAP drivers need more than sizeof struct_iw range to complete 507 //ML: The HostAP drivers need more than sizeof struct_iw range to complete
508 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". 508 //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length".
509 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate 509 //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate
510 //ML: _too much_ space. This is damn shitty crap *sigh* 510 //ML: _too much_ space. This is damn shitty crap *sigh*
511 //ML: We allocate a large memory region in RAM and check whether the 511 //ML: We allocate a large memory region in RAM and check whether the
512 //ML: driver pollutes this extra space. The complaint will be made on stdout, 512 //ML: driver pollutes this extra space. The complaint will be made on stdout,
513 //ML: so please forward this... 513 //ML: so please forward this...
514 514
515 struct iwreq wrq; 515 struct iwreq wrq;
516 int len = sizeof( struct iw_range )*2; 516 int len = sizeof( struct iw_range )*2;
517 char *buffer = (char*) malloc( len ); 517 char *buffer = (char*) malloc( len );
518 //FIXME: Validate if we actually got the memory block 518 //FIXME: Validate if we actually got the memory block
519 memset( buffer, 0, len ); 519 memset( buffer, 0, len );
520 memcpy( wrq.ifr_name, name(), IFNAMSIZ); 520 memcpy( wrq.ifr_name, name(), IFNAMSIZ);
521 wrq.u.data.pointer = (caddr_t) buffer; 521 wrq.u.data.pointer = (caddr_t) buffer;
522 wrq.u.data.length = sizeof( struct iw_range ); 522 wrq.u.data.length = sizeof( struct iw_range );
523 wrq.u.data.flags = 0; 523 wrq.u.data.flags = 0;
524 524
525 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) 525 if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 )
526 { 526 {
527 owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl; 527 owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl;
528 _channels.insert( 2412, 1 ); // 2.412 GHz 528 _channels.insert( 2412, 1 ); // 2.412 GHz
529 _channels.insert( 2417, 2 ); // 2.417 GHz 529 _channels.insert( 2417, 2 ); // 2.417 GHz
530 _channels.insert( 2422, 3 ); // 2.422 GHz 530 _channels.insert( 2422, 3 ); // 2.422 GHz
531 _channels.insert( 2427, 4 ); // 2.427 GHz 531 _channels.insert( 2427, 4 ); // 2.427 GHz
532 _channels.insert( 2432, 5 ); // 2.432 GHz 532 _channels.insert( 2432, 5 ); // 2.432 GHz
533 _channels.insert( 2437, 6 ); // 2.437 GHz 533 _channels.insert( 2437, 6 ); // 2.437 GHz
534 _channels.insert( 2442, 7 ); // 2.442 GHz 534 _channels.insert( 2442, 7 ); // 2.442 GHz
535 _channels.insert( 2447, 8 ); // 2.447 GHz 535 _channels.insert( 2447, 8 ); // 2.447 GHz
536 _channels.insert( 2452, 9 ); // 2.452 GHz 536 _channels.insert( 2452, 9 ); // 2.452 GHz
537 _channels.insert( 2457, 10 ); // 2.457 GHz 537 _channels.insert( 2457, 10 ); // 2.457 GHz
538 _channels.insert( 2462, 11 ); // 2.462 GHz 538 _channels.insert( 2462, 11 ); // 2.462 GHz
539 539
540 memset( &_range, 0, sizeof( struct iw_range ) ); 540 memset( &_range, 0, sizeof( struct iw_range ) );
541 } 541 }
542 else 542 else
543 { 543 {
544 // <check if the driver overwrites stuff> 544 // <check if the driver overwrites stuff>
545 int max = 0; 545 int max = 0;
546 for ( int r = sizeof( struct iw_range ); r < len; r++ ) 546 for ( int r = sizeof( struct iw_range ); r < len; r++ )
547 if (buffer[r] != 0) 547 if (buffer[r] != 0)
548 max = r; 548 max = r;
549 if (max > 0) 549 if (max > 0)
550 { 550 {
551 owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() 551 owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name()
552 << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; 552 << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl;
553 } 553 }
554 // </check if the driver overwrites stuff> 554 // </check if the driver overwrites stuff>
555 555
556 struct iw_range range; 556 struct iw_range range;
557 memcpy( &range, buffer, sizeof range ); 557 memcpy( &range, buffer, sizeof range );
558 558
559 odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; 559 odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl;
560 for ( int i = 0; i < range.num_frequency; ++i ) 560 for ( int i = 0; i < range.num_frequency; ++i )
561 { 561 {
562 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 562 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
563 odebug << "OWirelessNetworkInterface::buildInformation: Adding frequency " << freq << " as channel " << i+1 << oendl; 563 odebug << "OWirelessNetworkInterface::buildInformation: Adding frequency " << freq << " as channel " << i+1 << oendl;
564 _channels.insert( freq, i+1 ); 564 _channels.insert( freq, i+1 );
565 } 565 }
566 } 566 }
567 567
568 memcpy( &_range, buffer, sizeof( struct iw_range ) ); 568 memcpy( &_range, buffer, sizeof( struct iw_range ) );
569 odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; 569 odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl;
570 free(buffer); 570 free(buffer);
571} 571}
572 572
573 573
574short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const 574short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const
575{ 575{
576 return _range.we_version_compiled; 576 return _range.we_version_compiled;
577} 577}
578 578
579 579
580void OWirelessNetworkInterface::buildPrivateList() 580void OWirelessNetworkInterface::buildPrivateList()
581{ 581{
582 odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; 582 odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl;
583 583
584 struct iw_priv_args priv[IW_MAX_PRIV_DEF]; 584 struct iw_priv_args priv[IW_MAX_PRIV_DEF];
585 585
586 _iwr.u.data.pointer = (char*) &priv; 586 _iwr.u.data.pointer = (char*) &priv;
587 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself 587 _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself
588 _iwr.u.data.flags = 0; 588 _iwr.u.data.flags = 0;
589 589
590 if ( !wioctl( SIOCGIWPRIV ) ) 590 if ( !wioctl( SIOCGIWPRIV ) )
591 { 591 {
592 owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; 592 owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl;
593 return; 593 return;
594 } 594 }
595 595
596 for ( int i = 0; i < _iwr.u.data.length; ++i ) 596 for ( int i = 0; i < _iwr.u.data.length; ++i )
597 { 597 {
598 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); 598 new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args );
599 } 599 }
600 odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; 600 odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl;
601} 601}
602 602
603 603
604void OWirelessNetworkInterface::dumpInformation() const 604void OWirelessNetworkInterface::dumpInformation() const
605{ 605{
606 odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; 606 odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl;
607 607
608 qDebug( " - driver's idea of maximum throughput is %d bps = %d byte/s = %d Kb/s = %f.2 Mb/s", 608 odebug << " - driver's idea of maximum throughput is " << _range.throughput
609 _range.throughput, _range.throughput / 8, _range.throughput / 8 / 1024, float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ); 609 << " bps = " << ( _range.throughput / 8 ) << " byte/s = " << ( _range.throughput / 8 / 1024 )
610 qDebug( " - driver for '%s' (V%d) has been compiled against WE V%d", 610 << " Kb/s = " << QString().sprintf("%f.2", float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 )
611 name(), _range.we_version_source, _range.we_version_compiled ); 611 << " Mb/s" << oendl;
612
613 odebug << " - driver for '" << name() << "' (V" << _range.we_version_source
614 << ") has been compiled against WE V" << _range.we_version_compiled << oendl;
612 615
613 if ( _range.we_version_compiled != WIRELESS_EXT ) 616 if ( _range.we_version_compiled != WIRELESS_EXT )
614 { 617 {
615 owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; 618 owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl;
616 } 619 }
617 620
618 odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; 621 odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl;
619} 622}
620 623
621 624
622int OWirelessNetworkInterface::channel() const 625int OWirelessNetworkInterface::channel() const
623{ 626{
624 //FIXME: When monitoring enabled, then use it 627 //FIXME: When monitoring enabled, then use it
625 //FIXME: to gather the current RF channel 628 //FIXME: to gather the current RF channel
626 //FIXME: Until then, get active channel from hopper. 629 //FIXME: Until then, get active channel from hopper.
627 if ( _hopper && _hopper->isActive() ) 630 if ( _hopper && _hopper->isActive() )
628 return _hopper->channel(); 631 return _hopper->channel();
629 632
630 if ( !wioctl( SIOCGIWFREQ ) ) 633 if ( !wioctl( SIOCGIWFREQ ) )
631 { 634 {
632 return -1; 635 return -1;
633 } 636 }
634 else 637 else
635 { 638 {
636 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 639 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
637 } 640 }
638} 641}
639 642
640 643
641void OWirelessNetworkInterface::setChannel( int c ) const 644void OWirelessNetworkInterface::setChannel( int c ) const
642{ 645{
643 if ( !c ) 646 if ( !c )
644 { 647 {
645 oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl; 648 oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl;
646 return; 649 return;
647 } 650 }
648 651
649 if ( !_mon ) 652 if ( !_mon )
650 { 653 {
651 memset( &_iwr, 0, sizeof( struct iwreq ) ); 654 memset( &_iwr, 0, sizeof( struct iwreq ) );
652 _iwr.u.freq.m = c; 655 _iwr.u.freq.m = c;
653 _iwr.u.freq.e = 0; 656 _iwr.u.freq.e = 0;
654 wioctl( SIOCSIWFREQ ); 657 wioctl( SIOCSIWFREQ );
655 } 658 }
656 else 659 else
657 { 660 {
658 _mon->setChannel( c ); 661 _mon->setChannel( c );
659 } 662 }
660} 663}
661 664
662 665
663double OWirelessNetworkInterface::frequency() const 666double OWirelessNetworkInterface::frequency() const
664{ 667{
665 if ( !wioctl( SIOCGIWFREQ ) ) 668 if ( !wioctl( SIOCGIWFREQ ) )
666 { 669 {
667 return -1.0; 670 return -1.0;
668 } 671 }
669 else 672 else
670 { 673 {
671 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 674 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
672 } 675 }
673} 676}
674 677
675 678
676int OWirelessNetworkInterface::channels() const 679int OWirelessNetworkInterface::channels() const
677{ 680{
678 return _channels.count(); 681 return _channels.count();
679} 682}
680 683
681 684
682void OWirelessNetworkInterface::setChannelHopping( int interval ) 685void OWirelessNetworkInterface::setChannelHopping( int interval )
683{ 686{
684 if ( !_hopper ) _hopper = new OChannelHopper( this ); 687 if ( !_hopper ) _hopper = new OChannelHopper( this );
685 _hopper->setInterval( interval ); 688 _hopper->setInterval( interval );
686 //FIXME: When and by whom will the channel hopper be deleted? 689 //FIXME: When and by whom will the channel hopper be deleted?
687 //TODO: rely on QObject hierarchy 690 //TODO: rely on QObject hierarchy
688} 691}
689 692
690 693
691int OWirelessNetworkInterface::channelHopping() const 694int OWirelessNetworkInterface::channelHopping() const
692{ 695{
693 return _hopper->interval(); 696 return _hopper->interval();
694} 697}
695 698
696 699
697OChannelHopper* OWirelessNetworkInterface::channelHopper() const 700OChannelHopper* OWirelessNetworkInterface::channelHopper() const
698{ 701{
699 return _hopper; 702 return _hopper;
700} 703}
701 704
702 705
703void OWirelessNetworkInterface::commit() const 706void OWirelessNetworkInterface::commit() const
704{ 707{
705 wioctl( SIOCSIWCOMMIT ); 708 wioctl( SIOCSIWCOMMIT );
706} 709}
707 710
708 711
709void OWirelessNetworkInterface::setMode( const QString& newMode ) 712void OWirelessNetworkInterface::setMode( const QString& newMode )
710{ 713{
711 #ifdef FINALIZE 714 #ifdef FINALIZE
712 QString currentMode = mode(); 715 QString currentMode = mode();
713 if ( currentMode == newMode ) return; 716 if ( currentMode == newMode ) return;
714 #endif 717 #endif
715 718
716 odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl; 719 odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl;
717 720
718 _iwr.u.mode = stringToMode( newMode ); 721 _iwr.u.mode = stringToMode( newMode );
719 722
720 if ( _iwr.u.mode != IW_MODE_MONITOR ) 723 if ( _iwr.u.mode != IW_MODE_MONITOR )
721 { 724 {
722 // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! 725 // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP!
723 _iwr.u.mode = stringToMode( newMode ); 726 _iwr.u.mode = stringToMode( newMode );
724 wioctl( SIOCSIWMODE ); 727 wioctl( SIOCSIWMODE );
725 728
726 // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) 729 // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now)
727 730
728 if ( mode() == "monitor" ) 731 if ( mode() == "monitor" )
729 { 732 {
730 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl; 733 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl;
731 if ( _mon ) 734 if ( _mon )
732 _mon->setEnabled( false ); 735 _mon->setEnabled( false );
733 else 736 else
734 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; 737 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl;
735 } 738 }
736 739
737 } 740 }
738 else // special iwpriv fallback for monitor mode 741 else // special iwpriv fallback for monitor mode
739 { 742 {
740 if ( wioctl( SIOCSIWMODE ) ) 743 if ( wioctl( SIOCSIWMODE ) )
741 { 744 {
742 odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl; 745 odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl;
743 } 746 }
744 else 747 else
745 { 748 {
746 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl; 749 odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl;
747 750
748 if ( _mon ) 751 if ( _mon )
749 _mon->setEnabled( true ); 752 _mon->setEnabled( true );
750 else 753 else
751 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; 754 odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl;
752 } 755 }
753 } 756 }
754} 757}
755 758
756 759
757QString OWirelessNetworkInterface::mode() const 760QString OWirelessNetworkInterface::mode() const
758{ 761{
759 memset( &_iwr, 0, sizeof( struct iwreq ) ); 762 memset( &_iwr, 0, sizeof( struct iwreq ) );
760 763
761 if ( !wioctl( SIOCGIWMODE ) ) 764 if ( !wioctl( SIOCGIWMODE ) )
762 { 765 {
763 return "<unknown>"; 766 return "<unknown>";
764 } 767 }
765 768
766 odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl; 769 odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl;
767 770
768 // legacy compatible monitor mode check 771 // legacy compatible monitor mode check
769 772
770 if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) 773 if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 )
771 { 774 {
772 return "monitor"; 775 return "monitor";
773 } 776 }
774 else 777 else
775 { 778 {
776 return modeToString( _iwr.u.mode ); 779 return modeToString( _iwr.u.mode );
777 } 780 }
778} 781}
779 782
780void OWirelessNetworkInterface::setNickName( const QString& nickname ) 783void OWirelessNetworkInterface::setNickName( const QString& nickname )
781{ 784{
782 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); 785 _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname );
783 _iwr.u.essid.length = nickname.length(); 786 _iwr.u.essid.length = nickname.length();
784 wioctl( SIOCSIWNICKN ); 787 wioctl( SIOCSIWNICKN );
785} 788}
786 789
787 790
788QString OWirelessNetworkInterface::nickName() const 791QString OWirelessNetworkInterface::nickName() const
789{ 792{
790 char str[IW_ESSID_MAX_SIZE]; 793 char str[IW_ESSID_MAX_SIZE];
791 _iwr.u.data.pointer = &str[0]; 794 _iwr.u.data.pointer = &str[0];
792 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 795 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
793 if ( !wioctl( SIOCGIWNICKN ) ) 796 if ( !wioctl( SIOCGIWNICKN ) )
794 { 797 {
795 return "<unknown>"; 798 return "<unknown>";
796 } 799 }
797 else 800 else
798 { 801 {
799 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 802 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
800 return str; 803 return str;
801 } 804 }
802} 805}
803 806
804 807
805void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) 808void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... )
806{ 809{
807 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); 810 OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) );
808 if ( !priv ) 811 if ( !priv )
809 { 812 {
810 owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name() 813 owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name()
811 << "' does not support private ioctl '" << call << "'" << oendl; 814 << "' does not support private ioctl '" << call << "'" << oendl;
812 return; 815 return;
813 } 816 }
814 if ( priv->numberSetArgs() != numargs ) 817 if ( priv->numberSetArgs() != numargs )
815 { 818 {
816 owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '" 819 owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '"
817 << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl; 820 << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl;
818 return; 821 return;
819 } 822 }
820 823
821 odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl; 824 odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl;
822 memset( &_iwr, 0, sizeof _iwr ); 825 memset( &_iwr, 0, sizeof _iwr );
823 va_list argp; 826 va_list argp;
824 va_start( argp, numargs ); 827 va_start( argp, numargs );
825 for ( int i = 0; i < numargs; ++i ) 828 for ( int i = 0; i < numargs; ++i )
826 { 829 {
827 priv->setParameter( i, va_arg( argp, int ) ); 830 priv->setParameter( i, va_arg( argp, int ) );
828 } 831 }
829 va_end( argp ); 832 va_end( argp );
830 priv->invoke(); 833 priv->invoke();
831} 834}
832 835
833 836
834void OWirelessNetworkInterface::getPrivate( const QString& call ) 837void OWirelessNetworkInterface::getPrivate( const QString& call )
835{ 838{
836 oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl; 839 oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl;
837} 840}
838 841
839 842
840bool OWirelessNetworkInterface::hasPrivate( const QString& call ) 843bool OWirelessNetworkInterface::hasPrivate( const QString& call )
841{ 844{
842 return child( (const char*) call ); 845 return child( (const char*) call );
843} 846}
844 847
845 848
846QString OWirelessNetworkInterface::SSID() const 849QString OWirelessNetworkInterface::SSID() const
847{ 850{
848 char str[IW_ESSID_MAX_SIZE]; 851 char str[IW_ESSID_MAX_SIZE];
849 _iwr.u.essid.pointer = &str[0]; 852 _iwr.u.essid.pointer = &str[0];
850 _iwr.u.essid.length = IW_ESSID_MAX_SIZE; 853 _iwr.u.essid.length = IW_ESSID_MAX_SIZE;
851 if ( !wioctl( SIOCGIWESSID ) ) 854 if ( !wioctl( SIOCGIWESSID ) )
852 { 855 {
853 return "<unknown>"; 856 return "<unknown>";
854 } 857 }
855 else 858 else
856 { 859 {
857 return str; 860 return str;
858 } 861 }
859} 862}
860 863
861 864
862void OWirelessNetworkInterface::setSSID( const QString& ssid ) 865void OWirelessNetworkInterface::setSSID( const QString& ssid )
863{ 866{
864 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); 867 _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid );
865 _iwr.u.essid.length = ssid.length(); 868 _iwr.u.essid.length = ssid.length();
866 wioctl( SIOCSIWESSID ); 869 wioctl( SIOCSIWESSID );
867} 870}
868 871
869 872
870OStationList* OWirelessNetworkInterface::scanNetwork() 873OStationList* OWirelessNetworkInterface::scanNetwork()
871{ 874{
872 _iwr.u.param.flags = IW_SCAN_DEFAULT; 875 _iwr.u.param.flags = IW_SCAN_DEFAULT;
873 _iwr.u.param.value = 0; 876 _iwr.u.param.value = 0;
874 if ( !wioctl( SIOCSIWSCAN ) ) 877 if ( !wioctl( SIOCSIWSCAN ) )
875 { 878 {
876 return 0; 879 return 0;
877 } 880 }
878 881
879 OStationList* stations = new OStationList(); 882 OStationList* stations = new OStationList();
880 883
881 int timeout = 1000000; 884 int timeout = 1000000;
882 885
883 odebug << "ONetworkInterface::scanNetwork() - scan started." << oendl; 886 odebug << "ONetworkInterface::scanNetwork() - scan started." << oendl;
884 887
885 bool results = false; 888 bool results = false;
886 struct timeval tv; 889 struct timeval tv;
887 tv.tv_sec = 0; 890 tv.tv_sec = 0;
888 tv.tv_usec = 250000; // initial timeout ~ 250ms 891 tv.tv_usec = 250000; // initial timeout ~ 250ms
889 char buffer[IW_SCAN_MAX_DATA]; 892 char buffer[IW_SCAN_MAX_DATA];
890 893
891 while ( !results && timeout > 0 ) 894 while ( !results && timeout > 0 )
892 { 895 {
893 timeout -= tv.tv_usec; 896 timeout -= tv.tv_usec;
894 select( 0, 0, 0, 0, &tv ); 897 select( 0, 0, 0, 0, &tv );
895 898
896 _iwr.u.data.pointer = &buffer[0]; 899 _iwr.u.data.pointer = &buffer[0];
897 _iwr.u.data.flags = 0; 900 _iwr.u.data.flags = 0;
898 _iwr.u.data.length = sizeof buffer; 901 _iwr.u.data.length = sizeof buffer;
899 if ( wioctl( SIOCGIWSCAN ) ) 902 if ( wioctl( SIOCGIWSCAN ) )
900 { 903 {
901 results = true; 904 results = true;
902 continue; 905 continue;
903 } 906 }
904 else if ( errno == EAGAIN) 907 else if ( errno == EAGAIN)
905 { 908 {
906 odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl; 909 odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl;
907 #if 0 910 #if 0
908 if ( qApp ) 911 if ( qApp )
909 { 912 {
910 qApp->processEvents( 100 ); 913 qApp->processEvents( 100 );
911 continue; 914 continue;
912 } 915 }
913 #endif 916 #endif
914 tv.tv_sec = 0; 917 tv.tv_sec = 0;
915 tv.tv_usec = 100000; 918 tv.tv_usec = 100000;
916 continue; 919 continue;
917 } 920 }
918 } 921 }
919 922
920 odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; 923 odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl;
921 924
922 if ( results ) 925 if ( results )
923 { 926 {
924 odebug << " - result length = " << _iwr.u.data.length << oendl; 927 odebug << " - result length = " << _iwr.u.data.length << oendl;
925 if ( !_iwr.u.data.length ) 928 if ( !_iwr.u.data.length )
926 { 929 {
927 odebug << " - no results (empty neighbourhood)" << oendl; 930 odebug << " - no results (empty neighbourhood)" << oendl;
928 return stations; 931 return stations;
929 } 932 }
930 933
931 odebug << " - results are in!" << oendl; 934 odebug << " - results are in!" << oendl;
932 dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); 935 dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length );
933 936
934 // parse results 937 // parse results
935 938
936 int offset = 0; 939 int offset = 0;
937 struct iw_event* we = (struct iw_event*) &buffer[0]; 940 struct iw_event* we = (struct iw_event*) &buffer[0];
938 941
939 while ( offset < _iwr.u.data.length ) 942 while ( offset < _iwr.u.data.length )
940 { 943 {
941 //const char* cmd = *(*_ioctlmap)[we->cmd]; 944 //const char* cmd = *(*_ioctlmap)[we->cmd];
942 //if ( !cmd ) cmd = "<unknown>"; 945 //if ( !cmd ) cmd = "<unknown>";
943 odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl; 946 odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl;
944 switch (we->cmd) 947 switch (we->cmd)
945 { 948 {
946 case SIOCGIWAP: 949 case SIOCGIWAP:
947 { 950 {
948 odebug << "SIOCGIWAP" << oendl; 951 odebug << "SIOCGIWAP" << oendl;
949 stations->append( new OStation() ); 952 stations->append( new OStation() );
950 stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; 953 stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0];
951 break; 954 break;
952 } 955 }
953 case SIOCGIWMODE: 956 case SIOCGIWMODE:
954 { 957 {
955 odebug << "SIOCGIWMODE" << oendl; 958 odebug << "SIOCGIWMODE" << oendl;
956 stations->last()->type = modeToString( we->u.mode ); 959 stations->last()->type = modeToString( we->u.mode );
957 break; 960 break;
958 } 961 }
959 case SIOCGIWFREQ: 962 case SIOCGIWFREQ:
960 { 963 {
961 odebug << "SIOCGIWFREQ" << oendl; 964 odebug << "SIOCGIWFREQ" << oendl;
962 stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; 965 stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ];
963 break; 966 break;
964 } 967 }
965 case SIOCGIWESSID: 968 case SIOCGIWESSID:
966 { 969 {
967 odebug << "SIOCGIWESSID" << oendl; 970 odebug << "SIOCGIWESSID" << oendl;
968 stations->last()->ssid = we->u.essid.pointer; 971 stations->last()->ssid = we->u.essid.pointer;
969 break; 972 break;
970 } 973 }
971 case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; 974 case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break;
972 case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break; 975 case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break;
973 case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ 976 case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */
974 case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */ 977 case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */
975 case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ 978 case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */
976 case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ 979 case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */
977 case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ 980 case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */
978 default: odebug << "unhandled event" << oendl; 981 default: odebug << "unhandled event" << oendl;
979 } 982 }
980 983
981 offset += we->len; 984 offset += we->len;
982 we = (struct iw_event*) &buffer[offset]; 985 we = (struct iw_event*) &buffer[offset];
983 } 986 }
984 return stations; 987 return stations;
985 988
986 return stations; 989 return stations;
987 990
988 } 991 }
989 else 992 else
990 { 993 {
991 odebug << " - no results (timeout) :(" << oendl; 994 odebug << " - no results (timeout) :(" << oendl;
992 return stations; 995 return stations;
993 } 996 }
994} 997}
995 998
996 999
997int OWirelessNetworkInterface::signalStrength() const 1000int OWirelessNetworkInterface::signalStrength() const
998{ 1001{
999 iw_statistics stat; 1002 iw_statistics stat;
1000 ::memset( &stat, 0, sizeof stat ); 1003 ::memset( &stat, 0, sizeof stat );
1001 _iwr.u.data.pointer = (char*) &stat; 1004 _iwr.u.data.pointer = (char*) &stat;
1002 _iwr.u.data.flags = 0; 1005 _iwr.u.data.flags = 0;
1003 _iwr.u.data.length = sizeof stat; 1006 _iwr.u.data.length = sizeof stat;
1004 1007
1005 if ( !wioctl( SIOCGIWSTATS ) ) 1008 if ( !wioctl( SIOCGIWSTATS ) )
1006 { 1009 {
1007 return -1; 1010 return -1;
1008 } 1011 }
1009 1012
1010 int max = _range.max_qual.qual; 1013 int max = _range.max_qual.qual;
1011 int cur = stat.qual.qual; 1014 int cur = stat.qual.qual;
1012 int lev = stat.qual.level; //FIXME: Do something with them? 1015 int lev = stat.qual.level; //FIXME: Do something with them?
1013 int noi = stat.qual.noise; //FIXME: Do something with them? 1016 int noi = stat.qual.noise; //FIXME: Do something with them?
1014 1017
1015 1018
1016 return max != 0 ? cur*100/max: -1; 1019 return max != 0 ? cur*100/max: -1;
1017} 1020}
1018 1021
1019 1022
1020bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const 1023bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const
1021{ 1024{
1022 #ifndef NODEBUG 1025 #ifndef NODEBUG
1023 int result = ::ioctl( _sfd, call, &iwreq ); 1026 int result = ::ioctl( _sfd, call, &iwreq );
1024 1027
1025 if ( result == -1 ) 1028 if ( result == -1 )
1026 odebug << "ONetworkInterface::wioctl (" << name() << ") call '" 1029 odebug << "ONetworkInterface::wioctl (" << name() << ") call '"
1027 << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; 1030 << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl;
1028 else 1031 else
1029 odebug << "ONetworkInterface::wioctl (" << name() << ") call '" 1032 odebug << "ONetworkInterface::wioctl (" << name() << ") call '"
1030 << debugmapper->map( call ) << "' - Status: Ok." << oendl; 1033 << debugmapper->map( call ) << "' - Status: Ok." << oendl;
1031 1034
1032 return ( result != -1 ); 1035 return ( result != -1 );
1033 #else 1036 #else
1034 return ::ioctl( _sfd, call, &iwreq ) != -1; 1037 return ::ioctl( _sfd, call, &iwreq ) != -1;
1035 #endif 1038 #endif
1036} 1039}
1037 1040
1038 1041
1039bool OWirelessNetworkInterface::wioctl( int call ) const 1042bool OWirelessNetworkInterface::wioctl( int call ) const
1040{ 1043{
1041 strcpy( _iwr.ifr_name, name() ); 1044 strcpy( _iwr.ifr_name, name() );
1042 return wioctl( call, _iwr ); 1045 return wioctl( call, _iwr );
1043} 1046}
1044 1047
1045 1048
1046/*====================================================================================== 1049/*======================================================================================
1047 * OMonitoringInterface 1050 * OMonitoringInterface
1048 *======================================================================================*/ 1051 *======================================================================================*/
1049 1052
1050OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1053OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
1051 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) 1054 :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader )
1052{ 1055{
1053} 1056}
1054 1057
1055 1058
1056OMonitoringInterface::~OMonitoringInterface() 1059OMonitoringInterface::~OMonitoringInterface()
1057{ 1060{
1058} 1061}
1059 1062
1060 1063
1061void OMonitoringInterface::setChannel( int c ) 1064void OMonitoringInterface::setChannel( int c )
1062{ 1065{
1063 // use standard WE channel switching protocol 1066 // use standard WE channel switching protocol
1064 memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); 1067 memset( &_if->_iwr, 0, sizeof( struct iwreq ) );
1065 _if->_iwr.u.freq.m = c; 1068 _if->_iwr.u.freq.m = c;
1066 _if->_iwr.u.freq.e = 0; 1069 _if->_iwr.u.freq.e = 0;
1067 _if->wioctl( SIOCSIWFREQ ); 1070 _if->wioctl( SIOCSIWFREQ );
1068} 1071}
1069 1072
1070 1073
1071void OMonitoringInterface::setEnabled( bool b ) 1074void OMonitoringInterface::setEnabled( bool b )
1072{ 1075{
1073} 1076}
1074 1077
1075 1078
1076/*====================================================================================== 1079/*======================================================================================
1077 * OCiscoMonitoringInterface 1080 * OCiscoMonitoringInterface
1078 *======================================================================================*/ 1081 *======================================================================================*/
1079 1082
1080OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1083OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
1081 :OMonitoringInterface( iface, prismHeader ) 1084 :OMonitoringInterface( iface, prismHeader )
1082{ 1085{
1083 iface->setMonitoring( this ); 1086 iface->setMonitoring( this );
1084} 1087}
1085 1088
1086 1089
1087OCiscoMonitoringInterface::~OCiscoMonitoringInterface() 1090OCiscoMonitoringInterface::~OCiscoMonitoringInterface()
1088{ 1091{
1089} 1092}
1090 1093
1091 1094
1092void OCiscoMonitoringInterface::setEnabled( bool b ) 1095void OCiscoMonitoringInterface::setEnabled( bool b )
1093{ 1096{
1094 QString fname; 1097 QString fname;
1095 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); 1098 fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() );
1096 QFile f( fname ); 1099 QFile f( fname );
1097 if ( !f.exists() ) return; 1100 if ( !f.exists() ) return;
1098 1101
1099 if ( f.open( IO_WriteOnly ) ) 1102 if ( f.open( IO_WriteOnly ) )
1100 { 1103 {
1101 QTextStream s( &f ); 1104 QTextStream s( &f );
1102 s << "Mode: r"; 1105 s << "Mode: r";
1103 s << "Mode: y"; 1106 s << "Mode: y";
1104 s << "XmitPower: 1"; 1107 s << "XmitPower: 1";
1105 } 1108 }
1106 1109
1107 // flushing and closing will be done automatically when f goes out of scope 1110 // flushing and closing will be done automatically when f goes out of scope
1108} 1111}
1109 1112
1110 1113
1111QString OCiscoMonitoringInterface::name() const 1114QString OCiscoMonitoringInterface::name() const
1112{ 1115{
1113 return "cisco"; 1116 return "cisco";
1114} 1117}
1115 1118
1116 1119
1117void OCiscoMonitoringInterface::setChannel( int ) 1120void OCiscoMonitoringInterface::setChannel( int )
1118{ 1121{
1119 // cisco devices automatically switch channels when in monitor mode 1122 // cisco devices automatically switch channels when in monitor mode
1120} 1123}
1121 1124
1122 1125
1123/*====================================================================================== 1126/*======================================================================================
1124 * OWlanNGMonitoringInterface 1127 * OWlanNGMonitoringInterface
1125 *======================================================================================*/ 1128 *======================================================================================*/
1126 1129
1127 1130
1128OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1131OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
1129 :OMonitoringInterface( iface, prismHeader ) 1132 :OMonitoringInterface( iface, prismHeader )
1130{ 1133{
1131 iface->setMonitoring( this ); 1134 iface->setMonitoring( this );
1132} 1135}
1133 1136
1134 1137
1135OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() 1138OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface()
1136{ 1139{
1137} 1140}
1138 1141
1139 1142
1140void OWlanNGMonitoringInterface::setEnabled( bool b ) 1143void OWlanNGMonitoringInterface::setEnabled( bool b )
1141{ 1144{
1142 //FIXME: do nothing if its already in the same mode 1145 //FIXME: do nothing if its already in the same mode
1143 1146
1144 QString enable = b ? "true" : "false"; 1147 QString enable = b ? "true" : "false";
1145 QString prism = _prismHeader ? "true" : "false"; 1148 QString prism = _prismHeader ? "true" : "false";
1146 QString cmd; 1149 QString cmd;
1147 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", 1150 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
1148 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); 1151 (const char*) _if->name(), 1, (const char*) enable, (const char*) prism );
1149 system( cmd ); 1152 system( cmd );
1150} 1153}
1151 1154
1152 1155
1153QString OWlanNGMonitoringInterface::name() const 1156QString OWlanNGMonitoringInterface::name() const
1154{ 1157{
1155 return "wlan-ng"; 1158 return "wlan-ng";
1156} 1159}
1157 1160
1158 1161
1159void OWlanNGMonitoringInterface::setChannel( int c ) 1162void OWlanNGMonitoringInterface::setChannel( int c )
1160{ 1163{
1161 //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. 1164 //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't.
1162 1165
1163 QString enable = "true"; //_if->monitorMode() ? "true" : "false"; 1166 QString enable = "true"; //_if->monitorMode() ? "true" : "false";
1164 QString prism = _prismHeader ? "true" : "false"; 1167 QString prism = _prismHeader ? "true" : "false";
1165 QString cmd; 1168 QString cmd;
1166 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", 1169 cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s",
1167 (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); 1170 (const char*) _if->name(), c, (const char*) enable, (const char*) prism );
1168 system( cmd ); 1171 system( cmd );
1169} 1172}
1170 1173
1171 1174
1172/*====================================================================================== 1175/*======================================================================================
1173 * OHostAPMonitoringInterface 1176 * OHostAPMonitoringInterface
1174 *======================================================================================*/ 1177 *======================================================================================*/
1175 1178
1176OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1179OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
1177 :OMonitoringInterface( iface, prismHeader ) 1180 :OMonitoringInterface( iface, prismHeader )
1178{ 1181{
1179 iface->setMonitoring( this ); 1182 iface->setMonitoring( this );
1180} 1183}
1181 1184
1182OHostAPMonitoringInterface::~OHostAPMonitoringInterface() 1185OHostAPMonitoringInterface::~OHostAPMonitoringInterface()
1183{ 1186{
1184} 1187}
1185 1188
1186void OHostAPMonitoringInterface::setEnabled( bool b ) 1189void OHostAPMonitoringInterface::setEnabled( bool b )
1187{ 1190{
1188 int monitorCode = _prismHeader ? 1 : 2; 1191 int monitorCode = _prismHeader ? 1 : 2;
1189 if ( b ) 1192 if ( b )
1190 { 1193 {
1191 _if->setPrivate( "monitor", 1, monitorCode ); 1194 _if->setPrivate( "monitor", 1, monitorCode );
1192 } 1195 }
1193 else 1196 else
1194 { 1197 {
1195 _if->setPrivate( "monitor", 1, 0 ); 1198 _if->setPrivate( "monitor", 1, 0 );
1196 } 1199 }
1197} 1200}
1198 1201
1199 1202
1200QString OHostAPMonitoringInterface::name() const 1203QString OHostAPMonitoringInterface::name() const
1201{ 1204{
1202 return "hostap"; 1205 return "hostap";
1203} 1206}
1204 1207
1205 1208
1206/*====================================================================================== 1209/*======================================================================================
1207 * OOrinocoNetworkInterface 1210 * OOrinocoNetworkInterface
1208 *======================================================================================*/ 1211 *======================================================================================*/
1209 1212
1210OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) 1213OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader )
1211 :OMonitoringInterface( iface, prismHeader ) 1214 :OMonitoringInterface( iface, prismHeader )
1212{ 1215{
1213 iface->setMonitoring( this ); 1216 iface->setMonitoring( this );
1214} 1217}
1215 1218
1216 1219
1217OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() 1220OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface()
1218{ 1221{
1219} 1222}
1220 1223
1221 1224
1222void OOrinocoMonitoringInterface::setChannel( int c ) 1225void OOrinocoMonitoringInterface::setChannel( int c )
1223{ 1226{
1224 if ( !_if->hasPrivate( "monitor" ) ) 1227 if ( !_if->hasPrivate( "monitor" ) )
1225 { 1228 {
1226 this->OMonitoringInterface::setChannel( c ); 1229 this->OMonitoringInterface::setChannel( c );
1227 } 1230 }
1228 else 1231 else
1229 { 1232 {
1230 int monitorCode = _prismHeader ? 1 : 2; 1233 int monitorCode = _prismHeader ? 1 : 2;
1231 _if->setPrivate( "monitor", 2, monitorCode, c ); 1234 _if->setPrivate( "monitor", 2, monitorCode, c );
1232 } 1235 }
1233} 1236}
1234 1237
1235 1238
1236void OOrinocoMonitoringInterface::setEnabled( bool b ) 1239void OOrinocoMonitoringInterface::setEnabled( bool b )
1237{ 1240{
1238 if ( b ) 1241 if ( b )
1239 { 1242 {
1240 setChannel( 1 ); 1243 setChannel( 1 );
1241 } 1244 }
1242 else 1245 else
1243 { 1246 {
1244 _if->setPrivate( "monitor", 2, 0, 0 ); 1247 _if->setPrivate( "monitor", 2, 0, 0 );
1245 } 1248 }
1246} 1249}
1247 1250
1248 1251
1249QString OOrinocoMonitoringInterface::name() const 1252QString OOrinocoMonitoringInterface::name() const
1250{ 1253{
1251 return "orinoco"; 1254 return "orinoco";
1252} 1255}
1253 1256
1254} 1257}
1255} 1258}
diff --git a/libopie2/opienet/ostation.cpp b/libopie2/opienet/ostation.cpp
index ce0995b..b5ac325 100644
--- a/libopie2/opienet/ostation.cpp
+++ b/libopie2/opienet/ostation.cpp
@@ -1,72 +1,72 @@
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 Michael 'Mickey' Lauer <mickey@Vanille.de> 3              Copyright (C) 2003 by Michael 'Mickey' Lauer <mickey@Vanille.de>
4 =. 4 =.
5 .=l. 5 .=l.
6           .>+-= 6           .>+-=
7 _;:,     .>    :=|. This program is free software; you can 7 _;:,     .>    :=|. This program is free software; you can
8.> <`_,   >  .   <= redistribute it and/or modify it under 8.> <`_,   >  .   <= redistribute it and/or modify it under
9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 9:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
10.="- .-=="i,     .._ License as published by the Free Software 10.="- .-=="i,     .._ License as published by the Free Software
11 - .   .-<_>     .<> Foundation; either version 2 of the License, 11 - .   .-<_>     .<> Foundation; either version 2 of the License,
12     ._= =}       : or (at your option) any later version. 12     ._= =}       : or (at your option) any later version.
13    .%`+i>       _;_. 13    .%`+i>       _;_.
14    .i_,=:_.      -<s. This program is distributed in the hope that 14    .i_,=:_.      -<s. This program is distributed in the hope that
15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 15     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
16    : ..    .:,     . . . without even the implied warranty of 16    : ..    .:,     . . . without even the implied warranty of
17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 17    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 18  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
19..}^=.=       =       ; Library General Public License for more 19..}^=.=       =       ; Library General Public License for more
20++=   -.     .`     .: details. 20++=   -.     .`     .: details.
21 :     =  ...= . :.=- 21 :     =  ...= . :.=-
22 -.   .:....=;==+<; You should have received a copy of the GNU 22 -.   .:....=;==+<; You should have received a copy of the GNU
23  -_. . .   )=.  = Library General Public License along with 23  -_. . .   )=.  = Library General Public License along with
24    --        :-=` this library; see the file COPYING.LIB. 24    --        :-=` this library; see the file COPYING.LIB.
25 If not, write to the Free Software Foundation, 25 If not, write to the Free Software Foundation,
26 Inc., 59 Temple Place - Suite 330, 26 Inc., 59 Temple Place - Suite 330,
27 Boston, MA 02111-1307, USA. 27 Boston, MA 02111-1307, USA.
28 28
29*/ 29*/
30 30
31#include <opie2/ostation.h> 31#include <opie2/ostation.h>
32#include <opie2/odebug.h> 32#include <opie2/odebug.h>
33 33
34 34
35using namespace Opie::Core; 35using namespace Opie::Core;
36 36
37namespace Opie { 37namespace Opie {
38namespace Net { 38namespace Net {
39/*====================================================================================== 39/*======================================================================================
40 * OStation 40 * OStation
41 *======================================================================================*/ 41 *======================================================================================*/
42 42
43OStation::OStation() 43OStation::OStation()
44{ 44{
45 odebug << "OStation::OStation()" << oendl; 45 odebug << "OStation::OStation()" << oendl;
46 46
47 type = "<unknown>"; 47 type = "<unknown>";
48 macAddress = OMacAddress::unknown; 48 macAddress = OMacAddress::unknown;
49 ssid = "<unknown>"; 49 ssid = "<unknown>";
50 channel = 0; 50 channel = 0;
51 apAddress = OMacAddress::unknown; 51 apAddress = OMacAddress::unknown;
52 52
53} 53}
54 54
55 55
56OStation::~OStation() 56OStation::~OStation()
57{ 57{
58 odebug << "OStation::~OStation()" << oendl; 58 odebug << "OStation::~OStation()" << oendl;
59} 59}
60 60
61 61
62void OStation::dump() 62void OStation::dump()
63{ 63{
64 odebug << "------- OStation::dump() ------------" << oendl; 64 odebug << "------- OStation::dump() ------------" << oendl;
65 qDebug( "type: %s", (const char*) type ); 65 odebug << "type: " << type << "" << oendl;
66 qDebug( "mac: %s", (const char*) macAddress.toString() ); 66 odebug << "mac: " << macAddress.toString() << "" << oendl;
67 qDebug( "ap: %s", (const char*) apAddress.toString() ); 67 odebug << "ap: " << apAddress.toString() << "" << oendl;
68 qDebug( "ip: %s", (const char*) ipAddress.toString() ); 68 odebug << "ip: " << ipAddress.toString() << "" << oendl;
69} 69}
70 70
71} 71}
72} 72}