• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • API Reference
  • Sitemap
  • Contact Us
 

SolidModules

NetworkManager-wirelessnetwork.cpp

Go to the documentation of this file.
00001 /*  This file is part of the KDE project
00002     Copyright (C) 2007 Will Stephenson <wstephenson@kde.org>
00003     Copyright (C) 2008 Pino Toscano <pino@kde.org>
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License version 2 as published by the Free Software Foundation.
00008 
00009     This library is distributed in the hope that it will be useful,
00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012     Library General Public License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to
00016     the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00017     Boston, MA 02110-1301, USA.
00018 
00019 */
00020 
00021 #include "NetworkManager-wirelessnetwork.h"
00022 
00023 #include "NetworkManager-networkinterface_p.h"
00024 
00025 // Copied from wireless.h
00026 /* Modes of operation */
00027 #define IW_MODE_AUTO    0   /* Let the driver decides */
00028 #define IW_MODE_ADHOC   1   /* Single cell network */
00029 #define IW_MODE_INFRA   2   /* Multi cell network, roaming, ... */
00030 #define IW_MODE_MASTER  3   /* Synchronization master or Access Point */
00031 #define IW_MODE_REPEAT  4   /* Wireless Repeater (forwarder) */
00032 #define IW_MODE_SECOND  5   /* Secondary master/repeater (backup) */
00033 #define IW_MODE_MONITOR 6   /* Passive monitor (listen only) */
00034 
00035 #include <kdebug.h>
00036 
00037 #include "NetworkManager-wirelessaccesspoint.h"
00038 
00039 #include <QtDBus/QDBusReply>
00040 
00041 void dump(const Solid::Control::WirelessNetworkInterface::Capabilities  & cap)
00042 {
00043     kDebug(1441) << "WPA      " << (cap  & Solid::Control::WirelessNetworkInterface::Wpa ? "X " : " O");
00044     kDebug(1441) << "Wep40    " << (cap  & Solid::Control::WirelessNetworkInterface::Wep40 ? "X " : " O");
00045     kDebug(1441) << "Wep104   " << (cap  & Solid::Control::WirelessNetworkInterface::Wep104 ? "X " : " O");
00046     kDebug(1441) << "TKIP     " << (cap  & Solid::Control::WirelessNetworkInterface::Tkip ? "X " : " O");
00047     kDebug(1441) << "CCMP     " << (cap  & Solid::Control::WirelessNetworkInterface::Ccmp ? "X " : " O");
00048     kDebug(1441) << "RSM      " << (cap  & Solid::Control::WirelessNetworkInterface::Rsn ? "X " : " O");
00049 }
00050 
00051 Solid::Control::WirelessNetworkInterface::Capabilities getCapabilities(const int nm)
00052 {
00053     Solid::Control::WirelessNetworkInterface::Capabilities caps;
00054     if (nm  & NM_802_11_CAP_NONE)
00055         caps |= Solid::Control::WirelessNetworkInterface::NoCapability;
00056 #if 0
00057     if (nm  & NM_802_11_CAP_PROTO_WEP)
00058         caps |= Solid::Control::WirelessNetworkInterface::Wep;
00059 #endif
00060     if (nm  & NM_802_11_CAP_PROTO_WPA)
00061         caps |= Solid::Control::WirelessNetworkInterface::Wpa;
00062 #if 0
00063     if (nm  & NM_802_11_CAP_PROTO_WPA2)
00064         caps |= Solid::Control::WirelessNetworkInterface::Wpa2;
00065     if (nm  & NM_802_11_CAP_KEY_MGMT_PSK)
00066         caps |= Solid::Control::WirelessNetworkInterface::Psk;
00067     if (nm  & NM_802_11_CAP_KEY_MGMT_802_1X)
00068         caps |= Solid::Control::WirelessNetworkInterface::Ieee8021x;
00069 #endif
00070     if (nm  & NM_802_11_CAP_CIPHER_WEP40)
00071         caps |= Solid::Control::WirelessNetworkInterface::Wep40;
00072     if (nm  & NM_802_11_CAP_CIPHER_WEP104)
00073         caps |= Solid::Control::WirelessNetworkInterface::Wep104;
00074     if (nm  & NM_802_11_CAP_CIPHER_TKIP)
00075         caps |= Solid::Control::WirelessNetworkInterface::Tkip;
00076     if (nm  & NM_802_11_CAP_CIPHER_CCMP)
00077         caps |= Solid::Control::WirelessNetworkInterface::Ccmp;
00078     return caps;
00079 }
00080 
00081 Solid::Control::WirelessNetworkInterface::OperationMode getOperationMode(const int nm)
00082 {
00083     Solid::Control::WirelessNetworkInterface::OperationMode mode = Solid::Control::WirelessNetworkInterface::Unassociated;
00084     switch (nm)
00085     {
00086     case IW_MODE_ADHOC:
00087         mode = Solid::Control::WirelessNetworkInterface::Adhoc;
00088         break;
00089     case IW_MODE_INFRA:
00090     case IW_MODE_MASTER:
00091         mode = Solid::Control::WirelessNetworkInterface::Managed;
00092         break;
00093     case IW_MODE_REPEAT:
00094         mode = Solid::Control::WirelessNetworkInterface::Repeater;
00095         break;
00096     }
00097     return mode;
00098 }
00099 
00100 
00101 class NMWirelessNetworkPrivate : public NMNetworkInterfacePrivate
00102 {
00103 public:
00104     NMWirelessNetworkPrivate(const QString  & netPath)
00105         : NMNetworkInterfacePrivate(netPath),
00106         rate(0) { }
00107     Q_DECLARE_PUBLIC(NMWirelessNetwork)
00108     /* reimp */ void notifyNewNetwork(const QDBusObjectPath & netPath);
00109     /* reimp */ void notifyRemoveNetwork(const QDBusObjectPath & netPath);
00110     /* reimp */ void applyProperties(const NMDBusDeviceProperties & props);
00111     void readActiveAccessPoint();
00112     MacAddress hwAddr;
00113     int rate;
00114     Solid::Control::WirelessNetworkInterface::OperationMode mode;
00115     Solid::Control::WirelessNetworkInterface::Capabilities wirelessCapabilities;
00116     QHash<QString, NMAccessPoint*> accessPoints;
00117     QString activeAccessPoint;
00118 };
00119 
00120 void NMWirelessNetworkPrivate::notifyNewNetwork(const QDBusObjectPath & netPath)
00121 {
00122     Q_Q(NMWirelessNetwork);
00123     const QString path = netPath.path();
00124     QHash<QString, NMAccessPoint*>::ConstIterator it = accessPoints.find(path);
00125     if (it == accessPoints.end()) {
00126         accessPoints.insert(path, 0);
00127         emit q->accessPointAppeared(path);
00128     }
00129 }
00130 
00131 void NMWirelessNetworkPrivate::notifyRemoveNetwork(const QDBusObjectPath & netPath)
00132 {
00133     Q_Q(NMWirelessNetwork);
00134     const QString path = netPath.path();
00135     QHash<QString, NMAccessPoint*>::Iterator it = accessPoints.find(path);
00136     if (it != accessPoints.end()) {
00137         NMAccessPoint * ap = it.value();
00138         accessPoints.erase(it);
00139         if (path == activeAccessPoint) {
00140             readActiveAccessPoint();
00141         }
00142         emit q->accessPointDisappeared(path);
00143         delete ap;
00144     }
00145 }
00146 
00147 void NMWirelessNetworkPrivate::readActiveAccessPoint()
00148 {
00149     activeAccessPoint = QString();
00150     const QDBusReply<QString> reply = iface.call("getActiveNetwork");
00151     if (reply.isValid()) {
00152         activeAccessPoint = reply.value();
00153     }
00154 }
00155 
00156 
00157 NMWirelessNetwork::NMWirelessNetwork(const QString  & networkPath)
00158  : NMNetworkInterface(*new NMWirelessNetworkPrivate(networkPath))
00159 {
00160     Q_D(NMWirelessNetwork);
00161     d->readActiveAccessPoint();
00162 }
00163 
00164 NMWirelessNetwork::~NMWirelessNetwork()
00165 {
00166     Q_D(NMWirelessNetwork);
00167     qDeleteAll(d->accessPoints);
00168 }
00169 
00170 void NMWirelessNetworkPrivate::applyProperties(const NMDBusDeviceProperties & props)
00171 {
00172     NMNetworkInterfacePrivate::applyProperties(props);
00173 
00174     hwAddr = props.hardwareAddress;
00175     Q_FOREACH (const QString & netudi, props.networks) {
00176         accessPoints.insert(netudi, 0);
00177     }
00178     mode = getOperationMode(props.mode);
00179     wirelessCapabilities = getCapabilities(props.capabilitiesType);
00180 }
00181 
00182 int NMWirelessNetwork::bitRate() const
00183 {
00184     Q_D(const NMWirelessNetwork);
00185     return d->rate;
00186 }
00187 
00188 Solid::Control::WirelessNetworkInterface::Capabilities NMWirelessNetwork::wirelessCapabilities() const
00189 {
00190     Q_D(const NMWirelessNetwork);
00191     return d->wirelessCapabilities;
00192 }
00193 
00194 Solid::Control::WirelessNetworkInterface::OperationMode NMWirelessNetwork::mode() const
00195 {
00196     Q_D(const NMWirelessNetwork);
00197     return d->mode;
00198 }
00199 
00200 void NMWirelessNetwork::setSignalStrength(const QDBusObjectPath & netPath, int strength)
00201 {
00202     Q_D(NMWirelessNetwork);
00203     QHash<QString, NMAccessPoint*>::ConstIterator it = d->accessPoints.find(netPath.path());
00204     if (it != d->accessPoints.end() && it.value()) {
00205         NMAccessPoint * ap = it.value();
00206         ap->setSignalStrength(strength);
00207     }
00208 }
00209 
00210 void NMWirelessNetwork::setBitrate(int rate)
00211 {
00212     Q_D(NMWirelessNetwork);
00213     if (d->rate == rate)
00214         return;
00215 
00216     d->rate = rate;
00217     emit bitRateChanged(rate);
00218 }
00219 
00220 #if 0
00221 void NMWirelessNetwork::setActivated(bool activated)
00222 {
00223     QDBusInterface manager(NM_DBUS_SERVICE, NM_DBUS_PATH, NM_DBUS_INTERFACE,
00224             QDBusConnection::systemBus());
00225     QString devicePath = uni().left(uni().indexOf("/Networks"));
00226     kDebug(1441) << devicePath << " - " << d->essid;
00227     QDBusObjectPath op(devicePath);
00228 #ifdef __GNUC__
00229 #warning fixme hardcoded false fallback bool in setActiveDevice - fixed, i think
00230 #endif
00231     QList<QVariant> args;
00232     args << qVariantFromValue(op) << d->essid;// << false;
00233     bool error;
00234     args = NMDBusHelper::serialize(d->authentication, d->essid, args, &error);
00235     kDebug(1441) << " " << args;
00236     if (error)
00237         kDebug(1411) << "Error whilst serializing authentication.";
00238     else
00239         manager.callWithArgumentList(QDBus::Block, "setActiveDevice", args);
00240     if (manager.lastError().isValid())
00241         kDebug(1441) << "setActiveDevice returned error: " << manager.lastError().name() << ": " << manager.lastError().message();
00242 
00243     emit activationStateChanged(activated);
00244 }
00245 #endif
00246 
00247 MacAddressList NMWirelessNetwork::accessPoints() const
00248 {
00249     Q_D(const NMWirelessNetwork);
00250     return d->accessPoints.keys();
00251 }
00252 
00253 QString NMWirelessNetwork::activeAccessPoint() const
00254 {
00255     Q_D(const NMWirelessNetwork);
00256     return d->activeAccessPoint;
00257 }
00258 
00259 QString NMWirelessNetwork::hardwareAddress() const
00260 {
00261     Q_D(const NMWirelessNetwork);
00262     return d->hwAddr;
00263 }
00264 
00265 QObject * NMWirelessNetwork::createAccessPoint(const QString & uni)
00266 {
00267     Q_D(NMWirelessNetwork);
00268     kDebug() << uni;
00269     QHash<QString, NMAccessPoint*>::Iterator it = d->accessPoints.find(uni);
00270     if (it != d->accessPoints.end()) {
00271         if (it.value()) {
00272             return it.value();
00273         } else {
00274             NMAccessPoint * ap = new NMAccessPoint(uni);
00275             it.value() = ap;
00276             return ap;
00277         }
00278     } else {
00279         kDebug(1441) << "no such AP:" << uni;
00280     }
00281     return 0;
00282 }
00283 
00284 bool NMWirelessNetwork::activateConnection(const QString & connectionUni, const QVariantMap & connectionParameters)
00285 {
00286     Q_UNUSED(connectionUni)
00287     Q_UNUSED(connectionParameters)
00288     return false;
00289 }
00290 
00291 bool NMWirelessNetwork::deactivateConnection()
00292 {
00293     return false;
00294 }
00295 
00296 #include "NetworkManager-wirelessnetwork.moc"

SolidModules

Skip menu "SolidModules"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

API Reference

Skip menu "API Reference"
  • KWin
  •   KWin Libraries
  • Libraries
  •   libkworkspace
  •   libsolidcontrol
  •   libtaskmanager
  • Plasma
  •   Animators
  •   Applets
  •   Engines
  • Solid Modules
Generated for API Reference by doxygen 1.5.7
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal