-
Notifications
You must be signed in to change notification settings - Fork 1
/
wirelessnetworkinterface.cpp
267 lines (212 loc) · 8.63 KB
/
wirelessnetworkinterface.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
/* This file is part of the KDE project
Copyright (C) 2008 Dario Freddi <[email protected]>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License version 2 as published by the Free Software Foundation.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "wirelessnetworkinterface.h"
#include "wirelessaccesspoint.h"
#include "wicddbusinterface.h"
#include "wicd-defines.h"
#include <QtDBus/QDBusInterface>
#include <QtDBus/QDBusReply>
#include <QtCore/QProcess>
#include <KDebug>
class WicdWirelessNetworkInterface::Private
{
public:
Private() {};
QMap<int, QString> getAccessPointsWithId();
Solid::Control::WirelessNetworkInterface::OperationMode parseOpMode(const QString &m);
bool isActiveInterface;
QString uni;
int bitrate;
int current_network;
QString driver;
QString mode;
QString auth_methods;
Solid::Control::NetworkInterface::ConnectionState connection_state;
};
Solid::Control::WirelessNetworkInterface::OperationMode WicdWirelessNetworkInterface::Private::parseOpMode(const QString &m)
{
if (m == "Master") {
return Solid::Control::WirelessNetworkInterface::Master;
} else if (m == "Managed") {
return Solid::Control::WirelessNetworkInterface::Managed;
} else if (m == "Adhoc") {
return Solid::Control::WirelessNetworkInterface::Adhoc;
}
return Solid::Control::WirelessNetworkInterface::Master;
}
void WicdWirelessNetworkInterface::recacheInformation()
{
QProcess process;
process.start("iwconfig " + d->uni);
process.waitForFinished();
QString iwconfig = process.readAll();
process.close();
process.start("iwlist " + d->uni + " auth");
process.waitForFinished();
QString iwlist = process.readAll();
QDBusReply< QString > bitrater = WicdDbusInterface::instance()->wireless().call("GetCurrentBitrate", iwconfig);
QDBusReply< QString > authmr = WicdDbusInterface::instance()->wireless().call("GetAvailableAuthMethods", iwlist);
QDBusReply< QString > moder = WicdDbusInterface::instance()->wireless().call("GetOperationalMode", iwconfig);
QDBusReply< int > networkr = WicdDbusInterface::instance()->wireless().call("GetCurrentNetworkID");
QDBusReply< QString > driverr = WicdDbusInterface::instance()->daemon().call("GetWPADriver");
QDBusReply< QString > interfacer = WicdDbusInterface::instance()->daemon().call("GetWirelessInterface");
QDBusReply< QString > cstater = WicdDbusInterface::instance()->wireless().call("CheckWirelessConnectingMessage");
if (d->bitrate != bitrater.value().split(' ').at(0).toInt() * 1000) {
d->bitrate = bitrater.value().split(' ').at(0).toInt() * 1000;
emit bitRateChanged(d->bitrate);
}
d->driver = driverr.value();
if (d->mode != moder.value()) {
d->mode = moder.value();
emit modeChanged(d->parseOpMode(d->mode));
}
d->auth_methods = authmr.value();
if (interfacer.value() == d->uni) {
kDebug() << "Active interface";
if (d->current_network != networkr.value()) {
d->current_network = networkr.value();
emit activeAccessPointChanged(d->getAccessPointsWithId()[d->current_network]);
}
Solid::Control::NetworkInterface::ConnectionState connection_state;
if (cstater.value() == "configuring_interface") {
connection_state = Solid::Control::NetworkInterface::Configuring;
} else if (cstater.value() == "validating_authentication") {
connection_state = Solid::Control::NetworkInterface::NeedAuth;
} else if (cstater.value() == "done") {
connection_state = Solid::Control::NetworkInterface::Activated;
} else if (cstater.value() == "interface_down") {
connection_state = Solid::Control::NetworkInterface::Disconnected;
} else if (cstater.value() == "running_dhcp" ||
cstater.value() == "setting_static_ip" ||
cstater.value() == "setting_broadcast_address") {
connection_state = Solid::Control::NetworkInterface::IPConfig;
} else if (cstater.value() == "interface_up") {
connection_state = Solid::Control::NetworkInterface::Preparing;
} else {
connection_state = Solid::Control::NetworkInterface::UnknownState;
}
if (connection_state != d->connection_state) {
connection_state = d->connection_state;
emit connectionStateChanged(d->connection_state);
}
}
}
QMap<int, QString> WicdWirelessNetworkInterface::Private::getAccessPointsWithId()
{
QDBusReply< int > networks = WicdDbusInterface::instance()->wireless().call("GetNumberOfNetworks");
QMap<int, QString> retlist;
for (int i = 0; i < networks.value(); ++i) {
QDBusReply< QString > r = WicdDbusInterface::instance()->wireless().call("GetWirelessProperty", i, "bssid");
retlist[i] = r;
}
return retlist;
}
WicdWirelessNetworkInterface::WicdWirelessNetworkInterface(const QString &objectPath)
: WicdNetworkInterface(objectPath)
, d(new Private())
{
d->uni = uni();
recacheInformation();
QDBusConnection::systemBus().connect(WICD_DBUS_SERVICE, WICD_DAEMON_DBUS_PATH, WICD_DAEMON_DBUS_INTERFACE,
"StatusChanged", this, SLOT(refreshStatus()));
}
WicdWirelessNetworkInterface::~WicdWirelessNetworkInterface()
{
delete d;
}
Solid::Control::NetworkInterface::Type WicdWirelessNetworkInterface::type() const
{
return Solid::Control::NetworkInterface::Ieee80211;
}
bool WicdWirelessNetworkInterface::isActive() const
{
return d->isActiveInterface;
}
Solid::Control::NetworkInterface::Capabilities WicdWirelessNetworkInterface::capabilities() const
{
Solid::Control::NetworkInterface::Capabilities cap;
if (interfaceName() != "lo" || !interfaceName().contains("wmaster")) {
cap |= Solid::Control::NetworkInterface::IsManageable;
}
return cap;
}
QString WicdWirelessNetworkInterface::driver() const
{
return d->driver;
}
int WicdWirelessNetworkInterface::bitRate() const
{
return d->bitrate;
}
Solid::Control::NetworkInterface::ConnectionState WicdWirelessNetworkInterface::connectionState() const
{
if (d->isActiveInterface) {
return d->connection_state;
} else {
return Solid::Control::NetworkInterface::Unavailable;
}
}
Solid::Control::WirelessNetworkInterface::Capabilities WicdWirelessNetworkInterface::wirelessCapabilities() const
{
Solid::Control::WirelessNetworkInterface::Capabilities cap;
if (d->auth_methods.contains("WPA")) {
cap |= Solid::Control::WirelessNetworkInterface::Wpa;
}
if (d->auth_methods.contains("CIPHER-TKIP")) {
cap |= Solid::Control::WirelessNetworkInterface::Tkip;
}
if (d->auth_methods.contains("CIPHER-CCMP")) {
cap |= Solid::Control::WirelessNetworkInterface::Ccmp;
}
cap |= Solid::Control::WirelessNetworkInterface::Wep104;
cap |= Solid::Control::WirelessNetworkInterface::Wep40;
return cap;
}
Solid::Control::WirelessNetworkInterface::OperationMode WicdWirelessNetworkInterface::mode() const
{
return d->parseOpMode(d->mode);
}
MacAddressList WicdWirelessNetworkInterface::accessPoints() const
{
return d->getAccessPointsWithId().values();
}
QString WicdWirelessNetworkInterface::activeAccessPoint() const
{
if (d->isActiveInterface) {
return d->getAccessPointsWithId()[d->current_network];
} else {
return QString();
}
}
QString WicdWirelessNetworkInterface::hardwareAddress() const
{
// Let's parse ifconfig here
QProcess ifconfig;
ifconfig.start(QString("ifconfig %1").arg(uni()));
ifconfig.waitForFinished();
QString result = ifconfig.readAllStandardOutput();
QStringList lines = result.split('\n');
return lines.at(0).split("HWaddr ").at(1);
}
QObject * WicdWirelessNetworkInterface::createAccessPoint(const QString & uni)
{
QMap<int, QString> aps = d->getAccessPointsWithId();
if (!aps.values().contains(uni)) {
kDebug() << "Requested a non existent AP";
}
int network = aps.key(uni);
return new WicdAccessPoint(network);
}
#include "wirelessnetworkinterface.moc"