vpnengine/vpntcwrapper/src/vpntcwrapper.cpp
changeset 0 33413c0669b9
equal deleted inserted replaced
-1:000000000000 0:33413c0669b9
       
     1 /*
       
     2 * Copyright (c) 2007 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:   PKCS#12 data handler
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include <x509cert.h>
       
    21 #include <mpkcs12.h>
       
    22 
       
    23 #include <e32std.h>
       
    24 #include <apacmdln.h>
       
    25 #include <bautils.h>
       
    26 
       
    27 #include <securityerr.h>
       
    28 #include <sysutil.h>
       
    29 
       
    30 #include "vpntcwrapper.h"
       
    31 #include "logvpncommon.h"
       
    32 
       
    33 EXPORT_C CVpnTcStub* NewTcStubL()
       
    34     {
       
    35     return new (ELeave) CVpnTcWrapper;
       
    36     }
       
    37 
       
    38 void CVpnTcWrapper::SetTCAttributeL(const TInt aAttribId, const TDesC8& aVal) 
       
    39     {
       
    40     LOG_("-> CVpnTcWrapper::SetTCAttribute()");
       
    41 
       
    42     if (!iConnected)
       
    43         {
       
    44         LOG_(" Not connected yet...");
       
    45         ConnectToDevLockL();
       
    46         }
       
    47 
       
    48     TInt err = iTs.SetDeviceLockParameter(aAttribId, aVal);
       
    49 
       
    50     LOG_1(" Errorcode: %d", err);
       
    51 
       
    52     User::LeaveIfError(err);
       
    53 
       
    54     LOG_("<- CVpnTcWrapper::SetTCAttribute()");
       
    55     }
       
    56 
       
    57 HBufC8* CVpnTcWrapper::GetTCAttributeL(TInt aAttribId) 
       
    58     {
       
    59     LOG_("-> CVpnTcWrapper::GetTCAttribute()");
       
    60 
       
    61     if (!iConnected)
       
    62         {
       
    63         LOG_(" Not connected yet...");
       
    64         ConnectToDevLockL();
       
    65         }
       
    66 
       
    67     LOG_(" Getting size");
       
    68 
       
    69     TInt size = iTs.GetDeviceLockParameterSize(aAttribId);
       
    70     if(size < 0)
       
    71         {
       
    72         LOG_1("<- CVpnTcWrapper::GetTCAttribute() Leave: %d", size);
       
    73         User::Leave(size);
       
    74         }
       
    75 
       
    76     LOG_1(" Attribute found, size: %d", size);
       
    77 
       
    78     HBufC8* buffer = HBufC8::NewLC(size);
       
    79     TPtr8 ptr8(buffer->Des());
       
    80 
       
    81     // Read the actual attribute value
       
    82     User::LeaveIfError(iTs.GetDeviceLockParameter(aAttribId, ptr8));
       
    83 
       
    84     CleanupStack::Pop(buffer);
       
    85 
       
    86     LOG_("<- CVpnTcWrapper::GetTCAttribute()");
       
    87     return buffer;
       
    88     }
       
    89 
       
    90 void CVpnTcWrapper::ConnectToDevLockL() 
       
    91     {
       
    92     LOG_("-> CVpnTcWrapper::ConnectToDevLockL()");
       
    93 
       
    94     User::LeaveIfError(iTc.Connect());
       
    95     User::LeaveIfError(iTs.Open(iTc));
       
    96     
       
    97     iConnected = ETrue;
       
    98 
       
    99     LOG_("<- CVpnTcWrapper::ConnectToDevLockL()");
       
   100     }
       
   101 
       
   102 CVpnTcWrapper::~CVpnTcWrapper() 
       
   103     {
       
   104     LOG_("-> CVpnTcWrapper::~CVpnTcWrapper()");
       
   105     
       
   106     iTs.Close();
       
   107     iTc.Close();
       
   108     iConnected = EFalse;
       
   109     
       
   110     LOG_("<- CVpnTcWrapper::~CVpnTcWrapper()");
       
   111     }
       
   112 
       
   113 
       
   114