add wireless class
This commit is contained in:
parent
c41e070e53
commit
95880c5161
10
kylin-nm.pro
10
kylin-nm.pro
|
@ -64,9 +64,14 @@ include(src/singleapplication/qt-single-application.pri)
|
|||
|
||||
SOURCES += \
|
||||
src/backthread.cpp \
|
||||
src/kyenterpricesettinginfo.cpp \
|
||||
src/kylinconnectinfo.cpp \
|
||||
src/kylinnetworkconnect.cpp \
|
||||
src/kylinnetworkresourcemanager.cpp \
|
||||
src/kywirelessconnectoperation.cpp \
|
||||
src/kywirelessnetitem.cpp \
|
||||
src/kywirelessnetresource.cpp \
|
||||
src/nmdemo.cpp \
|
||||
src/wifi-auth-thread.cpp \
|
||||
src/confform.cpp \
|
||||
src/dbusadaptor.cpp \
|
||||
|
@ -99,9 +104,14 @@ SOURCES += \
|
|||
|
||||
HEADERS += \
|
||||
src/backthread.h \
|
||||
src/kyenterpricesettinginfo.h \
|
||||
src/kylinconnectinfo.h \
|
||||
src/kylinnetworkconnect.h \
|
||||
src/kylinnetworkresourcemanager.h \
|
||||
src/kywirelessconnectoperation.h \
|
||||
src/kywirelessnetitem.h \
|
||||
src/kywirelessnetresource.h \
|
||||
src/nmdemo.h \
|
||||
src/wifi-auth-thread.h \
|
||||
src/confform.h \
|
||||
src/dbusadaptor.h \
|
||||
|
|
|
@ -0,0 +1,126 @@
|
|||
#include "kyenterpricesettinginfo.h"
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr KyEnterPriceSettingInfo::assembleEapMethodTlsSettings(KyEapMethodTlsInfo &info,
|
||||
bool isAutoConnect, NetworkManager::Setting::SecretFlags secretFlags)
|
||||
{
|
||||
NetworkManager::ConnectionSettings::Ptr settings{new NetworkManager::ConnectionSettings{NetworkManager::ConnectionSettings::Wireless}};
|
||||
settings->setId(info.connName);
|
||||
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(info.connName.toUtf8());
|
||||
wifi_sett->setSecurity("802-11-wireless-security");
|
||||
|
||||
NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett
|
||||
= settings->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
|
||||
|
||||
QList<NetworkManager::Security8021xSetting::EapMethod> list;
|
||||
list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodTls);
|
||||
wifi_8021x_sett->setInitialized(true);
|
||||
wifi_8021x_sett->setEapMethods(list);
|
||||
wifi_8021x_sett->setIdentity(info.identity);
|
||||
if (!info.domain.isEmpty()){
|
||||
wifi_8021x_sett->setDomainSuffixMatch(info.domain);
|
||||
}
|
||||
QByteArray caCerEndWithNull(info.caCertPath.toUtf8() + '\0');
|
||||
wifi_8021x_sett->setCaCertificate(caCerEndWithNull);
|
||||
QByteArray cliCertEndWithNull(info.clientCertPath.toUtf8() + '\0');
|
||||
wifi_8021x_sett->setClientCertificate(cliCertEndWithNull);
|
||||
QByteArray cliPriKeyEndWithNull(info.clientPrivateKey.toUtf8() + '\0');
|
||||
wifi_8021x_sett->setPrivateKey(cliPriKeyEndWithNull);
|
||||
wifi_8021x_sett->setPrivateKeyPassword(info.clientPrivateKeyPWD);
|
||||
wifi_8021x_sett->setPrivateKeyPasswordFlags(secretFlags);
|
||||
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
security_sett->setInitialized(true);
|
||||
security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr KyEnterPriceSettingInfo::assembleEapMethodPeapSettings(KyEapMethodPeapInfo &info,
|
||||
bool isAutoConnect, NetworkManager::Setting::SecretFlags secretFlags)
|
||||
{
|
||||
qDebug() << "assembleEapMethodPeapSettings";
|
||||
NetworkManager::ConnectionSettings::Ptr settings{new NetworkManager::ConnectionSettings{NetworkManager::ConnectionSettings::Wireless}};
|
||||
settings->setId(info.connName);
|
||||
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(info.connName.toUtf8());
|
||||
wifi_sett->setSecurity("802-11-wireless-security");
|
||||
|
||||
NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett
|
||||
= settings->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
|
||||
|
||||
QList<NetworkManager::Security8021xSetting::EapMethod> list;
|
||||
list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodPeap);
|
||||
wifi_8021x_sett->setInitialized(true);
|
||||
wifi_8021x_sett->setEapMethods(list);
|
||||
wifi_8021x_sett->setPhase2AuthEapMethod((NetworkManager::Security8021xSetting::AuthEapMethod)info.phase2AuthMethod);
|
||||
wifi_8021x_sett->setIdentity(info.userName);
|
||||
wifi_8021x_sett->setPassword(info.userPWD);
|
||||
wifi_8021x_sett->setPrivateKeyPasswordFlags(secretFlags);
|
||||
|
||||
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
security_sett->setInitialized(true);
|
||||
security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap);
|
||||
security_sett->setAuthAlg(NetworkManager::WirelessSecuritySetting::Open);
|
||||
|
||||
return settings;
|
||||
}
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr KyEnterPriceSettingInfo::assembleEapMethodTtlsSettings(KyEapMethodTtlsInfo &info,
|
||||
bool isAutoConnect, NetworkManager::Setting::SecretFlags secretFlags)
|
||||
{
|
||||
NetworkManager::ConnectionSettings::Ptr settings{new NetworkManager::ConnectionSettings{NetworkManager::ConnectionSettings::Wireless}};
|
||||
settings->setId(info.connName);
|
||||
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(info.connName.toUtf8());
|
||||
wifi_sett->setSecurity("802-11-wireless-security");
|
||||
|
||||
NetworkManager::Security8021xSetting::Ptr wifi_8021x_sett
|
||||
= settings->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
|
||||
|
||||
QList<NetworkManager::Security8021xSetting::EapMethod> list;
|
||||
list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodTtls);
|
||||
wifi_8021x_sett->setInitialized(true);
|
||||
wifi_8021x_sett->setEapMethods(list);
|
||||
if (info.authType == KyTtlsAuthMethod::AUTH_EAP)
|
||||
{
|
||||
wifi_8021x_sett->setPhase2AuthEapMethod((NetworkManager::Security8021xSetting::AuthEapMethod)info.authEapMethod);//gtc md5 mschapv2 otp tls
|
||||
} else if (info.authType == KyTtlsAuthMethod::AUTH_NO_EAP)
|
||||
{
|
||||
wifi_8021x_sett->setPhase2AuthMethod((NetworkManager::Security8021xSetting::AuthMethod)info.authNoEapMethod);//chap md5 mschapv2 pap gtc mschap otp tls
|
||||
}
|
||||
wifi_8021x_sett->setIdentity(info.userName);
|
||||
wifi_8021x_sett->setPassword(info.userPWD);
|
||||
wifi_8021x_sett->setPrivateKeyPasswordFlags(secretFlags);
|
||||
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
security_sett->setInitialized(true);
|
||||
security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap);
|
||||
|
||||
return settings;
|
||||
}
|
|
@ -0,0 +1,88 @@
|
|||
#ifndef KYENTERPRICESETTINGINFO_H
|
||||
#define KYENTERPRICESETTINGINFO_H
|
||||
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include <QObject>
|
||||
|
||||
class KyEapMethodTlsInfo
|
||||
{
|
||||
public:
|
||||
QString connName;
|
||||
QString identity;
|
||||
QString domain;
|
||||
QString devIfaceName;
|
||||
QString caCertPath;
|
||||
QString clientCertPath;
|
||||
QString clientPrivateKey;
|
||||
QString clientPrivateKeyPWD;
|
||||
};
|
||||
|
||||
typedef enum{
|
||||
AuthEapMethodPeapUnknown = 0,
|
||||
AuthEapMethodPeapMd5,
|
||||
AuthEapMethodPeapMschapv2,
|
||||
AuthEapMethodPeapOtp,
|
||||
AuthEapMethodPeapGtc,
|
||||
AuthEapMethodPeapTls
|
||||
} KyEapMethodPeapAuth;
|
||||
|
||||
class KyEapMethodPeapInfo
|
||||
{
|
||||
public:
|
||||
QString connName;
|
||||
KyEapMethodPeapAuth phase2AuthMethod;
|
||||
QString userName;
|
||||
QString userPWD;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
AuthEapMethodTtlsUnknown = 0,
|
||||
AuthEapMethodTtlsMd5,
|
||||
AuthEapMethodTtlsMschapv2,
|
||||
AuthEapMethodTtlsOtp,
|
||||
AuthEapMethodTtlsGtc,
|
||||
AuthEapMethodTtlsTls
|
||||
} KyEapMethodTtlsAuth;
|
||||
|
||||
typedef enum{
|
||||
AuthMethodTtlsUnknown = 0,
|
||||
AuthMethodTtlsPap,
|
||||
AuthMethodTtlsChap,
|
||||
AuthMethodTtlsMschap,
|
||||
AuthMethodTtlsMschapv2,
|
||||
AuthMethodTtlsGtc,
|
||||
AuthMethodTtlsOtp,
|
||||
AuthMethodTtlsMd5,
|
||||
AuthMethodTtlsTls
|
||||
} KyNoEapMethodTtlsAuth;
|
||||
|
||||
enum KyTtlsAuthMethod
|
||||
{
|
||||
AUTH_EAP,
|
||||
AUTH_NO_EAP
|
||||
};
|
||||
|
||||
class KyEapMethodTtlsInfo
|
||||
{
|
||||
public:
|
||||
QString connName;
|
||||
KyTtlsAuthMethod authType;
|
||||
KyEapMethodTtlsAuth authEapMethod;
|
||||
KyNoEapMethodTtlsAuth authNoEapMethod;
|
||||
QString userName;
|
||||
QString userPWD;
|
||||
};
|
||||
|
||||
class KyEnterPriceSettingInfo : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KyEnterPriceSettingInfo(QObject *parent = nullptr);
|
||||
|
||||
static NetworkManager::ConnectionSettings::Ptr assembleEapMethodTlsSettings(KyEapMethodTlsInfo &, bool, NetworkManager::Setting::SecretFlags);
|
||||
static NetworkManager::ConnectionSettings::Ptr assembleEapMethodPeapSettings(KyEapMethodPeapInfo &, bool, NetworkManager::Setting::SecretFlags);
|
||||
static NetworkManager::ConnectionSettings::Ptr assembleEapMethodTtlsSettings(KyEapMethodTtlsInfo &, bool, NetworkManager::Setting::SecretFlags);
|
||||
|
||||
};
|
||||
|
||||
#endif // KYENTERPRICESETTINGINFO_H
|
|
@ -306,6 +306,7 @@ int KyNetworkConnect::deactivateConnection(const QString connectName, const QStr
|
|||
QDBusPendingReply<> reply = NetworkManager::deactivateConnection(activateConnectPtr->path());
|
||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [activateConnectPtr] (QDBusPendingCallWatcher * watcher) {
|
||||
qDebug() << "finshed";
|
||||
//TODO::it may should send signal deactivateConnectionFinished
|
||||
if (watcher->isError() || !watcher->isValid()) {
|
||||
//TODO: in what form should we output the warning messages
|
||||
|
@ -459,7 +460,6 @@ void KyNetworkConnect::addAndActivateWirelessConnection(NetworkManager::Wireless
|
|||
}
|
||||
else{
|
||||
emit checkActiveonnection((qdbus_cast<QDBusObjectPath>(watcher->reply().arguments().at(1))).path());
|
||||
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
|
@ -471,6 +471,7 @@ void KyNetworkConnect::onActivateWirelessConnection(const QString &connectSsid,
|
|||
NetworkManager::WirelessNetwork::Ptr wirelessNet = nullptr;
|
||||
for (auto const & net : m_networkResourceInstance->m_wifiNets)
|
||||
{
|
||||
qDebug() << net->ssid() << " " << connectSsid;
|
||||
if (net->ssid() == connectSsid)
|
||||
{
|
||||
wirelessNet = net;
|
||||
|
@ -481,7 +482,7 @@ void KyNetworkConnect::onActivateWirelessConnection(const QString &connectSsid,
|
|||
if (wirelessNet.isNull())
|
||||
{
|
||||
//TODO:隐藏wifi不会存在与AP中,需要新建connection去连接
|
||||
qDebug() << "hidewifi";
|
||||
qDebug() << "hidewifi";emit noConnection();
|
||||
return;
|
||||
}
|
||||
|
||||
|
|
|
@ -51,10 +51,87 @@ KyNetworkResourceManager::KyNetworkResourceManager()
|
|||
connect(NetworkManager::settingsNotifier(), &NetworkManager::SettingsNotifier::connectionAdded, this, &KyNetworkResourceManager::onConnectionAdded);
|
||||
connect(NetworkManager::settingsNotifier(), &NetworkManager::SettingsNotifier::connectionRemoved, this, static_cast<void (KyNetworkResourceManager::*)(QString const &)>(&KyNetworkResourceManager::onConnectionRemoved));
|
||||
|
||||
//todo wifi开关信号
|
||||
connect(NetworkManager::notifier(), &NetworkManager::Notifier::wirelessEnabledChanged, this, &KyNetworkResourceManager::wifinEnabledChanged);
|
||||
connect(NetworkManager::notifier(), &NetworkManager::Notifier::wirelessHardwareEnabledChanged, [=](){
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
// Note: the connectionRemoved is never emitted in case network-manager service stop,
|
||||
// we need remove the connections manually.
|
||||
connect(NetworkManager::notifier(), &NetworkManager::Notifier::serviceDisappeared, this, &KyNetworkResourceManager::clearConnections);
|
||||
|
||||
|
||||
|
||||
connect(this, &KyNetworkResourceManager::wifiNetworkAdd, [this] (NetworkManager::Device * dev, QString const & ssid) {
|
||||
qDebug() << "wifiNetworkAdd" << dev << dev->interfaceName() << ssid;
|
||||
NetworkManager::WirelessDevice * w_dev = qobject_cast<NetworkManager::WirelessDevice *>(dev);
|
||||
NetworkManager::WirelessNetwork::Ptr net = w_dev->findNetwork(ssid);
|
||||
if (!net.isNull())
|
||||
{
|
||||
if (0 > m_wifiNets.indexOf(net))
|
||||
{
|
||||
addWifiNetwork(net);
|
||||
} else
|
||||
{
|
||||
//TODO: onWifiNetworkUpdate
|
||||
qDebug() << "add but already exist";
|
||||
}
|
||||
emit wifiNetworkAdded(dev->interfaceName(), ssid);
|
||||
}
|
||||
});
|
||||
connect(this, &KyNetworkResourceManager::wifiNetworkUpdate, [this] (NetworkManager::WirelessNetwork * net) {
|
||||
|
||||
auto i = std::find(m_wifiNets.cbegin(), m_wifiNets.cend(), net);
|
||||
if (m_wifiNets.cend() != i)
|
||||
{
|
||||
if (net->accessPoints().isEmpty())
|
||||
{
|
||||
//emit
|
||||
bool bFlag = false;
|
||||
QString devIface;
|
||||
NetworkManager::Device::Ptr dev = findDeviceUni(net->device());
|
||||
if(dev.isNull())
|
||||
{
|
||||
qDebug() << "device invalid";
|
||||
bFlag = true;
|
||||
} else {
|
||||
devIface = dev->interfaceName();
|
||||
}
|
||||
//remove
|
||||
auto pos = i - m_wifiNets.cbegin();
|
||||
removeWifiNetwork(pos);
|
||||
if(bFlag)
|
||||
{
|
||||
//device invalid
|
||||
qDebug() << "wifiNetworkDeviceDisappear";
|
||||
emit wifiNetworkDeviceDisappear();
|
||||
} else {
|
||||
qDebug() << "wifiNetwork disappear" << net << net->ssid();
|
||||
emit wifiNetworkRemoved(devIface,net->ssid());
|
||||
}
|
||||
} else {
|
||||
qDebug() << "wifiNetworkPropertyChange " << net << net->ssid();
|
||||
emit wifiNetworkPropertyChange(net);
|
||||
}
|
||||
}
|
||||
});
|
||||
connect(this, &KyNetworkResourceManager::wifiNetworkRemove, [this] (NetworkManager::Device * dev, QString const & ssid) {
|
||||
qDebug() << "wifiNetworkRemove" << dev << dev->interfaceName() << ssid;
|
||||
NetworkManager::WirelessNetwork::Ptr net = findWifiNetwork(ssid, dev->uni());
|
||||
if (!net.isNull())
|
||||
{
|
||||
auto pos = m_wifiNets.indexOf(net);
|
||||
if (0 <= pos)
|
||||
{
|
||||
removeWifiNetwork(pos);
|
||||
emit wifiNetworkRemoved(dev->interfaceName(), ssid);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
qDebug() << m_activeConns.size() << m_connections.size() << m_devices.size();
|
||||
}
|
||||
|
||||
|
@ -90,7 +167,7 @@ void KyNetworkResourceManager::addActiveConnection(NetworkManager::ActiveConnect
|
|||
connect(conn.data(), &NetworkManager::ActiveConnection::typeChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::masterChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::specificObjectChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::stateChangedReason, this, &KyNetworkResourceManager::onActiveConnectionChangedReason);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::stateChangedReason, this, &KyNetworkResourceManager::onActiveConnectionChangedReason);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::stateChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::vpnChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
connect(conn.data(), &NetworkManager::ActiveConnection::uuidChanged, this, &KyNetworkResourceManager::onActiveConnectionUpdated);
|
||||
|
@ -237,6 +314,7 @@ void KyNetworkResourceManager::addWifiNetwork(NetworkManager::WirelessNetwork::P
|
|||
|
||||
void KyNetworkResourceManager::insertWifiNetworks()
|
||||
{
|
||||
int count = 0;
|
||||
for (auto const & device : m_devices)
|
||||
{
|
||||
if (NetworkManager::Device::Wifi == device->type())
|
||||
|
@ -247,10 +325,12 @@ void KyNetworkResourceManager::insertWifiNetworks()
|
|||
if (!net.isNull())
|
||||
{
|
||||
addWifiNetwork(net);
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
qDebug() << "insertWifiNetworks" << count;
|
||||
}
|
||||
|
||||
NetworkManager::ActiveConnection::Ptr KyNetworkResourceManager::findActiveConnection(QString const & path)
|
||||
|
@ -360,7 +440,7 @@ void KyNetworkResourceManager::onConnectionUpdated()
|
|||
|
||||
void KyNetworkResourceManager::onConnectionRemoved()
|
||||
{
|
||||
emit connectionRemove(qobject_cast<NetworkManager::Connection *>(sender()));
|
||||
emit connectionRemove(qobject_cast<NetworkManager::Connection *>(sender())->uuid());
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onActiveConnectionUpdated()
|
||||
|
@ -386,12 +466,15 @@ void KyNetworkResourceManager::onDeviceStateChanged(
|
|||
NetworkManager::Device::State oldstate,
|
||||
NetworkManager::Device::StateChangeReason reason)
|
||||
{
|
||||
NetworkManager::WiredDevice *wiredDevice = qobject_cast<NetworkManager::WiredDevice *>(sender());
|
||||
if (wiredDevice->carrier()) {
|
||||
qWarning()<<"the device carrier true";
|
||||
} else {
|
||||
qWarning()<<"the device carrier false";
|
||||
}
|
||||
// NetworkManager::WiredDevice *wiredDevice = qobject_cast<NetworkManager::WiredDevice *>(sender());
|
||||
|
||||
// if (wiredDevice->type() == NM_DEVICE_TYPE_ETHERNET) {
|
||||
// if (wiredDevice->carrier()) {
|
||||
// qWarning()<<"the device carrier true";
|
||||
// } else {
|
||||
// qWarning()<<"the device carrier false";
|
||||
// }
|
||||
// }
|
||||
|
||||
qWarning()<<"the device state "<<oldstate << "to" <<newstate << "reason"<< reason;
|
||||
}
|
||||
|
@ -481,7 +564,6 @@ void KyNetworkResourceManager::onActiveConnectionRemoved(QString const & path)
|
|||
const int pos = index - m_activeConns.cbegin();
|
||||
removeActiveConnection(pos);
|
||||
}
|
||||
|
||||
emit activeConnectionRemove(conn.data());
|
||||
}
|
||||
}
|
||||
|
@ -503,27 +585,34 @@ void KyNetworkResourceManager::onConnectionAdded(QString const & path)
|
|||
addConnection(conn);
|
||||
} else {
|
||||
//TODO: onConnectionUpdate
|
||||
return;
|
||||
}
|
||||
|
||||
emit connectionAdd(conn);
|
||||
NetworkManager::ConnectionSettings::Ptr sett= conn->settings();
|
||||
qDebug() << "onConnectionAdded" << sett->name();
|
||||
}
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::onConnectionRemoved(QString const & path)
|
||||
{
|
||||
NetworkManager::Connection::Ptr conn = NetworkManager::findConnection(path);
|
||||
if (!conn.isNull()) {
|
||||
if (conn->isValid())
|
||||
qWarning() << Q_FUNC_INFO << path << " is currently invalid...";
|
||||
|
||||
auto index = std::find(m_connections.cbegin(), m_connections.cend(), conn);
|
||||
if (m_connections.cend() != index) {
|
||||
const int pos = index - m_connections.cbegin();
|
||||
removeConnection(pos);
|
||||
}
|
||||
|
||||
emit connectionRemove(conn.data());
|
||||
if (path.isEmpty()) {
|
||||
qDebug() <<"[KyNetworkResourceManager]" <<"the connect path is empty";
|
||||
return;
|
||||
}
|
||||
qDebug() <<"[KyNetworkResourceManager]" << "remove connection path" << path;
|
||||
NetworkManager::Connection::Ptr connectionPtr = nullptr;
|
||||
for (int index = 0; index < m_connections.size(); ++index) {
|
||||
connectionPtr = m_connections.at(index);
|
||||
if (connectionPtr->path() == path) {
|
||||
removeConnection(index);
|
||||
emit connectionRemove(path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
qWarning() <<"[KyNetworkResourceManager]" << path <<" connect is no exist in connect list";
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
void KyNetworkResourceManager::removeConnection(QString const & uuid)
|
||||
|
|
|
@ -40,6 +40,7 @@
|
|||
#include <NetworkManagerQt/WirelessSecuritySetting>
|
||||
#include <NetworkManagerQt/Utils>
|
||||
#include <NetworkManagerQt/ConnectionSettings>
|
||||
#include <NetworkManagerQt/Security8021xSetting>
|
||||
#include <QDBusPendingCallWatcher>
|
||||
#include <QInputDialog>
|
||||
#include <QMetaEnum>
|
||||
|
@ -95,7 +96,7 @@ public:
|
|||
signals:
|
||||
void connectionAdd(NetworkManager::Connection::Ptr conn);
|
||||
void connectionUpdate(NetworkManager::Connection * conn);
|
||||
void connectionRemove(NetworkManager::Connection * conn);
|
||||
// void connectionRemove(NetworkManager::Connection * conn);
|
||||
void activeConnectionAdd(NetworkManager::ActiveConnection::Ptr conn);
|
||||
void activeConnectionUpdate(NetworkManager::ActiveConnection * conn);
|
||||
void activeConnectionRemove(NetworkManager::ActiveConnection * conn);
|
||||
|
@ -107,6 +108,13 @@ signals:
|
|||
void wifiNetworkUpdate(NetworkManager::WirelessNetwork * net);
|
||||
void wifiNetworkRemove(NetworkManager::Device * dev, QString const & ssid);
|
||||
|
||||
//to KyWirelessNetResource
|
||||
void wifiNetworkRemoved(QString, QString);
|
||||
void wifiNetworkAdded(QString, QString);
|
||||
void wifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net);
|
||||
void wifiNetworkDeviceDisappear();
|
||||
void wifinEnabledChanged(bool);
|
||||
void connectionRemove(QString);
|
||||
|
||||
private slots:
|
||||
//connection
|
||||
|
|
|
@ -0,0 +1,597 @@
|
|||
#include "kywirelessconnectoperation.h"
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr assembleWpaXPskSettings(NetworkManager::AccessPoint::Ptr accessPoint, QString &psk, bool isAutoConnect, NetworkManager::Setting::SecretFlags secretFlag)
|
||||
{
|
||||
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::WpaPsk);
|
||||
}
|
||||
security_sett->setPsk(psk);
|
||||
return settings;
|
||||
}
|
||||
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr assembleWpaXPskHiddenSettings(QString &ssid, KySecuType &type, QString &psk, bool isAutoConnect, NetworkManager::Setting::SecretFlags secretFlag)
|
||||
{
|
||||
NetworkManager::ConnectionSettings::Ptr settings{new NetworkManager::ConnectionSettings{NetworkManager::ConnectionSettings::Wireless}};
|
||||
settings->setId(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(ssid.toUtf8());
|
||||
wifi_sett->setHidden(true);
|
||||
wifi_sett->setSecurity("802-11-wireless-security");
|
||||
|
||||
if (type != KySecuType::NONE)
|
||||
{
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
security_sett->setInitialized(true);
|
||||
switch (type) {
|
||||
case KySecuType::WPA_AND_WPA2_PERSONAL:
|
||||
security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaPsk);
|
||||
security_sett->setPskFlags(secretFlag);
|
||||
break;
|
||||
case KySecuType::WPA_AND_WPA2_ENTERPRISE:
|
||||
//TODO:隐藏企业wifi
|
||||
break;
|
||||
case KySecuType::WPA2_AND_WPA3_PERSONAL:
|
||||
security_sett->setKeyMgmt(NetworkManager::WirelessSecuritySetting::SAE);
|
||||
security_sett->setPskFlags(secretFlag);
|
||||
break;
|
||||
default:
|
||||
qDebug() << " unsupport security type";
|
||||
break;
|
||||
}
|
||||
|
||||
security_sett->setPsk(psk);
|
||||
}
|
||||
return settings;
|
||||
}
|
||||
|
||||
KyWirelessConnectOperation::KyWirelessConnectOperation(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifinEnabledChanged, this, &KyWirelessConnectOperation::wifinEnabledChanged);
|
||||
}
|
||||
|
||||
KyWirelessConnectOperation::~KyWirelessConnectOperation()
|
||||
{
|
||||
m_networkResourceInstance = nullptr;
|
||||
}
|
||||
|
||||
void KyWirelessConnectOperation::activeWirelessConnect(QString devIfaceName, QString connUuid)
|
||||
{
|
||||
NetworkManager::Connection::Ptr conn;
|
||||
conn = m_networkResourceInstance->getConnect(connUuid);
|
||||
if (conn.isNull())
|
||||
{
|
||||
qDebug() <<"get failed";
|
||||
emit connectFail(connUuid, devIfaceName, "connection do not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
QString conn_uni;
|
||||
QString dev_uni;
|
||||
QString spec_object;
|
||||
auto dev = m_networkResourceInstance->findDeviceInterface(devIfaceName);
|
||||
if (dev.isNull())
|
||||
{
|
||||
emit connectFail(conn->name(), devIfaceName, "devIface not exist");
|
||||
return;
|
||||
}
|
||||
dev_uni = dev->uni();
|
||||
conn_uni = conn->path();
|
||||
QDBusPendingCallWatcher * watcher;
|
||||
watcher = new QDBusPendingCallWatcher{NetworkManager::activateConnection(conn_uni, dev_uni, spec_object), this};
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) {
|
||||
if (watcher->isError() || !watcher->isValid())
|
||||
{
|
||||
qWarning() << QStringLiteral("activation of connection failed: %1").arg(watcher->error().message());
|
||||
emit connectFail(connUuid, devIfaceName, "Internal error");
|
||||
}
|
||||
qDebug() << "5";
|
||||
watcher->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
//void KyWirelessConnectOperation::activeWirelessConnectWithPwd(QString devIfaceName, QString connUuid, QString psk)
|
||||
//{
|
||||
|
||||
// //todo:
|
||||
// NetworkManager::Connection::Ptr conn;
|
||||
// conn = m_networkResourceInstance->getConnect(connUuid);
|
||||
// if (conn.isNull())
|
||||
// {
|
||||
// qDebug() <<"get failed";
|
||||
// emit connectFail(connUuid, devIfaceName, "connection do not exist");
|
||||
// return;
|
||||
// }
|
||||
|
||||
// NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
// = conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
// security_sett->setPsk(psk);
|
||||
|
||||
|
||||
// conn->update(conn->settings()->toMap());
|
||||
|
||||
|
||||
// QString conn_uni;
|
||||
// QString dev_uni;
|
||||
// QString spec_object;
|
||||
// auto dev = m_networkResourceInstance->findDeviceInterface(devIfaceName);
|
||||
// if (dev.isNull())
|
||||
// {
|
||||
// emit connectFail(conn->name(), devIfaceName, "devIface not exist");
|
||||
// return;
|
||||
// }
|
||||
// dev_uni = dev->uni();
|
||||
// conn_uni = conn->path();
|
||||
// QDBusPendingCallWatcher * watcher;
|
||||
// watcher = new QDBusPendingCallWatcher{NetworkManager::activateConnection(conn_uni, dev_uni, spec_object), this};
|
||||
// connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) {
|
||||
// if (watcher->isError() || !watcher->isValid())
|
||||
// {
|
||||
// qWarning() << QStringLiteral("activation of connection failed: %1").arg(watcher->error().message());
|
||||
// emit connectFail(connUuid, devIfaceName, "Internal error");
|
||||
// }
|
||||
// watcher->deleteLater();
|
||||
// });
|
||||
//}
|
||||
|
||||
void KyWirelessConnectOperation::deActiveWirelessConnect(QString &uuid)
|
||||
{
|
||||
int index = 0;
|
||||
NetworkManager::ActiveConnection::Ptr activateConnectPtr = nullptr;
|
||||
|
||||
qDebug()<<"deactivetate connect uuid "<<uuid;
|
||||
for (index = 0; index < m_networkResourceInstance->m_activeConns.size(); ++index) {
|
||||
activateConnectPtr = m_networkResourceInstance->m_activeConns.at(index);
|
||||
if (activateConnectPtr->uuid() == uuid) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (index >= m_networkResourceInstance->m_activeConns.size()) {
|
||||
qWarning()<<"it can not find the activate connect uuid "<<uuid;
|
||||
emit disConnectFail(uuid,"no","connection do not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << __FUNCTION__ <<"dead active connection path:"<< activateConnectPtr->path();
|
||||
|
||||
QDBusPendingReply<> reply = NetworkManager::deactivateConnection(activateConnectPtr->path());
|
||||
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) {
|
||||
if (watcher->isError() || !watcher->isValid()) {
|
||||
qWarning() << QStringLiteral("deactivation of connection failed");
|
||||
emit disConnectFail(uuid, "no", "Internal error");
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
void KyWirelessConnectOperation::addAndActiveWirelessConnect(QString & ssid, QString & devIface,
|
||||
QString psk, bool isAutoConnect, NetworkManager::Setting::SecretFlags secretFlags)
|
||||
{
|
||||
qDebug() << "addAndActiveWirelessConnect" << ssid << devIface <<psk;
|
||||
QString conn_uni;
|
||||
QString dev_uni;
|
||||
QString conn_name;
|
||||
QString dev_name;
|
||||
QString spec_object;
|
||||
NMVariantMapMap map_settings;
|
||||
bool bFind = false;
|
||||
|
||||
NetworkManager::WirelessNetwork::Ptr wifiNet = nullptr;
|
||||
|
||||
for (auto const & net : m_networkResourceInstance->m_wifiNets)
|
||||
{
|
||||
auto dev = m_networkResourceInstance->findDeviceUni(net->device());
|
||||
if (dev == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (dev->type() != NetworkManager::Device::Wifi || dev->interfaceName() != devIface)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (ssid == net->ssid())
|
||||
{
|
||||
wifiNet = net;
|
||||
bFind = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bFind)
|
||||
{
|
||||
qDebug() << "addAndActiveWirelessConnect can not find " << ssid << " in " << devIface;
|
||||
return;
|
||||
}
|
||||
|
||||
auto access_point = wifiNet->referenceAccessPoint();
|
||||
auto dev = m_networkResourceInstance->findDeviceInterface(devIface);
|
||||
if (dev.isNull())
|
||||
{
|
||||
emit connectFail(ssid, devIface, "devIface not exist");
|
||||
return;
|
||||
}
|
||||
auto spec_dev = dev->as<NetworkManager::WirelessDevice>();
|
||||
Q_ASSERT(nullptr != spec_dev);
|
||||
conn_uni = access_point->uni();
|
||||
conn_name = access_point->ssid();
|
||||
dev_name = dev->interfaceName();
|
||||
dev_uni = dev->uni();
|
||||
|
||||
spec_object = conn_uni;
|
||||
NetworkManager::WirelessSecurityType sec_type = NetworkManager::findBestWirelessSecurity(spec_dev->wirelessCapabilities()
|
||||
, true, (spec_dev->mode() == NetworkManager::WirelessDevice::Adhoc)
|
||||
, access_point->capabilities(), access_point->wpaFlags(), access_point->rsnFlags());
|
||||
|
||||
qDebug() << "findBestWirelessSecurity type "<< sec_type;
|
||||
switch (sec_type)
|
||||
{
|
||||
case NetworkManager::UnknownSecurity:
|
||||
qWarning() << QStringLiteral("unknown security to use for '%1'").arg(conn_name);
|
||||
case NetworkManager::NoneSecurity:
|
||||
//nothing to do
|
||||
break;
|
||||
case NetworkManager::WpaPsk:
|
||||
case NetworkManager::Wpa2Psk:
|
||||
if (NetworkManager::ConnectionSettings::Ptr settings = assembleWpaXPskSettings(access_point, psk, isAutoConnect ,secretFlags))
|
||||
{
|
||||
map_settings = settings->toMap();
|
||||
} else
|
||||
{
|
||||
qWarning() << QStringLiteral("connection settings assembly for '%1' failed, abandoning activation...").arg(conn_name);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
//TODO: other types...
|
||||
default:
|
||||
qDebug() << "not support";
|
||||
break;
|
||||
}
|
||||
|
||||
qDebug() << dev_uni;
|
||||
QDBusPendingCallWatcher * watcher;
|
||||
watcher = new QDBusPendingCallWatcher{NetworkManager::addAndActivateConnection(map_settings, dev_uni, spec_object), this};
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) {
|
||||
if (watcher->isError() || !watcher->isValid())
|
||||
{
|
||||
qDebug() << "activation of connection failed " << watcher->error().message();
|
||||
emit connectFail(ssid, devIface, "Internal error");
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
void KyWirelessConnectOperation::addAndActiveWirelessHiddenConnect(KySecuType &type, QString &ssid, QString &devIface,
|
||||
QString &psk, bool isAutoConnect, NetworkManager::Setting::SecretFlags secretFlags)
|
||||
{
|
||||
qDebug() << "addAndActiveWirelessHiddenConnect";
|
||||
QString conn_uni;
|
||||
QString dev_uni;
|
||||
QString conn_name;
|
||||
QString dev_name;
|
||||
QString spec_object;
|
||||
NMVariantMapMap map_settings;
|
||||
|
||||
auto dev = m_networkResourceInstance->findDeviceInterface(devIface);
|
||||
if (dev.isNull())
|
||||
{
|
||||
emit connectFail(ssid, devIface, "devIface not exist");
|
||||
return;
|
||||
}
|
||||
dev_name = dev->interfaceName();
|
||||
dev_uni = dev->uni();
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr settings = assembleWpaXPskHiddenSettings(ssid, type, psk, isAutoConnect, secretFlags);
|
||||
map_settings = settings->toMap();
|
||||
|
||||
|
||||
QDBusPendingCallWatcher * watcher;
|
||||
watcher = new QDBusPendingCallWatcher{NetworkManager::addAndActivateConnection(map_settings, dev_uni, spec_object), this};
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) {
|
||||
if (watcher->isError() || !watcher->isValid())
|
||||
{
|
||||
qDebug() << "activation of connection failed " << watcher->error().message();
|
||||
emit connectFail(ssid, devIface, "Internal error");
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
void KyWirelessConnectOperation::requestWirelessScan()
|
||||
{
|
||||
for (auto const & dev : m_networkResourceInstance->m_devices)
|
||||
{
|
||||
auto spec_dev = dev->as<NetworkManager::WirelessDevice>();
|
||||
if (nullptr != spec_dev)
|
||||
{
|
||||
m_networkResourceInstance->requestScan(spec_dev);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void KyWirelessConnectOperation::addAndActiveWirelessEnterPriseTlsConnect(KyEapMethodTlsInfo &info, QString & devIface,
|
||||
bool isHidden, bool isAutoConnect, NetworkManager::Setting::SecretFlags secretFlags)
|
||||
{
|
||||
QString conn_uni;
|
||||
QString dev_uni;
|
||||
QString conn_name;
|
||||
QString dev_name;
|
||||
QString spec_object;
|
||||
NMVariantMapMap map_settings;
|
||||
bool bFind = false;
|
||||
|
||||
if (!isHidden)
|
||||
{
|
||||
NetworkManager::WirelessNetwork::Ptr wifiNet = nullptr;
|
||||
|
||||
for (auto const & net : m_networkResourceInstance->m_wifiNets)
|
||||
{
|
||||
auto dev = m_networkResourceInstance->findDeviceUni(net->device());
|
||||
if (dev == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (dev->type() != NetworkManager::Device::Wifi || dev->interfaceName() != devIface)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (info.connName == net->ssid())
|
||||
{
|
||||
wifiNet = net;
|
||||
bFind = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bFind)
|
||||
{
|
||||
qDebug() << "addAndActiveWirelessEnterPriseTlsConnect can not find " << info.connName << " in " << devIface;
|
||||
return;
|
||||
}
|
||||
|
||||
auto access_point = wifiNet->referenceAccessPoint();
|
||||
conn_uni = access_point->uni();
|
||||
conn_name = access_point->ssid();
|
||||
spec_object = conn_uni;
|
||||
}
|
||||
|
||||
auto dev = m_networkResourceInstance->findDeviceInterface(devIface);
|
||||
if (dev.isNull())
|
||||
{
|
||||
emit connectFail(info.connName, devIface, "devIface not exist");
|
||||
return;
|
||||
}
|
||||
dev_name = dev->interfaceName();
|
||||
dev_uni = dev->uni();
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr settings = KyEnterPriceSettingInfo::assembleEapMethodTlsSettings(info, isAutoConnect, secretFlags);
|
||||
if(settings.isNull())
|
||||
{
|
||||
qDebug() << "assembleEapMethodPeapSettings failed";
|
||||
return;
|
||||
}
|
||||
|
||||
map_settings = settings->toMap();
|
||||
|
||||
QDBusPendingCallWatcher * watcher;
|
||||
watcher = new QDBusPendingCallWatcher{NetworkManager::addAndActivateConnection(map_settings, dev_uni, spec_object), this};
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) {
|
||||
if (watcher->isError() || !watcher->isValid())
|
||||
{
|
||||
qDebug() << "activation of connection failed " << watcher->error().message();
|
||||
emit connectFail(info.connName, devIface, "Internal error");
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void KyWirelessConnectOperation::addAndActiveWirelessEnterPrisePeapConnect(KyEapMethodPeapInfo &info, QString &devIface,
|
||||
bool isHidden, bool isAutoConnect, NetworkManager::Setting::SecretFlags secretFlags)
|
||||
{
|
||||
qDebug() <<"addAndActiveWirelessEnterPrisePeapConnect";
|
||||
QString conn_uni;
|
||||
QString dev_uni;
|
||||
QString conn_name;
|
||||
QString dev_name;
|
||||
QString spec_object;
|
||||
NMVariantMapMap map_settings;
|
||||
bool bFind = false;
|
||||
|
||||
if (!isHidden)
|
||||
{
|
||||
NetworkManager::WirelessNetwork::Ptr wifiNet = nullptr;
|
||||
|
||||
for (auto const & net : m_networkResourceInstance->m_wifiNets)
|
||||
{
|
||||
auto dev = m_networkResourceInstance->findDeviceUni(net->device());
|
||||
if (dev == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (dev->type() != NetworkManager::Device::Wifi || dev->interfaceName() != devIface)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (info.connName == net->ssid())
|
||||
{
|
||||
wifiNet = net;
|
||||
bFind = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bFind)
|
||||
{
|
||||
qDebug() << "addAndActiveWirelessEnterPrisePeapConnect can not find " << info.connName << " in " << devIface;
|
||||
return;
|
||||
}
|
||||
|
||||
auto access_point = wifiNet->referenceAccessPoint();
|
||||
|
||||
conn_uni = access_point->uni();
|
||||
conn_name = access_point->ssid();
|
||||
spec_object = conn_uni;
|
||||
}
|
||||
|
||||
auto dev = m_networkResourceInstance->findDeviceInterface(devIface);
|
||||
if (dev.isNull())
|
||||
{
|
||||
emit connectFail(info.connName, devIface, "devIface not exist");
|
||||
return;
|
||||
}
|
||||
dev_name = dev->interfaceName();
|
||||
dev_uni = dev->uni();
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr settings = KyEnterPriceSettingInfo::assembleEapMethodPeapSettings(info, isAutoConnect, secretFlags);
|
||||
if(settings.isNull())
|
||||
{
|
||||
qDebug() << "assembleEapMethodPeapSettings failed";
|
||||
return;
|
||||
}
|
||||
|
||||
map_settings = settings->toMap();
|
||||
|
||||
QDBusPendingCallWatcher * watcher;
|
||||
watcher = new QDBusPendingCallWatcher{NetworkManager::addAndActivateConnection(map_settings, dev_uni, spec_object), this};
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) {
|
||||
if (watcher->isError() || !watcher->isValid())
|
||||
{
|
||||
qDebug() << "activation of connection failed " << watcher->error().message();
|
||||
emit connectFail(info.connName, devIface, "Internal error");
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
void KyWirelessConnectOperation::addAndActiveWirelessEnterPriseTtlsConnect(KyEapMethodTtlsInfo &info, QString &devIface,
|
||||
bool isHidden, bool isAutoConnect, NetworkManager::Setting::SecretFlags secretFlags)
|
||||
{
|
||||
QString conn_uni;
|
||||
QString dev_uni;
|
||||
QString conn_name;
|
||||
QString dev_name;
|
||||
QString spec_object;
|
||||
NMVariantMapMap map_settings;
|
||||
bool bFind = false;
|
||||
|
||||
if (!isHidden)
|
||||
{
|
||||
NetworkManager::WirelessNetwork::Ptr wifiNet = nullptr;
|
||||
|
||||
for (auto const & net : m_networkResourceInstance->m_wifiNets)
|
||||
{
|
||||
auto dev = m_networkResourceInstance->findDeviceUni(net->device());
|
||||
if (dev == nullptr)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (dev->type() != NetworkManager::Device::Wifi || dev->interfaceName() != devIface)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (info.connName == net->ssid())
|
||||
{
|
||||
wifiNet = net;
|
||||
bFind = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!bFind)
|
||||
{
|
||||
qDebug() << "addAndActiveWirelessEnterPriseTlsConnect can not find " << info.connName << " in " << devIface;
|
||||
return;
|
||||
}
|
||||
|
||||
auto access_point = wifiNet->referenceAccessPoint();
|
||||
conn_uni = access_point->uni();
|
||||
conn_name = access_point->ssid();
|
||||
spec_object = conn_uni;
|
||||
}
|
||||
|
||||
auto dev = m_networkResourceInstance->findDeviceInterface(devIface);
|
||||
if (dev.isNull())
|
||||
{
|
||||
emit connectFail(info.connName, devIface, "devIface not exist");
|
||||
return;
|
||||
}
|
||||
dev_name = dev->interfaceName();
|
||||
dev_uni = dev->uni();
|
||||
|
||||
NetworkManager::ConnectionSettings::Ptr settings = KyEnterPriceSettingInfo::assembleEapMethodTtlsSettings(info, isAutoConnect, secretFlags);
|
||||
if(settings.isNull())
|
||||
{
|
||||
qDebug() << "assembleEapMethodPeapSettings failed";
|
||||
return;
|
||||
}
|
||||
|
||||
map_settings = settings->toMap();
|
||||
|
||||
QDBusPendingCallWatcher * watcher;
|
||||
watcher = new QDBusPendingCallWatcher{NetworkManager::addAndActivateConnection(map_settings, dev_uni, spec_object), this};
|
||||
connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) {
|
||||
if (watcher->isError() || !watcher->isValid())
|
||||
{
|
||||
qDebug() << "activation of connection failed " << watcher->error().message();
|
||||
emit connectFail(info.connName, devIface, "Internal error");
|
||||
}
|
||||
watcher->deleteLater();
|
||||
});
|
||||
}
|
||||
|
||||
//无线网络开关设置
|
||||
void KyWirelessConnectOperation::setWirelessEnabled(bool enabled)
|
||||
{
|
||||
NetworkManager::setWirelessEnabled(enabled);
|
||||
}
|
||||
|
||||
bool KyWirelessConnectOperation::getWirelessEnabled()
|
||||
{
|
||||
return NetworkManager::isWirelessEnabled();
|
||||
}
|
||||
|
||||
bool KyWirelessConnectOperation::getConnSecretFlags(QString &connUuid, NetworkManager::Setting::SecretFlags &flag)
|
||||
{
|
||||
NetworkManager::Connection::Ptr conn;
|
||||
conn = m_networkResourceInstance->getConnect(connUuid);
|
||||
if (conn.isNull())
|
||||
{
|
||||
qDebug() <<"get failed";
|
||||
return false;
|
||||
}
|
||||
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
flag = security_sett->pskFlags();
|
||||
return true;
|
||||
}
|
|
@ -0,0 +1,52 @@
|
|||
#ifndef KYWIRELESSCONNECTOPERATION_H
|
||||
#define KYWIRELESSCONNECTOPERATION_H
|
||||
|
||||
#include <QObject>
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kyenterpricesettinginfo.h"
|
||||
#include "kylinconnectinfo.h"
|
||||
|
||||
enum KySecuType {
|
||||
NONE = 0,
|
||||
WPA_AND_WPA2_PERSONAL,
|
||||
WPA_AND_WPA2_ENTERPRISE,
|
||||
WPA2_AND_WPA3_PERSONAL
|
||||
};
|
||||
|
||||
class KyWirelessConnectOperation : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KyWirelessConnectOperation(QObject *parent = nullptr);
|
||||
~KyWirelessConnectOperation();
|
||||
|
||||
void setWirelessEnabled(bool enabled);
|
||||
bool getWirelessEnabled();
|
||||
|
||||
bool getConnSecretFlags(QString &, NetworkManager::Setting::SecretFlags &);
|
||||
|
||||
void activeWirelessConnect(QString , QString);
|
||||
//todo:
|
||||
// void activeWirelessConnectWithPwd(QString , QString, QString);
|
||||
void deActiveWirelessConnect(QString &);
|
||||
void addAndActiveWirelessConnect(QString &, QString &, QString, bool, NetworkManager::Setting::SecretFlags);
|
||||
void requestWirelessScan();
|
||||
//仅普通隐藏wifi
|
||||
void addAndActiveWirelessHiddenConnect(KySecuType &, QString &, QString &, QString &, bool, NetworkManager::Setting::SecretFlags flags = 0);
|
||||
//企业wifi
|
||||
void addAndActiveWirelessEnterPriseTlsConnect(KyEapMethodTlsInfo &, QString &, bool, bool, NetworkManager::Setting::SecretFlags flags = 0);
|
||||
void addAndActiveWirelessEnterPrisePeapConnect(KyEapMethodPeapInfo &, QString &, bool, bool, NetworkManager::Setting::SecretFlags flags = 0);
|
||||
void addAndActiveWirelessEnterPriseTtlsConnect(KyEapMethodTtlsInfo &, QString &, bool, bool, NetworkManager::Setting::SecretFlags flags = 0);
|
||||
|
||||
|
||||
signals:
|
||||
void connectFail(QString, QString, QString);//连接失败信号
|
||||
void disConnectFail(QString, QString, QString);
|
||||
void wifinEnabledChanged(bool);
|
||||
|
||||
private:
|
||||
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
|
||||
|
||||
};
|
||||
|
||||
#endif // KYWIRELESSCONNECTOPERATION_H
|
|
@ -0,0 +1,90 @@
|
|||
#include "kywirelessnetitem.h"
|
||||
#include <NetworkManagerQt/Connection>
|
||||
|
||||
QString enumToQstring(NetworkManager::AccessPoint::Capabilities cap, NetworkManager::AccessPoint::WpaFlags wpa_flags,NetworkManager::AccessPoint::WpaFlags rsn_flags)
|
||||
{
|
||||
QString out;
|
||||
if ( (cap & NM_802_11_AP_FLAGS_PRIVACY)
|
||||
&& (wpa_flags == NM_802_11_AP_SEC_NONE)
|
||||
&& (rsn_flags == NM_802_11_AP_SEC_NONE)) {
|
||||
out += "WEP ";
|
||||
}
|
||||
if (wpa_flags != NM_802_11_AP_SEC_NONE) {
|
||||
out += "WPA1 ";
|
||||
}
|
||||
if ((rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_PSK)
|
||||
|| (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
|
||||
out += "WPA2 ";
|
||||
}
|
||||
if (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_SAE) {
|
||||
out += "WPA3 ";
|
||||
}
|
||||
if ( (wpa_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)
|
||||
|| (rsn_flags & NM_802_11_AP_SEC_KEY_MGMT_802_1X)) {
|
||||
out += "802.1X ";
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
KyWirelessNetItem::KyWirelessNetItem(NetworkManager::WirelessNetwork::Ptr net)
|
||||
{
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
|
||||
m_bssid = "";
|
||||
m_connectUuid = "";
|
||||
m_isConfigured = false;
|
||||
m_connName = "";
|
||||
m_connDbusPath = "";
|
||||
m_secuType = "";
|
||||
|
||||
init(net);
|
||||
}
|
||||
|
||||
|
||||
KyWirelessNetItem::~KyWirelessNetItem()
|
||||
{
|
||||
m_networkResourceInstance = nullptr;
|
||||
}
|
||||
|
||||
|
||||
void KyWirelessNetItem::init(NetworkManager::WirelessNetwork::Ptr net)
|
||||
{
|
||||
m_NetSsid = net->ssid();
|
||||
m_signalStrength = net->signalStrength();
|
||||
m_frequency = net->referenceAccessPoint()->frequency();
|
||||
NetworkManager::AccessPoint::Capabilities cap = net->referenceAccessPoint()->capabilities();
|
||||
NetworkManager::AccessPoint::WpaFlags wpaFlag = net->referenceAccessPoint()->wpaFlags();
|
||||
NetworkManager::AccessPoint::WpaFlags rsnFlag = net->referenceAccessPoint()->rsnFlags();
|
||||
m_secuType = enumToQstring(cap, wpaFlag, rsnFlag);
|
||||
m_bssid = net->referenceAccessPoint()->hardwareAddress();
|
||||
initInfoBySsid();
|
||||
}
|
||||
|
||||
void KyWirelessNetItem::initInfoBySsid()
|
||||
{
|
||||
for (auto const & conn : m_networkResourceInstance->m_connections)
|
||||
{
|
||||
NetworkManager::ConnectionSettings::Ptr settings = conn->settings();
|
||||
if (settings->connectionType() != NetworkManager::ConnectionSettings::Wireless)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
NetworkManager::WirelessSetting::Ptr wifi_sett
|
||||
= settings->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
|
||||
if (wifi_sett->ssid() == m_NetSsid)
|
||||
{
|
||||
m_connectUuid = settings->uuid();
|
||||
m_connName = conn->name();
|
||||
m_connDbusPath = conn->path();
|
||||
m_isConfigured = true;
|
||||
|
||||
if(wifi_sett->ssid() == "NewWifi")
|
||||
{
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
qDebug() << security_sett->keyMgmt();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,38 @@
|
|||
#ifndef KYWIRELESSNETITEM_H
|
||||
#define KYWIRELESSNETITEM_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
|
||||
QString enumToQstring(NetworkManager::AccessPoint::Capabilities, NetworkManager::AccessPoint::WpaFlags, NetworkManager::AccessPoint::WpaFlags);
|
||||
|
||||
class KyWirelessNetItem
|
||||
{
|
||||
public:
|
||||
KyWirelessNetItem(NetworkManager::WirelessNetwork::Ptr net);
|
||||
~KyWirelessNetItem();
|
||||
|
||||
private:
|
||||
void init(NetworkManager::WirelessNetwork::Ptr net);
|
||||
void initInfoBySsid();
|
||||
|
||||
public:
|
||||
QString m_NetSsid;
|
||||
QString m_connectUuid;
|
||||
QString m_bssid;
|
||||
int m_signalStrength;
|
||||
uint m_frequency;
|
||||
bool m_isConfigured;
|
||||
QString m_connName;
|
||||
QString m_connDbusPath;
|
||||
QString m_secuType;
|
||||
// NetworkManager::AccessPoint::WpaFlags m_wpaFlag;
|
||||
// NetworkManager::AccessPoint::WpaFlags m_rsnFlag;
|
||||
|
||||
private:
|
||||
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
|
||||
|
||||
};
|
||||
|
||||
#endif // KYWIRELESSNETITEM_H
|
|
@ -0,0 +1,599 @@
|
|||
#include "kywirelessnetresource.h"
|
||||
|
||||
KyWirelessNetResource::KyWirelessNetResource(QObject *parent)
|
||||
: QObject(parent)
|
||||
{
|
||||
qDebug()<<"KyWirelessNetResource";
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
|
||||
kyWirelessNetItemListInit();
|
||||
|
||||
//TODO:connect device signal
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkAdded, this, &KyWirelessNetResource::onWifiNetworkAdded);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkRemoved, this, &KyWirelessNetResource::onWifiNetworkRemoved);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkPropertyChange, this, &KyWirelessNetResource::onWifiNetworkPropertyChange);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::wifiNetworkDeviceDisappear, this, &KyWirelessNetResource::onWifiNetworkDeviceDisappear);
|
||||
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionAdd, this, &KyWirelessNetResource::onConnectionAdd);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::connectionRemove, this, &KyWirelessNetResource::onConnectionRemove);
|
||||
|
||||
}
|
||||
|
||||
KyWirelessNetResource::~KyWirelessNetResource()
|
||||
{
|
||||
m_networkResourceInstance = nullptr;
|
||||
}
|
||||
|
||||
bool KyWirelessNetResource::getAllDeviceWifiNetwork(QMap<QString,QList<KyWirelessNetItem> > &map)
|
||||
{
|
||||
onWifiNetworkDeviceDisappear();
|
||||
if (m_WifiNetworkList.isEmpty())
|
||||
{
|
||||
return false;
|
||||
} else {
|
||||
map = m_WifiNetworkList;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bool KyWirelessNetResource::getDeviceWifiNetwork(QString devIfaceName, QList<KyWirelessNetItem> &list)
|
||||
{
|
||||
onWifiNetworkDeviceDisappear();
|
||||
if (!m_WifiNetworkList.contains(devIfaceName))
|
||||
{
|
||||
return false;
|
||||
} else {
|
||||
list = m_WifiNetworkList[devIfaceName];
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool KyWirelessNetResource::getWirelessActiveConnection(QMap<QString,QStringList> &map)
|
||||
{
|
||||
int index = 0;
|
||||
NetworkManager::ActiveConnection::List activeConnectionList;
|
||||
|
||||
map.clear();
|
||||
activeConnectionList.clear();
|
||||
activeConnectionList = m_networkResourceInstance->m_activeConns;
|
||||
if (activeConnectionList.isEmpty())
|
||||
{
|
||||
map.clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
NetworkManager::ActiveConnection::Ptr activeConnectionPtr = nullptr;
|
||||
for (; index < activeConnectionList.size(); index++)
|
||||
{
|
||||
activeConnectionPtr = activeConnectionList.at(index);
|
||||
if (NetworkManager::ConnectionSettings::ConnectionType::Wireless != activeConnectionPtr->type())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (NetworkManager::ActiveConnection::Activated != activeConnectionPtr->state())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
QString ssid;
|
||||
QString ifaceName = getDeviceIFace(activeConnectionPtr,ssid);
|
||||
if (map.contains(ifaceName))
|
||||
{
|
||||
map[ifaceName].append(ssid);
|
||||
} else {
|
||||
QStringList list;
|
||||
list.append(ssid);
|
||||
map.insert(ifaceName,list);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
QString KyWirelessNetResource::getDeviceIFace(NetworkManager::ActiveConnection::Ptr actConn, QString &ssid)
|
||||
{
|
||||
if (actConn.isNull())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
NetworkManager::Connection::Ptr conn = actConn->connection();
|
||||
NetworkManager::ConnectionSettings::Ptr sett = conn->settings();
|
||||
ssid = sett->id();
|
||||
return sett->interfaceName();
|
||||
}
|
||||
|
||||
void KyWirelessNetResource::kyWirelessNetItemListInit()
|
||||
{
|
||||
qDebug() << m_networkResourceInstance->m_wifiNets.size();
|
||||
for (auto const & net : m_networkResourceInstance->m_wifiNets)
|
||||
{
|
||||
QString devIface = getDeviceIFace(net);
|
||||
if (devIface.isEmpty())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (!m_WifiNetworkList.contains(devIface))
|
||||
{
|
||||
QList<KyWirelessNetItem> list;
|
||||
KyWirelessNetItem item(net);
|
||||
list.append(item);
|
||||
m_WifiNetworkList.insert(devIface,list);
|
||||
} else {
|
||||
KyWirelessNetItem item(net);
|
||||
m_WifiNetworkList[devIface].append(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QString KyWirelessNetResource::getDeviceIFace(NetworkManager::WirelessNetwork::Ptr net)
|
||||
{
|
||||
if (net.isNull())
|
||||
{
|
||||
return "";
|
||||
}
|
||||
QString devUni = net->device();
|
||||
NetworkManager::Device::Ptr dev = m_networkResourceInstance->findDeviceUni(devUni);
|
||||
if (dev.isNull())
|
||||
{
|
||||
qDebug() << "KyWirelessNetResource: can't find " << net->ssid() << " find in device list";
|
||||
return "";
|
||||
}
|
||||
return dev->interfaceName();
|
||||
}
|
||||
|
||||
//void KyWirelessNetResource::onWifiNetworkChange(QString devIfaceName)
|
||||
//{
|
||||
// //创建新加入的的device key
|
||||
// if(!m_WifiNetworkList.contains(devIfaceName))
|
||||
// {
|
||||
// QList<KyWirelessNetItem> list;
|
||||
// m_WifiNetworkList.insert(devIfaceName,list);
|
||||
// }
|
||||
|
||||
// //清空重新append
|
||||
// m_WifiNetworkList[devIfaceName].clear();
|
||||
// for (auto const & net : m_networkResourceInstance->m_wifiNets)
|
||||
// {
|
||||
// if (m_networkResourceInstance->findDeviceUni(net->device())->interfaceName() == devIfaceName)
|
||||
// {
|
||||
// qDebug() << net->ssid();
|
||||
// KyWirelessNetItem item(net);
|
||||
// m_WifiNetworkList[devIfaceName].append(item);
|
||||
// }
|
||||
// }
|
||||
|
||||
// //若仍为空则remove
|
||||
// if (m_WifiNetworkList.value(devIfaceName).isEmpty())
|
||||
// {
|
||||
// m_WifiNetworkList.remove(devIfaceName);
|
||||
// }
|
||||
|
||||
// emit updateWifiNetworkList(devIfaceName);
|
||||
//}
|
||||
|
||||
void KyWirelessNetResource::onWifiNetworkAdded(QString devIfaceName, QString ssid)
|
||||
{
|
||||
NetworkManager::WirelessNetwork::Ptr wifi = nullptr;
|
||||
for (auto const & net : m_networkResourceInstance->m_wifiNets)
|
||||
{
|
||||
if (net->ssid() == ssid && m_networkResourceInstance->findDeviceUni(net->device())->interfaceName() == devIfaceName )
|
||||
{
|
||||
wifi = net;
|
||||
}
|
||||
}
|
||||
|
||||
if (wifi.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
KyWirelessNetItem item(wifi);
|
||||
|
||||
if (m_WifiNetworkList.contains(devIfaceName))
|
||||
{
|
||||
m_WifiNetworkList[devIfaceName].append(item);
|
||||
} else {
|
||||
QList<KyWirelessNetItem> list;
|
||||
list.append(item);
|
||||
m_WifiNetworkList.insert(devIfaceName,list);
|
||||
}
|
||||
emit wifiNetworkAdd(devIfaceName,item);
|
||||
}
|
||||
|
||||
void KyWirelessNetResource::onWifiNetworkRemoved(QString devIfaceName, QString ssid)
|
||||
{
|
||||
if (m_WifiNetworkList.contains(devIfaceName))
|
||||
{
|
||||
int index = 0;
|
||||
for ( ; index < m_WifiNetworkList.value(devIfaceName).size(); index++)
|
||||
{
|
||||
if ( m_WifiNetworkList[devIfaceName].at(index).m_NetSsid == ssid)
|
||||
{
|
||||
m_WifiNetworkList[devIfaceName].removeAt(index);
|
||||
}
|
||||
}
|
||||
//remove后为空则删除
|
||||
if (m_WifiNetworkList.value(devIfaceName).isEmpty())
|
||||
{
|
||||
m_WifiNetworkList.remove(devIfaceName);
|
||||
}
|
||||
emit wifiNetworkRemove(devIfaceName,ssid);
|
||||
}
|
||||
}
|
||||
|
||||
void KyWirelessNetResource::onWifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net)
|
||||
{
|
||||
if (nullptr == net)
|
||||
{
|
||||
return;
|
||||
}
|
||||
QString devIface = m_networkResourceInstance->findDeviceUni(net->device())->interfaceName();
|
||||
if (m_WifiNetworkList.contains(devIface))
|
||||
{
|
||||
QList<KyWirelessNetItem>::iterator iter = m_WifiNetworkList[devIface].begin();
|
||||
while (iter != m_WifiNetworkList[devIface].end())
|
||||
{
|
||||
|
||||
if (iter->m_NetSsid == net->ssid())
|
||||
{
|
||||
qDebug() << iter->m_NetSsid;
|
||||
if (iter->m_signalStrength != net->signalStrength())
|
||||
{
|
||||
iter->m_signalStrength = net->signalStrength();
|
||||
emit signalStrengthChange(devIface, net->ssid(), iter->m_signalStrength);
|
||||
}
|
||||
if (iter->m_bssid != net->referenceAccessPoint()->hardwareAddress())
|
||||
{
|
||||
iter->m_bssid = net->referenceAccessPoint()->hardwareAddress();
|
||||
emit bssidChange(devIface, net->ssid(), iter->m_bssid);
|
||||
}
|
||||
QString secuType = enumToQstring(net->referenceAccessPoint()->capabilities(), net->referenceAccessPoint()->wpaFlags(), net->referenceAccessPoint()->rsnFlags());
|
||||
if (iter->m_secuType != secuType)
|
||||
{
|
||||
iter->m_secuType = secuType;
|
||||
emit secuTypeChange(devIface, net->ssid(), secuType);
|
||||
}
|
||||
break;
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void KyWirelessNetResource::onWifiNetworkDeviceDisappear()
|
||||
{
|
||||
m_WifiNetworkList.clear();
|
||||
kyWirelessNetItemListInit();
|
||||
}
|
||||
|
||||
bool KyWirelessNetResource::modifyEnterPriseInfoTls(QString &uuid, KyEapMethodTlsInfo &info)
|
||||
{
|
||||
NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid);
|
||||
if (conn.isNull())
|
||||
{
|
||||
qDebug() << "modifyEnterPriseInfoTls connection missing";
|
||||
return false;
|
||||
}
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
if (security_sett.isNull())
|
||||
{
|
||||
qDebug() << "don't have WirelessSecurity connection";
|
||||
return false;
|
||||
}
|
||||
if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
NetworkManager::Security8021xSetting::Ptr setting = conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
|
||||
if (setting.isNull())
|
||||
{
|
||||
qDebug() << "don't have Security8021x connection";
|
||||
return false;
|
||||
}
|
||||
|
||||
QList<NetworkManager::Security8021xSetting::EapMethod> list;
|
||||
list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodTls);
|
||||
setting->setEapMethods(list);
|
||||
setting->setIdentity(info.identity);
|
||||
if(!info.domain.isEmpty())
|
||||
{
|
||||
setting->setDomainSuffixMatch(info.domain);
|
||||
}
|
||||
setting->setCaPath(info.caCertPath);
|
||||
setting->setClientCertificate(info.clientCertPath.toLocal8Bit());
|
||||
setting->setPrivateKey(info.clientPrivateKey.toLocal8Bit());
|
||||
setting->setPrivateKeyPassword(info.clientPrivateKeyPWD);
|
||||
|
||||
conn->update(conn->settings()->toMap());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KyWirelessNetResource::getEnterPriseInfoTls(QString &uuid, KyEapMethodTlsInfo &info)
|
||||
{
|
||||
NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid);
|
||||
if (conn.isNull())
|
||||
{
|
||||
qDebug() << "modifyEnterPriseInfoTls connection missing";
|
||||
return false;
|
||||
}
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
if (security_sett.isNull())
|
||||
{
|
||||
qDebug() << "don't have WirelessSecurity connection";
|
||||
return false;
|
||||
}
|
||||
if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
NetworkManager::Security8021xSetting::Ptr setting = conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
|
||||
if (setting.isNull())
|
||||
{
|
||||
qDebug() << "don't have Security8021x connection";
|
||||
return false;
|
||||
}
|
||||
|
||||
QList<NetworkManager::Security8021xSetting::EapMethod> list;
|
||||
list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodTls);
|
||||
setting->setEapMethods(list);
|
||||
setting->setIdentity(info.identity);
|
||||
if(!info.domain.isEmpty())
|
||||
{
|
||||
setting->setDomainSuffixMatch(info.domain);
|
||||
}
|
||||
setting->setCaPath(info.caCertPath);
|
||||
setting->setClientCertificate(info.clientCertPath.toLocal8Bit());
|
||||
setting->setPrivateKey(info.clientPrivateKey.toLocal8Bit());
|
||||
setting->setPrivateKeyPassword(info.clientPrivateKeyPWD);
|
||||
|
||||
conn->update(conn->settings()->toMap());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KyWirelessNetResource::modifyEnterPriseInfoPeap(QString &uuid, KyEapMethodPeapInfo &info)
|
||||
{
|
||||
NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid);
|
||||
if (conn.isNull())
|
||||
{
|
||||
qDebug() << "modifyEnterPriseInfoPeap connection missing";
|
||||
return false;
|
||||
}
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
if (security_sett.isNull())
|
||||
{
|
||||
qDebug() << "don't have WirelessSecurity connection";
|
||||
return false;
|
||||
}
|
||||
if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap)
|
||||
{
|
||||
qDebug() << "keyMgmt not WpaEap " << security_sett->keyMgmt();
|
||||
return false;
|
||||
}
|
||||
NetworkManager::Security8021xSetting::Ptr setting = conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
|
||||
if (setting.isNull() || !setting->eapMethods().contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodTls))
|
||||
{
|
||||
qDebug() << "don't have Security8021x connection";
|
||||
return false;
|
||||
}
|
||||
|
||||
info.connName = conn->name();
|
||||
info.phase2AuthMethod = (KyEapMethodPeapAuth)setting->phase2AuthEapMethod();
|
||||
info.userName = setting->identity();
|
||||
info.userPWD = setting->password();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KyWirelessNetResource::getEnterPriseInfoPeap(QString &uuid, KyEapMethodPeapInfo &info)
|
||||
{
|
||||
NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid);
|
||||
if (conn.isNull())
|
||||
{
|
||||
qDebug() << "modifyEnterPriseInfoPeap connection missing";
|
||||
return false;
|
||||
}
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
if (security_sett.isNull())
|
||||
{
|
||||
qDebug() << "don't have WirelessSecurity connection";
|
||||
return false;
|
||||
}
|
||||
if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap)
|
||||
{
|
||||
qDebug() << "keyMgmt not WpaEap " << security_sett->keyMgmt();
|
||||
return false;
|
||||
}
|
||||
NetworkManager::Security8021xSetting::Ptr setting = conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
|
||||
if (setting.isNull() || !setting->eapMethods().contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodPeap))
|
||||
{
|
||||
qDebug() << "don't have Security8021x connection";
|
||||
return false;
|
||||
}
|
||||
|
||||
info.connName = conn->name();
|
||||
info.phase2AuthMethod = (KyEapMethodPeapAuth)setting->phase2AuthEapMethod();
|
||||
info.userName = setting->identity();
|
||||
info.userPWD = setting->password();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KyWirelessNetResource::modifyEnterPriseInfoTtls(QString &uuid, KyEapMethodTtlsInfo &info)
|
||||
{
|
||||
NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid);
|
||||
if (conn.isNull())
|
||||
{
|
||||
qDebug() << "modifyEnterPriseInfoTtls connection missing";
|
||||
return false;
|
||||
}
|
||||
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
if (security_sett.isNull())
|
||||
{
|
||||
qDebug() << "don't have WirelessSecurity connection";
|
||||
return false;
|
||||
}
|
||||
if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap)
|
||||
{
|
||||
qDebug() << "not wpaeap"<<security_sett->keyMgmt();
|
||||
return false;
|
||||
}
|
||||
|
||||
NetworkManager::Security8021xSetting::Ptr setting = conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
|
||||
if (setting.isNull())
|
||||
{
|
||||
qDebug() << "don't have Security8021x connection";
|
||||
return false;
|
||||
}
|
||||
|
||||
qDebug() << setting->identity() << setting->eapMethods() << setting->password() << setting->phase2AuthEapMethod();
|
||||
|
||||
QList<NetworkManager::Security8021xSetting::EapMethod> list;
|
||||
list.append(NetworkManager::Security8021xSetting::EapMethod::EapMethodTtls);
|
||||
setting->setEapMethods(list);
|
||||
if (info.authType == KyTtlsAuthMethod::AUTH_EAP)
|
||||
{
|
||||
setting->setPhase2AuthEapMethod((NetworkManager::Security8021xSetting::AuthEapMethod)info.authEapMethod);//gtc md5 mschapv2 otp tls
|
||||
setting->setPhase2AuthMethod(NetworkManager::Security8021xSetting::AuthMethod::AuthMethodUnknown);
|
||||
} else if (info.authType == KyTtlsAuthMethod::AUTH_NO_EAP) {
|
||||
setting->setPhase2AuthMethod((NetworkManager::Security8021xSetting::AuthMethod)info.authNoEapMethod);//chap md5 mschapv2 pap gtc mschap otp tls
|
||||
setting->setPhase2AuthEapMethod(NetworkManager::Security8021xSetting::AuthEapMethod::AuthEapMethodUnknown);
|
||||
}
|
||||
setting->setIdentity(info.userName);
|
||||
setting->setPassword(info.userPWD);
|
||||
|
||||
conn->update(conn->settings()->toMap());
|
||||
|
||||
qDebug() << setting->identity() << setting->eapMethods() << setting->password() << setting->phase2AuthEapMethod();
|
||||
qDebug() << "set success";
|
||||
return true;
|
||||
}
|
||||
|
||||
bool KyWirelessNetResource::getEnterPriseInfoTtls(QString &uuid, KyEapMethodTtlsInfo &info)
|
||||
{
|
||||
NetworkManager::Connection::Ptr conn = m_networkResourceInstance->getConnect(uuid);
|
||||
if (conn.isNull())
|
||||
{
|
||||
qDebug() << "modifyEnterPriseInfoTtls connection missing";
|
||||
return false;
|
||||
}
|
||||
|
||||
NetworkManager::WirelessSecuritySetting::Ptr security_sett
|
||||
= conn->settings()->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
|
||||
if (security_sett.isNull())
|
||||
{
|
||||
qDebug() << "don't have WirelessSecurity connection";
|
||||
return false;
|
||||
}
|
||||
if (security_sett->keyMgmt() != NetworkManager::WirelessSecuritySetting::WpaEap)
|
||||
{
|
||||
qDebug() << "not wpaeap"<<security_sett->keyMgmt();
|
||||
return false;
|
||||
}
|
||||
|
||||
NetworkManager::Security8021xSetting::Ptr setting = conn->settings()->setting(NetworkManager::Setting::Security8021x).dynamicCast<NetworkManager::Security8021xSetting>();
|
||||
if (setting.isNull() || !setting->eapMethods().contains(NetworkManager::Security8021xSetting::EapMethod::EapMethodTtls))
|
||||
{
|
||||
qDebug() << "don't have Security8021x connection";
|
||||
return false;
|
||||
}
|
||||
|
||||
info.connName = conn->name();
|
||||
info.authEapMethod = (KyEapMethodTtlsAuth)setting->phase2AuthEapMethod();
|
||||
info.authNoEapMethod = (KyNoEapMethodTtlsAuth)setting->phase2AuthMethod();
|
||||
|
||||
info.authType = KyTtlsAuthMethod::AUTH_EAP;
|
||||
if (info.authEapMethod != AuthEapMethodTtlsUnknown)
|
||||
{
|
||||
info.authType = KyTtlsAuthMethod::AUTH_EAP;
|
||||
} else {
|
||||
info.authType = KyTtlsAuthMethod::AUTH_NO_EAP;
|
||||
}
|
||||
info.userName = setting->identity();
|
||||
info.userPWD = setting->password();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void KyWirelessNetResource::onConnectionAdd(NetworkManager::Connection::Ptr conn)
|
||||
{
|
||||
qDebug() << "onConnectionAdd add " << conn->name();
|
||||
QString devIfaceName;
|
||||
QString ssid;
|
||||
if (conn.isNull())
|
||||
{
|
||||
return;
|
||||
}
|
||||
NetworkManager::ConnectionSettings::Ptr sett= conn->settings();
|
||||
if (sett->connectionType() != NetworkManager::ConnectionSettings::ConnectionType::Wireless)
|
||||
{
|
||||
return;
|
||||
}
|
||||
NetworkManager::WirelessSetting::Ptr wireless_sett = sett->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
|
||||
bool isFind = false;
|
||||
QMap<QString, QList<KyWirelessNetItem> >::iterator iter = m_WifiNetworkList.begin();
|
||||
while (iter != m_WifiNetworkList.end())
|
||||
{
|
||||
for(int i = 0; i < iter.value().size(); i++)
|
||||
{
|
||||
if (iter.value().at(i).m_NetSsid == wireless_sett->ssid())
|
||||
{
|
||||
isFind = true;
|
||||
m_WifiNetworkList[iter.key()][i].m_isConfigured = true;
|
||||
m_WifiNetworkList[iter.key()][i].m_connName = conn->name();
|
||||
m_WifiNetworkList[iter.key()][i].m_connectUuid = conn->uuid();
|
||||
m_WifiNetworkList[iter.key()][i].m_connDbusPath = conn->path();
|
||||
|
||||
devIfaceName = sett->interfaceName();
|
||||
ssid = iter.value().at(i).m_NetSsid;
|
||||
}
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
if (isFind)
|
||||
{
|
||||
emit connectionAdd(devIfaceName, ssid);
|
||||
}
|
||||
}
|
||||
|
||||
void KyWirelessNetResource::onConnectionRemove(QString path)
|
||||
{
|
||||
qDebug() << "onConnectionRemove remove " << path;
|
||||
bool isFind = false;
|
||||
QString devIfaceName;
|
||||
QString ssid;
|
||||
|
||||
QMap<QString, QList<KyWirelessNetItem> >::iterator iter = m_WifiNetworkList.begin();
|
||||
while (iter != m_WifiNetworkList.end())
|
||||
{
|
||||
qDebug() << iter.key();
|
||||
for(int i = 0; i < iter.value().size(); i++)
|
||||
{
|
||||
qDebug() << iter.value().at(i).m_connDbusPath;
|
||||
if (iter.value().at(i).m_connDbusPath == path)
|
||||
{
|
||||
isFind = true;
|
||||
m_WifiNetworkList[iter.key()][i].m_isConfigured = false;
|
||||
m_WifiNetworkList[iter.key()][i].m_connName = "";
|
||||
m_WifiNetworkList[iter.key()][i].m_connectUuid = "";
|
||||
m_WifiNetworkList[iter.key()][i].m_connDbusPath = "";
|
||||
|
||||
devIfaceName = iter.key();
|
||||
ssid = iter.value().at(i).m_NetSsid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
|
||||
if (isFind)
|
||||
{
|
||||
emit connectionRemove(devIfaceName, ssid);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,63 @@
|
|||
#ifndef KYWIRELESSNETRESOURCE_H
|
||||
#define KYWIRELESSNETRESOURCE_H
|
||||
|
||||
#include <QObject>
|
||||
#include "kywirelessnetitem.h"
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kyenterpricesettinginfo.h"
|
||||
|
||||
|
||||
//class KyWirelessNetItem;
|
||||
|
||||
class KyWirelessNetResource : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit KyWirelessNetResource(QObject *parent = nullptr);
|
||||
~KyWirelessNetResource();
|
||||
|
||||
//ui层调用接口
|
||||
bool getAllDeviceWifiNetwork(QMap<QString,QList<KyWirelessNetItem> > &map);
|
||||
bool getDeviceWifiNetwork(QString devIfaceName, QList<KyWirelessNetItem> &KyWirelessNetResource);
|
||||
|
||||
bool modifyEnterPriseInfoTls(QString &, KyEapMethodTlsInfo &);
|
||||
bool modifyEnterPriseInfoPeap(QString &, KyEapMethodPeapInfo &);
|
||||
bool modifyEnterPriseInfoTtls(QString &, KyEapMethodTtlsInfo &);
|
||||
|
||||
bool getEnterPriseInfoTls(QString &, KyEapMethodTlsInfo &);
|
||||
bool getEnterPriseInfoPeap(QString &, KyEapMethodPeapInfo &);
|
||||
bool getEnterPriseInfoTtls(QString &, KyEapMethodTtlsInfo &);
|
||||
|
||||
bool getWirelessActiveConnection(QMap<QString, QStringList> &map);
|
||||
|
||||
|
||||
private:
|
||||
void kyWirelessNetItemListInit();
|
||||
QString getDeviceIFace(NetworkManager::WirelessNetwork::Ptr net);
|
||||
QString getDeviceIFace(NetworkManager::ActiveConnection::Ptr actConn, QString &KyWirelessNetResourcessid);
|
||||
|
||||
public slots:
|
||||
void onWifiNetworkAdded(QString, QString);
|
||||
void onWifiNetworkRemoved(QString, QString);
|
||||
void onWifiNetworkPropertyChange(NetworkManager::WirelessNetwork * net);
|
||||
void onWifiNetworkDeviceDisappear();
|
||||
|
||||
void onConnectionAdd(NetworkManager::Connection::Ptr conn);
|
||||
void onConnectionRemove(QString);
|
||||
|
||||
signals:
|
||||
void signalStrengthChange(QString, QString, int);
|
||||
void bssidChange(QString, QString, QString);
|
||||
void secuTypeChange(QString, QString, QString);
|
||||
void connectionRemove(QString, QString);
|
||||
void connectionAdd(QString, QString);
|
||||
void wifiNetworkAdd(QString, KyWirelessNetItem&);
|
||||
void wifiNetworkRemove(QString, QString);
|
||||
|
||||
private:
|
||||
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
|
||||
QMap<QString,QList<KyWirelessNetItem> > m_WifiNetworkList;
|
||||
|
||||
};
|
||||
|
||||
#endif // KYWIRELESSNETRESOURCE_H
|
|
@ -0,0 +1,432 @@
|
|||
#include "nmdemo.h"
|
||||
#include "../wireless-security/dlghidewifi.h"
|
||||
#include <QTime>
|
||||
#include <QTimeZone>
|
||||
|
||||
QString enumToQstring(NetworkManager::ActiveConnection::State state)
|
||||
{
|
||||
switch (state) {
|
||||
case NetworkManager::ActiveConnection::State::Unknown:
|
||||
return "Unknown";
|
||||
break;
|
||||
case NetworkManager::ActiveConnection::State::Activating:
|
||||
return "Activating";
|
||||
break;
|
||||
case NetworkManager::ActiveConnection::State::Activated:
|
||||
return "Activated";
|
||||
break;
|
||||
case NetworkManager::ActiveConnection::State::Deactivating:
|
||||
return "Deactivating";
|
||||
break;
|
||||
case NetworkManager::ActiveConnection::State::Deactivated:
|
||||
return "Deactivated";
|
||||
break;
|
||||
default:
|
||||
return "";
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
NmDemo::NmDemo(QWidget *parent) : QDialog(parent)
|
||||
{
|
||||
this->setFixedSize(510,810);
|
||||
|
||||
//init ptr
|
||||
m_networkResourceInstance = KyNetworkResourceManager::getInstance();
|
||||
m_wco = new KyWirelessConnectOperation(this);
|
||||
m_wnr = new KyWirelessNetResource(this);
|
||||
m_timer = new QTimer(this);
|
||||
|
||||
initUi();
|
||||
appendDebugLog("init...");
|
||||
initConnect();
|
||||
initTimer();
|
||||
appendDebugLog("init finish...");
|
||||
getWifiList();
|
||||
|
||||
if (m_wco->getWirelessEnabled())
|
||||
{
|
||||
wlansStatus->setText("WLAN:ENABLE");
|
||||
} else {
|
||||
wlansStatus->setText("WLAN:DISABLE");
|
||||
}
|
||||
}
|
||||
|
||||
NmDemo::~NmDemo()
|
||||
{
|
||||
m_networkResourceInstance = nullptr;
|
||||
}
|
||||
|
||||
void NmDemo::initUi()
|
||||
{
|
||||
refreshButton = new QPushButton(this);
|
||||
refreshButton->setText("Refresh");
|
||||
connectButton = new QPushButton(this);
|
||||
connectButton->setText("Connect");
|
||||
disConnectButton = new QPushButton(this);
|
||||
disConnectButton->setText("DisConn");
|
||||
modifyButton = new QPushButton(this);
|
||||
modifyButton->setText("Modify");
|
||||
enableButton = new QPushButton(this);
|
||||
enableButton->setText("Enable");
|
||||
disableButton = new QPushButton(this);
|
||||
disableButton->setText("Disable");
|
||||
wifiList = new QTextEdit(this);
|
||||
debugLog = new QTextEdit(this);
|
||||
ssidText = new QLineEdit(this);
|
||||
ifaceNameText = new QLineEdit(this);
|
||||
pwdText = new QLineEdit(this);
|
||||
wlansStatus = new QLabel(this);
|
||||
ssidLabel = new QLabel(this);
|
||||
ssidLabel->setText("SSID");
|
||||
ifaceLabel = new QLabel(this);
|
||||
ifaceLabel->setText("IfaceName");
|
||||
pwdLabel = new QLabel(this);
|
||||
pwdLabel->setText("password");
|
||||
actConnection = new QLabel(this);
|
||||
|
||||
|
||||
refreshButton->setGeometry( 5, 5, 80, 30);
|
||||
connectButton->setGeometry(105, 5, 80, 30);
|
||||
disConnectButton->setGeometry(205, 5, 80, 30);
|
||||
modifyButton->setGeometry(5, 55, 80, 30);
|
||||
enableButton->setGeometry(105, 55, 80, 30);
|
||||
disableButton->setGeometry(205, 55, 80, 30);
|
||||
wlansStatus->setGeometry(305, 55, 180, 30);
|
||||
ssidLabel->setGeometry(5, 105, 80, 30);
|
||||
ssidText->setGeometry(100, 105, 100, 30);
|
||||
pwdLabel->setGeometry(250, 105, 80, 30);
|
||||
pwdText->setGeometry(345, 105, 150, 30);
|
||||
actConnection->setGeometry(250, 145, 245, 30);
|
||||
ifaceLabel->setGeometry(5, 145, 80, 30);
|
||||
ifaceNameText->setGeometry(100, 145, 100, 30);
|
||||
wifiList->setGeometry(5, 200, 500,300);
|
||||
wifiList->setReadOnly(true);
|
||||
debugLog->setGeometry(5, 510, 500,300);
|
||||
debugLog->setReadOnly(true);
|
||||
}
|
||||
|
||||
void NmDemo::initConnect()
|
||||
{
|
||||
connect(m_wco, &KyWirelessConnectOperation::wifinEnabledChanged,[=](bool status){
|
||||
QString temp;
|
||||
temp.sprintf("wifinEnabledChanged %d",status);
|
||||
appendDebugLog(temp);
|
||||
if (status)
|
||||
{
|
||||
wlansStatus->setText("WLAN:ENABLE");
|
||||
} else {
|
||||
wlansStatus->setText("WLAN:DISABLE");
|
||||
}
|
||||
});
|
||||
|
||||
//ui button
|
||||
connect(refreshButton, &QPushButton::clicked, [=](){
|
||||
appendDebugLog("init refreshButton clicked...");
|
||||
m_wco->requestWirelessScan();
|
||||
});
|
||||
|
||||
connect(connectButton, &QPushButton::clicked, this, &NmDemo::onConnectClicked);
|
||||
connect(disConnectButton, &QPushButton::clicked, this, &NmDemo::onDisConnectClicked);
|
||||
connect(modifyButton, &QPushButton::clicked, this, &NmDemo::onModifyClicked);
|
||||
connect(enableButton, &QPushButton::clicked, this, &NmDemo::onEnableClick);
|
||||
connect(disableButton, &QPushButton::clicked, this, &NmDemo::onDisableClick);
|
||||
//连接变化
|
||||
connect(m_wco, &KyWirelessConnectOperation::connectFail, this, &NmDemo::onWcoSignals);
|
||||
connect(m_wco, &KyWirelessConnectOperation::disConnectFail, this, &NmDemo::onWcoSignals);
|
||||
|
||||
//列表变化
|
||||
connect(m_wnr, &KyWirelessNetResource::bssidChange, this ,&NmDemo::onBssidChange);
|
||||
connect(m_wnr, &KyWirelessNetResource::secuTypeChange, this ,&NmDemo::onSecuTypeChange);
|
||||
connect(m_wnr, &KyWirelessNetResource::signalStrengthChange, this ,&NmDemo::onSignalStrengthChange);
|
||||
|
||||
connect(m_wnr, &KyWirelessNetResource::connectionRemove, this ,&NmDemo::onConnectionRemove);
|
||||
connect(m_wnr, &KyWirelessNetResource::connectionAdd, this ,&NmDemo::onConnectionAdd);
|
||||
connect(m_wnr, &KyWirelessNetResource::wifiNetworkAdd, this ,&NmDemo::onWifiNetworkAdd);
|
||||
connect(m_wnr, &KyWirelessNetResource::wifiNetworkRemove, this ,&NmDemo::onWifiNetworkRemove);
|
||||
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::activeConnectionAdd, this, &NmDemo::onActiveConnectionAdd);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::activeConnectionUpdate, this, &NmDemo::onActiveConnectionUpdate);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::activeConnectionRemove, this, &NmDemo::onActiveConnectionRemove);
|
||||
connect(m_networkResourceInstance, &KyNetworkResourceManager::activeConnectionsReset, this, &NmDemo::onActiveConnectionsReset);
|
||||
}
|
||||
|
||||
void NmDemo::initTimer()
|
||||
{
|
||||
//30s扫描一次wifi
|
||||
m_timer->setTimerType(Qt::PreciseTimer);
|
||||
QObject::connect(m_timer, &QTimer::timeout, [=](){
|
||||
m_wco->requestWirelessScan();
|
||||
getWifiList();
|
||||
});
|
||||
m_timer->start(30*1000);
|
||||
}
|
||||
|
||||
|
||||
void NmDemo::onWcoSignals(QString ssid, QString devIFace, QString reason)
|
||||
{
|
||||
appendDebugLog(ssid + " connect or disconnect faild because " + reason);
|
||||
}
|
||||
|
||||
void NmDemo::onBssidChange(QString devIface, QString ssid, QString bssid)
|
||||
{
|
||||
appendDebugLog(ssid + " belongs to " + devIface + " bssid change to " + bssid);
|
||||
}
|
||||
|
||||
void NmDemo::onSecuTypeChange(QString devIface, QString ssid, QString secuType)
|
||||
{
|
||||
appendDebugLog(ssid + " belongs to " + devIface + " security change to " + secuType);
|
||||
}
|
||||
|
||||
void NmDemo::onSignalStrengthChange(QString devIface , QString ssid, int signal)
|
||||
{
|
||||
appendDebugLog(ssid + " belongs to " + devIface + " SignalStrength change to " + QString::number(signal));
|
||||
}
|
||||
|
||||
void NmDemo::onConnectionRemove(QString devIface, QString ssid)
|
||||
{
|
||||
appendDebugLog("onConnectionRemove..." + devIface + " " + ssid);
|
||||
getWifiList();
|
||||
}
|
||||
|
||||
void NmDemo::onConnectionAdd(QString devIface, QString ssid)
|
||||
{
|
||||
appendDebugLog("onConnectionAdd..." + devIface + " " + ssid);
|
||||
getWifiList();
|
||||
}
|
||||
|
||||
void NmDemo::onWifiNetworkAdd(QString devIface, KyWirelessNetItem& item)
|
||||
{
|
||||
appendDebugLog("onWifiNetworkAdd..." + devIface + " " + item.m_NetSsid);
|
||||
getWifiList();
|
||||
}
|
||||
|
||||
void NmDemo::onWifiNetworkRemove(QString devIface, QString ssid)
|
||||
{
|
||||
appendDebugLog("onWifiNetworkRemove..." + devIface + " " + ssid);
|
||||
getWifiList();
|
||||
}
|
||||
|
||||
void NmDemo::onConnectClicked()
|
||||
{
|
||||
appendDebugLog("onConnectClicked...");
|
||||
QString ssid = ssidText->text();
|
||||
QString devIface = ifaceNameText->text();
|
||||
QString pwd = pwdText->text();
|
||||
QString uuid;
|
||||
bool isNew = true;
|
||||
bool isHidden = true;
|
||||
bool isEnterPirse = false;
|
||||
|
||||
appendDebugLog("about to connect " + ssid + " " + devIface + " " + pwd);
|
||||
QList<KyWirelessNetItem> list;
|
||||
m_wnr->getDeviceWifiNetwork(devIface, list);
|
||||
appendDebugLog("agetDeviceWifiNetwork " + devIface + " size: " + QString::number(list.size()));
|
||||
QList<KyWirelessNetItem>::iterator iter = list.begin();
|
||||
while (iter != list.end())
|
||||
{
|
||||
if (iter->m_NetSsid == ssid)
|
||||
{
|
||||
isHidden = false;
|
||||
QString secuType = iter->m_secuType;
|
||||
qDebug() << secuType;
|
||||
if (secuType.indexOf("802.1X") >= 0)
|
||||
{
|
||||
isEnterPirse = true;
|
||||
}
|
||||
|
||||
if (iter->m_isConfigured == true)
|
||||
{
|
||||
isNew = false;
|
||||
uuid = iter->m_connectUuid;
|
||||
}
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
if (isEnterPirse)
|
||||
{
|
||||
if(!isNew)
|
||||
{
|
||||
KyEapMethodPeapInfo a;
|
||||
a.connName = ssid;
|
||||
a.phase2AuthMethod = AuthEapMethodPeapMschapv2;
|
||||
a.userName = "steve";
|
||||
a.userPWD = "testing";
|
||||
appendDebugLog("modifyEnterPriseInfoPeap");
|
||||
if (!(m_wnr->modifyEnterPriseInfoPeap(uuid,a)))
|
||||
{
|
||||
appendDebugLog("modifyEnterPriseInfoPeap fail");
|
||||
return;
|
||||
}
|
||||
appendDebugLog("activeWirelessConnect...");
|
||||
m_wco->activeWirelessConnect(devIface,uuid);
|
||||
return;
|
||||
} else {
|
||||
KyEapMethodTtlsInfo c;
|
||||
c.connName = ssid;
|
||||
c.authType = AUTH_NO_EAP;
|
||||
c.authNoEapMethod = AuthMethodTtlsMschapv2;
|
||||
c.userName = "steve";
|
||||
c.userPWD = "testing";
|
||||
appendDebugLog("addAndActiveWirelessEnterPriseTtlsConnect...");
|
||||
qDebug() << "addAndActiveWirelessEnterPriseTtlsConnect";
|
||||
m_wco->addAndActiveWirelessEnterPriseTtlsConnect(c, devIface, isHidden, true, 0);
|
||||
return;
|
||||
}
|
||||
}
|
||||
KySecuType secuType = WPA_AND_WPA2_PERSONAL;
|
||||
if (isHidden)
|
||||
{
|
||||
appendDebugLog("addAndActiveWirelessHiddenConnect...");
|
||||
m_wco->addAndActiveWirelessHiddenConnect(secuType, ssid, devIface, pwd, true, 0);
|
||||
return;
|
||||
}
|
||||
if (isNew)
|
||||
{
|
||||
appendDebugLog("addAndActiveWirelessConnect...");
|
||||
m_wco->addAndActiveWirelessConnect(ssid, devIface, pwd, true, 0);
|
||||
} else {
|
||||
appendDebugLog("activeWirelessConnectWithPwd...");
|
||||
m_wco->activeWirelessConnect(devIface,uuid);
|
||||
}
|
||||
}
|
||||
|
||||
void NmDemo::onDisConnectClicked()
|
||||
{
|
||||
appendDebugLog("onDisConnectClicked...");
|
||||
QString ssid = ssidText->text();
|
||||
QString devIface = ifaceNameText->text();
|
||||
QString uuid;
|
||||
bool isFind = false;
|
||||
QList<KyWirelessNetItem> list;
|
||||
m_wnr->getDeviceWifiNetwork(devIface, list);
|
||||
QList<KyWirelessNetItem>::iterator iter = list.begin();
|
||||
while (iter != list.end())
|
||||
{
|
||||
if (iter->m_NetSsid == ssid)
|
||||
{
|
||||
if (iter->m_isConfigured == true)
|
||||
{
|
||||
isFind = true;
|
||||
uuid = iter->m_connectUuid;
|
||||
break;
|
||||
}
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
if (!isFind)
|
||||
{
|
||||
return;
|
||||
}
|
||||
appendDebugLog("deActiveWirelessConnect " + ssid);
|
||||
m_wco->deActiveWirelessConnect(uuid);
|
||||
}
|
||||
|
||||
void NmDemo::onModifyClicked()
|
||||
{
|
||||
appendDebugLog("onModifyClicked...");
|
||||
//TODO
|
||||
}
|
||||
|
||||
void NmDemo::onEnableClick()
|
||||
{
|
||||
appendDebugLog("onEanbleClick...");
|
||||
m_wco->setWirelessEnabled(true);
|
||||
}
|
||||
|
||||
void NmDemo::onDisableClick()
|
||||
{
|
||||
appendDebugLog("onDisableClick...");
|
||||
m_wco->setWirelessEnabled(false);
|
||||
}
|
||||
|
||||
void NmDemo::appendDebugLog(QString log)
|
||||
{
|
||||
QTimeZone timeZone(QString::fromLatin1(QTimeZone::systemTimeZoneId()).toLatin1());
|
||||
QDateTime tzNow = QDateTime::currentDateTime().toTimeZone(timeZone);
|
||||
QString time= tzNow.toString("hh:mm:ss AP");
|
||||
debugLog->append(time + "===="+ log);
|
||||
qDebug() << log;
|
||||
}
|
||||
|
||||
void NmDemo::onActiveConnectionAdd(NetworkManager::ActiveConnection::Ptr conn)
|
||||
{
|
||||
if (conn->type() != NetworkManager::ConnectionSettings::ConnectionType::Wireless)
|
||||
{
|
||||
return;
|
||||
}
|
||||
appendDebugLog(conn->id()+ " " + enumToQstring(conn->state()));
|
||||
actConnection->setText(conn->id()+ " " + enumToQstring(conn->state()));
|
||||
}
|
||||
|
||||
void NmDemo::onActiveConnectionUpdate(NetworkManager::ActiveConnection * conn)
|
||||
{
|
||||
if (conn->type() != NetworkManager::ConnectionSettings::ConnectionType::Wireless)
|
||||
{
|
||||
return;
|
||||
}
|
||||
appendDebugLog(conn->id()+ " " + enumToQstring(conn->state()));
|
||||
actConnection->setText(conn->id()+ " " + enumToQstring(conn->state()));
|
||||
}
|
||||
|
||||
void NmDemo::onActiveConnectionRemove(NetworkManager::ActiveConnection * conn)
|
||||
{
|
||||
if (conn->type() != NetworkManager::ConnectionSettings::ConnectionType::Wireless)
|
||||
{
|
||||
return;
|
||||
}
|
||||
appendDebugLog(conn->id()+ " " + enumToQstring(conn->state()));
|
||||
actConnection->setText(conn->id()+ " " + enumToQstring(conn->state()));
|
||||
}
|
||||
|
||||
void NmDemo::onActiveConnectionsReset()
|
||||
{
|
||||
appendDebugLog("onActiveConnectionsReset");
|
||||
}
|
||||
|
||||
void NmDemo::getWifiList()
|
||||
{
|
||||
qDebug() << "getWifiList";
|
||||
wifiList->clear();
|
||||
QMap<QString,QStringList> actMap;
|
||||
if (!m_wnr->getWirelessActiveConnection(actMap))
|
||||
{
|
||||
return;
|
||||
}
|
||||
QMap<QString,QStringList>::iterator iter1 = actMap.begin();
|
||||
while (iter1 != actMap.end())
|
||||
{
|
||||
wifiList->append(iter1.key());
|
||||
for (int i = 0; i < iter1->size(); i++)
|
||||
{
|
||||
wifiList->append(iter1->at(i));
|
||||
}
|
||||
wifiList->append("====================================");
|
||||
iter1++;
|
||||
}
|
||||
QMap<QString, QList<KyWirelessNetItem> > map;
|
||||
if (!m_wnr->getAllDeviceWifiNetwork(map))
|
||||
{
|
||||
return;
|
||||
}
|
||||
QMap<QString, QList<KyWirelessNetItem> >::iterator iter = map.begin();
|
||||
while (iter != map.end())
|
||||
{
|
||||
for (int i = 0; i < iter.value().size(); i++)
|
||||
{
|
||||
qDebug() << iter.value().at(i).m_NetSsid;
|
||||
wifiList->append("SSID: " + iter.value().at(i).m_NetSsid + " Configed: " + QString::number(iter.value().at(i).m_isConfigured));
|
||||
wifiList->append("frequency: " + QString::number(iter.value().at(i).m_frequency));
|
||||
wifiList->append("signalStrength: " + QString::number(iter.value().at(i).m_signalStrength));
|
||||
QString security = iter.value().at(i).m_secuType;
|
||||
if (security.isEmpty())
|
||||
{
|
||||
security = "NONE";
|
||||
}
|
||||
wifiList->append("security: " + security);
|
||||
wifiList->append("MAC: " + iter.value().at(i).m_bssid);
|
||||
wifiList->append("====================================");
|
||||
}
|
||||
iter++;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
#ifndef NMDEMO_H
|
||||
#define NMDEMO_H
|
||||
|
||||
#include <QDialog>
|
||||
#include <QPushButton>
|
||||
#include <QTextEdit>
|
||||
#include <QTimer>
|
||||
#include <QLineEdit>
|
||||
#include <QLabel>
|
||||
|
||||
#include "kylinnetworkresourcemanager.h"
|
||||
#include "kywirelessconnectoperation.h"
|
||||
#include "kywirelessnetresource.h"
|
||||
|
||||
class NmDemo : public QDialog
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
QPushButton *refreshButton;
|
||||
QPushButton *connectButton;
|
||||
QPushButton *disConnectButton;
|
||||
QPushButton *modifyButton;
|
||||
QPushButton *enableButton;
|
||||
QPushButton *disableButton;
|
||||
QTextEdit *wifiList;
|
||||
QTextEdit *debugLog;
|
||||
QLabel *ssidLabel;
|
||||
QLabel *ifaceLabel;
|
||||
QLabel *wlansStatus;
|
||||
QLabel *pwdLabel;
|
||||
QLabel *actConnection;
|
||||
QLineEdit *ssidText;
|
||||
QLineEdit *ifaceNameText;
|
||||
QLineEdit *pwdText;
|
||||
|
||||
KyNetworkResourceManager *m_networkResourceInstance = nullptr;
|
||||
KyWirelessConnectOperation *m_wco;
|
||||
KyWirelessNetResource *m_wnr;
|
||||
|
||||
private:
|
||||
QTimer *m_timer;
|
||||
|
||||
public:
|
||||
explicit NmDemo(QWidget *parent = nullptr);
|
||||
~NmDemo();
|
||||
|
||||
private:
|
||||
void initUi();
|
||||
void initConnect();
|
||||
void initTimer();
|
||||
void appendDebugLog(QString);
|
||||
void getWifiList();
|
||||
|
||||
public slots:
|
||||
void onWcoSignals(QString, QString, QString);
|
||||
void onBssidChange(QString, QString, QString);
|
||||
void onSecuTypeChange(QString, QString, QString);
|
||||
void onSignalStrengthChange(QString, QString, int);
|
||||
|
||||
void onConnectionRemove(QString, QString);
|
||||
void onConnectionAdd(QString, QString);
|
||||
void onWifiNetworkAdd(QString, KyWirelessNetItem&);
|
||||
void onWifiNetworkRemove(QString, QString);
|
||||
|
||||
void onConnectClicked();
|
||||
void onDisConnectClicked();
|
||||
void onModifyClicked();
|
||||
void onEnableClick();
|
||||
void onDisableClick();
|
||||
|
||||
void onActiveConnectionAdd(NetworkManager::ActiveConnection::Ptr conn);
|
||||
void onActiveConnectionUpdate(NetworkManager::ActiveConnection * conn);
|
||||
void onActiveConnectionRemove(NetworkManager::ActiveConnection * conn);
|
||||
void onActiveConnectionsReset();
|
||||
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
};
|
||||
|
||||
#endif // NMDEMO_H
|
Loading…
Reference in New Issue