7#include "wirelesssetting.h"
8#include "wirelesssetting_p.h"
13#define NM_SETTING_WIRELESS_SEC "security"
14#define NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS "assigned-mac-address"
18NetworkManager::WirelessSettingPrivate::WirelessSettingPrivate()
19 : name(NM_SETTING_WIRELESS_SETTING_NAME)
27 , macAddressRandomization(
NetworkManager::Setting::MacAddressRandomizationDefault)
32NetworkManager::WirelessSetting::WirelessSetting()
33 : Setting(Setting::Wireless)
34 , d_ptr(new WirelessSettingPrivate())
38NetworkManager::WirelessSetting::WirelessSetting(
const Ptr &setting)
40 , d_ptr(new WirelessSettingPrivate)
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());
62NetworkManager::WirelessSetting::~WirelessSetting()
74void NetworkManager::WirelessSetting::setSsid(
const QByteArray &ssid)
81QByteArray NetworkManager::WirelessSetting::ssid()
const
83 Q_D(
const WirelessSetting);
88void NetworkManager::WirelessSetting::setMode(NetworkManager::WirelessSetting::NetworkMode mode)
95NetworkManager::WirelessSetting::NetworkMode NetworkManager::WirelessSetting::mode()
const
97 Q_D(
const WirelessSetting);
102void NetworkManager::WirelessSetting::setBand(NetworkManager::WirelessSetting::FrequencyBand band)
104 Q_D(WirelessSetting);
109NetworkManager::WirelessSetting::FrequencyBand NetworkManager::WirelessSetting::band()
const
111 Q_D(
const WirelessSetting);
116void NetworkManager::WirelessSetting::setChannel(quint32 channel)
118 Q_D(WirelessSetting);
120 d->channel = channel;
123quint32 NetworkManager::WirelessSetting::channel()
const
125 Q_D(
const WirelessSetting);
130void NetworkManager::WirelessSetting::setBssid(
const QByteArray &bssid)
132 Q_D(WirelessSetting);
137QByteArray NetworkManager::WirelessSetting::bssid()
const
139 Q_D(
const WirelessSetting);
144void NetworkManager::WirelessSetting::setRate(quint32 rate)
146 Q_D(WirelessSetting);
151quint32 NetworkManager::WirelessSetting::rate()
const
153 Q_D(
const WirelessSetting);
158void NetworkManager::WirelessSetting::setTxPower(quint32 power)
160 Q_D(WirelessSetting);
165quint32 NetworkManager::WirelessSetting::txPower()
const
167 Q_D(
const WirelessSetting);
172void NetworkManager::WirelessSetting::setAssignedMacAddress(
const QString &assignedMacAddress)
174 Q_D(WirelessSetting);
176 d->assignedMacAddress = assignedMacAddress;
179QString NetworkManager::WirelessSetting::assignedMacAddress()
const
181 Q_D(
const WirelessSetting);
183 return d->assignedMacAddress;
186void NetworkManager::WirelessSetting::setMacAddress(
const QByteArray &address)
188 Q_D(WirelessSetting);
193QByteArray NetworkManager::WirelessSetting::macAddress()
const
195 Q_D(
const WirelessSetting);
197 return d->macAddress;
207QByteArray NetworkManager::WirelessSetting::clonedMacAddress()
const
214void NetworkManager::WirelessSetting::setGenerateMacAddressMask(
const QString &macAddressMask)
216 Q_D(WirelessSetting);
218 d->generateMacAddressMask = macAddressMask;
221QString NetworkManager::WirelessSetting::generateMacAddressMask()
const
223 Q_D(
const WirelessSetting);
225 return d->generateMacAddressMask;
228void NetworkManager::WirelessSetting::setMacAddressBlacklist(
const QStringList &list)
230 Q_D(WirelessSetting);
232 d->macAddressBlacklist =
list;
235QStringList NetworkManager::WirelessSetting::macAddressBlacklist()
const
237 Q_D(
const WirelessSetting);
239 return d->macAddressBlacklist;
242void NetworkManager::WirelessSetting::setMacAddressRandomization(NetworkManager::Setting::MacAddressRandomization randomization)
244 Q_D(WirelessSetting);
246 d->macAddressRandomization = randomization;
249NetworkManager::Setting::MacAddressRandomization NetworkManager::WirelessSetting::macAddressRandomization()
const
251 Q_D(
const WirelessSetting);
253 return d->macAddressRandomization;
256void NetworkManager::WirelessSetting::setMtu(quint32 mtu)
258 Q_D(WirelessSetting);
263quint32 NetworkManager::WirelessSetting::mtu()
const
265 Q_D(
const WirelessSetting);
270void NetworkManager::WirelessSetting::setSeenBssids(
const QStringList &list)
272 Q_D(WirelessSetting);
274 d->seenBssids =
list;
277QStringList NetworkManager::WirelessSetting::seenBssids()
const
279 Q_D(
const WirelessSetting);
281 return d->seenBssids;
284void NetworkManager::WirelessSetting::setPowerSave(NetworkManager::WirelessSetting::PowerSave powersave)
286 Q_D(WirelessSetting);
288 d->powersave = powersave;
291NetworkManager::WirelessSetting::PowerSave NetworkManager::WirelessSetting::powerSave()
const
293 Q_D(
const WirelessSetting);
302 d->security = security;
305QString NetworkManager::WirelessSetting::security()
const
312void NetworkManager::WirelessSetting::setHidden(
bool hidden)
314 Q_D(WirelessSetting);
319bool NetworkManager::WirelessSetting::hidden()
const
321 Q_D(
const WirelessSetting);
328 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_SSID))) {
329 setSsid(setting.value(
QLatin1String(NM_SETTING_WIRELESS_SSID)).toByteArray());
332 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_MODE))) {
335 setMode(Infrastructure);
336 }
else if (mode ==
QLatin1String(NM_SETTING_WIRELESS_MODE_ADHOC)) {
338 }
else if (mode ==
QLatin1String(NM_SETTING_WIRELESS_MODE_AP)) {
343 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_BAND))) {
347 }
else if (band ==
"bg") {
352 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_CHANNEL))) {
353 setChannel(setting.value(
QLatin1String(NM_SETTING_WIRELESS_CHANNEL)).toUInt());
356 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_BSSID))) {
357 setBssid(setting.value(
QLatin1String(NM_SETTING_WIRELESS_BSSID)).toByteArray());
360 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_RATE))) {
361 setRate(setting.value(
QLatin1String(NM_SETTING_WIRELESS_RATE)).toUInt());
364 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_TX_POWER))) {
365 setTxPower(setting.value(
QLatin1String(NM_SETTING_WIRELESS_TX_POWER)).toUInt());
368 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS))) {
369 setAssignedMacAddress(setting.value(
QLatin1String(NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS)).toString());
372 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS))) {
373 setMacAddress(setting.value(
QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS)).toByteArray());
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());
380 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS))) {
381 setClonedMacAddress(setting.value(
QLatin1String(NM_SETTING_WIRELESS_CLONED_MAC_ADDRESS)).toByteArray());
384 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST))) {
385 setMacAddressBlacklist(setting.value(
QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST)).toStringList());
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()));
393 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_MTU))) {
394 setMtu(setting.value(
QLatin1String(NM_SETTING_WIRELESS_MTU)).toUInt());
397 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS))) {
398 setSeenBssids(setting.value(
QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS)).toStringList());
401 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_POWERSAVE))) {
402 setPowerSave(
static_cast<WirelessSetting::PowerSave
>(setting.value(
QLatin1String(NM_SETTING_WIRELESS_POWERSAVE)).toUInt()));
405 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_SEC))) {
406 setSecurity(setting.value(
QLatin1String(NM_SETTING_WIRELESS_SEC)).toString());
409 if (setting.contains(
QLatin1String(NM_SETTING_WIRELESS_HIDDEN))) {
410 setHidden(setting.value(
QLatin1String(NM_SETTING_WIRELESS_HIDDEN)).toBool());
418 if (!ssid().isEmpty()) {
419 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SSID), ssid());
422 if (mode() == Infrastructure) {
424 }
else if (mode() == Adhoc) {
426 }
else if (mode() == Ap) {
430 if (band() != Automatic) {
432 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_BAND),
"a");
433 }
else if (band() == Bg) {
434 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_BAND),
"bg");
439 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_CHANNEL), channel());
442 if (!bssid().isEmpty()) {
443 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_BSSID), bssid());
447 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_RATE), rate());
451 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_TX_POWER), txPower());
454 if (!assignedMacAddress().isEmpty()) {
455 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_ASSIGNED_MAC_ADDRESS), assignedMacAddress());
458 if (!macAddress().isEmpty()) {
459 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS), macAddress());
462 if (!generateMacAddressMask().isEmpty()) {
463 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_GENERATE_MAC_ADDRESS_MASK), generateMacAddressMask());
466 if (!macAddressBlacklist().isEmpty()) {
467 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_BLACKLIST), macAddressBlacklist());
470 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_MAC_ADDRESS_RANDOMIZATION), macAddressRandomization());
473 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_MTU), mtu());
476 if (!seenBssids().isEmpty()) {
477 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SEEN_BSSIDS), seenBssids());
480 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_POWERSAVE), powerSave());
482 if (!security().isEmpty()) {
483 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_SEC), security());
487 setting.insert(
QLatin1String(NM_SETTING_WIRELESS_HIDDEN), hidden());
495 dbg.
nospace() <<
"type: " << setting.typeAsString(setting.type()) <<
'\n';
496 dbg.
nospace() <<
"initialized: " << !setting.isNull() <<
'\n';
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';
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...
NETWORKMANAGERQT_EXPORT QByteArray macAddressFromString(const QString &s)
NETWORKMANAGERQT_EXPORT QString macAddressAsString(const QByteArray &ba)