Merge PR #582: Add API to configure the wired network
This commit is contained in:
commit
1d5144fb66
2
debian/control
vendored
2
debian/control
vendored
@ -9,7 +9,7 @@ Build-Depends: debhelper (>= 9.0.0),
|
||||
dbus-test-runner,
|
||||
dpkg-dev (>= 1.16.1~),
|
||||
libnymea-mqtt-dev (>= 0.1.2),
|
||||
libnymea-networkmanager-dev (>= 0.4.0),
|
||||
libnymea-networkmanager-dev (>= 1.5.0~),
|
||||
libnymea-remoteproxyclient-dev (>= 0.1.13),
|
||||
libnymea-zigbee-dev (>= 0.1.0),
|
||||
libnymea-gpio-dev,
|
||||
|
||||
@ -91,6 +91,7 @@ NetworkManagerHandler::NetworkManagerHandler(NetworkManager *networkManager, QOb
|
||||
registerEnum<NetworkManager::NetworkManagerState>();
|
||||
registerEnum<NetworkDevice::NetworkDeviceState>();
|
||||
registerEnum<WirelessNetworkDevice::WirelessMode>();
|
||||
registerEnum<WiredNetworkConnectionType>();
|
||||
|
||||
// Objects
|
||||
QVariantMap wirelessAccessPoint;
|
||||
@ -172,6 +173,17 @@ NetworkManagerHandler::NetworkManagerHandler(NetworkManager *networkManager, QOb
|
||||
returns.insert("networkManagerError", enumRef<NetworkManager::NetworkManagerError>());
|
||||
registerMethod("ScanWifiNetworks", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Create a wired connection.";
|
||||
params.insert("interface", enumValueName(String));
|
||||
params.insert("type", enumRef<WiredNetworkConnectionType>());
|
||||
params.insert("o:ip", enumValueName(String));
|
||||
params.insert("o:prefix", enumValueName(Uint));
|
||||
params.insert("o:gateway", enumValueName(String));
|
||||
params.insert("o:dns", enumValueName(String));
|
||||
returns.insert("networkManagerError", enumRef<NetworkManager::NetworkManagerError>());
|
||||
registerMethod("CreateWiredConnection", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
description = "Connect to the wifi network with the given ssid and password.";
|
||||
params.insert("interface", enumValueName(String));
|
||||
@ -341,6 +353,38 @@ JsonReply *NetworkManagerHandler::GetNetworkDevices(const QVariantMap ¶ms)
|
||||
return createReply(returns);
|
||||
}
|
||||
|
||||
JsonReply *NetworkManagerHandler::CreateWiredConnection(const QVariantMap ¶ms)
|
||||
{
|
||||
if (!m_networkManager->available()) {
|
||||
return createReply(statusToReply(NetworkManager::NetworkManagerErrorNetworkManagerNotAvailable));
|
||||
}
|
||||
QString interface = params.value("interface").toString();
|
||||
QMetaEnum typeEnum = QMetaEnum::fromType<WiredNetworkConnectionType>();
|
||||
WiredNetworkConnectionType type = static_cast<WiredNetworkConnectionType>(typeEnum.keyToValue(params.value("type").toByteArray()));
|
||||
|
||||
switch (type) {
|
||||
case WiredNetworkConnectionTypeManual: {
|
||||
QHostAddress ip = QHostAddress(params.value("ip").toString());
|
||||
quint8 prefix = params.value("prefix").toInt();
|
||||
QHostAddress gateway = QHostAddress(params.value("gateway").toString());
|
||||
QHostAddress dns = QHostAddress(params.value("dns").toString());
|
||||
NetworkManager::NetworkManagerError status = m_networkManager->createWiredManualConnection(interface, ip, prefix, gateway, dns);
|
||||
return createReply(statusToReply(status));
|
||||
}
|
||||
case WiredNetworkConnectionTypeDHCP: {
|
||||
NetworkManager::NetworkManagerError status = m_networkManager->createWiredAutoConnection(interface);
|
||||
return createReply(statusToReply(status));
|
||||
}
|
||||
case WiredNetworkConnectionTypeShared: {
|
||||
QHostAddress ip = QHostAddress(params.value("ip").toString());
|
||||
quint8 prefix = params.value("prefix").toInt();
|
||||
NetworkManager::NetworkManagerError status = m_networkManager->createSharedConnection(interface, ip, prefix);
|
||||
return createReply(statusToReply(status));
|
||||
}
|
||||
}
|
||||
return createReply(statusToReply(NetworkManager::NetworkManagerErrorInvalidConfiguration));
|
||||
}
|
||||
|
||||
JsonReply *NetworkManagerHandler::ScanWifiNetworks(const QVariantMap ¶ms)
|
||||
{
|
||||
Q_UNUSED(params)
|
||||
|
||||
@ -42,6 +42,13 @@ class NetworkManagerHandler : public JsonHandler
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
enum WiredNetworkConnectionType {
|
||||
WiredNetworkConnectionTypeDHCP,
|
||||
WiredNetworkConnectionTypeManual,
|
||||
WiredNetworkConnectionTypeShared
|
||||
};
|
||||
Q_ENUM(WiredNetworkConnectionType)
|
||||
|
||||
explicit NetworkManagerHandler(NetworkManager *networkManager, QObject *parent = nullptr);
|
||||
|
||||
QString name() const override;
|
||||
@ -51,14 +58,12 @@ public:
|
||||
Q_INVOKABLE JsonReply *EnableWirelessNetworking(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *GetWirelessAccessPoints(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *GetNetworkDevices(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *CreateWiredConnection(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *ScanWifiNetworks(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *ConnectWifiNetwork(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *DisconnectInterface(const QVariantMap ¶ms);
|
||||
Q_INVOKABLE JsonReply *StartAccessPoint(const QVariantMap ¶ms);
|
||||
|
||||
private:
|
||||
QVariantMap packNetworkManagerStatus();
|
||||
|
||||
signals:
|
||||
// NetworkManager
|
||||
void NetworkStatusChanged(const QVariantMap ¶ms);
|
||||
@ -86,6 +91,7 @@ private slots:
|
||||
void onWiredNetworkDeviceChanged(WiredNetworkDevice *networkDevice);
|
||||
|
||||
private:
|
||||
QVariantMap packNetworkManagerStatus();
|
||||
QVariantMap packWirelessAccessPoint(WirelessAccessPoint *wirelessAccessPoint);
|
||||
QVariantMap packWiredNetworkDevice(WiredNetworkDevice *networkDevice);
|
||||
QVariantMap packWirelessNetworkDevice(WirelessNetworkDevice *networkDevice);
|
||||
|
||||
@ -154,7 +154,8 @@
|
||||
"NetworkManagerErrorWirelessNetworkingDisabled",
|
||||
"NetworkManagerErrorWirelessConnectionFailed",
|
||||
"NetworkManagerErrorNetworkingDisabled",
|
||||
"NetworkManagerErrorNetworkManagerNotAvailable"
|
||||
"NetworkManagerErrorNetworkManagerNotAvailable",
|
||||
"NetworkManagerErrorInvalidConfiguration"
|
||||
],
|
||||
"NetworkManagerState": [
|
||||
"NetworkManagerStateUnknown",
|
||||
@ -375,6 +376,11 @@
|
||||
"ValueOperatorLessOrEqual",
|
||||
"ValueOperatorGreaterOrEqual"
|
||||
],
|
||||
"WiredNetworkConnectionType": [
|
||||
"WiredNetworkConnectionTypeDHCP",
|
||||
"WiredNetworkConnectionTypeManual",
|
||||
"WiredNetworkConnectionTypeShared"
|
||||
],
|
||||
"WirelessMode": [
|
||||
"WirelessModeUnknown",
|
||||
"WirelessModeAdhoc",
|
||||
@ -1460,6 +1466,21 @@
|
||||
"networkManagerError": "$ref:NetworkManagerError"
|
||||
}
|
||||
},
|
||||
"NetworkManager.CreateWiredConnection": {
|
||||
"description": "Create a wired connection.",
|
||||
"params": {
|
||||
"interface": "String",
|
||||
"o:dns": "String",
|
||||
"o:gateway": "String",
|
||||
"o:ip": "String",
|
||||
"o:prefix": "Uint",
|
||||
"type": "$ref:WiredNetworkConnectionType"
|
||||
},
|
||||
"permissionScope": "PermissionScopeAdmin",
|
||||
"returns": {
|
||||
"networkManagerError": "$ref:NetworkManagerError"
|
||||
}
|
||||
},
|
||||
"NetworkManager.DisconnectInterface": {
|
||||
"description": "Disconnect the given network interface. The interface will remain disconnected until the user connect it again.",
|
||||
"params": {
|
||||
|
||||
Reference in New Issue
Block a user