|
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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // Class include |
|
20 #include <DevEncSession.h> |
|
21 |
|
22 // User includes |
|
23 //#include "DevEncDiskUtils.h" |
|
24 #include "DevEncLog.h" |
|
25 #include "DevEncProtectedPSKey.h" |
|
26 |
|
27 // System includes |
|
28 #include <DevEncEngineBase.h> |
|
29 #include <DevEncEngineConstants.h> |
|
30 #include <e32property.h> |
|
31 |
|
32 #include <centralrepository.h> |
|
33 #include <DevEncExternalCRKeys.h> |
|
34 |
|
35 EXPORT_C CDevEncSessionBase* NewSessionL() |
|
36 { |
|
37 return new (ELeave) CDevEncSession; |
|
38 } |
|
39 |
|
40 // -------------------------------------------------------------------------- |
|
41 // CDevEncSession::CDevEncSession() |
|
42 // |
|
43 // -------------------------------------------------------------------------- |
|
44 EXPORT_C CDevEncSession::CDevEncSession(): |
|
45 iDriveNumber( EDriveC ) |
|
46 { |
|
47 |
|
48 } |
|
49 |
|
50 EXPORT_C CDevEncSession::CDevEncSession( TDriveNumber aNumber ): |
|
51 iConnected (EFalse), iDriveNumber( aNumber ), iDevEncEngine (NULL) |
|
52 { |
|
53 // Derived from CBase -> members zeroed. |
|
54 } |
|
55 |
|
56 // -------------------------------------------------------------------------- |
|
57 // CDevEncSession::~CDevEncSession() |
|
58 // |
|
59 // -------------------------------------------------------------------------- |
|
60 CDevEncSession::~CDevEncSession() |
|
61 { |
|
62 if (iConnected) |
|
63 UnloadDevEncEngine(); |
|
64 } |
|
65 |
|
66 // -------------------------------------------------------------------------- |
|
67 // CDevEncSession::Close() |
|
68 // |
|
69 // -------------------------------------------------------------------------- |
|
70 EXPORT_C void CDevEncSession::Close() |
|
71 { |
|
72 UnloadDevEncEngine(); |
|
73 iConnected = EFalse; |
|
74 } |
|
75 |
|
76 // -------------------------------------------------------------------------- |
|
77 // CDevEncSession::Connect() |
|
78 // |
|
79 // -------------------------------------------------------------------------- |
|
80 EXPORT_C TInt CDevEncSession::Connect() |
|
81 { |
|
82 TRAPD(err,LoadDevEncEngineL()); |
|
83 return err; |
|
84 } |
|
85 |
|
86 // -------------------------------------------------------------------------- |
|
87 // CDevEncSession::StartDiskEncrypt() |
|
88 // |
|
89 // -------------------------------------------------------------------------- |
|
90 EXPORT_C TInt CDevEncSession::StartDiskEncrypt() |
|
91 { |
|
92 FLOG("CDevEncSession::StartDiskEncrypt >>"); |
|
93 |
|
94 ASSERT( iConnected ); |
|
95 |
|
96 TInt err = KErrNone; |
|
97 TInt diskStatus = 0; |
|
98 |
|
99 err = DiskStatus( diskStatus ); |
|
100 |
|
101 if( err ) |
|
102 { |
|
103 DFLOG2( "ERROR: Disk status query failed, err %d", err); |
|
104 } |
|
105 else if( EDecrypted == diskStatus ) |
|
106 { |
|
107 DFLOG( "Starting encryption" ); |
|
108 err = iDevEncEngine->StartDiskOperation( EEncryptDisk ); |
|
109 } |
|
110 else |
|
111 { |
|
112 DFLOG2( "Encryption not possible, disk status %d", diskStatus); |
|
113 err = KErrNotReady; |
|
114 } |
|
115 FLOG2("CDevEncSession::StartDiskEncrypt, err = %d <<", err); |
|
116 return err; |
|
117 } |
|
118 |
|
119 // -------------------------------------------------------------------------- |
|
120 // CDevEncSession::StartDiskDecrypt() |
|
121 // |
|
122 // -------------------------------------------------------------------------- |
|
123 EXPORT_C TInt CDevEncSession::StartDiskDecrypt() |
|
124 { |
|
125 ASSERT( iConnected ); |
|
126 |
|
127 TInt err = KErrNone; |
|
128 TInt diskStatus = 0; |
|
129 |
|
130 err = DiskStatus( diskStatus ); |
|
131 |
|
132 if( err ) |
|
133 { |
|
134 DFLOG2( "ERROR: Disk status query failed, err %d", err); |
|
135 } |
|
136 else if( EEncrypted == diskStatus ) |
|
137 { |
|
138 DFLOG( "Starting decryption" ); |
|
139 err = iDevEncEngine->StartDiskOperation( EDecryptDisk ); |
|
140 } |
|
141 else |
|
142 { |
|
143 DFLOG2( "Encryption not possible, disk status %d", diskStatus); |
|
144 err = KErrNotReady; |
|
145 } |
|
146 |
|
147 return err; |
|
148 } |
|
149 |
|
150 // -------------------------------------------------------------------------- |
|
151 // CDevEncSession::StartDiskWipe() |
|
152 // |
|
153 // -------------------------------------------------------------------------- |
|
154 EXPORT_C TInt CDevEncSession::StartDiskWipe() |
|
155 { |
|
156 ASSERT( iConnected ); |
|
157 |
|
158 DFLOG( "Starting wiping" ); |
|
159 TInt err = iDevEncEngine->StartDiskOperation( EWipeDisk ); |
|
160 |
|
161 return err; |
|
162 } |
|
163 |
|
164 // -------------------------------------------------------------------------- |
|
165 // CDevEncSession::DiskStatus() |
|
166 // |
|
167 // -------------------------------------------------------------------------- |
|
168 EXPORT_C TInt CDevEncSession::DiskStatus( TInt& aStatus ) const |
|
169 { |
|
170 ASSERT( iConnected ); |
|
171 TInt err = iDevEncEngine->DiskStatus(aStatus); |
|
172 return err; |
|
173 } |
|
174 |
|
175 // -------------------------------------------------------------------------- |
|
176 // CDevEncSession::Progress() |
|
177 // |
|
178 // -------------------------------------------------------------------------- |
|
179 EXPORT_C TInt CDevEncSession::Progress( TInt& aProgress ) const |
|
180 { |
|
181 ASSERT( iConnected ); |
|
182 // Progress status must be polled, because after the extension has stopped |
|
183 // updating the status there will be no new progress updates --> will wait |
|
184 // indefinitely. |
|
185 TInt err = iDevEncEngine->Progress(aProgress); |
|
186 |
|
187 return err; |
|
188 } |
|
189 |
|
190 // -------------------------------------------------------------------------- |
|
191 // CDevEncSession::Connected() |
|
192 // |
|
193 // -------------------------------------------------------------------------- |
|
194 EXPORT_C TBool CDevEncSession::Connected() const |
|
195 { |
|
196 return iConnected; |
|
197 } |
|
198 |
|
199 // -------------------------------------------------------------------------- |
|
200 // CDevEncSession::DriveNumber() |
|
201 // |
|
202 // -------------------------------------------------------------------------- |
|
203 EXPORT_C TDriveNumber CDevEncSession::DriveNumber() const |
|
204 { |
|
205 return iDriveNumber; |
|
206 } |
|
207 |
|
208 // -------------------------------------------------------------------------- |
|
209 // CDevEncSession::SetDrive() |
|
210 // |
|
211 // -------------------------------------------------------------------------- |
|
212 EXPORT_C void CDevEncSession::SetDrive( TDriveNumber aNumber ) |
|
213 { |
|
214 iDriveNumber = aNumber; |
|
215 } |
|
216 |
|
217 void CDevEncSession::LoadDevEncEngineL() |
|
218 { |
|
219 FLOG(" CDevEncSession::LoadDevEncEngineL >> "); |
|
220 |
|
221 if (!iDevEncEngine) |
|
222 { |
|
223 TInt err = iLibrary.Load(KEncryptionDll); |
|
224 if (err != KErrNone) |
|
225 { |
|
226 FLOG2("Error in finding the library... %d", err); |
|
227 if (err == KErrNotFound) |
|
228 err = KErrNotSupported; |
|
229 User::Leave(err); |
|
230 } |
|
231 TLibraryFunction entry = iLibrary.Lookup(1); |
|
232 |
|
233 if (!entry) |
|
234 { |
|
235 FLOG("Error in loading the library..."); |
|
236 User::Leave(KErrBadLibraryEntryPoint); |
|
237 } |
|
238 iDevEncEngine = (CDevEncEngineBase *) entry(); |
|
239 TInt errconnection = iDevEncEngine->Connect(iDriveNumber); |
|
240 if( errconnection != KErrNone ) |
|
241 { |
|
242 User::Leave(errconnection); |
|
243 } |
|
244 iConnected = ETrue; |
|
245 } |
|
246 FLOG(" CDevEncSession::LoadDevEncEngineL << "); |
|
247 } |
|
248 |
|
249 void CDevEncSession::UnloadDevEncEngine() |
|
250 { |
|
251 FLOG(" CDevEncSession::UnloadDevEncEngineL >> "); |
|
252 |
|
253 if (iDevEncEngine) |
|
254 { |
|
255 iDevEncEngine->Close(); |
|
256 delete iDevEncEngine; |
|
257 iDevEncEngine = NULL; |
|
258 iLibrary.Close(); |
|
259 } |
|
260 iConnected = EFalse; |
|
261 |
|
262 FLOG(" CDevEncSession::UnloadDevEncEngineL << "); |
|
263 } |
|
264 |
|
265 EXPORT_C TInt CDevEncSession::SetDevEncControlL(TInt aValue) |
|
266 { |
|
267 DFLOG2("CDevEncSession SetDevEncControl, value = %d >>", aValue); |
|
268 |
|
269 CRepository* rep = CRepository::NewLC(TUid::Uid(KCRDevEncUiSettings)); |
|
270 TInt err = rep->Set(KDevEncUiDmControl, aValue); |
|
271 CleanupStack::PopAndDestroy(rep); |
|
272 |
|
273 DFLOG2("CDevEncSession SetDevEncControl, err = %d <<", err); |
|
274 return err; |
|
275 } |
|
276 |
|
277 EXPORT_C TInt CDevEncSession::GetDevEncControlL(TInt& aValue) |
|
278 { |
|
279 DFLOG("CDevEncSession GetDevEncControl >>"); |
|
280 |
|
281 CRepository* rep = CRepository::NewLC(TUid::Uid(KCRDevEncUiSettings)); |
|
282 TInt err = rep->Get(KDevEncUiDmControl, aValue); |
|
283 CleanupStack::PopAndDestroy(rep); |
|
284 |
|
285 DFLOG2("CDevEncSession GetDevEncControl, err = %d <<", err); |
|
286 return err; |
|
287 } |
|
288 // End of file |