1/*
2 SPDX-FileCopyrightText: 2008, 2010, 2011 Will Stephenson <wstephenson@kde.org>
3 SPDX-FileCopyrightText: 2011-2013 Lamarque Souza <lamarque@kde.org>
4 SPDX-FileCopyrightText: 2013 Jan Grulich <jgrulich@redhat.com>
5
6 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7*/
8
9#ifndef NETWORKMANAGERQT_NETWORKMANAGER_H
10#define NETWORKMANAGERQT_NETWORKMANAGER_H
11
12#include <networkmanagerqt/networkmanagerqt_export.h>
13
14#include "activeconnection.h"
15#include "device.h"
16#include "dnsconfiguration.h"
17
18/*!
19 * \namespace NetworkManager
20 * \inmodule NetworkManagerQt
21 *
22 * This class allows querying the underlying system to discover the available
23 * network interfaces and reachable networks. It has also the
24 * responsibility to notify when a network interface appears or disappears.
25 *
26 * It is the unique entry point for network management. Applications should use
27 * it to find network interfaces, or to be notified about network related changes.
28 *
29 * Note that it is implemented as a singleton
30 */
31namespace NetworkManager
32{
33Q_NAMESPACE_EXPORT(NETWORKMANAGERQT_EXPORT)
34
35/*!
36 *
37 * Possible device interfaceflags
38 *
39 * \value Unknown
40 * the networking system is not active or unable to report its status - proceed with caution
41 * \value Asleep
42 * networking is inactive and all devices are disabled
43 * \value Disconnected
44 * the system is not connected to any network
45 * \value Disconnecting
46 * the system is breaking the connection
47 * \value Connecting
48 * the system is not connected to any network
49 * \value ConnectedLinkLocal
50 * a network device is connected, but there is only link-local connectivity
51 * \value ConnectedSiteOnly
52 * a network device is connected, but there is only site-local connectivity
53 * \value Connected
54 * the system is currently connected to a network
55 */
56enum Status {
57 Unknown,
58 Asleep,
59 Disconnected,
60 Disconnecting,
61 Connecting,
62 ConnectedLinkLocal,
63 ConnectedSiteOnly,
64 Connected,
65};
66Q_ENUM_NS(Status)
67
68/*!
69 *
70 * \value Error
71 * \value Warning
72 * \value Info
73 * \value Debug
74 * \value Trace
75 * = Debug in runtime NM < 0.9.10
76 */
77enum LogLevel {
78 Error,
79 Warning,
80 Info,
81 Debug,
82 Trace,
83};
84
85/*!
86 *
87 * \value NoChange
88 * \value None
89 * \value Hardware
90 * \value RFKill
91 * \value Ethernet
92 * \value WiFi
93 * \value Bluetooth
94 * \value MobileBroadBand
95 * \value DHCP4
96 * \value DHCP6
97 * \value PPP
98 * \value WiFiScan
99 * \value IPv4
100 * \value IPv6
101 * \value AutoIPv4
102 * \value DNS
103 * \value VPN
104 * \value Sharing
105 * \value Supplicant
106 * \value UserSet
107 * \value SysSet
108 * \value Suspend
109 * \value Core
110 * \value Devices
111 * \value OLPC
112 * \value Wimax
113 * TODO: mark it deprecated somehow?
114 * \value Infiniband
115 * \value Firewall
116 * \value Adsl
117 * \value Bond
118 * \value Vlan
119 * \value Agents
120 * \value Settings
121 * \value Bridge
122 * \value DbusProps
123 * \value Team
124 * \value ConCheck
125 * \value Dcb
126 * \value Dispatch
127 */
128enum LogDomain {
129 NoChange,
130 None,
131 Hardware,
132 RFKill,
133 Ethernet,
134 WiFi,
135 Bluetooth,
136 MobileBroadBand,
137 DHCP4,
138 DHCP6,
139 PPP,
140 WiFiScan,
141 IPv4,
142 IPv6,
143 AutoIPv4,
144 DNS,
145 VPN,
146 Sharing,
147 Supplicant,
148 UserSet,
149 SysSet,
150 Suspend,
151 Core,
152 Devices,
153 OLPC,
154 Wimax /*TODO: mark it deprecated somehow?*/,
155 Infiniband,
156 Firewall,
157 Adsl,
158 Bond,
159 Vlan,
160 Agents,
161 Settings,
162 Bridge,
163 DbusProps,
164 Team,
165 ConCheck,
166 Dcb,
167 Dispatch,
168};
169Q_DECLARE_FLAGS(LogDomains, LogDomain)
170Q_FLAGS(LogDomain)
171
172/*!
173 *
174 * Describes the network connectivity state.
175 *
176 * \since 0.9.9.0
177 *
178 * \value UnknownConnectivity
179 * Network connectivity is unknown.
180 * \value NoConnectivity
181 * The host is not connected to any network.
182 * \value Portal
183 * The host is behind a captive portal and cannot reach the full Internet.
184 * \value Limited
185 * The host is connected to a network, but does not appear to be able to reach the full Internet.
186 * \value Full
187 * The host is connected to a network, and appears to be able to reach the full Internet.
188 */
189enum Connectivity {
190 UnknownConnectivity = 0,
191 NoConnectivity = 1,
192 Portal = 2,
193 Limited = 3,
194 Full = 4,
195};
196Q_ENUM_NS(Connectivity)
197
198/*!
199 * \class NetworkManager::Notifier
200 *
201 * \inmodule NetworkManagerQt
202 */
203class NETWORKMANAGERQT_EXPORT Notifier : public QObject
204{
205 Q_OBJECT
206Q_SIGNALS:
207 /*!
208 * This signal is emitted when the system's connection state changes
209 */
210 void statusChanged(NetworkManager::Status status);
211 /*!
212 * This signal is emitted when a new network interface is available.
213 *
214 * \a uni the network interface identifier
215 */
216 void deviceAdded(const QString &uni);
217 /*!
218 * This signal is emitted when a network interface is not available anymore.
219 *
220 * \a uni the network interface identifier
221 */
222 void deviceRemoved(const QString &uni);
223 /*!
224 * This signal is emitted when the status of the wireless changed
225 */
226 void wirelessEnabledChanged(bool);
227 /*!
228 * This signal is emitted when the status of the wireless changed
229 */
230 void wwanEnabledChanged(bool);
231 /*!
232 * This signal is emitted when the status of the wimax changed
233 *
234 * \deprecated Wimax support was removed from NetworkManager 1.2
235 * (never emitted in runtime NM >= 1.2.0).
236 */
237 void wimaxEnabledChanged(bool);
238 /*!
239 * This signal is emitted when the status of the wireless changed
240 */
241 void wirelessHardwareEnabledChanged(bool);
242 /*!
243 * This signal is emitted when the status of the wireless changed
244 */
245 void wwanHardwareEnabledChanged(bool);
246 /*!
247 * This signal is emitted when the status of the wimax hardware changed
248 *
249 * \deprecated Wimax support was removed from NetworkManager 1.2
250 * (never emitted in runtime NM >= 1.2.0).
251 */
252 void wimaxHardwareEnabledChanged(bool);
253 /*!
254 * This signal is emitted when the status of overall networking changed
255 */
256 void networkingEnabledChanged(bool);
257 /*!
258 * This signal is emitted when a new connection was made active
259 *
260 * \a path the path of the new connection
261 */
262 void activeConnectionAdded(const QString &path);
263 /*!
264 * This signal is emitted when an active connection is no longer active
265 *
266 * \a path the path of the removed connection
267 */
268 void activeConnectionRemoved(const QString &path);
269 /*!
270 * This signal is emitted when the set of active connections changes
271 */
272 void activeConnectionsChanged();
273 /*!
274 * This signal is emitted when the NetworkManager DBus service goes away
275 */
276 void serviceDisappeared();
277 /*!
278 * This signal is emitted when the NetworkManager DBus service appears
279 */
280 void serviceAppeared();
281 /*!
282 * Emitted when the global connectivity changes.
283 * \since 0.9.9.0
284 */
285 void connectivityChanged(NetworkManager::Connectivity connectivity);
286 /*!
287 * Emitted when the primary connection changes.
288 * \a uni path of the new primary connection
289 * \since 0.9.9.0
290 */
291 void primaryConnectionChanged(const QString &uni);
292 /*!
293 * Emitted when the activating connection changes.
294 * \a uni path of the new activating connection
295 * \since 0.9.9.0
296 */
297 void activatingConnectionChanged(const QString &uni);
298 /*!
299 * Emitted when the primary connection type changes.
300 * \a connection type of the new primary connection
301 * \since 5.8.0
302 */
303 void primaryConnectionTypeChanged(NetworkManager::ConnectionSettings::ConnectionType type);
304
305 /*!
306 * Emitted when NM has started/finished its startup sequence
307 * \since 0.9.9.0
308 */
309 void isStartingUpChanged();
310
311 /*!
312 * Emitted when metered property has changed
313 * \since 5.14.0
314 * \sa metered
315 */
316 void meteredChanged(NetworkManager::Device::MeteredStatus metered);
317
318 /*!
319 * Emitted when the global DNS configuration has changed
320 * \since 5.45.0
321 * \sa globalDnsConfiguration
322 */
323 void globalDnsConfigurationChanged(const NetworkManager::DnsConfiguration &configuration);
324
325 /*!
326 * Emitted when the connectivity check availability has changed
327 * @since 6.10.0
328 */
329 void isConnectivityCheckAvailableChanged(bool);
330
331 /*!
332 * Emitted when the connectivity check statu has changed
333 * @since 6.10.0
334 */
335 void isConnectivityCheckEnabledChanged(bool);
336
337 /*!
338 * Emitted when the connectivity check URI has changed
339 * @since 6.10.0
340 */
341 void connectivityCheckUriChanged(QString);
342};
343
344/*!
345 * Get the NetworkManager version
346 */
347NETWORKMANAGERQT_EXPORT QString version();
348/*!
349 * Compares NetworkManager's version to the parameter version.
350 * returns 1, -1 or 0 if NetworkManager's version is greater, less or equal to parameter.
351 */
352NETWORKMANAGERQT_EXPORT int compareVersion(const QString &version);
353/*!
354 * Compares NetworkManager version to x.y.z.
355 * returns 1, -1 or 0 if NetworkManager's version is greater, less or equal to x.y.z.
356 */
357NETWORKMANAGERQT_EXPORT int compareVersion(const int x, const int y, const int z);
358/*!
359 * Checks if NetworkManager version is at least x.y.z
360 * Returns true if NetworkManager's version is greater or equal, false otherwise
361 **/
362NETWORKMANAGERQT_EXPORT bool checkVersion(const int x, const int y, const int z);
363/*!
364 * Get the manager connection state
365 */
366NETWORKMANAGERQT_EXPORT NetworkManager::Status status();
367/*!
368 * Retrieves the list of all the network interfaces in the system.
369 * It includes both hardware and virtual devices.
370 *
371 * Returns the list of network interfaces available in this system
372 */
373NETWORKMANAGERQT_EXPORT Device::List networkInterfaces();
374/*!
375 * Find a new NetworkInterface object given its UNI. This pointer is owned by the Solid
376 * infrastructure.
377 *
378 * \a uni the identifier of the network interface to find
379 * Returns a valid NetworkInterface object if there's a device having the given UNI, an invalid one otherwise
380 */
381NETWORKMANAGERQT_EXPORT Device::Ptr findNetworkInterface(const QString &uni);
382/*!
383 * Return the network device referenced by its IP interface name.
384 * This is not system independent so programs that will use this method will not be portable.
385 */
386NETWORKMANAGERQT_EXPORT Device::Ptr findDeviceByIpFace(const QString &iface);
387/*!
388 * Retrieves the status of networking (as a whole) in the system.
389 * This is distinct from whether the system's networking is online or offline.
390 * To check that, see \ status().
391 *
392 * Returns true if this networking is enabled, false otherwise
393 */
394NETWORKMANAGERQT_EXPORT bool isNetworkingEnabled();
395/*!
396 * Retrieves the activation status of wireless networking in the system.
397 *
398 * Returns true if this wireless networking is enabled, false otherwise
399 */
400NETWORKMANAGERQT_EXPORT bool isWirelessEnabled();
401/*!
402 * Retrieves the status of wireless hardware in the system. This is typically
403 * controlled by a physical switch so there is no way to set this in software.
404 *
405 * Returns true if this wireless networking is enabled, false otherwise
406 */
407NETWORKMANAGERQT_EXPORT bool isWirelessHardwareEnabled();
408/*!
409 * Retrieves the status of wireless broadband (Wireless WAN) in the system.
410 *
411 * Returns true if this type of wireless networking is enabled, false otherwise
412 */
413NETWORKMANAGERQT_EXPORT bool isWwanEnabled();
414/*!
415 * Retrieves the status of wireless broadband (Wireless WAN) hardware in the system. This is typically
416 * controlled by a physical switch so there is no way to set this in software.
417 *
418 * Returns true if this broddband hardware is enabled, false otherwise
419 */
420NETWORKMANAGERQT_EXPORT bool isWwanHardwareEnabled();
421
422/*!
423 * Retrieves the activation status of wimax networking in the system.
424 *
425 * Returns true if this wimax networking is enabled, false otherwise
426 *
427 * \deprecated Wimax support was removed from NetworkManager 1.2
428 * (always returns false in runtime NM >= 1.2.0).
429 */
430NETWORKMANAGERQT_EXPORT bool isWimaxEnabled();
431/*!
432 * Retrieves the status of wimax hardware in the system. This is typically
433 * controlled by a physical switch so there is no way to set this in software.
434 *
435 * Returns true if wimax HW networking is enabled, false otherwise
436 *
437 * \deprecated Wimax support was removed from NetworkManager 1.2
438 * (always returns false in runtime NM >= 1.2.0).
439 */
440NETWORKMANAGERQT_EXPORT bool isWimaxHardwareEnabled();
441
442/*!
443 * Activate a connection using the supplied device.
444 *
445 * \a connectionUni unique identifier for the connection to be activated
446 * \a interfaceUni unique identifier of the network interface to be activated
447 * \a connectionParameter can be used to specify extra parameters not specific to the NetworkInterface or the connection, eg which AP to use when several
448 * present with same ESSID in range (because ESSID does not guarantee that the AP is part of the network you want to join!)
449 */
450NETWORKMANAGERQT_EXPORT QDBusPendingReply<QDBusObjectPath>
451activateConnection(const QString &connectionUni, const QString &interfaceUni, const QString &connectionParameter);
452/*!
453 * Adds a new connection using the given details (if any) as a template (automatically filling in missing settings with the capabilities of the given device and
454 * specific object), then activate the new connection. Cannot be used for VPN connections at this time.
455 *
456 * \a connection connection definition to be added and activated
457 * \a interfaceUni unique identifier of the network interface to be activated
458 * \a connectionParameter can be used to specify extra parameters not specific to the NetworkInterface or the connection, eg which AP to use when several
459 * present with same ESSID in range (because ESSID does not guarantee that the AP is part of the network you want to join!)
460 */
461NETWORKMANAGERQT_EXPORT QDBusPendingReply<QDBusObjectPath, QDBusObjectPath>
462addAndActivateConnection(const NMVariantMapMap &connection, const QString &interfaceUni, const QString &connectionParameter);
463/*!
464 * Adds a new connection using the given details (if any) as a template (automatically filling in missing settings with the capabilities of the given device and
465 * specific object), then activate the new connection. Cannot be used for VPN connections at this time.
466 *
467 * \a connection connection definition to be added and activated
468 * \a interfaceUni unique identifier of the network interface to be activated
469 * \a connectionParameter can be used to specify extra parameters not specific to the NetworkInterface or the connection, eg which AP to use when several
470 * present with same ESSID in range (because ESSID does not guarantee that the AP is part of the network you want to join!)
471 * \a options further options for the method call.
472 *
473 * This method extends AddAndActivateConnection to allow passing further
474 * parameters. At this time the following options are supported:
475 *
476 * * persist: A string value of either "disk" (default), "memory" or "volatile". If "memory" is passed, the connection will not be saved to disk. If
477 * "volatile" is passed, the connection will not be saved to disk and will be destroyed when disconnected.
478 * * bind-activation: Bind the activation lifetime. Set to "dbus-name" to automatically disconnect when the requesting process disappears from the bus.
479 * The default of "none" means the connection is kept activated normally.
480 *
481 * \
482ote will call AddAndActivateConnection(connection, interfaceUni, connectionParameter) instead when NetworkManager is older than 1.16, which means that the
483 * options property is ignored
484 */
485NETWORKMANAGERQT_EXPORT QDBusPendingReply<QDBusObjectPath, QDBusObjectPath, QVariantMap>
486addAndActivateConnection2(const NMVariantMapMap &connection, const QString &interfaceUni, const QString &connectionParameter, const QVariantMap &options);
487/*!
488 * Deactivate this network interface, if active
489 *
490 * \a activeConnection identifier of the connection to deactivate
491 */
492NETWORKMANAGERQT_EXPORT QDBusPendingReply<> deactivateConnection(const QString &activeConnection);
493/*!
494 * Access the list of any active connections
495 *
496 * Returns a list of valid ActiveConnection objects
497 */
498NETWORKMANAGERQT_EXPORT ActiveConnection::List activeConnections();
499/*!
500 * Access the list of any active connections paths
501 *
502 * Returns a list of valid ActiveConnection paths
503 */
504NETWORKMANAGERQT_EXPORT QStringList activeConnectionsPaths();
505/*!
506 * Get current logging verbosity level and operations domains
507 */
508NETWORKMANAGERQT_EXPORT QDBusPendingReply<QString, QString> getLogging();
509
510/*!
511 * Returns the network connectivity state
512 * \since 0.9.9.0
513 */
514NETWORKMANAGERQT_EXPORT Connectivity connectivity();
515
516/*!
517 * Re-check the network connectivity state.
518 * \sa connectivity()
519 * \since 0.9.9.0
520 */
521NETWORKMANAGERQT_EXPORT QDBusPendingReply<uint> checkConnectivity();
522
523/*!
524 * Returns the "primary" active connection being used
525 * to access the network. In particular, if there is no VPN
526 * active, or the VPN does not have the default route, then this
527 * indicates the connection that has the default route. If there
528 * is a VPN active with the default route, then this indicates
529 * the connection that contains the route to the VPN endpoint.
530 * \since 0.9.9.0
531 */
532NETWORKMANAGERQT_EXPORT ActiveConnection::Ptr primaryConnection();
533
534/*!
535 * Returns an active connection that is currently
536 * being activated and which is expected to become the new
537 * primaryConnection() when it finishes activating.
538 * \since 0.9.9.0
539 */
540NETWORKMANAGERQT_EXPORT ActiveConnection::Ptr activatingConnection();
541
542/*!
543 * Returns The connection type of the "primary" active connection being
544 * used to access the network. This is the same as the Type
545 * property on the object indicated by PrimaryConnection.
546 * \since 5.8.0
547 */
548NETWORKMANAGERQT_EXPORT NetworkManager::ConnectionSettings::ConnectionType primaryConnectionType();
549
550/*!
551 * Indicates whether NM is still starting up; this becomes \a false
552 * when NM has finished attempting to activate every connection
553 * that it might be able to activate at startup.
554 * \since 0.9.9.0
555 */
556NETWORKMANAGERQT_EXPORT bool isStartingUp();
557
558/*!
559 * Returns Indicates whether the connectivity is metered.
560 * \since 5.14.0
561 */
562NETWORKMANAGERQT_EXPORT NetworkManager::Device::MeteredStatus metered();
563
564/*!
565 * Returns Gets the global DNS configuration.
566 * \since 5.45.0
567 */
568NETWORKMANAGERQT_EXPORT NetworkManager::DnsConfiguration globalDnsConfiguration();
569
570/*!
571 * Returns Sets the global DNS configuration.
572 * \since 5.45.0
573 */
574NETWORKMANAGERQT_EXPORT void setGlobalDnsConfiguration(const NetworkManager::DnsConfiguration &configuration);
575
576/*!
577 * Returns whether the connectivity check is available
578 * \since 6.10.0
579 */
580NETWORKMANAGERQT_EXPORT bool isConnectivityCheckAvailable();
581
582/*!
583 * Returns whether the connectivity check is enabled
584 * \since 6.10.0
585 */
586NETWORKMANAGERQT_EXPORT bool isConnectivityCheckEnabled();
587
588/*!
589 * Returns the URI used for connectivity check
590 * \since 6.10.0
591 */
592NETWORKMANAGERQT_EXPORT QString connectivityCheckUri();
593
594/*!
595 * Find an ActiveConnection object for an active connection id
596 *
597 * \a uni the id of the ActiveConnection
598 * Returns a valid ActiveConnection object
599 */
600NETWORKMANAGERQT_EXPORT ActiveConnection::Ptr findActiveConnection(const QString &uni);
601/*!
602 * Retrieves the interface types supported by this network manager.
603 *
604 * Returns the interface types supported by the network manager
605 */
606NETWORKMANAGERQT_EXPORT Device::Types supportedInterfaceTypes();
607/*!
608 */
609NETWORKMANAGERQT_EXPORT void setNetworkingEnabled(bool enabled);
610// implemented in Notifier
611/*!
612 */
613NETWORKMANAGERQT_EXPORT void setWirelessEnabled(bool enabled);
614/*!
615 */
616NETWORKMANAGERQT_EXPORT void setWwanEnabled(bool enabled);
617/*!
618 * \deprecated Wimax support was removed from NetworkManager 1.2
619 * (it is a noop in runtime NM >= 1.2.0).
620 */
621NETWORKMANAGERQT_EXPORT void setWimaxEnabled(bool enabled);
622/*!
623 */
624NETWORKMANAGERQT_EXPORT void sleep(bool sleep);
625/*!
626 */
627NETWORKMANAGERQT_EXPORT void setLogging(LogLevel, LogDomains);
628/*!
629 */
630NETWORKMANAGERQT_EXPORT NMStringMap permissions();
631/*!
632 */
633NETWORKMANAGERQT_EXPORT Notifier *notifier();
634
635}
636
637#endif
638

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