vpnengine/vpnconnagt/src/vpnconnagt.cpp
branchRCL_3
changeset 8 032d3a818f49
parent 2 ef893827b4d1
child 18 5db1ac3b4374
equal deleted inserted replaced
4:29b591713d44 8:032d3a818f49
     1 /*
     1 /*
     2 * Copyright (c) 2000-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2000-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    22 #include <cmpluginvpndef.h>
    22 #include <cmpluginvpndef.h>
    23 #include <commdbconnpref.h>
    23 #include <commdbconnpref.h>
    24 #include <in_iface.h>
    24 #include <in_iface.h>
    25 #include <tunnelnifvar.h>
    25 #include <tunnelnifvar.h>
    26 #include <d32dbmsconstants.h>
    26 #include <d32dbmsconstants.h>
       
    27 #include <featmgr.h>
    27 
    28 
    28 #include "vpnconnagt.h"
    29 #include "vpnconnagt.h"
       
    30 #include "vpnsipobserver.h"
    29 
    31 
    30 
    32 
    31 /***************CVPNConnAgtFactory********************/
    33 /***************CVPNConnAgtFactory********************/
    32 
    34 
    33 extern "C" EXPORT_C CNifAgentFactory* NewAgentFactoryL()
    35 extern "C" EXPORT_C CNifAgentFactory* NewAgentFactoryL()
    74     TCallBack disconnectionCompleteCallback(DisconnectCompleteCb, this);
    76     TCallBack disconnectionCompleteCallback(DisconnectCompleteCb, this);
    75     iDisconnectCallback.Set(disconnectionCompleteCallback);
    77     iDisconnectCallback.Set(disconnectionCompleteCallback);
    76 
    78 
    77     iEventActivatedClose = EFalse;
    79     iEventActivatedClose = EFalse;
    78     iDisconnectType = (TDeactivateType)NORMAL_DISCONNECT_MODE; // means the normal way to shutdown
    80     iDisconnectType = (TDeactivateType)NORMAL_DISCONNECT_MODE; // means the normal way to shutdown
       
    81     
       
    82     iFeatureManagerInitialized = EFalse;
    79     }
    83     }
    80 
    84 
    81 // ---------------------------------------------------------------------------
    85 // ---------------------------------------------------------------------------
    82 // Destructor 
    86 // Destructor 
    83 // ---------------------------------------------------------------------------
    87 // ---------------------------------------------------------------------------
    85 CVPNConnAgt::~CVPNConnAgt()
    89 CVPNConnAgt::~CVPNConnAgt()
    86     {
    90     {
    87     LOG(TName name;
    91     LOG(TName name;
    88     name.AppendFormat(_L("[0x%08x]"), this);
    92     name.AppendFormat(_L("[0x%08x]"), this);
    89     Log::Printf(_L("%s Destructing VPN Connection Agent\n"),name.PtrZ()));
    93     Log::Printf(_L("%s Destructing VPN Connection Agent\n"),name.PtrZ()));
       
    94 
       
    95     if ( FeatureManager::FeatureSupported( KFeatureIdFfImsDeregistrationInVpn ) )
       
    96         {
       
    97         delete iSipObserver;
       
    98         iSipObserver = NULL;
       
    99         }
       
   100         
       
   101     if ( iFeatureManagerInitialized )
       
   102         {
       
   103         // We can safely call UnInitializeLib as we have really intialized it.
       
   104         FeatureManager::UnInitializeLib();  // Decreases ref.count
       
   105         }
    90 
   106 
    91     iEventMediator.Close();
   107     iEventMediator.Close();
    92     
   108     
    93     iServiceStartedCallback.Cancel();
   109     iServiceStartedCallback.Cancel();
    94     iConnectCompleteCallback.Cancel();
   110     iConnectCompleteCallback.Cancel();
   119     CAgentBase::ConstructL();
   135     CAgentBase::ConstructL();
   120     iConnected = EFalse;
   136     iConnected = EFalse;
   121     iDisconnecting = EFalse;
   137     iDisconnecting = EFalse;
   122     LOG_("CVPNConnAgt::ReadConfigurationL EventMediator");
   138     LOG_("CVPNConnAgt::ReadConfigurationL EventMediator");
   123     User::LeaveIfError(iEventMediator.Connect());
   139     User::LeaveIfError(iEventMediator.Connect());
       
   140         
       
   141     // Initialize Feature Manager.
       
   142     FeatureManager::InitializeLibL();  // Successfull call increases reference count
       
   143     iFeatureManagerInitialized = ETrue;
       
   144    
       
   145     // Create CVpnSipObserver for communicating with SIP profile server via 
       
   146     // P&S keys for SIP de/re-registration. this pointer is passed to have call back.
       
   147     if ( FeatureManager::FeatureSupported( KFeatureIdFfImsDeregistrationInVpn ) )
       
   148         {
       
   149         iSipObserver = CVpnSipObserver::NewL( *this );
       
   150         }
   124     }
   151     }
   125 
   152 
   126 // ---------------------------------------------------------------------------
   153 // ---------------------------------------------------------------------------
   127 // Info() 
   154 // Info() 
   128 // ---------------------------------------------------------------------------
   155 // ---------------------------------------------------------------------------
   291         iNotify->ConnectComplete(iLastErrorCode);
   318         iNotify->ConnectComplete(iLastErrorCode);
   292         aError = iLastErrorCode;
   319         aError = iLastErrorCode;
   293         return;
   320         return;
   294         }
   321         }
   295  
   322  
       
   323     // SIP is deregistered before starting a VPN session. First tell SIP profile server to 
       
   324     // perform deregistration.  And when it's completed, continue VPN session start.
       
   325     // Note: A wait note is not used here for holding VPN session starting process because 
       
   326     // CInternetConnectionManager is showing one.
       
   327     // Tell SIP Profile Server to perform deregistration before proceeding VPN start.
       
   328     // Multiple VPN connection use cases are handled in SIP side.  VPN just notifies SIP
       
   329     // a VPN session is about to start.
       
   330     if ( FeatureManager::FeatureSupported( KFeatureIdFfImsDeregistrationInVpn ) )
       
   331         {
       
   332         // For some reason, if the request fails, just proceeds.
       
   333         if ( iSipObserver->RequestDeregister() != KErrNone )
       
   334             {
       
   335             ProceedServiceStart();
       
   336             }
       
   337         // Return for now. ProceedServiceStart() will be called later by iSipObserver when
       
   338         // deregistration process has been completed. Then VPN start process will be actually
       
   339         // initiated.
       
   340         return;
       
   341         }
       
   342     // If KFeatureIdFfImsDeregistrationInVpn is disabled, no SIP deregisration is performed.
       
   343     else
       
   344         {
       
   345         ProceedServiceStart();
       
   346         }
       
   347     }
       
   348  
       
   349 /****************************************************************************/
       
   350 /* ProceedServiceStart()                                                    */
       
   351 /* Proceed VPN session start process                                        */
       
   352 /****************************************************************************/
       
   353 void CVPNConnAgt::ProceedServiceStart()
       
   354     {
   296     LOG_1("[0x%08x] Get protocol version\n", this);
   355     LOG_1("[0x%08x] Get protocol version\n", this);
   297     iProtocolVersionDes().iId = iEventMediator.NewEventSpecId();
   356     iProtocolVersionDes().iId = iEventMediator.NewEventSpecId();
   298     iProtocolVersionDes().iPolicyId = *(iVPNParameters.GetVPNPolicy());
   357     iProtocolVersionDes().iPolicyId = *(iVPNParameters.GetVPNPolicy());
   299     iEventMediator.ListenToEvent(
   358     iEventMediator.ListenToEvent(
   300         EGetProtocolVersionEvent, iProtocolVersionDes, *this);
   359         EGetProtocolVersionEvent, iProtocolVersionDes, *this);
   406         Log::Printf(_L("%s Disconnecting type is %d\n"),name.PtrZ(), (TInt)iDisconnectType));
   465         Log::Printf(_L("%s Disconnecting type is %d\n"),name.PtrZ(), (TInt)iDisconnectType));
   407 
   466 
   408         return;
   467         return;
   409         }
   468         }
   410 
   469 
       
   470     if ( FeatureManager::FeatureSupported( KFeatureIdFfImsDeregistrationInVpn ) )
       
   471         {
       
   472         // SIP is re-registered when a VPN session ends.
       
   473         // Note: return value ignored. Nothing to do here for error cases.
       
   474         iSipObserver->RequestRegister();
       
   475         }
       
   476 
   411     iNotify->AgentProgress(EVPNConnAgtDisconnected, KErrNone);
   477     iNotify->AgentProgress(EVPNConnAgtDisconnected, KErrNone);
   412     iNotify->DisconnectComplete();
   478     iNotify->DisconnectComplete();
   413     iDisconnecting = EFalse;
   479     iDisconnecting = EFalse;
   414     }
   480     }
   415 
   481 
   497             iState = EConnected;
   563             iState = EConnected;
   498             ConnectionComplete(KErrNone);
   564             ConnectionComplete(KErrNone);
   499             break;
   565             break;
   500         case ECloseVpnConnEvent:
   566         case ECloseVpnConnEvent:
   501             LOG(Log::Printf(_L("%s ECloseVpnConnEvent\n"),name.PtrZ()));
   567             LOG(Log::Printf(_L("%s ECloseVpnConnEvent\n"),name.PtrZ()));
       
   568                 
       
   569             if ( FeatureManager::FeatureSupported( KFeatureIdFfImsDeregistrationInVpn ) )
       
   570                 {
       
   571                 // SIP is re-registered when a VPN session ends.
       
   572                 // Note: return value ignored. Nothing to do here for error cases.
       
   573                 iSipObserver->RequestRegister();
       
   574                 }    
       
   575             
   502             closeData = (TCloseVpnConnEventData*)(aData->Ptr());
   576             closeData = (TCloseVpnConnEventData*)(aData->Ptr());
   503             if ( closeData->iTaskStatus )
   577             if ( closeData->iTaskStatus )
   504                 {
   578                 {
   505                 LOG(Log::Printf(_L("%s ECloseVpnConnEvent: TaskStatus %d\n"),name.PtrZ(), closeData->iTaskStatus));
   579                 LOG(Log::Printf(_L("%s ECloseVpnConnEvent: TaskStatus %d\n"),name.PtrZ(), closeData->iTaskStatus));
   506                 iLastErrorCode = closeData->iTaskStatus;
   580                 iLastErrorCode = closeData->iTaskStatus;