author | kergoth <kergoth> | 2003-04-14 23:31:22 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2003-04-14 23:31:22 (UTC) |
commit | fb07cc161b4adc5bc250569599a7164af2d7caba (patch) (unidiff) | |
tree | 1f391e35146e81835af5e0a395896b3fe3c0d46b /noncore/settings/networksettings/wlan/wlanimp2.cpp | |
parent | 68c558ca78e5416145b64ca87fd01361f033ef34 (diff) | |
download | opie-fb07cc161b4adc5bc250569599a7164af2d7caba.zip opie-fb07cc161b4adc5bc250569599a7164af2d7caba.tar.gz opie-fb07cc161b4adc5bc250569599a7164af2d7caba.tar.bz2 |
Add new wireless parser that uses the wireless-tools if-pre-up.d
script to handle wireless configuration, as opposed to pcmcia-cs
wireless.opts. This has a number of benefits. In addition to
improving clarity, this means one can now configure their wireless
non-pcmcia interfaces using networksettings. The only real question
is, how to handle the fact that its largely useless without the
if-pre-up.d script? I'll adapt the existing wlanimp.(cpp|h) to
the new .ui, and leave it as a compiletime selection for now.
Diffstat (limited to 'noncore/settings/networksettings/wlan/wlanimp2.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/settings/networksettings/wlan/wlanimp2.cpp | 266 |
1 files changed, 266 insertions, 0 deletions
diff --git a/noncore/settings/networksettings/wlan/wlanimp2.cpp b/noncore/settings/networksettings/wlan/wlanimp2.cpp new file mode 100644 index 0000000..01c9668 --- a/dev/null +++ b/noncore/settings/networksettings/wlan/wlanimp2.cpp | |||
@@ -0,0 +1,266 @@ | |||
1 | #include "wlanimp2.h" | ||
2 | #include "interfacesetupimp.h" | ||
3 | |||
4 | #include <qfile.h> | ||
5 | #include <qdir.h> | ||
6 | #include <qtextstream.h> | ||
7 | #include <qmessagebox.h> | ||
8 | #include <qlineedit.h> | ||
9 | #include <qlabel.h> | ||
10 | #include <qspinbox.h> | ||
11 | #include <qradiobutton.h> | ||
12 | #include <qcheckbox.h> | ||
13 | #include <qtabwidget.h> | ||
14 | #include <qcombobox.h> | ||
15 | |||
16 | #ifdef QWS | ||
17 | #include <opie/oprocess.h> | ||
18 | #else | ||
19 | #define OProcess KProcess | ||
20 | #include <kprocess.h> | ||
21 | #endif | ||
22 | |||
23 | #define WIRELESS_OPTS "/etc/pcmcia/wireless.opts" | ||
24 | #define PREUP "/etc/netwrok/if-pre-up.d/wireless-tools" | ||
25 | |||
26 | /** | ||
27 | * Constructor, read in the wireless.opts file for parsing later. | ||
28 | */ | ||
29 | WLANImp::WLANImp( QWidget* parent, const char* name, Interface *i, bool modal, WFlags fl) : WLAN(parent, name, modal, fl), currentProfile("*"), interface(i) { | ||
30 | interfaces = new Interfaces; | ||
31 | interfaceSetup = new InterfaceSetupImp(tabWidget, "InterfaceSetupImp", i, interfaces); | ||
32 | tabWidget->insertTab(interfaceSetup, "TCP/IP"); | ||
33 | |||
34 | // Check sanity - the existance of the wireless-tools if-pre-up script | ||
35 | QFile file(QString(PREUP)); | ||
36 | if (file.exists()) { | ||
37 | qWarning(QString("WLANImp: Unable to open /etc/network/if-pre-up.d/wireless-tools")); | ||
38 | } | ||
39 | } | ||
40 | |||
41 | WLANImp::~WLANImp() { | ||
42 | delete interfaces; | ||
43 | } | ||
44 | |||
45 | /** | ||
46 | * Change the profile for both wireless settings and network settings. | ||
47 | */ | ||
48 | void WLANImp::setProfile(const QString &profile){ | ||
49 | interfaceSetup->setProfile(profile); | ||
50 | parseOpts(); | ||
51 | } | ||
52 | |||
53 | void WLANImp::parseOpts() { | ||
54 | bool error; | ||
55 | QString opt; | ||
56 | |||
57 | if (! interfaces->isInterfaceSet()) | ||
58 | return; | ||
59 | |||
60 | |||
61 | opt = interfaces->getInterfaceOption("wireless_essid", error); | ||
62 | if(opt == "any" || opt == "off" || opt.isNull()){ | ||
63 | essid->setEditText("any"); | ||
64 | } else { | ||
65 | essid->setEditText(opt); | ||
66 | } | ||
67 | |||
68 | opt = interfaces->getInterfaceOption("wireless_mode", error).simplifyWhiteSpace(); | ||
69 | if (opt == "Auto") { | ||
70 | mode->setCurrentItem(0); | ||
71 | } else if (opt == "Ad-Hoc") { | ||
72 | mode->setCurrentItem(2); | ||
73 | } else { | ||
74 | // Managed/Infrastructure mode | ||
75 | mode->setCurrentItem(1); | ||
76 | } | ||
77 | |||
78 | opt = interfaces->getInterfaceOption("wireless_ap", error).simplifyWhiteSpace(); | ||
79 | if (! opt.isNull()) { | ||
80 | specifyAp->setChecked(true); | ||
81 | macEdit->setText(opt); | ||
82 | } | ||
83 | |||
84 | opt = interfaces->getInterfaceOption("wireless_channel", error).simplifyWhiteSpace(); | ||
85 | if (! opt.isNull()) { | ||
86 | specifyChan->setChecked(true); | ||
87 | networkChannel->setValue(opt.toInt()); | ||
88 | } | ||
89 | |||
90 | opt = interfaces->getInterfaceOption("wireless_key", error).simplifyWhiteSpace(); | ||
91 | if (opt.isNull()) | ||
92 | opt = interfaces->getInterfaceOption("wireless_enc", error).simplifyWhiteSpace(); | ||
93 | parseKeyStr(opt); | ||
94 | } | ||
95 | |||
96 | void WLANImp::parseKeyStr(QString keystr) { | ||
97 | int loc = 0; | ||
98 | int index = 1; | ||
99 | QString key; | ||
100 | QStringList keys = QStringList::split(QRegExp("\\s+"), keystr); | ||
101 | int enc = -1; // encryption state | ||
102 | |||
103 | for (QStringList::Iterator it = keys.begin(); it != keys.end(); ++it) { | ||
104 | if ((*it).left(3) == "off") { | ||
105 | // encryption disabled | ||
106 | enc = 0; | ||
107 | } else if ((*it).left(2) == "on") { | ||
108 | // encryption enabled | ||
109 | enc = 1; | ||
110 | } else if ((*it).left(4) == "open") { | ||
111 | // open mode, accept non encrypted packets | ||
112 | acceptNonEnc->setChecked(true); | ||
113 | } else if ((*it).left(10) == "restricted") { | ||
114 | // restricted mode, only accept encrypted packets | ||
115 | rejectNonEnc->setChecked(true); | ||
116 | } else if ((*it).left(3) == "key") { | ||
117 | // new set of options | ||
118 | } else if ((*it).left(1) == "[") { | ||
119 | index = (*it).mid(1, 1).toInt(); | ||
120 | // switch current key to index | ||
121 | switch (index) { | ||
122 | case 1: | ||
123 | keyRadio0->setChecked(true); | ||
124 | break; | ||
125 | case 2: | ||
126 | keyRadio1->setChecked(true); | ||
127 | break; | ||
128 | case 3: | ||
129 | keyRadio2->setChecked(true); | ||
130 | break; | ||
131 | case 4: | ||
132 | keyRadio3->setChecked(true); | ||
133 | break; | ||
134 | } | ||
135 | } else { | ||
136 | // key | ||
137 | key = (*it); | ||
138 | } | ||
139 | if (! key.isNull()) { | ||
140 | if (enc == -1) | ||
141 | enc = 1; | ||
142 | QStringList::Iterator next = ++it; | ||
143 | if (it == keys.end()) { | ||
144 | break; | ||
145 | } | ||
146 | if ((*(next)).left(1) == "[") { | ||
147 | // set key at index | ||
148 | index = (*(next)).mid(1, 1).toInt(); | ||
149 | } else { | ||
150 | index = 1; | ||
151 | } | ||
152 | switch (index) { | ||
153 | case 1: | ||
154 | keyLineEdit0->setText(key); | ||
155 | break; | ||
156 | case 2: | ||
157 | keyLineEdit1->setText(key); | ||
158 | break; | ||
159 | case 3: | ||
160 | keyLineEdit2->setText(key); | ||
161 | break; | ||
162 | case 4: | ||
163 | keyLineEdit3->setText(key); | ||
164 | break; | ||
165 | } | ||
166 | key = QString::null; | ||
167 | } | ||
168 | } | ||
169 | if (enc == 1) { | ||
170 | wepEnabled->setChecked(true); | ||
171 | } else { | ||
172 | wepEnabled->setChecked(false); | ||
173 | } | ||
174 | } | ||
175 | |||
176 | /** | ||
177 | * Check to see if the current config is valid | ||
178 | * Save interfaces | ||
179 | */ | ||
180 | void WLANImp::accept() { | ||
181 | if (wepEnabled->isChecked()) { | ||
182 | if ((keyRadio0->isChecked() && keyLineEdit0->text().isEmpty()) || | ||
183 | (keyRadio1->isChecked() && keyLineEdit1->text().isEmpty()) || | ||
184 | (keyRadio2->isChecked() && keyLineEdit2->text().isEmpty()) || | ||
185 | (keyRadio3->isChecked() && keyLineEdit3->text().isEmpty())) { | ||
186 | QMessageBox::information(this, "Error", "Please enter a WEP key.", QMessageBox::Ok); | ||
187 | return; | ||
188 | } | ||
189 | } | ||
190 | |||
191 | if (essid->currentText().isEmpty()) { | ||
192 | QMessageBox::information(this, "Error", "Please select/enter an ESSID.", QMessageBox::Ok); | ||
193 | return; | ||
194 | } | ||
195 | |||
196 | if (specifyAp->isChecked() && macEdit->text().isEmpty()) { | ||
197 | QMessageBox::information(this, "Error", "Please enter the MAC address of the Access Point.", QMessageBox::Ok); | ||
198 | return; | ||
199 | } | ||
200 | |||
201 | // Try to save the interfaces settings. | ||
202 | writeOpts(); | ||
203 | |||
204 | // Close out the dialog | ||
205 | QDialog::accept(); | ||
206 | } | ||
207 | |||
208 | void WLANImp::writeOpts() { | ||
209 | bool error = false; | ||
210 | |||
211 | interfaces->setInterfaceOption(QString("wireless_mode"), mode->currentText()); | ||
212 | interfaces->setInterfaceOption(QString("wireless_essid"), essid->currentText()); | ||
213 | |||
214 | if (specifyAp->isChecked()) { | ||
215 | interfaces->setInterfaceOption(QString("wireless_ap"), macEdit->text()); | ||
216 | } else { | ||
217 | interfaces->removeInterfaceOption(QString("wireless_ap")); | ||
218 | } | ||
219 | |||
220 | if (specifyChan->isChecked()) { | ||
221 | interfaces->setInterfaceOption(QString("wireless_channel"), networkChannel->text()); | ||
222 | } else { | ||
223 | interfaces->removeInterfaceOption(QString("wireless_channel")); | ||
224 | } | ||
225 | |||
226 | if (wepEnabled->isChecked()) { | ||
227 | QStringList keyList; | ||
228 | |||
229 | if (! keyLineEdit0->text().isNull()) { | ||
230 | keyList += keyLineEdit0->text(); | ||
231 | keyList += "[1]"; | ||
232 | } else if (! keyLineEdit1->text().isNull()) { | ||
233 | keyList += keyLineEdit1->text(); | ||
234 | keyList += "[2]"; | ||
235 | } else if (! keyLineEdit2->text().isNull()) { | ||
236 | keyList += keyLineEdit2->text(); | ||
237 | keyList += "[3]"; | ||
238 | } else if (! keyLineEdit3->text().isNull()) { | ||
239 | keyList += keyLineEdit3->text(); | ||
240 | keyList += "[4]"; | ||
241 | } | ||
242 | if (acceptNonEnc->isChecked()) { | ||
243 | keyList += "open"; | ||
244 | } else { | ||
245 | keyList += "restricted"; | ||
246 | } | ||
247 | |||
248 | keyList += "key"; | ||
249 | if (keyRadio0->isChecked()) { | ||
250 | keyList += "[1]"; | ||
251 | } else if (keyRadio1->isChecked()) { | ||
252 | keyList += "[2]"; | ||
253 | } else if (keyRadio2->isChecked()) { | ||
254 | keyList += "[3]"; | ||
255 | } else if (keyRadio3->isChecked()) { | ||
256 | keyList += "[4]"; | ||
257 | } | ||
258 | interfaces->setInterfaceOption(QString("wireless_key"), keyList.join(QString(" "))); | ||
259 | } else { | ||
260 | interfaces->removeInterfaceOption(QString("wireless_key")); | ||
261 | } | ||
262 | interfaces->removeInterfaceOption(QString("wireless_enc")); | ||
263 | |||
264 | if(!interfaceSetup->saveChanges()) | ||
265 | return; | ||
266 | } | ||