-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 | |||
@@ -516,43 +516,42 @@ OMacAddress OWirelessNetworkInterface::associatedAP() const | |||
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 | { |
@@ -569,55 +568,54 @@ void OWirelessNetworkInterface::buildInformation() | |||
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 |
@@ -1145,39 +1143,39 @@ OStationList* OWirelessNetworkInterface::scanNetwork() | |||
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; |