1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see http://www.qt.io/terms-conditions. For further
15 ** information use the contact form at http://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 or version 3 as published by the Free
20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and
21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the
22 ** following information to ensure the GNU Lesser General Public License
23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 **
26 ** As a special exception, The Qt Company gives you certain additional
27 ** rights. These rights are described in The Qt Company LGPL Exception
28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 **
30 ** GNU General Public License Usage
31 ** Alternatively, this file may be used under the terms of the GNU
32 ** General Public License version 3.0 as published by the Free Software
33 ** Foundation and appearing in the file LICENSE.GPL included in the
34 ** packaging of this file.  Please review the following information to
35 ** ensure the GNU General Public License version 3.0 requirements will be
36 ** met: http://www.gnu.org/copyleft/gpl.html.
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QNETWORKMANAGERSERVICE_H
43 #define QNETWORKMANAGERSERVICE_H
44 
45 //
46 //  W A R N I N G
47 //  -------------
48 //
49 // This file is not part of the Qt API.  It exists purely as an
50 // implementation detail.  This header file may change from version to
51 // version without notice, or even be removed.
52 //
53 // We mean it.
54 //
55 
56 #include <QtDBus/QtDBus>
57 #include <QtDBus/QDBusConnection>
58 #include <QtDBus/QDBusError>
59 #include <QtDBus/QDBusInterface>
60 #include <QtDBus/QDBusMessage>
61 #include <QtDBus/QDBusReply>
62 
63 #include <QtDBus/QDBusPendingCallWatcher>
64 #include <QtDBus/QDBusObjectPath>
65 #include <QtDBus/QDBusContext>
66 #include <QMap>
67 #include "qnmdbushelper.h"
68 
69 #ifndef QT_NO_DBUS
70 
71 #ifndef NETWORK_MANAGER_H
72 typedef enum NMDeviceType
73 {
74     DEVICE_TYPE_UNKNOWN = 0,
75     DEVICE_TYPE_802_3_ETHERNET,
76     DEVICE_TYPE_802_11_WIRELESS,
77     DEVICE_TYPE_GSM,
78     DEVICE_TYPE_CDMA
79 } NMDeviceType;
80 
81 typedef enum
82 {
83     NM_DEVICE_STATE_UNKNOWN = 0,
84     NM_DEVICE_STATE_UNMANAGED,
85     NM_DEVICE_STATE_UNAVAILABLE,
86     NM_DEVICE_STATE_DISCONNECTED,
87     NM_DEVICE_STATE_PREPARE,
88     NM_DEVICE_STATE_CONFIG,
89     NM_DEVICE_STATE_NEED_AUTH,
90     NM_DEVICE_STATE_IP_CONFIG,
91     NM_DEVICE_STATE_ACTIVATED,
92     NM_DEVICE_STATE_FAILED
93 } NMDeviceState;
94 
95 typedef enum
96 {
97     NM_ACTIVE_CONNECTION_STATE_UNKNOWN = 0,
98     NM_ACTIVE_CONNECTION_STATE_ACTIVATING,
99     NM_ACTIVE_CONNECTION_STATE_ACTIVATED
100 } NMActiveConnectionState;
101 
102 #define	NM_DBUS_SERVICE			"org.freedesktop.NetworkManager"
103 
104 #define	NM_DBUS_PATH				        "/org/freedesktop/NetworkManager"
105 #define	NM_DBUS_INTERFACE			        "org.freedesktop.NetworkManager"
106 #define	NM_DBUS_INTERFACE_DEVICE	        NM_DBUS_INTERFACE ".Device"
107 #define NM_DBUS_INTERFACE_DEVICE_WIRED      NM_DBUS_INTERFACE_DEVICE ".Wired"
108 #define NM_DBUS_INTERFACE_DEVICE_WIRELESS   NM_DBUS_INTERFACE_DEVICE ".Wireless"
109 #define NM_DBUS_PATH_ACCESS_POINT           NM_DBUS_PATH "/AccessPoint"
110 #define NM_DBUS_INTERFACE_ACCESS_POINT      NM_DBUS_INTERFACE ".AccessPoint"
111 
112 #define NM_DBUS_PATH_SETTINGS             "/org/freedesktop/NetworkManagerSettings"
113 
114 #define NM_DBUS_IFACE_SETTINGS_CONNECTION "org.freedesktop.NetworkManagerSettings.Connection"
115 #define NM_DBUS_IFACE_SETTINGS            "org.freedesktop.NetworkManagerSettings"
116 #define NM_DBUS_INTERFACE_ACTIVE_CONNECTION NM_DBUS_INTERFACE ".Connection.Active"
117 #define NM_DBUS_INTERFACE_IP4_CONFIG        NM_DBUS_INTERFACE ".IP4Config"
118 
119 #define NM_DBUS_SERVICE_USER_SETTINGS     "org.freedesktop.NetworkManagerUserSettings"
120 #define NM_DBUS_SERVICE_SYSTEM_SETTINGS   "org.freedesktop.NetworkManagerSystemSettings"
121 
122 #define NM_802_11_AP_FLAGS_NONE				0x00000000
123 #define NM_802_11_AP_FLAGS_PRIVACY			0x00000001
124 #endif
125 
126 QT_BEGIN_NAMESPACE
127 
128 typedef QMap< QString, QMap<QString,QVariant> > QNmSettingsMap;
129 typedef QList<quint32> ServerThing;
130 
131 QT_END_NAMESPACE
132 
133 Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(QNmSettingsMap))
134 Q_DECLARE_METATYPE(QT_PREPEND_NAMESPACE(ServerThing))
135 
136 QT_BEGIN_NAMESPACE
137 
138 class QNetworkManagerInterfacePrivate;
139 class QNetworkManagerInterface : public QObject
140 {
141     Q_OBJECT
142 
143 public:
144 
145     QNetworkManagerInterface(QObject *parent = 0);
146     ~QNetworkManagerInterface();
147 
148     QList <QDBusObjectPath> getDevices() const;
149     void activateConnection(const QString &serviceName, QDBusObjectPath connection, QDBusObjectPath device, QDBusObjectPath specificObject);
150     void deactivateConnection(QDBusObjectPath connectionPath) const;
151 
152     QDBusObjectPath path() const;
153     QDBusInterface *connectionInterface() const;
154 
155     bool wirelessEnabled() const;
156     bool wirelessHardwareEnabled() const;
157     QList <QDBusObjectPath> activeConnections() const;
158     quint32 state();
159     bool setConnections();
160     bool isValid();
161 
162 Q_SIGNALS:
163     void deviceAdded(QDBusObjectPath);
164     void deviceRemoved(QDBusObjectPath);
165     void propertiesChanged( const QString &, QMap<QString,QVariant>);
166     void stateChanged(const QString&, quint32);
167     void activationFinished(QDBusPendingCallWatcher*);
168 
169 private Q_SLOTS:
170 private:
171     QNetworkManagerInterfacePrivate *d;
172     QNmDBusHelper *nmDBusHelper;
173 };
174 
175 class QNetworkManagerInterfaceAccessPointPrivate;
176 class QNetworkManagerInterfaceAccessPoint : public QObject
177 {
178     Q_OBJECT
179 
180 public:
181 
182     enum DeviceState {
183         Unknown = 0,
184         Unmanaged,
185         Unavailable,
186         Disconnected,
187         Prepare,
188         Config,
189         NeedAuthentication,
190         IpConfig,
191         Activated,
192         Failed
193     };
194 
195     enum ApFlag {
196         ApNone = 0x0,
197         Privacy = 0x1
198     };
199 
200     Q_DECLARE_FLAGS(ApFlags, ApFlag);
201 
202     enum ApSecurityFlag {
203         ApSecurityNone = 0x0,
204         PairWep40 = 0x1,
205         PairWep104 = 0x2,
206         PairTkip = 0x4,
207         PairCcmp = 0x8,
208         GroupWep40 = 0x10,
209         GroupWep104 = 0x20,
210         GroupTkip = 0x40,
211         GroupCcmp = 0x80,
212         KeyPsk = 0x100,
213         Key8021x = 0x200
214     };
215 
216     Q_DECLARE_FLAGS(ApSecurityFlags, ApSecurityFlag);
217 
218     explicit QNetworkManagerInterfaceAccessPoint(const QString &dbusPathName, QObject *parent = 0);
219     ~QNetworkManagerInterfaceAccessPoint();
220 
221     QDBusInterface *connectionInterface() const;
222 
223     quint32 flags() const;
224     quint32 wpaFlags() const;
225     quint32 rsnFlags() const;
226     QString ssid() const;
227     quint32 frequency() const;
228     QString hwAddress() const;
229     quint32 mode() const;
230     quint32 maxBitrate() const;
231     quint32 strength() const;
232     bool setConnections();
233     bool isValid();
234 
235 Q_SIGNALS:
236     void propertiesChanged(QMap <QString,QVariant>);
237     void propertiesChanged( const QString &, QMap<QString,QVariant>);
238 private:
239     QNetworkManagerInterfaceAccessPointPrivate *d;
240     QNmDBusHelper *nmDBusHelper;
241 
242 };
243 
244 class QNetworkManagerInterfaceDevicePrivate;
245 class QNetworkManagerInterfaceDevice : public QObject
246 {
247     Q_OBJECT
248 
249 public:
250 
251     explicit QNetworkManagerInterfaceDevice(const QString &deviceObjectPath, QObject *parent = 0);
252     ~QNetworkManagerInterfaceDevice();
253 
254     QString udi() const;
255     QString networkInterface() const;
256     QDBusInterface *connectionInterface() const;
257     quint32 ip4Address() const;
258     quint32 state() const;
259     quint32 deviceType() const;
260 
261     QDBusObjectPath ip4config() const;
262     bool setConnections();
263     bool isValid();
264 
265 Q_SIGNALS:
266     void stateChanged(const QString &, quint32);
267 
268 private:
269     QNetworkManagerInterfaceDevicePrivate *d;
270     QNmDBusHelper *nmDBusHelper;
271 };
272 
273 class QNetworkManagerInterfaceDeviceWiredPrivate;
274 class QNetworkManagerInterfaceDeviceWired : public QObject
275 {
276     Q_OBJECT
277 
278 public:
279 
280     explicit QNetworkManagerInterfaceDeviceWired(const QString &ifaceDevicePath,
281                                                  QObject *parent = 0);
282     ~QNetworkManagerInterfaceDeviceWired();
283 
284     QDBusInterface  *connectionInterface() const;
285     QString hwAddress() const;
286     quint32 speed() const;
287     bool carrier() const;
288     bool setConnections();
289     bool isValid();
290 
291 Q_SIGNALS:
292     void propertiesChanged( const QString &, QMap<QString,QVariant>);
293 private:
294     QNetworkManagerInterfaceDeviceWiredPrivate *d;
295     QNmDBusHelper *nmDBusHelper;
296 };
297 
298 class QNetworkManagerInterfaceDeviceWirelessPrivate;
299 class QNetworkManagerInterfaceDeviceWireless : public QObject
300 {
301     Q_OBJECT
302 
303 public:
304 
305     enum DeviceCapability {
306         None = 0x0,
307         Wep40 = 0x1,
308         Wep104 = 0x2,
309         Tkip = 0x4,
310         Ccmp = 0x8,
311         Wpa = 0x10,
312         Rsn = 0x20
313        };
314 
315     explicit QNetworkManagerInterfaceDeviceWireless(const QString &ifaceDevicePath,
316                                                     QObject *parent = 0);
317     ~QNetworkManagerInterfaceDeviceWireless();
318 
319     QDBusObjectPath path() const;
320     QList <QDBusObjectPath> getAccessPoints();
321     QDBusInterface *connectionInterface() const;
322 
323     QString hwAddress() const;
324     quint32 mode() const;
325     quint32 bitrate() const;
326     QDBusObjectPath activeAccessPoint() const;
327     quint32 wirelessCapabilities() const;
328     bool setConnections();
329     bool isValid();
330 
331 Q_SIGNALS:
332     void propertiesChanged( const QString &, QMap<QString,QVariant>);
333     void accessPointAdded(const QString &,QDBusObjectPath);
334     void accessPointRemoved(const QString &,QDBusObjectPath);
335 private:
336     QNetworkManagerInterfaceDeviceWirelessPrivate *d;
337     QNmDBusHelper *nmDBusHelper;
338 };
339 
340 class QNetworkManagerSettingsPrivate;
341 class QNetworkManagerSettings : public QObject
342 {
343     Q_OBJECT
344 
345 public:
346 
347     explicit QNetworkManagerSettings(const QString &settingsService, QObject *parent = 0);
348     ~QNetworkManagerSettings();
349 
350     QDBusInterface  *connectionInterface() const;
351     QList <QDBusObjectPath> listConnections();
352     bool setConnections();
353     bool isValid();
354 
355 Q_SIGNALS:
356     void newConnection(QDBusObjectPath);
357 private:
358     QNetworkManagerSettingsPrivate *d;
359 };
360 
361 class QNetworkManagerSettingsConnectionPrivate;
362 class QNetworkManagerSettingsConnection : public QObject
363 {
364     Q_OBJECT
365 
366 public:
367 
368     QNetworkManagerSettingsConnection(const QString &settingsService, const QString &connectionObjectPath, QObject *parent = 0);
369     ~QNetworkManagerSettingsConnection();
370 
371     QDBusInterface  *connectionInterface() const;
372     QNmSettingsMap getSettings();
373     bool setConnections();
374     NMDeviceType getType();
375     bool isAutoConnect();
376     quint64 getTimestamp();
377     QString getId();
378     QString getUuid();
379     QString getSsid();
380     QString getMacAddress();
381     QStringList getSeenBssids();
382     bool isValid();
383 
384 Q_SIGNALS:
385 
386     void updated(const QNmSettingsMap &settings);
387     void removed(const QString &path);
388 
389 private:
390     QNmDBusHelper *nmDBusHelper;
391     QNetworkManagerSettingsConnectionPrivate *d;
392 };
393 
394 class QNetworkManagerConnectionActivePrivate;
395 class QNetworkManagerConnectionActive : public QObject
396 {
397     Q_OBJECT
398 
399 public:
400 
401     enum ActiveConnectionState {
402         Unknown = 0,
403         Activating = 1,
404         Activated = 2
405        };
406 
407     explicit QNetworkManagerConnectionActive(const QString &dbusPathName, QObject *parent = 0);
408     ~ QNetworkManagerConnectionActive();
409 
410     QDBusInterface  *connectionInterface() const;
411     QString serviceName() const;
412     QDBusObjectPath connection() const;
413     QDBusObjectPath specificObject() const;
414     QList<QDBusObjectPath> devices() const;
415     quint32 state() const;
416     bool defaultRoute() const;
417     bool setConnections();
418     bool isValid();
419 
420 
421 Q_SIGNALS:
422     void propertiesChanged(QList<QDBusObjectPath>);
423     void propertiesChanged( const QString &, QMap<QString,QVariant>);
424 private:
425     QNetworkManagerConnectionActivePrivate *d;
426     QNmDBusHelper *nmDBusHelper;
427 };
428 
429 class QNetworkManagerIp4ConfigPrivate;
430 class QNetworkManagerIp4Config : public QObject
431 {
432     Q_OBJECT
433 
434 public:
435     explicit QNetworkManagerIp4Config(const QString &dbusPathName, QObject *parent = 0);
436 	~QNetworkManagerIp4Config();
437 
438     QStringList domains() const;
439     bool isValid();
440 
441  private:
442 	QNetworkManagerIp4ConfigPrivate *d;
443 };
444 
445 QT_END_NAMESPACE
446 
447 #endif // QT_NO_DBUS
448 #endif //QNETWORKMANAGERSERVICE_H
449