-rw-r--r-- | noncore/settings/networksettings/wlan/wextensions.cpp | 2 |
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,161 +1,161 @@ | |||
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 | */ |
19 | WExtensions::WExtensions(QString interfaceName): hasWirelessExtensions(false), interface(interfaceName) { | 19 | WExtensions::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 | */ |
44 | QString WExtensions::station(){ | 44 | QString 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 | */ |
61 | QString WExtensions::essid(){ | 61 | QString 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 | */ |
74 | QString WExtensions::mode(){ | 74 | QString 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 | */ |
86 | double WExtensions::frequency(){ | 86 | double 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 | */ |
98 | int WExtensions::channel(){ | 98 | int 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 | */ |
123 | double WExtensions::rate(){ | 123 | double 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 | */ |
136 | QString WExtensions::ap(){ | 136 | QString 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 | */ |
160 | bool WExtensions::stats(int &signal, int &noise, int &quality){ | 160 | bool WExtensions::stats(int &signal, int &noise, int &quality){ |
161 | // gather link quality from /proc/net/wireless | 161 | // gather link quality from /proc/net/wireless |