31
|
1 |
/*
|
|
2 |
* Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
* WLAN Sniffer application engine.
|
|
16 |
*/
|
|
17 |
|
|
18 |
// System includes
|
|
19 |
|
|
20 |
#include <QTimerEvent>
|
|
21 |
|
|
22 |
#include <xqserviceutil.h>
|
|
23 |
#include <xqsettingsmanager.h>
|
|
24 |
#include <wlandevicesettingsinternalcrkeys.h>
|
|
25 |
#include <startupdomainpskeys.h>
|
|
26 |
|
|
27 |
// User includes
|
|
28 |
|
|
29 |
#include "wlanqtutils.h"
|
|
30 |
#include "wlansnifferservice.h"
|
|
31 |
#include "wlansnifferengine.h"
|
|
32 |
|
|
33 |
#include "OstTraceDefinitions.h"
|
|
34 |
#ifdef OST_TRACE_COMPILER_IN_USE
|
|
35 |
#include "wlansnifferengineTraces.h"
|
|
36 |
#endif
|
|
37 |
|
|
38 |
/*!
|
|
39 |
\class WlanSnifferEngine
|
|
40 |
\brief WLAN Sniffer application engine.
|
|
41 |
|
|
42 |
This class implements the WLAN Sniffer application engine.
|
|
43 |
The purpose of the engine implementation is to gather all non-UI
|
|
44 |
implementation base functionality into one place that can be utilized
|
|
45 |
from multiple places (i.e. multiple views and windows).
|
|
46 |
*/
|
|
47 |
|
|
48 |
|
|
49 |
// External function prototypes
|
|
50 |
|
|
51 |
// Local constants
|
|
52 |
|
|
53 |
//! Master WLAN ON/OFF setting key
|
|
54 |
static const XQSettingsKey masterWlanKey(
|
|
55 |
XQSettingsKey::TargetCentralRepository,
|
|
56 |
KCRUidWlanDeviceSettingsRegistryId.iUid,
|
|
57 |
KWlanOnOff);
|
|
58 |
|
|
59 |
//! WLAN forced OFF setting key
|
|
60 |
static const XQSettingsKey wlanForceKey(
|
|
61 |
XQSettingsKey::TargetCentralRepository,
|
|
62 |
KCRUidWlanDeviceSettingsRegistryId.iUid,
|
|
63 |
KWlanForceDisable);
|
|
64 |
|
|
65 |
//! Offline mode setting key
|
|
66 |
static const XQSettingsKey offlineKey(
|
|
67 |
XQSettingsKey::TargetPublishAndSubscribe,
|
|
68 |
KPSUidStartup.iUid,
|
|
69 |
KPSGlobalSystemState);
|
|
70 |
|
|
71 |
// ======== LOCAL FUNCTIONS ========
|
|
72 |
|
|
73 |
// ======== MEMBER FUNCTIONS ========
|
|
74 |
|
|
75 |
/*!
|
|
76 |
Constructor.
|
|
77 |
|
|
78 |
@param [in] parent Parent object.
|
|
79 |
*/
|
|
80 |
|
|
81 |
WlanSnifferEngine::WlanSnifferEngine(QObject *parent) :
|
|
82 |
QObject(parent),
|
|
83 |
mService(new WlanSnifferService(this)),
|
|
84 |
mSettingsManager(new XQSettingsManager(this)),
|
|
85 |
mScanTimerId(0),
|
|
86 |
mEmbedded(false),
|
|
87 |
mWlanQtUtils(new WlanQtUtils())
|
|
88 |
{
|
|
89 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_WLANSNIFFERENGINE_ENTRY);
|
|
90 |
|
|
91 |
// Subscribe for WLAN status change indications
|
|
92 |
bool connectStatus = connect(
|
|
93 |
mSettingsManager,
|
|
94 |
SIGNAL(valueChanged(XQSettingsKey, QVariant)),
|
|
95 |
this,
|
|
96 |
SLOT(updateSetting(XQSettingsKey, QVariant)));
|
|
97 |
Q_ASSERT(connectStatus);
|
|
98 |
mSettingsManager->startMonitoring(masterWlanKey);
|
|
99 |
mSettingsManager->startMonitoring(wlanForceKey);
|
|
100 |
|
|
101 |
// Connect WLAN Sniffer service signals
|
|
102 |
connectStatus = connect(
|
|
103 |
mService,
|
|
104 |
SIGNAL(toListView(QString)),
|
|
105 |
this,
|
|
106 |
SIGNAL(toListView(QString)));
|
|
107 |
Q_ASSERT(connectStatus == true);
|
|
108 |
connectStatus = connect(
|
|
109 |
mService,
|
|
110 |
SIGNAL(returnValueDelivered()),
|
|
111 |
this,
|
|
112 |
SIGNAL(exitTriggered()));
|
|
113 |
Q_ASSERT(connectStatus == true);
|
|
114 |
|
|
115 |
// Store WLAN Sniffer service embedded status
|
|
116 |
mEmbedded = XQServiceUtil::isEmbedded();
|
|
117 |
|
|
118 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_WLANSNIFFERENGINE_EXIT);
|
|
119 |
}
|
|
120 |
|
|
121 |
/*!
|
|
122 |
Destructor.
|
|
123 |
*/
|
|
124 |
|
|
125 |
WlanSnifferEngine::~WlanSnifferEngine()
|
|
126 |
{
|
|
127 |
OstTraceFunctionEntry0(DUP1_WLANSNIFFERENGINE_WLANSNIFFERENGINE_ENTRY);
|
|
128 |
OstTraceFunctionExit0(DUP1_WLANSNIFFERENGINE_WLANSNIFFERENGINE_EXIT);
|
|
129 |
}
|
|
130 |
|
|
131 |
/*!
|
|
132 |
Getter function for WLAN Qt Utilities instance owned by
|
|
133 |
this class. The whole WLAN Sniffer application uses the same
|
|
134 |
instance, and thus the reference is needed also in other classes.
|
|
135 |
|
|
136 |
@return WLAN Qt Utilities object.
|
|
137 |
*/
|
|
138 |
|
|
139 |
WlanQtUtils *WlanSnifferEngine::wlanQtUtils() const
|
|
140 |
{
|
|
141 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_WLANQTUTILS_ENTRY);
|
|
142 |
|
|
143 |
// The reference must never be null.
|
|
144 |
Q_ASSERT(mWlanQtUtils.data());
|
|
145 |
|
|
146 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_WLANQTUTILS_EXIT);
|
|
147 |
return mWlanQtUtils.data();
|
|
148 |
}
|
|
149 |
|
|
150 |
/*!
|
|
151 |
Getter for WLAN Sniffer service embedded property.
|
|
152 |
|
|
153 |
@return TRUE if WLAN Sniffer is used as an embedded service.
|
|
154 |
*/
|
|
155 |
|
|
156 |
bool WlanSnifferEngine::isEmbedded() const
|
|
157 |
{
|
|
158 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_ISEMBEDDED_ENTRY);
|
|
159 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_ISEMBEDDED_EXIT);
|
|
160 |
return mEmbedded;
|
|
161 |
}
|
|
162 |
|
|
163 |
/*!
|
|
164 |
Starts periodic WLAN Scanning.
|
|
165 |
It is allowed to call this function also when the scanning is already ON.
|
|
166 |
If so, the timer is not restarted but the scan period stays untouched.
|
|
167 |
*/
|
|
168 |
|
|
169 |
void WlanSnifferEngine::startWlanScanning()
|
|
170 |
{
|
|
171 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_STARTWLANSCANNING_ENTRY);
|
|
172 |
|
|
173 |
// A valid timer ID means scan is ON
|
|
174 |
if (mScanTimerId == 0) {
|
|
175 |
OstTrace0(
|
|
176 |
TRACE_NORMAL,
|
|
177 |
WLANSNIFFERENGINE_STARTWLANSCANNING,
|
|
178 |
"WlanSnifferEngine::startWlanScanning Periodic WLAN scanning starting");
|
|
179 |
|
|
180 |
// Connect signal forwarding
|
|
181 |
bool connectStatus = connect(
|
|
182 |
mWlanQtUtils.data(),
|
|
183 |
SIGNAL(wlanScanReady()),
|
|
184 |
this,
|
|
185 |
SIGNAL(wlanScanReady()));
|
|
186 |
Q_ASSERT(connectStatus);
|
|
187 |
|
|
188 |
// Start the first scan
|
|
189 |
mWlanQtUtils->scanWlans();
|
|
190 |
|
|
191 |
// Start timer for the next scan
|
|
192 |
mScanTimerId = startTimer(scanTimerInterval);
|
|
193 |
|
|
194 |
// The timer start must succeed
|
|
195 |
Q_ASSERT(mScanTimerId != 0);
|
|
196 |
}
|
|
197 |
|
|
198 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_STARTWLANSCANNING_EXIT);
|
|
199 |
}
|
|
200 |
|
|
201 |
/*!
|
|
202 |
Stops periodic WLAN Scanning.
|
|
203 |
It is allowed to call this function also when periodic scanning is OFF.
|
|
204 |
*/
|
|
205 |
|
|
206 |
void WlanSnifferEngine::stopWlanScanning()
|
|
207 |
{
|
|
208 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_STOPWLANSCANNING_ENTRY);
|
|
209 |
|
|
210 |
// A valid timer ID means scan is ON
|
|
211 |
if (mScanTimerId != 0) {
|
|
212 |
OstTrace0(
|
|
213 |
TRACE_NORMAL,
|
|
214 |
WLANSNIFFERENGINE_STOPWLANSCANNING,
|
|
215 |
"WlanSnifferEngine::stopWlanScanning Periodic WLAN scanning stopped");
|
|
216 |
|
|
217 |
// Disconnect signal forwarding
|
|
218 |
disconnect(
|
|
219 |
mWlanQtUtils.data(),
|
|
220 |
SIGNAL(wlanScanReady()),
|
|
221 |
this,
|
|
222 |
SIGNAL(wlanScanReady()));
|
|
223 |
|
|
224 |
killTimer(mScanTimerId);
|
|
225 |
mScanTimerId = 0;
|
|
226 |
}
|
|
227 |
|
|
228 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_STOPWLANSCANNING_EXIT);
|
|
229 |
}
|
|
230 |
|
|
231 |
/*!
|
|
232 |
Function for getting the master WLAN status.
|
|
233 |
|
|
234 |
@return Master WLAN status: true if enabled, otherwise false.
|
|
235 |
*/
|
|
236 |
|
|
237 |
bool WlanSnifferEngine::masterWlan() const
|
|
238 |
{
|
|
239 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_MASTERWLAN_ENTRY, this);
|
|
240 |
|
|
241 |
// Read WLAN ON/OFF setting from Cenrep
|
|
242 |
int wlanEnabled = mSettingsManager->readItemValue(masterWlanKey).toInt();
|
|
243 |
|
|
244 |
OstTrace1(
|
|
245 |
TRACE_NORMAL,
|
|
246 |
WLANSNIFFERENGINE_MASTERWLAN,
|
|
247 |
"WlanSnifferEngine::masterWlan;enabled=%d",
|
|
248 |
wlanEnabled);
|
|
249 |
|
|
250 |
OstTraceFunctionExit1(WLANSNIFFERENGINE_MASTERWLAN_EXIT, this);
|
|
251 |
return wlanEnabled ? true : false;
|
|
252 |
}
|
|
253 |
|
|
254 |
/*!
|
|
255 |
Function for switching the master WLAN status ON or OFF.
|
|
256 |
|
|
257 |
@param [in] enabled If set to true, WLAN is switched ON, and vice versa.
|
|
258 |
*/
|
|
259 |
|
|
260 |
void WlanSnifferEngine::setMasterWlan(bool enabled)
|
|
261 |
{
|
|
262 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_SETMASTERWLAN_ENTRY, this);
|
|
263 |
|
|
264 |
OstTraceExt1(
|
|
265 |
TRACE_NORMAL,
|
|
266 |
WLANSNIFFERENGINE_SETMASTERWLAN,
|
|
267 |
"WlanSnifferEngine::setMasterWlan;enabled=%hhu",
|
|
268 |
enabled);
|
|
269 |
|
|
270 |
// Store WLAN ON/OFF setting to Cenrep
|
|
271 |
int wlanEnabled = enabled ? 1 : 0;
|
|
272 |
bool writeStatus = mSettingsManager->writeItemValue(masterWlanKey, wlanEnabled);
|
|
273 |
Q_ASSERT(writeStatus);
|
|
274 |
|
|
275 |
OstTraceFunctionExit1(WLANSNIFFERENGINE_SETMASTERWLAN_EXIT, this);
|
|
276 |
}
|
|
277 |
|
|
278 |
/*!
|
|
279 |
Function for getting the force disable WLAN status.
|
|
280 |
|
|
281 |
@return forced WLAN status: true if disabled, otherwise false.
|
|
282 |
*/
|
|
283 |
|
|
284 |
bool WlanSnifferEngine::forceDisableWlan() const
|
|
285 |
{
|
|
286 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_FORCEDISABLEWLAN_ENTRY, this);
|
|
287 |
|
|
288 |
// Read force disable WLAN ON/OFF setting from Cenrep
|
|
289 |
int wlanDisabled = mSettingsManager->readItemValue(wlanForceKey).toInt();
|
|
290 |
|
|
291 |
OstTrace1(
|
|
292 |
TRACE_NORMAL,
|
|
293 |
WLANSNIFFERENGINE_FORCEDISABLEWLAN,
|
|
294 |
"WlanSnifferEngine::forceDisableWlan;wlanDisabled=%d",
|
|
295 |
wlanDisabled);
|
|
296 |
|
|
297 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_FORCEDISABLEWLAN_EXIT, this);
|
|
298 |
return wlanDisabled ? true : false;
|
|
299 |
}
|
|
300 |
|
|
301 |
/*!
|
|
302 |
Function for getting the offline mode status.
|
|
303 |
|
|
304 |
@return Offline mode status: true if offline, otherwise false.
|
|
305 |
*/
|
|
306 |
|
|
307 |
bool WlanSnifferEngine::offlineMode() const
|
|
308 |
{
|
|
309 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_OFFLINEMODE_ENTRY, this);
|
|
310 |
|
|
311 |
// Read offline mode setting from Cenrep
|
|
312 |
int systemState = mSettingsManager->readItemValue(offlineKey).toInt();
|
|
313 |
|
|
314 |
bool offline = false;
|
|
315 |
if (ESwStateNormalRfOff == systemState) {
|
|
316 |
offline = true;
|
|
317 |
}
|
|
318 |
|
|
319 |
OstTraceExt1(
|
|
320 |
TRACE_NORMAL,
|
|
321 |
WLANSNIFFERENGINE_OFFLINEMODE,
|
|
322 |
"WlanSnifferEngine::offlineMode;offline=%hhu",
|
|
323 |
offline);
|
|
324 |
|
|
325 |
OstTraceFunctionExit1(WLANSNIFFERENGINE_OFFLINEMODE_EXIT, this);
|
|
326 |
return offline;
|
|
327 |
}
|
|
328 |
|
|
329 |
/*!
|
|
330 |
Function for completing the running WLAN Sniffer service.
|
|
331 |
This function must only be ran if a WLAN Sniffer service is running.
|
|
332 |
*/
|
|
333 |
|
|
334 |
void WlanSnifferEngine::completeService()
|
|
335 |
{
|
|
336 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_COMPLETESERVICE_ENTRY);
|
|
337 |
|
|
338 |
mService->complete();
|
|
339 |
|
|
340 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_COMPLETESERVICE_EXIT);
|
|
341 |
}
|
|
342 |
|
|
343 |
/*!
|
|
344 |
This function (from QObject) handles timers. Initiates a new WLAN scan.
|
|
345 |
|
|
346 |
@param [in] event Timer event.
|
|
347 |
*/
|
|
348 |
|
|
349 |
void WlanSnifferEngine::timerEvent(QTimerEvent *event)
|
|
350 |
{
|
|
351 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_TIMEREVENT_ENTRY);
|
|
352 |
|
|
353 |
int timerId = event->timerId();
|
|
354 |
|
|
355 |
OstTrace1(
|
|
356 |
TRACE_NORMAL,
|
|
357 |
WLANSNIFFERENGINE_TIMEREVENT,
|
|
358 |
"WlanSnifferEngine::timerEvent;timerId=%d",
|
|
359 |
timerId);
|
|
360 |
|
|
361 |
// WLAN scan timer is the only used timer
|
|
362 |
Q_ASSERT(timerId == mScanTimerId);
|
|
363 |
|
|
364 |
// Request a new scan. Timer events come periodically.
|
|
365 |
mWlanQtUtils->scanWlans();
|
|
366 |
|
|
367 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_TIMEREVENT_EXIT);
|
|
368 |
}
|
|
369 |
|
|
370 |
/*!
|
|
371 |
Slot for updating settings.
|
|
372 |
|
|
373 |
@param [in] key The changed key setting.
|
|
374 |
@param [in] value The new value of the setting.
|
|
375 |
*/
|
|
376 |
|
|
377 |
void WlanSnifferEngine::updateSetting(
|
|
378 |
const XQSettingsKey &key,
|
|
379 |
const QVariant &value)
|
|
380 |
{
|
|
381 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_UPDATESETTING_ENTRY, this);
|
|
382 |
|
|
383 |
// Check that the key is WLAN ON/OFF, or wlanForceDisable since
|
|
384 |
// they are the only supported keys
|
|
385 |
Q_ASSERT(
|
|
386 |
key.target() == masterWlanKey.target() ||
|
|
387 |
key.target() == wlanForceKey.target());
|
|
388 |
Q_ASSERT(
|
|
389 |
key.uid() == masterWlanKey.uid() ||
|
|
390 |
key.uid() == wlanForceKey.uid());
|
|
391 |
Q_ASSERT(
|
|
392 |
key.key() == masterWlanKey.key() ||
|
|
393 |
key.key() == wlanForceKey.key());
|
|
394 |
|
|
395 |
bool ok;
|
|
396 |
bool boolean = value.toInt(&ok) ? true : false;
|
|
397 |
Q_ASSERT(ok);
|
|
398 |
|
|
399 |
// The updated key can be either the KWlanOnOff or the KWlanForceDisable
|
|
400 |
if (key.key() == wlanForceKey.key()) {
|
|
401 |
// Inform about WlanForceDisable status change
|
|
402 |
OstTraceExt1(
|
|
403 |
TRACE_NORMAL,
|
|
404 |
WLANSNIFFERENGINE_UPDATESETTING_WLANFORCEDISABLE,
|
|
405 |
"WlanSnifferEngine::emit forceWlanStatus;forcedWlanDisabled=%hhu",
|
|
406 |
boolean);
|
|
407 |
emit forceDisableWlanStatus(boolean);
|
|
408 |
} else {
|
|
409 |
// Inform about WLAN ON/OFF status change
|
|
410 |
OstTraceExt1(
|
|
411 |
TRACE_NORMAL,
|
|
412 |
WLANSNIFFERENGINE_UPDATESETTING_WLANONOFF,
|
|
413 |
"WlanSnifferEngine::emit masterWlanStatus;wlanEnabled=%hhu",
|
|
414 |
boolean);
|
|
415 |
emit masterWlanStatus(boolean);
|
|
416 |
}
|
|
417 |
|
|
418 |
OstTraceFunctionExit1(WLANSNIFFERENGINE_UPDATESETTING_EXIT, this);
|
|
419 |
}
|