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