bearermanagement/mpm/src/mpmserver.cpp
branchRCL_3
changeset 24 05bc53fe583b
parent 23 fc7b30ed2058
child 25 83ca720e2b9a
equal deleted inserted replaced
23:fc7b30ed2058 24:05bc53fe583b
     1 /*
     1 /*
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). 
     2 * Copyright (c) 2004-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".
    32 #include "mpmserversession.h"
    32 #include "mpmserversession.h"
    33 #include "mpmconnmonevents.h"
    33 #include "mpmconnmonevents.h"
    34 #include "mpmlogger.h"
    34 #include "mpmlogger.h"
    35 #include "mpmdtmwatcher.h"
    35 #include "mpmdtmwatcher.h"
    36 #include "mpmroamingwatcher.h"
    36 #include "mpmroamingwatcher.h"
    37 #include "mpmdisconnectdlg.h"
       
    38 #include "mpmconfirmdlgroaming.h"
    37 #include "mpmconfirmdlgroaming.h"
    39 #include "mpmconfirmdlgstarting.h"
    38 #include "mpmconfirmdlgstarting.h"
    40 #include "mpmdefaultconnection.h"
       
    41 #include "mpmcommsdataccess.h"
    39 #include "mpmcommsdataccess.h"
    42 #include "mpmwlanquerydialog.h"
       
    43 #include "mpmdialog.h"
       
    44 #include "mpmprivatecrkeys.h"
    40 #include "mpmprivatecrkeys.h"
    45 #include "mpmcsidwatcher.h"
    41 #include "mpmcsidwatcher.h"
       
    42 #include "mpmvpntogglewatcher.h"
    46 #include "mpmdatausagewatcher.h"
    43 #include "mpmdatausagewatcher.h"
    47 #include "mpmpropertydef.h"
    44 #include "mpmpropertydef.h"
    48 #include "mpmofflinewatcher.h"
       
    49 #include "mpmconnpermquerytimer.h"
    45 #include "mpmconnpermquerytimer.h"
    50 
    46 
       
    47 static const TUint32 KUidKmdServer = 0x1000088A;
       
    48     
    51 // ============================= LOCAL FUNCTIONS ===============================
    49 // ============================= LOCAL FUNCTIONS ===============================
    52 
    50 
    53 // -----------------------------------------------------------------------------
    51 // -----------------------------------------------------------------------------
    54 // PanicServer 
    52 // PanicServer 
    55 // Panics the server in case of programming error.
    53 // Panics the server in case of programming error.
    85     : CPolicyServer( CPolicyServer::EPriorityStandard, KMPMPolicy ),
    83     : CPolicyServer( CPolicyServer::EPriorityStandard, KMPMPolicy ),
    86       iEvents( NULL ), 
    84       iEvents( NULL ), 
    87       iTSYLoaded( EFalse ),
    85       iTSYLoaded( EFalse ),
    88       iPacketServLoaded( EFalse ), 
    86       iPacketServLoaded( EFalse ), 
    89       iDtmWatcher( NULL ), 
    87       iDtmWatcher( NULL ), 
       
    88       iRoamingWatcher( NULL ),
    90       iWLANScanRequired( EFalse ), 
    89       iWLANScanRequired( EFalse ), 
    91       iDisconnectQueue( NULL ), 
       
    92       iRoamingQueue( NULL ), 
    90       iRoamingQueue( NULL ), 
    93       iStartingQueue( NULL ),
    91       iStartingQueue( NULL ),
    94       iWlanQueryQueue( NULL ),
       
    95       iConnectDialogQueue( NULL ),
       
    96       iDefaultConnection( NULL ), 
       
    97       iConnectionCounter( 0 ),
    92       iConnectionCounter( 0 ),
    98       iOfflineMode( ECoreAppUIsNetworkConnectionAllowed )
    93       iUserConnection( EFalse ),
       
    94       iUserConnectionInInternet( EFalse ),
       
    95       iVpnUserConnectionSessionCount( 0 ),
       
    96       iMpmCsIdWatcher( NULL ),
       
    97       iMpmVpnToggleWatcher( NULL ),
       
    98       iMpmDataUsageWatcher( NULL ),
       
    99       iCommsDatAccess( NULL ),
       
   100       iConnUiUtils( NULL ),
       
   101       iOfflineMode( ECoreAppUIsNetworkConnectionAllowed ),
       
   102       iOfflineWlanQueryResponse( EOfflineResponseUndefined ),      
       
   103       iRoamingToWlanPeriodic( NULL ),
       
   104       iConnPermQueryTimer( NULL )
    99     {
   105     {
   100     }
   106     }
   101 
   107 
   102 
   108 
   103 // -----------------------------------------------------------------------------
   109 // -----------------------------------------------------------------------------
   154         }
   160         }
   155     
   161     
   156     iRoamingWatcher = CMPMRoamingWatcher::NewL(iMobilePhone);
   162     iRoamingWatcher = CMPMRoamingWatcher::NewL(iMobilePhone);
   157 
   163 
   158     iCommsDatAccess = CMPMCommsDatAccess::NewL( );
   164     iCommsDatAccess = CMPMCommsDatAccess::NewL( );
   159     
       
   160     iDisconnectQueue = new ( ELeave ) CArrayPtrFlat<CMPMDisconnectDlg>( KGranularity );
       
   161     iDisconnectQueue->Reset();
       
   162 
   165 
   163     iRoamingQueue = new ( ELeave ) CArrayPtrFlat<CMPMConfirmDlgRoaming>( KGranularity );
   166     iRoamingQueue = new ( ELeave ) CArrayPtrFlat<CMPMConfirmDlgRoaming>( KGranularity );
   164     iRoamingQueue->Reset();
   167     iRoamingQueue->Reset();
   165 
   168 
   166     iStartingQueue = new ( ELeave ) CArrayPtrFlat<CMPMConfirmDlgStarting>( KGranularity ); 
   169     iStartingQueue = new ( ELeave ) CArrayPtrFlat<CMPMConfirmDlgStarting>( KGranularity ); 
   167     iStartingQueue->Reset();
   170     iStartingQueue->Reset();
   168 
       
   169     iWlanQueryQueue = new ( ELeave ) CArrayPtrFlat<CMPMWlanQueryDialog>( KGranularity );
       
   170     iWlanQueryQueue->Reset();
       
   171 
       
   172     iConnectDialogQueue = new ( ELeave ) CArrayPtrFlat<CMPMDialog>( KGranularity );
       
   173     iConnectDialogQueue->Reset();
       
   174     
       
   175     iDefaultConnection = CMPMDefaultConnection::NewL( this );    
       
   176 
   171 
   177     // Create central repository watcher and start it
   172     // Create central repository watcher and start it
   178     iMpmCsIdWatcher = CMpmCsIdWatcher::NewL();
   173     iMpmCsIdWatcher = CMpmCsIdWatcher::NewL();
   179     iMpmCsIdWatcher->StartL();
   174     iMpmCsIdWatcher->StartL();
       
   175     
       
   176     // Create VPN toggle central repository watcher and start it
       
   177     iMpmVpnToggleWatcher = CMpmVpnToggleWatcher::NewL( *this );
   180 
   178 
   181     // Create another central repository watcher and start it
   179     // Create another central repository watcher and start it
   182     TRAPD( duwErr, iMpmDataUsageWatcher = CMpmDataUsageWatcher::NewL( this ) );
   180     TRAPD( duwErr, iMpmDataUsageWatcher = CMpmDataUsageWatcher::NewL( this ) );
   183     if (duwErr == KErrNone)
   181     if (duwErr == KErrNone)
   184         {
   182         {
   188         {
   186         {
   189         iMpmDataUsageWatcher = NULL;
   187         iMpmDataUsageWatcher = NULL;
   190         MPMLOGSTRING( "CMPMServer::ConstructL: CMpmDataUsageWatcher::NewL() failed!" )
   188         MPMLOGSTRING( "CMPMServer::ConstructL: CMpmDataUsageWatcher::NewL() failed!" )
   191         }
   189         }
   192 
   190 
   193     // Create another central repository watcher and start it
       
   194     TRAPD( owErr, iMpmOfflineWatcher = CMpmOfflineWatcher::NewL( this ) );
       
   195     if (owErr == KErrNone)
       
   196         {
       
   197         iMpmOfflineWatcher->StartL();
       
   198         }
       
   199     else
       
   200         {
       
   201         iMpmOfflineWatcher = NULL;
       
   202         MPMLOGSTRING( "CMPMServer::ConstructL: CMpmOfflineWatcher::NewL() failed!" )
       
   203         }
       
   204 
       
   205     // Define P&S keys (snap & iap) for the user connection
       
   206     TInt ret = RProperty::Define( KMPMUserConnectionCategory,
       
   207                                   KMPMPSKeyUserConnectionSnap,
       
   208                                   KMPMUserConnectionSnapType,
       
   209                                   KMPMUserConnectionReadPolicy,
       
   210                                   KMPMUserConnectionWritePolicy );
       
   211     
       
   212     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   213         {
       
   214         User::Leave(err);
       
   215         }
       
   216     
       
   217     ret = RProperty::Define( KMPMUserConnectionCategory,
       
   218                              KMPMPSKeyUserConnectionIap,
       
   219                              KMPMUserConnectionIapType,
       
   220                              KMPMUserConnectionReadPolicy,
       
   221                              KMPMUserConnectionWritePolicy );
       
   222                                           
       
   223     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   224         {
       
   225         User::Leave(err);
       
   226         }
       
   227 
       
   228     // Set initial values for the keys
       
   229     User::LeaveIfError(RProperty::Set( KMPMUserConnectionCategory,
       
   230                                        KMPMPSKeyUserConnectionSnap,
       
   231                                        0 ));
       
   232 
       
   233     User::LeaveIfError(RProperty::Set( KMPMUserConnectionCategory,
       
   234                                        KMPMPSKeyUserConnectionIap,
       
   235                                        0 ));
       
   236 
       
   237     // Read dedicated clients from the central repository
   191     // Read dedicated clients from the central repository
   238     CRepository* repository = CRepository::NewL( KCRUidMPM );
   192     CRepository* repository = CRepository::NewL( KCRUidMPM );
   239     
   193     
   240     CleanupStack::PushL( repository );
   194     CleanupStack::PushL( repository );
   241     
   195     
   242     TUint32 baseKey = KMpmDedicatedClientBase;
   196     TUint32 baseKey = KMpmDedicatedClientBase;
   243     TInt value;
   197     TInt value;
   244     ret = KErrNone;
   198     TInt ret = KErrNone;
   245     
   199     
   246     while ( ret == KErrNone )
   200     while ( ret == KErrNone )
   247         {
   201         {
   248         ret = repository->Get ( baseKey, value );
   202         ret = repository->Get ( baseKey, value );
   249 
   203 
   255 
   209 
   256         baseKey++;
   210         baseKey++;
   257         }
   211         }
   258     
   212     
   259     CleanupStack::PopAndDestroy ( repository );
   213     CleanupStack::PopAndDestroy ( repository );
   260     
       
   261     // Define P&S keys for the connection dialogs
       
   262     ret = RProperty::Define( KMPMActiveConnectionCategory,
       
   263                              KMPMPSKeyActiveConnectionIap,
       
   264                              KMPMActiveConnectionIapType,
       
   265                              KMPMActiveConnectionReadPolicy,
       
   266                              KMPMActiveConnectionWritePolicy );
       
   267     
       
   268     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   269         {
       
   270         User::Leave(err);
       
   271         }
       
   272     
       
   273     ret = RProperty::Define( KMPMActiveConnectionCategory,
       
   274                              KMPMPSKeyActiveConnectionSnap,
       
   275                              KMPMActiveConnectionSnapType,
       
   276                              KMPMActiveConnectionReadPolicy,
       
   277                              KMPMActiveConnectionWritePolicy );
       
   278     
       
   279     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   280         {
       
   281         User::Leave(err);
       
   282         }
       
   283 
       
   284     ret = RProperty::Define( KMPMActiveConnectionCategory,
       
   285                              KMPMPSKeyActiveConnectionBearer,
       
   286                              KMPMActiveConnectionBearerType,
       
   287                              KMPMActiveConnectionReadPolicy,
       
   288                              KMPMActiveConnectionWritePolicy );
       
   289                                           
       
   290     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   291         {
       
   292         User::Leave(err);
       
   293         }
       
   294         
   214         
   295     PublishActiveConnection();
   215     iConnUiUtils = CConnectionUiUtilities::NewL();
   296     
       
   297     iRoamingToWlanPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
   298     iRoamingToHotspotWlanPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
   299             
       
   300     }
   216     }
   301 
   217 
   302 
   218 
   303 // -----------------------------------------------------------------------------
   219 // -----------------------------------------------------------------------------
   304 // CMPMServer::~CMPMServer
   220 // CMPMServer::~CMPMServer
   309 	if ( iRoamingToWlanPeriodic )
   225 	if ( iRoamingToWlanPeriodic )
   310         {
   226         {
   311         iRoamingToWlanPeriodic->Cancel();
   227         iRoamingToWlanPeriodic->Cancel();
   312 		delete iRoamingToWlanPeriodic;
   228 		delete iRoamingToWlanPeriodic;
   313         }
   229         }
   314     if ( iRoamingToHotspotWlanPeriodic )
       
   315         {
       
   316         iRoamingToHotspotWlanPeriodic->Cancel();
       
   317         delete iRoamingToHotspotWlanPeriodic;
       
   318         }
       
   319     if ( iDisconnectQueue )
       
   320         {
       
   321         iDisconnectQueue->ResetAndDestroy();
       
   322         }
       
   323     delete iDisconnectQueue;
       
   324 
       
   325     if ( iRoamingQueue )
   230     if ( iRoamingQueue )
   326         {
   231         {
   327         iRoamingQueue->ResetAndDestroy();
   232         iRoamingQueue->ResetAndDestroy();
   328         }
   233         }
   329     delete iRoamingQueue;
   234     delete iRoamingQueue;
   331     if ( iStartingQueue )
   236     if ( iStartingQueue )
   332         {
   237         {
   333         iStartingQueue->ResetAndDestroy();
   238         iStartingQueue->ResetAndDestroy();
   334         }
   239         }
   335     delete iStartingQueue;
   240     delete iStartingQueue;
   336 
       
   337     while ( iWlanQueryQueue && iWlanQueryQueue->Count() > 0 )
       
   338         {
       
   339         iWlanQueryQueue->Delete( 0 );
       
   340         }
       
   341     delete iWlanQueryQueue;
       
   342     
       
   343     if ( iConnectDialogQueue )
       
   344         {
       
   345         iConnectDialogQueue->ResetAndDestroy();
       
   346         }
       
   347     delete iConnectDialogQueue;
       
   348 
   241 
   349     delete iEvents;
   242     delete iEvents;
   350 
   243 
   351     for ( TInt i = 0; i < iBlackListIdList.Count(); i++ )
   244     for ( TInt i = 0; i < iBlackListIdList.Count(); i++ )
   352         {
   245         {
   366         }    
   259         }    
   367 
   260 
   368     iMobilePhone.Close();
   261     iMobilePhone.Close();
   369     iTelServer.Close();
   262     iTelServer.Close();
   370     
   263     
   371     delete iDefaultConnection;
       
   372     
       
   373     delete iMpmCsIdWatcher;    
   264     delete iMpmCsIdWatcher;    
   374     
   265        
       
   266     delete iMpmVpnToggleWatcher;
       
   267  
   375     delete iMpmDataUsageWatcher;    
   268     delete iMpmDataUsageWatcher;    
   376 
   269 
   377     delete iMpmOfflineWatcher;    
       
   378 
       
   379     iDedicatedClients.Close();
   270     iDedicatedClients.Close();
   380 
   271 
   381     delete iCommsDatAccess;
   272     delete iCommsDatAccess;
   382     
   273     
       
   274     delete iConnUiUtils;
       
   275     
   383     delete iConnPermQueryTimer;
   276     delete iConnPermQueryTimer;
   384     }
   277     }
   385 
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CMPMServer::SetVpnToggleValuesL
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CMPMServer::SetVpnToggleValuesL( const TBool aVpnPreferred,
       
   284                                       const TUint32 /*aVpnIapId*/,
       
   285                                       const TUint32 /*aSnapId*/ )
       
   286     {
       
   287     MPMLOGSTRING2("CMPMServer::SetVpnToggleValues, VPN connection preferred: %d",
       
   288             aVpnPreferred)
       
   289     if ( aVpnPreferred )
       
   290         {
       
   291         // Stop Internet connections, except if VPN user connection
       
   292         // would not be made with current preferences when reconnecting.
       
   293         for (TInt index = 0; index < iSessions.Count(); index++)
       
   294             {
       
   295             CMPMServerSession* session = iSessions[index];
       
   296             TUint32 iapId = GetBMIap( session->ConnectionId() );
       
   297             TUint32 snapId = GetBMSnap( session->ConnectionId() );
       
   298             
       
   299             if ( (session->ChooseBestIapCalled()) &&
       
   300                  (!session->IapSelectionL()->MpmConnPref().MandateIap()) &&
       
   301                  (session->AppUid() != KUidKmdServer) &&                 
       
   302                  (!session->UserConnection()) &&                 
       
   303                  iCommsDatAccess->IsInternetSnapL(iapId, snapId) )
       
   304                 {
       
   305                 // Stop connection.
       
   306                 MPMLOGSTRING2( "CMPMServer::SetVpnToggleValuesL: \
       
   307  Disconnected Connection Id = 0x%x", session->ConnectionId() )            
       
   308                 session->ClientErrorNotificationL(KErrForceDisconnected);
       
   309                 }
       
   310             }        
       
   311         }
       
   312     else
       
   313         {
       
   314         // Stop connections, which use VPN user connection.
       
   315         for (TInt index = 0; index < iSessions.Count(); index++)
       
   316             {
       
   317             CMPMServerSession* session = iSessions[index];
       
   318             if ( session->VpnUserConnectionUsed() )
       
   319                 {
       
   320                 session->SetVpnUserConnectionUsed( EFalse );                    
       
   321                 // Stop connection.
       
   322                 MPMLOGSTRING2( "CMPMServer::SetVpnToggleValuesL: \
       
   323  Disconnected Connection Id = 0x%x", session->ConnectionId() )            
       
   324                 session->ClientErrorNotificationL(KErrForceDisconnected);
       
   325                 }
       
   326             }
       
   327         ASSERT( iVpnUserConnectionSessionCount == 0 );
       
   328         }    
       
   329     }
   386 
   330 
   387 // -----------------------------------------------------------------------------
   331 // -----------------------------------------------------------------------------
   388 // CMPMServer::NewSessionL
   332 // CMPMServer::NewSessionL
   389 // -----------------------------------------------------------------------------
   333 // -----------------------------------------------------------------------------
   390 //
   334 //
   471             iActiveBMConns[index1].iConnInfo.iState = aState;
   415             iActiveBMConns[index1].iConnInfo.iState = aState;
   472             iActiveBMConns[index1].iConnInfo.iAppUid = aSession.AppUid();
   416             iActiveBMConns[index1].iConnInfo.iAppUid = aSession.AppUid();
   473             }
   417             }
   474         }
   418         }
   475 
   419 
   476     if ( aState == EStarted && aSession.ChooseBestIapCalled() )
       
   477         {
       
   478         UpdateActiveConnection( aSession );
       
   479         }
       
   480 
       
   481 #ifdef _DEBUG
   420 #ifdef _DEBUG
   482     // Dump array of active connections to log in order to support testing.
   421     // Dump array of active connections to log in order to support testing.
   483     // 
   422     // 
   484     DumpActiveBMConns();
   423     DumpActiveBMConns();
   485 #endif // _DEBUG
   424 #endif // _DEBUG
   490 // CMPMServer::ResetBMConnection
   429 // CMPMServer::ResetBMConnection
   491 // -----------------------------------------------------------------------------
   430 // -----------------------------------------------------------------------------
   492 //
   431 //
   493 void CMPMServer::ResetBMConnection( const TConnectionId aConnId,
   432 void CMPMServer::ResetBMConnection( const TConnectionId aConnId,
   494                                     const TUint32       aIapId,
   433                                     const TUint32       aIapId,
   495                                     CMPMServerSession&  aSession )
   434                                     CMPMServerSession&  /*aSession*/ )
   496     {
   435     {
   497     MPMLOGSTRING3(
   436     MPMLOGSTRING3(
   498         "CMPMServer::ResetBMConnection - aConnId = 0x%x, aIapId = %i", 
   437         "CMPMServer::ResetBMConnection - aConnId = 0x%x, aIapId = %i", 
   499         aConnId, aIapId )
   438         aConnId, aIapId )
   500 
   439 
   526         // relationship in a database entry and that this entry survives 
   465         // relationship in a database entry and that this entry survives 
   527         // a roaming event (an ApplicationLeavesConnection call).
   466         // a roaming event (an ApplicationLeavesConnection call).
   528         //
   467         //
   529         iActiveBMConns[index1].iConnInfo.iIapId = 0;
   468         iActiveBMConns[index1].iConnInfo.iIapId = 0;
   530         iActiveBMConns[index1].iConnInfo.iState = EIdle;
   469         iActiveBMConns[index1].iConnInfo.iState = EIdle;
   531         
       
   532         // Change state of P&S keys if needed
       
   533         if ( aSession.ChooseBestIapCalled() )
       
   534             {
       
   535             UpdateActiveConnection( aSession );
       
   536             }
       
   537         }
   470         }
   538 #ifdef _DEBUG
   471 #ifdef _DEBUG
   539     // Dump array of active connections to log in order to support testing.
   472     // Dump array of active connections to log in order to support testing.
   540     // 
   473     // 
   541     DumpActiveBMConns();
   474     DumpActiveBMConns();
   546 // -----------------------------------------------------------------------------
   479 // -----------------------------------------------------------------------------
   547 // CMPMServer::RemoveBMConnection
   480 // CMPMServer::RemoveBMConnection
   548 // -----------------------------------------------------------------------------
   481 // -----------------------------------------------------------------------------
   549 //
   482 //
   550 void CMPMServer::RemoveBMConnection( const TConnectionId aConnId,
   483 void CMPMServer::RemoveBMConnection( const TConnectionId aConnId,
   551                                      CMPMServerSession&  aSession )
   484                                      CMPMServerSession&  /*aSession*/ )
   552     {
   485     {
   553     MPMLOGSTRING2( "CMPMServer::RemoveBMConnection - aConnId = 0x%x", 
   486     MPMLOGSTRING2( "CMPMServer::RemoveBMConnection - aConnId = 0x%x", 
   554         aConnId )
   487         aConnId )
   555 
   488 
       
   489     TInt count = iActiveBMConns.Count();
       
   490     
       
   491     // Decrement by one, because count is n, 
       
   492     // but indexes in array are 0 .. n-1.
       
   493     // 
       
   494     count--;
       
   495 
   556     // This time we are browsing the array from the end to the beginning, 
   496     // This time we are browsing the array from the end to the beginning, 
   557     // because removing one element from array affects index numbering.
   497     // because removing one element from array affects index numbering.
   558     // Decrement i by one, because count is n, but indexes in array are 0 .. n-1
   498     // 
   559     for ( TInt i = iActiveBMConns.Count() - 1; i >= 0; i-- )
   499     for ( TInt i = count; i >= 0; i-- )
   560         {
   500         {
   561         if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
   501         if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
   562             {
   502             {
   563             
       
   564             TInt closeIapId = iActiveBMConns[i].iConnInfo.iIapId;
       
   565             if ( !closeIapId )
       
   566                 {
       
   567                 TRAP_IGNORE( closeIapId = aSession.IapSelectionL()->MpmConnPref().IapId() );
       
   568                 }
       
   569 
       
   570             // If Connection Id found, remove it. 
   503             // If Connection Id found, remove it. 
       
   504             //
   571             iActiveBMConns.Remove( i );
   505             iActiveBMConns.Remove( i );
   572             
   506             }
   573             // Update active connection
   507         }
   574             if ( aSession.ChooseBestIapCalled() )
   508 
   575                 {
       
   576                 UpdateActiveConnection( aSession );
       
   577                 }
       
   578             
       
   579             CheckIapForDisconnect( closeIapId );
       
   580             }
       
   581         }
       
   582     
       
   583 #ifdef _DEBUG
   509 #ifdef _DEBUG
   584     // Dump array of active connections to log in order to support testing.
   510     // Dump array of active connections to log in order to support testing.
   585     // 
   511     // 
   586     DumpActiveBMConns();
   512     DumpActiveBMConns();
   587 #endif // _DEBUG
   513 #endif // _DEBUG
   596     MPMLOGSTRING2( "CMPMServer::GetBMIap - aConnId = 0x%x", aConnId )
   522     MPMLOGSTRING2( "CMPMServer::GetBMIap - aConnId = 0x%x", aConnId )
   597 
   523 
   598     TUint32 connectionIapId( 0 );
   524     TUint32 connectionIapId( 0 );
   599 
   525 
   600     // Set the Connection Id and SNAP
   526     // Set the Connection Id and SNAP
       
   527     // 
   601     TConnectionInfo connInfo;
   528     TConnectionInfo connInfo;
   602     connInfo.iConnId = aConnId;
   529     connInfo.iConnId = aConnId;
   603 
   530 
   604     TActiveBMConn conn;
   531     TActiveBMConn conn;
   605     conn.iConnInfo = connInfo;
   532     conn.iConnInfo = connInfo;
   607     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
   534     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
   608 
   535 
   609     if ( ( index1 != KErrNotFound ) && ( index1 < iActiveBMConns.Count() ) )
   536     if ( ( index1 != KErrNotFound ) && ( index1 < iActiveBMConns.Count() ) )
   610         {
   537         {
   611         // If connInfo found, set the Iap Id as connectionIapId
   538         // If connInfo found, set the Iap Id as connectionIapId
       
   539         //
   612         connectionIapId = iActiveBMConns[index1].iConnInfo.iIapId;
   540         connectionIapId = iActiveBMConns[index1].iConnInfo.iIapId;
   613         }
   541         }
   614 
   542 
   615     MPMLOGSTRING2( "CMPMServer::GetBMIap - connectionIapId = %i", 
   543     MPMLOGSTRING2( "CMPMServer::GetBMIap - connectionIapId = %i", 
   616         connectionIapId )
   544         connectionIapId )
   704         }
   632         }
   705 #endif // _DEBUG
   633 #endif // _DEBUG
   706     }
   634     }
   707 
   635 
   708 // -----------------------------------------------------------------------------
   636 // -----------------------------------------------------------------------------
   709 // CMPMServer::CheckUsageOfIap
   637 // CMPMServer::CheckIfStarted
   710 // -----------------------------------------------------------------------------
   638 // -----------------------------------------------------------------------------
   711 //
   639 //
   712 TConnectionState CMPMServer::CheckUsageOfIap( const TUint32 aIapId , 
   640 TBool CMPMServer::CheckIfStarted( const TUint32 aIapId , 
   713                                   const TConnectionId aOwnConnId )
   641                                   const TConnectionId aConnId )
   714     {
   642     {
   715     MPMLOGSTRING3( "CMPMServer::CheckUsageOfIap - aIapId = %i, aOwnConnId = 0x%x", 
   643     MPMLOGSTRING3( "CMPMServer::CheckIfStarted - aIapId = %i, aConnId = 0x%x", 
   716                   aIapId, aOwnConnId )
   644                   aIapId, aConnId )
   717 
   645 
   718     TConnectionState state = EIdle;
   646     TConnectionState state( EIdle );
       
   647     TBool stopLoop( EFalse );
   719 
   648 
   720     // Loop all connections until EStarted is found or no more connections
   649     // Loop all connections until EStarted is found or no more connections
   721     // 
   650     // 
   722     for ( TInt i = 0; i < iActiveBMConns.Count(); i++ )
   651     for ( TInt i = 0; ( ( i < iActiveBMConns.Count() ) && !stopLoop ); i++ )
   723         {
   652         {
   724         // Check if IAP Id matches; exclude matching with own connection
   653         // Check if IAP Id matches; exclude matching with own connection
   725         // 
   654         // 
   726         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId && 
   655         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId && 
   727              iActiveBMConns[i].iConnInfo.iConnId != aOwnConnId)
   656              iActiveBMConns[i].iConnInfo.iConnId != aConnId)
   728             {
   657             {
   729             state = iActiveBMConns[i].iConnInfo.iState;  
   658             state = iActiveBMConns[i].iConnInfo.iState;  
   730 
   659 
   731             // Stop looping if EStarted found
   660             // Stop looping if EStarted found
   732             // 
   661             // 
   733             if ( state == EStarted )
   662             if ( state == EStarted )
   734                 {
   663                 {
   735                 break; // Breaks the for loop
   664                 stopLoop = ETrue;
   736                 }
   665                 }
   737             }
   666             }
   738         }
   667         }
   739 
   668 
   740 #ifdef _DEBUG
   669 #ifdef _DEBUG
   741     switch( state )
   670     switch( state )
   742         {
   671         {
   743         case EStarting:
   672         case EStarting:
   744             {
   673             {
   745             MPMLOGSTRING( "CMPMServer::CheckUsageOfIap - Starting" )
   674             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Starting" )
   746             break;
   675             break;
   747             }
   676             }
   748         case EStarted:
   677         case EStarted:
   749             {
   678             {
   750             MPMLOGSTRING( "CMPMServer::CheckUsageOfIap - Started" )
   679             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Started" )
   751             break;
   680             break;
   752             }
   681             }
   753         case EIdle:
   682         case EIdle:
   754             {
   683             {
   755             MPMLOGSTRING( "CMPMServer::CheckUsageOfIap - Idle" )
   684             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Idle" )
   756             break;
   685             break;
   757             }
   686             }
   758         case ERoaming:
   687         case ERoaming:
   759             {
   688             {
   760             MPMLOGSTRING( "CMPMServer::CheckUsageOfIap - Roaming" )
   689             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Roaming" )
   761             break;
   690             break;
   762             }
   691             }
   763         default:
   692         default:
   764             {
   693             {
   765             MPMLOGSTRING( "CMPMServer::CheckUsageOfIap - Unknown" )
   694             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Unknown" )
   766             break;
   695             break;
   767             }
   696             }
   768         }
   697         }
   769 #endif // _DEBUG
   698 #endif // _DEBUG
   770         
   699         
   771     return state;
   700     //Return true incase the matching connection is in EStarting state also because
       
   701     //sometimes when connections are started simultaneously (for same iapID) 
       
   702     //the first connection may still be in EStarting state. 
       
   703     //
       
   704     if ( state == EStarted || state == EStarting )
       
   705         {
       
   706         return ETrue;
       
   707         }
       
   708     else
       
   709         {
       
   710         return EFalse;
       
   711         }
   772     }
   712     }
   773 
   713 
   774 // -----------------------------------------------------------------------------
   714 // -----------------------------------------------------------------------------
   775 // CMPMServer::IsWlanConnectionStartedL
   715 // CMPMServer::IsWlanConnectionStartedL
   776 // -----------------------------------------------------------------------------
   716 // -----------------------------------------------------------------------------
   848                 iActiveBMConns[i].iConnInfo.iState = EStarted;
   788                 iActiveBMConns[i].iConnInfo.iState = EStarted;
   849                 }
   789                 }
   850             }
   790             }
   851         }
   791         }
   852 
   792 
   853     if ( aSession.ChooseBestIapCalled() )
       
   854         {
       
   855         UpdateActiveConnection( aSession );
       
   856         }
       
   857 
       
   858 #ifdef _DEBUG
   793 #ifdef _DEBUG
   859     // Dump array of active connections to log in order to support testing.
   794     // Dump array of active connections to log in order to support testing.
   860     // 
   795     // 
   861     DumpActiveBMConns();
   796     DumpActiveBMConns();
   862 #endif // _DEBUG
   797 #endif // _DEBUG
   867 // CMPMServer::RemoveBMIAPConnection
   802 // CMPMServer::RemoveBMIAPConnection
   868 // -----------------------------------------------------------------------------
   803 // -----------------------------------------------------------------------------
   869 //
   804 //
   870 void CMPMServer::RemoveBMIAPConnection( const TUint32       aIapId, 
   805 void CMPMServer::RemoveBMIAPConnection( const TUint32       aIapId, 
   871                                         const TConnectionId aConnId,
   806                                         const TConnectionId aConnId,
   872                                         CMPMServerSession&  aSession )
   807                                         CMPMServerSession&  /*aSession*/ )
   873     {
   808     {
   874     MPMLOGSTRING3(
   809     MPMLOGSTRING3(
   875         "CMPMServer::RemoveBMIAPConnection - aIapId = %i, aConnId = 0x%x", 
   810         "CMPMServer::RemoveBMIAPConnection - aIapId = %i, aConnId = 0x%x", 
   876         aIapId, aConnId )
   811         aIapId, aConnId )
   877 
   812 
       
   813     TActiveBMConn conn;
       
   814     conn.iConnInfo.iIapId = aIapId;
       
   815 
   878     // The IAP connection lifetime is determined by the two calls 
   816     // The IAP connection lifetime is determined by the two calls 
   879     // IAPConnectionStarted and IAPConnectionStopped. 
   817     // IAPConnectionStarted and IAPConnectionStopped. 
       
   818     //
       
   819     TInt count = iActiveBMConns.Count();
       
   820 
       
   821     // Decrement by one, because count is n, 
       
   822     // but indexes in array are 0 .. n-1.
       
   823     // 
       
   824     count--;
   880 
   825 
   881     // This time we are browsing the array from the end to the beginning, 
   826     // This time we are browsing the array from the end to the beginning, 
   882     // because removing one element from array affects index numbering.
   827     // because removing one element from array affects index numbering.
   883     // Decrement i by one, because count is n, but indexes in array are 0 .. n-1
   828     // 
   884     for ( TInt i = iActiveBMConns.Count() - 1; i >= 0; i-- )
   829     for ( TInt i = count; i >= 0; i-- )
   885         {
   830         {
   886         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId )
   831         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId )
   887             {
   832             {
   888             if ( iActiveBMConns[i].iConnInfo.iSnap == 0 )
   833             if ( iActiveBMConns[i].iConnInfo.iSnap == 0 )
   889                 {
   834                 {
   903                     {
   848                     {
   904                     iActiveBMConns[i].iConnInfo.iIapId = 0;
   849                     iActiveBMConns[i].iConnInfo.iIapId = 0;
   905                     iActiveBMConns[i].iConnInfo.iState = EIdle;
   850                     iActiveBMConns[i].iConnInfo.iState = EIdle;
   906                     }
   851                     }
   907                 }
   852                 }
   908             
       
   909             // Update active connection
       
   910             if ( aSession.ChooseBestIapCalled() )
       
   911                 {
       
   912                 UpdateActiveConnection( aSession );
       
   913                 }
       
   914             }
   853             }
   915         }
   854         }
   916 
   855 
   917 #ifdef _DEBUG
   856 #ifdef _DEBUG
   918     // Dump array of active connections to log in order to support testing.
   857     // Dump array of active connections to log in order to support testing.
   962                                    const TPrefIAPNotifCaller aCaller )
   901                                    const TPrefIAPNotifCaller aCaller )
   963     {
   902     {
   964     MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIapL - IAPs count: %d", 
   903     MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIapL - IAPs count: %d", 
   965         aIapInfo.iCount)
   904         aIapInfo.iCount)
   966     TConnMonIapInfo iapInfo = aIapInfo;
   905     TConnMonIapInfo iapInfo = aIapInfo;
   967     iConnMonIapInfo = aIapInfo;
   906     
   968 #ifdef _DEBUG
   907 #ifdef _DEBUG
   969     for (TUint i = 0; i < iapInfo.Count(); i++)
   908     for (TUint i = 0; i < iapInfo.Count(); i++)
   970         {
   909         {
   971         MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIap - IAP: %d", 
   910         MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIap - IAP: %d", 
   972             iapInfo.iIap[i].iIapId) 
   911             iapInfo.iIap[i].iIapId) 
   973         }
   912         }
   974 #endif // _DEBUG
   913 #endif // _DEBUG
   975 
   914 
   976     // Read info for forced roaming from Commdat
       
   977     TUint32 maxOpenTransAttempts ( KMaxOpenTransAttempts ) ;
       
   978     TUint32 retryAfter ( KRetryAfter );
       
   979     TInt err;
       
   980     // CommDat reading might fail because CommDat session could be locked by another process at the moment
       
   981     // So, we may wait/retry to read from CommDat a bit later.
       
   982     TCmUsageOfWlan usageOfWlan ( ECmUsageOfWlanKnown );
       
   983     do
       
   984         {
       
   985         TRAP ( err, usageOfWlan = CommsDatAccess()->ForcedRoamingL() );
       
   986         
       
   987         if( err )
       
   988             {
       
   989             User::After( retryAfter );
       
   990             }
       
   991         } while( err && maxOpenTransAttempts-- );
       
   992     
       
   993     // Start possible forced roaming
   915     // Start possible forced roaming
   994     if ( !err )
   916     TCmUsageOfWlan usageOfWlan = CommsDatAccess()->ForcedRoamingL();
   995         {
   917     if ( usageOfWlan == ECmUsageOfWlanKnown || usageOfWlan == ECmUsageOfWlanKnownAndNew )
   996         if ( usageOfWlan == ECmUsageOfWlanKnown || usageOfWlan == ECmUsageOfWlanKnownAndNew )
   918         {
   997             {
   919         if ( IsWlanConnectionStartedL( CommsDatAccess() ) )
   998             if ( IsWlanConnectionStartedL( CommsDatAccess() ) )
   920             {
       
   921             iConnMonIapInfo = aIapInfo;
       
   922                 
       
   923             if ( iRoamingToWlanPeriodic )
   999                 {
   924                 {
  1000                 iRoamingToWlanPeriodic->Cancel();
   925                 iRoamingToWlanPeriodic->Cancel();
  1001                 iRoamingToHotspotWlanPeriodic->Cancel();
       
  1002                         
       
  1003                 // Start periodic object that calls StartForcedRoamingToWlanL after 10s. 
       
  1004                 // this handles the case when new wlan connection is 
       
  1005                 // started from e.g. wlan sniffer but IAP is not yet in Internet SNAP 
       
  1006                 iRoamingToWlanPeriodic->Start( 
       
  1007                         TTimeIntervalMicroSeconds32( KRoamingToWlanUpdateInterval ), 
       
  1008                         TTimeIntervalMicroSeconds32( KRoamingToWlanUpdateInterval ), 
       
  1009                         TCallBack( StartForcedRoamingToConnectedWlanL, this ) );
       
  1010                 
       
  1011                 // Start periodic object that calls StartForcedRoamingToWlanL after 120s. 
       
  1012                 // this handles the case when new captive portal hotspot wlan 
       
  1013                 // connection is started. IAP will be moved to Internet SNAP after 
       
  1014                 // successful login only. 
       
  1015                 iRoamingToHotspotWlanPeriodic->Start( 
       
  1016                         TTimeIntervalMicroSeconds32( KRoamingToHotspotWlanUpdateInterval ), 
       
  1017                         TTimeIntervalMicroSeconds32( KRoamingToHotspotWlanUpdateInterval ), 
       
  1018                         TCallBack( StartForcedRoamingToConnectedHotspotWlanL, this ) );
       
  1019                 }
   926                 }
  1020             else
   927             else
  1021                 {
   928                 {
  1022                 StartForcedRoamingToWlanL( iapInfo );
   929                 iRoamingToWlanPeriodic = CPeriodic::NewL( 
  1023                 }
   930                                                    CActive::EPriorityStandard );
  1024 
   931                 }
  1025             StartForcedRoamingFromWlanL( iapInfo );
   932             // start periodic object that calls StartForcedRoamingToWlanL after 10s. 
  1026             }
   933             // this handles the case when new wlan connection is 
  1027         }
   934             // started from e.g. wlan sniffer but IAP is not yet in Internet SNAP 
  1028     else
   935             iRoamingToWlanPeriodic->Start( 
  1029         {
   936                    TTimeIntervalMicroSeconds32( KRoamingToWlanUpdateInterval ), 
  1030         MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIapL - \
   937                    TTimeIntervalMicroSeconds32( KRoamingToWlanUpdateInterval ), 
  1031 reading info for forced roaming fails with err %d, forced roaming fails", err )
   938                    TCallBack( StartForcedRoamingToConnectedWlanL, this ) );
       
   939             }
       
   940         else
       
   941             {
       
   942             StartForcedRoamingToWlanL( iapInfo );
       
   943             }
       
   944 
       
   945         StartForcedRoamingFromWlanL( iapInfo );
  1032         }
   946         }
  1033     
   947     
  1034     MPMLOGSTRING2(
   948     MPMLOGSTRING2(
  1035     "CMPMServer::NotifyBMPrefIapL - Send notifications for %d sessions", 
   949     "CMPMServer::NotifyBMPrefIapL - Send notifications for %d sessions", 
  1036         iSessions.Count() )
   950         iSessions.Count() )
  1037 
   951 
  1038     for ( TInt i = 0; i < iSessions.Count(); i++ )
   952     for ( TInt i = 0; i < iSessions.Count(); i++ )
  1039         {
   953         {
  1040         iapInfo = iSessions[i]->GetAvailableIAPs( );
   954         iapInfo = iSessions[i]->GetAvailableIAPs( );
  1041         iSessions[i]->PrefIAPNotificationL( iapInfo, aCaller );
   955         iSessions[i]->PrefIAPNotificationL( iapInfo, aCaller );
  1042         }
       
  1043 
       
  1044     // If a session is displaying connection selection dialog 
       
  1045     // the contents of the dialog should be updated according to the 
       
  1046     // current iap availability
       
  1047     //
       
  1048     for ( TInt i( 0 ); i < iSessions.Count(); i++ )
       
  1049         {
       
  1050         iSessions[i]->UpdateConnectionDialogL();
       
  1051         }
       
  1052     }
       
  1053 
       
  1054 // -----------------------------------------------------------------------------
       
  1055 // CMPMServer::UpdateSessionConnectionDlgL
       
  1056 // -----------------------------------------------------------------------------
       
  1057 //
       
  1058 void CMPMServer::UpdateSessionConnectionDlgL()
       
  1059     {
       
  1060     MPMLOGSTRING( "CMPMServer::UpdateSessionConnectionDlgL" )
       
  1061 
       
  1062     // If a session is displaying connection selection dialog 
       
  1063     // the contents of the dialog should be updated according to the 
       
  1064     // current iap availability
       
  1065     //
       
  1066     for ( TInt i( 0 ); i < iSessions.Count(); i++ )
       
  1067         {
       
  1068         iSessions[i]->UpdateConnectionDialogL();
       
  1069         }
       
  1070     }
       
  1071 
       
  1072 
       
  1073 // -----------------------------------------------------------------------------
       
  1074 // CMPMServer::HandlePendingMsgs
       
  1075 // -----------------------------------------------------------------------------
       
  1076 //
       
  1077 void CMPMServer::HandlePendingMsgs( TUint            aIapId,
       
  1078                                     TInt             aError, 
       
  1079                                     TInt*            aErrorReturned,
       
  1080                                     TBMNeededAction* aNeededAction )
       
  1081     {
       
  1082     MPMLOGSTRING3( "CMPMServer::HandlePendingMsgs aError = %d iapId = %d", 
       
  1083                    aError, aIapId )
       
  1084 
       
  1085     for ( TInt i( 0 ); i < iSessions.Count(); i++ )
       
  1086         {
       
  1087         // Read the Connection Id of the application
       
  1088         TConnectionId connId = iSessions[i]->ConnectionId();
       
  1089 
       
  1090         // Get the current connection IapId for this connId 
       
  1091         TUint32 currentIap = iSessions[i]->MyServer().GetBMIap( connId );
       
  1092 
       
  1093         MPMLOGSTRING2( "Session IapId = %d", currentIap );
       
  1094 
       
  1095         if ( currentIap == aIapId && !iSessions[i]->ChooseBestIapCalled() )
       
  1096             {
       
  1097             iSessions[i]->ProcessErrorComplete( aError, 
       
  1098                                                 aErrorReturned, 
       
  1099                                                 aNeededAction );
       
  1100             }
       
  1101         }
   956         }
  1102     }
   957     }
  1103 
   958 
  1104 
   959 
  1105 // -----------------------------------------------------------------------------
   960 // -----------------------------------------------------------------------------
  1196 reset Connection Id blacklisted iap list" )
  1051 reset Connection Id blacklisted iap list" )
  1197 
  1052 
  1198             connIdInfo.Close();
  1053             connIdInfo.Close();
  1199             return KErrNone;
  1054             return KErrNone;
  1200             }
  1055             }
  1201         
  1056 
  1202         found = EFalse;
  1057         found = EFalse;
  1203         for (TInt j = 0; j < connIdInfo.Count(); j++)
  1058         for (TInt j = 0; j < connIdInfo.Count(); j++)
  1204             {
  1059             {
  1205             if ( connIdInfo.Iap( j ) == aIapId )
  1060             if ( connIdInfo.Iap( j ) == aIapId )
  1206                 {
  1061                 {
  1539 
  1394 
  1540     MPMLOGSTRING( "Display array of active connections - End" )
  1395     MPMLOGSTRING( "Display array of active connections - End" )
  1541 #endif // _DEBUG
  1396 #endif // _DEBUG
  1542     }
  1397     }
  1543 
  1398 
  1544 
       
  1545 // -----------------------------------------------------------------------------
       
  1546 // CMPMServer::DefaultConnection
       
  1547 // -----------------------------------------------------------------------------
       
  1548 //
       
  1549 CMPMDefaultConnection* CMPMServer::DefaultConnection()
       
  1550     {
       
  1551     MPMLOGSTRING( "CMPMServer::DefaultConnection:\
       
  1552  Default Connection" )
       
  1553     return iDefaultConnection;
       
  1554     }
       
  1555 
       
  1556 // -----------------------------------------------------------------------------
  1399 // -----------------------------------------------------------------------------
  1557 // CMPMServer::StartedConnectionExists
  1400 // CMPMServer::StartedConnectionExists
  1558 // -----------------------------------------------------------------------------
  1401 // -----------------------------------------------------------------------------
  1559 //
  1402 //
  1560 TInt CMPMServer::StartedConnectionExists( TInt aIapId )
  1403 TInt CMPMServer::StartedConnectionExists( TInt aIapId )
  1585         return KErrNotFound;
  1428         return KErrNotFound;
  1586         }
  1429         }
  1587     }
  1430     }
  1588 
  1431 
  1589 // -----------------------------------------------------------------------------
  1432 // -----------------------------------------------------------------------------
  1590 // CMPMServer::AppendWlanQueryQueueL
       
  1591 // -----------------------------------------------------------------------------
       
  1592 //
       
  1593 void CMPMServer::AppendWlanQueryQueueL( CMPMWlanQueryDialog* aDlg )
       
  1594     {
       
  1595     if( aDlg )
       
  1596         {
       
  1597         iWlanQueryQueue->AppendL( aDlg );
       
  1598         }
       
  1599     else
       
  1600         {
       
  1601         MPMLOGSTRING( "CMPMServer::AppendWlanQueryQueueL argument NULL, Error" )
       
  1602         }
       
  1603     }
       
  1604 
       
  1605 // -----------------------------------------------------------------------------
       
  1606 // CMPMServer::StopConnections
  1433 // CMPMServer::StopConnections
  1607 // -----------------------------------------------------------------------------
  1434 // -----------------------------------------------------------------------------
  1608 //
  1435 //
  1609 void CMPMServer::StopConnections( TInt aIapId )
  1436 void CMPMServer::StopConnections( TInt aIapId )
  1610     {
  1437     {
  1620         else if ( GetBMIap( session->ConnectionId() ) == aIapId )
  1447         else if ( GetBMIap( session->ConnectionId() ) == aIapId )
  1621             {
  1448             {
  1622             TRAP_IGNORE( session->StopIAPNotificationL( aIapId ));
  1449             TRAP_IGNORE( session->StopIAPNotificationL( aIapId ));
  1623             }     
  1450             }     
  1624         }
  1451         }
  1625     }
       
  1626 
       
  1627 // -----------------------------------------------------------------------------
       
  1628 // CMPMServer::UpdateActiveConnection
       
  1629 // -----------------------------------------------------------------------------
       
  1630 //
       
  1631 void CMPMServer::UpdateActiveConnection( CMPMServerSession& aSession )
       
  1632     {
       
  1633     // Update active connection
       
  1634     TInt ret = KErrNone;
       
  1635             
       
  1636     TRAP ( ret, UpdateActiveConnectionL( aSession ) );
       
  1637             
       
  1638     if ( ret != KErrNone )
       
  1639         {
       
  1640         iActiveBearerType = EMPMBearerTypeNone;
       
  1641         iActiveIapId = 0;
       
  1642         iActiveSnapId = 0;            
       
  1643         }   
       
  1644     }
       
  1645 
       
  1646 // -----------------------------------------------------------------------------
       
  1647 // CMPMServer::UpdateActiveConnectionL
       
  1648 // -----------------------------------------------------------------------------
       
  1649 //
       
  1650 void CMPMServer::UpdateActiveConnectionL( CMPMServerSession& aSession )
       
  1651     {
       
  1652     MPMLOGSTRING( "CMPMServer::UpdateActiveConnectionL" )
       
  1653 
       
  1654     TBool keysUpToDate( ETrue );
       
  1655     
       
  1656     // number of active iaps
       
  1657     TInt numberOfActive = NumberOfActiveConnections( keysUpToDate );
       
  1658     
       
  1659     if ( numberOfActive == 0 )
       
  1660         {
       
  1661         // If no active connections then just reset keys and publish
       
  1662         iActiveBearerType = EMPMBearerTypeNone;
       
  1663         iActiveIapId = 0;
       
  1664         iActiveSnapId = 0;
       
  1665         PublishActiveConnection();
       
  1666         return;
       
  1667         }
       
  1668         
       
  1669     if ( keysUpToDate )
       
  1670         {
       
  1671         MPMLOGSTRING( "CMPMServer::UpdateActiveConnectionL: already up-to-date" )
       
  1672         return;   
       
  1673         }
       
  1674 
       
  1675     if ( numberOfActive > 1 )
       
  1676         {
       
  1677         // Check if all active connections are in same snap
       
  1678         TUint32 snapId;
       
  1679 
       
  1680         if ( CommsDatAccess()->AreActiveIapsInSameSnapL(
       
  1681              iActiveBMConns, snapId, *this ) )
       
  1682             {
       
  1683             MPMLOGSTRING( "CMPMServer::UpdateActiveConnectionL: Active iaps are in one SNAP" )
       
  1684             // Select active connection according to priority
       
  1685             CommsDatAccess()->SelectActiveConnectionL (
       
  1686                 snapId,
       
  1687                 iActiveBMConns,
       
  1688                 iActiveIapId,
       
  1689                 iActiveSnapId,
       
  1690                 iActiveBearerType,
       
  1691                 aSession );
       
  1692 
       
  1693             PublishActiveConnection();
       
  1694             return;
       
  1695             }
       
  1696         
       
  1697         MPMLOGSTRING( "CMPMServer::UpdateActiveConnectionL: Active iaps are in different SNAPs" )
       
  1698         }
       
  1699 
       
  1700     // Reset active connections
       
  1701     iActiveBearerType = EMPMBearerTypeNone;
       
  1702     iActiveIapId = 0;
       
  1703     iActiveSnapId = 0;
       
  1704                 
       
  1705     // Active connections locating in different snaps
       
  1706     // Use priority order vpn, wlan and packet
       
  1707     for ( TInt index = 0; index < iActiveBMConns.Count(); index++ )
       
  1708         {
       
  1709         CMPMServerSession* serverSession = GetServerSession(
       
  1710             iActiveBMConns[index].iConnInfo.iConnId );
       
  1711                      	
       
  1712         // Do check only for active connections
       
  1713         if ( iActiveBMConns[index].iConnInfo.iState == EStarted &&
       
  1714         	   serverSession->ChooseBestIapCalled() )
       
  1715             {
       
  1716             TMPMBearerType bearerType = EMPMBearerTypeOther;
       
  1717         
       
  1718             TInt ret = iDedicatedClients.Find( iActiveBMConns[index].iConnInfo.iAppUid );
       
  1719             if ( ret != KErrNotFound )
       
  1720                 {
       
  1721                 // Skip dedicated client
       
  1722                 MPMLOGSTRING2( "Skip dedicated client = %d", iActiveBMConns[index].iConnInfo.iAppUid )
       
  1723                 continue;
       
  1724                 }
       
  1725 
       
  1726             bearerType = CommsDatAccess()->GetBearerTypeL( 
       
  1727                          iActiveBMConns[index].iConnInfo.iIapId );
       
  1728         
       
  1729             if ( bearerType == EMPMBearerTypeOther )
       
  1730                 {
       
  1731                 // Don't publish this connection
       
  1732                 continue;
       
  1733                 }
       
  1734                     
       
  1735             // This is true if,
       
  1736             // bearer type is smaller or different than none
       
  1737             // or
       
  1738             // bearer type is same and iap is different.
       
  1739             if ( ( bearerType < iActiveBearerType ) || 
       
  1740                  ( iActiveBearerType == EMPMBearerTypeNone ) ||
       
  1741                  ( ( bearerType == iActiveBearerType) &&
       
  1742                    ( iActiveIapId != iActiveBMConns[index].iConnInfo.iIapId ) ) )
       
  1743                 {
       
  1744                 iActiveBearerType = bearerType;
       
  1745                 iActiveIapId = iActiveBMConns[index].iConnInfo.iIapId;
       
  1746                 iActiveSnapId = iActiveBMConns[index].iConnInfo.iSnap;
       
  1747                 }
       
  1748             }
       
  1749         }
       
  1750     PublishActiveConnection();
       
  1751     }
       
  1752 
       
  1753 // -----------------------------------------------------------------------------
       
  1754 // CMPMServer::MapBearerType
       
  1755 // -----------------------------------------------------------------------------
       
  1756 //
       
  1757 TUint32 CMPMServer::MapBearerType(TMPMBearerType aBearerType)
       
  1758     {
       
  1759     MPMLOGSTRING( "CMPMServer::MapBearerType" )
       
  1760     
       
  1761     switch ( aBearerType )
       
  1762         {
       
  1763         case EMPMBearerTypeNone:
       
  1764             return 0;
       
  1765 
       
  1766         case EMPMBearerTypeVpn:
       
  1767             return KCommDbBearerVirtual;
       
  1768             
       
  1769         case EMPMBearerTypeWlan:
       
  1770             return KCommDbBearerWLAN;
       
  1771             
       
  1772         case EMPMBearerTypePacketData:
       
  1773             return KCommDbBearerWcdma;
       
  1774 
       
  1775         case EMPMBearerTypeOther:
       
  1776             return KCommDbBearerUnknown;
       
  1777             
       
  1778         default:
       
  1779             MPMLOGSTRING( "CMPMServer::MapBearerType: Unknown bearer type" )
       
  1780             break;
       
  1781         }
       
  1782     
       
  1783     return KCommDbBearerUnknown;
       
  1784     }
       
  1785 
       
  1786 // -----------------------------------------------------------------------------
       
  1787 // CMPMServer::PublishActiveConnection
       
  1788 // -----------------------------------------------------------------------------
       
  1789 //
       
  1790 void CMPMServer::PublishActiveConnection()
       
  1791     {
       
  1792     MPMLOGSTRING( "CMPMServer::PublishActiveConnection" )
       
  1793     
       
  1794     // update active connection keys
       
  1795     RProperty::Set( KMPMActiveConnectionCategory,
       
  1796                     KMPMPSKeyActiveConnectionIap,
       
  1797                     iActiveIapId );
       
  1798 
       
  1799     RProperty::Set( KMPMActiveConnectionCategory,
       
  1800                     KMPMPSKeyActiveConnectionSnap,
       
  1801                     iActiveSnapId );
       
  1802 
       
  1803     RProperty::Set( KMPMActiveConnectionCategory,
       
  1804                     KMPMPSKeyActiveConnectionBearer,
       
  1805                     MapBearerType( iActiveBearerType ) );    
       
  1806 
       
  1807     MPMLOGSTRING4( "CMPMServer::PublishActiveConnection: Set to: %d, %d, %d",
       
  1808                    iActiveIapId, iActiveSnapId, iActiveBearerType )
       
  1809     }
       
  1810 
       
  1811 // -----------------------------------------------------------------------------
       
  1812 // CMPMServer::NumberOfActiveConnections
       
  1813 // Returns number of active iaps.
       
  1814 // -----------------------------------------------------------------------------
       
  1815 //
       
  1816 TInt CMPMServer::NumberOfActiveConnections( TBool& aKeysUpToDate )
       
  1817     {
       
  1818     MPMLOGSTRING( "CMPMServer::NumberOfActiveConnections" )
       
  1819     
       
  1820     aKeysUpToDate = ETrue; 
       
  1821     TInt count( 0 );
       
  1822     RArray<TUint32> activeIaps;
       
  1823     
       
  1824     activeIaps.Reset();
       
  1825     
       
  1826     for ( TInt index = 0; index < iActiveBMConns.Count(); index++ )
       
  1827         {
       
  1828         CMPMServerSession* serverSession = GetServerSession(
       
  1829              iActiveBMConns[index].iConnInfo.iConnId );
       
  1830 
       
  1831         if ( iActiveBMConns[index].iConnInfo.iState == EStarted &&
       
  1832              serverSession->ChooseBestIapCalled() )
       
  1833             {
       
  1834             TInt ret = activeIaps.Find( iActiveBMConns[index].iConnInfo.iIapId );
       
  1835  
       
  1836             if ( ret == KErrNotFound )
       
  1837                 {        
       
  1838                 activeIaps.Append ( iActiveBMConns[index].iConnInfo.iIapId ); 
       
  1839                 count++;
       
  1840                 }
       
  1841             
       
  1842             if ( iActiveIapId != iActiveBMConns[index].iConnInfo.iIapId )
       
  1843                  {
       
  1844                  // iap that is different from current active iap was found
       
  1845                  aKeysUpToDate = EFalse;
       
  1846                  }
       
  1847             }
       
  1848         }
       
  1849     
       
  1850     activeIaps.Close();
       
  1851     MPMLOGSTRING2( "CMPMServer::NumberOfActiveConnections: count = %d", count )
       
  1852     
       
  1853     return count;
       
  1854     }
  1452     }
  1855 
  1453 
  1856 // -----------------------------------------------------------------------------
  1454 // -----------------------------------------------------------------------------
  1857 // CMPMServer::UserConnectionInInternet
  1455 // CMPMServer::UserConnectionInInternet
  1858 // -----------------------------------------------------------------------------
  1456 // -----------------------------------------------------------------------------
  1878 // -----------------------------------------------------------------------------
  1476 // -----------------------------------------------------------------------------
  1879 //
  1477 //
  1880 void CMPMServer::StartForcedRoamingToWlanL( const TConnMonIapInfo& aIapInfo )
  1478 void CMPMServer::StartForcedRoamingToWlanL( const TConnMonIapInfo& aIapInfo )
  1881     {
  1479     {
  1882     MPMLOGSTRING( "CMPMServer::StartForcedRoamingToWlan" )
  1480     MPMLOGSTRING( "CMPMServer::StartForcedRoamingToWlan" )
  1883  
  1481     
       
  1482     // cancel the periodic object
       
  1483     if ( iRoamingToWlanPeriodic )
       
  1484         {
       
  1485         iRoamingToWlanPeriodic->Cancel();
       
  1486         }
       
  1487 
  1884     // Copy all available wlan iap ids to own array
  1488     // Copy all available wlan iap ids to own array
  1885     RArray<TUint32> wlanIapIds;
  1489     RArray<TUint32> wlanIapIds;
  1886     CleanupClosePushL( wlanIapIds );
  1490     CleanupClosePushL( wlanIapIds );
  1887     RAvailableIAPList iapList;
  1491     RAvailableIAPList iapList;
  1888     CleanupClosePushL( iapList );
  1492     CleanupClosePushL( iapList );
  1889 
  1493 
  1890     for ( TUint index = 0; index < aIapInfo.iCount; index++ )
  1494     for ( TUint index = 0; index < aIapInfo.iCount; index++ )
  1891         {
  1495         {
  1892         TWlanIapType iapType ( ENotWlanIap );
  1496         if ( CommsDatAccess()->CheckWlanL( aIapInfo.iIap[index].iIapId ) != ENotWlanIap )
  1893         TRAPD (leave, iapType = CommsDatAccess()->CheckWlanL( aIapInfo.iIap[index].iIapId ) );
       
  1894         if ( ( iapType != ENotWlanIap ) && ( leave == KErrNone ) )
       
  1895             {
  1497             {
  1896             // Accept only wlan iaps in internet snap
  1498             // Accept only wlan iaps in internet snap
  1897             if ( iCommsDatAccess->IsInternetSnapL( aIapInfo.iIap[index].iIapId, 0 ) )
  1499             if ( iCommsDatAccess->IsInternetSnapL( aIapInfo.iIap[index].iIapId, 0 ) )
  1898                 {
  1500                 {
  1899                 wlanIapIds.AppendL( aIapInfo.iIap[index].iIapId );
  1501                 wlanIapIds.AppendL( aIapInfo.iIap[index].iIapId );
  1900                 }
  1502                 }
  1901             }
  1503             }
  1902         // Fill iap list to be used later to check best iap;
  1504         // Fill iap list to be used later to check best iap
  1903         if ( leave == KErrNone )
  1505         iapList.AppendL( aIapInfo.iIap[index].iIapId );
  1904             {
  1506         }
  1905             iapList.AppendL( aIapInfo.iIap[index].iIapId );
  1507 
  1906             }
       
  1907         }
       
  1908     // No wlans available -> no reason to continue
  1508     // No wlans available -> no reason to continue
  1909     if ( !wlanIapIds.Count() )
  1509     if ( !wlanIapIds.Count() )
  1910         {
  1510         {
  1911         CleanupStack::PopAndDestroy( &iapList );
  1511         CleanupStack::PopAndDestroy( &iapList );
  1912         CleanupStack::PopAndDestroy( &wlanIapIds );
  1512         CleanupStack::PopAndDestroy( &wlanIapIds );
  1947 // CMPMServer::StartForcedRoamingToConnectedWlanL
  1547 // CMPMServer::StartForcedRoamingToConnectedWlanL
  1948 // ---------------------------------------------------------------------------
  1548 // ---------------------------------------------------------------------------
  1949 //    
  1549 //    
  1950 TInt CMPMServer::StartForcedRoamingToConnectedWlanL( TAny* aUpdater )
  1550 TInt CMPMServer::StartForcedRoamingToConnectedWlanL( TAny* aUpdater )
  1951     {
  1551     {
  1952     MPMLOGSTRING( "CMPMServer::StartForcedRoamingToConnectedWlanL" )
  1552     MPMLOGSTRING( "CMPMServer::StartForcedRoamingToConnectedWlanL" );
  1953     CMPMServer* self = static_cast<CMPMServer*>( aUpdater );
  1553     static_cast<CMPMServer*>( aUpdater )->StartForcedRoamingToWlanL( 
  1954     if ( self )
  1554             static_cast<CMPMServer*>( aUpdater )->iConnMonIapInfo );
  1955         {
  1555     // Added also execution of policy based roaming logic because
  1956         // cancel the periodic object        
  1556     // connections that are in EStarting state, when WLAN signal
  1957         self->iRoamingToWlanPeriodic->Cancel();
  1557     // gets weak, would remain in WLAN as long as signal is weak. 
  1958         self->StartForcedRoamingToWlanL( self->iConnMonIapInfo );
  1558     static_cast<CMPMServer*>( aUpdater )->StartForcedRoamingFromWlanL(
  1959         }
  1559             static_cast<CMPMServer*>( aUpdater )->iConnMonIapInfo );
  1960     return 0;
  1560     return 0;
  1961     }
  1561     }
  1962 
  1562 
  1963 // ---------------------------------------------------------------------------
       
  1964 // CMPMServer::StartForcedRoamingToConnectedHotspotWlanL
       
  1965 // ---------------------------------------------------------------------------
       
  1966 //    
       
  1967 TInt CMPMServer::StartForcedRoamingToConnectedHotspotWlanL( TAny* aUpdater )
       
  1968     {
       
  1969     MPMLOGSTRING( "CMPMServer::StartForcedRoamingToConnectedHotspotWlanL" )
       
  1970     CMPMServer* self = static_cast<CMPMServer*>( aUpdater );
       
  1971     if ( self )
       
  1972         {        
       
  1973         // cancel the periodic object
       
  1974         self->iRoamingToHotspotWlanPeriodic->Cancel();
       
  1975         self->StartForcedRoamingToWlanL( self->iConnMonIapInfo );
       
  1976         }
       
  1977     return 0;
       
  1978     }
       
  1979 
  1563 
  1980 // -----------------------------------------------------------------------------
  1564 // -----------------------------------------------------------------------------
  1981 // CMPMServer::StartForcedRoamingFromWlanL
  1565 // CMPMServer::StartForcedRoamingFromWlanL
  1982 // -----------------------------------------------------------------------------
  1566 // -----------------------------------------------------------------------------
  1983 //
  1567 //
  2208 // ---------------------------------------------------------------------------
  1792 // ---------------------------------------------------------------------------
  2209 // CMPMServer::StopCellularConns
  1793 // CMPMServer::StopCellularConns
  2210 // Stop all cellular connections except MMS
  1794 // Stop all cellular connections except MMS
  2211 // ---------------------------------------------------------------------------
  1795 // ---------------------------------------------------------------------------
  2212 //
  1796 //
  2213 void CMPMServer::StopCellularConns( TBool aSilentOnly )
  1797 void CMPMServer::StopCellularConns()
  2214     {
  1798     {
  2215     MPMLOGSTRING( "CMPMServer::StopCellularConns" )
  1799     MPMLOGSTRING( "CMPMServer::StopCellularConns" )
  2216 
  1800 
  2217     TUint32 iapId;
  1801     TUint32 iapId;
  2218 	TMPMBearerType bearerType = EMPMBearerTypeNone;
  1802 	TMPMBearerType bearerType = EMPMBearerTypeNone;
  2237                 err = RProperty::Get( KMPMCathegory, KMPMPropertyKeyMMS, mmsIap );
  1821                 err = RProperty::Get( KMPMCathegory, KMPMPropertyKeyMMS, mmsIap );
  2238                 // Check that it's not MMS IAP.
  1822                 // Check that it's not MMS IAP.
  2239                 if (!(err == KErrNone && iapId == mmsIap))
  1823                 if (!(err == KErrNone && iapId == mmsIap))
  2240                     {
  1824                     {
  2241                     // Stop the conn / IAP.
  1825                     // Stop the conn / IAP.
  2242                     if ( aSilentOnly )
  1826                     StopConnections( iapId );
  2243                         {
       
  2244                         CheckIapForDisconnect( iapId );
       
  2245                         }
       
  2246                     else
       
  2247                         {
       
  2248                         StopConnections( iapId );
       
  2249                         }
       
  2250                     stoppedIaps.Append( iapId );
  1827                     stoppedIaps.Append( iapId );
  2251                     }
  1828                     }
  2252                 }
  1829                 }
  2253             }
  1830             }
  2254         }
  1831         }
  2255     stoppedIaps.Close();
  1832     stoppedIaps.Close();
       
  1833     }
       
  1834 
       
  1835 // -----------------------------------------------------------------------------
       
  1836 // CMPMServer::AddVpnUserConnectionSession
       
  1837 // -----------------------------------------------------------------------------
       
  1838 //
       
  1839 void CMPMServer::AddVpnUserConnectionSession()
       
  1840     {
       
  1841     iVpnUserConnectionSessionCount++;
       
  1842     }
       
  1843 
       
  1844 // -----------------------------------------------------------------------------
       
  1845 // CMPMServer::RemoveVpnUserConnectionSession
       
  1846 // -----------------------------------------------------------------------------
       
  1847 //
       
  1848 void CMPMServer::RemoveVpnUserConnectionSession()
       
  1849     {    
       
  1850     ASSERT( iVpnUserConnectionSessionCount > 0 );
       
  1851     iVpnUserConnectionSessionCount--;
       
  1852     }
       
  1853 
       
  1854 // ---------------------------------------------------------------------------
       
  1855 // CMPMServer::UseVpnUserConnection
       
  1856 // Informs if VPN user connection is used with given MPM preferences and
       
  1857 // application.
       
  1858 // ---------------------------------------------------------------------------
       
  1859 //
       
  1860 TBool CMPMServer::UseVpnUserConnection( const TMpmConnPref aMpmConnPref,
       
  1861                                         const TUint32 aAppUid ) const
       
  1862     {    
       
  1863     if ( iMpmVpnToggleWatcher->IsVpnConnectionPreferred() &&
       
  1864          !aMpmConnPref.MandateIap() &&
       
  1865          aAppUid != KUidKmdServer &&
       
  1866          aAppUid != iMpmCsIdWatcher->ConnectScreenId() )
       
  1867         {
       
  1868         // VPN connection is preferred connection, connection preferences are
       
  1869         // not mandatet and client is not KMD server or Connect Screen.            
       
  1870         if ( aMpmConnPref.ConnType() == TMpmConnPref::EConnTypeDefault ||
       
  1871              aMpmConnPref.ConnType() == TMpmConnPref::EConnTypeImplicit )
       
  1872             {
       
  1873             // Default or implicit connection is requested.
       
  1874             // VPN user connection is used.
       
  1875             return ETrue;
       
  1876             }
       
  1877         else
       
  1878             {
       
  1879             // Explicit connection is requested.
       
  1880             TBool internetSnap(EFalse);    
       
  1881             TRAPD( err, internetSnap = iCommsDatAccess->IsInternetSnapL( aMpmConnPref.IapId(),
       
  1882                                                                          aMpmConnPref.SnapId() ) );
       
  1883             if ( err == KErrNone &&
       
  1884                  internetSnap )
       
  1885                 {
       
  1886                 // Connection belongs to Internet SNAP.
       
  1887                 // VPN user connection is used.
       
  1888                 return ETrue;
       
  1889                 }
       
  1890             }
       
  1891         }
       
  1892     
       
  1893     // VPN user connection is not used.
       
  1894     return EFalse;    
       
  1895     }
       
  1896 
       
  1897 // -----------------------------------------------------------------------------
       
  1898 // CMPMServer::PrepareVpnUserConnection
       
  1899 // -----------------------------------------------------------------------------
       
  1900 //
       
  1901 TBool CMPMServer::PrepareVpnUserConnection( TMpmConnPref& aMpmConnPref )
       
  1902     {
       
  1903     // Get VPN IAP Id or SNAP Id, which is used for VPN user connection. 
       
  1904     TUint32 vpnIapId = iMpmVpnToggleWatcher->VpnIapId();
       
  1905     TUint32 snapId = iMpmVpnToggleWatcher->SnapId();
       
  1906 
       
  1907     // Check first if SNAP Id is set, in which case VPN IAP Id is ignored.
       
  1908     if ( snapId != 0 )
       
  1909         {
       
  1910         TBool intranetSnap( EFalse );   
       
  1911         TRAPD( err , intranetSnap = 
       
  1912             iCommsDatAccess->IsIntranetSnapL( snapId ) );
       
  1913         if ( (err != KErrNone) ||
       
  1914              (!intranetSnap) )
       
  1915             {
       
  1916             // SNAP is not intranet SNAP.
       
  1917             // Reset VPN toggle values and continue without using VPN user
       
  1918             // connection.
       
  1919             MPMLOGSTRING3( "CMPMServer::PrepareVpnUserConnection failed, \
       
  1920 SNAP Id=%d, err=%d", snapId, err );
       
  1921         
       
  1922             iMpmVpnToggleWatcher->ResetVpnToggleValues();        
       
  1923             return EFalse;
       
  1924             }        
       
  1925         aMpmConnPref.SetIapId( 0 );
       
  1926         aMpmConnPref.SetSnapId( snapId );               
       
  1927         }
       
  1928     else
       
  1929         {
       
  1930         // Validate that IAP is VPN IAP. 
       
  1931         TMPMBearerType bearerType = EMPMBearerTypeNone;
       
  1932         TRAPD( err, bearerType = iCommsDatAccess->GetBearerTypeL( vpnIapId ) );        
       
  1933         if ( (err != KErrNone) ||
       
  1934              (bearerType != EMPMBearerTypeVpn) )
       
  1935             {        
       
  1936             // IAP is not valid VPN IAP.
       
  1937             // Reset VPN toggle values and continue without using VPN user
       
  1938             // connection.
       
  1939             MPMLOGSTRING4( "CMPMServer::PrepareVpnUserConnection failed, \
       
  1940 IAP Id=%d, err=%d, bearerType=%d", vpnIapId, err, bearerType );
       
  1941         
       
  1942             iMpmVpnToggleWatcher->ResetVpnToggleValues();
       
  1943             return EFalse;
       
  1944             }
       
  1945         aMpmConnPref.SetIapId( vpnIapId );
       
  1946         aMpmConnPref.SetSnapId( 0 );            
       
  1947         }
       
  1948    
       
  1949     aMpmConnPref.SetConnType( TMpmConnPref::EConnTypeExplicit );
       
  1950     
       
  1951     // VPN user connection will be activated.
       
  1952     return ETrue;        
  2256     }
  1953     }
  2257 
  1954 
  2258 // ---------------------------------------------------------------------------
  1955 // ---------------------------------------------------------------------------
  2259 // CMPMServer::UpdateOfflineMode
  1956 // CMPMServer::UpdateOfflineMode
  2260 // Offline watcher listens the offline mode and calls this when it's changed.
  1957 // Offline watcher listens the offline mode and calls this when it's changed.
  2261 // ---------------------------------------------------------------------------
  1958 // ---------------------------------------------------------------------------
  2262 //
  1959 //
  2263 void CMPMServer::UpdateOfflineMode( TInt newModeValue )
  1960 void CMPMServer::UpdateOfflineMode( TInt aNewModeValue )
  2264     {
  1961     {
  2265     MPMLOGSTRING2( "CMPMServer::UpdateOfflineMode: Value %d", newModeValue )
  1962     MPMLOGSTRING2( "CMPMServer::UpdateOfflineMode: Value %d", aNewModeValue )
  2266 
  1963 
  2267     iOfflineMode = newModeValue;
  1964     iOfflineMode = aNewModeValue;
  2268 
  1965 
  2269     if ( iOfflineMode == ECoreAppUIsNetworkConnectionAllowed )
  1966     if ( iOfflineMode == ECoreAppUIsNetworkConnectionAllowed )
  2270         {
  1967         {
  2271         // Offline mode finished, reset the QueryResponse variable.
  1968         // Offline mode finished, reset the QueryResponse variable.
  2272         iOfflineWlanQueryResponse = EOfflineResponseUndefined;
  1969         iOfflineWlanQueryResponse = EOfflineResponseUndefined;
  2378         }
  2075         }
  2379     return retval;
  2076     return retval;
  2380     }
  2077     }
  2381 
  2078 
  2382 // -----------------------------------------------------------------------------
  2079 // -----------------------------------------------------------------------------
  2383 // CMPMServer::CheckIapForDisconnect
       
  2384 // -----------------------------------------------------------------------------
       
  2385 //
       
  2386 void CMPMServer::CheckIapForDisconnect( TInt aIapId )
       
  2387     {
       
  2388     MPMLOGSTRING2( "CMPMServer::CheckIapForDisconnect - aIapId = 0x%x", 
       
  2389         aIapId )
       
  2390 
       
  2391     // Fix for case ou1cimx1#468999: stop sessions to cellular iap
       
  2392     // when there is only silent connections to it, and cellular usage is set
       
  2393     // to always ask
       
  2394     
       
  2395     // Check iap type and usage policy
       
  2396     TMPMBearerType bearerType( EMPMBearerTypeNone );
       
  2397     TRAP_IGNORE( bearerType = CommsDatAccess()->GetBearerTypeL( aIapId ) );
       
  2398 
       
  2399     TBool closeIap = ( bearerType == EMPMBearerTypePacketData
       
  2400                 && DataUsageWatcher()->CellularDataUsage() == ECmCellularDataUsageConfirm ); 
       
  2401     
       
  2402     // No need to put iapSessions to CleanupStack; there are no leaves
       
  2403     RPointerArray<CMPMServerSession> iapSessions;
       
  2404     if ( closeIap )
       
  2405         {
       
  2406         // Check for non-silent sessions to iap
       
  2407         // closeIap is left true also when there are no sessions using the iap
       
  2408         for ( TInt i = 0; i < iActiveBMConns.Count(); i++ )
       
  2409             {
       
  2410 
       
  2411             CMPMServerSession* session
       
  2412                 = GetServerSession( iActiveBMConns[i].iConnInfo.iConnId );
       
  2413 
       
  2414             TInt sessionIapId = iActiveBMConns[i].iConnInfo.iIapId;
       
  2415             if ( !sessionIapId )
       
  2416                 {
       
  2417                 TRAP_IGNORE( sessionIapId = session->IapSelectionL()->MpmConnPref().IapId() );
       
  2418                 }
       
  2419 
       
  2420             if ( sessionIapId == aIapId )
       
  2421                 {
       
  2422                 iapSessions.Append( session ); // Don't mind if Append fails
       
  2423                 
       
  2424                 TBool silent( ETrue );
       
  2425                 TRAP_IGNORE( silent = session->IapSelectionL()->MpmConnPref().NoteBehaviour()
       
  2426                                       & TExtendedConnPref::ENoteBehaviourConnDisableNotes );
       
  2427                 if ( !silent )
       
  2428                     {
       
  2429                     // Non-silent session to iap found
       
  2430                     closeIap = EFalse;
       
  2431                     break; // for
       
  2432                     }
       
  2433                 }
       
  2434             }
       
  2435         }
       
  2436     
       
  2437     if ( closeIap )
       
  2438         {
       
  2439         MPMLOGSTRING2( "CMPMServer::CheckIapForDisconnect - stopping silent sessions to iap 0x%x", 
       
  2440             aIapId )
       
  2441         // Stop all (silent) sessions to iap
       
  2442         for ( TInt i = 0; i < iapSessions.Count(); i++)
       
  2443             {
       
  2444             MPMLOGSTRING2( "CMPMServer::CheckIapForDisconnect - stopping connId 0x%x",
       
  2445                     iapSessions[i]->ConnectionId());
       
  2446             iapSessions[i]->StopConnection();
       
  2447             }
       
  2448         }
       
  2449 
       
  2450     iapSessions.Close();
       
  2451     
       
  2452     }
       
  2453 
       
  2454 
       
  2455 // -----------------------------------------------------------------------------
       
  2456 // TMPMBlackListConnId::Append
  2080 // TMPMBlackListConnId::Append
  2457 // -----------------------------------------------------------------------------
  2081 // -----------------------------------------------------------------------------
  2458 //
  2082 //
  2459 void TMPMBlackListConnId::Append( TUint32 aIap, TBlacklistCategory aCategory )
  2083 void TMPMBlackListConnId::Append( TUint32 aIap, TBlacklistCategory aCategory )
  2460     {
  2084     {