From 4fbca156e2bede574f458f9d96cc650c75219973 Mon Sep 17 00:00:00 2001 From: benmeyer Date: Tue, 22 Oct 2002 14:48:26 +0000 Subject: Added wireless extensions abstraction --- (limited to 'noncore/settings/networksettings/wlan/wlanmodule.cpp') 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,23 +1,10 @@ #include "wlanmodule.h" #include "wlanimp.h" #include "info.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include +#include "wextensions.h" #include +#include /** * Constructor, find all of the possible interfaces @@ -27,6 +14,14 @@ WLANModule::WLANModule() : Module() { } /** + */ +WLANModule::~WLANModule(){ + Interface *i; + for ( i=list.first(); i != 0; i=list.next() ) + delete i; +} + +/** * Change the current profile */ void WLANModule::setProfile(QString newProfile){ @@ -48,11 +43,16 @@ QString WLANModule::getPixmapName(Interface* ){ * @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; } /** @@ -60,7 +60,7 @@ bool WLANModule::isOwner(Interface *i){ * @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; @@ -72,119 +72,25 @@ QWidget *WLANModule::configure(Interface *i, QTabWidget **tabWidget){ * @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; } -- cgit v0.9.0.2