wlanutilities/wlanqtutilities/base/src/wlanqtutils_p.cpp
changeset 31 e8f4211554fb
parent 19 10810c91db26
child 39 7b3e49e4608a
equal deleted inserted replaced
30:ab513c8439db 31:e8f4211554fb
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2009-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    10 * Nokia Corporation - initial contribution.
    10 * Nokia Corporation - initial contribution.
    11 *
    11 *
    12 * Contributors:
    12 * Contributors:
    13 *
    13 *
    14 * Description:
    14 * Description:
    15 */
    15 * WLAN Qt Utilities private implementation.
    16 
    16 */
    17 #include "wlanqtutilswlanap.h"
    17 
    18 #include "wlanqtutilswlaniap.h"
    18 // System includes
    19 #include "wlanqtutilsactiveconn.h"
    19 
    20 #include "wlanqtutilscmmwrapper.h"
    20 #include <QSharedPointer>
       
    21 
       
    22 // User includes
       
    23 
       
    24 #include "wlanqtutilsap.h"
       
    25 #include "wlanqtutilsiap.h"
       
    26 #include "wlanqtutilsconnection.h"
       
    27 #include "wlanqtutilsiapsettings.h"
    21 #include "wlanqtutilsconmonwrapper.h"
    28 #include "wlanqtutilsconmonwrapper.h"
    22 #include "wlanqtutilsesockwrapper.h"
    29 #include "wlanqtutilsesockwrapper.h"
    23 #include "wlanqtutilsconntestwrapper.h"
    30 #include "wlanqtutilsconntestwrapper.h"
    24 
    31 
    25 #include "wlanqtutils.h"
    32 #include "wlanqtutils.h"
    26 #include "wlanqtutils_p.h"
    33 #include "wlanqtutils_p.h"
    27 
    34 
    28 #ifdef WLANQTUTILS_NO_OST_TRACES_FLAG
       
    29 #include <opensystemtrace.h>
       
    30 #else
       
    31 #include "OstTraceDefinitions.h"
    35 #include "OstTraceDefinitions.h"
    32 #endif
       
    33 #ifdef OST_TRACE_COMPILER_IN_USE
    36 #ifdef OST_TRACE_COMPILER_IN_USE
    34 #include "wlanqtutils_pTraces.h"
    37 #include "wlanqtutils_pTraces.h"
    35 #endif
    38 #endif
    36 
    39 
    37 
    40 /*!
    38 WlanQtUtilsPrivate::WlanQtUtilsPrivate(WlanQtUtils *publicPtr) :
    41     \class WlanQtUtilsPrivate
    39     q_ptr(publicPtr),
    42     \brief Private implementation class for WLAN Qt Utilities.
    40     wlanScanList_(),
    43 
    41     wlanIapList_(),
    44     The private interface functions are identical to those in WlanQtUtils
    42     toBeTestedIapId_(WlanQtUtilsInvalidIapId),
    45     class, so refer to that for descriptions. Other functions contain
    43     connectingIapId_(WlanQtUtilsInvalidIapId),
    46     implementation documentation.
    44     activeConnection_(NULL)
    47 */
    45 {
    48 
    46     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_WLANQTUTILSPRIVATE_ENTRY, this );
    49 
    47     
    50 // External function prototypes
    48     // Let's allocate memory for wrapper objects.
    51 
    49     // Engine is set as a parent for wrapper objects.
    52 // Local constants
    50     cmmWrapper_ = new CmmWrapper(this);
    53 
    51     conMonWrapper_ = new ConMonWrapper(this);
    54 // ======== LOCAL FUNCTIONS ========
    52     esockWrapper_ = new EsockWrapper(this);
    55 
    53     connTestWrapper_ = new ConnTestWrapper(this);
    56 // ======== MEMBER FUNCTIONS ========
    54     
    57 
       
    58 /*!
       
    59     Constructor.
       
    60 */
       
    61 
       
    62 WlanQtUtilsPrivate::WlanQtUtilsPrivate(WlanQtUtils *q_ptr) :
       
    63     q_ptr(q_ptr),
       
    64     mSettings(new WlanQtUtilsIapSettings(this)),
       
    65     mConMonWrapper(new WlanQtUtilsConMonWrapper(this)),
       
    66     mEsockWrapper(new WlanQtUtilsEsockWrapper(this)),
       
    67     mConnTestWrapper(new ConnTestWrapper(this)),
       
    68     mWlanScanList(),
       
    69     mToBeTestedIapId(WlanQtUtils::IapIdNone), 
       
    70     mConnectingIapId(WlanQtUtils::IapIdNone),
       
    71     mConnection()
       
    72 {
       
    73     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_WLANQTUTILSPRIVATE_ENTRY, this);
       
    74 
    55     // Make all connections.
    75     // Make all connections.
    56     // Todo: having these as signals from the wrappers doesn't bring much benefit
    76     bool connectStatus = connect(
    57     // -> could be optimized as normal callbacks
    77         mConMonWrapper, 
    58     connect(
    78         SIGNAL(availableWlanApsFromWrapper(
    59         conMonWrapper_,
    79             QList< QSharedPointer<WlanQtUtilsAp> >&)), 
    60         SIGNAL(availableWlanApsFromWrapper(QList<WlanQtUtilsWlanAp *>&)),
    80         this, 
    61         this,
    81         SLOT(updateAvailableWlanAps(
    62         SLOT(updateAvailableWlanAps(QList<WlanQtUtilsWlanAp *>&)));
    82             QList< QSharedPointer<WlanQtUtilsAp> >&)));
    63 
    83     Q_ASSERT(connectStatus);
    64     connect(
    84 
    65         esockWrapper_,
    85     connectStatus = connect(
    66         SIGNAL(connectionStatusFromWrapper(bool)),
    86         mEsockWrapper, 
       
    87         SIGNAL(connectionStatusFromWrapper(bool)), 
    67         this,
    88         this,
    68         SLOT(updateConnectionStatus(bool)));
    89         SLOT(updateConnectionStatus(bool)));
    69 
    90     Q_ASSERT(connectStatus);
    70     connect(
    91 
    71         connTestWrapper_,
    92     connectStatus = connect(
    72         SIGNAL(connectivityTestResult(bool)),
    93         mConnTestWrapper, 
       
    94         SIGNAL(connectivityTestResult(bool)), 
    73         this,
    95         this,
    74         SLOT(updateConnectivityTestResult(bool)));
    96         SLOT(updateConnectivityTestResult(bool)));
    75 
    97     Q_ASSERT(connectStatus);
    76     connect(
    98 
    77         conMonWrapper_,
    99     connectStatus = connect(
    78         SIGNAL(connCreatedEventFromWrapper(uint)),
   100         mConMonWrapper, 
       
   101         SIGNAL(connCreatedEventFromWrapper(uint)), 
    79         this,
   102         this,
    80         SLOT(addActiveConnection(uint)));
   103         SLOT(addActiveConnection(uint)));
    81 
   104     Q_ASSERT(connectStatus);
    82     connect(
   105 
    83         conMonWrapper_,
   106     connectStatus = connect(
    84         SIGNAL(connDeletedEventFromWrapper(uint)),
   107         mConMonWrapper, 
       
   108         SIGNAL(connDeletedEventFromWrapper(uint)), 
    85         this,
   109         this,
    86         SLOT(removeActiveConnection(uint)));
   110         SLOT(removeActiveConnection(uint)));
    87     
   111     Q_ASSERT(connectStatus);
    88     connect(
   112 
    89         conMonWrapper_,
   113     connectStatus = connect(
    90         SIGNAL(connStatusEventFromWrapper(uint, WlanQtUtilsConnectionStatus)),
   114         mConMonWrapper, 
    91         this,
   115         SIGNAL(connStatusEventFromWrapper(uint, WlanQtUtils::ConnStatus)),
    92         SLOT(updateActiveConnection(uint, WlanQtUtilsConnectionStatus)));
   116         this, 
    93 
   117         SLOT(updateActiveConnection(uint, WlanQtUtils::ConnStatus)));
    94     // Fetch the initial IAP configuration
   118     Q_ASSERT(connectStatus);
    95     fetchIaps();
   119 
    96 
   120     // Retrieve initial status of active connections
    97     // Retrieve initial status of active connections and update IAPs, if needed.
   121     mConnection = QSharedPointer<WlanQtUtilsConnection>(
    98     activeConnection_ = conMonWrapper_->activeConnection();
   122         mConMonWrapper->activeConnection());
    99     if (activeConnection_ != NULL) {
   123 
   100         updateIapConnectionStatuses(activeConnection_->iapId(), activeConnection_->connectionStatus());
   124     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_WLANQTUTILSPRIVATE_EXIT, this);
   101     }
   125 }
   102 
   126 
   103     // TODO: error handling
   127 /*!
   104 
   128     Destructor. 
   105     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_WLANQTUTILSPRIVATE_EXIT, this );
   129 */
   106 }
       
   107 
   130 
   108 WlanQtUtilsPrivate::~WlanQtUtilsPrivate()
   131 WlanQtUtilsPrivate::~WlanQtUtilsPrivate()
   109 {
   132 {
   110     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_WLANQTUTILSPRIVATEDESTR_ENTRY, this );
   133     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_WLANQTUTILSPRIVATEDESTR_ENTRY, this);
   111     
   134     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_WLANQTUTILSPRIVATEDESTR_EXIT, this);
   112     // Delete WLAN scan list
   135 }
   113     for (int i = 0; i < wlanScanList_.count(); i++) {
   136 
   114         delete wlanScanList_[i];
   137 /*!
   115     }
   138    See WlanQtUtils::scanWlans().
   116     wlanScanList_.clear();
   139 */
   117     
   140 
   118     delete activeConnection_;
   141 void WlanQtUtilsPrivate::scanWlans()
   119     
   142 {
   120     delete cmmWrapper_;
   143     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_SCANWLANS_ENTRY, this);
   121     delete conMonWrapper_;
   144 
   122     delete esockWrapper_;
   145     // Just forward the request to wrapper, which triggers a single WLAN scan
   123     delete connTestWrapper_;
   146     mConMonWrapper->scanAvailableWlanAPs();
   124 
   147 
   125     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_WLANQTUTILSPRIVATEDESTR_EXIT, this );
   148     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_SCANWLANS_EXIT, this);
   126 }
   149 }
   127 
   150 
   128 void WlanQtUtilsPrivate::availableWlanAps(
   151 /*!
   129     QList<WlanQtUtilsWlanIap *> &wlanIapList,
   152    See WlanQtUtils::scanWlanAps().
   130     QList<WlanQtUtilsWlanAp *> &wlanApList)
   153 */
   131 {
   154 
   132     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_AVAILABLEWLANAPS_ENTRY, this );
   155 void WlanQtUtilsPrivate::scanWlanAps()
   133     
   156 {
       
   157     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_SCANWLANAPS_ENTRY, this);
       
   158     
       
   159     emit q_ptr->wlanScanApReady();
       
   160     // TODO: implement me (wizard requires this)
       
   161 
       
   162     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_SCANWLANAPS_EXIT, this);
       
   163 }
       
   164 
       
   165 /*!
       
   166    See WlanQtUtils::scanWlanDirect().
       
   167 */
       
   168 
       
   169 void WlanQtUtilsPrivate::scanWlanDirect(const QString &ssid)
       
   170 {
       
   171     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_SCANWLANDIRECT_ENTRY, this);
       
   172     
       
   173     Q_UNUSED(ssid);
       
   174     
       
   175     emit q_ptr->wlanScanDirectReady();
       
   176     // TODO: implement me (wizard requires this)
       
   177     
       
   178     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_SCANWLANDIRECT_EXIT, this);
       
   179 }
       
   180 
       
   181 /*!
       
   182    See WlanQtUtils::stopWlanScan().
       
   183 */
       
   184 
       
   185 void WlanQtUtilsPrivate::stopWlanScan()
       
   186 {
       
   187     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_STOPWLANSCAN_ENTRY, this);
       
   188     
       
   189     mConMonWrapper->stopScan();
       
   190     
       
   191     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_STOPWLANSCAN_EXIT, this);
       
   192 }
       
   193 
       
   194 /*!
       
   195    See WlanQtUtils::availableWlans().
       
   196 */
       
   197 
       
   198 void WlanQtUtilsPrivate::availableWlans(
       
   199     QList< QSharedPointer<WlanQtUtilsIap> > &wlanIapList,
       
   200     QList< QSharedPointer<WlanQtUtilsAp> > &wlanApList) const
       
   201 {
       
   202     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_AVAILABLEWLAN_ENTRY, this);
       
   203 
   134     wlanIapList.clear();
   204     wlanIapList.clear();
   135     wlanApList.clear();
   205     wlanApList.clear();
   136     
   206 
   137     // Add possible connected or connecting IAP as the first item in the list
   207     // Read the list of configured IAPs
   138     int activeIapId = WlanQtUtilsInvalidIapId;
   208     QList<QSharedPointer<WlanQtUtilsIap> > configuredIapList;
   139     if (activeConnection_ != NULL) {
   209     mSettings->fetchIaps(configuredIapList);
   140         activeIapId = activeConnection_->iapId();
   210 
   141     } else if (connectingIapId_ != WlanQtUtilsInvalidIapId) {
       
   142         activeIapId = connectingIapId_;
       
   143     }
       
   144     if (wlanIapList_.contains(activeIapId)) {
       
   145         wlanIapList_[activeIapId]->setSignalStrength(WlanQtUtilsWlanSignalStrengthMax);
       
   146         wlanIapList_[activeIapId]->setConnectionStatus(WlanQtUtilsConnectionStatusConnected);
       
   147         wlanIapList.append(wlanIapList_[activeIapId]);
       
   148     }
       
   149     
       
   150     // Todo: IAPs with same SSID and security mode? probably we want to show only one of them?
       
   151     
       
   152     // Match IAPs against WLAN scan results
   211     // Match IAPs against WLAN scan results
   153     foreach (WlanQtUtilsWlanIap *iap, wlanIapList_) {
   212     foreach (QSharedPointer<WlanQtUtilsIap> iap, configuredIapList) {
   154         foreach (WlanQtUtilsWlanAp *scanAp, wlanScanList_) {
   213         foreach (QSharedPointer<WlanQtUtilsAp> scanAp, mWlanScanList) {
   155             // Todo: security mode check
   214             if (WlanQtUtilsAp::compare(iap.data(), scanAp.data()) == true) {
   156             if (iap->ssid() == scanAp->ssid()) {
   215                 // IAP found, add it to caller's list of known IAPs
   157                 // IAP found, add it to caller's list of known IAPs (signal strength needs to be
   216                 // (signal strength needs to be updated manually since
   158                 // updated manually since the IAP in our list does not have that information yet)
   217                 // the IAP in our list does not have that information yet)
   159                 iap->setSignalStrength(scanAp->signalStrength());
   218                 iap->setValue(
   160                 if (iap->id() != activeIapId) {
   219                     WlanQtUtilsAp::ConfIdSignalStrength,
   161                     wlanIapList.append(iap);
   220                     scanAp->value(WlanQtUtilsAp::ConfIdSignalStrength));
   162                 } // else: connected IAP, added as the first item in the list already
   221                 wlanIapList.append(iap);
   163                 break;
   222                 break;
   164             }
   223             }
   165         }
   224         }
   166     }
   225     }
   167 
   226 
   168     // Go through the scan results to find unknown APs
   227     // Go through the scan results to find unknown APs
   169     for (int i = 0; i < wlanScanList_.count(); i++) {
   228     for (int i = 0; i < mWlanScanList.count(); i++) {
   170         // Skip networks with empty SSID (hidden networks are handled by UI currently)
   229         // Check whether an IAP with these parameters exists (in which
   171         if (wlanScanList_[i]->ssid().isEmpty() == FALSE) {
   230         // case this network is already added as an IAP in the loop above)
   172             // Check whether an IAP with these parameters exists in any SNAP (in which case this
   231         if (!wlanIapExists(configuredIapList, mWlanScanList[i].data())) {
   173             // network should not be shown as available in this SNAP)
   232             // No IAP found in, copy the AP to caller's list of
   174             if (wlanIapExists(wlanScanList_[i]->ssid(), wlanScanList_[i]->securityMode()) == false) {
   233             // unknown APs
   175                 // No IAP found in any SNAP, copy the AP to caller's list of unknown APs
   234             wlanApList.append(mWlanScanList[i]);
   176                 wlanApList.append(wlanScanList_[i]);
   235         }
   177             }
   236     }
   178         }
   237 
   179     }
   238     traceIapsAndAps(wlanIapList, wlanApList);
   180     
   239 
   181     // Sort APs by their SSIDs.
   240     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_AVAILABLEWLAN_EXIT, this);
   182     QMap<QString, WlanQtUtilsWlanAp *> wlanApMap;
   241 }
   183     // Loop the AP list copying the keys (lower case SSID) and elements
   242 
   184     // into the map.
   243 /*!
   185     for (int i = 0; i < wlanApList.count(); i++ ) {
   244    See WlanQtUtils::availableWlanAps().
   186         wlanApMap.insertMulti(wlanApList[i]->ssid().toLower(), wlanApList[i]);
   245 */
   187     }
   246 
   188     wlanApList = wlanApMap.values();
   247 void WlanQtUtilsPrivate::availableWlanAps(
   189 
   248     QList< QSharedPointer<WlanQtUtilsAp> > &wlanApList) const
   190     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_AVAILABLEWLANAPS_EXIT, this );
   249 {
   191 }
   250     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_AVAILABLEWLANAPS_ENTRY, this);
   192 
   251     
   193 int WlanQtUtilsPrivate::createWlanIap(const WlanQtUtilsWlanAp *wlanAp)
   252     Q_UNUSED(wlanApList);
   194 {
   253     // TODO: implement me (wizard requires this)
   195     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_CREATEWLANIAP_ENTRY, this );
   254     
   196     
   255     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_AVAILABLEWLANAPS_EXIT, this);
   197     // Create the new IAP. Store its ID, because we need to run ICT for it later
   256 }
   198     WlanQtUtilsWlanIap *newIap = cmmWrapper_->createWlanIap(wlanAp);
   257 
   199     toBeTestedIapId_ = newIap->id();
   258 /*!
   200     wlanIapList_.insert(newIap->id(), newIap);
   259    See WlanQtUtils::createIap().
   201     
   260 */
       
   261 
       
   262 int WlanQtUtilsPrivate::createIap(const WlanQtUtilsAp *wlanAp)
       
   263 {
       
   264     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_CREATEIAP_ENTRY, this);
       
   265 
       
   266     // Create the new IAP and return its ID
       
   267     int newIapId = mSettings->createIap(wlanAp);
       
   268 
   202     OstTrace1(
   269     OstTrace1(
   203         TRACE_API,
   270         TRACE_BORDER,
   204         WLANQTUTILSPRIVATE_CREATEWLANIAP,
   271         WLANQTUTILSPRIVATE_CREATEIAP,
   205         "WlanQtUtilsPrivate::createWlanIap;New IAP ID=%d", toBeTestedIapId_ );
   272         "WlanQtUtilsPrivate::createIap;New IAP ID=%d",
   206     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_CREATEWLANIAP_EXIT, this );
   273         newIapId);
   207     return toBeTestedIapId_;
   274         
   208 }
   275     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_CREATEIAP_EXIT, this);
   209 
   276     return newIapId;
   210 void WlanQtUtilsPrivate::connectIap(int iapId)
   277 }
   211 {
   278 
   212     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_CONNECTIAP_ENTRY, this );
   279 /*!
   213     OstTrace1( TRACE_API, WLANQTUTILSPRIVATE_CONNECTIAP, "WlanQtUtilsPrivate::connectIap;IAP ID=%d", iapId );
   280    See WlanQtUtils::updateIap().
   214     
   281 */
   215     Q_ASSERT(activeConnection_ == NULL);
   282 
   216     connectingIapId_ = iapId;
   283 bool WlanQtUtilsPrivate::updateIap(int iapId, const WlanQtUtilsAp *wlanAp)
   217     esockWrapper_->connectIap(iapId);
   284 {
   218 
   285     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_UPDATEIAP_ENTRY, this);
   219     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_CONNECTIAP_EXIT, this );
   286 
   220 }
   287     bool success = mSettings->updateIap(iapId, wlanAp);
       
   288     
       
   289     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_UPDATEIAP_EXIT, this);
       
   290     return success;
       
   291 }
       
   292 
       
   293 /*!
       
   294    See WlanQtUtils::deleteIap().
       
   295 */
       
   296 
       
   297 void WlanQtUtilsPrivate::deleteIap(int iapId)
       
   298 {
       
   299     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_DELETEIAP_ENTRY, this);
       
   300 
       
   301     mSettings->deleteIap(iapId);
       
   302 
       
   303     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_DELETEIAP_EXIT, this);
       
   304 }
       
   305 
       
   306 /*!
       
   307    See WlanQtUtils::connectIap().
       
   308 */
       
   309 
       
   310 void WlanQtUtilsPrivate::connectIap(int iapId, bool runIct)
       
   311 {
       
   312     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_CONNECTIAP_ENTRY, this);
       
   313     
       
   314     OstTraceExt2(
       
   315         TRACE_BORDER,
       
   316         WLANQTUTILSPRIVATE_CONNECTIAP,
       
   317         "WlanQtUtilsPrivate::connectIap;IAP ID=%d;runIct=%hhu",
       
   318         iapId,
       
   319         runIct);
       
   320 
       
   321     Q_ASSERT(iapId != WlanQtUtils::IapIdNone);
       
   322 
       
   323     if (runIct) {
       
   324         // Mark this IAP for ICT testing after it has been opened
       
   325         mToBeTestedIapId = iapId;
       
   326     }
       
   327     mConnectingIapId = iapId;
       
   328     mEsockWrapper->connectIap(iapId);
       
   329 
       
   330     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_CONNECTIAP_EXIT, this);
       
   331 }
       
   332 
       
   333 /*!
       
   334    See WlanQtUtils::disconnectIap().
       
   335 */
   221 
   336 
   222 void WlanQtUtilsPrivate::disconnectIap(int iapId)
   337 void WlanQtUtilsPrivate::disconnectIap(int iapId)
   223 {
   338 {
   224     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_DISCONNECTIAP_ENTRY, this );
   339     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_DISCONNECTIAP_ENTRY, this);
   225     OstTrace1( TRACE_API, WLANQTUTILSPRIVATE_DISCONNECTIAP, "WlanQtUtilsPrivate::disconnectIap;IAP ID=%d", iapId );
   340     
   226     
   341     OstTrace1(
   227     Q_ASSERT(activeConnection_ != NULL);
   342         TRACE_BORDER,
   228     Q_ASSERT(activeConnection_->iapId() == iapId);
   343         WLANQTUTILSPRIVATE_DISCONNECTIAP,
   229     Q_ASSERT(wlanIapList_.contains(iapId));
   344         "WlanQtUtilsPrivate::disconnectIap;IAP ID=%d", iapId );
   230     
   345 
   231     // Todo: IAP may have been opened by someone else... how to know when to disconnect RConnection?    
   346     if (iapId != WlanQtUtils::IapIdNone) {
   232     esockWrapper_->disconnectIap();
   347         // Close our RConnection handle, if needed. Wrapper ignores call, if
   233     
   348         // no handle exists.
   234     // In order to close connection even if there are other users for the IAP, close also via ConMon
   349         mEsockWrapper->disconnectIap();
   235     conMonWrapper_->disconnectIap(iapId);
   350         
   236     // Change status of the IAP to non-connected
   351         // In order to close connection even if there are other users for the
   237     wlanIapList_[iapId]->setConnectionStatus(WlanQtUtilsConnectionStatusDisconnected);
   352         // IAP, close also via ConMon
   238 
   353         mConMonWrapper->disconnectIap(iapId);
   239     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_DISCONNECTIAP_EXIT, this );
   354     } // else: just ignore call
   240 }
   355 
   241 
   356     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_DISCONNECTIAP_EXIT, this);
   242 WlanQtUtilsIap *WlanQtUtilsPrivate::iap(int iapId) const
   357 }
   243 {
   358 
   244     if (wlanIapList_.contains(iapId)) {
   359 /*!
   245         return wlanIapList_.value(iapId);
   360    See WlanQtUtils::connectionStatus().
   246     }
   361 */
   247     // else: no match
   362 
   248     return NULL;
   363 WlanQtUtils::ConnStatus WlanQtUtilsPrivate::connectionStatus() const
   249 }
   364 {
   250 
   365     OstTraceFunctionEntry0(WLANQTUTILSPRIVATE_CONNECTIONSTATUS_ENTRY);
   251 bool WlanQtUtilsPrivate::masterWlan() const
   366 
   252 {
   367     WlanQtUtils::ConnStatus status = WlanQtUtils::ConnStatusDisconnected;
   253     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_MASTERWLAN_ENTRY, this );
   368     
   254     
   369     if (mConnection) {
   255     // TODO: Add actual implementation, this is just temporary dummy for testing wlanentryplugin!
   370         status = mConnection->connectionStatus();
   256 
   371     }
   257     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_MASTERWLAN_EXIT, this );
   372     OstTrace1(
   258     return true;
   373         TRACE_BORDER,
   259 }
   374         WLANQTUTILSPRIVATE_CONNECTIONSTATUS,
   260 
   375         "WlanQtUtilsPrivate::connectionStatus;status=%{ConnStatus};",
   261 void WlanQtUtilsPrivate::setMasterWlan(bool enabled)
   376         (TUint)status);
   262 {
   377     
   263     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_SETMASTERWLAN_ENTRY, this );
   378     OstTraceFunctionExit0(WLANQTUTILSPRIVATE_CONNECTIONSTATUS_EXIT);
   264     
   379     return status;
   265     // TODO: Add actual implementation.
   380 }
   266     (void)enabled;
   381 
   267 
   382 /*!
   268     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_SETMASTERWLAN_EXIT, this );
   383    See WlanQtUtils::activeIap().
   269 }
   384 */
   270 
   385 
   271 int WlanQtUtilsPrivate::connectedWlanId() const
   386 int WlanQtUtilsPrivate::activeIap() const
   272 {
   387 {
   273     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_CONNECTEDWLANID_ENTRY, this );
   388     OstTraceFunctionEntry0(WLANQTUTILSPRIVATE_ACTIVEIAP_ENTRY);
   274 
   389 
   275     int retVal = WlanQtUtilsInvalidIapId;
   390     int iapId = WlanQtUtils::IapIdNone;
   276     if (activeConnection_ != NULL) {
   391     
   277         retVal = activeConnection_->iapId();
   392     if (mConnection) {
   278     }
   393         iapId = mConnection->iapId();
   279     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_CONNECTEDWLANID_EXIT, this );
   394     }
   280     return retVal;
   395     OstTrace1(
   281 }
   396         TRACE_BORDER,
   282 
   397         WLANQTUTILSPRIVATE_ACTIVEIAP,
   283 void WlanQtUtilsPrivate::scanWlans()
   398         "WlanQtUtilsPrivate::activeIap;iapId=%d",
   284 {
   399         iapId);
   285     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_SCANWLANS_ENTRY, this );
   400     
   286 
   401     OstTraceFunctionExit0(WLANQTUTILSPRIVATE_ACTIVEIAP_EXIT);
   287     // Just forward the request to wrapper, which triggers a single WLAN scan
   402     return iapId;
   288     conMonWrapper_->scanAvailableWlanAPs();
   403 }
   289 
   404 
   290     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_SCANWLANS_EXIT, this );
   405 /*!
   291 }
   406    See WlanQtUtils::iapName().
   292 
   407 */
   293 void WlanQtUtilsPrivate::updateAvailableWlanAps(QList<WlanQtUtilsWlanAp *> &availableWlanList)
   408 
   294 {
   409 QString WlanQtUtilsPrivate::iapName(int iapId) const
   295     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_UPDATEAVAILABLEWLANAPS_ENTRY, this );
   410 {
   296     
   411     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_IAPNAME_ENTRY, this);
       
   412     
       
   413     QString name;
       
   414     // Read the IAP from settings and return its name
       
   415     QSharedPointer<WlanQtUtilsIap> iap = mSettings->fetchIap(iapId);
       
   416     if (iap) {
       
   417         name = iap->value(WlanQtUtilsIap::ConfIdName).toString();
       
   418     }
       
   419 
       
   420     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_IAPNAME_EXIT, this);
       
   421     return name;
       
   422 }
       
   423 
       
   424 /*!
       
   425     This function searches for a WLAN IAP matching the given WLAN AP.
       
   426 
       
   427     @param [in] list List to search from.
       
   428     @param [in] ap Access point to search for.
       
   429     
       
   430     @return True, if suitable WLAN IAP found, false otherwise.
       
   431 */
       
   432 
       
   433 bool WlanQtUtilsPrivate::wlanIapExists(
       
   434     const QList< QSharedPointer<WlanQtUtilsIap> > list,
       
   435     const WlanQtUtilsAp *ap) const
       
   436 {
       
   437     bool match = false;     // Return value
       
   438     
       
   439     foreach (QSharedPointer<WlanQtUtilsIap> iap, list) {
       
   440         if (WlanQtUtilsAp::compare(iap.data(), ap) == true) {
       
   441             // Match found
       
   442             match = true;
       
   443             break;
       
   444         }
       
   445     }
       
   446     
       
   447     return match;
       
   448 }
       
   449 
       
   450 /*!
       
   451     This function traces the given IAPs and APs.
       
   452 
       
   453     @param [in] iaps IAPs to trace.
       
   454     @param [in] aps APs to trace.
       
   455 */
       
   456 
       
   457 void WlanQtUtilsPrivate::traceIapsAndAps(
       
   458     const QList<QSharedPointer<WlanQtUtilsIap> > &iaps,
       
   459     const QList<QSharedPointer<WlanQtUtilsAp> > &aps) const
       
   460 {
       
   461 #ifndef OST_TRACE_COMPILER_IN_USE
       
   462     Q_UNUSED(iaps);
       
   463     Q_UNUSED(aps);
       
   464 #else
       
   465     foreach (QSharedPointer<WlanQtUtilsIap> iap, iaps) {
       
   466         QString tmp(iap->value(WlanQtUtilsIap::ConfIdName).toString());
       
   467         TPtrC16 name(tmp.utf16(), tmp.length());
       
   468         OstTraceExt3(
       
   469             TRACE_NORMAL,
       
   470             WLANQTUTILSPRIVATE_TRACEAVAILABLEWLANAPS_IAP,
       
   471             "WlanQtUtilsPrivate::traceAvailableWlanAps IAP;name=%S;iap->securityMode()=%d;iap->signalStrength()=%d",
       
   472             name,
       
   473             iap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(),
       
   474             iap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt());
       
   475     }
       
   476     foreach (QSharedPointer<WlanQtUtilsAp> ap, aps) {
       
   477         QString tmp(ap->value(WlanQtUtilsAp::ConfIdSsid).toString());
       
   478         TPtrC16 ssid(tmp.utf16(), tmp.length());
       
   479         OstTraceExt3(
       
   480             TRACE_NORMAL,
       
   481             WLANQTUTILSPRIVATE_TRACEAVAILABLEWLANAPS_AP,
       
   482             "WlanQtUtilsPrivate::traceAvailableWlanAps AP;ssid=%S;ap->securityMode()=%d;ap->signalStrength()=%d",
       
   483             ssid,
       
   484             ap->value(WlanQtUtilsAp::ConfIdSecurityMode).toInt(),
       
   485             ap->value(WlanQtUtilsAp::ConfIdSignalStrength).toInt() );
       
   486     }
       
   487 #endif
       
   488 }
       
   489 
       
   490 /*!
       
   491     Slot for handling WLAN scan result event from wrapper. Results are
       
   492     stored in member variable (possible duplicates are removed).
       
   493 
       
   494     @param [in] availableWlanList WLAN networks found in scan.
       
   495 */
       
   496 
       
   497 void WlanQtUtilsPrivate::updateAvailableWlanAps(
       
   498     QList<QSharedPointer<WlanQtUtilsAp> > &availableWlanList)
       
   499 {
       
   500     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_UPDATEAVAILABLEWLANAPS_ENTRY, this);
       
   501 
   297     // Old results are removed
   502     // Old results are removed
   298     wlanScanList_.clear();
   503     mWlanScanList.clear();
   299     // Copy available WLAN's to engine's scan result list (duplicates are removed)
   504     // Copy available WLANs to scan result list (duplicates are removed)
   300     for (int i = 0; i < availableWlanList.count(); i++) {
   505     for (int i = 0; i < availableWlanList.count(); i++) {
   301         bool duplicate = false;
   506         bool duplicate = false;
   302         for (int j = 0; j < wlanScanList_.count(); j++) {
   507         for (int j = 0; j < mWlanScanList.count(); j++) {
   303             if (availableWlanList[i]->ssid() == wlanScanList_[j]->ssid()
   508             if (WlanQtUtilsAp::compare(
   304                 && availableWlanList[i]->securityMode() == wlanScanList_[j]->securityMode()) {
   509                 availableWlanList[i].data(),
       
   510                 mWlanScanList[j].data()) == true) {
   305                 duplicate = true;
   511                 duplicate = true;
   306                 break;
   512                 break;
   307             }
   513             }
   308         }
   514         }
   309         if (duplicate == false) {
   515         if (duplicate == false) {
   310             wlanScanList_.append(availableWlanList[i]);
   516             mWlanScanList.append(availableWlanList[i]);
   311         }
   517         }
   312         // Todo: else deallocate?
   518     }
   313     }
   519 
   314 
   520     // The information is forwarded to the UI
   315     // the information is forwarded to the UI
   521     OstTrace0(
       
   522         TRACE_BORDER,
       
   523         WLANQTUTILSPRIVATE_WLANSCANREADY,
       
   524         "WlanQtUtilsPrivate::emit wlanScanReady");
   316     emit q_ptr->wlanScanReady();
   525     emit q_ptr->wlanScanReady();
   317 
   526     
   318     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_UPDATEAVAILABLEWLANAPS_EXIT, this );
   527     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_UPDATEAVAILABLEWLANAPS_EXIT, this);
   319 }
   528 }
       
   529 
       
   530 /*!
       
   531     Slot for handling connection setup status event from wrapper.
       
   532 
       
   533     @param [in] isOpened Was connection setup successful?
       
   534 */
   320 
   535 
   321 void WlanQtUtilsPrivate::updateConnectionStatus(bool isOpened)
   536 void WlanQtUtilsPrivate::updateConnectionStatus(bool isOpened)
   322 {
   537 {
   323     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_UPDATECONNECTIONSTATUS_ENTRY, this );    
   538     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_UPDATECONNECTIONSTATUS_ENTRY, this);
   324     OstTrace1(
   539 
   325         TRACE_API,
       
   326         WLANQTUTILSPRIVATE_UPDATECONNECTIONSTATUS,
       
   327         "WlanQtUtilsPrivate::updateConnectionStatus;isOpened=%d", isOpened );
       
   328     
       
   329     if (isOpened == false) {
   540     if (isOpened == false) {
   330         // Opening failed, update connection statuses, but don't inform UI about
   541         // Opening failed, update connection status and inform UI
   331         // connection closing here. It is done always in removeActiveConnection().
   542         if (mConnection) {
   332         if (activeConnection_ != NULL) {
   543             mConnection->setConnectionStatus(
   333             activeConnection_->setConnectionStatus(WlanQtUtilsConnectionStatusDisconnected);
   544                 WlanQtUtils::ConnStatusDisconnected);
   334         }
   545         }
   335         updateIapConnectionStatuses(connectingIapId_, WlanQtUtilsConnectionStatusDisconnected);
   546         
       
   547         // Include the status code from connection wrapper
       
   548         int status = mEsockWrapper->lastStatusCode();
       
   549         OstTraceExt2(
       
   550             TRACE_BORDER,
       
   551             WLANQTUTILSPRIVATE_WLANNETWORKCLOSED,
       
   552             "WlanQtUtilsPrivate::emit wlanNetworkClosed;IAP ID=%d;status=%d",
       
   553             mConnectingIapId,
       
   554             status);
       
   555         emit q_ptr->wlanNetworkClosed(mConnectingIapId, status);
   336     } else {
   556     } else {
   337         // Opening succeeded, update connection statuses and inform UI
   557         // Opening succeeded, update connection status and inform UI
   338         if (activeConnection_ != NULL) {
   558         if (mConnection) {
   339             activeConnection_->setConnectionStatus(WlanQtUtilsConnectionStatusConnected);
   559             mConnection->setConnectionStatus(
   340         }
   560                 WlanQtUtils::ConnStatusConnected);
   341         updateIapConnectionStatuses(connectingIapId_, WlanQtUtilsConnectionStatusConnected);
   561         }
   342         emit q_ptr->wlanNetworkOpened(connectingIapId_);
   562         
       
   563         OstTrace1(
       
   564             TRACE_BORDER,
       
   565             WLANQTUTILSPRIVATE_WLANNETWORKOPENED,
       
   566             "WlanQtUtilsPrivate::emit wlanNetworkOpened;IAP ID=%d",
       
   567             mConnectingIapId);
       
   568         emit q_ptr->wlanNetworkOpened(mConnectingIapId);
   343 
   569 
   344         // Start ICT, if needed
   570         // Start ICT, if needed
   345         if (connectingIapId_ == toBeTestedIapId_) {
   571         if (mConnectingIapId == mToBeTestedIapId) {
   346             WlanQtUtilsIap *iap = WlanQtUtilsPrivate::iap(toBeTestedIapId_);
   572             QSharedPointer<WlanQtUtilsIap> iap = 
   347             connTestWrapper_->startConnectivityTest(toBeTestedIapId_, iap->networkId());
   573                 mSettings->fetchIap(mToBeTestedIapId);
       
   574             mConnTestWrapper->startConnectivityTest(
       
   575                 mToBeTestedIapId,
       
   576                 iap->value(WlanQtUtilsIap::ConfIdNetworkId).toInt());
   348         }
   577         }
   349     }
   578     }
   350     // IAP is no more in connecting state
   579     // IAP is no more in connecting state
   351     connectingIapId_ = WlanQtUtilsInvalidIapId;
   580     mConnectingIapId = WlanQtUtils::IapIdNone;
   352 
   581 
   353     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_UPDATECONNECTIONSTATUS_EXIT, this );
   582     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_UPDATECONNECTIONSTATUS_EXIT, this);
   354 }
   583 }
       
   584 
       
   585 /*!
       
   586     Slot for handling connectivity test result event from wrapper. Tested
       
   587     IAP is stored to Internet SNAP, if test was successful.
       
   588 
       
   589     @param [in] result Was the test successful?
       
   590 */
   355 
   591 
   356 void WlanQtUtilsPrivate::updateConnectivityTestResult(bool result)
   592 void WlanQtUtilsPrivate::updateConnectivityTestResult(bool result)
   357 {
   593 {
   358     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_UPDATECONNECTIVITYTESTRESULT_ENTRY, this );
   594     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_UPDATECONNECTIVITYTESTRESULT_ENTRY, this);
   359     OstTrace1(
   595 
   360         TRACE_API,
       
   361         WLANQTUTILSPRIVATE_UPDATECONNECTIVITYTESTRESULT,
       
   362         "WlanQtUtilsPrivate::updateConnectivityTestResult;result=%d", result );
       
   363     
       
   364     if (result == true) {
   596     if (result == true) {
   365         // Move the tested IAP to Internet SNAP since the test passed
   597         // Move the tested IAP to Internet SNAP since the test passed
   366         Q_ASSERT(toBeTestedIapId_ != WlanQtUtilsInvalidIapId);
   598         Q_ASSERT(mToBeTestedIapId != WlanQtUtils::IapIdNone);
   367         cmmWrapper_->moveIapToInternetSnap(toBeTestedIapId_);
   599         mSettings->moveIapToInternetSnap(mToBeTestedIapId);
   368     } // else: do nothing, IAP remains to be uncategorized
   600     } // else: do nothing, IAP remains to be uncategorized
   369     else
   601 
   370     {
   602     // Inform UI
   371         // TODO: Remove this. This is needed now since the connectivity test fails
   603     OstTraceExt2(
   372         // and thus the IAP is not shown correctly.
   604         TRACE_NORMAL,
   373         cmmWrapper_->moveIapToInternetSnap(toBeTestedIapId_);
   605         WLANQTUTILSPRIVATE_ICTRESULT,
   374 
   606         "WlanQtUtilsPrivate::emit ictResult;result=%hhu;IAP ID=%d",
   375     }
   607         result,
       
   608         mToBeTestedIapId);
       
   609 
       
   610     emit q_ptr->ictResult(mToBeTestedIapId, result);
       
   611 
   376     // This IAP is now tested
   612     // This IAP is now tested
   377     toBeTestedIapId_ = WlanQtUtilsInvalidIapId;
   613     mToBeTestedIapId = WlanQtUtils::IapIdNone;
   378 
   614 
   379     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_UPDATECONNECTIVITYTESTRESULT_EXIT, this );
   615     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_UPDATECONNECTIVITYTESTRESULT_EXIT, this);
   380 }
   616 }
       
   617 
       
   618 /*!
       
   619     Slot for updating active connection status from wrapper.
       
   620 
       
   621     @param [in] connectionId ID of the new connection.
       
   622 */
   381 
   623 
   382 void WlanQtUtilsPrivate::addActiveConnection(uint connectionId)
   624 void WlanQtUtilsPrivate::addActiveConnection(uint connectionId)
   383 {
   625 {
   384     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_ADDACTIVECONNECTION_ENTRY, this );
   626     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_ADDACTIVECONNECTION_ENTRY, this);
   385     OstTrace1(
   627     OstTrace1(
   386         TRACE_API,
   628         TRACE_BORDER,
   387         WLANQTUTILSPRIVATE_ADDACTIVECONNECTION,
   629         WLANQTUTILSPRIVATE_ADDACTIVECONNECTION,
   388         "WlanQtUtilsPrivate::addActiveConnection;connectionId=%u", connectionId );
   630         "WlanQtUtilsPrivate::addActiveConnection;connectionId=%u",
   389 
   631         connectionId);
   390     Q_ASSERT(activeConnection_ == NULL);
   632 
   391     activeConnection_ = conMonWrapper_->connectionInfo(connectionId);
   633     Q_ASSERT(mConnection == NULL);
   392     Q_ASSERT(wlanIapList_.contains(activeConnection_->iapId()));
   634     mConnection = QSharedPointer<WlanQtUtilsConnection>(
   393     updateIapConnectionStatuses(activeConnection_->iapId(), activeConnection_->connectionStatus());
   635         mConMonWrapper->connectionInfo(connectionId));
   394 
   636 
   395     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_ADDACTIVECONNECTION_EXIT, this );
   637     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_ADDACTIVECONNECTION_EXIT, this);
   396 }
   638 }
       
   639 
       
   640 /*!
       
   641     Slot for updating active connection status from wrapper.
       
   642 
       
   643     @param [in] connectionId ID of the deleted connection.
       
   644 */
   397 
   645 
   398 void WlanQtUtilsPrivate::removeActiveConnection(uint connectionId)
   646 void WlanQtUtilsPrivate::removeActiveConnection(uint connectionId)
   399 {
   647 {
   400     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_REMOVEACTIVECONNECTION_ENTRY, this );
   648     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_REMOVEACTIVECONNECTION_ENTRY, this);
   401     OstTrace1(
   649     OstTrace1(
   402         TRACE_API,
   650         TRACE_BORDER,
   403         WLANQTUTILSPRIVATE_REMOVEACTIVECONNECTION,
   651         WLANQTUTILSPRIVATE_REMOVEACTIVECONNECTION,
   404         "WlanQtUtilsPrivate::removeActiveConnection;connectionId=%u", connectionId );
   652         "WlanQtUtilsPrivate::removeActiveConnection;connectionId=%u",
   405     
   653         connectionId);
   406     Q_ASSERT(activeConnection_ != NULL);
   654 
   407     if (activeConnection_->connectionId() == connectionId) {
   655     Q_ASSERT(mConnection);
   408         // Connection is closed, update connection statuses and inform UI.
   656     if (mConnection->connectionId() == connectionId) {
   409         // wlanNetworkClosed is sent from here (and only from here), because, in some cases,
   657         int closedIapId = mConnection->iapId();
   410         // connection may be removed without any connection status updates.
   658         mConnection.clear();
   411         int closedIapId = activeConnection_->iapId();
   659 
   412         updateIapConnectionStatuses(activeConnection_->iapId(), WlanQtUtilsConnectionStatusDisconnected);
   660         if (mConnectingIapId != closedIapId) {
   413         delete activeConnection_;
   661             // Connection is closed, inform UI. wlanNetworkClosed is sent
   414         activeConnection_ = NULL;
   662             // from here instead of updateActiveConnection(closed),
   415         emit q_ptr->wlanNetworkClosed(closedIapId);
   663             // because, in some cases, connection may be removed without
   416     }
   664             // any connection status updates.
   417 
   665             // Note: reason parameter is not accurate here, because it is
   418     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_REMOVEACTIVECONNECTION_EXIT, this );
   666             // only relevant for connections opened by this dll
   419 }
   667             // (updateConnectionStatus)
   420 
   668             OstTraceExt2(
   421 void WlanQtUtilsPrivate::updateActiveConnection(uint connectionId, WlanQtUtilsConnectionStatus connectionStatus)
   669                 TRACE_BORDER,
   422 {
   670                 DUP1_WLANQTUTILSPRIVATE_WLANNETWORKCLOSED,
   423     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_UPDATEACTIVECONNECTION_ENTRY, this );
   671                 "WlanQtUtilsPrivate::emit wlanNetworkClosed;IAP ID=%d;status=%d",
       
   672                 closedIapId,
       
   673                 KErrNone);
       
   674             emit q_ptr->wlanNetworkClosed(closedIapId, KErrNone);
       
   675         }
       
   676         // else: connection creation started by thid dll, but creation failed
       
   677         // -> wlanNetworkClosed is sent from updateConnectionStatus
       
   678     }
       
   679 
       
   680     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_REMOVEACTIVECONNECTION_EXIT, this);
       
   681 }
       
   682 
       
   683 /*!
       
   684     Slot for updating active connection status from wrapper.
       
   685 
       
   686     @param [in] connectionId ID of the updated connection.
       
   687     @param [in] connectionStatus New status of the connection.
       
   688 */
       
   689 
       
   690 void WlanQtUtilsPrivate::updateActiveConnection(
       
   691     uint connectionId,
       
   692     WlanQtUtils::ConnStatus connectionStatus)
       
   693 {
       
   694     OstTraceFunctionEntry1(WLANQTUTILSPRIVATE_UPDATEACTIVECONNECTION_ENTRY, this);
   424     OstTraceExt2(
   695     OstTraceExt2(
   425         TRACE_API,
   696         TRACE_BORDER,
   426         WLANQTUTILSPRIVATE_UPDATEACTIVECONNECTION,
   697         WLANQTUTILSPRIVATE_UPDATEACTIVECONNECTION,
   427         "WlanQtUtilsPrivate::updateActiveConnection;connectionId=%u;connectionStatus=%u", connectionId, connectionStatus );
   698         "WlanQtUtilsPrivate::updateActiveConnection;connectionId=%u;connectionStatus=%u",
   428     
   699         connectionId,
   429     Q_ASSERT(activeConnection_ != NULL);
   700         (uint)connectionStatus);
   430     if (activeConnection_->connectionId() == connectionId
   701 
   431         && activeConnection_->connectionStatus() != connectionStatus) {
   702     Q_ASSERT(mConnection);
   432         // Update connection statuses and inform UI, if necessary
   703     if (mConnection->connectionId() == connectionId
   433         activeConnection_->setConnectionStatus(connectionStatus);
   704         && mConnection->connectionStatus() != connectionStatus) {
   434         updateIapConnectionStatuses(activeConnection_->iapId(), connectionStatus);
   705         // Update connection status and inform UI, if necessary
   435         if (connectionStatus == WlanQtUtilsConnectionStatusConnected) {
   706         mConnection->setConnectionStatus(connectionStatus);
   436             emit q_ptr->wlanNetworkOpened(activeConnection_->iapId());
   707         if (connectionStatus == WlanQtUtils::ConnStatusConnected) {
   437         }
   708             OstTrace1(
   438         // Do not inform UI about connection closing here. It is done always in
   709                 TRACE_BORDER,
   439         // removeActiveConnection(), because that may occur without any connection status updates.
   710                 DUP1_WLANQTUTILSPRIVATE_WLANNETWORKOPENED,
       
   711                 "WlanQtUtilsPrivate::emit wlanNetworkOpened;IAP ID=%d",
       
   712                 mConnection->iapId());
       
   713             emit q_ptr->wlanNetworkOpened(mConnection->iapId());
       
   714         }
       
   715         // Do not inform UI about connection closing here. It is done in
       
   716         // removeActiveConnection(), because that may occur without any
       
   717         // connection status updates.
   440     } // else: connection status did not change
   718     } // else: connection status did not change
   441 
   719 
   442     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_UPDATEACTIVECONNECTION_EXIT, this );
   720     OstTraceFunctionExit1(WLANQTUTILSPRIVATE_UPDATEACTIVECONNECTION_EXIT, this);
   443 }
   721 }
   444 
       
   445 int WlanQtUtilsPrivate::fetchIaps()
       
   446 {
       
   447     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_FETCHIAPS_ENTRY, this );
       
   448     
       
   449     QList<WlanQtUtilsIap *> list;
       
   450     int error = 0; 
       
   451     // Read the IAP list and store WLAN IAPs in our internal map data structure
       
   452     error = cmmWrapper_->fetchIaps(list);    
       
   453     foreach (WlanQtUtilsIap *iap, list) {
       
   454         if (iap->bearerType() == WlanQtUtilsBearerTypeWlan) {
       
   455             // Notice that insertMulti not used, because IAP IDs should be unique
       
   456             wlanIapList_.insert(iap->id(), qobject_cast<WlanQtUtilsWlanIap *>(iap));            
       
   457         }
       
   458     }
       
   459         
       
   460     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_FETCHIAPS_EXIT, this );
       
   461     return error;
       
   462 }
       
   463 
       
   464 bool WlanQtUtilsPrivate::wlanIapExists(QString ssid, WlanQtUtilsWlanSecMode secMode)
       
   465 {    
       
   466     foreach (WlanQtUtilsWlanIap *iap, wlanIapList_) {
       
   467         // todo: secmode
       
   468         (void)secMode;
       
   469         if (iap->ssid() == ssid) {
       
   470             return true;
       
   471         }
       
   472     }
       
   473     
       
   474     return false;
       
   475 }
       
   476 
       
   477 void WlanQtUtilsPrivate::updateIapConnectionStatuses(int iapId, WlanQtUtilsConnectionStatus status)
       
   478 {
       
   479     OstTraceFunctionEntry1( WLANQTUTILSPRIVATE_UPDATEIAPCONNECTIONSTATUSES_ENTRY, this );
       
   480     
       
   481     const WlanQtUtilsWlanIap *referenceIap = qobject_cast<WlanQtUtilsWlanIap *>(iap(iapId));
       
   482     foreach (WlanQtUtilsWlanIap *iap, wlanIapList_) {
       
   483         // todo: security mode checking
       
   484         if (iap->id() == referenceIap->id() || iap->ssid() == referenceIap->ssid()) {
       
   485             iap->setConnectionStatus(status);
       
   486         }
       
   487     }
       
   488 
       
   489     OstTraceFunctionExit1( WLANQTUTILSPRIVATE_UPDATEIAPCONNECTIONSTATUSES_EXIT, this );
       
   490 }