vpnengine/dmadipsecvpn/src/dmadstorevpnapcmm.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2008 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:   VPN access point manipulation.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <cmpluginvpndef.h>
       
    21 #include <cmdestinationext.h>
       
    22 
       
    23 #include "dmadstorevpnap.h"
       
    24 #include "vpnlogger.h"
       
    25 
       
    26 using namespace CMManager;
       
    27 // ======== LOCAL FUNCTIONS ========
       
    28 
       
    29 CVpnAp* CVpnAp::NewL(void)
       
    30     {
       
    31     TRACE("CVpnAp::NewL");
       
    32     CVpnAp* self = new (ELeave) CVpnAp;
       
    33     CleanupStack::PushL(self);
       
    34     self->ConstructL();
       
    35     CleanupStack::Pop(self);
       
    36     
       
    37     return self;
       
    38     }
       
    39 
       
    40 
       
    41 CVpnAp::CVpnAp()
       
    42     {
       
    43     TRACE("CVpnAp::CVpnAp");
       
    44     }
       
    45 
       
    46 
       
    47 void CVpnAp::ConstructL()
       
    48     {
       
    49     TRACE("CVpnAp::ConstructL");
       
    50     
       
    51     iCmManagerExt.OpenL();
       
    52     }
       
    53 
       
    54 
       
    55 CVpnAp::~CVpnAp()
       
    56     {
       
    57     TRACE("CVpnAp::~CVpnAp");
       
    58     
       
    59     iCmManagerExt.Close();
       
    60     }
       
    61 
       
    62 
       
    63 TBool CVpnAp::FindVpnApL(TVpnApCommsId aId)
       
    64     {
       
    65     TRACE("CVpnAp::FindVpnApL");
       
    66     
       
    67     TBool connectionFound = EFalse;
       
    68     
       
    69     RCmConnectionMethodExt vpnConnectionMethod;    
       
    70     TRAPD(err, vpnConnectionMethod = iCmManagerExt.ConnectionMethodL( aId ));
       
    71     CleanupClosePushL(vpnConnectionMethod); 
       
    72 
       
    73     switch(err)    
       
    74         {
       
    75         case KErrNone:
       
    76             if ( IsVpnConnectionMethodL(vpnConnectionMethod) )
       
    77                 {
       
    78                 connectionFound = ETrue;
       
    79                 }
       
    80             break;
       
    81         case KErrNotFound:
       
    82             //do nothing
       
    83             break;
       
    84         default:
       
    85             User::Leave(err);
       
    86             break;
       
    87         }
       
    88     
       
    89     CleanupStack::PopAndDestroy(); //vpnConnectionMethod    
       
    90     return connectionFound;
       
    91     }
       
    92 
       
    93 
       
    94 void CVpnAp::DeleteVpnApL(TVpnApCommsId aId)
       
    95     {
       
    96     TRACE("CVpnAp::DeleteVpnApL");
       
    97     
       
    98     RCmConnectionMethodExt vpnConnectionMethod = iCmManagerExt.ConnectionMethodL( aId );
       
    99     CleanupClosePushL(vpnConnectionMethod);
       
   100     
       
   101     //Check that the type of the connection is correct.
       
   102     if ( !IsVpnConnectionMethodL(vpnConnectionMethod) )
       
   103         {
       
   104         User::Leave(KErrNotFound);
       
   105         }
       
   106 
       
   107     if ( !vpnConnectionMethod.DeleteL() )
       
   108         {
       
   109         User::Leave(KErrGeneral);
       
   110         }    
       
   111         
       
   112     CleanupStack::PopAndDestroy(); //vpnConnectionMethod
       
   113     }
       
   114 
       
   115 
       
   116 void CVpnAp::ListVpnApsL(RArray<TVpnApCommsId>& aIdArray)
       
   117     {
       
   118     TRACE("CVpnAp::ListVpnApsL");
       
   119             
       
   120     aIdArray.Reset();            
       
   121             
       
   122     //First collect all VPN connection methods from destinations
       
   123     RArray<TUint32> destinationArray;    
       
   124     iCmManagerExt.AllDestinationsL( destinationArray );
       
   125     CleanupClosePushL(destinationArray);    
       
   126     
       
   127     for (TInt i = 0; i < destinationArray.Count(); ++i)
       
   128         {
       
   129         RCmDestinationExt destination = iCmManagerExt.DestinationL( destinationArray[i] );
       
   130         CleanupClosePushL(destination);
       
   131         
       
   132         TInt connectionMethodCount = destination.ConnectionMethodCount();
       
   133         for (TInt j = 0; j < connectionMethodCount; ++j)
       
   134             {
       
   135             RCmConnectionMethodExt connectionMethod = destination.ConnectionMethodL( j );  
       
   136             CleanupClosePushL(connectionMethod);
       
   137             if ( IsVpnConnectionMethodL(connectionMethod) )
       
   138                 {
       
   139                 TUint32 apId = connectionMethod.GetIntAttributeL( ECmId );
       
   140                 User::LeaveIfError(aIdArray.Append(apId));
       
   141                 }
       
   142             CleanupStack::PopAndDestroy(); //connectionMethod       
       
   143             }
       
   144         
       
   145         CleanupStack::PopAndDestroy(); //destination
       
   146         }
       
   147     CleanupStack::PopAndDestroy(); //destinationArray    
       
   148     
       
   149     //Second collect VPN connection methods, which are not inside a destination.    
       
   150     RArray<TUint32> connectionMethodArray;    
       
   151     iCmManagerExt.ConnectionMethodL( connectionMethodArray );
       
   152     CleanupClosePushL(connectionMethodArray);
       
   153     
       
   154     for ( TInt i = 0; i < connectionMethodArray.Count(); ++i)
       
   155         {
       
   156         RCmConnectionMethodExt connectionMethod = 
       
   157                 iCmManagerExt.ConnectionMethodL( connectionMethodArray[i] );
       
   158         CleanupClosePushL(connectionMethod);
       
   159         if ( IsVpnConnectionMethodL(connectionMethod) )
       
   160             {
       
   161             User::LeaveIfError(aIdArray.Append(connectionMethodArray[i]));
       
   162             }
       
   163         CleanupStack::PopAndDestroy(); //connectionMethod               
       
   164         }    
       
   165     CleanupStack::PopAndDestroy(); //connectionMethodArray
       
   166     }
       
   167 
       
   168 
       
   169 void CVpnAp::GetVpnApL(TVpnApCommsId aId, TVpnApParms& aVpnApParms)
       
   170     {
       
   171     TRACE("CVpnAp::GetVpnApL");
       
   172     
       
   173     RCmConnectionMethodExt vpnConnectionMethod = iCmManagerExt.ConnectionMethodL( aId );
       
   174     CleanupClosePushL(vpnConnectionMethod);
       
   175     
       
   176     //Check that the type of the connection is correct.
       
   177     if ( !IsVpnConnectionMethodL(vpnConnectionMethod) )
       
   178         {
       
   179         User::Leave(KErrNotFound);
       
   180         }
       
   181     
       
   182     HBufC* string = vpnConnectionMethod.GetStringAttributeL( ECmName );
       
   183     aVpnApParms.iName = *string;
       
   184     delete string;
       
   185     string = NULL;
       
   186     
       
   187     string = vpnConnectionMethod.GetStringAttributeL( EVpnServicePolicy );  
       
   188     aVpnApParms.iPolicyId = *string;
       
   189     delete string;
       
   190     string = NULL;
       
   191         
       
   192     // real IAP or SNAP. ECmNextLayerIapId == EVpnIapId
       
   193     TUint32 realConn = vpnConnectionMethod.GetIntAttributeL(EVpnIapId); 
       
   194     if (realConn != 0)
       
   195         {
       
   196         DEBUG_LOG1(_L("Real connection is IAP %d"), realConn);         
       
   197         aVpnApParms.iRealConnRefType = TVpnApParms::EIapRealConnRef;
       
   198         aVpnApParms.iRealConnRef = realConn;        
       
   199         }
       
   200     else
       
   201         {
       
   202         realConn = vpnConnectionMethod.GetIntAttributeL(ECmNextLayerSNAPId);
       
   203         DEBUG_LOG1(_L("Real connection is snap %d"), realConn);         
       
   204         aVpnApParms.iRealConnRefType = TVpnApParms::ESnapRealConnRef;
       
   205         aVpnApParms.iRealConnRef = realConn;        
       
   206         }                        
       
   207 
       
   208     CleanupStack::PopAndDestroy(); //vpnConnectionMethod    
       
   209     }
       
   210 
       
   211 
       
   212 TVpnApCommsId CVpnAp::AddVpnApL(const TVpnApParms& aVpnApParms)
       
   213     {
       
   214     TRACE("CVpnAp::AddVpnApL");
       
   215     
       
   216     RCmConnectionMethodExt vpnConnectionMethod = 
       
   217         iCmManagerExt.CreateConnectionMethodL( KPluginVPNBearerTypeUid );
       
   218 
       
   219     CleanupClosePushL( vpnConnectionMethod );
       
   220 
       
   221     UpdateVpnApL(vpnConnectionMethod, aVpnApParms);
       
   222     
       
   223     // save changes
       
   224     vpnConnectionMethod.UpdateL();
       
   225 
       
   226     TUint32 apId = vpnConnectionMethod.GetIntAttributeL( ECmId );
       
   227 
       
   228     CleanupStack::PopAndDestroy(); // vpnConnectionMethod
       
   229     
       
   230     return apId;
       
   231     }
       
   232 
       
   233 
       
   234 void CVpnAp::UpdateVpnApL(TVpnApCommsId aId, const TVpnApParms& aVpnApParms)
       
   235     {
       
   236     TRACE("CVpnAp::UpdateVpnApL");
       
   237 
       
   238     RCmConnectionMethodExt vpnConnectionMethod = iCmManagerExt.ConnectionMethodL( aId );
       
   239     CleanupClosePushL(vpnConnectionMethod);
       
   240     
       
   241     //Check that the type of the connection is correct.
       
   242     if ( !IsVpnConnectionMethodL(vpnConnectionMethod) )
       
   243         {
       
   244         User::Leave(KErrNotFound);
       
   245         }
       
   246 
       
   247     UpdateVpnApL(vpnConnectionMethod, aVpnApParms);    
       
   248     vpnConnectionMethod.UpdateL();    
       
   249     CleanupStack::PopAndDestroy(); //vpnConnectionMethod    
       
   250     }
       
   251     
       
   252 
       
   253 void CVpnAp::UpdateVpnApL(RCmConnectionMethodExt& aConnectionMethod, 
       
   254                           const TVpnApParms& aVpnApParms)
       
   255     {
       
   256     
       
   257     TRACE("CVpnAp::UpdateVpnApL");
       
   258     
       
   259     __ASSERT_DEBUG( aConnectionMethod.GetBoolAttributeL(ECmVirtual), User::Invariant() );
       
   260     
       
   261     aConnectionMethod.SetIntAttributeL( ECmNamingMethod, ENamingNothing );
       
   262     aConnectionMethod.SetStringAttributeL( ECmName, aVpnApParms.iName );
       
   263     aConnectionMethod.SetStringAttributeL( EVpnServicePolicy, aVpnApParms.iPolicyId );  
       
   264     
       
   265     switch(aVpnApParms.iRealConnRefType)
       
   266         {        
       
   267         case TVpnApParms::EIapRealConnRef:
       
   268             aConnectionMethod.SetIntAttributeL( EVpnIapId, aVpnApParms.iRealConnRef );            
       
   269             DEBUG_LOG1(_L("VPN iap uses real iap %d"), aVpnApParms.iRealConnRef);
       
   270             DEBUG_LOG1(_L("ECmNextLayerSNAPId is %d"), aConnectionMethod.GetIntAttributeL(ECmNextLayerSNAPId));            
       
   271             break;
       
   272         case TVpnApParms::ESnapRealConnRef:            
       
   273             aConnectionMethod.SetIntAttributeL( ECmNextLayerSNAPId, aVpnApParms.iRealConnRef );
       
   274             DEBUG_LOG1(_L("VPN iap uses real SNAP %d"), aVpnApParms.iRealConnRef);
       
   275             DEBUG_LOG1(_L("EVpnIapId is %d"), aConnectionMethod.GetIntAttributeL(EVpnIapId));            
       
   276             break;
       
   277         default:
       
   278             User::Invariant();
       
   279             break;                    
       
   280         }                
       
   281     }
       
   282 
       
   283 
       
   284 TBool CVpnAp::IsVpnConnectionMethodL(RCmConnectionMethodExt& aConnectionMethod) const
       
   285     {
       
   286     TBool isVPNConnectionMethod = EFalse;
       
   287     
       
   288     if ( aConnectionMethod.GetBoolAttributeL(ECmVirtual) &&
       
   289          aConnectionMethod.GetIntAttributeL( ECmBearerType ) == KPluginVPNBearerTypeUid)
       
   290         {
       
   291         isVPNConnectionMethod = ETrue;        
       
   292         }
       
   293     
       
   294     return isVPNConnectionMethod;
       
   295     }