author | skyhusker <skyhusker> | 2005-04-20 10:20:20 (UTC) |
---|---|---|
committer | skyhusker <skyhusker> | 2005-04-20 10:20:20 (UTC) |
commit | f6b9c85c09692f298ffa5ee95e1f171a9e158502 (patch) (side-by-side diff) | |
tree | d147bc5b67eb9bc3c7f042a4fa2fb1868d37faef /libopie2/opienet | |
parent | 6ec538f7e4a84e4f76addaf558c415b7dffc659b (diff) | |
download | opie-f6b9c85c09692f298ffa5ee95e1f171a9e158502.zip opie-f6b9c85c09692f298ffa5ee95e1f171a9e158502.tar.gz opie-f6b9c85c09692f298ffa5ee95e1f171a9e158502.tar.bz2 |
Added function to set the associated AP address. Some improvements to scanNetwork(): read the signal quality, AP rates and fix channel reading when driver reports values < 1000.
-rw-r--r-- | libopie2/opienet/onetwork.cpp | 38 | ||||
-rw-r--r-- | libopie2/opienet/onetwork.h | 3 | ||||
-rw-r--r-- | libopie2/opienet/ostation.h | 2 |
3 files changed, 38 insertions, 5 deletions
diff --git a/libopie2/opienet/onetwork.cpp b/libopie2/opienet/onetwork.cpp index 546be9e..0a74019 100644 --- a/libopie2/opienet/onetwork.cpp +++ b/libopie2/opienet/onetwork.cpp @@ -29,39 +29,41 @@ */ /* OPIE */ #include <opie2/onetwork.h> #include <opie2/ostation.h> #include <opie2/odebug.h> /* QT */ #include <qfile.h> #include <qtextstream.h> +#include <qapplication.h> /* UNIX */ #include <assert.h> #include <arpa/inet.h> #include <errno.h> #include <string.h> #include <stdlib.h> #include <math.h> #include <sys/ioctl.h> #include <sys/socket.h> #include <sys/types.h> #include <unistd.h> #include <linux/sockios.h> #include <net/if_arp.h> +#include <net/ethernet.h> #include <stdarg.h> #ifndef NODEBUG #include <opie2/odebugmapper.h> using namespace Opie::Core; using namespace Opie::Net::Internal; DebugMapper* debugmapper = new DebugMapper(); #endif /*====================================================================================== * ONetwork @@ -482,24 +484,32 @@ void OWirelessNetworkInterface::init() buildPrivateList(); dumpInformation(); } bool OWirelessNetworkInterface::isAssociated() const { //FIXME: handle different modes return !(associatedAP() == OMacAddress::unknown); } +void OWirelessNetworkInterface::setAssociatedAP( const OMacAddress& mac ) const +{ + _iwr.u.ap_addr.sa_family = ARPHRD_ETHER; + ::memcpy(_iwr.u.ap_addr.sa_data, mac.native(), ETH_ALEN); + wioctl( SIOCSIWAP ); +} + + OMacAddress OWirelessNetworkInterface::associatedAP() const { if ( ioctl( SIOCGIWAP ) ) return (const unsigned char*) &_ifr.ifr_hwaddr.sa_data[0]; else return OMacAddress::unknown; } void OWirelessNetworkInterface::buildInformation() { //ML: If you listen carefully enough, you can hear lots of WLAN drivers suck @@ -897,31 +907,29 @@ OStationList* OWirelessNetworkInterface::scanNetwork() _iwr.u.data.pointer = &buffer[0]; _iwr.u.data.flags = 0; _iwr.u.data.length = sizeof buffer; if ( wioctl( SIOCGIWSCAN ) ) { results = true; continue; } else if ( errno == EAGAIN) { odebug << "ONetworkInterface::scanNetwork() - scan in progress..." << oendl; - #if 0 if ( qApp ) { qApp->processEvents( 100 ); continue; } - #endif tv.tv_sec = 0; tv.tv_usec = 100000; continue; } } odebug << "ONetworkInterface::scanNetwork() - scan finished." << oendl; if ( results ) { odebug << " - result length = " << _iwr.u.data.length << oendl; if ( !_iwr.u.data.length ) @@ -1118,39 +1126,59 @@ OStationList* OWirelessNetworkInterface::scanNetwork() stations->last()->macAddress = (const unsigned char*) &we->u.ap_addr.sa_data[0]; break; } case SIOCGIWMODE: { odebug << "SIOCGIWMODE" << oendl; stations->last()->type = modeToString( we->u.mode ); break; } case SIOCGIWFREQ: { odebug << "SIOCGIWFREQ" << oendl; - stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; + if ( we->u.freq.m > 1000 ) + stations->last()->channel = _channels[ static_cast<int>(double( we->u.freq.m ) * pow( 10.0, we->u.freq.e ) / 1000000) ]; + else + stations->last()->channel = static_cast<int>(((double) we->u.freq.m) * pow( 10.0, we->u.freq.e )); break; } case SIOCGIWESSID: { odebug << "SIOCGIWESSID" << oendl; we->u.essid.length = '\0'; // make sure it is zero terminated stations->last()->ssid = static_cast<const char*> (we->u.essid.pointer); odebug << "ESSID: " << stations->last()->ssid << oendl; break; } + case IWEVQUAL: + { + odebug << "IWEVQUAL" << oendl; + stations->last()->level = static_cast<int>(we->u.qual.level); + break; /* Quality part of statistics (scan) */ + } + case SIOCGIWENCODE: + { + odebug << "SIOCGIWENCODE" << oendl; + stations->last()->encrypted = !(we->u.data.flags & IW_ENCODE_DISABLED); + break; + } + + case SIOCGIWRATE: + { + odebug << "SIOCGIWRATE" << oendl; + stations->last()->rates.append(we->u.bitrate.value); + break; + } case SIOCGIWSENS: odebug << "SIOCGIWSENS" << oendl; break; - case SIOCGIWENCODE: odebug << "SIOCGIWENCODE" << oendl; break; case IWEVTXDROP: odebug << "IWEVTXDROP" << oendl; break; /* Packet dropped to excessive retry */ - case IWEVQUAL: odebug << "IWEVQUAL" << oendl; break; /* Quality part of statistics (scan) */ case IWEVCUSTOM: odebug << "IWEVCUSTOM" << oendl; break; /* Driver specific ascii string */ case IWEVREGISTERED: odebug << "IWEVREGISTERED" << oendl; break; /* Discovered a new node (AP mode) */ case IWEVEXPIRED: odebug << "IWEVEXPIRED" << oendl; break; /* Expired a node (AP mode) */ default: odebug << "unhandled event" << oendl; } } while (true); } else { odebug << " - no results (timeout) :(" << oendl; } diff --git a/libopie2/opienet/onetwork.h b/libopie2/opienet/onetwork.h index 4d9912d..fa9f39f 100644 --- a/libopie2/opienet/onetwork.h +++ b/libopie2/opienet/onetwork.h @@ -404,24 +404,27 @@ class OWirelessNetworkInterface : public ONetworkInterface */ virtual void setPrivate( const QString& command, int number, ... ); /** * @returns true if the interface is featuring the private IOCTL @command. */ virtual bool hasPrivate( const QString& command ); virtual void getPrivate( const QString& command ); //FIXME: Implement and document this /** * @returns true if the interface is associated to an access point * @note: This information is only valid if the interface is in managed mode. */ virtual bool isAssociated() const; + /** Set the @a mac associated AP address. + */ + virtual void setAssociatedAP( const OMacAddress& mac ) const; /** * @returns the MAC address of the Access Point if the device is in infrastructure mode. * @returns a (more or less random) cell ID address if the device is in adhoc mode. */ virtual OMacAddress associatedAP() const; /** * Set the @a ssid (Service Set ID) string. This is used to decide * which network to associate with (use "any" to let the driver decide). */ virtual void setSSID( const QString& ssid ); /** * @returns the current SSID (Service Set ID). diff --git a/libopie2/opienet/ostation.h b/libopie2/opienet/ostation.h index 5219d92..86c9a52 100644 --- a/libopie2/opienet/ostation.h +++ b/libopie2/opienet/ostation.h @@ -28,24 +28,25 @@ */ #ifndef OSTATION_H #define OSTATION_H #include <opie2/onetutils.h> #include <qlist.h> #include <qstring.h> #include <qhostaddress.h> #include <qobject.h> +#include <qvaluelist.h> #include <sys/types.h> namespace Opie { namespace Net { class OStation; typedef QList<OStation> OStationList; /*====================================================================================== @@ -62,22 +63,23 @@ class OStation /* Ethernet */ QString type; OMacAddress macAddress; QHostAddress ipAddress; /* WaveLan */ QString ssid; OMacAddress apAddress; int channel; int level; bool encrypted; + QValueList <int> rates; private: class Private; Private *d; }; } } #endif // OSTATION_H |