1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/test/h4drv/crypto_h4/cryptoldd.h Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,232 @@
1.4 +/*
1.5 +* Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +/**
1.23 + @file
1.24 + @internalComponent
1.25 + @released
1.26 +*/
1.27 +#ifndef __CRYPTOLDD__
1.28 +#define __CRYPTOLDD__
1.29 +#include <e32cmn.h>
1.30 +#include <e32ver.h>
1.31 +#include <e32def.h>
1.32 +#include "cryptojobs.h"
1.33 +
1.34 +
1.35 +class DCryptoLddChannelFactory : public DLogicalDevice
1.36 + {
1.37 +public:
1.38 + DCryptoLddChannelFactory();
1.39 + ~DCryptoLddChannelFactory();
1.40 + virtual TInt Install();
1.41 + virtual void GetCaps(TDes8& aDes) const;
1.42 + virtual TInt Create(DLogicalChannelBase*& aChannel);
1.43 +
1.44 + // The job scheduler for the Random h/w
1.45 + DCryptoJobScheduler iJSRandom;
1.46 +
1.47 + // The job scheduler for the AES h/w
1.48 + DCryptoJobScheduler iJSAes;
1.49 + };
1.50 +
1.51 +class DCryptoPddChannel;
1.52 +/**
1.53 + Logical Channel classes for 'Crypto'
1.54 +*/
1.55 +
1.56 +/**
1.57 + DLddChanRandom
1.58 +
1.59 + This class just exists to keep all the LDD Chan variables for
1.60 + dealing with Random requests in one place.
1.61 +*/
1.62 +class DCryptoLddChannel;
1.63 +class DLddChanRandom : public DBase, public MCryptoJobCallbacks
1.64 + {
1.65 +public:
1.66 + DLddChanRandom(DCryptoLddChannel &aParent);
1.67 + // Cleanup must be done by DCryptoLddChannel destructor because
1.68 + // by the time our destructor gets called the DCryptoLddChannel
1.69 + // has already been destroyed.
1.70 +
1.71 + // Functions are virtual so PDD can call them via a vtable instead
1.72 + // of linking directly to them.
1.73 +
1.74 + virtual TInt Random(TRequestStatus* aStatus,TDes8* aBuffer);
1.75 +
1.76 + // Callbacks for PDD
1.77 + virtual TInt DataRequired();
1.78 + virtual TInt DataAvailable();
1.79 + virtual void JobComplete(TInt aResult);
1.80 +
1.81 + /**
1.82 + Cancel a user request
1.83 + */
1.84 + virtual void RandomCancel();
1.85 +private:
1.86 + DCryptoLddChannel &iParent;
1.87 + // Members used for processing a Random request
1.88 +
1.89 + TRequestStatus* iRandomStatus; // User request
1.90 + TDes8* iRandomDescriptor; // User descriptor
1.91 + TInt iRequestLength;
1.92 + TInt iCurrentIndex;
1.93 +
1.94 + CryptoJobRandom *iJob; // Ptr to PDD Random job (not owned by us)
1.95 + };
1.96 +
1.97 +/**
1.98 + DLddChanAes
1.99 +
1.100 + This class just exists to keep all the LDD Chan variables for
1.101 + dealing with Aes requests in one place.
1.102 +*/
1.103 +class DCryptoLddChannel;
1.104 +class DLddChanAes : public DBase, public MCryptoJobCallbacks
1.105 + {
1.106 +public:
1.107 + DLddChanAes(DCryptoLddChannel &aParent);
1.108 + // Cleanup must be done by DCryptoLddChannel destructor because
1.109 + // by the time our destructor gets called the DCryptoLddChannel
1.110 + // has already been destroyed.
1.111 +
1.112 + // Functions are virtual so PDD can call them via a vtable instead
1.113 + // of linking directly to them.
1.114 +
1.115 + virtual TInt SetAesConfig(const TDesC8 *aConfigBuf);
1.116 + virtual TInt AesWrite(TRequestStatus *aStatus, TDesC8 *aBuffer);
1.117 + virtual TInt AesRead(TRequestStatus *aStatus, TDes8 *aBuffer, TUint32 aLength);
1.118 +
1.119 + // Callbacks for PDD
1.120 + virtual TInt DataRequired();
1.121 + virtual TInt DataAvailable();
1.122 + virtual void JobComplete(TInt aResult);
1.123 +
1.124 + /**
1.125 + Cancel a user request
1.126 + */
1.127 + virtual void CancelRead();
1.128 + virtual void CancelWrite();
1.129 +private:
1.130 + DCryptoLddChannel &iParent;
1.131 + // Members used for processing a Aes request
1.132 +
1.133 + TRequestStatus *iAesWriteStatus; // User request
1.134 + TDesC8 *iAesWriteDescriptor; // User descriptor
1.135 + TInt iWriteRequestLength;
1.136 + TInt iCurrentUserWriteIndex;
1.137 +
1.138 + TRequestStatus *iAesReadStatus; // User request
1.139 + TDes8 *iAesReadDescriptor; // User descriptor
1.140 + TInt iReadRequestLength;
1.141 + TInt iOriginalUserReadDescLength;
1.142 + TInt iCurrentUserReadIndex;
1.143 +
1.144 + TBool iEncrypt;
1.145 + RCryptoDriver::TChainingMode iMode;
1.146 + TInt iKeyLengthBytes;
1.147 +
1.148 + CryptoJobAes *iJob; // Ptr to PDD AES job (not owned by us)
1.149 + };
1.150 +
1.151 +
1.152 +class DCryptoLddChannel : public DLogicalChannel
1.153 + {
1.154 +public:
1.155 + DCryptoLddChannel();
1.156 + virtual ~DCryptoLddChannel();
1.157 + // Inherited from DObject
1.158 + virtual TInt RequestUserHandle(DThread* aThread, TOwnerType aType);
1.159 + // Inherited from DLogicalChannelBase
1.160 + virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer);
1.161 + // Inherited from DLogicalChannel
1.162 + virtual void HandleMsg(TMessageBase* aMsg);
1.163 +
1.164 + // Accessor for the LDD Factory
1.165 + inline DCryptoLddChannelFactory *LddFactory() const;
1.166 +
1.167 + DLddChanRandom iLddChanRandom;
1.168 + DLddChanAes iLddChanAes;
1.169 +
1.170 +private:
1.171 + friend class DLddChanRandom;
1.172 + friend class DLddChanAes;
1.173 +
1.174 + // Panic reasons
1.175 + enum TPanic
1.176 + {
1.177 + ERequestAlreadyPending = 1
1.178 + };
1.179 + // Implementation for the differnt kinds of requests send through RBusLogicalChannel
1.180 + TInt DoControl(TInt aFunction, TAny* a1, TAny* a2);
1.181 + TInt DoRequest(TInt aReqNo, TRequestStatus* aStatus, TAny* a1, TAny* a2);
1.182 + void DoCancel(TUint aMask);
1.183 +
1.184 + // Accessor for the PDD
1.185 + inline DCryptoPddChannel* PddChan() const;
1.186 +
1.187 + // Query h/w versions
1.188 + TInt GetHwVersions(TDes8* aHwVersionsBuf) const;
1.189 +
1.190 + // Methods for configuration
1.191 + TInt GetConfig(TDes8* aConfigBuf) const;
1.192 + TInt SetConfig(const TDesC8* aConfigBuf);
1.193 + void CurrentConfig(RCryptoDriver::TConfig& aConfig) const;
1.194 +
1.195 +private:
1.196 + DThread* iClient;
1.197 + };
1.198 +inline DCryptoLddChannelFactory *DCryptoLddChannel::LddFactory() const
1.199 + {
1.200 + return static_cast<DCryptoLddChannelFactory *>(iDevice);
1.201 + }
1.202 +
1.203 +
1.204 +class DCryptoPddChannel : public DBase
1.205 + {
1.206 +public:
1.207 + virtual TDfcQue* DfcQue() = 0;
1.208 +
1.209 + virtual void GetHwVersions(RCryptoDriver::THwVersions& aHwVersions) const = 0;
1.210 + virtual TInt FakeDriverSetting() const = 0;
1.211 + virtual TInt SetFakeDriverSetting(TInt aFakeDriverSetting) = 0;
1.212 +
1.213 + virtual CryptoJobRandom *GetJobRandom(TBool aAutoCreate = ETrue) = 0;
1.214 + virtual CryptoJobAes *GetJobAes(TBool aAutoCreate = ETrue) = 0;
1.215 +
1.216 + // The LDD chan needs to be able to set this, and the Job
1.217 + // implementation classes need to be able to read it, so there is
1.218 + // no point in having accessor functions for it...
1.219 + DCryptoLddChannel *iCryptoLddChannel;
1.220 + };
1.221 +
1.222 +
1.223 +
1.224 +
1.225 +
1.226 +
1.227 +inline DCryptoPddChannel* DCryptoLddChannel::PddChan() const
1.228 + {
1.229 + return static_cast<DCryptoPddChannel *>(iPdd);
1.230 + }
1.231 +
1.232 +
1.233 +
1.234 +
1.235 +#endif