Update contrib.
2 * Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
29 #include "cryptojobs.h"
32 class DCryptoLddChannelFactory : public DLogicalDevice
35 DCryptoLddChannelFactory();
36 ~DCryptoLddChannelFactory();
37 virtual TInt Install();
38 virtual void GetCaps(TDes8& aDes) const;
39 virtual TInt Create(DLogicalChannelBase*& aChannel);
41 // The job scheduler for the Random h/w
42 DCryptoJobScheduler iJSRandom;
44 // The job scheduler for the AES h/w
45 DCryptoJobScheduler iJSAes;
48 class DCryptoPddChannel;
50 Logical Channel classes for 'Crypto'
56 This class just exists to keep all the LDD Chan variables for
57 dealing with Random requests in one place.
59 class DCryptoLddChannel;
60 class DLddChanRandom : public DBase, public MCryptoJobCallbacks
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.
68 // Functions are virtual so PDD can call them via a vtable instead
69 // of linking directly to them.
71 virtual TInt Random(TRequestStatus* aStatus,TDes8* aBuffer);
74 virtual TInt DataRequired();
75 virtual TInt DataAvailable();
76 virtual void JobComplete(TInt aResult);
81 virtual void RandomCancel();
83 DCryptoLddChannel &iParent;
84 // Members used for processing a Random request
86 TRequestStatus* iRandomStatus; // User request
87 TDes8* iRandomDescriptor; // User descriptor
91 CryptoJobRandom *iJob; // Ptr to PDD Random job (not owned by us)
97 This class just exists to keep all the LDD Chan variables for
98 dealing with Aes requests in one place.
100 class DCryptoLddChannel;
101 class DLddChanAes : public DBase, public MCryptoJobCallbacks
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.
109 // Functions are virtual so PDD can call them via a vtable instead
110 // of linking directly to them.
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);
117 virtual TInt DataRequired();
118 virtual TInt DataAvailable();
119 virtual void JobComplete(TInt aResult);
122 Cancel a user request
124 virtual void CancelRead();
125 virtual void CancelWrite();
127 DCryptoLddChannel &iParent;
128 // Members used for processing a Aes request
130 TRequestStatus *iAesWriteStatus; // User request
131 TDesC8 *iAesWriteDescriptor; // User descriptor
132 TInt iWriteRequestLength;
133 TInt iCurrentUserWriteIndex;
135 TRequestStatus *iAesReadStatus; // User request
136 TDes8 *iAesReadDescriptor; // User descriptor
137 TInt iReadRequestLength;
138 TInt iOriginalUserReadDescLength;
139 TInt iCurrentUserReadIndex;
142 RCryptoDriver::TChainingMode iMode;
143 TInt iKeyLengthBytes;
145 CryptoJobAes *iJob; // Ptr to PDD AES job (not owned by us)
149 class DCryptoLddChannel : public DLogicalChannel
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);
161 // Accessor for the LDD Factory
162 inline DCryptoLddChannelFactory *LddFactory() const;
164 DLddChanRandom iLddChanRandom;
165 DLddChanAes iLddChanAes;
168 friend class DLddChanRandom;
169 friend class DLddChanAes;
174 ERequestAlreadyPending = 1
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);
181 // Accessor for the PDD
182 inline DCryptoPddChannel* PddChan() const;
184 // Query h/w versions
185 TInt GetHwVersions(TDes8* aHwVersionsBuf) const;
187 // Methods for configuration
188 TInt GetConfig(TDes8* aConfigBuf) const;
189 TInt SetConfig(const TDesC8* aConfigBuf);
190 void CurrentConfig(RCryptoDriver::TConfig& aConfig) const;
195 inline DCryptoLddChannelFactory *DCryptoLddChannel::LddFactory() const
197 return static_cast<DCryptoLddChannelFactory *>(iDevice);
201 class DCryptoPddChannel : public DBase
204 virtual TDfcQue* DfcQue() = 0;
206 virtual void GetHwVersions(RCryptoDriver::THwVersions& aHwVersions) const = 0;
207 virtual TInt FakeDriverSetting() const = 0;
208 virtual TInt SetFakeDriverSetting(TInt aFakeDriverSetting) = 0;
210 virtual CryptoJobRandom *GetJobRandom(TBool aAutoCreate = ETrue) = 0;
211 virtual CryptoJobAes *GetJobAes(TBool aAutoCreate = ETrue) = 0;
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;
224 inline DCryptoPddChannel* DCryptoLddChannel::PddChan() const
226 return static_cast<DCryptoPddChannel *>(iPdd);