summaryrefslogtreecommitdiff
authormickeyl <mickeyl>2004-02-23 18:38:28 (UTC)
committer mickeyl <mickeyl>2004-02-23 18:38:28 (UTC)
commitd66f871dfeae78babeb1fa0b8a3e1c72dd10ea2b (patch) (unidiff)
tree224c86eb4ab72154365ae450ce517c559b363bf0
parent19b274033fc05d5190cee2fa974c683892173c84 (diff)
downloadopie-d66f871dfeae78babeb1fa0b8a3e1c72dd10ea2b.zip
opie-d66f871dfeae78babeb1fa0b8a3e1c72dd10ea2b.tar.gz
opie-d66f871dfeae78babeb1fa0b8a3e1c72dd10ea2b.tar.bz2
The wireless applet uses now libopie2net instead of its own routines.
Display mode "ANTENNA" is fixed, "BAR GRAPH" is still broken but will be removed anyway, since nearly everyone used "ANTENNA".
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/applets/wirelessapplet/networkinfo.cpp284
-rw-r--r--noncore/applets/wirelessapplet/networkinfo.h126
-rw-r--r--noncore/applets/wirelessapplet/wireless.cpp55
-rw-r--r--noncore/applets/wirelessapplet/wirelessapplet.pro4
4 files changed, 26 insertions, 443 deletions
diff --git a/noncore/applets/wirelessapplet/networkinfo.cpp b/noncore/applets/wirelessapplet/networkinfo.cpp
deleted file mode 100644
index e0c487b..0000000
--- a/noncore/applets/wirelessapplet/networkinfo.cpp
+++ b/dev/null
@@ -1,284 +0,0 @@
1/**********************************************************************
2** MNetwork* classes
3**
4** Encapsulate network information
5**
6** Copyright (C) 2002, Michael Lauer
7** mickey@tm.informatik.uni-frankfurt.de
8** http://www.Vanille.de
9**
10** Based on portions of the Wireless Extensions
11** Copyright (c) 1997-2002 Jean Tourrilhes <jt@hpl.hp.com>
12**
13** This file may be distributed and/or modified under the terms of the
14** GNU General Public License version 2 as published by the Free Software
15** Foundation and appearing in the file LICENSE.GPL included in the
16** packaging of this file.
17**
18** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
19** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20**
21**********************************************************************/
22
23#include "networkinfo.h"
24
25#include <arpa/inet.h>
26#include <sys/socket.h>
27#include <linux/if_ether.h>
28#include <netinet/ip.h>
29#include <sys/ioctl.h>
30#include <linux/wireless.h>
31
32#include <unistd.h>
33#include <math.h>
34#include <errno.h>
35#include <string.h>
36
37#include <stdlib.h>
38
39#include <qstring.h>
40#include <qfile.h>
41#include <qtextstream.h>
42
43/* estimated wireless signal strength and noise level values
44 based on experimentation with Orinoco and Prism2 cards.
45 Seem to be correct, but please inform me, if you got values
46 outside these boundaries. :Mickey: */
47
48#define IW_UPPER 220
49#define IW_LOWER 140
50
51#define PROCNETDEV "/proc/net/dev"
52#define PROCNETWIRELESS "/proc/net/wireless"
53
54//#define MDEBUG 0
55#undef MDEBUG
56
57//---------------------------------------------------------------------------
58// class MNetworkInterface
59//
60
61MNetworkInterface::MNetworkInterface( const char* name )
62 :name( name )
63{
64 struct ifreq ifr;
65 struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr;
66 fd = socket( AF_INET, SOCK_DGRAM, 0 );
67}
68
69MNetworkInterface::~MNetworkInterface()
70{
71 if ( fd != -1 )
72 close( fd );
73}
74
75bool MNetworkInterface::updateStatistics()
76{
77 return true;
78}
79
80//---------------------------------------------------------------------------
81// class MWirelessNetworkInterface
82//
83
84MWirelessNetworkInterface::MWirelessNetworkInterface( const char* n )
85 :MNetworkInterface( n )
86{
87 signal = 0;
88 noise = 0;
89 quality = 0;
90}
91
92MWirelessNetworkInterface::~MWirelessNetworkInterface()
93{
94}
95
96int MWirelessNetworkInterface::qualityPercent()
97{
98 return ( quality*100 ) / 92;
99}
100
101int MWirelessNetworkInterface::signalPercent()
102{
103 return ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER;
104}
105
106int MWirelessNetworkInterface::noisePercent()
107{
108 return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER;
109}
110
111bool MWirelessNetworkInterface::updateStatistics()
112{
113 bool base = MNetworkInterface::updateStatistics();
114 if ( !base )
115 return false;
116
117 const char* buffer[200];
118
119 struct iwreq iwr;
120 memset( &iwr, 0, sizeof( iwr ) );
121 iwr.u.essid.pointer = (caddr_t) buffer;
122 iwr.u.essid.length = IW_ESSID_MAX_SIZE;
123 iwr.u.essid.flags = 0;
124
125 // check if it is an IEEE 802.11 standard conform
126 // wireless device by sending SIOCGIWESSID
127 // which also gives back the Extended Service Set ID
128 // (see IEEE 802.11 for more information)
129
130 strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name );
131 int result = ioctl( fd, SIOCGIWESSID, &iwr );
132 if ( result == 0 )
133 {
134 hasWirelessExtensions = true;
135 iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0';
136 essid = iwr.u.essid.pointer;
137 }
138 else essid = "*** Unknown ***";
139
140 // Address of associated access-point
141
142 result = ioctl( fd, SIOCGIWAP, &iwr );
143 if ( result == 0 )
144 {
145 APAddr.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
146 iwr.u.ap_addr.sa_data[0]&0xff,
147 iwr.u.ap_addr.sa_data[1]&0xff,
148 iwr.u.ap_addr.sa_data[2]&0xff,
149 iwr.u.ap_addr.sa_data[3]&0xff,
150 iwr.u.ap_addr.sa_data[4]&0xff,
151 iwr.u.ap_addr.sa_data[5]&0xff );
152 } else APAddr = "*** Unknown ***";
153
154 iwr.u.data.pointer = (caddr_t) buffer;
155 iwr.u.data.length = IW_ESSID_MAX_SIZE;
156 iwr.u.data.flags = 0;
157
158 result = ioctl( fd, SIOCGIWNICKN, &iwr );
159 if ( result == 0 )
160 {
161 iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0';
162 nick = iwr.u.data.pointer;
163 } else nick = "*** Unknown ***";
164
165 result = ioctl( fd, SIOCGIWMODE, &iwr );
166 if ( result == 0 )
167 mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed";
168 else mode = "*** Unknown ***";
169
170 result = ioctl( fd, SIOCGIWFREQ, &iwr );
171 if ( result == 0 )
172 freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000;
173 else freq = 0;
174
175 // gather link quality from /proc/net/wireless
176
177 char c;
178 QString status;
179 QString name;
180 QFile wfile( PROCNETWIRELESS );
181 bool hasFile = wfile.open( IO_ReadOnly );
182 QTextStream wstream( &wfile );
183 if ( hasFile )
184 {
185 wstream.readLine(); // skip the first two lines
186 wstream.readLine(); // because they only contain headers
187 }
188 if ( ( !hasFile ) || ( wstream.atEnd() ) )
189 {
190#ifdef MDEBUG
191 qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." );
192#endif
193 quality = -1;
194 signal = IW_LOWER;
195 noise = IW_LOWER;
196 return false;
197 }
198
199 wstream >> name >> status >> quality >> c >> signal >> c >> noise;
200
201#ifdef MDEBUG
202 if ( quality > 92 )
203 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality );
204
205 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) )
206 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal );
207
208 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) )
209 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise );
210#endif
211
212 return true;
213
214}
215
216//---------------------------------------------------------------------------
217// class Network
218//
219
220MNetwork::MNetwork()
221{
222 procfile = PROCNETDEV;
223}
224
225MNetwork::~MNetwork()
226{
227}
228
229//---------------------------------------------------------------------------
230// class WirelessNetwork
231//
232
233MWirelessNetwork::MWirelessNetwork()
234{
235 procfile = PROCNETWIRELESS;
236}
237
238MWirelessNetwork::~MWirelessNetwork()
239{
240}
241
242MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const
243{
244 return new MWirelessNetworkInterface( n );
245}
246
247//---------------------------------------------------------------------------
248// class NetworkInterface
249//
250
251MNetworkInterface* MNetwork::getFirstInterface()
252{
253 enumerateInterfaces();
254 InterfaceMapIterator it( interfaces );
255 return ( it.count() > 0 ) ? it.toFirst() : 0;
256}
257
258void MNetwork::enumerateInterfaces()
259{
260 interfaces.clear();
261 QString str;
262 QFile f( procfile );
263 bool hasFile = f.open( IO_ReadOnly );
264 if ( !hasFile )
265 return;
266 QTextStream s( &f );
267 s.readLine();
268 s.readLine();
269 while ( !s.atEnd() )
270 {
271 s >> str;
272 str.truncate( str.find( ':' ) );
273#ifdef MDEBUG
274 qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str );
275#endif
276 interfaces.insert( str, createInterface( str ) );
277 s.readLine();
278 }
279}
280
281MNetworkInterface* MNetwork::createInterface( const char* n ) const
282{
283 return new MNetworkInterface( n );
284}
diff --git a/noncore/applets/wirelessapplet/networkinfo.h b/noncore/applets/wirelessapplet/networkinfo.h
deleted file mode 100644
index 7e50bc4..0000000
--- a/noncore/applets/wirelessapplet/networkinfo.h
+++ b/dev/null
@@ -1,126 +0,0 @@
1/**********************************************************************
2** MNetwork* classes
3**
4** Encapsulates network information
5**
6** Copyright (C) 2002, Michael Lauer
7** mickey@tm.informatik.uni-frankfurt.de
8** http://www.Vanille.de
9**
10** This file may be distributed and/or modified under the terms of the
11** GNU General Public License version 2 as published by the Free Software
12** Foundation and appearing in the file LICENSE.GPL included in the
13** packaging of this file.
14**
15** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
16** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17**
18**********************************************************************/
19
20#ifndef NETWORKINFO_H
21#define NETWORKINFO_H
22
23#include <qstring.h>
24#include <qdict.h>
25
26//---------------------------------------------------------------------------
27// class MNetworkInterface
28//
29
30class MNetworkInterface
31{
32public:
33
34 MNetworkInterface( const char* name = "eth0" );
35 virtual ~MNetworkInterface();
36
37 bool isLoopback() { return isLoopbackInterface; };
38 const QString& getName() { return name; };
39
40 virtual bool updateStatistics();
41
42protected:
43
44 int fd;
45 const QString name;
46 bool isLoopbackInterface;
47 bool isIrda;
48 bool isTunnel;
49};
50
51//---------------------------------------------------------------------------
52// class MWirelessNetworkInterface
53//
54
55class MWirelessNetworkInterface : public MNetworkInterface
56{
57public:
58 MWirelessNetworkInterface( const char* name = "wlan0" );
59 virtual ~MWirelessNetworkInterface();
60
61 int noisePercent();
62 int qualityPercent();
63 int signalPercent();
64
65 QString APAddr;
66 QString essid;
67 QString mode;
68 QString nick;
69 QString rate;
70 double freq;
71 int channel;
72
73 virtual bool updateStatistics();
74
75private:
76 int quality;
77 int signal;
78 int noise;
79
80 bool hasWirelessExtensions;
81};
82
83//---------------------------------------------------------------------------
84// class MNetwork
85//
86
87class MNetwork
88{
89public:
90 MNetwork();
91 virtual ~MNetwork();
92
93 typedef QDict<MNetworkInterface> InterfaceMap;
94 typedef QDictIterator<MNetworkInterface> InterfaceMapIterator;
95
96 bool hasInterfaces() const { return interfaces.isEmpty(); };
97 int numInterfaces() const { return interfaces.count(); };
98
99 MNetworkInterface* getFirstInterface();
100
101protected:
102 QString procfile;
103 InterfaceMap interfaces;
104
105 virtual MNetworkInterface* createInterface( const char* name ) const;
106
107private:
108 void enumerateInterfaces();
109};
110
111//---------------------------------------------------------------------------
112// class MWirelessNetwork
113//
114
115class MWirelessNetwork : public MNetwork
116{
117public:
118 MWirelessNetwork();
119 virtual ~MWirelessNetwork();
120
121protected:
122 virtual MNetworkInterface* createInterface( const char* name )
123 const;
124};
125
126#endif
diff --git a/noncore/applets/wirelessapplet/wireless.cpp b/noncore/applets/wirelessapplet/wireless.cpp
index dc9742a..72ac380 100644
--- a/noncore/applets/wirelessapplet/wireless.cpp
+++ b/noncore/applets/wirelessapplet/wireless.cpp
@@ -12,7 +12,6 @@
12**********************************************************************/ 12**********************************************************************/
13 13
14#include "wireless.h" 14#include "wireless.h"
15#include "networkinfo.h"
16#include "mgraph.h" 15#include "mgraph.h"
17#include "advancedconfig.h" 16#include "advancedconfig.h"
18#include "connect0.xpm" 17#include "connect0.xpm"
@@ -51,8 +50,8 @@
51#define STYLE_BARS 0 50#define STYLE_BARS 0
52#define STYLE_ANTENNA 1 51#define STYLE_ANTENNA 1
53 52
54//#define MDEBUG 53#define MDEBUG
55#undef MDEBUG 54//#undef MDEBUG
56 55
57WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name ) 56WirelessControl::WirelessControl( WirelessApplet *applet, QWidget *parent, const char *name )
58 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet ) 57 : QFrame( parent, name, WStyle_StaysOnTop | WType_Popup ), applet( applet )
@@ -325,32 +324,26 @@ WirelessApplet::~WirelessApplet()
325 324
326void WirelessApplet::timerEvent( QTimerEvent* ) 325void WirelessApplet::timerEvent( QTimerEvent* )
327{ 326{
328 /* 327 qDebug( "WirelessApplet::timerEvent" );
329
330 OWirelessNetworkInterface* iface = interface; 328 OWirelessNetworkInterface* iface = interface;
331 329
332 if ( iface ) 330 if ( iface )
333 { 331 {
334 bool statResult = iface->updateStatistics();
335 if ( !statResult )
336 {
337 interface = 0;
338 mustRepaint();
339 return ;
340 }
341 else
342 if ( mustRepaint() ) 332 if ( mustRepaint() )
343 { 333 {
344 //qDebug( "WIFIAPPLET: A value has changed -> repainting." ); 334 qDebug( "WIFIAPPLET: A value has changed -> repainting." );
345 repaint(); 335 repaint();
346 } 336 }
347 337
348 if ( status->isVisible() ) 338 if ( status->isVisible() )
339 {
349 updatePopupWindow(); 340 updatePopupWindow();
350 } 341 }
351 else checkInterface(); 342 }
352 343 else
353 */ 344 {
345 checkInterface();
346 }
354} 347}
355 348
356void WirelessApplet::mousePressEvent( QMouseEvent * ) 349void WirelessApplet::mousePressEvent( QMouseEvent * )
@@ -450,28 +443,28 @@ bool WirelessApplet::mustRepaint()
450 443
451void WirelessApplet::updatePopupWindow() 444void WirelessApplet::updatePopupWindow()
452{ 445{
453 MWirelessNetworkInterface * iface = ( MWirelessNetworkInterface* ) interface; 446 OWirelessNetworkInterface* iface = interface;
454 int qualityH = iface->qualityPercent(); 447 int qualityH = iface->signalStrength();
455 448
456 if ( status->mgraph ) 449 if ( status->mgraph )
457 status->mgraph->addValue( qualityH, false ); 450 status->mgraph->addValue( qualityH, false );
458 451
459 QString freqString; 452 QString freqString;
460 QString cell = ( iface->mode == "Managed" ) ? "AP: " : "Cell: "; 453 QString cell = ( iface->mode() == "Managed" ) ? "AP: " : "Cell: ";
461 freqString.sprintf( "%.3f GHz", iface->freq ); 454 freqString.sprintf( "%.3f GHz", iface->frequency() );
462 status->statusLabel->setText( "Station: " + iface->nick + "<br>" + 455 status->statusLabel->setText( "Station: " + iface->nickName() + "<br>" +
463 "ESSID: " + iface->essid + "<br>" + 456 "ESSID: " + iface->SSID() + "<br>" +
464 "MODE: " + iface->mode + "<br>" + 457 "MODE: " + iface->mode() + "<br>" +
465 "FREQ: " + freqString + "<br>" + 458 "FREQ: " + freqString + "<br>" +
466 cell + " " + iface->APAddr ); 459 cell + " " + iface->associatedAP().toString() );
467} 460}
468 461
469const char** WirelessApplet::getQualityPixmap() 462const char** WirelessApplet::getQualityPixmap()
470{ 463{
471 MWirelessNetworkInterface * iface = ( MWirelessNetworkInterface* ) interface; 464 OWirelessNetworkInterface* iface = interface;
472 465
473 if ( !iface ) return ( const char** ) nowireless_xpm; 466 if ( !iface ) return ( const char** ) nowireless_xpm;
474 int qualityH = iface->qualityPercent(); 467 int qualityH = iface->signalStrength();
475 if ( qualityH < 0 ) return ( const char** ) nowireless_xpm; 468 if ( qualityH < 0 ) return ( const char** ) nowireless_xpm;
476 469
477 if ( visualStyle == STYLE_ANTENNA ) 470 if ( visualStyle == STYLE_ANTENNA )
@@ -489,7 +482,7 @@ const char** WirelessApplet::getQualityPixmap()
489 482
490void WirelessApplet::paintEvent( QPaintEvent* ) 483void WirelessApplet::paintEvent( QPaintEvent* )
491{ 484{
492 MWirelessNetworkInterface * iface = ( MWirelessNetworkInterface* ) interface; 485 OWirelessNetworkInterface* iface = interface;
493 486
494 QPainter p( this ); 487 QPainter p( this );
495 QColor color; 488 QColor color;
@@ -501,9 +494,9 @@ void WirelessApplet::paintEvent( QPaintEvent* )
501 else 494 else
502 { 495 {
503 496
504 int noiseH = iface->noisePercent() * ( height() - 3 ) / 100; 497 int noiseH = 30; // iface->noisePercent() * ( height() - 3 ) / 100;
505 int signalH = iface->signalPercent() * ( height() - 3 ) / 100; 498 int signalH = 50; // iface->signalPercent() * ( height() - 3 ) / 100;
506 int qualityH = iface->qualityPercent() * ( height() - 3 ) / 100; 499 int qualityH = iface->signalStrength(); // iface->qualityPercent() * ( height() - 3 ) / 100;
507 500
508 double intensity; 501 double intensity;
509 int pixelHeight; 502 int pixelHeight;
diff --git a/noncore/applets/wirelessapplet/wirelessapplet.pro b/noncore/applets/wirelessapplet/wirelessapplet.pro
index 7bd7380..636b2d3 100644
--- a/noncore/applets/wirelessapplet/wirelessapplet.pro
+++ b/noncore/applets/wirelessapplet/wirelessapplet.pro
@@ -1,7 +1,7 @@
1TEMPLATE = lib 1TEMPLATE = lib
2CONFIG += qt plugin warn_on release 2CONFIG += qt plugin warn_on release
3HEADERS = wireless.h networkinfo.h mgraph.h advancedconfig.h 3HEADERS = wireless.h mgraph.h advancedconfig.h
4SOURCES = wireless.cpp networkinfo.cpp mgraph.cpp advancedconfig.cpp 4SOURCES = wireless.cpp mgraph.cpp advancedconfig.cpp
5INTERFACES = advancedconfigbase.ui 5INTERFACES = advancedconfigbase.ui
6TARGET = wirelessapplet 6TARGET = wirelessapplet
7DESTDIR = $(OPIEDIR)/plugins/applets 7DESTDIR = $(OPIEDIR)/plugins/applets