NetworkManagerQt

accesspoint.cpp
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{
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(NetworkManagerPrivate::DBUS_SERVICE,
56 d->uni,
57 NetworkManagerPrivate::FDO_DBUS_PROPERTIES,
58 QLatin1String("PropertiesChanged"),
59 d,
60 SLOT(dbusPropertiesChanged(QString, QVariantMap, QStringList)));
61
62 // Get all AccessPoint's properties at once
63 QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->iface.staticInterfaceName(), path);
64 if (!initialProperties.isEmpty()) {
65 d->propertiesChanged(initialProperties);
66 }
67}
68
69NetworkManager::AccessPoint::~AccessPoint()
70{
71 Q_D(AccessPoint);
72 delete d;
73}
74
76{
77 Q_D(const AccessPoint);
78 return d->uni;
79}
80
82{
83 Q_D(const AccessPoint);
84 return d->hardwareAddress;
85}
86
92
98
104
106{
107 Q_D(const AccessPoint);
108 return d->ssid;
109}
110
112{
113 Q_D(const AccessPoint);
114 return d->rawSsid;
115}
116
118{
119 Q_D(const AccessPoint);
120 return d->frequency;
121}
122
124{
125 Q_D(const AccessPoint);
126 return d->maxBitRate;
127}
128
134
136{
137 Q_D(const AccessPoint);
138 return d->signalStrength;
139}
140
142{
143 Q_D(const AccessPoint);
144 return d->lastSeen;
145}
146
148{
150 switch (mode) {
151 case NM_802_11_MODE_UNKNOWN:
153 break;
154 case NM_802_11_MODE_ADHOC:
156 break;
157 case NM_802_11_MODE_INFRA:
159 break;
160 case NM_802_11_MODE_AP:
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(it->toUInt());
190 Q_EMIT q->capabilitiesChanged(capabilities);
191 } else if (property == QLatin1String("WpaFlags")) {
192 wpaFlags = convertWpaFlags(it->toUInt());
193 Q_EMIT q->wpaFlagsChanged(wpaFlags);
194 } else if (property == QLatin1String("RsnFlags")) {
195 rsnFlags = convertWpaFlags(it->toUInt());
196 Q_EMIT q->rsnFlagsChanged(rsnFlags);
197 } else if (property == QLatin1String("Ssid")) {
198 rawSsid = it->toByteArray();
199 ssid = QString::fromUtf8(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(it->toUInt());
208 } else if (property == QLatin1String("MaxBitrate")) {
209 maxBitRate = it->toUInt();
210 Q_EMIT q->bitRateChanged(maxBitRate);
211 } else if (property == QLatin1String("Strength")) {
212 signalStrength = it->toInt();
213 Q_EMIT q->signalStrengthChanged(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"
Represents an access point.
Definition accesspoint.h:28
QString hardwareAddress() const
AccessPoint::WpaFlags wpaFlags() const
static OperationMode convertOperationMode(uint mode)
Helper method to convert wire representation of operation mode to enum.
OperationMode mode() const
OperationMode
The access point's current operating mode.
Definition accesspoint.h:36
@ Unknown
not associated with a network
Definition accesspoint.h:37
@ ApMode
access point in an infrastructure network
Definition accesspoint.h:40
@ Infra
a station in an infrastructure wireless network
Definition accesspoint.h:39
@ Adhoc
part of an adhoc network
Definition accesspoint.h:38
AccessPoint::WpaFlags rsnFlags() const
Capabilities capabilities() const
QByteArray rawSsid() const
Capabilities capabilities()
QString path(const QString &relativePath)
KGuiItem properties()
bool connect(const QString &service, const QString &path, const QString &interface, const QString &name, QObject *receiver, const char *slot)
QDBusConnection sessionBus()
QDBusConnection systemBus()
QString fromUtf8(QByteArrayView str)
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:08:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.