author | Mike Kinghan <mikek@symbian.org> |
Mon, 19 Jul 2010 08:40:05 +0100 | |
branch | GCC_SURGE |
changeset 209 | 6035754ebf88 |
parent 109 | b3a1d9898418 |
child 244 | a77889bee936 |
permissions | -rw-r--r-- |
0 | 1 |
// Copyright (c) 1998-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 |
// f32test\server\t_pwstr.cpp |
|
15 |
// Tests peripheral bus controller password store. |
|
16 |
// |
|
17 |
// |
|
18 |
||
19 |
//#include <p32mmc.h> |
|
20 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
21 |
#define __E32TEST_EXTENSION__ |
0 | 22 |
#include <e32test.h> |
23 |
#include <f32fsys.h> |
|
24 |
#include <e32def.h> |
|
25 |
#include <e32def_private.h> |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
26 |
#include <e32hal.h> |
0 | 27 |
|
28 |
// define this macro to autodetect card re-insertion |
|
29 |
#define __AUTO_DETECT_MEDIA_CHANGE__ |
|
30 |
||
31 |
const TUint KMMCCIDLength=16; |
|
32 |
||
33 |
class TCID |
|
34 |
{ |
|
35 |
public: |
|
36 |
inline TCID() {} // Default constructor |
|
37 |
inline TCID(const TUint8*); |
|
38 |
inline TCID& operator=(const TCID&); |
|
39 |
inline TCID& operator=(const TUint8*); |
|
40 |
inline TBool operator==(const TCID&) const; |
|
41 |
inline TBool operator==(const TUint8*) const; |
|
42 |
inline void Copy(TUint8*) const; // Copies big endian 16 bytes CID |
|
43 |
inline TUint8 At(TUint anIndex) const; // Byte from CID at anIndex |
|
44 |
//private: |
|
45 |
public: |
|
46 |
TUint8 iData[KMMCCIDLength]; // Big endian 128 bit bitfield representing CID |
|
47 |
}; |
|
48 |
||
49 |
class TMMC |
|
50 |
{ |
|
51 |
public: |
|
52 |
static inline TUint32 BigEndian32(const TUint8*); |
|
53 |
static inline void BigEndian4Bytes(TUint8* aPtr, TUint32 aVal); |
|
54 |
}; |
|
55 |
||
56 |
||
57 |
// -------- class TCID -------- |
|
58 |
||
59 |
inline TCID::TCID(const TUint8* aPtr) |
|
60 |
{memcpy(&iData[0], aPtr, KMMCCIDLength);} |
|
61 |
||
62 |
inline TCID& TCID::operator=(const TCID& aCID) |
|
63 |
{memcpy(&iData[0], &aCID.iData[0], KMMCCIDLength); return(*this);} |
|
64 |
||
65 |
inline TCID& TCID::operator=(const TUint8* aPtr) |
|
66 |
{memcpy(&iData[0], aPtr, KMMCCIDLength); return(*this);} |
|
67 |
||
68 |
inline TBool TCID::operator==(const TCID& aCID) const |
|
69 |
{return(memcompare(&iData[0],KMMCCIDLength,&aCID.iData[0],KMMCCIDLength)==0);} |
|
70 |
||
71 |
inline TBool TCID::operator==(const TUint8* aPtr) const |
|
72 |
{return(memcompare(&iData[0],KMMCCIDLength,aPtr,KMMCCIDLength)==0);} |
|
73 |
||
74 |
inline void TCID::Copy(TUint8* aPtr) const |
|
75 |
{memcpy(aPtr, &iData[0], KMMCCIDLength);} |
|
76 |
||
77 |
inline TUint8 TCID::At(TUint anIndex) const |
|
78 |
{return(iData[KMMCCIDLength-1-anIndex]);} |
|
79 |
||
80 |
||
81 |
inline TUint32 TMMC::BigEndian32(const TUint8* aPtr) |
|
82 |
{return( (aPtr[0]<<24) | (aPtr[1]<<16) | (aPtr[2]<<8) | (aPtr[3]) );} |
|
83 |
||
84 |
inline void TMMC::BigEndian4Bytes(TUint8* aPtr, TUint32 aVal) |
|
85 |
{ |
|
86 |
aPtr[0] = (TUint8)((aVal >> 24) & 0xFF); |
|
87 |
aPtr[1] = (TUint8)((aVal >> 16) & 0xFF); |
|
88 |
aPtr[2] = (TUint8)((aVal >> 8) & 0xFF); |
|
89 |
aPtr[3] = (TUint8)(aVal & 0xFF); |
|
90 |
} |
|
91 |
||
92 |
// Static data. |
|
93 |
||
94 |
LOCAL_D RTest test(_L("T_PWSTR")); |
|
95 |
||
96 |
LOCAL_D TBusLocalDrive TBLD; |
|
97 |
LOCAL_D TBool TBLDChangedFlag; |
|
98 |
||
99 |
LOCAL_D TInt TBLDNum = -1; // Change this to specify the drive under test |
|
100 |
// e.g. for the lm_pana board when fitted to the |
|
101 |
// integrator, TBLDNum should be set to 3. |
|
102 |
||
103 |
LOCAL_D TInt RFsDNum = -1; // File Server Drive number |
|
104 |
||
105 |
struct TTestMapping |
|
106 |
{ |
|
107 |
TInt iCIDIdx; // index in CID |
|
108 |
TInt iPWDIdx; // index in PWD |
|
109 |
}; |
|
110 |
||
111 |
const TInt KMaxLengthOfStoreMapping = KMMCCIDLength + sizeof(TInt32) + KMaxMediaPassword; |
|
112 |
// EMaxPasswordLength is max size of the password store descriptor |
|
113 |
// (which actually contains multiple mappings of CID and passwords) |
|
114 |
const TInt KMaxNumOfStoreEntries= TPasswordStore::EMaxPasswordLength/KMaxLengthOfStoreMapping; |
|
115 |
||
116 |
const TInt KPWDCnt(4); |
|
117 |
LOCAL_C TMediaPassword *PWDs[KPWDCnt]; |
|
118 |
||
119 |
//Allocate enough unique CIDs to be able to overflow the store |
|
120 |
const TInt KCIDCnt(KMaxNumOfStoreEntries+1); |
|
121 |
LOCAL_C TCID *CIDs[KCIDCnt]; |
|
122 |
||
123 |
//Let the descriptor be one mapping longer than allowed by the password |
|
124 |
//store to test overflowing it. |
|
125 |
const TInt KMaxPersistentStore(TPasswordStore::EMaxPasswordLength+KMaxLengthOfStoreMapping); |
|
126 |
typedef TBuf8<KMaxPersistentStore> TPersistentStore; |
|
127 |
LOCAL_C TInt mapSizes[KCIDCnt][KPWDCnt]; |
|
128 |
||
129 |
// Static function prototypes. |
|
130 |
||
131 |
LOCAL_C void AllocateTestData(); |
|
132 |
LOCAL_C void DeleteTestData(); |
|
133 |
||
134 |
LOCAL_C void AllocateCIDs(); |
|
135 |
LOCAL_C void DeleteCIDs(); |
|
136 |
||
137 |
LOCAL_C void AllocatePasswords(); |
|
138 |
LOCAL_C void DeletePasswords(); |
|
139 |
||
140 |
LOCAL_C void SetUpMapSizes(); |
|
141 |
||
142 |
LOCAL_C void AddMapping(TDes8 &aSt, const TCID *aCID, const TMediaPassword *aPWD); |
|
143 |
LOCAL_C void DumpStore(const TDesC &aName, const TDesC8 &aSt); |
|
144 |
LOCAL_C TBool StoresEqual(const TDesC8 &aSt0, const TDesC8 &aSt1); |
|
145 |
LOCAL_C TBool IsStoreValid(const TDesC8 &aSt); |
|
146 |
LOCAL_C void PrintCID(const TCID &aCID); |
|
147 |
LOCAL_C void ParseStore(const TDesC8 &aStore, CArrayFixSeg<TTestMapping> *aMP); |
|
148 |
LOCAL_C void TestStaticStore(); |
|
149 |
||
150 |
LOCAL_C void RemountMedia(); |
|
151 |
LOCAL_C void AttemptToUnlock(TMediaPassword &aPWD, TBool aStore = EFalse); |
|
152 |
LOCAL_C void TestLockUnlock(); |
|
153 |
LOCAL_C void TestElidePasswords(); |
|
154 |
LOCAL_C void TestNullPasswords(); |
|
155 |
LOCAL_C void TestControllerStore(); |
|
156 |
||
157 |
LOCAL_C TInt AccessDisk(); |
|
158 |
LOCAL_C void TestAutoUnlock(); |
|
159 |
||
160 |
LOCAL_C void RunTests(); |
|
161 |
||
162 |
// Test data |
|
163 |
||
164 |
||
165 |
LOCAL_C void AllocateCIDs() |
|
166 |
// |
|
167 |
// Allocates a set of static global media identifiers on the heap. |
|
168 |
// The identifiers are all exactly 128 bits. |
|
169 |
// Because the test uses only one card, CIDs 1 through 3 can be arbitrary |
|
170 |
// (they are just used to construct store data.) |
|
171 |
// |
|
172 |
// Format is "CIDXccccccccccc#", where X is the ASCII digit for the index. |
|
173 |
// The CID is stored internally in big endian format. |
|
174 |
// TCID::At(TInt i) returns the i'th byte, i.e. cid >> (i * 8) & 0xff, which |
|
175 |
// is the opposite order to the way they are stored in the array. |
|
176 |
// CIDs are formed in the same way in pp_mmc.cpp, the WINS ASSP layer. |
|
177 |
// |
|
178 |
// For actual card tests, CIDs[0] must correspond to the card's actual CID. |
|
179 |
// |
|
180 |
{ |
|
181 |
||
182 |
#if 1 |
|
183 |
static TUint8 ht0[KMMCCIDLength] = // CID0 |
|
184 |
{ |
|
185 |
0x06, 0x00, 0x00, 0x31, |
|
186 |
0x36, 0x4d, 0x20, 0x20, |
|
187 |
0x20, 0x00, 0xb4, 0xff, |
|
188 |
0xff, 0xff, 0x63, 0xd9 |
|
189 |
}; |
|
190 |
#else |
|
191 |
static TUint8 ht0[KMMCCIDLength] = // BPC2 |
|
192 |
{ |
|
193 |
0x06, 0x00, 0x00, 0x31, |
|
194 |
0x36, 0x4d, 0x20, 0x20, |
|
195 |
0x20, 0x00, 0x89, 0xff, |
|
196 |
0xff, 0xff, 0x63, 0xa7 |
|
197 |
}; |
|
198 |
#endif |
|
199 |
||
200 |
test.Start(_L("AllocateCIDs")); |
|
201 |
||
202 |
TInt i; |
|
203 |
for (i = 0; i < KCIDCnt; i++) |
|
204 |
{ |
|
205 |
TUint8 bf[KMMCCIDLength]; |
|
206 |
TUint j; |
|
207 |
bf[0] = 'C'; |
|
208 |
bf[1] = 'I'; |
|
209 |
bf[2] = 'D'; |
|
210 |
bf[3] = TUint8('0' + i); |
|
211 |
for (j = 4; j < KMMCCIDLength - 1; j++) |
|
212 |
bf[j] = 'c'; |
|
213 |
bf[KMMCCIDLength - 1] = '#'; |
|
214 |
||
215 |
if (i == 0) |
|
216 |
{ |
|
217 |
TUint cidIdx = 0; |
|
218 |
TLocalDriveCapsV5 driveCaps; |
|
219 |
TPckg<TLocalDriveCapsV5> driveCapsPkg(driveCaps); |
|
220 |
if(TBLD.Caps(driveCapsPkg) == KErrNone) |
|
221 |
{ |
|
222 |
// V5 of TLocalDriveCapsV5 now contains a serial number |
|
223 |
// which for MMC cards is defined to be the unique CID |
|
224 |
if(driveCaps.iSerialNumLength == KMMCCIDLength) |
|
225 |
{ |
|
226 |
for(cidIdx=0; cidIdx<KMMCCIDLength; cidIdx++) |
|
227 |
{ |
|
228 |
bf[cidIdx] = driveCaps.iSerialNum[KMMCCIDLength-cidIdx-1]; |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
232 |
if(cidIdx == KMMCCIDLength) |
|
233 |
{ |
|
234 |
test((CIDs[i] = new TCID(bf)) != NULL); |
|
235 |
} |
|
236 |
else |
|
237 |
{ |
|
238 |
#ifdef __WINS__ |
|
239 |
test((CIDs[i] = new TCID(bf)) != NULL); |
|
240 |
#else |
|
241 |
test((CIDs[i] = new TCID(ht0)) != NULL); |
|
242 |
#endif |
|
243 |
} |
|
244 |
} |
|
245 |
else |
|
246 |
{ |
|
247 |
test((CIDs[i] = new TCID(bf)) != NULL); |
|
248 |
} |
|
249 |
} |
|
250 |
||
251 |
test.End(); |
|
252 |
} |
|
253 |
||
254 |
||
255 |
LOCAL_C void DeleteCIDs() |
|
256 |
// |
|
257 |
// Deletes static global media identifiers from the heap. |
|
258 |
// |
|
259 |
{ |
|
260 |
test.Start(_L("DeleteCIDs")); |
|
261 |
||
262 |
TInt i; |
|
263 |
for (i = 0; i < KCIDCnt; i++) |
|
264 |
delete CIDs[i]; |
|
265 |
||
266 |
test.End(); |
|
267 |
} |
|
268 |
||
269 |
||
270 |
LOCAL_C void AllocatePasswords() |
|
271 |
// |
|
272 |
// Allocates a set of static global TMediaPassword objects on the heap. |
|
273 |
// The passwords range from zero to 16 bytes in length. |
|
274 |
// |
|
275 |
{ |
|
276 |
test.Start(_L("AllocatePasswords")); |
|
277 |
||
278 |
TInt i; |
|
279 |
for (i = 0; i < KPWDCnt; i++) |
|
280 |
{ |
|
281 |
test((PWDs[i] = new TMediaPassword) != NULL); |
|
282 |
TInt j; |
|
283 |
for (j = 0; j < i * 2; j++) |
|
284 |
PWDs[i]->Append(TChar('a' + i + j)); |
|
285 |
} |
|
286 |
||
287 |
test.End(); |
|
288 |
} |
|
289 |
||
290 |
||
291 |
LOCAL_C void DeletePasswords() |
|
292 |
// |
|
293 |
// Deletes static global TMediaPassword objects from the heap. |
|
294 |
// |
|
295 |
{ |
|
296 |
test.Start(_L("DeletePasswords")); |
|
297 |
||
298 |
TInt i; |
|
299 |
for (i = 0; i < KPWDCnt; i++) |
|
300 |
delete PWDs[i]; |
|
301 |
||
302 |
test.End(); |
|
303 |
} |
|
304 |
||
305 |
||
306 |
LOCAL_C void SetUpMapSizes() |
|
307 |
// |
|
308 |
// Initializes static global mapSizes[,] with the persistent store mapping |
|
309 |
// sizes of each CID and password. |
|
310 |
// |
|
311 |
{ |
|
312 |
test.Start(_L("SetUpMapSizes")); |
|
313 |
||
314 |
TInt i; |
|
315 |
for (i = 0; i < KCIDCnt; i++) |
|
316 |
{ |
|
317 |
TInt j; |
|
318 |
||
319 |
for (j = 0; j < KPWDCnt; j++) |
|
320 |
mapSizes[i][j] = KMMCCIDLength + sizeof(TInt32) + PWDs[j]->Length(); |
|
321 |
} |
|
322 |
||
323 |
test.End(); |
|
324 |
} |
|
325 |
||
326 |
||
327 |
LOCAL_C void AllocateTestData() |
|
328 |
// |
|
329 |
// Allocates all test data objects on the heap. |
|
330 |
// |
|
331 |
{ |
|
332 |
AllocateCIDs(); |
|
333 |
AllocatePasswords(); |
|
334 |
||
335 |
SetUpMapSizes(); |
|
336 |
} |
|
337 |
||
338 |
||
339 |
LOCAL_C void DeleteTestData() |
|
340 |
// |
|
341 |
// Frees all test data objects on the heap. |
|
342 |
// |
|
343 |
{ |
|
344 |
DeletePasswords(); |
|
345 |
DeleteCIDs(); |
|
346 |
} |
|
347 |
||
348 |
||
349 |
// Test functions. |
|
350 |
||
351 |
||
352 |
LOCAL_C void TestStaticStore() |
|
353 |
// |
|
354 |
// Tests the non card specific virtual functions in DPeriphBusController. |
|
355 |
// TInt ReadPasswordData(TDes8 &aBuf); |
|
356 |
// TInt WritePasswordData(const TDesC8 &aBuf); |
|
357 |
// TInt PasswordStoreLengthInBytes(); |
|
358 |
// |
|
359 |
// store is reset at start of DMMCController::WritePasswordData(). |
|
360 |
// |
|
361 |
{ |
|
362 |
test.Start(_L("TestStore")); |
|
363 |
||
364 |
// TBuf8<KMaxPersistentStore> is 4 + 4 + 256 bytes, so allocate on heap. |
|
365 |
TPersistentStore *pwStore; |
|
366 |
test((pwStore = new TPersistentStore) != NULL); |
|
367 |
TPersistentStore &wStore = *pwStore; |
|
368 |
TPersistentStore *prStore; |
|
369 |
test((prStore = new TPersistentStore) != NULL); |
|
370 |
TPersistentStore &rStore = *prStore; |
|
371 |
||
372 |
// WritePasswordData() |
|
373 |
||
374 |
test.Next(_L("WritePasswordData()")); |
|
375 |
||
376 |
test(TBLD.WritePasswordData(wStore) == KErrNone);// empty |
|
377 |
test(TBLD.PasswordStoreLengthInBytes() == 0); |
|
378 |
||
379 |
AddMapping(wStore, CIDs[1], PWDs[1]); // exactly one entry |
|
380 |
test(TBLD.WritePasswordData(wStore) == KErrNone); |
|
381 |
test(TBLD.PasswordStoreLengthInBytes() == mapSizes[1][1]); |
|
382 |
||
383 |
AddMapping(wStore, CIDs[2], PWDs[2]); // exactly two entries |
|
384 |
test(TBLD.WritePasswordData(wStore) == KErrNone); |
|
385 |
test(TBLD.PasswordStoreLengthInBytes() == mapSizes[1][1] + mapSizes[2][2]); |
|
386 |
||
387 |
TInt i; |
|
388 |
for (i = 0; i < wStore.Length(); i++) // corrupt (partial) |
|
389 |
{ |
|
390 |
wStore.SetLength(i); |
|
391 |
TInt r(TBLD.WritePasswordData(wStore)); |
|
392 |
if (i == 0 || i == mapSizes[0][0] || i == mapSizes[0][0] + mapSizes[1][1]) |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
393 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
394 |
test_KErrNone(r); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
395 |
} |
0 | 396 |
else |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
397 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
398 |
test_Value(r, r == KErrCorrupt && TBLD.PasswordStoreLengthInBytes() == 0); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
399 |
} |
0 | 400 |
} |
401 |
||
402 |
test.Next(_L("Exceeding password store size")); |
|
403 |
||
404 |
wStore.Zero(); // empty password store |
|
405 |
test(TBLD.WritePasswordData(wStore) == KErrNone); |
|
406 |
||
407 |
test.Printf(_L("Adding mappings...\n")); |
|
408 |
||
409 |
const TMediaPassword password(_L8("abcdefghijklmnop")); //Need a max length password (KMaxMediaPassword) |
|
410 |
for(TInt n=0; n<KCIDCnt; ++n) |
|
411 |
{ |
|
412 |
AddMapping(wStore, CIDs[n], &password); |
|
413 |
test.Printf(_L("Mapping:%d store size: %d bytes\n"),n , wStore.Length() ); |
|
414 |
const TInt r = TBLD.WritePasswordData(wStore); |
|
415 |
test.Printf(_L("WritePasswordData() --> ret=%d\n"), r); |
|
416 |
if(n==KMaxNumOfStoreEntries) |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
417 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
418 |
test_Value(r, r == KErrOverflow); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
419 |
} |
0 | 420 |
else |
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
421 |
{ |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
422 |
test_KErrNone(r); |
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
423 |
} |
0 | 424 |
} |
425 |
||
426 |
||
427 |
// ReadPasswordData(). |
|
428 |
||
429 |
test.Next(_L("ReadPasswordData()")); |
|
430 |
||
431 |
wStore.Zero(); // empty |
|
432 |
test(TBLD.WritePasswordData(wStore) == KErrNone); |
|
433 |
test(TBLD.ReadPasswordData(rStore) == KErrNone); |
|
434 |
test(rStore.Length() == 0); |
|
435 |
||
436 |
AddMapping(wStore, CIDs[1], PWDs[1]); // exactly one entry |
|
437 |
test(TBLD.WritePasswordData(wStore) == KErrNone); |
|
438 |
rStore.SetLength(0); // lt store len |
|
439 |
test(TBLD.ReadPasswordData(rStore) == KErrNone); |
|
440 |
test(rStore.Length() == TBLD.PasswordStoreLengthInBytes()); |
|
441 |
// gt store len |
|
442 |
rStore.SetLength(TBLD.PasswordStoreLengthInBytes() + 4); |
|
443 |
test(TBLD.ReadPasswordData(rStore) == 0); |
|
444 |
test(rStore.Length() == TBLD.PasswordStoreLengthInBytes()); |
|
445 |
||
446 |
TBuf8<2> srStore; // max lt store len |
|
447 |
test(TBLD.ReadPasswordData(srStore) == KErrOverflow); |
|
448 |
||
449 |
// Stress test high turnover with memory failure. |
|
450 |
||
451 |
test.Next(_L("Memory test")); |
|
452 |
||
453 |
TInt r; // error code |
|
454 |
||
455 |
TInt m; |
|
456 |
for (m = 1; m < 100; m++) |
|
457 |
{ |
|
458 |
__KHEAP_SETFAIL(RHeap::EDeterministic, m); |
|
459 |
||
460 |
TInt j; |
|
461 |
for (j = 1; j < KCIDCnt - 1; j++) |
|
462 |
{ |
|
463 |
TInt k; |
|
464 |
for (k = 1; k < KPWDCnt - 1; k++) |
|
465 |
{ |
|
466 |
wStore.Zero(); |
|
467 |
||
468 |
AddMapping(wStore, CIDs[j], PWDs[k]); |
|
469 |
AddMapping(wStore, CIDs[j + 1], PWDs[k + 1]); |
|
470 |
||
471 |
if ((r = TBLD.WritePasswordData(wStore)) != KErrNone) |
|
472 |
{ |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
473 |
test_Value(r, r == KErrNoMemory); |
0 | 474 |
test(TBLD.PasswordStoreLengthInBytes() == 0); |
475 |
} |
|
476 |
else |
|
477 |
{ |
|
478 |
test(TBLD.ReadPasswordData(rStore) == KErrNone); |
|
479 |
test(IsStoreValid(rStore) && StoresEqual(rStore, wStore)); |
|
480 |
} |
|
481 |
} |
|
482 |
} |
|
483 |
__KHEAP_RESET; |
|
484 |
} // for (m = 1; m < 16; m++) |
|
485 |
||
486 |
// Clear the store for subsequent tests. |
|
487 |
||
488 |
wStore.Zero(); |
|
489 |
test(TBLD.WritePasswordData(wStore) == KErrNone); |
|
490 |
test(TBLD.PasswordStoreLengthInBytes() == 0); |
|
491 |
||
492 |
delete prStore; |
|
493 |
delete pwStore; |
|
494 |
||
495 |
test.End(); |
|
496 |
} |
|
497 |
||
498 |
||
499 |
LOCAL_C void AddMapping(TDes8 &aSt, const TCID *aCID, const TMediaPassword *aPWD) |
|
500 |
// |
|
501 |
// Adds aCID |-> aPWD mapping to persistent file's store contents. |
|
502 |
// |
|
503 |
{ |
|
504 |
aSt.SetLength(aSt.Length() + KMMCCIDLength); |
|
505 |
aCID->Copy(&aSt[aSt.Length() - KMMCCIDLength]); |
|
506 |
||
507 |
TUint8 lenBuf[sizeof(TInt32)]; // TInt32, big endian |
|
508 |
TMMC::BigEndian4Bytes(lenBuf, TInt32(aPWD->Length())); |
|
509 |
aSt.Append(&lenBuf[0], sizeof(TInt32)); |
|
510 |
||
511 |
aSt.Append(*aPWD); |
|
512 |
} |
|
513 |
||
514 |
||
515 |
LOCAL_C TBool IsStoreValid(const TDesC8 &aSt) |
|
516 |
// |
|
517 |
// Checks the integrity of the supplied buffer. |
|
518 |
// |
|
519 |
{ |
|
520 |
TInt iBIdx; // buffer index |
|
521 |
TBool corrupt(EFalse); // abort flag |
|
522 |
for (iBIdx = 0; iBIdx < aSt.Length(); /* nop */) |
|
523 |
{ |
|
524 |
// Enough raw data for CID, PWD_LEN and 1 byte of PWD. |
|
525 |
corrupt = TUint(aSt.Length() - iBIdx) < KMMCCIDLength + sizeof(TInt32) + 1; |
|
526 |
if (corrupt) |
|
527 |
break; |
|
528 |
||
529 |
// PWD_LEN is valid and enough raw data left for PWD. |
|
530 |
iBIdx += KMMCCIDLength; |
|
531 |
const TInt32 pwd_len(TMMC::BigEndian32(aSt.Mid(iBIdx).TDesC8::Ptr())); |
|
532 |
corrupt = !( |
|
533 |
(pwd_len <= KMaxMediaPassword) |
|
534 |
&& aSt.Length() - iBIdx >= TInt(sizeof(TInt32)) + pwd_len ); |
|
535 |
if (corrupt) |
|
536 |
break; |
|
537 |
||
538 |
// skip over PWD_LEN and PWD to next entry. |
|
539 |
iBIdx += sizeof(TInt32) + pwd_len; |
|
540 |
} |
|
541 |
||
542 |
if (corrupt) |
|
543 |
DumpStore(_L("invalid"), aSt); |
|
544 |
||
545 |
return ! corrupt; |
|
546 |
} |
|
547 |
||
548 |
||
549 |
LOCAL_C void PrintCID(const TCID &aCID) |
|
550 |
// |
|
551 |
// Prints the 128 bit CID in big endian format. |
|
552 |
// |
|
553 |
{ |
|
554 |
test.Printf(_L("CID: ")); |
|
555 |
TInt i; |
|
556 |
for (i = 0; i < TInt(KMMCCIDLength); i += 4) |
|
557 |
{ |
|
558 |
TInt j; |
|
559 |
for (j = i; j < i + 4; ++j) |
|
560 |
{ |
|
561 |
test.Printf(_L("%02x: %02x "), j, aCID.At(KMMCCIDLength - j - 1)); |
|
562 |
} |
|
563 |
test.Printf(_L("\n")); |
|
564 |
} |
|
565 |
} |
|
566 |
||
567 |
||
568 |
LOCAL_C void ParseStore(const TDesC8 &aSt, CArrayFixSeg<TTestMapping> *aMP) |
|
569 |
// |
|
570 |
// Fills aMP with the mappings in aSt. |
|
571 |
// |
|
572 |
{ |
|
573 |
TInt iBIdx; // buffer index |
|
574 |
TInt r(KErrNone); // exit code |
|
575 |
for (iBIdx = 0; r == KErrNone && iBIdx < aSt.Length(); /* nop */) |
|
576 |
{ |
|
577 |
// Calculate index for CID. |
|
578 |
TPtrC8 pCID(aSt.Mid(iBIdx, KMMCCIDLength)); // CID |
|
579 |
const TCID cid(pCID.Ptr()); |
|
580 |
TInt cidIdx; |
|
581 |
for (cidIdx = 0; cidIdx < KCIDCnt && !(*(CIDs[cidIdx]) == cid); cidIdx++) |
|
582 |
{ /* empty. */ } |
|
583 |
// If invalid CID then print CID with valid CIDs. |
|
584 |
if (!(cidIdx < KCIDCnt)) |
|
585 |
{ |
|
586 |
test.Printf(_L("ParseStore: invalid CID\n")); |
|
587 |
PrintCID(cid); |
|
588 |
TInt i; |
|
589 |
for (i = 0; i < KCIDCnt; i++) |
|
590 |
{ |
|
591 |
test.Printf(_L("ParseStore: valid CID %d\n"), i); |
|
592 |
PrintCID(*CIDs[i]); |
|
593 |
} |
|
594 |
test(EFalse); |
|
595 |
} |
|
596 |
||
597 |
const TInt32 pwd_len(TMMC::BigEndian32(&aSt[iBIdx + KMMCCIDLength])); |
|
598 |
||
599 |
// Calculate index for PWD. |
|
600 |
TMediaPassword pwd; |
|
601 |
pwd.Copy(&aSt[iBIdx + KMMCCIDLength + sizeof(TInt32)], pwd_len); |
|
602 |
||
603 |
TInt pwdIdx; |
|
604 |
for (pwdIdx = 0; pwdIdx < KPWDCnt && *PWDs[pwdIdx] != pwd; pwdIdx++) |
|
605 |
{ /* empty. */ } |
|
606 |
test(pwdIdx < KPWDCnt); |
|
607 |
||
608 |
TTestMapping mp; |
|
609 |
mp.iCIDIdx = cidIdx; |
|
610 |
mp.iPWDIdx = pwdIdx; |
|
611 |
TRAP(r, aMP->InsertL(0, mp)); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
612 |
test_KErrNone(r); |
0 | 613 |
|
614 |
iBIdx += KMMCCIDLength + sizeof(TInt32) + pwd_len; |
|
615 |
} |
|
616 |
} |
|
617 |
||
618 |
||
619 |
LOCAL_C void DumpStore(const TDesC &aName, const TDesC8 &aSt) |
|
620 |
// |
|
621 |
// Prints the contents of the supplied store. |
|
622 |
// |
|
623 |
{ |
|
624 |
test.Printf(_L("\nstore %S: len = %d\n"), &aName, aSt.Length()); |
|
625 |
||
626 |
TInt i; |
|
627 |
for (i = 0; i < aSt.Length(); i += 8) |
|
628 |
{ |
|
629 |
TInt j; |
|
630 |
for (j = i; j < Min(aSt.Length(), i + 8); j++) |
|
631 |
test.Printf(_L("%02d: %03d : %02x : %c \n "), j, aSt[j], aSt[j], aSt[j]); |
|
632 |
test.Printf(_L("\n")); |
|
633 |
} |
|
634 |
} |
|
635 |
||
636 |
||
637 |
LOCAL_C TBool StoresEqual(const TDesC8 &aSt0, const TDesC8 &aSt1) |
|
638 |
// |
|
639 |
// Compares aSt1 with aSt2. Return value indicates whether or not the |
|
640 |
// stores contain exactly the same mappings, but not necessarily in the |
|
641 |
// same order. |
|
642 |
// |
|
643 |
{ |
|
644 |
TBool same(EFalse); |
|
645 |
||
646 |
CArrayFixSeg<TTestMapping> *ramp0, *ramp1; |
|
647 |
||
648 |
test((ramp0 = new(ELeave) CArrayFixSeg<TTestMapping>(2)) != NULL); |
|
649 |
test((ramp1 = new(ELeave) CArrayFixSeg<TTestMapping>(2)) != NULL); |
|
650 |
||
651 |
test(IsStoreValid(aSt0)); |
|
652 |
test(IsStoreValid(aSt1)); |
|
653 |
||
654 |
ParseStore(aSt0, ramp0); |
|
655 |
ParseStore(aSt1, ramp1); |
|
656 |
||
657 |
TArray<TTestMapping> a0(ramp0->Array()); |
|
658 |
TArray<TTestMapping> a1(ramp1->Array()); |
|
659 |
||
660 |
if (a0.Count() == a1.Count()) |
|
661 |
// if #a0 == #a1 and a0 <= a1 then a0 == a1. |
|
662 |
{ |
|
663 |
TBool allInA1(ETrue); |
|
664 |
TInt i; |
|
665 |
for (i = 0; allInA1 && i < a0.Count(); i++) |
|
666 |
{ |
|
667 |
TBool found(EFalse); |
|
668 |
TInt j; |
|
669 |
for (j = 0; ! found && j < a0.Count(); j++) |
|
670 |
{ |
|
671 |
found = ( |
|
672 |
a0[i].iCIDIdx == a1[j].iCIDIdx |
|
673 |
&& a0[i].iPWDIdx == a1[j].iPWDIdx ); |
|
674 |
} |
|
675 |
allInA1 = found; |
|
676 |
} |
|
677 |
||
678 |
same = allInA1; |
|
679 |
} |
|
680 |
||
681 |
delete ramp1; |
|
682 |
delete ramp0; |
|
683 |
||
684 |
if (! same) |
|
685 |
{ |
|
686 |
DumpStore(_L("0"), aSt0); |
|
687 |
DumpStore(_L("1"), aSt1); |
|
688 |
} |
|
689 |
||
690 |
return same; |
|
691 |
} |
|
692 |
||
693 |
||
694 |
LOCAL_C void RemountMedia() |
|
695 |
// |
|
696 |
// Forces a media remount and waits for it to take effect. If the card has a |
|
697 |
// password, it will become locked the next time that it is powered up. |
|
698 |
// |
|
699 |
{ |
|
700 |
//#ifdef __WINS__ |
|
701 |
// TBLD.ForceMediaChange(); |
|
702 |
// UserSvr::ForceRemountMedia(ERemovableMedia0); |
|
703 |
// User::After(1 * 1000 * 1000); |
|
704 |
//#else |
|
705 |
||
706 |
#ifdef __AUTO_DETECT_MEDIA_CHANGE__ |
|
707 |
RFs fs; |
|
708 |
test(fs.Connect() == KErrNone); |
|
709 |
||
710 |
test.Printf(_L("Remove and re-insert card..")); |
|
711 |
||
712 |
TInt r; |
|
713 |
do |
|
714 |
{ |
|
715 |
TRequestStatus status; |
|
716 |
TDriveUnit driveUnit(RFsDNum); |
|
717 |
TDriveName driveName = driveUnit.Name(); |
|
718 |
fs.NotifyChange(ENotifyAll, status, driveName); |
|
719 |
test(status == KRequestPending); |
|
720 |
User::WaitForRequest(status); |
|
721 |
test.Printf(_L("\rAccessing card... \r")); |
|
722 |
||
723 |
r = AccessDisk(); |
|
724 |
if (r == KErrNotReady) |
|
725 |
test.Printf(_L("\rRemove and re-insert card..")); |
|
726 |
||
727 |
if (r != KErrNone && r != KErrNotReady && r != KErrLocked) |
|
728 |
test.Printf(_L("AccessDisk() returned %d"), r); |
|
729 |
} |
|
730 |
while (r == KErrNotReady); |
|
731 |
||
732 |
test.Printf(_L("\n")); |
|
733 |
||
734 |
fs.Close(); |
|
735 |
||
736 |
#else |
|
737 |
// Power down the card so that it is locked the next time it is powered up. |
|
738 |
test.Printf(_L("Remove and re-insert card. Press \'z\' when finished.\n")); |
|
739 |
while (test.Getch() != 'z') |
|
740 |
{ /* empty. */ } |
|
741 |
#endif |
|
742 |
||
743 |
//#endif |
|
744 |
} |
|
745 |
||
746 |
||
747 |
LOCAL_C void AttemptToUnlock(TMediaPassword &aPWD, TBool aStore) |
|
748 |
// |
|
749 |
// Tests that the card is locked and then tries to unlock it. |
|
750 |
// |
|
751 |
{ |
|
752 |
TInt r = AccessDisk(); |
|
753 |
if (r != KErrLocked) |
|
754 |
test.Printf(_L("AccessDisk() returned %d\n"), r); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
755 |
test_Value(r, r == KErrLocked); |
0 | 756 |
test(TBLD.Unlock(aPWD, aStore) == KErrNone); |
757 |
} |
|
758 |
||
759 |
||
760 |
LOCAL_C void TestLockUnlock() |
|
761 |
// |
|
762 |
// Tests TBusLocalDrive functions for locking / unlocking individual cards. |
|
763 |
// Lock() currently means set password only. The media must be remounted before it |
|
764 |
// can really be locked. |
|
765 |
// |
|
766 |
// EPbPswdUnlock EPbPswdLock EPbPswdClear |
|
767 |
// right wrong right wrong right wrong |
|
768 |
// locked None AccDen AccDec AccDen AccDen AccDen |
|
769 |
// unlocked AldExst AldExst None AccDec None AccDen |
|
770 |
// |
|
771 |
// Locked means inaccessible, not just has password. |
|
772 |
// |
|
773 |
{ |
|
774 |
test.Start(_L("TestLockUnlock")); |
|
775 |
||
776 |
TMediaPassword nul(*PWDs[0]); |
|
777 |
TMediaPassword arb1(*PWDs[1]); |
|
778 |
TMediaPassword arb2(*PWDs[2]); |
|
779 |
||
780 |
// Clear the password store for when function run on its own. |
|
781 |
TBuf8<1> nulSt; |
|
782 |
test(TBLD.WritePasswordData(nulSt) == KErrNone);// empty |
|
783 |
test(TBLD.PasswordStoreLengthInBytes() == 0); |
|
784 |
||
785 |
// Give the card an arbitrary password |
|
786 |
test.Next(_L("assign test password")); |
|
787 |
test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone); |
|
788 |
RemountMedia(); // card is now locked |
|
789 |
||
790 |
test.Next(_L("lock locked card")); |
|
791 |
test(TBLD.SetPassword(arb2, arb1, EFalse) == KErrAccessDenied); // lock locked wrong |
|
792 |
test(TBLD.SetPassword(arb1, arb1, EFalse) == KErrAccessDenied); // lock locked right |
|
793 |
||
794 |
test.Next(_L("unlock locked card")); |
|
795 |
test(TBLD.Unlock(arb2, EFalse) == KErrAccessDenied); // unlock locked wrong |
|
796 |
AttemptToUnlock(arb1); |
|
797 |
||
798 |
test.Next(_L("unlock unlocked card")); |
|
799 |
test(TBLD.Unlock(arb1, EFalse) == KErrAlreadyExists); // unlock unlocked right |
|
800 |
test(TBLD.Unlock(arb2, EFalse) == KErrAlreadyExists); // unlock unlocked wrong |
|
801 |
||
802 |
test.Next(_L("lock unlocked card")); |
|
803 |
test(TBLD.SetPassword(arb2, arb1, EFalse) == KErrAccessDenied); // lock unlocked wrong |
|
804 |
test(TBLD.SetPassword(arb1, arb1, EFalse) == KErrNone); // lock unlocked right |
|
805 |
||
806 |
test.Next(_L("clear unlocked card")); |
|
807 |
test(TBLD.Clear(arb2) == KErrAccessDenied); // clear unlocked wrong |
|
808 |
||
809 |
//!!! If clear with wrong password, cannot clear with right password in same |
|
810 |
// power session (H). |
|
811 |
RemountMedia(); |
|
812 |
AttemptToUnlock(arb1); |
|
813 |
test(TBLD.Clear(arb1) == KErrNone); |
|
814 |
||
815 |
test.Next(_L("assign test password")); |
|
816 |
test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone); // give test password |
|
817 |
RemountMedia(); // make inaccessible |
|
818 |
||
819 |
test.Next(_L("clear locked card")); |
|
820 |
test(TBLD.Clear(arb2) == KErrAccessDenied); // clear locked wrong |
|
821 |
test(TBLD.Clear(arb1) == KErrAccessDenied); // clear locked right |
|
822 |
||
823 |
// Clear password for subsequent tests. |
|
824 |
test.Next(_L("clear password")); |
|
825 |
AttemptToUnlock(arb1); |
|
826 |
test(TBLD.Clear(arb1) == KErrNone); |
|
827 |
test(TBLD.WritePasswordData(nulSt) == KErrNone); |
|
828 |
test(TBLD.PasswordStoreLengthInBytes() == 0); |
|
829 |
||
830 |
test.End(); |
|
831 |
} |
|
832 |
||
833 |
||
834 |
/** |
|
835 |
* Because MultiMediaCards cannot distinguish where the current password ends |
|
836 |
* and the new password begins, test the media driver can abort those operations |
|
837 |
* that would end up giving the user unexpected passwords. |
|
838 |
* |
|
839 |
* The stores are directly compared with buffers because they only use one password |
|
840 |
* and the passwords are not part of the standard test data. |
|
841 |
*/ |
|
842 |
||
843 |
LOCAL_C void TestElidePasswords() |
|
844 |
{ |
|
845 |
test.Start(_L("TestElidePasswords")); |
|
846 |
||
847 |
TMediaPassword a((const TUint8*) "a"); TMediaPassword bcxyz((const TUint8*) "bcxyz"); |
|
848 |
TMediaPassword ab((const TUint8*) "ab"); TMediaPassword cxyz((const TUint8*) "cxyz"); |
|
849 |
TMediaPassword abc((const TUint8*) "abc"); TMediaPassword xyz((const TUint8*) "xyz"); |
|
850 |
||
851 |
TPersistentStore* pstoreAB; |
|
852 |
test((pstoreAB = new TPersistentStore) != 0); |
|
853 |
TPersistentStore& storeAB = *pstoreAB; |
|
854 |
AddMapping(storeAB, CIDs[0], &ab); |
|
855 |
||
856 |
TPersistentStore* pstoreCXYZ; |
|
857 |
test((pstoreCXYZ = new TPersistentStore) != 0); |
|
858 |
TPersistentStore& storeCXYZ = *pstoreCXYZ; |
|
859 |
AddMapping(storeCXYZ, CIDs[0], &cxyz); |
|
860 |
||
861 |
TPersistentStore *pstoreRd; // scratch for reading |
|
862 |
test((pstoreRd = new TPersistentStore) != NULL); |
|
863 |
TPersistentStore& storeRd = *pstoreRd; |
|
864 |
||
865 |
TBuf8<1> nulSt; |
|
866 |
test(TBLD.SetPassword(nulSt, ab, ETrue) == KErrNone); |
|
867 |
RemountMedia(); // card is now locked |
|
868 |
test(AccessDisk() == KErrNone); |
|
869 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
870 |
test(storeRd == storeAB); |
|
871 |
||
872 |
test.Next(_L("current password too short")); |
|
873 |
test(TBLD.SetPassword(a, bcxyz, ETrue) == KErrAccessDenied); |
|
874 |
test(AccessDisk() == KErrNone); |
|
875 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
876 |
test(storeRd == storeAB); |
|
877 |
||
878 |
test.Next(_L("current password too long")); |
|
879 |
test(TBLD.SetPassword(abc, xyz, ETrue) == KErrAccessDenied); |
|
880 |
test(AccessDisk() == KErrNone); |
|
881 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
882 |
test(storeRd == storeAB); |
|
883 |
||
884 |
test.Next(_L("current password exactly right")); |
|
885 |
test(TBLD.SetPassword(ab, cxyz, ETrue) == KErrNone); |
|
886 |
test(AccessDisk() == KErrNone); |
|
887 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
888 |
test(storeRd == storeCXYZ); |
|
889 |
||
890 |
test.Next(_L("clean up for following tests")); |
|
891 |
test(TBLD.Clear(cxyz) == KErrNone); |
|
892 |
test(TBLD.WritePasswordData(nulSt) == KErrNone); |
|
893 |
test(TBLD.PasswordStoreLengthInBytes() == 0); |
|
894 |
||
895 |
delete pstoreRd; |
|
896 |
delete pstoreCXYZ; |
|
897 |
delete pstoreAB; |
|
898 |
||
899 |
test.End(); |
|
900 |
} |
|
901 |
||
902 |
||
903 |
/** |
|
904 |
* test the special cases where null passwords are used. These are all failed with |
|
905 |
* KErrAccessDenied by the controller. |
|
906 |
*/ |
|
907 |
||
908 |
LOCAL_C void TestNullPasswords() |
|
909 |
{ |
|
910 |
test.Start(_L("TestNullPasswords")); |
|
911 |
||
912 |
TMediaPassword nul(*PWDs[0]); |
|
913 |
TMediaPassword arb1(*PWDs[1]); |
|
914 |
||
915 |
test.Next(_L("card has no password")); |
|
916 |
test(TBLD.SetPassword(nul, nul, ETrue) == KErrAccessDenied); |
|
917 |
test(TBLD.Unlock(nul, ETrue) == KErrAlreadyExists); |
|
918 |
test(TBLD.Clear(nul) == KErrAccessDenied); |
|
919 |
||
920 |
test.Next(_L("card has password and is unlocked")); |
|
921 |
test(TBLD.SetPassword(nul, arb1, ETrue) == KErrNone); |
|
922 |
RemountMedia(); |
|
923 |
test(AccessDisk() == KErrNone); |
|
924 |
test(TBLD.SetPassword(nul, nul, ETrue) == KErrAccessDenied); |
|
925 |
test(TBLD.Unlock(nul, ETrue) == KErrAlreadyExists); |
|
926 |
test(TBLD.Clear(nul) == KErrAccessDenied); |
|
927 |
||
928 |
test.Next(_L("clean up for following tests")); |
|
929 |
test(TBLD.Clear(arb1) == KErrNone); |
|
930 |
TBuf8<1> nulSt; |
|
931 |
test(TBLD.WritePasswordData(nulSt) == KErrNone); |
|
932 |
test(TBLD.PasswordStoreLengthInBytes() == 0); |
|
933 |
||
934 |
test.End(); |
|
935 |
} |
|
936 |
||
937 |
||
938 |
LOCAL_C void TestControllerStore() |
|
939 |
// |
|
940 |
// Performs standard password functions but stores the mappings in the controller store. |
|
941 |
// |
|
942 |
// + mapping added to store (if not exists) |
|
943 |
// - mapping removed from store (if exists) |
|
944 |
// |
|
945 |
// EPbPswdUnlock EPbPswdLock EPbPswdClear |
|
946 |
// right wrong right wrong right wrong |
|
947 |
// locked None1 AccDen- AccDec AccDen AccDen AccDen |
|
948 |
// unlocked AccDen AccDen None+ AccDec- None- AccDen- |
|
949 |
// |
|
950 |
// Locked means inaccessible, not just has password. |
|
951 |
// When the user supplies a password, the mapping in the password store is not used. |
|
952 |
// |
|
953 |
// 1. A locked card with the right mapping in the store cannot happen because of the |
|
954 |
// automatic unlocking mechanism. |
|
955 |
// |
|
956 |
// Tests start with an unlocked card that has no password. |
|
957 |
// |
|
958 |
{ |
|
959 |
test.Start(_L("TestControllerStore")); |
|
960 |
||
961 |
test.Next(_L("allocate test data")); |
|
962 |
||
963 |
TMediaPassword nul(*PWDs[0]); |
|
964 |
TMediaPassword arb1(*PWDs[1]); |
|
965 |
TMediaPassword arb2(*PWDs[2]); |
|
966 |
||
967 |
TPersistentStore *pstoreDef; // { 3 |-> 3 } |
|
968 |
test((pstoreDef = new TPersistentStore) != NULL); |
|
969 |
TPersistentStore &storeDef = *pstoreDef; |
|
970 |
AddMapping(storeDef, CIDs[3], PWDs[3]); |
|
971 |
||
972 |
TPersistentStore *pstore0_1; // { 3 |-> 3, 0 |-> 1 } |
|
973 |
test((pstore0_1 = new TPersistentStore) != NULL); |
|
974 |
TPersistentStore &store0_1 = *pstore0_1; |
|
975 |
AddMapping(store0_1, CIDs[3], PWDs[3]); |
|
976 |
AddMapping(store0_1, CIDs[0], PWDs[1]); |
|
977 |
||
978 |
TPersistentStore *pstore0_2; // { 3 |-> 3, 0 |-> 2 } |
|
979 |
test((pstore0_2 = new TPersistentStore) != NULL); |
|
980 |
TPersistentStore &store0_2 = *pstore0_2; |
|
981 |
AddMapping(store0_2, CIDs[3], PWDs[3]); |
|
982 |
AddMapping(store0_2, CIDs[0], PWDs[2]); |
|
983 |
||
984 |
TPersistentStore *pstoreRd; // temp for reading |
|
985 |
test((pstoreRd = new TPersistentStore) != NULL); |
|
986 |
TPersistentStore &storeRd = *pstoreRd; |
|
987 |
||
988 |
// Give card arbitrary password but do not lock or store. |
|
989 |
test.Next(_L("assign test password")); |
|
990 |
test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone); |
|
991 |
||
992 |
// Lock |
|
993 |
||
994 |
// Lock unlocked right out. |
|
995 |
test.Next(_L("lock unlocked right out")); |
|
996 |
test(TBLD.WritePasswordData(storeDef) == KErrNone); |
|
997 |
test(TBLD.SetPassword(arb1, arb1, ETrue) == KErrNone); // + (0 |-> 1) |
|
998 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
999 |
test(StoresEqual(storeRd, store0_1)); |
|
1000 |
||
1001 |
// Lock unlocked right in (different to make sure store modified.) |
|
1002 |
test.Next(_L("lock unlocked right in")); |
|
1003 |
test(TBLD.WritePasswordData(store0_1) == KErrNone); |
|
1004 |
test(TBLD.SetPassword(arb1, arb2, ETrue) == KErrNone); // - (0 |-> 1) + (0 |-> 2) |
|
1005 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1006 |
test(StoresEqual(storeRd, store0_2)); |
|
1007 |
||
1008 |
// Lock unlocked wrong out. |
|
1009 |
test.Next(_L("lock unlocked wrong out")); |
|
1010 |
test(TBLD.SetPassword(arb2, arb1, ETrue) == KErrNone); // restore to arb1 |
|
1011 |
test(TBLD.WritePasswordData(storeDef) == KErrNone); |
|
1012 |
test(TBLD.SetPassword(arb2, arb1, ETrue) == KErrAccessDenied); // not add (0 |-> 1) |
|
1013 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1014 |
test(StoresEqual(storeRd, storeDef)); |
|
1015 |
||
1016 |
// Lock unlocked wrong in. |
|
1017 |
test.Next(_L("lock unlocked wrong in")); |
|
1018 |
test(TBLD.WritePasswordData(store0_1) == KErrNone); |
|
1019 |
test(TBLD.SetPassword(arb2, arb1, ETrue) == KErrAccessDenied); // - (0 |-> 1) |
|
1020 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1021 |
test(StoresEqual(storeRd, store0_1)); |
|
1022 |
||
1023 |
||
1024 |
// Unlock |
|
1025 |
||
1026 |
// Unlock locked right out. |
|
1027 |
test.Next(_L("unlock locked right out")); |
|
1028 |
test(TBLD.WritePasswordData(storeDef) == KErrNone); |
|
1029 |
RemountMedia(); // make inaccessible |
|
1030 |
AttemptToUnlock(arb1, ETrue); // + (0 |-> 1) |
|
1031 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1032 |
test(StoresEqual(storeRd, store0_1)); |
|
1033 |
||
1034 |
// Unlock locked right in - see note 1. |
|
1035 |
||
1036 |
// Unlock locked wrong in. |
|
1037 |
test.Next(_L("unlock locked wrong in")); |
|
1038 |
test(TBLD.WritePasswordData(store0_2) == KErrNone); |
|
1039 |
RemountMedia(); // make inaccessible |
|
1040 |
test(TBLD.Unlock(arb2, ETrue) == KErrAccessDenied); // - (0 |-> 2) |
|
1041 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1042 |
test(StoresEqual(storeRd, storeDef)); |
|
1043 |
||
1044 |
// Unlock locked wrong out. |
|
1045 |
test.Next(_L("unlock locked wrong out")); |
|
1046 |
test(TBLD.WritePasswordData(storeDef) == KErrNone); |
|
1047 |
RemountMedia(); // make inaccessible |
|
1048 |
test(TBLD.Unlock(arb2, ETrue) == KErrAccessDenied); // not add (0 |-> 2) |
|
1049 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1050 |
test(StoresEqual(storeRd, storeDef)); |
|
1051 |
||
1052 |
||
1053 |
// Clear |
|
1054 |
||
1055 |
// Clear unlocked right out. |
|
1056 |
test.Next(_L("clear unlocked right out")); |
|
1057 |
test(TBLD.WritePasswordData(storeDef) == KErrNone); |
|
1058 |
AttemptToUnlock(arb1); // make accessible |
|
1059 |
test(TBLD.Clear(arb1) == KErrNone); // not add (0 |-> 1) |
|
1060 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1061 |
test(StoresEqual(storeRd, storeDef)); |
|
1062 |
||
1063 |
// Clear unlocked right in. |
|
1064 |
test.Next(_L("clear unlocked right in")); |
|
1065 |
test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone); // give password |
|
1066 |
test(TBLD.WritePasswordData(store0_1) == KErrNone); |
|
1067 |
test(TBLD.Clear(arb1) == KErrNone); // - (0 |-> 2) |
|
1068 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1069 |
test(StoresEqual(storeRd, storeDef)); |
|
1070 |
||
1071 |
// Clear unlocked wrong out. |
|
1072 |
test.Next(_L("clear unlocked wrong out")); |
|
1073 |
test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone); // give password |
|
1074 |
test(TBLD.WritePasswordData(storeDef) == KErrNone); |
|
1075 |
test(TBLD.Clear(arb2) == KErrAccessDenied); // not add (0 |-> 2) |
|
1076 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1077 |
test(StoresEqual(storeRd, storeDef)); |
|
1078 |
||
1079 |
// Clear unlocked wrong in. |
|
1080 |
test.Next(_L("clear unlocked wrong in")); |
|
1081 |
test(TBLD.WritePasswordData(store0_1) == KErrNone); |
|
1082 |
test(TBLD.Clear(arb2) == KErrAccessDenied); // - (0 |-> 2) |
|
1083 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1084 |
test(StoresEqual(storeRd, store0_1)); |
|
1085 |
||
1086 |
// Clear password for subsequent tests. |
|
1087 |
||
1088 |
test.Next(_L("clean up for following tests")); |
|
1089 |
test(TBLD.WritePasswordData(storeDef) == KErrNone); |
|
1090 |
RemountMedia(); |
|
1091 |
AttemptToUnlock(arb1); |
|
1092 |
test(TBLD.Clear(arb1) == KErrNone); |
|
1093 |
TBuf8<1> nulSt; |
|
1094 |
test(TBLD.WritePasswordData(nulSt) == KErrNone); |
|
1095 |
test(TBLD.PasswordStoreLengthInBytes() == 0); |
|
1096 |
||
1097 |
test.Next(_L("free test data")); |
|
1098 |
||
1099 |
delete pstoreRd; |
|
1100 |
delete pstore0_2; |
|
1101 |
delete pstore0_1; |
|
1102 |
delete pstoreDef; |
|
1103 |
||
1104 |
test.End(); |
|
1105 |
} |
|
1106 |
||
1107 |
||
1108 |
LOCAL_C TInt AccessDisk() |
|
1109 |
// |
|
1110 |
// Attempts to read the first sector of the removable media to determine whether |
|
1111 |
// it is locked. |
|
1112 |
// |
|
1113 |
{ |
|
1114 |
const TInt KSectSize = 512; |
|
1115 |
TBuf8<KSectSize> sect; // 8 + 512 |
|
1116 |
||
1117 |
return TBLD.Read(0, KSectSize, sect); |
|
1118 |
} |
|
1119 |
||
1120 |
||
1121 |
LOCAL_C void TestAutoUnlock() |
|
1122 |
// |
|
1123 |
// Tests controller internal store unlocking mechanism. |
|
1124 |
// A locked card should be transparently unlocked after the peripheral bus is |
|
1125 |
// powered up. |
|
1126 |
// |
|
1127 |
{ |
|
1128 |
test.Start(_L("TestAutoUnlock")); |
|
1129 |
||
1130 |
test.Next(_L("allocate test data")); |
|
1131 |
||
1132 |
TMediaPassword nul(*PWDs[0]); |
|
1133 |
TMediaPassword arb1(*PWDs[1]); |
|
1134 |
||
1135 |
TPersistentStore *pstoreDef; // { 3 |-> 3 } |
|
1136 |
test((pstoreDef = new TPersistentStore) != NULL); |
|
1137 |
TPersistentStore &storeDef = *pstoreDef; |
|
1138 |
AddMapping(storeDef, CIDs[3], PWDs[3]); |
|
1139 |
||
1140 |
TPersistentStore *pstore0_1; // { 3 |-> 3, 0 |-> 1 } |
|
1141 |
test((pstore0_1 = new TPersistentStore) != NULL); |
|
1142 |
TPersistentStore &store0_1 = *pstore0_1; |
|
1143 |
AddMapping(store0_1, CIDs[3], PWDs[3]); |
|
1144 |
AddMapping(store0_1, CIDs[0], PWDs[1]); |
|
1145 |
||
1146 |
TPersistentStore *pstore0_2; // { 3 |-> 3, 0 |-> 2 } |
|
1147 |
test((pstore0_2 = new TPersistentStore) != NULL); |
|
1148 |
TPersistentStore &store0_2 = *pstore0_2; |
|
1149 |
AddMapping(store0_2, CIDs[3], PWDs[3]); |
|
1150 |
AddMapping(store0_2, CIDs[0], PWDs[2]); |
|
1151 |
||
1152 |
TPersistentStore *pstoreRd; // temp for reading |
|
1153 |
test((pstoreRd = new TPersistentStore) != NULL); |
|
1154 |
TPersistentStore &storeRd = *pstoreRd; |
|
1155 |
||
1156 |
test.Next(_L("assign password")); |
|
1157 |
test(TBLD.SetPassword(nul, arb1, EFalse) == KErrNone); // give password |
|
1158 |
||
1159 |
// No mapping in store. |
|
1160 |
test.Next(_L("no mapping in store")); |
|
1161 |
test(TBLD.WritePasswordData(storeDef) == KErrNone); |
|
1162 |
RemountMedia(); |
|
1163 |
test(AccessDisk() == KErrLocked); |
|
1164 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1165 |
test(StoresEqual(storeRd, storeDef)); |
|
1166 |
||
1167 |
// Right mapping in store. |
|
1168 |
test.Next(_L("right mapping in store")); |
|
1169 |
test(TBLD.WritePasswordData(store0_1) == KErrNone); |
|
1170 |
RemountMedia(); |
|
1171 |
test(AccessDisk() == KErrNone); |
|
1172 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1173 |
test(StoresEqual(storeRd, store0_1)); |
|
1174 |
||
1175 |
// Wrong mapping in store - mapping should be removed. |
|
1176 |
test.Next(_L("wrong mapping in store")); |
|
1177 |
test(TBLD.WritePasswordData(store0_2) == KErrNone); |
|
1178 |
RemountMedia(); |
|
1179 |
test(AccessDisk() == KErrLocked); |
|
1180 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1181 |
test(StoresEqual(storeRd, storeDef)); |
|
1182 |
||
1183 |
// Redundant mapping in store. |
|
1184 |
test.Next(_L("redundant mapping in store")); |
|
1185 |
AttemptToUnlock(arb1); |
|
1186 |
test(TBLD.Clear(arb1) == KErrNone); |
|
1187 |
test(TBLD.WritePasswordData(store0_2) == KErrNone); |
|
1188 |
RemountMedia(); |
|
1189 |
test(AccessDisk() == KErrNone); |
|
1190 |
test(TBLD.ReadPasswordData(storeRd) == KErrNone); |
|
1191 |
test(StoresEqual(storeRd, storeDef)); |
|
1192 |
||
1193 |
test.Next(_L("clean up for following tests")); |
|
1194 |
TBuf8<1> nulSt; |
|
1195 |
test(TBLD.WritePasswordData(nulSt) == KErrNone); |
|
1196 |
test(TBLD.PasswordStoreLengthInBytes() == 0); |
|
1197 |
||
1198 |
test.Next(_L("free test data")); |
|
1199 |
delete pstoreRd; |
|
1200 |
delete pstore0_2; |
|
1201 |
delete pstore0_1; |
|
1202 |
delete pstoreDef; |
|
1203 |
||
1204 |
test.End(); |
|
1205 |
} |
|
1206 |
||
1207 |
||
1208 |
LOCAL_C void TestPasswordFile() |
|
1209 |
// |
|
1210 |
// Additional test added for INC066636 |
|
1211 |
// |
|
1212 |
// Tests that the MMC password file is created in the correct place on the disk |
|
1213 |
// as defined by KMediaPWrdFile in f32fsys.h |
|
1214 |
// |
|
1215 |
// The following test cases are checked: |
|
1216 |
// o Card can be locked |
|
1217 |
// o Cannot lock the card or change its password if the wrong password is |
|
1218 |
// specified |
|
1219 |
// o Password can be changed |
|
1220 |
// o Password can be removed |
|
1221 |
// |
|
1222 |
{ |
|
1223 |
const TInt KDriveNum = RFsDNum; |
|
1224 |
||
1225 |
TInt error = KErrNone; |
|
1226 |
||
1227 |
||
1228 |
test.Start(_L("Testing password file")); |
|
1229 |
||
1230 |
||
1231 |
test.Next(_L("open connection")); |
|
1232 |
RFs theFs; |
|
1233 |
test(theFs.Connect() == KErrNone); |
|
1234 |
||
1235 |
||
1236 |
||
1237 |
// Now set the first password that we will use |
|
1238 |
test.Next(_L("lock the media card")); |
|
1239 |
TMediaPassword& nulPWrd = *PWDs[0]; |
|
1240 |
TMediaPassword& oldPWrd = *PWDs[1]; |
|
1241 |
error = theFs.LockDrive(KDriveNum, nulPWrd, oldPWrd, ETrue); |
|
1242 |
test(KErrNone == error); |
|
1243 |
||
1244 |
||
1245 |
// Verify that the password file does exist and is in the correct place |
|
1246 |
test.Next(_L("check password file exists")); |
|
1247 |
TEntry theEntry; |
|
1248 |
TBuf<sizeof(KMediaPWrdFile)> mediaPWrdFile(KMediaPWrdFile); |
|
1249 |
mediaPWrdFile[0] = (TUint8) RFs::GetSystemDriveChar(); |
|
1250 |
error = theFs.Entry(mediaPWrdFile, theEntry); |
|
1251 |
test (KErrNone == error); |
|
1252 |
||
1253 |
||
1254 |
// Attempt to set a new password without specifying the current one |
|
1255 |
test.Next(_L("change password failure")); |
|
1256 |
TMediaPassword& newPWrd = *PWDs[2]; |
|
1257 |
error = theFs.LockDrive(KDriveNum, nulPWrd, newPWrd, ETrue); |
|
1258 |
test(KErrAccessDenied == error); |
|
1259 |
||
1260 |
||
1261 |
// Change the password for a new one... |
|
1262 |
test.Next(_L("change password success")); |
|
1263 |
error = theFs.LockDrive(KDriveNum, oldPWrd, newPWrd, ETrue); |
|
1264 |
test(KErrNone == error); |
|
1265 |
||
1266 |
||
1267 |
// Clear the password |
|
1268 |
test.Next(_L("clear the password")); |
|
1269 |
error = theFs.ClearPassword(KDriveNum, newPWrd); |
|
1270 |
test(KErrNone == error); |
|
1271 |
||
1272 |
||
1273 |
// Check that the password has been removed from the file |
|
1274 |
// (KMediaPWrdFile should now be zero bytes in size) |
|
1275 |
test.Next(_L("check password removal")); |
|
1276 |
error = theFs.Entry(mediaPWrdFile, theEntry); |
|
1277 |
test (KErrNone == error); |
|
1278 |
test (0 == theEntry.iSize); |
|
1279 |
||
1280 |
||
1281 |
// Remove the password file |
|
1282 |
test.Next(_L("tidy up")); |
|
1283 |
error = theFs.Delete(mediaPWrdFile); |
|
1284 |
test (KErrNone == error); |
|
1285 |
||
1286 |
||
1287 |
theFs.Close(); |
|
1288 |
||
1289 |
test.End(); |
|
1290 |
} |
|
1291 |
||
1292 |
||
1293 |
LOCAL_C void TestFormatErase() |
|
1294 |
// |
|
1295 |
// Additional test added for DEF067976 - MR1: Force Erase of MMC lock UI until complete |
|
1296 |
// |
|
1297 |
// Tests that a card can be locked & then force-erased using the new format switch |
|
1298 |
// |
|
1299 |
// Test modified for INC073653 - RFormat::Open returns KErrNone, even if card is locked |
|
1300 |
// |
|
1301 |
// RFormat:Open now returns KErrLocked if media is locked (previously this wasn't returned |
|
1302 |
// until calling RFormat::Next |
|
1303 |
// |
|
1304 |
// |
|
1305 |
{ |
|
1306 |
TInt r = KErrNone; |
|
1307 |
||
1308 |
test.Start(_L("Testing force erase")); |
|
1309 |
||
1310 |
||
1311 |
test.Next(_L("open connection")); |
|
1312 |
RFs fs; |
|
1313 |
test(fs.Connect() == KErrNone); |
|
1314 |
||
1315 |
// Clear the password store for when function run on its own. |
|
1316 |
TBuf8<1> nulSt; |
|
1317 |
test(TBLD.WritePasswordData(nulSt) == KErrNone);// empty |
|
1318 |
test(TBLD.PasswordStoreLengthInBytes() == 0); |
|
1319 |
||
1320 |
||
1321 |
test.Next(_L("lock card")); |
|
1322 |
// Now set the first password that we will use |
|
1323 |
TMediaPassword& nulPWrd = *PWDs[0]; |
|
1324 |
TMediaPassword& oldPWrd = *PWDs[1]; |
|
1325 |
r = fs.LockDrive(RFsDNum, nulPWrd, oldPWrd, EFalse); |
|
1326 |
if (r != KErrNone) |
|
1327 |
test.Printf(_L("RFs::LockDrive() returned %d\n"), r); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1328 |
test_KErrNone(r); |
0 | 1329 |
|
1330 |
RemountMedia(); // card is now locked |
|
1331 |
||
1332 |
RFormat fmt; |
|
1333 |
TPckgBuf<TInt> stepPkg; |
|
1334 |
TDriveUnit driveUnit(RFsDNum); |
|
1335 |
TDriveName driveName = driveUnit.Name(); |
|
1336 |
||
1337 |
test.Next(_L("format locked card")); |
|
1338 |
r = fmt.Open(fs, driveName, EHighDensity, stepPkg()); |
|
1339 |
if (r != KErrLocked) |
|
1340 |
test.Printf(_L("RFormat::Next() returned %d\n"), r); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1341 |
test_Value(r, r == KErrLocked); |
0 | 1342 |
|
1343 |
test.Printf(_L("\n")); |
|
1344 |
fmt.Close(); |
|
1345 |
||
1346 |
_LIT(KLitStars,"********************"); |
|
1347 |
test.Next(_L("force erase locked card")); |
|
1348 |
r = fmt.Open(fs, driveName, EHighDensity | EForceErase, stepPkg()); |
|
1349 |
if (r != KErrNone) |
|
1350 |
test.Printf(_L("RFormat::Open() returned %d\n"), r); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1351 |
test_KErrNone(r); |
0 | 1352 |
|
1353 |
while (stepPkg() > 0) |
|
1354 |
{ |
|
1355 |
TRequestStatus status; |
|
1356 |
fmt.Next(stepPkg, status); |
|
1357 |
test (status == KRequestPending || status == KErrNone); |
|
1358 |
User::WaitForRequest(status); |
|
1359 |
||
1360 |
TInt length=(100-stepPkg())/5; |
|
1361 |
length=Min(length,20); |
|
1362 |
TPtrC stars=KLitStars().Left(length); |
|
1363 |
test.Printf(_L("\r%S"),&stars); |
|
1364 |
} |
|
1365 |
test.Printf(_L("\n")); |
|
1366 |
fmt.Close(); |
|
1367 |
||
1368 |
fs.Close(); |
|
1369 |
||
1370 |
test.End(); |
|
1371 |
} |
|
1372 |
||
1373 |
LOCAL_C void TestWriteToPasswordStoreUnlocksCard() |
|
1374 |
// |
|
1375 |
// Additional test added for INC096612 - Writing to password store should unlock the card |
|
1376 |
// |
|
1377 |
// Tests that a card can be auto-unlocked just by writing to the password store (as this is what |
|
1378 |
// estart does) |
|
1379 |
// |
|
1380 |
// |
|
1381 |
{ |
|
1382 |
TInt r = KErrNone; |
|
1383 |
||
1384 |
test.Start(_L("Testing writing to password store unlocks the card")); |
|
1385 |
||
1386 |
test.Next(_L("open connection")); |
|
1387 |
RFs fs; |
|
1388 |
test(fs.Connect() == KErrNone); |
|
1389 |
||
1390 |
// Clear the password store for when function run on its own. |
|
1391 |
TMediaPassword& nulPWrd = *PWDs[0]; |
|
1392 |
TMediaPassword testPassword((const TUint8*) "xyz"); |
|
1393 |
||
1394 |
test(TBLD.WritePasswordData(nulPWrd) == KErrNone);// empty |
|
1395 |
test(TBLD.PasswordStoreLengthInBytes() == 0); |
|
1396 |
||
1397 |
test.Next(_L("lock card")); |
|
1398 |
test.Next(_L("assign test password")); |
|
1399 |
r = TBLD.SetPassword(nulPWrd, testPassword, EFalse); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1400 |
test_KErrNone(r); |
0 | 1401 |
|
1402 |
RemountMedia(); // card is now locked |
|
1403 |
||
1404 |
// test Caps() reports that card is locked |
|
1405 |
test.Next(_L("test card is locked")); |
|
1406 |
TLocalDriveCapsV5 driveCaps; |
|
1407 |
TPckg<TLocalDriveCapsV5> driveCapsPkg(driveCaps); |
|
1408 |
r = TBLD.Caps(driveCapsPkg); |
|
1409 |
test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt); |
|
1410 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1411 |
test_KErrNone(r); |
0 | 1412 |
test ((driveCaps.iMediaAtt & KMediaAttLocked) != 0); |
1413 |
||
1414 |
// Write correct password to store |
|
1415 |
test.Next(_L("write correct password to store")); |
|
1416 |
||
1417 |
TPersistentStore *pstoreDef; |
|
1418 |
test((pstoreDef = new TPersistentStore) != NULL); |
|
1419 |
TPersistentStore &storeDef = *pstoreDef; |
|
1420 |
AddMapping(storeDef, CIDs[0], &testPassword); |
|
1421 |
r = TBLD.WritePasswordData(storeDef); |
|
1422 |
||
1423 |
test.Printf(_L("WritePasswordData() returned %d\n"), r); |
|
1424 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1425 |
test_KErrNone(r); |
0 | 1426 |
|
1427 |
// test Caps() reports that card is unlocked |
|
1428 |
test.Next(_L("test card is unlocked")); |
|
1429 |
r = TBLD.Caps(driveCapsPkg); |
|
1430 |
test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt); |
|
1431 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1432 |
test_KErrNone(r); |
0 | 1433 |
test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0); |
1434 |
||
1435 |
// Clear the password, remount and test card is unlocked |
|
1436 |
test.Next(_L("clear password, remount & test card is unlocked")); |
|
1437 |
test.Next(_L("clear the password")); |
|
1438 |
test(TBLD.Clear(testPassword) == KErrNone); |
|
1439 |
RemountMedia(); |
|
1440 |
test.Next(_L("test card is unlocked")); |
|
1441 |
||
1442 |
r = TBLD.Caps(driveCapsPkg); |
|
1443 |
test.Printf(_L("Caps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt); |
|
1444 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1445 |
test_KErrNone(r); |
0 | 1446 |
test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0); |
1447 |
||
1448 |
||
1449 |
delete pstoreDef; |
|
1450 |
pstoreDef = NULL; |
|
1451 |
||
1452 |
test.End(); |
|
1453 |
} |
|
1454 |
||
1455 |
||
1456 |
LOCAL_C TBool SetupDrivesForPlatform(TInt& aDrive, TInt &aRFsDriveNum) |
|
1457 |
/** |
|
1458 |
* Finds a suitable drive for the password store test |
|
1459 |
* |
|
1460 |
* @param aDrive The number of the local drive to test |
|
1461 |
* @return TBool ETrue if a suitable drive is found, EFalse otherwise. |
|
1462 |
*/ |
|
1463 |
{ |
|
1464 |
||
1465 |
TDriveInfoV1Buf diBuf; |
|
1466 |
UserHal::DriveInfo(diBuf); |
|
1467 |
TDriveInfoV1 &di=diBuf(); |
|
1468 |
||
1469 |
test.Printf(_L(" iRegisteredDriveBitmask 0x%08X"), di.iRegisteredDriveBitmask); |
|
1470 |
||
1471 |
aDrive = -1; |
|
1472 |
||
1473 |
TLocalDriveCapsV5Buf capsBuf; |
|
1474 |
TBusLocalDrive TBLD; |
|
1475 |
TLocalDriveCapsV5& caps = capsBuf(); |
|
1476 |
TPtrC8 localSerialNum; |
|
1477 |
TInt registeredDriveNum = 0; |
|
1478 |
for(aDrive=0; aDrive < KMaxLocalDrives; aDrive++) |
|
1479 |
{ |
|
1480 |
TInt driveNumberMask = 1 << aDrive; |
|
1481 |
if ((di.iRegisteredDriveBitmask & driveNumberMask) == 0) |
|
1482 |
continue; |
|
1483 |
||
1484 |
test.Printf(_L(" Drive %d - %S\r\n"), aDrive, &di.iDriveName[registeredDriveNum]); |
|
1485 |
||
1486 |
// check that the card is readable (so we can ignore for empty card slots) |
|
1487 |
if ((di.iDriveName[registeredDriveNum].MatchF(_L("MultiMediaCard0")) == KErrNone) || |
|
1488 |
(di.iDriveName[registeredDriveNum].MatchF(_L("SDIOCard0")) == KErrNone)) |
|
1489 |
{ |
|
1490 |
||
1491 |
TBool TBLDChangedFlag; |
|
1492 |
TInt r = TBLD.Connect(aDrive, TBLDChangedFlag); |
|
1493 |
//test.Printf(_L(" Connect returned %d\n"), r); |
|
1494 |
if (r == KErrNone) |
|
1495 |
{ |
|
1496 |
r = TBLD.Caps(capsBuf); |
|
1497 |
localSerialNum.Set(caps.iSerialNum, caps.iSerialNumLength); |
|
1498 |
const TInt KSectSize = 512; |
|
1499 |
TBuf8<KSectSize> sect; |
|
1500 |
r = TBLD.Read(0, KSectSize, sect); |
|
1501 |
//test.Printf(_L(" Read returned %d\n"), r); |
|
1502 |
||
1503 |
TBLD.Disconnect(); |
|
1504 |
if (r == KErrNone) |
|
1505 |
break; |
|
1506 |
} |
|
1507 |
} |
|
1508 |
registeredDriveNum++; |
|
1509 |
} |
|
1510 |
||
1511 |
if(aDrive == KMaxLocalDrives) |
|
1512 |
{ |
|
1513 |
test.Printf(_L(" MMC Drive Not Found\r\n")); |
|
1514 |
return EFalse; |
|
1515 |
} |
|
1516 |
||
1517 |
// Work out the file server drive number (which isn't necessarily the same |
|
1518 |
// as the TBusLocalDrive drive number) |
|
1519 |
RFs theFs; |
|
1520 |
test(theFs.Connect() == KErrNone); |
|
1521 |
||
1522 |
TInt i; |
|
1523 |
for (i = EDriveA; i < EDriveZ; i++) |
|
1524 |
{ |
|
1525 |
TMediaSerialNumber serialNum; |
|
1526 |
TInt r = theFs.GetMediaSerialNumber(serialNum, i); |
|
1527 |
TInt len = serialNum.Length(); |
|
1528 |
TInt n; |
|
1529 |
for (n=0; n<len; n+=16) |
|
1530 |
{ |
|
1531 |
TBuf16<16*3 +1> buf; |
|
1532 |
for (TInt m=n; m<n+16; m++) |
|
1533 |
{ |
|
1534 |
TBuf16<3> hexBuf; |
|
1535 |
hexBuf.Format(_L("%02X "),serialNum[m]); |
|
1536 |
buf.Append(hexBuf); |
|
1537 |
} |
|
1538 |
buf.Append(_L("\n")); |
|
1539 |
test.Printf(buf); |
|
1540 |
} |
|
1541 |
if (serialNum.Compare(localSerialNum) == 0) |
|
1542 |
{ |
|
1543 |
TVolumeInfo vi; |
|
1544 |
r = theFs.Volume(vi, i); |
|
1545 |
TBool sizeMatch = (vi.iSize < caps.iSize); |
|
1546 |
if (sizeMatch) |
|
1547 |
{ |
|
1548 |
aRFsDriveNum = i; |
|
1549 |
break; |
|
1550 |
} |
|
1551 |
} |
|
1552 |
||
1553 |
} |
|
1554 |
if (i == EDriveZ) |
|
1555 |
{ |
|
1556 |
test.Printf(_L(" RFs MMC Drive Not Found\r\n")); |
|
1557 |
return EFalse; |
|
1558 |
} |
|
1559 |
||
1560 |
theFs.Close(); |
|
1561 |
||
1562 |
return ETrue; |
|
1563 |
} |
|
1564 |
||
1565 |
||
1566 |
TInt TestLockCard(RFs& aFs, TInt aTheMemoryCardDrive, TMediaPassword &aOldPassword, TMediaPassword& aNewPassword, TBool aStore) |
|
1567 |
{ |
|
1568 |
TMediaPassword newPassWord; |
|
1569 |
TMediaPassword oldPassWord; |
|
1570 |
TInt err=0; |
|
1571 |
TDriveInfo dInfo; |
|
1572 |
||
1573 |
aFs.Drive(dInfo, RFsDNum); |
|
1574 |
||
1575 |
newPassWord.Append(aNewPassword); |
|
1576 |
oldPassWord.Append(aOldPassword); |
|
1577 |
||
1578 |
test (dInfo.iMediaAtt & KMediaAttLockable); |
|
1579 |
||
1580 |
err=aFs.LockDrive(RFsDNum, oldPassWord, newPassWord, aStore ); |
|
1581 |
||
1582 |
aFs.Drive(dInfo, aTheMemoryCardDrive); |
|
1583 |
return err; |
|
1584 |
} |
|
1585 |
||
1586 |
TInt TestUnlockCard(RFs& aFs, TInt aTheMemoryCardDrive, TMediaPassword& aPassword, TBool aStore) |
|
1587 |
{ |
|
1588 |
TMediaPassword oldPw; |
|
1589 |
||
1590 |
oldPw.Append(aPassword); |
|
1591 |
TInt err = aFs.UnlockDrive( aTheMemoryCardDrive, oldPw, aStore); |
|
1592 |
return err; |
|
1593 |
} |
|
1594 |
||
1595 |
TInt TestClearPassword(RFs& aFs, TInt aTheMemoryCardDrive, TMediaPassword& aPassword) |
|
1596 |
{ |
|
1597 |
TMediaPassword oldPwd = aPassword; |
|
1598 |
||
1599 |
TInt err = aFs.ClearPassword( aTheMemoryCardDrive, oldPwd ); |
|
1600 |
return err; |
|
1601 |
} |
|
1602 |
||
1603 |
||
1604 |
TInt ExecuteForcedEraseTestL(RFs& aFs, TInt aTheMemoryCardDrive) |
|
1605 |
{ |
|
1606 |
TInt err = aFs.ErasePassword( aTheMemoryCardDrive ); |
|
1607 |
return err; |
|
1608 |
} |
|
1609 |
||
1610 |
||
1611 |
TBool TestLocked(RFs& aFs, TInt aTheMemoryCardDrive) |
|
1612 |
{ |
|
1613 |
TDriveInfo info; |
|
1614 |
||
1615 |
TInt r = aFs.Drive(info, aTheMemoryCardDrive); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1616 |
test_KErrNone(r); |
0 | 1617 |
|
1618 |
return (info.iMediaAtt & KMediaAttLocked)?(TBool)ETrue:(TBool)EFalse; |
|
1619 |
} |
|
1620 |
||
1621 |
void WaitForPowerDownLock(RFs& aFs, TInt aTheMemoryCardDrive) |
|
1622 |
{ |
|
1623 |
test.Printf(_L("Waiting for stack to power down...\n")); |
|
1624 |
TInt n; |
|
1625 |
for (n=0; n<30 && !TestLocked(aFs, aTheMemoryCardDrive); n++) |
|
1626 |
{ |
|
1627 |
User::After(1000000); |
|
1628 |
} |
|
1629 |
test(n < 30); |
|
1630 |
test(TestLocked(aFs, aTheMemoryCardDrive)); // should now be locked |
|
1631 |
} |
|
1632 |
||
1633 |
void WaitForPowerDownUnlock(RFs& /*aFs*/, TInt /*aTheMemoryCardDrive*/) |
|
1634 |
{ |
|
1635 |
test.Printf(_L("Allow some time for stack to power down")); |
|
1636 |
for (TUint i=0; i < 80; ++i) |
|
1637 |
{ |
|
1638 |
User::After(100000); |
|
1639 |
test.Printf(_L(".")); |
|
1640 |
} |
|
1641 |
test.Printf(_L("\n")); |
|
1642 |
} |
|
1643 |
||
1644 |
/* |
|
1645 |
INC103721: |
|
1646 |
The MMC Media drivers do not power up the MMC Stack to retrieve card status, |
|
1647 |
the following tests ensure that the 'lock status' is correctly returned after a |
|
1648 |
stack power down. |
|
1649 |
*/ |
|
1650 |
LOCAL_C void TestPowerDownStatus() |
|
1651 |
{ |
|
1652 |
TInt r = KErrNone; |
|
1653 |
TLocalDriveCapsV5 driveCaps; |
|
1654 |
TPckg<TLocalDriveCapsV5> driveCapsPkg(driveCaps); |
|
1655 |
TMediaPassword password = (TUint8*) "salasana"; |
|
1656 |
TMediaPassword oldpassword; |
|
1657 |
||
1658 |
test.Start(_L("Testing Power Down Status Reporting")); |
|
1659 |
||
1660 |
test.Next(_L("Open Connection")); |
|
1661 |
RFs fs; |
|
1662 |
test(fs.Connect() == KErrNone); |
|
1663 |
||
1664 |
// Lock card (with password stored) |
|
1665 |
test.Next(_L("Locking Card - Password Stored")); |
|
1666 |
||
1667 |
test.Next(_L("Locking card (Successful)")) ; |
|
1668 |
r = TestLockCard(fs, RFsDNum, oldpassword, password, ETrue); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1669 |
test_KErrNone(r); |
0 | 1670 |
|
1671 |
test(!TestLocked(fs, RFsDNum)); // not locked yet as stack hasn't powered down |
|
1672 |
||
1673 |
test.Next(_L("Card reports unlocked - before PowerDown")); |
|
1674 |
r = TBLD.Caps(driveCapsPkg); |
|
1675 |
test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt); |
|
1676 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1677 |
test_KErrNone(r); |
0 | 1678 |
test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0); |
1679 |
||
1680 |
WaitForPowerDownUnlock(fs, RFsDNum); |
|
1681 |
||
1682 |
test.Next(_L("Check card reports unlocked - after PowerDown")); |
|
1683 |
r = TBLD.Caps(driveCapsPkg); |
|
1684 |
test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt); |
|
1685 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1686 |
test_KErrNone(r); |
0 | 1687 |
test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0); |
1688 |
||
1689 |
test.Next(_L("Clear password (Successful)")); |
|
1690 |
r = TestClearPassword(fs, RFsDNum, password); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1691 |
test_KErrNone(r); |
0 | 1692 |
|
1693 |
// Lock card (without password in store) |
|
1694 |
test.Next(_L("Locking card - Password NOT Stored")); |
|
1695 |
||
1696 |
test.Next(_L("Locking card (Successful)")); |
|
1697 |
r = TestLockCard(fs, RFsDNum, oldpassword, password, EFalse); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1698 |
test_KErrNone(r); |
0 | 1699 |
|
1700 |
test(!TestLocked(fs, RFsDNum)); // not locked yet as stack hasn't powered down |
|
1701 |
||
1702 |
test.Next(_L("Card is reports Unlocked - before PowerDown")); |
|
1703 |
r = TBLD.Caps(driveCapsPkg); |
|
1704 |
test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt); |
|
1705 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1706 |
test_KErrNone(r); |
0 | 1707 |
test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0); |
1708 |
||
1709 |
WaitForPowerDownLock(fs, RFsDNum); |
|
1710 |
||
1711 |
test.Next(_L("Card reports Locked - after PowerDown")); |
|
1712 |
r = TBLD.Caps(driveCapsPkg); |
|
1713 |
test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt); |
|
1714 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1715 |
test_KErrNone(r); |
0 | 1716 |
test ((driveCaps.iMediaAtt & KMediaAttLocked) != 0); |
1717 |
||
1718 |
// Unlock card |
|
1719 |
test.Next(_L("Unlock 'locked' Card - Password Stored")); |
|
1720 |
||
1721 |
test.Next(_L("Unlocking card (Successful)")) ; |
|
1722 |
r = TestUnlockCard(fs, RFsDNum, password, ETrue); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1723 |
test_KErrNone(r); |
0 | 1724 |
test (!TestLocked(fs, RFsDNum)); // not locked as stack hasn't powered down |
1725 |
||
1726 |
test.Next(_L("Card reports unlocked - before PowerDown")); |
|
1727 |
r = TBLD.Caps(driveCapsPkg); |
|
1728 |
test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt); |
|
1729 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1730 |
test_KErrNone(r); |
0 | 1731 |
test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0); |
1732 |
||
1733 |
WaitForPowerDownUnlock(fs, RFsDNum); |
|
1734 |
||
1735 |
test.Next(_L("Card reports unlocked - after PowerDown")); |
|
1736 |
r = TBLD.Caps(driveCapsPkg); |
|
1737 |
test.Printf(_L("\tCaps() returned %d , iMediaAtt %08x\n"), r, driveCaps.iMediaAtt); |
|
1738 |
||
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1739 |
test_KErrNone(r); |
0 | 1740 |
test ((driveCaps.iMediaAtt & KMediaAttLocked) == 0); |
1741 |
||
1742 |
test.Next(_L("Clearing Password (Successful)")); |
|
1743 |
r = TestClearPassword(fs, RFsDNum, password); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1744 |
test_KErrNone(r); |
0 | 1745 |
|
1746 |
fs.Close(); |
|
1747 |
||
1748 |
test.End(); |
|
1749 |
} |
|
1750 |
||
1751 |
LOCAL_C void TestFsLockUnlock() |
|
1752 |
{ |
|
1753 |
TInt r = KErrNone; |
|
1754 |
||
1755 |
test.Start(_L("Testing RFs APIs")); |
|
1756 |
||
1757 |
test.Next(_L("open connection")); |
|
1758 |
RFs fs; |
|
1759 |
test(fs.Connect() == KErrNone); |
|
1760 |
||
1761 |
||
1762 |
test.Next(_L("test locking card")); |
|
1763 |
||
1764 |
TMediaPassword oldpassword; |
|
1765 |
TMediaPassword newpassword = (TUint8*) "salasana"; |
|
1766 |
TMediaPassword wrongpwd = (TUint8*) "failtest"; |
|
1767 |
||
1768 |
r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1769 |
test_KErrNone(r); |
0 | 1770 |
test(!TestLocked(fs, RFsDNum)); // not locked yet as stack hasn't powered down |
1771 |
||
1772 |
test.Next(_L("test unlocking fails if still powered up")); |
|
1773 |
r = TestUnlockCard(fs, RFsDNum, newpassword, EFalse); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1774 |
test_Value(r, r == KErrAlreadyExists); // already unlocked (as stack won't have powered down yet) |
0 | 1775 |
test (!TestLocked(fs, RFsDNum)); |
1776 |
||
1777 |
test.Next(_L("test clearing succeeds if still powered up")); |
|
1778 |
r = TestClearPassword(fs, RFsDNum, newpassword); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1779 |
test_KErrNone(r); |
0 | 1780 |
test(!TestLocked(fs, RFsDNum)); |
1781 |
||
1782 |
test.Next(_L("test locking card again")); |
|
1783 |
r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1784 |
test_KErrNone(r); |
0 | 1785 |
test(!TestLocked(fs, RFsDNum)); // not locked yet as stack hasn't powered down |
1786 |
||
1787 |
WaitForPowerDownLock(fs, RFsDNum); |
|
1788 |
||
1789 |
// DEF111681: CheckDisk is returning bad error code when run on locked SD card |
|
1790 |
// RFs::CheckDisk() should return KErrNone or KErrLocked (not KErrCorrupt) if the card is locked and the |
|
1791 |
// stack powers down |
|
1792 |
// NB For FAT16 cards, the FAT will be entirely cached so CheckDisk will not actually access the media |
|
1793 |
// so KErrNone will be returned. For FAT32 cards, KErrLocked will be returned. |
|
1794 |
test.Next(_L("test CheckDisk() returns KErrLocked if the card is locked and the stack powered down")); |
|
1795 |
WaitForPowerDownLock(fs, RFsDNum); |
|
1796 |
TFileName sessionPath; |
|
1797 |
sessionPath=_L("?:\\"); |
|
1798 |
TChar driveLetter; |
|
1799 |
r = fs.DriveToChar(RFsDNum,driveLetter); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1800 |
test_KErrNone(r); |
0 | 1801 |
sessionPath[0]=(TText)driveLetter; |
1802 |
r = fs.CheckDisk(sessionPath); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1803 |
test_Value(r, r == KErrNone || r == KErrLocked); |
0 | 1804 |
WaitForPowerDownLock(fs, RFsDNum); |
1805 |
||
1806 |
||
1807 |
// DEF111700: Formatting a locked SD/MMC leaves it in a bad state (causes panics later) |
|
1808 |
// This was caused by format calling TDrive::MountMedia(ETrue) and then not dismounting |
|
1809 |
r = fs.RemountDrive(RFsDNum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1810 |
test_KErrNone(r); |
0 | 1811 |
RFormat fmt; |
1812 |
TPckgBuf<TInt> stepPkg; |
|
1813 |
TDriveUnit driveUnit(RFsDNum); |
|
1814 |
TDriveName driveName = driveUnit.Name(); |
|
1815 |
test.Next(_L("format locked card")); |
|
1816 |
r = fmt.Open(fs, driveName, EHighDensity, stepPkg()); |
|
1817 |
if (r != KErrLocked) |
|
1818 |
test.Printf(_L("RFormat::Next() returned %d\n"), r); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1819 |
test_Value(r, r == KErrLocked); |
0 | 1820 |
test.Printf(_L("\n")); |
1821 |
fmt.Close(); |
|
1822 |
r = fs.CheckDisk(sessionPath); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1823 |
test_Value(r, r == KErrLocked); |
0 | 1824 |
|
1825 |
||
1826 |
test.Next(_L("test unlocking fails after powered down & unlocked with wrong password")); |
|
1827 |
r = TestUnlockCard(fs, RFsDNum, wrongpwd, EFalse); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1828 |
test_Value(r, r == KErrAccessDenied); // unlocked should now fail |
0 | 1829 |
|
1830 |
test.Next(_L("test unlocking succeeds for correct password after powered down & locked")); |
|
1831 |
r = TestUnlockCard(fs, RFsDNum, newpassword, EFalse); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1832 |
test_KErrNone(r); // unlocked should now succeed |
0 | 1833 |
|
1834 |
test.Next(_L("test unlocking fails after successful unlock")); |
|
1835 |
r = TestUnlockCard(fs, RFsDNum, wrongpwd, EFalse); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1836 |
test_Value(r, r == KErrAlreadyExists); // unlocked should now succeed |
0 | 1837 |
test(!TestLocked(fs, RFsDNum)); // not locked yet as stack hasn't powered down |
1838 |
||
1839 |
test.Next(_L("test locking card with new password (with wrong password as old password)")); |
|
1840 |
r = TestLockCard(fs, RFsDNum, wrongpwd, newpassword, EFalse); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1841 |
test_Value(r, r == KErrAccessDenied); |
0 | 1842 |
test(!TestLocked(fs, RFsDNum)); // not locked yet as stack hasn't powered down |
1843 |
||
1844 |
test.Next(_L("test locking card with new password (with right password as old password)")); |
|
1845 |
r = TestLockCard(fs, RFsDNum, newpassword, wrongpwd, EFalse); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1846 |
test_KErrNone(r); |
0 | 1847 |
test(!TestLocked(fs, RFsDNum)); // not locked yet as stack hasn't powered down |
1848 |
||
1849 |
WaitForPowerDownLock(fs, RFsDNum); |
|
1850 |
||
1851 |
test.Next(_L("test clearing fails with wrong password if powered down & locked")); |
|
1852 |
r = TestClearPassword(fs, RFsDNum, newpassword); // Note: we have set the wrong password as the new password |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1853 |
test_Value(r, r == KErrAccessDenied); |
0 | 1854 |
test(TestLocked(fs, RFsDNum)); |
1855 |
||
1856 |
test.Next(_L("test clearing succeeds with right password if powered down & locked")); |
|
1857 |
r = TestClearPassword(fs, RFsDNum, wrongpwd); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1858 |
test_KErrNone(r); |
0 | 1859 |
test(!TestLocked(fs, RFsDNum)); |
1860 |
||
1861 |
test.Next(_L("test locking card again")); |
|
1862 |
r = TestLockCard(fs, RFsDNum, oldpassword, newpassword, EFalse); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1863 |
test_KErrNone(r); |
0 | 1864 |
test(!TestLocked(fs, RFsDNum)); // not locked yet as stack hasn't powered down |
1865 |
||
1866 |
test.Next(_L("test forced erase fails if still powered up")); |
|
1867 |
r = ExecuteForcedEraseTestL(fs, RFsDNum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1868 |
test_Value(r, r == KErrAccessDenied); // fails because card is not yet locked |
0 | 1869 |
|
1870 |
WaitForPowerDownLock(fs, RFsDNum); |
|
1871 |
||
1872 |
||
1873 |
test.Next(_L("test forced erase succeeds if powered down & locked")); |
|
1874 |
r = ExecuteForcedEraseTestL(fs, RFsDNum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1875 |
test_KErrNone(r); |
0 | 1876 |
|
1877 |
fs.Close(); |
|
1878 |
test.End(); |
|
1879 |
} |
|
1880 |
||
1881 |
||
1882 |
||
1883 |
/** |
|
1884 |
PDEF104639: Phone automatically reboots when inserting memory card with password. |
|
1885 |
Testing that TheFs.UnlockDrive() results in a notification - and doesn't crash the file server (!) |
|
1886 |
*/ |
|
1887 |
void TestUnlockDriveNotifyChange() |
|
1888 |
{ |
|
1889 |
RFs fs; |
|
1890 |
test(fs.Connect() == KErrNone); |
|
1891 |
||
1892 |
TFileName sessionPath; |
|
1893 |
sessionPath=_L("?:\\"); |
|
1894 |
TChar driveLetter; |
|
1895 |
TInt r=fs.DriveToChar(RFsDNum,driveLetter); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1896 |
test_KErrNone(r); |
0 | 1897 |
sessionPath[0]=(TText)driveLetter; |
1898 |
r=fs.SetSessionPath(sessionPath); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1899 |
test_KErrNone(r); |
0 | 1900 |
|
1901 |
TInt nRes; |
|
1902 |
TDriveInfo dInfo; |
|
1903 |
||
1904 |
nRes = fs.Drive(dInfo, RFsDNum); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1905 |
test_KErrNone(nRes); |
0 | 1906 |
if (!(dInfo.iMediaAtt & KMediaAttLockable)) |
1907 |
{ |
|
1908 |
test.Printf(_L("Drive %d is not lockable %d\n"), RFsDNum); |
|
1909 |
fs.Close(); |
|
1910 |
return; |
|
1911 |
} |
|
1912 |
||
1913 |
// attempt to lock the drive |
|
1914 |
TMediaPassword oldPassword; |
|
1915 |
TMediaPassword newPassword = (TUint8*) "salasana"; |
|
1916 |
nRes = fs.LockDrive(RFsDNum, oldPassword, newPassword, EFalse ); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1917 |
test_KErrNone(nRes); |
0 | 1918 |
|
1919 |
WaitForPowerDownLock(fs, RFsDNum); |
|
1920 |
||
1921 |
TRequestStatus reqStatNotify1(KRequestPending); |
|
1922 |
||
1923 |
//-- set up notifier |
|
1924 |
fs.NotifyChange(ENotifyAll, reqStatNotify1, sessionPath); |
|
1925 |
test(reqStatNotify1.Int() == KRequestPending); |
|
1926 |
||
1927 |
//-- unlock the drive |
|
1928 |
nRes = fs.UnlockDrive(RFsDNum, newPassword, EFalse); |
|
1929 |
test.Printf(_L("UnlockDrive() %d reqStatNotify1 %d\n"), nRes, reqStatNotify1.Int()); |
|
1930 |
||
1931 |
//-- check that the notifier worked |
|
1932 |
User::WaitForRequest(reqStatNotify1); |
|
1933 |
test(reqStatNotify1.Int() == KErrNone); |
|
1934 |
||
1935 |
r = TestClearPassword(fs, RFsDNum, newPassword); |
|
109
b3a1d9898418
Revision: 201019
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
33
diff
changeset
|
1936 |
test_KErrNone(r); |
0 | 1937 |
test(!TestLocked(fs, RFsDNum)); |
1938 |
||
1939 |
||
1940 |
||
1941 |
fs.Close(); |
|
1942 |
} |
|
1943 |
||
1944 |
||
1945 |
LOCAL_C void RunTests() |
|
1946 |
// |
|
1947 |
// Main test routine. Calls other test functions. |
|
1948 |
// |
|
1949 |
{ |
|
1950 |
__UHEAP_MARK; |
|
1951 |
||
1952 |
if(TBLDNum == -1) |
|
1953 |
{ |
|
1954 |
if(!SetupDrivesForPlatform(TBLDNum, RFsDNum)) |
|
1955 |
{ |
|
1956 |
test.Printf(_L("MMC Drive Not Found - Skipping test\r\n")); |
|
1957 |
return; |
|
1958 |
} |
|
1959 |
} |
|
1960 |
||
1961 |
test.Next(_L("Connecting TBLD")); |
|
1962 |
test(TBLD.Connect(TBLDNum, TBLDChangedFlag) == KErrNone); |
|
1963 |
||
1964 |
test.Next(_L("Allocating test data")); |
|
1965 |
AllocateTestData(); |
|
1966 |
||
1967 |
test.Next(_L("Testing locking / unlocking using file server APIs")); |
|
1968 |
TestFsLockUnlock(); |
|
1969 |
||
1970 |
test.Next(_L("Testing Power Down Status Reporting using file server APIs")); |
|
1971 |
TestPowerDownStatus(); |
|
1972 |
||
1973 |
test.Next(_L("Testing RFs::NotifyChange() with RFs::UnlockDrive()")); |
|
1974 |
TestUnlockDriveNotifyChange(); |
|
1975 |
||
1976 |
test.Next(_L("Forced Erase")); |
|
1977 |
TestFormatErase(); |
|
1978 |
test.Next(_L("Testing store management")); |
|
1979 |
TestStaticStore(); |
|
1980 |
test.Next(_L("Testing locking functions")); |
|
1981 |
TestLockUnlock(); |
|
1982 |
test.Next(_L("Testing Elide Passwords")); |
|
1983 |
TestElidePasswords(); |
|
1984 |
test.Next(_L("Testing Null Passwords")); |
|
1985 |
TestNullPasswords(); |
|
1986 |
test.Next(_L("Testing controller store")); |
|
1987 |
TestControllerStore(); |
|
1988 |
test.Next(_L("Testing auto unlock")); |
|
1989 |
TestAutoUnlock(); |
|
1990 |
test.Next(_L("Testing password file")); |
|
1991 |
TestPasswordFile(); |
|
1992 |
test.Next(_L("Testing writing a valid password to store unlocks card")); |
|
1993 |
TestWriteToPasswordStoreUnlocksCard(); |
|
1994 |
||
1995 |
test.Next(_L("Disconnecting TBLD")); |
|
1996 |
TBLD.Disconnect(); |
|
1997 |
||
1998 |
test.Next(_L("Deleting test data")); |
|
1999 |
DeleteTestData(); |
|
2000 |
||
2001 |
__UHEAP_MARKEND; |
|
2002 |
} |
|
2003 |
||
2004 |
||
2005 |
TInt E32Main() |
|
2006 |
{ |
|
2007 |
||
2008 |
test.Title(); |
|
2009 |
test.Start(_L("E32Main")); |
|
2010 |
||
2011 |
RunTests(); |
|
2012 |
||
2013 |
test.End(); |
|
2014 |
test.Close(); |
|
2015 |
||
2016 |
return KErrNone; |
|
2017 |
} |
|
2018 |