00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include <cstdio>
00016 #include <QMessageBox>
00017
00018 #include "networkconfig.h"
00019 #include "wpagui.h"
00020
00021 enum {
00022 AUTH_NONE_OPEN,
00023 AUTH_NONE_WEP,
00024 AUTH_NONE_WEP_SHARED,
00025 AUTH_IEEE8021X,
00026 AUTH_WPA_PSK,
00027 AUTH_WPA_EAP,
00028 AUTH_WPA2_PSK,
00029 AUTH_WPA2_EAP
00030 };
00031
00032 #define WPA_GUI_KEY_DATA "[key is configured]"
00033
00034
00035 NetworkConfig::NetworkConfig(QWidget *parent, const char *, bool, Qt::WFlags)
00036 : QDialog(parent)
00037 {
00038 setupUi(this);
00039
00040 encrSelect->setEnabled(false);
00041 connect(authSelect, SIGNAL(activated(int)), this,
00042 SLOT(authChanged(int)));
00043 connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
00044 connect(addButton, SIGNAL(clicked()), this, SLOT(addNetwork()));
00045 connect(encrSelect, SIGNAL(activated(const QString &)), this,
00046 SLOT(encrChanged(const QString &)));
00047 connect(removeButton, SIGNAL(clicked()), this, SLOT(removeNetwork()));
00048 connect(eapSelect, SIGNAL(activated(int)), this,
00049 SLOT(eapChanged(int)));
00050 connect(useWpsButton, SIGNAL(clicked()), this, SLOT(useWps()));
00051
00052 wpagui = NULL;
00053 new_network = false;
00054 }
00055
00056
00057 NetworkConfig::~NetworkConfig()
00058 {
00059 }
00060
00061
00062 void NetworkConfig::languageChange()
00063 {
00064 retranslateUi(this);
00065 }
00066
00067
00068 void NetworkConfig::paramsFromScanResults(QTreeWidgetItem *sel)
00069 {
00070 new_network = true;
00071
00072
00073 setWindowTitle(sel->text(0));
00074 ssidEdit->setText(sel->text(0));
00075
00076 QString flags = sel->text(4);
00077 int auth, encr = 0;
00078 if (flags.indexOf("[WPA2-EAP") >= 0)
00079 auth = AUTH_WPA2_EAP;
00080 else if (flags.indexOf("[WPA-EAP") >= 0)
00081 auth = AUTH_WPA_EAP;
00082 else if (flags.indexOf("[WPA2-PSK") >= 0)
00083 auth = AUTH_WPA2_PSK;
00084 else if (flags.indexOf("[WPA-PSK") >= 0)
00085 auth = AUTH_WPA_PSK;
00086 else
00087 auth = AUTH_NONE_OPEN;
00088
00089 if (flags.indexOf("-CCMP") >= 0)
00090 encr = 1;
00091 else if (flags.indexOf("-TKIP") >= 0)
00092 encr = 0;
00093 else if (flags.indexOf("WEP") >= 0) {
00094 encr = 1;
00095 if (auth == AUTH_NONE_OPEN)
00096 auth = AUTH_NONE_WEP;
00097 } else
00098 encr = 0;
00099
00100 authSelect->setCurrentIndex(auth);
00101 authChanged(auth);
00102 encrSelect->setCurrentIndex(encr);
00103
00104 wepEnabled(auth == AUTH_NONE_WEP);
00105
00106 getEapCapa();
00107
00108 if (flags.indexOf("[WPS") >= 0)
00109 useWpsButton->setEnabled(true);
00110 bssid = sel->text(1);
00111 }
00112
00113
00114 void NetworkConfig::authChanged(int sel)
00115 {
00116 encrSelect->setEnabled(sel != AUTH_NONE_OPEN && sel != AUTH_NONE_WEP &&
00117 sel != AUTH_NONE_WEP_SHARED);
00118 pskEdit->setEnabled(sel == AUTH_WPA_PSK || sel == AUTH_WPA2_PSK);
00119 bool eap = sel == AUTH_IEEE8021X || sel == AUTH_WPA_EAP ||
00120 sel == AUTH_WPA2_EAP;
00121 eapSelect->setEnabled(eap);
00122 identityEdit->setEnabled(eap);
00123 passwordEdit->setEnabled(eap);
00124 cacertEdit->setEnabled(eap);
00125 phase2Select->setEnabled(eap);
00126 if (eap)
00127 eapChanged(eapSelect->currentIndex());
00128
00129 while (encrSelect->count())
00130 encrSelect->removeItem(0);
00131
00132 if (sel == AUTH_NONE_OPEN || sel == AUTH_NONE_WEP ||
00133 sel == AUTH_NONE_WEP_SHARED || sel == AUTH_IEEE8021X) {
00134 encrSelect->addItem("None");
00135 encrSelect->addItem("WEP");
00136 encrSelect->setCurrentIndex(sel == AUTH_NONE_OPEN ? 0 : 1);
00137 } else {
00138 encrSelect->addItem("TKIP");
00139 encrSelect->addItem("CCMP");
00140 encrSelect->setCurrentIndex((sel == AUTH_WPA2_PSK ||
00141 sel == AUTH_WPA2_EAP) ? 1 : 0);
00142 }
00143
00144 wepEnabled(sel == AUTH_NONE_WEP || sel == AUTH_NONE_WEP_SHARED);
00145 }
00146
00147
00148 void NetworkConfig::eapChanged(int sel)
00149 {
00150 QString prev_val = phase2Select->currentText();
00151 while (phase2Select->count())
00152 phase2Select->removeItem(0);
00153
00154 QStringList inner;
00155 inner << "PEAP" << "TTLS" << "FAST";
00156 if (!inner.contains(eapSelect->itemText(sel)))
00157 return;
00158
00159 phase2Select->addItem("[ any ]");
00160
00161
00162 if (eapSelect->currentText().compare("TTLS") == 0) {
00163 phase2Select->addItem("PAP");
00164 phase2Select->addItem("CHAP");
00165 phase2Select->addItem("MSCHAP");
00166 phase2Select->addItem("MSCHAPv2");
00167 } else if (eapSelect->currentText().compare("FAST") == 0)
00168 phase2Select->addItem("GTC(auth) + MSCHAPv2(prov)");
00169
00170
00171 int i;
00172 QStringList allowed;
00173 allowed << "MSCHAPV2" << "MD5" << "GTC" << "TLS" << "OTP" << "SIM"
00174 << "AKA";
00175 for (i = 0; i < eapSelect->count(); i++) {
00176 if (allowed.contains(eapSelect->itemText(i))) {
00177 phase2Select->addItem("EAP-" + eapSelect->itemText(i));
00178 }
00179 }
00180
00181 for (i = 0; i < phase2Select->count(); i++) {
00182 if (phase2Select->itemText(i).compare(prev_val) == 0) {
00183 phase2Select->setCurrentIndex(i);
00184 break;
00185 }
00186 }
00187 }
00188
00189
00190 void NetworkConfig::addNetwork()
00191 {
00192 char reply[10], cmd[256];
00193 size_t reply_len;
00194 int id;
00195 int psklen = pskEdit->text().length();
00196 int auth = authSelect->currentIndex();
00197
00198 if (auth == AUTH_WPA_PSK || auth == AUTH_WPA2_PSK) {
00199 if (psklen < 8 || psklen > 64) {
00200 QMessageBox::warning(
00201 this,
00202 tr("WPA Pre-Shared Key Error"),
00203 tr("WPA-PSK requires a passphrase of 8 to 63 "
00204 "characters\n"
00205 "or 64 hex digit PSK"));
00206 pskEdit->setFocus();
00207 return;
00208 }
00209 }
00210
00211 if (idstrEdit->isEnabled() && !idstrEdit->text().isEmpty()) {
00212 QRegExp rx("^(\\w|-)+$");
00213 if (rx.indexIn(idstrEdit->text()) < 0) {
00214 QMessageBox::warning(
00215 this, tr("Network ID Error"),
00216 tr("Network ID String contains non-word "
00217 "characters.\n"
00218 "It must be a simple string, "
00219 "without spaces, containing\n"
00220 "only characters in this range: "
00221 "[A-Za-z0-9_-]\n"));
00222 idstrEdit->setFocus();
00223 return;
00224 }
00225 }
00226
00227 if (wpagui == NULL)
00228 return;
00229
00230 memset(reply, 0, sizeof(reply));
00231 reply_len = sizeof(reply) - 1;
00232
00233 if (new_network) {
00234 wpagui->ctrlRequest("ADD_NETWORK", reply, &reply_len);
00235 if (reply[0] == 'F') {
00236 QMessageBox::warning(this, "wpa_gui",
00237 tr("Failed to add "
00238 "network to wpa_supplicant\n"
00239 "configuration."));
00240 return;
00241 }
00242 id = atoi(reply);
00243 } else
00244 id = edit_network_id;
00245
00246 setNetworkParam(id, "ssid", ssidEdit->text().toAscii().constData(),
00247 true);
00248
00249 const char *key_mgmt = NULL, *proto = NULL, *pairwise = NULL;
00250 switch (auth) {
00251 case AUTH_NONE_OPEN:
00252 case AUTH_NONE_WEP:
00253 case AUTH_NONE_WEP_SHARED:
00254 key_mgmt = "NONE";
00255 break;
00256 case AUTH_IEEE8021X:
00257 key_mgmt = "IEEE8021X";
00258 break;
00259 case AUTH_WPA_PSK:
00260 key_mgmt = "WPA-PSK";
00261 proto = "WPA";
00262 break;
00263 case AUTH_WPA_EAP:
00264 key_mgmt = "WPA-EAP";
00265 proto = "WPA";
00266 break;
00267 case AUTH_WPA2_PSK:
00268 key_mgmt = "WPA-PSK";
00269 proto = "WPA2";
00270 break;
00271 case AUTH_WPA2_EAP:
00272 key_mgmt = "WPA-EAP";
00273 proto = "WPA2";
00274 break;
00275 }
00276
00277 if (auth == AUTH_NONE_WEP_SHARED)
00278 setNetworkParam(id, "auth_alg", "SHARED", false);
00279 else
00280 setNetworkParam(id, "auth_alg", "OPEN", false);
00281
00282 if (auth == AUTH_WPA_PSK || auth == AUTH_WPA_EAP ||
00283 auth == AUTH_WPA2_PSK || auth == AUTH_WPA2_EAP) {
00284 int encr = encrSelect->currentIndex();
00285 if (encr == 0)
00286 pairwise = "TKIP";
00287 else
00288 pairwise = "CCMP";
00289 }
00290
00291 if (proto)
00292 setNetworkParam(id, "proto", proto, false);
00293 if (key_mgmt)
00294 setNetworkParam(id, "key_mgmt", key_mgmt, false);
00295 if (pairwise) {
00296 setNetworkParam(id, "pairwise", pairwise, false);
00297 setNetworkParam(id, "group", "TKIP CCMP WEP104 WEP40", false);
00298 }
00299 if (pskEdit->isEnabled() &&
00300 strcmp(pskEdit->text().toAscii().constData(),
00301 WPA_GUI_KEY_DATA) != 0)
00302 setNetworkParam(id, "psk",
00303 pskEdit->text().toAscii().constData(),
00304 psklen != 64);
00305 if (eapSelect->isEnabled()) {
00306 const char *eap =
00307 eapSelect->currentText().toAscii().constData();
00308 setNetworkParam(id, "eap", eap, false);
00309 if (strcmp(eap, "SIM") == 0 || strcmp(eap, "AKA") == 0)
00310 setNetworkParam(id, "pcsc", "", true);
00311 else
00312 setNetworkParam(id, "pcsc", "NULL", false);
00313 }
00314 if (phase2Select->isEnabled()) {
00315 QString eap = eapSelect->currentText();
00316 QString inner = phase2Select->currentText();
00317 char phase2[32];
00318 phase2[0] = '\0';
00319 if (eap.compare("PEAP") == 0) {
00320 if (inner.startsWith("EAP-"))
00321 snprintf(phase2, sizeof(phase2), "auth=%s",
00322 inner.right(inner.size() - 4).
00323 toAscii().constData());
00324 } else if (eap.compare("TTLS") == 0) {
00325 if (inner.startsWith("EAP-"))
00326 snprintf(phase2, sizeof(phase2), "autheap=%s",
00327 inner.right(inner.size() - 4).
00328 toAscii().constData());
00329 else
00330 snprintf(phase2, sizeof(phase2), "auth=%s",
00331 inner.toAscii().constData());
00332 } else if (eap.compare("FAST") == 0) {
00333 const char *provisioning = NULL;
00334 if (inner.startsWith("EAP-")) {
00335 snprintf(phase2, sizeof(phase2), "auth=%s",
00336 inner.right(inner.size() - 4).
00337 toAscii().constData());
00338 provisioning = "fast_provisioning=2";
00339 } else if (inner.compare("GTC(auth) + MSCHAPv2(prov)")
00340 == 0) {
00341 snprintf(phase2, sizeof(phase2),
00342 "auth=GTC auth=MSCHAPV2");
00343 provisioning = "fast_provisioning=1";
00344 } else
00345 provisioning = "fast_provisioning=3";
00346 if (provisioning) {
00347 char blob[32];
00348 setNetworkParam(id, "phase1", provisioning,
00349 true);
00350 snprintf(blob, sizeof(blob),
00351 "blob://fast-pac-%d", id);
00352 setNetworkParam(id, "pac_file", blob, true);
00353 }
00354 }
00355 if (phase2[0])
00356 setNetworkParam(id, "phase2", phase2, true);
00357 else
00358 setNetworkParam(id, "phase2", "NULL", false);
00359 } else
00360 setNetworkParam(id, "phase2", "NULL", false);
00361 if (identityEdit->isEnabled() && identityEdit->text().length() > 0)
00362 setNetworkParam(id, "identity",
00363 identityEdit->text().toAscii().constData(),
00364 true);
00365 else
00366 setNetworkParam(id, "identity", "NULL", false);
00367 if (passwordEdit->isEnabled() && passwordEdit->text().length() > 0 &&
00368 strcmp(passwordEdit->text().toAscii().constData(),
00369 WPA_GUI_KEY_DATA) != 0)
00370 setNetworkParam(id, "password",
00371 passwordEdit->text().toAscii().constData(),
00372 true);
00373 else if (passwordEdit->text().length() == 0)
00374 setNetworkParam(id, "password", "NULL", false);
00375 if (cacertEdit->isEnabled() && cacertEdit->text().length() > 0)
00376 setNetworkParam(id, "ca_cert",
00377 cacertEdit->text().toAscii().constData(),
00378 true);
00379 else
00380 setNetworkParam(id, "ca_cert", "NULL", false);
00381 writeWepKey(id, wep0Edit, 0);
00382 writeWepKey(id, wep1Edit, 1);
00383 writeWepKey(id, wep2Edit, 2);
00384 writeWepKey(id, wep3Edit, 3);
00385
00386 if (wep0Radio->isEnabled() && wep0Radio->isChecked())
00387 setNetworkParam(id, "wep_tx_keyidx", "0", false);
00388 else if (wep1Radio->isEnabled() && wep1Radio->isChecked())
00389 setNetworkParam(id, "wep_tx_keyidx", "1", false);
00390 else if (wep2Radio->isEnabled() && wep2Radio->isChecked())
00391 setNetworkParam(id, "wep_tx_keyidx", "2", false);
00392 else if (wep3Radio->isEnabled() && wep3Radio->isChecked())
00393 setNetworkParam(id, "wep_tx_keyidx", "3", false);
00394
00395 if (idstrEdit->isEnabled() && idstrEdit->text().length() > 0)
00396 setNetworkParam(id, "id_str",
00397 idstrEdit->text().toAscii().constData(),
00398 true);
00399 else
00400 setNetworkParam(id, "id_str", "NULL", false);
00401
00402 if (prioritySpinBox->isEnabled()) {
00403 QString prio;
00404 prio = prio.setNum(prioritySpinBox->value());
00405 setNetworkParam(id, "priority", prio.toAscii().constData(),
00406 false);
00407 }
00408
00409 snprintf(cmd, sizeof(cmd), "ENABLE_NETWORK %d", id);
00410 reply_len = sizeof(reply);
00411 wpagui->ctrlRequest(cmd, reply, &reply_len);
00412 if (strncmp(reply, "OK", 2) != 0) {
00413 QMessageBox::warning(this, "wpa_gui",
00414 tr("Failed to enable "
00415 "network in wpa_supplicant\n"
00416 "configuration."));
00417
00418 }
00419 wpagui->triggerUpdate();
00420 wpagui->ctrlRequest("SAVE_CONFIG", reply, &reply_len);
00421
00422 close();
00423 }
00424
00425
00426 void NetworkConfig::setWpaGui(WpaGui *_wpagui)
00427 {
00428 wpagui = _wpagui;
00429 }
00430
00431
00432 int NetworkConfig::setNetworkParam(int id, const char *field,
00433 const char *value, bool quote)
00434 {
00435 char reply[10], cmd[256];
00436 size_t reply_len;
00437 snprintf(cmd, sizeof(cmd), "SET_NETWORK %d %s %s%s%s",
00438 id, field, quote ? "\"" : "", value, quote ? "\"" : "");
00439 reply_len = sizeof(reply);
00440 wpagui->ctrlRequest(cmd, reply, &reply_len);
00441 return strncmp(reply, "OK", 2) == 0 ? 0 : -1;
00442 }
00443
00444
00445 void NetworkConfig::encrChanged(const QString &)
00446 {
00447 }
00448
00449
00450 void NetworkConfig::wepEnabled(bool enabled)
00451 {
00452 wep0Edit->setEnabled(enabled);
00453 wep1Edit->setEnabled(enabled);
00454 wep2Edit->setEnabled(enabled);
00455 wep3Edit->setEnabled(enabled);
00456 wep0Radio->setEnabled(enabled);
00457 wep1Radio->setEnabled(enabled);
00458 wep2Radio->setEnabled(enabled);
00459 wep3Radio->setEnabled(enabled);
00460 }
00461
00462
00463 void NetworkConfig::writeWepKey(int network_id, QLineEdit *edit, int id)
00464 {
00465 char buf[10];
00466 bool hex;
00467 const char *txt, *pos;
00468 size_t len;
00469
00470 if (!edit->isEnabled() || edit->text().isEmpty())
00471 return;
00472
00473
00474
00475
00476
00477 txt = edit->text().toAscii().constData();
00478 if (strcmp(txt, WPA_GUI_KEY_DATA) == 0)
00479 return;
00480 len = strlen(txt);
00481 if (len == 0)
00482 return;
00483 pos = txt;
00484 hex = true;
00485 while (*pos) {
00486 if (!((*pos >= '0' && *pos <= '9') ||
00487 (*pos >= 'a' && *pos <= 'f') ||
00488 (*pos >= 'A' && *pos <= 'F'))) {
00489 hex = false;
00490 break;
00491 }
00492 pos++;
00493 }
00494 if (hex && len != 10 && len != 26 && len != 32)
00495 hex = false;
00496 snprintf(buf, sizeof(buf), "wep_key%d", id);
00497 setNetworkParam(network_id, buf, txt, !hex);
00498 }
00499
00500
00501 static int key_value_isset(const char *reply, size_t reply_len)
00502 {
00503 return reply_len > 0 && (reply_len < 4 || memcmp(reply, "FAIL", 4) != 0);
00504 }
00505
00506
00507 void NetworkConfig::paramsFromConfig(int network_id)
00508 {
00509 int i, res;
00510
00511 edit_network_id = network_id;
00512 getEapCapa();
00513
00514 char reply[1024], cmd[256], *pos;
00515 size_t reply_len;
00516
00517 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d ssid", network_id);
00518 reply_len = sizeof(reply) - 1;
00519 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 &&
00520 reply_len >= 2 && reply[0] == '"') {
00521 reply[reply_len] = '\0';
00522 pos = strchr(reply + 1, '"');
00523 if (pos)
00524 *pos = '\0';
00525 ssidEdit->setText(reply + 1);
00526 }
00527
00528 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d proto", network_id);
00529 reply_len = sizeof(reply) - 1;
00530 int wpa = 0;
00531 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
00532 reply[reply_len] = '\0';
00533 if (strstr(reply, "RSN") || strstr(reply, "WPA2"))
00534 wpa = 2;
00535 else if (strstr(reply, "WPA"))
00536 wpa = 1;
00537 }
00538
00539 int auth = AUTH_NONE_OPEN, encr = 0;
00540 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d key_mgmt", network_id);
00541 reply_len = sizeof(reply) - 1;
00542 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
00543 reply[reply_len] = '\0';
00544 if (strstr(reply, "WPA-EAP"))
00545 auth = wpa & 2 ? AUTH_WPA2_EAP : AUTH_WPA_EAP;
00546 else if (strstr(reply, "WPA-PSK"))
00547 auth = wpa & 2 ? AUTH_WPA2_PSK : AUTH_WPA_PSK;
00548 else if (strstr(reply, "IEEE8021X")) {
00549 auth = AUTH_IEEE8021X;
00550 encr = 1;
00551 }
00552 }
00553
00554 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d pairwise", network_id);
00555 reply_len = sizeof(reply) - 1;
00556 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
00557 reply[reply_len] = '\0';
00558 if (strstr(reply, "CCMP") && auth != AUTH_NONE_OPEN &&
00559 auth != AUTH_NONE_WEP && auth != AUTH_NONE_WEP_SHARED)
00560 encr = 1;
00561 else if (strstr(reply, "TKIP"))
00562 encr = 0;
00563 else if (strstr(reply, "WEP"))
00564 encr = 1;
00565 else
00566 encr = 0;
00567 }
00568
00569 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d psk", network_id);
00570 reply_len = sizeof(reply) - 1;
00571 res = wpagui->ctrlRequest(cmd, reply, &reply_len);
00572 if (res >= 0 && reply_len >= 2 && reply[0] == '"') {
00573 reply[reply_len] = '\0';
00574 pos = strchr(reply + 1, '"');
00575 if (pos)
00576 *pos = '\0';
00577 pskEdit->setText(reply + 1);
00578 } else if (res >= 0 && key_value_isset(reply, reply_len)) {
00579 pskEdit->setText(WPA_GUI_KEY_DATA);
00580 }
00581
00582 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d identity", network_id);
00583 reply_len = sizeof(reply) - 1;
00584 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 &&
00585 reply_len >= 2 && reply[0] == '"') {
00586 reply[reply_len] = '\0';
00587 pos = strchr(reply + 1, '"');
00588 if (pos)
00589 *pos = '\0';
00590 identityEdit->setText(reply + 1);
00591 }
00592
00593 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d password", network_id);
00594 reply_len = sizeof(reply) - 1;
00595 res = wpagui->ctrlRequest(cmd, reply, &reply_len);
00596 if (res >= 0 && reply_len >= 2 && reply[0] == '"') {
00597 reply[reply_len] = '\0';
00598 pos = strchr(reply + 1, '"');
00599 if (pos)
00600 *pos = '\0';
00601 passwordEdit->setText(reply + 1);
00602 } else if (res >= 0 && key_value_isset(reply, reply_len)) {
00603 passwordEdit->setText(WPA_GUI_KEY_DATA);
00604 }
00605
00606 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d ca_cert", network_id);
00607 reply_len = sizeof(reply) - 1;
00608 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 &&
00609 reply_len >= 2 && reply[0] == '"') {
00610 reply[reply_len] = '\0';
00611 pos = strchr(reply + 1, '"');
00612 if (pos)
00613 *pos = '\0';
00614 cacertEdit->setText(reply + 1);
00615 }
00616
00617 enum { NO_INNER, PEAP_INNER, TTLS_INNER, FAST_INNER } eap = NO_INNER;
00618 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d eap", network_id);
00619 reply_len = sizeof(reply) - 1;
00620 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 &&
00621 reply_len >= 1) {
00622 reply[reply_len] = '\0';
00623 for (i = 0; i < eapSelect->count(); i++) {
00624 if (eapSelect->itemText(i).compare(reply) == 0) {
00625 eapSelect->setCurrentIndex(i);
00626 if (strcmp(reply, "PEAP") == 0)
00627 eap = PEAP_INNER;
00628 else if (strcmp(reply, "TTLS") == 0)
00629 eap = TTLS_INNER;
00630 else if (strcmp(reply, "FAST") == 0)
00631 eap = FAST_INNER;
00632 break;
00633 }
00634 }
00635 }
00636
00637 if (eap != NO_INNER) {
00638 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d phase2",
00639 network_id);
00640 reply_len = sizeof(reply) - 1;
00641 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 &&
00642 reply_len >= 1) {
00643 reply[reply_len] = '\0';
00644 eapChanged(eapSelect->currentIndex());
00645 } else
00646 eap = NO_INNER;
00647 }
00648
00649 char *val;
00650 val = reply + 1;
00651 while (*(val + 1))
00652 val++;
00653 if (*val == '"')
00654 *val = '\0';
00655
00656 switch (eap) {
00657 case PEAP_INNER:
00658 if (strncmp(reply, "\"auth=", 6))
00659 break;
00660 val = reply + 2;
00661 memcpy(val, "EAP-", 4);
00662 break;
00663 case TTLS_INNER:
00664 if (strncmp(reply, "\"autheap=", 9) == 0) {
00665 val = reply + 5;
00666 memcpy(val, "EAP-", 4);
00667 } else if (strncmp(reply, "\"auth=", 6) == 0)
00668 val = reply + 6;
00669 break;
00670 case FAST_INNER:
00671 if (strncmp(reply, "\"auth=", 6))
00672 break;
00673 if (strcmp(reply + 6, "GTC auth=MSCHAPV2") == 0) {
00674 val = (char *) "GTC(auth) + MSCHAPv2(prov)";
00675 break;
00676 }
00677 val = reply + 2;
00678 memcpy(val, "EAP-", 4);
00679 break;
00680 case NO_INNER:
00681 break;
00682 }
00683
00684 for (i = 0; i < phase2Select->count(); i++) {
00685 if (phase2Select->itemText(i).compare(val) == 0) {
00686 phase2Select->setCurrentIndex(i);
00687 break;
00688 }
00689 }
00690
00691 for (i = 0; i < 4; i++) {
00692 QLineEdit *wepEdit;
00693 switch (i) {
00694 default:
00695 case 0:
00696 wepEdit = wep0Edit;
00697 break;
00698 case 1:
00699 wepEdit = wep1Edit;
00700 break;
00701 case 2:
00702 wepEdit = wep2Edit;
00703 break;
00704 case 3:
00705 wepEdit = wep3Edit;
00706 break;
00707 }
00708 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d wep_key%d",
00709 network_id, i);
00710 reply_len = sizeof(reply) - 1;
00711 res = wpagui->ctrlRequest(cmd, reply, &reply_len);
00712 if (res >= 0 && reply_len >= 2 && reply[0] == '"') {
00713 reply[reply_len] = '\0';
00714 pos = strchr(reply + 1, '"');
00715 if (pos)
00716 *pos = '\0';
00717 if (auth == AUTH_NONE_OPEN || auth == AUTH_IEEE8021X) {
00718 if (auth == AUTH_NONE_OPEN)
00719 auth = AUTH_NONE_WEP;
00720 encr = 1;
00721 }
00722
00723 wepEdit->setText(reply + 1);
00724 } else if (res >= 0 && key_value_isset(reply, reply_len)) {
00725 if (auth == AUTH_NONE_OPEN || auth == AUTH_IEEE8021X) {
00726 if (auth == AUTH_NONE_OPEN)
00727 auth = AUTH_NONE_WEP;
00728 encr = 1;
00729 }
00730 wepEdit->setText(WPA_GUI_KEY_DATA);
00731 }
00732 }
00733
00734 if (auth == AUTH_NONE_WEP) {
00735 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d auth_alg",
00736 network_id);
00737 reply_len = sizeof(reply) - 1;
00738 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0) {
00739 reply[reply_len] = '\0';
00740 if (strcmp(reply, "SHARED") == 0)
00741 auth = AUTH_NONE_WEP_SHARED;
00742 }
00743 }
00744
00745 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d wep_tx_keyidx", network_id);
00746 reply_len = sizeof(reply) - 1;
00747 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1)
00748 {
00749 reply[reply_len] = '\0';
00750 switch (atoi(reply)) {
00751 case 0:
00752 wep0Radio->setChecked(true);
00753 break;
00754 case 1:
00755 wep1Radio->setChecked(true);
00756 break;
00757 case 2:
00758 wep2Radio->setChecked(true);
00759 break;
00760 case 3:
00761 wep3Radio->setChecked(true);
00762 break;
00763 }
00764 }
00765
00766 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d id_str", network_id);
00767 reply_len = sizeof(reply) - 1;
00768 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 &&
00769 reply_len >= 2 && reply[0] == '"') {
00770 reply[reply_len] = '\0';
00771 pos = strchr(reply + 1, '"');
00772 if (pos)
00773 *pos = '\0';
00774 idstrEdit->setText(reply + 1);
00775 }
00776
00777 snprintf(cmd, sizeof(cmd), "GET_NETWORK %d priority", network_id);
00778 reply_len = sizeof(reply) - 1;
00779 if (wpagui->ctrlRequest(cmd, reply, &reply_len) >= 0 && reply_len >= 1)
00780 {
00781 reply[reply_len] = '\0';
00782 prioritySpinBox->setValue(atoi(reply));
00783 }
00784
00785 authSelect->setCurrentIndex(auth);
00786 authChanged(auth);
00787 encrSelect->setCurrentIndex(encr);
00788 wepEnabled(auth == AUTH_NONE_WEP || auth == AUTH_NONE_WEP_SHARED);
00789
00790 removeButton->setEnabled(true);
00791 addButton->setText("Save");
00792 }
00793
00794
00795 void NetworkConfig::removeNetwork()
00796 {
00797 char reply[10], cmd[256];
00798 size_t reply_len;
00799
00800 if (QMessageBox::information(
00801 this, "wpa_gui",
00802 tr("This will permanently remove the network\n"
00803 "from the configuration. Do you really want\n"
00804 "to remove this network?"),
00805 tr("Yes"), tr("No")) != 0)
00806 return;
00807
00808 snprintf(cmd, sizeof(cmd), "REMOVE_NETWORK %d", edit_network_id);
00809 reply_len = sizeof(reply);
00810 wpagui->ctrlRequest(cmd, reply, &reply_len);
00811 if (strncmp(reply, "OK", 2) != 0) {
00812 QMessageBox::warning(this, "wpa_gui",
00813 tr("Failed to remove network from "
00814 "wpa_supplicant\n"
00815 "configuration."));
00816 } else {
00817 wpagui->triggerUpdate();
00818 wpagui->ctrlRequest("SAVE_CONFIG", reply, &reply_len);
00819 }
00820
00821 close();
00822 }
00823
00824
00825 void NetworkConfig::newNetwork()
00826 {
00827 new_network = true;
00828 getEapCapa();
00829 }
00830
00831
00832 void NetworkConfig::getEapCapa()
00833 {
00834 char reply[256];
00835 size_t reply_len;
00836
00837 if (wpagui == NULL)
00838 return;
00839
00840 reply_len = sizeof(reply) - 1;
00841 if (wpagui->ctrlRequest("GET_CAPABILITY eap", reply, &reply_len) < 0)
00842 return;
00843 reply[reply_len] = '\0';
00844
00845 QString res(reply);
00846 QStringList types = res.split(QChar(' '));
00847 eapSelect->insertItems(-1, types);
00848 }
00849
00850
00851 void NetworkConfig::useWps()
00852 {
00853 if (wpagui == NULL)
00854 return;
00855 wpagui->setBssFromScan(bssid);
00856 wpagui->wpsDialog();
00857 close();
00858 }