summaryrefslogtreecommitdiff
Unidiff
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
@@ -1,46 +1,46 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>WlanInfo</class> 2<class>WlanInfo</class>
3<widget> 3<widget>
4 <class>QWidget</class> 4 <class>QWidget</class>
5 <property stdset="1"> 5 <property stdset="1">
6 <name>name</name> 6 <name>name</name>
7 <cstring>WlanInfo</cstring> 7 <cstring>WlanInfo</cstring>
8 </property> 8 </property>
9 <property stdset="1"> 9 <property stdset="1">
10 <name>geometry</name> 10 <name>geometry</name>
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>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>WLAN Information</string> 20 <string>WLAN Information</string>
21 </property> 21 </property>
22 <vbox> 22 <vbox>
23 <property stdset="1"> 23 <property stdset="1">
24 <name>margin</name> 24 <name>margin</name>
25 <number>0</number> 25 <number>0</number>
26 </property> 26 </property>
27 <property stdset="1"> 27 <property stdset="1">
28 <name>spacing</name> 28 <name>spacing</name>
29 <number>0</number> 29 <number>0</number>
30 </property> 30 </property>
31 <widget> 31 <widget>
32 <class>QTabWidget</class> 32 <class>QTabWidget</class>
33 <property stdset="1"> 33 <property stdset="1">
34 <name>name</name> 34 <name>name</name>
35 <cstring>tabWidget</cstring> 35 <cstring>tabWidget</cstring>
36 </property> 36 </property>
37 <widget> 37 <widget>
38 <class>QWidget</class> 38 <class>QWidget</class>
39 <property stdset="1"> 39 <property stdset="1">
40 <name>name</name> 40 <name>name</name>
41 <cstring>Widget2</cstring> 41 <cstring>Widget2</cstring>
42 </property> 42 </property>
43 <attribute> 43 <attribute>
44 <name>title</name> 44 <name>title</name>
45 <string>802.11b</string> 45 <string>802.11b</string>
46 </attribute> 46 </attribute>
@@ -177,58 +177,154 @@
177 <property stdset="1"> 177 <property stdset="1">
178 <name>frameShape</name> 178 <name>frameShape</name>
179 <enum>Panel</enum> 179 <enum>Panel</enum>
180 </property> 180 </property>
181 <property stdset="1"> 181 <property stdset="1">
182 <name>frameShadow</name> 182 <name>frameShadow</name>
183 <enum>Sunken</enum> 183 <enum>Sunken</enum>
184 </property> 184 </property>
185 </widget> 185 </widget>
186 <spacer row="5" column="1" > 186 <spacer row="5" column="1" >
187 <property> 187 <property>
188 <name>name</name> 188 <name>name</name>
189 <cstring>Spacer7</cstring> 189 <cstring>Spacer7</cstring>
190 </property> 190 </property>
191 <property stdset="1"> 191 <property stdset="1">
192 <name>orientation</name> 192 <name>orientation</name>
193 <enum>Vertical</enum> 193 <enum>Vertical</enum>
194 </property> 194 </property>
195 <property stdset="1"> 195 <property stdset="1">
196 <name>sizeType</name> 196 <name>sizeType</name>
197 <enum>Expanding</enum> 197 <enum>Expanding</enum>
198 </property> 198 </property>
199 <property> 199 <property>
200 <name>sizeHint</name> 200 <name>sizeHint</name>
201 <size> 201 <size>
202 <width>20</width> 202 <width>20</width>
203 <height>20</height> 203 <height>20</height>
204 </size> 204 </size>
205 </property> 205 </property>
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>
212<customwidgets> 308<customwidgets>
213 <customwidget> 309 <customwidget>
214 <class>QWidget</class> 310 <class>QWidget</class>
215 <header location="local">qwidget.h</header> 311 <header location="local">qwidget.h</header>
216 <sizehint> 312 <sizehint>
217 <width>100</width> 313 <width>100</width>
218 <height>100</height> 314 <height>100</height>
219 </sizehint> 315 </sizehint>
220 <container>0</container> 316 <container>0</container>
221 <sizepolicy> 317 <sizepolicy>
222 <hordata>7</hordata> 318 <hordata>7</hordata>
223 <verdata>7</verdata> 319 <verdata>7</verdata>
224 </sizepolicy> 320 </sizepolicy>
225 <pixmap>image0</pixmap> 321 <pixmap>image0</pixmap>
226 </customwidget> 322 </customwidget>
227</customwidgets> 323</customwidgets>
228<images> 324<images>
229 <image> 325 <image>
230 <name>image0</name> 326 <name>image0</name>
231 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> 327 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data>
232 </image> 328 </image>
233</images> 329</images>
234</UI> 330</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 @@
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
@@ -1,12 +1,12 @@
1TEMPLATE = lib 1TEMPLATE = 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
10 INTERFACES= wlan.ui info.ui 10 INTERFACES= wlan.ui info.ui
11 TARGET = wlanplugin 11 TARGET = wlanplugin
12 VERSION = 1.0.0 12 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 @@
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
24 */ 11 */
25WLANModule::WLANModule() : Module() { 12WLANModule::WLANModule() : Module() {
26 // get output from iwconfig 13 // get output from iwconfig
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){
33 profile = newProfile; 28 profile = newProfile;
34} 29}
35 30
36/** 31/**
37 * get the icon name for this device. 32 * get the icon name for this device.
38 * @param Interface* can be used in determining the icon. 33 * @param Interface* can be used in determining the icon.
39 * @return QString the icon name (minus .png, .gif etc) 34 * @return QString the icon name (minus .png, .gif etc)
40 */ 35 */
41QString WLANModule::getPixmapName(Interface* ){ 36QString WLANModule::getPixmapName(Interface* ){
42 return "wlan"; 37 return "wlan";
43} 38}
44 39
45/** 40/**
46 * Check to see if the interface i is owned by this module. 41 * Check to see if the interface i is owned by this module.
47 * @param Interface* interface to check against 42 * @param Interface* interface to check against
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/**
59 * Create, set tabWiget and return the WLANConfigure Module 59 * Create, set tabWiget and return the WLANConfigure Module
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;
67} 67}
68 68
69/** 69/**
70 * Create, set tabWiget and return the Information Module 70 * Create, set tabWiget and return the Information Module
71 * @param tabWidget a pointer to the tab widget that this information has. 71 * @param tabWidget a pointer to the tab widget that this information has.
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
191/** 97/**
192 * Get all active (up or down) interfaces 98 * Get all active (up or down) interfaces
193 * @return QList<Interface> A list of interfaces that exsist that havn't 99 * @return QList<Interface> A list of interfaces that exsist that havn't
194 * been called by isOwner() 100 * been called by isOwner()
195 */ 101 */
196QList<Interface> WLANModule::getInterfaces(){ 102QList<Interface> WLANModule::getInterfaces(){
197 return list; 103 return list;
198} 104}
199 105
200/** 106/**
201 * Attempt to add a new interface as defined by name 107 * Attempt to add a new interface as defined by name
202 * @param name the name of the type of interface that should be created given 108 * @param name the name of the type of interface that should be created given
203 * by possibleNewInterfaces(); 109 * by possibleNewInterfaces();
204 * @return Interface* NULL if it was unable to be created. 110 * @return Interface* NULL if it was unable to be created.
205 */ 111 */
206Interface *WLANModule::addNewInterface(QString ){ 112Interface *WLANModule::addNewInterface(QString ){
207 // We can't add a 802.11 interface, either the hardware will be there 113 // We can't add a 802.11 interface, either the hardware will be there
208 // or it wont. 114 // or it wont.
209 return NULL; 115 return NULL;
210} 116}
211 117
212/** 118/**
213 * Attempts to remove the interface, doesn't delete i 119 * Attempts to remove the interface, doesn't delete i
214 * @return bool true if successfull, false otherwise. 120 * @return bool true if successfull, false otherwise.
215 */ 121 */
216bool WLANModule::remove(Interface*){ 122bool WLANModule::remove(Interface*){
217 // Can't remove a hardware device, you can stop it though. 123 // Can't remove a hardware device, you can stop it though.
218 return false; 124 return false;
219} 125}
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 @@
1#ifndef WLAN_MODULE_H 1#ifndef WLAN_MODULE_H
2#define WLAN_MODULE_H 2#define WLAN_MODULE_H
3 3
4#include "module.h" 4#include "module.h"
5 5
6class WLANModule : Module{ 6class WLANModule : Module{
7 7
8signals: 8signals:
9 void updateInterface(Interface *i); 9 void updateInterface(Interface *i);
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);
23 24
24private: 25private:
25 QList<Interface> list; 26 QList<Interface> list;
26 QString profile; 27 QString profile;
27 28
28}; 29};
29 30
30extern "C" 31extern "C"
31{ 32{
32 void* create_plugin() { 33 void* create_plugin() {
33 return new WLANModule(); 34 return new WLANModule();
34 } 35 }
35}; 36};
36 37
37#endif 38#endif
38 39
39// wlanmodule.h 40// wlanmodule.h
40 41
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 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>WlanInfo</class> 2<class>WlanInfo</class>
3<widget> 3<widget>
4 <class>QWidget</class> 4 <class>QWidget</class>
5 <property stdset="1"> 5 <property stdset="1">
6 <name>name</name> 6 <name>name</name>
7 <cstring>WlanInfo</cstring> 7 <cstring>WlanInfo</cstring>
8 </property> 8 </property>
9 <property stdset="1"> 9 <property stdset="1">
10 <name>geometry</name> 10 <name>geometry</name>
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>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>WLAN Information</string> 20 <string>WLAN Information</string>
21 </property> 21 </property>
22 <vbox> 22 <vbox>
23 <property stdset="1"> 23 <property stdset="1">
24 <name>margin</name> 24 <name>margin</name>
25 <number>0</number> 25 <number>0</number>
26 </property> 26 </property>
27 <property stdset="1"> 27 <property stdset="1">
28 <name>spacing</name> 28 <name>spacing</name>
29 <number>0</number> 29 <number>0</number>
30 </property> 30 </property>
31 <widget> 31 <widget>
32 <class>QTabWidget</class> 32 <class>QTabWidget</class>
33 <property stdset="1"> 33 <property stdset="1">
34 <name>name</name> 34 <name>name</name>
35 <cstring>tabWidget</cstring> 35 <cstring>tabWidget</cstring>
36 </property> 36 </property>
37 <widget> 37 <widget>
38 <class>QWidget</class> 38 <class>QWidget</class>
39 <property stdset="1"> 39 <property stdset="1">
40 <name>name</name> 40 <name>name</name>
41 <cstring>Widget2</cstring> 41 <cstring>Widget2</cstring>
42 </property> 42 </property>
43 <attribute> 43 <attribute>
44 <name>title</name> 44 <name>title</name>
45 <string>802.11b</string> 45 <string>802.11b</string>
46 </attribute> 46 </attribute>
@@ -177,58 +177,154 @@
177 <property stdset="1"> 177 <property stdset="1">
178 <name>frameShape</name> 178 <name>frameShape</name>
179 <enum>Panel</enum> 179 <enum>Panel</enum>
180 </property> 180 </property>
181 <property stdset="1"> 181 <property stdset="1">
182 <name>frameShadow</name> 182 <name>frameShadow</name>
183 <enum>Sunken</enum> 183 <enum>Sunken</enum>
184 </property> 184 </property>
185 </widget> 185 </widget>
186 <spacer row="5" column="1" > 186 <spacer row="5" column="1" >
187 <property> 187 <property>
188 <name>name</name> 188 <name>name</name>
189 <cstring>Spacer7</cstring> 189 <cstring>Spacer7</cstring>
190 </property> 190 </property>
191 <property stdset="1"> 191 <property stdset="1">
192 <name>orientation</name> 192 <name>orientation</name>
193 <enum>Vertical</enum> 193 <enum>Vertical</enum>
194 </property> 194 </property>
195 <property stdset="1"> 195 <property stdset="1">
196 <name>sizeType</name> 196 <name>sizeType</name>
197 <enum>Expanding</enum> 197 <enum>Expanding</enum>
198 </property> 198 </property>
199 <property> 199 <property>
200 <name>sizeHint</name> 200 <name>sizeHint</name>
201 <size> 201 <size>
202 <width>20</width> 202 <width>20</width>
203 <height>20</height> 203 <height>20</height>
204 </size> 204 </size>
205 </property> 205 </property>
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>
212<customwidgets> 308<customwidgets>
213 <customwidget> 309 <customwidget>
214 <class>QWidget</class> 310 <class>QWidget</class>
215 <header location="local">qwidget.h</header> 311 <header location="local">qwidget.h</header>
216 <sizehint> 312 <sizehint>
217 <width>100</width> 313 <width>100</width>
218 <height>100</height> 314 <height>100</height>
219 </sizehint> 315 </sizehint>
220 <container>0</container> 316 <container>0</container>
221 <sizepolicy> 317 <sizepolicy>
222 <hordata>7</hordata> 318 <hordata>7</hordata>
223 <verdata>7</verdata> 319 <verdata>7</verdata>
224 </sizepolicy> 320 </sizepolicy>
225 <pixmap>image0</pixmap> 321 <pixmap>image0</pixmap>
226 </customwidget> 322 </customwidget>
227</customwidgets> 323</customwidgets>
228<images> 324<images>
229 <image> 325 <image>
230 <name>image0</name> 326 <name>image0</name>
231 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data> 327 <data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data>
232 </image> 328 </image>
233</images> 329</images>
234</UI> 330</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 @@
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
@@ -1,12 +1,12 @@
1TEMPLATE = lib 1TEMPLATE = 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
10 INTERFACES= wlan.ui info.ui 10 INTERFACES= wlan.ui info.ui
11 TARGET = wlanplugin 11 TARGET = wlanplugin
12 VERSION = 1.0.0 12 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 @@
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
24 */ 11 */
25WLANModule::WLANModule() : Module() { 12WLANModule::WLANModule() : Module() {
26 // get output from iwconfig 13 // get output from iwconfig
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){
33 profile = newProfile; 28 profile = newProfile;
34} 29}
35 30
36/** 31/**
37 * get the icon name for this device. 32 * get the icon name for this device.
38 * @param Interface* can be used in determining the icon. 33 * @param Interface* can be used in determining the icon.
39 * @return QString the icon name (minus .png, .gif etc) 34 * @return QString the icon name (minus .png, .gif etc)
40 */ 35 */
41QString WLANModule::getPixmapName(Interface* ){ 36QString WLANModule::getPixmapName(Interface* ){
42 return "wlan"; 37 return "wlan";
43} 38}
44 39
45/** 40/**
46 * Check to see if the interface i is owned by this module. 41 * Check to see if the interface i is owned by this module.
47 * @param Interface* interface to check against 42 * @param Interface* interface to check against
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/**
59 * Create, set tabWiget and return the WLANConfigure Module 59 * Create, set tabWiget and return the WLANConfigure Module
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;
67} 67}
68 68
69/** 69/**
70 * Create, set tabWiget and return the Information Module 70 * Create, set tabWiget and return the Information Module
71 * @param tabWidget a pointer to the tab widget that this information has. 71 * @param tabWidget a pointer to the tab widget that this information has.
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
191/** 97/**
192 * Get all active (up or down) interfaces 98 * Get all active (up or down) interfaces
193 * @return QList<Interface> A list of interfaces that exsist that havn't 99 * @return QList<Interface> A list of interfaces that exsist that havn't
194 * been called by isOwner() 100 * been called by isOwner()
195 */ 101 */
196QList<Interface> WLANModule::getInterfaces(){ 102QList<Interface> WLANModule::getInterfaces(){
197 return list; 103 return list;
198} 104}
199 105
200/** 106/**
201 * Attempt to add a new interface as defined by name 107 * Attempt to add a new interface as defined by name
202 * @param name the name of the type of interface that should be created given 108 * @param name the name of the type of interface that should be created given
203 * by possibleNewInterfaces(); 109 * by possibleNewInterfaces();
204 * @return Interface* NULL if it was unable to be created. 110 * @return Interface* NULL if it was unable to be created.
205 */ 111 */
206Interface *WLANModule::addNewInterface(QString ){ 112Interface *WLANModule::addNewInterface(QString ){
207 // We can't add a 802.11 interface, either the hardware will be there 113 // We can't add a 802.11 interface, either the hardware will be there
208 // or it wont. 114 // or it wont.
209 return NULL; 115 return NULL;
210} 116}
211 117
212/** 118/**
213 * Attempts to remove the interface, doesn't delete i 119 * Attempts to remove the interface, doesn't delete i
214 * @return bool true if successfull, false otherwise. 120 * @return bool true if successfull, false otherwise.
215 */ 121 */
216bool WLANModule::remove(Interface*){ 122bool WLANModule::remove(Interface*){
217 // Can't remove a hardware device, you can stop it though. 123 // Can't remove a hardware device, you can stop it though.
218 return false; 124 return false;
219} 125}
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 @@
1#ifndef WLAN_MODULE_H 1#ifndef WLAN_MODULE_H
2#define WLAN_MODULE_H 2#define WLAN_MODULE_H
3 3
4#include "module.h" 4#include "module.h"
5 5
6class WLANModule : Module{ 6class WLANModule : Module{
7 7
8signals: 8signals:
9 void updateInterface(Interface *i); 9 void updateInterface(Interface *i);
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);
23 24
24private: 25private:
25 QList<Interface> list; 26 QList<Interface> list;
26 QString profile; 27 QString profile;
27 28
28}; 29};
29 30
30extern "C" 31extern "C"
31{ 32{
32 void* create_plugin() { 33 void* create_plugin() {
33 return new WLANModule(); 34 return new WLANModule();
34 } 35 }
35}; 36};
36 37
37#endif 38#endif
38 39
39// wlanmodule.h 40// wlanmodule.h
40 41