author | mickeyl <mickeyl> | 2005-05-15 13:41:19 (UTC) |
---|---|---|
committer | mickeyl <mickeyl> | 2005-05-15 13:41:19 (UTC) |
commit | 1de015fb8f267f2451dd26d992cc713e6e02af79 (patch) (unidiff) | |
tree | a82bcaf6bce0b713910de85450a83862b2d0a73a | |
parent | 4451abf402aa1dd967ef8b70a7eba1192f13afb0 (diff) | |
download | opie-1de015fb8f267f2451dd26d992cc713e6e02af79.zip opie-1de015fb8f267f2451dd26d992cc713e6e02af79.tar.gz opie-1de015fb8f267f2451dd26d992cc713e6e02af79.tar.bz2 |
submit iw_range*2 as argument to SIOCGIWRANGE.length to make it work on newer hostap drivers
let's see if this breaks it at another end again :/
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index f4bdbe0..05513f8 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -276,588 +276,586 @@ QString ONetworkInterface::ipV4Address() const | |||
276 | //FIXME: Use QHostAddress here | 276 | //FIXME: Use QHostAddress here |
277 | return QString( inet_ntoa( sa->sin_addr ) ); | 277 | return QString( inet_ntoa( sa->sin_addr ) ); |
278 | } | 278 | } |
279 | else | 279 | else |
280 | return "<unknown>"; | 280 | return "<unknown>"; |
281 | 281 | ||
282 | } | 282 | } |
283 | 283 | ||
284 | 284 | ||
285 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) | 285 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) |
286 | { | 286 | { |
287 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | 287 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
288 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); | 288 | memcpy( &_ifr.ifr_hwaddr.sa_data, addr.native(), 6 ); |
289 | ioctl( SIOCSIFHWADDR ); | 289 | ioctl( SIOCSIFHWADDR ); |
290 | } | 290 | } |
291 | 291 | ||
292 | 292 | ||
293 | OMacAddress ONetworkInterface::macAddress() const | 293 | OMacAddress ONetworkInterface::macAddress() const |
294 | { | 294 | { |
295 | if ( ioctl( SIOCGIFHWADDR ) ) | 295 | if ( ioctl( SIOCGIFHWADDR ) ) |
296 | { | 296 | { |
297 | return OMacAddress( _ifr ); | 297 | return OMacAddress( _ifr ); |
298 | } | 298 | } |
299 | else | 299 | else |
300 | { | 300 | { |
301 | return OMacAddress::unknown; | 301 | return OMacAddress::unknown; |
302 | } | 302 | } |
303 | } | 303 | } |
304 | 304 | ||
305 | 305 | ||
306 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) | 306 | void ONetworkInterface::setIPV4Netmask( const QHostAddress& addr ) |
307 | { | 307 | { |
308 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 308 | struct sockaddr_in *sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
309 | sa->sin_family = AF_INET; | 309 | sa->sin_family = AF_INET; |
310 | sa->sin_port = 0; | 310 | sa->sin_port = 0; |
311 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); | 311 | sa->sin_addr.s_addr = htonl( addr.ip4Addr() ); |
312 | ioctl( SIOCSIFNETMASK ); | 312 | ioctl( SIOCSIFNETMASK ); |
313 | } | 313 | } |
314 | 314 | ||
315 | 315 | ||
316 | QString ONetworkInterface::ipV4Netmask() const | 316 | QString ONetworkInterface::ipV4Netmask() const |
317 | { | 317 | { |
318 | if ( ioctl( SIOCGIFNETMASK ) ) | 318 | if ( ioctl( SIOCGIFNETMASK ) ) |
319 | { | 319 | { |
320 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 320 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
321 | //FIXME: Use QHostAddress here | 321 | //FIXME: Use QHostAddress here |
322 | return QString( inet_ntoa( sa->sin_addr ) ); | 322 | return QString( inet_ntoa( sa->sin_addr ) ); |
323 | } | 323 | } |
324 | else | 324 | else |
325 | return "<unknown>"; | 325 | return "<unknown>"; |
326 | } | 326 | } |
327 | 327 | ||
328 | 328 | ||
329 | int ONetworkInterface::dataLinkType() const | 329 | int ONetworkInterface::dataLinkType() const |
330 | { | 330 | { |
331 | if ( ioctl( SIOCGIFHWADDR ) ) | 331 | if ( ioctl( SIOCGIFHWADDR ) ) |
332 | { | 332 | { |
333 | return _ifr.ifr_hwaddr.sa_family; | 333 | return _ifr.ifr_hwaddr.sa_family; |
334 | } | 334 | } |
335 | else | 335 | else |
336 | { | 336 | { |
337 | return -1; | 337 | return -1; |
338 | } | 338 | } |
339 | } | 339 | } |
340 | 340 | ||
341 | 341 | ||
342 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) | 342 | void ONetworkInterface::setMonitoring( OMonitoringInterface* m ) |
343 | { | 343 | { |
344 | _mon = m; | 344 | _mon = m; |
345 | odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl; | 345 | odebug << "ONetwork::setMonitoring(): Installed monitoring driver '" << m->name() << "' on interface '" << name() << "'" << oendl; |
346 | } | 346 | } |
347 | 347 | ||
348 | 348 | ||
349 | OMonitoringInterface* ONetworkInterface::monitoring() const | 349 | OMonitoringInterface* ONetworkInterface::monitoring() const |
350 | { | 350 | { |
351 | return _mon; | 351 | return _mon; |
352 | } | 352 | } |
353 | 353 | ||
354 | 354 | ||
355 | ONetworkInterface::~ONetworkInterface() | 355 | ONetworkInterface::~ONetworkInterface() |
356 | { | 356 | { |
357 | odebug << "ONetworkInterface::~ONetworkInterface()" << oendl; | 357 | odebug << "ONetworkInterface::~ONetworkInterface()" << oendl; |
358 | if ( _sfd != -1 ) ::close( _sfd ); | 358 | if ( _sfd != -1 ) ::close( _sfd ); |
359 | } | 359 | } |
360 | 360 | ||
361 | 361 | ||
362 | bool ONetworkInterface::setPromiscuousMode( bool b ) | 362 | bool ONetworkInterface::setPromiscuousMode( bool b ) |
363 | { | 363 | { |
364 | ioctl( SIOCGIFFLAGS ); | 364 | ioctl( SIOCGIFFLAGS ); |
365 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; | 365 | if ( b ) _ifr.ifr_flags |= IFF_PROMISC; |
366 | else _ifr.ifr_flags &= (~IFF_PROMISC); | 366 | else _ifr.ifr_flags &= (~IFF_PROMISC); |
367 | return ioctl( SIOCSIFFLAGS ); | 367 | return ioctl( SIOCSIFFLAGS ); |
368 | } | 368 | } |
369 | 369 | ||
370 | 370 | ||
371 | bool ONetworkInterface::promiscuousMode() const | 371 | bool ONetworkInterface::promiscuousMode() const |
372 | { | 372 | { |
373 | ioctl( SIOCGIFFLAGS ); | 373 | ioctl( SIOCGIFFLAGS ); |
374 | return _ifr.ifr_flags & IFF_PROMISC; | 374 | return _ifr.ifr_flags & IFF_PROMISC; |
375 | } | 375 | } |
376 | 376 | ||
377 | 377 | ||
378 | bool ONetworkInterface::isWireless() const | 378 | bool ONetworkInterface::isWireless() const |
379 | { | 379 | { |
380 | return ioctl( SIOCGIWNAME ); | 380 | return ioctl( SIOCGIWNAME ); |
381 | } | 381 | } |
382 | 382 | ||
383 | 383 | ||
384 | /*====================================================================================== | 384 | /*====================================================================================== |
385 | * OChannelHopper | 385 | * OChannelHopper |
386 | *======================================================================================*/ | 386 | *======================================================================================*/ |
387 | 387 | ||
388 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) | 388 | OChannelHopper::OChannelHopper( OWirelessNetworkInterface* iface ) |
389 | :QObject( 0, "Mickey's funky hopper" ), | 389 | :QObject( 0, "Mickey's funky hopper" ), |
390 | _iface( iface ), _interval( 0 ), _tid( 0 ) | 390 | _iface( iface ), _interval( 0 ), _tid( 0 ) |
391 | { | 391 | { |
392 | int _maxChannel = iface->channels(); | 392 | int _maxChannel = iface->channels(); |
393 | // generate fancy hopping sequence honoring the device capabilities | 393 | // generate fancy hopping sequence honoring the device capabilities |
394 | if ( _maxChannel >= 1 ) _channels.append( 1 ); | 394 | if ( _maxChannel >= 1 ) _channels.append( 1 ); |
395 | if ( _maxChannel >= 7 ) _channels.append( 7 ); | 395 | if ( _maxChannel >= 7 ) _channels.append( 7 ); |
396 | if ( _maxChannel >= 13 ) _channels.append( 13 ); | 396 | if ( _maxChannel >= 13 ) _channels.append( 13 ); |
397 | if ( _maxChannel >= 2 ) _channels.append( 2 ); | 397 | if ( _maxChannel >= 2 ) _channels.append( 2 ); |
398 | if ( _maxChannel >= 8 ) _channels.append( 8 ); | 398 | if ( _maxChannel >= 8 ) _channels.append( 8 ); |
399 | if ( _maxChannel >= 3 ) _channels.append( 3 ); | 399 | if ( _maxChannel >= 3 ) _channels.append( 3 ); |
400 | if ( _maxChannel >= 14 ) _channels.append( 14 ); | 400 | if ( _maxChannel >= 14 ) _channels.append( 14 ); |
401 | if ( _maxChannel >= 9 ) _channels.append( 9 ); | 401 | if ( _maxChannel >= 9 ) _channels.append( 9 ); |
402 | if ( _maxChannel >= 4 ) _channels.append( 4 ); | 402 | if ( _maxChannel >= 4 ) _channels.append( 4 ); |
403 | if ( _maxChannel >= 10 ) _channels.append( 10 ); | 403 | if ( _maxChannel >= 10 ) _channels.append( 10 ); |
404 | if ( _maxChannel >= 5 ) _channels.append( 5 ); | 404 | if ( _maxChannel >= 5 ) _channels.append( 5 ); |
405 | if ( _maxChannel >= 11 ) _channels.append( 11 ); | 405 | if ( _maxChannel >= 11 ) _channels.append( 11 ); |
406 | if ( _maxChannel >= 6 ) _channels.append( 6 ); | 406 | if ( _maxChannel >= 6 ) _channels.append( 6 ); |
407 | if ( _maxChannel >= 12 ) _channels.append( 12 ); | 407 | if ( _maxChannel >= 12 ) _channels.append( 12 ); |
408 | _channel = _channels.begin(); | 408 | _channel = _channels.begin(); |
409 | } | 409 | } |
410 | 410 | ||
411 | 411 | ||
412 | OChannelHopper::~OChannelHopper() | 412 | OChannelHopper::~OChannelHopper() |
413 | { | 413 | { |
414 | } | 414 | } |
415 | 415 | ||
416 | 416 | ||
417 | bool OChannelHopper::isActive() const | 417 | bool OChannelHopper::isActive() const |
418 | { | 418 | { |
419 | return _tid; | 419 | return _tid; |
420 | } | 420 | } |
421 | 421 | ||
422 | 422 | ||
423 | int OChannelHopper::channel() const | 423 | int OChannelHopper::channel() const |
424 | { | 424 | { |
425 | return *_channel; | 425 | return *_channel; |
426 | } | 426 | } |
427 | 427 | ||
428 | 428 | ||
429 | void OChannelHopper::timerEvent( QTimerEvent* ) | 429 | void OChannelHopper::timerEvent( QTimerEvent* ) |
430 | { | 430 | { |
431 | _iface->setChannel( *_channel ); | 431 | _iface->setChannel( *_channel ); |
432 | emit( hopped( *_channel ) ); | 432 | emit( hopped( *_channel ) ); |
433 | odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl; | 433 | odebug << "OChannelHopper::timerEvent(): set channel " << *_channel << " on interface '" << _iface->name() << "'" << oendl; |
434 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); | 434 | if ( ++_channel == _channels.end() ) _channel = _channels.begin(); |
435 | } | 435 | } |
436 | 436 | ||
437 | 437 | ||
438 | void OChannelHopper::setInterval( int interval ) | 438 | void OChannelHopper::setInterval( int interval ) |
439 | { | 439 | { |
440 | if ( interval == _interval ) | 440 | if ( interval == _interval ) |
441 | return; | 441 | return; |
442 | 442 | ||
443 | if ( _interval ) | 443 | if ( _interval ) |
444 | killTimer( _tid ); | 444 | killTimer( _tid ); |
445 | 445 | ||
446 | _tid = 0; | 446 | _tid = 0; |
447 | _interval = interval; | 447 | _interval = interval; |
448 | 448 | ||
449 | if ( _interval ) | 449 | if ( _interval ) |
450 | { | 450 | { |
451 | _tid = startTimer( interval ); | 451 | _tid = startTimer( interval ); |
452 | } | 452 | } |
453 | } | 453 | } |
454 | 454 | ||
455 | 455 | ||
456 | int OChannelHopper::interval() const | 456 | int OChannelHopper::interval() const |
457 | { | 457 | { |
458 | return _interval; | 458 | return _interval; |
459 | } | 459 | } |
460 | 460 | ||
461 | 461 | ||
462 | /*====================================================================================== | 462 | /*====================================================================================== |
463 | * OWirelessNetworkInterface | 463 | * OWirelessNetworkInterface |
464 | *======================================================================================*/ | 464 | *======================================================================================*/ |
465 | 465 | ||
466 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) | 466 | OWirelessNetworkInterface::OWirelessNetworkInterface( QObject* parent, const char* name ) |
467 | :ONetworkInterface( parent, name ), _hopper( 0 ) | 467 | :ONetworkInterface( parent, name ), _hopper( 0 ) |
468 | { | 468 | { |
469 | odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl; | 469 | odebug << "OWirelessNetworkInterface::OWirelessNetworkInterface()" << oendl; |
470 | init(); | 470 | init(); |
471 | } | 471 | } |
472 | 472 | ||
473 | 473 | ||
474 | OWirelessNetworkInterface::~OWirelessNetworkInterface() | 474 | OWirelessNetworkInterface::~OWirelessNetworkInterface() |
475 | { | 475 | { |
476 | } | 476 | } |
477 | 477 | ||
478 | 478 | ||
479 | struct iwreq& OWirelessNetworkInterface::iwr() const | 479 | struct iwreq& OWirelessNetworkInterface::iwr() const |
480 | { | 480 | { |
481 | return _iwr; | 481 | return _iwr; |
482 | } | 482 | } |
483 | 483 | ||
484 | 484 | ||
485 | void OWirelessNetworkInterface::init() | 485 | void OWirelessNetworkInterface::init() |
486 | { | 486 | { |
487 | odebug << "OWirelessNetworkInterface::init()" << oendl; | 487 | odebug << "OWirelessNetworkInterface::init()" << oendl; |
488 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 488 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
489 | buildInformation(); | 489 | buildInformation(); |
490 | buildPrivateList(); | 490 | buildPrivateList(); |
491 | dumpInformation(); | 491 | dumpInformation(); |
492 | } | 492 | } |
493 | 493 | ||
494 | 494 | ||
495 | bool OWirelessNetworkInterface::isAssociated() const | 495 | bool OWirelessNetworkInterface::isAssociated() const |
496 | { | 496 | { |
497 | //FIXME: handle different modes | 497 | //FIXME: handle different modes |
498 | return !(associatedAP() == OMacAddress::unknown); | 498 | return !(associatedAP() == OMacAddress::unknown); |
499 | } | 499 | } |
500 | 500 | ||
501 | 501 | ||
502 | void OWirelessNetworkInterface::setAssociatedAP( const OMacAddress& mac ) const | 502 | void OWirelessNetworkInterface::setAssociatedAP( const OMacAddress& mac ) const |
503 | { | 503 | { |
504 | _iwr.u.ap_addr.sa_family = ARPHRD_ETHER; | 504 | _iwr.u.ap_addr.sa_family = ARPHRD_ETHER; |
505 | ::memcpy(_iwr.u.ap_addr.sa_data, mac.native(), ETH_ALEN); | 505 | ::memcpy(_iwr.u.ap_addr.sa_data, mac.native(), ETH_ALEN); |
506 | wioctl( SIOCSIWAP ); | 506 | wioctl( SIOCSIWAP ); |
507 | } | 507 | } |
508 | 508 | ||
509 | 509 | ||
510 | OMacAddress OWirelessNetworkInterface::associatedAP() const | 510 | OMacAddress OWirelessNetworkInterface::associatedAP() const |
511 | { | 511 | { |
512 | if ( ioctl( SIOCGIWAP ) ) | 512 | if ( ioctl( SIOCGIWAP ) ) |
513 | return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; | 513 | return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; |
514 | else | 514 | else |
515 | return OMacAddress::unknown; | 515 | return OMacAddress::unknown; |
516 | } | 516 | } |
517 | 517 | ||
518 | 518 | ||
519 | void OWirelessNetworkInterface::buildInformation() | 519 | void OWirelessNetworkInterface::buildInformation() |
520 | { | 520 | { |
521 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 521 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
522 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete | 522 | //ML: The HostAP drivers need more than sizeof struct_iw range to complete |
523 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". | 523 | //ML: SIOCGIWRANGE otherwise they fail with "Invalid Argument Length". |
524 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate | 524 | //ML: The Wlan-NG drivers on the otherside fail (segfault!) if you allocate |
525 | //ML: _too much_ space. This is damn shitty crap *sigh* | 525 | //ML: _too much_ space. This is damn shitty crap *sigh* |
526 | //ML: We allocate a large memory region in RAM and check whether the | 526 | //ML: We allocate a large memory region in RAM and check whether the |
527 | //ML: driver pollutes this extra space. The complaint will be made on stdout, | 527 | //ML: driver pollutes this extra space. The complaint will be made on stdout, |
528 | //ML: so please forward this... | 528 | //ML: so please forward this... |
529 | 529 | ||
530 | struct iwreq wrq; | 530 | struct iwreq wrq; |
531 | int len = sizeof( struct iw_range )*2; | 531 | int len = sizeof( struct iw_range )*2; |
532 | char *buffer = (char*) malloc( len ); | 532 | char buffer[len]; |
533 | //FIXME: Validate if we actually got the memory block | ||
534 | memset( buffer, 0, len ); | 533 | memset( buffer, 0, len ); |
535 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); | 534 | memcpy( wrq.ifr_name, name(), IFNAMSIZ); |
536 | wrq.u.data.pointer = (caddr_t) buffer; | 535 | wrq.u.data.pointer = (caddr_t) buffer; |
537 | wrq.u.data.length = sizeof( struct iw_range ); | 536 | wrq.u.data.length = sizeof buffer; |
538 | wrq.u.data.flags = 0; | 537 | wrq.u.data.flags = 0; |
539 | 538 | ||
540 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) | 539 | if ( ::ioctl( _sfd, SIOCGIWRANGE, &wrq ) == -1 ) |
541 | { | 540 | { |
542 | owarn << "OWirelessNetworkInterface::buildInformation(): Can't get channel information - using default values." << oendl; | 541 | owarn << "OWirelessNetworkInterface::buildInformation(): Can't get driver information (" << strerror( errno ) << ") - using default values." << oendl; |
543 | _channels.insert( 2412, 1 ); // 2.412 GHz | 542 | _channels.insert( 2412, 1 ); // 2.412 GHz |
544 | _channels.insert( 2417, 2 ); // 2.417 GHz | 543 | _channels.insert( 2417, 2 ); // 2.417 GHz |
545 | _channels.insert( 2422, 3 ); // 2.422 GHz | 544 | _channels.insert( 2422, 3 ); // 2.422 GHz |
546 | _channels.insert( 2427, 4 ); // 2.427 GHz | 545 | _channels.insert( 2427, 4 ); // 2.427 GHz |
547 | _channels.insert( 2432, 5 ); // 2.432 GHz | 546 | _channels.insert( 2432, 5 ); // 2.432 GHz |
548 | _channels.insert( 2437, 6 ); // 2.437 GHz | 547 | _channels.insert( 2437, 6 ); // 2.437 GHz |
549 | _channels.insert( 2442, 7 ); // 2.442 GHz | 548 | _channels.insert( 2442, 7 ); // 2.442 GHz |
550 | _channels.insert( 2447, 8 ); // 2.447 GHz | 549 | _channels.insert( 2447, 8 ); // 2.447 GHz |
551 | _channels.insert( 2452, 9 ); // 2.452 GHz | 550 | _channels.insert( 2452, 9 ); // 2.452 GHz |
552 | _channels.insert( 2457, 10 ); // 2.457 GHz | 551 | _channels.insert( 2457, 10 ); // 2.457 GHz |
553 | _channels.insert( 2462, 11 ); // 2.462 GHz | 552 | _channels.insert( 2462, 11 ); // 2.462 GHz |
554 | 553 | ||
555 | memset( &_range, 0, sizeof( struct iw_range ) ); | 554 | memset( &_range, 0, sizeof( struct iw_range ) ); |
556 | } | 555 | } |
557 | else | 556 | else |
558 | { | 557 | { |
559 | // <check if the driver overwrites stuff> | 558 | // <check if the driver overwrites stuff> |
560 | int max = 0; | 559 | int max = 0; |
561 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) | 560 | for ( int r = sizeof( struct iw_range ); r < len; r++ ) |
562 | if (buffer[r] != 0) | 561 | if (buffer[r] != 0) |
563 | max = r; | 562 | max = r; |
564 | if (max > 0) | 563 | if (max > 0) |
565 | { | 564 | { |
566 | owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() | 565 | owarn << "OWirelessNetworkInterface::buildInformation(): Driver for wireless interface '" << name() |
567 | << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; | 566 | << "' sucks! It overwrote the buffer end with at least " << max - sizeof( struct iw_range ) << " bytes!" << oendl; |
568 | } | 567 | } |
569 | // </check if the driver overwrites stuff> | 568 | // </check if the driver overwrites stuff> |
570 | 569 | ||
571 | struct iw_range range; | 570 | struct iw_range range; |
572 | memcpy( &range, buffer, sizeof range ); | 571 | memcpy( &range, buffer, sizeof range ); |
573 | 572 | ||
574 | odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; | 573 | odebug << "OWirelessNetworkInterface::buildInformation(): Interface reported to have " << (int) range.num_frequency << " channels." << oendl; |
575 | for ( int i = 0; i < range.num_frequency; ++i ) | 574 | for ( int i = 0; i < range.num_frequency; ++i ) |
576 | { | 575 | { |
577 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); | 576 | int freq = (int) ( double( range.freq[i].m ) * pow( 10.0, range.freq[i].e ) / 1000000.0 ); |
578 | odebug << "OWirelessNetworkInterface::buildInformation: Adding frequency " << freq << " as channel " << i+1 << oendl; | 577 | odebug << "OWirelessNetworkInterface::buildInformation: Adding frequency " << freq << " as channel " << i+1 << oendl; |
579 | _channels.insert( freq, i+1 ); | 578 | _channels.insert( freq, i+1 ); |
580 | } | 579 | } |
581 | } | 580 | } |
582 | 581 | ||
583 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); | 582 | memcpy( &_range, buffer, sizeof( struct iw_range ) ); |
584 | odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; | 583 | odebug << "OWirelessNetworkInterface::buildInformation(): Information block constructed." << oendl; |
585 | free(buffer); | ||
586 | } | 584 | } |
587 | 585 | ||
588 | 586 | ||
589 | short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const | 587 | short OWirelessNetworkInterface::wirelessExtensionDriverVersion() const |
590 | { | 588 | { |
591 | return _range.we_version_compiled; | 589 | return _range.we_version_compiled; |
592 | } | 590 | } |
593 | 591 | ||
594 | 592 | ||
595 | void OWirelessNetworkInterface::buildPrivateList() | 593 | void OWirelessNetworkInterface::buildPrivateList() |
596 | { | 594 | { |
597 | odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; | 595 | odebug << "OWirelessNetworkInterface::buildPrivateList()" << oendl; |
598 | 596 | ||
599 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; | 597 | struct iw_priv_args priv[IW_MAX_PRIV_DEF]; |
600 | 598 | ||
601 | _iwr.u.data.pointer = (char*) &priv; | 599 | _iwr.u.data.pointer = (char*) &priv; |
602 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself | 600 | _iwr.u.data.length = IW_MAX_PRIV_DEF; // length in terms of number of (sizeof iw_priv_args), not (sizeof iw_priv_args) itself |
603 | _iwr.u.data.flags = 0; | 601 | _iwr.u.data.flags = 0; |
604 | 602 | ||
605 | if ( !wioctl( SIOCGIWPRIV ) ) | 603 | if ( !wioctl( SIOCGIWPRIV ) ) |
606 | { | 604 | { |
607 | owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information." << oendl; | 605 | owarn << "OWirelessNetworkInterface::buildPrivateList(): Can't get private ioctl information (" << strerror( errno ) << ")." << oendl; |
608 | return; | 606 | return; |
609 | } | 607 | } |
610 | 608 | ||
611 | for ( int i = 0; i < _iwr.u.data.length; ++i ) | 609 | for ( int i = 0; i < _iwr.u.data.length; ++i ) |
612 | { | 610 | { |
613 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); | 611 | new OPrivateIOCTL( this, priv[i].name, priv[i].cmd, priv[i].get_args, priv[i].set_args ); |
614 | } | 612 | } |
615 | odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; | 613 | odebug << "OWirelessNetworkInterface::buildPrivateList(): Private ioctl list constructed." << oendl; |
616 | } | 614 | } |
617 | 615 | ||
618 | 616 | ||
619 | void OWirelessNetworkInterface::dumpInformation() const | 617 | void OWirelessNetworkInterface::dumpInformation() const |
620 | { | 618 | { |
621 | odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; | 619 | odebug << "OWirelessNetworkInterface::() -------------- dumping information block ----------------" << oendl; |
622 | 620 | ||
623 | odebug << " - driver's idea of maximum throughput is " << _range.throughput | 621 | odebug << " - driver's idea of maximum throughput is " << _range.throughput |
624 | << " bps = " << ( _range.throughput / 8 ) << " byte/s = " << ( _range.throughput / 8 / 1024 ) | 622 | << " bps = " << ( _range.throughput / 8 ) << " byte/s = " << ( _range.throughput / 8 / 1024 ) |
625 | << " Kb/s = " << QString().sprintf("%f.2", float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ) | 623 | << " Kb/s = " << QString().sprintf("%f.2", float( _range.throughput ) / 8.0 / 1024.0 / 1024.0 ) |
626 | << " Mb/s" << oendl; | 624 | << " Mb/s" << oendl; |
627 | 625 | ||
628 | odebug << " - driver for '" << name() << "' (V" << _range.we_version_source | 626 | odebug << " - driver for '" << name() << "' (V" << _range.we_version_source |
629 | << ") has been compiled against WE V" << _range.we_version_compiled << oendl; | 627 | << ") has been compiled against WE V" << _range.we_version_compiled << oendl; |
630 | 628 | ||
631 | if ( _range.we_version_compiled != WIRELESS_EXT ) | 629 | if ( _range.we_version_compiled != WIRELESS_EXT ) |
632 | { | 630 | { |
633 | owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; | 631 | owarn << "Version mismatch! WE_DRIVER = " << _range.we_version_compiled << " and WE_OPIENET = " << WIRELESS_EXT << oendl; |
634 | } | 632 | } |
635 | 633 | ||
636 | odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; | 634 | odebug << "OWirelessNetworkInterface::() ---------------------------------------------------------" << oendl; |
637 | } | 635 | } |
638 | 636 | ||
639 | 637 | ||
640 | int OWirelessNetworkInterface::channel() const | 638 | int OWirelessNetworkInterface::channel() const |
641 | { | 639 | { |
642 | //FIXME: When monitoring enabled, then use it | 640 | //FIXME: When monitoring enabled, then use it |
643 | //FIXME: to gather the current RF channel | 641 | //FIXME: to gather the current RF channel |
644 | //FIXME: Until then, get active channel from hopper. | 642 | //FIXME: Until then, get active channel from hopper. |
645 | if ( _hopper && _hopper->isActive() ) | 643 | if ( _hopper && _hopper->isActive() ) |
646 | return _hopper->channel(); | 644 | return _hopper->channel(); |
647 | 645 | ||
648 | if ( !wioctl( SIOCGIWFREQ ) ) | 646 | if ( !wioctl( SIOCGIWFREQ ) ) |
649 | { | 647 | { |
650 | return -1; | 648 | return -1; |
651 | } | 649 | } |
652 | else | 650 | else |
653 | { | 651 | { |
654 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; | 652 | return _channels[ static_cast<int>(double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000) ]; |
655 | } | 653 | } |
656 | } | 654 | } |
657 | 655 | ||
658 | 656 | ||
659 | void OWirelessNetworkInterface::setChannel( int c ) const | 657 | void OWirelessNetworkInterface::setChannel( int c ) const |
660 | { | 658 | { |
661 | if ( !c ) | 659 | if ( !c ) |
662 | { | 660 | { |
663 | oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl; | 661 | oerr << "OWirelessNetworkInterface::setChannel( 0 ) called - fix your application!" << oendl; |
664 | return; | 662 | return; |
665 | } | 663 | } |
666 | 664 | ||
667 | if ( !_mon ) | 665 | if ( !_mon ) |
668 | { | 666 | { |
669 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 667 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
670 | _iwr.u.freq.m = c; | 668 | _iwr.u.freq.m = c; |
671 | _iwr.u.freq.e = 0; | 669 | _iwr.u.freq.e = 0; |
672 | wioctl( SIOCSIWFREQ ); | 670 | wioctl( SIOCSIWFREQ ); |
673 | } | 671 | } |
674 | else | 672 | else |
675 | { | 673 | { |
676 | _mon->setChannel( c ); | 674 | _mon->setChannel( c ); |
677 | } | 675 | } |
678 | } | 676 | } |
679 | 677 | ||
680 | 678 | ||
681 | double OWirelessNetworkInterface::frequency() const | 679 | double OWirelessNetworkInterface::frequency() const |
682 | { | 680 | { |
683 | if ( !wioctl( SIOCGIWFREQ ) ) | 681 | if ( !wioctl( SIOCGIWFREQ ) ) |
684 | { | 682 | { |
685 | return -1.0; | 683 | return -1.0; |
686 | } | 684 | } |
687 | else | 685 | else |
688 | { | 686 | { |
689 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; | 687 | return double( _iwr.u.freq.m ) * pow( 10.0, _iwr.u.freq.e ) / 1000000000.0; |
690 | } | 688 | } |
691 | } | 689 | } |
692 | 690 | ||
693 | 691 | ||
694 | int OWirelessNetworkInterface::channels() const | 692 | int OWirelessNetworkInterface::channels() const |
695 | { | 693 | { |
696 | return _channels.count(); | 694 | return _channels.count(); |
697 | } | 695 | } |
698 | 696 | ||
699 | 697 | ||
700 | void OWirelessNetworkInterface::setChannelHopping( int interval ) | 698 | void OWirelessNetworkInterface::setChannelHopping( int interval ) |
701 | { | 699 | { |
702 | if ( !_hopper ) _hopper = new OChannelHopper( this ); | 700 | if ( !_hopper ) _hopper = new OChannelHopper( this ); |
703 | _hopper->setInterval( interval ); | 701 | _hopper->setInterval( interval ); |
704 | //FIXME: When and by whom will the channel hopper be deleted? | 702 | //FIXME: When and by whom will the channel hopper be deleted? |
705 | //TODO: rely on QObject hierarchy | 703 | //TODO: rely on QObject hierarchy |
706 | } | 704 | } |
707 | 705 | ||
708 | 706 | ||
709 | int OWirelessNetworkInterface::channelHopping() const | 707 | int OWirelessNetworkInterface::channelHopping() const |
710 | { | 708 | { |
711 | return _hopper->interval(); | 709 | return _hopper->interval(); |
712 | } | 710 | } |
713 | 711 | ||
714 | 712 | ||
715 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const | 713 | OChannelHopper* OWirelessNetworkInterface::channelHopper() const |
716 | { | 714 | { |
717 | return _hopper; | 715 | return _hopper; |
718 | } | 716 | } |
719 | 717 | ||
720 | 718 | ||
721 | void OWirelessNetworkInterface::commit() const | 719 | void OWirelessNetworkInterface::commit() const |
722 | { | 720 | { |
723 | wioctl( SIOCSIWCOMMIT ); | 721 | wioctl( SIOCSIWCOMMIT ); |
724 | } | 722 | } |
725 | 723 | ||
726 | 724 | ||
727 | void OWirelessNetworkInterface::setMode( const QString& newMode ) | 725 | void OWirelessNetworkInterface::setMode( const QString& newMode ) |
728 | { | 726 | { |
729 | #ifdef FINALIZE | 727 | #ifdef FINALIZE |
730 | QString currentMode = mode(); | 728 | QString currentMode = mode(); |
731 | if ( currentMode == newMode ) return; | 729 | if ( currentMode == newMode ) return; |
732 | #endif | 730 | #endif |
733 | 731 | ||
734 | odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl; | 732 | odebug << "OWirelessNetworkInterface::setMode(): trying to set mode " << newMode << oendl; |
735 | 733 | ||
736 | _iwr.u.mode = stringToMode( newMode ); | 734 | _iwr.u.mode = stringToMode( newMode ); |
737 | 735 | ||
738 | if ( _iwr.u.mode != IW_MODE_MONITOR ) | 736 | if ( _iwr.u.mode != IW_MODE_MONITOR ) |
739 | { | 737 | { |
740 | // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! | 738 | // IWR.U.MODE WIRD DURCH ABFRAGE DES MODE HIER PLATTGEMACHT!!!!!!!!!!!!!!!!!!!!! DEPP! |
741 | _iwr.u.mode = stringToMode( newMode ); | 739 | _iwr.u.mode = stringToMode( newMode ); |
742 | wioctl( SIOCSIWMODE ); | 740 | wioctl( SIOCSIWMODE ); |
743 | 741 | ||
744 | // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) | 742 | // special iwpriv fallback for monitor mode (check if we're really out of monitor mode now) |
745 | 743 | ||
746 | if ( mode() == "monitor" ) | 744 | if ( mode() == "monitor" ) |
747 | { | 745 | { |
748 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl; | 746 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not sufficient - trying fallback to iwpriv..." << oendl; |
749 | if ( _mon ) | 747 | if ( _mon ) |
750 | _mon->setEnabled( false ); | 748 | _mon->setEnabled( false ); |
751 | else | 749 | else |
752 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; | 750 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; |
753 | } | 751 | } |
754 | 752 | ||
755 | } | 753 | } |
756 | else // special iwpriv fallback for monitor mode | 754 | else // special iwpriv fallback for monitor mode |
757 | { | 755 | { |
758 | if ( wioctl( SIOCSIWMODE ) ) | 756 | if ( wioctl( SIOCSIWMODE ) ) |
759 | { | 757 | { |
760 | odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl; | 758 | odebug << "OWirelessNetworkInterface::setMode(): IW_MODE_MONITOR ok" << oendl; |
761 | } | 759 | } |
762 | else | 760 | else |
763 | { | 761 | { |
764 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl; | 762 | odebug << "OWirelessNetworkInterface::setMode(): SIOCSIWMODE not working - trying fallback to iwpriv..." << oendl; |
765 | 763 | ||
766 | if ( _mon ) | 764 | if ( _mon ) |
767 | _mon->setEnabled( true ); | 765 | _mon->setEnabled( true ); |
768 | else | 766 | else |
769 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; | 767 | odebug << "ONetwork(): can't switch monitor mode without installed monitoring interface" << oendl; |
770 | } | 768 | } |
771 | } | 769 | } |
772 | } | 770 | } |
773 | 771 | ||
774 | 772 | ||
775 | QString OWirelessNetworkInterface::mode() const | 773 | QString OWirelessNetworkInterface::mode() const |
776 | { | 774 | { |
777 | memset( &_iwr, 0, sizeof( struct iwreq ) ); | 775 | memset( &_iwr, 0, sizeof( struct iwreq ) ); |
778 | 776 | ||
779 | if ( !wioctl( SIOCGIWMODE ) ) | 777 | if ( !wioctl( SIOCGIWMODE ) ) |
780 | { | 778 | { |
781 | return "<unknown>"; | 779 | return "<unknown>"; |
782 | } | 780 | } |
783 | 781 | ||
784 | odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl; | 782 | odebug << "OWirelessNetworkInterface::setMode(): WE's idea of current mode seems to be " << modeToString( _iwr.u.mode ) << oendl; |
785 | 783 | ||
786 | // legacy compatible monitor mode check | 784 | // legacy compatible monitor mode check |
787 | 785 | ||
788 | if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) | 786 | if ( dataLinkType() == ARPHRD_IEEE80211 || dataLinkType() == 802 ) |
789 | { | 787 | { |
790 | return "monitor"; | 788 | return "monitor"; |
791 | } | 789 | } |
792 | else | 790 | else |
793 | { | 791 | { |
794 | return modeToString( _iwr.u.mode ); | 792 | return modeToString( _iwr.u.mode ); |
795 | } | 793 | } |
796 | } | 794 | } |
797 | 795 | ||
798 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) | 796 | void OWirelessNetworkInterface::setNickName( const QString& nickname ) |
799 | { | 797 | { |
800 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); | 798 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) nickname ); |
801 | _iwr.u.essid.length = nickname.length(); | 799 | _iwr.u.essid.length = nickname.length(); |
802 | wioctl( SIOCSIWNICKN ); | 800 | wioctl( SIOCSIWNICKN ); |
803 | } | 801 | } |
804 | 802 | ||
805 | 803 | ||
806 | QString OWirelessNetworkInterface::nickName() const | 804 | QString OWirelessNetworkInterface::nickName() const |
807 | { | 805 | { |
808 | char str[IW_ESSID_MAX_SIZE]; | 806 | char str[IW_ESSID_MAX_SIZE]; |
809 | _iwr.u.data.pointer = &str[0]; | 807 | _iwr.u.data.pointer = &str[0]; |
810 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; | 808 | _iwr.u.data.length = IW_ESSID_MAX_SIZE; |
811 | if ( !wioctl( SIOCGIWNICKN ) ) | 809 | if ( !wioctl( SIOCGIWNICKN ) ) |
812 | { | 810 | { |
813 | return "<unknown>"; | 811 | return "<unknown>"; |
814 | } | 812 | } |
815 | else | 813 | else |
816 | { | 814 | { |
817 | str[_iwr.u.data.length] = '\0'; // some drivers don't zero-terminate the string | 815 | str[_iwr.u.data.length] = '\0'; // some drivers don't zero-terminate the string |
818 | return str; | 816 | return str; |
819 | } | 817 | } |
820 | } | 818 | } |
821 | 819 | ||
822 | 820 | ||
823 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) | 821 | void OWirelessNetworkInterface::setPrivate( const QString& call, int numargs, ... ) |
824 | { | 822 | { |
825 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); | 823 | OPrivateIOCTL* priv = static_cast<OPrivateIOCTL*>( child( (const char*) call ) ); |
826 | if ( !priv ) | 824 | if ( !priv ) |
827 | { | 825 | { |
828 | owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name() | 826 | owarn << "OWirelessNetworkInterface::setPrivate(): interface '" << name() |
829 | << "' does not support private ioctl '" << call << "'" << oendl; | 827 | << "' does not support private ioctl '" << call << "'" << oendl; |
830 | return; | 828 | return; |
831 | } | 829 | } |
832 | if ( priv->numberSetArgs() != numargs ) | 830 | if ( priv->numberSetArgs() != numargs ) |
833 | { | 831 | { |
834 | owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '" | 832 | owarn << "OWirelessNetworkInterface::setPrivate(): parameter count not matching. '" |
835 | << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl; | 833 | << call << "' expects " << priv->numberSetArgs() << ", but got " << numargs << oendl; |
836 | return; | 834 | return; |
837 | } | 835 | } |
838 | 836 | ||
839 | odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl; | 837 | odebug << "OWirelessNetworkInterface::setPrivate(): about to call '" << call << "' on interface '" << name() << "'" << oendl; |
840 | memset( &_iwr, 0, sizeof _iwr ); | 838 | memset( &_iwr, 0, sizeof _iwr ); |
841 | va_list argp; | 839 | va_list argp; |
842 | va_start( argp, numargs ); | 840 | va_start( argp, numargs ); |
843 | for ( int i = 0; i < numargs; ++i ) | 841 | for ( int i = 0; i < numargs; ++i ) |
844 | { | 842 | { |
845 | priv->setParameter( i, va_arg( argp, int ) ); | 843 | priv->setParameter( i, va_arg( argp, int ) ); |
846 | } | 844 | } |
847 | va_end( argp ); | 845 | va_end( argp ); |
848 | priv->invoke(); | 846 | priv->invoke(); |
849 | } | 847 | } |
850 | 848 | ||
851 | 849 | ||
852 | void OWirelessNetworkInterface::getPrivate( const QString& ) | 850 | void OWirelessNetworkInterface::getPrivate( const QString& ) |
853 | { | 851 | { |
854 | oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl; | 852 | oerr << "OWirelessNetworkInterface::getPrivate() is not implemented yet." << oendl; |
855 | } | 853 | } |
856 | 854 | ||
857 | 855 | ||
858 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) | 856 | bool OWirelessNetworkInterface::hasPrivate( const QString& call ) |
859 | { | 857 | { |
860 | return child( call.local8Bit() ); | 858 | return child( call.local8Bit() ); |
861 | } | 859 | } |
862 | 860 | ||
863 | 861 | ||
@@ -905,519 +903,519 @@ OStationList* OWirelessNetworkInterface::scanNetwork() | |||
905 | struct timeval tv; | 903 | struct timeval tv; |
906 | tv.tv_sec = 0; | 904 | tv.tv_sec = 0; |
907 | tv.tv_usec = 250000; // initial timeout ~ 250ms | 905 | tv.tv_usec = 250000; // initial timeout ~ 250ms |
908 | char buffer[IW_SCAN_MAX_DATA]; | 906 | char buffer[IW_SCAN_MAX_DATA]; |
909 | 907 | ||
910 | while ( !results && timeout > 0 ) | 908 | while ( !results && timeout > 0 ) |
911 | { | 909 | { |
912 | timeout -= tv.tv_usec; | 910 | timeout -= tv.tv_usec; |
913 | select( 0, 0, 0, 0, &tv ); | 911 | select( 0, 0, 0, 0, &tv ); |
914 | 912 | ||
915 | _iwr.u.data.pointer = &buffer[0]; | 913 | _iwr.u.data.pointer = &buffer[0]; |
916 | _iwr.u.data.flags = 0; | 914 | _iwr.u.data.flags = 0; |
917 | _iwr.u.data.length = sizeof buffer; | 915 | _iwr.u.data.length = sizeof buffer; |
918 | if ( wioctl( SIOCGIWSCAN ) ) | 916 | if ( wioctl( SIOCGIWSCAN ) ) |
919 | { | 917 | { |
920 | results = true; | 918 | results = true; |
921 | continue; | 919 | continue; |
922 | } | 920 | } |
923 | else if ( errno == EAGAIN) | 921 | else if ( errno == EAGAIN) |
924 | { | 922 | { |
925 | odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl; | 923 | odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl; |
926 | if ( qApp ) | 924 | if ( qApp ) |
927 | { | 925 | { |
928 | qApp->processEvents( 100 ); | 926 | qApp->processEvents( 100 ); |
929 | continue; | 927 | continue; |
930 | } | 928 | } |
931 | tv.tv_sec = 0; | 929 | tv.tv_sec = 0; |
932 | tv.tv_usec = 100000; | 930 | tv.tv_usec = 100000; |
933 | continue; | 931 | continue; |
934 | } | 932 | } |
935 | } | 933 | } |
936 | 934 | ||
937 | odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; | 935 | odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; |
938 | 936 | ||
939 | if ( results ) | 937 | if ( results ) |
940 | { | 938 | { |
941 | odebug << " - result length = " << _iwr.u.data.length << oendl; | 939 | odebug << " - result length = " << _iwr.u.data.length << oendl; |
942 | if ( !_iwr.u.data.length ) | 940 | if ( !_iwr.u.data.length ) |
943 | { | 941 | { |
944 | odebug << " - no results (empty neighbourhood)" << oendl; | 942 | odebug << " - no results (empty neighbourhood)" << oendl; |
945 | return stations; | 943 | return stations; |
946 | } | 944 | } |
947 | 945 | ||
948 | odebug << " - results are in!" << oendl; | 946 | odebug << " - results are in!" << oendl; |
949 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); | 947 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); |
950 | 948 | ||
951 | // parse results | 949 | // parse results |
952 | struct iw_event iwe; | 950 | struct iw_event iwe; |
953 | struct iw_stream_descr stream; | 951 | struct iw_stream_descr stream; |
954 | unsigned int cmd_index, event_type, event_len; | 952 | unsigned int cmd_index, event_type, event_len; |
955 | char *pointer; | 953 | char *pointer; |
956 | 954 | ||
957 | const char standard_ioctl_hdr[] = { | 955 | const char standard_ioctl_hdr[] = { |
958 | IW_HEADER_TYPE_NULL, /* SIOCSIWCOMMIT */ | 956 | IW_HEADER_TYPE_NULL, /* SIOCSIWCOMMIT */ |
959 | IW_HEADER_TYPE_CHAR, /* SIOCGIWNAME */ | 957 | IW_HEADER_TYPE_CHAR, /* SIOCGIWNAME */ |
960 | IW_HEADER_TYPE_PARAM, /* SIOCSIWNWID */ | 958 | IW_HEADER_TYPE_PARAM, /* SIOCSIWNWID */ |
961 | IW_HEADER_TYPE_PARAM, /* SIOCGIWNWID */ | 959 | IW_HEADER_TYPE_PARAM, /* SIOCGIWNWID */ |
962 | IW_HEADER_TYPE_FREQ, /* SIOCSIWFREQ */ | 960 | IW_HEADER_TYPE_FREQ, /* SIOCSIWFREQ */ |
963 | IW_HEADER_TYPE_FREQ, /* SIOCGIWFREQ */ | 961 | IW_HEADER_TYPE_FREQ, /* SIOCGIWFREQ */ |
964 | IW_HEADER_TYPE_UINT, /* SIOCSIWMODE */ | 962 | IW_HEADER_TYPE_UINT, /* SIOCSIWMODE */ |
965 | IW_HEADER_TYPE_UINT, /* SIOCGIWMODE */ | 963 | IW_HEADER_TYPE_UINT, /* SIOCGIWMODE */ |
966 | IW_HEADER_TYPE_PARAM, /* SIOCSIWSENS */ | 964 | IW_HEADER_TYPE_PARAM, /* SIOCSIWSENS */ |
967 | IW_HEADER_TYPE_PARAM, /* SIOCGIWSENS */ | 965 | IW_HEADER_TYPE_PARAM, /* SIOCGIWSENS */ |
968 | IW_HEADER_TYPE_NULL, /* SIOCSIWRANGE */ | 966 | IW_HEADER_TYPE_NULL, /* SIOCSIWRANGE */ |
969 | IW_HEADER_TYPE_POINT, /* SIOCGIWRANGE */ | 967 | IW_HEADER_TYPE_POINT, /* SIOCGIWRANGE */ |
970 | IW_HEADER_TYPE_NULL, /* SIOCSIWPRIV */ | 968 | IW_HEADER_TYPE_NULL, /* SIOCSIWPRIV */ |
971 | IW_HEADER_TYPE_POINT, /* SIOCGIWPRIV */ | 969 | IW_HEADER_TYPE_POINT, /* SIOCGIWPRIV */ |
972 | IW_HEADER_TYPE_NULL, /* SIOCSIWSTATS */ | 970 | IW_HEADER_TYPE_NULL, /* SIOCSIWSTATS */ |
973 | IW_HEADER_TYPE_POINT, /* SIOCGIWSTATS */ | 971 | IW_HEADER_TYPE_POINT, /* SIOCGIWSTATS */ |
974 | IW_HEADER_TYPE_POINT, /* SIOCSIWSPY */ | 972 | IW_HEADER_TYPE_POINT, /* SIOCSIWSPY */ |
975 | IW_HEADER_TYPE_POINT, /* SIOCGIWSPY */ | 973 | IW_HEADER_TYPE_POINT, /* SIOCGIWSPY */ |
976 | IW_HEADER_TYPE_POINT, /* SIOCSIWTHRSPY */ | 974 | IW_HEADER_TYPE_POINT, /* SIOCSIWTHRSPY */ |
977 | IW_HEADER_TYPE_POINT, /* SIOCGIWTHRSPY */ | 975 | IW_HEADER_TYPE_POINT, /* SIOCGIWTHRSPY */ |
978 | IW_HEADER_TYPE_ADDR, /* SIOCSIWAP */ | 976 | IW_HEADER_TYPE_ADDR, /* SIOCSIWAP */ |
979 | IW_HEADER_TYPE_ADDR, /* SIOCGIWAP */ | 977 | IW_HEADER_TYPE_ADDR, /* SIOCGIWAP */ |
980 | IW_HEADER_TYPE_NULL, /* -- hole -- */ | 978 | IW_HEADER_TYPE_NULL, /* -- hole -- */ |
981 | IW_HEADER_TYPE_POINT, /* SIOCGIWAPLIST */ | 979 | IW_HEADER_TYPE_POINT, /* SIOCGIWAPLIST */ |
982 | IW_HEADER_TYPE_PARAM, /* SIOCSIWSCAN */ | 980 | IW_HEADER_TYPE_PARAM, /* SIOCSIWSCAN */ |
983 | IW_HEADER_TYPE_POINT, /* SIOCGIWSCAN */ | 981 | IW_HEADER_TYPE_POINT, /* SIOCGIWSCAN */ |
984 | IW_HEADER_TYPE_POINT, /* SIOCSIWESSID */ | 982 | IW_HEADER_TYPE_POINT, /* SIOCSIWESSID */ |
985 | IW_HEADER_TYPE_POINT, /* SIOCGIWESSID */ | 983 | IW_HEADER_TYPE_POINT, /* SIOCGIWESSID */ |
986 | IW_HEADER_TYPE_POINT, /* SIOCSIWNICKN */ | 984 | IW_HEADER_TYPE_POINT, /* SIOCSIWNICKN */ |
987 | IW_HEADER_TYPE_POINT, /* SIOCGIWNICKN */ | 985 | IW_HEADER_TYPE_POINT, /* SIOCGIWNICKN */ |
988 | IW_HEADER_TYPE_NULL, /* -- hole -- */ | 986 | IW_HEADER_TYPE_NULL, /* -- hole -- */ |
989 | IW_HEADER_TYPE_NULL, /* -- hole -- */ | 987 | IW_HEADER_TYPE_NULL, /* -- hole -- */ |
990 | IW_HEADER_TYPE_PARAM, /* SIOCSIWRATE */ | 988 | IW_HEADER_TYPE_PARAM, /* SIOCSIWRATE */ |
991 | IW_HEADER_TYPE_PARAM, /* SIOCGIWRATE */ | 989 | IW_HEADER_TYPE_PARAM, /* SIOCGIWRATE */ |
992 | IW_HEADER_TYPE_PARAM, /* SIOCSIWRTS */ | 990 | IW_HEADER_TYPE_PARAM, /* SIOCSIWRTS */ |
993 | IW_HEADER_TYPE_PARAM, /* SIOCGIWRTS */ | 991 | IW_HEADER_TYPE_PARAM, /* SIOCGIWRTS */ |
994 | IW_HEADER_TYPE_PARAM, /* SIOCSIWFRAG */ | 992 | IW_HEADER_TYPE_PARAM, /* SIOCSIWFRAG */ |
995 | IW_HEADER_TYPE_PARAM, /* SIOCGIWFRAG */ | 993 | IW_HEADER_TYPE_PARAM, /* SIOCGIWFRAG */ |
996 | IW_HEADER_TYPE_PARAM, /* SIOCSIWTXPOW */ | 994 | IW_HEADER_TYPE_PARAM, /* SIOCSIWTXPOW */ |
997 | IW_HEADER_TYPE_PARAM, /* SIOCGIWTXPOW */ | 995 | IW_HEADER_TYPE_PARAM, /* SIOCGIWTXPOW */ |
998 | IW_HEADER_TYPE_PARAM, /* SIOCSIWRETRY */ | 996 | IW_HEADER_TYPE_PARAM, /* SIOCSIWRETRY */ |
999 | IW_HEADER_TYPE_PARAM, /* SIOCGIWRETRY */ | 997 | IW_HEADER_TYPE_PARAM, /* SIOCGIWRETRY */ |
1000 | IW_HEADER_TYPE_POINT, /* SIOCSIWENCODE */ | 998 | IW_HEADER_TYPE_POINT, /* SIOCSIWENCODE */ |
1001 | IW_HEADER_TYPE_POINT, /* SIOCGIWENCODE */ | 999 | IW_HEADER_TYPE_POINT, /* SIOCGIWENCODE */ |
1002 | IW_HEADER_TYPE_PARAM, /* SIOCSIWPOWER */ | 1000 | IW_HEADER_TYPE_PARAM, /* SIOCSIWPOWER */ |
1003 | IW_HEADER_TYPE_PARAM, /* SIOCGIWPOWER */ | 1001 | IW_HEADER_TYPE_PARAM, /* SIOCGIWPOWER */ |
1004 | }; | 1002 | }; |
1005 | 1003 | ||
1006 | const char standard_event_hdr[] = { | 1004 | const char standard_event_hdr[] = { |
1007 | IW_HEADER_TYPE_ADDR, /* IWEVTXDROP */ | 1005 | IW_HEADER_TYPE_ADDR, /* IWEVTXDROP */ |
1008 | IW_HEADER_TYPE_QUAL, /* IWEVQUAL */ | 1006 | IW_HEADER_TYPE_QUAL, /* IWEVQUAL */ |
1009 | IW_HEADER_TYPE_POINT, /* IWEVCUSTOM */ | 1007 | IW_HEADER_TYPE_POINT, /* IWEVCUSTOM */ |
1010 | IW_HEADER_TYPE_ADDR, /* IWEVREGISTERED */ | 1008 | IW_HEADER_TYPE_ADDR, /* IWEVREGISTERED */ |
1011 | IW_HEADER_TYPE_ADDR, /* IWEVEXPIRED */ | 1009 | IW_HEADER_TYPE_ADDR, /* IWEVEXPIRED */ |
1012 | IW_HEADER_TYPE_POINT, /* IWEVGENIE */ | 1010 | IW_HEADER_TYPE_POINT, /* IWEVGENIE */ |
1013 | IW_HEADER_TYPE_POINT, /* IWEVMICHAELMICFAILURE */ | 1011 | IW_HEADER_TYPE_POINT, /* IWEVMICHAELMICFAILURE */ |
1014 | IW_HEADER_TYPE_POINT, /* IWEVASSOCREQIE */ | 1012 | IW_HEADER_TYPE_POINT, /* IWEVASSOCREQIE */ |
1015 | IW_HEADER_TYPE_POINT, /* IWEVASSOCRESPIE */ | 1013 | IW_HEADER_TYPE_POINT, /* IWEVASSOCRESPIE */ |
1016 | IW_HEADER_TYPE_POINT, /* IWEVPMKIDCAND */ | 1014 | IW_HEADER_TYPE_POINT, /* IWEVPMKIDCAND */ |
1017 | }; | 1015 | }; |
1018 | 1016 | ||
1019 | 1017 | ||
1020 | const int event_type_size[] = { | 1018 | const int event_type_size[] = { |
1021 | IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */ | 1019 | IW_EV_LCP_LEN, /* IW_HEADER_TYPE_NULL */ |
1022 | 0, | 1020 | 0, |
1023 | IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */ | 1021 | IW_EV_CHAR_LEN, /* IW_HEADER_TYPE_CHAR */ |
1024 | 0, | 1022 | 0, |
1025 | IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */ | 1023 | IW_EV_UINT_LEN, /* IW_HEADER_TYPE_UINT */ |
1026 | IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */ | 1024 | IW_EV_FREQ_LEN, /* IW_HEADER_TYPE_FREQ */ |
1027 | IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */ | 1025 | IW_EV_ADDR_LEN, /* IW_HEADER_TYPE_ADDR */ |
1028 | 0, | 1026 | 0, |
1029 | IW_EV_POINT_LEN, /* Without variable payload */ | 1027 | IW_EV_POINT_LEN, /* Without variable payload */ |
1030 | IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */ | 1028 | IW_EV_PARAM_LEN, /* IW_HEADER_TYPE_PARAM */ |
1031 | IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */ | 1029 | IW_EV_QUAL_LEN, /* IW_HEADER_TYPE_QUAL */ |
1032 | }; | 1030 | }; |
1033 | 1031 | ||
1034 | 1032 | ||
1035 | //Initialize the stream | 1033 | //Initialize the stream |
1036 | memset( &stream, 0, sizeof(struct iw_stream_descr) ); | 1034 | memset( &stream, 0, sizeof(struct iw_stream_descr) ); |
1037 | stream.current = buffer; | 1035 | stream.current = buffer; |
1038 | stream.end = buffer + _iwr.u.data.length; | 1036 | stream.end = buffer + _iwr.u.data.length; |
1039 | 1037 | ||
1040 | do | 1038 | do |
1041 | { | 1039 | { |
1042 | if ((stream.current + IW_EV_LCP_LEN) > stream.end) | 1040 | if ((stream.current + IW_EV_LCP_LEN) > stream.end) |
1043 | break; | 1041 | break; |
1044 | memcpy((char *) &iwe, stream.current, IW_EV_LCP_LEN); | 1042 | memcpy((char *) &iwe, stream.current, IW_EV_LCP_LEN); |
1045 | 1043 | ||
1046 | if (iwe.len <= IW_EV_LCP_LEN) //If yes, it is an invalid event | 1044 | if (iwe.len <= IW_EV_LCP_LEN) //If yes, it is an invalid event |
1047 | break; | 1045 | break; |
1048 | if (iwe.cmd <= SIOCIWLAST) { | 1046 | if (iwe.cmd <= SIOCIWLAST) { |
1049 | cmd_index = iwe.cmd - SIOCIWFIRST; | 1047 | cmd_index = iwe.cmd - SIOCIWFIRST; |
1050 | 1048 | ||
1051 | if(cmd_index < sizeof(standard_ioctl_hdr)) | 1049 | if(cmd_index < sizeof(standard_ioctl_hdr)) |
1052 | event_type = standard_ioctl_hdr[cmd_index]; | 1050 | event_type = standard_ioctl_hdr[cmd_index]; |
1053 | } | 1051 | } |
1054 | else { | 1052 | else { |
1055 | cmd_index = iwe.cmd - IWEVFIRST; | 1053 | cmd_index = iwe.cmd - IWEVFIRST; |
1056 | 1054 | ||
1057 | if(cmd_index < sizeof(standard_event_hdr)) | 1055 | if(cmd_index < sizeof(standard_event_hdr)) |
1058 | event_type = standard_event_hdr[cmd_index]; | 1056 | event_type = standard_event_hdr[cmd_index]; |
1059 | } | 1057 | } |
1060 | 1058 | ||
1061 | /* Unknown events -> event_type=0 => IW_EV_LCP_LEN */ | 1059 | /* Unknown events -> event_type=0 => IW_EV_LCP_LEN */ |
1062 | event_len = event_type_size[event_type]; | 1060 | event_len = event_type_size[event_type]; |
1063 | 1061 | ||
1064 | /* Fixup for later version of WE */ | 1062 | /* Fixup for later version of WE */ |
1065 | if((_range.we_version_compiled > 18) && (event_type == IW_HEADER_TYPE_POINT)) | 1063 | if((_range.we_version_compiled > 18) && (event_type == IW_HEADER_TYPE_POINT)) |
1066 | event_len -= IW_EV_POINT_OFF; | 1064 | event_len -= IW_EV_POINT_OFF; |
1067 | 1065 | ||
1068 | /* Check if we know about this event */ | 1066 | /* Check if we know about this event */ |
1069 | if(event_len <= IW_EV_LCP_LEN) { | 1067 | if(event_len <= IW_EV_LCP_LEN) { |
1070 | /* Skip to next event */ | 1068 | /* Skip to next event */ |
1071 | stream.current += iwe.len; | 1069 | stream.current += iwe.len; |
1072 | continue; | 1070 | continue; |
1073 | } | 1071 | } |
1074 | 1072 | ||
1075 | event_len -= IW_EV_LCP_LEN; | 1073 | event_len -= IW_EV_LCP_LEN; |
1076 | 1074 | ||
1077 | /* Set pointer on data */ | 1075 | /* Set pointer on data */ |
1078 | if(stream.value != NULL) | 1076 | if(stream.value != NULL) |
1079 | pointer = stream.value; /* Next value in event */ | 1077 | pointer = stream.value; /* Next value in event */ |
1080 | else | 1078 | else |
1081 | pointer = stream.current + IW_EV_LCP_LEN; /* First value in event */ | 1079 | pointer = stream.current + IW_EV_LCP_LEN; /* First value in event */ |
1082 | 1080 | ||
1083 | if((pointer + event_len) > stream.end) { | 1081 | if((pointer + event_len) > stream.end) { |
1084 | /* Go to next event */ | 1082 | /* Go to next event */ |
1085 | stream.current += iwe.len; | 1083 | stream.current += iwe.len; |
1086 | break; | 1084 | break; |
1087 | } | 1085 | } |
1088 | 1086 | ||
1089 | /* Fixup for later version of WE */ | 1087 | /* Fixup for later version of WE */ |
1090 | if((_range.we_version_compiled > 18) && (event_type == IW_HEADER_TYPE_POINT)) | 1088 | if((_range.we_version_compiled > 18) && (event_type == IW_HEADER_TYPE_POINT)) |
1091 | memcpy((char *) &iwe + IW_EV_LCP_LEN + IW_EV_POINT_OFF, pointer, event_len); | 1089 | memcpy((char *) &iwe + IW_EV_LCP_LEN + IW_EV_POINT_OFF, pointer, event_len); |
1092 | else | 1090 | else |
1093 | memcpy((char *) &iwe + IW_EV_LCP_LEN, pointer, event_len); | 1091 | memcpy((char *) &iwe + IW_EV_LCP_LEN, pointer, event_len); |
1094 | 1092 | ||
1095 | /* Skip event in the stream */ | 1093 | /* Skip event in the stream */ |
1096 | pointer += event_len; | 1094 | pointer += event_len; |
1097 | 1095 | ||
1098 | /* Special processing for iw_point events */ | 1096 | /* Special processing for iw_point events */ |
1099 | if(event_type == IW_HEADER_TYPE_POINT) { | 1097 | if(event_type == IW_HEADER_TYPE_POINT) { |
1100 | /* Check the length of the payload */ | 1098 | /* Check the length of the payload */ |
1101 | 1099 | ||
1102 | if((iwe.len - (event_len + IW_EV_LCP_LEN)) > 0) | 1100 | if((iwe.len - (event_len + IW_EV_LCP_LEN)) > 0) |
1103 | /* Set pointer on variable part (warning : non aligned) */ | 1101 | /* Set pointer on variable part (warning : non aligned) */ |
1104 | iwe.u.data.pointer = pointer; | 1102 | iwe.u.data.pointer = pointer; |
1105 | else | 1103 | else |
1106 | /* No data */ | 1104 | /* No data */ |
1107 | iwe.u.data.pointer = NULL; | 1105 | iwe.u.data.pointer = NULL; |
1108 | /* Go to next event */ | 1106 | /* Go to next event */ |
1109 | stream.current += iwe.len; | 1107 | stream.current += iwe.len; |
1110 | } | 1108 | } |
1111 | 1109 | ||
1112 | else { | 1110 | else { |
1113 | /* Is there more value in the event ? */ | 1111 | /* Is there more value in the event ? */ |
1114 | if((pointer + event_len) <= (stream.current + iwe.len)) | 1112 | if((pointer + event_len) <= (stream.current + iwe.len)) |
1115 | /* Go to next value */ | 1113 | /* Go to next value */ |
1116 | stream.value = pointer; | 1114 | stream.value = pointer; |
1117 | else { | 1115 | else { |
1118 | /* Go to next event */ | 1116 | /* Go to next event */ |
1119 | stream.value = NULL; | 1117 | stream.value = NULL; |
1120 | stream.current += iwe.len; | 1118 | stream.current += iwe.len; |
1121 | } | 1119 | } |
1122 | } | 1120 | } |
1123 | 1121 | ||
1124 | struct iw_event *we = &iwe; | 1122 | struct iw_event *we = &iwe; |
1125 | //------ | 1123 | //------ |
1126 | odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl; | 1124 | odebug << " - reading next event... cmd=" << we->cmd << ", len=" << we->len << oendl; |
1127 | switch (we->cmd) | 1125 | switch (we->cmd) |
1128 | { | 1126 | { |
1129 | case SIOCGIWAP: | 1127 | case SIOCGIWAP: |
1130 | { | 1128 | { |
1131 | odebug << "SIOCGIWAP" << oendl; | 1129 | odebug << "SIOCGIWAP" << oendl; |
1132 | stations->append( new OStation() ); | 1130 | stations->append( new OStation() ); |
1133 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; | 1131 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; |
1134 | break; | 1132 | break; |
1135 | } | 1133 | } |
1136 | case SIOCGIWMODE: | 1134 | case SIOCGIWMODE: |
1137 | { | 1135 | { |
1138 | odebug << "SIOCGIWMODE" << oendl; | 1136 | odebug << "SIOCGIWMODE" << oendl; |
1139 | stations->last()->type = modeToString( we->u.mode ); | 1137 | stations->last()->type = modeToString( we->u.mode ); |
1140 | break; | 1138 | break; |
1141 | } | 1139 | } |
1142 | case SIOCGIWFREQ: | 1140 | case SIOCGIWFREQ: |
1143 | { | 1141 | { |
1144 | odebug << "SIOCGIWFREQ" << oendl; | 1142 | odebug << "SIOCGIWFREQ" << oendl; |
1145 | if ( we->u.freq.m > 1000 ) | 1143 | if ( we->u.freq.m > 1000 ) |
1146 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; | 1144 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; |
1147 | else | 1145 | else |
1148 | stations->last()->channel = static_cast<int>(((double) we->u.freq.m) * pow( 10.0, we->u.freq.e )); | 1146 | stations->last()->channel = static_cast<int>(((double) we->u.freq.m) * pow( 10.0, we->u.freq.e )); |
1149 | break; | 1147 | break; |
1150 | } | 1148 | } |
1151 | case SIOCGIWESSID: | 1149 | case SIOCGIWESSID: |
1152 | { | 1150 | { |
1153 | odebug << "SIOCGIWESSID" << oendl; | 1151 | odebug << "SIOCGIWESSID" << oendl; |
1154 | we->u.essid.length = '\0'; // make sure it is zero terminated | 1152 | we->u.essid.length = '\0'; // make sure it is zero terminated |
1155 | stations->last()->ssid = static_cast<const char*> (we->u.essid.pointer); | 1153 | stations->last()->ssid = static_cast<const char*> (we->u.essid.pointer); |
1156 | odebug << "ESSID: " << stations->last()->ssid << oendl; | 1154 | odebug << "ESSID: " << stations->last()->ssid << oendl; |
1157 | break; | 1155 | break; |
1158 | } | 1156 | } |
1159 | case IWEVQUAL: | 1157 | case IWEVQUAL: |
1160 | { | 1158 | { |
1161 | odebug << "IWEVQUAL" << oendl; | 1159 | odebug << "IWEVQUAL" << oendl; |
1162 | stations->last()->level = static_cast<int>(we->u.qual.level); | 1160 | stations->last()->level = static_cast<int>(we->u.qual.level); |
1163 | break; /* Quality part of statistics (scan) */ | 1161 | break; /* Quality part of statistics (scan) */ |
1164 | } | 1162 | } |
1165 | case SIOCGIWENCODE: | 1163 | case SIOCGIWENCODE: |
1166 | { | 1164 | { |
1167 | odebug << "SIOCGIWENCODE" << oendl; | 1165 | odebug << "SIOCGIWENCODE" << oendl; |
1168 | stations->last()->encrypted = !(we->u.data.flags & IW_ENCODE_DISABLED); | 1166 | stations->last()->encrypted = !(we->u.data.flags & IW_ENCODE_DISABLED); |
1169 | break; | 1167 | break; |
1170 | } | 1168 | } |
1171 | 1169 | ||
1172 | case SIOCGIWRATE: | 1170 | case SIOCGIWRATE: |
1173 | { | 1171 | { |
1174 | odebug << "SIOCGIWRATE" << oendl; | 1172 | odebug << "SIOCGIWRATE" << oendl; |
1175 | stations->last()->rates.append(we->u.bitrate.value); | 1173 | stations->last()->rates.append(we->u.bitrate.value); |
1176 | break; | 1174 | break; |
1177 | } | 1175 | } |
1178 | case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; | 1176 | case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; |
1179 | case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ | 1177 | case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ |
1180 | case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ | 1178 | case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ |
1181 | case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ | 1179 | case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ |
1182 | case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ | 1180 | case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ |
1183 | default: odebug << "unhandled event" << oendl; | 1181 | default: odebug << "unhandled event" << oendl; |
1184 | } | 1182 | } |
1185 | 1183 | ||
1186 | } while (true); | 1184 | } while (true); |
1187 | } | 1185 | } |
1188 | else | 1186 | else |
1189 | { | 1187 | { |
1190 | odebug << " - no results (timeout) :(" << oendl; | 1188 | odebug << " - no results (timeout) :(" << oendl; |
1191 | } | 1189 | } |
1192 | return stations; | 1190 | return stations; |
1193 | } | 1191 | } |
1194 | 1192 | ||
1195 | 1193 | ||
1196 | int OWirelessNetworkInterface::signalStrength() const | 1194 | int OWirelessNetworkInterface::signalStrength() const |
1197 | { | 1195 | { |
1198 | iw_statistics stat; | 1196 | iw_statistics stat; |
1199 | ::memset( &stat, 0, sizeof stat ); | 1197 | ::memset( &stat, 0, sizeof stat ); |
1200 | _iwr.u.data.pointer = (char*) &stat; | 1198 | _iwr.u.data.pointer = (char*) &stat; |
1201 | _iwr.u.data.flags = 0; | 1199 | _iwr.u.data.flags = 0; |
1202 | _iwr.u.data.length = sizeof stat; | 1200 | _iwr.u.data.length = sizeof stat; |
1203 | 1201 | ||
1204 | if ( !wioctl( SIOCGIWSTATS ) ) | 1202 | if ( !wioctl( SIOCGIWSTATS ) ) |
1205 | { | 1203 | { |
1206 | return -1; | 1204 | return -1; |
1207 | } | 1205 | } |
1208 | 1206 | ||
1209 | int max = _range.max_qual.qual; | 1207 | int max = _range.max_qual.qual; |
1210 | int cur = stat.qual.qual; | 1208 | int cur = stat.qual.qual; |
1211 | // int lev = stat.qual.level; //FIXME: Do something with them? | 1209 | // int lev = stat.qual.level; //FIXME: Do something with them? |
1212 | // int noi = stat.qual.noise; //FIXME: Do something with them? | 1210 | // int noi = stat.qual.noise; //FIXME: Do something with them? |
1213 | 1211 | ||
1214 | 1212 | ||
1215 | return max != 0 ? cur*100/max: -1; | 1213 | return max != 0 ? cur*100/max: -1; |
1216 | } | 1214 | } |
1217 | 1215 | ||
1218 | 1216 | ||
1219 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 1217 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
1220 | { | 1218 | { |
1221 | #ifndef NODEBUG | 1219 | #ifndef NODEBUG |
1222 | int result = ::ioctl( _sfd, call, &iwreq ); | 1220 | int result = ::ioctl( _sfd, call, &iwreq ); |
1223 | 1221 | ||
1224 | if ( result == -1 ) | 1222 | if ( result == -1 ) |
1225 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1223 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1226 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; | 1224 | << debugmapper->map( call ) << "' FAILED! " << result << " (" << strerror( errno ) << ")" << oendl; |
1227 | else | 1225 | else |
1228 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" | 1226 | odebug << "ONetworkInterface::wioctl (" << name() << ") call '" |
1229 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; | 1227 | << debugmapper->map( call ) << "' - Status: Ok." << oendl; |
1230 | 1228 | ||
1231 | return ( result != -1 ); | 1229 | return ( result != -1 ); |
1232 | #else | 1230 | #else |
1233 | return ::ioctl( _sfd, call, &iwreq ) != -1; | 1231 | return ::ioctl( _sfd, call, &iwreq ) != -1; |
1234 | #endif | 1232 | #endif |
1235 | } | 1233 | } |
1236 | 1234 | ||
1237 | 1235 | ||
1238 | bool OWirelessNetworkInterface::wioctl( int call ) const | 1236 | bool OWirelessNetworkInterface::wioctl( int call ) const |
1239 | { | 1237 | { |
1240 | strcpy( _iwr.ifr_name, name() ); | 1238 | strcpy( _iwr.ifr_name, name() ); |
1241 | return wioctl( call, _iwr ); | 1239 | return wioctl( call, _iwr ); |
1242 | } | 1240 | } |
1243 | 1241 | ||
1244 | 1242 | ||
1245 | /*====================================================================================== | 1243 | /*====================================================================================== |
1246 | * OMonitoringInterface | 1244 | * OMonitoringInterface |
1247 | *======================================================================================*/ | 1245 | *======================================================================================*/ |
1248 | 1246 | ||
1249 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1247 | OMonitoringInterface::OMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1250 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) | 1248 | :_if( static_cast<OWirelessNetworkInterface*>( iface ) ), _prismHeader( prismHeader ) |
1251 | { | 1249 | { |
1252 | } | 1250 | } |
1253 | 1251 | ||
1254 | 1252 | ||
1255 | OMonitoringInterface::~OMonitoringInterface() | 1253 | OMonitoringInterface::~OMonitoringInterface() |
1256 | { | 1254 | { |
1257 | } | 1255 | } |
1258 | 1256 | ||
1259 | 1257 | ||
1260 | void OMonitoringInterface::setChannel( int c ) | 1258 | void OMonitoringInterface::setChannel( int c ) |
1261 | { | 1259 | { |
1262 | // use standard WE channel switching protocol | 1260 | // use standard WE channel switching protocol |
1263 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); | 1261 | memset( &_if->_iwr, 0, sizeof( struct iwreq ) ); |
1264 | _if->_iwr.u.freq.m = c; | 1262 | _if->_iwr.u.freq.m = c; |
1265 | _if->_iwr.u.freq.e = 0; | 1263 | _if->_iwr.u.freq.e = 0; |
1266 | _if->wioctl( SIOCSIWFREQ ); | 1264 | _if->wioctl( SIOCSIWFREQ ); |
1267 | } | 1265 | } |
1268 | 1266 | ||
1269 | 1267 | ||
1270 | void OMonitoringInterface::setEnabled( bool ) | 1268 | void OMonitoringInterface::setEnabled( bool ) |
1271 | { | 1269 | { |
1272 | } | 1270 | } |
1273 | 1271 | ||
1274 | 1272 | ||
1275 | /*====================================================================================== | 1273 | /*====================================================================================== |
1276 | * OCiscoMonitoringInterface | 1274 | * OCiscoMonitoringInterface |
1277 | *======================================================================================*/ | 1275 | *======================================================================================*/ |
1278 | 1276 | ||
1279 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1277 | OCiscoMonitoringInterface::OCiscoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1280 | :OMonitoringInterface( iface, prismHeader ) | 1278 | :OMonitoringInterface( iface, prismHeader ) |
1281 | { | 1279 | { |
1282 | iface->setMonitoring( this ); | 1280 | iface->setMonitoring( this ); |
1283 | } | 1281 | } |
1284 | 1282 | ||
1285 | 1283 | ||
1286 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() | 1284 | OCiscoMonitoringInterface::~OCiscoMonitoringInterface() |
1287 | { | 1285 | { |
1288 | } | 1286 | } |
1289 | 1287 | ||
1290 | 1288 | ||
1291 | void OCiscoMonitoringInterface::setEnabled( bool /*b*/ ) | 1289 | void OCiscoMonitoringInterface::setEnabled( bool /*b*/ ) |
1292 | { | 1290 | { |
1293 | QString fname; | 1291 | QString fname; |
1294 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); | 1292 | fname.sprintf( "/proc/driver/aironet/%s", (const char*) _if->name() ); |
1295 | QFile f( fname ); | 1293 | QFile f( fname ); |
1296 | if ( !f.exists() ) return; | 1294 | if ( !f.exists() ) return; |
1297 | 1295 | ||
1298 | if ( f.open( IO_WriteOnly ) ) | 1296 | if ( f.open( IO_WriteOnly ) ) |
1299 | { | 1297 | { |
1300 | QTextStream s( &f ); | 1298 | QTextStream s( &f ); |
1301 | s << "Mode: r"; | 1299 | s << "Mode: r"; |
1302 | s << "Mode: y"; | 1300 | s << "Mode: y"; |
1303 | s << "XmitPower: 1"; | 1301 | s << "XmitPower: 1"; |
1304 | } | 1302 | } |
1305 | 1303 | ||
1306 | // flushing and closing will be done automatically when f goes out of scope | 1304 | // flushing and closing will be done automatically when f goes out of scope |
1307 | } | 1305 | } |
1308 | 1306 | ||
1309 | 1307 | ||
1310 | QString OCiscoMonitoringInterface::name() const | 1308 | QString OCiscoMonitoringInterface::name() const |
1311 | { | 1309 | { |
1312 | return "cisco"; | 1310 | return "cisco"; |
1313 | } | 1311 | } |
1314 | 1312 | ||
1315 | 1313 | ||
1316 | void OCiscoMonitoringInterface::setChannel( int ) | 1314 | void OCiscoMonitoringInterface::setChannel( int ) |
1317 | { | 1315 | { |
1318 | // cisco devices automatically switch channels when in monitor mode | 1316 | // cisco devices automatically switch channels when in monitor mode |
1319 | } | 1317 | } |
1320 | 1318 | ||
1321 | 1319 | ||
1322 | /*====================================================================================== | 1320 | /*====================================================================================== |
1323 | * OWlanNGMonitoringInterface | 1321 | * OWlanNGMonitoringInterface |
1324 | *======================================================================================*/ | 1322 | *======================================================================================*/ |
1325 | 1323 | ||
1326 | 1324 | ||
1327 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1325 | OWlanNGMonitoringInterface::OWlanNGMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1328 | :OMonitoringInterface( iface, prismHeader ) | 1326 | :OMonitoringInterface( iface, prismHeader ) |
1329 | { | 1327 | { |
1330 | iface->setMonitoring( this ); | 1328 | iface->setMonitoring( this ); |
1331 | } | 1329 | } |
1332 | 1330 | ||
1333 | 1331 | ||
1334 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() | 1332 | OWlanNGMonitoringInterface::~OWlanNGMonitoringInterface() |
1335 | { | 1333 | { |
1336 | } | 1334 | } |
1337 | 1335 | ||
1338 | 1336 | ||
1339 | void OWlanNGMonitoringInterface::setEnabled( bool b ) | 1337 | void OWlanNGMonitoringInterface::setEnabled( bool b ) |
1340 | { | 1338 | { |
1341 | //FIXME: do nothing if its already in the same mode | 1339 | //FIXME: do nothing if its already in the same mode |
1342 | 1340 | ||
1343 | QString enable = b ? "true" : "false"; | 1341 | QString enable = b ? "true" : "false"; |
1344 | QString prism = _prismHeader ? "true" : "false"; | 1342 | QString prism = _prismHeader ? "true" : "false"; |
1345 | QString cmd; | 1343 | QString cmd; |
1346 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 1344 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
1347 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); | 1345 | (const char*) _if->name(), 1, (const char*) enable, (const char*) prism ); |
1348 | system( cmd ); | 1346 | system( cmd ); |
1349 | } | 1347 | } |
1350 | 1348 | ||
1351 | 1349 | ||
1352 | QString OWlanNGMonitoringInterface::name() const | 1350 | QString OWlanNGMonitoringInterface::name() const |
1353 | { | 1351 | { |
1354 | return "wlan-ng"; | 1352 | return "wlan-ng"; |
1355 | } | 1353 | } |
1356 | 1354 | ||
1357 | 1355 | ||
1358 | void OWlanNGMonitoringInterface::setChannel( int c ) | 1356 | void OWlanNGMonitoringInterface::setChannel( int c ) |
1359 | { | 1357 | { |
1360 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. | 1358 | //NOTE: Older wlan-ng drivers automatically hopped channels while lnxreq_wlansniff=true. Newer ones don't. |
1361 | 1359 | ||
1362 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; | 1360 | QString enable = "true"; //_if->monitorMode() ? "true" : "false"; |
1363 | QString prism = _prismHeader ? "true" : "false"; | 1361 | QString prism = _prismHeader ? "true" : "false"; |
1364 | QString cmd; | 1362 | QString cmd; |
1365 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", | 1363 | cmd.sprintf( "$(which wlanctl-ng) %s lnxreq_wlansniff channel=%d enable=%s prismheader=%s", |
1366 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); | 1364 | (const char*) _if->name(), c, (const char*) enable, (const char*) prism ); |
1367 | system( cmd ); | 1365 | system( cmd ); |
1368 | } | 1366 | } |
1369 | 1367 | ||
1370 | 1368 | ||
1371 | /*====================================================================================== | 1369 | /*====================================================================================== |
1372 | * OHostAPMonitoringInterface | 1370 | * OHostAPMonitoringInterface |
1373 | *======================================================================================*/ | 1371 | *======================================================================================*/ |
1374 | 1372 | ||
1375 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1373 | OHostAPMonitoringInterface::OHostAPMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1376 | :OMonitoringInterface( iface, prismHeader ) | 1374 | :OMonitoringInterface( iface, prismHeader ) |
1377 | { | 1375 | { |
1378 | iface->setMonitoring( this ); | 1376 | iface->setMonitoring( this ); |
1379 | } | 1377 | } |
1380 | 1378 | ||
1381 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() | 1379 | OHostAPMonitoringInterface::~OHostAPMonitoringInterface() |
1382 | { | 1380 | { |
1383 | } | 1381 | } |
1384 | 1382 | ||
1385 | void OHostAPMonitoringInterface::setEnabled( bool b ) | 1383 | void OHostAPMonitoringInterface::setEnabled( bool b ) |
1386 | { | 1384 | { |
1387 | int monitorCode = _prismHeader ? 1 : 2; | 1385 | int monitorCode = _prismHeader ? 1 : 2; |
1388 | if ( b ) | 1386 | if ( b ) |
1389 | { | 1387 | { |
1390 | _if->setPrivate( "monitor", 1, monitorCode ); | 1388 | _if->setPrivate( "monitor", 1, monitorCode ); |
1391 | } | 1389 | } |
1392 | else | 1390 | else |
1393 | { | 1391 | { |
1394 | _if->setPrivate( "monitor", 1, 0 ); | 1392 | _if->setPrivate( "monitor", 1, 0 ); |
1395 | } | 1393 | } |
1396 | } | 1394 | } |
1397 | 1395 | ||
1398 | 1396 | ||
1399 | QString OHostAPMonitoringInterface::name() const | 1397 | QString OHostAPMonitoringInterface::name() const |
1400 | { | 1398 | { |
1401 | return "hostap"; | 1399 | return "hostap"; |
1402 | } | 1400 | } |
1403 | 1401 | ||
1404 | 1402 | ||
1405 | /*====================================================================================== | 1403 | /*====================================================================================== |
1406 | * OOrinocoNetworkInterface | 1404 | * OOrinocoNetworkInterface |
1407 | *======================================================================================*/ | 1405 | *======================================================================================*/ |
1408 | 1406 | ||
1409 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) | 1407 | OOrinocoMonitoringInterface::OOrinocoMonitoringInterface( ONetworkInterface* iface, bool prismHeader ) |
1410 | :OMonitoringInterface( iface, prismHeader ) | 1408 | :OMonitoringInterface( iface, prismHeader ) |
1411 | { | 1409 | { |
1412 | iface->setMonitoring( this ); | 1410 | iface->setMonitoring( this ); |
1413 | } | 1411 | } |
1414 | 1412 | ||
1415 | 1413 | ||
1416 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() | 1414 | OOrinocoMonitoringInterface::~OOrinocoMonitoringInterface() |
1417 | { | 1415 | { |
1418 | } | 1416 | } |
1419 | 1417 | ||
1420 | 1418 | ||
1421 | void OOrinocoMonitoringInterface::setChannel( int c ) | 1419 | void OOrinocoMonitoringInterface::setChannel( int c ) |
1422 | { | 1420 | { |
1423 | if ( !_if->hasPrivate( "monitor" ) ) | 1421 | if ( !_if->hasPrivate( "monitor" ) ) |