void WirelessInterfaceConnectionBuilder::init(WirelessInterfaceConnection *ic) { InterfaceConnectionBuilder::init(ic); Knm::WirelessSetting * wirelessSetting = dynamic_cast<Knm::WirelessSetting *>(m_connection->setting(Knm::Setting::Wireless)); if (wirelessSetting) { int strength = -1; NetworkManager::AccessPoint::Capabilities caps = 0; NetworkManager::AccessPoint::WpaFlags wpaFlags = 0; NetworkManager::AccessPoint::WpaFlags rsnFlags = 0; NetworkManager::AccessPoint::OperationMode mode = NetworkManager::AccessPoint::Infra; // show connections where the network is present OR adhoc connections NetworkManager::WirelessNetwork::Ptr network = m_interface->findNetwork(wirelessSetting->ssid()); if (network) { strength = network->signalStrength(); NetworkManager::AccessPoint::Ptr ap = network->referenceAccessPoint(); if (ap) { caps = ap->capabilities(); wpaFlags = ap->wpaFlags(); rsnFlags = ap->rsnFlags(); mode = ap->mode(); } } else if (wirelessSetting->mode() == Knm::WirelessSetting::EnumMode::adhoc || wirelessSetting->mode() == Knm::WirelessSetting::EnumMode::apMode) { mode = (wirelessSetting->mode() == Knm::WirelessSetting::EnumMode::adhoc) ? NetworkManager::AccessPoint::Adhoc : NetworkManager::AccessPoint::ApMode; Knm::WirelessSecuritySetting * wirelessSecuritySetting = dynamic_cast<Knm::WirelessSecuritySetting *>(m_connection->setting(Knm::Setting::WirelessSecurity)); switch( wirelessSecuritySetting->securityType()) { case Knm::WirelessSecuritySetting::EnumSecurityType::StaticWep: case Knm::WirelessSecuritySetting::EnumSecurityType::Leap: case Knm::WirelessSecuritySetting::EnumSecurityType::DynamicWep: caps |= NetworkManager::AccessPoint::Privacy; break; case Knm::WirelessSecuritySetting::EnumSecurityType::WpaPsk: wpaFlags |= NetworkManager::AccessPoint::KeyMgmtPsk | NetworkManager::AccessPoint::PairTkip | NetworkManager::AccessPoint::PairCcmp; break; case Knm::WirelessSecuritySetting::EnumSecurityType::WpaEap: wpaFlags |= NetworkManager::AccessPoint::KeyMgmt8021x; break; case Knm::WirelessSecuritySetting::EnumSecurityType::Wpa2Psk: rsnFlags |= NetworkManager::AccessPoint::KeyMgmtPsk | NetworkManager::AccessPoint::PairTkip | NetworkManager::AccessPoint::PairCcmp; break; case Knm::WirelessSecuritySetting::EnumSecurityType::Wpa2Eap: rsnFlags |= NetworkManager::AccessPoint::KeyMgmt8021x; break; case Knm::WirelessSecuritySetting::EnumSecurityType::None: default: break; } } ic->m_interfaceCapabilities = m_interface->wirelessCapabilities(); ic->m_ssid = wirelessSetting->ssid(); ic->m_strength = strength; ic->m_apCapabilities = caps; ic->m_wpaFlags = wpaFlags; ic->m_rsnFlags = rsnFlags; ic->m_operationMode = mode; } }
void WirelessSecurityDbus::fromMap(const QVariantMap &map) { Knm::WirelessSecuritySetting *setting = static_cast<Knm::WirelessSecuritySetting *>(m_setting); if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT))) { if (map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT)) == "none") { setting->setKeymgmt(Knm::WirelessSecuritySetting::EnumKeymgmt::None); setting->setSecurityType(Knm::WirelessSecuritySetting::EnumSecurityType::StaticWep); } else if (map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT)) == "ieee8021x") { setting->setKeymgmt(Knm::WirelessSecuritySetting::EnumKeymgmt::Ieee8021x); setting->setSecurityType(Knm::WirelessSecuritySetting::EnumSecurityType::DynamicWep); } else if (map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT)) == "wpa-none") { setting->setKeymgmt(Knm::WirelessSecuritySetting::EnumKeymgmt::WPANone); setting->setSecurityType(Knm::WirelessSecuritySetting::EnumSecurityType::WpaPsk); } else if (map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT)) == "wpa-psk") { setting->setKeymgmt(Knm::WirelessSecuritySetting::EnumKeymgmt::WPAPSK); setting->setSecurityType(Knm::WirelessSecuritySetting::EnumSecurityType::WpaPsk); } else if (map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT)) == "wpa-eap") { setting->setKeymgmt(Knm::WirelessSecuritySetting::EnumKeymgmt::WPAEAP); setting->setSecurityType(Knm::WirelessSecuritySetting::EnumSecurityType::WpaEap); } setting->setSecretsAvailable(true); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX))) { setting->setWeptxkeyindex(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX)).value<uint>()); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG))) { if (map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG)) == "open") setting->setAuthalg(Knm::WirelessSecuritySetting::EnumAuthalg::open); else if (map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG)) == "shared") setting->setAuthalg(Knm::WirelessSecuritySetting::EnumAuthalg::shared); else if (map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG)) == "leap") { setting->setAuthalg(Knm::WirelessSecuritySetting::EnumAuthalg::leap); setting->setSecurityType(Knm::WirelessSecuritySetting::EnumSecurityType::Leap); if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME))) { setting->setLeapusername(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME)).value<QString>()); } //SECRET if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD))) { setting->setLeappassword(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD)).value<QString>()); setting->setLeappasswordflags((Knm::Setting::secretsTypes)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS)).value<int>()); } } } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO))) { setting->setProto(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO)).value<QStringList>()); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE))) { setting->setPairwise(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE)).value<QStringList>()); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP))) { setting->setGroup(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP)).value<QStringList>()); } // SECRET if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0))) { setting->setWepkey0(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0)).value<QString>()); } // SECRET if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1))) { setting->setWepkey1(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1)).value<QString>()); } // SECRET if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2))) { setting->setWepkey2(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2)).value<QString>()); } // SECRET if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3))) { setting->setWepkey3(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3)).value<QString>()); } // SECRET if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK))) { setting->setPsk(map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK)).value<QString>()); setting->setPskflags((Knm::Setting::secretsTypes)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS)).value<int>()); } if (map.contains(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE))) { if (map.value(QLatin1String(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE))).value<int>() == 1) { setting->setWepKeyType(Knm::WirelessSecuritySetting::Hex); } else { setting->setWepKeyType(Knm::WirelessSecuritySetting::Passphrase); } setting->setWepkeyflags((Knm::Setting::secretsTypes)map.value(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS)).value<int>()); } }
QVariantMap WirelessSecurityDbus::toSecretsMap() { QVariantMap map; Knm::WirelessSecuritySetting *setting = static_cast<Knm::WirelessSecuritySetting *>(m_setting); if (setting->securityType() != Knm::WirelessSecuritySetting::EnumSecurityType::None) // don't return anything if there is no security { if (setting->securityType() == Knm::WirelessSecuritySetting::EnumSecurityType::StaticWep || setting->securityType() == Knm::WirelessSecuritySetting::EnumSecurityType::DynamicWep) { if (setting->wepKeyType() == Knm::WirelessSecuritySetting::Hex) map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), 1); else if (setting->wepKeyType() == Knm::WirelessSecuritySetting::Passphrase) map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_TYPE), 2); else qWarning() << "Wep key type is not set!"; map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_TX_KEYIDX), setting->weptxkeyindex()); if (!setting->wepkey0().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY0), setting->wepkey0()); } if (!setting->wepkey1().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY1), setting->wepkey1()); } if (!setting->wepkey2().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY2), setting->wepkey2()); } if (!setting->wepkey3().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY3), setting->wepkey3()); } } else if (setting->securityType() == Knm::WirelessSecuritySetting::EnumSecurityType::WpaPsk || setting->securityType() == Knm::WirelessSecuritySetting::EnumSecurityType::Wpa2Psk) { if (!setting->psk().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK), setting->psk()); } } else if (setting->securityType() == Knm::WirelessSecuritySetting::EnumSecurityType::Leap) { if (!setting->leappassword().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD), setting->leappassword()); } } } // end of if not clear return map; }
QVariantMap WirelessSecurityDbus::toMap() { QVariantMap map; Knm::WirelessSecuritySetting *setting = static_cast<Knm::WirelessSecuritySetting *>(m_setting); if (setting->securityType() != Knm::WirelessSecuritySetting::EnumSecurityType::None) // don't return anything if there is no security { switch (setting->keymgmt()) { case Knm::WirelessSecuritySetting::EnumKeymgmt::None: map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "none"); qDebug() << "Adding key-mgmt: none"; break; case Knm::WirelessSecuritySetting::EnumKeymgmt::Ieee8021x: map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "ieee8021x"); qDebug() << "Adding key-mgmt: ieee8021x"; break; case Knm::WirelessSecuritySetting::EnumKeymgmt::WPANone: map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "wpa-none"); qDebug() << "Adding key-mgmt: wpa-none"; break; case Knm::WirelessSecuritySetting::EnumKeymgmt::WPAPSK: map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "wpa-psk"); qDebug() << "Adding key-mgmt: wpa-psk"; break; case Knm::WirelessSecuritySetting::EnumKeymgmt::WPAEAP: map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_KEY_MGMT), "wpa-eap"); qDebug() << "Adding key-mgmt: wpa-eap"; break; } switch (setting->authalg()) { case Knm::WirelessSecuritySetting::EnumAuthalg::none: // the none auth alg is internal break; case Knm::WirelessSecuritySetting::EnumAuthalg::open: // the default map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), "open"); break; case Knm::WirelessSecuritySetting::EnumAuthalg::shared: map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), "shared"); break; case Knm::WirelessSecuritySetting::EnumAuthalg::leap: map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_AUTH_ALG), "leap"); break; } if (!setting->proto().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PROTO), setting->proto()); } if (!setting->pairwise().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PAIRWISE), setting->pairwise()); } if (!setting->group().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_GROUP), setting->group()); } if (!setting->leapusername().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_USERNAME), setting->leapusername()); map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_LEAP_PASSWORD_FLAGS), (int)setting->leappasswordflags()); } map.unite(toSecretsMap()); if (!setting->wepkey0().isEmpty() || !setting->wepkey1().isEmpty() || !setting->wepkey2().isEmpty() || !setting->wepkey3().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_WEP_KEY_FLAGS), (int)setting->wepkeyflags()); } if (!setting->psk().isEmpty()) { map.insert(QLatin1String(NM_SETTING_WIRELESS_SECURITY_PSK_FLAGS), (int)setting->pskflags()); } } // end of if not setting->clear() return map; }