Diffstat (limited to 'noncore/net/networksetup/wlan/wextensions.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/networksetup/wlan/wextensions.cpp | 41 |
1 files changed, 29 insertions, 12 deletions
diff --git a/noncore/net/networksetup/wlan/wextensions.cpp b/noncore/net/networksetup/wlan/wextensions.cpp index f45ebf2..ef4ba8f 100644 --- a/noncore/net/networksetup/wlan/wextensions.cpp +++ b/noncore/net/networksetup/wlan/wextensions.cpp | |||
@@ -1,38 +1,38 @@ | |||
1 | #include "wextensions.h" | 1 | #include "wextensions.h" |
2 | 2 | ||
3 | #include <qfile.h> | 3 | #include <qfile.h> |
4 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
5 | 5 | ||
6 | #include <arpa/inet.h> | 6 | #include <arpa/inet.h> |
7 | #include <sys/socket.h> | 7 | #include <sys/socket.h> |
8 | #include <sys/ioctl.h> | 8 | #include <sys/ioctl.h> |
9 | 9 | ||
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 |
18 | */ | 18 | */ |
19 | WExtensions::WExtensions(QString interfaceName){ | 19 | WExtensions::WExtensions(QString interfaceName){ |
20 | interface = interfaceName; | 20 | interface = interfaceName; |
21 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); | 21 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); |
22 | 22 | ||
23 | const char* buffer[200]; | 23 | const char* buffer[200]; |
24 | memset( &iwr, 0, sizeof( iwr ) ); | 24 | memset( &iwr, 0, sizeof( iwr ) ); |
25 | iwr.u.essid.pointer = (caddr_t) buffer; | 25 | iwr.u.essid.pointer = (caddr_t) buffer; |
26 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 26 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
27 | iwr.u.essid.flags = 0; | 27 | iwr.u.essid.flags = 0; |
28 | 28 | ||
29 | // check if it is an IEEE 802.11 standard conform | 29 | // check if it is an IEEE 802.11 standard conform |
30 | // wireless device by sending SIOCGIWESSID | 30 | // wireless device by sending SIOCGIWESSID |
31 | // which also gives back the Extended Service Set ID | 31 | // which also gives back the Extended Service Set ID |
32 | // (see IEEE 802.11 for more information) | 32 | // (see IEEE 802.11 for more information) |
33 | 33 | ||
34 | const char* iname = interface.latin1(); | 34 | const char* iname = interface.latin1(); |
35 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); | 35 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); |
36 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) ) | 36 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) ) |
37 | hasWirelessExtensions = true; | 37 | hasWirelessExtensions = true; |
38 | else | 38 | else |
@@ -68,91 +68,108 @@ QString WExtensions::essid(){ | |||
68 | } | 68 | } |
69 | return QString(); | 69 | return QString(); |
70 | } | 70 | } |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * @return QString the mode of interface | 73 | * @return QString the mode of interface |
74 | */ | 74 | */ |
75 | QString WExtensions::mode(){ | 75 | QString WExtensions::mode(){ |
76 | if(!hasWirelessExtensions) | 76 | if(!hasWirelessExtensions) |
77 | return QString(); | 77 | return QString(); |
78 | if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) ) | 78 | if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) ) |
79 | return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed"); | 79 | return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed"); |
80 | return QString(); | 80 | return QString(); |
81 | } | 81 | } |
82 | 82 | ||
83 | /** | 83 | /** |
84 | * Get the frequency that the interface is running at. | 84 | * Get the frequency that the interface is running at. |
85 | * @return int the frequency that the interfacae is running at. | 85 | * @return int the frequency that the interfacae is running at. |
86 | */ | 86 | */ |
87 | double WExtensions::frequency(){ | 87 | double WExtensions::frequency(){ |
88 | if(!hasWirelessExtensions) | 88 | if(!hasWirelessExtensions) |
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 | */ | ||
98 | double 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 | */ |
98 | QString WExtensions::ap(){ | 111 | QString WExtensions::ap(){ |
99 | if(!hasWirelessExtensions) | 112 | if(!hasWirelessExtensions) |
100 | return QString(); | 113 | return QString(); |
101 | if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){ | 114 | if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){ |
102 | QString ap; | 115 | QString ap; |
103 | ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 116 | ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
104 | iwr.u.ap_addr.sa_data[0]&0xff, | 117 | iwr.u.ap_addr.sa_data[0]&0xff, |
105 | iwr.u.ap_addr.sa_data[1]&0xff, | 118 | iwr.u.ap_addr.sa_data[1]&0xff, |
106 | iwr.u.ap_addr.sa_data[2]&0xff, | 119 | iwr.u.ap_addr.sa_data[2]&0xff, |
107 | iwr.u.ap_addr.sa_data[3]&0xff, | 120 | iwr.u.ap_addr.sa_data[3]&0xff, |
108 | iwr.u.ap_addr.sa_data[4]&0xff, | 121 | iwr.u.ap_addr.sa_data[4]&0xff, |
109 | iwr.u.ap_addr.sa_data[5]&0xff ); | 122 | iwr.u.ap_addr.sa_data[5]&0xff ); |
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 | */ | ||
116 | bool WExtensions::stats(int &signal, int &noise, int &quality){ | 135 | bool 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)) |
119 | return false; | 138 | return false; |
120 | 139 | ||
121 | char c; | 140 | char c; |
122 | QString status; | 141 | QString status; |
123 | QString name; | 142 | QString name; |
124 | 143 | ||
125 | QFile wfile( PROCNETWIRELESS ); | 144 | QFile wfile( PROCNETWIRELESS ); |
126 | if(!wfile.open( IO_ReadOnly )) | 145 | if(!wfile.open( IO_ReadOnly )) |
127 | return false; | 146 | return false; |
128 | 147 | ||
129 | QTextStream wstream( &wfile ); | 148 | QTextStream wstream( &wfile ); |
130 | wstream.readLine(); // skip the first two lines | 149 | wstream.readLine(); // skip the first two lines |
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; |
155 | return false; | 172 | return false; |
156 | } | 173 | } |
157 | 174 | ||
158 | // wextensions.cpp | 175 | // wextensions.cpp |