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