os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4/cryptoldd.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 /*
     2 * Copyright (c) 2007-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 the License "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: 
    15 *
    16 */
    17 
    18 
    19 /**
    20  @file
    21  @internalComponent
    22  @released
    23 */
    24 #ifndef __CRYPTOLDD__
    25 #define __CRYPTOLDD__
    26 #include <e32cmn.h>
    27 #include <e32ver.h>
    28 #include <e32def.h>
    29 #include "cryptojobs.h"
    30 
    31 
    32 class DCryptoLddChannelFactory : public DLogicalDevice
    33 	{
    34 public:
    35 	DCryptoLddChannelFactory();
    36 	~DCryptoLddChannelFactory();
    37 	virtual TInt Install();
    38 	virtual void GetCaps(TDes8& aDes) const;
    39 	virtual TInt Create(DLogicalChannelBase*& aChannel);
    40 
    41 	// The job scheduler for the Random h/w
    42 	DCryptoJobScheduler iJSRandom;
    43 
    44 	// The job scheduler for the AES h/w
    45 	DCryptoJobScheduler iJSAes;
    46 	};
    47 
    48 class DCryptoPddChannel;
    49 /**
    50   Logical Channel classes for 'Crypto'
    51 */
    52 
    53 /**
    54    DLddChanRandom
    55 
    56    This class just exists to keep all the LDD Chan variables for
    57    dealing with Random requests in one place.
    58 */
    59 class DCryptoLddChannel;
    60 class DLddChanRandom : public DBase, public MCryptoJobCallbacks
    61 	{
    62 public:
    63 	DLddChanRandom(DCryptoLddChannel &aParent);
    64 	// Cleanup must be done by DCryptoLddChannel destructor because
    65 	// by the time our destructor gets called the DCryptoLddChannel
    66 	// has already been destroyed.
    67 
    68 	// Functions are virtual so PDD can call them via a vtable instead
    69 	// of linking directly to them.
    70 
    71     virtual TInt Random(TRequestStatus* aStatus,TDes8* aBuffer);
    72 
    73 	// Callbacks for PDD
    74 	virtual TInt DataRequired();
    75 	virtual TInt DataAvailable();
    76 	virtual void JobComplete(TInt aResult);
    77 	
    78 	/**
    79 	   Cancel a user request
    80 	*/
    81 	virtual void RandomCancel();
    82 private:
    83 	DCryptoLddChannel &iParent;
    84     // Members used for processing a Random request
    85 	
    86     TRequestStatus* iRandomStatus;	// User request
    87     TDes8* iRandomDescriptor;		// User descriptor
    88 	TInt iRequestLength;
    89 	TInt iCurrentIndex;
    90 
    91 	CryptoJobRandom *iJob; // Ptr to PDD Random job (not owned by us)
    92 	};
    93 
    94 /**
    95    DLddChanAes
    96 
    97    This class just exists to keep all the LDD Chan variables for
    98    dealing with Aes requests in one place.
    99 */
   100 class DCryptoLddChannel;
   101 class DLddChanAes : public DBase, public MCryptoJobCallbacks
   102 	{
   103 public:
   104 	DLddChanAes(DCryptoLddChannel &aParent);
   105 	// Cleanup must be done by DCryptoLddChannel destructor because
   106 	// by the time our destructor gets called the DCryptoLddChannel
   107 	// has already been destroyed.
   108 
   109 	// Functions are virtual so PDD can call them via a vtable instead
   110 	// of linking directly to them.
   111 
   112     virtual TInt SetAesConfig(const TDesC8 *aConfigBuf);
   113     virtual TInt AesWrite(TRequestStatus *aStatus, TDesC8 *aBuffer);
   114     virtual TInt AesRead(TRequestStatus *aStatus, TDes8 *aBuffer, TUint32 aLength);
   115 
   116 	// Callbacks for PDD
   117 	virtual TInt DataRequired();
   118 	virtual TInt DataAvailable();
   119 	virtual void JobComplete(TInt aResult);
   120 
   121 	/**
   122 	   Cancel a user request
   123 	*/
   124 	virtual void CancelRead();
   125 	virtual void CancelWrite();
   126 private:
   127 	DCryptoLddChannel &iParent;
   128     // Members used for processing a Aes request
   129 	
   130     TRequestStatus *iAesWriteStatus;	// User request
   131     TDesC8 *iAesWriteDescriptor;		// User descriptor
   132 	TInt iWriteRequestLength;
   133 	TInt iCurrentUserWriteIndex;
   134 
   135     TRequestStatus *iAesReadStatus;	// User request
   136     TDes8 *iAesReadDescriptor;		// User descriptor
   137 	TInt iReadRequestLength;
   138 	TInt iOriginalUserReadDescLength;
   139 	TInt iCurrentUserReadIndex;
   140 
   141 	TBool iEncrypt;
   142 	RCryptoDriver::TChainingMode iMode;
   143 	TInt iKeyLengthBytes;
   144 
   145 	CryptoJobAes *iJob; // Ptr to PDD AES job (not owned by us)
   146 	};
   147 
   148 
   149 class DCryptoLddChannel : public DLogicalChannel
   150     {
   151 public:
   152     DCryptoLddChannel();
   153     virtual ~DCryptoLddChannel();
   154     // Inherited from DObject
   155     virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
   156     // Inherited from DLogicalChannelBase
   157     virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
   158     // Inherited from DLogicalChannel
   159     virtual void HandleMsg(TMessageBase* aMsg);
   160 
   161     // Accessor for the LDD Factory
   162 	inline DCryptoLddChannelFactory *LddFactory() const;
   163 	
   164 	DLddChanRandom iLddChanRandom;
   165 	DLddChanAes iLddChanAes;
   166 	
   167 private:
   168 	friend class DLddChanRandom;
   169 	friend class DLddChanAes;
   170 	
   171     // Panic reasons
   172     enum TPanic
   173         {
   174         ERequestAlreadyPending = 1
   175         };
   176     // Implementation for the differnt kinds of requests send through RBusLogicalChannel
   177     TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
   178     TInt DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2);
   179     void DoCancel(TUint aMask);
   180 
   181     // Accessor for the PDD
   182 	inline DCryptoPddChannel* PddChan() const;
   183 
   184     // Query h/w versions
   185     TInt GetHwVersions(TDes8* aHwVersionsBuf) const;
   186 
   187     // Methods for configuration
   188     TInt GetConfig(TDes8* aConfigBuf) const;
   189     TInt SetConfig(const TDesC8* aConfigBuf);
   190 	void CurrentConfig(RCryptoDriver::TConfig& aConfig) const;
   191 
   192 private:
   193     DThread* iClient;
   194     };
   195 inline DCryptoLddChannelFactory *DCryptoLddChannel::LddFactory() const
   196 	{
   197 	return static_cast<DCryptoLddChannelFactory *>(iDevice);
   198 	}
   199 
   200 
   201 class DCryptoPddChannel : public DBase
   202     {
   203 public:
   204     virtual TDfcQue* DfcQue() = 0;
   205 
   206     virtual void GetHwVersions(RCryptoDriver::THwVersions& aHwVersions) const = 0;
   207     virtual TInt FakeDriverSetting() const = 0;
   208     virtual TInt SetFakeDriverSetting(TInt aFakeDriverSetting) = 0;
   209 
   210 	virtual CryptoJobRandom *GetJobRandom(TBool aAutoCreate = ETrue) = 0;
   211 	virtual CryptoJobAes *GetJobAes(TBool aAutoCreate = ETrue) = 0;
   212 
   213 	// The LDD chan needs to be able to set this, and the Job
   214 	// implementation classes need to be able to read it, so there is
   215 	// no point in having accessor functions for it...
   216 	DCryptoLddChannel *iCryptoLddChannel;
   217     };
   218 
   219 
   220 
   221 
   222 
   223 
   224 inline DCryptoPddChannel* DCryptoLddChannel::PddChan() const
   225     {
   226 	return static_cast<DCryptoPddChannel *>(iPdd);
   227 	}
   228 
   229 
   230 
   231 
   232 #endif