~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to solid/networkmanager-0.7/accesspoint.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
Copyright 2008 Will Stephenson <wstephenson@kde.org>
 
3
 
 
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.
 
11
 
 
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.
 
16
 
 
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/>.
 
19
*/
 
20
 
 
21
#include "accesspoint.h"
 
22
 
 
23
#include <KDebug>
 
24
#include "dbus/nm-access-pointinterface.h"
 
25
#include "manager.h"
 
26
#include "wirelessnetworkinterface.h"
 
27
 
 
28
 
 
29
class NMAccessPoint::Private
 
30
{
 
31
public:
 
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)
 
33
    {
 
34
    }
 
35
    OrgFreedesktopNetworkManagerAccessPointInterface iface;
 
36
    QString uni;
 
37
    Solid::Control::AccessPoint::Capabilities capabilities;
 
38
    Solid::Control::AccessPoint::WpaFlags wpaFlags;
 
39
    Solid::Control::AccessPoint::WpaFlags rsnFlags;
 
40
    QString ssid;
 
41
    QByteArray rawSsid;
 
42
    uint frequency;
 
43
    QString hardwareAddress;
 
44
    uint maxBitRate;
 
45
    Solid::Control::WirelessNetworkInterface::OperationMode mode;
 
46
    int signalStrength;
 
47
};
 
48
 
 
49
NMAccessPoint::NMAccessPoint( const QString& path, QObject * parent ) : Solid::Control::Ifaces::AccessPoint(parent), d(new Private( path ))
 
50
{
 
51
    d->uni = 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 &)));
 
66
    }
 
67
}
 
68
 
 
69
NMAccessPoint::~NMAccessPoint()
 
70
{
 
71
    delete d;
 
72
}
 
73
 
 
74
QString NMAccessPoint::uni() const
 
75
{
 
76
    return d->uni;
 
77
}
 
78
 
 
79
QString NMAccessPoint::hardwareAddress() const
 
80
{
 
81
    return d->hardwareAddress;
 
82
}
 
83
 
 
84
Solid::Control::AccessPoint::Capabilities NMAccessPoint::capabilities() const
 
85
{
 
86
    return d->capabilities;
 
87
}
 
88
 
 
89
Solid::Control::AccessPoint::WpaFlags NMAccessPoint::wpaFlags() const
 
90
{
 
91
    return d->wpaFlags;
 
92
}
 
93
 
 
94
Solid::Control::AccessPoint::WpaFlags NMAccessPoint::rsnFlags() const
 
95
{
 
96
    return d->rsnFlags;
 
97
}
 
98
 
 
99
QString NMAccessPoint::ssid() const
 
100
{
 
101
    return d->ssid;
 
102
}
 
103
 
 
104
QByteArray NMAccessPoint::rawSsid() const
 
105
{
 
106
    return d->rawSsid;
 
107
}
 
108
 
 
109
uint NMAccessPoint::frequency() const
 
110
{
 
111
    return d->frequency;
 
112
}
 
113
 
 
114
uint NMAccessPoint::maxBitRate() const
 
115
{
 
116
    return d->maxBitRate;
 
117
}
 
118
 
 
119
Solid::Control::WirelessNetworkInterface::OperationMode NMAccessPoint::mode() const
 
120
{
 
121
    return d->mode;
 
122
}
 
123
 
 
124
int NMAccessPoint::signalStrength() const
 
125
{
 
126
    return d->signalStrength;
 
127
}
 
128
 
 
129
void NMAccessPoint::propertiesChanged(const QVariantMap &properties)
 
130
{
 
131
    QStringList propKeys = properties.keys();
 
132
    //kDebug(1441) << propKeys;
 
133
    QLatin1String flagsKey("Flags"),
 
134
                  wpaFlagsKey("WpaFlags"),
 
135
                  rsnFlagsKey("RsnFlags"),
 
136
                  ssidKey("Ssid"),
 
137
                  freqKey("Frequency"),
 
138
                  hwAddrKey("HwAddress"),
 
139
                  modeKey("Mode"),
 
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);
 
146
    }
 
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);
 
152
    }
 
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);
 
158
    }
 
159
    it = properties.find(ssidKey);
 
160
    if (it != properties.end()) {
 
161
        d->ssid = it->toByteArray();
 
162
        emit ssidChanged(d->ssid);
 
163
        propKeys.removeOne(ssidKey);
 
164
    }
 
165
    it = properties.find(freqKey);
 
166
    if (it != properties.end()) {
 
167
        d->frequency = it->toUInt();
 
168
        emit frequencyChanged(d->frequency);
 
169
        propKeys.removeOne(freqKey);
 
170
    }
 
171
    it = properties.find(hwAddrKey);
 
172
    if (it != properties.end()) {
 
173
        d->hardwareAddress = it->toString();
 
174
        propKeys.removeOne(hwAddrKey);
 
175
    }
 
176
    it = properties.find(modeKey);
 
177
    if (it != properties.end()) {
 
178
        d->mode = NMWirelessNetworkInterface::convertOperationMode(it->toUInt());
 
179
        propKeys.removeOne(modeKey);
 
180
    }
 
181
    it = properties.find(maxBitRateKey);
 
182
    if (it != properties.end()) {
 
183
        d->maxBitRate = it->toUInt();
 
184
        emit bitRateChanged(d->maxBitRate);
 
185
        propKeys.removeOne(maxBitRateKey);
 
186
    }
 
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);
 
193
    }
 
194
    if (propKeys.count()) {
 
195
        kDebug(1441) << "Unhandled properties: " << propKeys;
 
196
    }
 
197
}
 
198
 
 
199
Solid::Control::AccessPoint::Capabilities NMAccessPoint::convertCapabilities(int caps)
 
200
{
 
201
    if ( 1 == caps ) {
 
202
        return Solid::Control::AccessPoint::Privacy;
 
203
    } else {
 
204
        return 0;
 
205
    }
 
206
}
 
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) */
 
216
 
 
217
Solid::Control::AccessPoint::WpaFlags NMAccessPoint::convertWpaFlags(uint theirFlags)
 
218
{
 
219
    return (Solid::Control::AccessPoint::WpaFlags)theirFlags;
 
220
}
 
221
 
 
222
#include "accesspoint.moc"
 
223