summaryrefslogtreecommitdiff
path: root/noncore/applets/wirelessapplet/networkinfo.cpp
Unidiff
Diffstat (limited to 'noncore/applets/wirelessapplet/networkinfo.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/wirelessapplet/networkinfo.cpp30
1 files changed, 22 insertions, 8 deletions
diff --git a/noncore/applets/wirelessapplet/networkinfo.cpp b/noncore/applets/wirelessapplet/networkinfo.cpp
index 22d7d83..8531fd5 100644
--- a/noncore/applets/wirelessapplet/networkinfo.cpp
+++ b/noncore/applets/wirelessapplet/networkinfo.cpp
@@ -42,44 +42,47 @@
42 42
43/* estimated wireless signal strength and noise level values 43/* estimated wireless signal strength and noise level values
44 based on experimentation with Orinoco and Prism2 cards. 44 based on experimentation with Orinoco and Prism2 cards.
45 Seem to be correct, but please inform me, if you got values 45 Seem to be correct, but please inform me, if you got values
46 outside these boundaries. :Mickey: */ 46 outside these boundaries. :Mickey: */
47 47
48#define IW_UPPER 220 48#define IW_UPPER 220
49#define IW_LOWER 140 49#define IW_LOWER 140
50 50
51#define PROCNETDEV "/proc/net/dev" 51#define PROCNETDEV "/proc/net/dev"
52#define PROCNETWIRELESS "/proc/net/wireless" 52#define PROCNETWIRELESS "/proc/net/wireless"
53 53
54#define MDEBUG 0
55
54//--------------------------------------------------------------------------- 56//---------------------------------------------------------------------------
55// class MNetworkInterface 57// class MNetworkInterface
56// 58//
57 59
58MNetworkInterface::MNetworkInterface( const char* name ) 60MNetworkInterface::MNetworkInterface( const char* name )
59 :name( name ) 61 :name( name )
60{ 62{
61 struct ifreq ifr; 63 struct ifreq ifr;
62 struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; 64 struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr;
63 fd = socket( AF_INET, SOCK_DGRAM, 0 ); 65 fd = socket( AF_INET, SOCK_DGRAM, 0 );
64} 66}
65 67
66MNetworkInterface::~MNetworkInterface() 68MNetworkInterface::~MNetworkInterface()
67{ 69{
68 if ( fd != -1 ) 70 if ( fd != -1 )
69 close( fd ); 71 close( fd );
70} 72}
71 73
72void MNetworkInterface::updateStatistics() 74bool MNetworkInterface::updateStatistics()
73{ 75{
76 return true;
74} 77}
75 78
76//--------------------------------------------------------------------------- 79//---------------------------------------------------------------------------
77// class MWirelessNetworkInterface 80// class MWirelessNetworkInterface
78// 81//
79 82
80MWirelessNetworkInterface::MWirelessNetworkInterface( const char* n ) 83MWirelessNetworkInterface::MWirelessNetworkInterface( const char* n )
81 :MNetworkInterface( n ) 84 :MNetworkInterface( n )
82{ 85{
83 signal = 0; 86 signal = 0;
84 noise = 0; 87 noise = 0;
85 quality = 0; 88 quality = 0;
@@ -95,27 +98,29 @@ int MWirelessNetworkInterface::qualityPercent()
95} 98}
96 99
97int MWirelessNetworkInterface::signalPercent() 100int MWirelessNetworkInterface::signalPercent()
98{ 101{
99 return ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; 102 return ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER;
100} 103}
101 104
102int MWirelessNetworkInterface::noisePercent() 105int MWirelessNetworkInterface::noisePercent()
103{ 106{
104 return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; 107 return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER;
105} 108}
106 109
107void MWirelessNetworkInterface::updateStatistics() 110bool MWirelessNetworkInterface::updateStatistics()
108{ 111{
109 MNetworkInterface::updateStatistics(); 112 bool base = MNetworkInterface::updateStatistics();
113 if ( !base )
114 return false;
110 115
111 const char* buffer[200]; 116 const char* buffer[200];
112 117
113 struct iwreq iwr; 118 struct iwreq iwr;
114 memset( &iwr, 0, sizeof( iwr ) ); 119 memset( &iwr, 0, sizeof( iwr ) );
115 iwr.u.essid.pointer = (caddr_t) buffer; 120 iwr.u.essid.pointer = (caddr_t) buffer;
116 iwr.u.essid.length = IW_ESSID_MAX_SIZE; 121 iwr.u.essid.length = IW_ESSID_MAX_SIZE;
117 iwr.u.essid.flags = 0; 122 iwr.u.essid.flags = 0;
118 123
119 // check if it is an IEEE 802.11 standard conform 124 // check if it is an IEEE 802.11 standard conform
120 // wireless device by sending SIOCGIWESSID 125 // wireless device by sending SIOCGIWESSID
121 // which also gives back the Extended Service Set ID 126 // which also gives back the Extended Service Set ID
@@ -172,69 +177,76 @@ void MWirelessNetworkInterface::updateStatistics()
172 QString status; 177 QString status;
173 QString name; 178 QString name;
174 QFile wfile( PROCNETWIRELESS ); 179 QFile wfile( PROCNETWIRELESS );
175 bool hasFile = wfile.open( IO_ReadOnly ); 180 bool hasFile = wfile.open( IO_ReadOnly );
176 QTextStream wstream( &wfile ); 181 QTextStream wstream( &wfile );
177 if ( hasFile ) 182 if ( hasFile )
178 { 183 {
179 wstream.readLine(); // skip the first two lines 184 wstream.readLine(); // skip the first two lines
180 wstream.readLine(); // because they only contain headers 185 wstream.readLine(); // because they only contain headers
181 } 186 }
182 if ( ( !hasFile ) || ( wstream.atEnd() ) ) 187 if ( ( !hasFile ) || ( wstream.atEnd() ) )
183 { 188 {
189#ifdef MDEBUG
184 qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); 190 qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." );
191#endif
185 quality = -1; 192 quality = -1;
186 signal = IW_LOWER; 193 signal = IW_LOWER;
187 noise = IW_LOWER; 194 noise = IW_LOWER;
188 return; 195 return false;
189 } 196 }
190 197
191 wstream >> name >> status >> quality >> c >> signal >> c >> noise; 198 wstream >> name >> status >> quality >> c >> signal >> c >> noise;
192 199
193 if ( quality > 92 ) 200 if ( quality > 92 )
201#ifdef MDEBUG
194 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); 202 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality );
203#endif
195 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) 204 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) )
205#ifdef MDEBUG
196 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); 206 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal );
207#endif
197 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) 208 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) )
209#ifdef MDEBUG
198 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); 210 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise );
211#endif
212
213 return true;
214
199} 215}
200 216
201//--------------------------------------------------------------------------- 217//---------------------------------------------------------------------------
202// class Network 218// class Network
203// 219//
204 220
205MNetwork::MNetwork() 221MNetwork::MNetwork()
206{ 222{
207 //qDebug( "MNetwork::MNetwork()" );
208 procfile = PROCNETDEV; 223 procfile = PROCNETDEV;
209} 224}
210 225
211MNetwork::~MNetwork() 226MNetwork::~MNetwork()
212{ 227{
213 //qDebug( "MNetwork::~MNetwork()" );
214} 228}
215 229
216//--------------------------------------------------------------------------- 230//---------------------------------------------------------------------------
217// class WirelessNetwork 231// class WirelessNetwork
218// 232//
219 233
220MWirelessNetwork::MWirelessNetwork() 234MWirelessNetwork::MWirelessNetwork()
221{ 235{
222 //qDebug( "MWirelessNetwork::MWirelessNetwork()" );
223 procfile = PROCNETWIRELESS; 236 procfile = PROCNETWIRELESS;
224} 237}
225 238
226MWirelessNetwork::~MWirelessNetwork() 239MWirelessNetwork::~MWirelessNetwork()
227{ 240{
228 //qDebug( "MWirelessNetwork::~MWirelessNetwork()" );
229} 241}
230 242
231MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const 243MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const
232{ 244{
233 return new MWirelessNetworkInterface( n ); 245 return new MWirelessNetworkInterface( n );
234} 246}
235 247
236//--------------------------------------------------------------------------- 248//---------------------------------------------------------------------------
237// class NetworkInterface 249// class NetworkInterface
238// 250//
239 251
240MNetworkInterface* MNetwork::getFirstInterface() 252MNetworkInterface* MNetwork::getFirstInterface()
@@ -250,22 +262,24 @@ void MNetwork::enumerateInterfaces()
250 QString str; 262 QString str;
251 QFile f( procfile ); 263 QFile f( procfile );
252 bool hasFile = f.open( IO_ReadOnly ); 264 bool hasFile = f.open( IO_ReadOnly );
253 if ( !hasFile ) 265 if ( !hasFile )
254 return; 266 return;
255 QTextStream s( &f ); 267 QTextStream s( &f );
256 s.readLine(); 268 s.readLine();
257 s.readLine(); 269 s.readLine();
258 while ( !s.atEnd() ) 270 while ( !s.atEnd() )
259 { 271 {
260 s >> str; 272 s >> str;
261 str.truncate( str.find( ':' ) ); 273 str.truncate( str.find( ':' ) );
274#ifdef MDEBUG
262 qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str ); 275 qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str );
276#endif
263 interfaces.insert( str, createInterface( str ) ); 277 interfaces.insert( str, createInterface( str ) );
264 s.readLine(); 278 s.readLine();
265 } 279 }
266} 280}
267 281
268MNetworkInterface* MNetwork::createInterface( const char* n ) const 282MNetworkInterface* MNetwork::createInterface( const char* n ) const
269{ 283{
270 return new MNetworkInterface( n ); 284 return new MNetworkInterface( n );
271} 285}