4 files changed, 189 insertions, 52 deletions
diff --git a/noncore/settings/networksettings/wlan/wextensions.cpp b/noncore/settings/networksettings/wlan/wextensions.cpp index 8a9db66..64d8752 100644 --- a/noncore/settings/networksettings/wlan/wextensions.cpp +++ b/noncore/settings/networksettings/wlan/wextensions.cpp | |||
@@ -1,211 +1,214 @@ | |||
1 | #include "wextensions.h" | 1 | #include "wextensions.h" |
2 | 2 | ||
3 | /* OPIE */ | 3 | /* OPIE */ |
4 | #include <opie2/odebug.h> | 4 | #include <opie2/odebug.h> |
5 | using namespace Opie::Core; | 5 | using namespace Opie::Core; |
6 | 6 | ||
7 | /* QT */ | 7 | /* QT */ |
8 | #include <qfile.h> | 8 | #include <qfile.h> |
9 | #include <qtextstream.h> | 9 | #include <qtextstream.h> |
10 | 10 | ||
11 | /* STD */ | 11 | /* STD */ |
12 | #include <arpa/inet.h> | 12 | #include <arpa/inet.h> |
13 | #include <sys/socket.h> | 13 | #include <sys/socket.h> |
14 | #include <sys/ioctl.h> | 14 | #include <sys/ioctl.h> |
15 | #include <math.h> | 15 | #include <math.h> |
16 | 16 | ||
17 | #define PROCNETWIRELESS "/proc/net/wireless" | 17 | #define PROCNETWIRELESS "/proc/net/wireless" |
18 | #define IW_LOWER 0 | 18 | #define IW_LOWER 0 |
19 | #define IW_UPPER 256 | 19 | #define IW_UPPER 256 |
20 | 20 | ||
21 | #warning This is duplicated code. Use libopienet2! | 21 | #warning This is duplicated code. Use libopienet2! |
22 | 22 | ||
23 | /** | 23 | /** |
24 | * Constructor. Sets hasWirelessExtensions | 24 | * Constructor. Sets hasWirelessExtensions |
25 | */ | 25 | */ |
26 | WExtensions::WExtensions(QString interfaceName): hasWirelessExtensions(false), interface(interfaceName) { | 26 | WExtensions::WExtensions(QString interfaceName): hasWirelessExtensions(false), interface(interfaceName) { |
27 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); | 27 | fd = socket( AF_INET, SOCK_DGRAM, 0 ); |
28 | if(fd == -1) | 28 | if(fd == -1) |
29 | return; | 29 | return; |
30 | 30 | ||
31 | const char* buffer[200]; | 31 | const char* buffer[200]; |
32 | memset( &iwr, 0, sizeof( iwr ) ); | 32 | memset( &iwr, 0, sizeof( iwr ) ); |
33 | iwr.u.essid.pointer = (caddr_t) buffer; | 33 | iwr.u.essid.pointer = (caddr_t) buffer; |
34 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | 34 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; |
35 | iwr.u.essid.flags = 0; | 35 | iwr.u.essid.flags = 0; |
36 | 36 | ||
37 | // check if it is an IEEE 802.11 standard conform | 37 | // check if it is an IEEE 802.11 standard conform |
38 | // wireless device by sending SIOCGIWESSID | 38 | // wireless device by sending SIOCGIWESSID |
39 | // which also gives back the Extended Service Set ID | 39 | // which also gives back the Extended Service Set ID |
40 | // (see IEEE 802.11 for more information) | 40 | // (see IEEE 802.11 for more information) |
41 | 41 | ||
42 | const char* iname = interface.latin1(); | 42 | const char* iname = interface.latin1(); |
43 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); | 43 | strcpy( iwr.ifr_ifrn.ifrn_name, (const char *)iname ); |
44 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) ) | 44 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr ) ) |
45 | hasWirelessExtensions = true; | 45 | hasWirelessExtensions = true; |
46 | } | 46 | } |
47 | 47 | ||
48 | /** | 48 | /** |
49 | * @return QString the station name of the access point. | 49 | * @return QString the station name of the access point. |
50 | */ | 50 | */ |
51 | QString WExtensions::station(){ | 51 | QString WExtensions::station(){ |
52 | if(!hasWirelessExtensions) | 52 | if(!hasWirelessExtensions) |
53 | return QString(); | 53 | return QString(); |
54 | const char* buffer[200]; | 54 | const char* buffer[200]; |
55 | iwr.u.data.pointer = (caddr_t) buffer; | 55 | iwr.u.data.pointer = (caddr_t) buffer; |
56 | iwr.u.data.length = IW_ESSID_MAX_SIZE; | 56 | iwr.u.data.length = IW_ESSID_MAX_SIZE; |
57 | iwr.u.data.flags = 0; | 57 | iwr.u.data.flags = 0; |
58 | if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){ | 58 | if ( 0 == ioctl( fd, SIOCGIWNICKN, &iwr )){ |
59 | buffer[(unsigned int) iwr.u.data.length-1] = '\0'; | 59 | buffer[(unsigned int) iwr.u.data.length-1] = '\0'; |
60 | return (const char*) buffer; | 60 | return (const char*) buffer; |
61 | } | 61 | } |
62 | return QString::null; | 62 | return QString::null; |
63 | } | 63 | } |
64 | 64 | ||
65 | /** | 65 | /** |
66 | * @return QString the essid of the host 802.11 access point. | 66 | * @return QString the essid of the host 802.11 access point. |
67 | */ | 67 | */ |
68 | QString WExtensions::essid(){ | 68 | QString WExtensions::essid(){ |
69 | if(!hasWirelessExtensions) | 69 | if(!hasWirelessExtensions) |
70 | return QString(); | 70 | return QString(); |
71 | const char* buffer[200]; | 71 | const char* buffer[200]; |
72 | memset(buffer,0x00,200); | ||
72 | iwr.u.data.pointer = (caddr_t) buffer; | 73 | iwr.u.data.pointer = (caddr_t) buffer; |
73 | iwr.u.data.length = IW_ESSID_MAX_SIZE; | 74 | iwr.u.data.length = IW_ESSID_MAX_SIZE; |
74 | iwr.u.data.flags = 0; | 75 | iwr.u.data.flags = 0; |
75 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){ | 76 | if ( 0 == ioctl( fd, SIOCGIWESSID, &iwr )){ |
77 | if (iwr.u.essid.length > IW_ESSID_MAX_SIZE) | ||
78 | iwr.u.essid.length = IW_ESSID_MAX_SIZE; | ||
76 | buffer[(unsigned int) iwr.u.essid.length] = '\0'; | 79 | buffer[(unsigned int) iwr.u.essid.length] = '\0'; |
77 | return (const char*) buffer; | 80 | return (const char*) buffer; |
78 | } | 81 | } |
79 | return QString::null; | 82 | return QString::null; |
80 | } | 83 | } |
81 | 84 | ||
82 | /** | 85 | /** |
83 | * @return QString the mode of interface | 86 | * @return QString the mode of interface |
84 | */ | 87 | */ |
85 | QString WExtensions::mode(){ | 88 | QString WExtensions::mode(){ |
86 | if(!hasWirelessExtensions) | 89 | if(!hasWirelessExtensions) |
87 | return QString(); | 90 | return QString(); |
88 | if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) ) | 91 | if ( 0 == ioctl( fd, SIOCGIWMODE, &iwr ) ) |
89 | return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed"); | 92 | return QString("%1").arg(iwr.u.mode == IW_MODE_ADHOC ? "Ad-Hoc" : "Managed"); |
90 | return QString(); | 93 | return QString(); |
91 | } | 94 | } |
92 | 95 | ||
93 | /** | 96 | /** |
94 | * Get the frequency that the interface is running at. | 97 | * Get the frequency that the interface is running at. |
95 | * @return int the frequency that the interfacae is running at. | 98 | * @return int the frequency that the interfacae is running at. |
96 | */ | 99 | */ |
97 | double WExtensions::frequency(){ | 100 | double WExtensions::frequency(){ |
98 | if(!hasWirelessExtensions) | 101 | if(!hasWirelessExtensions) |
99 | return 0; | 102 | return 0; |
100 | if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr )) | 103 | if ( 0 == ioctl( fd, SIOCGIWFREQ, &iwr )) |
101 | return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000); | 104 | return (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000); |
102 | return 0; | 105 | return 0; |
103 | } | 106 | } |
104 | 107 | ||
105 | /** | 108 | /** |
106 | * Get the channel that the interface is running at. | 109 | * Get the channel that the interface is running at. |
107 | * @return int the channel that the interfacae is running at. | 110 | * @return int the channel that the interfacae is running at. |
108 | */ | 111 | */ |
109 | int WExtensions::channel(){ | 112 | int WExtensions::channel(){ |
110 | if(!hasWirelessExtensions) | 113 | if(!hasWirelessExtensions) |
111 | return 0; | 114 | return 0; |
112 | if ( 0 != ioctl( fd, SIOCGIWFREQ, &iwr )) | 115 | if ( 0 != ioctl( fd, SIOCGIWFREQ, &iwr )) |
113 | return 0; | 116 | return 0; |
114 | 117 | ||
115 | // http://www.elanix.com/pdf/an137e.pdf | 118 | // http://www.elanix.com/pdf/an137e.pdf |
116 | 119 | ||
117 | double num = (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000); | 120 | double num = (double( iwr.u.freq.m ) * pow( 10, iwr.u.freq.e ) / 1000000000); |
118 | double left = 2.401; | 121 | double left = 2.401; |
119 | double right = 2.416; | 122 | double right = 2.416; |
120 | for(int channel = 1; channel<= 15; channel++){ | 123 | for(int channel = 1; channel<= 15; channel++){ |
121 | if( num >= left && num <= right ) | 124 | if( num >= left && num <= right ) |
122 | return channel; | 125 | return channel; |
123 | left += 0.005; | 126 | left += 0.005; |
124 | right += 0.005; | 127 | right += 0.005; |
125 | } | 128 | } |
126 | odebug << QString("Unknown frequency: %1, returning -1 for the channel.").arg(num).latin1() << oendl; | 129 | odebug << QString("Unknown frequency: %1, returning -1 for the channel.").arg(num).latin1() << oendl; |
127 | return -1; | 130 | return -1; |
128 | } | 131 | } |
129 | 132 | ||
130 | /*** | 133 | /*** |
131 | * Get the current rate that the card is transmiting at. | 134 | * Get the current rate that the card is transmiting at. |
132 | * @return double the rate, 0 if error. | 135 | * @return double the rate, 0 if error. |
133 | */ | 136 | */ |
134 | double WExtensions::rate(){ | 137 | double WExtensions::rate(){ |
135 | if(!hasWirelessExtensions) | 138 | if(!hasWirelessExtensions) |
136 | return 0; | 139 | return 0; |
137 | if(0 == ioctl(fd, SIOCGIWRATE, &iwr)){ | 140 | if(0 == ioctl(fd, SIOCGIWRATE, &iwr)){ |
138 | return ((double)iwr.u.bitrate.value)/1000000; | 141 | return ((double)iwr.u.bitrate.value)/1000000; |
139 | } | 142 | } |
140 | return 0; | 143 | return 0; |
141 | } | 144 | } |
142 | 145 | ||
143 | 146 | ||
144 | /** | 147 | /** |
145 | * @return QString the AccessPoint that the interface is connected to. | 148 | * @return QString the AccessPoint that the interface is connected to. |
146 | */ | 149 | */ |
147 | QString WExtensions::ap(){ | 150 | QString WExtensions::ap(){ |
148 | if(!hasWirelessExtensions) | 151 | if(!hasWirelessExtensions) |
149 | return QString(); | 152 | return QString(); |
150 | if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){ | 153 | if ( 0 == ioctl( fd, SIOCGIWAP, &iwr )){ |
151 | QString ap; | 154 | QString ap; |
152 | ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", | 155 | ap = ap.sprintf( "%.2X:%.2X:%.2X:%.2X:%.2X:%.2X", |
153 | iwr.u.ap_addr.sa_data[0]&0xff, | 156 | iwr.u.ap_addr.sa_data[0]&0xff, |
154 | iwr.u.ap_addr.sa_data[1]&0xff, | 157 | iwr.u.ap_addr.sa_data[1]&0xff, |
155 | iwr.u.ap_addr.sa_data[2]&0xff, | 158 | iwr.u.ap_addr.sa_data[2]&0xff, |
156 | iwr.u.ap_addr.sa_data[3]&0xff, | 159 | iwr.u.ap_addr.sa_data[3]&0xff, |
157 | iwr.u.ap_addr.sa_data[4]&0xff, | 160 | iwr.u.ap_addr.sa_data[4]&0xff, |
158 | iwr.u.ap_addr.sa_data[5]&0xff ); | 161 | iwr.u.ap_addr.sa_data[5]&0xff ); |
159 | return ap; | 162 | return ap; |
160 | } | 163 | } |
161 | else return QString(); | 164 | else return QString(); |
162 | } | 165 | } |
163 | 166 | ||
164 | /** | 167 | /** |
165 | * Get the stats for interfaces | 168 | * Get the stats for interfaces |
166 | * @param signal the signal strength of interface | 169 | * @param signal the signal strength of interface |
167 | * @param noise the noise level of the interface | 170 | * @param noise the noise level of the interface |
168 | * @param quality the quality level of the interface | 171 | * @param quality the quality level of the interface |
169 | * @return bool true if successful | 172 | * @return bool true if successful |
170 | */ | 173 | */ |
171 | bool WExtensions::stats(int &signal, int &noise, int &quality){ | 174 | bool WExtensions::stats(int &signal, int &noise, int &quality){ |
172 | // gather link quality from /proc/net/wireless | 175 | // gather link quality from /proc/net/wireless |
173 | if(!QFile::exists(PROCNETWIRELESS)) | 176 | if(!QFile::exists(PROCNETWIRELESS)) |
174 | return false; | 177 | return false; |
175 | 178 | ||
176 | char c; | 179 | char c; |
177 | QString status; | 180 | QString status; |
178 | QString name; | 181 | QString name; |
179 | 182 | ||
180 | QFile wfile( PROCNETWIRELESS ); | 183 | QFile wfile( PROCNETWIRELESS ); |
181 | if(!wfile.open( IO_ReadOnly )) | 184 | if(!wfile.open( IO_ReadOnly )) |
182 | return false; | 185 | return false; |
183 | 186 | ||
184 | QTextStream wstream( &wfile ); | 187 | QTextStream wstream( &wfile ); |
185 | wstream.readLine(); // skip the first two lines | 188 | wstream.readLine(); // skip the first two lines |
186 | wstream.readLine(); // because they only contain headers | 189 | wstream.readLine(); // because they only contain headers |
187 | while(!wstream.atEnd()){ | 190 | while(!wstream.atEnd()){ |
188 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; | 191 | wstream >> name >> status >> quality >> c >> signal >> c >> noise; |
189 | if(name == QString("%1:").arg(interface)){ | 192 | if(name == QString("%1:").arg(interface)){ |
190 | if ( quality > 92 ) | 193 | if ( quality > 92 ) |
191 | odebug << "WIFIAPPLET: D'oh! Quality " << quality << " > estimated max!\n" << oendl; | 194 | odebug << "WIFIAPPLET: D'oh! Quality " << quality << " > estimated max!\n" << oendl; |
192 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) | 195 | if ( ( signal > IW_UPPER ) || ( signal < IW_LOWER ) ) |
193 | odebug << "WIFIAPPLET: Doh! Strength " << signal << " > estimated max!\n" << oendl; | 196 | odebug << "WIFIAPPLET: Doh! Strength " << signal << " > estimated max!\n" << oendl; |
194 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) | 197 | if ( ( noise > IW_UPPER ) || ( noise < IW_LOWER ) ) |
195 | odebug << "WIFIAPPLET: Doh! Noise " << noise << " > estimated max!\n" << oendl; | 198 | odebug << "WIFIAPPLET: Doh! Noise " << noise << " > estimated max!\n" << oendl; |
196 | //odebug << QString("q:%1, s:%2, n:%3").arg(quality).arg(signal).arg(noise).latin1() << oendl; | 199 | //odebug << QString("q:%1, s:%2, n:%3").arg(quality).arg(signal).arg(noise).latin1() << oendl; |
197 | signal = ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; | 200 | signal = ( ( signal-IW_LOWER ) * 100 ) / IW_UPPER; |
198 | noise = ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; | 201 | noise = ( ( noise-IW_LOWER ) * 100 ) / IW_UPPER; |
199 | quality = ( quality*100 ) / 92; | 202 | quality = ( quality*100 ) / 92; |
200 | return true; | 203 | return true; |
201 | } | 204 | } |
202 | } | 205 | } |
203 | 206 | ||
204 | odebug << "WExtensions::statsCard no longer present." << oendl; | 207 | odebug << "WExtensions::statsCard no longer present." << oendl; |
205 | quality = -1; | 208 | quality = -1; |
206 | signal = IW_LOWER; | 209 | signal = IW_LOWER; |
207 | noise = IW_LOWER; | 210 | noise = IW_LOWER; |
208 | return false; | 211 | return false; |
209 | } | 212 | } |
210 | 213 | ||
211 | // wextensions.cpp | 214 | // wextensions.cpp |
diff --git a/noncore/settings/networksettings/wlan/wlan.pro b/noncore/settings/networksettings/wlan/wlan.pro index eb9dd4f..3a064d3 100644 --- a/noncore/settings/networksettings/wlan/wlan.pro +++ b/noncore/settings/networksettings/wlan/wlan.pro | |||
@@ -1,32 +1,32 @@ | |||
1 | TEMPLATE = lib | 1 | TEMPLATE = lib |
2 | CONFIG += qt plugin warn_on | 2 | CONFIG += qt plugin warn_on |
3 | DESTDIR = $(OPIEDIR)/plugins/networksettings | 3 | DESTDIR = $(OPIEDIR)/plugins/networksettings |
4 | HEADERS = infoimp.h wlanmodule.h wextensions.h keyedit.h | 4 | HEADERS = infoimp.h wlanmodule.h wextensions.h keyedit.h |
5 | SOURCES = infoimp.cpp wlanmodule.cpp wextensions.cpp keyedit.cpp | 5 | SOURCES = infoimp.cpp wlanmodule.cpp wextensions.cpp keyedit.cpp |
6 | INCLUDEPATH+= $(OPIEDIR)/include ../ ../interfaces/ | 6 | INCLUDEPATH+= $(OPIEDIR)/include ../ ../interfaces/ |
7 | DEPENDPATH+= $(OPIEDIR)/include | 7 | DEPENDPATH+= $(OPIEDIR)/include |
8 | LIBS += -lqpe -L../interfaces/ -linterfaces -lopiecore2 -lopienet2 | 8 | LIBS += -lqpe -L../interfaces/ -linterfaces -lopiecore2 -lopienet2 |
9 | INTERFACES= wlan.ui info.ui | 9 | INTERFACES= wlan.ui info.ui |
10 | TARGET = wlan | 10 | TARGET = wlan |
11 | VERSION = 1.0.1 | 11 | VERSION = 1.0.2 |
12 | 12 | ||
13 | #CONFIG += wirelessopts | 13 | #CONFIG += wirelessopts |
14 | 14 | ||
15 | wirelessopts { | 15 | wirelessopts { |
16 | HEADERS+= wlanimp.h | 16 | HEADERS+= wlanimp.h |
17 | SOURCES+= wlanimp.cpp | 17 | SOURCES+= wlanimp.cpp |
18 | } | 18 | } |
19 | 19 | ||
20 | ! wirelessopts { | 20 | ! wirelessopts { |
21 | HEADERS+= wlanimp2.h | 21 | HEADERS+= wlanimp2.h |
22 | SOURCES += wlanimp2.cpp | 22 | SOURCES += wlanimp2.cpp |
23 | } | 23 | } |
24 | 24 | ||
25 | include( $(OPIEDIR)/include.pro ) | 25 | include( $(OPIEDIR)/include.pro ) |
26 | 26 | ||
27 | !isEmpty( LIBPCAP_INC_DIR ) { | 27 | !isEmpty( LIBPCAP_INC_DIR ) { |
28 | INCLUDEPATH = $$LIBPCAP_INC_DIR $$INCLUDEPATH | 28 | INCLUDEPATH = $$LIBPCAP_INC_DIR $$INCLUDEPATH |
29 | } | 29 | } |
30 | !isEmpty( LIBPCAP_LIB_DIR ) { | 30 | !isEmpty( LIBPCAP_LIB_DIR ) { |
31 | LIBS = -L$$LIBPCAP_LIB_DIR $$LIBS | 31 | LIBS = -L$$LIBPCAP_LIB_DIR $$LIBS |
32 | } | 32 | } |
diff --git a/noncore/settings/networksettings/wlan/wlanimp2.cpp b/noncore/settings/networksettings/wlan/wlanimp2.cpp index 11dfe74..2fd97c3 100644 --- a/noncore/settings/networksettings/wlan/wlanimp2.cpp +++ b/noncore/settings/networksettings/wlan/wlanimp2.cpp | |||
@@ -1,494 +1,627 @@ | |||
1 | #include "wlanimp2.h" | 1 | #include "wlanimp2.h" |
2 | #include "keyedit.h" | 2 | #include "keyedit.h" |
3 | #include "interfacesetupimp.h" | 3 | #include "interfacesetupimp.h" |
4 | #include "../interfaces/interface.h" | 4 | #include "../interfaces/interface.h" |
5 | 5 | ||
6 | #include <assert.h> | 6 | #include <assert.h> |
7 | #include <errno.h> | 7 | #include <errno.h> |
8 | #include <string.h> | 8 | #include <string.h> |
9 | 9 | ||
10 | /* OPIE */ | 10 | /* OPIE */ |
11 | #include <opie2/odebug.h> | 11 | #include <opie2/odebug.h> |
12 | #include <opie2/oprocess.h> | 12 | #include <opie2/oprocess.h> |
13 | #include <opie2/onetwork.h> | 13 | #include <opie2/onetwork.h> |
14 | #include <opie2/opcap.h> | 14 | #include <opie2/opcap.h> |
15 | #include <qpe/resource.h> | 15 | #include <qpe/resource.h> |
16 | using namespace Opie::Core; | 16 | using namespace Opie::Core; |
17 | using namespace Opie::Net; | 17 | using namespace Opie::Net; |
18 | 18 | ||
19 | /* QT */ | 19 | /* QT */ |
20 | #include <qapplication.h> | 20 | #include <qapplication.h> |
21 | #include <qfile.h> | 21 | #include <qfile.h> |
22 | #include <qdir.h> | 22 | #include <qdir.h> |
23 | #include <qdialog.h> | 23 | #include <qdialog.h> |
24 | #include <qtextstream.h> | 24 | #include <qtextstream.h> |
25 | #include <qmessagebox.h> | 25 | #include <qmessagebox.h> |
26 | #include <qlineedit.h> | 26 | #include <qlineedit.h> |
27 | #include <qlabel.h> | 27 | #include <qlabel.h> |
28 | #include <qspinbox.h> | 28 | #include <qspinbox.h> |
29 | #include <qradiobutton.h> | 29 | #include <qradiobutton.h> |
30 | #include <qpushbutton.h> | 30 | #include <qpushbutton.h> |
31 | #include <qcheckbox.h> | 31 | #include <qcheckbox.h> |
32 | #include <qtabwidget.h> | 32 | #include <qtabwidget.h> |
33 | #include <qcombobox.h> | 33 | #include <qcombobox.h> |
34 | #include <qlistview.h> | 34 | #include <qlistview.h> |
35 | #include <qvbox.h> | 35 | #include <qvbox.h> |
36 | #include <qprogressbar.h> | 36 | #include <qprogressbar.h> |
37 | 37 | ||
38 | /* STD */ | 38 | /* STD */ |
39 | #include <assert.h> | 39 | #include <assert.h> |
40 | #include <errno.h> | 40 | #include <errno.h> |
41 | #include <string.h> | 41 | #include <string.h> |
42 | 42 | ||
43 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" | 43 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" |
44 | #define PREUP "/etc/network/if-pre-up.d/wireless-tools" | 44 | #define PREUP "/etc/network/if-pre-up.d/wireless-tools" |
45 | 45 | ||
46 | /** | 46 | /** |
47 | * Constructor, read in the wireless.opts file for parsing later. | 47 | * Constructor, read in the wireless.opts file for parsing later. |
48 | */ | 48 | */ |
49 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") { | 49 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), interface(i), currentProfile("*") { |
50 | interfaces = new Interfaces(); | 50 | interfaces = new Interfaces(); |
51 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces); | 51 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces); |
52 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); | 52 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); |
53 | 53 | ||
54 | // Check sanity - the existance of the wireless-tools if-pre-up script | 54 | // Check sanity - the existance of the wireless-tools if-pre-up script |
55 | QFile file(QString(PREUP)); | 55 | QFile file(QString(PREUP)); |
56 | if (file.exists()) { | 56 | if (file.exists()) { |
57 | owarn << QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools") << oendl; | 57 | owarn << QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools") << oendl; |
58 | } | 58 | } |
59 | 59 | ||
60 | connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) ); | 60 | connect( rescanButton, SIGNAL( clicked() ), this, SLOT( rescanNeighbourhood() ) ); |
61 | connect( netView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( selectNetwork(QListViewItem*) ) ); | 61 | connect( netView, SIGNAL( clicked(QListViewItem*) ), this, SLOT( selectNetwork(QListViewItem*) ) ); |
62 | netView->setColumnAlignment( col_chn, AlignCenter ); | 62 | netView->setColumnAlignment( col_chn, AlignCenter ); |
63 | netView->setItemMargin( 3 ); | 63 | netView->setItemMargin( 3 ); |
64 | netView->setAllColumnsShowFocus( true ); | 64 | netView->setAllColumnsShowFocus( true ); |
65 | 65 | ||
66 | } | 66 | } |
67 | 67 | ||
68 | WLANImp::~WLANImp() { | 68 | WLANImp::~WLANImp() { |
69 | //FIXME: delete interfaces; | 69 | //FIXME: delete interfaces; |
70 | } | 70 | } |
71 | 71 | ||
72 | /** | 72 | /** |
73 | * Change the profile for both wireless settings and network settings. | 73 | * Change the profile for both wireless settings and network settings. |
74 | */ | 74 | */ |
75 | void WLANImp::setProfile(const QString &profile){ | 75 | void WLANImp::setProfile(const QString &profile){ |
76 | interfaceSetup->setProfile(profile); | 76 | interfaceSetup->setProfile(profile); |
77 | parseOpts(); | 77 | parseOpts(); |
78 | } | 78 | } |
79 | 79 | ||
80 | void WLANImp::parseOpts() { | 80 | void WLANImp::parseOpts() { |
81 | bool error; | 81 | bool error; |
82 | QString opt; | 82 | QString opt,key; |
83 | 83 | ||
84 | if (! interfaces->isInterfaceSet()) | 84 | if (! interfaces->isInterfaceSet()) |
85 | return; | 85 | return; |
86 | 86 | ||
87 | |||
88 | opt = interfaces->getInterfaceOption("wireless_essid", error); | 87 | opt = interfaces->getInterfaceOption("wireless_essid", error); |
89 | if(opt == "any" || opt == "off" || opt.isNull()){ | 88 | if(opt == "any" || opt == "off" || opt.isNull()){ |
90 | essid->setEditText("any"); | 89 | essid->setEditText("any"); |
91 | } else { | 90 | } else { |
92 | essid->setEditText(opt); | 91 | essid->setEditText(opt); |
93 | } | 92 | } |
94 | 93 | ||
95 | opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace(); | 94 | opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace(); |
96 | 95 | ||
97 | for ( int i = 0; i < mode->count(); i++) | 96 | for ( int i = 0; i < mode->count(); i++) |
98 | if ( mode->text( i ) == opt ) mode->setCurrentItem( i ); | 97 | if ( mode->text( i ) == opt ) mode->setCurrentItem( i ); |
99 | 98 | ||
100 | opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace(); | 99 | opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace(); |
101 | if (! opt.isNull()) { | 100 | if (! opt.isNull()) { |
102 | specifyAp->setChecked(true); | 101 | specifyAp->setChecked(true); |
103 | macEdit->setText(opt); | 102 | macEdit->setText(opt); |
104 | } | 103 | } |
105 | 104 | ||
106 | opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace(); | 105 | opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace(); |
107 | if (! opt.isNull()) { | 106 | if (! opt.isNull()) { |
108 | specifyChan->setChecked(true); | 107 | specifyChan->setChecked(true); |
109 | networkChannel->setValue(opt.toInt()); | 108 | networkChannel->setValue(opt.toInt()); |
110 | } | 109 | } |
111 | 110 | ||
112 | opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace(); | 111 | opt = interfaces->getInterfaceOption("wireless_type", error).simplifyWhiteSpace(); |
113 | if (opt.isNull()) | 112 | |
113 | if ( opt == "wlan-ng") { | ||
114 | |||
115 | //FIXME:Handle wlan_ng_priv_genstr | ||
116 | |||
117 | // get default key_id | ||
118 | opt = interfaces->getInterfaceOption("wlan_ng_default_key_id", error).simplifyWhiteSpace(); | ||
119 | |||
120 | if (opt == "0") | ||
121 | keyRadio0->setChecked(true); | ||
122 | if (opt == "1") | ||
123 | keyRadio1->setChecked(true); | ||
124 | if (opt == "2") | ||
125 | keyRadio2->setChecked(true); | ||
126 | if (opt == "3") | ||
127 | keyRadio3->setChecked(true); | ||
128 | |||
129 | // get key0 | ||
130 | key = interfaces->getInterfaceOption("wlan_ng_key0", error).simplifyWhiteSpace(); | ||
131 | key.replace(QString(":"),QString("")); | ||
132 | keyLineEdit0->setText(key); | ||
133 | |||
134 | // get key1 | ||
135 | key = interfaces->getInterfaceOption("wlan_ng_key1", error).simplifyWhiteSpace(); | ||
136 | key.replace(QString(":"),QString("")); | ||
137 | keyLineEdit1->setText(key); | ||
138 | |||
139 | // get key2 | ||
140 | key = interfaces->getInterfaceOption("wlan_ng_key2", error).simplifyWhiteSpace(); | ||
141 | key.replace(QString(":"),QString("")); | ||
142 | keyLineEdit2->setText(key); | ||
143 | |||
144 | // get key3 | ||
145 | key = interfaces->getInterfaceOption("wlan_ng_key3", error).simplifyWhiteSpace(); | ||
146 | key.replace(QString(":"),QString("")); | ||
147 | keyLineEdit3->setText(key); | ||
148 | |||
114 | opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace(); | 149 | opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace(); |
115 | parseKeyStr(opt); | 150 | |
151 | // encryption on? | ||
152 | if(opt == "on"){ | ||
153 | wepEnabled->setChecked(true); | ||
154 | } else { | ||
155 | wepEnabled->setChecked(false); | ||
156 | } | ||
157 | |||
158 | opt = interfaces->getInterfaceOption("wireless_keymode", error).simplifyWhiteSpace(); | ||
159 | |||
160 | if(opt == "restricted"){ | ||
161 | // restricted mode, only accept encrypted packets | ||
162 | rejectNonEnc->setChecked(true); | ||
163 | } | ||
164 | } | ||
165 | else { | ||
166 | opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace(); | ||
167 | |||
168 | parseKeyStr(opt); | ||
169 | } | ||
116 | } | 170 | } |
117 | 171 | ||
118 | void WLANImp::parseKeyStr(QString keystr) { | 172 | void WLANImp::parseKeyStr(QString keystr) { |
119 | int index = 1; | 173 | int index = 1; |
120 | QString key; | 174 | QString key; |
121 | QStringList keys = QStringList::split(QRegExp("\\s+"), keystr); | 175 | QStringList keys = QStringList::split(QRegExp("\\s+"), keystr); |
122 | int enc = -1; // encryption state | 176 | int enc = -1; // encryption state |
123 | 177 | ||
124 | for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { | 178 | for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { |
125 | if ((*it).left(3) == "off") { | 179 | if ((*it).left(3) == "off") { |
126 | // encryption disabled | 180 | // encryption disabled |
127 | enc = 0; | 181 | enc = 0; |
128 | } else if ((*it).left(2) == "on") { | 182 | } else if ((*it).left(2) == "on") { |
129 | // encryption enabled | 183 | // encryption enabled |
130 | enc = 1; | 184 | enc = 1; |
131 | } else if ((*it).left(4) == "open") { | 185 | } else if ((*it).left(4) == "open") { |
132 | // open mode, accept non encrypted packets | 186 | // open mode, accept non encrypted packets |
133 | acceptNonEnc->setChecked(true); | 187 | acceptNonEnc->setChecked(true); |
134 | } else if ((*it).left(10) == "restricted") { | 188 | } else if ((*it).left(10) == "restricted") { |
135 | // restricted mode, only accept encrypted packets | 189 | // restricted mode, only accept encrypted packets |
136 | rejectNonEnc->setChecked(true); | 190 | rejectNonEnc->setChecked(true); |
137 | } else if ((*it).left(3) == "key") { | 191 | } else if ((*it).left(3) == "key") { |
138 | // new set of options | 192 | // new set of options |
139 | } else if ((*it).left(1) == "[") { | 193 | } else if ((*it).left(1) == "[") { |
140 | index = (*it).mid(1, 1).toInt(); | 194 | index = (*it).mid(1, 1).toInt(); |
141 | // switch current key to index | 195 | // switch current key to index |
142 | switch (index) { | 196 | switch (index) { |
143 | case 1: | 197 | case 1: |
144 | keyRadio0->setChecked(true); | 198 | keyRadio0->setChecked(true); |
145 | break; | 199 | break; |
146 | case 2: | 200 | case 2: |
147 | keyRadio1->setChecked(true); | 201 | keyRadio1->setChecked(true); |
148 | break; | 202 | break; |
149 | case 3: | 203 | case 3: |
150 | keyRadio2->setChecked(true); | 204 | keyRadio2->setChecked(true); |
151 | break; | 205 | break; |
152 | case 4: | 206 | case 4: |
153 | keyRadio3->setChecked(true); | 207 | keyRadio3->setChecked(true); |
154 | break; | 208 | break; |
155 | } | 209 | } |
156 | } else { | 210 | } else { |
157 | // key | 211 | // key |
158 | key = (*it); | 212 | key = (*it); |
159 | } | 213 | } |
160 | if (! key.isNull()) { | 214 | if (! key.isNull()) { |
161 | if (enc == -1) | 215 | if (enc == -1) |
162 | enc = 1; | 216 | enc = 1; |
163 | QStringList::Iterator next = ++it; | 217 | QStringList::Iterator next = ++it; |
164 | if (it == keys.end()) { | 218 | if (it == keys.end()) { |
165 | break; | 219 | break; |
166 | } | 220 | } |
167 | if ((*(next)).left(1) == "[") { | 221 | if ((*(next)).left(1) == "[") { |
168 | // set key at index | 222 | // set key at index |
169 | index = (*(next)).mid(1, 1).toInt(); | 223 | index = (*(next)).mid(1, 1).toInt(); |
170 | } else { | 224 | } else { |
171 | index = 1; | 225 | index = 1; |
172 | } | 226 | } |
173 | switch (index) { | 227 | switch (index) { |
174 | case 1: | 228 | case 1: |
175 | keyLineEdit0->setText(key); | 229 | keyLineEdit0->setText(key); |
176 | break; | 230 | break; |
177 | case 2: | 231 | case 2: |
178 | keyLineEdit1->setText(key); | 232 | keyLineEdit1->setText(key); |
179 | break; | 233 | break; |
180 | case 3: | 234 | case 3: |
181 | keyLineEdit2->setText(key); | 235 | keyLineEdit2->setText(key); |
182 | break; | 236 | break; |
183 | case 4: | 237 | case 4: |
184 | keyLineEdit3->setText(key); | 238 | keyLineEdit3->setText(key); |
185 | break; | 239 | break; |
186 | } | 240 | } |
187 | key = QString::null; | 241 | key = QString::null; |
188 | } | 242 | } |
189 | } | 243 | } |
190 | if (enc == 1) { | 244 | if (enc == 1) { |
191 | wepEnabled->setChecked(true); | 245 | wepEnabled->setChecked(true); |
192 | } else { | 246 | } else { |
193 | wepEnabled->setChecked(false); | 247 | wepEnabled->setChecked(false); |
194 | } | 248 | } |
195 | } | 249 | } |
196 | 250 | ||
197 | /** | 251 | /** |
198 | * Check to see if the current config is valid | 252 | * Check to see if the current config is valid |
199 | * Save interfaces | 253 | * Save interfaces |
200 | */ | 254 | */ |
201 | void WLANImp::accept() { | 255 | void WLANImp::accept() { |
202 | if (wepEnabled->isChecked()) { | 256 | if (wepEnabled->isChecked()) { |
203 | if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) || | 257 | if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) || |
204 | (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) || | 258 | (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) || |
205 | (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) || | 259 | (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) || |
206 | (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) { | 260 | (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) { |
207 | QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok); | 261 | QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok); |
208 | return; | 262 | return; |
209 | } | 263 | } |
210 | } | 264 | } |
211 | 265 | ||
212 | if (essid->currentText().isEmpty()) { | 266 | if (essid->currentText().isEmpty()) { |
213 | QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok); | 267 | QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok); |
214 | return; | 268 | return; |
215 | } | 269 | } |
216 | 270 | ||
217 | if (specifyAp->isChecked() && macEdit->text().isEmpty()) { | 271 | if (specifyAp->isChecked() && macEdit->text().isEmpty()) { |
218 | QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok); | 272 | QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok); |
219 | return; | 273 | return; |
220 | } | 274 | } |
221 | 275 | ||
222 | // Try to save the interfaces settings. | 276 | // Try to save the interfaces settings. |
223 | writeOpts(); | 277 | writeOpts(); |
224 | 278 | ||
225 | // Close out the dialog | 279 | // Close out the dialog |
226 | // FIXME: QDialog::accept(); | 280 | // FIXME: QDialog::accept(); |
227 | } | 281 | } |
228 | 282 | ||
283 | QString WLANImp::formatKey(QString input) | ||
284 | { | ||
285 | int len,r=0; | ||
286 | |||
287 | len = input.length(); | ||
288 | |||
289 | if (!len) | ||
290 | return input; | ||
291 | |||
292 | for(int i=1;i<len/2;i++) | ||
293 | { | ||
294 | input.insert(r+i*2,QString(":")); | ||
295 | r++; | ||
296 | } | ||
297 | |||
298 | return input; | ||
299 | } | ||
300 | |||
229 | void WLANImp::writeOpts() { | 301 | void WLANImp::writeOpts() { |
230 | // eh can't really do anything about it other then return. :-D | 302 | QString para, devicetype; |
231 | if(!interfaces->isInterfaceSet()){ | ||
232 | QMessageBox::warning(0,"Inface not set","should not happen!!!"); | ||
233 | return; | ||
234 | } | ||
235 | bool error = false; | ||
236 | 303 | ||
237 | odebug << "setting wlan interface " << interfaces->getInterfaceName( error ).latin1() << "" << oendl; | 304 | // eh can't really do anything about it other then return. :-D |
305 | if(!interfaces->isInterfaceSet()){ | ||
306 | QMessageBox::warning(0,"Inface not set","should not happen!!!"); | ||
307 | return; | ||
308 | } | ||
309 | bool error = false; | ||
238 | 310 | ||
239 | if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!"); | 311 | odebug << "setting wlan interface " << interfaces->getInterfaceName( error ).latin1() << "" << oendl; |
312 | |||
313 | if (error) QMessageBox::warning(0,"Inface not set","should not happen!!!"); | ||
240 | 314 | ||
241 | interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText()); | 315 | interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText()); |
242 | interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText()); | 316 | interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText()); |
243 | 317 | ||
244 | if (specifyAp->isChecked()) { | 318 | if (specifyAp->isChecked()) { |
245 | interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text()); | 319 | interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text()); |
246 | } else { | 320 | } else { |
247 | interfaces->removeInterfaceOption(QString("wireless_ap")); | 321 | interfaces->removeInterfaceOption(QString("wireless_ap")); |
248 | } | 322 | } |
249 | 323 | ||
250 | if (specifyChan->isChecked()) { | 324 | if (specifyChan->isChecked()) { |
251 | interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text()); | 325 | interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text()); |
252 | } else { | 326 | } else { |
253 | interfaces->removeInterfaceOption(QString("wireless_channel")); | 327 | interfaces->removeInterfaceOption(QString("wireless_channel")); |
254 | } | 328 | } |
255 | 329 | ||
256 | if (wepEnabled->isChecked()) { | 330 | devicetype = interfaces->getInterfaceOption("wireless_type", error).simplifyWhiteSpace(); |
257 | QStringList keyList; | 331 | |
258 | 332 | if ( devicetype == "wlan-ng") { | |
259 | if (! keyLineEdit0->text().isNull()) { | 333 | |
260 | keyList += keyLineEdit0->text(); | 334 | // wlan-ng style |
261 | keyList += "[1]"; | 335 | interfaces->removeInterfaceOption(QString("wireless_key")); |
262 | } //else | 336 | |
263 | if (! keyLineEdit1->text().isNull()) { | 337 | if (wepEnabled->isChecked()) { |
264 | keyList += keyLineEdit1->text(); | 338 | |
265 | keyList += "[2]"; | 339 | interfaces->setInterfaceOption(QString("wireless_enc"),"on"); |
266 | } //else | 340 | |
267 | if (! keyLineEdit2->text().isNull()) { | 341 | if (! keyLineEdit0->text().isNull()) { |
268 | keyList += keyLineEdit2->text(); | 342 | interfaces->setInterfaceOption(QString("wlan_ng_key0"), formatKey(keyLineEdit0->text())); |
269 | keyList += "[3]"; | 343 | } else |
270 | } //else | 344 | interfaces->removeInterfaceOption(QString("wlan_ng_key0")); |
271 | if (! keyLineEdit3->text().isNull()) { | 345 | if (! keyLineEdit1->text().isNull()) { |
272 | keyList += keyLineEdit3->text(); | 346 | interfaces->setInterfaceOption(QString("wlan_ng_key1"), formatKey(keyLineEdit1->text())); |
273 | keyList += "[4]"; | 347 | } else |
274 | } | 348 | interfaces->removeInterfaceOption(QString("wlan_ng_key1")); |
275 | if (acceptNonEnc->isChecked()) { | 349 | if (! keyLineEdit2->text().isNull()) { |
276 | keyList += "open"; | 350 | interfaces->setInterfaceOption(QString("wlan_ng_key2"), formatKey(keyLineEdit2->text())); |
351 | } else | ||
352 | interfaces->removeInterfaceOption(QString("wlan_ng_key2")); | ||
353 | if (! keyLineEdit3->text().isNull()) { | ||
354 | interfaces->setInterfaceOption(QString("wlan_ng_key3"), formatKey(keyLineEdit3->text())); | ||
355 | } else | ||
356 | interfaces->removeInterfaceOption(QString("wlan_ng_key3")); | ||
357 | |||
358 | if (acceptNonEnc->isChecked()) | ||
359 | interfaces->removeInterfaceOption(QString("wireless_keymode")); | ||
360 | else | ||
361 | interfaces->setInterfaceOption(QString("wireless_keymode"),"restricted"); | ||
362 | |||
363 | para = ""; | ||
364 | if (keyRadio0->isChecked()) { | ||
365 | para = "0"; | ||
366 | } else if (keyRadio1->isChecked()) { | ||
367 | para = "1"; | ||
368 | } else if (keyRadio2->isChecked()) { | ||
369 | para = "2"; | ||
370 | } else if (keyRadio3->isChecked()) { | ||
371 | para = "3"; | ||
372 | } | ||
373 | |||
374 | interfaces->setInterfaceOption(QString("wlan_ng_default_key_id"), para); | ||
375 | |||
277 | } else { | 376 | } else { |
278 | keyList += "restricted"; | 377 | // No wep, remove all previous keys |
378 | interfaces->removeInterfaceOption(QString("wireless_enc")); | ||
379 | interfaces->removeInterfaceOption(QString("wlan_ng_default_key_id")); | ||
380 | interfaces->removeInterfaceOption(QString("wlan_ng_key0")); | ||
381 | interfaces->removeInterfaceOption(QString("wlan_ng_key1")); | ||
382 | interfaces->removeInterfaceOption(QString("wlan_ng_key2")); | ||
383 | interfaces->removeInterfaceOption(QString("wlan_ng_key3")); | ||
279 | } | 384 | } |
280 | 385 | ||
281 | keyList += "key"; | ||
282 | if (keyRadio0->isChecked()) { | ||
283 | keyList += "[1]"; | ||
284 | } else if (keyRadio1->isChecked()) { | ||
285 | keyList += "[2]"; | ||
286 | } else if (keyRadio2->isChecked()) { | ||
287 | keyList += "[3]"; | ||
288 | } else if (keyRadio3->isChecked()) { | ||
289 | keyList += "[4]"; | ||
290 | } | ||
291 | interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" "))); | ||
292 | } else { | 386 | } else { |
293 | interfaces->removeInterfaceOption(QString("wireless_key")); | 387 | // This is the old style |
388 | if (wepEnabled->isChecked()) { | ||
389 | QStringList keyList; | ||
390 | |||
391 | if (! keyLineEdit0->text().isNull()) { | ||
392 | keyList += keyLineEdit0->text(); | ||
393 | keyList += "[1]"; | ||
394 | } //else | ||
395 | if (! keyLineEdit1->text().isNull()) { | ||
396 | keyList += keyLineEdit1->text(); | ||
397 | keyList += "[2]"; | ||
398 | } //else | ||
399 | if (! keyLineEdit2->text().isNull()) { | ||
400 | keyList += keyLineEdit2->text(); | ||
401 | keyList += "[3]"; | ||
402 | } //else | ||
403 | if (! keyLineEdit3->text().isNull()) { | ||
404 | keyList += keyLineEdit3->text(); | ||
405 | keyList += "[4]"; | ||
406 | } | ||
407 | if (acceptNonEnc->isChecked()) { | ||
408 | keyList += "open"; | ||
409 | } else { | ||
410 | keyList += "restricted"; | ||
411 | } | ||
412 | |||
413 | keyList += "key"; | ||
414 | if (keyRadio0->isChecked()) { | ||
415 | keyList += "[1]"; | ||
416 | } else if (keyRadio1->isChecked()) { | ||
417 | keyList += "[2]"; | ||
418 | } else if (keyRadio2->isChecked()) { | ||
419 | keyList += "[3]"; | ||
420 | } else if (keyRadio3->isChecked()) { | ||
421 | keyList += "[4]"; | ||
422 | } | ||
423 | interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" "))); | ||
424 | } else { | ||
425 | interfaces->removeInterfaceOption(QString("wireless_key")); | ||
426 | } | ||
427 | interfaces->removeInterfaceOption(QString("wireless_enc")); | ||
294 | } | 428 | } |
295 | interfaces->removeInterfaceOption(QString("wireless_enc")); | ||
296 | 429 | ||
297 | if(!interfaceSetup->saveChanges()) | 430 | if(!interfaceSetup->saveChanges()) |
298 | return; | 431 | return; |
299 | 432 | ||
300 | QDialog::accept(); | 433 | QDialog::accept(); |
301 | } | 434 | } |
302 | 435 | ||
303 | /* | 436 | /* |
304 | * Scan for possible wireless networks around... | 437 | * Scan for possible wireless networks around... |
305 | * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org> | 438 | * ... powered by Wellenreiter II technology (C) Michael 'Mickey' Lauer <mickeyl@handhelds.org> |
306 | */ | 439 | */ |
307 | 440 | ||
308 | void WLANImp::rescanNeighbourhood() | 441 | void WLANImp::rescanNeighbourhood() |
309 | { | 442 | { |
310 | QString name = interface->getInterfaceName(); | 443 | QString name = interface->getInterfaceName(); |
311 | odebug << "rescanNeighbourhood via '" << name << "'" << oendl; | 444 | odebug << "rescanNeighbourhood via '" << name << "'" << oendl; |
312 | 445 | ||
313 | OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( ONetwork::instance()->interface( name ) ); | 446 | OWirelessNetworkInterface* wiface = static_cast<OWirelessNetworkInterface*>( ONetwork::instance()->interface( name ) ); |
314 | assert( wiface ); | 447 | assert( wiface ); |
315 | 448 | ||
316 | // try to guess device type | 449 | // try to guess device type |
317 | QString devicetype; | 450 | QString devicetype; |
318 | QFile m( "/proc/modules" ); | 451 | QFile m( "/proc/modules" ); |
319 | if ( m.open( IO_ReadOnly ) ) | 452 | if ( m.open( IO_ReadOnly ) ) |
320 | { | 453 | { |
321 | QString line; | 454 | QString line; |
322 | QTextStream modules( &m ); | 455 | QTextStream modules( &m ); |
323 | while( !modules.atEnd() && !devicetype ) | 456 | while( !modules.atEnd() && !devicetype ) |
324 | { | 457 | { |
325 | modules >> line; | 458 | modules >> line; |
326 | if ( line.contains( "cisco" ) ) devicetype = "cisco"; | 459 | if ( line.contains( "cisco" ) ) devicetype = "cisco"; |
327 | else if ( line.contains( "hostap" ) ) devicetype = "hostap"; | 460 | else if ( line.contains( "hostap" ) ) devicetype = "hostap"; |
328 | else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */ | 461 | else if ( line.contains( "prism" ) ) devicetype = "wlan-ng"; /* puke */ |
329 | else if ( line.contains( "orinoco" ) ) devicetype = "orinoco"; | 462 | else if ( line.contains( "orinoco" ) ) devicetype = "orinoco"; |
330 | } | 463 | } |
331 | } | 464 | } |
332 | if ( devicetype.isEmpty() ) | 465 | if ( devicetype.isEmpty() ) |
333 | { | 466 | { |
334 | owarn << "rescanNeighbourhood(): couldn't guess device type :(" << oendl; | 467 | owarn << "rescanNeighbourhood(): couldn't guess device type :(" << oendl; |
335 | return; | 468 | return; |
336 | } | 469 | } |
337 | else | 470 | else |
338 | { | 471 | { |
339 | odebug << "rescanNeighbourhood(): device type seems to be '" << devicetype << "'" << oendl; | 472 | odebug << "rescanNeighbourhood(): device type seems to be '" << devicetype << "'" << oendl; |
340 | } | 473 | } |
341 | 474 | ||
342 | // configure interface to receive 802.11 management frames | 475 | // configure interface to receive 802.11 management frames |
343 | 476 | ||
344 | wiface->setUp( true ); | 477 | wiface->setUp( true ); |
345 | wiface->setPromiscuousMode( true ); | 478 | wiface->setPromiscuousMode( true ); |
346 | 479 | ||
347 | if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) ); | 480 | if ( devicetype == "cisco" ) wiface->setMonitoring( new OCiscoMonitoringInterface( wiface, false ) ); |
348 | else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) ); | 481 | else if ( devicetype == "hostap" ) wiface->setMonitoring( new OHostAPMonitoringInterface( wiface, false ) ); |
349 | else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) ); | 482 | else if ( devicetype == "wlan-ng" ) wiface->setMonitoring( new OWlanNGMonitoringInterface( wiface, false ) ); |
350 | else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) ); | 483 | else if ( devicetype == "orinoco" ) wiface->setMonitoring( new OOrinocoMonitoringInterface( wiface, false ) ); |
351 | else | 484 | else |
352 | { | 485 | { |
353 | odebug << "rescanNeighbourhood(): unsupported device type for monitoring :(" << oendl; | 486 | odebug << "rescanNeighbourhood(): unsupported device type for monitoring :(" << oendl; |
354 | return; | 487 | return; |
355 | } | 488 | } |
356 | 489 | ||
357 | wiface->setMode( "monitor" ); | 490 | wiface->setMode( "monitor" ); |
358 | if ( wiface->mode() != "monitor" ) | 491 | if ( wiface->mode() != "monitor" ) |
359 | { | 492 | { |
360 | owarn << "rescanNeighbourhood(): Unable to bring device into monitor mode (" << strerror( errno ) << ")." << oendl; | 493 | owarn << "rescanNeighbourhood(): Unable to bring device into monitor mode (" << strerror( errno ) << ")." << oendl; |
361 | return; | 494 | return; |
362 | } | 495 | } |
363 | 496 | ||
364 | // open a packet capturer | 497 | // open a packet capturer |
365 | OPacketCapturer* cap = new OPacketCapturer(); | 498 | OPacketCapturer* cap = new OPacketCapturer(); |
366 | cap->open( name ); | 499 | cap->open( name ); |
367 | if ( !cap->isOpen() ) | 500 | if ( !cap->isOpen() ) |
368 | { | 501 | { |
369 | owarn << "rescanNeighbourhood(): Unable to open libpcap (" << strerror( errno ) << ")." << oendl; | 502 | owarn << "rescanNeighbourhood(): Unable to open libpcap (" << strerror( errno ) << ")." << oendl; |
370 | return; | 503 | return; |
371 | } | 504 | } |
372 | 505 | ||
373 | // disable button and display splash screen | 506 | // disable button and display splash screen |
374 | rescanButton->setEnabled( false ); | 507 | rescanButton->setEnabled( false ); |
375 | QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize ); | 508 | QFrame* splash = new QFrame( this, "splash", false, WStyle_StaysOnTop | WStyle_DialogBorder | WStyle_Customize ); |
376 | splash->setLineWidth( 2 ); | 509 | splash->setLineWidth( 2 ); |
377 | splash->setFrameStyle( QFrame::Panel | QFrame::Raised ); | 510 | splash->setFrameStyle( QFrame::Panel | QFrame::Raised ); |
378 | QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 ); | 511 | QVBoxLayout* vbox = new QVBoxLayout( splash, 4, 4 ); |
379 | QLabel* lab = new QLabel( "<center><b>Scanning...</b><br>Please Wait...</center>", splash ); | 512 | QLabel* lab = new QLabel( "<center><b>Scanning...</b><br>Please Wait...</center>", splash ); |
380 | QProgressBar* pb = new QProgressBar( wiface->channels(), splash ); | 513 | QProgressBar* pb = new QProgressBar( wiface->channels(), splash ); |
381 | vbox->addWidget( lab ); | 514 | vbox->addWidget( lab ); |
382 | vbox->addWidget( pb ); | 515 | vbox->addWidget( pb ); |
383 | pb->setCenterIndicator( true ); | 516 | pb->setCenterIndicator( true ); |
384 | pb->setFixedHeight( pb->sizeHint().height() ); | 517 | pb->setFixedHeight( pb->sizeHint().height() ); |
385 | QWidget* widgetDesktop = qApp->desktop(); | 518 | QWidget* widgetDesktop = qApp->desktop(); |
386 | int dw = widgetDesktop->width(); | 519 | int dw = widgetDesktop->width(); |
387 | int dh = widgetDesktop->height(); | 520 | int dh = widgetDesktop->height(); |
388 | int pw = vbox->sizeHint().width(); | 521 | int pw = vbox->sizeHint().width(); |
389 | int ph = vbox->sizeHint().height(); | 522 | int ph = vbox->sizeHint().height(); |
390 | splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph); | 523 | splash->setGeometry((dw-pw)/2,(dh-ph)/2,pw,ph); |
391 | splash->show(); | 524 | splash->show(); |
392 | splash->raise(); | 525 | splash->raise(); |
393 | qApp->processEvents(); | 526 | qApp->processEvents(); |
394 | 527 | ||
395 | // set capturer to non-blocking mode | 528 | // set capturer to non-blocking mode |
396 | cap->setBlocking( false ); | 529 | cap->setBlocking( false ); |
397 | 530 | ||
398 | for ( int i = 1; i <= wiface->channels(); ++i ) | 531 | for ( int i = 1; i <= wiface->channels(); ++i ) |
399 | { | 532 | { |
400 | wiface->setChannel( i ); | 533 | wiface->setChannel( i ); |
401 | pb->setProgress( i ); | 534 | pb->setProgress( i ); |
402 | qApp->processEvents(); | 535 | qApp->processEvents(); |
403 | odebug << "rescanNeighbourhood(): listening on channel " << i << "..." << oendl; | 536 | odebug << "rescanNeighbourhood(): listening on channel " << i << "..." << oendl; |
404 | OPacket* p = cap->next( 1000 ); | 537 | OPacket* p = cap->next( 1000 ); |
405 | if ( !p ) | 538 | if ( !p ) |
406 | { | 539 | { |
407 | odebug << "rescanNeighbourhood(): nothing received on channel " << i << "" << oendl; | 540 | odebug << "rescanNeighbourhood(): nothing received on channel " << i << "" << oendl; |
408 | } | 541 | } |
409 | else | 542 | else |
410 | { | 543 | { |
411 | odebug << "rescanNeighbourhood(): TADAA - something came in on channel " << i << "" << oendl; | 544 | odebug << "rescanNeighbourhood(): TADAA - something came in on channel " << i << "" << oendl; |
412 | handlePacket( p ); | 545 | handlePacket( p ); |
413 | } | 546 | } |
414 | } | 547 | } |
415 | 548 | ||
416 | cap->close(); | 549 | cap->close(); |
417 | wiface->setMode( "managed" ); // TODO: use previous mode | 550 | wiface->setMode( "managed" ); // TODO: use previous mode |
418 | wiface->setPromiscuousMode( false ); | 551 | wiface->setPromiscuousMode( false ); |
419 | 552 | ||
420 | // hide splash screen and reenable button | 553 | // hide splash screen and reenable button |
421 | splash->hide(); | 554 | splash->hide(); |
422 | delete splash; | 555 | delete splash; |
423 | rescanButton->setEnabled( true ); | 556 | rescanButton->setEnabled( true ); |
424 | } | 557 | } |
425 | 558 | ||
426 | void WLANImp::handlePacket( OPacket* p ) | 559 | void WLANImp::handlePacket( OPacket* p ) |
427 | { | 560 | { |
428 | 561 | ||
429 | // check if we received a beacon frame | 562 | // check if we received a beacon frame |
430 | OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) ); | 563 | OWaveLanManagementPacket* beacon = static_cast<OWaveLanManagementPacket*>( p->child( "802.11 Management" ) ); |
431 | if ( beacon && beacon->managementType() == "Beacon" ) | 564 | if ( beacon && beacon->managementType() == "Beacon" ) |
432 | { | 565 | { |
433 | 566 | ||
434 | QString type; | 567 | QString type; |
435 | if ( beacon->canIBSS() ) | 568 | if ( beacon->canIBSS() ) |
436 | { | 569 | { |
437 | type = "adhoc"; | 570 | type = "adhoc"; |
438 | } | 571 | } |
439 | else if ( beacon->canESS() ) | 572 | else if ( beacon->canESS() ) |
440 | { | 573 | { |
441 | type = "managed"; | 574 | type = "managed"; |
442 | } | 575 | } |
443 | else | 576 | else |
444 | { | 577 | { |
445 | owarn << "handlePacket(): invalid frame [possibly noise] detected!" << oendl; | 578 | owarn << "handlePacket(): invalid frame [possibly noise] detected!" << oendl; |
446 | return; | 579 | return; |
447 | } | 580 | } |
448 | 581 | ||
449 | OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); | 582 | OWaveLanManagementSSID* ssid = static_cast<OWaveLanManagementSSID*>( p->child( "802.11 SSID" ) ); |
450 | QString essid = ssid ? ssid->ID() : QString("<unknown>"); | 583 | QString essid = ssid ? ssid->ID() : QString("<unknown>"); |
451 | OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); | 584 | OWaveLanManagementDS* ds = static_cast<OWaveLanManagementDS*>( p->child( "802.11 DS" ) ); |
452 | int channel = ds ? ds->channel() : -1; | 585 | int channel = ds ? ds->channel() : -1; |
453 | OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); | 586 | OWaveLanPacket* header = static_cast<OWaveLanPacket*>( p->child( "802.11" ) ); |
454 | displayFoundNetwork( type, channel, essid, header->macAddress2() ); | 587 | displayFoundNetwork( type, channel, essid, header->macAddress2() ); |
455 | } | 588 | } |
456 | } | 589 | } |
457 | 590 | ||
458 | 591 | ||
459 | void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac ) | 592 | void WLANImp::displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const OMacAddress& mac ) |
460 | { | 593 | { |
461 | 594 | ||
462 | odebug << "found network: <" << (const char*) mode << ">, chn " << channel | 595 | odebug << "found network: <" << (const char*) mode << ">, chn " << channel |
463 | << ", ssid '" << (const char*) ssid << "', mac '" << (const char*) mac.toString() << "'" << oendl; | 596 | << ", ssid '" << (const char*) ssid << "', mac '" << (const char*) mac.toString() << "'" << oendl; |
464 | 597 | ||
465 | QListViewItemIterator it( netView ); | 598 | QListViewItemIterator it( netView ); |
466 | while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it; | 599 | while ( it.current() && it.current()->text( col_ssid ) != ssid ) ++it; |
467 | if ( !it.current() ) // ssid didn't show up yet | 600 | if ( !it.current() ) // ssid didn't show up yet |
468 | { | 601 | { |
469 | QListViewItem* item = new QListViewItem( netView, mode.left( 1 ).upper(), ssid, QString::number( channel ), mac.toString() ); | 602 | QListViewItem* item = new QListViewItem( netView, mode.left( 1 ).upper(), ssid, QString::number( channel ), mac.toString() ); |
470 | QString name; | 603 | QString name; |
471 | name.sprintf( "networksettings/%s", (const char*) mode ); | 604 | name.sprintf( "networksettings/%s", (const char*) mode ); |
472 | item->setPixmap( col_mode, Resource::loadPixmap( name ) ); | 605 | item->setPixmap( col_mode, Resource::loadPixmap( name ) ); |
473 | qApp->processEvents(); | 606 | qApp->processEvents(); |
474 | } | 607 | } |
475 | 608 | ||
476 | } | 609 | } |
477 | 610 | ||
478 | 611 | ||
479 | void WLANImp::selectNetwork( QListViewItem* item ) | 612 | void WLANImp::selectNetwork( QListViewItem* item ) |
480 | { | 613 | { |
481 | bool ok; | 614 | bool ok; |
482 | if ( item ) | 615 | if ( item ) |
483 | { | 616 | { |
484 | specifyAp->setChecked(true); | 617 | specifyAp->setChecked(true); |
485 | macEdit->setText( item->text( col_mac ) ); | 618 | macEdit->setText( item->text( col_mac ) ); |
486 | specifyChan->setChecked( item->text( col_mode ) == "A" ); | 619 | specifyChan->setChecked( item->text( col_mode ) == "A" ); |
487 | networkChannel->setValue( item->text( col_chn ).toInt( &ok ) ); | 620 | networkChannel->setValue( item->text( col_chn ).toInt( &ok ) ); |
488 | essid->setEditText( item->text( col_ssid ) ); | 621 | essid->setEditText( item->text( col_ssid ) ); |
489 | if ( item->text( col_mode ) == "A" ) | 622 | if ( item->text( col_mode ) == "A" ) |
490 | mode->setCurrentItem( 3 ); | 623 | mode->setCurrentItem( 3 ); |
491 | else | 624 | else |
492 | mode->setCurrentItem( 2 ); | 625 | mode->setCurrentItem( 2 ); |
493 | } | 626 | } |
494 | } | 627 | } |
diff --git a/noncore/settings/networksettings/wlan/wlanimp2.h b/noncore/settings/networksettings/wlan/wlanimp2.h index c3d1eee..0e8d533 100644 --- a/noncore/settings/networksettings/wlan/wlanimp2.h +++ b/noncore/settings/networksettings/wlan/wlanimp2.h | |||
@@ -1,52 +1,53 @@ | |||
1 | #ifndef WLANIMP_H | 1 | #ifndef WLANIMP_H |
2 | #define WLANIMP_H | 2 | #define WLANIMP_H |
3 | 3 | ||
4 | #include "wlan.h" | 4 | #include "wlan.h" |
5 | #include "interfaces.h" | 5 | #include "interfaces.h" |
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | #include <opie2/onetutils.h> | 7 | #include <opie2/onetutils.h> |
8 | 8 | ||
9 | class InterfaceSetupImp; | 9 | class InterfaceSetupImp; |
10 | class Interface; | 10 | class Interface; |
11 | class Config; | 11 | class Config; |
12 | namespace Opie {namespace Net {class OPacket;}} | 12 | namespace Opie {namespace Net {class OPacket;}} |
13 | class QListViewItem; | 13 | class QListViewItem; |
14 | 14 | ||
15 | const int col_mode= 0; | 15 | const int col_mode= 0; |
16 | const int col_ssid = 1; | 16 | const int col_ssid = 1; |
17 | const int col_chn = 2; | 17 | const int col_chn = 2; |
18 | const int col_mac = 3; | 18 | const int col_mac = 3; |
19 | 19 | ||
20 | class WLANImp : public WLAN { | 20 | class WLANImp : public WLAN { |
21 | Q_OBJECT | 21 | Q_OBJECT |
22 | 22 | ||
23 | public: | 23 | public: |
24 | WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); | 24 | WLANImp( QWidget* parent = 0, const char* name = 0, Interface *i=0, bool modal = FALSE, WFlags fl = 0 ); |
25 | ~WLANImp(); | 25 | ~WLANImp(); |
26 | void setProfile(const QString &profile); | 26 | void setProfile(const QString &profile); |
27 | 27 | ||
28 | public slots: | 28 | public slots: |
29 | void rescanNeighbourhood(); | 29 | void rescanNeighbourhood(); |
30 | void selectNetwork( QListViewItem* ); | 30 | void selectNetwork( QListViewItem* ); |
31 | 31 | ||
32 | protected: | 32 | protected: |
33 | void accept(); | 33 | void accept(); |
34 | 34 | ||
35 | private: | 35 | private: |
36 | void parseOpts(); | 36 | void parseOpts(); |
37 | void writeOpts(); | 37 | void writeOpts(); |
38 | 38 | ||
39 | void parseKeyStr(QString keystr); | 39 | void parseKeyStr(QString keystr); |
40 | 40 | QString formatKey(QString input); | |
41 | |||
41 | void handlePacket( Opie::Net::OPacket* ); | 42 | void handlePacket( Opie::Net::OPacket* ); |
42 | void displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const Opie::Net::OMacAddress& mac ); | 43 | void displayFoundNetwork( const QString& mode, int channel, const QString& ssid, const Opie::Net::OMacAddress& mac ); |
43 | 44 | ||
44 | InterfaceSetupImp *interfaceSetup; | 45 | InterfaceSetupImp *interfaceSetup; |
45 | Interfaces *interfaces; | 46 | Interfaces *interfaces; |
46 | Interface *interface; | 47 | Interface *interface; |
47 | 48 | ||
48 | QString currentProfile; | 49 | QString currentProfile; |
49 | }; | 50 | }; |
50 | 51 | ||
51 | #endif | 52 | #endif |
52 | 53 | ||