vpnengine/kmdapi/src/kmdapi.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:   Key Management Daemon API
       
    15 *
       
    16 */
       
    17 
       
    18 // EXTERNAL INCLUDES
       
    19 #include <e32std.h>
       
    20 #include <e32math.h>
       
    21 
       
    22 // INTERNAL INCLUDES
       
    23 #include "kmdserver.h"
       
    24 #include "clistatic.h"
       
    25 
       
    26 // CLASS HEADER
       
    27 #include "kmdapi.h"
       
    28 
       
    29 // ---------------------------------------------------------------------------
       
    30 // Opens a session to KMD server and starts the server if it is not yet
       
    31 // started.
       
    32 // ---------------------------------------------------------------------------
       
    33 //
       
    34 EXPORT_C TInt RKMD::Connect()
       
    35 	{
       
    36 	TInt retry=2;
       
    37 	for ( ;; )
       
    38 		{
       
    39 		TInt r = CreateSession( KKmdServerName,
       
    40                                 TVersion( KKmdServMajorVersion,
       
    41                                           KKmdServMinorVersion,
       
    42                                           KKmdServBuildVersion),
       
    43                                           KDefaultMessageSlots );
       
    44 
       
    45 		if ( r != KErrNotFound && r != KErrServerTerminated )
       
    46 		    {
       
    47 		    return r;
       
    48 		    }
       
    49 		if ( --retry == 0 )
       
    50 		    {
       
    51 			return r;
       
    52 		    }
       
    53 		r = Launcher::LaunchServer( KKmdServerName,
       
    54 		                            KKmdServerImg,
       
    55                                     KServerUid3,
       
    56                                     KMyServerInitHeapSize,
       
    57                                     KMyServerMaxHeapSize,
       
    58                                     KMyServerStackSize );
       
    59 		if ( r != KErrNone && r != KErrAlreadyExists )
       
    60 		    {
       
    61 			return r;
       
    62 		    }
       
    63 		}
       
    64 	}
       
    65 
       
    66 // ---------------------------------------------------------------------------
       
    67 // Start a real network connection.
       
    68 // ---------------------------------------------------------------------------
       
    69 //
       
    70 EXPORT_C void RKMD::StartRealConnection( TUint32 aVpnIapId, 
       
    71                                          TPckg<TVpnRealConnectionParams>& aRealConfig,
       
    72                                          TRequestStatus& aStatus ) const
       
    73     {
       
    74     SendReceive( CKmdServer::KKmdStartConnection,
       
    75                  TIpcArgs( aVpnIapId, &aRealConfig ),
       
    76                  aStatus );
       
    77     }
       
    78     
       
    79 // ---------------------------------------------------------------------------
       
    80 // Cancels ongoing activate request.
       
    81 // ---------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C void RKMD::CancelStartRealConnection() const
       
    84     {
       
    85     SendReceive( CKmdServer::KKmdCancelStartConnection );
       
    86     }
       
    87 
       
    88 // ---------------------------------------------------------------------------
       
    89 // Asynchronous Activate request.
       
    90 // ---------------------------------------------------------------------------
       
    91 //
       
    92 EXPORT_C void RKMD::Activate( TUint32 aVpnIapId,
       
    93                               const TDesC& aVpnIfName,
       
    94                               const TDesC8& aIkeConf,                               
       
    95                               TVPNAddressPckg& aVPNAddress,
       
    96                               TRequestStatus& aStatus ) const
       
    97     {
       
    98 	SendReceive( CKmdServer::KKmdActivateAsync,
       
    99 				 TIpcArgs( aVpnIapId,
       
   100 				           &aVpnIfName,
       
   101 				           &aIkeConf,
       
   102 				           &aVPNAddress ),
       
   103 				           aStatus );
       
   104     }
       
   105 
       
   106 // ---------------------------------------------------------------------------
       
   107 // Cancels ongoing Activate request.
       
   108 // ---------------------------------------------------------------------------
       
   109 //
       
   110 EXPORT_C void RKMD::CancelActivate() const
       
   111     {
       
   112     SendReceive( CKmdServer::KKmdCancelActivateAsync );
       
   113     }
       
   114 
       
   115 // ---------------------------------------------------------------------------
       
   116 // Stops specified VPN connection.
       
   117 // ---------------------------------------------------------------------------
       
   118 //
       
   119 EXPORT_C TInt RKMD::StopVpnConnection( TUint32 aVpnIapId,
       
   120                                        TKmdStopConnection::TType aType )
       
   121     { 
       
   122     return SendReceive( CKmdServer::KKmdStopConnection,
       
   123                         TIpcArgs( aVpnIapId, aType ) );
       
   124     }
       
   125 
       
   126 // ---------------------------------------------------------------------------
       
   127 // Resolve an IP address from FQDN.
       
   128 // ---------------------------------------------------------------------------
       
   129 //
       
   130 EXPORT_C void RKMD::ResolveAddress( TUint32 aVpnIapId, 
       
   131                                     const TDesC& aFqdn,
       
   132                                     TNameEntry& aResult,
       
   133                                     TRequestStatus& aStatus ) const
       
   134     {
       
   135     SendReceive( CKmdServer::KKmdResolveAddress,
       
   136                  TIpcArgs( aVpnIapId, &aFqdn, &aResult ),
       
   137                  aStatus );    
       
   138     }
       
   139     
       
   140 // ---------------------------------------------------------------------------
       
   141 // Cancel outstanding ResolveAddress query.
       
   142 // ---------------------------------------------------------------------------
       
   143 //    
       
   144 EXPORT_C void RKMD::CancelResolve() const
       
   145     {
       
   146     SendReceive( CKmdServer::KKmdCancelResolveAddress );
       
   147     }
       
   148