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