void NetworkConfig::writeWepKey(int network_id, QLineEdit *edit, int id) { char buf[10]; bool hex; const char *txt, *pos; size_t len; if (!edit->isEnabled() || edit->text().isEmpty()) return; /* * Assume hex key if only hex characters are present and length matches * with 40, 104, or 128-bit key */ txt = edit->text().ascii(); if (strcmp(txt, WPA_GUI_KEY_DATA) == 0) return; len = strlen(txt); if (len == 0) return; pos = txt; hex = true; while (*pos) { if (!((*pos >= '0' && *pos <= '9') || (*pos >= 'a' && *pos <= 'f') || (*pos >= 'A' && *pos <= 'F'))) { hex = false; break; } pos++; } if (hex && len != 10 && len != 26 && len != 32) hex = false; snprintf(buf, sizeof(buf), "wep_key%d", id); setNetworkParam(network_id, buf, txt, !hex); }
void NetworkConfig::addNetwork() { char reply[10], cmd[256]; size_t reply_len; int id; int psklen = pskEdit->text().length(); int auth = authSelect->currentItem(); if (auth == AUTH_WPA_PSK || auth == AUTH_WPA2_PSK) { if (psklen < 8 || psklen > 64) { QMessageBox::warning(this, "wpa_gui", "WPA-PSK requires a passphrase " "of 8 to 63 characters\n" "or 64 hex digit PSK"); return; } } if (wpagui == NULL) return; memset(reply, 0, sizeof(reply)); reply_len = sizeof(reply) - 1; if (new_network) { wpagui->ctrlRequest("ADD_NETWORK", reply, &reply_len); if (reply[0] == 'F') { QMessageBox::warning(this, "wpa_gui", "Failed to add " "network to wpa_supplicant\n" "configuration."); return; } id = atoi(reply); } else id = edit_network_id; setNetworkParam(id, "ssid", ssidEdit->text().ascii(), true); const char *key_mgmt = NULL, *proto = NULL, *pairwise = NULL; switch (auth) { case AUTH_NONE: key_mgmt = "NONE"; break; case AUTH_IEEE8021X: key_mgmt = "IEEE8021X"; break; case AUTH_WPA_PSK: key_mgmt = "WPA-PSK"; proto = "WPA"; break; case AUTH_WPA_EAP: key_mgmt = "WPA-EAP"; proto = "WPA"; break; case AUTH_WPA2_PSK: key_mgmt = "WPA-PSK"; proto = "WPA2"; break; case AUTH_WPA2_EAP: key_mgmt = "WPA-EAP"; proto = "WPA2"; break; } if (auth == AUTH_WPA_PSK || auth == AUTH_WPA_EAP || auth == AUTH_WPA2_PSK || auth == AUTH_WPA2_EAP) { int encr = encrSelect->currentItem(); if (encr == 0) pairwise = "TKIP"; else pairwise = "CCMP"; } if (proto) setNetworkParam(id, "proto", proto, false); if (key_mgmt) setNetworkParam(id, "key_mgmt", key_mgmt, false); if (pairwise) { setNetworkParam(id, "pairwise", pairwise, false); setNetworkParam(id, "group", "TKIP CCMP WEP104 WEP40", false); } if (pskEdit->isEnabled() && strcmp(passwordEdit->text().ascii(), WPA_GUI_KEY_DATA) != 0) setNetworkParam(id, "psk", pskEdit->text().ascii(), psklen != 64); if (eapSelect->isEnabled()) setNetworkParam(id, "eap", eapSelect->currentText().ascii(), false); if (identityEdit->isEnabled()) setNetworkParam(id, "identity", identityEdit->text().ascii(), true); if (passwordEdit->isEnabled() && strcmp(passwordEdit->text().ascii(), WPA_GUI_KEY_DATA) != 0) setNetworkParam(id, "password", passwordEdit->text().ascii(), true); if (cacertEdit->isEnabled()) setNetworkParam(id, "ca_cert", cacertEdit->text().ascii(), true); writeWepKey(id, wep0Edit, 0); writeWepKey(id, wep1Edit, 1); writeWepKey(id, wep2Edit, 2); writeWepKey(id, wep3Edit, 3); if (wep0Radio->isEnabled() && wep0Radio->isChecked()) setNetworkParam(id, "wep_tx_keyidx", "0", false); else if (wep1Radio->isEnabled() && wep1Radio->isChecked()) setNetworkParam(id, "wep_tx_keyidx", "1", false); else if (wep2Radio->isEnabled() && wep2Radio->isChecked()) setNetworkParam(id, "wep_tx_keyidx", "2", false); else if (wep3Radio->isEnabled() && wep3Radio->isChecked()) setNetworkParam(id, "wep_tx_keyidx", "3", false); snprintf(cmd, sizeof(cmd), "ENABLE_NETWORK %d", id); reply_len = sizeof(reply); wpagui->ctrlRequest(cmd, reply, &reply_len); if (strncmp(reply, "OK", 2) != 0) { QMessageBox::warning(this, "wpa_gui", "Failed to enable " "network in wpa_supplicant\n" "configuration."); /* Network was added, so continue anyway */ } wpagui->triggerUpdate(); wpagui->ctrlRequest("SAVE_CONFIG", reply, &reply_len); close(); }
void NetworkConfig::addNetwork() { char reply[10], cmd[256]; size_t reply_len; int id; int psklen = pskEdit->text().length(); int auth = authSelect->currentIndex(); if (auth == AUTH_WPA_PSK || auth == AUTH_WPA2_PSK) { if (psklen < 8 || psklen > 64) { QMessageBox::warning( this, tr("WPA Pre-Shared Key Error"), tr("WPA-PSK requires a passphrase of 8 to 63 " "characters\n" "or 64 hex digit PSK")); pskEdit->setFocus(); return; } } if (idstrEdit->isEnabled() && !idstrEdit->text().isEmpty()) { QRegExp rx("^(\\w|-)+$"); if (rx.indexIn(idstrEdit->text()) < 0) { QMessageBox::warning( this, tr("Network ID Error"), tr("Network ID String contains non-word " "characters.\n" "It must be a simple string, " "without spaces, containing\n" "only characters in this range: " "[A-Za-z0-9_-]\n")); idstrEdit->setFocus(); return; } } if (wpagui == NULL) return; memset(reply, 0, sizeof(reply)); reply_len = sizeof(reply) - 1; if (new_network) { wpagui->ctrlRequest("ADD_NETWORK", reply, &reply_len); if (reply[0] == 'F') { QMessageBox::warning(this, "wpa_gui", tr("Failed to add " "network to wpa_supplicant\n" "configuration.")); return; } id = atoi(reply); } else id = edit_network_id; setNetworkParam(id, "ssid", ssidEdit->text().toLocal8Bit().constData(), true); const char *key_mgmt = NULL, *proto = NULL, *pairwise = NULL; switch (auth) { case AUTH_NONE_OPEN: case AUTH_NONE_WEP: case AUTH_NONE_WEP_SHARED: key_mgmt = "NONE"; break; case AUTH_IEEE8021X: key_mgmt = "IEEE8021X"; break; case AUTH_WPA_PSK: key_mgmt = "WPA-PSK"; proto = "WPA"; break; case AUTH_WPA_EAP: key_mgmt = "WPA-EAP"; proto = "WPA"; break; case AUTH_WPA2_PSK: key_mgmt = "WPA-PSK"; proto = "WPA2"; break; case AUTH_WPA2_EAP: key_mgmt = "WPA-EAP"; proto = "WPA2"; break; } if (auth == AUTH_NONE_WEP_SHARED) setNetworkParam(id, "auth_alg", "SHARED", false); else setNetworkParam(id, "auth_alg", "OPEN", false); if (auth == AUTH_WPA_PSK || auth == AUTH_WPA_EAP || auth == AUTH_WPA2_PSK || auth == AUTH_WPA2_EAP) { int encr = encrSelect->currentIndex(); if (encr == 0) pairwise = "TKIP"; else pairwise = "CCMP"; } if (proto) setNetworkParam(id, "proto", proto, false); if (key_mgmt) setNetworkParam(id, "key_mgmt", key_mgmt, false); if (pairwise) { setNetworkParam(id, "pairwise", pairwise, false); setNetworkParam(id, "group", "TKIP CCMP WEP104 WEP40", false); } if (pskEdit->isEnabled() && strcmp(pskEdit->text().toLocal8Bit().constData(), WPA_GUI_KEY_DATA) != 0) setNetworkParam(id, "psk", pskEdit->text().toLocal8Bit().constData(), psklen != 64); if (eapSelect->isEnabled()) { const char *eap = eapSelect->currentText().toLocal8Bit().constData(); setNetworkParam(id, "eap", eap, false); if (strcmp(eap, "SIM") == 0 || strcmp(eap, "AKA") == 0) setNetworkParam(id, "pcsc", "", true); else setNetworkParam(id, "pcsc", "NULL", false); } if (phase2Select->isEnabled()) { QString eap = eapSelect->currentText(); QString inner = phase2Select->currentText(); char phase2[32]; phase2[0] = '\0'; if (eap.compare("PEAP") == 0) { if (inner.startsWith("EAP-")) snprintf(phase2, sizeof(phase2), "auth=%s", inner.right(inner.size() - 4). toLocal8Bit().constData()); } else if (eap.compare("TTLS") == 0) { if (inner.startsWith("EAP-")) snprintf(phase2, sizeof(phase2), "autheap=%s", inner.right(inner.size() - 4). toLocal8Bit().constData()); else snprintf(phase2, sizeof(phase2), "auth=%s", inner.toLocal8Bit().constData()); } else if (eap.compare("FAST") == 0) { const char *provisioning = NULL; if (inner.startsWith("EAP-")) { snprintf(phase2, sizeof(phase2), "auth=%s", inner.right(inner.size() - 4). toLocal8Bit().constData()); provisioning = "fast_provisioning=2"; } else if (inner.compare("GTC(auth) + MSCHAPv2(prov)") == 0) { snprintf(phase2, sizeof(phase2), "auth=GTC auth=MSCHAPV2"); provisioning = "fast_provisioning=1"; } else provisioning = "fast_provisioning=3"; if (provisioning) { char blob[32]; setNetworkParam(id, "phase1", provisioning, true); snprintf(blob, sizeof(blob), "blob://fast-pac-%d", id); setNetworkParam(id, "pac_file", blob, true); } } if (phase2[0]) setNetworkParam(id, "phase2", phase2, true); else setNetworkParam(id, "phase2", "NULL", false); } else setNetworkParam(id, "phase2", "NULL", false); if (identityEdit->isEnabled() && identityEdit->text().length() > 0) setNetworkParam(id, "identity", identityEdit->text().toLocal8Bit().constData(), true); else setNetworkParam(id, "identity", "NULL", false); if (passwordEdit->isEnabled() && passwordEdit->text().length() > 0 && strcmp(passwordEdit->text().toLocal8Bit().constData(), WPA_GUI_KEY_DATA) != 0) setNetworkParam(id, "password", passwordEdit->text().toLocal8Bit().constData(), true); else if (passwordEdit->text().length() == 0) setNetworkParam(id, "password", "NULL", false); if (cacertEdit->isEnabled() && cacertEdit->text().length() > 0) setNetworkParam(id, "ca_cert", cacertEdit->text().toLocal8Bit().constData(), true); else setNetworkParam(id, "ca_cert", "NULL", false); writeWepKey(id, wep0Edit, 0); writeWepKey(id, wep1Edit, 1); writeWepKey(id, wep2Edit, 2); writeWepKey(id, wep3Edit, 3); if (wep0Radio->isEnabled() && wep0Radio->isChecked()) setNetworkParam(id, "wep_tx_keyidx", "0", false); else if (wep1Radio->isEnabled() && wep1Radio->isChecked()) setNetworkParam(id, "wep_tx_keyidx", "1", false); else if (wep2Radio->isEnabled() && wep2Radio->isChecked()) setNetworkParam(id, "wep_tx_keyidx", "2", false); else if (wep3Radio->isEnabled() && wep3Radio->isChecked()) setNetworkParam(id, "wep_tx_keyidx", "3", false); if (idstrEdit->isEnabled() && idstrEdit->text().length() > 0) setNetworkParam(id, "id_str", idstrEdit->text().toLocal8Bit().constData(), true); else setNetworkParam(id, "id_str", "NULL", false); if (prioritySpinBox->isEnabled()) { QString prio; prio = prio.setNum(prioritySpinBox->value()); setNetworkParam(id, "priority", prio.toLocal8Bit().constData(), false); } snprintf(cmd, sizeof(cmd), "ENABLE_NETWORK %d", id); reply_len = sizeof(reply); wpagui->ctrlRequest(cmd, reply, &reply_len); if (strncmp(reply, "OK", 2) != 0) { QMessageBox::warning(this, "wpa_gui", tr("Failed to enable " "network in wpa_supplicant\n" "configuration.")); /* Network was added, so continue anyway */ } wpagui->triggerUpdate(); wpagui->ctrlRequest("SAVE_CONFIG", reply, &reply_len); close(); }