Add API to configure the wired network
This commit is contained in:
parent
b4e396fae9
commit
baab4ed8c6
2
debian/control
vendored
2
debian/control
vendored
@ -9,7 +9,7 @@ Build-Depends: debhelper (>= 9.0.0),
|
|||||||
dbus-test-runner,
|
dbus-test-runner,
|
||||||
dpkg-dev (>= 1.16.1~),
|
dpkg-dev (>= 1.16.1~),
|
||||||
libnymea-mqtt-dev (>= 0.1.2),
|
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-remoteproxyclient-dev (>= 0.1.13),
|
||||||
libnymea-zigbee-dev (>= 0.1.0),
|
libnymea-zigbee-dev (>= 0.1.0),
|
||||||
libnymea-gpio-dev,
|
libnymea-gpio-dev,
|
||||||
|
|||||||
@ -91,6 +91,7 @@ NetworkManagerHandler::NetworkManagerHandler(NetworkManager *networkManager, QOb
|
|||||||
registerEnum<NetworkManager::NetworkManagerState>();
|
registerEnum<NetworkManager::NetworkManagerState>();
|
||||||
registerEnum<NetworkDevice::NetworkDeviceState>();
|
registerEnum<NetworkDevice::NetworkDeviceState>();
|
||||||
registerEnum<WirelessNetworkDevice::WirelessMode>();
|
registerEnum<WirelessNetworkDevice::WirelessMode>();
|
||||||
|
registerEnum<WiredNetworkConnectionType>();
|
||||||
|
|
||||||
// Objects
|
// Objects
|
||||||
QVariantMap wirelessAccessPoint;
|
QVariantMap wirelessAccessPoint;
|
||||||
@ -172,6 +173,17 @@ NetworkManagerHandler::NetworkManagerHandler(NetworkManager *networkManager, QOb
|
|||||||
returns.insert("networkManagerError", enumRef<NetworkManager::NetworkManagerError>());
|
returns.insert("networkManagerError", enumRef<NetworkManager::NetworkManagerError>());
|
||||||
registerMethod("ScanWifiNetworks", description, params, returns);
|
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();
|
params.clear(); returns.clear();
|
||||||
description = "Connect to the wifi network with the given ssid and password.";
|
description = "Connect to the wifi network with the given ssid and password.";
|
||||||
params.insert("interface", enumValueName(String));
|
params.insert("interface", enumValueName(String));
|
||||||
@ -341,6 +353,38 @@ JsonReply *NetworkManagerHandler::GetNetworkDevices(const QVariantMap ¶ms)
|
|||||||
return createReply(returns);
|
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)
|
JsonReply *NetworkManagerHandler::ScanWifiNetworks(const QVariantMap ¶ms)
|
||||||
{
|
{
|
||||||
Q_UNUSED(params)
|
Q_UNUSED(params)
|
||||||
|
|||||||
@ -42,6 +42,13 @@ class NetworkManagerHandler : public JsonHandler
|
|||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
|
enum WiredNetworkConnectionType {
|
||||||
|
WiredNetworkConnectionTypeDHCP,
|
||||||
|
WiredNetworkConnectionTypeManual,
|
||||||
|
WiredNetworkConnectionTypeShared
|
||||||
|
};
|
||||||
|
Q_ENUM(WiredNetworkConnectionType)
|
||||||
|
|
||||||
explicit NetworkManagerHandler(NetworkManager *networkManager, QObject *parent = nullptr);
|
explicit NetworkManagerHandler(NetworkManager *networkManager, QObject *parent = nullptr);
|
||||||
|
|
||||||
QString name() const override;
|
QString name() const override;
|
||||||
@ -51,14 +58,12 @@ public:
|
|||||||
Q_INVOKABLE JsonReply *EnableWirelessNetworking(const QVariantMap ¶ms);
|
Q_INVOKABLE JsonReply *EnableWirelessNetworking(const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE JsonReply *GetWirelessAccessPoints(const QVariantMap ¶ms);
|
Q_INVOKABLE JsonReply *GetWirelessAccessPoints(const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE JsonReply *GetNetworkDevices(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 *ScanWifiNetworks(const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE JsonReply *ConnectWifiNetwork(const QVariantMap ¶ms);
|
Q_INVOKABLE JsonReply *ConnectWifiNetwork(const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE JsonReply *DisconnectInterface(const QVariantMap ¶ms);
|
Q_INVOKABLE JsonReply *DisconnectInterface(const QVariantMap ¶ms);
|
||||||
Q_INVOKABLE JsonReply *StartAccessPoint(const QVariantMap ¶ms);
|
Q_INVOKABLE JsonReply *StartAccessPoint(const QVariantMap ¶ms);
|
||||||
|
|
||||||
private:
|
|
||||||
QVariantMap packNetworkManagerStatus();
|
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
// NetworkManager
|
// NetworkManager
|
||||||
void NetworkStatusChanged(const QVariantMap ¶ms);
|
void NetworkStatusChanged(const QVariantMap ¶ms);
|
||||||
@ -86,6 +91,7 @@ private slots:
|
|||||||
void onWiredNetworkDeviceChanged(WiredNetworkDevice *networkDevice);
|
void onWiredNetworkDeviceChanged(WiredNetworkDevice *networkDevice);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
QVariantMap packNetworkManagerStatus();
|
||||||
QVariantMap packWirelessAccessPoint(WirelessAccessPoint *wirelessAccessPoint);
|
QVariantMap packWirelessAccessPoint(WirelessAccessPoint *wirelessAccessPoint);
|
||||||
QVariantMap packWiredNetworkDevice(WiredNetworkDevice *networkDevice);
|
QVariantMap packWiredNetworkDevice(WiredNetworkDevice *networkDevice);
|
||||||
QVariantMap packWirelessNetworkDevice(WirelessNetworkDevice *networkDevice);
|
QVariantMap packWirelessNetworkDevice(WirelessNetworkDevice *networkDevice);
|
||||||
|
|||||||
@ -5,7 +5,7 @@ NYMEA_VERSION_STRING=$$system('dpkg-parsechangelog | sed -n -e "s/^Version: //p"
|
|||||||
|
|
||||||
# define protocol versions
|
# define protocol versions
|
||||||
JSON_PROTOCOL_VERSION_MAJOR=6
|
JSON_PROTOCOL_VERSION_MAJOR=6
|
||||||
JSON_PROTOCOL_VERSION_MINOR=1
|
JSON_PROTOCOL_VERSION_MINOR=2
|
||||||
JSON_PROTOCOL_VERSION="$${JSON_PROTOCOL_VERSION_MAJOR}.$${JSON_PROTOCOL_VERSION_MINOR}"
|
JSON_PROTOCOL_VERSION="$${JSON_PROTOCOL_VERSION_MAJOR}.$${JSON_PROTOCOL_VERSION_MINOR}"
|
||||||
LIBNYMEA_API_VERSION_MAJOR=7
|
LIBNYMEA_API_VERSION_MAJOR=7
|
||||||
LIBNYMEA_API_VERSION_MINOR=3
|
LIBNYMEA_API_VERSION_MINOR=3
|
||||||
|
|||||||
@ -1,4 +1,4 @@
|
|||||||
6.1
|
6.2
|
||||||
{
|
{
|
||||||
"enums": {
|
"enums": {
|
||||||
"BasicType": [
|
"BasicType": [
|
||||||
@ -154,7 +154,8 @@
|
|||||||
"NetworkManagerErrorWirelessNetworkingDisabled",
|
"NetworkManagerErrorWirelessNetworkingDisabled",
|
||||||
"NetworkManagerErrorWirelessConnectionFailed",
|
"NetworkManagerErrorWirelessConnectionFailed",
|
||||||
"NetworkManagerErrorNetworkingDisabled",
|
"NetworkManagerErrorNetworkingDisabled",
|
||||||
"NetworkManagerErrorNetworkManagerNotAvailable"
|
"NetworkManagerErrorNetworkManagerNotAvailable",
|
||||||
|
"NetworkManagerErrorInvalidConfiguration"
|
||||||
],
|
],
|
||||||
"NetworkManagerState": [
|
"NetworkManagerState": [
|
||||||
"NetworkManagerStateUnknown",
|
"NetworkManagerStateUnknown",
|
||||||
@ -375,6 +376,11 @@
|
|||||||
"ValueOperatorLessOrEqual",
|
"ValueOperatorLessOrEqual",
|
||||||
"ValueOperatorGreaterOrEqual"
|
"ValueOperatorGreaterOrEqual"
|
||||||
],
|
],
|
||||||
|
"WiredNetworkConnectionType": [
|
||||||
|
"WiredNetworkConnectionTypeDHCP",
|
||||||
|
"WiredNetworkConnectionTypeManual",
|
||||||
|
"WiredNetworkConnectionTypeShared"
|
||||||
|
],
|
||||||
"WirelessMode": [
|
"WirelessMode": [
|
||||||
"WirelessModeUnknown",
|
"WirelessModeUnknown",
|
||||||
"WirelessModeAdhoc",
|
"WirelessModeAdhoc",
|
||||||
@ -1439,6 +1445,21 @@
|
|||||||
"networkManagerError": "$ref:NetworkManagerError"
|
"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": {
|
"NetworkManager.DisconnectInterface": {
|
||||||
"description": "Disconnect the given network interface. The interface will remain disconnected until the user connect it again.",
|
"description": "Disconnect the given network interface. The interface will remain disconnected until the user connect it again.",
|
||||||
"params": {
|
"params": {
|
||||||
|
|||||||
Reference in New Issue
Block a user