⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 networkconfig.cpp

📁 IEEE802.11 a/b/g 客户端应用程序源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/* * wpa_gui - NetworkConfig class * Copyright (c) 2005-2006, Jouni Malinen <j@w1.fi> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * Alternatively, this software may be distributed under the terms of BSD * license. * * See README and COPYING for more details. */#include <QMessageBox>#include "networkconfig.h"#include "wpagui.h"enum {    AUTH_NONE = 0,    AUTH_IEEE8021X = 1,    AUTH_WPA_PSK = 2,    AUTH_WPA_EAP = 3,    AUTH_WPA2_PSK = 4,    AUTH_WPA2_EAP = 5};#define WPA_GUI_KEY_DATA "[key is configured]"NetworkConfig::NetworkConfig(QWidget *parent, const char *, bool, Qt::WFlags)	: QDialog(parent){	setupUi(this);	connect(authSelect, SIGNAL(activated(int)), this,		SLOT(authChanged(int)));	connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));	connect(addButton, SIGNAL(clicked()), this, SLOT(addNetwork()));	connect(encrSelect, SIGNAL(activated(const QString &)), this,		SLOT(encrChanged(const QString &)));	connect(removeButton, SIGNAL(clicked()), this, SLOT(removeNetwork()));	wpagui = NULL;	new_network = false;}NetworkConfig::~NetworkConfig(){}void NetworkConfig::languageChange(){	retranslateUi(this);}void NetworkConfig::paramsFromScanResults(QTreeWidgetItem *sel){	new_network = true;	/* SSID BSSID frequency signal flags */	setWindowTitle(sel->text(0));	ssidEdit->setText(sel->text(0));	QString flags = sel->text(4);	int auth, encr = 0;	if (flags.indexOf("[WPA2-EAP") >= 0)		auth = AUTH_WPA2_EAP;	else if (flags.indexOf("[WPA-EAP") >= 0)		auth = AUTH_WPA_EAP;	else if (flags.indexOf("[WPA2-PSK") >= 0)		auth = AUTH_WPA2_PSK;	else if (flags.indexOf("[WPA-PSK") >= 0)		auth = AUTH_WPA_PSK;	else		auth = AUTH_NONE;	if (flags.indexOf("-CCMP") >= 0)		encr = 1;	else if (flags.indexOf("-TKIP") >= 0)		encr = 0;	else if (flags.indexOf("WEP") >= 0)		encr = 1;	else		encr = 0;	authSelect->setCurrentIndex(auth);	authChanged(auth);	encrSelect->setCurrentIndex(encr);	wepEnabled(auth == AUTH_NONE && encr == 1);	getEapCapa();}void NetworkConfig::authChanged(int sel){	pskEdit->setEnabled(sel == AUTH_WPA_PSK || sel == AUTH_WPA2_PSK);	bool eap = sel == AUTH_IEEE8021X || sel == AUTH_WPA_EAP ||		sel == AUTH_WPA2_EAP;	eapSelect->setEnabled(eap);	identityEdit->setEnabled(eap);	passwordEdit->setEnabled(eap);	cacertEdit->setEnabled(eap);	while (encrSelect->count())		encrSelect->removeItem(0);	if (sel == AUTH_NONE || sel == AUTH_IEEE8021X) {		encrSelect->addItem("None");		encrSelect->addItem("WEP");		encrSelect->setCurrentIndex(sel == AUTH_NONE ? 0 : 1);	} else {		encrSelect->addItem("TKIP");		encrSelect->addItem("CCMP");		encrSelect->setCurrentIndex((sel == AUTH_WPA2_PSK ||					     sel == AUTH_WPA2_EAP) ? 1 : 0);	}	wepEnabled(sel == AUTH_IEEE8021X);}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, "WPA Pre-Shared Key Error",					     "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, "Network ID Error",					     "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", "Failed to add "					     "network to wpa_supplicant\n"					     "configuration.");			return;		}		id = atoi(reply);	} else		id = edit_network_id;	setNetworkParam(id, "ssid", ssidEdit->text().toAscii().constData(),			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->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(passwordEdit->text().toAscii().constData(),		   WPA_GUI_KEY_DATA) != 0)		setNetworkParam(id, "psk",				pskEdit->text().toAscii().constData(),				psklen != 64);	if (eapSelect->isEnabled())		setNetworkParam(id, "eap",				eapSelect->currentText().toAscii().constData(),				false);	if (identityEdit->isEnabled())		setNetworkParam(id, "identity",				identityEdit->text().toAscii().constData(),				true);	if (passwordEdit->isEnabled() &&	    strcmp(passwordEdit->text().toAscii().constData(),		   WPA_GUI_KEY_DATA) != 0)		setNetworkParam(id, "password",				passwordEdit->text().toAscii().constData(),				true);	if (cacertEdit->isEnabled())		setNetworkParam(id, "ca_cert",				cacertEdit->text().toAscii().constData(),				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);	if (idstrEdit->isEnabled())		setNetworkParam(id, "id_str",				idstrEdit->text().toAscii().constData(),				true);	if (prioritySpinBox->isEnabled()) {		QString prio;		prio = prio.setNum(prioritySpinBox->value());		setNetworkParam(id, "priority", prio.toAscii().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", "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::setWpaGui(WpaGui *_wpagui){	wpagui = _wpagui;}int NetworkConfig::setNetworkParam(int id, const char *field,				   const char *value, bool quote){	char reply[10], cmd[256];	size_t reply_len;	snprintf(cmd, sizeof(cmd), "SET_NETWORK %d %s %s%s%s",		 id, field, quote ? "\"" : "", value, quote ? "\"" : "");	reply_len = sizeof(reply);	wpagui->ctrlRequest(cmd, reply, &reply_len);	return strncmp(reply, "OK", 2) == 0 ? 0 : -1;}void NetworkConfig::encrChanged(const QString &sel){	wepEnabled(sel.indexOf("WEP") == 0);}void NetworkConfig::wepEnabled(bool enabled){	wep0Edit->setEnabled(enabled);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -