wifi安全类型改变

This commit is contained in:
zhangyuanyuan1 2022-09-13 17:14:12 +08:00
parent db9892e6f8
commit cf088d463f
8 changed files with 140 additions and 11 deletions

View File

@ -306,7 +306,20 @@ void KyNetworkResourceManager::addWifiNetwork(NetworkManager::WirelessNetwork::P
//device signals
connect(net.data(), &NetworkManager::WirelessNetwork::signalStrengthChanged, this, &KyNetworkResourceManager::onUpdateWirelessNet);
connect(net.data(), &NetworkManager::WirelessNetwork::referenceAccessPointChanged, this, &KyNetworkResourceManager::onUpdateWirelessNet);
connect(net.data(), &NetworkManager::WirelessNetwork::referenceAccessPointChanged, this, &KyNetworkResourceManager::onReferenceAccessPointChanged);
connect(net.data(), &NetworkManager::WirelessNetwork::disappeared, this, &KyNetworkResourceManager::onUpdateWirelessNet);
connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::wpaFlagsChanged, this, [&](NetworkManager::AccessPoint::WpaFlags flags)
{
NetworkManager::AccessPoint *p_wirelessNet =
qobject_cast<NetworkManager::AccessPoint *>(sender());
emit wifiNetworkSecuChange(p_wirelessNet);
}, Qt::UniqueConnection);
connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::rsnFlagsChanged, this, [&](NetworkManager::AccessPoint::WpaFlags flags)
{
NetworkManager::AccessPoint *p_wirelessNet =
qobject_cast<NetworkManager::AccessPoint *>(sender());
emit wifiNetworkSecuChange(p_wirelessNet);
}, Qt::UniqueConnection);
}
void KyNetworkResourceManager::insertWifiNetworks()
@ -838,6 +851,39 @@ void KyNetworkResourceManager::onWifiNetworkDisappeared(QString const & ssid)
return;
}
void KyNetworkResourceManager::onReferenceAccessPointChanged()
{
NetworkManager::WirelessNetwork *p_wirelessNet =
qobject_cast<NetworkManager::WirelessNetwork *>(sender());
if (nullptr != p_wirelessNet) {
onAccessPointUpdate(p_wirelessNet);
}
}
void KyNetworkResourceManager::onAccessPointUpdate(NetworkManager::WirelessNetwork * net)
{
if (nullptr == net) {
return;
}
auto index = std::find(m_wifiNets.cbegin(), m_wifiNets.cend(), net);
if (m_wifiNets.cend() != index) {
if (!net->referenceAccessPoint().isNull()) {
connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::wpaFlagsChanged, this, [&]()
{
NetworkManager::AccessPoint *p_wirelessNet =
qobject_cast<NetworkManager::AccessPoint *>(sender());
emit wifiNetworkSecuChange(p_wirelessNet);
}, Qt::UniqueConnection);
connect(net->referenceAccessPoint().data(), &NetworkManager::AccessPoint::rsnFlagsChanged, this, [&]()
{
NetworkManager::AccessPoint *p_wirelessNet =
qobject_cast<NetworkManager::AccessPoint *>(sender());
emit wifiNetworkSecuChange(p_wirelessNet);
}, Qt::UniqueConnection);
}
}
}
void KyNetworkResourceManager::onUpdateWirelessNet()
{
NetworkManager::WirelessNetwork *p_wirelessNet =

View File

@ -122,6 +122,7 @@ signals:
void wifiNetworkRemoved(QString, QString);
void wifiNetworkAdded(QString, QString);
void wifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net);
void wifiNetworkSecuChange(NetworkManager::AccessPoint *);
void wifiNetworkDeviceDisappear();
void wifiEnabledChanged(bool);
@ -193,6 +194,9 @@ private:
void onWifiNetworkUpdate(NetworkManager::WirelessNetwork * net);
void onWifiNetworkRemove(NetworkManager::Device * dev, QString const & ssid);
void onAccessPointUpdate(NetworkManager::WirelessNetwork * net);
void onReferenceAccessPointChanged();
private:
bool m_initFinished = false;

View File

@ -21,6 +21,9 @@
#include "kylinutil.h"
#define LOG_FLAG "[KyWirelessNetResource]"
const QString ENTERPRICE_TYPE = "802.1X";
const QString WPA1_AND_WPA2 = "WPA";
const QString WPA3 = "WPA3";
static bool subWifiListSort(const KyWirelessNetItem info1, const KyWirelessNetItem info2)
{
@ -63,6 +66,8 @@ KyWirelessNetResource::KyWirelessNetResource(QObject *parent)
this, &KyWirelessNetResource::onWifiNetworkRemoved, Qt::ConnectionType::DirectConnection);
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkPropertyChange,
this, &KyWirelessNetResource::onWifiNetworkPropertyChange, Qt::ConnectionType::DirectConnection);
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkSecuChange,
this, &KyWirelessNetResource::onWifiNetworkSecuChange, Qt::ConnectionType::DirectConnection);
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkDeviceDisappear,
this, &KyWirelessNetResource::onWifiNetworkDeviceDisappear, Qt::ConnectionType::DirectConnection);
@ -426,12 +431,47 @@ void KyWirelessNetResource::onWifiNetworkRemoved(QString devIfaceName, QString s
}
}
void KyWirelessNetResource::onWifiNetworkSecuChange(NetworkManager::AccessPoint *accessPointPtr)
{
QString secuType = enumToQstring(accessPointPtr->capabilities(),
accessPointPtr->wpaFlags(),
accessPointPtr->rsnFlags());
QMap<QString, QList<KyWirelessNetItem> >::iterator iter = m_WifiNetworkList.begin();
while (iter != m_WifiNetworkList.end()) {
QList<KyWirelessNetItem>::iterator itemIter = iter.value().begin();
while (itemIter != iter.value().end()) {
if (itemIter->m_NetSsid == accessPointPtr->ssid()) {
QString devName = iter.key();
itemIter->m_secuType = secuType;
if (secuType.indexOf(ENTERPRICE_TYPE) >= 0) {
itemIter->m_kySecuType = WPA_AND_WPA2_ENTERPRISE;
} else if (secuType.indexOf(WPA3) >= 0) {
itemIter->m_kySecuType = WPA3_PERSONAL;
} else if (secuType.indexOf(WPA1_AND_WPA2) >= 0) {
itemIter->m_kySecuType = WPA_AND_WPA2_PERSONAL;
} else {
itemIter->m_kySecuType = NONE;
}
//qDebug() << "!!!!" << itemIter->m_NetSsid << itemIter->m_secuType << itemIter->m_kySecuType;
emit secuTypeChange(devName, accessPointPtr->ssid(), secuType);
break;
}
itemIter++;
}
iter++;
}
}
void KyWirelessNetResource::onWifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net)
{
if (nullptr == net) {
return;
}
qDebug() << "onWifiNetworkPropertyChange" << net->ssid();
NetworkManager::AccessPoint::Ptr accessPointPtr = net->referenceAccessPoint();
QByteArray rawSsid = accessPointPtr->rawSsid();
QString wifiSsid = getSsidFromByteArray(rawSsid);
@ -460,7 +500,17 @@ void KyWirelessNetResource::onWifiNetworkPropertyChange(NetworkManager::Wireless
accessPointPtr->wpaFlags(),
accessPointPtr->rsnFlags());
if (iter->m_secuType != secuType) {
//qDebug() << "!!!!secuTypeChange" << wifiSsid << iter->m_secuType << "change to " << secuType;
iter->m_secuType = secuType;
if (secuType.indexOf(ENTERPRICE_TYPE) >= 0) {
iter->m_kySecuType = WPA_AND_WPA2_ENTERPRISE;
} else if (secuType.indexOf(WPA3) >= 0) {
iter->m_kySecuType = WPA3_PERSONAL;
} else if (secuType.indexOf(WPA1_AND_WPA2) >= 0) {
iter->m_kySecuType = WPA_AND_WPA2_PERSONAL;
} else {
iter->m_kySecuType = NONE;
}
emit secuTypeChange(devIface, wifiSsid, secuType);
}
@ -693,7 +743,7 @@ void KyWirelessNetResource::onConnectionRemove(QString path)
for(auto var = map.cbegin(); var != map.cend(); var++) {
QString devIfaceName = var.key();
QString ssid = var.value();
emit connectionRemove(devIfaceName, ssid);
emit connectionRemove(devIfaceName, ssid, path);
}
}

View File

@ -64,6 +64,7 @@ public slots:
void onWifiNetworkAdded(QString, QString);
void onWifiNetworkRemoved(QString, QString);
void onWifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net);
void onWifiNetworkSecuChange(NetworkManager::AccessPoint *accessPointPtr);
void onWifiNetworkDeviceDisappear();
void onConnectionAdd(QString uuid);
@ -78,7 +79,7 @@ signals:
void signalStrengthChange(QString, QString, int);
void bssidChange(QString, QString, QString);
void secuTypeChange(QString, QString, QString);
void connectionRemove(QString, QString);
void connectionRemove(QString, QString, QString);
void connectionAdd(QString, QString);
void wifiNetworkUpdate();
void wifiNetworkAdd(QString, KyWirelessNetItem&);

View File

@ -28,6 +28,10 @@
#define ENABLE_BUTTON_COLOR qApp->palette().highlight().color()
#define UNABLE_BUTTON_COLOR qApp->palette().button().color()
const QString ENTERPRICE_TYPE = "802.1X";
const QString WPA1_AND_WPA2 = "WPA";
const QString WPA3 = "WPA3";
WlanListItem::WlanListItem(KyWirelessNetItem &wirelessNetItem, QString device, bool isApMode, QWidget *parent)
: WlanListItem(wirelessNetItem, device, parent)
{
@ -84,6 +88,11 @@ QString WlanListItem::getUuid()
return m_wirelessNetItem.m_connectUuid;
}
QString WlanListItem::getPath()
{
return m_wirelessNetItem.m_connDbusPath;
}
void WlanListItem::setSignalStrength(const int &signal)
{
m_wirelessNetItem.m_signalStrength = signal;
@ -467,7 +476,7 @@ void WlanListItem::onNetButtonClicked()
} else {
qDebug() << "KeyMgmt not support now " << type;
}
//qDebug() << "!!!!" << m_wirelessNetItem.m_kySecuType << kySecuType;
//有配置或者无密码的wifi直接连接
if (m_wirelessNetItem.m_isConfigured) {
if (m_wirelessNetItem.m_kySecuType == kySecuType) {
@ -512,7 +521,7 @@ void WlanListItem::updateWirelessNetSecurity(QString ssid, QString securityType)
}
qDebug() << LOG_FLAG << "Security changed! ssid = " << m_wirelessNetItem.m_NetSsid
<< "; security = " << m_wirelessNetItem.m_secuType << "." <<Q_FUNC_INFO << __LINE__;
<< "; security = " << m_wirelessNetItem.m_secuType << "change to "<< securityType <<Q_FUNC_INFO << __LINE__;
m_wirelessNetItem.m_secuType = securityType;
bool newSecu = (m_wirelessNetItem.m_secuType.isEmpty() || m_wirelessNetItem.m_secuType == "") ? false : true;
@ -521,6 +530,16 @@ void WlanListItem::updateWirelessNetSecurity(QString ssid, QString securityType)
refreshIcon(false);
}
if (securityType.indexOf(ENTERPRICE_TYPE) >= 0) {
m_wirelessNetItem.m_kySecuType = WPA_AND_WPA2_ENTERPRISE;
} else if (securityType.indexOf(WPA3) >= 0) {
m_wirelessNetItem.m_kySecuType = WPA3_PERSONAL;
} else if ( securityType.indexOf(WPA1_AND_WPA2) >= 0) {
m_wirelessNetItem.m_kySecuType = WPA_AND_WPA2_PERSONAL;
} else {
m_wirelessNetItem.m_kySecuType = NONE;
}
return;
}

View File

@ -61,6 +61,8 @@ public:
QString getSsid();
QString getUuid();
QString getPath();
void setSignalStrength(const int &signal);
int getSignalStrength();

View File

@ -606,12 +606,12 @@ void WlanPage::onConnectionAdd(QString deviceName, QString ssid)
return;
}
void WlanPage::onConnectionRemove(QString deviceName, QString ssid)
void WlanPage::onConnectionRemove(QString deviceName, QString ssid, QString path)
{
qDebug() << LOG_FLAG << "one connection is removed, it's ssid " << ssid << "device name"<< deviceName;
if (deviceName == m_currentDevice) {
if (m_activateConnectionItemMap.contains(ssid)) {
updateWirelessNetArea(nullptr, ssid, deviceName);
updateWirelessNetArea(nullptr, ssid, deviceName, path);
}
updateWlanListItem(ssid);
}
@ -872,7 +872,7 @@ void WlanPage::updateActivatedArea(QString uuid, QString ssid, QString devName)
return;
}
void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName)
void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName, QString path)
{
if(m_wirelessNetItemMap.contains(ssid)) {
return;
@ -889,7 +889,12 @@ void WlanPage::updateWirelessNetArea(QString uuid, QString ssid, QString devName
qWarning() << LOG_FLAG << "p_wlanItem is null";
return;
}
if (p_wlanItem->getUuid() == uuid) {
if (p_wlanItem->getUuid() == uuid || uuid.isEmpty()) {
if (uuid.isEmpty() && p_wlanItem->getPath() != path) {
return;
}
deleteWirelessItemFormMap(m_activateConnectionItemMap, m_activatedNetListWidget, ssid);
QListWidgetItem *p_activeListWidgetItem = addEmptyItem(m_activatedNetListWidget);
m_activateConnectionItemMap.insert(EMPTY_SSID, p_activeListWidgetItem);
@ -1005,7 +1010,9 @@ void WlanPage::onConnectionStateChanged(QString uuid,
if (devName.isEmpty()) {
devName = m_currentDevice;
}
updateWirelessNetArea(uuid, ssid, devName);
updateWirelessNetArea(uuid, ssid, devName,"");
if (m_wirelessNetItemMap.contains(ssid)) {
QListWidgetItem *p_listWidgetItem = m_wirelessNetItemMap.value(ssid);
updateWlanItemState(m_inactivatedNetListWidget, p_listWidgetItem, Deactivated);

View File

@ -108,7 +108,7 @@ private slots:
void onWlanRemoved(QString interface, QString ssid);
void onConnectionAdd(QString deviceName, QString ssid);
void onConnectionRemove(QString deviceName, QString ssid);
void onConnectionRemove(QString deviceName, QString ssid, QString path);
void onDeviceAdd(QString deviceName, NetworkManager::Device::Type deviceType);
void onDeviceRemove(QString deviceName);
@ -167,7 +167,7 @@ private:
void constructActivateConnectionArea();
void updateActivatedArea(QString uuid, QString ssid, QString devName);
void updateWirelessNetArea(QString uuid, QString ssid, QString devName);
void updateWirelessNetArea(QString uuid, QString ssid, QString devName, QString path);
void addDeviceToCombox(QString deviceName);
void deleteDeviceFromCombox(QString deviceName);