bearermanagement/mpm/src/mpmserver.cpp
changeset 41 bbb64eb3bdee
parent 40 c5b848e6c7d1
child 44 a0c4ceac30d0
equal deleted inserted replaced
40:c5b848e6c7d1 41:bbb64eb3bdee
    37 #include "mpmconfirmdlgroaming.h"
    37 #include "mpmconfirmdlgroaming.h"
    38 #include "mpmconfirmdlgstarting.h"
    38 #include "mpmconfirmdlgstarting.h"
    39 #include "mpmcommsdataccess.h"
    39 #include "mpmcommsdataccess.h"
    40 #include "mpmprivatecrkeys.h"
    40 #include "mpmprivatecrkeys.h"
    41 #include "mpmcsidwatcher.h"
    41 #include "mpmcsidwatcher.h"
       
    42 #include "mpmvpntogglewatcher.h"
    42 #include "mpmdatausagewatcher.h"
    43 #include "mpmdatausagewatcher.h"
    43 #include "mpmpropertydef.h"
    44 #include "mpmpropertydef.h"
    44 #include "mpmofflinewatcher.h"
    45 
    45 
    46 static const TUint32 KUidKmdServer = 0x1000088A;
       
    47     
    46 // ============================= LOCAL FUNCTIONS ===============================
    48 // ============================= LOCAL FUNCTIONS ===============================
    47 
    49 
    48 // -----------------------------------------------------------------------------
    50 // -----------------------------------------------------------------------------
    49 // PanicServer 
    51 // PanicServer 
    50 // Panics the server in case of programming error.
    52 // Panics the server in case of programming error.
    80     : CPolicyServer( CPolicyServer::EPriorityStandard, KMPMPolicy ),
    82     : CPolicyServer( CPolicyServer::EPriorityStandard, KMPMPolicy ),
    81       iEvents( NULL ), 
    83       iEvents( NULL ), 
    82       iTSYLoaded( EFalse ),
    84       iTSYLoaded( EFalse ),
    83       iPacketServLoaded( EFalse ), 
    85       iPacketServLoaded( EFalse ), 
    84       iDtmWatcher( NULL ), 
    86       iDtmWatcher( NULL ), 
       
    87       iRoamingWatcher( NULL ),
    85       iWLANScanRequired( EFalse ), 
    88       iWLANScanRequired( EFalse ), 
    86       iRoamingQueue( NULL ), 
    89       iRoamingQueue( NULL ), 
    87       iStartingQueue( NULL ),
    90       iStartingQueue( NULL ),
    88       iConnectionCounter( 0 ),
    91       iConnectionCounter( 0 ),
    89       iOfflineMode( ECoreAppUIsNetworkConnectionAllowed )
    92       iUserConnection( EFalse ),
       
    93       iUserConnectionInInternet( EFalse ),
       
    94       iVpnUserConnectionSessionCount( 0 ),
       
    95       iMpmCsIdWatcher( NULL ),
       
    96       iMpmVpnToggleWatcher( NULL ),
       
    97       iMpmDataUsageWatcher( NULL ),
       
    98       iCommsDatAccess( NULL ),
       
    99       iConnUiUtils( NULL ),
       
   100       iOfflineMode( ECoreAppUIsNetworkConnectionAllowed ),
       
   101       iOfflineWlanQueryResponse( EOfflineResponseUndefined ),      
       
   102       iRoamingToWlanPeriodic( NULL )
    90     {
   103     {
    91     }
   104     }
    92 
   105 
    93 
   106 
    94 // -----------------------------------------------------------------------------
   107 // -----------------------------------------------------------------------------
   155     iStartingQueue->Reset();
   168     iStartingQueue->Reset();
   156 
   169 
   157     // Create central repository watcher and start it
   170     // Create central repository watcher and start it
   158     iMpmCsIdWatcher = CMpmCsIdWatcher::NewL();
   171     iMpmCsIdWatcher = CMpmCsIdWatcher::NewL();
   159     iMpmCsIdWatcher->StartL();
   172     iMpmCsIdWatcher->StartL();
       
   173     
       
   174     // Create VPN toggle central repository watcher and start it
       
   175     iMpmVpnToggleWatcher = CMpmVpnToggleWatcher::NewL( *this );
   160 
   176 
   161     // Create another central repository watcher and start it
   177     // Create another central repository watcher and start it
   162     TRAPD( duwErr, iMpmDataUsageWatcher = CMpmDataUsageWatcher::NewL( this ) );
   178     TRAPD( duwErr, iMpmDataUsageWatcher = CMpmDataUsageWatcher::NewL( this ) );
   163     if (duwErr == KErrNone)
   179     if (duwErr == KErrNone)
   164         {
   180         {
   168         {
   184         {
   169         iMpmDataUsageWatcher = NULL;
   185         iMpmDataUsageWatcher = NULL;
   170         MPMLOGSTRING( "CMPMServer::ConstructL: CMpmDataUsageWatcher::NewL() failed!" )
   186         MPMLOGSTRING( "CMPMServer::ConstructL: CMpmDataUsageWatcher::NewL() failed!" )
   171         }
   187         }
   172 
   188 
   173     // Create another central repository watcher and start it
       
   174     TRAPD( owErr, iMpmOfflineWatcher = CMpmOfflineWatcher::NewL( this ) );
       
   175     if (owErr == KErrNone)
       
   176         {
       
   177         iMpmOfflineWatcher->StartL();
       
   178         }
       
   179     else
       
   180         {
       
   181         iMpmOfflineWatcher = NULL;
       
   182         MPMLOGSTRING( "CMPMServer::ConstructL: CMpmOfflineWatcher::NewL() failed!" )
       
   183         }
       
   184 
       
   185     // Read dedicated clients from the central repository
   189     // Read dedicated clients from the central repository
   186     CRepository* repository = CRepository::NewL( KCRUidMPM );
   190     CRepository* repository = CRepository::NewL( KCRUidMPM );
   187     
   191     
   188     CleanupStack::PushL( repository );
   192     CleanupStack::PushL( repository );
   189     
   193     
   254 
   258 
   255     iMobilePhone.Close();
   259     iMobilePhone.Close();
   256     iTelServer.Close();
   260     iTelServer.Close();
   257     
   261     
   258     delete iMpmCsIdWatcher;    
   262     delete iMpmCsIdWatcher;    
   259     
   263        
       
   264     delete iMpmVpnToggleWatcher;
       
   265  
   260     delete iMpmDataUsageWatcher;    
   266     delete iMpmDataUsageWatcher;    
   261 
   267 
   262     delete iMpmOfflineWatcher;    
       
   263 
       
   264     iDedicatedClients.Close();
   268     iDedicatedClients.Close();
   265 
   269 
   266     delete iCommsDatAccess;
   270     delete iCommsDatAccess;
   267     
   271     
   268     delete iConnUiUtils;
   272     delete iConnUiUtils;
   269     }
   273     }
   270 
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // CMPMServer::SetVpnToggleValuesL
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 void CMPMServer::SetVpnToggleValuesL( const TBool aVpnPreferred,
       
   280                                       const TUint32 /*aVpnIapId*/,
       
   281                                       const TUint32 /*aSnapId*/ )
       
   282     {
       
   283     MPMLOGSTRING2("CMPMServer::SetVpnToggleValues, VPN connection preferred: %d",
       
   284             aVpnPreferred)
       
   285     if ( aVpnPreferred )
       
   286         {
       
   287         // Stop Internet connections, except if VPN user connection
       
   288         // would not be made with current preferences when reconnecting.
       
   289         for (TInt index = 0; index < iSessions.Count(); index++)
       
   290             {
       
   291             CMPMServerSession* session = iSessions[index];
       
   292             TUint32 iapId = GetBMIap( session->ConnectionId() );
       
   293             TUint32 snapId = GetBMSnap( session->ConnectionId() );
       
   294             
       
   295             if ( (session->ChooseBestIapCalled()) &&
       
   296                  (!session->IapSelectionL()->MpmConnPref().MandateIap()) &&
       
   297                  (session->AppUid() != KUidKmdServer) &&                 
       
   298                  (!session->UserConnection()) &&                 
       
   299                  iCommsDatAccess->IsInternetSnapL(iapId, snapId) )
       
   300                 {
       
   301                 // Stop connection.
       
   302                 MPMLOGSTRING2( "CMPMServer::SetVpnToggleValuesL: \
       
   303  Disconnected Connection Id = 0x%x", session->ConnectionId() )            
       
   304                 session->ClientErrorNotificationL(KErrForceDisconnected);
       
   305                 }
       
   306             }        
       
   307         }
       
   308     else
       
   309         {
       
   310         // Stop connections, which use VPN user connection.
       
   311         for (TInt index = 0; index < iSessions.Count(); index++)
       
   312             {
       
   313             CMPMServerSession* session = iSessions[index];
       
   314             if ( session->VpnUserConnectionUsed() )
       
   315                 {
       
   316                 session->SetVpnUserConnectionUsed( EFalse );                    
       
   317                 // Stop connection.
       
   318                 MPMLOGSTRING2( "CMPMServer::SetVpnToggleValuesL: \
       
   319  Disconnected Connection Id = 0x%x", session->ConnectionId() )            
       
   320                 session->ClientErrorNotificationL(KErrForceDisconnected);
       
   321                 }
       
   322             }
       
   323         ASSERT( iVpnUserConnectionSessionCount == 0 );
       
   324         }    
       
   325     }
   271 
   326 
   272 // -----------------------------------------------------------------------------
   327 // -----------------------------------------------------------------------------
   273 // CMPMServer::NewSessionL
   328 // CMPMServer::NewSessionL
   274 // -----------------------------------------------------------------------------
   329 // -----------------------------------------------------------------------------
   275 //
   330 //
  1772             }
  1827             }
  1773         }
  1828         }
  1774     stoppedIaps.Close();
  1829     stoppedIaps.Close();
  1775     }
  1830     }
  1776 
  1831 
       
  1832 // -----------------------------------------------------------------------------
       
  1833 // CMPMServer::AddVpnUserConnectionSession
       
  1834 // -----------------------------------------------------------------------------
       
  1835 //
       
  1836 void CMPMServer::AddVpnUserConnectionSession()
       
  1837     {
       
  1838     iVpnUserConnectionSessionCount++;
       
  1839     }
       
  1840 
       
  1841 // -----------------------------------------------------------------------------
       
  1842 // CMPMServer::RemoveVpnUserConnectionSession
       
  1843 // -----------------------------------------------------------------------------
       
  1844 //
       
  1845 void CMPMServer::RemoveVpnUserConnectionSession()
       
  1846     {    
       
  1847     ASSERT( iVpnUserConnectionSessionCount > 0 );
       
  1848     iVpnUserConnectionSessionCount--;
       
  1849     }
       
  1850 
       
  1851 // ---------------------------------------------------------------------------
       
  1852 // CMPMServer::UseVpnUserConnection
       
  1853 // Informs if VPN user connection is used with given MPM preferences and
       
  1854 // application.
       
  1855 // ---------------------------------------------------------------------------
       
  1856 //
       
  1857 TBool CMPMServer::UseVpnUserConnection( const TMpmConnPref aMpmConnPref,
       
  1858                                         const TUint32 aAppUid ) const
       
  1859     {    
       
  1860     if ( iMpmVpnToggleWatcher->IsVpnConnectionPreferred() &&
       
  1861          !aMpmConnPref.MandateIap() &&
       
  1862          aAppUid != KUidKmdServer &&
       
  1863          aAppUid != iMpmCsIdWatcher->ConnectScreenId() )
       
  1864         {
       
  1865         // VPN connection is preferred connection, connection preferences are
       
  1866         // not mandatet and client is not KMD server or Connect Screen.            
       
  1867         if ( aMpmConnPref.ConnType() == TMpmConnPref::EConnTypeDefault ||
       
  1868              aMpmConnPref.ConnType() == TMpmConnPref::EConnTypeImplicit )
       
  1869             {
       
  1870             // Default or implicit connection is requested.
       
  1871             // VPN user connection is used.
       
  1872             return ETrue;
       
  1873             }
       
  1874         else
       
  1875             {
       
  1876             // Explicit connection is requested.
       
  1877             TBool internetSnap(EFalse);    
       
  1878             TRAPD( err, internetSnap = iCommsDatAccess->IsInternetSnapL( aMpmConnPref.IapId(),
       
  1879                                                                          aMpmConnPref.SnapId() ) );
       
  1880             if ( err == KErrNone &&
       
  1881                  internetSnap )
       
  1882                 {
       
  1883                 // Connection belongs to Internet SNAP.
       
  1884                 // VPN user connection is used.
       
  1885                 return ETrue;
       
  1886                 }
       
  1887             }
       
  1888         }
       
  1889     
       
  1890     // VPN user connection is not used.
       
  1891     return EFalse;    
       
  1892     }
       
  1893 
       
  1894 // -----------------------------------------------------------------------------
       
  1895 // CMPMServer::PrepareVpnUserConnection
       
  1896 // -----------------------------------------------------------------------------
       
  1897 //
       
  1898 TBool CMPMServer::PrepareVpnUserConnection( TMpmConnPref& aMpmConnPref )
       
  1899     {
       
  1900     // Get VPN IAP Id or SNAP Id, which is used for VPN user connection. 
       
  1901     TUint32 vpnIapId = iMpmVpnToggleWatcher->VpnIapId();
       
  1902     TUint32 snapId = iMpmVpnToggleWatcher->SnapId();
       
  1903 
       
  1904     // Check first if SNAP Id is set, in which case VPN IAP Id is ignored.
       
  1905     if ( snapId != 0 )
       
  1906         {
       
  1907         TBool intranetSnap( EFalse );   
       
  1908         TRAPD( err , intranetSnap = 
       
  1909             iCommsDatAccess->IsIntranetSnapL( snapId ) );
       
  1910         if ( (err != KErrNone) ||
       
  1911              (!intranetSnap) )
       
  1912             {
       
  1913             // SNAP is not intranet SNAP.
       
  1914             // Reset VPN toggle values and continue without using VPN user
       
  1915             // connection.
       
  1916             MPMLOGSTRING3( "CMPMServer::PrepareVpnUserConnection failed, \
       
  1917 SNAP Id=%d, err=%d", snapId, err );
       
  1918         
       
  1919             iMpmVpnToggleWatcher->ResetVpnToggleValues();        
       
  1920             return EFalse;
       
  1921             }        
       
  1922         aMpmConnPref.SetIapId( 0 );
       
  1923         aMpmConnPref.SetSnapId( snapId );               
       
  1924         }
       
  1925     else
       
  1926         {
       
  1927         // Validate that IAP is VPN IAP. 
       
  1928         TMPMBearerType bearerType = EMPMBearerTypeNone;
       
  1929         TRAPD( err, bearerType = iCommsDatAccess->GetBearerTypeL( vpnIapId ) );        
       
  1930         if ( (err != KErrNone) ||
       
  1931              (bearerType != EMPMBearerTypeVpn) )
       
  1932             {        
       
  1933             // IAP is not valid VPN IAP.
       
  1934             // Reset VPN toggle values and continue without using VPN user
       
  1935             // connection.
       
  1936             MPMLOGSTRING4( "CMPMServer::PrepareVpnUserConnection failed, \
       
  1937 IAP Id=%d, err=%d, bearerType=%d", vpnIapId, err, bearerType );
       
  1938         
       
  1939             iMpmVpnToggleWatcher->ResetVpnToggleValues();
       
  1940             return EFalse;
       
  1941             }
       
  1942         aMpmConnPref.SetIapId( vpnIapId );
       
  1943         aMpmConnPref.SetSnapId( 0 );            
       
  1944         }
       
  1945    
       
  1946     aMpmConnPref.SetConnType( TMpmConnPref::EConnTypeExplicit );
       
  1947     
       
  1948     // VPN user connection will be activated.
       
  1949     return ETrue;        
       
  1950     }
       
  1951 
  1777 // ---------------------------------------------------------------------------
  1952 // ---------------------------------------------------------------------------
  1778 // CMPMServer::UpdateOfflineMode
  1953 // CMPMServer::UpdateOfflineMode
  1779 // Offline watcher listens the offline mode and calls this when it's changed.
  1954 // Offline watcher listens the offline mode and calls this when it's changed.
  1780 // ---------------------------------------------------------------------------
  1955 // ---------------------------------------------------------------------------
  1781 //
  1956 //