wlanutilities/wlanqtutilities/wrapper/src/wlanqtutilsconmonwrapper_s60.cpp
changeset 19 10810c91db26
child 29 dbe86d96ce5b
equal deleted inserted replaced
3:ff3b37722600 19:10810c91db26
       
     1 /*
       
     2  * Copyright (c) 2009 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  * This is a source file for following classes:
       
    16  * ConnMonScanWlanAps,
       
    17  * ConnMonConnInfo,
       
    18  * ConnMonConnDisconnect
       
    19  */
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <cmconnectionmethodext.h>
       
    23 #include <rconnmon.h>
       
    24 #include <nifvar.h>
       
    25 
       
    26 #include "wlanqtutilscommon.h"
       
    27 #include "wlanqtutilswlanap.h"
       
    28 #include "wlanqtutilsactiveconn.h"
       
    29 #include "wlanqtutilsconmonwrapper.h"
       
    30 #include "wlanqtutilsconmonwrapper_s60_p.h"
       
    31 
       
    32 #ifdef WLANQTUTILS_NO_OST_TRACES_FLAG
       
    33 #include <opensystemtrace.h>
       
    34 #else
       
    35 #include "OstTraceDefinitions.h"
       
    36 #endif
       
    37 #ifdef OST_TRACE_COMPILER_IN_USE
       
    38 #include "wlanqtutilsconmonwrapper_s60Traces.h"
       
    39 #endif
       
    40 
       
    41 
       
    42 // =========== PRIVATE CLASS MEMBER FUNCTIONS ===============
       
    43 //
       
    44 // ---------------------------------------------------------
       
    45 // ConnMonScanWlanAps::ConnMonScanWlanAps()
       
    46 // Constructor
       
    47 // ---------------------------------------------------------
       
    48 //
       
    49 ConnMonScanWlanAps::ConnMonScanWlanAps(ConMonWrapper *wrapper) :
       
    50     CActive(EPriorityStandard), q_ptr(wrapper), wlanPtr(0, 0)
       
    51     {
       
    52     OstTraceFunctionEntry1( CONNMONSCANWLANAPS_CONNMONSCANWLANAPS_ENTRY, this );
       
    53     
       
    54     CActiveScheduler::Add(this);
       
    55     // TBD: What if this leaves?
       
    56     // Beware! iConnMon.ConnectL() can
       
    57     // both leave AND return an error code..
       
    58     // User::LeaveIfError( iMonitor.ConnectL() );
       
    59     iMonitor.ConnectL();
       
    60 
       
    61     OstTraceFunctionExit1( CONNMONSCANWLANAPS_CONNMONSCANWLANAPS_EXIT, this );
       
    62     }
       
    63 
       
    64 // ---------------------------------------------------------
       
    65 // ConnMonScanWlanAps::ConnMonScanWlanAps()
       
    66 // Destructor
       
    67 // ---------------------------------------------------------
       
    68 //
       
    69 ConnMonScanWlanAps::~ConnMonScanWlanAps()
       
    70     {
       
    71     OstTraceFunctionEntry1( CONNMONSCANWLANAPS_CONNMONSCANWLANAPSDESTR_ENTRY, this );
       
    72     
       
    73     Cancel();
       
    74     // Cancel notifications and close connection monitor session
       
    75     iMonitor.Close();
       
    76     if (wlanBuf)
       
    77         {
       
    78         delete wlanBuf;
       
    79         }
       
    80 
       
    81     OstTraceFunctionExit1( CONNMONSCANWLANAPS_CONNMONSCANWLANAPSDESTR_EXIT, this );
       
    82     }
       
    83 
       
    84 // ---------------------------------------------------------
       
    85 // ConnMonScanWlanAps::DoCancel()
       
    86 // 
       
    87 // ---------------------------------------------------------
       
    88 //
       
    89 void ConnMonScanWlanAps::DoCancel()
       
    90     {
       
    91     OstTraceFunctionEntry1( CONNMONSCANWLANAPS_DOCANCEL_ENTRY, this );
       
    92     // TODO: error handling
       
    93     OstTraceFunctionExit1( CONNMONSCANWLANAPS_DOCANCEL_EXIT, this );
       
    94     }
       
    95 
       
    96 // ---------------------------------------------------------
       
    97 // ConnMonScanWlanAps::RunL()
       
    98 // Called when scan is ready. Emits scan results in a signal.
       
    99 // ---------------------------------------------------------
       
   100 //
       
   101 void ConnMonScanWlanAps::RunL()
       
   102     {
       
   103     OstTraceFunctionEntry1( CONNMONSCANWLANAPS_RUNL_ENTRY, this );
       
   104     
       
   105     if (iStatus == KErrNone)
       
   106         {
       
   107         RConnMonWlanNetworksPtrArray wlanPtrArray;
       
   108         wlanBuf->UnpackToL(wlanPtrArray);
       
   109         QList<WlanQtUtilsWlanAp*> wlanScanResult;
       
   110 
       
   111         for (TInt i = 0; i < wlanPtrArray.Count(); i++)
       
   112             {
       
   113             WlanQtUtilsWlanAp *ap = new WlanQtUtilsWlanAp();
       
   114 
       
   115             // Security mode values defined in enum TConnMonSecurityMode, rconnmon.h.
       
   116             TUint connMonWlanSecMode;
       
   117             WlanQtUtilsWlanSecMode wlanQtUtilsWlanSecMode;
       
   118 
       
   119             TBuf<CConnMonWlanNetwork::KMaxNameLength> wlanName =
       
   120                     wlanPtrArray[i]->Name();
       
   121 
       
   122             QString wlanNameInQt = QString::fromUtf16(wlanName.Ptr(),
       
   123                     wlanName.Length());
       
   124 
       
   125             if (wlanNameInQt.length() == 1 && wlanNameInQt.at(0).unicode()
       
   126                     == 0)
       
   127                 {
       
   128                 // QString handles empty strings (single \0 char) strangely,
       
   129                 // so let's initialize them in a different way:
       
   130                 wlanNameInQt = "";
       
   131                 }
       
   132 
       
   133             ap->setSsid(wlanNameInQt);
       
   134 
       
   135             // TODO: Won't compile to ARMV5 for some reason. Commented for awhile. 
       
   136             //TBuf8<CConnMonWlanNetwork::KWlanBssId> wlanBssid = wlanPtrArray[i]->WlanBssid();
       
   137             //ap->setBssid(QString::fromUtf8(wlanBssid.Ptr(), wlanBssid.Length()));
       
   138             ap->setBssid("addMAC");
       
   139 
       
   140             TUint wlanConnectionMode = wlanPtrArray[i]->ConnectionMode();
       
   141             ap->setConnectionMode(wlanConnectionMode);
       
   142 
       
   143             TUint wlanSignalStrength = wlanPtrArray[i]->SignalStrength();
       
   144             ap->setSignalStrength(wlanSignalStrength);
       
   145 
       
   146             connMonWlanSecMode = wlanPtrArray[i]->SecurityMode();
       
   147             wlanQtUtilsWlanSecMode = conMon2WlanQtUtilsSecModeMap(connMonWlanSecMode);
       
   148             ap->setSecurityMode(wlanQtUtilsWlanSecMode);
       
   149 
       
   150             wlanScanResult.append(ap);
       
   151             delete wlanPtrArray[i];
       
   152             }
       
   153         q_ptr->emitAvailableWlans(wlanScanResult);
       
   154         wlanPtrArray.Close();
       
   155         delete wlanBuf;
       
   156         wlanBuf = NULL;
       
   157         // TODO: Is this enough for clearing QList containing ConnUtilsWlanAps?
       
   158         wlanScanResult.clear();
       
   159         }
       
   160     else
       
   161         {
       
   162         // TODO: add error handling
       
   163         }
       
   164     
       
   165     OstTraceFunctionExit1( CONNMONSCANWLANAPS_RUNL_EXIT, this );
       
   166     }
       
   167 
       
   168 // ---------------------------------------------------------
       
   169 // ConnMonScanWlanAps::scanAvailableWlanAPs()
       
   170 // Gets APs from Connection Monitor
       
   171 // ---------------------------------------------------------
       
   172 //
       
   173 int ConnMonScanWlanAps::scanAvailableWlanAPs()
       
   174     {
       
   175     OstTraceFunctionEntry1( CONNMONSCANWLANAPS_SCANAVAILABLEWLANAPS_ENTRY, this );
       
   176 
       
   177     if (!IsActive())
       
   178         {
       
   179         // TODO: What size for wlanBuf? How to know exact size?
       
   180         // 2560 ~ 35 wlan APs
       
   181         wlanBuf = new (ELeave) CConnMonWlanNetworksPtrArrayPckg(2560);
       
   182         wlanPtr.Set(wlanBuf->Buf()->Des());
       
   183 
       
   184         iMonitor.GetPckgAttribute(EBearerIdWLAN, 0, KWlanNetworks, wlanPtr,
       
   185                 iStatus);
       
   186         SetActive();            
       
   187         }
       
   188     
       
   189     OstTraceFunctionExit1( CONNMONSCANWLANAPS_SCANAVAILABLEWLANAPS_EXIT, this );
       
   190     return KErrNone;
       
   191     }
       
   192 
       
   193 // ---------------------------------------------------------
       
   194 // ConMonScanWlanAps::connMon2WlanQtUtilsSecModeMap()
       
   195 // Map security mode from Connection Monitor into WlanQtUtilsWlanSecMode.
       
   196 // ---------------------------------------------------------
       
   197 //
       
   198 WlanQtUtilsWlanSecMode ConnMonScanWlanAps::conMon2WlanQtUtilsSecModeMap(TUint connMonSecMode)
       
   199     {
       
   200     WlanQtUtilsWlanSecMode ret = WlanQtUtilsWlanSecModeNone;
       
   201     switch (connMonSecMode)
       
   202         {
       
   203         case EConnMonSecurityWep:
       
   204             ret = WlanQtUtilsWlanSecModeWep;
       
   205             break;
       
   206         case EConnMonSecurity802d1x:
       
   207             ret = WlanQtUtilsWlanSecMode802_1x;
       
   208             break;
       
   209         case EConnMonSecurityWpa:
       
   210             ret = WlanQtUtilsWlanSecModeWpa;
       
   211             break;
       
   212         case EConnMonSecurityWpaPsk:
       
   213             ret = WlanQtUtilsWlanSecModeWpa2;
       
   214             break;
       
   215         default:
       
   216             // TODO: should default be None/unknown or should there be assert against EConnMonSecurityOpen.
       
   217             ret = WlanQtUtilsWlanSecModeOpen;
       
   218             break;
       
   219         }
       
   220     
       
   221     return ret;
       
   222     }
       
   223 
       
   224 
       
   225 // ---------------------------------------------------------
       
   226 // ConnMonConnInfo::ConnMonConnInfo()
       
   227 // Constructor
       
   228 // ---------------------------------------------------------
       
   229 //
       
   230 ConnMonConnInfo::ConnMonConnInfo(ConMonWrapper *wrapper) :
       
   231     q_ptr(wrapper)
       
   232     {
       
   233     OstTraceFunctionEntry1( CONNMONCONNINFO_CONNMONCONNINFO_ENTRY, this );
       
   234     
       
   235     iMonitor.ConnectL();
       
   236     StartMonitoringL();
       
   237     
       
   238     OstTraceFunctionExit1( CONNMONCONNINFO_CONNMONCONNINFO_EXIT, this );
       
   239     }
       
   240 
       
   241 // ---------------------------------------------------------
       
   242 // ConnMonConnInfo::~ConnMonConnInfo()
       
   243 // Destructor
       
   244 // ---------------------------------------------------------
       
   245 //
       
   246 ConnMonConnInfo::~ConnMonConnInfo()
       
   247     {
       
   248     OstTraceFunctionEntry1( CONNMONCONNINFO_CONNMONCONNINFODESTR_ENTRY, this );
       
   249     
       
   250     StopMonitoring();
       
   251     iMonitor.Close();
       
   252     
       
   253     OstTraceFunctionExit1( CONNMONCONNINFO_CONNMONCONNINFODESTR_EXIT, this );
       
   254     }
       
   255 
       
   256 // ---------------------------------------------------------
       
   257 // ConnMonConnInfo::StartMonitoringL()
       
   258 // Starts monitoring of Connection Monitor Server events
       
   259 // ---------------------------------------------------------
       
   260 //
       
   261 void ConnMonConnInfo::StartMonitoringL()
       
   262     {
       
   263     OstTraceFunctionEntry1( CONNMONCONNINFO_STARTMONITORINGL_ENTRY, this );
       
   264     
       
   265     iMonitoring = ETrue;
       
   266     iMonitor.NotifyEventL(*this);
       
   267     
       
   268     OstTraceFunctionExit1( CONNMONCONNINFO_STARTMONITORINGL_EXIT, this );
       
   269     }
       
   270 
       
   271 // ---------------------------------------------------------
       
   272 // ConnMonConnInfo::StopMonitoring()
       
   273 // Stops monitoring of Connection Monitor Server events
       
   274 // ---------------------------------------------------------
       
   275 //
       
   276 void ConnMonConnInfo::StopMonitoring()
       
   277     {
       
   278     OstTraceFunctionEntry1( CONNMONCONNINFO_STOPMONITORING_ENTRY, this );
       
   279     
       
   280     iMonitoring = EFalse;
       
   281     iMonitor.CancelNotifications();
       
   282 
       
   283     OstTraceFunctionExit1( CONNMONCONNINFO_STOPMONITORING_EXIT, this );
       
   284     }
       
   285 
       
   286 // ---------------------------------------------------------
       
   287 // ConnMonConnInfo::EventL()
       
   288 // Handler of Connection Monitor Server events
       
   289 // ---------------------------------------------------------
       
   290 //
       
   291 void ConnMonConnInfo::EventL(const CConnMonEventBase& aConnMonEvent)
       
   292     {
       
   293     OstTraceFunctionEntry1( CONNMONCONNINFO_EVENTL_ENTRY, this );
       
   294     
       
   295     TUint connectionId = aConnMonEvent.ConnectionId();
       
   296     OstTraceExt2(
       
   297         TRACE_NORMAL,
       
   298         CONNMONCONNINFO_EVENTL_EVENTTYPE,
       
   299         "ConnMonConnInfo::EventL;connectionId=%u;aConnMonEvent.EventType()=%d", connectionId, aConnMonEvent.EventType() );
       
   300 
       
   301     // Note: Conversions from CConnMonEventBase to sub classes cannot be made to use dynamic_cast
       
   302     // because constructors of CConnMonEventBase and its sub classes are not public in
       
   303     // connmon library's interface.
       
   304 
       
   305     switch (aConnMonEvent.EventType())
       
   306         {
       
   307         case EConnMonCreateConnection:
       
   308             q_ptr->emitConnCreatedEvent( connectionId );
       
   309             break;
       
   310         case EConnMonDeleteConnection:
       
   311 
       
   312             // TODO: take the following into use.
       
   313             // const CConnMonDeleteConnection* eventDelete; 
       
   314             // eventDelete = static_cast< const CConnMonDeleteConnection*>( &aConnMonEvent );
       
   315             //TUint totalDlVolume = eventDelete->DownlinkData();
       
   316             //TUint totalUlVolume = eventDelete->UplinkData();
       
   317             //TBool authDelete    = eventDelete->AuthoritativeDelete();
       
   318 
       
   319             q_ptr->emitConnDeletedEvent( connectionId );
       
   320             break;
       
   321         case EConnMonConnectionStatusChange:
       
   322             const CConnMonConnectionStatusChange* eventConnectionStatusChange;
       
   323             eventConnectionStatusChange =
       
   324                 static_cast< const CConnMonConnectionStatusChange* >( &aConnMonEvent );
       
   325             WlanQtUtilsConnectionStatus connectionStatus;
       
   326             connectionStatus = connMon2WlanQtUtilsConnectionStatusMap(
       
   327                 eventConnectionStatusChange->ConnectionStatus() );
       
   328             
       
   329             OstTraceExt2(
       
   330                 TRACE_NORMAL,
       
   331                 CONNMONCONNINFO_EVENTL_CONNSTATUS,
       
   332                 "ConnMonConnInfo::EventL;connectionId=%u;eventConnectionStatusChange->ConnectionStatus()=%d",
       
   333                 connectionId,
       
   334                 eventConnectionStatusChange->ConnectionStatus() );
       
   335 
       
   336             if (connectionStatus != WlanQtUtilsConnectionStatusNone) {
       
   337                 q_ptr->emitConnStatusEvent( connectionId, connectionStatus );
       
   338             }
       
   339             break;
       
   340         default:
       
   341             break;
       
   342         }
       
   343 
       
   344     OstTraceFunctionExit1( CONNMONCONNINFO_EVENTL_EXIT, this );
       
   345     }
       
   346 
       
   347 // ---------------------------------------------------------
       
   348 // ConnMonConnInfo::activeConnection()
       
   349 // ---------------------------------------------------------
       
   350 //
       
   351 WlanQtUtilsActiveConn *ConnMonConnInfo::activeConnection()
       
   352     {
       
   353     OstTraceFunctionEntry1( CONNMONCONNINFO_ACTIVECONNECTION_ENTRY, this );
       
   354     
       
   355     // Get number of active connections
       
   356     TRequestStatus status;
       
   357 
       
   358     TUint numConnections = 0;
       
   359     iMonitor.GetConnectionCount( numConnections, status );
       
   360     User::WaitForRequest( status );
       
   361     if ( status.Int() == KErrNone )
       
   362         {
       
   363         // Get connection info of this connection
       
   364         for ( TUint i = 1; i <= numConnections; i++ )
       
   365             {
       
   366             TUint numSubConnections = 0;
       
   367             TUint connectionId = 0;
       
   368             TInt ret = iMonitor.GetConnectionInfo( i, connectionId, numSubConnections );
       
   369             Q_ASSERT( ret == KErrNone ); // TODO: error handling
       
   370     
       
   371             WlanQtUtilsActiveConn* activeConn = connectionInfo( connectionId );
       
   372             if ( activeConn != NULL )
       
   373                 {
       
   374                 // connectionInfo() only returns WLAN connections, and there may be only
       
   375                 // one active WLAN connection, so this is the one we want to return
       
   376                 OstTraceFunctionExit1( CONNMONCONNINFO_ACTIVECONNECTION_EXIT, this );
       
   377                 return activeConn;
       
   378                 }
       
   379             }
       
   380         }
       
   381 
       
   382     OstTraceFunctionExit1( DUP1_CONNMONCONNINFO_ACTIVECONNECTION_EXIT, this );
       
   383     return NULL;
       
   384     }
       
   385 
       
   386 // ---------------------------------------------------------
       
   387 // ConnMonConnInfo::connectionInfo()
       
   388 // ---------------------------------------------------------
       
   389 //
       
   390 WlanQtUtilsActiveConn *ConnMonConnInfo::connectionInfo( uint connectionId )
       
   391     {
       
   392     OstTraceFunctionEntry1( CONNMONCONNINFO_CONNECTIONINFO_ENTRY, this );
       
   393     
       
   394     TRequestStatus status;
       
   395     WlanQtUtilsActiveConn *activeConn = NULL;
       
   396 
       
   397     // Get the connection bearer.
       
   398     TInt bearer = 0;
       
   399     iMonitor.GetIntAttribute(
       
   400             connectionId,
       
   401             0,
       
   402             KBearer,
       
   403             bearer,
       
   404             status );
       
   405     User::WaitForRequest( status );
       
   406     if ( status.Int() == KErrNone )
       
   407         {
       
   408         // We are only interested in WLAN connections. 
       
   409         WlanQtUtilsBearerType bearerType = connMon2WlanQtUtilsBearerTypeMap( bearer );
       
   410         if ( bearerType == WlanQtUtilsBearerTypeWlan )
       
   411             {
       
   412             activeConn = new WlanQtUtilsActiveConn();
       
   413             activeConn->setConnectionId( connectionId );
       
   414             activeConn->setBearerType( bearerType );
       
   415             activeConnInfoUpdate( activeConn );
       
   416             }
       
   417         }
       
   418 
       
   419     OstTraceFunctionExit1( CONNMONCONNINFO_CONNECTIONINFO_EXIT, this );
       
   420     return activeConn;
       
   421     }
       
   422 
       
   423 // ---------------------------------------------------------
       
   424 // ConnMonConnInfo::activeConnInfoUpdate()
       
   425 // Requests active connection info from Connection Monitor Server
       
   426 // ---------------------------------------------------------
       
   427 //
       
   428 // TODO: divide this function into smaller pieces depending on the need.
       
   429 // TODO: optimize so that all the information is not always requested from connmon.
       
   430 //       Only information that is missing is requested.
       
   431 void ConnMonConnInfo::activeConnInfoUpdate( WlanQtUtilsActiveConn *activeConn )
       
   432     {
       
   433     OstTraceFunctionEntry1( CONNMONCONNINFO_ACTIVECONNINFOUPDATE_ENTRY, this );
       
   434     
       
   435     Q_ASSERT( activeConn != NULL );
       
   436     Q_ASSERT( activeConn->bearerType() != WlanQtUtilsBearerTypeNone );
       
   437 
       
   438     TUint connectionId = activeConn->connectionId();
       
   439     TRequestStatus status;
       
   440 
       
   441     // Get connection IAP ID.
       
   442     TUint iapId = 0;
       
   443     iMonitor.GetUintAttribute(
       
   444             connectionId,
       
   445             0,
       
   446             KIAPId,
       
   447             iapId,
       
   448             status );
       
   449     User::WaitForRequest( status );
       
   450     if ( status.Int() == KErrNone )
       
   451         {
       
   452         activeConn->setIapId( iapId );
       
   453         }
       
   454 
       
   455     // Get connection status.
       
   456     TInt connectionStatus = 0;
       
   457     iMonitor.GetIntAttribute(
       
   458             connectionId,
       
   459             0,
       
   460             KConnectionStatus,
       
   461             connectionStatus,
       
   462             status );
       
   463     User::WaitForRequest( status );
       
   464     if ( status.Int() == KErrNone ) {
       
   465         activeConn->setConnectionStatus( connMon2WlanQtUtilsConnectionStatusMap( connectionStatus ) );
       
   466     }
       
   467 
       
   468     OstTraceFunctionExit1( CONNMONCONNINFO_ACTIVECONNINFOUPDATE_EXIT, this );
       
   469     }
       
   470 
       
   471 // ---------------------------------------------------------
       
   472 // ConnMonConnInfo::connMon2WlanQtUtilsConnectionStatusMap()
       
   473 // Maps connection status of Connection Monitor Server to connection
       
   474 // status of Wlan Qt Utilities.
       
   475 // ---------------------------------------------------------
       
   476 //
       
   477 WlanQtUtilsConnectionStatus ConnMonConnInfo::connMon2WlanQtUtilsConnectionStatusMap( TInt aConnectionStatus )
       
   478     {    
       
   479     // TODO: This mapping is not specific to current status which is unknown to wrapper.
       
   480     // TODO: This is only current implementation and will need serious modifications and
       
   481     //       verification from connmon guys.
       
   482     WlanQtUtilsConnectionStatus connUtilsConnectionStatus = WlanQtUtilsConnectionStatusNone;
       
   483     switch (aConnectionStatus)
       
   484         {
       
   485         // KConnectionOpen is not final status for WLAN, because DHCP is run after that
       
   486         case KConnectionOpen:
       
   487         case KStartingConnection:
       
   488             connUtilsConnectionStatus = WlanQtUtilsConnectionStatusConnecting;
       
   489             break;
       
   490         case KLinkLayerOpen:
       
   491             connUtilsConnectionStatus = WlanQtUtilsConnectionStatusConnected;
       
   492             break;
       
   493         case KConnectionClosed:
       
   494         case KLinkLayerClosed:
       
   495             connUtilsConnectionStatus = WlanQtUtilsConnectionStatusDisconnected;
       
   496             break;
       
   497         default:
       
   498             // Ignore all other values
       
   499             connUtilsConnectionStatus = WlanQtUtilsConnectionStatusNone;
       
   500             break;
       
   501         }
       
   502     
       
   503     return connUtilsConnectionStatus;
       
   504     }
       
   505 
       
   506 // ---------------------------------------------------------
       
   507 // ConnMonConnInfo::connMon2WlanQtUtilsBearerTypeMap()
       
   508 // Maps bearer type of Connection Monitor Server to bearer
       
   509 // type of Wlan Qt Utilities.
       
   510 // ---------------------------------------------------------
       
   511 //
       
   512 WlanQtUtilsBearerType ConnMonConnInfo::connMon2WlanQtUtilsBearerTypeMap( TInt aBearerType )
       
   513     {    
       
   514     WlanQtUtilsBearerType connUtilsBearerType = WlanQtUtilsBearerTypeNone;
       
   515     switch ( aBearerType ) {
       
   516     case EBearerWCDMA:
       
   517     case EBearerGPRS:
       
   518     case EBearerEdgeGPRS:
       
   519         connUtilsBearerType = WlanQtUtilsBearerTypeCellular;
       
   520         break;
       
   521     case EBearerWLAN:
       
   522         connUtilsBearerType = WlanQtUtilsBearerTypeWlan;
       
   523         break;
       
   524     default:
       
   525         break;
       
   526     }
       
   527 
       
   528     return connUtilsBearerType;
       
   529     }
       
   530 
       
   531 // ---------------------------------------------------------
       
   532 // ConnMonConnDisconnect::ConnMonConnDisconnect()
       
   533 // Constructor
       
   534 // ---------------------------------------------------------
       
   535 //
       
   536 ConnMonConnDisconnect::ConnMonConnDisconnect(ConMonWrapper *wrapper) :
       
   537     CActive(EPriorityStandard), q_ptr(wrapper)
       
   538     {
       
   539     OstTraceFunctionEntry1( CONNMONCONNDISCONNECT_CONNMONCONNDISCONNECT_ENTRY, this );
       
   540     
       
   541     CActiveScheduler::Add(this);
       
   542     iMonitor.ConnectL();
       
   543 
       
   544     OstTraceFunctionExit1( CONNMONCONNDISCONNECT_CONNMONCONNDISCONNECT_EXIT, this );
       
   545     }
       
   546 
       
   547 // ---------------------------------------------------------
       
   548 // ConnMonConnDisconnect::ConnMonConnDisconnect()
       
   549 // Destructor
       
   550 // ---------------------------------------------------------
       
   551 //
       
   552 ConnMonConnDisconnect::~ConnMonConnDisconnect()
       
   553     {
       
   554     OstTraceFunctionEntry1( CONNMONCONNDISCONNECT_CONNMONCONNDISCONNECTDESTR_ENTRY, this );
       
   555 
       
   556     // Cancel notifications and close connection monitor session
       
   557     //iMonitor.CancelNotifications();
       
   558     iMonitor.Close();
       
   559     
       
   560     OstTraceFunctionExit1( CONNMONCONNDISCONNECT_CONNMONCONNDISCONNECTDESTR_EXIT, this );
       
   561     }
       
   562 
       
   563 // ---------------------------------------------------------
       
   564 // ConnMonConnDisconnect::DoCancel()
       
   565 // 
       
   566 // ---------------------------------------------------------
       
   567 //
       
   568 void ConnMonConnDisconnect::DoCancel()
       
   569     {
       
   570     OstTraceFunctionEntry1( CONNMONCONNDISCONNECT_DOCANCEL_ENTRY, this );
       
   571     // TODO: error handling
       
   572     OstTraceFunctionExit1( CONNMONCONNDISCONNECT_DOCANCEL_EXIT, this );
       
   573     }
       
   574 
       
   575 // ---------------------------------------------------------
       
   576 // ConnMonConnDisconnect::RunL()
       
   577 // 
       
   578 // ---------------------------------------------------------
       
   579 //
       
   580 void ConnMonConnDisconnect::RunL()
       
   581     {
       
   582     OstTraceFunctionEntry1( CONNMONCONNDISCONNECT_RUNL_ENTRY, this );
       
   583     // TODO: Is anything needed? 
       
   584     OstTraceFunctionExit1( CONNMONCONNDISCONNECT_RUNL_EXIT, this );
       
   585     }
       
   586 
       
   587 // ---------------------------------------------------------
       
   588 // ConnMonConnDisconnect::disconnectConnection(int iapId)
       
   589 // Stop active connection.
       
   590 // ---------------------------------------------------------
       
   591 //
       
   592 void ConnMonConnDisconnect::disconnectConnection(int iapId)
       
   593     {
       
   594     OstTraceFunctionEntry1( CONNMONCONNDISCONNECT_DISCONNECTCONNECTION_ENTRY, this );
       
   595     OstTrace1(
       
   596         TRACE_NORMAL,
       
   597         CONNMONCONNDISCONNECT_DISCONNECTCONNECTION,
       
   598         "ConnMonConnDisconnect::disconnectConnection;iapId=%d", iapId );
       
   599 
       
   600     // TODO: Error handling
       
   601     TUint count;
       
   602     TRequestStatus status;
       
   603     iMonitor.GetConnectionCount(count, status);
       
   604     User::WaitForRequest(status);
       
   605 
       
   606     for (TInt i = 1; i <= count; i++)
       
   607         {
       
   608         TUint numSubConnections;
       
   609         TUint iap = 0;
       
   610         TUint connectionId = 0;
       
   611         TInt ret = iMonitor.GetConnectionInfo(i, connectionId,
       
   612                 numSubConnections);
       
   613         if (ret != KErrNone)
       
   614             {
       
   615             // error
       
   616             }
       
   617         iMonitor.GetUintAttribute(connectionId, 0, KIAPId, iap, status);
       
   618         User::WaitForRequest(status);
       
   619         if (status.Int() != KErrNone)
       
   620             {
       
   621             // error  
       
   622             }
       
   623         if (iap == iapId)
       
   624             {
       
   625             TInt KErr = iMonitor.SetBoolAttribute(connectionId, 0,
       
   626                     KConnectionStop, ETrue);
       
   627             }
       
   628         }
       
   629 
       
   630     OstTraceFunctionExit1( CONNMONCONNDISCONNECT_DISCONNECTCONNECTION_EXIT, this );
       
   631     }
       
   632 
       
   633 //end of file