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