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
/* Modes of operation */
22
#define NM_802_11_MODE_UNKNOWN 0 /* Mode is unknown. */
23
#define NM_802_11_MODE_ADHOC 1 /* Uncoordinated network without central infrastructure. */
24
#define NM_802_11_MODE_INFRA 2 /* Coordinated network with one or more central controllers. */
26
#include "wirelessnetworkinterface.h"
27
#include "wirelessnetworkinterface_p.h"
31
#include "accesspoint.h"
34
NMWirelessNetworkInterfacePrivate::NMWirelessNetworkInterfacePrivate(const QString & path, QObject * owner)
35
: NMNetworkInterfacePrivate(path, owner), wirelessIface(NMNetworkManager::DBUS_SERVICE, path, QDBusConnection::systemBus())
41
NMWirelessNetworkInterface::NMWirelessNetworkInterface(const QString & path, NMNetworkManager * manager, QObject * parent)
42
: NMNetworkInterface(*new NMWirelessNetworkInterfacePrivate(path, this), manager, parent)
44
Q_D(NMWirelessNetworkInterface);
45
d->hardwareAddress = d->wirelessIface.hwAddress();
46
d->mode = convertOperationMode(d->wirelessIface.mode());
47
d->bitRate = d->wirelessIface.bitrate();
48
d->activeAccessPoint = d->wirelessIface.activeAccessPoint().path();
49
d->wirelessCapabilities = convertCapabilities(d->wirelessIface.wirelessCapabilities());
51
connect( &d->wirelessIface, SIGNAL(PropertiesChanged(const QVariantMap &)),
52
this, SLOT(wirelessPropertiesChanged(const QVariantMap &)));
53
connect( &d->wirelessIface, SIGNAL(AccessPointAdded(const QDBusObjectPath &)),
54
this, SLOT(accessPointAdded(const QDBusObjectPath &)));
55
connect( &d->wirelessIface, SIGNAL(AccessPointRemoved(const QDBusObjectPath &)),
56
this, SLOT(accessPointRemoved(const QDBusObjectPath &)));
59
qDBusRegisterMetaType<QList<QDBusObjectPath> >();
60
QDBusReply< QList <QDBusObjectPath> > apPathList = d->wirelessIface.GetAccessPoints();
61
if (apPathList.isValid())
63
//kDebug(1441) << "Got device list";
64
QList <QDBusObjectPath> aps = apPathList.value();
65
foreach (const QDBusObjectPath &op, aps)
67
d->accessPoints.append(op.path());
68
//kDebug(1441) << " " << op.path();
72
kDebug(1441) << "Error getting access point list: " << apPathList.error().name() << ": " << apPathList.error().message();
75
NMWirelessNetworkInterface::~NMWirelessNetworkInterface()
80
QStringList NMWirelessNetworkInterface::accessPoints() const
82
Q_D(const NMWirelessNetworkInterface);
83
return d->accessPoints;
86
QString NMWirelessNetworkInterface::activeAccessPoint() const
88
Q_D(const NMWirelessNetworkInterface);
89
return d->activeAccessPoint;
92
QString NMWirelessNetworkInterface::hardwareAddress() const
94
Q_D(const NMWirelessNetworkInterface);
95
return d->hardwareAddress;
98
Solid::Control::WirelessNetworkInterface::OperationMode NMWirelessNetworkInterface::mode() const
100
Q_D(const NMWirelessNetworkInterface);
104
int NMWirelessNetworkInterface::bitRate() const
106
Q_D(const NMWirelessNetworkInterface);
110
Solid::Control::WirelessNetworkInterface::Capabilities NMWirelessNetworkInterface::wirelessCapabilities() const
112
Q_D(const NMWirelessNetworkInterface);
113
return d->wirelessCapabilities;
116
QObject * NMWirelessNetworkInterface::createAccessPoint(const QString & uni)
118
Q_D(NMWirelessNetworkInterface);
119
NMAccessPoint * ap = 0;
120
if (d->accessPoints.contains(uni)) {
121
ap = new NMAccessPoint(uni, 0);
127
void NMWirelessNetworkInterface::wirelessPropertiesChanged(const QVariantMap & changedProperties)
129
//kDebug(1441) << changedProperties.keys();
130
QStringList propKeys = changedProperties.keys();
131
Q_D(NMWirelessNetworkInterface);
132
QLatin1String activeApKey("ActiveAccessPoint"),
133
hwAddrKey("HwAddress"),
134
bitRateKey("Bitrate"),
136
wirelessCapsKey("WirelessCapabilities");
137
QVariantMap::const_iterator it = changedProperties.find(activeApKey);
138
if (it != changedProperties.end()) {
139
d->activeAccessPoint = qdbus_cast<QDBusObjectPath>(*it).path();
140
emit activeAccessPointChanged(d->activeAccessPoint);
141
propKeys.removeOne(activeApKey);
143
it = changedProperties.find(hwAddrKey);
144
if (it != changedProperties.end()) {
145
d->hardwareAddress = it->toString();
146
propKeys.removeOne(hwAddrKey);
148
it = changedProperties.find(bitRateKey);
149
if (it != changedProperties.end()) {
150
d->bitRate = it->toUInt();
151
emit bitRateChanged(d->bitRate);
152
propKeys.removeOne(bitRateKey);
154
it = changedProperties.find(modeKey);
155
if (it != changedProperties.end()) {
156
d->mode = convertOperationMode(it->toUInt());
157
emit modeChanged(d->mode);
158
propKeys.removeOne(modeKey);
160
it = changedProperties.find(wirelessCapsKey);
161
if (it != changedProperties.end()) {
162
d->wirelessCapabilities = convertCapabilities(it->toUInt());
163
propKeys.removeOne(wirelessCapsKey);
165
//if (propKeys.count()) {
166
// kDebug(1441) << "Unhandled properties: " << propKeys;
170
void NMWirelessNetworkInterface::accessPointAdded(const QDBusObjectPath &apPath)
172
//kDebug(1441) << apPath.path();
173
Q_D(NMWirelessNetworkInterface);
174
if (!d->accessPoints.contains(apPath.path())) {
175
d->accessPoints.append(apPath.path());
176
emit accessPointAppeared(apPath.path());
180
void NMWirelessNetworkInterface::accessPointRemoved(const QDBusObjectPath &apPath)
182
//kDebug(1441) << apPath.path();
183
Q_D(NMWirelessNetworkInterface);
184
if (!d->accessPoints.contains(apPath.path())) {
185
kDebug(1441) << "Access point list lookup failed for " << apPath.path();
187
d->accessPoints.removeAll(apPath.path());
188
emit accessPointDisappeared(apPath.path());
191
Solid::Control::WirelessNetworkInterface::OperationMode NMWirelessNetworkInterface::convertOperationMode(uint theirMode)
193
Solid::Control::WirelessNetworkInterface::OperationMode ourMode = Solid::Control::WirelessNetworkInterface::Unassociated;
194
switch ( theirMode ) {
195
case NM_802_11_MODE_UNKNOWN:
196
ourMode = Solid::Control::WirelessNetworkInterface::Unassociated;
198
case NM_802_11_MODE_ADHOC:
199
ourMode = Solid::Control::WirelessNetworkInterface::Adhoc;
201
case NM_802_11_MODE_INFRA:
202
ourMode = Solid::Control::WirelessNetworkInterface::Managed;
208
Solid::Control::WirelessNetworkInterface::Capabilities NMWirelessNetworkInterface::convertCapabilities(uint caps)
210
return (Solid::Control::WirelessNetworkInterface::Capabilities)caps;