NetworkManagerQt

wirelesssetting.cpp
1/*
2 SPDX-FileCopyrightText: 2012-2013 Jan Grulich <jgrulich@redhat.com>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "wirelesssetting.h"
8#include "wirelesssetting_p.h"
9
10#include "utils.h"
11
12// define the deprecated&dropped values
13#define NM_SETTING_WIRELESS_SEC "security"
14#define NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS "assigned-mac-address"
15
16#include <QDebug>
17
18NetworkManager::WirelessSettingPrivate::WirelessSettingPrivate()
19 : name(NM_SETTING_WIRELESS_SETTING_NAME)
20 , mode(NetworkManager::WirelessSetting::Infrastructure)
21 , band(NetworkManager::WirelessSetting::Automatic)
22 , channel(0)
23 , rate(0)
24 , txPower(0)
25 , mtu(0)
26 , hidden(false)
27 , macAddressRandomization(NetworkManager::Setting::MacAddressRandomizationDefault)
28 , powersave(NetworkManager::WirelessSetting::PowerSaveDefault)
29{
30}
31
32NetworkManager::WirelessSetting::WirelessSetting()
33 : Setting(Setting::Wireless)
34 , d_ptr(new WirelessSettingPrivate())
35{
36}
37
38NetworkManager::WirelessSetting::WirelessSetting(const Ptr &setting)
39 : Setting(setting)
40 , d_ptr(new WirelessSettingPrivate)
41{
42 setSsid(setting->ssid());
43 setMode(setting->mode());
44 setBand(setting->band());
45 setChannel(setting->channel());
46 setBssid(setting->bssid());
47 setRate(setting->rate());
48 setTxPower(setting->txPower());
49 setMacAddress(setting->macAddress());
50 setGenerateMacAddressMask(setting->generateMacAddressMask());
51 setClonedMacAddress(setting->clonedMacAddress());
52 setMacAddressBlacklist(setting->macAddressBlacklist());
53 setMacAddressRandomization(setting->macAddressRandomization());
54 setMtu(setting->mtu());
55 setSeenBssids(setting->seenBssids());
56 setPowerSave(setting->powerSave());
57 setSecurity(setting->security());
58 setHidden(setting->hidden());
59 setAssignedMacAddress(setting->assignedMacAddress());
60}
61
62NetworkManager::WirelessSetting::~WirelessSetting()
63{
64 delete d_ptr;
65}
66
68{
69 Q_D(const WirelessSetting);
70
71 return d->name;
72}
73
74void NetworkManager::WirelessSetting::setSsid(const QByteArray &ssid)
75{
77
78 d->ssid = ssid;
79}
80
81QByteArray NetworkManager::WirelessSetting::ssid() const
82{
83 Q_D(const WirelessSetting);
84
85 return d->ssid;
86}
87
88void NetworkManager::WirelessSetting::setMode(NetworkManager::WirelessSetting::NetworkMode mode)
89{
90 Q_D(WirelessSetting);
91
92 d->mode = mode;
93}
94
95NetworkManager::WirelessSetting::NetworkMode NetworkManager::WirelessSetting::mode() const
96{
97 Q_D(const WirelessSetting);
98
99 return d->mode;
100}
101
102void NetworkManager::WirelessSetting::setBand(NetworkManager::WirelessSetting::FrequencyBand band)
103{
104 Q_D(WirelessSetting);
105
106 d->band = band;
107}
108
109NetworkManager::WirelessSetting::FrequencyBand NetworkManager::WirelessSetting::band() const
110{
111 Q_D(const WirelessSetting);
112
113 return d->band;
114}
115
116void NetworkManager::WirelessSetting::setChannel(quint32 channel)
117{
118 Q_D(WirelessSetting);
119
120 d->channel = channel;
121}
122
123quint32 NetworkManager::WirelessSetting::channel() const
124{
125 Q_D(const WirelessSetting);
126
127 return d->channel;
128}
129
130void NetworkManager::WirelessSetting::setBssid(const QByteArray &bssid)
131{
132 Q_D(WirelessSetting);
133
134 d->bssid = bssid;
135}
136
137QByteArray NetworkManager::WirelessSetting::bssid() const
138{
139 Q_D(const WirelessSetting);
140
141 return d->bssid;
142}
143
144void NetworkManager::WirelessSetting::setRate(quint32 rate)
145{
146 Q_D(WirelessSetting);
147
148 d->rate = rate;
149}
150
151quint32 NetworkManager::WirelessSetting::rate() const
152{
153 Q_D(const WirelessSetting);
154
155 return d->rate;
156}
157
158void NetworkManager::WirelessSetting::setTxPower(quint32 power)
159{
160 Q_D(WirelessSetting);
161
162 d->txPower = power;
163}
164
165quint32 NetworkManager::WirelessSetting::txPower() const
166{
167 Q_D(const WirelessSetting);
168
169 return d->txPower;
170}
171
172void NetworkManager::WirelessSetting::setAssignedMacAddress(const QString &assignedMacAddress)
173{
174 Q_D(WirelessSetting);
175
176 d->assignedMacAddress = assignedMacAddress;
177}
178
179QString NetworkManager::WirelessSetting::assignedMacAddress() const
180{
181 Q_D(const WirelessSetting);
182
183 return d->assignedMacAddress;
184}
185
186void NetworkManager::WirelessSetting::setMacAddress(const QByteArray &address)
187{
188 Q_D(WirelessSetting);
189
190 d->macAddress = address;
191}
192
193QByteArray NetworkManager::WirelessSetting::macAddress() const
194{
195 Q_D(const WirelessSetting);
196
197 return d->macAddress;
198}
199
201{
203
204 d->assignedMacAddress = NetworkManager::macAddressAsString(address);
205}
206
207QByteArray NetworkManager::WirelessSetting::clonedMacAddress() const
208{
209 Q_D(const WirelessSetting);
210
211 return NetworkManager::macAddressFromString(d->assignedMacAddress.toUtf8());
212}
213
214void NetworkManager::WirelessSetting::setGenerateMacAddressMask(const QString &macAddressMask)
215{
216 Q_D(WirelessSetting);
217
218 d->generateMacAddressMask = macAddressMask;
219}
220
221QString NetworkManager::WirelessSetting::generateMacAddressMask() const
222{
223 Q_D(const WirelessSetting);
224
225 return d->generateMacAddressMask;
226}
227
228void NetworkManager::WirelessSetting::setMacAddressBlacklist(const QStringList &list)
229{
230 Q_D(WirelessSetting);
231
232 d->macAddressBlacklist = list;
233}
234
235QStringList NetworkManager::WirelessSetting::macAddressBlacklist() const
236{
237 Q_D(const WirelessSetting);
238
239 return d->macAddressBlacklist;
240}
241
242void NetworkManager::WirelessSetting::setMacAddressRandomization(NetworkManager::Setting::MacAddressRandomization randomization)
243{
244 Q_D(WirelessSetting);
245
246 d->macAddressRandomization = randomization;
247}
248
249NetworkManager::Setting::MacAddressRandomization NetworkManager::WirelessSetting::macAddressRandomization() const
250{
251 Q_D(const WirelessSetting);
252
253 return d->macAddressRandomization;
254}
255
256void NetworkManager::WirelessSetting::setMtu(quint32 mtu)
257{
258 Q_D(WirelessSetting);
259
260 d->mtu = mtu;
261}
262
263quint32 NetworkManager::WirelessSetting::mtu() const
264{
265 Q_D(const WirelessSetting);
266
267 return d->mtu;
268}
269
270void NetworkManager::WirelessSetting::setSeenBssids(const QStringList &list)
271{
272 Q_D(WirelessSetting);
273
274 d->seenBssids = list;
275}
276
277QStringList NetworkManager::WirelessSetting::seenBssids() const
278{
279 Q_D(const WirelessSetting);
280
281 return d->seenBssids;
282}
283
284void NetworkManager::WirelessSetting::setPowerSave(NetworkManager::WirelessSetting::PowerSave powersave)
285{
286 Q_D(WirelessSetting);
287
288 d->powersave = powersave;
289}
290
291NetworkManager::WirelessSetting::PowerSave NetworkManager::WirelessSetting::powerSave() const
292{
293 Q_D(const WirelessSetting);
294
295 return d->powersave;
296}
297
299{
301
302 d->security = security;
303}
304
305QString NetworkManager::WirelessSetting::security() const
306{
307 Q_D(const WirelessSetting);
308
309 return d->security;
310}
311
312void NetworkManager::WirelessSetting::setHidden(bool hidden)
313{
314 Q_D(WirelessSetting);
315
316 d->hidden = hidden;
317}
318
319bool NetworkManager::WirelessSetting::hidden() const
320{
321 Q_D(const WirelessSetting);
322
323 return d->hidden;
324}
325
326void NetworkManager::WirelessSetting::fromMap(const QVariantMap &setting)
327{
328 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_SSID))) {
329 setSsid(setting.value(QLatin1String(NM_SETTING_WIRELESS_SSID)).toByteArray());
330 }
331
332 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_MODE))) {
333 const QString mode = setting.value(QLatin1String(NM_SETTING_WIRELESS_MODE)).toString();
334 if (mode == QLatin1String(NM_SETTING_WIRELESS_MODE_INFRA)) {
335 setMode(Infrastructure);
336 } else if (mode == QLatin1String(NM_SETTING_WIRELESS_MODE_ADHOC)) {
337 setMode(Adhoc);
338 } else if (mode == QLatin1String(NM_SETTING_WIRELESS_MODE_AP)) {
339 setMode(Ap);
340 }
341 }
342
343 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_BAND))) {
344 const QString band = setting.value(QLatin1String(NM_SETTING_WIRELESS_BAND)).toString();
345 if (band == "a") {
346 setBand(A);
347 } else if (band == "bg") {
348 setBand(Bg);
349 }
350 }
351
352 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_CHANNEL))) {
353 setChannel(setting.value(QLatin1String(NM_SETTING_WIRELESS_CHANNEL)).toUInt());
354 }
355
356 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_BSSID))) {
357 setBssid(setting.value(QLatin1String(NM_SETTING_WIRELESS_BSSID)).toByteArray());
358 }
359
360 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_RATE))) {
361 setRate(setting.value(QLatin1String(NM_SETTING_WIRELESS_RATE)).toUInt());
362 }
363
364 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_TX_POWER))) {
365 setTxPower(setting.value(QLatin1String(NM_SETTING_WIRELESS_TX_POWER)).toUInt());
366 }
367
368 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS))) {
369 setAssignedMacAddress(setting.value(QLatin1String(NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS)).toString());
370 }
371
372 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS))) {
373 setMacAddress(setting.value(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS)).toByteArray());
374 }
375
376 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK))) {
377 setGenerateMacAddressMask(setting.value(QLatin1String(NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK)).toString());
378 }
379
380 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS))) {
381 setClonedMacAddress(setting.value(QLatin1String(NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS)).toByteArray());
382 }
383
384 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST))) {
385 setMacAddressBlacklist(setting.value(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST)).toStringList());
386 }
387
388 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION))) {
389 setMacAddressRandomization(
390 static_cast<Setting::MacAddressRandomization>(setting.value(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION)).toUInt()));
391 }
392
393 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_MTU))) {
394 setMtu(setting.value(QLatin1String(NM_SETTING_WIRELESS_MTU)).toUInt());
395 }
396
397 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS))) {
398 setSeenBssids(setting.value(QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS)).toStringList());
399 }
400
401 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_POWERSAVE))) {
402 setPowerSave(static_cast<WirelessSetting::PowerSave>(setting.value(QLatin1String(NM_SETTING_WIRELESS_POWERSAVE)).toUInt()));
403 }
404
405 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_SEC))) {
406 setSecurity(setting.value(QLatin1String(NM_SETTING_WIRELESS_SEC)).toString());
407 }
408
409 if (setting.contains(QLatin1String(NM_SETTING_WIRELESS_HIDDEN))) {
410 setHidden(setting.value(QLatin1String(NM_SETTING_WIRELESS_HIDDEN)).toBool());
411 }
412}
413
415{
416 QVariantMap setting;
417
418 if (!ssid().isEmpty()) {
419 setting.insert(QLatin1String(NM_SETTING_WIRELESS_SSID), ssid());
420 }
421
422 if (mode() == Infrastructure) {
423 setting.insert(QLatin1String(NM_SETTING_WIRELESS_MODE), QLatin1String(NM_SETTING_WIRELESS_MODE_INFRA));
424 } else if (mode() == Adhoc) {
425 setting.insert(QLatin1String(NM_SETTING_WIRELESS_MODE), QLatin1String(NM_SETTING_WIRELESS_MODE_ADHOC));
426 } else if (mode() == Ap) {
427 setting.insert(QLatin1String(NM_SETTING_WIRELESS_MODE), QLatin1String(NM_SETTING_WIRELESS_MODE_AP));
428 }
429
430 if (band() != Automatic) {
431 if (band() == A) {
432 setting.insert(QLatin1String(NM_SETTING_WIRELESS_BAND), "a");
433 } else if (band() == Bg) {
434 setting.insert(QLatin1String(NM_SETTING_WIRELESS_BAND), "bg");
435 }
436 }
437
438 if (channel()) {
439 setting.insert(QLatin1String(NM_SETTING_WIRELESS_CHANNEL), channel());
440 }
441
442 if (!bssid().isEmpty()) {
443 setting.insert(QLatin1String(NM_SETTING_WIRELESS_BSSID), bssid());
444 }
445
446 if (rate()) {
447 setting.insert(QLatin1String(NM_SETTING_WIRELESS_RATE), rate());
448 }
449
450 if (txPower()) {
451 setting.insert(QLatin1String(NM_SETTING_WIRELESS_TX_POWER), txPower());
452 }
453
454 if (!assignedMacAddress().isEmpty()) {
455 setting.insert(QLatin1String(NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS), assignedMacAddress());
456 }
457
458 if (!macAddress().isEmpty()) {
459 setting.insert(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS), macAddress());
460 }
461
462 if (!generateMacAddressMask().isEmpty()) {
463 setting.insert(QLatin1String(NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK), generateMacAddressMask());
464 }
465
466 if (!macAddressBlacklist().isEmpty()) {
467 setting.insert(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST), macAddressBlacklist());
468 }
469
470 setting.insert(QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION), macAddressRandomization());
471
472 if (mtu()) {
473 setting.insert(QLatin1String(NM_SETTING_WIRELESS_MTU), mtu());
474 }
475
476 if (!seenBssids().isEmpty()) {
477 setting.insert(QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS), seenBssids());
478 }
479
480 setting.insert(QLatin1String(NM_SETTING_WIRELESS_POWERSAVE), powerSave());
481
482 if (!security().isEmpty()) {
483 setting.insert(QLatin1String(NM_SETTING_WIRELESS_SEC), security());
484 }
485
486 if (hidden()) {
487 setting.insert(QLatin1String(NM_SETTING_WIRELESS_HIDDEN), hidden());
488 }
489
490 return setting;
491}
492
493QDebug NetworkManager::operator<<(QDebug dbg, const NetworkManager::WirelessSetting &setting)
494{
495 dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n';
496 dbg.nospace() << "initialized: " << !setting.isNull() << '\n';
497
498 dbg.nospace() << NM_SETTING_WIRELESS_SSID << ": " << setting.ssid() << '\n';
499 dbg.nospace() << NM_SETTING_WIRELESS_MODE << ": " << setting.mode() << '\n';
500 dbg.nospace() << NM_SETTING_WIRELESS_BAND << ": " << setting.band() << '\n';
501 dbg.nospace() << NM_SETTING_WIRELESS_CHANNEL << ": " << setting.channel() << '\n';
502 dbg.nospace() << NM_SETTING_WIRELESS_BSSID << ": " << setting.bssid() << '\n';
503 dbg.nospace() << NM_SETTING_WIRELESS_RATE << ": " << setting.rate() << '\n';
504 dbg.nospace() << NM_SETTING_WIRELESS_TX_POWER << ": " << setting.txPower() << '\n';
505 dbg.nospace() << NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS << ": " << setting.assignedMacAddress() << '\n';
506 dbg.nospace() << NM_SETTING_WIRELESS_MAC_ADDRESS << ": " << setting.macAddress() << '\n';
507 dbg.nospace() << NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK << ": " << setting.generateMacAddressMask() << '\n';
508 dbg.nospace() << NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST << ": " << setting.macAddressBlacklist() << '\n';
509 dbg.nospace() << NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION << ": " << setting.macAddressRandomization() << '\n';
510 dbg.nospace() << NM_SETTING_WIRELESS_MTU << ": " << setting.mtu() << '\n';
511 dbg.nospace() << NM_SETTING_WIRELESS_SEEN_BSSIDS << ": " << setting.seenBssids() << '\n';
512 dbg.nospace() << NM_SETTING_WIRELESS_POWERSAVE << ": " << setting.powerSave() << '\n';
513 dbg.nospace() << NM_SETTING_WIRELESS_SEC << ": " << setting.security() << '\n';
514 dbg.nospace() << NM_SETTING_WIRELESS_HIDDEN << ": " << setting.hidden() << '\n';
515
516 return dbg.maybeSpace();
517}
Represents wireless setting.
QString name() const override
Must be reimplemented, default implementationd does nothing.
void setClonedMacAddress(const QByteArray &address)
void fromMap(const QVariantMap &setting) override
Must be reimplemented, default implementation does nothing.
QVariantMap toMap() const override
Must be reimplemented, default implementationd does nothing.
void setSecurity(const QString &security)
PostalAddress address(const QVariant &location)
KIOCORE_EXPORT QStringList list(const QString &fileClass)
This class allows querying the underlying system to discover the available network interfaces and rea...
Definition accesspoint.h:21
NETWORKMANAGERQT_EXPORT QByteArray macAddressFromString(const QString &s)
Definition utils.cpp:50
NETWORKMANAGERQT_EXPORT QString macAddressAsString(const QByteArray &ba)
Definition utils.cpp:39
QDebug & maybeSpace()
QDebug & nospace()
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.