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