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),
|
39
|
86 |
mScanEnabled(false),
|
31
|
87 |
mEmbedded(false),
|
|
88 |
mWlanQtUtils(new WlanQtUtils())
|
|
89 |
{
|
|
90 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_WLANSNIFFERENGINE_ENTRY);
|
|
91 |
|
|
92 |
// Subscribe for WLAN status change indications
|
|
93 |
bool connectStatus = connect(
|
|
94 |
mSettingsManager,
|
|
95 |
SIGNAL(valueChanged(XQSettingsKey, QVariant)),
|
|
96 |
this,
|
|
97 |
SLOT(updateSetting(XQSettingsKey, QVariant)));
|
|
98 |
Q_ASSERT(connectStatus);
|
|
99 |
mSettingsManager->startMonitoring(masterWlanKey);
|
|
100 |
mSettingsManager->startMonitoring(wlanForceKey);
|
|
101 |
|
|
102 |
// Connect WLAN Sniffer service signals
|
|
103 |
connectStatus = connect(
|
|
104 |
mService,
|
|
105 |
SIGNAL(toListView(QString)),
|
|
106 |
this,
|
|
107 |
SIGNAL(toListView(QString)));
|
|
108 |
Q_ASSERT(connectStatus == true);
|
|
109 |
connectStatus = connect(
|
|
110 |
mService,
|
|
111 |
SIGNAL(returnValueDelivered()),
|
|
112 |
this,
|
|
113 |
SIGNAL(exitTriggered()));
|
|
114 |
Q_ASSERT(connectStatus == true);
|
|
115 |
|
|
116 |
// Store WLAN Sniffer service embedded status
|
|
117 |
mEmbedded = XQServiceUtil::isEmbedded();
|
|
118 |
|
|
119 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_WLANSNIFFERENGINE_EXIT);
|
|
120 |
}
|
|
121 |
|
|
122 |
/*!
|
|
123 |
Destructor.
|
|
124 |
*/
|
|
125 |
|
|
126 |
WlanSnifferEngine::~WlanSnifferEngine()
|
|
127 |
{
|
|
128 |
OstTraceFunctionEntry0(DUP1_WLANSNIFFERENGINE_WLANSNIFFERENGINE_ENTRY);
|
|
129 |
OstTraceFunctionExit0(DUP1_WLANSNIFFERENGINE_WLANSNIFFERENGINE_EXIT);
|
|
130 |
}
|
|
131 |
|
|
132 |
/*!
|
|
133 |
Getter function for WLAN Qt Utilities instance owned by
|
|
134 |
this class. The whole WLAN Sniffer application uses the same
|
|
135 |
instance, and thus the reference is needed also in other classes.
|
|
136 |
|
|
137 |
@return WLAN Qt Utilities object.
|
|
138 |
*/
|
|
139 |
|
|
140 |
WlanQtUtils *WlanSnifferEngine::wlanQtUtils() const
|
|
141 |
{
|
|
142 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_WLANQTUTILS_ENTRY);
|
|
143 |
|
|
144 |
// The reference must never be null.
|
|
145 |
Q_ASSERT(mWlanQtUtils.data());
|
|
146 |
|
|
147 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_WLANQTUTILS_EXIT);
|
|
148 |
return mWlanQtUtils.data();
|
|
149 |
}
|
|
150 |
|
|
151 |
/*!
|
|
152 |
Getter for WLAN Sniffer service embedded property.
|
|
153 |
|
|
154 |
@return TRUE if WLAN Sniffer is used as an embedded service.
|
|
155 |
*/
|
|
156 |
|
|
157 |
bool WlanSnifferEngine::isEmbedded() const
|
|
158 |
{
|
|
159 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_ISEMBEDDED_ENTRY);
|
|
160 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_ISEMBEDDED_EXIT);
|
|
161 |
return mEmbedded;
|
|
162 |
}
|
|
163 |
|
|
164 |
/*!
|
|
165 |
Starts periodic WLAN Scanning.
|
|
166 |
It is allowed to call this function also when the scanning is already ON.
|
|
167 |
If so, the timer is not restarted but the scan period stays untouched.
|
|
168 |
*/
|
|
169 |
|
|
170 |
void WlanSnifferEngine::startWlanScanning()
|
|
171 |
{
|
|
172 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_STARTWLANSCANNING_ENTRY);
|
|
173 |
|
39
|
174 |
if (!mScanEnabled) {
|
31
|
175 |
OstTrace0(
|
|
176 |
TRACE_NORMAL,
|
|
177 |
WLANSNIFFERENGINE_STARTWLANSCANNING,
|
|
178 |
"WlanSnifferEngine::startWlanScanning Periodic WLAN scanning starting");
|
|
179 |
|
39
|
180 |
mScanEnabled = true;
|
|
181 |
// Connect response signal
|
31
|
182 |
bool connectStatus = connect(
|
|
183 |
mWlanQtUtils.data(),
|
39
|
184 |
SIGNAL(wlanScanReady(int)),
|
31
|
185 |
this,
|
39
|
186 |
SLOT(handleWlanScanReady(int)));
|
31
|
187 |
Q_ASSERT(connectStatus);
|
|
188 |
|
39
|
189 |
// Start the first scan. Scan timer is started when scan result
|
|
190 |
// signal is received.
|
31
|
191 |
mWlanQtUtils->scanWlans();
|
|
192 |
}
|
|
193 |
|
|
194 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_STARTWLANSCANNING_EXIT);
|
|
195 |
}
|
|
196 |
|
|
197 |
/*!
|
|
198 |
Stops periodic WLAN Scanning.
|
|
199 |
It is allowed to call this function also when periodic scanning is OFF.
|
|
200 |
*/
|
|
201 |
|
|
202 |
void WlanSnifferEngine::stopWlanScanning()
|
|
203 |
{
|
|
204 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_STOPWLANSCANNING_ENTRY);
|
|
205 |
|
39
|
206 |
if (mScanEnabled) {
|
31
|
207 |
OstTrace0(
|
|
208 |
TRACE_NORMAL,
|
|
209 |
WLANSNIFFERENGINE_STOPWLANSCANNING,
|
|
210 |
"WlanSnifferEngine::stopWlanScanning Periodic WLAN scanning stopped");
|
39
|
211 |
|
|
212 |
mScanEnabled = false;
|
|
213 |
// Disconnect response signal
|
31
|
214 |
disconnect(
|
|
215 |
mWlanQtUtils.data(),
|
39
|
216 |
SIGNAL(wlanScanReady(int)),
|
31
|
217 |
this,
|
39
|
218 |
SLOT(handleWlanScanReady(int)));
|
53
|
219 |
|
|
220 |
// Stop the scan
|
|
221 |
mWlanQtUtils->stopWlanScan();
|
|
222 |
|
|
223 |
// Stop periodic scan timer
|
39
|
224 |
if (mScanTimerId != 0) {
|
|
225 |
killTimer(mScanTimerId);
|
|
226 |
mScanTimerId = 0;
|
|
227 |
}
|
31
|
228 |
}
|
|
229 |
|
|
230 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_STOPWLANSCANNING_EXIT);
|
|
231 |
}
|
|
232 |
|
|
233 |
/*!
|
|
234 |
Function for getting the master WLAN status.
|
|
235 |
|
|
236 |
@return Master WLAN status: true if enabled, otherwise false.
|
|
237 |
*/
|
|
238 |
|
|
239 |
bool WlanSnifferEngine::masterWlan() const
|
|
240 |
{
|
|
241 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_MASTERWLAN_ENTRY, this);
|
|
242 |
|
|
243 |
// Read WLAN ON/OFF setting from Cenrep
|
|
244 |
int wlanEnabled = mSettingsManager->readItemValue(masterWlanKey).toInt();
|
|
245 |
|
|
246 |
OstTrace1(
|
|
247 |
TRACE_NORMAL,
|
|
248 |
WLANSNIFFERENGINE_MASTERWLAN,
|
|
249 |
"WlanSnifferEngine::masterWlan;enabled=%d",
|
|
250 |
wlanEnabled);
|
|
251 |
|
|
252 |
OstTraceFunctionExit1(WLANSNIFFERENGINE_MASTERWLAN_EXIT, this);
|
|
253 |
return wlanEnabled ? true : false;
|
|
254 |
}
|
|
255 |
|
|
256 |
/*!
|
|
257 |
Function for switching the master WLAN status ON or OFF.
|
|
258 |
|
|
259 |
@param [in] enabled If set to true, WLAN is switched ON, and vice versa.
|
|
260 |
*/
|
|
261 |
|
|
262 |
void WlanSnifferEngine::setMasterWlan(bool enabled)
|
|
263 |
{
|
|
264 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_SETMASTERWLAN_ENTRY, this);
|
|
265 |
|
|
266 |
OstTraceExt1(
|
|
267 |
TRACE_NORMAL,
|
|
268 |
WLANSNIFFERENGINE_SETMASTERWLAN,
|
|
269 |
"WlanSnifferEngine::setMasterWlan;enabled=%hhu",
|
|
270 |
enabled);
|
|
271 |
|
|
272 |
// Store WLAN ON/OFF setting to Cenrep
|
|
273 |
int wlanEnabled = enabled ? 1 : 0;
|
|
274 |
bool writeStatus = mSettingsManager->writeItemValue(masterWlanKey, wlanEnabled);
|
|
275 |
Q_ASSERT(writeStatus);
|
|
276 |
|
|
277 |
OstTraceFunctionExit1(WLANSNIFFERENGINE_SETMASTERWLAN_EXIT, this);
|
|
278 |
}
|
|
279 |
|
|
280 |
/*!
|
|
281 |
Function for getting the force disable WLAN status.
|
|
282 |
|
|
283 |
@return forced WLAN status: true if disabled, otherwise false.
|
|
284 |
*/
|
|
285 |
|
|
286 |
bool WlanSnifferEngine::forceDisableWlan() const
|
|
287 |
{
|
|
288 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_FORCEDISABLEWLAN_ENTRY, this);
|
|
289 |
|
|
290 |
// Read force disable WLAN ON/OFF setting from Cenrep
|
|
291 |
int wlanDisabled = mSettingsManager->readItemValue(wlanForceKey).toInt();
|
|
292 |
|
|
293 |
OstTrace1(
|
|
294 |
TRACE_NORMAL,
|
|
295 |
WLANSNIFFERENGINE_FORCEDISABLEWLAN,
|
|
296 |
"WlanSnifferEngine::forceDisableWlan;wlanDisabled=%d",
|
|
297 |
wlanDisabled);
|
|
298 |
|
|
299 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_FORCEDISABLEWLAN_EXIT, this);
|
|
300 |
return wlanDisabled ? true : false;
|
|
301 |
}
|
|
302 |
|
|
303 |
/*!
|
|
304 |
Function for getting the offline mode status.
|
|
305 |
|
|
306 |
@return Offline mode status: true if offline, otherwise false.
|
|
307 |
*/
|
|
308 |
|
|
309 |
bool WlanSnifferEngine::offlineMode() const
|
|
310 |
{
|
|
311 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_OFFLINEMODE_ENTRY, this);
|
|
312 |
|
|
313 |
// Read offline mode setting from Cenrep
|
|
314 |
int systemState = mSettingsManager->readItemValue(offlineKey).toInt();
|
|
315 |
|
|
316 |
bool offline = false;
|
|
317 |
if (ESwStateNormalRfOff == systemState) {
|
|
318 |
offline = true;
|
|
319 |
}
|
|
320 |
|
|
321 |
OstTraceExt1(
|
|
322 |
TRACE_NORMAL,
|
|
323 |
WLANSNIFFERENGINE_OFFLINEMODE,
|
|
324 |
"WlanSnifferEngine::offlineMode;offline=%hhu",
|
|
325 |
offline);
|
|
326 |
|
|
327 |
OstTraceFunctionExit1(WLANSNIFFERENGINE_OFFLINEMODE_EXIT, this);
|
|
328 |
return offline;
|
|
329 |
}
|
|
330 |
|
|
331 |
/*!
|
|
332 |
Function for completing the running WLAN Sniffer service.
|
|
333 |
This function must only be ran if a WLAN Sniffer service is running.
|
|
334 |
*/
|
|
335 |
|
|
336 |
void WlanSnifferEngine::completeService()
|
|
337 |
{
|
|
338 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_COMPLETESERVICE_ENTRY);
|
|
339 |
|
|
340 |
mService->complete();
|
|
341 |
|
|
342 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_COMPLETESERVICE_EXIT);
|
|
343 |
}
|
|
344 |
|
|
345 |
/*!
|
|
346 |
This function (from QObject) handles timers. Initiates a new WLAN scan.
|
|
347 |
|
|
348 |
@param [in] event Timer event.
|
|
349 |
*/
|
|
350 |
|
|
351 |
void WlanSnifferEngine::timerEvent(QTimerEvent *event)
|
|
352 |
{
|
|
353 |
OstTraceFunctionEntry0(WLANSNIFFERENGINE_TIMEREVENT_ENTRY);
|
|
354 |
|
|
355 |
int timerId = event->timerId();
|
|
356 |
|
|
357 |
OstTrace1(
|
|
358 |
TRACE_NORMAL,
|
|
359 |
WLANSNIFFERENGINE_TIMEREVENT,
|
|
360 |
"WlanSnifferEngine::timerEvent;timerId=%d",
|
|
361 |
timerId);
|
|
362 |
|
|
363 |
// WLAN scan timer is the only used timer
|
|
364 |
Q_ASSERT(timerId == mScanTimerId);
|
|
365 |
|
|
366 |
// Request a new scan. Timer events come periodically.
|
|
367 |
mWlanQtUtils->scanWlans();
|
|
368 |
|
|
369 |
OstTraceFunctionExit0(WLANSNIFFERENGINE_TIMEREVENT_EXIT);
|
|
370 |
}
|
|
371 |
|
|
372 |
/*!
|
|
373 |
Slot for updating settings.
|
|
374 |
|
|
375 |
@param [in] key The changed key setting.
|
|
376 |
@param [in] value The new value of the setting.
|
|
377 |
*/
|
|
378 |
|
|
379 |
void WlanSnifferEngine::updateSetting(
|
|
380 |
const XQSettingsKey &key,
|
|
381 |
const QVariant &value)
|
|
382 |
{
|
|
383 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_UPDATESETTING_ENTRY, this);
|
|
384 |
|
|
385 |
// Check that the key is WLAN ON/OFF, or wlanForceDisable since
|
|
386 |
// they are the only supported keys
|
|
387 |
Q_ASSERT(
|
|
388 |
key.target() == masterWlanKey.target() ||
|
|
389 |
key.target() == wlanForceKey.target());
|
|
390 |
Q_ASSERT(
|
|
391 |
key.uid() == masterWlanKey.uid() ||
|
|
392 |
key.uid() == wlanForceKey.uid());
|
|
393 |
Q_ASSERT(
|
|
394 |
key.key() == masterWlanKey.key() ||
|
|
395 |
key.key() == wlanForceKey.key());
|
|
396 |
|
|
397 |
bool ok;
|
|
398 |
bool boolean = value.toInt(&ok) ? true : false;
|
|
399 |
Q_ASSERT(ok);
|
|
400 |
|
|
401 |
// The updated key can be either the KWlanOnOff or the KWlanForceDisable
|
|
402 |
if (key.key() == wlanForceKey.key()) {
|
|
403 |
// Inform about WlanForceDisable status change
|
|
404 |
OstTraceExt1(
|
|
405 |
TRACE_NORMAL,
|
|
406 |
WLANSNIFFERENGINE_UPDATESETTING_WLANFORCEDISABLE,
|
|
407 |
"WlanSnifferEngine::emit forceWlanStatus;forcedWlanDisabled=%hhu",
|
|
408 |
boolean);
|
|
409 |
emit forceDisableWlanStatus(boolean);
|
|
410 |
} else {
|
|
411 |
// Inform about WLAN ON/OFF status change
|
|
412 |
OstTraceExt1(
|
|
413 |
TRACE_NORMAL,
|
|
414 |
WLANSNIFFERENGINE_UPDATESETTING_WLANONOFF,
|
|
415 |
"WlanSnifferEngine::emit masterWlanStatus;wlanEnabled=%hhu",
|
|
416 |
boolean);
|
|
417 |
emit masterWlanStatus(boolean);
|
|
418 |
}
|
|
419 |
|
|
420 |
OstTraceFunctionExit1(WLANSNIFFERENGINE_UPDATESETTING_EXIT, this);
|
|
421 |
}
|
39
|
422 |
|
|
423 |
/*!
|
|
424 |
Slot for handling Wlan scan result.
|
|
425 |
|
|
426 |
@param [in] status Scan status code.
|
|
427 |
*/
|
|
428 |
|
|
429 |
void WlanSnifferEngine::handleWlanScanReady(int status)
|
|
430 |
{
|
|
431 |
OstTraceFunctionEntry1(WLANSNIFFERENGINE_HANDLEWLANSCANREADY_ENTRY, this);
|
|
432 |
|
|
433 |
OstTrace1(
|
|
434 |
TRACE_NORMAL,
|
|
435 |
WLANSNIFFERENGINE_HANDLEWLANSCANREADY,
|
|
436 |
"WlanSnifferEngine::handleWlanScanReady;status=%d",
|
|
437 |
status);
|
|
438 |
|
|
439 |
// Forward result signal only, if there was no error
|
|
440 |
if (status == WlanQtUtils::ScanStatusOk) {
|
|
441 |
emit wlanScanReady();
|
|
442 |
}
|
|
443 |
|
|
444 |
// Start timer for the next scan, if not running already
|
|
445 |
if (mScanTimerId == 0) {
|
|
446 |
mScanTimerId = startTimer(scanTimerInterval);
|
|
447 |
// The timer start must succeed
|
|
448 |
Q_ASSERT(mScanTimerId != 0);
|
|
449 |
}
|
|
450 |
|
|
451 |
OstTraceFunctionExit1(WLANSNIFFERENGINE_HANDLEWLANSCANREADY_EXIT, this);
|
|
452 |
}
|