1
/****************************************************************************
2
** ui.h extension file, included from the uic-generated form implementation.
4
** If you want to add, delete, or rename functions or slots, use
5
** Qt Designer to update this file, preserving your code.
7
** You should not define a constructor or destructor in this file.
8
** Instead, write your code in functions called init() and destroy().
9
** These will automatically be called by the form's constructor and
11
*****************************************************************************/
23
void NetworkConfig::init()
29
void NetworkConfig::paramsFromScanResults(Q3ListViewItem *sel)
33
/* SSID BSSID frequency signal flags */
34
setCaption(sel->text(0));
35
ssidEdit->setText(sel->text(0));
37
QString flags = sel->text(4);
39
if (flags.find("[WPA2-EAP") >= 0)
41
else if (flags.find("[WPA-EAP") >= 0)
43
else if (flags.find("[WPA2-PSK") >= 0)
45
else if (flags.find("[WPA-PSK") >= 0)
50
if (flags.find("-CCMP") >= 0)
52
else if (flags.find("-TKIP") >= 0)
54
else if (flags.find("WEP") >= 0)
59
authSelect->setCurrentItem(auth);
61
encrSelect->setCurrentItem(encr);
67
void NetworkConfig::authChanged(int sel)
69
pskEdit->setEnabled(sel == AUTH_WPA_PSK || sel == AUTH_WPA2_PSK);
70
bool eap = sel == AUTH_IEEE8021X || sel == AUTH_WPA_EAP ||
72
eapSelect->setEnabled(eap);
73
identityEdit->setEnabled(eap);
74
passwordEdit->setEnabled(eap);
75
cacertEdit->setEnabled(eap);
77
while (encrSelect->count())
78
encrSelect->removeItem(0);
80
if (sel == AUTH_NONE || sel == AUTH_IEEE8021X) {
81
encrSelect->insertItem("None");
82
encrSelect->insertItem("WEP");
83
encrSelect->setCurrentItem(sel == AUTH_NONE ? 0 : 1);
85
encrSelect->insertItem("TKIP");
86
encrSelect->insertItem("CCMP");
87
encrSelect->setCurrentItem((sel == AUTH_WPA2_PSK ||
88
sel == AUTH_WPA2_EAP) ? 1 : 0);
91
wepEnabled(sel == AUTH_IEEE8021X);
95
void NetworkConfig::addNetwork()
97
char reply[10], cmd[256];
100
int psklen = pskEdit->text().length();
101
int auth = authSelect->currentItem();
103
if (auth == AUTH_WPA_PSK || auth == AUTH_WPA2_PSK) {
104
if (psklen < 8 || psklen > 64) {
105
QMessageBox::warning(this, "wpa_gui", "WPA-PSK requires a passphrase "
106
"of 8 to 63 characters\n"
107
"or 64 hex digit PSK");
115
memset(reply, 0, sizeof(reply));
116
reply_len = sizeof(reply) - 1;
119
wpagui->ctrlRequest("ADD_NETWORK", reply, &reply_len);
120
if (reply[0] == 'F') {
121
QMessageBox::warning(this, "wpa_gui", "Failed to add network to wpa_supplicant\n"
127
id = edit_network_id;
130
setNetworkParam(id, "ssid", ssidEdit->text().ascii(), true);
132
char *key_mgmt = NULL, *proto = NULL, *pairwise = NULL;
138
key_mgmt = "IEEE8021X";
141
key_mgmt = "WPA-PSK";
145
key_mgmt = "WPA-EAP";
149
key_mgmt = "WPA-PSK";
153
key_mgmt = "WPA-EAP";
158
if (auth == AUTH_WPA_PSK || auth == AUTH_WPA_EAP ||
159
auth == AUTH_WPA2_PSK || auth == AUTH_WPA2_EAP) {
160
int encr = encrSelect->currentItem();
168
setNetworkParam(id, "proto", proto, false);
170
setNetworkParam(id, "key_mgmt", key_mgmt, false);
172
setNetworkParam(id, "pairwise", pairwise, false);
173
setNetworkParam(id, "group", "TKIP CCMP WEP104 WEP40", false);
175
if (pskEdit->isEnabled())
176
setNetworkParam(id, "psk", pskEdit->text().ascii(), psklen != 64);
177
if (eapSelect->isEnabled())
178
setNetworkParam(id, "eap", eapSelect->currentText().ascii(), false);
179
if (identityEdit->isEnabled())
180
setNetworkParam(id, "identity", identityEdit->text().ascii(), true);
181
if (passwordEdit->isEnabled())
182
setNetworkParam(id, "password", passwordEdit->text().ascii(), true);
183
if (cacertEdit->isEnabled())
184
setNetworkParam(id, "ca_cert", cacertEdit->text().ascii(), true);
185
writeWepKey(id, wep0Edit, 0);
186
writeWepKey(id, wep1Edit, 1);
187
writeWepKey(id, wep2Edit, 2);
188
writeWepKey(id, wep3Edit, 3);
190
if (wep0Radio->isEnabled() && wep0Radio->isChecked())
191
setNetworkParam(id, "wep_tx_keyidx", "0", false);
192
else if (wep1Radio->isEnabled() && wep1Radio->isChecked())
193
setNetworkParam(id, "wep_tx_keyidx", "1", false);
194
else if (wep2Radio->isEnabled() && wep2Radio->isChecked())
195
setNetworkParam(id, "wep_tx_keyidx", "2", false);
196
else if (wep3Radio->isEnabled() && wep3Radio->isChecked())
197
setNetworkParam(id, "wep_tx_keyidx", "3", false);
199
snprintf(cmd, sizeof(cmd), "ENABLE_NETWORK %d", id);
200
reply_len = sizeof(reply);
201
wpagui->ctrlRequest(cmd, reply, &reply_len);
202
if (strncmp(reply, "OK", 2) != 0) {
203
QMessageBox::warning(this, "wpa_gui", "Failed to enable network in wpa_supplicant\n"
205
/* Network was added, so continue anyway */
207
wpagui->triggerUpdate();
208
wpagui->ctrlRequest("SAVE_CONFIG", reply, &reply_len);
214
void NetworkConfig::setWpaGui( WpaGui *_wpagui )
220
int NetworkConfig::setNetworkParam(int id, const char *field, const char *value, bool quote)
222
char reply[10], cmd[256];
224
snprintf(cmd, sizeof(cmd), "SET_NETWORK %d %s %s%s%s",
225
id, field, quote ? "\"" : "", value, quote ? "\"" : "");
226
reply_len = sizeof(reply);
227
wpagui->ctrlRequest(cmd, reply, &reply_len);
228
return strncmp(reply, "OK", 2) == 0 ? 0 : -1;
232
void NetworkConfig::encrChanged( const QString &sel )
234
wepEnabled(sel.find("WEP") == 0);
238
void NetworkConfig::wepEnabled( bool enabled )
240
wep0Edit->setEnabled(enabled);
241
wep1Edit->setEnabled(enabled);
242
wep2Edit->setEnabled(enabled);
243
wep3Edit->setEnabled(enabled);
244
wep0Radio->setEnabled(enabled);
245
wep1Radio->setEnabled(enabled);
246
wep2Radio->setEnabled(enabled);
247
wep3Radio->setEnabled(enabled);
251
void NetworkConfig::writeWepKey( int network_id, QLineEdit *edit, int id )
255
const char *txt, *pos;
258
if (!edit->isEnabled() || edit->text().isEmpty())
262
* Assume hex key if only hex characters are present and length matches
263
* with 40, 104, or 128-bit key
265
txt = edit->text().ascii();
272
if (!((*pos >= '0' && *pos <= '9') || (*pos >= 'a' && *pos <= 'f') ||
273
(*pos >= 'A' && *pos <= 'F'))) {
279
if (hex && len != 10 && len != 26 && len != 32)
281
snprintf(buf, sizeof(buf), "wep_key%d", id);
282
setNetworkParam(network_id, buf, txt, !hex);
286
void NetworkConfig::paramsFromConfig( int network_id )
290
edit_network_id = network_id;
293
char reply[1024], cmd[256], *pos;
296
snprintf(cmd, sizeof(cmd), "GET_NETWORK %d ssid", network_id);
297
reply_len = sizeof(reply);
298
if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
300
reply[reply_len] = '\0';
301
pos = strchr(reply + 1, '"');
304
ssidEdit->setText(reply + 1);
307
snprintf(cmd, sizeof(cmd), "GET_NETWORK %d proto", network_id);
308
reply_len = sizeof(reply);
310
if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
311
reply[reply_len] = '\0';
312
if (strstr(reply, "RSN") || strstr(reply, "WPA2"))
314
else if (strstr(reply, "WPA"))
318
int auth = AUTH_NONE, encr = 0;
319
snprintf(cmd, sizeof(cmd), "GET_NETWORK %d key_mgmt", network_id);
320
reply_len = sizeof(reply);
321
if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
322
reply[reply_len] = '\0';
323
if (strstr(reply, "WPA-EAP"))
324
auth = wpa & 2 ? AUTH_WPA2_EAP : AUTH_WPA_EAP;
325
else if (strstr(reply, "WPA-PSK"))
326
auth = wpa & 2 ? AUTH_WPA2_PSK : AUTH_WPA_PSK;
327
else if (strstr(reply, "IEEE8021X")) {
328
auth = AUTH_IEEE8021X;
333
snprintf(cmd, sizeof(cmd), "GET_NETWORK %d pairwise", network_id);
334
reply_len = sizeof(reply);
335
if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
336
reply[reply_len] = '\0';
337
if (strstr(reply, "CCMP"))
339
else if (strstr(reply, "TKIP"))
341
else if (strstr(reply, "WEP"))
347
snprintf(cmd, sizeof(cmd), "GET_NETWORK %d psk", network_id);
348
reply_len = sizeof(reply);
349
if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
351
reply[reply_len] = '\0';
352
pos = strchr(reply + 1, '"');
355
pskEdit->setText(reply + 1);
358
snprintf(cmd, sizeof(cmd), "GET_NETWORK %d identity", network_id);
359
reply_len = sizeof(reply);
360
if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
362
reply[reply_len] = '\0';
363
pos = strchr(reply + 1, '"');
366
identityEdit->setText(reply + 1);
369
snprintf(cmd, sizeof(cmd), "GET_NETWORK %d password", network_id);
370
reply_len = sizeof(reply);
371
if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
373
reply[reply_len] = '\0';
374
pos = strchr(reply + 1, '"');
377
passwordEdit->setText(reply + 1);
380
snprintf(cmd, sizeof(cmd), "GET_NETWORK %d ca_cert", network_id);
381
reply_len = sizeof(reply);
382
if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
384
reply[reply_len] = '\0';
385
pos = strchr(reply + 1, '"');
388
cacertEdit->setText(reply + 1);
391
snprintf(cmd, sizeof(cmd), "GET_NETWORK %d eap", network_id);
392
reply_len = sizeof(reply);
393
if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1) {
394
reply[reply_len] = '\0';
395
for (i = 0; i < eapSelect->count(); i++) {
396
if (eapSelect->text(i).compare(reply) == 0) {
397
eapSelect->setCurrentItem(i);
403
for (i = 0; i < 4; i++) {
404
snprintf(cmd, sizeof(cmd), "GET_NETWORK %d wep_key%d", network_id, i);
405
reply_len = sizeof(reply);
406
if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 2 &&
408
reply[reply_len] = '\0';
409
pos = strchr(reply + 1, '"');
412
if (auth == AUTH_NONE || auth == AUTH_IEEE8021X)
417
wep0Edit->setText(reply + 1);
420
wep1Edit->setText(reply + 1);
423
wep2Edit->setText(reply + 1);
426
wep3Edit->setText(reply + 1);
432
snprintf(cmd, sizeof(cmd), "GET_NETWORK %d wep_tx_keyidx", network_id);
433
reply_len = sizeof(reply);
434
if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1) {
435
reply[reply_len] = '\0';
436
switch (atoi(reply)) {
438
wep0Radio->setChecked(true);
441
wep1Radio->setChecked(true);
444
wep2Radio->setChecked(true);
447
wep3Radio->setChecked(true);
452
authSelect->setCurrentItem(auth);
454
encrSelect->setCurrentItem(encr);
455
if (auth == AUTH_NONE || auth == AUTH_IEEE8021X)
456
wepEnabled(encr == 1);
458
removeButton->setEnabled(true);
459
addButton->setText("Save");
463
void NetworkConfig::removeNetwork()
465
char reply[10], cmd[256];
468
if (QMessageBox::information(this, "wpa_gui",
469
"This will permanently remove the network\n"
470
"from the configuration. Do you really want\n"
471
"to remove this network?", "Yes", "No") != 0)
474
snprintf(cmd, sizeof(cmd), "REMOVE_NETWORK %d", edit_network_id);
475
reply_len = sizeof(reply);
476
wpagui->ctrlRequest(cmd, reply, &reply_len);
477
if (strncmp(reply, "OK", 2) != 0) {
478
QMessageBox::warning(this, "wpa_gui",
479
"Failed to remove network from wpa_supplicant\n"
482
wpagui->triggerUpdate();
483
wpagui->ctrlRequest("SAVE_CONFIG", reply, &reply_len);
490
void NetworkConfig::newNetwork()
497
void NetworkConfig::getEapCapa()
505
reply_len = sizeof(reply) - 1;
506
if (wpagui->ctrlRequest("GET_CAPABILITY eap", reply, &reply_len) < 0)
508
reply[reply_len] = '\0';
511
QStringList types = QStringList::split(QChar(' '), res);
512
eapSelect->insertStringList(types);