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

« back to all changes in this revision

Viewing changes to solid/wicd/wirelessaccesspoint.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
/*  This file is part of the KDE project
 
2
    Copyright (C) 2008 Dario Freddi <drf54321@gmail.com>
 
3
 
 
4
    This library is free software; you can redistribute it and/or
 
5
    modify it under the terms of the GNU Library General Public
 
6
    License version 2 as published by the Free Software Foundation.
 
7
 
 
8
    This library is distributed in the hope that it will be useful,
 
9
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
    Library General Public License for more details.
 
12
 
 
13
    You should have received a copy of the GNU Library General Public License
 
14
    along with this library; see the file COPYING.LIB.  If not, write to
 
15
    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
16
    Boston, MA 02110-1301, USA.
 
17
 
 
18
*/
 
19
 
 
20
#include "wirelessaccesspoint.h"
 
21
 
 
22
#include "wicddbusinterface.h"
 
23
#include "wicd-defines.h"
 
24
 
 
25
#include <QtDBus/QDBusReply>
 
26
 
 
27
#include <KDebug>
 
28
 
 
29
class WicdAccessPoint::Private
 
30
{
 
31
public:
 
32
    Private(WicdAccessPoint *parent)
 
33
            : q(parent) {
 
34
        createChanMap();
 
35
    };
 
36
 
 
37
    void createChanMap();
 
38
 
 
39
    void recacheInformation();
 
40
    void reloadNetworkId();
 
41
 
 
42
    WicdAccessPoint *q;
 
43
    int networkid;
 
44
    QString essid;
 
45
    QString bssid;
 
46
    int channel;
 
47
    QString mode;
 
48
    int strength;
 
49
    int quality;
 
50
    QString encryption_method;
 
51
    QString enctype;
 
52
    uint frequency;
 
53
    QMap<int, uint> chanToFreq;
 
54
    int bitrate;
 
55
};
 
56
 
 
57
void WicdAccessPoint::Private::createChanMap()
 
58
{
 
59
    chanToFreq[1] = 2412;
 
60
    chanToFreq[2] = 2417;
 
61
    chanToFreq[3] = 2422;
 
62
    chanToFreq[4] = 2427;
 
63
    chanToFreq[5] = 2432;
 
64
    chanToFreq[6] = 2437;
 
65
    chanToFreq[7] = 2442;
 
66
    chanToFreq[8] = 2447;
 
67
    chanToFreq[9] = 2452;
 
68
    chanToFreq[10] = 2457;
 
69
    chanToFreq[11] = 2462;
 
70
    chanToFreq[12] = 2467;
 
71
    chanToFreq[13] = 2472;
 
72
    chanToFreq[14] = 2484;
 
73
}
 
74
 
 
75
void WicdAccessPoint::Private::recacheInformation()
 
76
{
 
77
    QDBusReply< QString > essidr = WicdDbusInterface::instance()->wireless().call("GetWirelessProperty", networkid, "essid");
 
78
    QDBusReply< QString > bssidr = WicdDbusInterface::instance()->wireless().call("GetWirelessProperty", networkid, "bssid");
 
79
    QDBusReply< QString > channelr = WicdDbusInterface::instance()->wireless().call("GetWirelessProperty", networkid, "channel");
 
80
    QDBusReply< QString > bitrater = WicdDbusInterface::instance()->wireless().call("GetWirelessProperty", networkid, "bitrates");
 
81
    QDBusReply< QString > moder = WicdDbusInterface::instance()->wireless().call("GetWirelessProperty", networkid, "mode");
 
82
    QDBusReply< int > strengthr = WicdDbusInterface::instance()->wireless().call("GetWirelessProperty", networkid, "strength");
 
83
    QDBusReply< int > qualityr = WicdDbusInterface::instance()->wireless().call("GetWirelessProperty", networkid, "quality");
 
84
    QDBusReply< QString > encryption_methodr = WicdDbusInterface::instance()->wireless().call("GetWirelessProperty", networkid, "encryption_method");
 
85
    QDBusReply< QString > enctyper = WicdDbusInterface::instance()->wireless().call("GetWirelessProperty", networkid, "enctype");
 
86
 
 
87
    if (essidr.value() != essid) {
 
88
        essid = essidr.value();
 
89
        emit q->ssidChanged(essid);
 
90
    }
 
91
    bssid = bssidr.value();
 
92
    channel = channelr.value().toInt();
 
93
    mode = moder.value();
 
94
    if (strength != strengthr.value()) {
 
95
        strength = strengthr.value();
 
96
        emit q->signalStrengthChanged(strength);
 
97
    }
 
98
    quality = qualityr.value();
 
99
    encryption_method = encryption_methodr.value();
 
100
    enctype = enctyper.value();
 
101
    if (frequency != chanToFreq[channel]) {
 
102
        frequency = chanToFreq[channel];
 
103
        emit q->frequencyChanged(frequency);
 
104
    }
 
105
    QStringList bitrates = bitrater.value().split(" Mb/s; ");
 
106
    bitrates.last().remove(" Mb/s");
 
107
    int bitrate_new = 0;
 
108
 
 
109
    foreach(const QString &b, bitrates) {
 
110
        bitrate_new = qMax(bitrate_new, b.toInt() * 1000);
 
111
    }
 
112
 
 
113
    if (bitrate_new != bitrate) {
 
114
        bitrate = bitrate_new;
 
115
        emit q->bitRateChanged(bitrate);
 
116
    }
 
117
}
 
118
 
 
119
void WicdAccessPoint::Private::reloadNetworkId()
 
120
{
 
121
    QDBusReply< int > networks = WicdDbusInterface::instance()->wireless().call("GetNumberOfNetworks");
 
122
 
 
123
    for (int i = 0; i < networks.value(); ++i) {
 
124
        QDBusReply< QString > r = WicdDbusInterface::instance()->wireless().call("GetWirelessProperty", i, "bssid");
 
125
        if (r.value() == bssid) {
 
126
            networkid = i;
 
127
            return;
 
128
        }
 
129
    }
 
130
}
 
131
 
 
132
WicdAccessPoint::WicdAccessPoint(int networkid)
 
133
        : AccessPoint(0)
 
134
        , d(new Private(this))
 
135
{
 
136
    d->networkid = networkid;
 
137
    d->recacheInformation();
 
138
    QDBusConnection::systemBus().connect(WICD_DBUS_SERVICE, WICD_DAEMON_DBUS_PATH, WICD_DAEMON_DBUS_INTERFACE,
 
139
                                         "StatusChanged", this, SLOT(refreshStatus()));
 
140
}
 
141
 
 
142
WicdAccessPoint::~WicdAccessPoint()
 
143
{
 
144
    delete d;
 
145
}
 
146
 
 
147
void WicdAccessPoint::refreshStatus()
 
148
{
 
149
    d->recacheInformation();
 
150
}
 
151
 
 
152
QString WicdAccessPoint::uni() const
 
153
{
 
154
    return d->bssid;
 
155
}
 
156
 
 
157
Solid::Control::AccessPoint::Capabilities WicdAccessPoint::capabilities() const
 
158
{
 
159
    return 0;
 
160
}
 
161
 
 
162
Solid::Control::AccessPoint::WpaFlags WicdAccessPoint::wpaFlags() const
 
163
{
 
164
    Solid::Control::AccessPoint::WpaFlags f = (Solid::Control::AccessPoint::WpaFlags)0;
 
165
 
 
166
    if (d->encryption_method == "WPA") {
 
167
        f |= Solid::Control::AccessPoint::KeyMgmtPsk;
 
168
        f |= Solid::Control::AccessPoint::GroupTkip;
 
169
    } else if (d->encryption_method == "WPA2") {
 
170
        f |= Solid::Control::AccessPoint::KeyMgmtPsk;
 
171
        f |= Solid::Control::AccessPoint::GroupTkip;
 
172
    } else if (d->encryption_method == "WEP") {
 
173
        f |= Solid::Control::AccessPoint::PairWep104;
 
174
        f |= Solid::Control::AccessPoint::PairWep40;
 
175
    }
 
176
 
 
177
    return f;
 
178
}
 
179
 
 
180
Solid::Control::AccessPoint::WpaFlags WicdAccessPoint::rsnFlags() const
 
181
{
 
182
    return 0;
 
183
}
 
184
 
 
185
QString WicdAccessPoint::ssid() const
 
186
{
 
187
    return d->essid;
 
188
}
 
189
 
 
190
QByteArray WicdAccessPoint::rawSsid() const
 
191
{
 
192
    return d->essid.toUtf8();
 
193
}
 
194
 
 
195
uint WicdAccessPoint::frequency() const
 
196
{
 
197
    return d->frequency;
 
198
}
 
199
 
 
200
QString WicdAccessPoint::hardwareAddress() const
 
201
{
 
202
    return d->bssid;
 
203
}
 
204
 
 
205
uint WicdAccessPoint::maxBitRate() const
 
206
{
 
207
    return d->bitrate;
 
208
}
 
209
 
 
210
Solid::Control::WirelessNetworkInterface::OperationMode WicdAccessPoint::mode() const
 
211
{
 
212
    if (d->mode == "Master") {
 
213
        return Solid::Control::WirelessNetworkInterface::Master;
 
214
    } else if (d->mode == "Managed") {
 
215
        return Solid::Control::WirelessNetworkInterface::Managed;
 
216
    } else if (d->mode == "Adhoc") {
 
217
        return Solid::Control::WirelessNetworkInterface::Adhoc;
 
218
    }
 
219
 
 
220
    return Solid::Control::WirelessNetworkInterface::Master;
 
221
}
 
222
 
 
223
int WicdAccessPoint::signalStrength() const
 
224
{
 
225
    return d->quality;
 
226
}
 
227
 
 
228
#include "wirelessaccesspoint.moc"