bearermanagement/mpm/src/mpmserver.cpp
changeset 0 5a93021fdf25
child 3 f7816ffc66ed
equal deleted inserted replaced
-1:000000000000 0:5a93021fdf25
       
     1 /*
       
     2 * Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: MPM server implementation
       
    15 *
       
    16 */
       
    17 
       
    18 /**
       
    19 @file mpmserver.cpp
       
    20 Mobility Policy Manager server implementation.
       
    21 */
       
    22 
       
    23 // INCLUDE FILES
       
    24 #include <commdb.h>
       
    25 #include <etel3rdparty.h>                // Voice call notification
       
    26 #include <mmtsy_names.h>                 // KMmTsyModuleName
       
    27 #include <centralrepository.h>
       
    28 
       
    29 #include "mpmserver.h"
       
    30 #include "mpmserversession.h"
       
    31 #include "mpmconnmonevents.h"
       
    32 #include "mpmlogger.h"
       
    33 #include "mpmdtmwatcher.h"
       
    34 #include "mpmroamingwatcher.h"
       
    35 #include "mpmdisconnectdlg.h"
       
    36 #include "mpmconfirmdlgroaming.h"
       
    37 #include "mpmconfirmdlgstarting.h"
       
    38 #include "mpmdefaultconnection.h"
       
    39 #include "mpmcommsdataccess.h"
       
    40 #include "mpmwlanquerydialog.h"
       
    41 #include "mpmdialog.h"
       
    42 #include "mpmprivatecrkeys.h"
       
    43 #include "mpmcsidwatcher.h"
       
    44 
       
    45 // ============================= LOCAL FUNCTIONS ===============================
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // PanicServer 
       
    49 // Panics the server in case of programming error.
       
    50 // -----------------------------------------------------------------------------
       
    51 //
       
    52 void PanicServer( TInt aPanic )
       
    53     {
       
    54     User::Panic( KMPMPanicCategory, aPanic );
       
    55     }
       
    56 
       
    57 
       
    58 // ============================ MEMBER FUNCTIONS ===============================
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 // CMPMServer::NewL
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 CMPMServer* CMPMServer::NewL()
       
    65     {
       
    66     CMPMServer* self = new ( ELeave ) CMPMServer();
       
    67     CleanupStack::PushL( self );
       
    68     self->ConstructL();
       
    69     CleanupStack::Pop( self );
       
    70     return self;
       
    71     }
       
    72 
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // CMPMServer::CMPMServer
       
    76 // -----------------------------------------------------------------------------
       
    77 //
       
    78 CMPMServer::CMPMServer()
       
    79     : CPolicyServer( CPolicyServer::EPriorityStandard, KMPMPolicy ),
       
    80       iEvents( NULL ), 
       
    81       iTSYLoaded( EFalse ),
       
    82       iPacketServLoaded( EFalse ), 
       
    83       iDtmWatcher( NULL ), 
       
    84       iWLANScanRequired( EFalse ), 
       
    85       iDisconnectQueue( NULL ), 
       
    86       iRoamingQueue( NULL ), 
       
    87       iStartingQueue( NULL ),
       
    88       iWlanQueryQueue( NULL ),
       
    89       iConnectDialogQueue( NULL ),
       
    90       iDefaultConnection( NULL ), 
       
    91       iConnectionCounter( 0 )
       
    92     {
       
    93     }
       
    94 
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CMPMServer::ConstructL
       
    98 // -----------------------------------------------------------------------------
       
    99 //
       
   100 void CMPMServer::ConstructL()
       
   101     {
       
   102     // identify ourselves and open for service
       
   103     MPMLOGSTRING( "MPMServer is starting" )
       
   104     StartL( KMPMServerName );
       
   105 
       
   106     // Connect to ETel server
       
   107     // The RTelServer::Connect() might not always work with the first trial,
       
   108     // because of a coding error related to using semaphores in the method.
       
   109     TInt err( KErrNotReady );
       
   110     TInt a = 0;
       
   111     while( a < KPhoneRetryCount && err != KErrNone )
       
   112         {
       
   113         User::After( KPhoneRetryTimeout );
       
   114         err = iTelServer.Connect();
       
   115         a++;       
       
   116         }
       
   117     User::LeaveIfError( err );
       
   118        
       
   119     // Try to load phone.tsy
       
   120     TBuf< KCommsDbSvrMaxColumnNameLength > tsyName;
       
   121     tsyName.Copy( KMmTsyModuleName );
       
   122     err = iTelServer.LoadPhoneModule( tsyName );
       
   123 
       
   124     if ( err == KErrNone )
       
   125         {
       
   126         iTSYLoaded = ETrue;
       
   127         // Phone info can be retrieved with value 0 if there is only 1 phone
       
   128         RTelServer::TPhoneInfo info;
       
   129         User::LeaveIfError( iTelServer.GetPhoneInfo( 0, info ) );
       
   130         User::LeaveIfError( iMobilePhone.Open( iTelServer, info.iName ) );
       
   131 
       
   132         // Open packet service
       
   133         err = iPacketService.Open( iMobilePhone );
       
   134         if ( err == KErrNone )
       
   135             {
       
   136             iPacketServLoaded = ETrue;
       
   137             iDtmWatcher = CMPMDtmWatcher::NewL( iPacketService );
       
   138             }
       
   139 #ifdef _DEBUG
       
   140         else
       
   141             {
       
   142             MPMLOGSTRING2( 
       
   143                 "CMPMServer::ConstructL iPacketService.Open error: %d", err )  
       
   144             }
       
   145 #endif // _DEBUG
       
   146         }
       
   147     
       
   148     iRoamingWatcher = CMPMRoamingWatcher::NewL(iMobilePhone);
       
   149 
       
   150     iCommsDatAccess = CMPMCommsDatAccess::NewL( );
       
   151     
       
   152     iDisconnectQueue = new ( ELeave ) CArrayPtrFlat<CMPMDisconnectDlg>( KGranularity );
       
   153     iDisconnectQueue->Reset();
       
   154 
       
   155     iRoamingQueue = new ( ELeave ) CArrayPtrFlat<CMPMConfirmDlgRoaming>( KGranularity );
       
   156     iRoamingQueue->Reset();
       
   157 
       
   158     iStartingQueue = new ( ELeave ) CArrayPtrFlat<CMPMConfirmDlgStarting>( KGranularity ); 
       
   159     iStartingQueue->Reset();
       
   160 
       
   161     iWlanQueryQueue = new ( ELeave ) CArrayPtrFlat<CMPMWlanQueryDialog>( KGranularity );
       
   162     iWlanQueryQueue->Reset();
       
   163 
       
   164     iConnectDialogQueue = new ( ELeave ) CArrayPtrFlat<CMPMDialog>( KGranularity );
       
   165     iConnectDialogQueue->Reset();
       
   166     
       
   167     iDefaultConnection = CMPMDefaultConnection::NewL( this );    
       
   168 
       
   169     // Create central repository watcher and start it
       
   170     iMpmCsIdWatcher = CMpmCsIdWatcher::NewL();
       
   171     iMpmCsIdWatcher->StartL();
       
   172 
       
   173     // Define P&S keys (snap & iap) for the user connection
       
   174     TInt ret = RProperty::Define( KMPMUserConnectionCategory,
       
   175                                   KMPMPSKeyUserConnectionSnap,
       
   176                                   KMPMUserConnectionSnapType,
       
   177                                   KMPMUserConnectionReadPolicy,
       
   178                                   KMPMUserConnectionWritePolicy );
       
   179     
       
   180     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   181         {
       
   182         User::Leave(err);
       
   183         }
       
   184     
       
   185     ret = RProperty::Define( KMPMUserConnectionCategory,
       
   186                              KMPMPSKeyUserConnectionIap,
       
   187                              KMPMUserConnectionIapType,
       
   188                              KMPMUserConnectionReadPolicy,
       
   189                              KMPMUserConnectionWritePolicy );
       
   190                                           
       
   191     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   192         {
       
   193         User::Leave(err);
       
   194         }
       
   195 
       
   196     // Set initial values for the keys
       
   197     User::LeaveIfError(RProperty::Set( KMPMUserConnectionCategory,
       
   198                                        KMPMPSKeyUserConnectionSnap,
       
   199                                        0 ));
       
   200 
       
   201     User::LeaveIfError(RProperty::Set( KMPMUserConnectionCategory,
       
   202                                        KMPMPSKeyUserConnectionIap,
       
   203                                        0 ));
       
   204 
       
   205     // Read dedicated clients from the central repository
       
   206     CRepository* repository = CRepository::NewL( KCRUidMPM );
       
   207     
       
   208     CleanupStack::PushL( repository );
       
   209     
       
   210     TUint32 baseKey = KMpmDedicatedClientBase;
       
   211     TInt value;
       
   212     ret = KErrNone;
       
   213     
       
   214     while ( ret == KErrNone )
       
   215         {
       
   216         ret = repository->Get ( baseKey, value );
       
   217 
       
   218         if ( ret == KErrNone )
       
   219             {
       
   220             iDedicatedClients.AppendL( value );
       
   221             MPMLOGSTRING2( "CMPMServer::ConstructL: Dedicated client id: %d", value)
       
   222             }
       
   223 
       
   224         baseKey++;
       
   225         }
       
   226     
       
   227     CleanupStack::PopAndDestroy ( repository );
       
   228     
       
   229     // Define P&S keys for the connection dialogs
       
   230     ret = RProperty::Define( KMPMActiveConnectionCategory,
       
   231                              KMPMPSKeyActiveConnectionIap,
       
   232                              KMPMActiveConnectionIapType,
       
   233                              KMPMActiveConnectionReadPolicy,
       
   234                              KMPMActiveConnectionWritePolicy );
       
   235     
       
   236     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   237         {
       
   238         User::Leave(err);
       
   239         }
       
   240     
       
   241     ret = RProperty::Define( KMPMActiveConnectionCategory,
       
   242                              KMPMPSKeyActiveConnectionSnap,
       
   243                              KMPMActiveConnectionSnapType,
       
   244                              KMPMActiveConnectionReadPolicy,
       
   245                              KMPMActiveConnectionWritePolicy );
       
   246     
       
   247     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   248         {
       
   249         User::Leave(err);
       
   250         }
       
   251 
       
   252     ret = RProperty::Define( KMPMActiveConnectionCategory,
       
   253                              KMPMPSKeyActiveConnectionBearer,
       
   254                              KMPMActiveConnectionBearerType,
       
   255                              KMPMActiveConnectionReadPolicy,
       
   256                              KMPMActiveConnectionWritePolicy );
       
   257                                           
       
   258     if ( (ret != KErrNone) && (ret != KErrAlreadyExists) )
       
   259         {
       
   260         User::Leave(err);
       
   261         }
       
   262         
       
   263     PublishActiveConnection();
       
   264     }
       
   265 
       
   266 
       
   267 // -----------------------------------------------------------------------------
       
   268 // CMPMServer::~CMPMServer
       
   269 // -----------------------------------------------------------------------------
       
   270 //
       
   271 CMPMServer::~CMPMServer()
       
   272     {
       
   273     if ( iDisconnectQueue )
       
   274         {
       
   275         iDisconnectQueue->ResetAndDestroy();
       
   276         }
       
   277     delete iDisconnectQueue;
       
   278 
       
   279     if ( iRoamingQueue )
       
   280         {
       
   281         iRoamingQueue->ResetAndDestroy();
       
   282         }
       
   283     delete iRoamingQueue;
       
   284 
       
   285     if ( iStartingQueue )
       
   286         {
       
   287         iStartingQueue->ResetAndDestroy();
       
   288         }
       
   289     delete iStartingQueue;
       
   290 
       
   291     while ( iWlanQueryQueue && iWlanQueryQueue->Count() > 0 )
       
   292         {
       
   293         iWlanQueryQueue->Delete( 0 );
       
   294         }
       
   295     delete iWlanQueryQueue;
       
   296     
       
   297     if ( iConnectDialogQueue )
       
   298         {
       
   299         iConnectDialogQueue->ResetAndDestroy();
       
   300         }
       
   301     delete iConnectDialogQueue;
       
   302 
       
   303     delete iEvents;
       
   304 
       
   305     for ( TInt i = 0; i < iBlackListIdList.Count(); i++ )
       
   306         {
       
   307         iBlackListIdList[i].Close();
       
   308         }
       
   309 
       
   310     iActiveBMConns.Close();
       
   311     iSessions.Close();
       
   312 
       
   313     delete iDtmWatcher;
       
   314     delete iRoamingWatcher;
       
   315 
       
   316     // Close "global" ETEL objects
       
   317     if ( iPacketServLoaded )
       
   318         {
       
   319         iPacketService.Close();
       
   320         }    
       
   321 
       
   322     iMobilePhone.Close();
       
   323     iTelServer.Close();
       
   324     
       
   325     delete iDefaultConnection;
       
   326     
       
   327     delete iMpmCsIdWatcher;    
       
   328     
       
   329     iDedicatedClients.Close();
       
   330 
       
   331     delete iCommsDatAccess;    
       
   332     }
       
   333 
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // CMPMServer::NewSessionL
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 CSession2* CMPMServer::NewSessionL(
       
   340     const TVersion& aVersion,
       
   341     const RMessage2& /*aMessage*/) const
       
   342     {
       
   343     MPMLOGSTRING( "CMPMServer::NewSessionL" )
       
   344     // Check we're the right version
       
   345     if ( !User::QueryVersionSupported(TVersion(KMPMServerMajorVersionNumber,
       
   346                                                KMPMServerMinorVersionNumber,
       
   347                                                KMPMServerBuildVersionNumber ),
       
   348                                      aVersion ) )
       
   349         {
       
   350         User::Leave( KErrNotSupported );
       
   351         }
       
   352 
       
   353     CSession2* session = CMPMServerSession::NewL( 
       
   354                              *const_cast<CMPMServer*>( this ));
       
   355     return session;
       
   356     }
       
   357 
       
   358 // -----------------------------------------------------------------------------
       
   359 // CMPMServer::PanicClient
       
   360 // -----------------------------------------------------------------------------
       
   361 //
       
   362 void CMPMServer::PanicClient(
       
   363     const TInt aPanic) const
       
   364     {
       
   365     // let's have a look before we panic the client
       
   366     __DEBUGGER()
       
   367     // ok, go for it
       
   368     RThread clientThread;
       
   369 
       
   370     TInt err = Message().Client( clientThread );
       
   371 
       
   372     if ( err == KErrNone )
       
   373         {
       
   374         clientThread.Panic( KMPMServerName, aPanic );
       
   375         clientThread.Close();
       
   376         }
       
   377     }
       
   378 
       
   379 
       
   380 // -----------------------------------------------------------------------------
       
   381 // CMPMServer::AppendBMConnection
       
   382 // -----------------------------------------------------------------------------
       
   383 //
       
   384 void CMPMServer::AppendBMConnection( const TConnectionId aConnId, 
       
   385                                      const TUint32       aSnap,
       
   386                                      const TUint32       aIapId, 
       
   387                                      TConnectionState    aState,
       
   388                                      CMPMServerSession&  aSession )
       
   389     {
       
   390     MPMLOGSTRING3(
       
   391         "CMPMServer::AppendBMConnection - aConnId = 0x%x, aSnap = %i",
       
   392         aConnId, aSnap )
       
   393 
       
   394     // Set the Connection Id, SNAP, Iap Id and connection state
       
   395     // 
       
   396     TConnectionInfo connInfo;
       
   397     connInfo.iConnId = aConnId;
       
   398     connInfo.iSnap   = aSnap;
       
   399     connInfo.iIapId  = aIapId;
       
   400     connInfo.iState  = aState;
       
   401 
       
   402     // Package into TActiveBMConn //TODO Redundant.. remove the other one.
       
   403     // 
       
   404     TActiveBMConn conn;
       
   405     conn.iConnInfo          = connInfo;
       
   406 
       
   407     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
       
   408 
       
   409     if ( index1 == KErrNotFound )
       
   410         {
       
   411         // If this connInfo is not yet there, insert it at the end of array
       
   412         //
       
   413         iActiveBMConns.Append( conn );
       
   414         }
       
   415     else
       
   416         {
       
   417         // connInfo already active, check whether Connection Id is there
       
   418         //
       
   419         if ( index1 < iActiveBMConns.Count() )
       
   420             {
       
   421             // Set the Iap Id and connection state
       
   422             // 
       
   423             iActiveBMConns[index1].iConnInfo.iIapId = aIapId;
       
   424             iActiveBMConns[index1].iConnInfo.iState = aState;
       
   425             iActiveBMConns[index1].iConnInfo.iAppUid = aSession.AppUid();
       
   426             }
       
   427         }
       
   428 
       
   429     if ( aState == EStarted )
       
   430         {
       
   431         TInt ret = KErrNone;
       
   432         
       
   433         TRAP ( ret, UpdateActiveConnectionL( aSession ) );
       
   434         
       
   435         if ( ret != KErrNone )
       
   436             {
       
   437             iActiveBearerType = EMPMBearerTypeNone;
       
   438             iActiveIapId = 0;
       
   439             iActiveSnapId = 0;            
       
   440             }
       
   441         }
       
   442 
       
   443 #ifdef _DEBUG
       
   444     // Dump array of active connections to log in order to support testing.
       
   445     // 
       
   446     DumpActiveBMConns();
       
   447 #endif // _DEBUG
       
   448     }
       
   449 
       
   450 
       
   451 // -----------------------------------------------------------------------------
       
   452 // CMPMServer::ResetBMConnection
       
   453 // -----------------------------------------------------------------------------
       
   454 //
       
   455 void CMPMServer::ResetBMConnection( const TConnectionId aConnId,
       
   456                                     const TUint32       aIapId,
       
   457                                     CMPMServerSession&  aSession )
       
   458     {
       
   459     MPMLOGSTRING3(
       
   460         "CMPMServer::ResetBMConnection - aConnId = 0x%x, aIapId = %i", 
       
   461         aConnId, aIapId )
       
   462 
       
   463     // Get the current connection SNAP for this Connection Id
       
   464     //
       
   465     TUint32 snap = GetBMSnap( aConnId );
       
   466 
       
   467     // Set the Connection Id and SNAP
       
   468     // 
       
   469     TConnectionInfo connInfo;
       
   470     connInfo.iConnId = aConnId;
       
   471     connInfo.iSnap   = snap;
       
   472 
       
   473     // Set the Iap Id 
       
   474     // 
       
   475     TActiveBMConn conn;
       
   476     conn.iConnInfo          = connInfo;
       
   477     conn.iConnInfo.iIapId   = aIapId;
       
   478 
       
   479     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
       
   480 
       
   481     if ( ( index1 != KErrNotFound ) && ( index1 < iActiveBMConns.Count() ) )
       
   482 //       && ( aIapId == iActiveBMConns[index1].iConnInfo.iIapId ) )
       
   483         {
       
   484         // If connInfo found, reset the Iap Id as zero and 
       
   485         // update connection state as EIdle.
       
   486         // 
       
   487         // It is expected that MPM keeps the Connection Id and SNAP 
       
   488         // relationship in a database entry and that this entry survives 
       
   489         // a roaming event (an ApplicationLeavesConnection call).
       
   490         //
       
   491         iActiveBMConns[index1].iConnInfo.iIapId = 0;
       
   492         iActiveBMConns[index1].iConnInfo.iState = EIdle;
       
   493         
       
   494         // Change state of P&S keys if needed
       
   495         TInt ret = KErrNone;
       
   496         
       
   497         TRAP ( ret, UpdateActiveConnectionL( aSession ) );
       
   498         
       
   499         if ( ret != KErrNone )
       
   500             {
       
   501             iActiveBearerType = EMPMBearerTypeNone;
       
   502             iActiveIapId = 0;
       
   503             iActiveSnapId = 0;            
       
   504             }
       
   505         }
       
   506 #ifdef _DEBUG
       
   507     // Dump array of active connections to log in order to support testing.
       
   508     // 
       
   509     DumpActiveBMConns();
       
   510 #endif // _DEBUG
       
   511     }
       
   512 
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CMPMServer::RemoveBMConnection
       
   516 // -----------------------------------------------------------------------------
       
   517 //
       
   518 void CMPMServer::RemoveBMConnection( const TConnectionId aConnId,
       
   519                                      CMPMServerSession&  aSession )
       
   520     {
       
   521     MPMLOGSTRING2( "CMPMServer::RemoveBMConnection - aConnId = 0x%x", 
       
   522         aConnId )
       
   523 
       
   524     TInt count = iActiveBMConns.Count();
       
   525     
       
   526     // Decrement by one, because count is n, 
       
   527     // but indexes in array are 0 .. n-1.
       
   528     // 
       
   529     count--;
       
   530 
       
   531     // This time we are browsing the array from the end to the beginning, 
       
   532     // because removing one element from array affects index numbering.
       
   533     // 
       
   534     for ( TInt i = count; i >= 0; i-- )
       
   535         {
       
   536         if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
       
   537             {
       
   538             // If Connection Id found, remove it. 
       
   539             //
       
   540             iActiveBMConns.Remove( i );
       
   541 
       
   542             // Update active connection
       
   543             TInt ret = KErrNone;
       
   544         
       
   545             TRAP ( ret, UpdateActiveConnectionL( aSession ) );
       
   546         
       
   547             if ( ret != KErrNone )
       
   548                 {
       
   549                 iActiveBearerType = EMPMBearerTypeNone;
       
   550                 iActiveIapId = 0;
       
   551                 iActiveSnapId = 0;            
       
   552                 }
       
   553             }
       
   554         }
       
   555 
       
   556 #ifdef _DEBUG
       
   557     // Dump array of active connections to log in order to support testing.
       
   558     // 
       
   559     DumpActiveBMConns();
       
   560 #endif // _DEBUG
       
   561     }
       
   562 
       
   563 // -----------------------------------------------------------------------------
       
   564 // CMPMServer::GetBMIap
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 TUint32 CMPMServer::GetBMIap( const TConnectionId aConnId )
       
   568     {
       
   569     MPMLOGSTRING2( "CMPMServer::GetBMIap - aConnId = 0x%x", aConnId )
       
   570 
       
   571     TUint32 connectionIapId( 0 );
       
   572 
       
   573     // Set the Connection Id and SNAP
       
   574     // 
       
   575     TConnectionInfo connInfo;
       
   576     connInfo.iConnId = aConnId;
       
   577 
       
   578     TActiveBMConn conn;
       
   579     conn.iConnInfo = connInfo;
       
   580 
       
   581     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
       
   582 
       
   583     if ( ( index1 != KErrNotFound ) && ( index1 < iActiveBMConns.Count() ) )
       
   584         {
       
   585         // If connInfo found, set the Iap Id as connectionIapId
       
   586         //
       
   587         connectionIapId = iActiveBMConns[index1].iConnInfo.iIapId;
       
   588         }
       
   589 
       
   590     MPMLOGSTRING2( "CMPMServer::GetBMIap - connectionIapId = %i", 
       
   591         connectionIapId )
       
   592     return connectionIapId;
       
   593     }
       
   594 
       
   595 
       
   596 // -----------------------------------------------------------------------------
       
   597 // CMPMServer::GetBMSnap
       
   598 // -----------------------------------------------------------------------------
       
   599 //
       
   600 TUint32 CMPMServer::GetBMSnap( const TConnectionId aConnId )
       
   601     {
       
   602     MPMLOGSTRING2( "CMPMServer::GetBMSnap - aConnId = 0x%x", aConnId )
       
   603 
       
   604     TUint32 snap( 0 );
       
   605     TBool   snapFound( EFalse );
       
   606 
       
   607     for ( TInt i = 0; ( ( i < iActiveBMConns.Count() ) && !snapFound ); i++ )
       
   608         {
       
   609         if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
       
   610             {
       
   611             snap = iActiveBMConns[i].iConnInfo.iSnap;
       
   612             snapFound = ETrue;
       
   613             }
       
   614         }
       
   615     MPMLOGSTRING2( "CMPMServer::GetBMSnap - SNAP = %i", snap )
       
   616     return snap;
       
   617     }
       
   618 
       
   619 // -----------------------------------------------------------------------------
       
   620 // CMPMServer::GetConnectionState
       
   621 // -----------------------------------------------------------------------------
       
   622 //
       
   623 void CMPMServer::GetConnectionState( const TConnectionId    aConnId,
       
   624                                      TConnectionState&      aState )
       
   625     {
       
   626     MPMLOGSTRING2( "CMPMServer::GetConnectionState - aConnId = 0x%x", 
       
   627         aConnId )
       
   628 
       
   629     TConnectionInfo connInfo;
       
   630     connInfo.iConnId = aConnId; 
       
   631 
       
   632     TActiveBMConn conn;
       
   633     conn.iConnInfo = connInfo;
       
   634 
       
   635     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchConnInfo );
       
   636 
       
   637     if ( ( index1 != KErrNotFound ) && ( index1 < iActiveBMConns.Count() ) )
       
   638         {
       
   639         // If connInfo found
       
   640         //
       
   641         aState = iActiveBMConns[index1].iConnInfo.iState;
       
   642         }
       
   643     else
       
   644         {
       
   645         // Since connInfo has no entry in iActiveBMConns, then 
       
   646         // the state of connection must be EStarting.
       
   647         // 
       
   648         aState = EStarting;
       
   649         }
       
   650 
       
   651 #ifdef _DEBUG
       
   652     switch( aState )
       
   653         {
       
   654         case EStarting:
       
   655             {
       
   656             MPMLOGSTRING( "CMPMServer::GetConnectionState - Starting" )
       
   657             break;
       
   658             }
       
   659         case EStarted:
       
   660             {
       
   661             MPMLOGSTRING( "CMPMServer::GetConnectionState - Started" )
       
   662             break;
       
   663             }
       
   664         case EIdle:
       
   665             {
       
   666             MPMLOGSTRING( "CMPMServer::GetConnectionState - Idle" )
       
   667             break;
       
   668             }
       
   669         case ERoaming:
       
   670             {
       
   671             MPMLOGSTRING( "CMPMServer::GetConnectionState - Roaming" )
       
   672             break;
       
   673             }
       
   674         default:
       
   675             {
       
   676             MPMLOGSTRING( "CMPMServer::GetConnectionState - Unknown" )
       
   677             break;
       
   678             }
       
   679         }
       
   680 #endif // _DEBUG
       
   681     }
       
   682 
       
   683 // -----------------------------------------------------------------------------
       
   684 // CMPMServer::CheckIfStarted
       
   685 // -----------------------------------------------------------------------------
       
   686 //
       
   687 TBool CMPMServer::CheckIfStarted( const TUint32 aIapId )
       
   688     {
       
   689     MPMLOGSTRING2( "CMPMServer::CheckIfStarted - aIapId = %i", aIapId )
       
   690 
       
   691     TConnectionState state( EIdle );
       
   692     TBool stopLoop( EFalse );
       
   693 
       
   694     // Loop all connections until EStarted is found or no more connections
       
   695     // 
       
   696     for ( TInt i = 0; ( ( i < iActiveBMConns.Count() ) && !stopLoop ); i++ )
       
   697         {
       
   698         // Check if IAP Id matches
       
   699         // 
       
   700         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId )
       
   701             {
       
   702             state = iActiveBMConns[i].iConnInfo.iState;  
       
   703 
       
   704             // Stop looping if EStarted found
       
   705             // 
       
   706             if ( state == EStarted )
       
   707                 {
       
   708                 stopLoop = ETrue;
       
   709                 }
       
   710             }
       
   711         }
       
   712 
       
   713 #ifdef _DEBUG
       
   714     switch( state )
       
   715         {
       
   716         case EStarting:
       
   717             {
       
   718             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Starting" )
       
   719             break;
       
   720             }
       
   721         case EStarted:
       
   722             {
       
   723             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Started" )
       
   724             break;
       
   725             }
       
   726         case EIdle:
       
   727             {
       
   728             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Idle" )
       
   729             break;
       
   730             }
       
   731         case ERoaming:
       
   732             {
       
   733             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Roaming" )
       
   734             break;
       
   735             }
       
   736         default:
       
   737             {
       
   738             MPMLOGSTRING( "CMPMServer::CheckIfStarted - Unknown" )
       
   739             break;
       
   740             }
       
   741         }
       
   742 #endif // _DEBUG
       
   743 
       
   744     if ( state == EStarted )
       
   745         {
       
   746         return ETrue;
       
   747         }
       
   748     else
       
   749         {
       
   750         return EFalse;
       
   751         }
       
   752     }
       
   753 
       
   754 // -----------------------------------------------------------------------------
       
   755 // CMPMServer::IsWlanConnectionStartedL
       
   756 // -----------------------------------------------------------------------------
       
   757 //
       
   758 TUint32 CMPMServer::IsWlanConnectionStartedL( const CMPMCommsDatAccess* aCdbAccess )
       
   759     {
       
   760     TUint32 iapId( 0 );
       
   761     
       
   762     MPMLOGSTRING( "CMPMServer::IsWlanConnectionStartedL" )
       
   763 
       
   764     TBool stopLoop( EFalse );
       
   765 
       
   766     // Loop all connections until EStarted is found or no more connections
       
   767     // 
       
   768     for ( TInt i = 0; ( ( i < iActiveBMConns.Count() ) && !stopLoop ); i++ )
       
   769         {
       
   770         // Check if IAP Id matches
       
   771         // 
       
   772         if ( iActiveBMConns[i].iConnInfo.iState == EStarting ||
       
   773              iActiveBMConns[i].iConnInfo.iState == EStarted )
       
   774             {
       
   775             if ( aCdbAccess->CheckWlanL( iActiveBMConns[i].iConnInfo.iIapId ) != ENotWlanIap )
       
   776                 {
       
   777                 stopLoop = ETrue;
       
   778                 iapId = iActiveBMConns[i].iConnInfo.iIapId;
       
   779                 MPMLOGSTRING2( "CMPMServer::IsWlanConnectionStartedL, found wlan iap %d", iapId )
       
   780                 }
       
   781             }
       
   782         }
       
   783 
       
   784     
       
   785     return iapId;
       
   786     }
       
   787 
       
   788 // -----------------------------------------------------------------------------
       
   789 // CMPMServer::AppendBMIAPConnectionL
       
   790 // -----------------------------------------------------------------------------
       
   791 //
       
   792 void CMPMServer::AppendBMIAPConnectionL( const TUint32       aIapId, 
       
   793                                          const TConnectionId aConnId,
       
   794                                          CMPMServerSession& aSession )
       
   795     {
       
   796     MPMLOGSTRING3(
       
   797         "CMPMServer::AppendBMIAPConnectionL - aIapId = %i, aConnId = 0x%x", 
       
   798         aIapId, aConnId )
       
   799 
       
   800     TActiveBMConn conn;
       
   801     conn.iConnInfo.iIapId = aIapId;
       
   802     conn.iConnInfo.iState = EStarted;
       
   803     conn.iConnInfo.iAppUid = aSession.AppUid();
       
   804     
       
   805     TInt index1 = iActiveBMConns.Find( conn, TActiveBMConn::MatchIapId );
       
   806 
       
   807     if ( index1 == KErrNotFound )
       
   808         {
       
   809         // If this Iap is not yet there, insert it at the end of array
       
   810         //
       
   811         iActiveBMConns.AppendL( conn );
       
   812         }
       
   813     else
       
   814         {
       
   815         // Iap already active, update connection state as started. 
       
   816         // This Iap could be shared by multiple applications, but 
       
   817         // update only the one with matching connection id.
       
   818         //
       
   819         for ( TInt i = 0; i < iActiveBMConns.Count(); i++ )
       
   820             {
       
   821             if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
       
   822                 {
       
   823                 iActiveBMConns[i].iConnInfo.iState = EStarted;
       
   824                 }
       
   825             else if ( iActiveBMConns[i].iConnInfo.iSnap == 0 &&
       
   826                     iActiveBMConns[i].iConnInfo.iIapId == aIapId )
       
   827                 {
       
   828                 iActiveBMConns[i].iConnInfo.iState = EStarted;
       
   829                 }
       
   830             }
       
   831         }
       
   832 
       
   833     TInt ret = KErrNone;
       
   834         
       
   835     TRAP ( ret, UpdateActiveConnectionL( aSession ) );
       
   836         
       
   837     if ( ret != KErrNone )
       
   838         {
       
   839         iActiveBearerType = EMPMBearerTypeNone;
       
   840         iActiveIapId = 0;
       
   841         iActiveSnapId = 0;            
       
   842         }
       
   843 
       
   844 #ifdef _DEBUG
       
   845     // Dump array of active connections to log in order to support testing.
       
   846     // 
       
   847     DumpActiveBMConns();
       
   848 #endif // _DEBUG
       
   849     }
       
   850 
       
   851 
       
   852 // -----------------------------------------------------------------------------
       
   853 // CMPMServer::RemoveBMIAPConnection
       
   854 // -----------------------------------------------------------------------------
       
   855 //
       
   856 void CMPMServer::RemoveBMIAPConnection( const TUint32       aIapId, 
       
   857                                         const TConnectionId aConnId,
       
   858                                         CMPMServerSession&  aSession )
       
   859     {
       
   860     MPMLOGSTRING3(
       
   861         "CMPMServer::RemoveBMIAPConnection - aIapId = %i, aConnId = 0x%x", 
       
   862         aIapId, aConnId )
       
   863 
       
   864     TActiveBMConn conn;
       
   865     conn.iConnInfo.iIapId = aIapId;
       
   866 
       
   867     // The IAP connection lifetime is determined by the two calls 
       
   868     // IAPConnectionStarted and IAPConnectionStopped. 
       
   869     //
       
   870     TInt count = iActiveBMConns.Count();
       
   871 
       
   872     // Decrement by one, because count is n, 
       
   873     // but indexes in array are 0 .. n-1.
       
   874     // 
       
   875     count--;
       
   876 
       
   877     // This time we are browsing the array from the end to the beginning, 
       
   878     // because removing one element from array affects index numbering.
       
   879     // 
       
   880     for ( TInt i = count; i >= 0; i-- )
       
   881         {
       
   882         if ( iActiveBMConns[i].iConnInfo.iIapId == aIapId )
       
   883             {
       
   884             if ( iActiveBMConns[i].iConnInfo.iSnap == 0 )
       
   885                 {
       
   886                 // If IAPConnectionStopped has been called and SNAP is zero,
       
   887                 // then this entry can be removed from database.
       
   888                 // 
       
   889                 iActiveBMConns.Remove( i );
       
   890                 }
       
   891             else
       
   892                 {
       
   893                 // If IAP found, reset the Iap Id as zero and 
       
   894                 // update connection state as idle.
       
   895                 // This Iap could be shared by multiple applications, 
       
   896                 // but update only the one with matching connection id.
       
   897                 // 
       
   898                 if ( iActiveBMConns[i].iConnInfo.iConnId == aConnId )
       
   899                     {
       
   900                     iActiveBMConns[i].iConnInfo.iIapId = 0;
       
   901                     iActiveBMConns[i].iConnInfo.iState = EIdle;
       
   902                     }
       
   903                 }
       
   904             
       
   905             // Update active connection
       
   906             TInt ret = KErrNone;
       
   907         
       
   908             TRAP ( ret, UpdateActiveConnectionL( aSession ) );
       
   909         
       
   910             if ( ret != KErrNone )
       
   911                 {
       
   912                 iActiveBearerType = EMPMBearerTypeNone;
       
   913                 iActiveIapId = 0;
       
   914                 iActiveSnapId = 0;            
       
   915                 }
       
   916             }
       
   917         }
       
   918 
       
   919 #ifdef _DEBUG
       
   920     // Dump array of active connections to log in order to support testing.
       
   921     // 
       
   922     DumpActiveBMConns();
       
   923 #endif // _DEBUG
       
   924     }
       
   925 
       
   926 
       
   927 // -----------------------------------------------------------------------------
       
   928 // CMPMServer::AppendSessionL
       
   929 // -----------------------------------------------------------------------------
       
   930 //
       
   931 void CMPMServer::AppendSessionL( const CMPMServerSession* aSession )
       
   932     {
       
   933     MPMLOGSTRING( "CMPMServer::AppendSession" )
       
   934     
       
   935     iSessions.AppendL( aSession );
       
   936     }
       
   937 
       
   938 
       
   939 // -----------------------------------------------------------------------------
       
   940 // CMPMServer::RemoveSession
       
   941 // -----------------------------------------------------------------------------
       
   942 //
       
   943 void CMPMServer::RemoveSession( const CMPMServerSession* aSession )
       
   944     {
       
   945     MPMLOGSTRING( "CMPMServer::RemoveSession" )
       
   946 
       
   947     TInt index = iSessions.Find( aSession );
       
   948     if ( index != KErrNotFound )
       
   949         {
       
   950         iSessions.Remove( index );
       
   951         }
       
   952     }
       
   953 
       
   954 // -----------------------------------------------------------------------------
       
   955 // CMPMServer::NotifyBMPrefIapL
       
   956 // -----------------------------------------------------------------------------
       
   957 //
       
   958 void CMPMServer::NotifyBMPrefIapL( const TConnMonIapInfo& aIapInfo )
       
   959     {
       
   960     MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIapL - IAPs count: %d", 
       
   961         aIapInfo.iCount)
       
   962     TConnMonIapInfo iapInfo = aIapInfo;
       
   963     
       
   964 #ifdef _DEBUG
       
   965     for (TUint i = 0; i < iapInfo.Count(); i++)
       
   966         {
       
   967         MPMLOGSTRING2( "CMPMServer::NotifyBMPrefIap - IAP: %d", 
       
   968             iapInfo.iIap[i].iIapId) 
       
   969         }
       
   970 #endif // _DEBUG
       
   971 
       
   972     // Start possible forced roaming
       
   973     TCmUsageOfWlan usageOfWlan = CommsDatAccess()->ForcedRoamingL();
       
   974     if ( usageOfWlan == ECmUsageOfWlanKnown || usageOfWlan == ECmUsageOfWlanKnownAndNew )
       
   975         {
       
   976         StartForcedRoamingToWlanL( iapInfo );
       
   977         StartForcedRoamingFromWlanL( iapInfo );
       
   978         }
       
   979     
       
   980     MPMLOGSTRING2(
       
   981     "CMPMServer::NotifyBMPrefIapL - Send notifications for %d sessions", 
       
   982         iSessions.Count() )
       
   983 
       
   984     for ( TInt i = 0; i < iSessions.Count(); i++ )
       
   985         {
       
   986         iapInfo = iSessions[i]->GetAvailableIAPs( );
       
   987         iSessions[i]->PrefIAPNotificationL( iapInfo, EConnMon );
       
   988         }
       
   989 
       
   990     // If a session is displaying connection selection dialog 
       
   991     // the contents of the dialog should be updated according to the 
       
   992     // current iap availability
       
   993     //
       
   994     for ( TInt i( 0 ); i < iSessions.Count(); i++ )
       
   995         {
       
   996         iSessions[i]->UpdateConnectionDialogL();
       
   997         }
       
   998     }
       
   999 
       
  1000 // -----------------------------------------------------------------------------
       
  1001 // CMPMServer::UpdateSessionConnectionDlgL
       
  1002 // -----------------------------------------------------------------------------
       
  1003 //
       
  1004 void CMPMServer::UpdateSessionConnectionDlgL()
       
  1005     {
       
  1006     MPMLOGSTRING( "CMPMServer::UpdateSessionConnectionDlgL" )
       
  1007 
       
  1008     // If a session is displaying connection selection dialog 
       
  1009     // the contents of the dialog should be updated according to the 
       
  1010     // current iap availability
       
  1011     //
       
  1012     for ( TInt i( 0 ); i < iSessions.Count(); i++ )
       
  1013         {
       
  1014         iSessions[i]->UpdateConnectionDialogL();
       
  1015         }
       
  1016     }
       
  1017 
       
  1018 // -----------------------------------------------------------------------------
       
  1019 // CMPMServer::HandleServerBlackListIap
       
  1020 // -----------------------------------------------------------------------------
       
  1021 //
       
  1022 TInt CMPMServer::HandleServerBlackListIap( const TConnectionId  aConnId,
       
  1023                                            TUint32              aIapId, 
       
  1024                                            TBlacklistCategory   aCategory )
       
  1025     {
       
  1026     MPMLOGSTRING3(
       
  1027         "CMPMServer::HandleServerBlackListIap - aConnId = 0x%x, iapId = %i",
       
  1028         aConnId, aIapId )
       
  1029 
       
  1030     MPMLOGSTRING2(
       
  1031         "CMPMServer::HandleServerBlackListIap - aCategory = %i", aCategory )
       
  1032 
       
  1033     BlackListIap( aConnId, aIapId, aCategory ); 
       
  1034 
       
  1035     TUint32 presumedIap = Events()->PresumedIapId( aConnId, 
       
  1036                                                    aIapId );
       
  1037     if ( ( presumedIap != 0 ) && 
       
  1038          ( presumedIap != aIapId ) )
       
  1039         {
       
  1040         MPMLOGSTRING2(
       
  1041             "CMPMServer::HandleServerBlackListIap - presumedIap = %i",
       
  1042             presumedIap )
       
  1043         BlackListIap( aConnId, presumedIap, aCategory ); 
       
  1044         }
       
  1045 
       
  1046     return KErrNone;
       
  1047     }
       
  1048 
       
  1049 
       
  1050 // -----------------------------------------------------------------------------
       
  1051 // CMPMServer::BlackListIap
       
  1052 // -----------------------------------------------------------------------------
       
  1053 //
       
  1054 TInt CMPMServer::BlackListIap( const TConnectionId  aConnId,
       
  1055                                TUint32              aIapId, 
       
  1056                                TBlacklistCategory   aCategory )
       
  1057     {
       
  1058     TInt i;
       
  1059     TBool found = EFalse;
       
  1060 
       
  1061     found = FindBlacklistedConnIndex( aConnId, i );
       
  1062     if ( found )
       
  1063         {
       
  1064         TMPMBlackListConnId connIdInfo = iBlackListIdList[i];
       
  1065         connIdInfo.Append( aIapId, aCategory );
       
  1066         iBlackListIdList.Remove( i );
       
  1067         iBlackListIdList.Insert( connIdInfo, 0 );
       
  1068         }
       
  1069     else
       
  1070         {
       
  1071         TMPMBlackListConnId connIdInfo;
       
  1072         connIdInfo.iConnId = aConnId;
       
  1073         connIdInfo.Append( aIapId, aCategory );
       
  1074         iBlackListIdList.Insert( connIdInfo, 0 );
       
  1075         }
       
  1076 
       
  1077     return KErrNone;
       
  1078     }
       
  1079 
       
  1080 
       
  1081 // -----------------------------------------------------------------------------
       
  1082 // CMPMServer::HandleServerUnblackListIap
       
  1083 // -----------------------------------------------------------------------------
       
  1084 //
       
  1085 TInt CMPMServer::HandleServerUnblackListIap( 
       
  1086     const TConnectionId aConnId,
       
  1087     TUint32             aIapId )
       
  1088     {
       
  1089     MPMLOGSTRING3(
       
  1090         "CMPMServer::HandleServerUnblackListIap - aConnId = 0x%x, iapId = %i"
       
  1091         ,aConnId, aIapId )
       
  1092 
       
  1093     TInt i;
       
  1094     TBool found = EFalse;
       
  1095 
       
  1096     found = FindBlacklistedConnIndex( aConnId, i );
       
  1097     if ( found )
       
  1098         {
       
  1099         // found blacklisted Connection Id
       
  1100         TMPMBlackListConnId connIdInfo = iBlackListIdList[i];
       
  1101         iBlackListIdList.Remove( i ); // remove from the list 
       
  1102 
       
  1103         if ( aIapId == 0 )
       
  1104             { // 0 will reset Connection Id blacklisted iap list 
       
  1105             connIdInfo.Close();
       
  1106             return KErrNone;
       
  1107             }
       
  1108 
       
  1109         found = EFalse;
       
  1110         for (TInt j = 0; j < connIdInfo.Count(); j++)
       
  1111             {
       
  1112             if ( connIdInfo.Iap( j ) == aIapId )
       
  1113                 {
       
  1114                 // found and remove blacklisted iap
       
  1115                 connIdInfo.Remove( j ); 
       
  1116                 if ( connIdInfo.Count() == 0 )
       
  1117                     {
       
  1118                     return KErrNone;
       
  1119                     }
       
  1120 
       
  1121                 // reinsert connIdInfo at the beginning to reflect activeness
       
  1122                 iBlackListIdList.Insert( connIdInfo, 0 ); 
       
  1123                 return KErrNone;
       
  1124                 }
       
  1125             }
       
  1126         // nothing found and reinsert at the beginning 
       
  1127         // connIdInfo to reflect activeness
       
  1128         iBlackListIdList.Insert( connIdInfo, 0 ); 
       
  1129         return KErrNotFound;
       
  1130         }
       
  1131     else
       
  1132         {
       
  1133         return KErrNotFound;
       
  1134         }
       
  1135     }
       
  1136 
       
  1137 
       
  1138 // -----------------------------------------------------------------------------
       
  1139 // CMPMServer::HandleServerUnblackListIap
       
  1140 // -----------------------------------------------------------------------------
       
  1141 //
       
  1142 TInt CMPMServer::HandleServerUnblackListIap( 
       
  1143     const TConnectionId aConnId,
       
  1144     TBlacklistCategory  aCategory )
       
  1145     {
       
  1146     MPMLOGSTRING3( "CMPMServer::HandleServerUnblackListIap -\
       
  1147  aConnId = 0x%x, aCategory = %i", aConnId, aCategory )
       
  1148 
       
  1149     TInt i;
       
  1150     TBool found = EFalse;
       
  1151 
       
  1152     found = FindBlacklistedConnIndex( aConnId, i );
       
  1153     if ( found )
       
  1154         {
       
  1155         // found blacklisted Connection Id
       
  1156         TMPMBlackListConnId connIdInfo = iBlackListIdList[i];
       
  1157         iBlackListIdList.Remove( i ); // remove from the list 
       
  1158 
       
  1159         found = EFalse;
       
  1160         for (TInt j = 0; j < connIdInfo.Count(); j++)
       
  1161             {
       
  1162             if ( connIdInfo.Category( j ) == aCategory ) 
       
  1163                 {
       
  1164                 // found and remove blacklisted iap
       
  1165                 connIdInfo.Remove( j ); 
       
  1166                 if ( connIdInfo.Count() == 0 )
       
  1167                     {
       
  1168                     return KErrNone;
       
  1169                     }
       
  1170 
       
  1171                 // reinsert connIdInfo at the beginning to reflect activeness
       
  1172                 iBlackListIdList.Insert( connIdInfo, 0 ); 
       
  1173                 return KErrNone;
       
  1174                 }
       
  1175             }
       
  1176         // nothing found and reinsert at the beginning 
       
  1177         // connIdInfo to reflect activeness
       
  1178         iBlackListIdList.Insert( connIdInfo, 0 ); 
       
  1179         return KErrNotFound;
       
  1180         }
       
  1181     else
       
  1182         {
       
  1183         return KErrNotFound;
       
  1184         }
       
  1185     }
       
  1186 
       
  1187 
       
  1188 // -----------------------------------------------------------------------------
       
  1189 // CMPMServer::HandleServerUnblackListIap
       
  1190 // -----------------------------------------------------------------------------
       
  1191 //
       
  1192 void CMPMServer::HandleServerUnblackListIap( 
       
  1193     TBlacklistCategory  aCategory )
       
  1194     {
       
  1195     MPMLOGSTRING2( "CMPMServer::HandleServerUnblackListIap -\
       
  1196  aCategory = %i", aCategory )
       
  1197 
       
  1198     for( TInt i( 0 ); i < iBlackListIdList.Count(); i++ )
       
  1199         {
       
  1200         // found blacklisted Connection Id
       
  1201         TMPMBlackListConnId connIdInfo = iBlackListIdList[i];
       
  1202         iBlackListIdList.Remove( i ); // remove from the list 
       
  1203 
       
  1204         for (TInt j = 0; j < connIdInfo.Count(); j++)
       
  1205             {
       
  1206             if ( connIdInfo.Category( j ) == aCategory ) 
       
  1207                 {
       
  1208                 // found and remove blacklisted iap
       
  1209                 connIdInfo.Remove( j ); 
       
  1210                 }
       
  1211             }
       
  1212         // If any blacklisted iaps remain reinsert at the 
       
  1213         // beginning connIdInfo to reflect activeness
       
  1214         //
       
  1215         if( connIdInfo.Count() > 0 )
       
  1216             {
       
  1217             iBlackListIdList.Insert( connIdInfo, 0 );             
       
  1218             }
       
  1219         }
       
  1220     }
       
  1221 
       
  1222 // -----------------------------------------------------------------------------
       
  1223 // CMPMServer::GetBlacklistedIAP
       
  1224 // -----------------------------------------------------------------------------
       
  1225 //
       
  1226 TInt CMPMServer::GetBlacklistedIAP( TConnectionId    aConnId, 
       
  1227                                     RArray<TUint32> &aBlacklistedIAP )
       
  1228     {
       
  1229     TInt  i;
       
  1230     TBool found = EFalse;
       
  1231 
       
  1232     found = FindBlacklistedConnIndex( aConnId, i );
       
  1233     if ( !found )
       
  1234         {
       
  1235         return KErrNotFound;
       
  1236         }
       
  1237 
       
  1238     TMPMBlackListConnId connIdInfo = iBlackListIdList[i];
       
  1239     iBlackListIdList.Remove( i );
       
  1240     iBlackListIdList.Insert( connIdInfo, 0 );
       
  1241 
       
  1242     for (TInt j = 0; j < connIdInfo.Count(); j++)
       
  1243         {
       
  1244         aBlacklistedIAP.Append( connIdInfo.Iap( j ) );
       
  1245         }
       
  1246 
       
  1247     return KErrNone;
       
  1248     }
       
  1249 
       
  1250 
       
  1251 // -----------------------------------------------------------------------------
       
  1252 // CMPMServer::GetBlacklistedIAP
       
  1253 // -----------------------------------------------------------------------------
       
  1254 //
       
  1255 TInt CMPMServer::GetBlacklistedIAP( RArray<TUint32> &aBlacklistedIAP )
       
  1256     {
       
  1257     // Returns all blacklisted IAPs regardless of Connection Id 
       
  1258     // 
       
  1259     for ( TInt i( 0 ); i < iBlackListIdList.Count(); i++ )
       
  1260         {
       
  1261         for ( TInt j( 0 ); j < iBlackListIdList[i].Count(); 
       
  1262               j++ )
       
  1263             {
       
  1264             // Inserts an object into the array in ascending unsigned 
       
  1265             // key order. No duplicate entries are permitted. 
       
  1266             // 
       
  1267             // The array remains unchanged following an attempt to 
       
  1268             // insert a duplicate entry.
       
  1269             // 
       
  1270             aBlacklistedIAP.InsertInUnsignedKeyOrder( 
       
  1271                                     iBlackListIdList[i].Iap( j ) );
       
  1272             }
       
  1273         }
       
  1274     return KErrNone;
       
  1275     }
       
  1276 
       
  1277 
       
  1278 // -----------------------------------------------------------------------------
       
  1279 // CMPMServer::FindId
       
  1280 // -----------------------------------------------------------------------------
       
  1281 //
       
  1282 TBool CMPMServer::FindBlacklistedConnIndex( const TConnectionId aConnId, 
       
  1283                                             TInt                &aIndex )
       
  1284     {
       
  1285     TInt  i;
       
  1286     TBool found = EFalse;
       
  1287 
       
  1288     for (i = 0;( (i < iBlackListIdList.Count()) && !found ); i++)
       
  1289         {
       
  1290         if ( iBlackListIdList[i].iConnId == aConnId )
       
  1291             {
       
  1292             found = ETrue;
       
  1293             }
       
  1294         }
       
  1295     i--; // Since i is incremented after finding the correct iConnId
       
  1296     aIndex = i;
       
  1297     return found;
       
  1298     }
       
  1299 
       
  1300 
       
  1301 // -----------------------------------------------------------------------------
       
  1302 // CMPMServer::IsVoiceCallActiveL
       
  1303 // 
       
  1304 // Checks if voice call is active or not.
       
  1305 // Return ETrue if voice call is active.
       
  1306 // Return EFalse if voice call is not active.
       
  1307 // -----------------------------------------------------------------------------
       
  1308 //
       
  1309 TBool CMPMServer::IsVoiceCallActiveL() const
       
  1310     {
       
  1311     MPMLOGSTRING( "CMPMServer::IsVoiceCallActiveL" )
       
  1312 
       
  1313     CTelephony*                   telephony = CTelephony::NewLC();
       
  1314     CTelephony::TCallStatusV1     callStatusV1;
       
  1315     CTelephony::TCallStatusV1Pckg callStatusV1Pckg( callStatusV1 );
       
  1316     CTelephony::TPhoneLine        line = CTelephony::EVoiceLine;
       
  1317 
       
  1318     telephony->GetLineStatus( line, callStatusV1Pckg );
       
  1319     CTelephony::TCallStatus voiceLineStatus = callStatusV1.iStatus;
       
  1320 
       
  1321     CleanupStack::PopAndDestroy( telephony );
       
  1322 
       
  1323     if ( voiceLineStatus == CTelephony::EStatusDialling         ||
       
  1324          voiceLineStatus == CTelephony::EStatusRinging          ||
       
  1325          voiceLineStatus == CTelephony::EStatusAnswering        ||
       
  1326          voiceLineStatus == CTelephony::EStatusConnecting       ||
       
  1327          voiceLineStatus == CTelephony::EStatusConnected        ||
       
  1328          voiceLineStatus == CTelephony::EStatusReconnectPending ||
       
  1329          voiceLineStatus == CTelephony::EStatusDisconnecting    ||
       
  1330          voiceLineStatus == CTelephony::EStatusHold             ||
       
  1331          voiceLineStatus == CTelephony::EStatusTransferring     ||
       
  1332          voiceLineStatus == CTelephony::EStatusTransferAlerting  )
       
  1333         {
       
  1334         MPMLOGSTRING2(
       
  1335             "CMPMServer::IsVoiceCallActiveL Voice call is active: %d", 
       
  1336             voiceLineStatus )
       
  1337         return ETrue;
       
  1338         }
       
  1339     else if ( voiceLineStatus == CTelephony::EStatusIdle ||
       
  1340               voiceLineStatus == CTelephony::EStatusUnknown )
       
  1341         {
       
  1342         MPMLOGSTRING2(
       
  1343             "CMPMServer::IsVoiceCallActiveL Voice call is not active: %d", 
       
  1344             voiceLineStatus )
       
  1345         return EFalse;
       
  1346         }
       
  1347     else
       
  1348         {
       
  1349         MPMLOGSTRING2(
       
  1350             "CMPMServer::IsVoiceCallActiveL Unknown voice line status: %d", 
       
  1351             voiceLineStatus )
       
  1352         return EFalse;
       
  1353         }
       
  1354     }
       
  1355 
       
  1356 
       
  1357 // -----------------------------------------------------------------------------
       
  1358 // CMPMServer::IsModeGSM
       
  1359 // 
       
  1360 // Checks if mode is GSM or not.
       
  1361 // Return ETrue if mode is GSM.
       
  1362 // Return EFalse if mode is something else.
       
  1363 // -----------------------------------------------------------------------------
       
  1364 //
       
  1365 TBool CMPMServer::IsModeGSM() const
       
  1366     {
       
  1367     MPMLOGSTRING( "CMPMServer::IsModeGSM" )
       
  1368 
       
  1369     if ( iTSYLoaded )
       
  1370         {
       
  1371         RMobilePhone::TMobilePhoneNetworkMode mode( 
       
  1372             RMobilePhone::ENetworkModeUnknown );
       
  1373 
       
  1374         TInt ret = iMobilePhone.GetCurrentMode( mode );
       
  1375 
       
  1376         if ( ( ret == KErrNone ) && 
       
  1377              ( mode == RMobilePhone::ENetworkModeGsm ) )
       
  1378             {
       
  1379             MPMLOGSTRING( "CMPMServer::IsModeGSM Mode is GSM" )
       
  1380             return ETrue;
       
  1381             }
       
  1382         else
       
  1383             {
       
  1384             MPMLOGSTRING( "CMPMServer::IsModeGSM Mode is not GSM" )
       
  1385             return EFalse;
       
  1386             }
       
  1387         }
       
  1388     MPMLOGSTRING( "CMPMServer::IsModeGSM phone.tsy not loaded" )
       
  1389     return EFalse;
       
  1390     }
       
  1391 
       
  1392 
       
  1393 // -----------------------------------------------------------------------------
       
  1394 // CMPMServer::IsDTMSupported
       
  1395 // 
       
  1396 // Checks if phone supports Dual Transfer Mode or not.
       
  1397 // Return ETrue if phone supports DTM.
       
  1398 // Return EFalse if phone does not support DTM.
       
  1399 // -----------------------------------------------------------------------------
       
  1400 //
       
  1401 TBool CMPMServer::IsDTMSupported() const
       
  1402     {
       
  1403     MPMLOGSTRING( "CMPMServer::IsDTMSupported" )
       
  1404 
       
  1405     if ( iPacketServLoaded )
       
  1406         {
       
  1407         TBool rv = iDtmWatcher->IsInDualMode();
       
  1408         if ( rv )
       
  1409             {
       
  1410             MPMLOGSTRING( "CMPMServer::IsDTMSupported DTM is supported" )
       
  1411             }
       
  1412         else
       
  1413             {
       
  1414             MPMLOGSTRING( "CMPMServer::IsDTMSupported DTM is not supported" )
       
  1415             }
       
  1416         return rv;
       
  1417         }
       
  1418  
       
  1419     MPMLOGSTRING( "CMPMServer::IsDTMSupported Packet service not loaded" )
       
  1420     return EFalse;
       
  1421     }
       
  1422 
       
  1423 
       
  1424 // -----------------------------------------------------------------------------
       
  1425 // CMPMServer::DumpActiveBMConns
       
  1426 // -----------------------------------------------------------------------------
       
  1427 //
       
  1428 void CMPMServer::DumpActiveBMConns()
       
  1429     {
       
  1430 #ifdef _DEBUG
       
  1431     // Dump array of active connections to log in order to support testing.
       
  1432     // 
       
  1433     MPMLOGSTRING( "Display array of active connections - Start" )
       
  1434     MPMLOGSTRING( "" )
       
  1435 
       
  1436     if ( iActiveBMConns.Count() == 0 )
       
  1437         {
       
  1438         MPMLOGSTRING( "Array of active connections is empty" )
       
  1439         MPMLOGSTRING( "" )
       
  1440         }
       
  1441 
       
  1442     for ( TInt i = 0; i < iActiveBMConns.Count(); i++ )
       
  1443         {
       
  1444         MPMLOGSTRING3( "Connection Id = 0x%x Snap = %i", 
       
  1445             iActiveBMConns[i].iConnInfo.iConnId, 
       
  1446             iActiveBMConns[i].iConnInfo.iSnap )
       
  1447 
       
  1448         switch( iActiveBMConns[i].iConnInfo.iState )
       
  1449             {
       
  1450             case EStarting:
       
  1451                 {
       
  1452                 MPMLOGSTRING2( "IAP %i: Connection state = Starting", 
       
  1453                     iActiveBMConns[i].iConnInfo.iIapId )
       
  1454                 break;
       
  1455                 }
       
  1456             case EStarted:
       
  1457                 {
       
  1458                 MPMLOGSTRING2( "IAP %i: Connection state = Started", 
       
  1459                     iActiveBMConns[i].iConnInfo.iIapId )
       
  1460                 break;
       
  1461                 }
       
  1462             case EIdle:
       
  1463                 {
       
  1464                 MPMLOGSTRING2( "IAP %i: Connection state = Idle", 
       
  1465                     iActiveBMConns[i].iConnInfo.iIapId )
       
  1466                 break;
       
  1467                 }
       
  1468             case ERoaming:
       
  1469                 {
       
  1470                 MPMLOGSTRING2( "IAP %i: Connection state = Roaming", 
       
  1471                     iActiveBMConns[i].iConnInfo.iIapId )
       
  1472                 break;
       
  1473                 }
       
  1474             default:
       
  1475                 {
       
  1476                 MPMLOGSTRING2( "IAP %i: Unknown connection state", 
       
  1477                     iActiveBMConns[i].iConnInfo.iIapId )
       
  1478                 break;
       
  1479                 }
       
  1480             }
       
  1481 
       
  1482         MPMLOGSTRING( "" )
       
  1483         }
       
  1484 
       
  1485     MPMLOGSTRING( "Display array of active connections - End" )
       
  1486 #endif // _DEBUG
       
  1487     }
       
  1488 
       
  1489 
       
  1490 // -----------------------------------------------------------------------------
       
  1491 // CMPMServer::DefaultConnection
       
  1492 // -----------------------------------------------------------------------------
       
  1493 //
       
  1494 CMPMDefaultConnection* CMPMServer::DefaultConnection()
       
  1495     {
       
  1496     MPMLOGSTRING( "CMPMServer::DefaultConnection:\
       
  1497  Default Connection" )
       
  1498     return iDefaultConnection;
       
  1499     }
       
  1500 
       
  1501 // -----------------------------------------------------------------------------
       
  1502 // CMPMServer::StartedConnectionExists
       
  1503 // -----------------------------------------------------------------------------
       
  1504 //
       
  1505 TInt CMPMServer::StartedConnectionExists( TInt aIapId )
       
  1506     {
       
  1507     MPMLOGSTRING( "CMPMServer::StartedConnectionExists" )
       
  1508 
       
  1509     // Loop all connections until EStarted is found or no more connections
       
  1510     // 
       
  1511     for ( TInt i = 0; ( i < iActiveBMConns.Count() ); i++ )
       
  1512         {
       
  1513         if ( iActiveBMConns[i].iConnInfo.iState == EStarted &&
       
  1514                 ( aIapId == KErrNotFound || aIapId == iActiveBMConns[i].iConnInfo.iIapId ) )
       
  1515             {
       
  1516             MPMLOGSTRING( "CMPMServer::StartedConnectionExists: True" )
       
  1517             return iActiveBMConns[i].iConnInfo.iIapId;
       
  1518             }
       
  1519         }
       
  1520     // Modem connection may exist, check from connection counter
       
  1521     // 
       
  1522     if ( ConnectionCounter() > 0 )
       
  1523         {
       
  1524         MPMLOGSTRING( "CMPMServer::StartedConnectionExists: True (modem connection)" )
       
  1525         return KMaxTInt; // arbitrary high number that is NOT from Iap range[0:255] 
       
  1526         }
       
  1527     else
       
  1528         {
       
  1529         MPMLOGSTRING( "CMPMServer::StartedConnectionExists: False" )
       
  1530         return KErrNotFound;
       
  1531         }
       
  1532     }
       
  1533 
       
  1534 // -----------------------------------------------------------------------------
       
  1535 // CMPMServer::AppendWlanQueryQueueL
       
  1536 // -----------------------------------------------------------------------------
       
  1537 //
       
  1538 void CMPMServer::AppendWlanQueryQueueL( CMPMWlanQueryDialog* aDlg )
       
  1539     {
       
  1540     if( aDlg )
       
  1541         {
       
  1542         iWlanQueryQueue->AppendL( aDlg );
       
  1543         }
       
  1544     else
       
  1545         {
       
  1546         MPMLOGSTRING( "CMPMServer::AppendWlanQueryQueueL argument NULL, Error" )
       
  1547         }
       
  1548     }
       
  1549 
       
  1550 // -----------------------------------------------------------------------------
       
  1551 // CMPMServer::StopConnections
       
  1552 // -----------------------------------------------------------------------------
       
  1553 //
       
  1554 void CMPMServer::StopConnections( TInt aIapId )
       
  1555     {
       
  1556     for (TInt index = 0; index < iSessions.Count(); index++)
       
  1557         {
       
  1558 /*        if (iSessions[index]->UserConnection())
       
  1559             continue;
       
  1560   */          
       
  1561         // Stop connection
       
  1562         if ( aIapId == 0 )
       
  1563             {
       
  1564             iSessions[index]->StopConnection();
       
  1565             }
       
  1566         else
       
  1567             {
       
  1568             TRAP_IGNORE( iSessions[index]->StopIAPNotificationL( aIapId ));
       
  1569             }
       
  1570         
       
  1571         }
       
  1572     }
       
  1573 
       
  1574 // -----------------------------------------------------------------------------
       
  1575 // CMPMServer::UpdateActiveConnectionL
       
  1576 // -----------------------------------------------------------------------------
       
  1577 //
       
  1578 void CMPMServer::UpdateActiveConnectionL( CMPMServerSession& aSession )
       
  1579     {
       
  1580     MPMLOGSTRING( "CMPMServer::UpdateActiveConnectionL" )
       
  1581     TUint32 snapId;
       
  1582 
       
  1583     if ( !NumberOfActiveConnections() )
       
  1584         {
       
  1585         // If no active connections then just reset keys and publish
       
  1586         iActiveBearerType = EMPMBearerTypeNone;
       
  1587         iActiveIapId = 0;
       
  1588         iActiveSnapId = 0;
       
  1589         PublishActiveConnection();
       
  1590         return;
       
  1591         }
       
  1592 
       
  1593     // Check if all active connections are in same snap
       
  1594     if ( CommsDatAccess()->AreActiveIapsInSameSnapL(
       
  1595          iActiveBMConns, snapId ) )
       
  1596         {
       
  1597         // Select active connection according to priority
       
  1598         CommsDatAccess()->SelectActiveConnectionL (
       
  1599             snapId,
       
  1600             iActiveBMConns,
       
  1601             iActiveIapId,
       
  1602             iActiveSnapId,
       
  1603             iActiveBearerType,
       
  1604             aSession );
       
  1605 
       
  1606         PublishActiveConnection();
       
  1607         return;
       
  1608         }
       
  1609 
       
  1610     // Reset active connections
       
  1611     iActiveBearerType = EMPMBearerTypeNone;
       
  1612     iActiveIapId = 0;
       
  1613     iActiveSnapId = 0;
       
  1614             
       
  1615     // Active connections locating in different snaps
       
  1616     // Use priority order vpn, wlan and packet
       
  1617     for ( TInt index = 0; index < iActiveBMConns.Count(); index++ )
       
  1618         {
       
  1619         // Do check only for active connections
       
  1620         if ( iActiveBMConns[index].iConnInfo.iState == EStarted )
       
  1621             {
       
  1622             TMPMBearerType bearerType = EMPMBearerTypeOther;
       
  1623         
       
  1624             if ( iDedicatedClients.Find( iActiveBMConns[index].iConnInfo.iAppUid ) == 
       
  1625                  KErrNone )
       
  1626                 {
       
  1627                 // Skip dedicated client
       
  1628                 continue;
       
  1629                 }
       
  1630 
       
  1631             bearerType = CommsDatAccess()->GetBearerTypeL( 
       
  1632                          iActiveBMConns[index].iConnInfo.iIapId );
       
  1633         
       
  1634             if ( bearerType == EMPMBearerTypeOther )
       
  1635                 {
       
  1636                 // Don't publish this connection
       
  1637                 continue;
       
  1638                 }
       
  1639                     
       
  1640             // This is true if,
       
  1641             // bearer type is smaller or different than none
       
  1642             // or
       
  1643             // bearer type is same and iap is different.
       
  1644             if ( ( bearerType < iActiveBearerType ) || 
       
  1645                  ( iActiveBearerType == EMPMBearerTypeNone ) ||
       
  1646                  ( ( bearerType == iActiveBearerType) &&
       
  1647                    ( iActiveIapId != iActiveBMConns[index].iConnInfo.iIapId ) ) )
       
  1648                 {
       
  1649                 iActiveBearerType = bearerType;
       
  1650                 iActiveIapId = iActiveBMConns[index].iConnInfo.iIapId;
       
  1651                 iActiveSnapId = iActiveBMConns[index].iConnInfo.iSnap;
       
  1652                 }
       
  1653             }
       
  1654 
       
  1655         PublishActiveConnection();  
       
  1656         }
       
  1657     }
       
  1658 
       
  1659 // -----------------------------------------------------------------------------
       
  1660 // CMPMServer::MapBearerType
       
  1661 // -----------------------------------------------------------------------------
       
  1662 //
       
  1663 TUint32 CMPMServer::MapBearerType(TMPMBearerType aBearerType)
       
  1664     {
       
  1665     MPMLOGSTRING( "CMPMServer::MapBearerType" )
       
  1666     
       
  1667     switch ( aBearerType )
       
  1668         {
       
  1669         case EMPMBearerTypeNone:
       
  1670             return 0;
       
  1671 
       
  1672         case EMPMBearerTypeVpn:
       
  1673             return KCommDbBearerVirtual;
       
  1674             
       
  1675         case EMPMBearerTypeWlan:
       
  1676             return KCommDbBearerWLAN;
       
  1677             
       
  1678         case EMPMBearerTypePacketData:
       
  1679             return KCommDbBearerWcdma;
       
  1680 
       
  1681         case EMPMBearerTypeOther:
       
  1682             return KCommDbBearerUnknown;
       
  1683             
       
  1684         default:
       
  1685             MPMLOGSTRING( "CMPMServer::MapBearerType: Unknown bearer type" )
       
  1686             break;
       
  1687         }
       
  1688     
       
  1689     return KCommDbBearerUnknown;
       
  1690     }
       
  1691 
       
  1692 // -----------------------------------------------------------------------------
       
  1693 // CMPMServer::PublishActiveConnection
       
  1694 // -----------------------------------------------------------------------------
       
  1695 //
       
  1696 void CMPMServer::PublishActiveConnection()
       
  1697     {
       
  1698     MPMLOGSTRING( "CMPMServer::PublishActiveConnection" )
       
  1699     
       
  1700     // update active connection keys
       
  1701     RProperty::Set( KMPMActiveConnectionCategory,
       
  1702                     KMPMPSKeyActiveConnectionIap,
       
  1703                     iActiveIapId );
       
  1704 
       
  1705     RProperty::Set( KMPMActiveConnectionCategory,
       
  1706                     KMPMPSKeyActiveConnectionSnap,
       
  1707                     iActiveSnapId );
       
  1708 
       
  1709     RProperty::Set( KMPMActiveConnectionCategory,
       
  1710                     KMPMPSKeyActiveConnectionBearer,
       
  1711                     MapBearerType( iActiveBearerType ) );    
       
  1712 
       
  1713     MPMLOGSTRING4( "CMPMServer::PublishActiveConnection: Set to: %d, %d, %d",
       
  1714                    iActiveIapId, iActiveSnapId, iActiveBearerType )
       
  1715     }
       
  1716 
       
  1717 // -----------------------------------------------------------------------------
       
  1718 // CMPMServer::NumberOfActiveConnections
       
  1719 // -----------------------------------------------------------------------------
       
  1720 //
       
  1721 TInt CMPMServer::NumberOfActiveConnections()
       
  1722     {
       
  1723     MPMLOGSTRING( "CMPMServer::NumberOfActiveConnections" )
       
  1724     
       
  1725     TInt count( 0 );
       
  1726     
       
  1727     for ( TInt index = 0; index < iActiveBMConns.Count(); index++ )
       
  1728         {
       
  1729         if ( iActiveBMConns[index].iConnInfo.iState == EStarted )
       
  1730             {
       
  1731             count++;
       
  1732             }
       
  1733         }
       
  1734     
       
  1735     return count;
       
  1736     }
       
  1737 
       
  1738 // -----------------------------------------------------------------------------
       
  1739 // CMPMServer::UserConnectionInInternet
       
  1740 // -----------------------------------------------------------------------------
       
  1741 //
       
  1742 TBool CMPMServer::UserConnectionInInternet() const
       
  1743     {
       
  1744     TBool isInternet = EFalse;
       
  1745     TInt ret = KErrNone;
       
  1746         
       
  1747     TRAP( ret, isInternet = iCommsDatAccess->IsInternetSnapL(
       
  1748           UserConnPref()->IapId(), UserConnPref()->SnapId() ) );
       
  1749 
       
  1750     if ( ret != KErrNone )
       
  1751         {
       
  1752         isInternet = EFalse;
       
  1753         }
       
  1754     
       
  1755     return isInternet;
       
  1756     }
       
  1757 
       
  1758 // -----------------------------------------------------------------------------
       
  1759 // CMPMServer::StartForcedRoamingToWlanL
       
  1760 // -----------------------------------------------------------------------------
       
  1761 //
       
  1762 void CMPMServer::StartForcedRoamingToWlanL( const TConnMonIapInfo& aIapInfo )
       
  1763     {
       
  1764     MPMLOGSTRING( "CMPMServer::StartForcedRoamingToWlan" )
       
  1765 
       
  1766     // First check that there is no active wlan connection
       
  1767     if ( IsWlanConnectionStartedL( CommsDatAccess() ) )
       
  1768         {
       
  1769         // Wlan already active can't roam to it
       
  1770         return;
       
  1771         }
       
  1772 
       
  1773     // Copy all available wlan iap ids to own array
       
  1774     RArray<TUint32> wlanIapIds;
       
  1775     CleanupClosePushL( wlanIapIds );
       
  1776     RAvailableIAPList iapList;
       
  1777     CleanupClosePushL( iapList );
       
  1778 
       
  1779     for ( TInt index = 0; index < aIapInfo.iCount; index++ )
       
  1780         {
       
  1781         if ( CommsDatAccess()->CheckWlanL( aIapInfo.iIap[index].iIapId ) != ENotWlanIap )
       
  1782             {
       
  1783             // Accept only wlan iaps in internet snap
       
  1784             if ( iCommsDatAccess->IsInternetSnapL( aIapInfo.iIap[index].iIapId, 0 ) )
       
  1785                 {
       
  1786                 wlanIapIds.AppendL( aIapInfo.iIap[index].iIapId );
       
  1787                 }
       
  1788             }
       
  1789         // Fill iap list to be used later to check best iap
       
  1790         iapList.AppendL( aIapInfo.iIap[index].iIapId );
       
  1791         }
       
  1792 
       
  1793     // No wlans available -> no reason to continue
       
  1794     if ( !wlanIapIds.Count() )
       
  1795         {
       
  1796         CleanupStack::PopAndDestroy( &iapList );
       
  1797         CleanupStack::PopAndDestroy( &wlanIapIds );
       
  1798         return;
       
  1799         }
       
  1800 
       
  1801     // Go through all active connections and start roaming for the ones connected
       
  1802     // to snap containing wlan and not using mobility api
       
  1803     for ( TInt index = 0; index < iActiveBMConns.Count(); index++ )
       
  1804         {
       
  1805         // Check if snap is internet snap
       
  1806         TBool internetSnap =
       
  1807             iCommsDatAccess->IsInternetSnapL(
       
  1808                 iActiveBMConns[index].iConnInfo.iIapId,
       
  1809                 iActiveBMConns[index].iConnInfo.iSnap );
       
  1810 
       
  1811         CMPMServerSession* serverSession = GetServerSession(
       
  1812                 iActiveBMConns[index].iConnInfo.iConnId );
       
  1813 
       
  1814         // Check that connection is started, established to snap and
       
  1815         // choose best iap is called for the connection
       
  1816         if ( ( iActiveBMConns[index].iConnInfo.iState == EStarted ) &&
       
  1817              ( iActiveBMConns[index].iConnInfo.iSnap ) && 
       
  1818              ( serverSession->ChooseBestIapCalled() ) &&
       
  1819              ( internetSnap ) )
       
  1820             {
       
  1821             // Notify client to disconnect
       
  1822             NotifyDisconnectL( index, wlanIapIds, iapList, ETrue,
       
  1823                 EMPMBearerTypeWlan );
       
  1824             }
       
  1825         }
       
  1826     CleanupStack::PopAndDestroy( &iapList );
       
  1827     CleanupStack::PopAndDestroy( &wlanIapIds );
       
  1828     }
       
  1829 
       
  1830 // -----------------------------------------------------------------------------
       
  1831 // CMPMServer::StartForcedRoamingFromWlanL
       
  1832 // -----------------------------------------------------------------------------
       
  1833 //
       
  1834 void CMPMServer::StartForcedRoamingFromWlanL( const TConnMonIapInfo& aIapInfo )
       
  1835     {
       
  1836     MPMLOGSTRING( "CMPMServer::StartForcedRoamingFromWlan" )
       
  1837 
       
  1838     // Copy all available packet data iap ids to own array
       
  1839     RArray<TUint32> packetDataIapIds;
       
  1840     CleanupClosePushL( packetDataIapIds );
       
  1841 
       
  1842     for ( TInt index = 0; index < aIapInfo.iCount; index++ )
       
  1843         {
       
  1844         if ( CommsDatAccess()->GetBearerTypeL( aIapInfo.iIap[index].iIapId ) ==
       
  1845             EMPMBearerTypePacketData )
       
  1846             {
       
  1847             // Accept only packet data iaps in internet snap
       
  1848             if ( iCommsDatAccess->IsInternetSnapL( aIapInfo.iIap[index].iIapId, 0 ) )
       
  1849                 {
       
  1850                 packetDataIapIds.AppendL( aIapInfo.iIap[index].iIapId );
       
  1851                 }
       
  1852             }
       
  1853         }
       
  1854 
       
  1855     // No packet data iaps available -> no reason to continue
       
  1856     if ( !packetDataIapIds.Count() )
       
  1857         {
       
  1858         CleanupStack::PopAndDestroy( &packetDataIapIds );
       
  1859         return;
       
  1860         }
       
  1861     
       
  1862     // Go through all active connections and start roaming for the ones connected
       
  1863     // to a wlan not anymore listed in available iaps and not using mobility api
       
  1864     for ( TInt index = 0; index < iActiveBMConns.Count(); index++ )
       
  1865         {
       
  1866         if ( iCommsDatAccess->CheckWlanL( iActiveBMConns[index].iConnInfo.iIapId )
       
  1867             == EWlanIap )
       
  1868             {
       
  1869             // Check if used WLAN is still available
       
  1870             TBool currentWlanIapAvailable = EFalse;
       
  1871             for ( TInt iapIndex = 0; iapIndex < aIapInfo.iCount; iapIndex++ )
       
  1872                 {
       
  1873                 if ( aIapInfo.iIap[iapIndex].iIapId ==
       
  1874                     iActiveBMConns[index].iConnInfo.iIapId )
       
  1875                     {
       
  1876                     // Current WLAN IAP found from list of available IAPs
       
  1877                     currentWlanIapAvailable = ETrue;
       
  1878                     break;
       
  1879                     }
       
  1880                 }
       
  1881             
       
  1882             if ( !currentWlanIapAvailable )
       
  1883                 {
       
  1884                 // Current WLAN not available anymore
       
  1885                 // Check if snap is internet snap
       
  1886                 TBool internetSnap = iCommsDatAccess->IsInternetSnapL(
       
  1887                     iActiveBMConns[index].iConnInfo.iIapId,
       
  1888                     iActiveBMConns[index].iConnInfo.iSnap );
       
  1889     
       
  1890                 CMPMServerSession* serverSession = GetServerSession(
       
  1891                     iActiveBMConns[index].iConnInfo.iConnId );
       
  1892                 
       
  1893                 // Check that connection is started, established to snap,
       
  1894                 // choose best iap is called for the connection
       
  1895                 if ( ( iActiveBMConns[index].iConnInfo.iState == EStarted ) &&
       
  1896                     ( iActiveBMConns[index].iConnInfo.iSnap ) && 
       
  1897                     ( serverSession->ChooseBestIapCalled() ) &&
       
  1898                     ( internetSnap ) )
       
  1899                     {
       
  1900                     // Notify client to disconnect, don't check if current
       
  1901                     // WLAN IAP is the best because we want to disconnect
       
  1902                     // it anyway (it was not included in available IAP
       
  1903                     // list anymore)
       
  1904                     RAvailableIAPList iapList;
       
  1905                     CleanupClosePushL( iapList );
       
  1906                     NotifyDisconnectL( index, packetDataIapIds, iapList, EFalse,
       
  1907                         EMPMBearerTypePacketData );
       
  1908                     CleanupStack::PopAndDestroy( &iapList );
       
  1909                     }
       
  1910                 }
       
  1911             }
       
  1912         }
       
  1913     CleanupStack::PopAndDestroy( &packetDataIapIds );
       
  1914     }
       
  1915 
       
  1916 // -----------------------------------------------------------------------------
       
  1917 // CMPMServer::NotifyDisconnectL
       
  1918 // -----------------------------------------------------------------------------
       
  1919 //
       
  1920 void CMPMServer::NotifyDisconnectL( TInt aConnIndex,
       
  1921                                     RArray<TUint32>& aAvailIapIds,
       
  1922                                     RAvailableIAPList& aIapList,
       
  1923                                     TBool aCheckForBestIap,
       
  1924                                     TMPMBearerType aDestinationBearerType )
       
  1925     {
       
  1926     MPMLOGSTRING( "CMPMServer::NotifyDisconnectL" )
       
  1927     
       
  1928     // Get iaps in internet snap
       
  1929     RArray<TNetIap> destNetIds;
       
  1930     CleanupClosePushL( destNetIds );
       
  1931     CommsDatAccess()->SearchDNEntriesL( iActiveBMConns[aConnIndex].iConnInfo.iSnap,
       
  1932                                         destNetIds );
       
  1933 
       
  1934     // Save available iaps in internet snap
       
  1935     RArray<TUint32> iapIdsInInternet;
       
  1936     CleanupClosePushL( iapIdsInInternet );
       
  1937                         
       
  1938     for ( TInt iIndex = 0; iIndex < destNetIds.Count(); iIndex++ )
       
  1939         {
       
  1940         for ( TInt wIndex = 0; wIndex < aAvailIapIds.Count(); wIndex++ )
       
  1941             {
       
  1942             if ( destNetIds[iIndex].iIapId == aAvailIapIds[wIndex] )
       
  1943                 {
       
  1944                 iapIdsInInternet.AppendL( destNetIds[iIndex].iIapId );
       
  1945                 break;
       
  1946                 }
       
  1947             }
       
  1948                     
       
  1949         if ( iapIdsInInternet.Count() )
       
  1950             {
       
  1951             // Leave loop when count is non-zero
       
  1952             break;
       
  1953             }
       
  1954         }
       
  1955 
       
  1956     // Check if an iap in internet snap is available
       
  1957     if ( iapIdsInInternet.Count() )
       
  1958         {
       
  1959         // Find session and notify error
       
  1960         for (TInt sIndex = 0; sIndex < iSessions.Count(); sIndex++ )
       
  1961             {
       
  1962             // Check that CMPMIapSelection object exists for the session.
       
  1963             TRAPD( error, iSessions[sIndex]->IapSelectionL() );
       
  1964             if ( error == KErrNone )
       
  1965                 {
       
  1966                 MPMLOGSTRING( "CMPMServer::NotifyDisconnectL: IapSelectionL() != NULL" )
       
  1967                 // Check the connection preferences for forced roaming
       
  1968                 if ( iSessions[sIndex]->ForcedRoaming() )
       
  1969                     {
       
  1970                     MPMLOGSTRING( "CMPMServer::NotifyDisconnectL: ForcedRoaming == ETrue" )
       
  1971                     // Notify disconnect error for session,
       
  1972                     // if mobility api is not used
       
  1973                     if ( ( iSessions[sIndex]->ConnectionId() ==
       
  1974                         iActiveBMConns[aConnIndex].iConnInfo.iConnId ) &&
       
  1975                         !iSessions[sIndex]->PreferredIapRequested() &&
       
  1976                         iSessions[sIndex]->IsBearerAccepted( aDestinationBearerType ) )
       
  1977                         {
       
  1978                         if ( aCheckForBestIap )
       
  1979                             {
       
  1980                             // Check whether current IAP and the best IAP are the same.
       
  1981                             // Disconnection not done if IAPs are the same   
       
  1982                             TMpmConnPref connPref;
       
  1983                             connPref.SetIapId( 0 );
       
  1984                             connPref.SetSnapId(
       
  1985                                 iActiveBMConns[aConnIndex].iConnInfo.iSnap );
       
  1986 
       
  1987                             iSessions[sIndex]->IapSelectionL()->ChooseBestIAPL( connPref, aIapList );
       
  1988 
       
  1989                             // if the best iap is the current iap, don't roam, move to next item
       
  1990                             if ( ( aIapList.Count() > 0 ) && 
       
  1991                                 ( connPref.IapId() == iActiveBMConns[aConnIndex].iConnInfo.iIapId ) )
       
  1992                                 {
       
  1993                                 MPMLOGSTRING( "CMPMServer::NotifyDisconnectL: Same IAP selected. Disconnection not done." )
       
  1994                                 break;
       
  1995                                 }
       
  1996                             }
       
  1997     
       
  1998                         MPMLOGSTRING2( "CMPMServer::NotifyDisconnectL: \
       
  1999 Disconnected Connection Id = 0x%x", iSessions[sIndex]->ConnectionId() )
       
  2000                         iSessions[sIndex]->ClientErrorNotificationL( KErrDisconnected );
       
  2001                         }
       
  2002                     }
       
  2003                 }
       
  2004             }
       
  2005         }
       
  2006             
       
  2007     CleanupStack::PopAndDestroy( &iapIdsInInternet );
       
  2008     CleanupStack::PopAndDestroy( &destNetIds );
       
  2009     }
       
  2010 
       
  2011 // -----------------------------------------------------------------------------
       
  2012 // CMPMServer::IsVisitorNetwork
       
  2013 // 
       
  2014 // Checks if phone is in visitor network or in home network.
       
  2015 // Return ETrue if phone is in visitor network.
       
  2016 // Return EFalse if phone is not in visitor network.
       
  2017 // -----------------------------------------------------------------------------
       
  2018 //
       
  2019 TBool CMPMServer::IsVisitorNetwork() const
       
  2020     {
       
  2021     MPMLOGSTRING( "CMPMServer::IsVisitorNetwork" )
       
  2022     
       
  2023     if ( iRoamingWatcher->RoamingStatus()== EMPMInternationalRoaming )
       
  2024         {
       
  2025         MPMLOGSTRING( "CMPMServer::IsVisitorNetwork: TRUE" )
       
  2026         return ETrue;
       
  2027         } 
       
  2028     else
       
  2029         {
       
  2030         MPMLOGSTRING( "CMPMServer::IsVisitorNetwork: FALSE" )
       
  2031         return EFalse;
       
  2032         }
       
  2033     }
       
  2034 
       
  2035 // -----------------------------------------------------------------------------
       
  2036 // CMPMServer::GetServerSession
       
  2037 // -----------------------------------------------------------------------------
       
  2038 //
       
  2039 CMPMServerSession* CMPMServer::GetServerSession( TConnectionId aConnId ) const
       
  2040     {
       
  2041     MPMLOGSTRING2( "CMPMServer::GetServerSession: \
       
  2042 Connection Id = 0x%x", aConnId );
       
  2043 
       
  2044     CMPMServerSession* serverSession = NULL;
       
  2045     for ( TInt sIndex = 0; sIndex < iSessions.Count(); sIndex++ )
       
  2046         {
       
  2047         if ( iSessions[sIndex]->ConnectionId() == aConnId )
       
  2048             {
       
  2049             serverSession = iSessions[sIndex];
       
  2050             }
       
  2051         }
       
  2052 
       
  2053     ASSERT( serverSession != NULL );
       
  2054 
       
  2055     return serverSession;
       
  2056     }
       
  2057 
       
  2058 // -----------------------------------------------------------------------------
       
  2059 // TMPMBlackListConnId::Append
       
  2060 // -----------------------------------------------------------------------------
       
  2061 //
       
  2062 void TMPMBlackListConnId::Append( TUint32 aIap, TBlacklistCategory aCategory )
       
  2063     {
       
  2064     iBlackListIap.Append( aIap );
       
  2065     iCategory.Append( aCategory );
       
  2066     }
       
  2067 
       
  2068 // -----------------------------------------------------------------------------
       
  2069 // TMPMBlackListConnId::Remove
       
  2070 // -----------------------------------------------------------------------------
       
  2071 //
       
  2072 void TMPMBlackListConnId::Remove( TInt aIndex )
       
  2073     {
       
  2074     iBlackListIap.Remove( aIndex );
       
  2075     iCategory.Remove( aIndex );    
       
  2076     }
       
  2077 
       
  2078 // -----------------------------------------------------------------------------
       
  2079 // TMPMBlackListConnId::Close
       
  2080 // -----------------------------------------------------------------------------
       
  2081 //
       
  2082 void TMPMBlackListConnId::Close()
       
  2083     {
       
  2084     iBlackListIap.Close();
       
  2085     iCategory.Close();    
       
  2086     }
       
  2087 
       
  2088 // -----------------------------------------------------------------------------
       
  2089 // TMPMBlackListConnId::Count
       
  2090 // -----------------------------------------------------------------------------
       
  2091 //
       
  2092 TInt TMPMBlackListConnId::Count() const
       
  2093     {
       
  2094     return iBlackListIap.Count();
       
  2095     }
       
  2096 
       
  2097 // -----------------------------------------------------------------------------
       
  2098 // TConnectionInfo::TConnectionInfo
       
  2099 // -----------------------------------------------------------------------------
       
  2100 //
       
  2101 TConnectionInfo::TConnectionInfo() 
       
  2102     : iConnId( 0 ),
       
  2103       iSnap( 0 ),
       
  2104       iIapId( 0 ), 
       
  2105       iState( EIdle ),
       
  2106       iAppUid( 0 )
       
  2107     {
       
  2108     }
       
  2109 
       
  2110 // -----------------------------------------------------------------------------
       
  2111 // TConnectionInfo::MatchId
       
  2112 // -----------------------------------------------------------------------------
       
  2113 //
       
  2114 TBool TConnectionInfo::MatchId( const TConnectionInfo& aFirst,
       
  2115                                        const TConnectionInfo& aSecond )
       
  2116     {
       
  2117     if ( aFirst.iConnId == aSecond.iConnId )
       
  2118         {
       
  2119         return ETrue;
       
  2120         }
       
  2121     else
       
  2122         {
       
  2123         return EFalse;
       
  2124         }
       
  2125     }
       
  2126 
       
  2127 // -----------------------------------------------------------------------------
       
  2128 // TConnectionInfo::MatchIdSnap
       
  2129 // -----------------------------------------------------------------------------
       
  2130 //
       
  2131 TBool TConnectionInfo::MatchIdSnap( const TConnectionInfo& aFirst,
       
  2132                                     const TConnectionInfo& aSecond )
       
  2133     {
       
  2134     if ( ( aFirst.iConnId  == aSecond.iConnId ) &&
       
  2135          ( aFirst.iSnap    == aSecond.iSnap ) )
       
  2136         {
       
  2137         return ETrue;
       
  2138         }
       
  2139     else
       
  2140         {
       
  2141         return EFalse;
       
  2142         }
       
  2143     }
       
  2144 
       
  2145 // -----------------------------------------------------------------------------
       
  2146 // TActiveBMConn::TActiveBMConn
       
  2147 // -----------------------------------------------------------------------------
       
  2148 //
       
  2149 TActiveBMConn::TActiveBMConn() 
       
  2150     : iConnInfo()
       
  2151     {
       
  2152     }
       
  2153 
       
  2154 
       
  2155 // -----------------------------------------------------------------------------
       
  2156 // TActiveBMConn::MatchIapId
       
  2157 // -----------------------------------------------------------------------------
       
  2158 //
       
  2159 TBool TActiveBMConn::MatchIapId( const TActiveBMConn& aFirst,
       
  2160                                  const TActiveBMConn& aSecond )
       
  2161     {
       
  2162     if ( aFirst.iConnInfo.iIapId == aSecond.iConnInfo.iIapId )
       
  2163         {
       
  2164         return ETrue;
       
  2165         }
       
  2166     else
       
  2167         {
       
  2168         return EFalse;
       
  2169         }
       
  2170     }
       
  2171 
       
  2172 
       
  2173 // -----------------------------------------------------------------------------
       
  2174 // TActiveBMConn::MatchConnInfo
       
  2175 // -----------------------------------------------------------------------------
       
  2176 //
       
  2177 TBool TActiveBMConn::MatchConnInfo( const TActiveBMConn& aFirst,
       
  2178                                     const TActiveBMConn& aSecond )
       
  2179     { 
       
  2180     if ( TConnectionInfo::MatchId( aFirst.iConnInfo, aSecond.iConnInfo ) )
       
  2181         {
       
  2182         return ETrue;
       
  2183         }
       
  2184     else
       
  2185         {
       
  2186         return EFalse;
       
  2187         }
       
  2188     }
       
  2189 
       
  2190 
       
  2191 //  End of File