mirror of https://github.com/nymea/nymea.git
Drop internal networkmanager and use libnymea-networkmanager instead
parent
9af820b696
commit
58c4dcb6c9
|
|
@ -9,13 +9,14 @@ Build-Depends: debhelper (>= 9.0.0),
|
|||
dbus-test-runner,
|
||||
dh-systemd,
|
||||
dpkg-dev (>= 1.16.1~),
|
||||
libnymea-mqtt-dev (>= 0.1.2),
|
||||
libnymea-networkmanager-dev (>= 0.3.0),
|
||||
libnymea-remoteproxyclient-dev,
|
||||
libqt5websockets5-dev,
|
||||
libqt5bluetooth5,
|
||||
libqt5sql5-sqlite,
|
||||
libqt5dbus5,
|
||||
libssl-dev,
|
||||
libnymea-mqtt-dev (>= 0.1.2),
|
||||
rsync,
|
||||
qml-module-qtquick2,
|
||||
qtchooser,
|
||||
|
|
|
|||
|
|
@ -37,6 +37,8 @@
|
|||
#include "nymeaconfiguration.h"
|
||||
#include "nymeasettings.h"
|
||||
|
||||
#include <networkmanager.h>
|
||||
|
||||
#include "nymea-remoteproxyclient/remoteproxyconnection.h"
|
||||
#include <QDir>
|
||||
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
#include <QNetworkSession>
|
||||
#include <QUuid>
|
||||
|
||||
#include "networkmanager/networkmanager.h"
|
||||
class NetworkManager;
|
||||
|
||||
class AWSConnector;
|
||||
class CloudNotifications;
|
||||
|
|
|
|||
|
|
@ -58,6 +58,7 @@
|
|||
#include "loggingcategories.h"
|
||||
#include "platform/platform.h"
|
||||
#include "version.h"
|
||||
#include "cloud/cloudmanager.h"
|
||||
|
||||
#include "devicehandler.h"
|
||||
#include "integrationshandler.h"
|
||||
|
|
|
|||
|
|
@ -80,7 +80,6 @@
|
|||
#include "nymeacore.h"
|
||||
#include "loggingcategories.h"
|
||||
#include "networkmanagerhandler.h"
|
||||
#include "networkmanager/networkmanager.h"
|
||||
|
||||
|
||||
namespace nymeaserver {
|
||||
|
|
@ -95,8 +94,22 @@ NetworkManagerHandler::NetworkManagerHandler(QObject *parent) :
|
|||
registerEnum<NetworkDevice::NetworkDeviceState>();
|
||||
|
||||
// Objects
|
||||
registerUncreatableObject<WirelessAccessPoint>();
|
||||
registerUncreatableObject<WiredNetworkDevice>();
|
||||
QVariantMap wirelessAccessPoint;
|
||||
wirelessAccessPoint.insert("ssid", enumValueName(String));
|
||||
wirelessAccessPoint.insert("macAddress", enumValueName(String));
|
||||
wirelessAccessPoint.insert("frequency", enumValueName(Double));
|
||||
wirelessAccessPoint.insert("signalStrength", enumValueName(Int));
|
||||
wirelessAccessPoint.insert("protected", enumValueName(Bool));
|
||||
registerObject("WirelessAccessPoint", wirelessAccessPoint);
|
||||
|
||||
|
||||
QVariantMap wiredNetworkDevice;
|
||||
wiredNetworkDevice.insert("interface", enumValueName(String));
|
||||
wiredNetworkDevice.insert("macAddress", enumValueName(String));
|
||||
wiredNetworkDevice.insert("state", enumRef<NetworkDevice::NetworkDeviceState>());
|
||||
wiredNetworkDevice.insert("bitRate", enumValueName(String));
|
||||
wiredNetworkDevice.insert("pluggedIn", enumValueName(Bool));
|
||||
registerObject("WiredNetworkDevice", wiredNetworkDevice);
|
||||
|
||||
QVariantMap wirelessNetworkDevice;
|
||||
wirelessNetworkDevice.insert("interface", enumValueName(String));
|
||||
|
|
@ -144,9 +157,9 @@ NetworkManagerHandler::NetworkManagerHandler(QObject *parent) :
|
|||
|
||||
params.clear(); returns.clear();
|
||||
description = "Get the list of current network devices.";
|
||||
returns.insert("wiredNetworkDevices", QVariantList() << objectRef("WiredNetworkDevice"));
|
||||
returns.insert("wirelessNetworkDevices", QVariantList() << objectRef("WirelessNetworkDevice"));
|
||||
returns.insert("networkManagerError", enumRef<NetworkManager::NetworkManagerError>());
|
||||
returns.insert("o:wiredNetworkDevices", QVariantList() << objectRef("WiredNetworkDevice"));
|
||||
returns.insert("o:wirelessNetworkDevices", QVariantList() << objectRef("WirelessNetworkDevice"));
|
||||
registerMethod("GetNetworkDevices", description, params, returns);
|
||||
|
||||
params.clear(); returns.clear();
|
||||
|
|
@ -250,7 +263,7 @@ JsonReply *NetworkManagerHandler::EnableWirelessNetworking(const QVariantMap &pa
|
|||
if (!NymeaCore::instance()->networkManager()->available())
|
||||
return createReply(statusToReply(NetworkManager::NetworkManagerErrorNetworkManagerNotAvailable));
|
||||
|
||||
if (!NymeaCore::instance()->networkManager()->wifiAvailable())
|
||||
if (!NymeaCore::instance()->networkManager()->wirelessAvailable())
|
||||
return createReply(statusToReply(NetworkManager::NetworkManagerErrorWirelessNotAvailable));
|
||||
|
||||
if (!NymeaCore::instance()->networkManager()->enableWireless(params.value("enable").toBool()))
|
||||
|
|
@ -264,7 +277,7 @@ JsonReply *NetworkManagerHandler::GetWirelessAccessPoints(const QVariantMap &par
|
|||
if (!NymeaCore::instance()->networkManager()->available())
|
||||
return createReply(statusToReply(NetworkManager::NetworkManagerErrorNetworkManagerNotAvailable));
|
||||
|
||||
if (!NymeaCore::instance()->networkManager()->wifiAvailable())
|
||||
if (!NymeaCore::instance()->networkManager()->wirelessAvailable())
|
||||
return createReply(statusToReply(NetworkManager::NetworkManagerErrorWirelessNotAvailable));
|
||||
|
||||
if (!NymeaCore::instance()->networkManager()->networkingEnabled())
|
||||
|
|
@ -296,7 +309,7 @@ JsonReply *NetworkManagerHandler::GetWirelessAccessPoints(const QVariantMap &par
|
|||
|
||||
JsonReply *NetworkManagerHandler::GetNetworkDevices(const QVariantMap ¶ms)
|
||||
{
|
||||
Q_UNUSED(params);
|
||||
Q_UNUSED(params)
|
||||
|
||||
if (!NymeaCore::instance()->networkManager()->available())
|
||||
return createReply(statusToReply(NetworkManager::NetworkManagerErrorNetworkManagerNotAvailable));
|
||||
|
|
@ -322,7 +335,7 @@ JsonReply *NetworkManagerHandler::ScanWifiNetworks(const QVariantMap ¶ms)
|
|||
if (!NymeaCore::instance()->networkManager()->available())
|
||||
return createReply(statusToReply(NetworkManager::NetworkManagerErrorNetworkManagerNotAvailable));
|
||||
|
||||
if (!NymeaCore::instance()->networkManager()->wifiAvailable())
|
||||
if (!NymeaCore::instance()->networkManager()->wirelessAvailable())
|
||||
return createReply(statusToReply(NetworkManager::NetworkManagerErrorWirelessNotAvailable));
|
||||
|
||||
if (!NymeaCore::instance()->networkManager()->networkingEnabled())
|
||||
|
|
@ -352,7 +365,7 @@ JsonReply *NetworkManagerHandler::ConnectWifiNetwork(const QVariantMap ¶ms)
|
|||
if (!NymeaCore::instance()->networkManager()->available())
|
||||
return createReply(statusToReply(NetworkManager::NetworkManagerErrorNetworkManagerNotAvailable));
|
||||
|
||||
if (!NymeaCore::instance()->networkManager()->wifiAvailable())
|
||||
if (!NymeaCore::instance()->networkManager()->wirelessAvailable())
|
||||
return createReply(statusToReply(NetworkManager::NetworkManagerErrorWirelessNotAvailable));
|
||||
|
||||
if (!NymeaCore::instance()->networkManager()->networkingEnabled())
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@
|
|||
#include <QObject>
|
||||
|
||||
#include "jsonrpc/jsonhandler.h"
|
||||
#include "networkmanager/networkmanager.h"
|
||||
#include <networkmanager.h>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@ include(../nymea.pri)
|
|||
|
||||
QT += sql qml
|
||||
INCLUDEPATH += $$top_srcdir/libnymea $$top_builddir
|
||||
LIBS += -L$$top_builddir/libnymea/ -lnymea -lssl -lcrypto -lnymea-mqtt
|
||||
LIBS += -L$$top_builddir/libnymea/ -lnymea -lssl -lcrypto
|
||||
|
||||
CONFIG += link_pkgconfig
|
||||
PKGCONFIG += nymea-mqtt nymea-networkmanager
|
||||
|
||||
target.path = $$[QT_INSTALL_LIBS]
|
||||
INSTALLS += target
|
||||
|
|
@ -63,14 +66,6 @@ HEADERS += nymeacore.h \
|
|||
logging/logentry.h \
|
||||
logging/logvaluetool.h \
|
||||
time/timemanager.h \
|
||||
networkmanager/dbus-interfaces.h \
|
||||
networkmanager/networkmanager.h \
|
||||
networkmanager/networkdevice.h \
|
||||
networkmanager/wirelessaccesspoint.h \
|
||||
networkmanager/wirelessnetworkdevice.h \
|
||||
networkmanager/networksettings.h \
|
||||
networkmanager/networkconnection.h \
|
||||
networkmanager/wirednetworkdevice.h \
|
||||
usermanager/userinfo.h \
|
||||
usermanager/usermanager.h \
|
||||
usermanager/tokeninfo.h \
|
||||
|
|
@ -148,13 +143,6 @@ SOURCES += nymeacore.cpp \
|
|||
logging/logentry.cpp \
|
||||
logging/logvaluetool.cpp \
|
||||
time/timemanager.cpp \
|
||||
networkmanager/networkmanager.cpp \
|
||||
networkmanager/networkdevice.cpp \
|
||||
networkmanager/wirelessaccesspoint.cpp \
|
||||
networkmanager/wirelessnetworkdevice.cpp \
|
||||
networkmanager/networksettings.cpp \
|
||||
networkmanager/networkconnection.cpp \
|
||||
networkmanager/wirednetworkdevice.cpp \
|
||||
usermanager/userinfo.cpp \
|
||||
usermanager/usermanager.cpp \
|
||||
usermanager/tokeninfo.cpp \
|
||||
|
|
|
|||
|
|
@ -1,52 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef DBUSINTERFACES_H
|
||||
#define DBUSINTERFACES_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
static const QString serviceString("org.freedesktop.NetworkManager");
|
||||
|
||||
static const QString pathString("/org/freedesktop/NetworkManager");
|
||||
static const QString settingsPathString("/org/freedesktop/NetworkManager/Settings");
|
||||
|
||||
static const QString deviceInterfaceString("org.freedesktop.NetworkManager.Device");
|
||||
static const QString wirelessInterfaceString("org.freedesktop.NetworkManager.Device.Wireless");
|
||||
static const QString wiredInterfaceString("org.freedesktop.NetworkManager.Device.Wired");
|
||||
static const QString accessPointInterfaceString("org.freedesktop.NetworkManager.AccessPoint");
|
||||
static const QString settingsInterfaceString("org.freedesktop.NetworkManager.Settings");
|
||||
static const QString connectionsInterfaceString("org.freedesktop.NetworkManager.Settings.Connection");
|
||||
|
||||
}
|
||||
|
||||
#endif // DBUSINTERFACES_H
|
||||
|
|
@ -1,148 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*!
|
||||
\class nymeaserver::NetworkConnection
|
||||
\brief Represents a saved network connection of the \l{NetworkManager}.
|
||||
|
||||
\ingroup networkmanager
|
||||
\inmodule core
|
||||
|
||||
\sa NetworkSettings
|
||||
*/
|
||||
|
||||
#include "networkconnection.h"
|
||||
#include "dbus-interfaces.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
#include <QJsonDocument>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
/*! Constructs a new \l{NetworkConnection} with the given dbus \a objectPath and \a parent. */
|
||||
NetworkConnection::NetworkConnection(const QDBusObjectPath &objectPath, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_objectPath(objectPath)
|
||||
{
|
||||
qDBusRegisterMetaType<ConnectionSettings>();
|
||||
|
||||
m_connectionInterface = new QDBusInterface(serviceString, m_objectPath.path(), connectionsInterfaceString, QDBusConnection::systemBus(), this);
|
||||
if(!m_connectionInterface->isValid()) {
|
||||
qCWarning(dcNetworkManager()) << "Invalid connection dbus interface";
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusMessage query = m_connectionInterface->call("GetSettings");
|
||||
if(query.type() != QDBusMessage::ReplyMessage) {
|
||||
qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if (query.arguments().isEmpty())
|
||||
return;
|
||||
|
||||
const QDBusArgument &argument = query.arguments().at(0).value<QDBusArgument>();
|
||||
m_connectionSettings = qdbus_cast<ConnectionSettings>(argument);
|
||||
}
|
||||
|
||||
/*! Delets this \l{NetworkConnection} in the \l{NetworkManager}. */
|
||||
void NetworkConnection::deleteConnection()
|
||||
{
|
||||
QDBusMessage query = m_connectionInterface->call("Delete");
|
||||
if(query.type() != QDBusMessage::ReplyMessage)
|
||||
qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage();
|
||||
|
||||
}
|
||||
|
||||
/*! Returns the dbus object path of this \l{NetworkConnection}. */
|
||||
QDBusObjectPath NetworkConnection::objectPath() const
|
||||
{
|
||||
return m_objectPath;
|
||||
}
|
||||
|
||||
/*! Returns the connection settings of this \l{NetworkConnection}. */
|
||||
ConnectionSettings NetworkConnection::connectionSettings() const
|
||||
{
|
||||
return m_connectionSettings;
|
||||
}
|
||||
|
||||
/*! Returns the id of this \l{NetworkConnection}. */
|
||||
QString NetworkConnection::id() const
|
||||
{
|
||||
return m_connectionSettings.value("connection").value("id").toString();
|
||||
}
|
||||
|
||||
/*! Returns the name of this \l{NetworkConnection}. */
|
||||
QString NetworkConnection::name() const
|
||||
{
|
||||
return m_connectionSettings.value("connection").value("name").toString();
|
||||
}
|
||||
|
||||
/*! Returns the type of this \l{NetworkConnection}. */
|
||||
QString NetworkConnection::type() const
|
||||
{
|
||||
return m_connectionSettings.value("connection").value("type").toString();
|
||||
}
|
||||
|
||||
/*! Returns the uuid of this \l{NetworkConnection}. */
|
||||
QUuid NetworkConnection::uuid() const
|
||||
{
|
||||
return m_connectionSettings.value("connection").value("uuid").toUuid();
|
||||
}
|
||||
|
||||
/*! Returns the interface name of this \l{NetworkConnection}. */
|
||||
QString NetworkConnection::interfaceName() const
|
||||
{
|
||||
return m_connectionSettings.value("connection").value("interface-name").toString();
|
||||
}
|
||||
|
||||
/*! Returns true if this \l{NetworkConnection} will autoconnect if available. */
|
||||
bool NetworkConnection::autoconnect() const
|
||||
{
|
||||
return m_connectionSettings.value("connection").value("autoconnect").toBool();
|
||||
}
|
||||
|
||||
/*! Returns the timestamp of this \l{NetworkConnection} from the last connection. */
|
||||
QDateTime NetworkConnection::timeStamp() const
|
||||
{
|
||||
return QDateTime::fromTime_t(m_connectionSettings.value("connection").value("timestamp").toUInt());
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, NetworkConnection *networkConnection)
|
||||
{
|
||||
debug.nospace() << "NetworkConnection(" << networkConnection->id() << ", ";
|
||||
debug.nospace() << networkConnection->uuid().toString() << ", ";
|
||||
debug.nospace() << networkConnection->interfaceName() << ", ";
|
||||
debug.nospace() << networkConnection->type() << ", ";
|
||||
debug.nospace() << networkConnection->timeStamp().toString("dd.MM.yyyy hh:mm") << ") ";
|
||||
return debug;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,82 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef NETWORKCONNECTION_H
|
||||
#define NETWORKCONNECTION_H
|
||||
|
||||
#include <QUuid>
|
||||
#include <QDebug>
|
||||
#include <QObject>
|
||||
#include <QDateTime>
|
||||
#include <QDBusMetaType>
|
||||
#include <QDBusObjectPath>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusArgument>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
typedef QMap<QString, QVariantMap> ConnectionSettings;
|
||||
|
||||
class NetworkConnection : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NetworkConnection(const QDBusObjectPath &objectPath, QObject *parent = 0);
|
||||
|
||||
void deleteConnection();
|
||||
|
||||
QDBusObjectPath objectPath() const;
|
||||
ConnectionSettings connectionSettings() const;
|
||||
|
||||
QString id() const;
|
||||
QString name() const;
|
||||
QString type() const;
|
||||
QUuid uuid() const;
|
||||
QString interfaceName() const;
|
||||
bool autoconnect() const;
|
||||
QDateTime timeStamp() const;
|
||||
|
||||
private:
|
||||
QDBusObjectPath m_objectPath;
|
||||
QDBusInterface *m_connectionInterface;
|
||||
|
||||
ConnectionSettings m_connectionSettings;
|
||||
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug debug, NetworkConnection *networkConnection);
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(nymeaserver::ConnectionSettings)
|
||||
|
||||
|
||||
#endif // NETWORKCONNECTION_H
|
||||
|
|
@ -1,361 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*!
|
||||
\class nymeaserver::NetworkDevice
|
||||
\brief Represents a generic network device the \l{NetworkManager}.
|
||||
|
||||
\ingroup networkmanager
|
||||
\inmodule core
|
||||
|
||||
\sa WiredNetworkDevice, WirelessNetworkDevice
|
||||
*/
|
||||
|
||||
/*! \enum nymeaserver::NetworkDevice::NetworkDeviceState
|
||||
\value NetworkDeviceStateUnknown
|
||||
\value NetworkDeviceStateUnmanaged
|
||||
\value NetworkDeviceStateUnavailable
|
||||
\value NetworkDeviceStateDisconnected
|
||||
\value NetworkDeviceStatePrepare
|
||||
\value NetworkDeviceStateConfig
|
||||
\value NetworkDeviceStateNeedAuth
|
||||
\value NetworkDeviceStateIpConfig
|
||||
\value NetworkDeviceStateIpCheck
|
||||
\value NetworkDeviceStateSecondaries
|
||||
\value NetworkDeviceStateActivated
|
||||
\value NetworkDeviceStateDeactivating
|
||||
\value NetworkDeviceStateFailed
|
||||
*/
|
||||
|
||||
/*! \enum nymeaserver::NetworkDevice::NetworkDeviceStateReason
|
||||
\value NetworkDeviceStateReasonNone
|
||||
\value NetworkDeviceStateReasonUnknown
|
||||
\value NetworkDeviceStateReasonNowManaged
|
||||
\value NetworkDeviceStateReasonNowUnmanaged
|
||||
\value NetworkDeviceStateReasonConfigFailed
|
||||
\value NetworkDeviceStateReasonIpConfigUnavailable
|
||||
\value NetworkDeviceStateReasonIpConfigExpired
|
||||
\value NetworkDeviceStateReasonNoSecrets
|
||||
\value NetworkDeviceStateReasonSupplicantDisconnected
|
||||
\value NetworkDeviceStateReasonSupplicantConfigFailed
|
||||
\value NetworkDeviceStateReasonSupplicantFailed
|
||||
\value NetworkDeviceStateReasonSupplicantTimeout
|
||||
\value NetworkDeviceStateReasonPppStartFailed
|
||||
\value NetworkDeviceStateReasonPppDisconnected
|
||||
\value NetworkDeviceStateReasonPppFailed
|
||||
\value NetworkDeviceStateReasonDhcpStartFailed
|
||||
\value NetworkDeviceStateReasonDhcpError
|
||||
\value NetworkDeviceStateReasonDhcpFailed
|
||||
\value NetworkDeviceStateReasonSharedStartFailed
|
||||
\value NetworkDeviceStateReasonSharedFailed
|
||||
\value NetworkDeviceStateReasonAutoIpStartFailed
|
||||
\value NetworkDeviceStateReasonAutoIpError
|
||||
\value NetworkDeviceStateReasonAutoIpFailed
|
||||
\value NetworkDeviceStateReasonModemBusy
|
||||
\value NetworkDeviceStateReasonModemNoDialTone
|
||||
\value NetworkDeviceStateReasonModemNoCarrier
|
||||
\value NetworkDeviceStateReasonModemDialTimeout
|
||||
\value NetworkDeviceStateReasonModemDialFailed
|
||||
\value NetworkDeviceStateReasonModemInitFailed
|
||||
\value NetworkDeviceStateReasonGsmApnFailed
|
||||
\value NetworkDeviceStateReasonGsmRegistrationNotSearching
|
||||
\value NetworkDeviceStateReasonGsmRegistrationDenied
|
||||
\value NetworkDeviceStateReasonGsmRegistrationTimeout
|
||||
\value NetworkDeviceStateReasonGsmRegistrationFailed
|
||||
\value NetworkDeviceStateReasonGsmPinCheckFailed
|
||||
\value NetworkDeviceStateReasonFirmwareMissing
|
||||
\value NetworkDeviceStateReasonRemoved
|
||||
\value NetworkDeviceStateReasonSleeping
|
||||
\value NetworkDeviceStateReasonConnectionRemoved
|
||||
\value NetworkDeviceStateReasonUserRequest
|
||||
\value NetworkDeviceStateReasonCarrier
|
||||
\value NetworkDeviceStateReasonConnectionAssumed
|
||||
\value NetworkDeviceStateReasonSupplicantAvailable
|
||||
\value NetworkDeviceStateReasonModemNotFound
|
||||
\value NetworkDeviceStateReasonBtFailed
|
||||
\value NetworkDeviceStateReasonGsmSimNotInserted
|
||||
\value NetworkDeviceStateReasonGsmSimPinRequired
|
||||
\value NetworkDeviceStateReasonGsmSimPukRequired
|
||||
\value NetworkDeviceStateReasonGsmSimWrong
|
||||
\value NetworkDeviceStateReasonInfinibandMode
|
||||
\value NetworkDeviceStateReasonDependencyFailed
|
||||
\value NetworkDeviceStateReasonBR2684Failed
|
||||
\value NetworkDeviceStateReasonModemManagerUnavailable
|
||||
\value NetworkDeviceStateReasonSsidNotFound
|
||||
\value NetworkDeviceStateReasonSecondaryConnectionFailed
|
||||
\value NetworkDeviceStateReasonDcbFoecFailed
|
||||
\value NetworkDeviceStateReasonTeamdControlFailed
|
||||
\value NetworkDeviceStateReasonModemFailed
|
||||
\value NetworkDeviceStateReasonModemAvailable
|
||||
\value NetworkDeviceStateReasonSimPinIncorrect
|
||||
\value NetworkDeviceStateReasonNewActivision
|
||||
\value NetworkDeviceStateReasonParentChanged
|
||||
\value NetworkDeviceStateReasonParentManagedChanged
|
||||
*/
|
||||
|
||||
|
||||
/*! \enum nymeaserver::NetworkDevice::NetworkDeviceType
|
||||
\value NetworkDeviceTypeUnknown
|
||||
\value NetworkDeviceTypeEthernet
|
||||
\value NetworkDeviceTypeWifi
|
||||
\value NetworkDeviceTypeBluetooth
|
||||
\value NetworkDeviceTypeOlpcMesh
|
||||
\value NetworkDeviceTypeWiMax
|
||||
\value NetworkDeviceTypeModem
|
||||
\value NetworkDeviceTypeInfiniBand
|
||||
\value NetworkDeviceTypeBond
|
||||
\value NetworkDeviceTypeVLan
|
||||
\value NetworkDeviceTypeAdsl
|
||||
\value NetworkDeviceTypeBridge
|
||||
\value NetworkDeviceTypeGeneric
|
||||
\value NetworkDeviceTypeTeam
|
||||
\value NetworkDeviceTypeTun
|
||||
\value NetworkDeviceTypeIpTunnel
|
||||
\value NetworkDeviceTypeMacVLan
|
||||
\value NetworkDeviceTypeVXLan
|
||||
\value NetworkDeviceTypeVEth
|
||||
*/
|
||||
|
||||
|
||||
/*! \fn void NetworkDevice::deviceChanged();
|
||||
This signal will be emitted when the properties of this \l{NetworkDevice} have changed.
|
||||
*/
|
||||
|
||||
|
||||
#include "networkdevice.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
#include <QMetaEnum>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
/*! Constructs a new \l{NetworkDevice} with the given dbus \a objectPath and \a parent. */
|
||||
NetworkDevice::NetworkDevice(const QDBusObjectPath &objectPath, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_objectPath(objectPath),
|
||||
m_mtu(0),
|
||||
m_metered(0),
|
||||
m_deviceState(NetworkDeviceStateUnknown),
|
||||
m_deviceStateReason(NetworkDeviceStateReasonUnknown)
|
||||
{
|
||||
QDBusConnection systemBus = QDBusConnection::systemBus();
|
||||
if (!systemBus.isConnected()) {
|
||||
qCWarning(dcNetworkManager()) << "NetworkDevice: System DBus not connected";
|
||||
return;
|
||||
}
|
||||
|
||||
m_networkDeviceInterface = new QDBusInterface(serviceString, m_objectPath.path(), deviceInterfaceString, QDBusConnection::systemBus(), this);
|
||||
if(!m_networkDeviceInterface->isValid()) {
|
||||
qCWarning(dcNetworkManager()) << "NetworkDevice: Invalid DBus device interface" << m_objectPath.path();
|
||||
return;
|
||||
}
|
||||
|
||||
m_udi = m_networkDeviceInterface->property("Udi").toString();
|
||||
m_interface = m_networkDeviceInterface->property("Interface").toString();
|
||||
m_ipInterface = m_networkDeviceInterface->property("IpInterface").toString();
|
||||
m_driver = m_networkDeviceInterface->property("Driver").toString();
|
||||
m_driverVersion = m_networkDeviceInterface->property("DriverVersion").toString();
|
||||
m_firmwareVersion = m_networkDeviceInterface->property("FirmwareVersion").toString();
|
||||
m_physicalPortId = m_networkDeviceInterface->property("PhysicalPortId").toString();
|
||||
m_mtu = m_networkDeviceInterface->property("Mtu").toUInt();
|
||||
m_metered = m_networkDeviceInterface->property("Metered").toUInt();
|
||||
m_autoconnect = m_networkDeviceInterface->property("Autoconnect").toBool();
|
||||
|
||||
m_deviceState = NetworkDeviceState(m_networkDeviceInterface->property("State").toUInt());
|
||||
m_deviceType = NetworkDeviceType(m_networkDeviceInterface->property("DeviceType").toUInt());
|
||||
|
||||
m_activeConnection = qdbus_cast<QDBusObjectPath>(m_networkDeviceInterface->property("ActiveConnection"));
|
||||
m_ip4Config = qdbus_cast<QDBusObjectPath>(m_networkDeviceInterface->property("Ip4Config"));
|
||||
m_ip6Config = qdbus_cast<QDBusObjectPath>(m_networkDeviceInterface->property("Ip6Config"));
|
||||
|
||||
QDBusConnection::systemBus().connect(serviceString, m_objectPath.path(), deviceInterfaceString, "StateChanged", this, SLOT(onStateChanged(uint,uint,uint)));
|
||||
}
|
||||
|
||||
/*! Returns the dbus object path of this \l{NetworkDevice}. */
|
||||
QDBusObjectPath NetworkDevice::objectPath() const
|
||||
{
|
||||
return m_objectPath;
|
||||
}
|
||||
|
||||
/*! Returns the udi of this \l{NetworkDevice}. */
|
||||
QString NetworkDevice::udi() const
|
||||
{
|
||||
return m_udi;
|
||||
}
|
||||
|
||||
/*! Returns the interface name of this \l{NetworkDevice}. */
|
||||
QString NetworkDevice::interface() const
|
||||
{
|
||||
return m_interface;
|
||||
}
|
||||
|
||||
/*! Returns the ip interface of this \l{NetworkDevice}. */
|
||||
QString NetworkDevice::ipInterface() const
|
||||
{
|
||||
return m_ipInterface;
|
||||
}
|
||||
|
||||
/*! Returns the used driver name for this \l{NetworkDevice}. */
|
||||
QString NetworkDevice::driver() const
|
||||
{
|
||||
return m_driver;
|
||||
}
|
||||
|
||||
/*! Returns the version of the used driver for this \l{NetworkDevice}. */
|
||||
QString NetworkDevice::driverVersion() const
|
||||
{
|
||||
return m_driverVersion;
|
||||
}
|
||||
|
||||
/*! Returns the firmware version of this \l{NetworkDevice}. */
|
||||
QString NetworkDevice::firmwareVersion() const
|
||||
{
|
||||
return m_firmwareVersion;
|
||||
}
|
||||
|
||||
/*! Returns the physical port id of this \l{NetworkDevice}. */
|
||||
QString NetworkDevice::physicalPortId() const
|
||||
{
|
||||
return m_physicalPortId;
|
||||
}
|
||||
|
||||
/*! Returns the mtu of this \l{NetworkDevice}. */
|
||||
uint NetworkDevice::mtu() const
|
||||
{
|
||||
return m_mtu;
|
||||
}
|
||||
|
||||
/*! Returns the metered property of this \l{NetworkDevice}. */
|
||||
uint NetworkDevice::metered() const
|
||||
{
|
||||
return m_metered;
|
||||
}
|
||||
|
||||
/*! Returns true if autoconnect is enabled for this \l{NetworkDevice}. */
|
||||
bool NetworkDevice::autoconnect() const
|
||||
{
|
||||
return m_autoconnect;
|
||||
}
|
||||
|
||||
/*! Returns the device state of this \l{NetworkDevice}. \sa NetworkDeviceState, */
|
||||
NetworkDevice::NetworkDeviceState NetworkDevice::deviceState() const
|
||||
{
|
||||
return m_deviceState;
|
||||
}
|
||||
|
||||
/*! Returns the human readable device state of this \l{NetworkDevice}. \sa NetworkDeviceState, */
|
||||
QString NetworkDevice::deviceStateString() const
|
||||
{
|
||||
return NetworkDevice::deviceStateToString(m_deviceState);
|
||||
}
|
||||
|
||||
/*! Returns the reason for the current state of this \l{NetworkDevice}. \sa NetworkDeviceStateReason, */
|
||||
NetworkDevice::NetworkDeviceStateReason NetworkDevice::deviceStateReason() const
|
||||
{
|
||||
return m_deviceStateReason;
|
||||
}
|
||||
|
||||
/*! Returns the device type of this \l{NetworkDevice}. \sa NetworkDeviceType, */
|
||||
NetworkDevice::NetworkDeviceType NetworkDevice::deviceType() const
|
||||
{
|
||||
return m_deviceType;
|
||||
}
|
||||
|
||||
/*! Returns the dbus object path of the currently active connection of this \l{NetworkDevice}. */
|
||||
QDBusObjectPath NetworkDevice::activeConnection() const
|
||||
{
|
||||
return m_activeConnection;
|
||||
}
|
||||
|
||||
/*! Returns the dbus object path from the IPv4 configuration of this \l{NetworkDevice}. */
|
||||
QDBusObjectPath NetworkDevice::ip4Config() const
|
||||
{
|
||||
return m_ip4Config;
|
||||
}
|
||||
|
||||
/*! Returns the list of dbus object paths for the currently available connection of this \l{NetworkDevice}. */
|
||||
QList<QDBusObjectPath> NetworkDevice::availableConnections() const
|
||||
{
|
||||
return m_availableConnections;
|
||||
}
|
||||
|
||||
/*! Disconnect the current connection from this \l{NetworkDevice}. */
|
||||
void NetworkDevice::disconnectDevice()
|
||||
{
|
||||
QDBusMessage query = m_networkDeviceInterface->call("Disconnect");
|
||||
if(query.type() != QDBusMessage::ReplyMessage)
|
||||
qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage();
|
||||
|
||||
}
|
||||
|
||||
/*! Returns the human readable device type string of the given \a deviceType. \sa NetworkDeviceType, */
|
||||
QString NetworkDevice::deviceTypeToString(const NetworkDevice::NetworkDeviceType &deviceType)
|
||||
{
|
||||
QMetaObject metaObject = NetworkDevice::staticMetaObject;
|
||||
int enumIndex = metaObject.indexOfEnumerator(QString("NetworkDeviceType").toLatin1().data());
|
||||
QMetaEnum metaEnum = metaObject.enumerator(enumIndex);
|
||||
return QString(metaEnum.valueToKey(deviceType)).remove("NetworkDeviceType");
|
||||
}
|
||||
|
||||
/*! Returns the human readable device state string of the given \a deviceState. \sa NetworkDeviceState, */
|
||||
QString NetworkDevice::deviceStateToString(const NetworkDevice::NetworkDeviceState &deviceState)
|
||||
{
|
||||
QMetaObject metaObject = NetworkDevice::staticMetaObject;
|
||||
int enumIndex = metaObject.indexOfEnumerator(QString("NetworkDeviceState").toLatin1().data());
|
||||
QMetaEnum metaEnum = metaObject.enumerator(enumIndex);
|
||||
return QString(metaEnum.valueToKey(deviceState));
|
||||
}
|
||||
|
||||
/*! Returns the human readable device state reason string of the given \a deviceStateReason. \sa NetworkDeviceStateReason, */
|
||||
QString NetworkDevice::deviceStateReasonToString(const NetworkDevice::NetworkDeviceStateReason &deviceStateReason)
|
||||
{
|
||||
QMetaObject metaObject = NetworkDevice::staticMetaObject;
|
||||
int enumIndex = metaObject.indexOfEnumerator(QString("NetworkDeviceStateReason").toLatin1().data());
|
||||
QMetaEnum metaEnum = metaObject.enumerator(enumIndex);
|
||||
return QString(metaEnum.valueToKey(deviceStateReason));
|
||||
}
|
||||
|
||||
void NetworkDevice::onStateChanged(uint newState, uint oldState, uint reason)
|
||||
{
|
||||
Q_UNUSED(oldState)
|
||||
qCDebug(dcNetworkManager()) << m_interface << "--> State changed:" << deviceStateToString(NetworkDeviceState(newState)) << ":" << deviceStateReasonToString(NetworkDeviceStateReason(reason));
|
||||
if (m_deviceState != NetworkDeviceState(newState)) {
|
||||
m_deviceState = NetworkDeviceState(newState);
|
||||
emit deviceChanged();
|
||||
}
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, NetworkDevice *device)
|
||||
{
|
||||
debug.nospace() << "NetworkDevice(" << device->interface() << " - " << NetworkDevice::deviceTypeToString(device->deviceType()) << ", " << device->deviceStateString() << ")";
|
||||
return debug;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,230 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef NETWORKDEVICE_H
|
||||
#define NETWORKDEVICE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusContext>
|
||||
#include <QDBusArgument>
|
||||
|
||||
#include "dbus-interfaces.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class NetworkDevice : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum NetworkDeviceState {
|
||||
NetworkDeviceStateUnknown = 0,
|
||||
NetworkDeviceStateUnmanaged = 10,
|
||||
NetworkDeviceStateUnavailable = 20,
|
||||
NetworkDeviceStateDisconnected = 30,
|
||||
NetworkDeviceStatePrepare = 40,
|
||||
NetworkDeviceStateConfig = 50,
|
||||
NetworkDeviceStateNeedAuth = 60,
|
||||
NetworkDeviceStateIpConfig = 70,
|
||||
NetworkDeviceStateIpCheck = 80,
|
||||
NetworkDeviceStateSecondaries = 90,
|
||||
NetworkDeviceStateActivated = 100,
|
||||
NetworkDeviceStateDeactivating = 110,
|
||||
NetworkDeviceStateFailed = 120
|
||||
};
|
||||
Q_ENUM(NetworkDeviceState)
|
||||
|
||||
enum NetworkDeviceStateReason {
|
||||
NetworkDeviceStateReasonNone = 0,
|
||||
NetworkDeviceStateReasonUnknown = 1,
|
||||
NetworkDeviceStateReasonNowManaged = 2,
|
||||
NetworkDeviceStateReasonNowUnmanaged = 3,
|
||||
NetworkDeviceStateReasonConfigFailed = 4,
|
||||
NetworkDeviceStateReasonIpConfigUnavailable = 5,
|
||||
NetworkDeviceStateReasonIpConfigExpired = 6,
|
||||
NetworkDeviceStateReasonNoSecrets = 7,
|
||||
NetworkDeviceStateReasonSupplicantDisconnected = 8,
|
||||
NetworkDeviceStateReasonSupplicantConfigFailed = 9,
|
||||
NetworkDeviceStateReasonSupplicantFailed = 10,
|
||||
NetworkDeviceStateReasonSupplicantTimeout = 11,
|
||||
NetworkDeviceStateReasonPppStartFailed = 12,
|
||||
NetworkDeviceStateReasonPppDisconnected = 13,
|
||||
NetworkDeviceStateReasonPppFailed = 14,
|
||||
NetworkDeviceStateReasonDhcpStartFailed = 15,
|
||||
NetworkDeviceStateReasonDhcpError = 16,
|
||||
NetworkDeviceStateReasonDhcpFailed = 17,
|
||||
NetworkDeviceStateReasonSharedStartFailed = 18,
|
||||
NetworkDeviceStateReasonSharedFailed = 19,
|
||||
NetworkDeviceStateReasonAutoIpStartFailed = 20,
|
||||
NetworkDeviceStateReasonAutoIpError = 21,
|
||||
NetworkDeviceStateReasonAutoIpFailed = 22,
|
||||
NetworkDeviceStateReasonModemBusy = 23,
|
||||
NetworkDeviceStateReasonModemNoDialTone = 24,
|
||||
NetworkDeviceStateReasonModemNoCarrier = 25,
|
||||
NetworkDeviceStateReasonModemDialTimeout = 26,
|
||||
NetworkDeviceStateReasonModemDialFailed = 27,
|
||||
NetworkDeviceStateReasonModemInitFailed = 28,
|
||||
NetworkDeviceStateReasonGsmApnFailed = 29,
|
||||
NetworkDeviceStateReasonGsmRegistrationNotSearching = 30,
|
||||
NetworkDeviceStateReasonGsmRegistrationDenied = 31,
|
||||
NetworkDeviceStateReasonGsmRegistrationTimeout = 32,
|
||||
NetworkDeviceStateReasonGsmRegistrationFailed = 33,
|
||||
NetworkDeviceStateReasonGsmPinCheckFailed = 34,
|
||||
NetworkDeviceStateReasonFirmwareMissing = 35,
|
||||
NetworkDeviceStateReasonRemoved = 36,
|
||||
NetworkDeviceStateReasonSleeping = 37,
|
||||
NetworkDeviceStateReasonConnectionRemoved = 38,
|
||||
NetworkDeviceStateReasonUserRequest = 39,
|
||||
NetworkDeviceStateReasonCarrier = 40,
|
||||
NetworkDeviceStateReasonConnectionAssumed = 41,
|
||||
NetworkDeviceStateReasonSupplicantAvailable = 42,
|
||||
NetworkDeviceStateReasonModemNotFound = 43,
|
||||
NetworkDeviceStateReasonBtFailed = 44,
|
||||
NetworkDeviceStateReasonGsmSimNotInserted = 45,
|
||||
NetworkDeviceStateReasonGsmSimPinRequired = 46,
|
||||
NetworkDeviceStateReasonGsmSimPukRequired = 47,
|
||||
NetworkDeviceStateReasonGsmSimWrong = 48,
|
||||
NetworkDeviceStateReasonInfinibandMode = 49,
|
||||
NetworkDeviceStateReasonDependencyFailed = 50,
|
||||
NetworkDeviceStateReasonBR2684Failed = 51,
|
||||
NetworkDeviceStateReasonModemManagerUnavailable = 52,
|
||||
NetworkDeviceStateReasonSsidNotFound = 53,
|
||||
NetworkDeviceStateReasonSecondaryConnectionFailed = 54,
|
||||
NetworkDeviceStateReasonDcbFoecFailed = 55,
|
||||
NetworkDeviceStateReasonTeamdControlFailed = 56,
|
||||
NetworkDeviceStateReasonModemFailed = 57,
|
||||
NetworkDeviceStateReasonModemAvailable = 58,
|
||||
NetworkDeviceStateReasonSimPinIncorrect = 59,
|
||||
NetworkDeviceStateReasonNewActivision = 60,
|
||||
NetworkDeviceStateReasonParentChanged = 61,
|
||||
NetworkDeviceStateReasonParentManagedChanged = 62
|
||||
};
|
||||
Q_ENUM(NetworkDeviceStateReason)
|
||||
|
||||
enum NetworkDeviceType {
|
||||
NetworkDeviceTypeUnknown = 0,
|
||||
NetworkDeviceTypeEthernet = 1,
|
||||
NetworkDeviceTypeWifi = 2,
|
||||
NetworkDeviceTypeBluetooth = 5,
|
||||
NetworkDeviceTypeOlpcMesh = 6,
|
||||
NetworkDeviceTypeWiMax = 7,
|
||||
NetworkDeviceTypeModem = 8,
|
||||
NetworkDeviceTypeInfiniBand = 9,
|
||||
NetworkDeviceTypeBond = 10,
|
||||
NetworkDeviceTypeVLan = 11,
|
||||
NetworkDeviceTypeAdsl = 12,
|
||||
NetworkDeviceTypeBridge = 13,
|
||||
NetworkDeviceTypeGeneric = 14,
|
||||
NetworkDeviceTypeTeam = 15,
|
||||
NetworkDeviceTypeTun = 16,
|
||||
NetworkDeviceTypeIpTunnel = 17,
|
||||
NetworkDeviceTypeMacVLan = 18,
|
||||
NetworkDeviceTypeVXLan = 19,
|
||||
NetworkDeviceTypeVEth = 20,
|
||||
};
|
||||
Q_ENUM(NetworkDeviceType)
|
||||
|
||||
explicit NetworkDevice(const QDBusObjectPath &objectPath, QObject *parent = nullptr);
|
||||
|
||||
QDBusObjectPath objectPath() const;
|
||||
|
||||
QString udi() const;
|
||||
QString interface() const;
|
||||
QString ipInterface() const;
|
||||
QString driver() const;
|
||||
QString driverVersion() const;
|
||||
QString firmwareVersion() const;
|
||||
QString physicalPortId() const;
|
||||
uint mtu() const;
|
||||
uint metered() const;
|
||||
bool autoconnect() const;
|
||||
|
||||
NetworkDeviceState deviceState() const;
|
||||
QString deviceStateString() const;
|
||||
|
||||
NetworkDeviceStateReason deviceStateReason() const;
|
||||
NetworkDeviceType deviceType() const;
|
||||
|
||||
QDBusObjectPath activeConnection() const;
|
||||
QDBusObjectPath ip4Config() const;
|
||||
QList<QDBusObjectPath> availableConnections() const;
|
||||
|
||||
// Method
|
||||
void disconnectDevice();
|
||||
|
||||
static QString deviceTypeToString(const NetworkDeviceType &deviceType);
|
||||
static QString deviceStateToString(const NetworkDeviceState &deviceState);
|
||||
static QString deviceStateReasonToString(const NetworkDeviceStateReason &deviceStateReason);
|
||||
|
||||
private:
|
||||
QDBusInterface *m_networkDeviceInterface;
|
||||
QDBusObjectPath m_objectPath;
|
||||
|
||||
// Device properties
|
||||
QString m_udi;
|
||||
QString m_interface;
|
||||
QString m_ipInterface;
|
||||
QString m_driver;
|
||||
QString m_driverVersion;
|
||||
QString m_firmwareVersion;
|
||||
QString m_physicalPortId;
|
||||
uint m_mtu;
|
||||
uint m_metered;
|
||||
bool m_autoconnect;
|
||||
NetworkDeviceState m_deviceState;
|
||||
NetworkDeviceStateReason m_deviceStateReason;
|
||||
NetworkDeviceType m_deviceType;
|
||||
|
||||
QDBusObjectPath m_activeConnection;
|
||||
QDBusObjectPath m_ip4Config;
|
||||
QDBusObjectPath m_ip6Config;
|
||||
|
||||
QList<QDBusObjectPath> m_availableConnections;
|
||||
|
||||
private slots:
|
||||
void onStateChanged(uint newState, uint oldState, uint reason);
|
||||
|
||||
signals:
|
||||
void deviceChanged();
|
||||
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug debug, NetworkDevice *device);
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(nymeaserver::NetworkDevice::NetworkDeviceType)
|
||||
Q_DECLARE_METATYPE(nymeaserver::NetworkDevice::NetworkDeviceState)
|
||||
Q_DECLARE_METATYPE(nymeaserver::NetworkDevice::NetworkDeviceStateReason)
|
||||
|
||||
#endif // NETWORKDEVICE_H
|
||||
|
|
@ -1,522 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*!
|
||||
\class nymeaserver::NetworkManager
|
||||
\brief Represents the dbus network-manager.
|
||||
|
||||
\ingroup networkmanager
|
||||
\inmodule core
|
||||
*/
|
||||
|
||||
/*! \fn void NetworkManager::versionChanged();
|
||||
This signal will be emitted when the version of this \l{WiredNetworkDevice} has changed.
|
||||
*/
|
||||
|
||||
/*! \fn void NetworkManager::networkingEnabledChanged();
|
||||
This signal will be emitted when the networking of this \l{WiredNetworkDevice} has changed. \sa networkingEnabled()
|
||||
*/
|
||||
|
||||
/*! \fn void NetworkManager::wirelessEnabledChanged();
|
||||
This signal will be emitted when the wireless networking of this \l{WiredNetworkDevice} has changed. \sa wirelessEnabled()
|
||||
*/
|
||||
|
||||
/*! \fn void NetworkManager::stateChanged();
|
||||
This signal will be emitted when the state of this \l{WiredNetworkDevice} has changed. \sa NetworkManagerState
|
||||
*/
|
||||
|
||||
/*! \fn void NetworkManager::connectivityStateChanged();
|
||||
This signal will be emitted when the connectivity state of this \l{WiredNetworkDevice} has changed. \sa NetworkManagerConnectivityState
|
||||
*/
|
||||
|
||||
/*! \fn void NetworkManager::wirelessDeviceAdded(WirelessNetworkDevice *wirelessDevice);
|
||||
This signal will be emitted when a new \a wirelessDevice was added to this \l{NetworkManager}. \sa WirelessNetworkDevice
|
||||
*/
|
||||
|
||||
/*! \fn void NetworkManager::wirelessDeviceRemoved(const QString &interface);
|
||||
This signal will be emitted when the \l{WirelessNetworkDevice} with the given \a interface was removed from this \l{NetworkManager}. \sa WirelessNetworkDevice
|
||||
*/
|
||||
|
||||
/*! \fn void NetworkManager::wirelessDeviceChanged(WirelessNetworkDevice *wirelessDevice);
|
||||
This signal will be emitted when the given \a wirelessDevice has changed. \sa WirelessNetworkDevice
|
||||
*/
|
||||
|
||||
/*! \fn void NetworkManager::wiredDeviceAdded(WiredNetworkDevice *wiredDevice);
|
||||
This signal will be emitted when a new \a wiredDevice was added to this \l{NetworkManager}. \sa WiredNetworkDevice
|
||||
*/
|
||||
|
||||
/*! \fn void NetworkManager::wiredDeviceRemoved(const QString &interface);
|
||||
This signal will be emitted when the \l{WiredNetworkDevice} with the given \a interface was removed from this \l{NetworkManager}. \sa WiredNetworkDevice
|
||||
*/
|
||||
|
||||
/*! \fn void NetworkManager::wiredDeviceChanged(WiredNetworkDevice *wiredDevice);
|
||||
This signal will be emitted when the given \a wiredDevice has changed. \sa WiredNetworkDevice
|
||||
*/
|
||||
|
||||
/*! \enum nymeaserver::NetworkManager::NetworkManagerState
|
||||
\value NetworkManagerStateUnknown
|
||||
\value NetworkManagerStateAsleep
|
||||
\value NetworkManagerStateDisconnected
|
||||
\value NetworkManagerStateDisconnecting
|
||||
\value NetworkManagerStateConnecting
|
||||
\value NetworkManagerStateConnectedLocal
|
||||
\value NetworkManagerStateConnectedSite
|
||||
\value NetworkManagerStateConnectedGlobal
|
||||
*/
|
||||
|
||||
/*! \enum nymeaserver::NetworkManager::NetworkManagerConnectivityState
|
||||
\value NetworkManagerConnectivityStateUnknown
|
||||
\value NetworkManagerConnectivityStateNone
|
||||
\value NetworkManagerConnectivityStatePortal
|
||||
\value NetworkManagerConnectivityStateLimited
|
||||
\value NetworkManagerConnectivityStateFull
|
||||
*/
|
||||
|
||||
/*! \enum nymeaserver::NetworkManager::NetworkManagerError
|
||||
\value NetworkManagerErrorNoError
|
||||
\value NetworkManagerErrorUnknownError
|
||||
\value NetworkManagerErrorWirelessNotAvailable
|
||||
\value NetworkManagerErrorAccessPointNotFound
|
||||
\value NetworkManagerErrorNetworkInterfaceNotFound
|
||||
\value NetworkManagerErrorInvalidNetworkDeviceType
|
||||
\value NetworkManagerErrorWirelessNetworkingDisabled
|
||||
\value NetworkManagerErrorWirelessConnectionFailed
|
||||
\value NetworkManagerErrorNetworkingDisabled
|
||||
\value NetworkManagerErrorNetworkManagerNotAvailable
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "networkmanager.h"
|
||||
#include "loggingcategories.h"
|
||||
#include "networkconnection.h"
|
||||
|
||||
#include <QMetaEnum>
|
||||
#include <QUuid>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
/*! Constructs a new \l{NetworkManager} object with the given \a parent. */
|
||||
NetworkManager::NetworkManager(QObject *parent) :
|
||||
QObject(parent),
|
||||
m_networkManagerInterface(0),
|
||||
m_available(false),
|
||||
m_wifiAvailable(false),
|
||||
m_state(NetworkManagerStateUnknown),
|
||||
m_connectivityState(NetworkManagerConnectivityStateUnknown),
|
||||
m_networkingEnabled(false),
|
||||
m_wirelessEnabled(false)
|
||||
{
|
||||
// Check DBus connection
|
||||
if (!QDBusConnection::systemBus().isConnected()) {
|
||||
qCWarning(dcNetworkManager()) << "System DBus not connected. NetworkManagre not available.";
|
||||
return;
|
||||
}
|
||||
|
||||
// Create interface
|
||||
m_networkManagerInterface = new QDBusInterface(serviceString, pathString, serviceString, QDBusConnection::systemBus(), this);
|
||||
if(!m_networkManagerInterface->isValid()) {
|
||||
qCWarning(dcNetworkManager()) << "Invalid DBus network manager interface. NetworkManagre not available.";
|
||||
return;
|
||||
}
|
||||
|
||||
m_available = true;
|
||||
|
||||
// Read properties
|
||||
setVersion(m_networkManagerInterface->property("Version").toString());
|
||||
setState((NetworkManagerState)m_networkManagerInterface->property("State").toUInt());
|
||||
setConnectivityState((NetworkManagerConnectivityState)m_networkManagerInterface->property("Connectivity").toUInt());
|
||||
setNetworkingEnabled(m_networkManagerInterface->property("NetworkingEnabled").toBool());
|
||||
setWirelessEnabled(m_networkManagerInterface->property("WirelessEnabled").toBool());
|
||||
|
||||
loadDevices();
|
||||
|
||||
// Connect signals
|
||||
QDBusConnection::systemBus().connect(serviceString, pathString, serviceString, "StateChanged", this, SLOT(onStateChanged(uint)));
|
||||
QDBusConnection::systemBus().connect(serviceString, pathString, serviceString, "DeviceAdded", this, SLOT(onDeviceAdded(QDBusObjectPath)));
|
||||
QDBusConnection::systemBus().connect(serviceString, pathString, serviceString, "DeviceRemoved", this, SLOT(onDeviceRemoved(QDBusObjectPath)));
|
||||
QDBusConnection::systemBus().connect(serviceString, pathString, serviceString, "PropertiesChanged", this, SLOT(onPropertiesChanged(QVariantMap)));
|
||||
|
||||
// Create settings
|
||||
m_networkSettings = new NetworkSettings(this);
|
||||
}
|
||||
|
||||
/*! Returns true if the network-manager is available on this system. */
|
||||
bool NetworkManager::available()
|
||||
{
|
||||
return m_available;
|
||||
}
|
||||
|
||||
/*! Returns true if wifi is available on this system. */
|
||||
bool NetworkManager::wifiAvailable()
|
||||
{
|
||||
return m_wifiAvailable;
|
||||
}
|
||||
|
||||
/*! Returns the list of \l{NetworkDevice}{NetworkDevices} from this \l{NetworkManager}. */
|
||||
QList<NetworkDevice *> NetworkManager::networkDevices() const
|
||||
{
|
||||
return m_networkDevices.values();
|
||||
}
|
||||
|
||||
/*! Returns the list of \l{WirelessNetworkDevice}{WirelessNetworkDevices} from this \l{NetworkManager}. */
|
||||
QList<WirelessNetworkDevice *> NetworkManager::wirelessNetworkDevices() const
|
||||
{
|
||||
return m_wirelessNetworkDevices.values();
|
||||
}
|
||||
|
||||
/*! Returns the list of \l{WiredNetworkDevice}{WiredNetworkDevices} from this \l{NetworkManager}. */
|
||||
QList<WiredNetworkDevice *> NetworkManager::wiredNetworkDevices() const
|
||||
{
|
||||
return m_wiredNetworkDevices.values();
|
||||
}
|
||||
|
||||
/*! Returns the \l{NetworkDevice} with the given \a interface from this \l{NetworkManager}. If there is no such \a interface returns Q_NULLPTR. */
|
||||
NetworkDevice *NetworkManager::getNetworkDevice(const QString &interface)
|
||||
{
|
||||
foreach (NetworkDevice *device, m_networkDevices.values()) {
|
||||
if (device->interface() == interface)
|
||||
return device;
|
||||
}
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
|
||||
/*! Returns the version of the running \l{NetworkManager}. */
|
||||
QString NetworkManager::version() const
|
||||
{
|
||||
return m_version;
|
||||
}
|
||||
|
||||
/*! Returns the state of this \l{NetworkManager}. \sa NetworkManagerState, */
|
||||
NetworkManager::NetworkManagerState NetworkManager::state() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
/*! Returns the human readable string of the current state of this \l{NetworkManager}. \sa NetworkManagerState, */
|
||||
QString NetworkManager::stateString() const
|
||||
{
|
||||
return networkManagerStateToString(m_state);
|
||||
}
|
||||
|
||||
/*! Returns the current connectivity state of this \l{NetworkManager}. \sa NetworkManagerConnectivityState, */
|
||||
NetworkManager::NetworkManagerConnectivityState NetworkManager::connectivityState() const
|
||||
{
|
||||
return m_connectivityState;
|
||||
}
|
||||
|
||||
/*! Connect the given \a interface to a wifi network with the given \a ssid and \a password. Returns the \l{NetworkManagerError} to inform about the result. \sa NetworkManagerError, */
|
||||
NetworkManager::NetworkManagerError NetworkManager::connectWifi(const QString &interface, const QString &ssid, const QString &password)
|
||||
{
|
||||
// Check interface
|
||||
if (!getNetworkDevice(interface))
|
||||
return NetworkManagerErrorNetworkInterfaceNotFound;
|
||||
|
||||
// Get wirelessNetworkDevice
|
||||
WirelessNetworkDevice *wirelessNetworkDevice = 0;
|
||||
foreach (WirelessNetworkDevice *networkDevice, wirelessNetworkDevices()) {
|
||||
if (networkDevice->interface() == interface)
|
||||
wirelessNetworkDevice = networkDevice;
|
||||
}
|
||||
|
||||
if (!wirelessNetworkDevice)
|
||||
return NetworkManagerErrorInvalidNetworkDeviceType;
|
||||
|
||||
// Get the access point object path
|
||||
WirelessAccessPoint *accessPoint = wirelessNetworkDevice->getAccessPoint(ssid);
|
||||
if (!accessPoint)
|
||||
return NetworkManagerErrorAccessPointNotFound;
|
||||
|
||||
// https://developer.gnome.org/NetworkManager/stable/ref-settings.html
|
||||
|
||||
QVariantMap connectionSettings;
|
||||
connectionSettings.insert("autoconnect", true);
|
||||
connectionSettings.insert("id", ssid + " (nymea)");
|
||||
connectionSettings.insert("type", "802-11-wireless");
|
||||
|
||||
QVariantMap wirelessSettings;
|
||||
wirelessSettings.insert("ssid", ssid.toUtf8());
|
||||
wirelessSettings.insert("mode", "infrastructure");
|
||||
wirelessSettings.insert("security", "802-11-wireless-security");
|
||||
|
||||
QVariantMap wirelessSecuritySettings;
|
||||
wirelessSecuritySettings.insert("auth-alg", "open");
|
||||
wirelessSecuritySettings.insert("key-mgmt", "wpa-psk");
|
||||
wirelessSecuritySettings.insert("psk", password);
|
||||
|
||||
QVariantMap ipv4Settings;
|
||||
ipv4Settings.insert("method", "auto");
|
||||
|
||||
QVariantMap ipv6Settings;
|
||||
ipv6Settings.insert("method", "auto");
|
||||
|
||||
// Build connection object
|
||||
ConnectionSettings settings;
|
||||
settings.insert("connection", connectionSettings);
|
||||
settings.insert("802-11-wireless", wirelessSettings);
|
||||
settings.insert("ipv4", ipv4Settings);
|
||||
settings.insert("ipv6", ipv6Settings);
|
||||
settings.insert("802-11-wireless-security", wirelessSecuritySettings);
|
||||
|
||||
// Remove old configuration (if there is any)
|
||||
foreach (NetworkConnection *connection, m_networkSettings->connections()) {
|
||||
if (connection->id() == connectionSettings.value("id")) {
|
||||
connection->deleteConnection();
|
||||
}
|
||||
}
|
||||
|
||||
// Add connection
|
||||
QDBusObjectPath connectionObjectPath = m_networkSettings->addConnection(settings);
|
||||
if (connectionObjectPath.path().isEmpty())
|
||||
return NetworkManagerErrorWirelessConnectionFailed;
|
||||
|
||||
// Activate connection
|
||||
QDBusMessage query = m_networkManagerInterface->call("ActivateConnection", QVariant::fromValue(connectionObjectPath), QVariant::fromValue(wirelessNetworkDevice->objectPath()), QVariant::fromValue(accessPoint->objectPath()));
|
||||
if(query.type() != QDBusMessage::ReplyMessage) {
|
||||
qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage();
|
||||
return NetworkManagerErrorWirelessConnectionFailed;
|
||||
}
|
||||
|
||||
return NetworkManagerErrorNoError;
|
||||
}
|
||||
|
||||
/*! Returns true if the networking of this \l{NetworkManager} is enabled. */
|
||||
bool NetworkManager::networkingEnabled() const
|
||||
{
|
||||
return m_networkingEnabled;
|
||||
}
|
||||
|
||||
/*! Returns true if the networking of this \l{NetworkManager} could be \a enabled. */
|
||||
bool NetworkManager::enableNetworking(const bool &enabled)
|
||||
{
|
||||
if (m_networkingEnabled == enabled)
|
||||
return true;
|
||||
|
||||
QDBusMessage query = m_networkManagerInterface->call("Enable", enabled);
|
||||
if(query.type() != QDBusMessage::ReplyMessage) {
|
||||
qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/*! Sets the networking of this \l{NetworkManager} to \a enabled. */
|
||||
void NetworkManager::setNetworkingEnabled(const bool &enabled)
|
||||
{
|
||||
qCDebug(dcNetworkManager()) << "Networking" << (enabled ? "enabled" : "disabled");
|
||||
m_networkingEnabled = enabled;
|
||||
emit networkingEnabledChanged();
|
||||
}
|
||||
|
||||
/*! Returns true if the wireless networking of this \l{NetworkManager} is enabled. */
|
||||
bool NetworkManager::wirelessEnabled() const
|
||||
{
|
||||
return m_wirelessEnabled;
|
||||
}
|
||||
|
||||
/*! Returns true if the wireless networking of this \l{NetworkManager} could be set to \a enabled. */
|
||||
bool NetworkManager::enableWireless(const bool &enabled)
|
||||
{
|
||||
if (m_wirelessEnabled == enabled)
|
||||
return true;
|
||||
|
||||
return m_networkManagerInterface->setProperty("WirelessEnabled", enabled);
|
||||
}
|
||||
|
||||
void NetworkManager::loadDevices()
|
||||
{
|
||||
// Get network devices
|
||||
QDBusMessage query = m_networkManagerInterface->call("GetDevices");
|
||||
if(query.type() != QDBusMessage::ReplyMessage) {
|
||||
qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if (query.arguments().isEmpty())
|
||||
return;
|
||||
|
||||
const QDBusArgument &argument = query.arguments().at(0).value<QDBusArgument>();
|
||||
argument.beginArray();
|
||||
while(!argument.atEnd()) {
|
||||
QDBusObjectPath deviceObjectPath = qdbus_cast<QDBusObjectPath>(argument);
|
||||
onDeviceAdded(deviceObjectPath);
|
||||
}
|
||||
argument.endArray();
|
||||
}
|
||||
|
||||
QString NetworkManager::networkManagerStateToString(const NetworkManager::NetworkManagerState &state)
|
||||
{
|
||||
QMetaObject metaObject = NetworkManager::staticMetaObject;
|
||||
int enumIndex = metaObject.indexOfEnumerator(QString("NetworkManagerState").toLatin1().data());
|
||||
QMetaEnum metaEnum = metaObject.enumerator(enumIndex);
|
||||
return QString(metaEnum.valueToKey(state));
|
||||
}
|
||||
|
||||
QString NetworkManager::networkManagerConnectivityStateToString(const NetworkManager::NetworkManagerConnectivityState &state)
|
||||
{
|
||||
QMetaObject metaObject = NetworkManager::staticMetaObject;
|
||||
int enumIndex = metaObject.indexOfEnumerator(QString("NetworkManagerConnectivityState").toLatin1().data());
|
||||
QMetaEnum metaEnum = metaObject.enumerator(enumIndex);
|
||||
return QString(metaEnum.valueToKey(state)).remove("NetworkManagerConnectivityState");
|
||||
}
|
||||
|
||||
void NetworkManager::setVersion(const QString &version)
|
||||
{
|
||||
qCDebug(dcNetworkManager()) << "Version:" << version;
|
||||
m_version = version;
|
||||
emit versionChanged();
|
||||
}
|
||||
|
||||
void NetworkManager::setWirelessEnabled(const bool &enabled)
|
||||
{
|
||||
qCDebug(dcNetworkManager()) << "Wireless networking" << (enabled ? "enabled" : "disabled");
|
||||
m_wirelessEnabled = enabled;
|
||||
emit wirelessEnabledChanged();
|
||||
}
|
||||
|
||||
void NetworkManager::setConnectivityState(const NetworkManager::NetworkManagerConnectivityState &connectivityState)
|
||||
{
|
||||
qCDebug(dcNetworkManager()) << "Connectivity state changed:" << networkManagerConnectivityStateToString(connectivityState);
|
||||
m_connectivityState = connectivityState;
|
||||
emit connectivityStateChanged();
|
||||
}
|
||||
|
||||
void NetworkManager::setState(const NetworkManager::NetworkManagerState &state)
|
||||
{
|
||||
qCDebug(dcNetworkManager()) << "State changed:" << networkManagerStateToString(state);
|
||||
m_state = state;
|
||||
emit stateChanged();
|
||||
}
|
||||
|
||||
void NetworkManager::onDeviceAdded(const QDBusObjectPath &deviceObjectPath)
|
||||
{
|
||||
if (m_networkDevices.keys().contains(deviceObjectPath)) {
|
||||
qCWarning(dcNetworkManager()) << "Device" << deviceObjectPath.path() << "already added.";
|
||||
return;
|
||||
}
|
||||
|
||||
// Get device Type
|
||||
QDBusInterface networkDeviceInterface(serviceString, deviceObjectPath.path(), deviceInterfaceString, QDBusConnection::systemBus());
|
||||
if(!networkDeviceInterface.isValid()) {
|
||||
qCWarning(dcNetworkManager()) << "NetworkDevice: Invalid DBus device interface" << deviceObjectPath.path();
|
||||
return;
|
||||
}
|
||||
|
||||
// Create object
|
||||
NetworkDevice::NetworkDeviceType deviceType = NetworkDevice::NetworkDeviceType(networkDeviceInterface.property("DeviceType").toUInt());
|
||||
switch (deviceType) {
|
||||
case NetworkDevice::NetworkDeviceTypeWifi: {
|
||||
WirelessNetworkDevice *wirelessNetworkDevice = new WirelessNetworkDevice(deviceObjectPath, this);
|
||||
qCDebug(dcNetworkManager()) << "[+]" << wirelessNetworkDevice;
|
||||
m_wifiAvailable = true;
|
||||
m_networkDevices.insert(deviceObjectPath, wirelessNetworkDevice);
|
||||
m_wirelessNetworkDevices.insert(deviceObjectPath, wirelessNetworkDevice);
|
||||
connect(wirelessNetworkDevice, &WirelessNetworkDevice::deviceChanged, this, &NetworkManager::onWirelessDeviceChanged);
|
||||
emit wirelessDeviceAdded(wirelessNetworkDevice);
|
||||
break;
|
||||
}
|
||||
case NetworkDevice::NetworkDeviceTypeEthernet: {
|
||||
WiredNetworkDevice *wiredNetworkDevice = new WiredNetworkDevice(deviceObjectPath, this);
|
||||
qCDebug(dcNetworkManager()) << "[+]" << wiredNetworkDevice;
|
||||
m_networkDevices.insert(deviceObjectPath, wiredNetworkDevice);
|
||||
m_wiredNetworkDevices.insert(deviceObjectPath, wiredNetworkDevice);
|
||||
|
||||
connect(wiredNetworkDevice, &WiredNetworkDevice::deviceChanged, this, &NetworkManager::onWiredDeviceChanged);
|
||||
emit wiredDeviceAdded(wiredNetworkDevice);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
NetworkDevice *networkDevice = new NetworkDevice(deviceObjectPath, this);
|
||||
qCDebug(dcNetworkManager()) << "[+]" << networkDevice;
|
||||
m_networkDevices.insert(deviceObjectPath, networkDevice);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkManager::onDeviceRemoved(const QDBusObjectPath &deviceObjectPath)
|
||||
{
|
||||
if (!m_networkDevices.keys().contains(deviceObjectPath)) {
|
||||
qCWarning(dcNetworkManager()) << "Unknown network device removed:" << deviceObjectPath.path();
|
||||
return;
|
||||
}
|
||||
|
||||
NetworkDevice *networkDevice = m_networkDevices.take(deviceObjectPath);
|
||||
|
||||
if (m_wiredNetworkDevices.contains(deviceObjectPath)) {
|
||||
qCDebug(dcNetworkManager()) << "[-]" << m_wiredNetworkDevices.value(deviceObjectPath);
|
||||
m_wiredNetworkDevices.remove(deviceObjectPath);
|
||||
emit wiredDeviceRemoved(networkDevice->interface());
|
||||
} else if (m_wirelessNetworkDevices.contains(deviceObjectPath)) {
|
||||
qCDebug(dcNetworkManager()) << "[-]" << m_wirelessNetworkDevices.value(deviceObjectPath);
|
||||
m_wirelessNetworkDevices.remove(deviceObjectPath);
|
||||
emit wirelessDeviceRemoved(networkDevice->interface());
|
||||
} else {
|
||||
qCDebug(dcNetworkManager()) << "[-]" << networkDevice;
|
||||
}
|
||||
|
||||
// Check if wireless is still available
|
||||
if (m_wirelessNetworkDevices.isEmpty())
|
||||
m_wifiAvailable = false;
|
||||
|
||||
networkDevice->deleteLater();
|
||||
}
|
||||
|
||||
void NetworkManager::onPropertiesChanged(const QVariantMap &properties)
|
||||
{
|
||||
if (properties.contains("Version"))
|
||||
setVersion(properties.value("Version").toString());
|
||||
|
||||
if (properties.contains("State"))
|
||||
setState((NetworkManagerState)properties.value("State").toUInt());
|
||||
|
||||
if (properties.contains("Connectivity"))
|
||||
setConnectivityState(NetworkManagerConnectivityState(properties.value("Connectivity").toUInt()));
|
||||
|
||||
if (properties.contains("NetworkingEnabled"))
|
||||
setNetworkingEnabled(properties.value("NetworkingEnabled").toBool());
|
||||
|
||||
if (properties.contains("WirelessEnabled"))
|
||||
setWirelessEnabled(properties.value("WirelessEnabled").toBool());
|
||||
|
||||
}
|
||||
|
||||
void NetworkManager::onWirelessDeviceChanged()
|
||||
{
|
||||
WirelessNetworkDevice *networkDevice = static_cast<WirelessNetworkDevice *>(sender());
|
||||
emit wirelessDeviceChanged(networkDevice);
|
||||
}
|
||||
|
||||
void NetworkManager::onWiredDeviceChanged()
|
||||
{
|
||||
WiredNetworkDevice *networkDevice = static_cast<WiredNetworkDevice *>(sender());
|
||||
emit wiredDeviceChanged(networkDevice);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,176 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef NETWORKMANAGER_H
|
||||
#define NETWORKMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusContext>
|
||||
#include <QDBusArgument>
|
||||
|
||||
#include "dbus-interfaces.h"
|
||||
#include "wirednetworkdevice.h"
|
||||
#include "wirelessnetworkdevice.h"
|
||||
#include "networksettings.h"
|
||||
|
||||
// Docs: https://developer.gnome.org/NetworkManager/unstable/spec.html
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class NetworkManager : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum NetworkManagerState {
|
||||
NetworkManagerStateUnknown = 0,
|
||||
NetworkManagerStateAsleep = 10,
|
||||
NetworkManagerStateDisconnected = 20,
|
||||
NetworkManagerStateDisconnecting = 30,
|
||||
NetworkManagerStateConnecting = 40,
|
||||
NetworkManagerStateConnectedLocal = 50,
|
||||
NetworkManagerStateConnectedSite = 60,
|
||||
NetworkManagerStateConnectedGlobal = 70
|
||||
};
|
||||
Q_ENUM(NetworkManagerState)
|
||||
|
||||
enum NetworkManagerConnectivityState {
|
||||
NetworkManagerConnectivityStateUnknown = 0,
|
||||
NetworkManagerConnectivityStateNone = 1,
|
||||
NetworkManagerConnectivityStatePortal = 2,
|
||||
NetworkManagerConnectivityStateLimited = 3,
|
||||
NetworkManagerConnectivityStateFull = 4
|
||||
};
|
||||
Q_ENUM(NetworkManagerConnectivityState)
|
||||
|
||||
enum NetworkManagerError {
|
||||
NetworkManagerErrorNoError,
|
||||
NetworkManagerErrorUnknownError,
|
||||
NetworkManagerErrorWirelessNotAvailable,
|
||||
NetworkManagerErrorAccessPointNotFound,
|
||||
NetworkManagerErrorNetworkInterfaceNotFound,
|
||||
NetworkManagerErrorInvalidNetworkDeviceType,
|
||||
NetworkManagerErrorWirelessNetworkingDisabled,
|
||||
NetworkManagerErrorWirelessConnectionFailed,
|
||||
NetworkManagerErrorNetworkingDisabled,
|
||||
NetworkManagerErrorNetworkManagerNotAvailable
|
||||
};
|
||||
Q_ENUM(NetworkManagerError)
|
||||
|
||||
explicit NetworkManager(QObject *parent = nullptr);
|
||||
|
||||
bool available();
|
||||
bool wifiAvailable();
|
||||
|
||||
QList<NetworkDevice *> networkDevices() const;
|
||||
QList<WirelessNetworkDevice *> wirelessNetworkDevices() const;
|
||||
QList<WiredNetworkDevice *> wiredNetworkDevices() const;
|
||||
|
||||
NetworkDevice *getNetworkDevice(const QString &interface);
|
||||
|
||||
// Properties
|
||||
QString version() const;
|
||||
NetworkManagerState state() const;
|
||||
QString stateString() const;
|
||||
NetworkManagerConnectivityState connectivityState() const;
|
||||
|
||||
NetworkManagerError connectWifi(const QString &interface, const QString &ssid, const QString &password);
|
||||
|
||||
// Networking
|
||||
bool networkingEnabled() const;
|
||||
bool enableNetworking(const bool &enabled);
|
||||
|
||||
// Wireless Networking
|
||||
bool wirelessEnabled() const;
|
||||
bool enableWireless(const bool &enabled);
|
||||
|
||||
private:
|
||||
QDBusInterface *m_networkManagerInterface;
|
||||
|
||||
QHash<QDBusObjectPath, NetworkDevice *> m_networkDevices;
|
||||
QHash<QDBusObjectPath, WirelessNetworkDevice *> m_wirelessNetworkDevices;
|
||||
QHash<QDBusObjectPath, WiredNetworkDevice *> m_wiredNetworkDevices;
|
||||
|
||||
NetworkSettings *m_networkSettings;
|
||||
|
||||
bool m_available;
|
||||
bool m_wifiAvailable;
|
||||
|
||||
QString m_version;
|
||||
|
||||
NetworkManagerState m_state;
|
||||
NetworkManagerConnectivityState m_connectivityState;
|
||||
bool m_networkingEnabled;
|
||||
bool m_wirelessEnabled;
|
||||
|
||||
void loadDevices();
|
||||
|
||||
static QString networkManagerStateToString(const NetworkManagerState &state);
|
||||
static QString networkManagerConnectivityStateToString(const NetworkManagerConnectivityState &state);
|
||||
|
||||
void setVersion(const QString &version);
|
||||
void setNetworkingEnabled(const bool &enabled);
|
||||
void setWirelessEnabled(const bool &enabled);
|
||||
void setConnectivityState(const NetworkManagerConnectivityState &connectivityState);
|
||||
void setState(const NetworkManagerState &state);
|
||||
|
||||
signals:
|
||||
void versionChanged();
|
||||
void networkingEnabledChanged();
|
||||
void wirelessEnabledChanged();
|
||||
void stateChanged();
|
||||
void connectivityStateChanged();
|
||||
|
||||
void wirelessDeviceAdded(WirelessNetworkDevice *wirelessDevice);
|
||||
void wirelessDeviceRemoved(const QString &interface);
|
||||
void wirelessDeviceChanged(WirelessNetworkDevice *wirelessDevice);
|
||||
|
||||
void wiredDeviceAdded(WiredNetworkDevice *wiredDevice);
|
||||
void wiredDeviceRemoved(const QString &interface);
|
||||
void wiredDeviceChanged(WiredNetworkDevice *wiredDevice);
|
||||
|
||||
private slots:
|
||||
void onDeviceAdded(const QDBusObjectPath &deviceObjectPath);
|
||||
void onDeviceRemoved(const QDBusObjectPath &deviceObjectPath);
|
||||
void onPropertiesChanged(const QVariantMap &properties);
|
||||
|
||||
void onWirelessDeviceChanged();
|
||||
void onWiredDeviceChanged();
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(nymeaserver::NetworkManager::NetworkManagerState)
|
||||
Q_DECLARE_METATYPE(nymeaserver::NetworkManager::NetworkManagerError)
|
||||
|
||||
#endif // NETWORKMANAGER_H
|
||||
|
|
@ -1,124 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*!
|
||||
\class nymeaserver::NetworkSettings
|
||||
\brief Represents the network settings in the \l{NetworkManager}.
|
||||
|
||||
\ingroup networkmanager
|
||||
\inmodule core
|
||||
*/
|
||||
|
||||
#include "networksettings.h"
|
||||
#include "dbus-interfaces.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
/*! Constructs a new \l{NetworkSettings} object with the given \a parent. */
|
||||
NetworkSettings::NetworkSettings(QObject *parent) : QObject(parent)
|
||||
{
|
||||
m_settingsInterface = new QDBusInterface(serviceString, settingsPathString, settingsInterfaceString, QDBusConnection::systemBus(), this);
|
||||
if(!m_settingsInterface->isValid()) {
|
||||
qCWarning(dcNetworkManager()) << "Invalid DBus network settings interface";
|
||||
return;
|
||||
}
|
||||
|
||||
loadConnections();
|
||||
|
||||
QDBusConnection::systemBus().connect(serviceString, settingsPathString, settingsInterfaceString, "NewConnection", this, SLOT(connectionAdded(QDBusObjectPath)));
|
||||
QDBusConnection::systemBus().connect(serviceString, settingsPathString, settingsInterfaceString, "ConnectionRemoved", this, SLOT(connectionRemoved(QDBusObjectPath)));
|
||||
QDBusConnection::systemBus().connect(serviceString, settingsPathString, settingsInterfaceString, "PropertiesChanged", this, SLOT(propertiesChanged(QVariantMap)));
|
||||
}
|
||||
|
||||
/*! Add the given \a settings to this \l{NetworkSettings}. Returns the dbus object path from the new settings. */
|
||||
QDBusObjectPath NetworkSettings::addConnection(const ConnectionSettings &settings)
|
||||
{
|
||||
QDBusMessage query = m_settingsInterface->call("AddConnection", QVariant::fromValue(settings));
|
||||
if(query.type() != QDBusMessage::ReplyMessage) {
|
||||
qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage();
|
||||
return QDBusObjectPath();
|
||||
}
|
||||
|
||||
if (query.arguments().isEmpty())
|
||||
return QDBusObjectPath();
|
||||
|
||||
return query.arguments().at(0).value<QDBusObjectPath>();
|
||||
}
|
||||
|
||||
/*! Returns the list of current \l{NetworkConnection}{NetworkConnections} from this \l{NetworkSettings}. */
|
||||
QList<NetworkConnection *> NetworkSettings::connections() const
|
||||
{
|
||||
return m_connections.values();
|
||||
}
|
||||
|
||||
void NetworkSettings::loadConnections()
|
||||
{
|
||||
QDBusMessage query = m_settingsInterface->call("ListConnections");
|
||||
if(query.type() != QDBusMessage::ReplyMessage) {
|
||||
qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if (query.arguments().isEmpty())
|
||||
return;
|
||||
|
||||
const QDBusArgument &argument = query.arguments().at(0).value<QDBusArgument>();
|
||||
argument.beginArray();
|
||||
while(!argument.atEnd()) {
|
||||
QDBusObjectPath objectPath = qdbus_cast<QDBusObjectPath>(argument);
|
||||
connectionAdded(objectPath);
|
||||
}
|
||||
argument.endArray();
|
||||
|
||||
}
|
||||
|
||||
void NetworkSettings::connectionAdded(const QDBusObjectPath &objectPath)
|
||||
{
|
||||
NetworkConnection *connection = new NetworkConnection(objectPath, this);
|
||||
m_connections.insert(objectPath, connection);
|
||||
|
||||
qCDebug(dcNetworkManager()) << "Settings: [+]" << connection;
|
||||
}
|
||||
|
||||
void NetworkSettings::connectionRemoved(const QDBusObjectPath &objectPath)
|
||||
{
|
||||
NetworkConnection *connection = m_connections.take(objectPath);
|
||||
qCDebug(dcNetworkManager()) << "Settings: [-]" << connection;
|
||||
connection->deleteLater();
|
||||
}
|
||||
|
||||
void NetworkSettings::propertiesChanged(const QVariantMap &properties)
|
||||
{
|
||||
Q_UNUSED(properties);
|
||||
//qCDebug(dcNetworkManager()) << "Settins: properties changed" << properties;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,72 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef NETWORKSETTINGS_H
|
||||
#define NETWORKSETTINGS_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusObjectPath>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusArgument>
|
||||
|
||||
#include "networkconnection.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class NetworkConnection;
|
||||
|
||||
class NetworkSettings : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit NetworkSettings(QObject *parent = 0);
|
||||
|
||||
QDBusObjectPath addConnection(const ConnectionSettings &settings);
|
||||
QList<NetworkConnection *> connections() const;
|
||||
|
||||
private:
|
||||
QDBusInterface *m_settingsInterface;
|
||||
QHash<QDBusObjectPath, NetworkConnection *> m_connections;
|
||||
|
||||
void loadConnections();
|
||||
|
||||
signals:
|
||||
|
||||
private slots:
|
||||
void connectionAdded(const QDBusObjectPath &objectPath);
|
||||
void connectionRemoved(const QDBusObjectPath &objectPath);
|
||||
void propertiesChanged(const QVariantMap &properties);
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // NETWORKSETTINGS_H
|
||||
|
|
@ -1,121 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*!
|
||||
\class nymeaserver::WiredNetworkDevice
|
||||
\brief Represents an ethernet device in the \l{NetworkManager}.
|
||||
|
||||
\ingroup networkmanager
|
||||
\inmodule core
|
||||
*/
|
||||
|
||||
/*! \fn void WiredNetworkDevice::propertiesChanged(const QVariantMap &properties);
|
||||
This signal will be emitted when the \a properties of this \l{WiredNetworkDevice} have changed.
|
||||
*/
|
||||
|
||||
#include "wirednetworkdevice.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
/*! Constructs a new \l{WiredNetworkDevice} with the given dbus \a objectPath and \a parent. */
|
||||
WiredNetworkDevice::WiredNetworkDevice(const QDBusObjectPath &objectPath, QObject *parent) :
|
||||
NetworkDevice(objectPath, parent)
|
||||
{
|
||||
QDBusConnection systemBus = QDBusConnection::systemBus();
|
||||
if (!systemBus.isConnected()) {
|
||||
qCWarning(dcNetworkManager()) << "WiredNetworkDevice: System DBus not connected";
|
||||
return;
|
||||
}
|
||||
|
||||
m_wiredInterface = new QDBusInterface(serviceString, this->objectPath().path(), wiredInterfaceString, systemBus, this);
|
||||
if(!m_wiredInterface->isValid()) {
|
||||
qCWarning(dcNetworkManager()) << "WiredNetworkDevice: Invalid wired dbus interface";
|
||||
return;
|
||||
}
|
||||
|
||||
setMacAddress(m_wiredInterface->property("HwAddress").toString());
|
||||
setBitRate(m_wiredInterface->property("Bitrate").toInt());
|
||||
setPluggedIn(m_wiredInterface->property("Carrier").toBool());
|
||||
|
||||
QDBusConnection::systemBus().connect(serviceString, this->objectPath().path(), wiredInterfaceString, "PropertiesChanged", this, SLOT(propertiesChanged(QVariantMap)));
|
||||
}
|
||||
|
||||
/*! Returns the mac address of this \l{WiredNetworkDevice}. */
|
||||
QString WiredNetworkDevice::macAddress() const
|
||||
{
|
||||
return m_macAddress;
|
||||
}
|
||||
|
||||
/*! Returns the current bit rate [Mb/s] of this \l{WiredNetworkDevice}. */
|
||||
int WiredNetworkDevice::bitRate() const
|
||||
{
|
||||
return m_bitRate;
|
||||
}
|
||||
|
||||
/*! Returns true if this \l{WiredNetworkDevice} has a cable plugged in. */
|
||||
bool WiredNetworkDevice::pluggedIn() const
|
||||
{
|
||||
return m_pluggedIn;
|
||||
}
|
||||
|
||||
void WiredNetworkDevice::setMacAddress(const QString &macAddress)
|
||||
{
|
||||
m_macAddress = macAddress;
|
||||
}
|
||||
|
||||
void WiredNetworkDevice::setBitRate(const int &bitRate)
|
||||
{
|
||||
m_bitRate = bitRate;
|
||||
}
|
||||
|
||||
void WiredNetworkDevice::setPluggedIn(const bool &pluggedIn)
|
||||
{
|
||||
m_pluggedIn = pluggedIn;
|
||||
}
|
||||
|
||||
void WiredNetworkDevice::propertiesChanged(const QVariantMap &properties)
|
||||
{
|
||||
if (properties.contains("Carrier"))
|
||||
setPluggedIn(properties.value("Carrier").toBool());
|
||||
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, WiredNetworkDevice *networkDevice)
|
||||
{
|
||||
debug.nospace() << "WiredNetworkDevice(" << networkDevice->interface() << ", ";
|
||||
debug.nospace() << networkDevice->macAddress() << ", ";
|
||||
debug.nospace() << networkDevice->bitRate() << " [Mb/s], ";
|
||||
debug.nospace() << networkDevice->pluggedIn() << ", ";
|
||||
debug.nospace() << networkDevice->deviceStateString() << ") ";
|
||||
return debug;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef WIREDNETWORKDEVICE_H
|
||||
#define WIREDNETWORKDEVICE_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDBusObjectPath>
|
||||
|
||||
#include "networkdevice.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class WiredNetworkDevice : public NetworkDevice
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString interface READ interface)
|
||||
Q_PROPERTY(QString macAddress READ macAddress)
|
||||
Q_PROPERTY(NetworkDeviceState state READ deviceState)
|
||||
Q_PROPERTY(QString bitRate READ bitRate)
|
||||
Q_PROPERTY(bool pluggedIn READ pluggedIn)
|
||||
|
||||
public:
|
||||
explicit WiredNetworkDevice(const QDBusObjectPath &objectPath, QObject *parent = nullptr);
|
||||
|
||||
QString macAddress() const;
|
||||
int bitRate() const;
|
||||
bool pluggedIn() const;
|
||||
|
||||
private:
|
||||
QDBusInterface *m_wiredInterface;
|
||||
|
||||
QString m_macAddress;
|
||||
int m_bitRate = 0;
|
||||
bool m_pluggedIn = false;
|
||||
|
||||
void setMacAddress(const QString &macAddress);
|
||||
void setBitRate(const int &bitRate);
|
||||
void setPluggedIn(const bool &pluggedIn);
|
||||
|
||||
private slots:
|
||||
void propertiesChanged(const QVariantMap &properties);
|
||||
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug debug, WiredNetworkDevice *networkDevice);
|
||||
|
||||
}
|
||||
|
||||
#endif // WIREDNETWORKDEVICE_H
|
||||
|
|
@ -1,176 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*!
|
||||
\class nymeaserver::WirelessAccessPoint
|
||||
\brief Represents a wireless access point from a \l{WirelessNetworkDevice}.
|
||||
|
||||
\ingroup networkmanager
|
||||
\inmodule core
|
||||
|
||||
\sa WirelessNetworkDevice
|
||||
*/
|
||||
|
||||
/*! \enum nymeaserver::WirelessAccessPoint::ApSecurityMode
|
||||
\value ApSecurityModeNone
|
||||
\value ApSecurityModePairWep40
|
||||
\value ApSecurityModePairWep104
|
||||
\value ApSecurityModePairTkip
|
||||
\value ApSecurityModePairCcmp
|
||||
\value ApSecurityModeGroupWep40
|
||||
\value ApSecurityModeGroupWep104
|
||||
\value ApSecurityModeGroupTkip
|
||||
\value ApSecurityModeGroupCcmp
|
||||
\value ApSecurityModeKeyMgmtPsk
|
||||
\value ApSecurityModeKeyMgmt8021X
|
||||
*/
|
||||
|
||||
/*! \fn void WirelessAccessPoint::signalStrengthChanged();
|
||||
This signal will be emitted when the signalStrength of this \l{WirelessAccessPoint} has changed.
|
||||
*/
|
||||
|
||||
#include "wirelessaccesspoint.h"
|
||||
#include "loggingcategories.h"
|
||||
#include "dbus-interfaces.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
/*! Constructs a new \l{WirelessAccessPoint} with the given dbus \a objectPath and \a parent. */
|
||||
WirelessAccessPoint::WirelessAccessPoint(const QDBusObjectPath &objectPath, QObject *parent) :
|
||||
QObject(parent),
|
||||
m_objectPath(objectPath),
|
||||
m_securityFlags(0)
|
||||
{
|
||||
QDBusInterface accessPointInterface(serviceString, m_objectPath.path(), accessPointInterfaceString, QDBusConnection::systemBus());
|
||||
if(!accessPointInterface.isValid()) {
|
||||
qCWarning(dcNetworkManager()) << "Invalid access point dbus interface";
|
||||
return;
|
||||
}
|
||||
|
||||
// Init properties
|
||||
setSsid(accessPointInterface.property("Ssid").toString());
|
||||
setMacAddress(accessPointInterface.property("HwAddress").toString());
|
||||
setFrequency(accessPointInterface.property("Frequency").toDouble() / 1000);
|
||||
setSignalStrength(accessPointInterface.property("Strength").toUInt());
|
||||
setSecurityFlags(WirelessAccessPoint::ApSecurityModes(accessPointInterface.property("WpaFlags").toUInt()));
|
||||
setIsProtected((bool)accessPointInterface.property("Flags").toUInt());
|
||||
|
||||
QDBusConnection::systemBus().connect(serviceString, objectPath.path(), accessPointInterfaceString, "PropertiesChanged", this, SLOT(onPropertiesChanged(QVariantMap)));
|
||||
}
|
||||
|
||||
/*! Returns the dbus object path of this \l{WirelessAccessPoint}. */
|
||||
QDBusObjectPath WirelessAccessPoint::objectPath() const
|
||||
{
|
||||
return m_objectPath;
|
||||
}
|
||||
|
||||
/*! Returns the ssid of this \l{WirelessAccessPoint}. */
|
||||
QString WirelessAccessPoint::ssid() const
|
||||
{
|
||||
return m_ssid;
|
||||
}
|
||||
|
||||
void WirelessAccessPoint::setSsid(const QString &ssid)
|
||||
{
|
||||
m_ssid = ssid;
|
||||
}
|
||||
|
||||
/*! Returns the mac address of this \l{WirelessAccessPoint}. */
|
||||
QString WirelessAccessPoint::macAddress() const
|
||||
{
|
||||
return m_macAddress;
|
||||
}
|
||||
|
||||
void WirelessAccessPoint::setMacAddress(const QString &macAddress)
|
||||
{
|
||||
m_macAddress = macAddress;
|
||||
}
|
||||
|
||||
/*! Returns the frequency of this \l{WirelessAccessPoint}. (2.4 GHz or 5GHz) */
|
||||
double WirelessAccessPoint::frequency() const
|
||||
{
|
||||
return m_frequency;
|
||||
}
|
||||
|
||||
void WirelessAccessPoint::setFrequency(const double &frequency)
|
||||
{
|
||||
m_frequency = frequency;
|
||||
}
|
||||
|
||||
/*! Returns the signal strength in percentage [0, 100] % of this \l{WirelessAccessPoint}. */
|
||||
int WirelessAccessPoint::signalStrength() const
|
||||
{
|
||||
return m_signalStrength;
|
||||
}
|
||||
|
||||
void WirelessAccessPoint::setSignalStrength(const int &signalStrength)
|
||||
{
|
||||
m_signalStrength = signalStrength;
|
||||
emit signalStrengthChanged();
|
||||
}
|
||||
|
||||
void WirelessAccessPoint::setIsProtected(const bool &isProtected)
|
||||
{
|
||||
m_isProtected = isProtected;
|
||||
}
|
||||
|
||||
/*! Returns true if this \l{WirelessAccessPoint} is password protected. */
|
||||
bool WirelessAccessPoint::isProtected() const
|
||||
{
|
||||
return m_isProtected;
|
||||
}
|
||||
|
||||
/*! Returns the security flags of this \l{WirelessAccessPoint}.
|
||||
|
||||
\sa ApSecurityModes
|
||||
*/
|
||||
WirelessAccessPoint::ApSecurityModes WirelessAccessPoint::securityFlags() const
|
||||
{
|
||||
return m_securityFlags;
|
||||
}
|
||||
|
||||
void WirelessAccessPoint::setSecurityFlags(const WirelessAccessPoint::ApSecurityModes &securityFlags)
|
||||
{
|
||||
m_securityFlags = securityFlags;
|
||||
}
|
||||
|
||||
void WirelessAccessPoint::onPropertiesChanged(const QVariantMap &properties)
|
||||
{
|
||||
if (properties.contains("Strength"))
|
||||
setSignalStrength(properties.value("Strength").toUInt());
|
||||
|
||||
}
|
||||
|
||||
QDebug operator<<(QDebug debug, WirelessAccessPoint *accessPoint)
|
||||
{
|
||||
return debug.nospace() << "AccessPoint(" << accessPoint->signalStrength() << "%, " << accessPoint->frequency()<< " GHz, " << accessPoint->ssid() << ", " << (accessPoint->isProtected() ? "protected" : "open" ) << ")";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,115 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef WIRELESSACCESSPOINT_H
|
||||
#define WIRELESSACCESSPOINT_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QFlags>
|
||||
#include <QDBusObjectPath>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusArgument>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class WirelessAccessPoint : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_FLAGS(ApSecurityModes)
|
||||
|
||||
Q_PROPERTY(QString ssid READ ssid)
|
||||
Q_PROPERTY(QString macAddress READ macAddress)
|
||||
Q_PROPERTY(double frequency READ frequency)
|
||||
Q_PROPERTY(int signalStrength READ signalStrength NOTIFY signalStrengthChanged)
|
||||
Q_PROPERTY(bool protected READ isProtected)
|
||||
|
||||
public:
|
||||
enum ApSecurityMode{
|
||||
ApSecurityModeNone = 0x000,
|
||||
ApSecurityModePairWep40 = 0x001,
|
||||
ApSecurityModePairWep104 = 0x002,
|
||||
ApSecurityModePairTkip = 0x004,
|
||||
ApSecurityModePairCcmp = 0x008,
|
||||
ApSecurityModeGroupWep40 = 0x010,
|
||||
ApSecurityModeGroupWep104 = 0x020,
|
||||
ApSecurityModeGroupTkip = 0x040,
|
||||
ApSecurityModeGroupCcmp = 0x080,
|
||||
ApSecurityModeKeyMgmtPsk = 0x100,
|
||||
ApSecurityModeKeyMgmt8021X = 0x200,
|
||||
};
|
||||
Q_DECLARE_FLAGS(ApSecurityModes, ApSecurityMode)
|
||||
|
||||
|
||||
explicit WirelessAccessPoint(const QDBusObjectPath &objectPath, QObject *parent = nullptr);
|
||||
|
||||
QDBusObjectPath objectPath() const;
|
||||
|
||||
QString ssid() const;
|
||||
QString macAddress() const;
|
||||
double frequency() const;
|
||||
int signalStrength() const;
|
||||
bool isProtected() const;
|
||||
|
||||
WirelessAccessPoint::ApSecurityModes securityFlags() const;
|
||||
|
||||
private:
|
||||
QDBusObjectPath m_objectPath;
|
||||
QString m_ssid;
|
||||
QString m_macAddress;
|
||||
double m_frequency;
|
||||
int m_signalStrength;
|
||||
bool m_isProtected;
|
||||
WirelessAccessPoint::ApSecurityModes m_securityFlags;
|
||||
|
||||
void setSsid(const QString &ssid);
|
||||
void setMacAddress(const QString &macAddress);
|
||||
void setFrequency(const double &frequency);
|
||||
void setSignalStrength(const int &signalStrength);
|
||||
void setIsProtected(const bool &isProtected);
|
||||
void setSecurityFlags(const WirelessAccessPoint::ApSecurityModes &securityFlags);
|
||||
|
||||
signals:
|
||||
void signalStrengthChanged();
|
||||
|
||||
private slots:
|
||||
void onPropertiesChanged(const QVariantMap &properties);
|
||||
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug debug, WirelessAccessPoint *accessPoint);
|
||||
|
||||
}
|
||||
|
||||
Q_DECLARE_OPERATORS_FOR_FLAGS(nymeaserver::WirelessAccessPoint::ApSecurityModes)
|
||||
Q_DECLARE_METATYPE(nymeaserver::WirelessAccessPoint::ApSecurityMode)
|
||||
|
||||
#endif // WIRELESSACCESSPOINT_H
|
||||
|
|
@ -1,244 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
/*!
|
||||
\class nymeaserver::WirelessNetworkDevice
|
||||
\brief Represents a wireless device (adapter) in the networkmanager.
|
||||
|
||||
\ingroup networkmanager
|
||||
\inmodule core
|
||||
*/
|
||||
|
||||
/*! \fn void WirelessNetworkDevice::bitRateChanged(const bool &bitRate);
|
||||
This signal will be emitted when the \a bitRate of this \l{WirelessNetworkDevice} has changed.
|
||||
*/
|
||||
|
||||
|
||||
/*! \fn void WirelessNetworkDevice::stateChanged(const NetworkDeviceState &state);
|
||||
This signal will be emitted when the current \a state of this \l{WirelessNetworkDevice} has changed.
|
||||
|
||||
\sa NetworkDeviceState
|
||||
*/
|
||||
|
||||
|
||||
#include "wirelessnetworkdevice.h"
|
||||
|
||||
#include "dbus-interfaces.h"
|
||||
#include "loggingcategories.h"
|
||||
|
||||
#include <QMetaEnum>
|
||||
#include <QUuid>
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
/*! Constructs a new \l{WirelessNetworkDevice} with the given dbus \a objectPath and \a parent. */
|
||||
WirelessNetworkDevice::WirelessNetworkDevice(const QDBusObjectPath &objectPath, QObject *parent) :
|
||||
NetworkDevice(objectPath, parent),
|
||||
m_activeAccessPoint(Q_NULLPTR)
|
||||
{
|
||||
QDBusConnection systemBus = QDBusConnection::systemBus();
|
||||
if (!systemBus.isConnected()) {
|
||||
qCWarning(dcNetworkManager()) << "WirelessNetworkDevice: System DBus not connected";
|
||||
return;
|
||||
}
|
||||
|
||||
m_wirelessInterface = new QDBusInterface(serviceString, this->objectPath().path(), wirelessInterfaceString, systemBus, this);
|
||||
if (!m_wirelessInterface->isValid()) {
|
||||
qCWarning(dcNetworkManager()) << "WirelessNetworkDevice: Invalid wireless dbus interface";
|
||||
return;
|
||||
}
|
||||
|
||||
QDBusConnection::systemBus().connect(serviceString, this->objectPath().path(), wirelessInterfaceString, "AccessPointAdded", this, SLOT(accessPointAdded(QDBusObjectPath)));
|
||||
QDBusConnection::systemBus().connect(serviceString, this->objectPath().path(), wirelessInterfaceString, "AccessPointRemoved", this, SLOT(accessPointRemoved(QDBusObjectPath)));
|
||||
QDBusConnection::systemBus().connect(serviceString, this->objectPath().path(), wirelessInterfaceString, "PropertiesChanged", this, SLOT(propertiesChanged(QVariantMap)));
|
||||
|
||||
readAccessPoints();
|
||||
|
||||
setMacAddress(m_wirelessInterface->property("HwAddress").toString());
|
||||
setBitrate(m_wirelessInterface->property("Bitrate").toInt());
|
||||
setActiveAccessPoint(qdbus_cast<QDBusObjectPath>(m_wirelessInterface->property("ActiveAccessPoint")));
|
||||
}
|
||||
|
||||
/*! Returns the mac address of this \l{WirelessNetworkDevice}. */
|
||||
QString WirelessNetworkDevice::macAddress() const
|
||||
{
|
||||
return m_macAddress;
|
||||
}
|
||||
|
||||
/*! Returns the bit rate [Mb/s] of this \l{WirelessNetworkDevice}. */
|
||||
int WirelessNetworkDevice::bitRate() const
|
||||
{
|
||||
return m_bitRate;
|
||||
}
|
||||
|
||||
/*! Returns the current active \l{WirelessAccessPoint} of this \l{WirelessNetworkDevice}. */
|
||||
WirelessAccessPoint *WirelessNetworkDevice::activeAccessPoint()
|
||||
{
|
||||
return m_activeAccessPoint;
|
||||
}
|
||||
|
||||
/*! Perform a wireless network scan on this \l{WirelessNetworkDevice}. */
|
||||
void WirelessNetworkDevice::scanWirelessNetworks()
|
||||
{
|
||||
qCDebug(dcNetworkManager()) << this << "Request scan";
|
||||
QDBusMessage query = m_wirelessInterface->call("RequestScan", QVariantMap());
|
||||
if (query.type() != QDBusMessage::ReplyMessage) {
|
||||
qCWarning(dcNetworkManager()) << "Scan error:" << query.errorName() << query.errorMessage();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/*! Returns the list of all \l{WirelessAccessPoint}{WirelessAccessPoints} of this \l{WirelessNetworkDevice}. */
|
||||
QList<WirelessAccessPoint *> WirelessNetworkDevice::accessPoints()
|
||||
{
|
||||
return m_accessPointsTable.values();
|
||||
}
|
||||
|
||||
/*! Returns the \l{WirelessAccessPoint} with the given \a ssid. If the \l{WirelessAccessPoint} could not be found, return Q_NULLPTR. */
|
||||
WirelessAccessPoint *WirelessNetworkDevice::getAccessPoint(const QString &ssid)
|
||||
{
|
||||
foreach (WirelessAccessPoint *accessPoint, m_accessPointsTable.values()) {
|
||||
if (accessPoint->ssid() == ssid)
|
||||
return accessPoint;
|
||||
}
|
||||
return Q_NULLPTR;
|
||||
}
|
||||
|
||||
/*! Returns the \l{WirelessAccessPoint} with the given \a objectPath. If the \l{WirelessAccessPoint} could not be found, return Q_NULLPTR. */
|
||||
WirelessAccessPoint *WirelessNetworkDevice::getAccessPoint(const QDBusObjectPath &objectPath)
|
||||
{
|
||||
return m_accessPointsTable.value(objectPath);
|
||||
}
|
||||
|
||||
void WirelessNetworkDevice::readAccessPoints()
|
||||
{
|
||||
QDBusMessage query = m_wirelessInterface->call("GetAccessPoints");
|
||||
if(query.type() != QDBusMessage::ReplyMessage) {
|
||||
qCWarning(dcNetworkManager()) << query.errorName() << query.errorMessage();
|
||||
return;
|
||||
}
|
||||
|
||||
if (query.arguments().isEmpty())
|
||||
return;
|
||||
|
||||
const QDBusArgument &argument = query.arguments().at(0).value<QDBusArgument>();
|
||||
argument.beginArray();
|
||||
while (!argument.atEnd()) {
|
||||
QDBusObjectPath accessPointObjectPath = qdbus_cast<QDBusObjectPath>(argument);
|
||||
accessPointAdded(accessPointObjectPath);
|
||||
}
|
||||
argument.endArray();
|
||||
}
|
||||
|
||||
void WirelessNetworkDevice::setMacAddress(const QString &macAddress)
|
||||
{
|
||||
m_macAddress = macAddress;
|
||||
}
|
||||
|
||||
void WirelessNetworkDevice::setBitrate(const int &bitRate)
|
||||
{
|
||||
if (m_bitRate != bitRate / 1000) {
|
||||
m_bitRate = bitRate / 1000;
|
||||
emit deviceChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void WirelessNetworkDevice::setActiveAccessPoint(const QDBusObjectPath &activeAccessPointObjectPath)
|
||||
{
|
||||
if (m_activeAccessPointObjectPath != activeAccessPointObjectPath) {
|
||||
m_activeAccessPointObjectPath = activeAccessPointObjectPath;
|
||||
if (m_accessPointsTable.contains(m_activeAccessPointObjectPath)) {
|
||||
if (m_activeAccessPoint)
|
||||
disconnect(m_activeAccessPoint, &WirelessAccessPoint::signalStrengthChanged, this, &WirelessNetworkDevice::deviceChanged);
|
||||
|
||||
// Set new access point object
|
||||
m_activeAccessPoint = m_accessPointsTable.value(activeAccessPointObjectPath);
|
||||
// Update the device when the signalstrength changed
|
||||
connect(m_activeAccessPoint, &WirelessAccessPoint::signalStrengthChanged, this, &WirelessNetworkDevice::deviceChanged);
|
||||
} else {
|
||||
m_activeAccessPoint = Q_NULLPTR;
|
||||
}
|
||||
emit deviceChanged();
|
||||
}
|
||||
}
|
||||
|
||||
void WirelessNetworkDevice::accessPointAdded(const QDBusObjectPath &objectPath)
|
||||
{
|
||||
QDBusInterface accessPointInterface(serviceString, objectPath.path(), accessPointInterfaceString, QDBusConnection::systemBus());
|
||||
if (!accessPointInterface.isValid()) {
|
||||
qCWarning(dcNetworkManager()) << "WirelessNetworkDevice: Invalid access point dbus interface";
|
||||
return;
|
||||
}
|
||||
|
||||
if (m_accessPointsTable.keys().contains(objectPath)) {
|
||||
qCWarning(dcNetworkManager()) << "WirelessNetworkDevice: Access point already added" << objectPath.path();
|
||||
return;
|
||||
}
|
||||
|
||||
WirelessAccessPoint *accessPoint = new WirelessAccessPoint(objectPath, this);
|
||||
//qCDebug(dcNetworkManager()) << "WirelessNetworkDevice: [+]" << accessPoint;
|
||||
m_accessPointsTable.insert(objectPath, accessPoint);
|
||||
}
|
||||
|
||||
void WirelessNetworkDevice::accessPointRemoved(const QDBusObjectPath &objectPath)
|
||||
{
|
||||
if (!m_accessPointsTable.keys().contains(objectPath))
|
||||
return;
|
||||
|
||||
WirelessAccessPoint *accessPoint = m_accessPointsTable.take(objectPath);
|
||||
if (accessPoint == m_activeAccessPoint)
|
||||
m_activeAccessPoint = Q_NULLPTR;
|
||||
|
||||
//qCDebug(dcNetworkManager()) << "WirelessNetworkDevice: [-]" << accessPoint;
|
||||
accessPoint->deleteLater();
|
||||
}
|
||||
|
||||
void WirelessNetworkDevice::propertiesChanged(const QVariantMap &properties)
|
||||
{
|
||||
//qCDebug(dcNetworkManager()) << "WirelessNetworkDevice: Property changed" << properties;
|
||||
|
||||
if (properties.contains("Bitrate"))
|
||||
setBitrate(properties.value("Bitrate").toInt());
|
||||
|
||||
if (properties.contains("ActiveAccessPoint"))
|
||||
setActiveAccessPoint(qdbus_cast<QDBusObjectPath>(properties.value("ActiveAccessPoint")));
|
||||
}
|
||||
|
||||
/*! Writes the given \a device to the given to \a debug. \sa WirelessNetworkDevice, */
|
||||
QDebug operator<<(QDebug debug, WirelessNetworkDevice *device)
|
||||
{
|
||||
debug.nospace() << "WirelessNetworkDevice(" << device->interface() << ", ";
|
||||
debug.nospace() << device->macAddress() << ", ";
|
||||
debug.nospace() << device->bitRate() << " [Mb/s], ";
|
||||
debug.nospace() << device->deviceStateString() << ") ";
|
||||
return debug;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
*
|
||||
* Copyright 2013 - 2020, nymea GmbH
|
||||
* Contact: contact@nymea.io
|
||||
*
|
||||
* This file is part of nymea.
|
||||
* This project including source code and documentation is protected by
|
||||
* copyright law, and remains the property of nymea GmbH. All rights, including
|
||||
* reproduction, publication, editing and translation, are reserved. The use of
|
||||
* this project is subject to the terms of a license agreement to be concluded
|
||||
* with nymea GmbH in accordance with the terms of use of nymea GmbH, available
|
||||
* under https://nymea.io/license
|
||||
*
|
||||
* GNU General Public License Usage
|
||||
* Alternatively, this project may be redistributed and/or modified under the
|
||||
* terms of the GNU General Public License as published by the Free Software
|
||||
* Foundation, GNU version 3. This project is distributed in the hope that it
|
||||
* will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty
|
||||
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
|
||||
* Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with
|
||||
* this project. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For any further details and any questions please contact us under
|
||||
* contact@nymea.io or see our FAQ/Licensing Information on
|
||||
* https://nymea.io/license/faq
|
||||
*
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef WIRELESSNETWORKMANAGER_H
|
||||
#define WIRELESSNETWORKMANAGER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QDebug>
|
||||
#include <QDBusConnection>
|
||||
#include <QDBusInterface>
|
||||
#include <QDBusMessage>
|
||||
#include <QDBusContext>
|
||||
#include <QDBusArgument>
|
||||
|
||||
#include "networkdevice.h"
|
||||
#include "wirelessaccesspoint.h"
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class WirelessNetworkDevice : public NetworkDevice
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PROPERTY(QString interface READ interface)
|
||||
Q_PROPERTY(QString macAddress READ macAddress)
|
||||
Q_PROPERTY(NetworkDeviceState state READ deviceState)
|
||||
Q_PROPERTY(QString bitRate READ bitRate)
|
||||
Q_PROPERTY(WirelessAccessPoint* currentAccessPoint READ activeAccessPoint)
|
||||
|
||||
public:
|
||||
|
||||
explicit WirelessNetworkDevice(const QDBusObjectPath &objectPath, QObject *parent = nullptr);
|
||||
|
||||
// Properties
|
||||
QString macAddress() const;
|
||||
int bitRate() const;
|
||||
WirelessAccessPoint *activeAccessPoint();
|
||||
|
||||
// Accesspoints
|
||||
QList<WirelessAccessPoint *> accessPoints();
|
||||
WirelessAccessPoint *getAccessPoint(const QString &ssid);
|
||||
WirelessAccessPoint *getAccessPoint(const QDBusObjectPath &objectPath);
|
||||
|
||||
// Methods
|
||||
void scanWirelessNetworks();
|
||||
|
||||
private:
|
||||
QDBusInterface *m_wirelessInterface;
|
||||
|
||||
QString m_macAddress;
|
||||
int m_bitRate = 0;
|
||||
WirelessAccessPoint *m_activeAccessPoint;
|
||||
QDBusObjectPath m_activeAccessPointObjectPath;
|
||||
|
||||
QHash<QDBusObjectPath, WirelessAccessPoint *> m_accessPointsTable;
|
||||
|
||||
void readAccessPoints();
|
||||
|
||||
void setMacAddress(const QString &macAddress);
|
||||
void setBitrate(const int &bitRate);
|
||||
void setActiveAccessPoint(const QDBusObjectPath &activeAccessPointObjectPath);
|
||||
|
||||
private slots:
|
||||
void accessPointAdded(const QDBusObjectPath &objectPath);
|
||||
void accessPointRemoved(const QDBusObjectPath &objectPath);
|
||||
void propertiesChanged(const QVariantMap &properties);
|
||||
|
||||
signals:
|
||||
void bitRateChanged(const bool &bitRate);
|
||||
void stateChanged(const NetworkDeviceState &state);
|
||||
};
|
||||
|
||||
QDebug operator<<(QDebug debug, WirelessNetworkDevice *device);
|
||||
|
||||
}
|
||||
|
||||
#endif // WIRELESSNETWORKMANAGER_H
|
||||
|
|
@ -33,7 +33,6 @@
|
|||
#include "platform/platform.h"
|
||||
#include "jsonrpc/jsonrpcserverimplementation.h"
|
||||
#include "ruleengine/ruleengine.h"
|
||||
#include "networkmanager/networkmanager.h"
|
||||
#include "nymeasettings.h"
|
||||
#include "tagging/tagsstorage.h"
|
||||
#include "platform/platform.h"
|
||||
|
|
@ -48,9 +47,12 @@
|
|||
#include "integrations/thingactioninfo.h"
|
||||
#include "integrations/browseractioninfo.h"
|
||||
#include "integrations/browseritemactioninfo.h"
|
||||
#include "cloud/cloudmanager.h"
|
||||
#include "cloud/cloudnotifications.h"
|
||||
#include "cloud/cloudtransport.h"
|
||||
|
||||
#include <networkmanager.h>
|
||||
|
||||
#include <QDir>
|
||||
#include <QCoreApplication>
|
||||
|
||||
|
|
@ -120,6 +122,7 @@ void NymeaCore::init() {
|
|||
|
||||
qCDebug(dcApplication) << "Creating Network Manager";
|
||||
m_networkManager = new NetworkManager(this);
|
||||
m_networkManager->start();
|
||||
|
||||
qCDebug(dcApplication) << "Creating Debug Server Handler";
|
||||
m_debugServerHandler = new DebugServerHandler(this);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,6 @@
|
|||
|
||||
#include "logging/logengine.h"
|
||||
#include "servermanager.h"
|
||||
#include "cloud/cloudmanager.h"
|
||||
|
||||
#include "time/timemanager.h"
|
||||
#include "hardwaremanagerimplementation.h"
|
||||
|
|
@ -53,11 +52,12 @@
|
|||
|
||||
class Thing;
|
||||
|
||||
class NetworkManager;
|
||||
|
||||
namespace nymeaserver {
|
||||
|
||||
class JsonRPCServerImplementation;
|
||||
class LogEngine;
|
||||
class NetworkManager;
|
||||
class NymeaConfiguration;
|
||||
class TagsStorage;
|
||||
class UserManager;
|
||||
|
|
@ -65,6 +65,7 @@ class Platform;
|
|||
class System;
|
||||
class ExperienceManager;
|
||||
class ScriptEngine;
|
||||
class CloudManager;
|
||||
|
||||
class NymeaCore : public QObject
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue