1/*
2 SPDX-FileCopyrightText: 2008, 2011 Will Stephenson <wstephenson@kde.org>
3 SPDX-FileCopyrightText: 2011-2013 Lamarque V. Souza <lamarque@kde.org>
4 SPDX-FileCopyrightText: 2013 Daniel Nicoletti <dantti12@gmail.com>
5 SPDX-FileCopyrightText: 2013 Jan Grulich <jgrulich@redhat.com>
6
7 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
8*/
9
10#ifndef NETWORKMANAGERQT_DEVICE_H
11#define NETWORKMANAGERQT_DEVICE_H
12
13#include <QObject>
14#include <QSharedPointer>
15
16#include "activeconnection.h"
17#include "devicestatistics.h"
18#include "dhcp4config.h"
19#include "dhcp6config.h"
20#include "generictypes.h"
21#include "ipconfig.h"
22#include <networkmanagerqt/networkmanagerqt_export.h>
23
24namespace NetworkManager
25{
26class DevicePrivate;
27class DeviceStateReason;
28class DeviceStateReasonPrivate;
29
30/**
31 * This class represents a common device interface
32 */
33class NETWORKMANAGERQT_EXPORT Device : public QObject
34{
35 Q_OBJECT
36
37 Q_PROPERTY(QString uni READ uni)
38 Q_PROPERTY(QString interfaceName READ interfaceName)
39 Q_PROPERTY(QString ipInterfaceName READ ipInterfaceName)
40 Q_PROPERTY(QString driver READ driver)
41 Q_PROPERTY(QString driverVersion READ driverVersion)
42 Q_PROPERTY(QString firmwareVersion READ firmwareVersion)
43 Q_PROPERTY(QVariant genericCapabilities READ capabilitiesV)
44 Q_PROPERTY(QHostAddress ipV4Address READ ipV4Address)
45 Q_PROPERTY(bool managed READ managed)
46 Q_PROPERTY(uint mtu READ mtu)
47 Q_PROPERTY(Interfaceflags InterfaceFlags READ interfaceFlags)
48 Q_PROPERTY(bool nmPluginMissing READ nmPluginMissing)
49 Q_PROPERTY(MeteredStatus metered READ metered)
50 Q_PROPERTY(QString udi READ udi)
51 Q_PROPERTY(bool firmwareMissing READ firmwareMissing)
52 Q_PROPERTY(bool autoconnect READ autoconnect WRITE setAutoconnect)
53 Q_PROPERTY(DeviceStateReason stateReason READ stateReason)
54 Q_PROPERTY(State state READ state)
55 Q_PROPERTY(NetworkManager::DeviceStatistics::Ptr deviceStatistics READ deviceStatistics)
56
57public:
58 typedef QSharedPointer<Device> Ptr;
59 typedef QList<Ptr> List;
60 /**
61 * Device connection states describe the possible states of a
62 * network connection from the user's point of view. For
63 * simplicity, states from several different layers are present -
64 * this is a high level view
65 */
66 enum State {
67 UnknownState = 0, /**< The device is in an unknown state */
68 Unmanaged = 10, /**< The device is recognized but not managed by NetworkManager */
69 Unavailable = 20, /**< The device cannot be used (carrier off, rfkill, etc) */
70 Disconnected = 30, /**< The device is not connected */
71 Preparing = 40, /**< The device is preparing to connect */
72 ConfiguringHardware = 50, /**< The device is being configured */
73 NeedAuth = 60, /**< The device is awaiting secrets necessary to continue connection */
74 ConfiguringIp = 70, /**< The IP settings of the device are being requested and configured */
75 CheckingIp = 80, /**< The device's IP connectivity ability is being determined */
76 WaitingForSecondaries = 90, /**< The device is waiting for secondary connections to be activated */
77 Activated = 100, /**< The device is active */
78 Deactivating = 110, /**< The device's network connection is being torn down */
79 Failed = 120, /**< The device is in a failure state following an attempt to activate it */
80 };
81 Q_ENUM(State)
82
83 /**
84 * Enums describing the reason for a connection state change
85 * @note StateChangeReasons NewActivation, ParentChanged, ParentManagedChanged are available in runtime NM >= 1.0.4
86 */
87 enum StateChangeReason {
88 UnknownReason = 0,
89 NoReason = 1,
90 NowManagedReason = 2,
91 NowUnmanagedReason = 3,
92 ConfigFailedReason = 4,
93 ConfigUnavailableReason = 5,
94 ConfigExpiredReason = 6,
95 NoSecretsReason = 7,
96 AuthSupplicantDisconnectReason = 8,
97 AuthSupplicantConfigFailedReason = 9,
98 AuthSupplicantFailedReason = 10,
99 AuthSupplicantTimeoutReason = 11,
100 PppStartFailedReason = 12,
101 PppDisconnectReason = 13,
102 PppFailedReason = 14,
103 DhcpStartFailedReason = 15,
104 DhcpErrorReason = 16,
105 DhcpFailedReason = 17,
106 SharedStartFailedReason = 18,
107 SharedFailedReason = 19,
108 AutoIpStartFailedReason = 20,
109 AutoIpErrorReason = 21,
110 AutoIpFailedReason = 22,
111 ModemBusyReason = 23,
112 ModemNoDialToneReason = 24,
113 ModemNoCarrierReason = 25,
114 ModemDialTimeoutReason = 26,
115 ModemDialFailedReason = 27,
116 ModemInitFailedReason = 28,
117 GsmApnSelectFailedReason = 29,
118 GsmNotSearchingReason = 30,
119 GsmRegistrationDeniedReason = 31,
120 GsmRegistrationTimeoutReason = 32,
121 GsmRegistrationFailedReason = 33,
122 GsmPinCheckFailedReason = 34,
123 FirmwareMissingReason = 35,
124 DeviceRemovedReason = 36,
125 SleepingReason = 37,
126 ConnectionRemovedReason = 38,
127 UserRequestedReason = 39,
128 CarrierReason = 40,
129 ConnectionAssumedReason = 41,
130 SupplicantAvailableReason = 42,
131 ModemNotFoundReason = 43,
132 BluetoothFailedReason = 44,
133 GsmSimNotInserted = 45,
134 GsmSimPinRequired = 46,
135 GsmSimPukRequired = 47,
136 GsmSimWrong = 48,
137 InfiniBandMode = 49,
138 DependencyFailed = 50,
139 Br2684Failed = 51,
140 ModemManagerUnavailable = 52,
141 SsidNotFound = 53,
142 SecondaryConnectionFailed = 54,
143 DcbFcoeFailed = 55,
144 TeamdControlFailed = 56,
145 ModemFailed = 57,
146 ModemAvailable = 58,
147 SimPinIncorrect = 59,
148 NewActivation = 60,
149 ParentChanged = 61,
150 ParentManagedChanged = 62,
151 Reserved = 65536,
152 };
153 Q_ENUM(StateChangeReason)
154
155 enum MeteredStatus {
156 UnknownStatus = 0, /**< The device metered status is unknown. */
157 Yes = 1, /**< The device is metered and the value was statically set. */
158 No = 2, /**< The device is not metered and the value was statically set. */
159 GuessYes = 3, /**< The device is metered and the value was guessed. */
160 GuessNo = 4, /**< The device is not metered and the value was guessed. */
161 };
162 Q_ENUM(MeteredStatus)
163
164 /**
165 * Possible device capabilities
166 */
167 enum Capability {
168 IsManageable = 0x1, /**< denotes that the device can be controlled by this API */
169 SupportsCarrierDetect = 0x2, /**< the device informs us when it is plugged in to the medium */
170 };
171 Q_ENUM(Capability)
172 Q_DECLARE_FLAGS(Capabilities, Capability)
173 Q_FLAG(Capabilities)
174
175 /**
176 * Possible device interfaceflags
177 */
178 enum Interfaceflag {
179 None = NM_DEVICE_INTERFACE_FLAG_NONE, /**< no flags set */
180 Up = NM_DEVICE_INTERFACE_FLAG_UP, /**< Corresponds to kernel IFF_UP */
181 LowerUp = NM_DEVICE_INTERFACE_FLAG_LOWER_UP, /**< Corresponds to kernel IFF_LOWER_UP */
182 Carrier = NM_DEVICE_INTERFACE_FLAG_CARRIER /**< the interface has carrier */
183 };
184 Q_ENUM(Interfaceflag)
185 Q_DECLARE_FLAGS(Interfaceflags, Interfaceflag)
186 Q_FLAG(Interfaceflags)
187
188 /**
189 * Device type
190 */
191 enum Type {
192 UnknownType = NM_DEVICE_TYPE_UNKNOWN, /**< Unknown device type */
193 Ethernet = NM_DEVICE_TYPE_ETHERNET, /**< Ieee8023 wired ethernet */
194 Wifi = NM_DEVICE_TYPE_WIFI, /**< the Ieee80211 family of wireless networks */
195 Unused1 = NM_DEVICE_TYPE_UNUSED1, /**< Currently unused */
196 Unused2 = NM_DEVICE_TYPE_UNUSED2, /**< Currently unused */
197 Bluetooth = NM_DEVICE_TYPE_BT, /**< network bluetooth device (usually a cell phone) */
198 OlpcMesh = NM_DEVICE_TYPE_OLPC_MESH, /**< OLPC Mesh networking device */
199 Wimax = NM_DEVICE_TYPE_WIMAX, /**< WiMax WWAN technology */
200 Modem = NM_DEVICE_TYPE_MODEM, /**< POTS, GSM, CDMA or LTE modems */
201 InfiniBand = NM_DEVICE_TYPE_INFINIBAND, /**< Infiniband network device */
202 Bond = NM_DEVICE_TYPE_BOND, /**< Bond virtual device */
203 Vlan = NM_DEVICE_TYPE_VLAN, /**< Vlan virtual device */
204 Adsl = NM_DEVICE_TYPE_ADSL, /**< ADSL modem device */
205 Bridge = NM_DEVICE_TYPE_BRIDGE, /**< Bridge virtual device */
206 Generic = NM_DEVICE_TYPE_GENERIC, /**< Generic device @since 1.0.0 */
207 Team = NM_DEVICE_TYPE_TEAM, /**< Team master device @since 1.0.0 */
208 Gre, /**< Gre virtual device @since 1.2.0, @deprecated use IpTunnel instead*/
209 MacVlan, /**< MacVlan virtual device @since 1.2.0 */
210 Tun, /**< Tun virtual device @since 1.2.0 */
211 Veth, /**< Veth virtual device @since 1.2.0 */
212 IpTunnel, /**< IP Tunneling Device @since 1.2.0 */
213 VxLan, /**< Vxlan Device @since 1.2.0 */
214 MacSec, /**< MacSec Device @since 1.6.0 */
215 Dummy, /**< Dummy Device @since 1.8.0 */
216 Ppp, /**< Ppp Device @since 1.10 */
217 OvsInterface, /**< OvsInterface Device @since 1.10 */
218 OvsPort, /**< OvsPort Device @since 1.10 */
219 OvsBridge, /**< OvsBridge Device @since 1.10 */
220 Wpan, /**< Wpan Device @since 1.14 */
221 Lowpan, /**< Lowpan Device @since 1.14 */
222 WireGuard, /**< WireGuard Device @since 1.14 */
223 WifiP2P, /**< WifiP2P Device @since 1.16 */
224 };
225 Q_ENUM(Type)
226 Q_DECLARE_FLAGS(Types, Type)
227 Q_FLAG(Types)
228
229 /**
230 * Creates a new device object.
231 *
232 * @param path UNI of the device
233 */
234 explicit Device(const QString &path, QObject *parent = nullptr);
235 /**
236 * Destroys a device object.
237 */
238 ~Device() override;
239 /**
240 * Retrieves the interface type. This is a virtual function that will return the
241 * proper type of all sub-classes.
242 *
243 * @returns the NetworkManager::Device::Type that corresponds to this device.
244 */
245 virtual Type type() const;
246 /**
247 * Retrieves the Unique Network Identifier (UNI) of the device.
248 * This identifier is unique for each network and network interface in the system.
249 *
250 * @returns the Unique Network Identifier of the current device
251 */
252 QString uni() const;
253 /**
254 * The current active connection for this device
255 *
256 * @returns A valid ActiveConnection object or NULL if no active connection was found
257 */
258 NetworkManager::ActiveConnection::Ptr activeConnection() const;
259 /**
260 * Returns available connections for this device
261 *
262 * @returns List of availables connection
263 */
264 Connection::List availableConnections();
265 /**
266 * The system name for the network device
267 */
268 QString interfaceName() const;
269 /**
270 * The name of the device's data interface when available. This property
271 * may not refer to the actual data interface until the device has
272 * successfully established a data connection, indicated by the device's
273 * state() becoming ACTIVATED.
274 */
275 QString ipInterfaceName() const;
276 /**
277 * Handle for the system driver controlling this network interface
278 */
279 QString driver() const;
280 /**
281 * The driver version.
282 */
283 QString driverVersion() const;
284 /**
285 * The firmware version.
286 */
287 QString firmwareVersion() const;
288 /**
289 * Reapplies connection settings on the interface.
290 */
291 QDBusPendingReply<> reapplyConnection(const NMVariantMapMap &connection, qulonglong version_id, uint flags);
292 /**
293 * Disconnects a device and prevents the device from automatically
294 * activating further connections without user intervention.
295 */
296 QDBusPendingReply<> disconnectInterface();
297 /**
298 * Deletes a software device from NetworkManager and removes the interface from the system.
299 * The method returns an error when called for a hardware device.
300 *
301 * @since 5.8.0
302 *
303 */
304 QDBusPendingReply<> deleteInterface();
305 /**
306 * returns the current IPv4 address without the prefix
307 * \sa ipV4Config()
308 * \sa ipV6Config()
309 * @deprecated
310 */
311 QHostAddress ipV4Address() const;
312 /**
313 * Get the current IPv4 configuration of this device.
314 * Only valid when device is Activated.
315 */
316 IpConfig ipV4Config() const;
317 /**
318 * Get the current IPv6 configuration of this device.
319 * Only valid when device is Activated.
320 */
321 IpConfig ipV6Config() const;
322
323 /**
324 * Get the DHCP options returned by the DHCP server
325 * or a null pointer if the device is not Activated or does not
326 * use DHCP configuration.
327 */
328 Dhcp4Config::Ptr dhcp4Config() const;
329
330 /**
331 * Get the DHCP options returned by the DHCP server
332 * or a null pointer if the device is not Activated or does not
333 * use DHCP configuration.
334 */
335 Dhcp6Config::Ptr dhcp6Config() const;
336
337 /**
338 * Retrieves the activation status of this network interface.
339 *
340 * @return true if this network interface is active, false otherwise
341 */
342 bool isActive() const;
343
344 /**
345 * Retrieves the device is valid.
346 *
347 * @return true if this device interface is valid, false otherwise
348 */
349 bool isValid() const;
350
351 /**
352 * Retrieves the current state of the device.
353 * This is a high level view of the device. It is user oriented, so
354 * actually it provides state coming from different layers.
355 *
356 * @return the current connection state
357 * @see Device::State
358 */
359 State state() const;
360 /**
361 * Retrieves the maximum speed as reported by the device.
362 * Note that this is only a design related piece of information, and that
363 * the device might not reach this maximum.
364 *
365 * @return the device's maximum speed
366 */
367 int designSpeed() const;
368 /**
369 * Retrieves the capabilities supported by this device.
370 *
371 * @return the capabilities of the device
372 */
373 Capabilities capabilities() const;
374 QVariant capabilitiesV() const;
375 /**
376 * Is the device currently being managed by NetworkManager?
377 */
378 bool managed() const;
379 /**
380 * The up or down flag for the device
381 */
382 Interfaceflags interfaceFlags() const;
383 /**
384 * Is the firmware needed by the device missing?
385 */
386 bool firmwareMissing() const;
387 /**
388 * If the device is allowed to autoconnect.
389 */
390 bool autoconnect() const;
391 /**
392 * The current state and reason for changing to that state.
393 */
394 DeviceStateReason stateReason() const;
395 /**
396 * Retrieves the Unique Device Identifier (UDI) of the device.
397 * This identifier is unique for each device in the system.
398 */
399 QString udi() const;
400
401 /**
402 * @return If non-empty, an (opaque) indicator of the physical network
403 * port associated with the device. This can be used to recognize
404 * when two seemingly-separate hardware devices are actually just
405 * different virtual interfaces to the same physical port.
406 *
407 * @since 0.9.9.0
408 */
409 QString physicalPortId() const;
410 /**
411 * The device MTU (maximum transmission unit)
412 * @since 0.9.9.0
413 *
414 */
415 uint mtu() const;
416
417 /**
418 * @return If TRUE, indicates the NetworkManager plugin for the device is likely
419 * missing or misconfigured.
420 * @since 5.14.0
421 */
422 bool nmPluginMissing() const;
423
424 /**
425 * @return Whether the amount of traffic flowing through the device is
426 * subject to limitations, for example set by service providers.
427 * @since 5.14.0
428 */
429 MeteredStatus metered() const;
430
431 /**
432 * If true, indicates the device is allowed to autoconnect.
433 * If false, manual intervention is required before the device
434 * will automatically connect to a known network, such as activating
435 * a connection using the device, or setting this property to @p true.
436 */
437 void setAutoconnect(bool autoconnect);
438
439 /**
440 * Returns Device Statistics interface
441 */
442 DeviceStatistics::Ptr deviceStatistics() const;
443
444 /**
445 * Retrieves a specialized interface to interact with the device corresponding
446 * to a given device interface.
447 *
448 * @returns a pointer to the device interface if it exists, @p 0 otherwise
449 */
450 template<class DevIface>
451 DevIface *as()
452 {
453 return qobject_cast<DevIface *>(this);
454 }
455
456 /**
457 * Retrieves a specialized interface to interact with the device corresponding
458 * to a given device interface.
459 *
460 * @returns a pointer to the device interface if it exists, 0 otherwise
461 */
462 template<class DevIface>
463 const DevIface *as() const
464 {
465 return qobject_cast<const DevIface *>(this);
466 }
467
468Q_SIGNALS:
469 /**
470 * This signal is emitted when the device's link status changed.
471 *
472 * @param newstate the new state of the connection
473 * @param oldstate the previous state of the connection
474 * @param reason the reason for the state change, if any. ReasonNone where the backend
475 * provides no reason.
476 * @see Device::State
477 * @see Device::StateChangeReason
478 */
479 void stateChanged(NetworkManager::Device::State newstate, NetworkManager::Device::State oldstate, NetworkManager::Device::StateChangeReason reason);
480
481 /**
482 * Emitted when the autoconnect of this network has changed.
483 */
484 void activeConnectionChanged();
485
486 /**
487 * Emitted when the autoconnect of this network has changed.
488 */
489 void autoconnectChanged();
490
491 /**
492 * Emitted when the list of avaiable connections of this network has changed.
493 */
494 void availableConnectionChanged();
495
496 /**
497 * Emitted when a new connection is available
498 */
499 void availableConnectionAppeared(const QString &connection);
500
501 /**
502 * Emitted when the connection is no longer available
503 */
504 void availableConnectionDisappeared(const QString &connection);
505
506 /**
507 * Emitted when the capabilities of this network has changed.
508 */
509 void capabilitiesChanged();
510
511 /**
512 * Emitted when the DHCP configuration for IPv4 of this network has changed.
513 */
514 void dhcp4ConfigChanged();
515
516 /**
517 * Emitted when the DHCP configuration for IPv6 of this network has changed.
518 */
519 void dhcp6ConfigChanged();
520
521 /**
522 * Emitted when the driver of this network has changed.
523 */
524 void driverChanged();
525
526 /**
527 * Emitted when the driver version of this network has changed.
528 */
529 void driverVersionChanged();
530
531 /**
532 * Emitted when the firmware missing state of this network has changed.
533 */
534 void firmwareMissingChanged();
535
536 /**
537 * Emitted when the firmware version of this network has changed.
538 */
539 void firmwareVersionChanged();
540
541 /**
542 * Emitted when the interface name of this network has changed.
543 */
544 void interfaceNameChanged();
545
546 /**
547 * Emitted when the IPv4 address of this network has changed.
548 */
549 void ipV4AddressChanged();
550
551 /**
552 * Emitted when the IPv4 configuration of this network has changed.
553 */
554 void ipV4ConfigChanged();
555
556 /**
557 * Emitted when the IPv6 configuration of this network has changed.
558 */
559 void ipV6ConfigChanged();
560
561 /**
562 * Emitted when the ip interface name of this network has changed.
563 */
564 void ipInterfaceChanged();
565
566 /**
567 * Emitted when the managed state of this network has changed.
568 */
569 void managedChanged();
570
571 /**
572 * Emitted when the up or down state of the device
573 * @since 1.22
574 * @note will always return NM_DEVICE_INTERFACE_FLAG_NONE when runtime NM < 1.22
575 */
576 void interfaceFlagsChanged();
577
578 /**
579 * Emitted when the physical port ID changes.
580 * @see physicalPortId()
581 * @since 0.9.9.0
582 */
583 void physicalPortIdChanged();
584
585 /**
586 * Emitted when the maximum transmission unit has changed
587 * @since 0.9.9.0
588 */
589 void mtuChanged();
590
591 /**
592 * Emitted when NmPluginMissing property has changed
593 * @since 5.14.0
594 * @see nmPluginMissing
595 */
596 void nmPluginMissingChanged(bool nmPluginMissing);
597
598 /**
599 * Emitted when metered property has changed
600 * @since 5.14.0
601 * @see metered
602 */
603 void meteredChanged(MeteredStatus metered);
604
605 /**
606 * Emitted when the connection state of this network has changed.
607 */
608 void connectionStateChanged();
609
610 /**
611 * Emitted when the state reason of this network has changed.
612 */
613 void stateReasonChanged();
614
615 /**
616 * Emitted when the Unique Device Identifier of this device has changed.
617 */
618 void udiChanged();
619
620protected:
621 NETWORKMANAGERQT_NO_EXPORT Device(DevicePrivate &dd, QObject *parent);
622
623 DevicePrivate *const d_ptr;
624
625private:
626 Q_DECLARE_PRIVATE(Device)
627};
628
629Q_DECLARE_OPERATORS_FOR_FLAGS(Device::Capabilities)
630Q_DECLARE_OPERATORS_FOR_FLAGS(Device::Types)
631Q_DECLARE_OPERATORS_FOR_FLAGS(Device::Interfaceflags)
632
633class NETWORKMANAGERQT_EXPORT DeviceStateReason
634{
635public:
636 DeviceStateReason(Device::State state, Device::StateChangeReason reason);
637 DeviceStateReason(const DeviceStateReason &);
638 ~DeviceStateReason();
639 Device::State state() const;
640 Device::StateChangeReason reason() const;
641 DeviceStateReason &operator=(const DeviceStateReason &);
642
643private:
644 Q_DECLARE_PRIVATE(DeviceStateReason)
645
646 DeviceStateReasonPrivate *const d_ptr;
647};
648
649}
650
651#endif
652

source code of networkmanager-qt/src/device.h