vpnengine/ikeutils/src/ipsecpolicyutil.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 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:  Utility class for using IPSec policy server
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "ipsecsalist.h"
       
    20 
       
    21 // CLASS HEADER
       
    22 #include "ipsecpolicyutil.h"
       
    23 
       
    24 // ======== MEMBER FUNCTIONS ========
       
    25 
       
    26 // ---------------------------------------------------------------------------
       
    27 // Two-phased constructor.
       
    28 // ---------------------------------------------------------------------------
       
    29 //
       
    30 EXPORT_C CIpsecPolicyUtil* CIpsecPolicyUtil::NewL()
       
    31     {
       
    32     CIpsecPolicyUtil* self = new (ELeave) CIpsecPolicyUtil();
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop(self);
       
    36     return self;    
       
    37     }
       
    38 
       
    39 // ---------------------------------------------------------------------------
       
    40 // Destructor.
       
    41 // ---------------------------------------------------------------------------
       
    42 //
       
    43 CIpsecPolicyUtil::~CIpsecPolicyUtil()
       
    44     {
       
    45     iIpsecPolicyServ.Close();
       
    46     }
       
    47 
       
    48 // ---------------------------------------------------------------------------
       
    49 // Constructor.
       
    50 // ---------------------------------------------------------------------------
       
    51 //
       
    52 CIpsecPolicyUtil::CIpsecPolicyUtil()
       
    53     {
       
    54     }
       
    55 
       
    56 // ---------------------------------------------------------------------------
       
    57 // Second phase construction.
       
    58 // ---------------------------------------------------------------------------
       
    59 //
       
    60 void CIpsecPolicyUtil::ConstructL()
       
    61     {
       
    62     User::LeaveIfError( iIpsecPolicyServ.Connect() );
       
    63     }
       
    64 
       
    65 // ---------------------------------------------------------------------------
       
    66 // Get acceptable IPsec policies for specified selectors. Get all acceptable
       
    67 // SA specifications with sequential GetIPSecSAInfo() method calls.
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 EXPORT_C CIpsecSaSpecList* CIpsecPolicyUtil::GetIpseSaSpecListLC( TInetAddr aLocalAddr, TInetAddr aLocalMask, 
       
    71                                                                   TInetAddr aRemoteAddr, TInetAddr aRemoteMask,
       
    72                                                                   TInt aProtocol, TUint32 aVpnNetId )
       
    73     {
       
    74     CIpsecSaSpecList* ipsecSaList = new (ELeave)CIpsecSaSpecList();
       
    75     CleanupStack::PushL(ipsecSaList);
       
    76     
       
    77     aLocalAddr.ConvertToV4Mapped();
       
    78     aLocalMask.ConvertToV4Mapped();
       
    79     aRemoteAddr.ConvertToV4Mapped();
       
    80     aRemoteAddr.SetScope(aVpnNetId);
       
    81     aRemoteMask.ConvertToV4Mapped();
       
    82     
       
    83     
       
    84     TIpsecSelectorInfo selectorInfo;
       
    85     selectorInfo.iLocal = aLocalAddr;
       
    86     selectorInfo.iLocalMask = aLocalMask;                
       
    87     selectorInfo.iRemote = aRemoteAddr;
       
    88     selectorInfo.iRemoteMask = aRemoteMask;
       
    89     selectorInfo.iProtocol  = aProtocol;
       
    90     selectorInfo.iSaIndex   = 0;
       
    91     TPckg<TIpsecSelectorInfo> pckgSelectorInfo(selectorInfo);
       
    92     TIpsecSaSpec saInfo;
       
    93     do
       
    94         {
       
    95         TRequestStatus requestStatus;        
       
    96         TPckg<TIpsecSaSpec> pckgSASpec(saInfo);
       
    97         
       
    98         iIpsecPolicyServ.MatchSelector( pckgSelectorInfo, 
       
    99                                         pckgSASpec,
       
   100                                         requestStatus );
       
   101         User::WaitForRequest(requestStatus);
       
   102         User::LeaveIfError(requestStatus.Int());
       
   103         
       
   104         ipsecSaList->AppendL(saInfo);
       
   105         selectorInfo.iSaIndex++;
       
   106         }
       
   107     while(saInfo.iMoreSasExist);        
       
   108 
       
   109     return ipsecSaList;    
       
   110     }
       
   111 
       
   112