1 /* This file is part of the KDE project
2 Copyright (C) 2007 Will Stephenson <wstephenson@kde.org>
3 Copyright (C) 2008 Pino Toscano <pino@kde.org>
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License version 2 as published by the Free Software Foundation.
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
21 #include "NetworkManager-wirelessnetwork.h"
23 #include "NetworkManager-networkinterface_p.h"
25 // Copied from wireless.h
26 /* Modes of operation */
27 #define IW_MODE_AUTO 0 /* Let the driver decides */
28 #define IW_MODE_ADHOC 1 /* Single cell network */
29 #define IW_MODE_INFRA 2 /* Multi cell network, roaming, ... */
30 #define IW_MODE_MASTER 3 /* Synchronization master or Access Point */
31 #define IW_MODE_REPEAT 4 /* Wireless Repeater (forwarder) */
32 #define IW_MODE_SECOND 5 /* Secondary master/repeater (backup) */
33 #define IW_MODE_MONITOR 6 /* Passive monitor (listen only) */
37 #include "NetworkManager-wirelessaccesspoint.h"
39 #include <QtDBus/QDBusReply>
41 void dump(const Solid::Control::WirelessNetworkInterface::Capabilities
& cap
)
43 kDebug(1441) << "WPA " << (cap
& Solid::Control::WirelessNetworkInterface::Wpa
? "X " : " O");
44 kDebug(1441) << "Wep40 " << (cap
& Solid::Control::WirelessNetworkInterface::Wep40
? "X " : " O");
45 kDebug(1441) << "Wep104 " << (cap
& Solid::Control::WirelessNetworkInterface::Wep104
? "X " : " O");
46 kDebug(1441) << "TKIP " << (cap
& Solid::Control::WirelessNetworkInterface::Tkip
? "X " : " O");
47 kDebug(1441) << "CCMP " << (cap
& Solid::Control::WirelessNetworkInterface::Ccmp
? "X " : " O");
48 kDebug(1441) << "RSM " << (cap
& Solid::Control::WirelessNetworkInterface::Rsn
? "X " : " O");
51 Solid::Control::WirelessNetworkInterface::Capabilities
getCapabilities(const int nm
)
53 Solid::Control::WirelessNetworkInterface::Capabilities caps
;
54 if (nm
& NM_802_11_CAP_NONE
)
55 caps
|= Solid::Control::WirelessNetworkInterface::NoCapability
;
57 if (nm
& NM_802_11_CAP_PROTO_WEP
)
58 caps
|= Solid::Control::WirelessNetworkInterface::Wep
;
60 if (nm
& NM_802_11_CAP_PROTO_WPA
)
61 caps
|= Solid::Control::WirelessNetworkInterface::Wpa
;
63 if (nm
& NM_802_11_CAP_PROTO_WPA2
)
64 caps
|= Solid::Control::WirelessNetworkInterface::Wpa2
;
65 if (nm
& NM_802_11_CAP_KEY_MGMT_PSK
)
66 caps
|= Solid::Control::WirelessNetworkInterface::Psk
;
67 if (nm
& NM_802_11_CAP_KEY_MGMT_802_1X
)
68 caps
|= Solid::Control::WirelessNetworkInterface::Ieee8021x
;
70 if (nm
& NM_802_11_CAP_CIPHER_WEP40
)
71 caps
|= Solid::Control::WirelessNetworkInterface::Wep40
;
72 if (nm
& NM_802_11_CAP_CIPHER_WEP104
)
73 caps
|= Solid::Control::WirelessNetworkInterface::Wep104
;
74 if (nm
& NM_802_11_CAP_CIPHER_TKIP
)
75 caps
|= Solid::Control::WirelessNetworkInterface::Tkip
;
76 if (nm
& NM_802_11_CAP_CIPHER_CCMP
)
77 caps
|= Solid::Control::WirelessNetworkInterface::Ccmp
;
81 Solid::Control::WirelessNetworkInterface::OperationMode
getOperationMode(const int nm
)
83 Solid::Control::WirelessNetworkInterface::OperationMode mode
= Solid::Control::WirelessNetworkInterface::Unassociated
;
87 mode
= Solid::Control::WirelessNetworkInterface::Adhoc
;
91 mode
= Solid::Control::WirelessNetworkInterface::Managed
;
94 mode
= Solid::Control::WirelessNetworkInterface::Repeater
;
101 class NMWirelessNetworkPrivate
: public NMNetworkInterfacePrivate
104 NMWirelessNetworkPrivate(const QString
& netPath
)
105 : NMNetworkInterfacePrivate(netPath
),
107 Q_DECLARE_PUBLIC(NMWirelessNetwork
)
108 /* reimp */ void notifyNewNetwork(const QDBusObjectPath
& netPath
);
109 /* reimp */ void notifyRemoveNetwork(const QDBusObjectPath
& netPath
);
110 /* reimp */ void applyProperties(const NMDBusDeviceProperties
& props
);
111 void readActiveAccessPoint();
114 Solid::Control::WirelessNetworkInterface::OperationMode mode
;
115 Solid::Control::WirelessNetworkInterface::Capabilities wirelessCapabilities
;
116 QHash
<QString
, NMAccessPoint
*> accessPoints
;
117 QString activeAccessPoint
;
120 void NMWirelessNetworkPrivate::notifyNewNetwork(const QDBusObjectPath
& netPath
)
122 Q_Q(NMWirelessNetwork
);
123 const QString path
= netPath
.path();
124 QHash
<QString
, NMAccessPoint
*>::ConstIterator it
= accessPoints
.find(path
);
125 if (it
== accessPoints
.end()) {
126 accessPoints
.insert(path
, 0);
127 emit q
->accessPointAppeared(path
);
131 void NMWirelessNetworkPrivate::notifyRemoveNetwork(const QDBusObjectPath
& netPath
)
133 Q_Q(NMWirelessNetwork
);
134 const QString path
= netPath
.path();
135 QHash
<QString
, NMAccessPoint
*>::Iterator it
= accessPoints
.find(path
);
136 if (it
!= accessPoints
.end()) {
137 NMAccessPoint
* ap
= it
.value();
138 accessPoints
.erase(it
);
139 if (path
== activeAccessPoint
) {
140 readActiveAccessPoint();
142 emit q
->accessPointDisappeared(path
);
147 void NMWirelessNetworkPrivate::readActiveAccessPoint()
149 activeAccessPoint
= QString();
150 const QDBusReply
<QString
> reply
= iface
.call("getActiveNetwork");
151 if (reply
.isValid()) {
152 activeAccessPoint
= reply
.value();
157 NMWirelessNetwork::NMWirelessNetwork(const QString
& networkPath
)
158 : NMNetworkInterface(*new NMWirelessNetworkPrivate(networkPath
))
160 Q_D(NMWirelessNetwork
);
161 d
->readActiveAccessPoint();
164 NMWirelessNetwork::~NMWirelessNetwork()
166 Q_D(NMWirelessNetwork
);
167 qDeleteAll(d
->accessPoints
);
170 void NMWirelessNetworkPrivate::applyProperties(const NMDBusDeviceProperties
& props
)
172 NMNetworkInterfacePrivate::applyProperties(props
);
174 hwAddr
= props
.hardwareAddress
;
175 Q_FOREACH (const QString
& netudi
, props
.networks
) {
176 accessPoints
.insert(netudi
, 0);
178 mode
= getOperationMode(props
.mode
);
179 wirelessCapabilities
= getCapabilities(props
.capabilitiesType
);
182 int NMWirelessNetwork::bitRate() const
184 Q_D(const NMWirelessNetwork
);
188 Solid::Control::WirelessNetworkInterface::Capabilities
NMWirelessNetwork::wirelessCapabilities() const
190 Q_D(const NMWirelessNetwork
);
191 return d
->wirelessCapabilities
;
194 Solid::Control::WirelessNetworkInterface::OperationMode
NMWirelessNetwork::mode() const
196 Q_D(const NMWirelessNetwork
);
200 void NMWirelessNetwork::setSignalStrength(const QDBusObjectPath
& netPath
, int strength
)
202 Q_D(NMWirelessNetwork
);
203 QHash
<QString
, NMAccessPoint
*>::ConstIterator it
= d
->accessPoints
.find(netPath
.path());
204 if (it
!= d
->accessPoints
.end() && it
.value()) {
205 NMAccessPoint
* ap
= it
.value();
206 ap
->setSignalStrength(strength
);
210 void NMWirelessNetwork::setBitrate(int rate
)
212 Q_D(NMWirelessNetwork
);
217 emit
bitRateChanged(rate
);
221 void NMWirelessNetwork::setActivated(bool activated
)
223 QDBusInterface
manager(NM_DBUS_SERVICE
, NM_DBUS_PATH
, NM_DBUS_INTERFACE
,
224 QDBusConnection::systemBus());
225 QString devicePath
= uni().left(uni().indexOf("/Networks"));
226 kDebug(1441) << devicePath
<< " - " << d
->essid
;
227 QDBusObjectPath
op(devicePath
);
229 #warning fixme hardcoded false fallback bool in setActiveDevice - fixed, i think
231 QList
<QVariant
> args
;
232 args
<< qVariantFromValue(op
) << d
->essid
;// << false;
234 args
= NMDBusHelper::serialize(d
->authentication
, d
->essid
, args
, &error
);
235 kDebug(1441) << " " << args
;
237 kDebug(1411) << "Error whilst serializing authentication.";
239 manager
.callWithArgumentList(QDBus::Block
, "setActiveDevice", args
);
240 if (manager
.lastError().isValid())
241 kDebug(1441) << "setActiveDevice returned error: " << manager
.lastError().name() << ": " << manager
.lastError().message();
243 emit
activationStateChanged(activated
);
247 MacAddressList
NMWirelessNetwork::accessPoints() const
249 Q_D(const NMWirelessNetwork
);
250 return d
->accessPoints
.keys();
253 QString
NMWirelessNetwork::activeAccessPoint() const
255 Q_D(const NMWirelessNetwork
);
256 return d
->activeAccessPoint
;
259 QString
NMWirelessNetwork::hardwareAddress() const
261 Q_D(const NMWirelessNetwork
);
265 QObject
* NMWirelessNetwork::createAccessPoint(const QString
& uni
)
267 Q_D(NMWirelessNetwork
);
269 QHash
<QString
, NMAccessPoint
*>::Iterator it
= d
->accessPoints
.find(uni
);
270 if (it
!= d
->accessPoints
.end()) {
274 NMAccessPoint
* ap
= new NMAccessPoint(uni
);
279 kDebug(1441) << "no such AP:" << uni
;
284 bool NMWirelessNetwork::activateConnection(const QString
& connectionUni
, const QVariantMap
& connectionParameters
)
286 Q_UNUSED(connectionUni
)
287 Q_UNUSED(connectionParameters
)
291 bool NMWirelessNetwork::deactivateConnection()
296 #include "NetworkManager-wirelessnetwork.moc"