diff --git a/src/accesspoint.h b/src/accesspoint.h index dff0e40..faafefd 100644 --- a/src/accesspoint.h +++ b/src/accesspoint.h @@ -1,205 +1,205 @@ /* Copyright 2008 Will Stephenson Copyright 2011-2013 Lamarque V. Souza Copyright 2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef NETWORKMANAGERQT_ACCESSPOINT_H #define NETWORKMANAGERQT_ACCESSPOINT_H #include #include #include #include #include namespace NetworkManager { class AccessPointPrivate; /** * Represents an access point */ class NETWORKMANAGERQT_EXPORT AccessPoint : public QObject { Q_OBJECT public: typedef QSharedPointer Ptr; typedef QList List; /** * The access point's current operating mode */ enum OperationMode { Unknown = 0, /**< not associated with a network */ Adhoc, /**< part of an adhoc network */ Infra, /**< a station in an infrastructure wireless network */ ApMode /**< access point in an infrastructure network */ }; /** * General capabilities of an access point */ enum Capability { None = 0x0, /**< Null capability - says nothing about the access point */ Privacy = 0x1 /**< Access point supports privacy measures */ }; /** * Flags describing the access point's capabilities according to WPA (Wifi Protected Access) */ enum WpaFlag { PairWep40 = 0x1, PairWep104 = 0x2, PairTkip = 0x4, PairCcmp = 0x8, GroupWep40 = 0x10, GroupWep104 = 0x20, GroupTkip = 0x40, GroupCcmp = 0x80, - KeyMgmtPsk = 0x100, KeyMgmt8021x = 0x200 + KeyMgmtPsk = 0x100, KeyMgmt8021x = 0x200, KeyMgmtSAE = 0x400 }; Q_DECLARE_FLAGS(Capabilities, Capability) Q_FLAG(Capabilities) Q_DECLARE_FLAGS(WpaFlags, WpaFlag) Q_FLAG(WpaFlags) explicit AccessPoint(const QString &path, QObject *parent = nullptr); virtual ~AccessPoint(); /** * @return path of the access point */ QString uni() const; /** * @return capabilities of an access point */ Capabilities capabilities() const; /** * @return flags describing the access point's capabilities according to WPA (Wifi Protected Access). * @see WpaFlag */ AccessPoint::WpaFlags wpaFlags() const; /** * @return Flags describing the access point's capabilities according to the RSN (Robust Secure Network) protocol. * @see WpaFlag */ AccessPoint::WpaFlags rsnFlags() const; /** * @return The Service Set Identifier identifying the access point. */ QString ssid() const; /** * @return raw SSID, encoded as a byte array */ QByteArray rawSsid() const; /** * @return The radio channel frequency in use by the access point, in MHz. */ uint frequency() const; /** * @return The hardware address (BSSID) of the access point. */ QString hardwareAddress() const; /** * @return The maximum bitrate this access point is capable of, in kilobits/second (Kb/s). */ uint maxBitRate() const; /** * @return Describes the operating mode of the access point. */ OperationMode mode() const; /** * @return The current signal quality of the access point, in percent. */ int signalStrength() const; /** * @return The timestamp (in CLOCK_BOOTTIME seconds) for the last time the access point * was found in scan results. A value of -1 means the access point has never been found in scan results. * @since 5.14.0 */ int lastSeen() const; /** * Helper method to convert wire representation of operation @p mode to enum */ static OperationMode convertOperationMode(uint mode); Q_SIGNALS: /** * This signal is emitted when the signal strength of this network has changed. * * @param strength the new signal strength value for this network */ void signalStrengthChanged(int strength); /** * This signal is emitted when the bitrate of this network has changed. * * @param bitrate the new bitrate value for this network */ void bitRateChanged(int bitrate); /** * This signal is emitted when the capabilities of this network have changed. * * @param caps the new capabilities */ void capabilitiesChanged(AccessPoint::Capabilities caps); /** * This signal is emitted when the WPA flags in use by this access point change * * @param flags the new flags */ void wpaFlagsChanged(AccessPoint::WpaFlags flags); /** * This signal is emitted when the RSN(WPA2) flags in use by this access point change * * @param flags the new flags */ void rsnFlagsChanged(AccessPoint::WpaFlags flags); /** * This signal is emitted when the ssid of this Access Point changes * * @param ssid the new SSID */ void ssidChanged(const QString &ssid); /** * This signal is emitted when the frequency used by this Access Point changes * * @param frequency the new frequency */ void frequencyChanged(uint frequency); /** * This signal is emitted when the timestamp for the last time the access point was found * in scan results changes * * @param lastSeen the timestamp for the last time the access point was found in scan results. * @since 5.14.0 * @see lastSeen */ void lastSeenChanged(int lastSeen); private: Q_DECLARE_PRIVATE(AccessPoint) AccessPointPrivate *const d_ptr; }; Q_DECLARE_OPERATORS_FOR_FLAGS(AccessPoint::WpaFlags) } #endif diff --git a/src/settings/wirelesssecuritysetting.cpp b/src/settings/wirelesssecuritysetting.cpp index 29f730b..8e23b83 100644 --- a/src/settings/wirelesssecuritysetting.cpp +++ b/src/settings/wirelesssecuritysetting.cpp @@ -1,711 +1,715 @@ /* Copyright 2012-2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "wirelesssecuritysetting.h" #include "wirelesssecuritysetting_p.h" #include NetworkManager::WirelessSecuritySettingPrivate::WirelessSecuritySettingPrivate() : name(NM_SETTING_WIRELESS_SECURITY_SETTING_NAME) , keyMgmt(NetworkManager::WirelessSecuritySetting::Unknown) , wepTxKeyidx(0) , authAlg(NetworkManager::WirelessSecuritySetting::None) , wepKeyFlags(NetworkManager::Setting::None) , wepKeyType(NetworkManager::WirelessSecuritySetting::NotSpecified) , pskFlags(NetworkManager::Setting::None) , leapPasswordFlags(NetworkManager::Setting::None) { } NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting() : Setting(Setting::WirelessSecurity) , d_ptr(new WirelessSecuritySettingPrivate()) { } NetworkManager::WirelessSecuritySetting::WirelessSecuritySetting(const Ptr &other) : Setting(other) , d_ptr(new WirelessSecuritySettingPrivate()) { setKeyMgmt(other->keyMgmt()); setWepTxKeyindex(other->wepTxKeyindex()); setAuthAlg(other->authAlg()); setProto(other->proto()); setPairwise(other->pairwise()); setGroup(other->group()); setWepKey0(other->wepKey0()); setWepKey1(other->wepKey1()); setWepKey2(other->wepKey2()); setWepKey3(other->wepKey3()); setWepKeyFlags(other->wepKeyFlags()); setWepKeyType(other->wepKeyType()); setPsk(other->psk()); setPskFlags(other->pskFlags()); setLeapPassword(other->leapPassword()); setLeapPasswordFlags(other->leapPasswordFlags()); } NetworkManager::WirelessSecuritySetting::~WirelessSecuritySetting() { delete d_ptr; } QString NetworkManager::WirelessSecuritySetting::name() const { Q_D(const WirelessSecuritySetting); return d->name; } void NetworkManager::WirelessSecuritySetting::setKeyMgmt(NetworkManager::WirelessSecuritySetting::KeyMgmt mgmt) { Q_D(WirelessSecuritySetting); d->keyMgmt = mgmt; } NetworkManager::WirelessSecuritySetting::KeyMgmt NetworkManager::WirelessSecuritySetting::keyMgmt() const { Q_D(const WirelessSecuritySetting); return d->keyMgmt; } void NetworkManager::WirelessSecuritySetting::setWepTxKeyindex(quint32 index) { Q_D(WirelessSecuritySetting); d->wepTxKeyidx = index; } quint32 NetworkManager::WirelessSecuritySetting::wepTxKeyindex() const { Q_D(const WirelessSecuritySetting); return d->wepTxKeyidx; } void NetworkManager::WirelessSecuritySetting::setAuthAlg(NetworkManager::WirelessSecuritySetting::AuthAlg alg) { Q_D(WirelessSecuritySetting); d->authAlg = alg; } NetworkManager::WirelessSecuritySetting::AuthAlg NetworkManager::WirelessSecuritySetting::authAlg() const { Q_D(const WirelessSecuritySetting); return d->authAlg; } void NetworkManager::WirelessSecuritySetting::setProto(const QList< NetworkManager::WirelessSecuritySetting::WpaProtocolVersion > &list) { Q_D(WirelessSecuritySetting); d->proto = list; } QList< NetworkManager::WirelessSecuritySetting::WpaProtocolVersion > NetworkManager::WirelessSecuritySetting::proto() const { Q_D(const WirelessSecuritySetting); return d->proto; } void NetworkManager::WirelessSecuritySetting::setPairwise(const QList< NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities > &list) { Q_D(WirelessSecuritySetting); d->pairwise = list; } QList< NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities > NetworkManager::WirelessSecuritySetting::pairwise() const { Q_D(const WirelessSecuritySetting); return d->pairwise; } void NetworkManager::WirelessSecuritySetting::setGroup(const QList< NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities > &list) { Q_D(WirelessSecuritySetting); d->group = list; } QList< NetworkManager::WirelessSecuritySetting::WpaEncryptionCapabilities > NetworkManager::WirelessSecuritySetting::group() const { Q_D(const WirelessSecuritySetting); return d->group; } void NetworkManager::WirelessSecuritySetting::setLeapUsername(const QString &username) { Q_D(WirelessSecuritySetting); d->leapUsername = username; } QString NetworkManager::WirelessSecuritySetting::leapUsername() const { Q_D(const WirelessSecuritySetting); return d->leapUsername; } void NetworkManager::WirelessSecuritySetting::setWepKey0(const QString key) { Q_D(WirelessSecuritySetting); d->wepKey0 = key; } QString NetworkManager::WirelessSecuritySetting::wepKey0() const { Q_D(const WirelessSecuritySetting); return d->wepKey0; } void NetworkManager::WirelessSecuritySetting::setWepKey1(const QString key) { Q_D(WirelessSecuritySetting); d->wepKey1 = key; } QString NetworkManager::WirelessSecuritySetting::wepKey1() const { Q_D(const WirelessSecuritySetting); return d->wepKey1; } void NetworkManager::WirelessSecuritySetting::setWepKey2(const QString key) { Q_D(WirelessSecuritySetting); d->wepKey2 = key; } QString NetworkManager::WirelessSecuritySetting::wepKey2() const { Q_D(const WirelessSecuritySetting); return d->wepKey2; } void NetworkManager::WirelessSecuritySetting::setWepKey3(const QString key) { Q_D(WirelessSecuritySetting); d->wepKey3 = key; } QString NetworkManager::WirelessSecuritySetting::wepKey3() const { Q_D(const WirelessSecuritySetting); return d->wepKey3; } void NetworkManager::WirelessSecuritySetting::setWepKeyFlags(NetworkManager::Setting::SecretFlags type) { Q_D(WirelessSecuritySetting); d->wepKeyFlags = type; } NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::wepKeyFlags() const { Q_D(const WirelessSecuritySetting); return d->wepKeyFlags; } void NetworkManager::WirelessSecuritySetting::setWepKeyType(NetworkManager::WirelessSecuritySetting::WepKeyType type) { Q_D(WirelessSecuritySetting); d->wepKeyType = type; } NetworkManager::WirelessSecuritySetting::WepKeyType NetworkManager::WirelessSecuritySetting::wepKeyType() const { Q_D(const WirelessSecuritySetting); return d->wepKeyType; } void NetworkManager::WirelessSecuritySetting::setPsk(const QString &key) { Q_D(WirelessSecuritySetting); d->psk = key; } QString NetworkManager::WirelessSecuritySetting::psk() const { Q_D(const WirelessSecuritySetting); return d->psk; } void NetworkManager::WirelessSecuritySetting::setPskFlags(NetworkManager::Setting::SecretFlags type) { Q_D(WirelessSecuritySetting); d->pskFlags = type; } NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::pskFlags() const { Q_D(const WirelessSecuritySetting); return d->pskFlags; } void NetworkManager::WirelessSecuritySetting::setLeapPassword(const QString &password) { Q_D(WirelessSecuritySetting); d->leapPassword = password; } QString NetworkManager::WirelessSecuritySetting::leapPassword() const { Q_D(const WirelessSecuritySetting); return d->leapPassword; } void NetworkManager::WirelessSecuritySetting::setLeapPasswordFlags(NetworkManager::Setting::SecretFlags type) { Q_D(WirelessSecuritySetting); d->leapPasswordFlags = type; } NetworkManager::Setting::SecretFlags NetworkManager::WirelessSecuritySetting::leapPasswordFlags() const { Q_D(const WirelessSecuritySetting); return d->leapPasswordFlags; } void NetworkManager::WirelessSecuritySetting::secretsFromMap(const QVariantMap &secrets) { if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0))) { setWepKey0(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)).toString()); } if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1))) { setWepKey1(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)).toString()); } if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2))) { setWepKey2(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)).toString()); } if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3))) { setWepKey3(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)).toString()); } if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK))) { setPsk(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK)).toString()); } if (secrets.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD))) { setLeapPassword(secrets.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD)).toString()); } } QVariantMap NetworkManager::WirelessSecuritySetting::secretsToMap() const { QVariantMap secrets; if (!wepKey0().isEmpty()) { secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), wepKey0()); } if (!wepKey1().isEmpty()) { secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), wepKey1()); } if (!wepKey2().isEmpty()) { secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), wepKey2()); } if (!wepKey3().isEmpty()) { secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), wepKey3()); } if (!psk().isEmpty()) { secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), psk()); } if (!leapPassword().isEmpty()) { secrets.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), leapPassword()); } return secrets; } QStringList NetworkManager::WirelessSecuritySetting::needSecrets(bool requestNew) const { QStringList secrets; if (keyMgmt() == Wep) { if (!wepKeyFlags().testFlag(Setting::NotRequired)) { switch (wepTxKeyindex()) { case 0: if (wepKey0().isEmpty() || requestNew) { secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0); return secrets; } break; case 1: if (wepKey1().isEmpty() || requestNew) { secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1); return secrets; } break; case 2: if (wepKey2().isEmpty() || requestNew) { secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2); return secrets; } break; case 3: if (wepKey3().isEmpty() || requestNew) { secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3); return secrets; } break; } } } if (keyMgmt() == WpaNone || - keyMgmt() == WpaPsk) { + keyMgmt() == WpaPsk || keyMgmt() == SAE) { if (!pskFlags().testFlag(Setting::NotRequired)) { if (psk().isEmpty() || requestNew) { secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK); return secrets; } } } if (authAlg() == Leap && keyMgmt() == Ieee8021x) { if (!leapPasswordFlags().testFlag(Setting::NotRequired)) { if (leapPassword().isEmpty() || requestNew) { secrets << QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD); return secrets; } } } return secrets; } void NetworkManager::WirelessSecuritySetting::fromMap(const QVariantMap &map) { if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT))) { const QString key = map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT)).toString(); if (key == "none") { setKeyMgmt(Wep); } else if (key == "ieee8021x") { setKeyMgmt(Ieee8021x); } else if (key == "wpa-none") { setKeyMgmt(WpaNone); } else if (key == "wpa-psk") { setKeyMgmt(WpaPsk); } else if (key == "wpa-eap") { setKeyMgmt(WpaEap); + } else if (key == "sae") { + setKeyMgmt(SAE); } } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX))) { setWepTxKeyindex(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX)).toUInt()); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG))) { const QString alg = map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG)).toString(); if (alg == "open") { setAuthAlg(Open); } else if (alg == "shared") { setAuthAlg(Shared); } else if (alg == "leap") { setAuthAlg(Leap); } } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO))) { const QStringList strList = map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO)).toStringList(); QList list; Q_FOREACH (const QString & str, strList) { if (str == "wpa") { list.push_back(Wpa); } else if (str == "rsn") { list.push_back(Rsn); } } setProto(list); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE))) { const QStringList strList = map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE)).toStringList(); QList list; Q_FOREACH (const QString & str, strList) { if (str == "wep40") { list.push_back(Wep40); } else if (str == "wep104") { list.push_back(Wep104); } else if (str == "tkip") { list.push_back(Tkip); } else if (str == "ccmp") { list.push_back(Ccmp); } } setPairwise(list); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP))) { const QStringList strList = map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP)).toStringList(); QList list; Q_FOREACH (const QString & str, strList) { if (str == "wep40") { list.push_back(Wep40); } else if (str == "wep104") { list.push_back(Wep104); } else if (str == "tkip") { list.push_back(Tkip); } else if (str == "ccmp") { list.push_back(Ccmp); } } setGroup(list); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME))) { setLeapUsername(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME)).toString()); } // Secrets if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0))) { setWepKey0(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)).toString()); } // Secrets if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1))) { setWepKey1(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)).toString()); } // Secrets if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2))) { setWepKey2(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)).toString()); } // Secrets if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3))) { setWepKey3(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)).toString()); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS))) { setWepKeyFlags((SecretFlags)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS)).toInt()); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE))) { setWepKeyType((WepKeyType)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE)).toUInt()); } // Secrets if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK))) { setPsk(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK)).toString()); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS))) { setPskFlags((SecretFlags)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS)).toInt()); } // Secrets if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD))) { setLeapPassword(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD)).toString()); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS))) { setLeapPasswordFlags((SecretFlags)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS)).toInt()); } } QVariantMap NetworkManager::WirelessSecuritySetting::toMap() const { QVariantMap setting; if (keyMgmt() == Wep) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "none"); } else if (keyMgmt() == Ieee8021x) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "ieee8021x"); } else if (keyMgmt() == WpaNone) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "wpa-none"); } else if (keyMgmt() == WpaPsk) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "wpa-psk"); } else if (keyMgmt() == WpaEap) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "wpa-eap"); + } else if (keyMgmt() == SAE) { + setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "sae"); } if (wepTxKeyindex()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX), wepTxKeyindex()); } if (authAlg() != None) { if (authAlg() == Open) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), "open"); } else if (authAlg() == Shared) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), "shared"); } else if (authAlg() == Leap) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), "leap"); } } if (!proto().isEmpty()) { QStringList strList; Q_FOREACH (const WpaProtocolVersion & version, proto()) { if (version == Wpa) { strList << "wpa"; } else if (version == Rsn) { strList << "rsn"; } } setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO), strList); } if (!pairwise().isEmpty()) { QStringList strList; Q_FOREACH (const WpaEncryptionCapabilities & capability, pairwise()) { if (capability == Wep40) { strList << "wep40"; } else if (capability == Wep104) { strList << "wep104"; } else if (capability == Tkip) { strList << "tkip"; } else if (capability == Ccmp) { strList << "ccmp"; } } setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE), strList); } if (!group().isEmpty()) { QStringList strList; Q_FOREACH (const WpaEncryptionCapabilities & capability, group()) { if (capability == Wep40) { strList << "wep40"; } else if (capability == Wep104) { strList << "wep104"; } else if (capability == Tkip) { strList << "tkip"; } else if (capability == Ccmp) { strList << "ccmp"; } } setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP), strList); } if (!leapUsername().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), leapUsername()); } // Secrets if (!wepKey0().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), wepKey0()); } // Secrets if (!wepKey1().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), wepKey1()); } // Secrets if (!wepKey2().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), wepKey2()); } // Secrets if (!wepKey3().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), wepKey3()); } if (wepKeyFlags()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS), (int)wepKeyFlags()); } if (wepKeyType()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), wepKeyType()); } // Secrets if (!psk().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), psk()); } if (pskFlags()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS), (int)pskFlags()); } // Secrets if (!leapPassword().isEmpty()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), leapPassword()); } if (leapPasswordFlags()) { setting.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS), (int)leapPasswordFlags()); } return setting; } QDebug NetworkManager::operator <<(QDebug dbg, const NetworkManager::WirelessSecuritySetting &setting) { dbg.nospace() << "type: " << setting.typeAsString(setting.type()) << '\n'; dbg.nospace() << "initialized: " << !setting.isNull() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_KEY_MGMT << ": " << setting.keyMgmt() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX << ": " << setting.wepTxKeyindex() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_AUTH_ALG << ": " << setting.authAlg() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PROTO << ": " << setting.proto() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PAIRWISE << ": " << setting.pairwise() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_GROUP << ": " << setting.group() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME << ": " << setting.leapUsername() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY0 << ": " << setting.wepKey0() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY1 << ": " << setting.wepKey1() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY2 << ": " << setting.wepKey2() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY3 << ": " << setting.wepKey3() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS << ": " << setting.wepKeyFlags() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE << ": " << setting.wepKeyType() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PSK << ": " << setting.psk() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS << ": " << setting.pskFlags() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD << ": " << setting.leapPassword() << '\n'; dbg.nospace() << NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS << ": " << setting.leapPasswordFlags() << '\n'; return dbg.maybeSpace(); } diff --git a/src/settings/wirelesssecuritysetting.h b/src/settings/wirelesssecuritysetting.h index e383b40..c3c1773 100644 --- a/src/settings/wirelesssecuritysetting.h +++ b/src/settings/wirelesssecuritysetting.h @@ -1,126 +1,126 @@ /* Copyright 2012-2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef NETWORKMANAGERQT_WIRELESSSECURITY_SETTING_H #define NETWORKMANAGERQT_WIRELESSSECURITY_SETTING_H #include #include "setting.h" #include namespace NetworkManager { class WirelessSecuritySettingPrivate; /** * Represents wireless security setting */ class NETWORKMANAGERQT_EXPORT WirelessSecuritySetting : public Setting { public: typedef QSharedPointer Ptr; typedef QList List; - enum KeyMgmt {Unknown = -1, Wep, Ieee8021x, WpaNone, WpaPsk, WpaEap}; + enum KeyMgmt {Unknown = -1, Wep, Ieee8021x, WpaNone, WpaPsk, WpaEap, SAE}; enum AuthAlg {None, Open, Shared, Leap}; enum WpaProtocolVersion {Wpa, Rsn}; enum WpaEncryptionCapabilities {Wep40, Wep104, Tkip, Ccmp}; enum WepKeyType {NotSpecified, Hex, Passphrase}; WirelessSecuritySetting(); explicit WirelessSecuritySetting(const Ptr &other); ~WirelessSecuritySetting() override; QString name() const override; void setKeyMgmt(KeyMgmt mgmt); KeyMgmt keyMgmt() const; void setWepTxKeyindex(quint32 index); quint32 wepTxKeyindex() const; void setAuthAlg(AuthAlg alg); AuthAlg authAlg() const; void setProto(const QList &list); QList proto() const; void setPairwise(const QList &list); QList pairwise() const; void setGroup(const QList &list); QList group() const; void setLeapUsername(const QString &username); QString leapUsername() const; void setWepKey0(const QString key); QString wepKey0() const; void setWepKey1(const QString key); QString wepKey1() const; void setWepKey2(const QString key); QString wepKey2() const; void setWepKey3(const QString key); QString wepKey3() const; void setWepKeyFlags(SecretFlags type); SecretFlags wepKeyFlags() const; void setWepKeyType(WepKeyType type); WepKeyType wepKeyType() const; void setPsk(const QString &key); QString psk() const; void setPskFlags(SecretFlags type); SecretFlags pskFlags() const; void setLeapPassword(const QString &password); QString leapPassword() const; void setLeapPasswordFlags(SecretFlags type); SecretFlags leapPasswordFlags() const; void secretsFromMap(const QVariantMap &secrets) override; QVariantMap secretsToMap() const override; QStringList needSecrets(bool requestNew = false) const override; void fromMap(const QVariantMap &map) override; QVariantMap toMap() const override; protected: WirelessSecuritySettingPrivate *d_ptr; private: Q_DECLARE_PRIVATE(WirelessSecuritySetting) }; NETWORKMANAGERQT_EXPORT QDebug operator<<(QDebug dbg, const WirelessSecuritySetting &setting); } #endif // NETWORKMANAGERQT_WIRELESSSECURITY_SETTING_H diff --git a/src/utils.cpp b/src/utils.cpp index 90f3f41..1e0c3a5 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -1,555 +1,580 @@ /* Copyright 2009 Will Stephenson Copyright 2012-2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "utils.h" #include "time.h" QHostAddress NetworkManager::ipv6AddressAsHostAddress(const QByteArray &address) { // Q_ASSERT(address.size() == 16); Q_IPV6ADDR tmp; for (int i = 0; i < 16; ++i) { tmp[i] = address[i]; } QHostAddress hostaddress(tmp); Q_ASSERT(hostaddress.protocol() == QAbstractSocket::IPv6Protocol); return hostaddress; } QByteArray NetworkManager::ipv6AddressFromHostAddress(const QHostAddress &address) { // Q_ASSERT(address.protocol() == QAbstractSocket::IPv6Protocol); Q_IPV6ADDR tmp = address.toIPv6Address(); QByteArray assembledAddress; for (int i = 0; i < 16; ++i) { assembledAddress[i] = tmp[i]; } return assembledAddress; } QString NetworkManager::macAddressAsString(const QByteArray &ba) { QStringList mac; for (int i = 0; i < ba.size(); ++i) { mac << QString("%1").arg((quint8)ba[i], 2, 16, QLatin1Char('0')).toUpper(); } return mac.join(":"); } QByteArray NetworkManager::macAddressFromString(const QString &s) { QStringList macStringList = s.split(':'); // Q_ASSERT(macStringList.size() == 6); QByteArray ba; if (!s.isEmpty()) { ba.resize(6); int i = 0; Q_FOREACH (const QString & macPart, macStringList) { ba[i++] = macPart.toUInt(nullptr, 16); } } return ba; } bool NetworkManager::macAddressIsValid(const QString &macAddress) { QRegExp macAddressCheck = QRegExp("([a-fA-F0-9][a-fA-F0-9]:){5}[0-9a-fA-F][0-9a-fA-F]"); return macAddress.contains(macAddressCheck); } bool NetworkManager::macAddressIsValid(const QByteArray &macAddress) { return macAddressIsValid(macAddressAsString(macAddress)); } int NetworkManager::findChannel(int freq) { int channel; if (freq < 2500) { channel = 0; int i = 0; QList > bFreqs = getBFreqs(); while (i < bFreqs.size()) { if (bFreqs.at(i).second <= freq) { channel = bFreqs.at(i).first; } else { break; } i++; } return channel; } channel = 0; int i = 0; QList > aFreqs = getAFreqs(); while (i < aFreqs.size()) { if (aFreqs.at(i).second <= freq) { channel = aFreqs.at(i).first; } else { break; } i++; } return channel; } NetworkManager::WirelessSetting::FrequencyBand NetworkManager::findFrequencyBand(int freq) { if (freq < 2500) { return WirelessSetting::Bg; } return WirelessSetting::A; } bool NetworkManager::deviceSupportsApCiphers(NetworkManager::WirelessDevice::Capabilities interfaceCaps, NetworkManager::AccessPoint::WpaFlags apCiphers, WirelessSecurityType type) { bool havePair = false; bool haveGroup = true; if (type == NetworkManager::StaticWep) { havePair = true; } else { if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep40) && apCiphers.testFlag(NetworkManager::AccessPoint::PairWep40)) { havePair = true; } if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep104) && apCiphers.testFlag(NetworkManager::AccessPoint::PairWep104)) { havePair = true; } if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Tkip) && apCiphers.testFlag(NetworkManager::AccessPoint::PairTkip)) { havePair = true; } if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp) && apCiphers.testFlag(NetworkManager::AccessPoint::PairCcmp)) { havePair = true; } } if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep40) && apCiphers.testFlag(NetworkManager::AccessPoint::GroupWep40)) { haveGroup = true; } if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep104) && apCiphers.testFlag(NetworkManager::AccessPoint::GroupWep104)) { haveGroup = true; } if (type != StaticWep) { if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Tkip) && apCiphers.testFlag(NetworkManager::AccessPoint::GroupTkip)) { haveGroup = true; } if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp) && apCiphers.testFlag(NetworkManager::AccessPoint::GroupCcmp)) { haveGroup = true; } } return (havePair && haveGroup); } // Keep this in sync with NetworkManager/libnm-util/nm-utils.c:nm_utils_security_valid() bool NetworkManager::securityIsValid(WirelessSecurityType type, NetworkManager::WirelessDevice::Capabilities interfaceCaps, bool haveAp, bool adhoc, NetworkManager::AccessPoint::Capabilities apCaps, NetworkManager::AccessPoint::WpaFlags apWpa, NetworkManager::AccessPoint::WpaFlags apRsn) { bool good = true; //kDebug() << "type(" << type << ") interfaceCaps(" << interfaceCaps << ") haveAp(" << haveAp << ") adhoc(" << adhoc << ") apCaps(" << apCaps << ") apWpa(" << apWpa << " apRsn(" << apRsn << ")"; if (!haveAp) { if (type == NoneSecurity) { return true; } if ((type == StaticWep) || ((type == DynamicWep) && !adhoc) || ((type == Leap) && !adhoc)) { if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep40) || interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wep104)) { return true; } } // apCaps.testFlag(Privacy) == true for StaticWep, Leap and DynamicWep // see libs/internals/wirelessinterfaceconnectionhelpers.cpp // TODO: this is not in nm-utils.c // if (type == Knm::WirelessSecurity::WpaPsk // || ((type == Knm::WirelessSecurity::WpaEap) && !adhoc)) { // if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wpa) && // !apCaps.testFlag(NetworkManager::AccessPoint::Privacy)) { // return true; // } // } // if (type == Knm::WirelessSecurity::Wpa2Psk // || ((type == Knm::WirelessSecurity::Wpa2Eap) && !adhoc)) { // if (interfaceCaps.testFlag(NetworkManager::WirelessDevice::Rsn) && // !apCaps.testFlag(NetworkManager::AccessPoint::Privacy)) { // return true; // } // } return false; } switch (type) { case NoneSecurity: Q_ASSERT(haveAp); if (apCaps.testFlag(NetworkManager::AccessPoint::Privacy)) { return false; } if (apWpa || apRsn) { return false; } break; case Leap: /* require PRIVACY bit for LEAP? */ if (adhoc) { return false; } /* Fall through */ case StaticWep: Q_ASSERT(haveAp); if (!apCaps.testFlag(NetworkManager::AccessPoint::Privacy)) { return false; } if (apWpa || apRsn) { if (!deviceSupportsApCiphers(interfaceCaps, apWpa, StaticWep)) if (!deviceSupportsApCiphers(interfaceCaps, apRsn, StaticWep)) { return false; } } break; case DynamicWep: if (adhoc) { return false; } Q_ASSERT(haveAp); if (apRsn || !(apCaps.testFlag(NetworkManager::AccessPoint::Privacy))) { return false; } /* Some APs broadcast minimal WPA-enabled beacons that must be handled */ if (apWpa) { if (!apWpa.testFlag(NetworkManager::AccessPoint::KeyMgmt8021x)) { return false; } if (!deviceSupportsApCiphers(interfaceCaps, apWpa, DynamicWep)) { return false; } } break; case WpaPsk: if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wpa)) { return false; } if (haveAp) { /* Ad-Hoc WPA APs won't necessarily have the PSK flag set */ if (adhoc) { if (apWpa.testFlag(NetworkManager::AccessPoint::GroupTkip) && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Tkip)) { return true; } if (apWpa.testFlag(NetworkManager::AccessPoint::GroupCcmp) && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp)) { return true; } } else if (apWpa.testFlag(NetworkManager::AccessPoint::KeyMgmtPsk)) { if (apWpa.testFlag(NetworkManager::AccessPoint::PairTkip) && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Tkip)) { return true; } if (apWpa.testFlag(NetworkManager::AccessPoint::PairCcmp) && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp)) { return true; } } return false; } break; case Wpa2Psk: if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::Rsn)) { return false; } if (haveAp) { /* Ad-Hoc WPA APs won't necessarily have the PSK flag set */ if (apRsn.testFlag(NetworkManager::AccessPoint::KeyMgmtPsk) || adhoc) { if (apRsn.testFlag(NetworkManager::AccessPoint::PairTkip) && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Tkip)) { return true; } if (apRsn.testFlag(NetworkManager::AccessPoint::PairCcmp) && interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp)) { return true; } } return false; } break; case WpaEap: if (adhoc) { return false; } if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::Wpa)) { return false; } if (haveAp) { if (!apWpa.testFlag(NetworkManager::AccessPoint::KeyMgmt8021x)) { return false; } /* Ensure at least one WPA cipher is supported */ if (!deviceSupportsApCiphers(interfaceCaps, apWpa, WpaEap)) { return false; } } break; case Wpa2Eap: if (adhoc) { return false; } if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::Rsn)) { return false; } if (haveAp) { if (!apRsn.testFlag(NetworkManager::AccessPoint::KeyMgmt8021x)) { return false; } /* Ensure at least one WPA cipher is supported */ if (!deviceSupportsApCiphers(interfaceCaps, apRsn, Wpa2Eap)) { return false; } } break; + case SAE: + if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::Rsn)) { + return false; + } + if (haveAp) { + if (!interfaceCaps.testFlag(NetworkManager::WirelessDevice::IBSSRsn)) { + return false; + } + if (apRsn.testFlag(NetworkManager::AccessPoint::PairCcmp) && + interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp)) { + return true; + } + } else { + if (apRsn.testFlag(NetworkManager::AccessPoint::KeyMgmtSAE)) { + if (apRsn.testFlag(NetworkManager::AccessPoint::PairTkip) && + interfaceCaps.testFlag(NetworkManager::WirelessDevice::Tkip)) { + return true; + } + if (apRsn.testFlag(NetworkManager::AccessPoint::PairCcmp) && + interfaceCaps.testFlag(NetworkManager::WirelessDevice::Ccmp)) { + return true; + } + } + return false; + } default: good = false; break; } return good; } NetworkManager::WirelessSecurityType NetworkManager::findBestWirelessSecurity(NetworkManager::WirelessDevice::Capabilities interfaceCaps, bool haveAp, bool adHoc, NetworkManager::AccessPoint::Capabilities apCaps, NetworkManager::AccessPoint::WpaFlags apWpa, NetworkManager::AccessPoint::WpaFlags apRsn) { QList types; // The ordering of this list is a pragmatic combination of security level and popularity. // Therefore static WEP is before LEAP and Dynamic WEP because there is no way to detect // if an AP is capable of Dynamic WEP and showing Dynamic WEP first would confuse // Static WEP users. - types << NetworkManager::Wpa2Eap << NetworkManager::Wpa2Psk << NetworkManager::WpaEap << NetworkManager::WpaPsk << NetworkManager::StaticWep << NetworkManager::DynamicWep << NetworkManager::Leap << NetworkManager::NoneSecurity; + types << NetworkManager::SAE << NetworkManager::Wpa2Eap << NetworkManager::Wpa2Psk << NetworkManager::WpaEap << NetworkManager::WpaPsk << NetworkManager::StaticWep << NetworkManager::DynamicWep << NetworkManager::Leap << NetworkManager::NoneSecurity; Q_FOREACH (NetworkManager::WirelessSecurityType type, types) { if (NetworkManager::securityIsValid(type, interfaceCaps, haveAp, adHoc, apCaps, apWpa, apRsn)) { return type; } } return NetworkManager::UnknownSecurity; } bool NetworkManager::wepKeyIsValid(const QString &key, NetworkManager::WirelessSecuritySetting::WepKeyType type) { if (key.isEmpty()) { return false; } const int keylen = key.length(); if (type != WirelessSecuritySetting::NotSpecified) { if (type == WirelessSecuritySetting::Hex) { if (keylen == 10 || keylen == 26) { /* Hex key */ for (int i = 0; i < keylen; ++i) { if (!(key.at(i).isDigit() || (key.at(i) >= 'A' && key.at(i) <= 'F') || (key.at(i) >= 'a' && key.at(i) <= 'f'))) { return false; } } return true; } else if (keylen == 5 || keylen == 13) { /* ASCII KEY */ for (int i = 0; i < keylen; ++i) { if (!key.at(i).isPrint()) { return false; } } return true; } return false; } else if (type == WirelessSecuritySetting::Passphrase) { if (!keylen || keylen > 64) { return false; } return true; } } return false; } bool NetworkManager::wpaPskIsValid(const QString &psk) { if (psk.isEmpty()) { return false; } const int psklen = psk.length(); if (psklen < 8 || psklen > 64) { return false; } if (psklen == 64) { /* Hex PSK */ for (int i = 0; i < psklen; ++i) { if (!psk.at(i).isLetterOrNumber()) { return false; } } } return true; } NetworkManager::WirelessSecurityType NetworkManager::securityTypeFromConnectionSetting(const NetworkManager::ConnectionSettings::Ptr &settings) { NetworkManager::WirelessSecuritySetting::Ptr wifiSecuritySetting = settings->setting(Setting::WirelessSecurity).dynamicCast(); if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::Wep) { return StaticWep; } else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::Ieee8021x) { if (wifiSecuritySetting->authAlg() == WirelessSecuritySetting::Leap) { return Leap; } else { return DynamicWep; } } else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::WpaPsk) { if (wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Wpa) && !wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Rsn)) { return WpaPsk; } return Wpa2Psk; } else if (wifiSecuritySetting->keyMgmt() == WirelessSecuritySetting::WpaEap) { if (wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Wpa) && !wifiSecuritySetting->proto().contains(WirelessSecuritySetting::Rsn)) { return WpaEap; } return Wpa2Eap; } return NoneSecurity; } QList > NetworkManager::getBFreqs() { QList > freqs; freqs.append(QPair(1, 2412)); freqs.append(QPair(2, 2417)); freqs.append(QPair(3, 2422)); freqs.append(QPair(4, 2427)); freqs.append(QPair(5, 2432)); freqs.append(QPair(6, 2437)); freqs.append(QPair(7, 2442)); freqs.append(QPair(8, 2447)); freqs.append(QPair(9, 2452)); freqs.append(QPair(10, 2457)); freqs.append(QPair(11, 2462)); freqs.append(QPair(12, 2467)); freqs.append(QPair(13, 2472)); freqs.append(QPair(14, 2484)); return freqs; } QList > NetworkManager::getAFreqs() { QList > freqs; freqs.append(QPair(7, 5035)); freqs.append(QPair(8, 5040)); freqs.append(QPair(9, 5045)); freqs.append(QPair(11, 5055)); freqs.append(QPair(12, 5060)); freqs.append(QPair(16, 5080)); freqs.append(QPair(34, 5170)); freqs.append(QPair(36, 5180)); freqs.append(QPair(38, 5190)); freqs.append(QPair(40, 5200)); freqs.append(QPair(42, 5210)); freqs.append(QPair(44, 5220)); freqs.append(QPair(46, 5230)); freqs.append(QPair(48, 5240)); freqs.append(QPair(52, 5260)); freqs.append(QPair(56, 5280)); freqs.append(QPair(60, 5300)); freqs.append(QPair(64, 5320)); freqs.append(QPair(100, 5500)); freqs.append(QPair(104, 5520)); freqs.append(QPair(108, 5540)); freqs.append(QPair(112, 5560)); freqs.append(QPair(116, 5580)); freqs.append(QPair(120, 5600)); freqs.append(QPair(124, 5620)); freqs.append(QPair(128, 5640)); freqs.append(QPair(132, 5660)); freqs.append(QPair(136, 5680)); freqs.append(QPair(140, 5700)); freqs.append(QPair(149, 5745)); freqs.append(QPair(153, 5765)); freqs.append(QPair(157, 5785)); freqs.append(QPair(161, 5805)); freqs.append(QPair(165, 5825)); freqs.append(QPair(183, 4915)); freqs.append(QPair(184, 4920)); freqs.append(QPair(185, 4925)); freqs.append(QPair(187, 4935)); freqs.append(QPair(188, 4940)); freqs.append(QPair(189, 4945)); freqs.append(QPair(192, 4960)); freqs.append(QPair(196, 4980)); return freqs; } QDateTime NetworkManager::clockBootTimeToDateTime(qlonglong clockBootime) { clockid_t clk_id = CLOCK_BOOTTIME; struct timespec tp; int r; // now is used as a point of reference // with the timespec that contains the number of msec since boot QDateTime now = QDateTime::currentDateTime(); r = clock_gettime (clk_id, &tp); if (r == -1 && errno == EINVAL) { clk_id = CLOCK_MONOTONIC; r = clock_gettime (clk_id, &tp); } // convert to msecs long now_msecs = tp.tv_sec * 1000 + tp.tv_nsec / 1000000; // diff the msecs and construct a QDateTime based on the offset QDateTime res; if (clockBootime > now_msecs) { qlonglong offset = clockBootime - now_msecs; res = QDateTime::fromMSecsSinceEpoch(now.toMSecsSinceEpoch() + offset); } else { qlonglong offset = now_msecs - clockBootime; res = QDateTime::fromMSecsSinceEpoch(now.toMSecsSinceEpoch() - offset); } return res; } diff --git a/src/utils.h b/src/utils.h index 08c5c0d..d091941 100644 --- a/src/utils.h +++ b/src/utils.h @@ -1,89 +1,89 @@ /* Copyright 2012-2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef NETWORKMANAGERQT_UTILS_H #define NETWORKMANAGERQT_UTILS_H #include #include #include #include "wirelessdevice.h" #include "wirelesssecuritysetting.h" #include "wirelesssetting.h" namespace NetworkManager { - enum WirelessSecurityType { UnknownSecurity = -1, NoneSecurity, StaticWep, DynamicWep, Leap, WpaPsk, WpaEap, Wpa2Psk, Wpa2Eap }; + enum WirelessSecurityType { UnknownSecurity = -1, NoneSecurity, StaticWep, DynamicWep, Leap, WpaPsk, WpaEap, Wpa2Psk, Wpa2Eap, SAE }; /** * @return QHostAddress representation of an ipv6 address * @param address byte array containing the binary representation of the address */ NETWORKMANAGERQT_EXPORT QHostAddress ipv6AddressAsHostAddress(const QByteArray &address); /** * @return binary representation of an ipv6 address * @param address qhostaddress containing the address */ NETWORKMANAGERQT_EXPORT QByteArray ipv6AddressFromHostAddress(const QHostAddress &address); /** * @return String representation of a mac address. * @param ba byte array containing the binary repesentation of the address */ NETWORKMANAGERQT_EXPORT QString macAddressAsString(const QByteArray &ba); /** * @return binary repesentation of a mac address. * @param s string representation of the address */ NETWORKMANAGERQT_EXPORT QByteArray macAddressFromString(const QString &s); NETWORKMANAGERQT_EXPORT bool macAddressIsValid(const QString &macAddress); NETWORKMANAGERQT_EXPORT bool macAddressIsValid(const QByteArray &macAddress); /** * @param freq frequency of a wireless network * @return The frequency channel. */ NETWORKMANAGERQT_EXPORT int findChannel(int freq); NETWORKMANAGERQT_EXPORT NetworkManager::WirelessSetting::FrequencyBand findFrequencyBand(int freq); NETWORKMANAGERQT_EXPORT bool deviceSupportsApCiphers(NetworkManager::WirelessDevice::Capabilities, NetworkManager::AccessPoint::WpaFlags ciphers, WirelessSecurityType type); NETWORKMANAGERQT_EXPORT bool securityIsValid(WirelessSecurityType type, NetworkManager::WirelessDevice::Capabilities interfaceCaps, bool haveAp, bool adHoc, NetworkManager::AccessPoint::Capabilities apCaps, NetworkManager::AccessPoint::WpaFlags apWpa, NetworkManager::AccessPoint::WpaFlags apRsn); NETWORKMANAGERQT_EXPORT WirelessSecurityType findBestWirelessSecurity(NetworkManager::WirelessDevice::Capabilities, bool haveAp, bool adHoc, NetworkManager::AccessPoint::Capabilities apCaps, NetworkManager::AccessPoint::WpaFlags apWpa, NetworkManager::AccessPoint::WpaFlags apRsn); NETWORKMANAGERQT_EXPORT bool wepKeyIsValid(const QString &key, NetworkManager::WirelessSecuritySetting::WepKeyType type); NETWORKMANAGERQT_EXPORT bool wpaPskIsValid(const QString &psk); NETWORKMANAGERQT_EXPORT WirelessSecurityType securityTypeFromConnectionSetting(const NetworkManager::ConnectionSettings::Ptr &settings); NETWORKMANAGERQT_EXPORT QList > getBFreqs(); NETWORKMANAGERQT_EXPORT QList > getAFreqs(); NETWORKMANAGERQT_EXPORT QDateTime clockBootTimeToDateTime(qlonglong clockBootime); } #endif // NETWORKMANAGERQT_UTILS_H diff --git a/src/wirelessdevice.h b/src/wirelessdevice.h index 00f8b9a..764f630 100644 --- a/src/wirelessdevice.h +++ b/src/wirelessdevice.h @@ -1,240 +1,241 @@ /* Copyright 2008,2011 Will Stephenson Copyright 2011-2013 Lamarque V. Souza Copyright 2013 Daniel Nicoletti Copyright 2013 Jan Grulich This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef NETWORKMANAGERQT_WIRELESSDEVICE_H #define NETWORKMANAGERQT_WIRELESSDEVICE_H #include #include "device.h" #include "accesspoint.h" #include "wirelessnetwork.h" #include #include namespace NetworkManager { class WirelessDevicePrivate; /** * A wireless network interface */ class NETWORKMANAGERQT_EXPORT WirelessDevice : public Device { Q_OBJECT public: typedef QSharedPointer Ptr; typedef QList List; /** * The device's current operating mode */ enum OperationMode { Unknown = 0, /**< not associated with a network */ Adhoc, /**< part of an adhoc network */ Infra, /**< a station in an infrastructure wireless network */ ApMode /**< access point in an infrastructure network */ }; Q_ENUM(OperationMode) /** * Capabilities (currently all encryption/authentication related) of the device * @note FreqValid, Freq2Ghz, Freq5Ghz are available in runtime NM >= 1.0.2 */ enum Capability { NoCapability = 0x0, /**< Null capability */ Wep40 = 0x1, /**< 40 bit WEP cipher */ Wep104 = 0x2, /**< 104 bit WEP cipher */ Tkip = 0x4, /**< TKIP encryption cipher */ Ccmp = 0x8, /**< CCMP encryption cipher */ Wpa = 0x10, /**< WPA authentication protocol */ Rsn = 0x20, /**< RSN authethication protocol */ ApCap = 0x40, /**< The device supports Access Point mode. */ AdhocCap = 0x80, /**< The device supports Ad-Hoc mode. */ FreqValid = 0x100, /**< The device properly reports information about supported frequencies */ Freq2Ghz = 0x200, /**< The device supports 2.4Ghz frequencies */ - Freq5Ghz = 0x400 /**< The device supports 5Ghz frequencies */ - + Freq5Ghz = 0x400, /**< The device supports 5Ghz frequencies */ + Mesh = 0x1000, /**< The device supports acting as a mesh point */ + IBSSRsn = 0x2000 /**< device supports WPA2/RSN in an IBSS network */ }; Q_DECLARE_FLAGS(Capabilities, Capability) /** * Creates a new WirelessDevice object. * * @param path the DBus path of the devise */ explicit WirelessDevice(const QString &path, QObject *parent = nullptr); /** * Destroys a WirelessDevice object. */ ~WirelessDevice() override; /** * Return the type */ Type type() const override; /** * List of wireless networks currently visible to the hardware */ QStringList accessPoints() const; /** * Asks the device for a new scan of available wireless networks * @param options Options of scan * No documentation for options yet, see http://projects.gnome.org/NetworkManager/developers/api/09/spec.html#org.freedesktop.NetworkManager.Device.Wireless */ QDBusPendingReply<> requestScan(const QVariantMap &options = QVariantMap()); /** * AccessPoint pointer this interface is currently associated with */ AccessPoint::Ptr activeAccessPoint() const; /** * The permanent hardware address of the network interface */ QString permanentHardwareAddress() const; /** * The hardware address currently used by the network interface */ QString hardwareAddress() const; /** * Retrieves the operation mode of this network. * * @return the current mode * @see OperationMode */ WirelessDevice::OperationMode mode() const; /** * Retrieves the effective bit rate currently attainable by this device. * * @return the bitrate in Kbit/s */ int bitRate() const; /** * The LastScan property value, converted to QDateTime * @since 5.62.0 * @note will always return invalid QDateTime when runtime NM < 1.12 * @return */ QDateTime lastScan() const; /** * The time the last RequestScan function was called * @since 5.62.0 * @return */ QDateTime lastRequestScan() const; /** * Retrieves the capabilities of this wifi network. * * @return the flag set describing the capabilities * @see Capabilities */ WirelessDevice::Capabilities wirelessCapabilities() const; /** * Helper method to convert wire representation of operation mode to enum */ static WirelessDevice::OperationMode convertOperationMode(uint); /** * Helper method to convert wire representation of capabilities to enum */ static WirelessDevice::Capabilities convertCapabilities(uint); /** * Finds access point object given its Unique Network Identifier. * * @param uni the identifier of the AP to find from this network interface * @returns a valid AccessPoint object if a network having the given UNI for this device is known to the system, 0 otherwise */ AccessPoint::Ptr findAccessPoint(const QString &uni); /** * Return the current list of networks */ WirelessNetwork::List networks() const; /** * Find a network with the given @p ssid, a Null object is * returned if it can not be found */ WirelessNetwork::Ptr findNetwork(const QString &ssid) const; Q_SIGNALS: /** * This signal is emitted when the bitrate of this network has changed. * * @param bitrate the new bitrate value for this network */ void bitRateChanged(int bitrate); /** * The active network changed. */ void activeAccessPointChanged(const QString &); /** * The device switched operating mode. */ void modeChanged(WirelessDevice::OperationMode); /** * The device changed its capabilities */ void wirelessCapabilitiesChanged(Capabilities); /** * The device changed its hardware address */ void hardwareAddressChanged(const QString &); /** * The device changed its permanent hardware address */ void permanentHardwareAddressChanged(const QString &); /** * The device changed its properties */ void wirelessPropertiesChanged(uint); // TODO this is bogus, remove /** * A new wireless access point appeared */ void accessPointAppeared(const QString &uni); /** * A wireless access point disappeared */ void accessPointDisappeared(const QString &uni); /** * A wireless network appeared */ void networkAppeared(const QString &ssid); /** * A wireless network disappeared */ void networkDisappeared(const QString &ssid); /** * The LastScan property has changed, meaning a scan has just finished * @since 5.62.0 * @note will never be emitted when runtime NM < 1.12 * @see lastScanTime */ void lastScanChanged(const QDateTime &dateTime); private: Q_DECLARE_PRIVATE(WirelessDevice) }; } // namespace NetworkManager #endif //NETWORKMANAGERQT_WIRELESSDEVICE_H