2 * wpa_gui - NetworkConfig class
3 * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
16 #include <QMessageBox>
18 #include "networkconfig.h"
32 #define WPA_GUI_KEY_DATA "[key is configured]"
35 NetworkConfig::NetworkConfig(QWidget
*parent
, const char *, bool, Qt::WFlags
)
40 encrSelect
->setEnabled(false);
41 connect(authSelect
, SIGNAL(activated(int)), this,
42 SLOT(authChanged(int)));
43 connect(cancelButton
, SIGNAL(clicked()), this, SLOT(close()));
44 connect(addButton
, SIGNAL(clicked()), this, SLOT(addNetwork()));
45 connect(encrSelect
, SIGNAL(activated(const QString
&)), this,
46 SLOT(encrChanged(const QString
&)));
47 connect(removeButton
, SIGNAL(clicked()), this, SLOT(removeNetwork()));
48 connect(eapSelect
, SIGNAL(activated(int)), this,
49 SLOT(eapChanged(int)));
50 connect(useWpsButton
, SIGNAL(clicked()), this, SLOT(useWps()));
57 NetworkConfig::~NetworkConfig()
62 void NetworkConfig::languageChange()
68 void NetworkConfig::paramsFromScanResults(QTreeWidgetItem
*sel
)
72 /* SSID BSSID frequency signal flags */
73 setWindowTitle(sel
->text(0));
74 ssidEdit
->setText(sel
->text(0));
76 QString flags
= sel
->text(4);
78 if (flags
.indexOf("[WPA2-EAP") >= 0)
80 else if (flags
.indexOf("[WPA-EAP") >= 0)
82 else if (flags
.indexOf("[WPA2-PSK") >= 0)
84 else if (flags
.indexOf("[WPA-PSK") >= 0)
87 auth
= AUTH_NONE_OPEN
;
89 if (flags
.indexOf("-CCMP") >= 0)
91 else if (flags
.indexOf("-TKIP") >= 0)
93 else if (flags
.indexOf("WEP") >= 0) {
95 if (auth
== AUTH_NONE_OPEN
)
100 authSelect
->setCurrentIndex(auth
);
102 encrSelect
->setCurrentIndex(encr
);
104 wepEnabled(auth
== AUTH_NONE_WEP
);
108 if (flags
.indexOf("[WPS") >= 0)
109 useWpsButton
->setEnabled(true);
110 bssid
= sel
->text(1);
114 void NetworkConfig::authChanged(int sel
)
116 encrSelect
->setEnabled(sel
!= AUTH_NONE_OPEN
&& sel
!= AUTH_NONE_WEP
&&
117 sel
!= AUTH_NONE_WEP_SHARED
);
118 pskEdit
->setEnabled(sel
== AUTH_WPA_PSK
|| sel
== AUTH_WPA2_PSK
);
119 bool eap
= sel
== AUTH_IEEE8021X
|| sel
== AUTH_WPA_EAP
||
120 sel
== AUTH_WPA2_EAP
;
121 eapSelect
->setEnabled(eap
);
122 identityEdit
->setEnabled(eap
);
123 passwordEdit
->setEnabled(eap
);
124 cacertEdit
->setEnabled(eap
);
125 phase2Select
->setEnabled(eap
);
127 eapChanged(eapSelect
->currentIndex());
129 while (encrSelect
->count())
130 encrSelect
->removeItem(0);
132 if (sel
== AUTH_NONE_OPEN
|| sel
== AUTH_NONE_WEP
||
133 sel
== AUTH_NONE_WEP_SHARED
|| sel
== AUTH_IEEE8021X
) {
134 encrSelect
->addItem("None");
135 encrSelect
->addItem("WEP");
136 encrSelect
->setCurrentIndex(sel
== AUTH_NONE_OPEN
? 0 : 1);
138 encrSelect
->addItem("TKIP");
139 encrSelect
->addItem("CCMP");
140 encrSelect
->setCurrentIndex((sel
== AUTH_WPA2_PSK
||
141 sel
== AUTH_WPA2_EAP
) ? 1 : 0);
144 wepEnabled(sel
== AUTH_NONE_WEP
|| sel
== AUTH_NONE_WEP_SHARED
);
148 void NetworkConfig::eapChanged(int sel
)
150 QString prev_val
= phase2Select
->currentText();
151 while (phase2Select
->count())
152 phase2Select
->removeItem(0);
155 inner
<< "PEAP" << "TTLS" << "FAST";
156 if (!inner
.contains(eapSelect
->itemText(sel
)))
159 phase2Select
->addItem("[ any ]");
161 /* Add special cases based on outer method */
162 if (eapSelect
->currentText().compare("TTLS") == 0) {
163 phase2Select
->addItem("PAP");
164 phase2Select
->addItem("CHAP");
165 phase2Select
->addItem("MSCHAP");
166 phase2Select
->addItem("MSCHAPv2");
167 } else if (eapSelect
->currentText().compare("FAST") == 0)
168 phase2Select
->addItem("GTC(auth) + MSCHAPv2(prov)");
170 /* Add all enabled EAP methods that can be used in the tunnel */
173 allowed
<< "MSCHAPV2" << "MD5" << "GTC" << "TLS" << "OTP" << "SIM"
175 for (i
= 0; i
< eapSelect
->count(); i
++) {
176 if (allowed
.contains(eapSelect
->itemText(i
))) {
177 phase2Select
->addItem("EAP-" + eapSelect
->itemText(i
));
181 for (i
= 0; i
< phase2Select
->count(); i
++) {
182 if (phase2Select
->itemText(i
).compare(prev_val
) == 0) {
183 phase2Select
->setCurrentIndex(i
);
190 void NetworkConfig::addNetwork()
192 char reply
[10], cmd
[256];
195 int psklen
= pskEdit
->text().length();
196 int auth
= authSelect
->currentIndex();
198 if (auth
== AUTH_WPA_PSK
|| auth
== AUTH_WPA2_PSK
) {
199 if (psklen
< 8 || psklen
> 64) {
200 QMessageBox::warning(this, "WPA Pre-Shared Key Error",
201 "WPA-PSK requires a passphrase "
202 "of 8 to 63 characters\n"
203 "or 64 hex digit PSK");
209 if (idstrEdit
->isEnabled() && !idstrEdit
->text().isEmpty()) {
210 QRegExp
rx("^(\\w|-)+$");
211 if (rx
.indexIn(idstrEdit
->text()) < 0) {
212 QMessageBox::warning(this, "Network ID Error",
213 "Network ID String contains "
214 "non-word characters.\n"
215 "It must be a simple string, "
216 "without spaces, containing\n"
217 "only characters in this range: "
219 idstrEdit
->setFocus();
227 memset(reply
, 0, sizeof(reply
));
228 reply_len
= sizeof(reply
) - 1;
231 wpagui
->ctrlRequest("ADD_NETWORK", reply
, &reply_len
);
232 if (reply
[0] == 'F') {
233 QMessageBox::warning(this, "wpa_gui", "Failed to add "
234 "network to wpa_supplicant\n"
240 id
= edit_network_id
;
242 setNetworkParam(id
, "ssid", ssidEdit
->text().toAscii().constData(),
245 const char *key_mgmt
= NULL
, *proto
= NULL
, *pairwise
= NULL
;
249 case AUTH_NONE_WEP_SHARED
:
253 key_mgmt
= "IEEE8021X";
256 key_mgmt
= "WPA-PSK";
260 key_mgmt
= "WPA-EAP";
264 key_mgmt
= "WPA-PSK";
268 key_mgmt
= "WPA-EAP";
273 if (auth
== AUTH_NONE_WEP_SHARED
)
274 setNetworkParam(id
, "auth_alg", "SHARED", false);
276 setNetworkParam(id
, "auth_alg", "OPEN", false);
278 if (auth
== AUTH_WPA_PSK
|| auth
== AUTH_WPA_EAP
||
279 auth
== AUTH_WPA2_PSK
|| auth
== AUTH_WPA2_EAP
) {
280 int encr
= encrSelect
->currentIndex();
288 setNetworkParam(id
, "proto", proto
, false);
290 setNetworkParam(id
, "key_mgmt", key_mgmt
, false);
292 setNetworkParam(id
, "pairwise", pairwise
, false);
293 setNetworkParam(id
, "group", "TKIP CCMP WEP104 WEP40", false);
295 if (pskEdit
->isEnabled() &&
296 strcmp(pskEdit
->text().toAscii().constData(),
297 WPA_GUI_KEY_DATA
) != 0)
298 setNetworkParam(id
, "psk",
299 pskEdit
->text().toAscii().constData(),
301 if (eapSelect
->isEnabled()) {
303 eapSelect
->currentText().toAscii().constData();
304 setNetworkParam(id
, "eap", eap
, false);
305 if (strcmp(eap
, "SIM") == 0 || strcmp(eap
, "AKA") == 0)
306 setNetworkParam(id
, "pcsc", "", true);
308 setNetworkParam(id
, "pcsc", "NULL", false);
310 if (phase2Select
->isEnabled()) {
311 QString eap
= eapSelect
->currentText();
312 QString inner
= phase2Select
->currentText();
315 if (eap
.compare("PEAP") == 0) {
316 if (inner
.startsWith("EAP-"))
317 snprintf(phase2
, sizeof(phase2
), "auth=%s",
318 inner
.right(inner
.size() - 4).
319 toAscii().constData());
320 } else if (eap
.compare("TTLS") == 0) {
321 if (inner
.startsWith("EAP-"))
322 snprintf(phase2
, sizeof(phase2
), "autheap=%s",
323 inner
.right(inner
.size() - 4).
324 toAscii().constData());
326 snprintf(phase2
, sizeof(phase2
), "auth=%s",
327 inner
.toAscii().constData());
328 } else if (eap
.compare("FAST") == 0) {
329 const char *provisioning
= NULL
;
330 if (inner
.startsWith("EAP-")) {
331 snprintf(phase2
, sizeof(phase2
), "auth=%s",
332 inner
.right(inner
.size() - 4).
333 toAscii().constData());
334 provisioning
= "fast_provisioning=2";
335 } else if (inner
.compare("GTC(auth) + MSCHAPv2(prov)")
337 snprintf(phase2
, sizeof(phase2
),
338 "auth=GTC auth=MSCHAPV2");
339 provisioning
= "fast_provisioning=1";
341 provisioning
= "fast_provisioning=3";
344 setNetworkParam(id
, "phase1", provisioning
,
346 snprintf(blob
, sizeof(blob
),
347 "blob://fast-pac-%d", id
);
348 setNetworkParam(id
, "pac_file", blob
, true);
352 setNetworkParam(id
, "phase2", phase2
, true);
354 setNetworkParam(id
, "phase2", "NULL", false);
356 setNetworkParam(id
, "phase2", "NULL", false);
357 if (identityEdit
->isEnabled() && identityEdit
->text().length() > 0)
358 setNetworkParam(id
, "identity",
359 identityEdit
->text().toAscii().constData(),
362 setNetworkParam(id
, "identity", "NULL", false);
363 if (passwordEdit
->isEnabled() && passwordEdit
->text().length() > 0 &&
364 strcmp(passwordEdit
->text().toAscii().constData(),
365 WPA_GUI_KEY_DATA
) != 0)
366 setNetworkParam(id
, "password",
367 passwordEdit
->text().toAscii().constData(),
369 else if (passwordEdit
->text().length() == 0)
370 setNetworkParam(id
, "password", "NULL", false);
371 if (cacertEdit
->isEnabled() && cacertEdit
->text().length() > 0)
372 setNetworkParam(id
, "ca_cert",
373 cacertEdit
->text().toAscii().constData(),
376 setNetworkParam(id
, "ca_cert", "NULL", false);
377 writeWepKey(id
, wep0Edit
, 0);
378 writeWepKey(id
, wep1Edit
, 1);
379 writeWepKey(id
, wep2Edit
, 2);
380 writeWepKey(id
, wep3Edit
, 3);
382 if (wep0Radio
->isEnabled() && wep0Radio
->isChecked())
383 setNetworkParam(id
, "wep_tx_keyidx", "0", false);
384 else if (wep1Radio
->isEnabled() && wep1Radio
->isChecked())
385 setNetworkParam(id
, "wep_tx_keyidx", "1", false);
386 else if (wep2Radio
->isEnabled() && wep2Radio
->isChecked())
387 setNetworkParam(id
, "wep_tx_keyidx", "2", false);
388 else if (wep3Radio
->isEnabled() && wep3Radio
->isChecked())
389 setNetworkParam(id
, "wep_tx_keyidx", "3", false);
391 if (idstrEdit
->isEnabled() && idstrEdit
->text().length() > 0)
392 setNetworkParam(id
, "id_str",
393 idstrEdit
->text().toAscii().constData(),
396 setNetworkParam(id
, "id_str", "NULL", false);
398 if (prioritySpinBox
->isEnabled()) {
400 prio
= prio
.setNum(prioritySpinBox
->value());
401 setNetworkParam(id
, "priority", prio
.toAscii().constData(),
405 snprintf(cmd
, sizeof(cmd
), "ENABLE_NETWORK %d", id
);
406 reply_len
= sizeof(reply
);
407 wpagui
->ctrlRequest(cmd
, reply
, &reply_len
);
408 if (strncmp(reply
, "OK", 2) != 0) {
409 QMessageBox::warning(this, "wpa_gui", "Failed to enable "
410 "network in wpa_supplicant\n"
412 /* Network was added, so continue anyway */
414 wpagui
->triggerUpdate();
415 wpagui
->ctrlRequest("SAVE_CONFIG", reply
, &reply_len
);
421 void NetworkConfig::setWpaGui(WpaGui
*_wpagui
)
427 int NetworkConfig::setNetworkParam(int id
, const char *field
,
428 const char *value
, bool quote
)
430 char reply
[10], cmd
[256];
432 snprintf(cmd
, sizeof(cmd
), "SET_NETWORK %d %s %s%s%s",
433 id
, field
, quote
? "\"" : "", value
, quote
? "\"" : "");
434 reply_len
= sizeof(reply
);
435 wpagui
->ctrlRequest(cmd
, reply
, &reply_len
);
436 return strncmp(reply
, "OK", 2) == 0 ? 0 : -1;
440 void NetworkConfig::encrChanged(const QString
&)
445 void NetworkConfig::wepEnabled(bool enabled
)
447 wep0Edit
->setEnabled(enabled
);
448 wep1Edit
->setEnabled(enabled
);
449 wep2Edit
->setEnabled(enabled
);
450 wep3Edit
->setEnabled(enabled
);
451 wep0Radio
->setEnabled(enabled
);
452 wep1Radio
->setEnabled(enabled
);
453 wep2Radio
->setEnabled(enabled
);
454 wep3Radio
->setEnabled(enabled
);
458 void NetworkConfig::writeWepKey(int network_id
, QLineEdit
*edit
, int id
)
462 const char *txt
, *pos
;
465 if (!edit
->isEnabled() || edit
->text().isEmpty())
469 * Assume hex key if only hex characters are present and length matches
470 * with 40, 104, or 128-bit key
472 txt
= edit
->text().toAscii().constData();
473 if (strcmp(txt
, WPA_GUI_KEY_DATA
) == 0)
481 if (!((*pos
>= '0' && *pos
<= '9') ||
482 (*pos
>= 'a' && *pos
<= 'f') ||
483 (*pos
>= 'A' && *pos
<= 'F'))) {
489 if (hex
&& len
!= 10 && len
!= 26 && len
!= 32)
491 snprintf(buf
, sizeof(buf
), "wep_key%d", id
);
492 setNetworkParam(network_id
, buf
, txt
, !hex
);
496 static int key_value_isset(const char *reply
, size_t reply_len
)
498 return reply_len
> 0 && (reply_len
< 4 || memcmp(reply
, "FAIL", 4) != 0);
502 void NetworkConfig::paramsFromConfig(int network_id
)
506 edit_network_id
= network_id
;
509 char reply
[1024], cmd
[256], *pos
;
512 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d ssid", network_id
);
513 reply_len
= sizeof(reply
) - 1;
514 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0 &&
515 reply_len
>= 2 && reply
[0] == '"') {
516 reply
[reply_len
] = '\0';
517 pos
= strchr(reply
+ 1, '"');
520 ssidEdit
->setText(reply
+ 1);
523 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d proto", network_id
);
524 reply_len
= sizeof(reply
) - 1;
526 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0) {
527 reply
[reply_len
] = '\0';
528 if (strstr(reply
, "RSN") || strstr(reply
, "WPA2"))
530 else if (strstr(reply
, "WPA"))
534 int auth
= AUTH_NONE_OPEN
, encr
= 0;
535 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d key_mgmt", network_id
);
536 reply_len
= sizeof(reply
) - 1;
537 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0) {
538 reply
[reply_len
] = '\0';
539 if (strstr(reply
, "WPA-EAP"))
540 auth
= wpa
& 2 ? AUTH_WPA2_EAP
: AUTH_WPA_EAP
;
541 else if (strstr(reply
, "WPA-PSK"))
542 auth
= wpa
& 2 ? AUTH_WPA2_PSK
: AUTH_WPA_PSK
;
543 else if (strstr(reply
, "IEEE8021X")) {
544 auth
= AUTH_IEEE8021X
;
549 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d pairwise", network_id
);
550 reply_len
= sizeof(reply
) - 1;
551 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0) {
552 reply
[reply_len
] = '\0';
553 if (strstr(reply
, "CCMP") && auth
!= AUTH_NONE_OPEN
&&
554 auth
!= AUTH_NONE_WEP
&& auth
!= AUTH_NONE_WEP_SHARED
)
556 else if (strstr(reply
, "TKIP"))
558 else if (strstr(reply
, "WEP"))
564 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d psk", network_id
);
565 reply_len
= sizeof(reply
) - 1;
566 res
= wpagui
->ctrlRequest(cmd
, reply
, &reply_len
);
567 if (res
>= 0 && reply_len
>= 2 && reply
[0] == '"') {
568 reply
[reply_len
] = '\0';
569 pos
= strchr(reply
+ 1, '"');
572 pskEdit
->setText(reply
+ 1);
573 } else if (res
>= 0 && key_value_isset(reply
, reply_len
)) {
574 pskEdit
->setText(WPA_GUI_KEY_DATA
);
577 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d identity", network_id
);
578 reply_len
= sizeof(reply
) - 1;
579 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0 &&
580 reply_len
>= 2 && reply
[0] == '"') {
581 reply
[reply_len
] = '\0';
582 pos
= strchr(reply
+ 1, '"');
585 identityEdit
->setText(reply
+ 1);
588 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d password", network_id
);
589 reply_len
= sizeof(reply
) - 1;
590 res
= wpagui
->ctrlRequest(cmd
, reply
, &reply_len
);
591 if (res
>= 0 && reply_len
>= 2 && reply
[0] == '"') {
592 reply
[reply_len
] = '\0';
593 pos
= strchr(reply
+ 1, '"');
596 passwordEdit
->setText(reply
+ 1);
597 } else if (res
>= 0 && key_value_isset(reply
, reply_len
)) {
598 passwordEdit
->setText(WPA_GUI_KEY_DATA
);
601 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d ca_cert", network_id
);
602 reply_len
= sizeof(reply
) - 1;
603 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0 &&
604 reply_len
>= 2 && reply
[0] == '"') {
605 reply
[reply_len
] = '\0';
606 pos
= strchr(reply
+ 1, '"');
609 cacertEdit
->setText(reply
+ 1);
612 enum { NO_INNER
, PEAP_INNER
, TTLS_INNER
, FAST_INNER
} eap
= NO_INNER
;
613 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d eap", network_id
);
614 reply_len
= sizeof(reply
) - 1;
615 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0 &&
617 reply
[reply_len
] = '\0';
618 for (i
= 0; i
< eapSelect
->count(); i
++) {
619 if (eapSelect
->itemText(i
).compare(reply
) == 0) {
620 eapSelect
->setCurrentIndex(i
);
621 if (strcmp(reply
, "PEAP") == 0)
623 else if (strcmp(reply
, "TTLS") == 0)
625 else if (strcmp(reply
, "FAST") == 0)
632 if (eap
!= NO_INNER
) {
633 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d phase2",
635 reply_len
= sizeof(reply
) - 1;
636 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0 &&
638 reply
[reply_len
] = '\0';
639 eapChanged(eapSelect
->currentIndex());
653 if (strncmp(reply
, "\"auth=", 6))
656 memcpy(val
, "EAP-", 4);
659 if (strncmp(reply
, "\"autheap=", 9) == 0) {
661 memcpy(val
, "EAP-", 4);
662 } else if (strncmp(reply
, "\"auth=", 6) == 0)
666 if (strncmp(reply
, "\"auth=", 6))
668 if (strcmp(reply
+ 6, "GTC auth=MSCHAPV2") == 0) {
669 val
= (char *) "GTC(auth) + MSCHAPv2(prov)";
673 memcpy(val
, "EAP-", 4);
679 for (i
= 0; i
< phase2Select
->count(); i
++) {
680 if (phase2Select
->itemText(i
).compare(val
) == 0) {
681 phase2Select
->setCurrentIndex(i
);
686 for (i
= 0; i
< 4; i
++) {
703 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d wep_key%d",
705 reply_len
= sizeof(reply
) - 1;
706 res
= wpagui
->ctrlRequest(cmd
, reply
, &reply_len
);
707 if (res
>= 0 && reply_len
>= 2 && reply
[0] == '"') {
708 reply
[reply_len
] = '\0';
709 pos
= strchr(reply
+ 1, '"');
712 if (auth
== AUTH_NONE_OPEN
|| auth
== AUTH_IEEE8021X
) {
713 if (auth
== AUTH_NONE_OPEN
)
714 auth
= AUTH_NONE_WEP
;
718 wepEdit
->setText(reply
+ 1);
719 } else if (res
>= 0 && key_value_isset(reply
, reply_len
)) {
720 if (auth
== AUTH_NONE_OPEN
|| auth
== AUTH_IEEE8021X
) {
721 if (auth
== AUTH_NONE_OPEN
)
722 auth
= AUTH_NONE_WEP
;
725 wepEdit
->setText(WPA_GUI_KEY_DATA
);
729 if (auth
== AUTH_NONE_WEP
) {
730 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d auth_alg",
732 reply_len
= sizeof(reply
) - 1;
733 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0) {
734 reply
[reply_len
] = '\0';
735 if (strcmp(reply
, "SHARED") == 0)
736 auth
= AUTH_NONE_WEP_SHARED
;
740 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d wep_tx_keyidx", network_id
);
741 reply_len
= sizeof(reply
) - 1;
742 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0 && reply_len
>= 1)
744 reply
[reply_len
] = '\0';
745 switch (atoi(reply
)) {
747 wep0Radio
->setChecked(true);
750 wep1Radio
->setChecked(true);
753 wep2Radio
->setChecked(true);
756 wep3Radio
->setChecked(true);
761 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d id_str", network_id
);
762 reply_len
= sizeof(reply
) - 1;
763 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0 &&
764 reply_len
>= 2 && reply
[0] == '"') {
765 reply
[reply_len
] = '\0';
766 pos
= strchr(reply
+ 1, '"');
769 idstrEdit
->setText(reply
+ 1);
772 snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %d priority", network_id
);
773 reply_len
= sizeof(reply
) - 1;
774 if (wpagui
->ctrlRequest(cmd
, reply
, &reply_len
) >= 0 && reply_len
>= 1)
776 reply
[reply_len
] = '\0';
777 prioritySpinBox
->setValue(atoi(reply
));
780 authSelect
->setCurrentIndex(auth
);
782 encrSelect
->setCurrentIndex(encr
);
783 wepEnabled(auth
== AUTH_NONE_WEP
|| auth
== AUTH_NONE_WEP_SHARED
);
785 removeButton
->setEnabled(true);
786 addButton
->setText("Save");
790 void NetworkConfig::removeNetwork()
792 char reply
[10], cmd
[256];
795 if (QMessageBox::information(this, "wpa_gui",
796 "This will permanently remove the "
798 "from the configuration. Do you really "
800 "to remove this network?", "Yes", "No")
804 snprintf(cmd
, sizeof(cmd
), "REMOVE_NETWORK %d", edit_network_id
);
805 reply_len
= sizeof(reply
);
806 wpagui
->ctrlRequest(cmd
, reply
, &reply_len
);
807 if (strncmp(reply
, "OK", 2) != 0) {
808 QMessageBox::warning(this, "wpa_gui",
809 "Failed to remove network from "
813 wpagui
->triggerUpdate();
814 wpagui
->ctrlRequest("SAVE_CONFIG", reply
, &reply_len
);
821 void NetworkConfig::newNetwork()
828 void NetworkConfig::getEapCapa()
836 reply_len
= sizeof(reply
) - 1;
837 if (wpagui
->ctrlRequest("GET_CAPABILITY eap", reply
, &reply_len
) < 0)
839 reply
[reply_len
] = '\0';
842 QStringList types
= res
.split(QChar(' '));
843 eapSelect
->insertItems(-1, types
);
847 void NetworkConfig::useWps()
851 wpagui
->setBssFromScan(bssid
);