bearermanagement/mpm/src/mpmserver.cpp
branchRCL_3
changeset 55 fc7b30ed2058
parent 45 4c83dcfb6f1a
child 57 05bc53fe583b
equal deleted inserted replaced
54:984e13af52c4 55:fc7b30ed2058
    44 #include "mpmprivatecrkeys.h"
    44 #include "mpmprivatecrkeys.h"
    45 #include "mpmcsidwatcher.h"
    45 #include "mpmcsidwatcher.h"
    46 #include "mpmdatausagewatcher.h"
    46 #include "mpmdatausagewatcher.h"
    47 #include "mpmpropertydef.h"
    47 #include "mpmpropertydef.h"
    48 #include "mpmofflinewatcher.h"
    48 #include "mpmofflinewatcher.h"
       
    49 #include "mpmconnpermquerytimer.h"
    49 
    50 
    50 // ============================= LOCAL FUNCTIONS ===============================
    51 // ============================= LOCAL FUNCTIONS ===============================
    51 
    52 
    52 // -----------------------------------------------------------------------------
    53 // -----------------------------------------------------------------------------
    53 // PanicServer 
    54 // PanicServer 
   290         {
   291         {
   291         User::Leave(err);
   292         User::Leave(err);
   292         }
   293         }
   293         
   294         
   294     PublishActiveConnection();
   295     PublishActiveConnection();
       
   296     
       
   297     iRoamingToWlanPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
   298     iRoamingToHotspotWlanPeriodic = CPeriodic::NewL( CActive::EPriorityStandard );
       
   299             
   295     }
   300     }
   296 
   301 
   297 
   302 
   298 // -----------------------------------------------------------------------------
   303 // -----------------------------------------------------------------------------
   299 // CMPMServer::~CMPMServer
   304 // CMPMServer::~CMPMServer
   304 	if ( iRoamingToWlanPeriodic )
   309 	if ( iRoamingToWlanPeriodic )
   305         {
   310         {
   306         iRoamingToWlanPeriodic->Cancel();
   311         iRoamingToWlanPeriodic->Cancel();
   307 		delete iRoamingToWlanPeriodic;
   312 		delete iRoamingToWlanPeriodic;
   308         }
   313         }
       
   314     if ( iRoamingToHotspotWlanPeriodic )
       
   315         {
       
   316         iRoamingToHotspotWlanPeriodic->Cancel();
       
   317         delete iRoamingToHotspotWlanPeriodic;
       
   318         }
   309     if ( iDisconnectQueue )
   319     if ( iDisconnectQueue )
   310         {
   320         {
   311         iDisconnectQueue->ResetAndDestroy();
   321         iDisconnectQueue->ResetAndDestroy();
   312         }
   322         }
   313     delete iDisconnectQueue;
   323     delete iDisconnectQueue;
   366 
   376 
   367     delete iMpmOfflineWatcher;    
   377     delete iMpmOfflineWatcher;    
   368 
   378 
   369     iDedicatedClients.Close();
   379     iDedicatedClients.Close();
   370 
   380 
   371     delete iCommsDatAccess;    
   381     delete iCommsDatAccess;
       
   382     
       
   383     delete iConnPermQueryTimer;
   372     }
   384     }
   373 
   385 
   374 
   386 
   375 // -----------------------------------------------------------------------------
   387 // -----------------------------------------------------------------------------
   376 // CMPMServer::NewSessionL
   388 // CMPMServer::NewSessionL
   429     {
   441     {
   430     MPMLOGSTRING3(
   442     MPMLOGSTRING3(
   431         "CMPMServer::AppendBMConnection - aConnId = 0x%x, aSnap = %i",
   443         "CMPMServer::AppendBMConnection - aConnId = 0x%x, aSnap = %i",
   432         aConnId, aSnap )
   444         aConnId, aSnap )
   433 
   445 
   434     // Set the Connection Id, SNAP, Iap Id and connection state
   446     // Set the Connection Id, SNAP, Iap Id and connection state, into TActiveBMConn
   435     // 
       
   436     TConnectionInfo connInfo;
       
   437     connInfo.iConnId = aConnId;
       
   438     connInfo.iSnap   = aSnap;
       
   439     connInfo.iIapId  = aIapId;
       
   440     connInfo.iState  = aState;
       
   441     connInfo.iAppUid = aSession.AppUid();
       
   442 
       
   443     // Package into TActiveBMConn //TODO Redundant.. remove the other one.
       
   444     // 
       
   445     TActiveBMConn conn;
   447     TActiveBMConn conn;
   446     conn.iConnInfo          = connInfo;
   448     conn.iConnInfo.iConnId = aConnId;
       
   449     conn.iConnInfo.iSnap   = aSnap;
       
   450     conn.iConnInfo.iIapId  = aIapId;
       
   451     conn.iConnInfo.iState  = aState;
       
   452     conn.iConnInfo.iAppUid = aSession.AppUid();
   447 
   453 
   448     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
   454     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
   449 
   455 
   450     if ( index1 == KErrNotFound )
   456     if ( index1 == KErrNotFound )
   451         {
   457         {
   545                                      CMPMServerSession&  aSession )
   551                                      CMPMServerSession&  aSession )
   546     {
   552     {
   547     MPMLOGSTRING2( "CMPMServer::RemoveBMConnection - aConnId = 0x%x", 
   553     MPMLOGSTRING2( "CMPMServer::RemoveBMConnection - aConnId = 0x%x", 
   548         aConnId )
   554         aConnId )
   549 
   555 
   550     TInt count = iActiveBMConns.Count();
       
   551     
       
   552     // Decrement by one, because count is n, 
       
   553     // but indexes in array are 0 .. n-1.
       
   554     // 
       
   555     count--;
       
   556 
       
   557     // This time we are browsing the array from the end to the beginning, 
   556     // This time we are browsing the array from the end to the beginning, 
   558     // because removing one element from array affects index numbering.
   557     // because removing one element from array affects index numbering.
   559     // 
   558     // Decrement i by one, because count is n, but indexes in array are 0 .. n-1
   560     for ( TInt i = count; i >= 0; i-- )
   559     for ( TInt i = iActiveBMConns.Count() - 1; i >= 0; i-- )
   561         {
   560         {
   562         if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
   561         if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
   563             {
   562             {
       
   563             
       
   564             TInt closeIapId = iActiveBMConns[i].iConnInfo.iIapId;
       
   565             if ( !closeIapId )
       
   566                 {
       
   567                 TRAP_IGNORE( closeIapId = aSession.IapSelectionL()->MpmConnPref().IapId() );
       
   568                 }
       
   569 
   564             // If Connection Id found, remove it. 
   570             // If Connection Id found, remove it. 
   565             //
       
   566             iActiveBMConns.Remove( i );
   571             iActiveBMConns.Remove( i );
   567 
   572             
   568             // Update active connection
   573             // Update active connection
   569             if ( aSession.ChooseBestIapCalled() )
   574             if ( aSession.ChooseBestIapCalled() )
   570                 {
   575                 {
   571                 UpdateActiveConnection( aSession );
   576                 UpdateActiveConnection( aSession );
   572                 }
   577                 }
   573             }
   578             
   574         }
   579             CheckIapForDisconnect( closeIapId );
   575 
   580             }
       
   581         }
       
   582     
   576 #ifdef _DEBUG
   583 #ifdef _DEBUG
   577     // Dump array of active connections to log in order to support testing.
   584     // Dump array of active connections to log in order to support testing.
   578     // 
   585     // 
   579     DumpActiveBMConns();
   586     DumpActiveBMConns();
   580 #endif // _DEBUG
   587 #endif // _DEBUG
   589     MPMLOGSTRING2( "CMPMServer::GetBMIap - aConnId = 0x%x", aConnId )
   596     MPMLOGSTRING2( "CMPMServer::GetBMIap - aConnId = 0x%x", aConnId )
   590 
   597 
   591     TUint32 connectionIapId( 0 );
   598     TUint32 connectionIapId( 0 );
   592 
   599 
   593     // Set the Connection Id and SNAP
   600     // Set the Connection Id and SNAP
   594     // 
       
   595     TConnectionInfo connInfo;
   601     TConnectionInfo connInfo;
   596     connInfo.iConnId = aConnId;
   602     connInfo.iConnId = aConnId;
   597 
   603 
   598     TActiveBMConn conn;
   604     TActiveBMConn conn;
   599     conn.iConnInfo = connInfo;
   605     conn.iConnInfo = connInfo;
   601     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
   607     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
   602 
   608 
   603     if ( ( index1 != KErrNotFound ) && ( index1 < iActiveBMConns.Count() ) )
   609     if ( ( index1 != KErrNotFound ) && ( index1 < iActiveBMConns.Count() ) )
   604         {
   610         {
   605         // If connInfo found, set the Iap Id as connectionIapId
   611         // If connInfo found, set the Iap Id as connectionIapId
   606         //
       
   607         connectionIapId = iActiveBMConns[index1].iConnInfo.iIapId;
   612         connectionIapId = iActiveBMConns[index1].iConnInfo.iIapId;
   608         }
   613         }
   609 
   614 
   610     MPMLOGSTRING2( "CMPMServer::GetBMIap - connectionIapId = %i", 
   615     MPMLOGSTRING2( "CMPMServer::GetBMIap - connectionIapId = %i", 
   611         connectionIapId )
   616         connectionIapId )
   868     {
   873     {
   869     MPMLOGSTRING3(
   874     MPMLOGSTRING3(
   870         "CMPMServer::RemoveBMIAPConnection - aIapId = %i, aConnId = 0x%x", 
   875         "CMPMServer::RemoveBMIAPConnection - aIapId = %i, aConnId = 0x%x", 
   871         aIapId, aConnId )
   876         aIapId, aConnId )
   872 
   877 
   873     TActiveBMConn conn;
       
   874     conn.iConnInfo.iIapId = aIapId;
       
   875 
       
   876     // The IAP connection lifetime is determined by the two calls 
   878     // The IAP connection lifetime is determined by the two calls 
   877     // IAPConnectionStarted and IAPConnectionStopped. 
   879     // IAPConnectionStarted and IAPConnectionStopped. 
   878     //
       
   879     TInt count = iActiveBMConns.Count();
       
   880 
       
   881     // Decrement by one, because count is n, 
       
   882     // but indexes in array are 0 .. n-1.
       
   883     // 
       
   884     count--;
       
   885 
   880 
   886     // This time we are browsing the array from the end to the beginning, 
   881     // This time we are browsing the array from the end to the beginning, 
   887     // because removing one element from array affects index numbering.
   882     // because removing one element from array affects index numbering.
   888     // 
   883     // Decrement i by one, because count is n, but indexes in array are 0 .. n-1
   889     for ( TInt i = count; i >= 0; i-- )
   884     for ( TInt i = iActiveBMConns.Count() - 1; i >= 0; i-- )
   890         {
   885         {
   891         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId )
   886         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId )
   892             {
   887             {
   893             if ( iActiveBMConns[i].iConnInfo.iSnap == 0 )
   888             if ( iActiveBMConns[i].iConnInfo.iSnap == 0 )
   894                 {
   889                 {
   967                                    const TPrefIAPNotifCaller aCaller )
   962                                    const TPrefIAPNotifCaller aCaller )
   968     {
   963     {
   969     MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIapL - IAPs count: %d", 
   964     MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIapL - IAPs count: %d", 
   970         aIapInfo.iCount)
   965         aIapInfo.iCount)
   971     TConnMonIapInfo iapInfo = aIapInfo;
   966     TConnMonIapInfo iapInfo = aIapInfo;
   972     
   967     iConnMonIapInfo = aIapInfo;
   973 #ifdef _DEBUG
   968 #ifdef _DEBUG
   974     for (TUint i = 0; i < iapInfo.Count(); i++)
   969     for (TUint i = 0; i < iapInfo.Count(); i++)
   975         {
   970         {
   976         MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIap - IAP: %d", 
   971         MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIap - IAP: %d", 
   977             iapInfo.iIap[i].iIapId) 
   972             iapInfo.iIap[i].iIapId) 
   978         }
   973         }
   979 #endif // _DEBUG
   974 #endif // _DEBUG
   980 
   975 
       
   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     
   981     // Start possible forced roaming
   993     // Start possible forced roaming
   982     TCmUsageOfWlan usageOfWlan = CommsDatAccess()->ForcedRoamingL();
   994     if ( !err )
   983     if ( usageOfWlan == ECmUsageOfWlanKnown || usageOfWlan == ECmUsageOfWlanKnownAndNew )
   995         {
   984         {
   996         if ( usageOfWlan == ECmUsageOfWlanKnown || usageOfWlan == ECmUsageOfWlanKnownAndNew )
   985         if ( IsWlanConnectionStartedL( CommsDatAccess() ) )
   997             {
   986             {
   998             if ( IsWlanConnectionStartedL( CommsDatAccess() ) )
   987             iConnMonIapInfo = aIapInfo;
   999                 {
       
  1000                 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 ) );
   988                 
  1010                 
   989             if ( iRoamingToWlanPeriodic )
  1011                 // Start periodic object that calls StartForcedRoamingToWlanL after 120s. 
   990                 {
  1012                 // this handles the case when new captive portal hotspot wlan 
   991                 iRoamingToWlanPeriodic->Cancel();
  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 ) );
   992                 }
  1019                 }
   993             else
  1020             else
   994                 {
  1021                 {
   995                 iRoamingToWlanPeriodic = CPeriodic::NewL( 
  1022                 StartForcedRoamingToWlanL( iapInfo );
   996                                                    CActive::EPriorityStandard );
  1023                 }
   997                 }
  1024 
   998             // start periodic object that calls StartForcedRoamingToWlanL after 10s. 
  1025             StartForcedRoamingFromWlanL( iapInfo );
   999             // this handles the case when new wlan connection is 
  1026             }
  1000             // started from e.g. wlan sniffer but IAP is not yet in Internet SNAP 
  1027         }
  1001             iRoamingToWlanPeriodic->Start( 
  1028     else
  1002                    TTimeIntervalMicroSeconds32( KRoamingToWlanUpdateInterval ), 
  1029         {
  1003                    TTimeIntervalMicroSeconds32( KRoamingToWlanUpdateInterval ), 
  1030         MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIapL - \
  1004                    TCallBack( StartForcedRoamingToConnectedWlanL, this ) );
  1031 reading info for forced roaming fails with err %d, forced roaming fails", err )
  1005             }
       
  1006         else
       
  1007             {
       
  1008             StartForcedRoamingToWlanL( iapInfo );
       
  1009             }
       
  1010 
       
  1011         StartForcedRoamingFromWlanL( iapInfo );
       
  1012         }
  1032         }
  1013     
  1033     
  1014     MPMLOGSTRING2(
  1034     MPMLOGSTRING2(
  1015     "CMPMServer::NotifyBMPrefIapL - Send notifications for %d sessions", 
  1035     "CMPMServer::NotifyBMPrefIapL - Send notifications for %d sessions", 
  1016         iSessions.Count() )
  1036         iSessions.Count() )
  1046     for ( TInt i( 0 ); i < iSessions.Count(); i++ )
  1066     for ( TInt i( 0 ); i < iSessions.Count(); i++ )
  1047         {
  1067         {
  1048         iSessions[i]->UpdateConnectionDialogL();
  1068         iSessions[i]->UpdateConnectionDialogL();
  1049         }
  1069         }
  1050     }
  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         }
       
  1102     }
       
  1103 
  1051 
  1104 
  1052 // -----------------------------------------------------------------------------
  1105 // -----------------------------------------------------------------------------
  1053 // CMPMServer::HandleServerBlackListIap
  1106 // CMPMServer::HandleServerBlackListIap
  1054 // -----------------------------------------------------------------------------
  1107 // -----------------------------------------------------------------------------
  1055 //
  1108 //
  1188     {
  1241     {
  1189     MPMLOGSTRING3( "CMPMServer::HandleServerUnblackListIap -\
  1242     MPMLOGSTRING3( "CMPMServer::HandleServerUnblackListIap -\
  1190 aCategory = %i blacklisted Id count = %d", 
  1243 aCategory = %i blacklisted Id count = %d", 
  1191                    aCategory, iBlackListIdList.Count() )
  1244                    aCategory, iBlackListIdList.Count() )
  1192 
  1245 
  1193     for( TInt i( 0 ); i < iBlackListIdList.Count(); i++ )
  1246     for (TInt i = iBlackListIdList.Count()-1; i >= 0; i--)
  1194         {
  1247         {
  1195         // found blacklisted Connection Id
  1248         // found blacklisted Connection Id
  1196         TMPMBlackListConnId connIdInfo = iBlackListIdList[i];
  1249         TMPMBlackListConnId connIdInfo = iBlackListIdList[i];
  1197         iBlackListIdList.Remove( i ); // remove from the list 
  1250         iBlackListIdList.Remove( i ); // remove from the list 
  1198 
  1251 
  1199         MPMLOGSTRING3( "CMPMServer::HandleServerUnblackListIap - \
  1252         MPMLOGSTRING3( "CMPMServer::HandleServerUnblackListIap - \
  1200 aConnId = 0x%x, blacklisted IapId count = %d", connIdInfo.iConnId, 
  1253 aConnId = 0x%x, blacklisted IapId count = %d", connIdInfo.iConnId, 
  1201         connIdInfo.Count() )
  1254         connIdInfo.Count() )
  1202         
  1255         
  1203         for (TInt j = 0; j < connIdInfo.Count(); j++)
  1256         for (TInt j = connIdInfo.Count()-1; j >= 0; j--)
  1204             {
  1257             {
  1205             if ( connIdInfo.Category( j ) == aCategory ) 
  1258             if ( connIdInfo.Category( j ) == aCategory ) 
  1206                 {
  1259                 {
  1207                 // found and remove blacklisted iap
  1260                 // found and remove blacklisted iap
  1208                 MPMLOGSTRING3( "CMPMServer::HandleServerUnblackListIap - \
  1261                 MPMLOGSTRING3( "CMPMServer::HandleServerUnblackListIap - \
  1825 // -----------------------------------------------------------------------------
  1878 // -----------------------------------------------------------------------------
  1826 //
  1879 //
  1827 void CMPMServer::StartForcedRoamingToWlanL( const TConnMonIapInfo& aIapInfo )
  1880 void CMPMServer::StartForcedRoamingToWlanL( const TConnMonIapInfo& aIapInfo )
  1828     {
  1881     {
  1829     MPMLOGSTRING( "CMPMServer::StartForcedRoamingToWlan" )
  1882     MPMLOGSTRING( "CMPMServer::StartForcedRoamingToWlan" )
  1830     
  1883  
  1831     // cancel the periodic object
       
  1832     if ( iRoamingToWlanPeriodic != NULL )
       
  1833         {
       
  1834         iRoamingToWlanPeriodic->Cancel();
       
  1835         }
       
  1836 
       
  1837     // Copy all available wlan iap ids to own array
  1884     // Copy all available wlan iap ids to own array
  1838     RArray<TUint32> wlanIapIds;
  1885     RArray<TUint32> wlanIapIds;
  1839     CleanupClosePushL( wlanIapIds );
  1886     CleanupClosePushL( wlanIapIds );
  1840     RAvailableIAPList iapList;
  1887     RAvailableIAPList iapList;
  1841     CleanupClosePushL( iapList );
  1888     CleanupClosePushL( iapList );
  1842 
  1889 
  1843     for ( TUint index = 0; index < aIapInfo.iCount; index++ )
  1890     for ( TUint index = 0; index < aIapInfo.iCount; index++ )
  1844         {
  1891         {
  1845         if ( CommsDatAccess()->CheckWlanL( aIapInfo.iIap[index].iIapId ) != ENotWlanIap )
  1892         TWlanIapType iapType ( ENotWlanIap );
       
  1893         TRAPD (leave, iapType = CommsDatAccess()->CheckWlanL( aIapInfo.iIap[index].iIapId ) );
       
  1894         if ( ( iapType != ENotWlanIap ) && ( leave == KErrNone ) )
  1846             {
  1895             {
  1847             // Accept only wlan iaps in internet snap
  1896             // Accept only wlan iaps in internet snap
  1848             if ( iCommsDatAccess->IsInternetSnapL( aIapInfo.iIap[index].iIapId, 0 ) )
  1897             if ( iCommsDatAccess->IsInternetSnapL( aIapInfo.iIap[index].iIapId, 0 ) )
  1849                 {
  1898                 {
  1850                 wlanIapIds.AppendL( aIapInfo.iIap[index].iIapId );
  1899                 wlanIapIds.AppendL( aIapInfo.iIap[index].iIapId );
  1851                 }
  1900                 }
  1852             }
  1901             }
  1853         // Fill iap list to be used later to check best iap
  1902         // Fill iap list to be used later to check best iap;
  1854         iapList.AppendL( aIapInfo.iIap[index].iIapId );
  1903         if ( leave == KErrNone )
  1855         }
  1904             {
  1856 
  1905             iapList.AppendL( aIapInfo.iIap[index].iIapId );
       
  1906             }
       
  1907         }
  1857     // No wlans available -> no reason to continue
  1908     // No wlans available -> no reason to continue
  1858     if ( !wlanIapIds.Count() )
  1909     if ( !wlanIapIds.Count() )
  1859         {
  1910         {
  1860         CleanupStack::PopAndDestroy( &iapList );
  1911         CleanupStack::PopAndDestroy( &iapList );
  1861         CleanupStack::PopAndDestroy( &wlanIapIds );
  1912         CleanupStack::PopAndDestroy( &wlanIapIds );
  1896 // CMPMServer::StartForcedRoamingToConnectedWlanL
  1947 // CMPMServer::StartForcedRoamingToConnectedWlanL
  1897 // ---------------------------------------------------------------------------
  1948 // ---------------------------------------------------------------------------
  1898 //    
  1949 //    
  1899 TInt CMPMServer::StartForcedRoamingToConnectedWlanL( TAny* aUpdater )
  1950 TInt CMPMServer::StartForcedRoamingToConnectedWlanL( TAny* aUpdater )
  1900     {
  1951     {
  1901     MPMLOGSTRING( "CMPMServer::StartForcedRoamingToConnectedWlanL" );
  1952     MPMLOGSTRING( "CMPMServer::StartForcedRoamingToConnectedWlanL" )
  1902     static_cast<CMPMServer*>( aUpdater )->StartForcedRoamingToWlanL( 
  1953     CMPMServer* self = static_cast<CMPMServer*>( aUpdater );
  1903             static_cast<CMPMServer*>( aUpdater )->iConnMonIapInfo );
  1954     if ( self )
       
  1955         {
       
  1956         // cancel the periodic object        
       
  1957         self->iRoamingToWlanPeriodic->Cancel();
       
  1958         self->StartForcedRoamingToWlanL( self->iConnMonIapInfo );
       
  1959         }
  1904     return 0;
  1960     return 0;
  1905     }
  1961     }
  1906 
  1962 
       
  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     }
  1907 
  1979 
  1908 // -----------------------------------------------------------------------------
  1980 // -----------------------------------------------------------------------------
  1909 // CMPMServer::StartForcedRoamingFromWlanL
  1981 // CMPMServer::StartForcedRoamingFromWlanL
  1910 // -----------------------------------------------------------------------------
  1982 // -----------------------------------------------------------------------------
  1911 //
  1983 //
  2136 // ---------------------------------------------------------------------------
  2208 // ---------------------------------------------------------------------------
  2137 // CMPMServer::StopCellularConns
  2209 // CMPMServer::StopCellularConns
  2138 // Stop all cellular connections except MMS
  2210 // Stop all cellular connections except MMS
  2139 // ---------------------------------------------------------------------------
  2211 // ---------------------------------------------------------------------------
  2140 //
  2212 //
  2141 void CMPMServer::StopCellularConns()
  2213 void CMPMServer::StopCellularConns( TBool aSilentOnly )
  2142     {
  2214     {
  2143     MPMLOGSTRING( "CMPMServer::StopCellularConns" )
  2215     MPMLOGSTRING( "CMPMServer::StopCellularConns" )
  2144 
  2216 
  2145     TUint32 iapId;
  2217     TUint32 iapId;
  2146 	TMPMBearerType bearerType = EMPMBearerTypeNone;
  2218 	TMPMBearerType bearerType = EMPMBearerTypeNone;
  2165                 err = RProperty::Get( KMPMCathegory, KMPMPropertyKeyMMS, mmsIap );
  2237                 err = RProperty::Get( KMPMCathegory, KMPMPropertyKeyMMS, mmsIap );
  2166                 // Check that it's not MMS IAP.
  2238                 // Check that it's not MMS IAP.
  2167                 if (!(err == KErrNone && iapId == mmsIap))
  2239                 if (!(err == KErrNone && iapId == mmsIap))
  2168                     {
  2240                     {
  2169                     // Stop the conn / IAP.
  2241                     // Stop the conn / IAP.
  2170                     StopConnections( iapId );
  2242                     if ( aSilentOnly )
       
  2243                         {
       
  2244                         CheckIapForDisconnect( iapId );
       
  2245                         }
       
  2246                     else
       
  2247                         {
       
  2248                         StopConnections( iapId );
       
  2249                         }
  2171                     stoppedIaps.Append( iapId );
  2250                     stoppedIaps.Append( iapId );
  2172                     }
  2251                     }
  2173                 }
  2252                 }
  2174             }
  2253             }
  2175         }
  2254         }
  2243     MPMLOGSTRING( "CMPMServer::SetOfflineWlanQueryResponse" )
  2322     MPMLOGSTRING( "CMPMServer::SetOfflineWlanQueryResponse" )
  2244 
  2323 
  2245     iOfflineWlanQueryResponse = aResponse;
  2324     iOfflineWlanQueryResponse = aResponse;
  2246     }
  2325     }
  2247 
  2326 
       
  2327 // ---------------------------------------------------------------------------
       
  2328 // CMPMServer::StartConnPermQueryTimer
       
  2329 // Starts the connection permission query timer.
       
  2330 // ---------------------------------------------------------------------------
       
  2331 //
       
  2332 void CMPMServer::StartConnPermQueryTimer()
       
  2333     {
       
  2334     MPMLOGSTRING( "CMPMServer::StartConnPermQueryTimer" )
       
  2335 
       
  2336     if ( !iConnPermQueryTimer )
       
  2337         {
       
  2338         TRAPD( err, iConnPermQueryTimer = CMPMConnPermQueryTimer::NewL( this ) );
       
  2339         if ( err == KErrNone )
       
  2340             {
       
  2341             iConnPermQueryTimer->StartTimer();
       
  2342             MPMLOGSTRING( "CMPMServer::StartConnPermQueryTimer: Ok." )
       
  2343             }
       
  2344         }
       
  2345     }
       
  2346 
       
  2347 // ---------------------------------------------------------------------------
       
  2348 // CMPMServer::ResetConnPermQueryTimer
       
  2349 // Resets the connection permission query timer.
       
  2350 // ---------------------------------------------------------------------------
       
  2351 //
       
  2352 void CMPMServer::ResetConnPermQueryTimer()
       
  2353     {
       
  2354     MPMLOGSTRING( "CMPMServer::ResetConnPermQueryTimer" )
       
  2355 
       
  2356     if ( iConnPermQueryTimer )
       
  2357         {
       
  2358         delete iConnPermQueryTimer;
       
  2359         iConnPermQueryTimer = NULL;
       
  2360         MPMLOGSTRING( "CMPMServer::ResetConnPermQueryTimer: Ok." )
       
  2361         }
       
  2362     }
       
  2363 
       
  2364 // ---------------------------------------------------------------------------
       
  2365 // CMPMServer::IsConnPermQueryTimerOn
       
  2366 // Tells if the connection permission query timer is on.
       
  2367 // ---------------------------------------------------------------------------
       
  2368 //
       
  2369 TBool CMPMServer::IsConnPermQueryTimerOn()
       
  2370     {
       
  2371     MPMLOGSTRING( "CMPMServer::IsConnPermQueryTimerOn" )
       
  2372 
       
  2373     TBool retval = EFalse;
       
  2374     if ( iConnPermQueryTimer )
       
  2375         {
       
  2376         retval = ETrue;
       
  2377         MPMLOGSTRING( "CMPMServer::IsConnPermQueryTimerOn: Yes." )
       
  2378         }
       
  2379     return retval;
       
  2380     }
       
  2381 
       
  2382 // -----------------------------------------------------------------------------
       
  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 
  2248 // -----------------------------------------------------------------------------
  2455 // -----------------------------------------------------------------------------
  2249 // TMPMBlackListConnId::Append
  2456 // TMPMBlackListConnId::Append
  2250 // -----------------------------------------------------------------------------
  2457 // -----------------------------------------------------------------------------
  2251 //
  2458 //
  2252 void TMPMBlackListConnId::Append( TUint32 aIap, TBlacklistCategory aCategory )
  2459 void TMPMBlackListConnId::Append( TUint32 aIap, TBlacklistCategory aCategory )