summaryrefslogtreecommitdiff
authorbenmeyer <benmeyer>2002-10-22 14:48:26 (UTC)
committer benmeyer <benmeyer>2002-10-22 14:48:26 (UTC)
commit4fbca156e2bede574f458f9d96cc650c75219973 (patch) (unidiff)
tree85a0a0a3ad44f744c55ba2076471438b4c25fc21
parent916da240f6ff546fd01ea803bf2301ee2c6a836b (diff)
downloadopie-4fbca156e2bede574f458f9d96cc650c75219973.zip
opie-4fbca156e2bede574f458f9d96cc650c75219973.tar.gz
opie-4fbca156e2bede574f458f9d96cc650c75219973.tar.bz2
Added wireless extensions abstraction
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/wlan/info.ui98
-rw-r--r--noncore/net/networksetup/wlan/wextensions.cpp158
-rw-r--r--noncore/net/networksetup/wlan/wextensions.h32
-rw-r--r--noncore/net/networksetup/wlan/wlan.pro4
-rw-r--r--noncore/net/networksetup/wlan/wlanmodule.cpp164
-rw-r--r--noncore/net/networksetup/wlan/wlanmodule.h5
-rw-r--r--noncore/settings/networksettings/wlan/info.ui98
-rw-r--r--noncore/settings/networksettings/wlan/wextensions.cpp158
-rw-r--r--noncore/settings/networksettings/wlan/wextensions.h32
-rw-r--r--noncore/settings/networksettings/wlan/wlan.pro4
-rw-r--r--noncore/settings/networksettings/wlan/wlanmodule.cpp164
-rw-r--r--noncore/settings/networksettings/wlan/wlanmodule.h5
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
@@ -11,7 +11,7 @@
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>283</width> 14 <width>279</width>
15 <height>292</height> 15 <height>292</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
@@ -206,6 +206,102 @@
206 </spacer> 206 </spacer>
207 </grid> 207 </grid>
208 </widget> 208 </widget>
209 <widget>
210 <class>QWidget</class>
211 <property stdset="1">
212 <name>name</name>
213 <cstring>tab</cstring>
214 </property>
215 <attribute>
216 <name>title</name>
217 <string>Statistics</string>
218 </attribute>
219 <grid>
220 <property stdset="1">
221 <name>margin</name>
222 <number>11</number>
223 </property>
224 <property stdset="1">
225 <name>spacing</name>
226 <number>6</number>
227 </property>
228 <spacer row="3" column="1" >
229 <property>
230 <name>name</name>
231 <cstring>Spacer2</cstring>
232 </property>
233 <property stdset="1">
234 <name>orientation</name>
235 <enum>Vertical</enum>
236 </property>
237 <property stdset="1">
238 <name>sizeType</name>
239 <enum>Expanding</enum>
240 </property>
241 <property>
242 <name>sizeHint</name>
243 <size>
244 <width>20</width>
245 <height>20</height>
246 </size>
247 </property>
248 </spacer>
249 <widget row="0" column="1" >
250 <class>QProgressBar</class>
251 <property stdset="1">
252 <name>name</name>
253 <cstring>signalProgressBar</cstring>
254 </property>
255 </widget>
256 <widget row="1" column="1" >
257 <class>QProgressBar</class>
258 <property stdset="1">
259 <name>name</name>
260 <cstring>noiseProgressBar</cstring>
261 </property>
262 </widget>
263 <widget row="2" column="1" >
264 <class>QProgressBar</class>
265 <property stdset="1">
266 <name>name</name>
267 <cstring>qualityProgressBar</cstring>
268 </property>
269 </widget>
270 <widget row="0" column="0" >
271 <class>QLabel</class>
272 <property stdset="1">
273 <name>name</name>
274 <cstring>TextLabel1_2</cstring>
275 </property>
276 <property stdset="1">
277 <name>text</name>
278 <string>Signal</string>
279 </property>
280 </widget>
281 <widget row="1" column="0" >
282 <class>QLabel</class>
283 <property stdset="1">
284 <name>name</name>
285 <cstring>TextLabel2_2</cstring>
286 </property>
287 <property stdset="1">
288 <name>text</name>
289 <string>Noise</string>
290 </property>
291 </widget>
292 <widget row="2" column="0" >
293 <class>QLabel</class>
294 <property stdset="1">
295 <name>name</name>
296 <cstring>TextLabel3_2</cstring>
297 </property>
298 <property stdset="1">
299 <name>text</name>
300 <string>Quality</string>
301 </property>
302 </widget>
303 </grid>
304 </widget>
209 </widget> 305 </widget>
210 </vbox> 306 </vbox>
211</widget> 307</widget>
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 @@
1#include "wextensions.h"
2
3#include <qfile.h>
4#include <qtextstream.h>
5
6#include <arpa/inet.h>
7#include <sys/socket.h>
8#include <sys/ioctl.h>
9
10#include <math.h>
11
12#define PROCNETWIRELESS "/proc/net/wireless"
13#define IW_LOWER 140
14#define IW_UPPER 200
15
16/**
17 * Constructor. Sets hasWirelessExtensions
18 */
19WExtensions::WExtensions(QString interfaceName){
20 interface = interfaceName;
21 fd = socket( AF_INET, SOCK_DGRAM, 0 );
22
23 const char* buffer[200];
24 memset( &iwr, 0, sizeof( iwr ) );
25 iwr.u.essid.pointer = (caddr_t) buffer;
26 iwr.u.essid.length = IW_ESSID_MAX_SIZE;
27 iwr.u.essid.flags = 0;
28
29 // check if it is an IEEE 802.11 standard conform
30 // wireless device by sending SIOCGIWESSID
31 // which also gives back the Extended Service Set ID
32 // (see IEEE 802.11 for more information)
33
34 const char* iname = interface.latin1();
35 strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname );
36 if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) )
37 hasWirelessExtensions = true;
38 else
39 hasWirelessExtensions = false;
40}
41
42/**
43 * @return QString the station name of the access point.
44 */
45QString WExtensions::station(){
46 if(!hasWirelessExtensions)
47 return QString();
48 const char* buffer[200];
49 iwr.u.data.pointer = (caddr_t) buffer;
50 iwr.u.data.length = IW_ESSID_MAX_SIZE;
51 iwr.u.data.flags = 0;
52 if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){
53 iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0';
54 return QString(iwr.u.data.pointer);
55 }
56 return QString();
57}
58
59/**
60 * @return QString the essid of the host 802.11 access point.
61 */
62QString WExtensions::essid(){
63 if(!hasWirelessExtensions)
64 return QString();
65 if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){
66 iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0';
67 return QString(iwr.u.essid.pointer);
68 }
69 return QString();
70}
71
72/**
73 * @return QString the mode of interface
74 */
75QString WExtensions::mode(){
76 if(!hasWirelessExtensions)
77 return QString();
78 if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) )
79 return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed");
80 return QString();
81}
82
83/**
84 * Get the frequency that the interface is running at.
85 * @return int the frequency that the interfacae is running at.
86 */
87double WExtensions::frequency(){
88 if(!hasWirelessExtensions)
89 return 0;
90 if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr ))
91 return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000);
92 return 0;;
93}
94
95/**
96 * @return QString the AccessPoint that the interface is connected to.
97 */
98QString WExtensions::ap(){
99 if(!hasWirelessExtensions)
100 return QString();
101 if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){
102 QString ap;
103 ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
104 iwr.u.ap_addr.sa_data[0]&0xff,
105 iwr.u.ap_addr.sa_data[1]&0xff,
106 iwr.u.ap_addr.sa_data[2]&0xff,
107 iwr.u.ap_addr.sa_data[3]&0xff,
108 iwr.u.ap_addr.sa_data[4]&0xff,
109 iwr.u.ap_addr.sa_data[5]&0xff );
110 return ap;
111 }
112 else return QString();
113
114}
115
116bool WExtensions::stats(int &signal, int &noise, int &quality){
117 // gather link quality from /proc/net/wireless
118 if(!QFile::exists(PROCNETWIRELESS))
119 return false;
120
121 char c;
122 QString status;
123 QString name;
124
125 QFile wfile( PROCNETWIRELESS );
126 if(!wfile.open( IO_ReadOnly ))
127 return false;
128
129 QTextStream wstream( &wfile );
130 wstream.readLine(); // skip the first two lines
131 wstream.readLine(); // because they only contain headers
132 while(!wstream.atEnd()){
133 wstream >> name >> status >> quality >> c >> signal >> c >> noise;
134 if(name == interface){
135 if ( quality > 92 )
136 #ifdef MDEBUG
137 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality );
138 #endif
139 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) )
140 #ifdef MDEBUG
141 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal );
142 #endif
143 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) )
144 #ifdef MDEBUG
145 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise );
146 #endif
147 return true;
148 }
149 }
150
151 qDebug("Card no longer present");
152 quality = -1;
153 signal = IW_LOWER;
154 noise = IW_LOWER;
155 return false;
156}
157
158// 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 @@
1#ifndef WEXTENSIONS_H
2#define WEXTENSIONS_H
3
4#include <qstring.h>
5
6#include <netinet/ip.h>
7#include <linux/wireless.h>
8
9class WExtensions {
10
11public:
12 WExtensions(QString interfaceName);
13 QString getInterfaceName(){return interface;};
14 bool doesHaveWirelessExtensions(){return hasWirelessExtensions;};
15 QString station();
16 QString essid();
17 QString mode();
18 double frequency();
19 QString ap();
20 bool stats( int &signal, int &noise, int &quality);
21
22private:
23 bool hasWirelessExtensions;
24 QString interface;
25
26 // Used in we calls
27 struct iwreq iwr;
28 int fd;
29
30};
31
32#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
@@ -2,8 +2,8 @@ TEMPLATE = lib
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3 #CONFIG += qt warn_on debug 3 #CONFIG += qt warn_on debug
4DESTDIR = $(OPIEDIR)/plugins/networksetup 4DESTDIR = $(OPIEDIR)/plugins/networksetup
5 HEADERS = wlanimp.h wlanmodule.h 5 HEADERS = wlanimp.h wlanmodule.h wextensions.h
6 SOURCES = wlanimp.cpp wlanmodule.cpp 6 SOURCES = wlanimp.cpp wlanmodule.cpp wextensions.cpp
7 INCLUDEPATH+= $(OPIEDIR)/include ../ 7 INCLUDEPATH+= $(OPIEDIR)/include ../
8 DEPENDPATH+= $(OPIEDIR)/include 8 DEPENDPATH+= $(OPIEDIR)/include
9LIBS += -lqpe 9LIBS += -lqpe
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 return NULL; 75 WExtensions we(i->getInterfaceName());
76 if(!we.doesHaveWirelessExtensions())
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
79 struct ifreq ifr;
80 struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr;
81 int fd = socket( AF_INET, SOCK_DGRAM, 0 );
82 81
83 const char* buffer[200]; 82 info->essidLabel->setText(we.essid());
84 struct iwreq iwr; 83 info->apLabel->setText(we.ap());
85 memset( &iwr, 0, sizeof( iwr ) ); 84 info->stationLabel->setText(we.station());
86 iwr.u.essid.pointer = (caddr_t) buffer; 85 info->modeLabel->setText(we.mode());
87 iwr.u.essid.length = IW_ESSID_MAX_SIZE; 86 info->freqLabel->setText(QString("%1").arg(we.frequency()));
88 iwr.u.essid.flags = 0; 87 int signal = 0;
89 88 int noise = 0;
90 // check if it is an IEEE 802.11 standard conform 89 int quality = 0;
91 // wireless device by sending SIOCGIWESSID 90 we.stats(signal, noise, quality);
92 // which also gives back the Extended Service Set ID 91 info->signalProgressBar->setProgress(signal);
93 // (see IEEE 802.11 for more information) 92 info->noiseProgressBar->setProgress(noise);
94 93 info->qualityProgressBar->setProgress(quality);
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
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
@@ -10,13 +10,14 @@ signals:
10 10
11public: 11public:
12 WLANModule(); 12 WLANModule();
13 13 ~WLANModule();
14
14 virtual void setProfile(QString newProfile); 15 virtual void setProfile(QString newProfile);
15 virtual bool isOwner(Interface *); 16 virtual bool isOwner(Interface *);
16 virtual QWidget *configure(Interface *i, QTabWidget **tabWidget); 17 virtual QWidget *configure(Interface *i, QTabWidget **tabWidget);
17 virtual QWidget *information(Interface *i, QTabWidget **tabWidget); 18 virtual QWidget *information(Interface *i, QTabWidget **tabWidget);
18 virtual QList<Interface> getInterfaces(); 19 virtual QList<Interface> getInterfaces();
19 virtual void possibleNewInterfaces(QMap<QString, QString> &list){}; 20 virtual void possibleNewInterfaces(QMap<QString, QString> &){};
20 virtual Interface *addNewInterface(QString name); 21 virtual Interface *addNewInterface(QString name);
21 virtual bool remove(Interface* i); 22 virtual bool remove(Interface* i);
22 virtual QString getPixmapName(Interface* i); 23 virtual QString getPixmapName(Interface* i);
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
@@ -11,7 +11,7 @@
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>283</width> 14 <width>279</width>
15 <height>292</height> 15 <height>292</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
@@ -206,6 +206,102 @@
206 </spacer> 206 </spacer>
207 </grid> 207 </grid>
208 </widget> 208 </widget>
209 <widget>
210 <class>QWidget</class>
211 <property stdset="1">
212 <name>name</name>
213 <cstring>tab</cstring>
214 </property>
215 <attribute>
216 <name>title</name>
217 <string>Statistics</string>
218 </attribute>
219 <grid>
220 <property stdset="1">
221 <name>margin</name>
222 <number>11</number>
223 </property>
224 <property stdset="1">
225 <name>spacing</name>
226 <number>6</number>
227 </property>
228 <spacer row="3" column="1" >
229 <property>
230 <name>name</name>
231 <cstring>Spacer2</cstring>
232 </property>
233 <property stdset="1">
234 <name>orientation</name>
235 <enum>Vertical</enum>
236 </property>
237 <property stdset="1">
238 <name>sizeType</name>
239 <enum>Expanding</enum>
240 </property>
241 <property>
242 <name>sizeHint</name>
243 <size>
244 <width>20</width>
245 <height>20</height>
246 </size>
247 </property>
248 </spacer>
249 <widget row="0" column="1" >
250 <class>QProgressBar</class>
251 <property stdset="1">
252 <name>name</name>
253 <cstring>signalProgressBar</cstring>
254 </property>
255 </widget>
256 <widget row="1" column="1" >
257 <class>QProgressBar</class>
258 <property stdset="1">
259 <name>name</name>
260 <cstring>noiseProgressBar</cstring>
261 </property>
262 </widget>
263 <widget row="2" column="1" >
264 <class>QProgressBar</class>
265 <property stdset="1">
266 <name>name</name>
267 <cstring>qualityProgressBar</cstring>
268 </property>
269 </widget>
270 <widget row="0" column="0" >
271 <class>QLabel</class>
272 <property stdset="1">
273 <name>name</name>
274 <cstring>TextLabel1_2</cstring>
275 </property>
276 <property stdset="1">
277 <name>text</name>
278 <string>Signal</string>
279 </property>
280 </widget>
281 <widget row="1" column="0" >
282 <class>QLabel</class>
283 <property stdset="1">
284 <name>name</name>
285 <cstring>TextLabel2_2</cstring>
286 </property>
287 <property stdset="1">
288 <name>text</name>
289 <string>Noise</string>
290 </property>
291 </widget>
292 <widget row="2" column="0" >
293 <class>QLabel</class>
294 <property stdset="1">
295 <name>name</name>
296 <cstring>TextLabel3_2</cstring>
297 </property>
298 <property stdset="1">
299 <name>text</name>
300 <string>Quality</string>
301 </property>
302 </widget>
303 </grid>
304 </widget>
209 </widget> 305 </widget>
210 </vbox> 306 </vbox>
211</widget> 307</widget>
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 @@
1#include "wextensions.h"
2
3#include <qfile.h>
4#include <qtextstream.h>
5
6#include <arpa/inet.h>
7#include <sys/socket.h>
8#include <sys/ioctl.h>
9
10#include <math.h>
11
12#define PROCNETWIRELESS "/proc/net/wireless"
13#define IW_LOWER 140
14#define IW_UPPER 200
15
16/**
17 * Constructor. Sets hasWirelessExtensions
18 */
19WExtensions::WExtensions(QString interfaceName){
20 interface = interfaceName;
21 fd = socket( AF_INET, SOCK_DGRAM, 0 );
22
23 const char* buffer[200];
24 memset( &iwr, 0, sizeof( iwr ) );
25 iwr.u.essid.pointer = (caddr_t) buffer;
26 iwr.u.essid.length = IW_ESSID_MAX_SIZE;
27 iwr.u.essid.flags = 0;
28
29 // check if it is an IEEE 802.11 standard conform
30 // wireless device by sending SIOCGIWESSID
31 // which also gives back the Extended Service Set ID
32 // (see IEEE 802.11 for more information)
33
34 const char* iname = interface.latin1();
35 strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname );
36 if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) )
37 hasWirelessExtensions = true;
38 else
39 hasWirelessExtensions = false;
40}
41
42/**
43 * @return QString the station name of the access point.
44 */
45QString WExtensions::station(){
46 if(!hasWirelessExtensions)
47 return QString();
48 const char* buffer[200];
49 iwr.u.data.pointer = (caddr_t) buffer;
50 iwr.u.data.length = IW_ESSID_MAX_SIZE;
51 iwr.u.data.flags = 0;
52 if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){
53 iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0';
54 return QString(iwr.u.data.pointer);
55 }
56 return QString();
57}
58
59/**
60 * @return QString the essid of the host 802.11 access point.
61 */
62QString WExtensions::essid(){
63 if(!hasWirelessExtensions)
64 return QString();
65 if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){
66 iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0';
67 return QString(iwr.u.essid.pointer);
68 }
69 return QString();
70}
71
72/**
73 * @return QString the mode of interface
74 */
75QString WExtensions::mode(){
76 if(!hasWirelessExtensions)
77 return QString();
78 if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) )
79 return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed");
80 return QString();
81}
82
83/**
84 * Get the frequency that the interface is running at.
85 * @return int the frequency that the interfacae is running at.
86 */
87double WExtensions::frequency(){
88 if(!hasWirelessExtensions)
89 return 0;
90 if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr ))
91 return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000);
92 return 0;;
93}
94
95/**
96 * @return QString the AccessPoint that the interface is connected to.
97 */
98QString WExtensions::ap(){
99 if(!hasWirelessExtensions)
100 return QString();
101 if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){
102 QString ap;
103 ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
104 iwr.u.ap_addr.sa_data[0]&0xff,
105 iwr.u.ap_addr.sa_data[1]&0xff,
106 iwr.u.ap_addr.sa_data[2]&0xff,
107 iwr.u.ap_addr.sa_data[3]&0xff,
108 iwr.u.ap_addr.sa_data[4]&0xff,
109 iwr.u.ap_addr.sa_data[5]&0xff );
110 return ap;
111 }
112 else return QString();
113
114}
115
116bool WExtensions::stats(int &signal, int &noise, int &quality){
117 // gather link quality from /proc/net/wireless
118 if(!QFile::exists(PROCNETWIRELESS))
119 return false;
120
121 char c;
122 QString status;
123 QString name;
124
125 QFile wfile( PROCNETWIRELESS );
126 if(!wfile.open( IO_ReadOnly ))
127 return false;
128
129 QTextStream wstream( &wfile );
130 wstream.readLine(); // skip the first two lines
131 wstream.readLine(); // because they only contain headers
132 while(!wstream.atEnd()){
133 wstream >> name >> status >> quality >> c >> signal >> c >> noise;
134 if(name == interface){
135 if ( quality > 92 )
136 #ifdef MDEBUG
137 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality );
138 #endif
139 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) )
140 #ifdef MDEBUG
141 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal );
142 #endif
143 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) )
144 #ifdef MDEBUG
145 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise );
146 #endif
147 return true;
148 }
149 }
150
151 qDebug("Card no longer present");
152 quality = -1;
153 signal = IW_LOWER;
154 noise = IW_LOWER;
155 return false;
156}
157
158// 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 @@
1#ifndef WEXTENSIONS_H
2#define WEXTENSIONS_H
3
4#include <qstring.h>
5
6#include <netinet/ip.h>
7#include <linux/wireless.h>
8
9class WExtensions {
10
11public:
12 WExtensions(QString interfaceName);
13 QString getInterfaceName(){return interface;};
14 bool doesHaveWirelessExtensions(){return hasWirelessExtensions;};
15 QString station();
16 QString essid();
17 QString mode();
18 double frequency();
19 QString ap();
20 bool stats( int &signal, int &noise, int &quality);
21
22private:
23 bool hasWirelessExtensions;
24 QString interface;
25
26 // Used in we calls
27 struct iwreq iwr;
28 int fd;
29
30};
31
32#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
@@ -2,8 +2,8 @@ TEMPLATE = lib
2CONFIG += qt warn_on release 2CONFIG += qt warn_on release
3 #CONFIG += qt warn_on debug 3 #CONFIG += qt warn_on debug
4DESTDIR = $(OPIEDIR)/plugins/networksetup 4DESTDIR = $(OPIEDIR)/plugins/networksetup
5 HEADERS = wlanimp.h wlanmodule.h 5 HEADERS = wlanimp.h wlanmodule.h wextensions.h
6 SOURCES = wlanimp.cpp wlanmodule.cpp 6 SOURCES = wlanimp.cpp wlanmodule.cpp wextensions.cpp
7 INCLUDEPATH+= $(OPIEDIR)/include ../ 7 INCLUDEPATH+= $(OPIEDIR)/include ../
8 DEPENDPATH+= $(OPIEDIR)/include 8 DEPENDPATH+= $(OPIEDIR)/include
9LIBS += -lqpe 9LIBS += -lqpe
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 @@
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 return NULL; 75 WExtensions we(i->getInterfaceName());
76 if(!we.doesHaveWirelessExtensions())
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
79 struct ifreq ifr;
80 struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr;
81 int fd = socket( AF_INET, SOCK_DGRAM, 0 );
82 81
83 const char* buffer[200]; 82 info->essidLabel->setText(we.essid());
84 struct iwreq iwr; 83 info->apLabel->setText(we.ap());
85 memset( &iwr, 0, sizeof( iwr ) ); 84 info->stationLabel->setText(we.station());
86 iwr.u.essid.pointer = (caddr_t) buffer; 85 info->modeLabel->setText(we.mode());
87 iwr.u.essid.length = IW_ESSID_MAX_SIZE; 86 info->freqLabel->setText(QString("%1").arg(we.frequency()));
88 iwr.u.essid.flags = 0; 87 int signal = 0;
89 88 int noise = 0;
90 // check if it is an IEEE 802.11 standard conform 89 int quality = 0;
91 // wireless device by sending SIOCGIWESSID 90 we.stats(signal, noise, quality);
92 // which also gives back the Extended Service Set ID 91 info->signalProgressBar->setProgress(signal);
93 // (see IEEE 802.11 for more information) 92 info->noiseProgressBar->setProgress(noise);
94 93 info->qualityProgressBar->setProgress(quality);
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
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
@@ -10,13 +10,14 @@ signals:
10 10
11public: 11public:
12 WLANModule(); 12 WLANModule();
13 13 ~WLANModule();
14
14 virtual void setProfile(QString newProfile); 15 virtual void setProfile(QString newProfile);
15 virtual bool isOwner(Interface *); 16 virtual bool isOwner(Interface *);
16 virtual QWidget *configure(Interface *i, QTabWidget **tabWidget); 17 virtual QWidget *configure(Interface *i, QTabWidget **tabWidget);
17 virtual QWidget *information(Interface *i, QTabWidget **tabWidget); 18 virtual QWidget *information(Interface *i, QTabWidget **tabWidget);
18 virtual QList<Interface> getInterfaces(); 19 virtual QList<Interface> getInterfaces();
19 virtual void possibleNewInterfaces(QMap<QString, QString> &list){}; 20 virtual void possibleNewInterfaces(QMap<QString, QString> &){};
20 virtual Interface *addNewInterface(QString name); 21 virtual Interface *addNewInterface(QString name);
21 virtual bool remove(Interface* i); 22 virtual bool remove(Interface* i);
22 virtual QString getPixmapName(Interface* i); 23 virtual QString getPixmapName(Interface* i);