summaryrefslogtreecommitdiff
path: root/noncore/net/networksetup/wlan/wextensions.cpp
Unidiff
Diffstat (limited to 'noncore/net/networksetup/wlan/wextensions.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/wlan/wextensions.cpp200
1 files changed, 0 insertions, 200 deletions
diff --git a/noncore/net/networksetup/wlan/wextensions.cpp b/noncore/net/networksetup/wlan/wextensions.cpp
deleted file mode 100644
index 827d075..0000000
--- a/noncore/net/networksetup/wlan/wextensions.cpp
+++ b/dev/null
@@ -1,200 +0,0 @@
1#include "wextensions.h"
2
3#include <qfile.h>
4#include <qtextstream.h>
5
6#include <arpa/inet.h>
7#include <sys/socket.h>
8#include <sys/ioctl.h>
9
10#include <math.h>
11
12#define PROCNETWIRELESS "/proc/net/wireless"
13#define IW_LOWER 0
14#define IW_UPPER 256
15
16/**
17 * Constructor. Sets hasWirelessExtensions
18 */
19WExtensions::WExtensions(QString interfaceName): hasWirelessExtensions(false), interface(interfaceName) {
20 fd = socket( AF_INET, SOCK_DGRAM, 0 );
21 if(fd == -1)
22 return;
23
24 const char* buffer[200];
25 memset( &iwr, 0, sizeof( iwr ) );
26 iwr.u.essid.pointer = (caddr_t) buffer;
27 iwr.u.essid.length = IW_ESSID_MAX_SIZE;
28 iwr.u.essid.flags = 0;
29
30 // check if it is an IEEE 802.11 standard conform
31 // wireless device by sending SIOCGIWESSID
32 // which also gives back the Extended Service Set ID
33 // (see IEEE 802.11 for more information)
34
35 const char* iname = interface.latin1();
36 strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname );
37 if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) )
38 hasWirelessExtensions = true;
39}
40
41/**
42 * @return QString the station name of the access point.
43 */
44QString WExtensions::station(){
45 if(!hasWirelessExtensions)
46 return QString();
47 const char* buffer[200];
48 iwr.u.data.pointer = (caddr_t) buffer;
49 iwr.u.data.length = IW_ESSID_MAX_SIZE;
50 iwr.u.data.flags = 0;
51 if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){
52 iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0';
53 return QString(iwr.u.data.pointer);
54 }
55 return QString();
56}
57
58/**
59 * @return QString the essid of the host 802.11 access point.
60 */
61QString WExtensions::essid(){
62 if(!hasWirelessExtensions)
63 return QString();
64 if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){
65 iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0';
66 return QString(iwr.u.essid.pointer);
67 }
68 return QString();
69}
70
71/**
72 * @return QString the mode of interface
73 */
74QString WExtensions::mode(){
75 if(!hasWirelessExtensions)
76 return QString();
77 if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) )
78 return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed");
79 return QString();
80}
81
82/**
83 * Get the frequency that the interface is running at.
84 * @return int the frequency that the interfacae is running at.
85 */
86double WExtensions::frequency(){
87 if(!hasWirelessExtensions)
88 return 0;
89 if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr ))
90 return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000);
91 return 0;
92}
93
94/**
95 * Get the channel that the interface is running at.
96 * @return int the channel that the interfacae is running at.
97 */
98int WExtensions::channel(){
99 if(!hasWirelessExtensions)
100 return 0;
101 if ( 0 != ioctl( fd, SIOCGIWFREQ, &iwr ))
102 return 0;
103
104 // http://www.elanix.com/pdf/an137e.pdf
105
106 double num = (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000);
107 double left = 2.401;
108 double right = 2.416;
109 for(int channel = 1; channel<= 15; channel++){
110 if( num >= left && num <= right )
111 return channel;
112 left += 0.005;
113 right += 0.005;
114 }
115 qDebug(QString("Unknown frequency: %1, returning -1 for the channel.").arg(num).latin1());
116 return -1;
117}
118
119/***
120 * Get the current rate that the card is transmiting at.
121 * @return double the rate, 0 if error.
122 */
123double WExtensions::rate(){
124 if(!hasWirelessExtensions)
125 return 0;
126 if(0 == ioctl(fd, SIOCGIWRATE, &iwr)){
127 return ((double)iwr.u.bitrate.value)/1000000;
128 }
129 return 0;
130}
131
132
133/**
134 * @return QString the AccessPoint that the interface is connected to.
135 */
136QString WExtensions::ap(){
137 if(!hasWirelessExtensions)
138 return QString();
139 if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){
140 QString ap;
141 ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X",
142 iwr.u.ap_addr.sa_data[0]&0xff,
143 iwr.u.ap_addr.sa_data[1]&0xff,
144 iwr.u.ap_addr.sa_data[2]&0xff,
145 iwr.u.ap_addr.sa_data[3]&0xff,
146 iwr.u.ap_addr.sa_data[4]&0xff,
147 iwr.u.ap_addr.sa_data[5]&0xff );
148 return ap;
149 }
150 else return QString();
151}
152
153/**
154 * Get the stats for interfaces
155 * @param signal the signal strength of interface
156 * @param noise the noise level of the interface
157 * @param quality the quality level of the interface
158 * @return bool true if successfull
159 */
160bool WExtensions::stats(int &signal, int &noise, int &quality){
161 // gather link quality from /proc/net/wireless
162 if(!QFile::exists(PROCNETWIRELESS))
163 return false;
164
165 char c;
166 QString status;
167 QString name;
168
169 QFile wfile( PROCNETWIRELESS );
170 if(!wfile.open( IO_ReadOnly ))
171 return false;
172
173 QTextStream wstream( &wfile );
174 wstream.readLine(); // skip the first two lines
175 wstream.readLine(); // because they only contain headers
176 while(!wstream.atEnd()){
177 wstream >> name >> status >> quality >> c >> signal >> c >> noise;
178 if(name == QString("%1:").arg(interface)){
179 if ( quality > 92 )
180 qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality );
181 if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) )
182 qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal );
183 if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) )
184 qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise );
185 //qDebug(QString("q:%1, s:%2, n:%3").arg(quality).arg(signal).arg(noise).latin1());
186 signal = ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER;
187 noise = ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER;
188 quality = ( quality*100 ) / 92;
189 return true;
190 }
191 }
192
193 qDebug("WExtensions::statsCard no longer present.");
194 quality = -1;
195 signal = IW_LOWER;
196 noise = IW_LOWER;
197 return false;
198}
199
200// wextensions.cpp