Merge branch 'up-dbus' into 'dbus-interface'

add wpa3 connect support

See merge request kylin-desktop/kylin-nm!329
This commit is contained in:
ren peijia 2021-10-19 07:49:28 +00:00
commit b434f1b484
12 changed files with 186 additions and 45 deletions

View File

@ -315,6 +315,7 @@ void KyConnectResourse::getIpv6ConnectSetting(
connectSetting.m_ipv6ConfigIpType = CONFIG_IP_MANUAL;
connectSetting.m_ipv6Address = ipv6Setting->addresses();
connectSetting.m_ipv6Dns = ipv6Setting->dns();
return;

View File

@ -121,8 +121,7 @@ void KyConnectSetting::dumpInfo()
qDebug()<<"ipv4 dns" << m_ipv4Dns.at(index).toString();
}
/*
for (int index = 0 ; index << m_ipv6Address.size(); index++) {
for (int index = 0 ; index < m_ipv6Address.size(); index++) {
qDebug()<<"ipv6 address" << m_ipv6Address.at(index).ip().toString();
qDebug()<<"ipv6 gate way" << m_ipv6Address.at(index).gateway().toString();
qDebug()<<"ipv6 net mask" << m_ipv6Address.at(index).netmask().toString();
@ -131,5 +130,4 @@ void KyConnectSetting::dumpInfo()
for (int index = 0; index < m_ipv6Dns.size(); ++index) {
qDebug()<<"ipv6 dns" << m_ipv6Dns.at(index).toString();
}
*/
}

View File

@ -35,6 +35,37 @@ NetworkManager::ConnectionSettings::Ptr assembleWpaXPskSettings(NetworkManager::
return settings;
}
NetworkManager::ConnectionSettings::Ptr assembleSaeSettings(NetworkManager::AccessPoint::Ptr accessPoint, QString &psk, bool isAutoConnect)
{
NetworkManager::ConnectionSettings::Ptr settings{new NetworkManager::ConnectionSettings{NetworkManager::ConnectionSettings::Wireless}};
settings->setId(accessPoint->ssid());
settings->setUuid(NetworkManager::ConnectionSettings::createNewUuid());
settings->setAutoconnect(isAutoConnect);
//Note: workaround for wrongly (randomly) initialized gateway-ping-timeout
settings->setGatewayPingTimeout(0);
NetworkManager::WirelessSetting::Ptr wifi_sett
= settings->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
wifi_sett->setInitialized(true);
wifi_sett->setSsid(accessPoint->ssid().toUtf8());
wifi_sett->setSecurity("802-11-wireless-security");
NetworkManager::WirelessSecuritySetting::Ptr security_sett
= settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
security_sett->setInitialized(true);
if (NetworkManager::AccessPoint::Adhoc == accessPoint->mode()) {
wifi_sett->setMode(NetworkManager::WirelessSetting::Adhoc);
security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaNone);
} else {
security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::SAE);
}
if (!psk.isEmpty()) {
security_sett->setPsk(psk);
}
return settings;
}
NetworkManager::ConnectionSettings::Ptr assembleWirelessSettings(const KyWirelessConnectSetting &connSettingInfo, bool isHidden)
{
NetworkManager::ConnectionSettings::Ptr settings{new NetworkManager::ConnectionSettings{NetworkManager::ConnectionSettings::Wireless}};
@ -435,6 +466,7 @@ void KyWirelessConnectOperation::addAndActiveWirelessConnect(QString & devIface,
qDebug() << "findBestWirelessSecurity type "<< sec_type;
NetworkManager::ConnectionSettings::Ptr settings = nullptr;
switch (sec_type)
{
case NetworkManager::UnknownSecurity:
@ -444,7 +476,8 @@ void KyWirelessConnectOperation::addAndActiveWirelessConnect(QString & devIface,
break;
case NetworkManager::WpaPsk:
case NetworkManager::Wpa2Psk:
if (NetworkManager::ConnectionSettings::Ptr settings = assembleWpaXPskSettings(access_point, connSettingInfo.m_psk, connSettingInfo.isAutoConnect)) {
settings = assembleWpaXPskSettings(access_point, connSettingInfo.m_psk, connSettingInfo.isAutoConnect);
if (nullptr != settings) {
map_settings = settings->toMap();
} else {
qWarning() << QStringLiteral("connection settings assembly for '%1' failed, abandoning activation...").arg(conn_name);
@ -452,6 +485,15 @@ void KyWirelessConnectOperation::addAndActiveWirelessConnect(QString & devIface,
}
break;
//TODO: other types...
case NetworkManager::SAE:
settings = assembleSaeSettings(access_point, connSettingInfo.m_psk, connSettingInfo.isAutoConnect);
if (nullptr != settings) {
map_settings = settings->toMap();
} else {
qWarning() << QStringLiteral("connection settings assembly for '%1' failed, abandoning activation...").arg(conn_name);
return;
}
break;
default:
qDebug() << "addAndActiveWirelessConnect not support";
break;

View File

@ -162,14 +162,12 @@ void EnterpriseWlanDialog::onBtnConnectClicked()
if (eapType == KyEapMethodType::TLS) {
m_info.tlsInfo.devIfaceName = m_deviceName;
m_securityPage->updateTlsChange(m_info.tlsInfo);
m_connectOperation->addAndActiveWirelessEnterPriseTlsConnect(m_info.tlsInfo, connetSetting, m_deviceName, true);
m_connectOperation->addAndActiveWirelessEnterPriseTlsConnect(m_info.tlsInfo, connetSetting, m_deviceName, false);
} else if (eapType == KyEapMethodType::PEAP) {
m_securityPage->updatePeapChange(m_info.peapInfo);
m_connectOperation->addAndActiveWirelessEnterPrisePeapConnect(m_info.peapInfo, connetSetting, m_deviceName, true);
m_connectOperation->addAndActiveWirelessEnterPrisePeapConnect(m_info.peapInfo, connetSetting, m_deviceName, false);
} else if (eapType == KyEapMethodType::TTLS) {
m_securityPage->updateTtlsChange(m_info.ttlsInfo);
m_connectOperation->addAndActiveWirelessEnterPriseTtlsConnect(m_info.ttlsInfo, connetSetting, m_deviceName, true);
m_connectOperation->addAndActiveWirelessEnterPriseTtlsConnect(m_info.ttlsInfo, connetSetting, m_deviceName, false);
} else {
qWarning() << "Connect enterprise wlan failed!(Unknown eap type)" << Q_FUNC_INFO << __LINE__;
}

View File

@ -48,7 +48,7 @@ public:
KyIpConfigType ipv6ConfigType = CONFIG_IP_DHCP;
QString strIPV6Address;
QString strIPV6Prefix;
int iIPV6Prefix;
QString strIPV6FirDns;
QString strIPV6SecDns;
QString strIPV6GateWay;

View File

@ -57,6 +57,9 @@ void DetailPage::setMac(const QString &mac) {
void DetailPage::setAutoConnect(bool flag)
{
if (!mIsWlan) {
return;
}
this->forgetNetBox->setChecked(flag);
}
@ -67,6 +70,9 @@ void DetailPage::getSsid(QString &ssid)
bool DetailPage::checkIsChanged(const ConInfo info)
{
if (!mIsWlan) {
return false;
}
if (info.isAutoConnect != forgetNetBox->isChecked()) {
return true;
} else {
@ -84,7 +90,6 @@ void DetailPage::addDetailItem(QListWidget *listWidget, DetailWidget *detailWidg
}
void DetailPage::initUI() {
forgetNetBox = new QCheckBox(this);
layout = new QVBoxLayout(this);
layout->setContentsMargins(0,0,0,0);
@ -147,16 +152,20 @@ void DetailPage::initUI() {
m_macWidget = new DetailWidget(qobject_cast<QWidget *>(mMac), m_listWidget);
m_macWidget->setKey(tr("Mac:"));
autoConnect = new QLabel(this);
if (mIsWlan) {
autoConnect = new QLabel(this);
forgetNetBox = new QCheckBox(this);
autoConnect->setText(tr("Auto Connection"));
mAutoLayout = new QHBoxLayout(this);
QSpacerItem *horizontalSpacer;
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
autoConnect->setText(tr("Auto Connection"));
mAutoLayout = new QHBoxLayout(this);
QSpacerItem *horizontalSpacer;
horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
mAutoLayout->addWidget(forgetNetBox);
mAutoLayout->addWidget(autoConnect);
mAutoLayout->addSpacerItem(horizontalSpacer);
mAutoLayout->addSpacing(20);
mAutoLayout->addWidget(forgetNetBox);
mAutoLayout->addWidget(autoConnect);
mAutoLayout->addSpacerItem(horizontalSpacer);
}
this->addDetailItem(m_listWidget, m_ssidWidget);
this->addDetailItem(m_listWidget, m_protocolWidget);
@ -179,7 +188,9 @@ void DetailPage::initUI() {
m_listWidget->setPalette(mpal);
layout->addWidget(mDetailFrame);
layout->addLayout(mAutoLayout);
if (mIsWlan) {
layout->addLayout(mAutoLayout);
}
}
void DetailPage::setEnableOfSaveBtn() {

View File

@ -1,5 +1,6 @@
#include "ipv4page.h"
#include "netdetail.h"
#include "math.h"
Ipv4Page::Ipv4Page(QWidget *parent):QFrame(parent)
{
@ -129,8 +130,9 @@ bool Ipv4Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting)
setting.setIpConfigType(IPADDRESS_V4, CONFIG_IP_MANUAL);
isChanged = true;
}
qDebug() << "ipv4 netmask " << getNetMaskText(netMaskEdit->text());
if(info.strIPV4Address != ipv4addressEdit->text()
|| info.strIPV4NetMask != netMaskEdit->text()
|| info.strIPV4NetMask != /*netMaskEdit->text()*/getNetMaskText(netMaskEdit->text())
|| info.strIPV4GateWay != gateWayEdit->text()
|| info.strIPV4FirDns != firstDnsEdit->text()
|| info.strIPV4SecDns != secondDnsEdit->text()) {
@ -146,7 +148,7 @@ bool Ipv4Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting)
}
QString ipv4address =ipv4addressEdit->text();
QString netMask = netMaskEdit->text();
QString netMask = getNetMaskText(netMaskEdit->text());
QString gateWay = gateWayEdit->text();
qDebug() << ipv4address << netMask << gateWay;
setting.ipv4AddressConstruct(ipv4address, netMask, gateWay, dnsList);
@ -168,7 +170,7 @@ bool Ipv4Page::checkConnectBtnIsEnabled()
return false;
}
if (netMaskEdit->text().isEmpty() || !getTextEditState(netMaskEdit->text())) {
if (netMaskEdit->text().isEmpty() || !netMaskIsValide(netMaskEdit->text())) {
qDebug() << "ipv4 netMask empty or invalid";
return false;
}
@ -239,3 +241,39 @@ bool Ipv4Page::getTextEditState(QString text)
return match;
}
bool Ipv4Page::netMaskIsValide(QString text)
{
if (getTextEditState(text)) {
return true;
} else {
if (text.length() > 0 && text.length() < 3) {
int num = text.toInt();
if (num > 0 && num < 33) {
return true;
}
}
}
return false;
}
QString Ipv4Page::getNetMaskText(QString text)
{
if (text.length() > 2) {
return text;
}
int num = text.toInt();
QStringList list;
list << "0" << "0" << "0" << "0";
int count = 0;
while (num - 8 >= 0) {
list[count] = "255";
num = num - 8;
count ++;
}
if (num > 0) {
int size = pow(2, 8) - pow(2,(8-num));
list[count] = QString::number(size);
}
return QString("%1.%2.%3.%4").arg(list[0],list[1],list[2],list[3]);
}

View File

@ -51,8 +51,11 @@ private:
void setLineEnabled(bool check);
void configSave();
bool getTextEditState(QString text);
bool netMaskIsValide(QString text);
QString getNetMaskText(QString text);
bool checkConnectBtnIsEnabled();
private slots:
void setEnableOfSaveBtn();
void configChanged(int index);

View File

@ -16,9 +16,14 @@ void Ipv6Page::setIpv6Config(KyIpConfigType ipv6Config)
}
}
void Ipv6Page::setIpv6(const QString &ipv4)
void Ipv6Page::setIpv6(const QString &ipv6)
{
ipv6AddressEdit->setText(ipv4);
ipv6AddressEdit->setText(ipv6);
}
void Ipv6Page::setIpv6Perfix(const int &ipv6Perfix)
{
lengthEdit->setText(QString::number(ipv6Perfix));
}
void Ipv6Page::setIpv6FirDns(const QString &ipv6FirDns)
@ -58,7 +63,7 @@ bool Ipv6Page::checkIsChanged(const ConInfo info, KyConnectSetting &setting)
isChanged = true;
}
if(info.strIPV6Address != ipv6AddressEdit->text()
|| info.strIPV6Prefix != lengthEdit->text()
|| info.iIPV6Prefix != lengthEdit->text().toInt()
|| info.strIPV6GateWay != gateWayEdit->text()
|| info.strIPV6FirDns != firstDnsEdit->text()
|| info.strIPV6SecDns != secondDnsEdit->text()) {
@ -226,3 +231,26 @@ bool Ipv6Page::getIpv6EditState(QString text)
return match;
}
int Ipv6Page::getPerfixLength(QString text)
{
qDebug() << "getPerfixLength" << text;
int length = 0;
QStringList list= text.split(":");
for (int i = 0; i < list.size(); ++i) {
QString temp = list.at(i);
if (temp.isEmpty()) {
continue;
}
bool ok;
unsigned int val = temp.toUInt(&ok, 16);
temp = temp.setNum(val,2);
for(int j = 0; j < temp.length(); ++j) {
if (temp.at(j) == "1") {
length++;
}
}
}
qDebug() << "getPerfixLength" << length;
return length;
}

View File

@ -22,12 +22,15 @@ public:
Ipv6Page(QWidget *parent = nullptr);
void setIpv6Config(KyIpConfigType ipv6Config);
void setIpv6(const QString &ipv4);
void setIpv6Perfix(const int &ipv6Perfix);
void setIpv6FirDns(const QString &ipv6FirDns);
void setIpv6SecDns(const QString &ipv6SecDns);
void setGateWay(const QString &gateWay);
bool checkIsChanged(const ConInfo info, KyConnectSetting &setting);
int getPerfixLength(QString text);
public:
QComboBox *ipv6ConfigCombox;
QLineEdit *ipv6AddressEdit;
@ -52,7 +55,6 @@ private:
bool checkConnectBtnIsEnabled();
private slots:
void configChanged(int index);
void setEnableOfSaveBtn();

View File

@ -296,7 +296,7 @@ void NetDetail::initComponent()
stackWidget->setCurrentIndex(SECURITY_PAGE_NUM);
});
connect(confimBtn, SIGNAL(clicked()), this, SLOT(on_btnConfirm_clicked()));
if (!m_uuid.isEmpty()) {
if (isWlan && !m_uuid.isEmpty()) {
forgetBtn->show();
connect(forgetBtn, SIGNAL(clicked()), this, SLOT(on_btnForget_clicked()));
} else {
@ -362,10 +362,11 @@ void NetDetail::pagePadding(QString netName, bool isWlan)
//ipv6页面填充
if (m_info.ipv6ConfigType == CONFIG_IP_MANUAL) {
ipv6Page->setIpv6Config(m_info.ipv6ConfigType);
ipv6Page->setIpv6(m_info.strIPV4Address);
ipv6Page->setIpv6(m_info.strIPV6Address);
ipv6Page->setIpv6Perfix(m_info.iIPV6Prefix);
ipv6Page->setIpv6FirDns(m_info.strIPV6FirDns);
ipv6Page->setIpv6SecDns(m_info.strIPV4SecDns);
ipv6Page->setGateWay(m_info.strIPV4GateWay);
ipv6Page->setIpv6SecDns(m_info.strIPV6SecDns);
ipv6Page->setGateWay(m_info.strIPV6GateWay);
} else {
ipv6Page->setIpv6Config(m_info.ipv6ConfigType);
}
@ -411,13 +412,11 @@ void NetDetail::getBaseInfo(ConInfo &conInfo)
if (!hardAddress.isEmpty()) {
conInfo.strBandWidth = QString("%1").arg(bandWith/1000) + "Mbps";
conInfo.strMac = hardAddress;
}
if (!isWlan) {
conInfo.strConType = "802-3-ethernet";
if (!hardAddress.isEmpty()) {
conInfo.strMac = hardAddress;
}
} else {
conInfo.strConType = "802-11-wireless";
if (!isActive) {
@ -426,8 +425,6 @@ void NetDetail::getBaseInfo(ConInfo &conInfo)
qDebug() << "getWifiNetWork failed device:" << m_deviceName << " name:" << m_name;
return;
} else {
conInfo.strMac = item.m_bssid;
conInfo.strHz = QString::number(item.m_frequency);
conInfo.strChan = QString::number(item.m_channel);
//无线特有
@ -494,6 +491,7 @@ void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived)
KyConnectResourse *kyConnectResourse = new KyConnectResourse(this);
KyConnectSetting connetSetting;
kyConnectResourse->getConnectionSetting(m_uuid,connetSetting);
connetSetting.dumpInfo();
conInfo.ipv4ConfigType = connetSetting.m_ipv4ConfigIpType;
conInfo.ipv6ConfigType = connetSetting.m_ipv6ConfigIpType;
@ -516,7 +514,7 @@ void NetDetail::getStaticIpInfo(ConInfo &conInfo, bool bActived)
if (connetSetting.m_ipv6ConfigIpType == CONFIG_IP_MANUAL) {
if (connetSetting.m_ipv6Address.size() > 0) {
conInfo.strIPV6Address = connetSetting.m_ipv6Address.at(0).ip().toString();
conInfo.strIPV6Prefix = connetSetting.m_ipv6Address.at(0).netmask().toString();
conInfo.iIPV6Prefix = ipv6Page->getPerfixLength(connetSetting.m_ipv6Address.at(0).netmask().toString());
conInfo.strIPV6GateWay = connetSetting.m_ipv6Address.at(0).gateway().toString();
}
@ -834,6 +832,7 @@ bool NetDetail::updateConnect()
bool securityChange = false;
if (isWlan) {
securityChange = securityPage->checkIsChanged(m_info);
qDebug() << "securityChange" << securityChange;
if (securityChange) {
KySecuType secuType;
KyEapMethodType enterpriseType;

View File

@ -338,7 +338,6 @@ void SecurityPage::getSecuType(KySecuType &secuType, KyEapMethodType &enterprise
bool SecurityPage::checkIsChanged(const ConInfo info)
{
qDebug() << "SecurityPage checkIsChanged";
if (info.secType != secuTypeCombox->currentData().toInt()) {
return true;
} else {
@ -538,15 +537,37 @@ KyEapMethodPeapInfo SecurityPage::assemblePeapInfo()
KyEapMethodTtlsInfo SecurityPage::assembleTtlsInfo()
{
KyEapMethodTtlsInfo info;
if (eapMethodCombox->currentData().toInt() == PAP
|| eapMethodCombox->currentData().toInt() == MSCHAP
|| eapMethodCombox->currentData().toInt() == MSCHAPV2
|| eapMethodCombox->currentData().toInt() == CHAP) {
switch (eapMethodCombox->currentData().toInt()) {
case PAP:
info.authType = AUTH_NO_EAP;
info.authEapMethod = (KyEapMethodAuth)eapMethodCombox->currentData().toInt();
} else {
info.authNoEapMethod = KyAuthMethodPap;
break;
case MSCHAP:
info.authType = AUTH_NO_EAP;
info.authNoEapMethod = KyAuthMethodChap;
break;
case MSCHAPV2_EAP:
info.authType = AUTH_EAP;
info.authNoEapMethod = (KyNoEapMethodAuth)eapMethodCombox->currentData().toInt();
info.authEapMethod = KyAuthEapMethodMschapv2;
break;
case MSCHAPV2:
info.authType = AUTH_NO_EAP;
info.authNoEapMethod = KyAuthMethodMschapv2;
break;
case CHAP:
info.authType = AUTH_NO_EAP;
info.authNoEapMethod = KyAuthMethodChap;
break;
case MD5_EAP:
info.authType = AUTH_EAP;
info.authEapMethod = KyAuthEapMethodMd5;
break;
case GTC_EAP:
info.authType = AUTH_EAP;
info.authEapMethod = KyAuthEapMethodGtc;
break;
default:
break;
}
info.userName = userNameEdit->text();
info.userPWD = userPwdEdit->text();