summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2003-04-01 15:03:49 (UTC)
committer mickeyl <mickeyl>2003-04-01 15:03:49 (UTC)
commita7ad29eb41163eec88b3bd835108bd80140ff086 (patch) (unidiff)
tree8fa122e07d475014d8343be06d99f53759af0582
parent14d3e700f80f8e26f3f3cceaa7174d5f1c445bd7 (diff)
downloadopie-a7ad29eb41163eec88b3bd835108bd80140ff086.zip
opie-a7ad29eb41163eec88b3bd835108bd80140ff086.tar.gz
opie-a7ad29eb41163eec88b3bd835108bd80140ff086.tar.bz2
introduce a more sophisticated channel hopping scheme
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--libopie2/opienet/onetwork.cpp41
-rw-r--r--libopie2/opienet/onetwork.h6
2 files changed, 36 insertions, 11 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp
index 50d67bb..ac2857a 100644
--- a/libopie2/opienet/onetwork.cpp
+++ b/libopie2/opienet/onetwork.cpp
@@ -115,407 +115,430 @@ ONetwork* ONetwork::instance()
115{ 115{
116 if ( !_instance ) _instance = new ONetwork(); 116 if ( !_instance ) _instance = new ONetwork();
117 return _instance; 117 return _instance;
118} 118}
119 119
120 120
121ONetwork::InterfaceIterator ONetwork::iterator() const 121ONetwork::InterfaceIterator ONetwork::iterator() const
122{ 122{
123 return ONetwork::InterfaceIterator( _interfaces ); 123 return ONetwork::InterfaceIterator( _interfaces );
124} 124}
125 125
126 126
127bool ONetwork::isWirelessInterface( const char* name ) const 127bool ONetwork::isWirelessInterface( const char* name ) const
128{ 128{
129 int sfd = socket( AF_INET, SOCK_DGRAM, 0 ); 129 int sfd = socket( AF_INET, SOCK_DGRAM, 0 );
130 iwreqstruct iwr; 130 iwreqstruct iwr;
131 memset( &iwr, 0, sizeof( iwreqstruct ) ); 131 memset( &iwr, 0, sizeof( iwreqstruct ) );
132 strcpy( (char*) &iwr.ifr_name, name ); 132 strcpy( (char*) &iwr.ifr_name, name );
133 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr ); 133 int result = ::ioctl( sfd, SIOCGIWNAME, &iwr );
134 if ( result == -1 ) 134 if ( result == -1 )
135 qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) ); 135 qDebug( "ONetwork::ioctl(): SIOCGIWNAME failed: %d (%s)", result, strerror( errno ) );
136 else 136 else
137 qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." ); 137 qDebug( "ONetwork::ioctl(): SIOCGIWNAME ok." );
138 return ( result != -1 ); 138 return ( result != -1 );
139} 139}
140 140
141/*====================================================================================== 141/*======================================================================================
142 * ONetworkInterface 142 * ONetworkInterface
143 *======================================================================================*/ 143 *======================================================================================*/
144 144
145ONetworkInterface::ONetworkInterface( const QString& name ) 145ONetworkInterface::ONetworkInterface( const QString& name )
146 :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 ) 146 :_name( name ), _sfd( socket( AF_INET, SOCK_DGRAM, 0 ) ), _mon( 0 )
147{ 147{
148 qDebug( "ONetworkInterface::ONetworkInterface()" ); 148 qDebug( "ONetworkInterface::ONetworkInterface()" );
149 init(); 149 init();
150} 150}
151 151
152 152
153ifreqstruct& ONetworkInterface::ifr() const 153ifreqstruct& ONetworkInterface::ifr() const
154{ 154{
155 return _ifr; 155 return _ifr;
156} 156}
157 157
158 158
159void ONetworkInterface::init() 159void ONetworkInterface::init()
160{ 160{
161 qDebug( "ONetworkInterface::init()" ); 161 qDebug( "ONetworkInterface::init()" );
162 162
163 memset( &_ifr, 0, sizeof( struct ifreq ) ); 163 memset( &_ifr, 0, sizeof( struct ifreq ) );
164 164
165 if ( _sfd == -1 ) 165 if ( _sfd == -1 )
166 { 166 {
167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name ); 167 qDebug( "ONetworkInterface::init(): Warning - can't get socket for device '%s'", (const char*) _name );
168 return; 168 return;
169 } 169 }
170} 170}
171 171
172 172
173bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const 173bool ONetworkInterface::ioctl( int call, ifreqstruct& ifreq ) const
174{ 174{
175 int result = ::ioctl( _sfd, call, &ifreq ); 175 int result = ::ioctl( _sfd, call, &ifreq );
176 if ( result == -1 ) 176 if ( result == -1 )
177 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) ); 177 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Failed: %d (%s)", call, result, strerror( errno ) );
178 else 178 else
179 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call ); 179 qDebug( "ONetworkInterface::ioctl(): Call %d - Status: Ok.", call );
180 return ( result != -1 ); 180 return ( result != -1 );
181} 181}
182 182
183 183
184bool ONetworkInterface::ioctl( int call ) const 184bool ONetworkInterface::ioctl( int call ) const
185{ 185{
186 strcpy( _ifr.ifr_name, (const char*) _name ); 186 strcpy( _ifr.ifr_name, (const char*) _name );
187 return ioctl( call, _ifr ); 187 return ioctl( call, _ifr );
188} 188}
189 189
190 190
191bool ONetworkInterface::isLoopback() const 191bool ONetworkInterface::isLoopback() const
192{ 192{
193 ioctl( SIOCGIFFLAGS ); 193 ioctl( SIOCGIFFLAGS );
194 return _ifr.ifr_flags & IFF_LOOPBACK; 194 return _ifr.ifr_flags & IFF_LOOPBACK;
195} 195}
196 196
197 197
198bool ONetworkInterface::setUp( bool b ) 198bool ONetworkInterface::setUp( bool b )
199{ 199{
200 ioctl( SIOCGIFFLAGS ); 200 ioctl( SIOCGIFFLAGS );
201 if ( b ) _ifr.ifr_flags |= IFF_UP; 201 if ( b ) _ifr.ifr_flags |= IFF_UP;
202 else _ifr.ifr_flags &= (~IFF_UP); 202 else _ifr.ifr_flags &= (~IFF_UP);
203 return ioctl( SIOCSIFFLAGS ); 203 return ioctl( SIOCSIFFLAGS );
204} 204}
205 205
206 206
207bool ONetworkInterface::isUp() const 207bool ONetworkInterface::isUp() const
208{ 208{
209 ioctl( SIOCGIFFLAGS ); 209 ioctl( SIOCGIFFLAGS );
210 return _ifr.ifr_flags & IFF_UP; 210 return _ifr.ifr_flags & IFF_UP;
211} 211}
212 212
213 213
214QString ONetworkInterface::ipV4Address() const 214QString ONetworkInterface::ipV4Address() const
215{ 215{
216 if ( ioctl( SIOCGIFADDR ) ) 216 if ( ioctl( SIOCGIFADDR ) )
217 { 217 {
218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; 218 struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr;
219 //FIXME: Use QHostAddress here 219 //FIXME: Use QHostAddress here
220 return QString( inet_ntoa( sa->sin_addr ) ); 220 return QString( inet_ntoa( sa->sin_addr ) );
221 } 221 }
222 else 222 else
223 return "<unknown>"; 223 return "<unknown>";
224} 224}
225 225
226 226
227OMacAddress ONetworkInterface::macAddress() const 227OMacAddress ONetworkInterface::macAddress() const
228{ 228{
229 if ( ioctl( SIOCGIFHWADDR ) ) 229 if ( ioctl( SIOCGIFHWADDR ) )
230 { 230 {
231 return OMacAddress( _ifr ); 231 return OMacAddress( _ifr );
232 } 232 }
233 else 233 else
234 { 234 {
235 return OMacAddress::unknown; 235 return OMacAddress::unknown;
236 } 236 }
237} 237}
238 238
239 239
240void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) 240void ONetworkInterface::setMonitoring( OMonitoringInterface* m )
241{ 241{
242 _mon = m; 242 _mon = m;
243 qDebug( "ONetwork::setMonitoring(): Installed monitoring interface '%s'", (const char*) m->name() ); 243 qDebug( "ONetwork::setMonitoring(): Installed monitoring driver '%s' on interface '%s'", (const char*) m->name(), (const char*) _name );
244} 244}
245 245
246 246
247OMonitoringInterface* ONetworkInterface::monitoring() const 247OMonitoringInterface* ONetworkInterface::monitoring() const
248{ 248{
249 return _mon; 249 return _mon;
250} 250}
251 251
252 252
253const QString& ONetworkInterface::name() const 253const QString& ONetworkInterface::name() const
254{ 254{
255 return _name; 255 return _name;
256} 256}
257 257
258 258
259ONetworkInterface::~ONetworkInterface() 259ONetworkInterface::~ONetworkInterface()
260{ 260{
261 qDebug( "ONetworkInterface::~ONetworkInterface()" ); 261 qDebug( "ONetworkInterface::~ONetworkInterface()" );
262 if ( _sfd != -1 ) ::close( _sfd ); 262 if ( _sfd != -1 ) ::close( _sfd );
263} 263}
264 264
265 265
266bool ONetworkInterface::setPromiscuousMode( bool b ) 266bool ONetworkInterface::setPromiscuousMode( bool b )
267{ 267{
268 ioctl( SIOCGIFFLAGS ); 268 ioctl( SIOCGIFFLAGS );
269 if ( b ) _ifr.ifr_flags |= IFF_PROMISC; 269 if ( b ) _ifr.ifr_flags |= IFF_PROMISC;
270 else _ifr.ifr_flags &= (~IFF_PROMISC); 270 else _ifr.ifr_flags &= (~IFF_PROMISC);
271 return ioctl( SIOCSIFFLAGS ); 271 return ioctl( SIOCSIFFLAGS );
272} 272}
273 273
274 274
275bool ONetworkInterface::promiscuousMode() const 275bool ONetworkInterface::promiscuousMode() const
276{ 276{
277 ioctl( SIOCGIFFLAGS ); 277 ioctl( SIOCGIFFLAGS );
278 return _ifr.ifr_flags & IFF_PROMISC; 278 return _ifr.ifr_flags & IFF_PROMISC;
279} 279}
280 280
281 281
282bool ONetworkInterface::isWireless() const 282bool ONetworkInterface::isWireless() const
283{ 283{
284 return ioctl( SIOCGIWNAME ); 284 return ioctl( SIOCGIWNAME );
285} 285}
286 286
287 287
288/*====================================================================================== 288/*======================================================================================
289 * OChannelHopper 289 * OChannelHopper
290 *======================================================================================*/ 290 *======================================================================================*/
291 291
292OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) 292OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface )
293 :QObject( 0, "Mickey's funky hopper" ), 293 :QObject( 0, "Mickey's funky hopper" ),
294 _iface( iface ), _interval( 0 ), _channel( 1 ), _tid( 0 ), 294 _iface( iface ), _interval( 0 ), _tid( 0 )
295 _maxChannel( iface->channels()+1 )
296{ 295{
296 int _maxChannel = iface->channels()+1;
297 // generate fancy hopping sequence honoring the device capabilities
298 if ( _maxChannel >= 1 ) _channels.append( 1 );
299 if ( _maxChannel >= 7 ) _channels.append( 7 );
300 if ( _maxChannel >= 13 ) _channels.append( 13 );
301 if ( _maxChannel >= 2 ) _channels.append( 2 );
302 if ( _maxChannel >= 8 ) _channels.append( 8 );
303 if ( _maxChannel >= 3 ) _channels.append( 3 );
304 if ( _maxChannel >= 14 ) _channels.append( 14 );
305 if ( _maxChannel >= 9 ) _channels.append( 9 );
306 if ( _maxChannel >= 4 ) _channels.append( 4 );
307 if ( _maxChannel >= 10 ) _channels.append( 10 );
308 if ( _maxChannel >= 5 ) _channels.append( 5 );
309 if ( _maxChannel >= 11 ) _channels.append( 11 );
310 if ( _maxChannel >= 6 ) _channels.append( 6 );
311 if ( _maxChannel >= 12 ) _channels.append( 12 );
312 _channel = _channels.begin();
313
297} 314}
298 315
299 316
300OChannelHopper::~OChannelHopper() 317OChannelHopper::~OChannelHopper()
301{ 318{
302} 319}
303 320
304 321
305bool OChannelHopper::isActive() const 322bool OChannelHopper::isActive() const
306{ 323{
307 return _tid; 324 return _tid;
308} 325}
309 326
310 327
311int OChannelHopper::channel() const 328int OChannelHopper::channel() const
312{ 329{
313 return _channel; 330 return *_channel;
314} 331}
315 332
316 333
317void OChannelHopper::timerEvent( QTimerEvent* ) 334void OChannelHopper::timerEvent( QTimerEvent* )
318{ 335{
319 if ( !--_channel ) _channel = _maxChannel; 336 _iface->setChannel( *_channel );
320 _iface->setChannel( _channel );
321 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'", 337 qDebug( "OChannelHopper::timerEvent(): set channel %d on interface '%s'",
322 _channel, (const char*) _iface->name() ); 338 *_channel, (const char*) _iface->name() );
339 if ( ++_channel == _channels.end() ) _channel = _channels.begin();
323} 340}
324 341
325 342
326void OChannelHopper::setInterval( int interval ) 343void OChannelHopper::setInterval( int interval )
327{ 344{
328 if ( interval == _interval ) 345 if ( interval == _interval )
329 return; 346 return;
330 347
331 if ( _interval ) 348 if ( _interval )
332 killTimer( _tid ); 349 killTimer( _tid );
333 350
334 _tid = 0; 351 _tid = 0;
335 _interval = interval; 352 _interval = interval;
336 353
337 if ( _interval ) 354 if ( _interval )
338 { 355 {
339 _tid = startTimer( interval ); 356 _tid = startTimer( interval );
340 } 357 }
341} 358}
342 359
343 360
344int OChannelHopper::interval() const 361int OChannelHopper::interval() const
345{ 362{
346 return _interval; 363 return _interval;
347} 364}
348 365
349 366
350/*====================================================================================== 367/*======================================================================================
351 * OWirelessNetworkInterface 368 * OWirelessNetworkInterface
352 *======================================================================================*/ 369 *======================================================================================*/
353 370
354OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name ) 371OWirelessNetworkInterface::OWirelessNetworkInterface( const QString& name )
355 :ONetworkInterface( name ), _hopper( 0 ) 372 :ONetworkInterface( name ), _hopper( 0 )
356{ 373{
357 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" ); 374 qDebug( "OWirelessNetworkInterface::OWirelessNetworkInterface()" );
358 init(); 375 init();
359} 376}
360 377
361 378
362OWirelessNetworkInterface::~OWirelessNetworkInterface() 379OWirelessNetworkInterface::~OWirelessNetworkInterface()
363{ 380{
364} 381}
365 382
366 383
367iwreqstruct& OWirelessNetworkInterface::iwr() const 384iwreqstruct& OWirelessNetworkInterface::iwr() const
368{ 385{
369 return _iwr; 386 return _iwr;
370} 387}
371 388
372 389
373void OWirelessNetworkInterface::init() 390void OWirelessNetworkInterface::init()
374{ 391{
375 qDebug( "OWirelessNetworkInterface::init()" ); 392 qDebug( "OWirelessNetworkInterface::init()" );
376 393
377 memset( &_iwr, 0, sizeof( struct iwreq ) ); 394 memset( &_iwr, 0, sizeof( struct iwreq ) );
378 395
379 // IEEE802.11(b) radio frequency channels 396 // IEEE802.11(b) radio frequency channels
380 397
381 iwrangestruct range; 398 iwrangestruct range;
382 //ML: work around an ugly HostAP bug, which needs 399 //ML: work around an ugly HostAP bug, which needs
383 //ML: extra space or will complain with "invalid argument length"... :-( 400 //ML: extra space or will complain with "invalid argument length"... :-(
384 char __extraBufferForBuggyDrivers[sizeof range]; 401 //ML: But don't allocate too much or prism2_usb will segfault *sigh*
402 char __extraBufferForBuggyDrivers[20];
403
404 qDebug( "sizeof(iwrangestruct)=%d, sizeof range=%d, sizeof range*2=%d", sizeof(iwrangestruct), sizeof range, (sizeof range)*2 );
405
385 _iwr.u.data.pointer = (char*) &range; 406 _iwr.u.data.pointer = (char*) &range;
386 _iwr.u.data.length = (sizeof range) * 2; 407 _iwr.u.data.length = sizeof(iwrangestruct)+20;
387 _iwr.u.data.flags = 0; 408 _iwr.u.data.flags = 0;
388 if ( !wioctl( SIOCGIWRANGE ) ) 409 if ( !wioctl( SIOCGIWRANGE ) )
389 { 410 {
390 qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) ); 411 qDebug( "OWirelessNetworkInterface::init(): SIOCGIWRANGE failed (%s)", strerror( errno ) );
391 return; 412 return;
392 } 413 }
393 414
415 qDebug( "OWirelessNetworkInterface::init(): Interface %s reported to have %d channels.", (const char*) _name, range.num_frequency );
416
394 for ( int i = 0; i < range.num_frequency; ++i ) 417 for ( int i = 0; i < range.num_frequency; ++i )
395 { 418 {
396 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); 419 int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 );
397 _channels.insert( freq, i+1 ); 420 _channels.insert( freq, i+1 );
398 } 421 }
399} 422}
400 423
401 424
402QString OWirelessNetworkInterface::associatedAP() const 425QString OWirelessNetworkInterface::associatedAP() const
403{ 426{
404 //FIXME: use OMacAddress 427 //FIXME: use OMacAddress
405 QString mac; 428 QString mac;
406 429
407 if ( ioctl( SIOCGIWAP ) ) 430 if ( ioctl( SIOCGIWAP ) )
408 { 431 {
409 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 432 mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
410 _ifr.ifr_hwaddr.sa_data[0]&0xff, 433 _ifr.ifr_hwaddr.sa_data[0]&0xff,
411 _ifr.ifr_hwaddr.sa_data[1]&0xff, 434 _ifr.ifr_hwaddr.sa_data[1]&0xff,
412 _ifr.ifr_hwaddr.sa_data[2]&0xff, 435 _ifr.ifr_hwaddr.sa_data[2]&0xff,
413 _ifr.ifr_hwaddr.sa_data[3]&0xff, 436 _ifr.ifr_hwaddr.sa_data[3]&0xff,
414 _ifr.ifr_hwaddr.sa_data[4]&0xff, 437 _ifr.ifr_hwaddr.sa_data[4]&0xff,
415 _ifr.ifr_hwaddr.sa_data[5]&0xff ); 438 _ifr.ifr_hwaddr.sa_data[5]&0xff );
416 } 439 }
417 else 440 else
418 { 441 {
419 mac = "<Unknown>"; 442 mac = "<Unknown>";
420 } 443 }
421 return mac; 444 return mac;
422} 445}
423 446
424 447
425int OWirelessNetworkInterface::channel() const 448int OWirelessNetworkInterface::channel() const
426{ 449{
427 //FIXME: When monitoring enabled, then use it 450 //FIXME: When monitoring enabled, then use it
428 //FIXME: to gather the current RF channel 451 //FIXME: to gather the current RF channel
429 //FIXME: Until then, get active channel from hopper. 452 //FIXME: Until then, get active channel from hopper.
430 if ( _hopper && _hopper->isActive() ) 453 if ( _hopper && _hopper->isActive() )
431 return _hopper->channel(); 454 return _hopper->channel();
432 455
433 if ( !wioctl( SIOCGIWFREQ ) ) 456 if ( !wioctl( SIOCGIWFREQ ) )
434 { 457 {
435 return -1; 458 return -1;
436 } 459 }
437 else 460 else
438 { 461 {
439 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; 462 return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ];
440 } 463 }
441} 464}
442 465
443 466
444void OWirelessNetworkInterface::setChannel( int c ) const 467void OWirelessNetworkInterface::setChannel( int c ) const
445{ 468{
446 if ( !_mon ) 469 if ( !_mon )
447 { 470 {
448 memset( &_iwr, 0, sizeof( iwreqstruct ) ); 471 memset( &_iwr, 0, sizeof( iwreqstruct ) );
449 _iwr.u.freq.m = c; 472 _iwr.u.freq.m = c;
450 _iwr.u.freq.e = 0; 473 _iwr.u.freq.e = 0;
451 wioctl( SIOCSIWFREQ ); 474 wioctl( SIOCSIWFREQ );
452 } 475 }
453 else 476 else
454 { 477 {
455 _mon->setChannel( c ); 478 _mon->setChannel( c );
456 } 479 }
457} 480}
458 481
459 482
460double OWirelessNetworkInterface::frequency() const 483double OWirelessNetworkInterface::frequency() const
461{ 484{
462 if ( !wioctl( SIOCGIWFREQ ) ) 485 if ( !wioctl( SIOCGIWFREQ ) )
463 { 486 {
464 return -1.0; 487 return -1.0;
465 } 488 }
466 else 489 else
467 { 490 {
468 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; 491 return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0;
469 } 492 }
470} 493}
471 494
472 495
473int OWirelessNetworkInterface::channels() const 496int OWirelessNetworkInterface::channels() const
474{ 497{
475 return _channels.count(); 498 return _channels.count();
476} 499}
477 500
478 501
479void OWirelessNetworkInterface::setChannelHopping( int interval ) 502void OWirelessNetworkInterface::setChannelHopping( int interval )
480{ 503{
481 if ( !_hopper ) _hopper = new OChannelHopper( this ); 504 if ( !_hopper ) _hopper = new OChannelHopper( this );
482 _hopper->setInterval( interval ); 505 _hopper->setInterval( interval );
483 //FIXME: When and by whom will the channel hopper be deleted? 506 //FIXME: When and by whom will the channel hopper be deleted?
484} 507}
485 508
486 509
487int OWirelessNetworkInterface::channelHopping() const 510int OWirelessNetworkInterface::channelHopping() const
488{ 511{
489 return _hopper->interval(); 512 return _hopper->interval();
490} 513}
491 514
492 515
493void OWirelessNetworkInterface::setMonitorMode( bool b ) 516void OWirelessNetworkInterface::setMonitorMode( bool b )
494{ 517{
495 if ( _mon ) 518 if ( _mon )
496 _mon->setEnabled( b ); 519 _mon->setEnabled( b );
497 else 520 else
498 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" ); 521 qDebug( "ONetwork(): can't switch monitor mode without installed monitoring interface" );
499} 522}
500 523
501 524
502bool OWirelessNetworkInterface::monitorMode() const 525bool OWirelessNetworkInterface::monitorMode() const
503{ 526{
504 return _mon ? _mon->enabled() : false; 527 return _mon ? _mon->enabled() : false;
505} 528}
506 529
507 530
508QString OWirelessNetworkInterface::nickName() const 531QString OWirelessNetworkInterface::nickName() const
509{ 532{
510 char str[IW_ESSID_MAX_SIZE]; 533 char str[IW_ESSID_MAX_SIZE];
511 _iwr.u.data.pointer = &str[0]; 534 _iwr.u.data.pointer = &str[0];
512 _iwr.u.data.length = IW_ESSID_MAX_SIZE; 535 _iwr.u.data.length = IW_ESSID_MAX_SIZE;
513 if ( !wioctl( SIOCGIWNICKN ) ) 536 if ( !wioctl( SIOCGIWNICKN ) )
514 { 537 {
515 return "<unknown>"; 538 return "<unknown>";
516 } 539 }
517 else 540 else
518 { 541 {
519 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string 542 str[_iwr.u.data.length] = 0x0; // some drivers (e.g. wlan-ng) don't zero-terminate the string
520 return str; 543 return str;
521 } 544 }
diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h
index c544454..b57ac3f 100644
--- a/libopie2/opienet/onetwork.h
+++ b/libopie2/opienet/onetwork.h
@@ -1,295 +1,297 @@
1/* 1/*
2                 This file is part of the Opie Project 2                 This file is part of the Opie Project
3              Copyright (C) 2003 by the Wellenreiter team: 3              Copyright (C) 2003 by the Wellenreiter team:
4 Martin J. Muench <mjm@remote-exploit.org> 4 Martin J. Muench <mjm@remote-exploit.org>
5 Max Moser <mmo@remote-exploit.org 5 Max Moser <mmo@remote-exploit.org
6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de> 6 Michael 'Mickey' Lauer <mickey@tm.informatik.uni-frankfurt.de>
7 =. 7 =.
8 .=l. 8 .=l.
9           .>+-= 9           .>+-=
10 _;:,     .>    :=|. This program is free software; you can 10 _;:,     .>    :=|. This program is free software; you can
11.> <`_,   >  .   <= redistribute it and/or modify it under 11.> <`_,   >  .   <= redistribute it and/or modify it under
12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public 12:`=1 )Y*s>-.--   : the terms of the GNU Library General Public
13.="- .-=="i,     .._ License as published by the Free Software 13.="- .-=="i,     .._ License as published by the Free Software
14 - .   .-<_>     .<> Foundation; either version 2 of the License, 14 - .   .-<_>     .<> Foundation; either version 2 of the License,
15     ._= =}       : or (at your option) any later version. 15     ._= =}       : or (at your option) any later version.
16    .%`+i>       _;_. 16    .%`+i>       _;_.
17    .i_,=:_.      -<s. This program is distributed in the hope that 17    .i_,=:_.      -<s. This program is distributed in the hope that
18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 18     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
19    : ..    .:,     . . . without even the implied warranty of 19    : ..    .:,     . . . without even the implied warranty of
20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 20    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU 21  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU
22..}^=.=       =       ; Library General Public License for more 22..}^=.=       =       ; Library General Public License for more
23++=   -.     .`     .: details. 23++=   -.     .`     .: details.
24 :     =  ...= . :.=- 24 :     =  ...= . :.=-
25 -.   .:....=;==+<; You should have received a copy of the GNU 25 -.   .:....=;==+<; You should have received a copy of the GNU
26  -_. . .   )=.  = Library General Public License along with 26  -_. . .   )=.  = Library General Public License along with
27    --        :-=` this library; see the file COPYING.LIB. 27    --        :-=` this library; see the file COPYING.LIB.
28 If not, write to the Free Software Foundation, 28 If not, write to the Free Software Foundation,
29 Inc., 59 Temple Place - Suite 330, 29 Inc., 59 Temple Place - Suite 330,
30 Boston, MA 02111-1307, USA. 30 Boston, MA 02111-1307, USA.
31 31
32*/ 32*/
33 33
34#ifndef ONETWORK_H 34#ifndef ONETWORK_H
35#define ONETWORK_H 35#define ONETWORK_H
36 36
37/* QT */ 37/* QT */
38 38
39#include <qvaluelist.h>
39#include <qdict.h> 40#include <qdict.h>
40#include <qmap.h> 41#include <qmap.h>
41#include <qobject.h> 42#include <qobject.h>
42#include <qhostaddress.h> 43#include <qhostaddress.h>
43 44
44/* OPIE */ 45/* OPIE */
45 46
46#include <opie2/onetutils.h> 47#include <opie2/onetutils.h>
47 48
48#ifndef IFNAMSIZ 49#ifndef IFNAMSIZ
49#define IFNAMSIZ 16 50#define IFNAMSIZ 16
50#endif 51#endif
51 52
52// ML: Yeah, I hate to include kernel headers, but it's necessary here 53// ML: Yeah, I hate to include kernel headers, but it's necessary here
53// ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h> 54// ML: Here comes an ugly hack to prevent <linux/wireless.h> including <linux/if.h>
54// ML: which conflicts with the user header <net/if.h> 55// ML: which conflicts with the user header <net/if.h>
55// ML: We really a user header for the Wireless Extensions, something like <net/wireless.h> 56// ML: We really a user header for the Wireless Extensions, something like <net/wireless.h>
56// ML: I will drop Jean an mail on that subject 57// ML: I will drop Jean an mail on that subject
57 58
58#include <net/if.h> 59#include <net/if.h>
59#define _LINUX_IF_H 60#define _LINUX_IF_H
60#include <linux/wireless.h> 61#include <linux/wireless.h>
61 62
62#ifndef SIOCIWFIRSTPRIV 63#ifndef SIOCIWFIRSTPRIV
63#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE 64#define SIOCIWFIRSTPRIV SIOCDEVPRIVATE
64#endif 65#endif
65 66
66class ONetworkInterface; 67class ONetworkInterface;
67class OWirelessNetworkInterface; 68class OWirelessNetworkInterface;
68class OChannelHopper; 69class OChannelHopper;
69class OMonitoringInterface; 70class OMonitoringInterface;
70 71
71typedef struct ifreq ifreqstruct; 72typedef struct ifreq ifreqstruct;
72typedef struct iwreq iwreqstruct; 73typedef struct iwreq iwreqstruct;
73typedef struct iw_event iweventstruct; 74typedef struct iw_event iweventstruct;
74typedef struct iw_freq iwfreqstruct; 75typedef struct iw_freq iwfreqstruct;
75typedef struct iw_priv_args iwprivargsstruct; 76typedef struct iw_priv_args iwprivargsstruct;
76typedef struct iw_range iwrangestruct; 77typedef struct iw_range iwrangestruct;
77 78
78/*====================================================================================== 79/*======================================================================================
79 * ONetwork 80 * ONetwork
80 *======================================================================================*/ 81 *======================================================================================*/
81 82
82class ONetwork : public QObject 83class ONetwork : public QObject
83{ 84{
84 Q_OBJECT 85 Q_OBJECT
85 86
86 public: 87 public:
87 typedef QDict<ONetworkInterface> InterfaceMap; 88 typedef QDict<ONetworkInterface> InterfaceMap;
88 typedef QDictIterator<ONetworkInterface> InterfaceIterator; 89 typedef QDictIterator<ONetworkInterface> InterfaceIterator;
89 90
90 public: 91 public:
91 static ONetwork* instance(); 92 static ONetwork* instance();
92 InterfaceIterator iterator() const; 93 InterfaceIterator iterator() const;
93 bool isWirelessInterface( const char* ) const; 94 bool isWirelessInterface( const char* ) const;
94 ONetworkInterface* interface( QString ) const; 95 ONetworkInterface* interface( QString ) const;
95 96
96 protected: 97 protected:
97 ONetwork(); 98 ONetwork();
98 void synchronize(); 99 void synchronize();
99 100
100 private: 101 private:
101 static ONetwork* _instance; 102 static ONetwork* _instance;
102 InterfaceMap _interfaces; 103 InterfaceMap _interfaces;
103}; 104};
104 105
105 106
106/*====================================================================================== 107/*======================================================================================
107 * ONetworkInterface 108 * ONetworkInterface
108 *======================================================================================*/ 109 *======================================================================================*/
109 110
110class ONetworkInterface 111class ONetworkInterface
111{ 112{
112 friend class OMonitoringInterface; 113 friend class OMonitoringInterface;
113 friend class OCiscoMonitoringInterface; 114 friend class OCiscoMonitoringInterface;
114 friend class OWlanNGMonitoringInterface; 115 friend class OWlanNGMonitoringInterface;
115 friend class OHostAPMonitoringInterface; 116 friend class OHostAPMonitoringInterface;
116 friend class OOrinocoMonitoringInterface; 117 friend class OOrinocoMonitoringInterface;
117 118
118 public: 119 public:
119 ONetworkInterface( const QString& name ); 120 ONetworkInterface( const QString& name );
120 virtual ~ONetworkInterface(); 121 virtual ~ONetworkInterface();
121 122
122 const QString& name() const; 123 const QString& name() const;
123 void setMonitoring( OMonitoringInterface* ); 124 void setMonitoring( OMonitoringInterface* );
124 OMonitoringInterface* monitoring() const; 125 OMonitoringInterface* monitoring() const;
125 bool setPromiscuousMode( bool ); 126 bool setPromiscuousMode( bool );
126 bool promiscuousMode() const; 127 bool promiscuousMode() const;
127 bool setUp( bool ); 128 bool setUp( bool );
128 bool isUp() const; 129 bool isUp() const;
129 bool isLoopback() const; 130 bool isLoopback() const;
130 bool isWireless() const; 131 bool isWireless() const;
131 QString ipV4Address() const; 132 QString ipV4Address() const;
132 OMacAddress macAddress() const; 133 OMacAddress macAddress() const;
133 134
134 protected: 135 protected:
135 const QString _name; 136 const QString _name;
136 const int _sfd; 137 const int _sfd;
137 mutable ifreqstruct _ifr; 138 mutable ifreqstruct _ifr;
138 OMonitoringInterface* _mon; 139 OMonitoringInterface* _mon;
139 140
140 protected: 141 protected:
141 ifreqstruct& ifr() const; 142 ifreqstruct& ifr() const;
142 virtual void init(); 143 virtual void init();
143 bool ioctl( int call ) const; 144 bool ioctl( int call ) const;
144 bool ioctl( int call, ifreqstruct& ) const; 145 bool ioctl( int call, ifreqstruct& ) const;
145}; 146};
146 147
147/*====================================================================================== 148/*======================================================================================
148 * OChannelHopper 149 * OChannelHopper
149 *======================================================================================*/ 150 *======================================================================================*/
150 151
151class OChannelHopper : public QObject 152class OChannelHopper : public QObject
152{ 153{
153 public: 154 public:
154 OChannelHopper( OWirelessNetworkInterface* ); 155 OChannelHopper( OWirelessNetworkInterface* );
155 virtual ~OChannelHopper(); 156 virtual ~OChannelHopper();
156 bool isActive() const; 157 bool isActive() const;
157 int channel() const; 158 int channel() const;
158 virtual void timerEvent( QTimerEvent* ); 159 virtual void timerEvent( QTimerEvent* );
159 void setInterval( int ); 160 void setInterval( int );
160 int interval() const; 161 int interval() const;
161 162
162 private: 163 private:
163 OWirelessNetworkInterface* _iface; 164 OWirelessNetworkInterface* _iface;
164 int _interval; 165 int _interval;
165 int _channel;
166 int _tid; 166 int _tid;
167 int _maxChannel; 167 QValueList<int> _channels;
168 QValueList<int>::Iterator _channel;
169
168}; 170};
169 171
170 172
171/*====================================================================================== 173/*======================================================================================
172 * OWirelessNetworkInterface 174 * OWirelessNetworkInterface
173 *======================================================================================*/ 175 *======================================================================================*/
174 176
175class OWirelessNetworkInterface : public ONetworkInterface 177class OWirelessNetworkInterface : public ONetworkInterface
176{ 178{
177 friend class OMonitoringInterface; 179 friend class OMonitoringInterface;
178 friend class OCiscoMonitoringInterface; 180 friend class OCiscoMonitoringInterface;
179 friend class OWlanNGMonitoringInterface; 181 friend class OWlanNGMonitoringInterface;
180 friend class OHostAPMonitoringInterface; 182 friend class OHostAPMonitoringInterface;
181 friend class OOrinocoMonitoringInterface; 183 friend class OOrinocoMonitoringInterface;
182 184
183 public: 185 public:
184 enum Mode { AdHoc, Managed, Monitor }; 186 enum Mode { AdHoc, Managed, Monitor };
185 187
186 OWirelessNetworkInterface( const QString& name ); 188 OWirelessNetworkInterface( const QString& name );
187 virtual ~OWirelessNetworkInterface(); 189 virtual ~OWirelessNetworkInterface();
188 190
189 virtual void setChannel( int ) const; 191 virtual void setChannel( int ) const;
190 virtual int channel() const; 192 virtual int channel() const;
191 virtual double frequency() const; 193 virtual double frequency() const;
192 virtual int channels() const; 194 virtual int channels() const;
193 //virtual double frequency(int) const; 195 //virtual double frequency(int) const;
194 196
195 virtual void setMode( Mode ) {}; 197 virtual void setMode( Mode ) {};
196 virtual bool mode() const {}; 198 virtual bool mode() const {};
197 199
198 virtual void setMonitorMode( bool ); 200 virtual void setMonitorMode( bool );
199 virtual bool monitorMode() const; 201 virtual bool monitorMode() const;
200 202
201 virtual void setChannelHopping( int interval = 0 ); 203 virtual void setChannelHopping( int interval = 0 );
202 virtual int channelHopping() const; 204 virtual int channelHopping() const;
203 205
204 virtual void setNickName( const QString& ) {}; 206 virtual void setNickName( const QString& ) {};
205 virtual QString nickName() const; 207 virtual QString nickName() const;
206 208
207 virtual bool isAssociated() const {}; 209 virtual bool isAssociated() const {};
208 virtual QString associatedAP() const; 210 virtual QString associatedAP() const;
209 211
210 virtual void setSSID( const QString& ); 212 virtual void setSSID( const QString& );
211 virtual QString SSID() const; 213 virtual QString SSID() const;
212 214
213 protected: 215 protected:
214 mutable iwreqstruct _iwr; 216 mutable iwreqstruct _iwr;
215 QMap<int,int> _channels; 217 QMap<int,int> _channels;
216 218
217 protected: 219 protected:
218 virtual void init(); 220 virtual void init();
219 iwreqstruct& iwr() const; 221 iwreqstruct& iwr() const;
220 bool wioctl( int call ) const; 222 bool wioctl( int call ) const;
221 bool wioctl( int call, iwreqstruct& ) const; 223 bool wioctl( int call, iwreqstruct& ) const;
222 224
223 private: 225 private:
224 OChannelHopper* _hopper; 226 OChannelHopper* _hopper;
225}; 227};
226 228
227 229
228/*====================================================================================== 230/*======================================================================================
229 * OMonitoringInterface 231 * OMonitoringInterface
230 *======================================================================================*/ 232 *======================================================================================*/
231 233
232 234
233class OMonitoringInterface 235class OMonitoringInterface
234{ 236{
235 public: 237 public:
236 OMonitoringInterface(); 238 OMonitoringInterface();
237 OMonitoringInterface( ONetworkInterface* ); 239 OMonitoringInterface( ONetworkInterface* );
238 virtual ~OMonitoringInterface(); 240 virtual ~OMonitoringInterface();
239 241
240 public: 242 public:
241 virtual void setEnabled( bool ); 243 virtual void setEnabled( bool );
242 virtual bool enabled() const; 244 virtual bool enabled() const;
243 virtual void setChannel( int ); 245 virtual void setChannel( int );
244 246
245 virtual QString name() const = 0; 247 virtual QString name() const = 0;
246 248
247 protected: 249 protected:
248 bool _enabled; 250 bool _enabled;
249 const OWirelessNetworkInterface* _if; 251 const OWirelessNetworkInterface* _if;
250 252
251}; 253};
252 254
253 255
254/*====================================================================================== 256/*======================================================================================
255 * OCiscoMonitoring 257 * OCiscoMonitoring
256 *======================================================================================*/ 258 *======================================================================================*/
257 259
258 260
259class OCiscoMonitoringInterface : public OMonitoringInterface 261class OCiscoMonitoringInterface : public OMonitoringInterface
260{ 262{
261 public: 263 public:
262 OCiscoMonitoringInterface( ONetworkInterface* ); 264 OCiscoMonitoringInterface( ONetworkInterface* );
263 virtual ~OCiscoMonitoringInterface(); 265 virtual ~OCiscoMonitoringInterface();
264 266
265 virtual void setEnabled( bool ); 267 virtual void setEnabled( bool );
266 virtual QString name() const; 268 virtual QString name() const;
267 virtual void setChannel( int ); 269 virtual void setChannel( int );
268 270
269}; 271};
270 272
271/*====================================================================================== 273/*======================================================================================
272 * OWlanNGMonitoringInterface 274 * OWlanNGMonitoringInterface
273 *======================================================================================*/ 275 *======================================================================================*/
274 276
275class OWlanNGMonitoringInterface : public OMonitoringInterface 277class OWlanNGMonitoringInterface : public OMonitoringInterface
276{ 278{
277 public: 279 public:
278 OWlanNGMonitoringInterface( ONetworkInterface* ); 280 OWlanNGMonitoringInterface( ONetworkInterface* );
279 virtual ~OWlanNGMonitoringInterface(); 281 virtual ~OWlanNGMonitoringInterface();
280 282
281 public: 283 public:
282 virtual void setEnabled( bool ); 284 virtual void setEnabled( bool );
283 virtual QString name() const; 285 virtual QString name() const;
284 virtual void setChannel( int ); 286 virtual void setChannel( int );
285 287
286}; 288};
287 289
288/*====================================================================================== 290/*======================================================================================
289 * OHostAPMonitoringInterface 291 * OHostAPMonitoringInterface
290 *======================================================================================*/ 292 *======================================================================================*/
291 293
292class OHostAPMonitoringInterface : public OMonitoringInterface 294class OHostAPMonitoringInterface : public OMonitoringInterface
293{ 295{
294 public: 296 public:
295 OHostAPMonitoringInterface( ONetworkInterface* ); 297 OHostAPMonitoringInterface( ONetworkInterface* );