Merge branch 'kylin-nm-dbus-renpj' into 'dbus-interface'

添加创建wifi  ap的功能

See merge request kylin-desktop/kylin-nm!167
This commit is contained in:
ren peijia 2021-08-17 07:37:41 +00:00
commit bf15d59efd
10 changed files with 309 additions and 3 deletions

View File

@ -5,6 +5,7 @@ HEADERS += \
$$PWD/kylinactiveconnectresource.h \
$$PWD/kylinagent.h \
$$PWD/kylinagentinterface.h \
$$PWD/kylinapconnectitem.h \
$$PWD/kylinbluetoothconnectitem.h \
$$PWD/kylinconnectitem.h \
$$PWD/kylinconnectoperation.h \
@ -23,6 +24,7 @@ SOURCES += \
$$PWD/kylinactiveconnectresource.cpp \
$$PWD/kylinagent.c \
$$PWD/kylinagentinterface.c \
$$PWD/kylinapconnectitem.cpp \
$$PWD/kylinbluetoothconnectitem.cpp \
$$PWD/kylinconnectitem.cpp \
$$PWD/kylinconnectoperation.cpp \

View File

@ -1,6 +1,9 @@
#ifndef KYENTERPRICESETTINGINFO_H
#define KYENTERPRICESETTINGINFO_H
#include <NetworkManagerQt/Ipv4Setting>
#include <NetworkManagerQt/Ipv6Setting>
#include "kylinnetworkresourcemanager.h"
#include <QObject>

View File

@ -1,5 +1,6 @@
#include "kylinactiveconnectresource.h"
#include "kywirelessconnectoperation.h"
#include <NetworkManagerQt/IpConfig>
#include <NetworkManagerQt/Dhcp4Config>
@ -440,3 +441,73 @@ void KyActiveConnectResourse::getBtActivateConnect(QList<KyBluetoothConnectItem
return;
}
KyApConnectItem *KyActiveConnectResourse::getApActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr)
{
qDebug()<<"[KyActiveConnectResourse]"<<"get wireless ap active connect item";
if (nullptr == activeConnectPtr) {
qWarning()<<"[KyActiveConnectResourse]"<<"get wireless ap item failed, the active connect is empty";
return nullptr;
}
if (NetworkManager::ActiveConnection::State::Activated != activeConnectPtr->state()) {
qWarning()<<"[KyActiveConnectResourse]"<<"get ap item failed, the active connect is not activated"
<<activeConnectPtr->connection()->name() << activeConnectPtr->state();
return nullptr;
}
NetworkManager::Connection::Ptr connectPtr = activeConnectPtr->connection();
NetworkManager::ConnectionSettings::Ptr settingPtr = connectPtr->settings();
NetworkManager::WirelessSetting::Ptr wirelessSetting
= settingPtr->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
if (NetworkManager::WirelessSetting::NetworkMode::Ap
!= wirelessSetting->mode()) {
qDebug() << "[KyActiveConnectResourse]" <<"get ap item failed, the active connect mode is not ap.";
return nullptr;
}
KyApConnectItem *apConnectItem = new KyApConnectItem();
apConnectItem->m_connectName = connectPtr->name();
apConnectItem->m_connectUuid = activeConnectPtr->uuid();
apConnectItem->m_ifaceName = settingPtr->interfaceName();
//NetworkManager::WirelessSecuritySetting::Ptr wirelessSecuritySetting
// = settingPtr->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
KyWirelessConnectOperation wirelessOperation;
apConnectItem->m_password = wirelessOperation.getPsk(apConnectItem->m_connectUuid);
return apConnectItem;
}
void KyActiveConnectResourse::getApActivateConnect(QList<KyApConnectItem *> &apConnectItemList)
{
int index = 0;
NetworkManager::ActiveConnection::List activeConnectList;
activeConnectList.clear();
activeConnectList = m_networkResourceInstance->getActiveConnectList();
if (activeConnectList.empty()) {
qWarning()<<"[KyActiveConnectResourse]"
<<"get ap active connect failed, the active connect list is empty";
return;
}
NetworkManager::ActiveConnection::Ptr activeConnectPtr = nullptr;
for (index = 0; index < activeConnectList.size(); index++) {
activeConnectPtr = activeConnectList.at(index);
if (NetworkManager::ConnectionSettings::ConnectionType::Wireless
!= activeConnectPtr->type()) {
continue;
}
KyApConnectItem *apConnectItem = getApActiveConnectItem(activeConnectPtr);
if (nullptr != apConnectItem) {
apConnectItemList << apConnectItem;
}
activeConnectPtr = nullptr;
}
return;
}

View File

@ -7,6 +7,7 @@
#include "kylinnetworkdeviceresource.h"
#include "kylinvpnconnectitem.h"
#include "kylinbluetoothconnectitem.h"
#include "kylinapconnectitem.h"
class KyActiveConnectResourse : public QObject
{
@ -31,6 +32,8 @@ public:
void getVpnActivateConnect(QList<KyVpnConnectItem *> &vpnActiveConnectItemList);
void getBtActivateConnect(QList<KyBluetoothConnectItem *> &btActiveConnectItemList);
void getApActivateConnect(QList<KyApConnectItem *> &apConnectItemList);
private:
void getActiveConnectIp(NetworkManager::ActiveConnection::Ptr activeConnectPtr,
QString &ipv4Address,
@ -44,6 +47,7 @@ private:
// KyWiredConnectItem *getWiredActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr);
KyVpnConnectItem *getVpnActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr);
KyBluetoothConnectItem *getBtActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr);
KyApConnectItem *getApActiveConnectItem(NetworkManager::ActiveConnection::Ptr activeConnectPtr);
signals:
void activeConnectAdd(QString activeConnectUuid);

View File

@ -0,0 +1,16 @@
#include "kylinapconnectitem.h"
KyApConnectItem::KyApConnectItem(QObject *parent) : QObject(parent)
{
m_connectName = "";
m_connectUuid = "";
m_ifaceName = "";
m_password = "";
}
KyApConnectItem::~KyApConnectItem()
{
}

View File

@ -0,0 +1,21 @@
#ifndef KYLINAPCONNECTITEM_H
#define KYLINAPCONNECTITEM_H
#include <QObject>
class KyApConnectItem : public QObject
{
Q_OBJECT
public:
explicit KyApConnectItem(QObject *parent = nullptr);
~KyApConnectItem();
public:
QString m_connectName;
QString m_connectUuid;
QString m_ifaceName;
QString m_password;
};
#endif // KYLINAPCONNECTITEM_H

View File

@ -1,5 +1,7 @@
#include "kylinconnectresource.h"
#include "kywirelessconnectoperation.h"
#include <NetworkManagerQt/Ipv4Setting>
#include <NetworkManagerQt/Ipv6Setting>
#include <NetworkManagerQt/VpnConnection>
@ -456,3 +458,69 @@ void KyConnectResourse::getBluetoothConnections(QList<KyBluetoothConnectItem *>
return;
}
KyApConnectItem *KyConnectResourse::getApConnectItem(NetworkManager::Connection::Ptr connectPtr)
{
if (nullptr == connectPtr) {
qWarning()<<"[KyConnectResourse]"<<"get bluetooth connection item failed, the connect is empty";
return nullptr;
}
NetworkManager::ConnectionSettings::Ptr settingPtr = connectPtr->settings();
NetworkManager::WirelessSetting::Ptr wirelessSetting
= settingPtr->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
if (NetworkManager::WirelessSetting::NetworkMode::Ap
!= wirelessSetting->mode()) {
qDebug() << "[KyConnectResourse]" <<"get ap item failed, the active connect mode is not ap.";
return nullptr;
}
KyApConnectItem *apConnectItem = new KyApConnectItem();
apConnectItem->m_connectName = connectPtr->name();
apConnectItem->m_connectUuid = connectPtr->uuid();
apConnectItem->m_ifaceName = settingPtr->interfaceName();
//NetworkManager::WirelessSecuritySetting::Ptr wirelessSecuritySetting
// = settingPtr->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
KyWirelessConnectOperation wirelessOperation;
apConnectItem->m_password = wirelessOperation.getPsk(apConnectItem->m_connectUuid);// wirelessSecuritySetting->psk();
return apConnectItem;
}
void KyConnectResourse::getApConnections(QList<KyApConnectItem *> &apConnectItemList)
{
int index = 0;
NetworkManager::Connection::List connectList;
qDebug()<<"[KyConnectResourse]"<<"get ap connections";
connectList.clear();
connectList = m_networkResourceInstance->getConnectList();
if (connectList.empty()) {
qWarning()<<"[KyConnectResourse]"<<"get ap connections failed, the connect list is empty";
return;
}
NetworkManager::Connection::Ptr connectPtr = nullptr;
for (index = 0; index < connectList.size(); index++) {
connectPtr = connectList.at(index);
if (NetworkManager::ConnectionSettings::ConnectionType::Wireless
!= connectPtr->settings()->connectionType()) {
qDebug()<<"[KyConnectResourse]"<<"connect name:" << connectPtr->name()
<<"connect type:"<<connectPtr->settings()->connectionType();
continue;
}
KyApConnectItem *connectItem = getApConnectItem(connectPtr);
if (nullptr != connectItem) {
apConnectItemList << connectItem;
}
connectPtr = nullptr;
}
return;
}

View File

@ -8,6 +8,7 @@
#include "kylinbluetoothconnectitem.h"
#include "kylinnetworkdeviceresource.h"
#include "kylinconnectsetting.h"
#include "kylinapconnectitem.h"
class KyConnectResourse : public QObject
{
@ -24,6 +25,7 @@ public:
// void getWiredConnections(QList<KyWiredConnectItem *> &wiredConnectItemList);
void getVpnConnections(QList<KyVpnConnectItem *> &vpnConnectItemList);
void getBluetoothConnections(QList<KyBluetoothConnectItem *> &bluetoothConnectItemList);
void getApConnections(QList<KyApConnectItem *> &apConnectItemList);
void getConnectionSetting(QString connectUuid, KyConnectSetting &connectSetting);
private:
@ -36,8 +38,8 @@ private:
void getVpnConnectData(NetworkManager::ConnectionSettings::Ptr settingPtr,
KyVpnConnectItem *vpnItem);
KyVpnConnectItem *getVpnConnectItem(NetworkManager::Connection::Ptr connectPtr);
KyBluetoothConnectItem *getBluetoothConnectItem(NetworkManager::Connection::Ptr connectPtr);
KyApConnectItem *getApConnectItem(NetworkManager::Connection::Ptr connectPtr);
void getIpv4ConnectSetting(NetworkManager::Ipv4Setting::Ptr &ipv4Setting,
KyConnectSetting &connectSetting);

View File

@ -416,6 +416,7 @@ qDebug() << dev_uni;
qDebug() << "addAndActiveWirelessConnect not support";
break;
}
qDebug() << "finish assemble";
} else {
qDebug() << "start assembleWirelessSettings";
@ -647,6 +648,116 @@ bool KyWirelessConnectOperation::getConnSecretFlags(QString &connUuid, NetworkMa
return true;
}
NetworkManager::ConnectionSettings::Ptr
KyWirelessConnectOperation::createWirelessApSetting(const QString apSsid, const QString apPassword, const QString apDevice)
{
NetworkManager::ConnectionSettings::Ptr connectionSettings =
NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wireless));
connectionSettings->setId(apSsid);
connectionSettings->setUuid(NetworkManager::ConnectionSettings::createNewUuid());
connectionSettings->setAutoconnect(true);
connectionSettings->setAutoconnectPriority(0);
connectionSettings->setInterfaceName(apDevice);
//Note: workaround for wrongly (randomly) initialized gateway-ping-timeout
connectionSettings->setGatewayPingTimeout(0);
NetworkManager::Ipv4Setting::Ptr ipv4Setting = connectionSettings->setting(NetworkManager::Setting::Ipv4).dynamicCast<NetworkManager::Ipv4Setting>();
ipv4Setting->setInitialized(true);
ipv4Setting->setMethod(NetworkManager::Ipv4Setting::Shared);
NetworkManager::Ipv6Setting::Ptr ipv6Setting = connectionSettings->setting(NetworkManager::Setting::Ipv6).dynamicCast<NetworkManager::Ipv6Setting>();
ipv6Setting->setInitialized(true);
ipv6Setting->setMethod(NetworkManager::Ipv6Setting::Ignored);
NetworkManager::WirelessSetting::Ptr wirelessSetting
= connectionSettings->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
wirelessSetting->setInitialized(true);
wirelessSetting->setSsid(apSsid.toUtf8());
wirelessSetting->setMode(NetworkManager::WirelessSetting::NetworkMode::Ap);
wirelessSetting->setSecurity("802-11-wireless-security");
NetworkManager::WirelessSecuritySetting::Ptr wirelessSecuritySetting
= connectionSettings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
wirelessSecuritySetting->setInitialized(true);
if (apPassword.isEmpty()) {
wirelessSecuritySetting->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaNone);
} else {
wirelessSecuritySetting->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaPsk);
wirelessSecuritySetting->setPsk(apPassword);
}
return connectionSettings;
}
void KyWirelessConnectOperation::updateWirelessApSetting(
NetworkManager::Connection::Ptr apConnectPtr,
const QString apName, const QString apPassword, const QString apDevice)
{
NetworkManager::ConnectionSettings::Ptr apConnectSettingPtr = apConnectPtr->settings();
apConnectSettingPtr->setId(apName);
apConnectSettingPtr->setInterfaceName(apDevice);
NetworkManager::WirelessSetting::Ptr wirelessSetting
= apConnectSettingPtr->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
wirelessSetting->setInitialized(true);
wirelessSetting->setSsid(apName.toUtf8());
NetworkManager::WirelessSecuritySetting::Ptr wirelessSecuritySetting
= apConnectSettingPtr->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();
wirelessSecuritySetting->setInitialized(true);
if (apPassword.isEmpty()) {
wirelessSecuritySetting->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaNone);
} else {
wirelessSecuritySetting->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaPsk);
wirelessSecuritySetting->setPsk(apPassword);
}
apConnectPtr->update(apConnectSettingPtr->toMap());
}
void KyWirelessConnectOperation::activeWirelessAp(const QString apUuid, const QString apName,
const QString apPassword, const QString apDevice)
{
//1、检查连接是否存在
NetworkManager::Connection::Ptr connectPtr = m_networkResourceInstance->getConnect(apUuid);
if (nullptr == connectPtr) {
NetworkManager::Device::Ptr devicePtr = m_networkResourceInstance->findDeviceInterface(apDevice);
if (devicePtr.isNull()) {
QString errorMsg ="active wifi ap failed," + apDevice + "is not existed";
qWarning()<< errorMsg;
emit andAndActivateConnectionError(errorMsg);
return;
}
QString deviceIdentifier = devicePtr->uni();
NetworkManager::ConnectionSettings::Ptr apConnectSettingPtr =
createWirelessApSetting(apName, apPassword, apDevice);
QString specificObject = "";
QDBusPendingCallWatcher * watcher;
watcher = new QDBusPendingCallWatcher{NetworkManager::addAndActivateConnection(apConnectSettingPtr->toMap(), deviceIdentifier, specificObject), this};
connect(watcher, &QDBusPendingCallWatcher::finished, [&] (QDBusPendingCallWatcher * watcher) {
if (watcher->isError() || !watcher->isValid()) {
QString errorMsg = "activation connection failed," + watcher->error().message();
qWarning() << errorMsg;
emit andAndActivateConnectionError(errorMsg);
}
watcher->deleteLater();
});
} else {
updateWirelessApSetting(connectPtr, apName, apPassword, apDevice);
activateConnection(apUuid, apDevice);
}
return;
}
void KyWirelessConnectOperation::deactiveWirelessAp(const QString apName, const QString apUuid)
{
deactivateConnection(apName, apUuid);
return;
}
//private
NetworkManager::WirelessNetwork::Ptr KyWirelessConnectOperation::checkWifiNetExist(QString ssid, QString devName)
{

View File

@ -82,8 +82,6 @@ public:
QString & devIface, bool isHidden);
void addAndActiveWirelessEnterPriseTtlsConnect(KyEapMethodTtlsInfo &info, KyWirelessConnectSetting &connSettingInfo,
QString & devIface, bool isHidden);
//属性页 page1 AutoConnect
void setWirelessAutoConnect(const QString &uuid, bool bAutoConnect);
//属性页 page2 page3 ipv6
@ -103,6 +101,16 @@ public:
//申请扫描
void requestWirelessScan();
void activeWirelessAp(const QString apUuid, const QString apName, const QString apPassword, const QString apDevice);
void deactiveWirelessAp(const QString apName, const QString apUuid);
private:
NetworkManager::ConnectionSettings::Ptr createWirelessApSetting(const QString apSsid, const QString apPassword, const QString apDevice);
void updateWirelessApSetting(NetworkManager::Connection::Ptr apConnectPtr,
const QString apName, const QString apPassword, const QString apDevice);
signals:
void wifinEnabledChanged(bool);
void andAndActivateConnectionError(QString errorMessage);