コード例 #1
0
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;
    }
}
コード例 #2
0
ファイル: handler.cpp プロジェクト: JosephMillsAtWork/u2t
void Handler::addAndActivateConnection(const QString& device, const QString& specificObject, const QString& password)
{
    NetworkManager::AccessPoint::Ptr ap;
    NetworkManager::WirelessDevice::Ptr wifiDev;
    Q_FOREACH (const NetworkManager::Device::Ptr & dev, NetworkManager::networkInterfaces()) {
        if (dev->type() == NetworkManager::Device::Wifi) {
            wifiDev = dev.objectCast<NetworkManager::WirelessDevice>();
            ap = wifiDev->findAccessPoint(specificObject);
            if (ap) {
                break;
            }
        }
    }

    if (!ap) {
        return;
    }

    NetworkManager::ConnectionSettings::Ptr settings = NetworkManager::ConnectionSettings::Ptr(new NetworkManager::ConnectionSettings(NetworkManager::ConnectionSettings::Wireless));
    settings->setId(ap->ssid());
    settings->setUuid(NetworkManager::ConnectionSettings::createNewUuid());
    settings->setAutoconnect(true);
#if 0
    settings->addToPermissions(KUser().loginName(), QString());
#endif

    NetworkManager::WirelessSetting::Ptr wifiSetting = settings->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
    wifiSetting->setInitialized(true);
    wifiSetting = settings->setting(NetworkManager::Setting::Wireless).dynamicCast<NetworkManager::WirelessSetting>();
    wifiSetting->setSsid(ap->ssid().toUtf8());
    if (ap->mode() == NetworkManager::AccessPoint::Adhoc) {
        wifiSetting->setMode(NetworkManager::WirelessSetting::Adhoc);
    }
    NetworkManager::WirelessSecuritySetting::Ptr wifiSecurity = settings->setting(NetworkManager::Setting::WirelessSecurity).dynamicCast<NetworkManager::WirelessSecuritySetting>();

    NetworkManager::WirelessSecurityType securityType = NetworkManager::findBestWirelessSecurity(wifiDev->wirelessCapabilities(), true, (ap->mode() == NetworkManager::AccessPoint::Adhoc), ap->capabilities(), ap->wpaFlags(), ap->rsnFlags());

    if (securityType != NetworkManager::NoneSecurity) {
        wifiSecurity->setInitialized(true);
        wifiSetting->setSecurity("802-11-wireless-security");
    }

    if (securityType == NetworkManager::Leap ||
        securityType == NetworkManager::DynamicWep ||
        securityType == NetworkManager::Wpa2Eap ||
        securityType == NetworkManager::WpaEap) {
        if (securityType == NetworkManager::DynamicWep || securityType == NetworkManager::Leap) {
            wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::Ieee8021x);
            if (securityType == NetworkManager::Leap) {
                wifiSecurity->setAuthAlg(NetworkManager::WirelessSecuritySetting::Leap);
            }
        } else {
            wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaEap);
        }
        m_tmpConnectionUuid = settings->uuid();
        m_tmpDevicePath = device;
        m_tmpSpecificPath = specificObject;

#if 0
        QPointer<ConnectionDetailEditor> editor = new ConnectionDetailEditor(settings, true);
        editor->show();
        KWindowSystem::setState(editor->winId(), NET::KeepAbove);
        KWindowSystem::forceActiveWindow(editor->winId());
        connect(editor.data(), &ConnectionDetailEditor::accepted,
                [editor, this] () {
                    addConnection(editor->setting());
                });
        connect(editor.data(), &ConnectionDetailEditor::finished,
                [editor] () {
                    if (editor) {
                        editor->deleteLater();
                    }
                });
        editor->setModal(true);
        editor->show();
#endif
    } else {
        if (securityType == NetworkManager::StaticWep) {
            wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::Wep);
            wifiSecurity->setWepKey0(password);
#if 0
            if (KWallet::Wallet::isEnabled()) {
                wifiSecurity->setWepKeyFlags(NetworkManager::Setting::AgentOwned);
            }
#endif
        } else {
            if (ap->mode() == NetworkManager::AccessPoint::Adhoc) {
                wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaNone);
            } else {
                wifiSecurity->setKeyMgmt(NetworkManager::WirelessSecuritySetting::WpaPsk);
            }
            wifiSecurity->setPsk(password);
#if 0
            if (KWallet::Wallet::isEnabled()) {
                wifiSecurity->setPskFlags(NetworkManager::Setting::AgentOwned);
            }
#endif
        }
        QDBusPendingReply<QDBusObjectPath> reply = NetworkManager::addAndActivateConnection(settings->toMap(), device, specificObject);
        QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(reply, this);
        watcher->setProperty("action", Handler::AddAndActivateConnection);
        watcher->setProperty("connection", settings->name());
        connect(watcher, &QDBusPendingCallWatcher::finished, this, &Handler::replyFinished);
    }

    settings.clear();
}