1/*
2 SPDX-FileCopyrightText: 2008 Will Stephenson <wstephenson@kde.org>
3 SPDX-FileCopyrightText: 2013 Daniel Nicoletti <dantti12@gmail.com>
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#include "accesspoint_p.h"
10#include "manager_p.h"
11#include "wirelessdevice.h"
12
13#include "nmdebug.h"
14
15NetworkManager::AccessPointPrivate::AccessPointPrivate(const QString &path, AccessPoint *q)
16#ifdef NMQT_STATIC
17 : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus())
18#else
19 : iface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus())
20#endif
21 , capabilities(AccessPoint::None)
22 , wpaFlags()
23 , rsnFlags()
24 , frequency(0)
25 , maxBitRate(0)
26 , mode(AccessPoint::Unknown)
27 , signalStrength(0)
28 , lastSeen(-1)
29 , q_ptr(q)
30{
31 uni = path;
32}
33
34NetworkManager::AccessPoint::Capabilities NetworkManager::AccessPointPrivate::convertCapabilities(int caps)
35{
36 NetworkManager::AccessPoint::Capabilities capFlags;
37 if (caps & NM_802_11_AP_FLAGS_PRIVACY) {
38 capFlags |= AccessPoint::Privacy;
39 }
40
41 return capFlags;
42}
43
44NetworkManager::AccessPoint::WpaFlags NetworkManager::AccessPointPrivate::convertWpaFlags(uint theirFlags)
45{
46 return (AccessPoint::WpaFlags)theirFlags;
47}
48
49NetworkManager::AccessPoint::AccessPoint(const QString &path, QObject *parent)
50 : QObject(parent)
51 , d_ptr(new AccessPointPrivate(path, this))
52{
53 Q_D(AccessPoint);
54
55 QDBusConnection::systemBus().connect(service: NetworkManagerPrivate::DBUS_SERVICE,
56 path: d->uni,
57 interface: NetworkManagerPrivate::FDO_DBUS_PROPERTIES,
58 name: QLatin1String("PropertiesChanged"),
59 receiver: d,
60 SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList)));
61
62 // Get all AccessPoint's properties at once
63 QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(interfaceName: d->iface.staticInterfaceName(), path);
64 if (!initialProperties.isEmpty()) {
65 d->propertiesChanged(properties: initialProperties);
66 }
67}
68
69NetworkManager::AccessPoint::~AccessPoint()
70{
71 Q_D(AccessPoint);
72 delete d;
73}
74
75QString NetworkManager::AccessPoint::uni() const
76{
77 Q_D(const AccessPoint);
78 return d->uni;
79}
80
81QString NetworkManager::AccessPoint::hardwareAddress() const
82{
83 Q_D(const AccessPoint);
84 return d->hardwareAddress;
85}
86
87NetworkManager::AccessPoint::Capabilities NetworkManager::AccessPoint::capabilities() const
88{
89 Q_D(const AccessPoint);
90 return d->capabilities;
91}
92
93NetworkManager::AccessPoint::WpaFlags NetworkManager::AccessPoint::wpaFlags() const
94{
95 Q_D(const AccessPoint);
96 return d->wpaFlags;
97}
98
99NetworkManager::AccessPoint::WpaFlags NetworkManager::AccessPoint::rsnFlags() const
100{
101 Q_D(const AccessPoint);
102 return d->rsnFlags;
103}
104
105QString NetworkManager::AccessPoint::ssid() const
106{
107 Q_D(const AccessPoint);
108 return d->ssid;
109}
110
111QByteArray NetworkManager::AccessPoint::rawSsid() const
112{
113 Q_D(const AccessPoint);
114 return d->rawSsid;
115}
116
117uint NetworkManager::AccessPoint::frequency() const
118{
119 Q_D(const AccessPoint);
120 return d->frequency;
121}
122
123uint NetworkManager::AccessPoint::maxBitRate() const
124{
125 Q_D(const AccessPoint);
126 return d->maxBitRate;
127}
128
129NetworkManager::AccessPoint::OperationMode NetworkManager::AccessPoint::mode() const
130{
131 Q_D(const AccessPoint);
132 return d->mode;
133}
134
135int NetworkManager::AccessPoint::signalStrength() const
136{
137 Q_D(const AccessPoint);
138 return d->signalStrength;
139}
140
141int NetworkManager::AccessPoint::lastSeen() const
142{
143 Q_D(const AccessPoint);
144 return d->lastSeen;
145}
146
147NetworkManager::AccessPoint::OperationMode NetworkManager::AccessPoint::convertOperationMode(uint mode)
148{
149 NetworkManager::AccessPoint::OperationMode ourMode = NetworkManager::AccessPoint::Unknown;
150 switch (mode) {
151 case NM_802_11_MODE_UNKNOWN:
152 ourMode = NetworkManager::AccessPoint::Unknown;
153 break;
154 case NM_802_11_MODE_ADHOC:
155 ourMode = NetworkManager::AccessPoint::Adhoc;
156 break;
157 case NM_802_11_MODE_INFRA:
158 ourMode = NetworkManager::AccessPoint::Infra;
159 break;
160 case NM_802_11_MODE_AP:
161 ourMode = NetworkManager::AccessPoint::ApMode;
162 break;
163 default:
164 qCDebug(NMQT) << Q_FUNC_INFO << "Unhandled mode" << mode;
165 }
166 return ourMode;
167}
168
169void NetworkManager::AccessPointPrivate::dbusPropertiesChanged(const QString &interfaceName,
170 const QVariantMap &properties,
171 const QStringList &invalidatedProperties)
172{
173 Q_UNUSED(invalidatedProperties);
174 if (interfaceName == QLatin1String("org.freedesktop.NetworkManager.AccessPoint")) {
175 propertiesChanged(properties);
176 }
177}
178
179void NetworkManager::AccessPointPrivate::propertiesChanged(const QVariantMap &properties)
180{
181 Q_Q(AccessPoint);
182
183 // qCDebug(NMQT) << Q_FUNC_INFO << properties;
184
185 QVariantMap::const_iterator it = properties.constBegin();
186 while (it != properties.constEnd()) {
187 const QString property = it.key();
188 if (property == QLatin1String("Flags")) {
189 capabilities = convertCapabilities(caps: it->toUInt());
190 Q_EMIT q->capabilitiesChanged(caps: capabilities);
191 } else if (property == QLatin1String("WpaFlags")) {
192 wpaFlags = convertWpaFlags(theirFlags: it->toUInt());
193 Q_EMIT q->wpaFlagsChanged(flags: wpaFlags);
194 } else if (property == QLatin1String("RsnFlags")) {
195 rsnFlags = convertWpaFlags(theirFlags: it->toUInt());
196 Q_EMIT q->rsnFlagsChanged(flags: rsnFlags);
197 } else if (property == QLatin1String("Ssid")) {
198 rawSsid = it->toByteArray();
199 ssid = QString::fromUtf8(ba: rawSsid);
200 Q_EMIT q->ssidChanged(ssid);
201 } else if (property == QLatin1String("Frequency")) {
202 frequency = it->toUInt();
203 Q_EMIT q->frequencyChanged(frequency);
204 } else if (property == QLatin1String("HwAddress")) {
205 hardwareAddress = it->toString();
206 } else if (property == QLatin1String("Mode")) {
207 mode = q->convertOperationMode(mode: it->toUInt());
208 } else if (property == QLatin1String("MaxBitrate")) {
209 maxBitRate = it->toUInt();
210 Q_EMIT q->bitRateChanged(bitrate: maxBitRate);
211 } else if (property == QLatin1String("Strength")) {
212 signalStrength = it->toInt();
213 Q_EMIT q->signalStrengthChanged(strength: signalStrength);
214 } else if (property == QLatin1String("LastSeen")) {
215 lastSeen = it->toInt();
216 Q_EMIT q->lastSeenChanged(lastSeen);
217 } else {
218 qCDebug(NMQT) << Q_FUNC_INFO << "Unhandled property" << property;
219 }
220 ++it;
221 }
222}
223
224#include "moc_accesspoint.cpp"
225#include "moc_accesspoint_p.cpp"
226

source code of networkmanager-qt/src/accesspoint.cpp