123
|
1 |
// Copyright (c) 1995-2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
2 |
// All rights reserved.
|
|
3 |
// This component and the accompanying materials are made available
|
|
4 |
// under the terms of the License "Eclipse Public License v1.0"
|
|
5 |
// which accompanies this distribution, and is available
|
|
6 |
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
7 |
//
|
|
8 |
// Initial Contributors:
|
|
9 |
// Nokia Corporation - initial contribution.
|
|
10 |
//
|
|
11 |
// Contributors:
|
|
12 |
//
|
|
13 |
// Description:
|
|
14 |
// e32test\mediext\t_nfe.cpp
|
|
15 |
//
|
|
16 |
//
|
|
17 |
|
|
18 |
#define __E32TEST_EXTENSION__
|
|
19 |
|
|
20 |
#include <e32test.h>
|
|
21 |
#include <f32file.h>
|
|
22 |
|
|
23 |
|
|
24 |
RTest test(_L("t_nfe"));
|
|
25 |
|
|
26 |
#include <d32locd.h>
|
|
27 |
#include <e32property.h>
|
|
28 |
#include "nfe.h"
|
|
29 |
|
|
30 |
|
|
31 |
TBusLocalDrive Drive;
|
|
32 |
TBool TheWaitFlag = EFalse; // wait for drive to be encrypted before exiting test
|
|
33 |
TBool TheFinaliseDriveFlag = EFalse;
|
|
34 |
TBool TheDisplayStatusFlag = EFalse; // display drive status and then exit (i.e. don't encrypt)
|
|
35 |
TBool TheEncryptDriveFlag = ETrue;
|
|
36 |
|
|
37 |
TInt FindNfeDrive(TInt aDriveNum)
|
|
38 |
/**
|
|
39 |
Find the next NFE drive
|
|
40 |
|
|
41 |
@return Local drive identifier.
|
|
42 |
*/
|
|
43 |
{
|
|
44 |
TInt drive = KErrNotFound;
|
|
45 |
|
|
46 |
// test.Printf(_L("Searching for NFE drive:\n"));
|
|
47 |
|
|
48 |
for (TInt i = aDriveNum; i < KMaxLocalDrives && drive < 0; ++i)
|
|
49 |
{
|
|
50 |
RLocalDrive d;
|
|
51 |
TBool change = EFalse;
|
|
52 |
|
|
53 |
if(d.Connect(i, change) == KErrNone)
|
|
54 |
{
|
|
55 |
// test.Printf(_L("Connected to local drive %d\n"), i);
|
|
56 |
TLocalDriveCapsV4 dc;
|
|
57 |
TPckg<TLocalDriveCapsV4> capsPack(dc);
|
|
58 |
capsPack.FillZ();
|
|
59 |
|
|
60 |
if(d.Caps(capsPack) != KErrNone)
|
|
61 |
continue;
|
|
62 |
if (dc.iType == EMediaNANDFlash || dc.iType == EMediaHardDisk)
|
|
63 |
{
|
|
64 |
TNfeDeviceInfo nfeDeviceInfo;
|
|
65 |
TPtr8 nfeDeviceInfoBuf((TUint8*) &nfeDeviceInfo, sizeof(nfeDeviceInfo));
|
|
66 |
nfeDeviceInfoBuf.FillZ();
|
|
67 |
|
|
68 |
TInt r = d.QueryDevice((RLocalDrive::TQueryDevice) EQueryNfeDeviceInfo, nfeDeviceInfoBuf);
|
|
69 |
|
|
70 |
// test.Printf(_L("EQueryNfeDeviceInfo on local drive %d returned %d\n"), i, r);
|
|
71 |
if (r == KErrNone)
|
|
72 |
{
|
|
73 |
test.Printf(_L("\nFound NFE on local drive %d\n"), i);
|
|
74 |
drive = i;
|
|
75 |
}
|
|
76 |
}
|
|
77 |
d.Close();
|
|
78 |
}
|
|
79 |
}
|
|
80 |
return drive;
|
|
81 |
}
|
|
82 |
|
|
83 |
|
|
84 |
|
|
85 |
const TDesC* DriveStatus(TNfeDiskStatus aStatus)
|
|
86 |
{
|
|
87 |
_LIT(KNfeUnmounted, "Unmounted");
|
|
88 |
_LIT(KNfeDecrypted, "Decrypted");
|
|
89 |
_LIT(KNfeDecrypting, "Decrypting");
|
|
90 |
_LIT(KNfeEncrypted, "Encrypted");
|
|
91 |
_LIT(KNfeEncrypting, "Encrypting");
|
|
92 |
_LIT(KNfeWiping, "Wiping");
|
|
93 |
_LIT(KNfeCorrupted, "Corrupted");
|
|
94 |
_LIT(KNfeUnrecognised, "Unrecognised");
|
|
95 |
|
|
96 |
switch(aStatus)
|
|
97 |
{
|
|
98 |
case ENfeUnmounted:
|
|
99 |
return &KNfeUnmounted;
|
|
100 |
case ENfeDecrypted:
|
|
101 |
return &KNfeDecrypted;
|
|
102 |
case ENfeDecrypting:
|
|
103 |
return &KNfeDecrypting;
|
|
104 |
case ENfeEncrypted:
|
|
105 |
return &KNfeEncrypted;
|
|
106 |
case ENfeEncrypting:
|
|
107 |
return &KNfeEncrypting;
|
|
108 |
case ENfeWiping:
|
|
109 |
return &KNfeWiping;
|
|
110 |
case ENfeCorrupted:
|
|
111 |
return &KNfeCorrupted;
|
|
112 |
default:
|
|
113 |
return &KNfeUnrecognised;
|
|
114 |
|
|
115 |
}
|
|
116 |
}
|
|
117 |
|
|
118 |
TInt DriveStatus(TInt aNfeDrive, TNfeDiskStatus& aStatus, TInt &aProgress)
|
|
119 |
{
|
|
120 |
TInt r = RProperty::Get(
|
|
121 |
KNfeUID,
|
|
122 |
NFE_KEY(aNfeDrive, KNfeStatusToUiKey),
|
|
123 |
*(TInt*) &aStatus);
|
|
124 |
if (r != KErrNone)
|
|
125 |
return r;
|
|
126 |
r = RProperty::Get(
|
|
127 |
KNfeUID,
|
|
128 |
NFE_KEY(aNfeDrive, KNfeProgressToUiKey),
|
|
129 |
*(TInt*) &aProgress);
|
|
130 |
return r;
|
|
131 |
}
|
|
132 |
|
|
133 |
void DisplayNfeDeviceInfo(TInt aNfeDrive, TNfeDeviceInfo& aDeviceInfo)
|
|
134 |
{
|
|
135 |
test.Printf(_L("Stats: \n"));
|
|
136 |
|
|
137 |
RLocalDrive d;
|
|
138 |
TBool change = EFalse;
|
|
139 |
TInt r = d.Connect(aNfeDrive, change);
|
|
140 |
test (r == KErrNone);
|
|
141 |
|
|
142 |
TPtr8 nfeDeviceInfoBuf((TUint8*) &aDeviceInfo, sizeof(aDeviceInfo));
|
|
143 |
nfeDeviceInfoBuf.FillZ();
|
|
144 |
r = d.QueryDevice((RLocalDrive::TQueryDevice) EQueryNfeDeviceInfo, nfeDeviceInfoBuf);
|
|
145 |
test (r == KErrNone || r == KErrNotSupported);
|
|
146 |
|
|
147 |
d.Close();
|
|
148 |
|
|
149 |
test.Printf(_L("iDriveCount %d\n"), aDeviceInfo.iDriveCount);
|
|
150 |
test.Printf(_L("iMediaSizeInBytes %lx\n"), aDeviceInfo.iMediaSizeInBytes);
|
|
151 |
|
|
152 |
for (TInt i=0; i<aDeviceInfo.iDriveCount; i++)
|
|
153 |
{
|
|
154 |
TNfeDriveInfo& di = aDeviceInfo.iDrives[i];
|
|
155 |
|
|
156 |
test.Printf(_L("*** drive index %d ***\n"), i);
|
|
157 |
test.Printf(_L("iLocalDriveNum %x\n"), di.iLocalDriveNum);
|
|
158 |
test.Printf(_L("iDriveLetter %c\n"), di.iDriveLetter >= 0 && di.iDriveLetter <= 25 ? di.iDriveLetter +'A' : '?');
|
|
159 |
test.Printf(_L("iState %d\n"), di.Status());
|
|
160 |
|
|
161 |
test.Printf(_L("State = %S\n"), DriveStatus(di.Status()));
|
|
162 |
|
|
163 |
test.Printf(_L("iEncryptStartPos %lx\n"), di.iEncryptStartPos);
|
|
164 |
test.Printf(_L("iEncryptEndPos %lx\n"), di.iEncryptEndPos);
|
|
165 |
test.Printf(_L("iPartitionBaseAddr %lx\n"), di.iEntry.iPartitionBaseAddr);
|
|
166 |
test.Printf(_L("iPartitionLen %lx\n"), di.iEntry.iPartitionLen);
|
|
167 |
test.Printf(_L("iPartitionType %x\n"), di.iEntry.iPartitionType);
|
|
168 |
|
|
169 |
test.Printf(_L("iReadRequestCount %d\n"), di.iReadRequestCount);
|
|
170 |
test.Printf(_L("iWriteRequestCount %d\n"), di.iWriteRequestCount);
|
|
171 |
test.Printf(_L("iCodePagingRequesCount %d\n"), di.iCodePagingRequesCount);
|
|
172 |
test.Printf(_L("iDataPagingReadRequestCount %d\n"), di.iDataPagingReadRequestCount);
|
|
173 |
test.Printf(_L("iDataPagingWriteRequestCount %d\n"), di.iDataPagingWriteRequestCount);
|
|
174 |
test.Printf(_L("iUniqueID %08X\n"), di.iUniqueID);
|
|
175 |
}
|
|
176 |
}
|
|
177 |
|
|
178 |
void EncryptDrive(TInt aNfeDrive)
|
|
179 |
{
|
|
180 |
// subscribe to cmd acknowledgement property - KNfeToUiKey
|
|
181 |
RProperty propToUi;
|
|
182 |
test.Printf(_L("Attaching ToUi property"));
|
|
183 |
TInt r = propToUi.Attach(KNfeUID,NFE_KEY(aNfeDrive,KNfeToUiKey));
|
|
184 |
test.Printf(_L("Attaching returned %d"), r);
|
|
185 |
if (r != KErrNone)
|
|
186 |
return;
|
|
187 |
|
|
188 |
|
|
189 |
TRequestStatus status;
|
|
190 |
propToUi.Subscribe( status );
|
|
191 |
|
|
192 |
|
|
193 |
// Issue command
|
|
194 |
test.Printf(_L("Encrypting drive %c...\n"), aNfeDrive+'A');
|
|
195 |
r = RProperty::Set(
|
|
196 |
KNfeUID,
|
|
197 |
NFE_KEY(aNfeDrive, KNfeToThreadKey),
|
|
198 |
ENfeEncryptDisk);
|
|
199 |
test.Printf(_L("Encrypting drive %c, r %d\n"), aNfeDrive+'A', r);
|
|
200 |
test (r == KErrNone);
|
|
201 |
|
|
202 |
// wait for ack
|
|
203 |
User::WaitForRequest( status );
|
|
204 |
r = status.Int();
|
|
205 |
test.Printf(_L("cmd status %d"), r);
|
|
206 |
test (r == KErrNone);
|
|
207 |
}
|
|
208 |
|
|
209 |
void DecryptDrive(TInt aNfeDrive)
|
|
210 |
{
|
|
211 |
// subscribe to cmd acknowledgement property - KNfeToUiKey
|
|
212 |
RProperty propToUi;
|
|
213 |
test.Printf(_L("Attaching ToUi property"));
|
|
214 |
TInt r = propToUi.Attach(KNfeUID,NFE_KEY(aNfeDrive,KNfeToUiKey));
|
|
215 |
test.Printf(_L("Attaching returned %d"), r);
|
|
216 |
if (r != KErrNone)
|
|
217 |
return;
|
|
218 |
|
|
219 |
|
|
220 |
TRequestStatus status;
|
|
221 |
propToUi.Subscribe( status );
|
|
222 |
|
|
223 |
|
|
224 |
// Issue command
|
|
225 |
test.Printf(_L("Decrypting drive %c...\n"), aNfeDrive+'A');
|
|
226 |
r = RProperty::Set(
|
|
227 |
KNfeUID,
|
|
228 |
NFE_KEY(aNfeDrive, KNfeToThreadKey),
|
|
229 |
ENfeDecryptDisk);
|
|
230 |
test.Printf(_L("Decrypting drive %c, r %d\n"), aNfeDrive+'A', r);
|
|
231 |
test (r == KErrNone);
|
|
232 |
|
|
233 |
// wait for ack
|
|
234 |
User::WaitForRequest( status );
|
|
235 |
r = status.Int();
|
|
236 |
test.Printf(_L("cmd status %d"), r);
|
|
237 |
test (r == KErrNone);
|
|
238 |
}
|
|
239 |
|
|
240 |
void WaitForFinish(TInt aNfeDrive, TBool aEncrypt)
|
|
241 |
{
|
|
242 |
TNfeDiskStatus diskStatus = ENfeCorrupted;
|
|
243 |
TInt progress = 0;
|
|
244 |
|
|
245 |
TInt r = DriveStatus(aNfeDrive, diskStatus, progress);
|
|
246 |
test (r == KErrNone);
|
|
247 |
|
|
248 |
// Poll progress status.
|
|
249 |
while (diskStatus != (aEncrypt ? ENfeEncrypted : ENfeDecrypted ))
|
|
250 |
{
|
|
251 |
r = DriveStatus(aNfeDrive, diskStatus, progress);
|
|
252 |
test (r == KErrNone);
|
|
253 |
test.Printf(_L("Drive %c, r %d progress %3u%% status %S\n"), aNfeDrive+'A', r, progress, DriveStatus((TNfeDiskStatus) diskStatus));
|
|
254 |
|
|
255 |
|
|
256 |
if (TheFinaliseDriveFlag && progress > 10)
|
|
257 |
{
|
|
258 |
TheFinaliseDriveFlag = EFalse;
|
|
259 |
RFs fs;
|
|
260 |
TInt r = fs.Connect();
|
|
261 |
test_KErrNone(r);
|
|
262 |
|
|
263 |
r = fs.FinaliseDrive(aNfeDrive, RFs::EFinal_RW);
|
|
264 |
test_KErrNone(r);
|
|
265 |
return;
|
|
266 |
}
|
|
267 |
|
|
268 |
User::After( 1000 * 500 );
|
|
269 |
}
|
|
270 |
test.Printf( _L("\nFinished\n") );
|
|
271 |
}
|
|
272 |
|
|
273 |
//
|
|
274 |
// E32Main
|
|
275 |
//
|
|
276 |
|
|
277 |
TInt ParseCommandArguments()
|
|
278 |
{
|
|
279 |
TInt tokenCount = 0;
|
|
280 |
TChar driveToTest = 'C';;
|
|
281 |
|
|
282 |
TBuf<0x100> cmd;
|
|
283 |
User::CommandLine(cmd);
|
|
284 |
TLex lex(cmd);
|
|
285 |
|
|
286 |
for (TPtrC token=lex.NextToken(); token.Length() != 0;token.Set(lex.NextToken()))
|
|
287 |
{
|
|
288 |
tokenCount++;
|
|
289 |
// Get the drive letter
|
|
290 |
if (tokenCount == 1)
|
|
291 |
{
|
|
292 |
TChar ch = token[0];
|
|
293 |
if (ch.IsAlpha())
|
|
294 |
{
|
|
295 |
if(token.Length() > 0)
|
|
296 |
{
|
|
297 |
driveToTest=token[0];
|
|
298 |
driveToTest.UpperCase();
|
|
299 |
}
|
|
300 |
}
|
|
301 |
RDebug::Print(_L("drive=%C"), (TUint) driveToTest);
|
|
302 |
continue;
|
|
303 |
}
|
|
304 |
|
|
305 |
else if (token.CompareF(_L("-d")) == 0)
|
|
306 |
{
|
|
307 |
TheEncryptDriveFlag = EFalse;
|
|
308 |
}
|
|
309 |
else if (token.CompareF(_L("-e")) == 0)
|
|
310 |
{
|
|
311 |
TheEncryptDriveFlag = ETrue;
|
|
312 |
}
|
|
313 |
else if (token.CompareF(_L("-f")) == 0)
|
|
314 |
{
|
|
315 |
TheFinaliseDriveFlag = ETrue;
|
|
316 |
}
|
|
317 |
else if (token.CompareF(_L("-w")) == 0)
|
|
318 |
{
|
|
319 |
TheWaitFlag = ETrue;
|
|
320 |
}
|
|
321 |
else if (token.CompareF(_L("-s")) == 0)
|
|
322 |
{
|
|
323 |
TheDisplayStatusFlag = ETrue;
|
|
324 |
}
|
|
325 |
}
|
|
326 |
|
|
327 |
return driveToTest;
|
|
328 |
}
|
|
329 |
|
|
330 |
TInt E32Main()
|
|
331 |
{
|
|
332 |
test.Title();
|
|
333 |
test.Start(_L("NFE tests"));
|
|
334 |
|
|
335 |
RFs fs;
|
|
336 |
|
|
337 |
TInt r = fs.Connect();
|
|
338 |
test_KErrNone(r);
|
|
339 |
|
|
340 |
TChar driveToTest = ParseCommandArguments();
|
|
341 |
|
|
342 |
TInt drive;
|
|
343 |
r = fs.CharToDrive(driveToTest,drive);
|
|
344 |
test_KErrNone(r);
|
|
345 |
|
|
346 |
|
|
347 |
TVolumeInfo volumeInfo;
|
|
348 |
r = fs.Volume(volumeInfo, drive);
|
|
349 |
test(r == KErrNone);
|
|
350 |
|
|
351 |
|
|
352 |
|
|
353 |
TNfeDiskStatus diskStatus = ENfeCorrupted;
|
|
354 |
TInt progress = 0;
|
|
355 |
|
|
356 |
r = DriveStatus(drive, diskStatus, progress);
|
|
357 |
test.Printf(_L("drive %c diskStatus %S, progress %d r %d\n"), drive+'A', DriveStatus(diskStatus), progress, r);
|
|
358 |
|
|
359 |
if (TheDisplayStatusFlag)
|
|
360 |
{
|
|
361 |
test.Printf(_L("*** press any key ***"));
|
|
362 |
test.Getch();
|
|
363 |
test.End();
|
|
364 |
test.Close();
|
|
365 |
return 0;
|
|
366 |
}
|
|
367 |
|
|
368 |
if (r == KErrNone && diskStatus == ENfeDecrypted && TheEncryptDriveFlag)
|
|
369 |
{
|
|
370 |
test.Next(_L("Encrypting NFE drive"));
|
|
371 |
EncryptDrive(drive);
|
|
372 |
r = DriveStatus(drive, diskStatus, progress);
|
|
373 |
test.Printf(_L("drive %c diskStatus %S, progress %d r %d\n"), drive+'A', DriveStatus(diskStatus), progress, r);
|
|
374 |
}
|
|
375 |
|
|
376 |
if (r == KErrNone && diskStatus == ENfeEncrypted && !TheEncryptDriveFlag)
|
|
377 |
{
|
|
378 |
test.Next(_L("Decrypting NFE drive"));
|
|
379 |
DecryptDrive(drive);
|
|
380 |
r = DriveStatus(drive, diskStatus, progress);
|
|
381 |
test.Printf(_L("drive %c diskStatus %S, progress %d r %d\n"), drive+'A', DriveStatus(diskStatus), progress, r);
|
|
382 |
}
|
|
383 |
|
|
384 |
|
|
385 |
if (r == KErrNone && TheWaitFlag)
|
|
386 |
{
|
|
387 |
test.Next(_L("Waiting for finish"));
|
|
388 |
WaitForFinish(drive, TheEncryptDriveFlag);
|
|
389 |
}
|
|
390 |
|
|
391 |
|
|
392 |
for(TInt nfeDrive = FindNfeDrive(0); nfeDrive != KErrNotFound; nfeDrive = FindNfeDrive(++nfeDrive))
|
|
393 |
{
|
|
394 |
TNfeDeviceInfo deviceInfo;
|
|
395 |
DisplayNfeDeviceInfo(nfeDrive, deviceInfo);
|
|
396 |
}
|
|
397 |
|
|
398 |
fs.Close();
|
|
399 |
|
|
400 |
test.End();
|
|
401 |
test.Close();
|
|
402 |
|
|
403 |
return 0;
|
|
404 |
}
|
|
405 |
|
|
406 |
|