summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/applets/wirelessapplet/networkinfo.cpp8
1 files changed, 3 insertions, 5 deletions
diff --git a/noncore/applets/wirelessapplet/networkinfo.cpp b/noncore/applets/wirelessapplet/networkinfo.cpp
index 2274d99..e0c487b 100644
--- a/noncore/applets/wirelessapplet/networkinfo.cpp
+++ b/noncore/applets/wirelessapplet/networkinfo.cpp
@@ -105,182 +105,180 @@ int MWirelessNetworkInterface::signalPercent()
105 105
106int MWirelessNetworkInterface::noisePercent() 106int MWirelessNetworkInterface::noisePercent()
107{ 107{
108 return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; 108 return ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER;
109} 109}
110 110
111bool MWirelessNetworkInterface::updateStatistics() 111bool MWirelessNetworkInterface::updateStatistics()
112{ 112{
113 bool base = MNetworkInterface::updateStatistics(); 113 bool base = MNetworkInterface::updateStatistics();
114 if ( !base ) 114 if ( !base )
115 return false; 115 return false;
116 116
117 const char* buffer[200]; 117 const char* buffer[200];
118 118
119 struct iwreq iwr; 119 struct iwreq iwr;
120 memset( &iwr, 0, sizeof( iwr ) ); 120 memset( &iwr, 0, sizeof( iwr ) );
121 iwr.u.essid.pointer = (caddr_t) buffer; 121 iwr.u.essid.pointer = (caddr_t) buffer;
122 iwr.u.essid.length = IW_ESSID_MAX_SIZE; 122 iwr.u.essid.length = IW_ESSID_MAX_SIZE;
123 iwr.u.essid.flags = 0; 123 iwr.u.essid.flags = 0;
124 124
125 // check if it is an IEEE 802.11 standard conform 125 // check if it is an IEEE 802.11 standard conform
126 // wireless device by sending SIOCGIWESSID 126 // wireless device by sending SIOCGIWESSID
127 // which also gives back the Extended Service Set ID 127 // which also gives back the Extended Service Set ID
128 // (see IEEE 802.11 for more information) 128 // (see IEEE 802.11 for more information)
129 129
130 strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name ); 130 strcpy( iwr.ifr_ifrn.ifrn_name, (const char*) name );
131 int result = ioctl( fd, SIOCGIWESSID, &iwr ); 131 int result = ioctl( fd, SIOCGIWESSID, &iwr );
132 if ( result == 0 ) 132 if ( result == 0 )
133 { 133 {
134 hasWirelessExtensions = true; 134 hasWirelessExtensions = true;
135 iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; 135 iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0';
136 essid = iwr.u.essid.pointer; 136 essid = iwr.u.essid.pointer;
137 } 137 }
138 else essid = "*** Unknown ***"; 138 else essid = "*** Unknown ***";
139 139
140 // Address of associated access-point 140 // Address of associated access-point
141 141
142 result = ioctl( fd, SIOCGIWAP, &iwr ); 142 result = ioctl( fd, SIOCGIWAP, &iwr );
143 if ( result == 0 ) 143 if ( result == 0 )
144 { 144 {
145 APAddr.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", 145 APAddr.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
146 iwr.u.ap_addr.sa_data[0]&0xff, 146 iwr.u.ap_addr.sa_data[0]&0xff,
147 iwr.u.ap_addr.sa_data[1]&0xff, 147 iwr.u.ap_addr.sa_data[1]&0xff,
148 iwr.u.ap_addr.sa_data[2]&0xff, 148 iwr.u.ap_addr.sa_data[2]&0xff,
149 iwr.u.ap_addr.sa_data[3]&0xff, 149 iwr.u.ap_addr.sa_data[3]&0xff,
150 iwr.u.ap_addr.sa_data[4]&0xff, 150 iwr.u.ap_addr.sa_data[4]&0xff,
151 iwr.u.ap_addr.sa_data[5]&0xff ); 151 iwr.u.ap_addr.sa_data[5]&0xff );
152 } else APAddr = "*** Unknown ***"; 152 } else APAddr = "*** Unknown ***";
153 153
154 iwr.u.data.pointer = (caddr_t) buffer; 154 iwr.u.data.pointer = (caddr_t) buffer;
155 iwr.u.data.length = IW_ESSID_MAX_SIZE; 155 iwr.u.data.length = IW_ESSID_MAX_SIZE;
156 iwr.u.data.flags = 0; 156 iwr.u.data.flags = 0;
157 157
158 result = ioctl( fd, SIOCGIWNICKN, &iwr ); 158 result = ioctl( fd, SIOCGIWNICKN, &iwr );
159 if ( result == 0 ) 159 if ( result == 0 )
160 { 160 {
161 iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; 161 iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0';
162 nick = iwr.u.data.pointer; 162 nick = iwr.u.data.pointer;
163 } else nick = "*** Unknown ***"; 163 } else nick = "*** Unknown ***";
164 164
165 result = ioctl( fd, SIOCGIWMODE, &iwr ); 165 result = ioctl( fd, SIOCGIWMODE, &iwr );
166 if ( result == 0 ) 166 if ( result == 0 )
167 mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed"; 167 mode = ( iwr.u.mode == IW_MODE_ADHOC ) ? "Ad-Hoc" : "Managed";
168 else mode = "*** Unknown ***"; 168 else mode = "*** Unknown ***";
169 169
170 result = ioctl( fd, SIOCGIWFREQ, &iwr ); 170 result = ioctl( fd, SIOCGIWFREQ, &iwr );
171 if ( result == 0 ) 171 if ( result == 0 )
172 freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000; 172 freq = double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000;
173 else freq = 0; 173 else freq = 0;
174 174
175 // gather link quality from /proc/net/wireless 175 // gather link quality from /proc/net/wireless
176 176
177 char c; 177 char c;
178 QString status; 178 QString status;
179 QString name; 179 QString name;
180 QFile wfile( PROCNETWIRELESS ); 180 QFile wfile( PROCNETWIRELESS );
181 bool hasFile = wfile.open( IO_ReadOnly ); 181 bool hasFile = wfile.open( IO_ReadOnly );
182 QTextStream wstream( &wfile ); 182 QTextStream wstream( &wfile );
183 if ( hasFile ) 183 if ( hasFile )
184 { 184 {
185 wstream.readLine(); // skip the first two lines 185 wstream.readLine(); // skip the first two lines
186 wstream.readLine(); // because they only contain headers 186 wstream.readLine(); // because they only contain headers
187 } 187 }
188 if ( ( !hasFile ) || ( wstream.atEnd() ) ) 188 if ( ( !hasFile ) || ( wstream.atEnd() ) )
189 { 189 {
190#ifdef MDEBUG 190#ifdef MDEBUG
191 qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); 191 qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." );
192#endif 192#endif
193 quality = -1; 193 quality = -1;
194 signal = IW_LOWER; 194 signal = IW_LOWER;
195 noise = IW_LOWER; 195 noise = IW_LOWER;
196 return false; 196 return false;
197 } 197 }
198 198
199 wstream >> name >> status >> quality >> c >> signal >> c >> noise; 199 wstream >> name >> status >> quality >> c >> signal >> c >> noise;
200 200
201 if ( quality > 92 )
202#ifdef MDEBUG 201#ifdef MDEBUG
202 if ( quality > 92 )
203 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); 203 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality );
204#endif 204
205 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) 205 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) )
206#ifdef MDEBUG
207 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); 206 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal );
208#endif 207
209 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) 208 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) )
210#ifdef MDEBUG
211 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); 209 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise );
212#endif 210#endif
213 211
214 return true; 212 return true;
215 213
216} 214}
217 215
218//--------------------------------------------------------------------------- 216//---------------------------------------------------------------------------
219// class Network 217// class Network
220// 218//
221 219
222MNetwork::MNetwork() 220MNetwork::MNetwork()
223{ 221{
224 procfile = PROCNETDEV; 222 procfile = PROCNETDEV;
225} 223}
226 224
227MNetwork::~MNetwork() 225MNetwork::~MNetwork()
228{ 226{
229} 227}
230 228
231//--------------------------------------------------------------------------- 229//---------------------------------------------------------------------------
232// class WirelessNetwork 230// class WirelessNetwork
233// 231//
234 232
235MWirelessNetwork::MWirelessNetwork() 233MWirelessNetwork::MWirelessNetwork()
236{ 234{
237 procfile = PROCNETWIRELESS; 235 procfile = PROCNETWIRELESS;
238} 236}
239 237
240MWirelessNetwork::~MWirelessNetwork() 238MWirelessNetwork::~MWirelessNetwork()
241{ 239{
242} 240}
243 241
244MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const 242MNetworkInterface* MWirelessNetwork::createInterface( const char* n ) const
245{ 243{
246 return new MWirelessNetworkInterface( n ); 244 return new MWirelessNetworkInterface( n );
247} 245}
248 246
249//--------------------------------------------------------------------------- 247//---------------------------------------------------------------------------
250// class NetworkInterface 248// class NetworkInterface
251// 249//
252 250
253MNetworkInterface* MNetwork::getFirstInterface() 251MNetworkInterface* MNetwork::getFirstInterface()
254{ 252{
255 enumerateInterfaces(); 253 enumerateInterfaces();
256 InterfaceMapIterator it( interfaces ); 254 InterfaceMapIterator it( interfaces );
257 return ( it.count() > 0 ) ? it.toFirst() : 0; 255 return ( it.count() > 0 ) ? it.toFirst() : 0;
258} 256}
259 257
260void MNetwork::enumerateInterfaces() 258void MNetwork::enumerateInterfaces()
261{ 259{
262 interfaces.clear(); 260 interfaces.clear();
263 QString str; 261 QString str;
264 QFile f( procfile ); 262 QFile f( procfile );
265 bool hasFile = f.open( IO_ReadOnly ); 263 bool hasFile = f.open( IO_ReadOnly );
266 if ( !hasFile ) 264 if ( !hasFile )
267 return; 265 return;
268 QTextStream s( &f ); 266 QTextStream s( &f );
269 s.readLine(); 267 s.readLine();
270 s.readLine(); 268 s.readLine();
271 while ( !s.atEnd() ) 269 while ( !s.atEnd() )
272 { 270 {
273 s >> str; 271 s >> str;
274 str.truncate( str.find( ':' ) ); 272 str.truncate( str.find( ':' ) );
275#ifdef MDEBUG 273#ifdef MDEBUG
276 qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str ); 274 qDebug( "WIFIAPPLET: found interface '%s'", (const char*) str );
277#endif 275#endif
278 interfaces.insert( str, createInterface( str ) ); 276 interfaces.insert( str, createInterface( str ) );
279 s.readLine(); 277 s.readLine();
280 } 278 }
281} 279}
282 280
283MNetworkInterface* MNetwork::createInterface( const char* n ) const 281MNetworkInterface* MNetwork::createInterface( const char* n ) const
284{ 282{
285 return new MNetworkInterface( n ); 283 return new MNetworkInterface( n );
286} 284}