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 @@ -258,2 +258,3 @@ QString ONetworkInterface::ipV4Address() const return "<unknown>"; + } @@ -476,3 +477,3 @@ bool OWirelessNetworkInterface::isAssociated() const //FIXME: handle different modes - return associatedAP() != "44:44:44:44:44:44"; + return !(associatedAP() == OMacAddress::unknown); } @@ -480,22 +481,8 @@ bool OWirelessNetworkInterface::isAssociated() const -QString OWirelessNetworkInterface::associatedAP() const +OMacAddress OWirelessNetworkInterface::associatedAP() const { - //FIXME: use OMacAddress - QString mac; - if ( ioctl( SIOCGIWAP ) ) - { - mac.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", - _ifr.ifr_hwaddr.sa_data[0]&0xff, - _ifr.ifr_hwaddr.sa_data[1]&0xff, - _ifr.ifr_hwaddr.sa_data[2]&0xff, - _ifr.ifr_hwaddr.sa_data[3]&0xff, - _ifr.ifr_hwaddr.sa_data[4]&0xff, - _ifr.ifr_hwaddr.sa_data[5]&0xff ); - } + return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; else - { - mac = "<Unknown>"; - } - return mac; + return OMacAddress::unknown; } @@ -690,14 +677,3 @@ void OWirelessNetworkInterface::setMode( const QString& mode ) { - if ( mode == "auto" ) _iwr.u.mode = IW_MODE_AUTO; - else if ( mode == "adhoc" ) _iwr.u.mode = IW_MODE_ADHOC; - else if ( mode == "managed" ) _iwr.u.mode = IW_MODE_INFRA; - else if ( mode == "master" ) _iwr.u.mode = IW_MODE_MASTER; - else if ( mode == "repeater" ) _iwr.u.mode = IW_MODE_REPEAT; - else if ( mode == "secondary" ) _iwr.u.mode = IW_MODE_SECOND; - else if ( mode == "monitor" ) _iwr.u.mode = IW_MODE_MONITOR; - else - { - qDebug( "ONetwork: Warning! Invalid IEEE 802.11 mode '%s' specified.", (const char*) mode ); - return; - } + _iwr.u.mode = stringToMode( mode ); wioctl( SIOCSIWMODE ); @@ -712,13 +688,3 @@ QString OWirelessNetworkInterface::mode() const } - switch ( _iwr.u.mode ) - { - case IW_MODE_AUTO: return "auto"; - case IW_MODE_ADHOC: return "adhoc"; - case IW_MODE_INFRA: return "managed"; - case IW_MODE_MASTER: return "master"; - case IW_MODE_REPEAT: return "repeater"; - case IW_MODE_SECOND: return "secondary"; - case IW_MODE_MONITOR: return "monitor"; - default: assert( 0 ); // shouldn't happen - } + return modeToString( _iwr.u.mode ); } @@ -832,3 +798,3 @@ void OWirelessNetworkInterface::setSSID( const QString& ssid ) -int OWirelessNetworkInterface::scanNetwork() +OStationList* OWirelessNetworkInterface::scanNetwork() { @@ -838,5 +804,7 @@ int OWirelessNetworkInterface::scanNetwork() { - return -1; + return 0; } + OStationList* stations = new OStationList(); + int timeout = 1000000; @@ -888,3 +856,3 @@ int OWirelessNetworkInterface::scanNetwork() qDebug( " - no results (empty neighbourhood)" ); - return 0; + return stations; } @@ -894,4 +862,2 @@ int OWirelessNetworkInterface::scanNetwork() - int stations = 0; - // parse results @@ -908,6 +874,27 @@ int OWirelessNetworkInterface::scanNetwork() { - case SIOCGIWAP: qDebug( "SIOCGIWAP" ); stations++; break; - case SIOCGIWMODE: qDebug( "SIOCGIWMODE" ); break; - case SIOCGIWFREQ: qDebug( "SIOCGIWFREQ" ); break; - case SIOCGIWESSID: qDebug( "SIOCGIWESSID" ); break; + case SIOCGIWAP: + { + qDebug( "SIOCGIWAP" ); + stations->append( new OStation() ); + stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; + break; + } + case SIOCGIWMODE: + { + qDebug( "SIOCGIWMODE" ); + stations->last()->type = modeToString( we->u.mode ); + break; + } + case SIOCGIWFREQ: + { + qDebug( "SIOCGIWFREQ" ); + stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; + break; + } + case SIOCGIWESSID: + { + qDebug( "SIOCGIWESSID" ); + stations->last()->ssid = we->u.essid.pointer; + break; + } case SIOCGIWSENS: qDebug( "SIOCGIWSENS" ); break; @@ -926,2 +913,4 @@ int OWirelessNetworkInterface::scanNetwork() + return stations; + } @@ -930,3 +919,3 @@ int OWirelessNetworkInterface::scanNetwork() qDebug( " - no results (timeout) :(" ); - return 0; + return stations; } |