diff --git a/src/device.cpp b/src/device.cpp index 397d691..565240c 100644 --- a/src/device.cpp +++ b/src/device.cpp @@ -1,633 +1,639 @@ /* Copyright 2008,2010 Will Stephenson Copyright 2013 Daniel Nicoletti Copyright 2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "device_p.h" #include "manager.h" #include "manager_p.h" #include "connection.h" #include "settings.h" #include "nmdebug.h" #include #include // logging category for this framework, default: log stuff >= warning Q_LOGGING_CATEGORY(NMQT, "networkmanager-qt", QtWarningMsg) namespace NetworkManager { class DeviceStateReasonPrivate { public: DeviceStateReasonPrivate(Device::State st, Device::StateChangeReason rsn) : state(st) , reason(rsn) {} DeviceStateReasonPrivate() : state(Device::UnknownState) , reason(Device::UnknownReason) {} Device::State state; Device::StateChangeReason reason; }; } NetworkManager::DeviceStateReason::DeviceStateReason(Device::State state, Device::StateChangeReason reason) : d_ptr(new DeviceStateReasonPrivate(state, reason)) { } NetworkManager::DeviceStateReason::DeviceStateReason(const NetworkManager::DeviceStateReason &other) : d_ptr(new DeviceStateReasonPrivate(*other.d_ptr)) { } NetworkManager::DeviceStateReason::~DeviceStateReason() { delete d_ptr; } NetworkManager::Device::State NetworkManager::DeviceStateReason::state() const { Q_D(const DeviceStateReason); return d->state; } NetworkManager::Device::StateChangeReason NetworkManager::DeviceStateReason::reason() const { Q_D(const DeviceStateReason); return d->reason; } NetworkManager::DeviceStateReason &NetworkManager::DeviceStateReason::operator=(const NetworkManager::DeviceStateReason &other) { if (&other != this) { *d_ptr = *other.d_ptr; } return *this; } NetworkManager::DevicePrivate::DevicePrivate(const QString &path, NetworkManager::Device *q) #ifdef NMQT_STATIC : deviceIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus()) #else : deviceIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus()) #endif , uni(path) , designSpeed(0) , dhcp4Config(nullptr) , dhcp6Config(nullptr) , mtu(0) , q_ptr(q) { } NetworkManager::DevicePrivate::~DevicePrivate() { } void NetworkManager::DevicePrivate::init() { qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); qDBusRegisterMetaType(); // This needs to be initialized as soon as possible, because based on this property // we initialize the device type deviceType = convertType(deviceIface.deviceType()); deviceStatistics = DeviceStatistics::Ptr(new NetworkManager::DeviceStatistics(uni), &QObject::deleteLater); // Get all Device's properties at once QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(deviceIface.staticInterfaceName(), uni); if (!initialProperties.isEmpty()) { propertiesChanged(initialProperties); } QObject::connect(&deviceIface, &OrgFreedesktopNetworkManagerDeviceInterface::StateChanged, this, &DevicePrivate::deviceStateChanged); } NetworkManager::Device::MeteredStatus NetworkManager::DevicePrivate::convertMeteredStatus(uint metered) { NetworkManager::Device::MeteredStatus ourMeteredStatus = (NetworkManager::Device::MeteredStatus) metered; return ourMeteredStatus; } NetworkManager::Device::Capabilities NetworkManager::DevicePrivate::convertCapabilities(uint theirCaps) { NetworkManager::Device::Capabilities ourCaps = (NetworkManager::Device::Capabilities) theirCaps; return ourCaps; } NetworkManager::Device::State NetworkManager::DevicePrivate::convertState(uint theirState) { NetworkManager::Device::State ourState = static_cast(theirState); return ourState; } NetworkManager::Device::StateChangeReason NetworkManager::DevicePrivate::convertReason(uint theirReason) { NetworkManager::Device::StateChangeReason ourReason = (NetworkManager::Device::StateChangeReason)theirReason; return ourReason; } NetworkManager::Device::Type NetworkManager::DevicePrivate::convertType(uint type) { // These are identical to NM enums if (type <= NM_DEVICE_TYPE_TEAM) { return (NetworkManager::Device::Type)type; } switch (type) { case 16: // NM_DEVICE_TYPE_TUN return NetworkManager::Device::Tun; case 17: // NM_DEVICE_TYPE_IP_TUNNEL return NetworkManager::Device::IpTunnel; case 18: // NM_DEVICE_TYPE_MACVLAN return NetworkManager::Device::MacVlan; case 19: // NM_DEVICE_TYPE_VXLAN return NetworkManager::Device::VxLan; case 20: // NM_DEVICE_TYPE_VETH return NetworkManager::Device::Veth; case 21: // NM_DEVICE_TYPE_MACSEC return NetworkManager::Device::MacSec; case 22: // NM_DEVICE_TYPE_DUMMY return NetworkManager::Device::Dummy; case 23: // NM_DEVICE_TYPE_PPP return NetworkManager::Device::Ppp; case 24: // NM_DEVICE_TYPE_OVS_INTERFACE return NetworkManager::Device::OvsInterface; case 25: // NM_DEVICE_TYPE_OVS_PORT return NetworkManager::Device::OvsPort; case 26: // NM_DEVICE_TYPE_OVS_BRIDGE return NetworkManager::Device::OvsBridge; case 27: // NM_DEVICE_TYPE_WPAN return NetworkManager::Device::Wpan; case 28: // NM_DEVICE_TYPE_6LOWPAN return NetworkManager::Device::Lowpan; case 29: // NM_DEVICE_TYPE_NM_DEVICE_TYPE_WIREGUARD return NetworkManager::Device::WireGuard; case 30: // NM_DEVICE_TYPE_WIFI_P2P return NetworkManager::Device::WifiP2P; } return NetworkManager::Device::UnknownType; } NetworkManager::Device::Device(const QString &path, QObject *parent) : QObject(parent) , d_ptr(new DevicePrivate(path, this)) { Q_D(Device); d->init(); } NetworkManager::Device::Device(DevicePrivate &dd, QObject *parent) : QObject(parent) , d_ptr(&dd) { Q_D(Device); d->init(); } void NetworkManager::DevicePrivate::propertyChanged(const QString &property, const QVariant &value) { Q_Q(Device); // qCDebug(NMQT) << property << " - " << value; if (property == QLatin1String("ActiveConnection")) { // FIXME workaround, because NM doesn't Q_EMIT correct value // d->activeConnection = value.value.path(); activeConnection = deviceIface.activeConnection().path(); Q_EMIT q->activeConnectionChanged(); } else if (property == QLatin1String("Autoconnect")) { autoconnect = value.toBool(); Q_EMIT q->autoconnectChanged(); } else if (property == QLatin1String("AvailableConnections")) { QStringList newAvailableConnections; QList availableConnectionsTmp = qdbus_cast< QList >(value); Q_FOREACH (const QDBusObjectPath & availableConnection, availableConnectionsTmp) { newAvailableConnections << availableConnection.path(); if (!availableConnections.contains(availableConnection.path())) { availableConnections << availableConnection.path(); Q_EMIT q->availableConnectionAppeared(availableConnection.path()); } } Q_FOREACH (const QString & availableConnection, availableConnections) { if (!newAvailableConnections.contains(availableConnection)) { availableConnections.removeOne(availableConnection); Q_EMIT q->availableConnectionDisappeared(availableConnection); } } Q_EMIT q->availableConnectionChanged(); } else if (property == QLatin1String("Capabilities")) { capabilities = NetworkManager::DevicePrivate::convertCapabilities(value.toUInt()); Q_EMIT q->capabilitiesChanged(); } else if (property == QLatin1String("DeviceType")) { deviceType = static_cast(value.toUInt()); } else if (property == QLatin1String("Dhcp4Config")) { QDBusObjectPath dhcp4ConfigPathTmp = value.value(); if (dhcp4ConfigPathTmp.path().isNull()) { dhcp4Config.clear(); dhcp4ConfigPath.clear(); } else if (!dhcp4Config || dhcp4Config->path() != dhcp4ConfigPathTmp.path()) { dhcp4Config.clear(); dhcp4ConfigPath = dhcp4ConfigPathTmp.path(); } Q_EMIT q->dhcp4ConfigChanged(); } else if (property == QLatin1String("Dhcp6Config")) { QDBusObjectPath dhcp6ConfigPathTmp = value.value(); if (dhcp6ConfigPathTmp.path().isNull()) { dhcp6Config.clear(); dhcp6ConfigPath.clear(); } else if (!dhcp6Config || dhcp6Config->path() != dhcp6ConfigPathTmp.path()) { dhcp6Config.clear(); dhcp6ConfigPath = dhcp6ConfigPathTmp.path(); } Q_EMIT q->dhcp6ConfigChanged(); } else if (property == QLatin1String("Driver")) { driver = value.toString(); Q_EMIT q->driverChanged(); } else if (property == QLatin1String("DriverVersion")) { driverVersion = value.toString(); Q_EMIT q->driverVersionChanged(); } else if (property == QLatin1String("FirmwareMissing")) { firmwareMissing = value.toBool(); Q_EMIT q->firmwareMissingChanged(); } else if (property == QLatin1String("FirmwareVersion")) { firmwareVersion = value.toString(); Q_EMIT q->firmwareVersionChanged(); } else if (property == QLatin1String("Interface")) { interfaceName = value.toString(); Q_EMIT q->interfaceNameChanged(); } else if (property == QLatin1String("Ip4Address")) { ipV4Address = QHostAddress(ntohl(value.toUInt())); Q_EMIT q->ipV4AddressChanged(); } else if (property == QLatin1String("Ip4Config")) { QDBusObjectPath ip4ConfigObjectPathTmp = value.value(); if (ip4ConfigObjectPathTmp.path().isNull() || ip4ConfigObjectPathTmp.path() == QLatin1String("/")) { ipV4ConfigPath.clear(); } else { ipV4ConfigPath = ip4ConfigObjectPathTmp.path(); } ipV4Config = IpConfig(); Q_EMIT q->ipV4ConfigChanged(); } else if (property == QLatin1String("Ip6Config")) { QDBusObjectPath ip6ConfigObjectPathTmp = value.value(); if (ip6ConfigObjectPathTmp.path().isNull() || ip6ConfigObjectPathTmp.path() == QLatin1String("/")) { ipV6ConfigPath.clear(); } else { ipV6ConfigPath = ip6ConfigObjectPathTmp.path(); } ipV6Config = IpConfig(); Q_EMIT q->ipV6ConfigChanged(); } else if (property == QLatin1String("IpInterface")) { ipInterface = value.toString(); Q_EMIT q->ipInterfaceChanged(); } else if (property == QLatin1String("Managed")) { managed = value.toBool(); Q_EMIT q->managedChanged(); } else if (property == QLatin1String("State")) { connectionState = NetworkManager::DevicePrivate::convertState(value.toUInt()); // FIXME NetworkManager 0.9.8 (maybe greater) doesn't // update ActiveConnection when disconnected // This is fixed in NM 73d128bbd17120225bb4986e3f05566f10fab581 if (connectionState == NetworkManager::Device::Disconnected && activeConnection != QLatin1String("/")) { activeConnection = QLatin1Char('/'); Q_EMIT q->activeConnectionChanged(); } Q_EMIT q->connectionStateChanged(); } else if (property == QLatin1String("StateReason")) { // just extracting the reason reason = NetworkManager::DevicePrivate::convertReason(qdbus_cast(value).reason); Q_EMIT q->stateReasonChanged(); } else if (property == QLatin1String("Udi")) { udi = value.toString(); Q_EMIT q->udiChanged(); } else if (property == QLatin1String("PhysicalPortId")) { physicalPortId = value.toString(); Q_EMIT q->physicalPortIdChanged(); } else if (property == QLatin1String("Mtu")) { mtu = value.toUInt(); Q_EMIT q->mtuChanged(); } else if (property == QLatin1String("NmPluginMissing")) { nmPluginMissing = value.toBool(); Q_EMIT q->nmPluginMissingChanged(nmPluginMissing); } else if (property == QLatin1String("Metered")) { metered = NetworkManager::DevicePrivate::convertMeteredStatus(value.toUInt()); Q_EMIT q->meteredChanged(metered); } else { qCDebug(NMQT) << Q_FUNC_INFO << "Unhandled property" << property; } } NetworkManager::Device::~Device() { Q_D(Device); delete d; } QString NetworkManager::Device::uni() const { Q_D(const Device); return d->uni; } QString NetworkManager::Device::interfaceName() const { Q_D(const Device); return d->interfaceName; } QString NetworkManager::Device::ipInterfaceName() const { Q_D(const Device); return d->ipInterface; } QString NetworkManager::Device::driver() const { Q_D(const Device); return d->driver; } QString NetworkManager::Device::driverVersion() const { Q_D(const Device); return d->driverVersion; } QString NetworkManager::Device::firmwareVersion() const { Q_D(const Device); return d->firmwareVersion; } NetworkManager::ActiveConnection::Ptr NetworkManager::Device::activeConnection() const { Q_D(const Device); return NetworkManager::findActiveConnection(d->activeConnection); } NetworkManager::Connection::List NetworkManager::Device::availableConnections() { Q_D(const Device); NetworkManager::Connection::List list; Q_FOREACH (const QString & availableConnection, d->availableConnections) { NetworkManager::Connection::Ptr connection = NetworkManager::findConnection(availableConnection); if (connection) { list << connection; } } return list; } bool NetworkManager::Device::firmwareMissing() const { Q_D(const Device); return d->firmwareMissing; } bool NetworkManager::Device::autoconnect() const { Q_D(const Device); return d->autoconnect; } void NetworkManager::Device::setAutoconnect(bool autoconnect) { Q_D(Device); d->deviceIface.setAutoconnect(autoconnect); } QString NetworkManager::Device::udi() const { Q_D(const Device); return d->udi; } QString NetworkManager::Device::physicalPortId() const { Q_D(const Device); return d->physicalPortId; } QHostAddress NetworkManager::Device::ipV4Address() const { Q_D(const Device); return d->ipV4Address; } NetworkManager::DeviceStateReason NetworkManager::Device::stateReason() const { Q_D(const Device); return DeviceStateReason(d->connectionState, d->reason); } NetworkManager::IpConfig NetworkManager::Device::ipV4Config() const { Q_D(const Device); if (!d->ipV4Config.isValid() && !d->ipV4ConfigPath.isNull()) { d->ipV4Config.setIPv4Path(d->ipV4ConfigPath); } return d->ipV4Config; } NetworkManager::IpConfig NetworkManager::Device::ipV6Config() const { Q_D(const Device); if (!d->ipV6Config.isValid() && !d->ipV6ConfigPath.isNull()) { d->ipV6Config.setIPv6Path(d->ipV6ConfigPath); } return d->ipV6Config; } NetworkManager::Dhcp4Config::Ptr NetworkManager::Device::dhcp4Config() const { Q_D(const Device); if (!d->dhcp4Config && !d->dhcp4ConfigPath.isNull()) { d->dhcp4Config = NetworkManager::Dhcp4Config::Ptr(new Dhcp4Config(d->dhcp4ConfigPath), &QObject::deleteLater); } return d->dhcp4Config; } NetworkManager::Dhcp6Config::Ptr NetworkManager::Device::dhcp6Config() const { Q_D(const Device); if (!d->dhcp6Config && !d->dhcp6ConfigPath.isNull()) { d->dhcp6Config = NetworkManager::Dhcp6Config::Ptr(new Dhcp6Config(d->dhcp6ConfigPath), &QObject::deleteLater); } return d->dhcp6Config; } bool NetworkManager::Device::isActive() const { Q_D(const Device); return !(d->connectionState == NetworkManager::Device::Unavailable || d->connectionState == NetworkManager::Device::Unmanaged || d->connectionState == NetworkManager::Device::Disconnected || d->connectionState == NetworkManager::Device::Failed); } bool NetworkManager::Device::isValid() const { Q_D(const Device); return d->deviceIface.isValid(); } bool NetworkManager::Device::managed() const { Q_D(const Device); return d->managed; } uint NetworkManager::Device::mtu() const { Q_D(const Device); return d->mtu; } bool NetworkManager::Device::nmPluginMissing() const { Q_D(const Device); return d->nmPluginMissing; } NetworkManager::Device::MeteredStatus NetworkManager::Device::metered() const { Q_D(const Device); return d->metered; } +QDBusPendingReply<> NetworkManager::Device::reapplyConnection(const NMVariantMapMap &connection, qulonglong version_id, uint flags) +{ + Q_D(Device); + return d->deviceIface.Reapply(connection, version_id, flags); +} + QDBusPendingReply<> NetworkManager::Device::disconnectInterface() { Q_D(Device); return d->deviceIface.Disconnect(); } QDBusPendingReply<> NetworkManager::Device::deleteInterface() { if (NetworkManager::checkVersion(1, 0, 0)) { Q_D(Device); return d->deviceIface.Delete(); } else { return QDBusPendingReply<>(); } } NetworkManager::Device::State NetworkManager::Device::state() const { Q_D(const Device); return d->connectionState; } int NetworkManager::Device::designSpeed() const { Q_D(const Device); return d->designSpeed; } NetworkManager::Device::Capabilities NetworkManager::Device::capabilities() const { Q_D(const Device); return d->capabilities; } QVariant NetworkManager::Device::capabilitiesV() const { Q_D(const Device); return QVariant(d->capabilities); } NetworkManager::DeviceStatistics::Ptr NetworkManager::Device::deviceStatistics() const { Q_D(const Device); return d->deviceStatistics; } void NetworkManager::DevicePrivate::deviceStateChanged(uint newState, uint oldState, uint reason) { Q_Q(Device); connectionState = NetworkManager::DevicePrivate::convertState(newState); reason = NetworkManager::DevicePrivate::convertReason(reason); Q_EMIT q->stateChanged(connectionState, NetworkManager::DevicePrivate::convertState(oldState), NetworkManager::DevicePrivate::convertReason(reason)); } void NetworkManager::DevicePrivate::dbusPropertiesChanged(const QString &interfaceName, const QVariantMap &properties, const QStringList &invalidatedProperties) { Q_UNUSED(invalidatedProperties); if (interfaceName.contains(QLatin1String("org.freedesktop.NetworkManager.Device")) && interfaceName != QLatin1String("org.freedesktop.NetworkManager.Device.Statistics")) { propertiesChanged(properties); } } void NetworkManager::DevicePrivate::propertiesChanged(const QVariantMap &properties) { // qCDebug(NMQT) << Q_FUNC_INFO << properties; QVariantMap::const_iterator it = properties.constBegin(); while (it != properties.constEnd()) { propertyChanged(it.key(), it.value()); ++it; } // FIXME workaround, we need to get a path to updated IPv[46]Config, // because NM doesn't Q_EMIT the updated value when the device is activated // BUG: https://bugzilla.gnome.org/show_bug.cgi?id=725657 if (properties.contains(QLatin1String("State")) && connectionState == NetworkManager::Device::Activated) { propertyChanged(QLatin1String("Ip4Config"), QVariant::fromValue(deviceIface.ip4Config())); propertyChanged(QLatin1String("Ip6Config"), QVariant::fromValue(deviceIface.ip6Config())); } } NetworkManager::Device::Type NetworkManager::Device::type() const { Q_D(const Device); return d->deviceType; } diff --git a/src/device.h b/src/device.h index 29c42d4..c1669a2 100644 --- a/src/device.h +++ b/src/device.h @@ -1,589 +1,593 @@ /* Copyright 2008,2011 Will Stephenson Copyright 2011-2013 Lamarque V. Souza Copyright 2013 Daniel Nicoletti Copyright 2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library 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 Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef NETWORKMANAGERQT_DEVICE_H #define NETWORKMANAGERQT_DEVICE_H #include #include #include #include #include "generictypes.h" #include "ipconfig.h" #include "dhcp4config.h" #include "dhcp6config.h" #include "activeconnection.h" #include "devicestatistics.h" namespace NetworkManager { class DevicePrivate; class DeviceStateReason; class DeviceStateReasonPrivate; /** * This class represents a common device interface */ class NETWORKMANAGERQT_EXPORT Device : public QObject { Q_OBJECT Q_PROPERTY(QString uni READ uni) Q_PROPERTY(QString interfaceName READ interfaceName) Q_PROPERTY(QString ipInterfaceName READ ipInterfaceName) Q_PROPERTY(QString driver READ driver) Q_PROPERTY(QString driverVersion READ driverVersion) Q_PROPERTY(QString firmwareVersion READ firmwareVersion) Q_PROPERTY(QVariant genericCapabilities READ capabilitiesV) Q_PROPERTY(QHostAddress ipV4Address READ ipV4Address) Q_PROPERTY(bool managed READ managed) Q_PROPERTY(uint mtu READ mtu) Q_PROPERTY(bool nmPluginMissing READ nmPluginMissing) Q_PROPERTY(MeteredStatus metered READ metered) Q_PROPERTY(QString udi READ udi) Q_PROPERTY(bool firmwareMissing READ firmwareMissing) Q_PROPERTY(bool autoconnect READ autoconnect WRITE setAutoconnect) Q_PROPERTY(DeviceStateReason stateReason READ stateReason) Q_PROPERTY(State state READ state) Q_PROPERTY(NetworkManager::DeviceStatistics::Ptr deviceStatistics READ deviceStatistics) public: typedef QSharedPointer Ptr; typedef QList List; /** * Device connection states describe the possible states of a * network connection from the user's point of view. For * simplicity, states from several different layers are present - * this is a high level view */ enum State { UnknownState = 0, /**< The device is in an unknown state */ Unmanaged = 10, /**< The device is recognized but not managed by NetworkManager */ Unavailable = 20, /**< The device cannot be used (carrier off, rfkill, etc) */ Disconnected = 30, /**< The device is not connected */ Preparing = 40, /**< The device is preparing to connect */ ConfiguringHardware = 50, /**< The device is being configured */ NeedAuth = 60, /**< The device is awaiting secrets necessary to continue connection */ ConfiguringIp = 70, /**< The IP settings of the device are being requested and configured */ CheckingIp = 80, /**< The device's IP connectivity ability is being determined */ WaitingForSecondaries = 90, /**< The device is waiting for secondary connections to be activated */ Activated = 100, /**< The device is active */ Deactivating = 110, /**< The device's network connection is being torn down */ Failed = 120 /**< The device is in a failure state following an attempt to activate it */ }; Q_ENUM(State) /** * Enums describing the reason for a connection state change * @note StateChangeReasons NewActivation, ParentChanged, ParentManagedChanged are available in runtime NM >= 1.0.4 */ enum StateChangeReason { UnknownReason = 0, NoReason = 1 , NowManagedReason = 2, NowUnmanagedReason = 3, ConfigFailedReason = 4, ConfigUnavailableReason = 5, ConfigExpiredReason = 6, NoSecretsReason = 7, AuthSupplicantDisconnectReason = 8, AuthSupplicantConfigFailedReason = 9, AuthSupplicantFailedReason = 10, AuthSupplicantTimeoutReason = 11, PppStartFailedReason = 12, PppDisconnectReason = 13, PppFailedReason = 14, DhcpStartFailedReason = 15, DhcpErrorReason = 16, DhcpFailedReason = 17, SharedStartFailedReason = 18, SharedFailedReason = 19, AutoIpStartFailedReason = 20, AutoIpErrorReason = 21, AutoIpFailedReason = 22, ModemBusyReason = 23, ModemNoDialToneReason = 24, ModemNoCarrierReason = 25, ModemDialTimeoutReason = 26, ModemDialFailedReason = 27, ModemInitFailedReason = 28, GsmApnSelectFailedReason = 29, GsmNotSearchingReason = 30, GsmRegistrationDeniedReason = 31, GsmRegistrationTimeoutReason = 32, GsmRegistrationFailedReason = 33, GsmPinCheckFailedReason = 34, FirmwareMissingReason = 35, DeviceRemovedReason = 36, SleepingReason = 37, ConnectionRemovedReason = 38, UserRequestedReason = 39, CarrierReason = 40, ConnectionAssumedReason = 41, SupplicantAvailableReason = 42, ModemNotFoundReason = 43, BluetoothFailedReason = 44, GsmSimNotInserted = 45, GsmSimPinRequired = 46, GsmSimPukRequired = 47, GsmSimWrong = 48 , InfiniBandMode = 49, DependencyFailed = 50, Br2684Failed = 51, ModemManagerUnavailable = 52, SsidNotFound = 53, SecondaryConnectionFailed = 54, DcbFcoeFailed = 55, TeamdControlFailed = 56, ModemFailed = 57, ModemAvailable = 58, SimPinIncorrect = 59, NewActivation = 60, ParentChanged = 61, ParentManagedChanged = 62, Reserved = 65536 }; Q_ENUM(StateChangeReason) enum MeteredStatus { UnknownStatus = 0, /**< The device metered status is unknown. */ Yes = 1, /**< The device is metered and the value was statically set. */ No = 2, /**< The device is not metered and the value was statically set. */ GuessYes = 3, /**< The device is metered and the value was guessed. */ GuessNo = 4 /**< The device is not metered and the value was guessed. */ }; Q_ENUM(MeteredStatus) /** * Possible device capabilities */ enum Capability { IsManageable = 0x1, /**< denotes that the device can be controlled by this API */ SupportsCarrierDetect = 0x2 /**< the device informs us when it is plugged in to the medium */ }; Q_ENUM(Capability) Q_DECLARE_FLAGS(Capabilities, Capability) Q_FLAG(Capabilities) /** * Device type */ enum Type { UnknownType = NM_DEVICE_TYPE_UNKNOWN, /**< Unknown device type */ Ethernet = NM_DEVICE_TYPE_ETHERNET, /**< Ieee8023 wired ethernet */ Wifi = NM_DEVICE_TYPE_WIFI, /**< the Ieee80211 family of wireless networks */ Unused1 = NM_DEVICE_TYPE_UNUSED1, /**< Currently unused */ Unused2 = NM_DEVICE_TYPE_UNUSED2, /**< Currently unused */ Bluetooth = NM_DEVICE_TYPE_BT, /**< network bluetooth device (usually a cell phone) */ OlpcMesh = NM_DEVICE_TYPE_OLPC_MESH, /**< OLPC Mesh networking device */ Wimax = NM_DEVICE_TYPE_WIMAX, /**< WiMax WWAN technology */ Modem = NM_DEVICE_TYPE_MODEM, /**< POTS, GSM, CDMA or LTE modems */ InfiniBand = NM_DEVICE_TYPE_INFINIBAND, /**< Infiniband network device */ Bond = NM_DEVICE_TYPE_BOND, /**< Bond virtual device */ Vlan = NM_DEVICE_TYPE_VLAN, /**< Vlan virtual device */ Adsl = NM_DEVICE_TYPE_ADSL, /**< ADSL modem device */ Bridge = NM_DEVICE_TYPE_BRIDGE, /**< Bridge virtual device */ Generic = NM_DEVICE_TYPE_GENERIC, /**< Generic device @since 1.0.0 */ Team = NM_DEVICE_TYPE_TEAM, /**< Team master device @since 1.0.0 */ Gre, /**< Gre virtual device @since 1.2.0, @deprecated use IpTunnel instead*/ MacVlan, /**< MacVlan virtual device @since 1.2.0 */ Tun, /**< Tun virtual device @since 1.2.0 */ Veth, /**< Veth virtual device @since 1.2.0 */ IpTunnel, /**< IP Tunneling Device @since 1.2.0 */ VxLan, /**< Vxlan Device @since 1.2.0 */ MacSec, /**< MacSec Device @since 1.6.0 */ Dummy, /**< Dummy Device @since 1.8.0 */ Ppp, /**< Ppp Device @since 1.10 */ OvsInterface, /**< OvsInterface Device @since 1.10 */ OvsPort, /**< OvsPort Device @since 1.10 */ OvsBridge, /**< OvsBridge Device @since 1.10 */ Wpan, /**< Wpan Device @since 1.14 */ Lowpan, /**< Lowpan Device @since 1.14 */ WireGuard, /**< WireGuard Device @since 1.14 */ WifiP2P /**< WifiP2P Device @since 1.16 */ }; Q_ENUM(Type) Q_DECLARE_FLAGS(Types, Type) Q_FLAG(Types) /** * Creates a new device object. * * @param path UNI of the device */ explicit Device(const QString &path, QObject *parent = nullptr); Device(DevicePrivate &dd, QObject *parent); /** * Destroys a device object. */ virtual ~Device(); /** * Retrieves the interface type. This is a virtual function that will return the * proper type of all sub-classes. * * @returns the NetworkManager::Device::Type that corresponds to this device. */ virtual Type type() const; /** * Retrieves the Unique Network Identifier (UNI) of the device. * This identifier is unique for each network and network interface in the system. * * @returns the Unique Network Identifier of the current device */ QString uni() const; /** * The current active connection for this device * * @returns A valid ActiveConnection object or NULL if no active connection was found */ NetworkManager::ActiveConnection::Ptr activeConnection() const; /** * Returns available connections for this device * * @returns List of availables connection */ Connection::List availableConnections(); /** * The system name for the network device */ QString interfaceName() const; /** * The name of the device's data interface when available. This property * may not refer to the actual data interface until the device has * successfully established a data connection, indicated by the device's * state() becoming ACTIVATED. */ QString ipInterfaceName() const; /** * Handle for the system driver controlling this network interface */ QString driver() const; /** * The driver version. */ QString driverVersion() const; /** * The firmware version. */ QString firmwareVersion() const; + /** + * Reapplies connection settings on the interface. + */ + QDBusPendingReply<> reapplyConnection(const NMVariantMapMap &connection, qulonglong version_id, uint flags); /** * Disconnects a device and prevents the device from automatically * activating further connections without user intervention. */ QDBusPendingReply<> disconnectInterface(); /** * Deletes a software device from NetworkManager and removes the interface from the system. * The method returns an error when called for a hardware device. * * @since 5.8.0 * */ QDBusPendingReply<> deleteInterface(); /** * returns the current IPv4 address without the prefix * \sa ipV4Config() * \sa ipV6Config() * @deprecated */ QHostAddress ipV4Address() const; /** * Get the current IPv4 configuration of this device. * Only valid when device is Activated. */ IpConfig ipV4Config() const; /** * Get the current IPv6 configuration of this device. * Only valid when device is Activated. */ IpConfig ipV6Config() const; /** * Get the DHCP options returned by the DHCP server * or a null pointer if the device is not Activated or does not * use DHCP configuration. */ Dhcp4Config::Ptr dhcp4Config() const; /** * Get the DHCP options returned by the DHCP server * or a null pointer if the device is not Activated or does not * use DHCP configuration. */ Dhcp6Config::Ptr dhcp6Config() const; /** * Retrieves the activation status of this network interface. * * @return true if this network interface is active, false otherwise */ bool isActive() const; /** * Retrieves the device is valid. * * @return true if this device interface is valid, false otherwise */ bool isValid() const; /** * Retrieves the current state of the device. * This is a high level view of the device. It is user oriented, so * actually it provides state coming from different layers. * * @return the current connection state * @see Device::State */ State state() const; /** * Retrieves the maximum speed as reported by the device. * Note that this is only a design related piece of information, and that * the device might not reach this maximum. * * @return the device's maximum speed */ int designSpeed() const; /** * Retrieves the capabilities supported by this device. * * @return the capabilities of the device */ Capabilities capabilities() const; QVariant capabilitiesV() const; /** * Is the device currently being managed by NetworkManager? */ bool managed() const; /** * Is the firmware needed by the device missing? */ bool firmwareMissing() const; /** * If the device is allowed to autoconnect. */ bool autoconnect() const; /** * The current state and reason for changing to that state. */ DeviceStateReason stateReason() const; /** * Retrieves the Unique Device Identifier (UDI) of the device. * This identifier is unique for each device in the system. */ QString udi() const; /** * @return If non-empty, an (opaque) indicator of the physical network * port associated with the device. This can be used to recognize * when two seemingly-separate hardware devices are actually just * different virtual interfaces to the same physical port. * * @since 0.9.9.0 */ QString physicalPortId() const; /** * The device MTU (maximum transmission unit) * @since 0.9.9.0 * */ uint mtu() const; /** * @return If TRUE, indicates the NetworkManager plugin for the device is likely * missing or misconfigured. * @since 5.14.0 */ bool nmPluginMissing() const; /** * @return Whether the amount of traffic flowing through the device is * subject to limitations, for example set by service providers. * @since 5.14.0 */ MeteredStatus metered() const; /** * If true, indicates the device is allowed to autoconnect. * If false, manual intervention is required before the device * will automatically connect to a known network, such as activating * a connection using the device, or setting this property to @p true. */ void setAutoconnect(bool autoconnect); /** * Returns Device Statistics interface */ DeviceStatistics::Ptr deviceStatistics() const; /** * Retrieves a specialized interface to interact with the device corresponding * to a given device interface. * * @returns a pointer to the device interface if it exists, @p 0 otherwise */ template DevIface *as() { return qobject_cast(this); } /** * Retrieves a specialized interface to interact with the device corresponding * to a given device interface. * * @returns a pointer to the device interface if it exists, 0 otherwise */ template const DevIface *as() const { return qobject_cast(this); } Q_SIGNALS: /** * This signal is emitted when the device's link status changed. * * @param newstate the new state of the connection * @param oldstate the previous state of the connection * @param reason the reason for the state change, if any. ReasonNone where the backend * provides no reason. * @see Device::State * @see Device::StateChangeReason */ void stateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason); /** * Emitted when the autoconnect of this network has changed. */ void activeConnectionChanged(); /** * Emitted when the autoconnect of this network has changed. */ void autoconnectChanged(); /** * Emitted when the list of avaiable connections of this network has changed. */ void availableConnectionChanged(); /** * Emitted when a new connection is available */ void availableConnectionAppeared(const QString &connection); /** * Emitted when the connection is no longer available */ void availableConnectionDisappeared(const QString &connection); /** * Emitted when the capabilities of this network has changed. */ void capabilitiesChanged(); /** * Emitted when the DHCP configuration for IPv4 of this network has changed. */ void dhcp4ConfigChanged(); /** * Emitted when the DHCP configuration for IPv6 of this network has changed. */ void dhcp6ConfigChanged(); /** * Emitted when the driver of this network has changed. */ void driverChanged(); /** * Emitted when the driver version of this network has changed. */ void driverVersionChanged(); /** * Emitted when the firmware missing state of this network has changed. */ void firmwareMissingChanged(); /** * Emitted when the firmware version of this network has changed. */ void firmwareVersionChanged(); /** * Emitted when the interface name of this network has changed. */ void interfaceNameChanged(); /** * Emitted when the IPv4 address of this network has changed. */ void ipV4AddressChanged(); /** * Emitted when the IPv4 configuration of this network has changed. */ void ipV4ConfigChanged(); /** * Emitted when the IPv6 configuration of this network has changed. */ void ipV6ConfigChanged(); /** * Emitted when the ip interface name of this network has changed. */ void ipInterfaceChanged(); /** * Emitted when the managed state of this network has changed. */ void managedChanged(); /** * Emitted when the physical port ID changes. * @see physicalPortId() * @since 0.9.9.0 */ void physicalPortIdChanged(); /** * Emitted when the maximum transmission unit has changed * @since 0.9.9.0 */ void mtuChanged(); /** * Emitted when NmPluginMissing property has changed * @since 5.14.0 * @see nmPluginMissing */ void nmPluginMissingChanged(bool nmPluginMissing); /** * Emitted when metered property has changed * @since 5.14.0 * @see metered */ void meteredChanged(MeteredStatus metered); /** * Emitted when the connection state of this network has changed. */ void connectionStateChanged(); /** * Emitted when the state reason of this network has changed. */ void stateReasonChanged(); /** * Emitted when the Unique Device Identifier of this device has changed. */ void udiChanged(); protected: DevicePrivate *const d_ptr; private: Q_DECLARE_PRIVATE(Device) }; Q_DECLARE_OPERATORS_FOR_FLAGS(Device::Capabilities) Q_DECLARE_OPERATORS_FOR_FLAGS(Device::Types) class NETWORKMANAGERQT_EXPORT DeviceStateReason { public: DeviceStateReason(Device::State state, Device::StateChangeReason reason); DeviceStateReason(const DeviceStateReason &); ~DeviceStateReason(); Device::State state() const; Device::StateChangeReason reason() const; DeviceStateReason &operator=(const DeviceStateReason &); private: Q_DECLARE_PRIVATE(DeviceStateReason) DeviceStateReasonPrivate *const d_ptr; }; } #endif