Diffstat (limited to 'noncore/net/networksetup/wlan/wlanmodule.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/networksetup/wlan/wlanmodule.cpp | 164 |
1 files changed, 35 insertions, 129 deletions
diff --git a/noncore/net/networksetup/wlan/wlanmodule.cpp b/noncore/net/networksetup/wlan/wlanmodule.cpp index 24cb1cd..ab0b9a5 100644 --- a/noncore/net/networksetup/wlan/wlanmodule.cpp +++ b/noncore/net/networksetup/wlan/wlanmodule.cpp | |||
@@ -3,19 +3,6 @@ | |||
3 | #include "info.h" | 3 | #include "info.h" |
4 | 4 | #include "wextensions.h" | |
5 | #include <arpa/inet.h> | ||
6 | #include <sys/socket.h> | ||
7 | #include <linux/if_ether.h> | ||
8 | #include <netinet/ip.h> | ||
9 | #include <sys/ioctl.h> | ||
10 | #include <linux/wireless.h> | ||
11 | |||
12 | #include <unistd.h> | ||
13 | #include <math.h> | ||
14 | #include <errno.h> | ||
15 | #include <string.h> | ||
16 | #include <stdio.h> | ||
17 | |||
18 | #include <stdlib.h> | ||
19 | 5 | ||
20 | #include <qlabel.h> | 6 | #include <qlabel.h> |
7 | #include <qprogressbar.h> | ||
21 | 8 | ||
@@ -29,2 +16,10 @@ WLANModule::WLANModule() : Module() { | |||
29 | /** | 16 | /** |
17 | */ | ||
18 | WLANModule::~WLANModule(){ | ||
19 | Interface *i; | ||
20 | for ( i=list.first(); i != 0; i=list.next() ) | ||
21 | delete i; | ||
22 | } | ||
23 | |||
24 | /** | ||
30 | * Change the current profile | 25 | * Change the current profile |
@@ -50,7 +45,12 @@ QString WLANModule::getPixmapName(Interface* ){ | |||
50 | bool WLANModule::isOwner(Interface *i){ | 45 | bool WLANModule::isOwner(Interface *i){ |
51 | if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ | 46 | WExtensions we(i->getInterfaceName()); |
47 | if(!we.doesHaveWirelessExtensions()) | ||
48 | return false; | ||
49 | |||
50 | //if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){ | ||
52 | i->setHardwareName("802.11b"); | 51 | i->setHardwareName("802.11b"); |
52 | list.append(i); | ||
53 | return true; | 53 | return true; |
54 | } | 54 | //} |
55 | return false; | 55 | //return false; |
56 | } | 56 | } |
@@ -62,3 +62,3 @@ bool WLANModule::isOwner(Interface *i){ | |||
62 | */ | 62 | */ |
63 | QWidget *WLANModule::configure(Interface *i, QTabWidget **tabWidget){ | 63 | QWidget *WLANModule::configure(Interface *, QTabWidget **tabWidget){ |
64 | WLANImp *wlanconfig = new WLANImp(0, "WlanConfig"); | 64 | WLANImp *wlanconfig = new WLANImp(0, "WlanConfig"); |
@@ -74,115 +74,21 @@ QWidget *WLANModule::configure(Interface *i, QTabWidget **tabWidget){ | |||
74 | QWidget *WLANModule::information(Interface *i, QTabWidget **tabWidget){ | 74 | QWidget *WLANModule::information(Interface *i, QTabWidget **tabWidget){ |
75 | return NULL; | 75 | WExtensions we(i->getInterfaceName()); |
76 | if(!we.doesHaveWirelessExtensions()) | ||
77 | return NULL; | ||
78 | |||
76 | WlanInfo *info = new WlanInfo(0, "wireless info"); | 79 | WlanInfo *info = new WlanInfo(0, "wireless info"); |
77 | (*tabWidget) = info->tabWidget; | 80 | (*tabWidget) = info->tabWidget; |
78 | |||
79 | struct ifreq ifr; | ||
80 | struct sockaddr_in *sin = (struct sockaddr_in *) &ifr.ifr_addr; | ||
81 | int fd = socket( AF_INET, SOCK_DGRAM, 0 ); | ||
82 | 81 | ||
83 | const char* buffer[200]; | 82 | info->essidLabel->setText(we.essid()); |
84 | struct iwreq iwr; | 83 | info->apLabel->setText(we.ap()); |
85 | memset( &iwr, 0, sizeof( iwr ) ); | 84 | info->stationLabel->setText(we.station()); |
86 | iwr.u.essid.pointer = (caddr_t) buffer; | 85 | info->modeLabel->setText(we.mode()); |
87 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 86 | info->freqLabel->setText(QString("%1").arg(we.frequency())); |
88 | iwr.u.essid.flags = 0; | 87 | int signal = 0; |
89 | 88 | int noise = 0; | |
90 | // check if it is an IEEE 802.11 standard conform | 89 | int quality = 0; |
91 | // wireless device by sending SIOCGIWESSID | 90 | we.stats(signal, noise, quality); |
92 | // which also gives back the Extended Service Set ID | 91 | info->signalProgressBar->setProgress(signal); |
93 | // (see IEEE 802.11 for more information) | 92 | info->noiseProgressBar->setProgress(noise); |
94 | 93 | info->qualityProgressBar->setProgress(quality); | |
95 | QString n = (i->getInterfaceName()); | ||
96 | const char* iname = n.latin1(); | ||
97 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); | ||
98 | int result = ioctl( fd, SIOCGIWESSID, &iwr ); | ||
99 | if ( result == 0 ){ | ||
100 | //hasWirelessExtensions = true; | ||
101 | iwr.u.essid.pointer[(unsigned int) iwr.u.essid.length-1] = '\0'; | ||
102 | info->essidLabel->setText(QString(iwr.u.essid.pointer)); | ||
103 | } | ||
104 | else | ||
105 | return info; | ||
106 | //info->essidLabel->setText("*** Unknown ***"); | ||
107 | |||
108 | // Address of associated access-point | ||
109 | result = ioctl( fd, SIOCGIWAP, &iwr ); | ||
110 | if ( result == 0 ){ | ||
111 | QString foo = foo.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | ||
112 | iwr.u.ap_addr.sa_data[0]&0xff, | ||
113 | iwr.u.ap_addr.sa_data[1]&0xff, | ||
114 | iwr.u.ap_addr.sa_data[2]&0xff, | ||
115 | iwr.u.ap_addr.sa_data[3]&0xff, | ||
116 | iwr.u.ap_addr.sa_data[4]&0xff, | ||
117 | iwr.u.ap_addr.sa_data[5]&0xff ); | ||
118 | info->apLabel->setText(foo); | ||
119 | } | ||
120 | else info->apLabel->setText("*** Unknown ***"); | ||
121 | |||
122 | iwr.u.data.pointer = (caddr_t) buffer; | ||
123 | iwr.u.data.length = IW_ESSID_MAX_SIZE; | ||
124 | iwr.u.data.flags = 0; | ||
125 | result = ioctl( fd, SIOCGIWNICKN, &iwr ); | ||
126 | if ( result == 0 ){ | ||
127 | iwr.u.data.pointer[(unsigned int) iwr.u.data.length-1] = '\0'; | ||
128 | info->stationLabel->setText(iwr.u.data.pointer); | ||
129 | } | ||
130 | else info->stationLabel->setText("*** Unknown ***"); | ||
131 | |||
132 | result = ioctl( fd, SIOCGIWMODE, &iwr ); | ||
133 | if ( result == 0 ) | ||
134 | info->modeLabel->setText( QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed")); | ||
135 | else | ||
136 | info->modeLabel->setText("*** Unknown ***"); | ||
137 | |||
138 | result = ioctl( fd, SIOCGIWFREQ, &iwr ); | ||
139 | if ( result == 0 ) | ||
140 | info->freqLabel->setText(QString("%1").arg((double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000))); | ||
141 | else | ||
142 | info->freqLabel->setText("*** Unknown ***"); | ||
143 | |||
144 | /* | ||
145 | // gather link quality from /proc/net/wireless | ||
146 | |||
147 | char c; | ||
148 | QString status; | ||
149 | QString name; | ||
150 | QFile wfile( PROCNETWIRELESS ); | ||
151 | bool hasFile = wfile.open( IO_ReadOnly ); | ||
152 | QTextStream wstream( &wfile ); | ||
153 | if ( hasFile ) | ||
154 | { | ||
155 | wstream.readLine(); // skip the first two lines | ||
156 | wstream.readLine(); // because they only contain headers | ||
157 | } | ||
158 | if ( ( !hasFile ) || ( wstream.atEnd() ) ) | ||
159 | { | ||
160 | #ifdef MDEBUG | ||
161 | qDebug( "WIFIAPPLET: D'oh! Someone removed the card..." ); | ||
162 | #endif | ||
163 | quality = -1; | ||
164 | signal = IW_LOWER; | ||
165 | noise = IW_LOWER; | ||
166 | return false; | ||
167 | } | ||
168 | |||
169 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; | ||
170 | |||
171 | if ( quality > 92 ) | ||
172 | #ifdef MDEBUG | ||
173 | qDebug( "WIFIAPPLET: D'oh! Quality %d > estimated max!\n", quality ); | ||
174 | #endif | ||
175 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) | ||
176 | #ifdef MDEBUG | ||
177 | qDebug( "WIFIAPPLET: Doh! Strength %d > estimated max!\n", signal ); | ||
178 | #endif | ||
179 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) | ||
180 | #ifdef MDEBUG | ||
181 | qDebug( "WIFIAPPLET: Doh! Noise %d > estimated max!\n", noise ); | ||
182 | #endif | ||
183 | |||
184 | return true; | ||
185 | |||
186 | } | ||
187 | */ | ||
188 | return info; | 94 | return info; |