summaryrefslogtreecommitdiff
path: root/noncore/net/networksetup/wlan/wlanmodule.cpp
Unidiff
Diffstat (limited to 'noncore/net/networksetup/wlan/wlanmodule.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/net/networksetup/wlan/wlanmodule.cpp162
1 files changed, 34 insertions, 128 deletions
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,23 +1,10 @@
1#include "wlanmodule.h" 1#include "wlanmodule.h"
2#include "wlanimp.h" 2#include "wlanimp.h"
3#include "info.h" 3#include "info.h"
4 4#include "wextensions.h"
5#include <arpa/inet.h>
6#include <sys/socket.h>
7#include <linux/if_ether.h>
8#include <netinet/ip.h>
9#include <sys/ioctl.h>
10#include <linux/wireless.h>
11
12#include <unistd.h>
13#include <math.h>
14#include <errno.h>
15#include <string.h>
16#include <stdio.h>
17
18#include <stdlib.h>
19 5
20#include <qlabel.h> 6#include <qlabel.h>
7#include <qprogressbar.h>
21 8
22/** 9/**
23 * Constructor, find all of the possible interfaces 10 * Constructor, find all of the possible interfaces
@@ -27,6 +14,14 @@ WLANModule::WLANModule() : Module() {
27} 14}
28 15
29/** 16/**
17 */
18WLANModule::~WLANModule(){
19 Interface *i;
20 for ( i=list.first(); i != 0; i=list.next() )
21 delete i;
22}
23
24/**
30 * Change the current profile 25 * Change the current profile
31 */ 26 */
32void WLANModule::setProfile(QString newProfile){ 27void WLANModule::setProfile(QString newProfile){
@@ -48,11 +43,16 @@ QString WLANModule::getPixmapName(Interface* ){
48 * @return bool true if i is owned by this module, false otherwise. 43 * @return bool true if i is owned by this module, false otherwise.
49 */ 44 */
50bool WLANModule::isOwner(Interface *i){ 45bool WLANModule::isOwner(Interface *i){
51 if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ 46 WExtensions we(i->getInterfaceName());
47 if(!we.doesHaveWirelessExtensions())
48 return false;
49
50 //if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){
52 i->setHardwareName("802.11b"); 51 i->setHardwareName("802.11b");
52 list.append(i);
53 return true; 53 return true;
54 } 54 //}
55 return false; 55 //return false;
56} 56}
57 57
58/** 58/**
@@ -60,7 +60,7 @@ bool WLANModule::isOwner(Interface *i){
60 * @param tabWidget a pointer to the tab widget that this configure has. 60 * @param tabWidget a pointer to the tab widget that this configure has.
61 * @return QWidget* pointer to the tab widget in this modules configure. 61 * @return QWidget* pointer to the tab widget in this modules configure.
62 */ 62 */
63QWidget *WLANModule::configure(Interface *i, QTabWidget **tabWidget){ 63QWidget *WLANModule::configure(Interface *, QTabWidget **tabWidget){
64 WLANImp *wlanconfig = new WLANImp(0, "WlanConfig"); 64 WLANImp *wlanconfig = new WLANImp(0, "WlanConfig");
65 (*tabWidget) = wlanconfig->tabWidget; 65 (*tabWidget) = wlanconfig->tabWidget;
66 return wlanconfig; 66 return wlanconfig;
@@ -72,119 +72,25 @@ QWidget *WLANModule::configure(Interface *i, QTabWidget **tabWidget){
72 * @return QWidget* pointer to the tab widget in this modules info. 72 * @return QWidget* pointer to the tab widget in this modules info.
73 */ 73 */
74QWidget *WLANModule::information(Interface *i, QTabWidget **tabWidget){ 74QWidget *WLANModule::information(Interface *i, QTabWidget **tabWidget){
75 WExtensions we(i->getInterfaceName());
76 if(!we.doesHaveWirelessExtensions())
75 return NULL; 77 return NULL;
78
76 WlanInfo *info = new WlanInfo(0, "wireless info"); 79 WlanInfo *info = new WlanInfo(0, "wireless info");
77 (*tabWidget) = info->tabWidget; 80 (*tabWidget) = info->tabWidget;
78 81
79 struct ifreq ifr; 82 info->essidLabel->setText(we.essid());
80 struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; 83 info->apLabel->setText(we.ap());
81 int fd = socket( AF_INET, SOCK_DGRAM, 0 ); 84 info->stationLabel->setText(we.station());
82 85 info->modeLabel->setText(we.mode());
83 const char* buffer[200]; 86 info->freqLabel->setText(QString("%1").arg(we.frequency()));
84 struct iwreq iwr; 87 int signal = 0;
85 memset( &iwr, 0, sizeof( iwr ) ); 88 int noise = 0;
86 iwr.u.essid.pointer = (caddr_t) buffer; 89 int quality = 0;
87 iwr.u.essid.length = IW_ESSID_MAX_SIZE; 90 we.stats(signal, noise, quality);
88 iwr.u.essid.flags = 0; 91 info->signalProgressBar->setProgress(signal);
89 92 info->noiseProgressBar->setProgress(noise);
90 // check if it is an IEEE 802.11 standard conform 93 info->qualityProgressBar->setProgress(quality);
91 // wireless device by sending SIOCGIWESSID
92 // which also gives back the Extended Service Set ID
93 // (see IEEE 802.11 for more information)
94
95 QString n = (i->getInterfaceName());
96 const char* iname = n.latin1();
97 strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname );
98 int result = ioctl( fd, SIOCGIWESSID, &iwr );
99 if ( result == 0 ){
100 //hasWirelessExtensions = true;
101 iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0';
102 info->essidLabel->setText(QString(iwr.u.essid.pointer));
103 }
104 else
105 return info;
106 //info->essidLabel->setText("*** Unknown ***");
107
108 // Address of associated access-point
109 result = ioctl( fd, SIOCGIWAP, &iwr );
110 if ( result == 0 ){
111 QString foo = foo.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
112 iwr.u.ap_addr.sa_data[0]&0xff,
113 iwr.u.ap_addr.sa_data[1]&0xff,
114 iwr.u.ap_addr.sa_data[2]&0xff,
115 iwr.u.ap_addr.sa_data[3]&0xff,
116 iwr.u.ap_addr.sa_data[4]&0xff,
117 iwr.u.ap_addr.sa_data[5]&0xff );
118 info->apLabel->setText(foo);
119 }
120 else info->apLabel->setText("*** Unknown ***");
121
122 iwr.u.data.pointer = (caddr_t) buffer;
123 iwr.u.data.length = IW_ESSID_MAX_SIZE;
124 iwr.u.data.flags = 0;
125 result = ioctl( fd, SIOCGIWNICKN, &iwr );
126 if ( result == 0 ){
127 iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0';
128 info->stationLabel->setText(iwr.u.data.pointer);
129 }
130 else info->stationLabel->setText("*** Unknown ***");
131
132 result = ioctl( fd, SIOCGIWMODE, &iwr );
133 if ( result == 0 )
134 info->modeLabel->setText( QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed"));
135 else
136 info->modeLabel->setText("*** Unknown ***");
137
138 result = ioctl( fd, SIOCGIWFREQ, &iwr );
139 if ( result == 0 )
140 info->freqLabel->setText(QString("%1").arg((double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000)));
141 else
142 info->freqLabel->setText("*** Unknown ***");
143
144 /*
145 // gather link quality from /proc/net/wireless
146
147 char c;
148 QString status;
149 QString name;
150 QFile wfile( PROCNETWIRELESS );
151 bool hasFile = wfile.open( IO_ReadOnly );
152 QTextStream wstream( &wfile );
153 if ( hasFile )
154 {
155 wstream.readLine(); // skip the first two lines
156 wstream.readLine(); // because they only contain headers
157 }
158 if ( ( !hasFile ) || ( wstream.atEnd() ) )
159 {
160#ifdef MDEBUG
161 qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." );
162#endif
163 quality = -1;
164 signal = IW_LOWER;
165 noise = IW_LOWER;
166 return false;
167 }
168
169 wstream >> name >> status >> quality >> c >> signal >> c >> noise;
170
171 if ( quality > 92 )
172#ifdef MDEBUG
173 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality );
174#endif
175 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) )
176#ifdef MDEBUG
177 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal );
178#endif
179 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) )
180#ifdef MDEBUG
181 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise );
182#endif
183
184 return true;
185
186}
187*/
188 return info; 94 return info;
189} 95}
190 96