NetworkManagerQt

wirelessdevice.cpp
1/*
2 SPDX-FileCopyrightText: 2008, 2011 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 "wirelessdevice.h"
10#include "wirelessdevice_p.h"
11
12#undef signals
13#include <libnm/NetworkManager.h>
14#define signals Q_SIGNALS
15
16#include "manager_p.h"
17
18#include "nmdebug.h"
19#include "utils.h"
20
21#include <QDBusMetaType>
22
23NetworkManager::WirelessDevicePrivate::WirelessDevicePrivate(const QString &path, WirelessDevice *q)
24 : DevicePrivate(path, q)
25#ifdef NMQT_STATIC
26 , wirelessIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::sessionBus())
27#else
28 , wirelessIface(NetworkManagerPrivate::DBUS_SERVICE, path, QDBusConnection::systemBus())
29#endif
30 , bitRate(0)
31{
32}
33
35 : Device(*new WirelessDevicePrivate(path, this), parent)
36{
38
39 qDBusRegisterMetaType<QList<QDBusObjectPath>>();
40
41#ifdef NMQT_STATIC
42 connect(&d->wirelessIface, &OrgFreedesktopNetworkManagerDeviceWirelessInterface::PropertiesChanged, d, &WirelessDevicePrivate::propertiesChanged);
43#endif
44
45 connect(&d->wirelessIface, &OrgFreedesktopNetworkManagerDeviceWirelessInterface::AccessPointAdded, d, &WirelessDevicePrivate::accessPointAdded);
46 connect(&d->wirelessIface, &OrgFreedesktopNetworkManagerDeviceWirelessInterface::AccessPointRemoved, d, &WirelessDevicePrivate::accessPointRemoved);
47
48 const QList<QDBusObjectPath> aps = d->wirelessIface.accessPoints();
49 // qCDebug(NMQT) << "AccessPoint list";
50 for (const QDBusObjectPath &op : aps) {
51 // qCDebug(NMQT) << " " << op.path();
52 d->accessPointAdded(op);
53 }
54
55 // Get all WirelessDevices's properties at once
56 QVariantMap initialProperties = NetworkManagerPrivate::retrieveInitialProperties(d->wirelessIface.staticInterfaceName(), path);
57 if (!initialProperties.isEmpty()) {
58 d->propertiesChanged(initialProperties);
59 }
60
61}
62
66
71
73{
74 Q_D(const WirelessDevice);
75 return d->apMap.keys();
76}
77
79{
81 d->lastRequestScan = QDateTime::currentDateTime();
82 return d->wirelessIface.RequestScan(options);
83}
84
90
92{
93 Q_D(const WirelessDevice);
94 return d->hardwareAddress;
95}
96
98{
99 Q_D(const WirelessDevice);
100 return d->permanentHardwareAddress;
101}
102
108
110{
111 Q_D(const WirelessDevice);
112 return d->bitRate;
113}
114
116{
117 Q_D(const WirelessDevice);
118 return d->lastScan;
119}
120
122{
123 Q_D(const WirelessDevice);
124 return d->lastRequestScan;
125}
126
132
134{
137
139 if (mapIt != d->apMap.constEnd()) {
140 accessPoint = mapIt.value();
141 } else if (!uni.isEmpty() && uni != QLatin1String("/")) {
142 d->accessPointAdded(QDBusObjectPath(uni));
143 mapIt = d->apMap.constFind(uni);
144 if (mapIt != d->apMap.constEnd()) {
145 accessPoint = mapIt.value();
146 }
147 }
148
149 return accessPoint;
150}
151
153{
154 Q_D(const WirelessDevice);
155 return d->networks.values();
156}
157
159{
160 Q_D(const WirelessDevice);
162 if (d->networks.contains(ssid)) {
163 ret = d->networks.value(ssid);
164 }
165 return ret;
166}
167
168void NetworkManager::WirelessDevicePrivate::accessPointAdded(const QDBusObjectPath &accessPoint)
169{
170 // kDebug(1441) << apPath.path();
171 Q_Q(WirelessDevice);
172
173 if (!apMap.contains(accessPoint.path())) {
175 apMap.insert(accessPoint.path(), accessPointPtr);
176 Q_EMIT q->accessPointAppeared(accessPoint.path());
177
178 const QString ssid = accessPointPtr->ssid();
179 if (!ssid.isEmpty() && !networks.contains(ssid)) {
181 networks.insert(ssid, wifiNetwork);
182 connect(wifiNetwork.data(), &WirelessNetwork::disappeared, this, &WirelessDevicePrivate::removeNetwork);
183 Q_EMIT q->networkAppeared(ssid);
184 }
185 }
186}
187
188void NetworkManager::WirelessDevicePrivate::accessPointRemoved(const QDBusObjectPath &accessPoint)
189{
190 // kDebug(1441) << apPath.path();
191 Q_Q(WirelessDevice);
192 if (!apMap.contains(accessPoint.path())) {
193 qCDebug(NMQT) << "Access point list lookup failed for " << accessPoint.path();
194 }
195 Q_EMIT q->accessPointDisappeared(accessPoint.path());
196 apMap.remove(accessPoint.path());
197}
198
199void NetworkManager::WirelessDevicePrivate::removeNetwork(const QString &network)
200{
201 Q_Q(WirelessDevice);
202
203 if (networks.contains(network)) {
204 networks.remove(network);
205 Q_EMIT q->networkDisappeared(network);
206 }
207}
208
209void NetworkManager::WirelessDevicePrivate::propertyChanged(const QString &property, const QVariant &value)
210{
211 Q_Q(WirelessDevice);
212
213 if (property == QLatin1String("ActiveAccessPoint")) {
214 QDBusObjectPath activeAccessPointTmp = qdbus_cast<QDBusObjectPath>(value);
215 activeAccessPoint = q->findAccessPoint(activeAccessPointTmp.path());
216 Q_EMIT q->activeAccessPointChanged(activeAccessPointTmp.path());
217 } else if (property == QLatin1String("HwAddress")) {
218 hardwareAddress = value.toString();
219 Q_EMIT q->hardwareAddressChanged(hardwareAddress);
220 } else if (property == QLatin1String("PermHwAddress")) {
221 permanentHardwareAddress = value.toString();
222 Q_EMIT q->permanentHardwareAddressChanged(permanentHardwareAddress);
223 } else if (property == QLatin1String("Bitrate")) {
224 bitRate = value.toUInt();
225 Q_EMIT q->bitRateChanged(bitRate);
226 } else if (property == QLatin1String("Mode")) {
227 mode = q->convertOperationMode(value.toUInt());
228 Q_EMIT q->modeChanged(mode);
229 } else if (property == QLatin1String("WirelessCapabilities")) {
230 wirelessCapabilities = q->convertCapabilities(value.toUInt());
231 Q_EMIT q->wirelessCapabilitiesChanged(wirelessCapabilities);
232 } else if (property == QLatin1String("LastScan")) {
233 lastScan = NetworkManager::clockBootTimeToDateTime(value.toLongLong());
234 Q_EMIT q->lastScanChanged(lastScan);
235 } else if (property == QLatin1String("AccessPoints")) {
236 // TODO use this instead AccessPointAdded/Removed signals?
237 } else {
238 DevicePrivate::propertyChanged(property, value);
239 }
240}
241
243{
245 switch (theirMode) {
246 case NM_802_11_MODE_UNKNOWN:
248 break;
249 case NM_802_11_MODE_ADHOC:
251 break;
252 case NM_802_11_MODE_INFRA:
254 break;
255 case NM_802_11_MODE_AP:
257 break;
258 default:
259 qCDebug(NMQT) << Q_FUNC_INFO << "Unhandled mode" << theirMode;
260 }
261 return ourMode;
262}
263
268
269#include "moc_wirelessdevice.cpp"
270#include "moc_wirelessdevice_p.cpp"
Represents an access point.
Definition accesspoint.h:28
This class represents a common device interface.
Definition device.h:34
Type
Device type.
Definition device.h:191
@ Wifi
the Ieee80211 family of wireless networks
Definition device.h:194
A wireless network interface.
QDateTime lastRequestScan() const
The time the last RequestScan function was called.
WirelessDevice::Capabilities wirelessCapabilities() const
Retrieves the capabilities of this wifi network.
static WirelessDevice::Capabilities convertCapabilities(uint)
Helper method to convert wire representation of capabilities to enum.
AccessPoint::Ptr activeAccessPoint() const
AccessPoint pointer this interface is currently associated with.
QString permanentHardwareAddress() const
The permanent hardware address of the network interface.
AccessPoint::Ptr findAccessPoint(const QString &uni)
Finds access point object given its Unique Network Identifier.
int bitRate() const
Retrieves the effective bit rate currently attainable by this device.
WirelessDevice(const QString &path, QObject *parent=nullptr)
Creates a new WirelessDevice object.
WirelessNetwork::List networks() const
Return the current list of networks.
~WirelessDevice() override
Destroys a WirelessDevice object.
OperationMode
The device's current operating mode.
@ ApMode
access point in an infrastructure network
@ Infra
a station in an infrastructure wireless network
@ Unknown
not associated with a network
@ Adhoc
part of an adhoc network
QStringList accessPoints() const
List of wireless networks currently visible to the hardware.
static WirelessDevice::OperationMode convertOperationMode(uint)
Helper method to convert wire representation of operation mode to enum.
Type type() const override
Return the type.
QDBusPendingReply requestScan(const QVariantMap &options=QVariantMap())
Asks the device for a new scan of available wireless networks.
WirelessNetwork::Ptr findNetwork(const QString &ssid) const
Find a network with the given ssid, a Null object is returned if it can not be found.
QDateTime lastScan() const
The LastScan property value, converted to QDateTime.
QString hardwareAddress() const
The hardware address currently used by the network interface.
WirelessDevice::OperationMode mode() const
Retrieves the operation mode of this network.
This class represents a wireless network, which aggregates all access points with the same SSID.
void disappeared(const QString &ssid)
Indicate that this network has no more access points (meaning the network has disappeared from view o...
QString path(const QString &relativePath)
QDateTime currentDateTime()
QString path() const const
ConstIterator
const_iterator constEnd() const const
const_iterator constFind(const Key &key) const const
T value(const Key &key, const T &defaultValue) const const
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
void deleteLater()
bool isEmpty() const const
qlonglong toLongLong(bool *ok) const const
QString toString() const const
uint toUInt(bool *ok) const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 16:56:21 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.