wlanutilities/wlanqtutilities/wrapper/src/wlanqtutilsconmonwrapper_s60.cpp
changeset 38 2dc6da6fb431
parent 29 dbe86d96ce5b
child 41 a87deff717bc
child 45 d9ec2b8c6bad
equal deleted inserted replaced
29:dbe86d96ce5b 38:2dc6da6fb431
     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     // Filter out other than WLAN connections
       
   302     if (!isWlan(connectionId)) {
       
   303         return;
       
   304     }
       
   305     
       
   306     // Note: Conversions from CConnMonEventBase to sub classes cannot be made to use dynamic_cast
       
   307     // because constructors of CConnMonEventBase and its sub classes are not public in
       
   308     // connmon library's interface.
       
   309 
       
   310     switch (aConnMonEvent.EventType())
       
   311         {
       
   312         case EConnMonCreateConnection:
       
   313             q_ptr->emitConnCreatedEvent( connectionId );
       
   314             break;
       
   315         case EConnMonDeleteConnection:
       
   316 
       
   317             // TODO: take the following into use.
       
   318             // const CConnMonDeleteConnection* eventDelete; 
       
   319             // eventDelete = static_cast< const CConnMonDeleteConnection*>( &aConnMonEvent );
       
   320             //TUint totalDlVolume = eventDelete->DownlinkData();
       
   321             //TUint totalUlVolume = eventDelete->UplinkData();
       
   322             //TBool authDelete    = eventDelete->AuthoritativeDelete();
       
   323 
       
   324             q_ptr->emitConnDeletedEvent( connectionId );
       
   325             break;
       
   326         case EConnMonConnectionStatusChange:
       
   327             const CConnMonConnectionStatusChange* eventConnectionStatusChange;
       
   328             eventConnectionStatusChange =
       
   329                 static_cast< const CConnMonConnectionStatusChange* >( &aConnMonEvent );
       
   330             WlanQtUtilsConnectionStatus connectionStatus;
       
   331             connectionStatus = connMon2WlanQtUtilsConnectionStatusMap(
       
   332                 eventConnectionStatusChange->ConnectionStatus() );
       
   333             
       
   334             OstTraceExt2(
       
   335                 TRACE_NORMAL,
       
   336                 CONNMONCONNINFO_EVENTL_CONNSTATUS,
       
   337                 "ConnMonConnInfo::EventL;connectionId=%u;eventConnectionStatusChange->ConnectionStatus()=%d",
       
   338                 connectionId,
       
   339                 eventConnectionStatusChange->ConnectionStatus() );
       
   340 
       
   341             if (connectionStatus != WlanQtUtilsConnectionStatusNone) {
       
   342                 q_ptr->emitConnStatusEvent( connectionId, connectionStatus );
       
   343             }
       
   344             break;
       
   345         default:
       
   346             break;
       
   347         }
       
   348 
       
   349     OstTraceFunctionExit1( CONNMONCONNINFO_EVENTL_EXIT, this );
       
   350     }
       
   351 
       
   352 // ---------------------------------------------------------
       
   353 // ConnMonConnInfo::activeConnection()
       
   354 // ---------------------------------------------------------
       
   355 //
       
   356 WlanQtUtilsActiveConn *ConnMonConnInfo::activeConnection()
       
   357     {
       
   358     OstTraceFunctionEntry1( CONNMONCONNINFO_ACTIVECONNECTION_ENTRY, this );
       
   359     
       
   360     // Get number of active connections
       
   361     TRequestStatus status;
       
   362 
       
   363     TUint numConnections = 0;
       
   364     iMonitor.GetConnectionCount( numConnections, status );
       
   365     User::WaitForRequest( status );
       
   366     if ( status.Int() == KErrNone )
       
   367         {
       
   368         // Get connection info of this connection
       
   369         for ( TUint i = 1; i <= numConnections; i++ )
       
   370             {
       
   371             TUint numSubConnections = 0;
       
   372             TUint connectionId = 0;
       
   373             TInt ret = iMonitor.GetConnectionInfo( i, connectionId, numSubConnections );
       
   374             Q_ASSERT( ret == KErrNone ); // TODO: error handling
       
   375     
       
   376             WlanQtUtilsActiveConn* activeConn = connectionInfo( connectionId );
       
   377             if ( activeConn != NULL )
       
   378                 {
       
   379                 // connectionInfo() only returns WLAN connections, and there may be only
       
   380                 // one active WLAN connection, so this is the one we want to return
       
   381                 OstTraceFunctionExit1( CONNMONCONNINFO_ACTIVECONNECTION_EXIT, this );
       
   382                 return activeConn;
       
   383                 }
       
   384             }
       
   385         }
       
   386 
       
   387     OstTraceFunctionExit1( DUP1_CONNMONCONNINFO_ACTIVECONNECTION_EXIT, this );
       
   388     return NULL;
       
   389     }
       
   390 
       
   391 // ---------------------------------------------------------
       
   392 // ConnMonConnInfo::connectionInfo()
       
   393 // ---------------------------------------------------------
       
   394 //
       
   395 WlanQtUtilsActiveConn *ConnMonConnInfo::connectionInfo( uint connectionId )
       
   396     {
       
   397     OstTraceFunctionEntry1( CONNMONCONNINFO_CONNECTIONINFO_ENTRY, this );
       
   398     
       
   399     TRequestStatus status;
       
   400     WlanQtUtilsActiveConn *activeConn = NULL;
       
   401 
       
   402     // Get the connection bearer.
       
   403     TInt bearer = 0;
       
   404     iMonitor.GetIntAttribute(
       
   405             connectionId,
       
   406             0,
       
   407             KBearer,
       
   408             bearer,
       
   409             status );
       
   410     User::WaitForRequest( status );
       
   411     if ( status.Int() == KErrNone )
       
   412         {
       
   413         // We are only interested in WLAN connections. 
       
   414         WlanQtUtilsBearerType bearerType = connMon2WlanQtUtilsBearerTypeMap( bearer );
       
   415         if ( bearerType == WlanQtUtilsBearerTypeWlan )
       
   416             {
       
   417             activeConn = new WlanQtUtilsActiveConn();
       
   418             activeConn->setConnectionId( connectionId );
       
   419             activeConn->setBearerType( bearerType );
       
   420             activeConnInfoUpdate( activeConn );
       
   421             }
       
   422         }
       
   423 
       
   424     OstTraceFunctionExit1( CONNMONCONNINFO_CONNECTIONINFO_EXIT, this );
       
   425     return activeConn;
       
   426     }
       
   427 
       
   428 // ---------------------------------------------------------
       
   429 // ConnMonConnInfo::activeConnInfoUpdate()
       
   430 // Requests active connection info from Connection Monitor Server
       
   431 // ---------------------------------------------------------
       
   432 //
       
   433 // TODO: divide this function into smaller pieces depending on the need.
       
   434 // TODO: optimize so that all the information is not always requested from connmon.
       
   435 //       Only information that is missing is requested.
       
   436 void ConnMonConnInfo::activeConnInfoUpdate( WlanQtUtilsActiveConn *activeConn )
       
   437     {
       
   438     OstTraceFunctionEntry1( CONNMONCONNINFO_ACTIVECONNINFOUPDATE_ENTRY, this );
       
   439     
       
   440     Q_ASSERT( activeConn != NULL );
       
   441     Q_ASSERT( activeConn->bearerType() != WlanQtUtilsBearerTypeNone );
       
   442 
       
   443     TUint connectionId = activeConn->connectionId();
       
   444     TRequestStatus status;
       
   445 
       
   446     // Get connection IAP ID.
       
   447     TUint iapId = 0;
       
   448     iMonitor.GetUintAttribute(
       
   449             connectionId,
       
   450             0,
       
   451             KIAPId,
       
   452             iapId,
       
   453             status );
       
   454     User::WaitForRequest( status );
       
   455     if ( status.Int() == KErrNone )
       
   456         {
       
   457         activeConn->setIapId( iapId );
       
   458         }
       
   459 
       
   460     // Get connection status.
       
   461     TInt connectionStatus = 0;
       
   462     iMonitor.GetIntAttribute(
       
   463             connectionId,
       
   464             0,
       
   465             KConnectionStatus,
       
   466             connectionStatus,
       
   467             status );
       
   468     User::WaitForRequest( status );
       
   469     if ( status.Int() == KErrNone ) {
       
   470         activeConn->setConnectionStatus( connMon2WlanQtUtilsConnectionStatusMap( connectionStatus ) );
       
   471     }
       
   472 
       
   473     OstTraceFunctionExit1( CONNMONCONNINFO_ACTIVECONNINFOUPDATE_EXIT, this );
       
   474     }
       
   475 
       
   476 // ---------------------------------------------------------
       
   477 // ConnMonConnInfo::connMon2WlanQtUtilsConnectionStatusMap()
       
   478 // Maps connection status of Connection Monitor Server to connection
       
   479 // status of Wlan Qt Utilities.
       
   480 // ---------------------------------------------------------
       
   481 //
       
   482 WlanQtUtilsConnectionStatus ConnMonConnInfo::connMon2WlanQtUtilsConnectionStatusMap( TInt aConnectionStatus )
       
   483     {    
       
   484     // TODO: This mapping is not specific to current status which is unknown to wrapper.
       
   485     // TODO: This is only current implementation and will need serious modifications and
       
   486     //       verification from connmon guys.
       
   487     WlanQtUtilsConnectionStatus connUtilsConnectionStatus = WlanQtUtilsConnectionStatusNone;
       
   488     switch (aConnectionStatus)
       
   489         {
       
   490         // KConnectionOpen is not final status for WLAN, because DHCP is run after that
       
   491         case KConnectionOpen:
       
   492         case KStartingConnection:
       
   493             connUtilsConnectionStatus = WlanQtUtilsConnectionStatusConnecting;
       
   494             break;
       
   495         case KLinkLayerOpen:
       
   496             connUtilsConnectionStatus = WlanQtUtilsConnectionStatusConnected;
       
   497             break;
       
   498         case KConnectionClosed:
       
   499         case KLinkLayerClosed:
       
   500             connUtilsConnectionStatus = WlanQtUtilsConnectionStatusDisconnected;
       
   501             break;
       
   502         default:
       
   503             // Ignore all other values
       
   504             connUtilsConnectionStatus = WlanQtUtilsConnectionStatusNone;
       
   505             break;
       
   506         }
       
   507     
       
   508     return connUtilsConnectionStatus;
       
   509     }
       
   510 
       
   511 // ---------------------------------------------------------
       
   512 // ConnMonConnInfo::connMon2WlanQtUtilsBearerTypeMap()
       
   513 // Maps bearer type of Connection Monitor Server to bearer
       
   514 // type of Wlan Qt Utilities.
       
   515 // ---------------------------------------------------------
       
   516 //
       
   517 WlanQtUtilsBearerType ConnMonConnInfo::connMon2WlanQtUtilsBearerTypeMap( TInt aBearerType )
       
   518     {    
       
   519     WlanQtUtilsBearerType connUtilsBearerType = WlanQtUtilsBearerTypeNone;
       
   520     switch ( aBearerType ) {
       
   521     case EBearerWCDMA:
       
   522     case EBearerGPRS:
       
   523     case EBearerEdgeGPRS:
       
   524         connUtilsBearerType = WlanQtUtilsBearerTypeCellular;
       
   525         break;
       
   526     case EBearerWLAN:
       
   527         connUtilsBearerType = WlanQtUtilsBearerTypeWlan;
       
   528         break;
       
   529     default:
       
   530         break;
       
   531     }
       
   532 
       
   533     return connUtilsBearerType;
       
   534     }
       
   535 
       
   536 /*!
       
   537     Checks the bearer of given connection.
       
   538     Meant for filtering handling only for WLAN IAP's.
       
   539     
       
   540     @param [in] connectionId Connection ID.
       
   541     
       
   542     @return Returns true if connection a WLAN connection, otherwise false. 
       
   543 */
       
   544 
       
   545 bool ConnMonConnInfo::isWlan(uint connectionId)
       
   546 {
       
   547     bool result = false;
       
   548     TRequestStatus status;
       
   549 
       
   550     TInt bearer = 0;
       
   551     iMonitor.GetIntAttribute(
       
   552         connectionId,
       
   553         0,
       
   554         KBearer,
       
   555         bearer,
       
   556         status);
       
   557     User::WaitForRequest(status);
       
   558 
       
   559     if (status.Int() == KErrNone && bearer == EBearerWLAN) {
       
   560         result = true;
       
   561     }
       
   562     
       
   563     return result;
       
   564 }
       
   565 
       
   566 // ---------------------------------------------------------
       
   567 // ConnMonConnDisconnect::ConnMonConnDisconnect()
       
   568 // Constructor
       
   569 // ---------------------------------------------------------
       
   570 //
       
   571 ConnMonConnDisconnect::ConnMonConnDisconnect(ConMonWrapper *wrapper) :
       
   572     CActive(EPriorityStandard), q_ptr(wrapper)
       
   573     {
       
   574     OstTraceFunctionEntry1( CONNMONCONNDISCONNECT_CONNMONCONNDISCONNECT_ENTRY, this );
       
   575     
       
   576     CActiveScheduler::Add(this);
       
   577     iMonitor.ConnectL();
       
   578 
       
   579     OstTraceFunctionExit1( CONNMONCONNDISCONNECT_CONNMONCONNDISCONNECT_EXIT, this );
       
   580     }
       
   581 
       
   582 // ---------------------------------------------------------
       
   583 // ConnMonConnDisconnect::ConnMonConnDisconnect()
       
   584 // Destructor
       
   585 // ---------------------------------------------------------
       
   586 //
       
   587 ConnMonConnDisconnect::~ConnMonConnDisconnect()
       
   588     {
       
   589     OstTraceFunctionEntry1( CONNMONCONNDISCONNECT_CONNMONCONNDISCONNECTDESTR_ENTRY, this );
       
   590 
       
   591     // Cancel notifications and close connection monitor session
       
   592     //iMonitor.CancelNotifications();
       
   593     iMonitor.Close();
       
   594     
       
   595     OstTraceFunctionExit1( CONNMONCONNDISCONNECT_CONNMONCONNDISCONNECTDESTR_EXIT, this );
       
   596     }
       
   597 
       
   598 // ---------------------------------------------------------
       
   599 // ConnMonConnDisconnect::DoCancel()
       
   600 // 
       
   601 // ---------------------------------------------------------
       
   602 //
       
   603 void ConnMonConnDisconnect::DoCancel()
       
   604     {
       
   605     OstTraceFunctionEntry1( CONNMONCONNDISCONNECT_DOCANCEL_ENTRY, this );
       
   606     // TODO: error handling
       
   607     OstTraceFunctionExit1( CONNMONCONNDISCONNECT_DOCANCEL_EXIT, this );
       
   608     }
       
   609 
       
   610 // ---------------------------------------------------------
       
   611 // ConnMonConnDisconnect::RunL()
       
   612 // 
       
   613 // ---------------------------------------------------------
       
   614 //
       
   615 void ConnMonConnDisconnect::RunL()
       
   616     {
       
   617     OstTraceFunctionEntry1( CONNMONCONNDISCONNECT_RUNL_ENTRY, this );
       
   618     // TODO: Is anything needed? 
       
   619     OstTraceFunctionExit1( CONNMONCONNDISCONNECT_RUNL_EXIT, this );
       
   620     }
       
   621 
       
   622 // ---------------------------------------------------------
       
   623 // ConnMonConnDisconnect::disconnectConnection(int iapId)
       
   624 // Stop active connection.
       
   625 // ---------------------------------------------------------
       
   626 //
       
   627 void ConnMonConnDisconnect::disconnectConnection(int iapId)
       
   628     {
       
   629     OstTraceFunctionEntry1( CONNMONCONNDISCONNECT_DISCONNECTCONNECTION_ENTRY, this );
       
   630     OstTrace1(
       
   631         TRACE_NORMAL,
       
   632         CONNMONCONNDISCONNECT_DISCONNECTCONNECTION,
       
   633         "ConnMonConnDisconnect::disconnectConnection;iapId=%d", iapId );
       
   634 
       
   635     // TODO: Error handling
       
   636     TUint count;
       
   637     TRequestStatus status;
       
   638     iMonitor.GetConnectionCount(count, status);
       
   639     User::WaitForRequest(status);
       
   640 
       
   641     for (TInt i = 1; i <= count; i++)
       
   642         {
       
   643         TUint numSubConnections;
       
   644         TUint iap = 0;
       
   645         TUint connectionId = 0;
       
   646         TInt ret = iMonitor.GetConnectionInfo(i, connectionId,
       
   647                 numSubConnections);
       
   648         if (ret != KErrNone)
       
   649             {
       
   650             // error
       
   651             }
       
   652         iMonitor.GetUintAttribute(connectionId, 0, KIAPId, iap, status);
       
   653         User::WaitForRequest(status);
       
   654         if (status.Int() != KErrNone)
       
   655             {
       
   656             // error  
       
   657             }
       
   658         if (iap == iapId)
       
   659             {
       
   660             TInt KErr = iMonitor.SetBoolAttribute(connectionId, 0,
       
   661                     KConnectionStop, ETrue);
       
   662             }
       
   663         }
       
   664 
       
   665     OstTraceFunctionExit1( CONNMONCONNDISCONNECT_DISCONNECTCONNECTION_EXIT, this );
       
   666     }