1
/* This file is part of the KDE project
2
Copyright (C) 2008 Dario Freddi <drf54321@gmail.com>
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.
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.
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.
20
#include "wirelessaccesspoint.h"
22
#include "wicddbusinterface.h"
23
#include "wicd-defines.h"
25
#include <QtDBus/QDBusReply>
29
class WicdAccessPoint::Private
32
Private(WicdAccessPoint *parent)
39
void recacheInformation();
40
void reloadNetworkId();
50
QString encryption_method;
53
QMap<int, uint> chanToFreq;
57
void WicdAccessPoint::Private::createChanMap()
68
chanToFreq[10] = 2457;
69
chanToFreq[11] = 2462;
70
chanToFreq[12] = 2467;
71
chanToFreq[13] = 2472;
72
chanToFreq[14] = 2484;
75
void WicdAccessPoint::Private::recacheInformation()
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");
87
if (essidr.value() != essid) {
88
essid = essidr.value();
89
emit q->ssidChanged(essid);
91
bssid = bssidr.value();
92
channel = channelr.value().toInt();
94
if (strength != strengthr.value()) {
95
strength = strengthr.value();
96
emit q->signalStrengthChanged(strength);
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);
105
QStringList bitrates = bitrater.value().split(" Mb/s; ");
106
bitrates.last().remove(" Mb/s");
109
foreach(const QString &b, bitrates) {
110
bitrate_new = qMax(bitrate_new, b.toInt() * 1000);
113
if (bitrate_new != bitrate) {
114
bitrate = bitrate_new;
115
emit q->bitRateChanged(bitrate);
119
void WicdAccessPoint::Private::reloadNetworkId()
121
QDBusReply< int > networks = WicdDbusInterface::instance()->wireless().call("GetNumberOfNetworks");
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) {
132
WicdAccessPoint::WicdAccessPoint(int networkid)
134
, d(new Private(this))
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()));
142
WicdAccessPoint::~WicdAccessPoint()
147
void WicdAccessPoint::refreshStatus()
149
d->recacheInformation();
152
QString WicdAccessPoint::uni() const
157
Solid::Control::AccessPoint::Capabilities WicdAccessPoint::capabilities() const
162
Solid::Control::AccessPoint::WpaFlags WicdAccessPoint::wpaFlags() const
164
Solid::Control::AccessPoint::WpaFlags f = (Solid::Control::AccessPoint::WpaFlags)0;
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;
180
Solid::Control::AccessPoint::WpaFlags WicdAccessPoint::rsnFlags() const
185
QString WicdAccessPoint::ssid() const
190
QByteArray WicdAccessPoint::rawSsid() const
192
return d->essid.toUtf8();
195
uint WicdAccessPoint::frequency() const
200
QString WicdAccessPoint::hardwareAddress() const
205
uint WicdAccessPoint::maxBitRate() const
210
Solid::Control::WirelessNetworkInterface::OperationMode WicdAccessPoint::mode() const
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;
220
return Solid::Control::WirelessNetworkInterface::Master;
223
int WicdAccessPoint::signalStrength() const
228
#include "wirelessaccesspoint.moc"