author | benmeyer <benmeyer> | 2002-10-22 14:48:26 (UTC) |
---|---|---|
committer | benmeyer <benmeyer> | 2002-10-22 14:48:26 (UTC) |
commit | 4fbca156e2bede574f458f9d96cc650c75219973 (patch) (side-by-side diff) | |
tree | 85a0a0a3ad44f744c55ba2076471438b4c25fc21 | |
parent | 916da240f6ff546fd01ea803bf2301ee2c6a836b (diff) | |
download | opie-4fbca156e2bede574f458f9d96cc650c75219973.zip opie-4fbca156e2bede574f458f9d96cc650c75219973.tar.gz opie-4fbca156e2bede574f458f9d96cc650c75219973.tar.bz2 |
Added wireless extensions abstraction
-rw-r--r-- | noncore/net/networksetup/wlan/info.ui | 98 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/wextensions.cpp | 158 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/wextensions.h | 32 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/wlan.pro | 4 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/wlanmodule.cpp | 164 | ||||
-rw-r--r-- | noncore/net/networksetup/wlan/wlanmodule.h | 5 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/info.ui | 98 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wextensions.cpp | 158 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wextensions.h | 32 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlan.pro | 4 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanmodule.cpp | 164 | ||||
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanmodule.h | 5 |
12 files changed, 654 insertions, 268 deletions
diff --git a/noncore/net/networksetup/wlan/info.ui b/noncore/net/networksetup/wlan/info.ui index 018ace3..4e85b1b 100644 --- a/noncore/net/networksetup/wlan/info.ui +++ b/noncore/net/networksetup/wlan/info.ui @@ -1,46 +1,46 @@ <!DOCTYPE UI><UI> <class>WlanInfo</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>WlanInfo</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>283</width> + <width>279</width> <height>292</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>WLAN Information</string> </property> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>0</number> </property> <widget> <class>QTabWidget</class> <property stdset="1"> <name>name</name> <cstring>tabWidget</cstring> </property> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>Widget2</cstring> </property> <attribute> <name>title</name> <string>802.11b</string> </attribute> @@ -177,58 +177,154 @@ <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> </widget> <spacer row="5" column="1" > <property> <name>name</name> <cstring>Spacer7</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </grid> </widget> + <widget> + <class>QWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>tab</cstring> + </property> + <attribute> + <name>title</name> + <string>Statistics</string> + </attribute> + <grid> + <property stdset="1"> + <name>margin</name> + <number>11</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <spacer row="3" column="1" > + <property> + <name>name</name> + <cstring>Spacer2</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Vertical</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>Expanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget row="0" column="1" > + <class>QProgressBar</class> + <property stdset="1"> + <name>name</name> + <cstring>signalProgressBar</cstring> + </property> + </widget> + <widget row="1" column="1" > + <class>QProgressBar</class> + <property stdset="1"> + <name>name</name> + <cstring>noiseProgressBar</cstring> + </property> + </widget> + <widget row="2" column="1" > + <class>QProgressBar</class> + <property stdset="1"> + <name>name</name> + <cstring>qualityProgressBar</cstring> + </property> + </widget> + <widget row="0" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel1_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Signal</string> + </property> + </widget> + <widget row="1" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel2_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Noise</string> + </property> + </widget> + <widget row="2" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel3_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Quality</string> + </property> + </widget> + </grid> + </widget> </widget> </vbox> </widget> <customwidgets> <customwidget> <class>QWidget</class> <header location="local">qwidget.h</header> <sizehint> <width>100</width> <height>100</height> </sizehint> <container>0</container> <sizepolicy> <hordata>7</hordata> <verdata>7</verdata> </sizepolicy> <pixmap>image0</pixmap> </customwidget> </customwidgets> <images> <image> <name>image0</name> <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> </image> </images> </UI> diff --git a/noncore/net/networksetup/wlan/wextensions.cpp b/noncore/net/networksetup/wlan/wextensions.cpp new file mode 100644 index 0000000..f45ebf2 --- a/dev/null +++ b/noncore/net/networksetup/wlan/wextensions.cpp @@ -0,0 +1,158 @@ +#include "wextensions.h" + +#include <qfile.h> +#include <qtextstream.h> + +#include <arpa/inet.h> +#include <sys/socket.h> +#include <sys/ioctl.h> + +#include <math.h> + +#define PROCNETWIRELESS "/proc/net/wireless" +#define IW_LOWER 140 +#define IW_UPPER 200 + +/** + * Constructor. Sets hasWirelessExtensions + */ +WExtensions::WExtensions(QString interfaceName){ + interface = interfaceName; + fd = socket( AF_INET, SOCK_DGRAM, 0 ); + + const char* buffer[200]; + memset( &iwr, 0, sizeof( iwr ) ); + iwr.u.essid.pointer = (caddr_t) buffer; + iwr.u.essid.length = IW_ESSID_MAX_SIZE; + iwr.u.essid.flags = 0; + + // check if it is an IEEE 802.11 standard conform + // wireless device by sending SIOCGIWESSID + // which also gives back the Extended Service Set ID + // (see IEEE 802.11 for more information) + + const char* iname = interface.latin1(); + strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); + if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) ) + hasWirelessExtensions = true; + else + hasWirelessExtensions = false; +} + +/** + * @return QString the station name of the access point. + */ +QString WExtensions::station(){ + if(!hasWirelessExtensions) + return QString(); + const char* buffer[200]; + iwr.u.data.pointer = (caddr_t) buffer; + iwr.u.data.length = IW_ESSID_MAX_SIZE; + iwr.u.data.flags = 0; + if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){ + iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; + return QString(iwr.u.data.pointer); + } + return QString(); +} + +/** + * @return QString the essid of the host 802.11 access point. + */ +QString WExtensions::essid(){ + if(!hasWirelessExtensions) + return QString(); + if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){ + iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; + return QString(iwr.u.essid.pointer); + } + return QString(); +} + +/** + * @return QString the mode of interface + */ +QString WExtensions::mode(){ + if(!hasWirelessExtensions) + return QString(); + if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) ) + return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed"); + return QString(); +} + +/** + * Get the frequency that the interface is running at. + * @return int the frequency that the interfacae is running at. + */ +double WExtensions::frequency(){ + if(!hasWirelessExtensions) + return 0; + if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr )) + return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000); + return 0;; +} + +/** + * @return QString the AccessPoint that the interface is connected to. + */ +QString WExtensions::ap(){ + if(!hasWirelessExtensions) + return QString(); + if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){ + QString ap; + ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", + iwr.u.ap_addr.sa_data[0]&0xff, + iwr.u.ap_addr.sa_data[1]&0xff, + iwr.u.ap_addr.sa_data[2]&0xff, + iwr.u.ap_addr.sa_data[3]&0xff, + iwr.u.ap_addr.sa_data[4]&0xff, + iwr.u.ap_addr.sa_data[5]&0xff ); + return ap; + } + else return QString(); + +} + +bool WExtensions::stats(int &signal, int &noise, int &quality){ + // gather link quality from /proc/net/wireless + if(!QFile::exists(PROCNETWIRELESS)) + return false; + + char c; + QString status; + QString name; + + QFile wfile( PROCNETWIRELESS ); + if(!wfile.open( IO_ReadOnly )) + return false; + + QTextStream wstream( &wfile ); + wstream.readLine(); // skip the first two lines + wstream.readLine(); // because they only contain headers + while(!wstream.atEnd()){ + wstream >> name >> status >> quality >> c >> signal >> c >> noise; + if(name == interface){ + if ( quality > 92 ) + #ifdef MDEBUG + qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); + #endif + if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) + #ifdef MDEBUG + qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); + #endif + if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) + #ifdef MDEBUG + qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); + #endif + return true; + } + } + + qDebug("Card no longer present"); + quality = -1; + signal = IW_LOWER; + noise = IW_LOWER; + return false; +} + +// wextensions.cpp diff --git a/noncore/net/networksetup/wlan/wextensions.h b/noncore/net/networksetup/wlan/wextensions.h new file mode 100644 index 0000000..29997f5 --- a/dev/null +++ b/noncore/net/networksetup/wlan/wextensions.h @@ -0,0 +1,32 @@ +#ifndef WEXTENSIONS_H +#define WEXTENSIONS_H + +#include <qstring.h> + +#include <netinet/ip.h> +#include <linux/wireless.h> + +class WExtensions { + +public: + WExtensions(QString interfaceName); + QString getInterfaceName(){return interface;}; + bool doesHaveWirelessExtensions(){return hasWirelessExtensions;}; + QString station(); + QString essid(); + QString mode(); + double frequency(); + QString ap(); + bool stats( int &signal, int &noise, int &quality); + +private: + bool hasWirelessExtensions; + QString interface; + + // Used in we calls + struct iwreq iwr; + int fd; + +}; + +#endif diff --git a/noncore/net/networksetup/wlan/wlan.pro b/noncore/net/networksetup/wlan/wlan.pro index 5b94a95..432a096 100644 --- a/noncore/net/networksetup/wlan/wlan.pro +++ b/noncore/net/networksetup/wlan/wlan.pro @@ -1,12 +1,12 @@ TEMPLATE = lib CONFIG += qt warn_on release #CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/plugins/networksetup -HEADERS = wlanimp.h wlanmodule.h -SOURCES = wlanimp.cpp wlanmodule.cpp +HEADERS = wlanimp.h wlanmodule.h wextensions.h +SOURCES = wlanimp.cpp wlanmodule.cpp wextensions.cpp INCLUDEPATH += $(OPIEDIR)/include ../ DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe INTERFACES = wlan.ui info.ui TARGET = wlanplugin VERSION = 1.0.0 diff --git a/noncore/net/networksetup/wlan/wlanmodule.cpp b/noncore/net/networksetup/wlan/wlanmodule.cpp index 24cb1cd..ab0b9a5 100644 --- a/noncore/net/networksetup/wlan/wlanmodule.cpp +++ b/noncore/net/networksetup/wlan/wlanmodule.cpp @@ -1,219 +1,125 @@ #include "wlanmodule.h" #include "wlanimp.h" #include "info.h" - -#include <arpa/inet.h> -#include <sys/socket.h> -#include <linux/if_ether.h> -#include <netinet/ip.h> -#include <sys/ioctl.h> -#include <linux/wireless.h> - -#include <unistd.h> -#include <math.h> -#include <errno.h> -#include <string.h> -#include <stdio.h> - -#include <stdlib.h> +#include "wextensions.h" #include <qlabel.h> +#include <qprogressbar.h> /** * Constructor, find all of the possible interfaces */ WLANModule::WLANModule() : Module() { // get output from iwconfig } /** + */ +WLANModule::~WLANModule(){ + Interface *i; + for ( i=list.first(); i != 0; i=list.next() ) + delete i; +} + +/** * Change the current profile */ void WLANModule::setProfile(QString newProfile){ profile = newProfile; } /** * get the icon name for this device. * @param Interface* can be used in determining the icon. * @return QString the icon name (minus .png, .gif etc) */ QString WLANModule::getPixmapName(Interface* ){ return "wlan"; } /** * Check to see if the interface i is owned by this module. * @param Interface* interface to check against * @return bool true if i is owned by this module, false otherwise. */ bool WLANModule::isOwner(Interface *i){ - if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ + WExtensions we(i->getInterfaceName()); + if(!we.doesHaveWirelessExtensions()) + return false; + + //if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ i->setHardwareName("802.11b"); + list.append(i); return true; - } - return false; + //} + //return false; } /** * Create, set tabWiget and return the WLANConfigure Module * @param tabWidget a pointer to the tab widget that this configure has. * @return QWidget* pointer to the tab widget in this modules configure. */ -QWidget *WLANModule::configure(Interface *i, QTabWidget **tabWidget){ +QWidget *WLANModule::configure(Interface *, QTabWidget **tabWidget){ WLANImp *wlanconfig = new WLANImp(0, "WlanConfig"); (*tabWidget) = wlanconfig->tabWidget; return wlanconfig; } /** * Create, set tabWiget and return the Information Module * @param tabWidget a pointer to the tab widget that this information has. * @return QWidget* pointer to the tab widget in this modules info. */ QWidget *WLANModule::information(Interface *i, QTabWidget **tabWidget){ - return NULL; + WExtensions we(i->getInterfaceName()); + if(!we.doesHaveWirelessExtensions()) + return NULL; + WlanInfo *info = new WlanInfo(0, "wireless info"); (*tabWidget) = info->tabWidget; - - struct ifreq ifr; - struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; - int fd = socket( AF_INET, SOCK_DGRAM, 0 ); - const char* buffer[200]; - struct iwreq iwr; - memset( &iwr, 0, sizeof( iwr ) ); - iwr.u.essid.pointer = (caddr_t) buffer; - iwr.u.essid.length = IW_ESSID_MAX_SIZE; - iwr.u.essid.flags = 0; - - // check if it is an IEEE 802.11 standard conform - // wireless device by sending SIOCGIWESSID - // which also gives back the Extended Service Set ID - // (see IEEE 802.11 for more information) - - QString n = (i->getInterfaceName()); - const char* iname = n.latin1(); - strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); - int result = ioctl( fd, SIOCGIWESSID, &iwr ); - if ( result == 0 ){ - //hasWirelessExtensions = true; - iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; - info->essidLabel->setText(QString(iwr.u.essid.pointer)); - } - else - return info; - //info->essidLabel->setText("*** Unknown ***"); - - // Address of associated access-point - result = ioctl( fd, SIOCGIWAP, &iwr ); - if ( result == 0 ){ - QString foo = foo.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", - iwr.u.ap_addr.sa_data[0]&0xff, - iwr.u.ap_addr.sa_data[1]&0xff, - iwr.u.ap_addr.sa_data[2]&0xff, - iwr.u.ap_addr.sa_data[3]&0xff, - iwr.u.ap_addr.sa_data[4]&0xff, - iwr.u.ap_addr.sa_data[5]&0xff ); - info->apLabel->setText(foo); - } - else info->apLabel->setText("*** Unknown ***"); - - iwr.u.data.pointer = (caddr_t) buffer; - iwr.u.data.length = IW_ESSID_MAX_SIZE; - iwr.u.data.flags = 0; - result = ioctl( fd, SIOCGIWNICKN, &iwr ); - if ( result == 0 ){ - iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; - info->stationLabel->setText(iwr.u.data.pointer); - } - else info->stationLabel->setText("*** Unknown ***"); - - result = ioctl( fd, SIOCGIWMODE, &iwr ); - if ( result == 0 ) - info->modeLabel->setText( QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed")); - else - info->modeLabel->setText("*** Unknown ***"); - - result = ioctl( fd, SIOCGIWFREQ, &iwr ); - if ( result == 0 ) - info->freqLabel->setText(QString("%1").arg((double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000))); - else - info->freqLabel->setText("*** Unknown ***"); - - /* - // gather link quality from /proc/net/wireless - - char c; - QString status; - QString name; - QFile wfile( PROCNETWIRELESS ); - bool hasFile = wfile.open( IO_ReadOnly ); - QTextStream wstream( &wfile ); - if ( hasFile ) - { - wstream.readLine(); // skip the first two lines - wstream.readLine(); // because they only contain headers - } - if ( ( !hasFile ) || ( wstream.atEnd() ) ) - { -#ifdef MDEBUG - qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); -#endif - quality = -1; - signal = IW_LOWER; - noise = IW_LOWER; - return false; - } - - wstream >> name >> status >> quality >> c >> signal >> c >> noise; - - if ( quality > 92 ) -#ifdef MDEBUG - qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); -#endif - if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) -#ifdef MDEBUG - qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); -#endif - if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) -#ifdef MDEBUG - qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); -#endif - - return true; - -} -*/ + info->essidLabel->setText(we.essid()); + info->apLabel->setText(we.ap()); + info->stationLabel->setText(we.station()); + info->modeLabel->setText(we.mode()); + info->freqLabel->setText(QString("%1").arg(we.frequency())); + int signal = 0; + int noise = 0; + int quality = 0; + we.stats(signal, noise, quality); + info->signalProgressBar->setProgress(signal); + info->noiseProgressBar->setProgress(noise); + info->qualityProgressBar->setProgress(quality); return info; } /** * Get all active (up or down) interfaces * @return QList<Interface> A list of interfaces that exsist that havn't * been called by isOwner() */ QList<Interface> WLANModule::getInterfaces(){ return list; } /** * Attempt to add a new interface as defined by name * @param name the name of the type of interface that should be created given * by possibleNewInterfaces(); * @return Interface* NULL if it was unable to be created. */ Interface *WLANModule::addNewInterface(QString ){ // We can't add a 802.11 interface, either the hardware will be there // or it wont. return NULL; } /** * Attempts to remove the interface, doesn't delete i * @return bool true if successfull, false otherwise. */ bool WLANModule::remove(Interface*){ // Can't remove a hardware device, you can stop it though. return false; } diff --git a/noncore/net/networksetup/wlan/wlanmodule.h b/noncore/net/networksetup/wlan/wlanmodule.h index 63f0949..1418ce8 100644 --- a/noncore/net/networksetup/wlan/wlanmodule.h +++ b/noncore/net/networksetup/wlan/wlanmodule.h @@ -1,40 +1,41 @@ #ifndef WLAN_MODULE_H #define WLAN_MODULE_H #include "module.h" class WLANModule : Module{ signals: void updateInterface(Interface *i); public: WLANModule(); - + ~WLANModule(); + virtual void setProfile(QString newProfile); virtual bool isOwner(Interface *); virtual QWidget *configure(Interface *i, QTabWidget **tabWidget); virtual QWidget *information(Interface *i, QTabWidget **tabWidget); virtual QList<Interface> getInterfaces(); - virtual void possibleNewInterfaces(QMap<QString, QString> &list){}; + virtual void possibleNewInterfaces(QMap<QString, QString> &){}; virtual Interface *addNewInterface(QString name); virtual bool remove(Interface* i); virtual QString getPixmapName(Interface* i); private: QList<Interface> list; QString profile; }; extern "C" { void* create_plugin() { return new WLANModule(); } }; #endif // wlanmodule.h diff --git a/noncore/settings/networksettings/wlan/info.ui b/noncore/settings/networksettings/wlan/info.ui index 018ace3..4e85b1b 100644 --- a/noncore/settings/networksettings/wlan/info.ui +++ b/noncore/settings/networksettings/wlan/info.ui @@ -1,46 +1,46 @@ <!DOCTYPE UI><UI> <class>WlanInfo</class> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>WlanInfo</cstring> </property> <property stdset="1"> <name>geometry</name> <rect> <x>0</x> <y>0</y> - <width>283</width> + <width>279</width> <height>292</height> </rect> </property> <property stdset="1"> <name>caption</name> <string>WLAN Information</string> </property> <vbox> <property stdset="1"> <name>margin</name> <number>0</number> </property> <property stdset="1"> <name>spacing</name> <number>0</number> </property> <widget> <class>QTabWidget</class> <property stdset="1"> <name>name</name> <cstring>tabWidget</cstring> </property> <widget> <class>QWidget</class> <property stdset="1"> <name>name</name> <cstring>Widget2</cstring> </property> <attribute> <name>title</name> <string>802.11b</string> </attribute> @@ -177,58 +177,154 @@ <property stdset="1"> <name>frameShape</name> <enum>Panel</enum> </property> <property stdset="1"> <name>frameShadow</name> <enum>Sunken</enum> </property> </widget> <spacer row="5" column="1" > <property> <name>name</name> <cstring>Spacer7</cstring> </property> <property stdset="1"> <name>orientation</name> <enum>Vertical</enum> </property> <property stdset="1"> <name>sizeType</name> <enum>Expanding</enum> </property> <property> <name>sizeHint</name> <size> <width>20</width> <height>20</height> </size> </property> </spacer> </grid> </widget> + <widget> + <class>QWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>tab</cstring> + </property> + <attribute> + <name>title</name> + <string>Statistics</string> + </attribute> + <grid> + <property stdset="1"> + <name>margin</name> + <number>11</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <spacer row="3" column="1" > + <property> + <name>name</name> + <cstring>Spacer2</cstring> + </property> + <property stdset="1"> + <name>orientation</name> + <enum>Vertical</enum> + </property> + <property stdset="1"> + <name>sizeType</name> + <enum>Expanding</enum> + </property> + <property> + <name>sizeHint</name> + <size> + <width>20</width> + <height>20</height> + </size> + </property> + </spacer> + <widget row="0" column="1" > + <class>QProgressBar</class> + <property stdset="1"> + <name>name</name> + <cstring>signalProgressBar</cstring> + </property> + </widget> + <widget row="1" column="1" > + <class>QProgressBar</class> + <property stdset="1"> + <name>name</name> + <cstring>noiseProgressBar</cstring> + </property> + </widget> + <widget row="2" column="1" > + <class>QProgressBar</class> + <property stdset="1"> + <name>name</name> + <cstring>qualityProgressBar</cstring> + </property> + </widget> + <widget row="0" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel1_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Signal</string> + </property> + </widget> + <widget row="1" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel2_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Noise</string> + </property> + </widget> + <widget row="2" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel3_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Quality</string> + </property> + </widget> + </grid> + </widget> </widget> </vbox> </widget> <customwidgets> <customwidget> <class>QWidget</class> <header location="local">qwidget.h</header> <sizehint> <width>100</width> <height>100</height> </sizehint> <container>0</container> <sizepolicy> <hordata>7</hordata> <verdata>7</verdata> </sizepolicy> <pixmap>image0</pixmap> </customwidget> </customwidgets> <images> <image> <name>image0</name> <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> </image> </images> </UI> diff --git a/noncore/settings/networksettings/wlan/wextensions.cpp b/noncore/settings/networksettings/wlan/wextensions.cpp new file mode 100644 index 0000000..f45ebf2 --- a/dev/null +++ b/noncore/settings/networksettings/wlan/wextensions.cpp @@ -0,0 +1,158 @@ +#include "wextensions.h" + +#include <qfile.h> +#include <qtextstream.h> + +#include <arpa/inet.h> +#include <sys/socket.h> +#include <sys/ioctl.h> + +#include <math.h> + +#define PROCNETWIRELESS "/proc/net/wireless" +#define IW_LOWER 140 +#define IW_UPPER 200 + +/** + * Constructor. Sets hasWirelessExtensions + */ +WExtensions::WExtensions(QString interfaceName){ + interface = interfaceName; + fd = socket( AF_INET, SOCK_DGRAM, 0 ); + + const char* buffer[200]; + memset( &iwr, 0, sizeof( iwr ) ); + iwr.u.essid.pointer = (caddr_t) buffer; + iwr.u.essid.length = IW_ESSID_MAX_SIZE; + iwr.u.essid.flags = 0; + + // check if it is an IEEE 802.11 standard conform + // wireless device by sending SIOCGIWESSID + // which also gives back the Extended Service Set ID + // (see IEEE 802.11 for more information) + + const char* iname = interface.latin1(); + strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); + if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) ) + hasWirelessExtensions = true; + else + hasWirelessExtensions = false; +} + +/** + * @return QString the station name of the access point. + */ +QString WExtensions::station(){ + if(!hasWirelessExtensions) + return QString(); + const char* buffer[200]; + iwr.u.data.pointer = (caddr_t) buffer; + iwr.u.data.length = IW_ESSID_MAX_SIZE; + iwr.u.data.flags = 0; + if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){ + iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; + return QString(iwr.u.data.pointer); + } + return QString(); +} + +/** + * @return QString the essid of the host 802.11 access point. + */ +QString WExtensions::essid(){ + if(!hasWirelessExtensions) + return QString(); + if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){ + iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; + return QString(iwr.u.essid.pointer); + } + return QString(); +} + +/** + * @return QString the mode of interface + */ +QString WExtensions::mode(){ + if(!hasWirelessExtensions) + return QString(); + if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) ) + return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed"); + return QString(); +} + +/** + * Get the frequency that the interface is running at. + * @return int the frequency that the interfacae is running at. + */ +double WExtensions::frequency(){ + if(!hasWirelessExtensions) + return 0; + if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr )) + return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000); + return 0;; +} + +/** + * @return QString the AccessPoint that the interface is connected to. + */ +QString WExtensions::ap(){ + if(!hasWirelessExtensions) + return QString(); + if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){ + QString ap; + ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", + iwr.u.ap_addr.sa_data[0]&0xff, + iwr.u.ap_addr.sa_data[1]&0xff, + iwr.u.ap_addr.sa_data[2]&0xff, + iwr.u.ap_addr.sa_data[3]&0xff, + iwr.u.ap_addr.sa_data[4]&0xff, + iwr.u.ap_addr.sa_data[5]&0xff ); + return ap; + } + else return QString(); + +} + +bool WExtensions::stats(int &signal, int &noise, int &quality){ + // gather link quality from /proc/net/wireless + if(!QFile::exists(PROCNETWIRELESS)) + return false; + + char c; + QString status; + QString name; + + QFile wfile( PROCNETWIRELESS ); + if(!wfile.open( IO_ReadOnly )) + return false; + + QTextStream wstream( &wfile ); + wstream.readLine(); // skip the first two lines + wstream.readLine(); // because they only contain headers + while(!wstream.atEnd()){ + wstream >> name >> status >> quality >> c >> signal >> c >> noise; + if(name == interface){ + if ( quality > 92 ) + #ifdef MDEBUG + qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); + #endif + if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) + #ifdef MDEBUG + qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); + #endif + if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) + #ifdef MDEBUG + qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); + #endif + return true; + } + } + + qDebug("Card no longer present"); + quality = -1; + signal = IW_LOWER; + noise = IW_LOWER; + return false; +} + +// wextensions.cpp diff --git a/noncore/settings/networksettings/wlan/wextensions.h b/noncore/settings/networksettings/wlan/wextensions.h new file mode 100644 index 0000000..29997f5 --- a/dev/null +++ b/noncore/settings/networksettings/wlan/wextensions.h @@ -0,0 +1,32 @@ +#ifndef WEXTENSIONS_H +#define WEXTENSIONS_H + +#include <qstring.h> + +#include <netinet/ip.h> +#include <linux/wireless.h> + +class WExtensions { + +public: + WExtensions(QString interfaceName); + QString getInterfaceName(){return interface;}; + bool doesHaveWirelessExtensions(){return hasWirelessExtensions;}; + QString station(); + QString essid(); + QString mode(); + double frequency(); + QString ap(); + bool stats( int &signal, int &noise, int &quality); + +private: + bool hasWirelessExtensions; + QString interface; + + // Used in we calls + struct iwreq iwr; + int fd; + +}; + +#endif diff --git a/noncore/settings/networksettings/wlan/wlan.pro b/noncore/settings/networksettings/wlan/wlan.pro index 5b94a95..432a096 100644 --- a/noncore/settings/networksettings/wlan/wlan.pro +++ b/noncore/settings/networksettings/wlan/wlan.pro @@ -1,12 +1,12 @@ TEMPLATE = lib CONFIG += qt warn_on release #CONFIG += qt warn_on debug DESTDIR = $(OPIEDIR)/plugins/networksetup -HEADERS = wlanimp.h wlanmodule.h -SOURCES = wlanimp.cpp wlanmodule.cpp +HEADERS = wlanimp.h wlanmodule.h wextensions.h +SOURCES = wlanimp.cpp wlanmodule.cpp wextensions.cpp INCLUDEPATH += $(OPIEDIR)/include ../ DEPENDPATH += $(OPIEDIR)/include LIBS += -lqpe INTERFACES = wlan.ui info.ui TARGET = wlanplugin VERSION = 1.0.0 diff --git a/noncore/settings/networksettings/wlan/wlanmodule.cpp b/noncore/settings/networksettings/wlan/wlanmodule.cpp index 24cb1cd..ab0b9a5 100644 --- a/noncore/settings/networksettings/wlan/wlanmodule.cpp +++ b/noncore/settings/networksettings/wlan/wlanmodule.cpp @@ -1,219 +1,125 @@ #include "wlanmodule.h" #include "wlanimp.h" #include "info.h" - -#include <arpa/inet.h> -#include <sys/socket.h> -#include <linux/if_ether.h> -#include <netinet/ip.h> -#include <sys/ioctl.h> -#include <linux/wireless.h> - -#include <unistd.h> -#include <math.h> -#include <errno.h> -#include <string.h> -#include <stdio.h> - -#include <stdlib.h> +#include "wextensions.h" #include <qlabel.h> +#include <qprogressbar.h> /** * Constructor, find all of the possible interfaces */ WLANModule::WLANModule() : Module() { // get output from iwconfig } /** + */ +WLANModule::~WLANModule(){ + Interface *i; + for ( i=list.first(); i != 0; i=list.next() ) + delete i; +} + +/** * Change the current profile */ void WLANModule::setProfile(QString newProfile){ profile = newProfile; } /** * get the icon name for this device. * @param Interface* can be used in determining the icon. * @return QString the icon name (minus .png, .gif etc) */ QString WLANModule::getPixmapName(Interface* ){ return "wlan"; } /** * Check to see if the interface i is owned by this module. * @param Interface* interface to check against * @return bool true if i is owned by this module, false otherwise. */ bool WLANModule::isOwner(Interface *i){ - if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ + WExtensions we(i->getInterfaceName()); + if(!we.doesHaveWirelessExtensions()) + return false; + + //if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ i->setHardwareName("802.11b"); + list.append(i); return true; - } - return false; + //} + //return false; } /** * Create, set tabWiget and return the WLANConfigure Module * @param tabWidget a pointer to the tab widget that this configure has. * @return QWidget* pointer to the tab widget in this modules configure. */ -QWidget *WLANModule::configure(Interface *i, QTabWidget **tabWidget){ +QWidget *WLANModule::configure(Interface *, QTabWidget **tabWidget){ WLANImp *wlanconfig = new WLANImp(0, "WlanConfig"); (*tabWidget) = wlanconfig->tabWidget; return wlanconfig; } /** * Create, set tabWiget and return the Information Module * @param tabWidget a pointer to the tab widget that this information has. * @return QWidget* pointer to the tab widget in this modules info. */ QWidget *WLANModule::information(Interface *i, QTabWidget **tabWidget){ - return NULL; + WExtensions we(i->getInterfaceName()); + if(!we.doesHaveWirelessExtensions()) + return NULL; + WlanInfo *info = new WlanInfo(0, "wireless info"); (*tabWidget) = info->tabWidget; - - struct ifreq ifr; - struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; - int fd = socket( AF_INET, SOCK_DGRAM, 0 ); - const char* buffer[200]; - struct iwreq iwr; - memset( &iwr, 0, sizeof( iwr ) ); - iwr.u.essid.pointer = (caddr_t) buffer; - iwr.u.essid.length = IW_ESSID_MAX_SIZE; - iwr.u.essid.flags = 0; - - // check if it is an IEEE 802.11 standard conform - // wireless device by sending SIOCGIWESSID - // which also gives back the Extended Service Set ID - // (see IEEE 802.11 for more information) - - QString n = (i->getInterfaceName()); - const char* iname = n.latin1(); - strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); - int result = ioctl( fd, SIOCGIWESSID, &iwr ); - if ( result == 0 ){ - //hasWirelessExtensions = true; - iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; - info->essidLabel->setText(QString(iwr.u.essid.pointer)); - } - else - return info; - //info->essidLabel->setText("*** Unknown ***"); - - // Address of associated access-point - result = ioctl( fd, SIOCGIWAP, &iwr ); - if ( result == 0 ){ - QString foo = foo.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", - iwr.u.ap_addr.sa_data[0]&0xff, - iwr.u.ap_addr.sa_data[1]&0xff, - iwr.u.ap_addr.sa_data[2]&0xff, - iwr.u.ap_addr.sa_data[3]&0xff, - iwr.u.ap_addr.sa_data[4]&0xff, - iwr.u.ap_addr.sa_data[5]&0xff ); - info->apLabel->setText(foo); - } - else info->apLabel->setText("*** Unknown ***"); - - iwr.u.data.pointer = (caddr_t) buffer; - iwr.u.data.length = IW_ESSID_MAX_SIZE; - iwr.u.data.flags = 0; - result = ioctl( fd, SIOCGIWNICKN, &iwr ); - if ( result == 0 ){ - iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; - info->stationLabel->setText(iwr.u.data.pointer); - } - else info->stationLabel->setText("*** Unknown ***"); - - result = ioctl( fd, SIOCGIWMODE, &iwr ); - if ( result == 0 ) - info->modeLabel->setText( QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed")); - else - info->modeLabel->setText("*** Unknown ***"); - - result = ioctl( fd, SIOCGIWFREQ, &iwr ); - if ( result == 0 ) - info->freqLabel->setText(QString("%1").arg((double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000))); - else - info->freqLabel->setText("*** Unknown ***"); - - /* - // gather link quality from /proc/net/wireless - - char c; - QString status; - QString name; - QFile wfile( PROCNETWIRELESS ); - bool hasFile = wfile.open( IO_ReadOnly ); - QTextStream wstream( &wfile ); - if ( hasFile ) - { - wstream.readLine(); // skip the first two lines - wstream.readLine(); // because they only contain headers - } - if ( ( !hasFile ) || ( wstream.atEnd() ) ) - { -#ifdef MDEBUG - qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); -#endif - quality = -1; - signal = IW_LOWER; - noise = IW_LOWER; - return false; - } - - wstream >> name >> status >> quality >> c >> signal >> c >> noise; - - if ( quality > 92 ) -#ifdef MDEBUG - qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); -#endif - if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) -#ifdef MDEBUG - qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); -#endif - if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) -#ifdef MDEBUG - qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); -#endif - - return true; - -} -*/ + info->essidLabel->setText(we.essid()); + info->apLabel->setText(we.ap()); + info->stationLabel->setText(we.station()); + info->modeLabel->setText(we.mode()); + info->freqLabel->setText(QString("%1").arg(we.frequency())); + int signal = 0; + int noise = 0; + int quality = 0; + we.stats(signal, noise, quality); + info->signalProgressBar->setProgress(signal); + info->noiseProgressBar->setProgress(noise); + info->qualityProgressBar->setProgress(quality); return info; } /** * Get all active (up or down) interfaces * @return QList<Interface> A list of interfaces that exsist that havn't * been called by isOwner() */ QList<Interface> WLANModule::getInterfaces(){ return list; } /** * Attempt to add a new interface as defined by name * @param name the name of the type of interface that should be created given * by possibleNewInterfaces(); * @return Interface* NULL if it was unable to be created. */ Interface *WLANModule::addNewInterface(QString ){ // We can't add a 802.11 interface, either the hardware will be there // or it wont. return NULL; } /** * Attempts to remove the interface, doesn't delete i * @return bool true if successfull, false otherwise. */ bool WLANModule::remove(Interface*){ // Can't remove a hardware device, you can stop it though. return false; } diff --git a/noncore/settings/networksettings/wlan/wlanmodule.h b/noncore/settings/networksettings/wlan/wlanmodule.h index 63f0949..1418ce8 100644 --- a/noncore/settings/networksettings/wlan/wlanmodule.h +++ b/noncore/settings/networksettings/wlan/wlanmodule.h @@ -1,40 +1,41 @@ #ifndef WLAN_MODULE_H #define WLAN_MODULE_H #include "module.h" class WLANModule : Module{ signals: void updateInterface(Interface *i); public: WLANModule(); - + ~WLANModule(); + virtual void setProfile(QString newProfile); virtual bool isOwner(Interface *); virtual QWidget *configure(Interface *i, QTabWidget **tabWidget); virtual QWidget *information(Interface *i, QTabWidget **tabWidget); virtual QList<Interface> getInterfaces(); - virtual void possibleNewInterfaces(QMap<QString, QString> &list){}; + virtual void possibleNewInterfaces(QMap<QString, QString> &){}; virtual Interface *addNewInterface(QString name); virtual bool remove(Interface* i); virtual QString getPixmapName(Interface* i); private: QList<Interface> list; QString profile; }; extern "C" { void* create_plugin() { return new WLANModule(); } }; #endif // wlanmodule.h |