vpnengine/sit/src/vpnconncloser.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2003-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: Task handler for closing VPN connection.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "vpnconncloser.h"
       
    21 #include "kmdapi.h"
       
    22 #include "log.h"
       
    23 
       
    24 CVpnConnCloser* CVpnConnCloser::NewL(MTaskHandlerManager* aManager,
       
    25                                      const TTaskArrivedEventData& aTaskInfo)
       
    26     {
       
    27     CVpnConnCloser* self = new (ELeave) CVpnConnCloser(aManager, aTaskInfo);
       
    28     CleanupStack::PushL(self);
       
    29     self->ConstructL();
       
    30     CleanupStack::Pop(); // self
       
    31     return self;
       
    32     }
       
    33 
       
    34 CVpnConnCloser::CVpnConnCloser(MTaskHandlerManager* aManager,
       
    35                                const TTaskArrivedEventData& aTaskInfo)
       
    36     : CTaskHandler(aManager, aTaskInfo, ECloseVpnConnCancelEvent, &iEventSpecDes) 
       
    37     {
       
    38     }
       
    39 
       
    40 void CVpnConnCloser::ConstructL()
       
    41     {
       
    42     CActiveScheduler::Add(this);
       
    43     User::LeaveIfError(iEventMediator.Connect());
       
    44     User::LeaveIfError(iKmdServ.Connect());
       
    45     User::LeaveIfError(iPolicyServ.Connect());
       
    46     }
       
    47     
       
    48 CVpnConnCloser::~CVpnConnCloser()
       
    49     {
       
    50     Cancel();
       
    51     iEventMediator.Close();
       
    52     iKmdServ.Close();
       
    53     iPolicyServ.Close();
       
    54     RELEASE_EVENT_LOGGER;
       
    55     }
       
    56     
       
    57 void CVpnConnCloser::StartTaskHandling()
       
    58     {
       
    59 	DEB(LOG(Log::Printf(_L("Starting VPN IAP deactivation\n")));)			
       
    60     INIT_EVENT_LOGGER(iEventMediator, iEventSpecDes().iVpnIapId, iEventSpecDes().iRealIapId);
       
    61     GotoState(KStateDeactivateKmd);
       
    62     }
       
    63     
       
    64 void CVpnConnCloser::ChangeStateL()
       
    65     {
       
    66     switch (NextState())
       
    67         {
       
    68         case KStateDeactivateKmd:
       
    69             StateDeactivateKmdL();
       
    70             break;
       
    71 
       
    72         case KStateUnloadIpsecPolicy:
       
    73             StateUnloadIpsecPolicy();
       
    74             break;
       
    75 
       
    76         case KStateAfterUnloadIpsecPolicy:
       
    77             StateAfterUnloadIpsecPolicy();
       
    78             break;
       
    79 
       
    80         default:
       
    81             User::Panic(KSitName, EPanicInvalidTaskHandlerState);
       
    82         }
       
    83     }
       
    84 
       
    85 void CVpnConnCloser::CancelOngoingOperation()
       
    86     {
       
    87     switch (CurrState())
       
    88         {
       
    89         case KStateDeactivateKmd:
       
    90         case KStateAfterUnloadIpsecPolicy:
       
    91             // There's no ongoing external request to cancel
       
    92             break;
       
    93 
       
    94         case KStateUnloadIpsecPolicy:
       
    95 			DEB(LOG(Log::Printf(_L("Canceling Ipsec policy unload\n")));)
       
    96             iPolicyServ.CancelUnload();
       
    97             break;
       
    98 
       
    99         default:
       
   100             User::Panic(KSitName, EPanicInvalidTaskHandlerState);
       
   101         }
       
   102     }
       
   103 
       
   104 void CVpnConnCloser::StateDeactivateKmdL()
       
   105     {
       
   106     SetCurrState(KStateDeactivateKmd);
       
   107     TInt err = iKmdServ.StopVpnConnection( iEventSpecDes().iVpnIapId,
       
   108                                         (TKmdStopConnection::TType)iEventSpecDes().iDeactivateType );
       
   109 	DEB(LOG(Log::Printf(_L("VPN connection stopped, VPN IAP id=%d, err=%d\n"),
       
   110 	        iEventSpecDes().iVpnIapId, err ));)	
       
   111     GotoState(KStateUnloadIpsecPolicy);
       
   112     }
       
   113 
       
   114 void CVpnConnCloser::StateUnloadIpsecPolicy()
       
   115     {
       
   116     SetCurrState(KStateUnloadIpsecPolicy);
       
   117 
       
   118     iPolicyServ.UnloadPolicy(iEventSpecDes().iIpsecPolicyHandle, iStatus);
       
   119 	DEB(LOG(Log::Printf(_L("Ipsec policy unloaded, handle = %d\n"), iEventSpecDes().iIpsecPolicyHandle));)	
       
   120     SetNextState(KStateAfterUnloadIpsecPolicy);
       
   121     SetActive();
       
   122     }
       
   123 
       
   124 void CVpnConnCloser::StateAfterUnloadIpsecPolicy()
       
   125     {
       
   126     SetCurrState(KStateAfterUnloadIpsecPolicy);
       
   127 	DEB(LOG(Log::Printf(_L("VPN IAP deactivation completed, Ipsec policy unload status = %d\n"), iStatus.Int()));)
       
   128 
       
   129     LOG_EVENT(R_VPN_MSG_VPN_IAP_DEACT, NULL, iStatus.Int(), iEventSpecDes().iDeactivateType);
       
   130     
       
   131     TaskComplete(iStatus.Int());
       
   132     }
       
   133 
       
   134 void CVpnConnCloser::ReportResult(TInt aStatus)
       
   135     {
       
   136     // Report the close operation status
       
   137     // information to the Event Mediator
       
   138 
       
   139     TCloseVpnConnEventData eventData;
       
   140     
       
   141     eventData.iTaskStatus = aStatus;
       
   142     
       
   143     TPckg<TCloseVpnConnEventData> eventDataDes(eventData);
       
   144     ReportEvent(ECloseVpnConnEvent, iEventSpecDes, eventDataDes);
       
   145     iKmdServ.Close();
       
   146     }