summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings/wlan/wextensions.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings/wlan/wextensions.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings/wlan/wextensions.cpp41
1 files changed, 29 insertions, 12 deletions
diff --git a/noncore/settings/networksettings/wlan/wextensions.cpp b/noncore/settings/networksettings/wlan/wextensions.cpp
index f45ebf2..ef4ba8f 100644
--- a/noncore/settings/networksettings/wlan/wextensions.cpp
+++ b/noncore/settings/networksettings/wlan/wextensions.cpp
@@ -10,8 +10,8 @@
10#include <math.h> 10#include <math.h>
11 11
12#define PROCNETWIRELESS "/proc/net/wireless" 12#define PROCNETWIRELESS "/proc/net/wireless"
13#define IW_LOWER 140 13#define IW_LOWER 0
14#define IW_UPPER 200 14#define IW_UPPER 256
15 15
16/** 16/**
17 * Constructor. Sets hasWirelessExtensions 17 * Constructor. Sets hasWirelessExtensions
@@ -89,9 +89,22 @@ double WExtensions::frequency(){
89 return 0; 89 return 0;
90 if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr )) 90 if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr ))
91 return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000); 91 return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000);
92 return 0;; 92 return 0;
93} 93}
94 94
95/***
96 * Get the current rate that the card is transmiting at.
97 */
98double WExtensions::rate(){
99 if(!hasWirelessExtensions)
100 return 0;
101 if(0 == ioctl(fd, SIOCGIWRATE, &iwr)){
102 return ((double)iwr.u.bitrate.value)/1000000;
103 }
104 return 0;
105}
106
107
95/** 108/**
96 * @return QString the AccessPoint that the interface is connected to. 109 * @return QString the AccessPoint that the interface is connected to.
97 */ 110 */
@@ -110,9 +123,15 @@ QString WExtensions::ap(){
110 return ap; 123 return ap;
111 } 124 }
112 else return QString(); 125 else return QString();
113
114} 126}
115 127
128/**
129 * Get the stats for interfaces
130 * @param signal the signal strength of interface
131 * @param noise the noise level of the interface
132 * @param quality the quality level of the interface
133 * @return bool true if successfull
134 */
116bool WExtensions::stats(int &signal, int &noise, int &quality){ 135bool WExtensions::stats(int &signal, int &noise, int &quality){
117 // gather link quality from /proc/net/wireless 136 // gather link quality from /proc/net/wireless
118 if(!QFile::exists(PROCNETWIRELESS)) 137 if(!QFile::exists(PROCNETWIRELESS))
@@ -131,24 +150,22 @@ bool WExtensions::stats(int &signal, int &noise, int &quality){
131 wstream.readLine(); // because they only contain headers 150 wstream.readLine(); // because they only contain headers
132 while(!wstream.atEnd()){ 151 while(!wstream.atEnd()){
133 wstream >> name >> status >> quality >> c >> signal >> c >> noise; 152 wstream >> name >> status >> quality >> c >> signal >> c >> noise;
134 if(name == interface){ 153 if(name == QString("%1:").arg(interface)){
135 if ( quality > 92 ) 154 if ( quality > 92 )
136 #ifdef MDEBUG
137 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); 155 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality );
138 #endif
139 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) 156 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) )
140 #ifdef MDEBUG
141 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); 157 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal );
142 #endif
143 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) 158 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) )
144 #ifdef MDEBUG
145 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); 159 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise );
146 #endif 160 qDebug(QString("q:%1, s:%2, n:%3").arg(quality).arg(signal).arg(noise).latin1());
161 signal = ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER;
162 noise = ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER;
163 quality = ( quality*100 ) / 92;
147 return true; 164 return true;
148 } 165 }
149 } 166 }
150 167
151 qDebug("Card no longer present"); 168 qDebug("WExtensions::statsCard no longer present.");
152 quality = -1; 169 quality = -1;
153 signal = IW_LOWER; 170 signal = IW_LOWER;
154 noise = IW_LOWER; 171 noise = IW_LOWER;