Diffstat (limited to 'libopie2/opienet/onetwork.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 91 |
1 files changed, 40 insertions, 51 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index a85a510..50c6679 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp | |||
@@ -253,12 +253,13 @@ QString ONetworkInterface::ipV4Address() const | |||
253 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; | 253 | struct sockaddr_in* sa = (struct sockaddr_in *) &_ifr.ifr_addr; |
254 | //FIXME: Use QHostAddress here | 254 | //FIXME: Use QHostAddress here |
255 | return QString( inet_ntoa( sa->sin_addr ) ); | 255 | return QString( inet_ntoa( sa->sin_addr ) ); |
256 | } | 256 | } |
257 | else | 257 | else |
258 | return "<unknown>"; | 258 | return "<unknown>"; |
259 | |||
259 | } | 260 | } |
260 | 261 | ||
261 | 262 | ||
262 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) | 263 | void ONetworkInterface::setMacAddress( const OMacAddress& addr ) |
263 | { | 264 | { |
264 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; | 265 | _ifr.ifr_hwaddr.sa_family = ARPHRD_ETHER; |
@@ -471,36 +472,22 @@ void OWirelessNetworkInterface::init() | |||
471 | } | 472 | } |
472 | 473 | ||
473 | 474 | ||
474 | bool OWirelessNetworkInterface::isAssociated() const | 475 | bool OWirelessNetworkInterface::isAssociated() const |
475 | { | 476 | { |
476 | //FIXME: handle different modes | 477 | //FIXME: handle different modes |
477 | return associatedAP() != "44:44:44:44:44:44"; | 478 | return !(associatedAP() == OMacAddress::unknown); |
478 | } | 479 | } |
479 | 480 | ||
480 | 481 | ||
481 | QString OWirelessNetworkInterface::associatedAP() const | 482 | OMacAddress OWirelessNetworkInterface::associatedAP() const |
482 | { | 483 | { |
483 | //FIXME: use OMacAddress | ||
484 | QString mac; | ||
485 | |||
486 | if ( ioctl( SIOCGIWAP ) ) | 484 | if ( ioctl( SIOCGIWAP ) ) |
487 | { | 485 | return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; |
488 | mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | ||
489 | _ifr.ifr_hwaddr.sa_data[0]&0xff, | ||
490 | _ifr.ifr_hwaddr.sa_data[1]&0xff, | ||
491 | _ifr.ifr_hwaddr.sa_data[2]&0xff, | ||
492 | _ifr.ifr_hwaddr.sa_data[3]&0xff, | ||
493 | _ifr.ifr_hwaddr.sa_data[4]&0xff, | ||
494 | _ifr.ifr_hwaddr.sa_data[5]&0xff ); | ||
495 | } | ||
496 | else | 486 | else |
497 | { | 487 | return OMacAddress::unknown; |
498 | mac = "<Unknown>"; | ||
499 | } | ||
500 | return mac; | ||
501 | } | 488 | } |
502 | 489 | ||
503 | 490 | ||
504 | void OWirelessNetworkInterface::buildInformation() | 491 | void OWirelessNetworkInterface::buildInformation() |
505 | { | 492 | { |
506 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck | 493 | //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck |
@@ -685,45 +672,24 @@ OChannelHopper* OWirelessNetworkInterface::channelHopper() const | |||
685 | return _hopper; | 672 | return _hopper; |
686 | } | 673 | } |
687 | 674 | ||
688 | 675 | ||
689 | void OWirelessNetworkInterface::setMode( const QString& mode ) | 676 | void OWirelessNetworkInterface::setMode( const QString& mode ) |
690 | { | 677 | { |
691 | if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; | 678 | _iwr.u.mode = stringToMode( mode ); |
692 | else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; | ||
693 | else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; | ||
694 | else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; | ||
695 | else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; | ||
696 | else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; | ||
697 | else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; | ||
698 | else | ||
699 | { | ||
700 | qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); | ||
701 | return; | ||
702 | } | ||
703 | wioctl( SIOCSIWMODE ); | 679 | wioctl( SIOCSIWMODE ); |
704 | } | 680 | } |
705 | 681 | ||
706 | 682 | ||
707 | QString OWirelessNetworkInterface::mode() const | 683 | QString OWirelessNetworkInterface::mode() const |
708 | { | 684 | { |
709 | if ( !wioctl( SIOCGIWMODE ) ) | 685 | if ( !wioctl( SIOCGIWMODE ) ) |
710 | { | 686 | { |
711 | return "<unknown>"; | 687 | return "<unknown>"; |
712 | } | 688 | } |
713 | switch ( _iwr.u.mode ) | 689 | return modeToString( _iwr.u.mode ); |
714 | { | ||
715 | case IW_MODE_AUTO: return "auto"; | ||
716 | case IW_MODE_ADHOC: return "adhoc"; | ||
717 | case IW_MODE_INFRA: return "managed"; | ||
718 | case IW_MODE_MASTER: return "master"; | ||
719 | case IW_MODE_REPEAT: return "repeater"; | ||
720 | case IW_MODE_SECOND: return "secondary"; | ||
721 | case IW_MODE_MONITOR: return "monitor"; | ||
722 | default: assert( 0 ); // shouldn't happen | ||
723 | } | ||
724 | } | 690 | } |
725 | 691 | ||
726 | 692 | ||
727 | void OWirelessNetworkInterface::setMonitorMode( bool b ) | 693 | void OWirelessNetworkInterface::setMonitorMode( bool b ) |
728 | { | 694 | { |
729 | if ( _mon ) | 695 | if ( _mon ) |
@@ -827,21 +793,23 @@ void OWirelessNetworkInterface::setSSID( const QString& ssid ) | |||
827 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); | 793 | _iwr.u.essid.pointer = const_cast<char*>( (const char*) ssid ); |
828 | _iwr.u.essid.length = ssid.length(); | 794 | _iwr.u.essid.length = ssid.length(); |
829 | wioctl( SIOCSIWESSID ); | 795 | wioctl( SIOCSIWESSID ); |
830 | } | 796 | } |
831 | 797 | ||
832 | 798 | ||
833 | int OWirelessNetworkInterface::scanNetwork() | 799 | OStationList* OWirelessNetworkInterface::scanNetwork() |
834 | { | 800 | { |
835 | _iwr.u.param.flags = IW_SCAN_DEFAULT; | 801 | _iwr.u.param.flags = IW_SCAN_DEFAULT; |
836 | _iwr.u.param.value = 0; | 802 | _iwr.u.param.value = 0; |
837 | if ( !wioctl( SIOCSIWSCAN ) ) | 803 | if ( !wioctl( SIOCSIWSCAN ) ) |
838 | { | 804 | { |
839 | return -1; | 805 | return 0; |
840 | } | 806 | } |
841 | 807 | ||
808 | OStationList* stations = new OStationList(); | ||
809 | |||
842 | int timeout = 1000000; | 810 | int timeout = 1000000; |
843 | 811 | ||
844 | qDebug( "ONetworkInterface::scanNetwork() - scan started." ); | 812 | qDebug( "ONetworkInterface::scanNetwork() - scan started." ); |
845 | 813 | ||
846 | bool results = false; | 814 | bool results = false; |
847 | struct timeval tv; | 815 | struct timeval tv; |
@@ -883,36 +851,55 @@ int OWirelessNetworkInterface::scanNetwork() | |||
883 | if ( results ) | 851 | if ( results ) |
884 | { | 852 | { |
885 | qDebug( " - result length = %d", _iwr.u.data.length ); | 853 | qDebug( " - result length = %d", _iwr.u.data.length ); |
886 | if ( !_iwr.u.data.length ) | 854 | if ( !_iwr.u.data.length ) |
887 | { | 855 | { |
888 | qDebug( " - no results (empty neighbourhood)" ); | 856 | qDebug( " - no results (empty neighbourhood)" ); |
889 | return 0; | 857 | return stations; |
890 | } | 858 | } |
891 | 859 | ||
892 | qDebug( " - results are in!" ); | 860 | qDebug( " - results are in!" ); |
893 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); | 861 | dumpBytes( (const unsigned char*) &buffer[0], _iwr.u.data.length ); |
894 | 862 | ||
895 | int stations = 0; | ||
896 | |||
897 | // parse results | 863 | // parse results |
898 | 864 | ||
899 | int offset = 0; | 865 | int offset = 0; |
900 | struct iw_event* we = (struct iw_event*) &buffer[0]; | 866 | struct iw_event* we = (struct iw_event*) &buffer[0]; |
901 | 867 | ||
902 | while ( offset < _iwr.u.data.length ) | 868 | while ( offset < _iwr.u.data.length ) |
903 | { | 869 | { |
904 | //const char* cmd = *(*_ioctlmap)[we->cmd]; | 870 | //const char* cmd = *(*_ioctlmap)[we->cmd]; |
905 | //if ( !cmd ) cmd = "<unknown>"; | 871 | //if ( !cmd ) cmd = "<unknown>"; |
906 | qDebug( "reading next event... cmd=%d, len=%d", we->cmd, we->len ); | 872 | qDebug( "reading next event... cmd=%d, len=%d", we->cmd, we->len ); |
907 | switch (we->cmd) | 873 | switch (we->cmd) |
908 | { | 874 | { |
909 | case SIOCGIWAP: qDebug( "SIOCGIWAP" ); stations++; break; | 875 | case SIOCGIWAP: |
910 | case SIOCGIWMODE: qDebug( "SIOCGIWMODE" ); break; | 876 | { |
911 | case SIOCGIWFREQ: qDebug( "SIOCGIWFREQ" ); break; | 877 | qDebug( "SIOCGIWAP" ); |
912 | case SIOCGIWESSID: qDebug( "SIOCGIWESSID" ); break; | 878 | stations->append( new OStation() ); |
879 | stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; | ||
880 | break; | ||
881 | } | ||
882 | case SIOCGIWMODE: | ||
883 | { | ||
884 | qDebug( "SIOCGIWMODE" ); | ||
885 | stations->last()->type = modeToString( we->u.mode ); | ||
886 | break; | ||
887 | } | ||
888 | case SIOCGIWFREQ: | ||
889 | { | ||
890 | qDebug( "SIOCGIWFREQ" ); | ||
891 | stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; | ||
892 | break; | ||
893 | } | ||
894 | case SIOCGIWESSID: | ||
895 | { | ||
896 | qDebug( "SIOCGIWESSID" ); | ||
897 | stations->last()->ssid = we->u.essid.pointer; | ||
898 | break; | ||
899 | } | ||
913 | case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break; | 900 | case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break; |
914 | case SIOCGIWENCODE: qDebug( "SIOCGIWENCODE" ); break; | 901 | case SIOCGIWENCODE: qDebug( "SIOCGIWENCODE" ); break; |
915 | case IWEVTXDROP: qDebug( "IWEVTXDROP" ); break; /* Packet dropped to excessive retry */ | 902 | case IWEVTXDROP: qDebug( "IWEVTXDROP" ); break; /* Packet dropped to excessive retry */ |
916 | case IWEVQUAL: qDebug( "IWEVQUAL" ); break; /* Quality part of statistics (scan) */ | 903 | case IWEVQUAL: qDebug( "IWEVQUAL" ); break; /* Quality part of statistics (scan) */ |
917 | case IWEVCUSTOM: qDebug( "IWEVCUSTOM" ); break; /* Driver specific ascii string */ | 904 | case IWEVCUSTOM: qDebug( "IWEVCUSTOM" ); break; /* Driver specific ascii string */ |
918 | case IWEVREGISTERED: qDebug( "IWEVREGISTERED" ); break; /* Discovered a new node (AP mode) */ | 905 | case IWEVREGISTERED: qDebug( "IWEVREGISTERED" ); break; /* Discovered a new node (AP mode) */ |
@@ -921,17 +908,19 @@ int OWirelessNetworkInterface::scanNetwork() | |||
921 | } | 908 | } |
922 | 909 | ||
923 | offset += we->len; | 910 | offset += we->len; |
924 | we = (struct iw_event*) &buffer[offset]; | 911 | we = (struct iw_event*) &buffer[offset]; |
925 | } | 912 | } |
926 | 913 | ||
914 | return stations; | ||
915 | |||
927 | } | 916 | } |
928 | else | 917 | else |
929 | { | 918 | { |
930 | qDebug( " - no results (timeout) :(" ); | 919 | qDebug( " - no results (timeout) :(" ); |
931 | return 0; | 920 | return stations; |
932 | } | 921 | } |
933 | } | 922 | } |
934 | 923 | ||
935 | 924 | ||
936 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const | 925 | bool OWirelessNetworkInterface::wioctl( int call, struct iwreq& iwreq ) const |
937 | { | 926 | { |