2
Copyright 2008 Will Stephenson <wstephenson@kde.org>
4
This program is free software; you can redistribute it and/or
5
modify it under the terms of the GNU General Public License as
6
published by the Free Software Foundation; either version 2 of
7
the License or (at your option) version 3 or any later version
8
accepted by the membership of KDE e.V. (or its successor approved
9
by the membership of KDE e.V.), which shall act as a proxy
10
defined in Section 14 of version 3 of the license.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program. If not, see <http://www.gnu.org/licenses/>.
21
#include "accesspoint.h"
24
#include "dbus/nm-access-pointinterface.h"
26
#include "wirelessnetworkinterface.h"
29
class NMAccessPoint::Private
32
Private( const QString & path ) : iface( NMNetworkManager::DBUS_SERVICE, path, QDBusConnection::systemBus()), capabilities(0), wpaFlags(0), rsnFlags(0), frequency(0), maxBitRate(0), mode((Solid::Control::WirelessNetworkInterface::OperationMode)0), signalStrength(0)
35
OrgFreedesktopNetworkManagerAccessPointInterface iface;
37
Solid::Control::AccessPoint::Capabilities capabilities;
38
Solid::Control::AccessPoint::WpaFlags wpaFlags;
39
Solid::Control::AccessPoint::WpaFlags rsnFlags;
43
QString hardwareAddress;
45
Solid::Control::WirelessNetworkInterface::OperationMode mode;
49
NMAccessPoint::NMAccessPoint( const QString& path, QObject * parent ) : Solid::Control::Ifaces::AccessPoint(parent), d(new Private( path ))
52
if (d->iface.isValid()) {
53
d->capabilities = convertCapabilities( d->iface.flags() );
54
d->wpaFlags = convertWpaFlags( d->iface.wpaFlags() );
55
d->rsnFlags = convertWpaFlags( d->iface.rsnFlags() );
56
d->signalStrength = d->iface.strength();
57
d->ssid = d->iface.ssid();
58
d->rawSsid = d->iface.ssid();
59
d->frequency = d->iface.frequency();
60
d->hardwareAddress = d->iface.hwAddress();
61
d->maxBitRate = d->iface.maxBitrate();
62
// make this a static on WirelessNetworkInterface
63
d->mode = NMWirelessNetworkInterface::convertOperationMode(d->iface.mode());
64
connect( &d->iface, SIGNAL(PropertiesChanged(const QVariantMap &)),
65
this, SLOT(propertiesChanged(const QVariantMap &)));
69
NMAccessPoint::~NMAccessPoint()
74
QString NMAccessPoint::uni() const
79
QString NMAccessPoint::hardwareAddress() const
81
return d->hardwareAddress;
84
Solid::Control::AccessPoint::Capabilities NMAccessPoint::capabilities() const
86
return d->capabilities;
89
Solid::Control::AccessPoint::WpaFlags NMAccessPoint::wpaFlags() const
94
Solid::Control::AccessPoint::WpaFlags NMAccessPoint::rsnFlags() const
99
QString NMAccessPoint::ssid() const
104
QByteArray NMAccessPoint::rawSsid() const
109
uint NMAccessPoint::frequency() const
114
uint NMAccessPoint::maxBitRate() const
116
return d->maxBitRate;
119
Solid::Control::WirelessNetworkInterface::OperationMode NMAccessPoint::mode() const
124
int NMAccessPoint::signalStrength() const
126
return d->signalStrength;
129
void NMAccessPoint::propertiesChanged(const QVariantMap &properties)
131
QStringList propKeys = properties.keys();
132
//kDebug(1441) << propKeys;
133
QLatin1String flagsKey("Flags"),
134
wpaFlagsKey("WpaFlags"),
135
rsnFlagsKey("RsnFlags"),
137
freqKey("Frequency"),
138
hwAddrKey("HwAddress"),
140
maxBitRateKey("MaxBitrate"),
141
strengthKey("Strength");
142
QVariantMap::const_iterator it = properties.find(flagsKey);
143
if (it != properties.end()) {
144
d->capabilities = convertCapabilities(it->toUInt());
145
propKeys.removeOne(flagsKey);
147
it = properties.find(wpaFlagsKey);
148
if (it != properties.end()) {
149
d->wpaFlags = convertWpaFlags(it->toUInt());
150
emit wpaFlagsChanged(d->wpaFlags);
151
propKeys.removeOne(wpaFlagsKey);
153
it = properties.find(rsnFlagsKey);
154
if (it != properties.end()) {
155
d->rsnFlags = convertWpaFlags(it->toUInt());
156
emit rsnFlagsChanged(d->rsnFlags);
157
propKeys.removeOne(rsnFlagsKey);
159
it = properties.find(ssidKey);
160
if (it != properties.end()) {
161
d->ssid = it->toByteArray();
162
emit ssidChanged(d->ssid);
163
propKeys.removeOne(ssidKey);
165
it = properties.find(freqKey);
166
if (it != properties.end()) {
167
d->frequency = it->toUInt();
168
emit frequencyChanged(d->frequency);
169
propKeys.removeOne(freqKey);
171
it = properties.find(hwAddrKey);
172
if (it != properties.end()) {
173
d->hardwareAddress = it->toString();
174
propKeys.removeOne(hwAddrKey);
176
it = properties.find(modeKey);
177
if (it != properties.end()) {
178
d->mode = NMWirelessNetworkInterface::convertOperationMode(it->toUInt());
179
propKeys.removeOne(modeKey);
181
it = properties.find(maxBitRateKey);
182
if (it != properties.end()) {
183
d->maxBitRate = it->toUInt();
184
emit bitRateChanged(d->maxBitRate);
185
propKeys.removeOne(maxBitRateKey);
187
it = properties.find(strengthKey);
188
if (it != properties.end()) {
189
d->signalStrength = it->toInt();
190
//kDebug(1441) << "UNI: " << d->uni << "MAC: " << d->hardwareAddress << "SignalStrength: " << d->signalStrength;
191
emit signalStrengthChanged(d->signalStrength);
192
propKeys.removeOne(strengthKey);
194
if (propKeys.count()) {
195
kDebug(1441) << "Unhandled properties: " << propKeys;
199
Solid::Control::AccessPoint::Capabilities NMAccessPoint::convertCapabilities(int caps)
202
return Solid::Control::AccessPoint::Privacy;
207
// Copied from wireless.h
208
// /* Modes of operation */
209
#define IW_MODE_AUTO 0 /* Let the driver decides */
210
#define IW_MODE_ADHOC 1 /* Single cell network */
211
#define IW_MODE_INFRA 2 /* Multi cell network, roaming, ... */
212
#define IW_MODE_MASTER 3 /* Synchronization master or Access Point */
213
#define IW_MODE_REPEAT 4 /* Wireless Repeater (forwarder) */
214
#define IW_MODE_SECOND 5 /* Secondary master/repeater (backup) */
215
#define IW_MODE_MONITOR 6 /* Passive monitor (listen only) */
217
Solid::Control::AccessPoint::WpaFlags NMAccessPoint::convertWpaFlags(uint theirFlags)
219
return (Solid::Control::AccessPoint::WpaFlags)theirFlags;
222
#include "accesspoint.moc"