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-wirelessaccesspoint.h"
23 #include <QtDBus/QDBusInterface>
24 #include <QtDBus/QDBusMessage>
28 #include <NetworkManager/NetworkManager.h>
30 extern Solid::Control::WirelessNetworkInterface::OperationMode
getOperationMode(const int nm
);
35 Solid::Control::AccessPoint::WpaFlags
getWpaFlags(int netflags
)
37 Solid::Control::AccessPoint::WpaFlags f
= (Solid::Control::AccessPoint::WpaFlags
)0;
38 if (netflags
& NM_802_11_CAP_KEY_MGMT_PSK
)
39 f
|= Solid::Control::AccessPoint::KeyMgmtPsk
;
40 if (netflags
& NM_802_11_CAP_KEY_MGMT_802_1X
)
41 f
|= Solid::Control::AccessPoint::KeyMgmt8021x
;
42 if (netflags
& NM_802_11_CAP_CIPHER_WEP40
)
43 f
|= Solid::Control::AccessPoint::PairWep40
;
44 if (netflags
& NM_802_11_CAP_CIPHER_WEP104
)
45 f
|= Solid::Control::AccessPoint::PairWep104
;
46 if (netflags
& NM_802_11_CAP_CIPHER_TKIP
)
47 f
|= Solid::Control::AccessPoint::GroupTkip
;
48 if (netflags
& NM_802_11_CAP_CIPHER_CCMP
)
49 f
|= Solid::Control::AccessPoint::GroupCcmp
;
56 class NMAccessPointPrivate
59 NMAccessPointPrivate(const QString
& networkPath
);
61 void deserialize(const QDBusMessage
& message
);
64 Solid::Control::AccessPoint::Capabilities capabilities
;
65 Solid::Control::AccessPoint::WpaFlags wpaFlags
;
66 Solid::Control::AccessPoint::WpaFlags rsnFlags
;
69 QString hardwareAddress
;
71 Solid::Control::WirelessNetworkInterface::OperationMode mode
;
76 NMAccessPointPrivate::NMAccessPointPrivate(const QString
& networkPath
)
77 : netPath(networkPath
)
83 , mode(static_cast<Solid::Control::WirelessNetworkInterface::OperationMode
>(0))
89 void NMAccessPointPrivate::deserialize(const QDBusMessage
&message
)
91 const QList
<QVariant
> args
= message
.arguments();
92 if (args
.size() > 1) ssid
= args
[1].toString();
93 if (args
.size() > 2) hardwareAddress
= args
[2].toString();
94 if (args
.size() > 3) signalStrength
= args
[3].toInt();
95 // frequency: NM 0.6 provides it in Hz, while we need MHz
96 if (args
.size() > 4) frequency
= static_cast<uint
>(args
[4].toDouble() / 1000000);
97 if (args
.size() > 5) maxBitRate
= args
[5].toUInt();
98 if (args
.size() > 6) mode
= getOperationMode(args
[6].toInt());
99 if (args
.size() > 7) wpaFlags
= AP::getWpaFlags(args
[7].toInt());
100 if (args
.size() > 8) broadcast
= args
[8].toBool();
104 NMAccessPoint::NMAccessPoint(const QString
& netPath
)
105 : Solid::Control::Ifaces::AccessPoint(0), d(new NMAccessPointPrivate(netPath
))
107 QDBusInterface
iface(NM_DBUS_SERVICE
, netPath
, NM_DBUS_INTERFACE_DEVICES
,
108 QDBusConnection::systemBus());
109 QDBusMessage reply
= iface
.call("getProperties");
110 d
->deserialize(reply
);
113 d
->capabilities
|= Solid::Control::AccessPoint::Privacy
;
116 NMAccessPoint::~NMAccessPoint()
121 QString
NMAccessPoint::uni() const
126 Solid::Control::AccessPoint::Capabilities
NMAccessPoint::capabilities() const
128 return d
->capabilities
;
131 Solid::Control::AccessPoint::WpaFlags
NMAccessPoint::wpaFlags() const
136 Solid::Control::AccessPoint::WpaFlags
NMAccessPoint::rsnFlags() const
141 QString
NMAccessPoint::ssid() const
146 uint
NMAccessPoint::frequency() const
151 QString
NMAccessPoint::hardwareAddress() const
153 return d
->hardwareAddress
;
156 uint
NMAccessPoint::maxBitRate() const
158 return d
->maxBitRate
;
161 Solid::Control::WirelessNetworkInterface::OperationMode
NMAccessPoint::mode() const
166 void NMAccessPoint::setSignalStrength(int strength
)
168 if (strength
== d
->signalStrength
)
171 d
->signalStrength
= strength
;
172 emit
signalStrengthChanged(d
->signalStrength
);
175 int NMAccessPoint::signalStrength() const
177 return d
->signalStrength
;
180 #include "NetworkManager-wirelessaccesspoint.moc"