|
1 // Copyright (c) 2010 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/rpmb/d_rpmb.cpp |
|
15 // LDD for testing RPMB kernel extension |
|
16 // |
|
17 // |
|
18 |
|
19 /** |
|
20 @file |
|
21 @internalComponent |
|
22 @prototype |
|
23 */ |
|
24 |
|
25 #include "d_rpmb.h" |
|
26 #include "../t_rpmb.h" |
|
27 |
|
28 _LIT(KRpmbTestThreadName,"RpmbTestThread"); |
|
29 const TInt KRpmbTestPriority = 24; |
|
30 |
|
31 TDfcQue RpmbTestDfcQ; |
|
32 TDfc* DfcPtr; |
|
33 |
|
34 // please read this before uncommenting out #define RPMBTESTS_TRY_TO_WRITE_KEY: |
|
35 // Don't want to write key 'pre production' on real device as this will lock |
|
36 // the system out of the RPMB partition (the key should be preprogrammed as |
|
37 // part of the production process so that the system has access to the key - |
|
38 // if the key has already been written it can't be written again). |
|
39 // #define RPMBTESTS_TRY_TO_WRITE_KEY |
|
40 |
|
41 |
|
42 /**************************************** |
|
43 Implementation of DRpmbTestFactory class |
|
44 *****************************************/ |
|
45 |
|
46 DRpmbTestFactory::DRpmbTestFactory() |
|
47 { |
|
48 } |
|
49 |
|
50 DRpmbTestFactory::~DRpmbTestFactory() |
|
51 { |
|
52 } |
|
53 |
|
54 TInt DRpmbTestFactory::Create(DLogicalChannelBase*& aChannel) |
|
55 { |
|
56 aChannel = new DRpmbTest; |
|
57 return KErrNone; |
|
58 } |
|
59 |
|
60 TInt DRpmbTestFactory::Install() |
|
61 { |
|
62 return SetName(&KRpmbTestLddName); |
|
63 } |
|
64 |
|
65 void DRpmbTestFactory::GetCaps(TDes8& /*aDes*/) const |
|
66 // implementation required since DLogicalDevice::GetCaps is pure virtual |
|
67 { |
|
68 // do nothing |
|
69 } |
|
70 |
|
71 |
|
72 static void RpmbTestDfcFunction(TAny* /*aPtr*/) |
|
73 { |
|
74 DRpmbDevice * rpmb; |
|
75 rpmb = new DRpmbDevice; |
|
76 TInt r = rpmb->Open(0); |
|
77 Kern::Printf("%S Early on DRpmbDevice::Open test returned %d",&KDRpmbTestBanner, r); |
|
78 // ASSERT to indicate test failure if DRpmbDevice::Open() returned error |
|
79 __ASSERT_ALWAYS((r==KErrNone), Kern::Fault(__FILE__, __LINE__)); |
|
80 rpmb->Close(); |
|
81 delete rpmb; |
|
82 // run more extensive tests early on |
|
83 // note the unconventional use of a class derived from DLogicalChannelBase which is justified |
|
84 // in the current context to provide more startup test coverage |
|
85 DRpmbTest * test; |
|
86 test = new DRpmbTest; |
|
87 // while a call to DRpmbTest::DRpmbDeviceTests() works in this context |
|
88 // a call to DRpmbTest::RpmbStackTests() would fail as DRpmbTest::DoCreate() wouldn't be |
|
89 // called so that DRpmbTest::iStackSemPtr wouldn't get set up properly so that when it |
|
90 // was uaed an exception would be generated |
|
91 r = test->DRpmbDeviceTests(); |
|
92 Kern::Printf("%S Early on DRpmbTest::DRpmbDeviceTests() returned %d",&KDRpmbTestBanner, r); |
|
93 // ASSERT to indicate test failure |
|
94 __ASSERT_ALWAYS((r==KErrNone), Kern::Fault(__FILE__, __LINE__)); |
|
95 // not safe to delete test as not setup conventionally DRpmbTest::DoCreate() wasn't called |
|
96 // at setup and DLogicalChannelBase::~DLogicalChannelBase__sub_object() would generate an |
|
97 // exception |
|
98 } |
|
99 |
|
100 |
|
101 /******************************** |
|
102 Entry point for RPMB test driver |
|
103 *********************************/ |
|
104 |
|
105 DECLARE_STANDARD_EXTENSION() |
|
106 { |
|
107 TInt r = Kern::DfcQInit(&RpmbTestDfcQ,KRpmbTestPriority,&KRpmbTestThreadName);; |
|
108 if (r != KErrNone) |
|
109 return r; |
|
110 DfcPtr = new TDfc(RpmbTestDfcFunction,NULL, &RpmbTestDfcQ, KMaxDfcPriority-7); |
|
111 DfcPtr->Enque(); |
|
112 return KErrNone; |
|
113 } |
|
114 |
|
115 DECLARE_EXTENSION_LDD() |
|
116 { |
|
117 return new DRpmbTestFactory; |
|
118 } |
|
119 |
|
120 /********************************* |
|
121 Implementation of DRpmbTest class |
|
122 **********************************/ |
|
123 |
|
124 DRpmbTest::DRpmbTest(): |
|
125 // initialise parameters |
|
126 iStackSemPtr(NULL), |
|
127 iPowerSemPtr(NULL), |
|
128 iSessionEndCallBack(DRpmbTest::StackCallBack, this) |
|
129 { |
|
130 } |
|
131 |
|
132 DRpmbTest::~DRpmbTest() |
|
133 { |
|
134 |
|
135 iBusCallBack.Remove(); |
|
136 |
|
137 if (iPowerSemPtr) |
|
138 { |
|
139 iPowerSemPtr->Close(NULL); |
|
140 } |
|
141 if (iStackSemPtr) |
|
142 { |
|
143 iStackSemPtr->Close(NULL); |
|
144 } |
|
145 if (iSession) |
|
146 { |
|
147 delete iSession; |
|
148 } |
|
149 } |
|
150 |
|
151 TInt DRpmbTest::DoCreate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& /*aVer*/) |
|
152 { |
|
153 TInt r = KErrNone; |
|
154 r = Kern::SemaphoreCreate(iStackSemPtr, _L("DRpmbStackSem"), 0); |
|
155 return r; |
|
156 } |
|
157 |
|
158 TInt DRpmbTest::Request(TInt aFunction, TAny* /*a1*/, TAny* /*a2*/) |
|
159 { |
|
160 TInt r = KErrNotSupported; |
|
161 switch (aFunction) |
|
162 { |
|
163 case RTestRpmb::ERunTests: |
|
164 { |
|
165 // respond to user side request |
|
166 // execute tests for RPMB kernel extension |
|
167 // run standatd tests that use the DRpmbDevice interface |
|
168 Kern::Printf(" "); |
|
169 Kern::Printf("%S << START DRpmbDevice TESTS >>", &KDRpmbTestBanner); |
|
170 r = DRpmbDeviceTests(); |
|
171 if (r != KErrNone) |
|
172 { |
|
173 Kern::Printf("%S DPrmbDevice test FAILED", &KDRpmbTestBanner); |
|
174 break; |
|
175 } |
|
176 Kern::Printf("%S >> ALL DRpmbDevice TESTS PASSED", &KDRpmbTestBanner); |
|
177 // run tests that use the MMC stack bypassing the RPMB kernel extension |
|
178 Kern::Printf(" "); |
|
179 Kern::Printf("%S << START STACK TESTS >>", &KDRpmbTestBanner); |
|
180 r = RpmbStackTests(); |
|
181 if (r != KErrNone) |
|
182 { |
|
183 Kern::Printf("%S stack test FAILED", &KDRpmbTestBanner); |
|
184 break; |
|
185 } |
|
186 Kern::Printf("%S >> ALL STACK TESTS PASSED", &KDRpmbTestBanner); |
|
187 break; |
|
188 } |
|
189 default: |
|
190 break; |
|
191 } |
|
192 return r; |
|
193 } |
|
194 |
|
195 |
|
196 // test RPMB using the DRpmbDevice interface |
|
197 TInt DRpmbTest::DRpmbDeviceTests() |
|
198 // open interface and make data write, ket write, counter read and data write accesses |
|
199 { |
|
200 TInt size = (TInt)(2*KRpmbOneFramePacketLength); |
|
201 |
|
202 NKern::ThreadEnterCS(); |
|
203 iRequest = (TUint8 *)Kern::Alloc(size); |
|
204 NKern::ThreadLeaveCS(); |
|
205 |
|
206 iResponse = iRequest + KRpmbOneFramePacketLength; |
|
207 |
|
208 TInt r = SendAccessRequestNotOpen(); |
|
209 |
|
210 if (r==KErrNone) |
|
211 { |
|
212 r = OpenWithBadIndex(); |
|
213 } |
|
214 |
|
215 if (r==KErrNone) |
|
216 { |
|
217 r = MultipleOpen(); |
|
218 } |
|
219 |
|
220 if (r==KErrNone) |
|
221 { |
|
222 r = iRpmb.Open(0); |
|
223 } |
|
224 |
|
225 if (r!=KErrNone) |
|
226 { |
|
227 Kern::Printf("%S DRpmbTest::DRpmbDeviceTest DRpmbDevice open error = %d", |
|
228 &KDRpmbTestBanner, r); |
|
229 } |
|
230 else |
|
231 { |
|
232 r = SendAccessRequestBadParms(); |
|
233 } |
|
234 |
|
235 if (r==KErrNone) |
|
236 { |
|
237 r = InvalidRequestId(); |
|
238 } |
|
239 |
|
240 if (r==KErrNone) |
|
241 { |
|
242 r = IsKeyProgrammed(); |
|
243 } |
|
244 |
|
245 // Don't want to write key 'pre production' on real device as this will lock |
|
246 // the system out of the RPMB partition (the key should be preprogrammed as |
|
247 // part of the production process so that the system has access to the key - |
|
248 // if the key has already been written it can't be written again) |
|
249 #ifdef RPMBTESTS_TRY_TO_WRITE_KEY |
|
250 if (r==KErrNone) |
|
251 { |
|
252 r = WriteKey(); |
|
253 } |
|
254 #endif |
|
255 |
|
256 if (r==KErrNone) |
|
257 { |
|
258 r = ReadWriteCounter(); |
|
259 } |
|
260 |
|
261 if (r==KErrNone) |
|
262 { |
|
263 r = ReadData(); |
|
264 } |
|
265 |
|
266 iRpmb.Close(); |
|
267 |
|
268 NKern::ThreadEnterCS(); |
|
269 |
|
270 Kern::Free(iRequest); |
|
271 |
|
272 NKern::ThreadLeaveCS(); |
|
273 |
|
274 return r; |
|
275 } |
|
276 |
|
277 TInt DRpmbTest::SendAccessRequestNotOpen() |
|
278 // test cases where DRpmbDevice::SendAccessRequest() is called |
|
279 // 1.) before DRpmbDevice::Open() is ever called |
|
280 // 2,) after DRpmbDevice::Close() has been called but before DRpmbDevice::Open() is called |
|
281 { |
|
282 Kern::Printf("%S DRpmbDevice::SendAccessRequest not open test", &KDRpmbTestBanner); |
|
283 // wrap up IO buffers in descriptors to pass across interface |
|
284 |
|
285 TPtr8 request(iRequest,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
286 TPtr8 response(iResponse,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
287 |
|
288 |
|
289 // test call DRpmbDevice::SendAccessRequest before EVER calling open |
|
290 |
|
291 TInt r = iRpmb.SendAccessRequest(request, response); |
|
292 if (r != KErrNotReady) |
|
293 { |
|
294 Kern::Printf("%S SendAccessRequest not open test, before EVER opening, unexpected error = %d", |
|
295 &KDRpmbTestBanner, r); |
|
296 return KErrGeneral; |
|
297 } |
|
298 |
|
299 // test open and close and call again |
|
300 r = iRpmb.Open(0); |
|
301 if (r != KErrNone) |
|
302 { |
|
303 Kern::Printf("%S SendAccessRequest not open test, opening, unexpected error = %d", |
|
304 &KDRpmbTestBanner, r); |
|
305 return KErrGeneral; |
|
306 } |
|
307 iRpmb.Close(); |
|
308 |
|
309 r = iRpmb.SendAccessRequest(request, response); |
|
310 if (r != KErrNotReady) |
|
311 { |
|
312 Kern::Printf("%S SendAccessRequest not open test, before opening AFTER closing, unexpected error = %d", |
|
313 &KDRpmbTestBanner, r); |
|
314 return KErrGeneral; |
|
315 } |
|
316 |
|
317 Kern::Printf("%S DRpmbDevice::SendAccessRequest not open test PASS", &KDRpmbTestBanner); |
|
318 return KErrNone; |
|
319 } |
|
320 |
|
321 |
|
322 TInt DRpmbTest::OpenWithBadIndex() |
|
323 // test case where DRpmbDevice::Open() is called with a device index of more than zero |
|
324 { |
|
325 Kern::Printf("%S DRpmbDevice::Open bad index test", &KDRpmbTestBanner); |
|
326 |
|
327 // test index > 0 |
|
328 TInt r = iRpmb.Open(1); |
|
329 if (r != KErrGeneral) |
|
330 { |
|
331 Kern::Printf("%S RpmbDevice::Open bad index test, unexpected error = %d", |
|
332 &KDRpmbTestBanner, r); |
|
333 return KErrGeneral; |
|
334 } |
|
335 |
|
336 Kern::Printf("%S DRpmbDevice::Open bad index test PASS", &KDRpmbTestBanner); |
|
337 return KErrNone; |
|
338 } |
|
339 |
|
340 |
|
341 TInt DRpmbTest::MultipleOpen() |
|
342 // test case where DRpmbDevice::Open() is called twice with the same index parameter and |
|
343 // the same instance of DRpmbDevice |
|
344 // test case where DRpmbDevice::Open() is called twice with the same index parameter and |
|
345 // a different instance of DRpmbDevice |
|
346 { |
|
347 Kern::Printf("%S DRpmbDevice::Open use more than once test", &KDRpmbTestBanner); |
|
348 |
|
349 TInt r = iRpmb.Open(0); |
|
350 if (r != KErrNone) |
|
351 { |
|
352 Kern::Printf("%S RpmbDevice::Open use more than once test first open, unexpected error = %d", |
|
353 &KDRpmbTestBanner, r); |
|
354 return KErrGeneral; |
|
355 } |
|
356 |
|
357 r = iRpmb.Open(0); |
|
358 if (r != KErrNone) |
|
359 { |
|
360 Kern::Printf("%S RpmbDevice::Open use more than once test second open, unexpected error = %d", |
|
361 &KDRpmbTestBanner, r); |
|
362 return KErrGeneral; |
|
363 } |
|
364 |
|
365 r = iRpmbSecondInstance.Open(0); |
|
366 if (r != KErrInUse) |
|
367 { |
|
368 Kern::Printf("%S RpmbDevice::Open use more than once test third open, unexpected error = %d", |
|
369 &KDRpmbTestBanner, r); |
|
370 return KErrGeneral; |
|
371 } |
|
372 |
|
373 iRpmb.Close(); |
|
374 iRpmbSecondInstance.Close(); |
|
375 |
|
376 Kern::Printf("%S DRpmbDevice::Open use more than once test PASS", &KDRpmbTestBanner); |
|
377 |
|
378 return KErrNone; |
|
379 } |
|
380 |
|
381 |
|
382 TInt DRpmbTest::SendAccessRequestBadParms() |
|
383 // test cases where DRpmbDevice::SendAccessRequest is called with secriptor arguments with invalid lengths |
|
384 { |
|
385 Kern::Printf("%S DRpmbDevice::SendAccessRequest bad parms test", &KDRpmbTestBanner); |
|
386 |
|
387 // test both lengths != KRpmbOneFramePacketLength |
|
388 TBuf<KRpmbOneFramePacketLength-1> request; |
|
389 TBuf<KRpmbOneFramePacketLength+1> response; |
|
390 request.SetLength(KRpmbOneFramePacketLength-1); |
|
391 response.SetLength(KRpmbOneFramePacketLength+1); |
|
392 |
|
393 TInt r = iRpmb.SendAccessRequest(request, response); |
|
394 if (r != KErrArgument) |
|
395 { |
|
396 Kern::Printf("%S SendAccessRequest bad parms test, both params bad, unexpected error = %d", |
|
397 &KDRpmbTestBanner, r); |
|
398 return KErrGeneral; |
|
399 } |
|
400 |
|
401 // test request length != KRpmbOneFramePacketLength |
|
402 TBuf<KRpmbOneFramePacketLength+1> request1; |
|
403 TBuf<KRpmbOneFramePacketLength> response1; |
|
404 request1.SetLength(KRpmbOneFramePacketLength+1); |
|
405 response1.SetLength(KRpmbOneFramePacketLength); |
|
406 |
|
407 r = iRpmb.SendAccessRequest(request1, response1); |
|
408 if (r != KErrArgument) |
|
409 { |
|
410 Kern::Printf("%S SendAccessRequest bad parms test, request param bad, unexpected error = %d", |
|
411 &KDRpmbTestBanner, r); |
|
412 return KErrGeneral; |
|
413 } |
|
414 |
|
415 // test response length !=KRpmbOneFramePacketLength |
|
416 TBuf<KRpmbOneFramePacketLength> request2; |
|
417 TBuf<KRpmbOneFramePacketLength-1> response2; |
|
418 request2.SetLength(KRpmbOneFramePacketLength); |
|
419 response2.SetLength(KRpmbOneFramePacketLength-1); |
|
420 |
|
421 r = iRpmb.SendAccessRequest(request1, response1); |
|
422 if (r != KErrArgument) |
|
423 { |
|
424 Kern::Printf("%S SendAccessRequest bad parms test, response param bad, unexpected error = %d", |
|
425 &KDRpmbTestBanner, r); |
|
426 return KErrGeneral; |
|
427 } |
|
428 |
|
429 |
|
430 Kern::Printf("%S DRpmbDevice::SendAccessRequest bad parms test PASS", &KDRpmbTestBanner); |
|
431 return KErrNone; |
|
432 } |
|
433 |
|
434 TInt DRpmbTest::InvalidRequestId() |
|
435 // send a request with an invalid request ID to the RPMB partition |
|
436 // when SendAccessRequest returns iResponse should not have reponse or result fields filled in |
|
437 { |
|
438 Kern::Printf("%S invalid request ID test", &KDRpmbTestBanner); |
|
439 |
|
440 // set up write request packet with blank MAC |
|
441 memset(iRequest, 0, KRpmbOneFramePacketLength); |
|
442 * (iRequest + KRpmbRequestLsbOffset) = KRpmbRequestReadResultRegister + 1; |
|
443 |
|
444 // wrap up IO buffers in descriptors to pass across interface |
|
445 TPtr8 request(iRequest,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
446 TPtr8 response(iResponse,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
447 |
|
448 TInt r = iRpmb.SendAccessRequest(request, response); |
|
449 if (r != KErrNone) |
|
450 { |
|
451 Kern::Printf("%S invalid request ID test, send request error = %d", |
|
452 &KDRpmbTestBanner, r); |
|
453 return r; |
|
454 } |
|
455 |
|
456 // check that response or result fields have not been set in response |
|
457 TUint resp = DecodeResponse(iResponse); |
|
458 TUint result = DecodeResult(iResponse); |
|
459 |
|
460 if (resp != 0x0006) |
|
461 { |
|
462 Kern::Printf("%S invalid request ID test, unexpected response = %d error", |
|
463 &KDRpmbTestBanner, resp); |
|
464 return KErrGeneral; |
|
465 } |
|
466 |
|
467 if (result != 0x0000) |
|
468 { |
|
469 Kern::Printf("%S invalid request ID test, unexpected result = %d error", |
|
470 &KDRpmbTestBanner, result); |
|
471 return KErrGeneral; |
|
472 } |
|
473 |
|
474 Kern::Printf("%S invalid requeset ID test PASS", &KDRpmbTestBanner); |
|
475 return KErrNone; |
|
476 } |
|
477 |
|
478 |
|
479 TInt DRpmbTest::IsKeyProgrammed() |
|
480 // send a data write request to the RPMB partition |
|
481 // because the request has a blank MAC (not authenticated) |
|
482 // the partition returns operation result authentication failure if the key is programmed |
|
483 // else the partition returns authentication key not programmed |
|
484 { |
|
485 Kern::Printf("%S data write test", &KDRpmbTestBanner); |
|
486 |
|
487 // set up write request packet with blank MAC |
|
488 memset(iRequest, 0, KRpmbOneFramePacketLength); |
|
489 * (iRequest + KRpmbRequestLsbOffset) = KRpmbRequestWriteData; |
|
490 |
|
491 // wrap up IO buffers in descriptors to pass across interface |
|
492 TPtr8 request(iRequest,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
493 TPtr8 response(iResponse,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
494 |
|
495 TInt r = iRpmb.SendAccessRequest(request, response); |
|
496 if (r != KErrNone) |
|
497 { |
|
498 Kern::Printf("%S data write test, send request error = %d", |
|
499 &KDRpmbTestBanner, r); |
|
500 return r; |
|
501 } |
|
502 |
|
503 TUint resp = DecodeResponse(iResponse); |
|
504 TUint result = DecodeResult(iResponse); |
|
505 |
|
506 if (resp != KRpmbResponseWriteData) |
|
507 { |
|
508 Kern::Printf("%S data write test, unexpected response = %d error", |
|
509 &KDRpmbTestBanner, resp); |
|
510 return KErrGeneral; |
|
511 } |
|
512 |
|
513 if (result == KRpmbResultKeyNotProgrammed) |
|
514 { |
|
515 iKeySet = EFalse; |
|
516 Kern::Printf("%S data write test, key NOT programmed", |
|
517 &KDRpmbTestBanner); |
|
518 } |
|
519 else if (result == KRpmbResultAuthenticationFailure) |
|
520 { |
|
521 iKeySet = ETrue; |
|
522 Kern::Printf("%S data write test, key ALREADY programmed", |
|
523 &KDRpmbTestBanner); |
|
524 } |
|
525 else |
|
526 { |
|
527 Kern::Printf("%S data write test, unexpected result = %d error", |
|
528 &KDRpmbTestBanner, result); |
|
529 return KErrGeneral; |
|
530 } |
|
531 Kern::Printf("%S data write test PASS", &KDRpmbTestBanner); |
|
532 return KErrNone; |
|
533 } |
|
534 |
|
535 TInt DRpmbTest::WriteKey() |
|
536 { |
|
537 Kern::Printf("%S write key test", &KDRpmbTestBanner); |
|
538 |
|
539 // set up write key request |
|
540 memset(iRequest, 0, KRpmbOneFramePacketLength); |
|
541 * (iRequest + KRpmbRequestLsbOffset) = KRpmbRequestWriteKey; |
|
542 // key = 0x0101010101010101010101010101010101010101010101010101010101010101 |
|
543 memset(iRequest+KRpmbKeyOffset,1, KRpmbKeyLength); |
|
544 |
|
545 // wrap up IO buffers in descriptors to pass across interface |
|
546 TPtr8 request(iRequest,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
547 TPtr8 response(iResponse,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
548 |
|
549 TInt r = iRpmb.SendAccessRequest(request, response); |
|
550 if (r != KErrNone) |
|
551 { |
|
552 Kern::Printf("%S write key test, send request error = %d", |
|
553 &KDRpmbTestBanner, r); |
|
554 return r; |
|
555 } |
|
556 |
|
557 TUint resp = DecodeResponse(iResponse); |
|
558 TUint result = DecodeResult(iResponse); |
|
559 |
|
560 if (resp != KRpmbResponseWriteKey) |
|
561 { |
|
562 Kern::Printf("%S write key test, unexpected repsponse = %d error", |
|
563 &KDRpmbTestBanner, resp); |
|
564 return KErrGeneral; |
|
565 } |
|
566 |
|
567 if (iKeySet) |
|
568 { |
|
569 if (result == KRpmbResultGeneralFailure) |
|
570 { |
|
571 Kern::Printf("%S write key test, key ALREADY written", |
|
572 &KDRpmbTestBanner); |
|
573 Kern::Printf("%S write key test PASS", |
|
574 &KDRpmbTestBanner); |
|
575 return KErrNone; |
|
576 } |
|
577 else |
|
578 { |
|
579 Kern::Printf("%S write key test, unexpected result = %d error", |
|
580 &KDRpmbTestBanner, result); |
|
581 return KErrGeneral; |
|
582 } |
|
583 } |
|
584 else |
|
585 { |
|
586 if(result == KRpmbResultOk) |
|
587 { |
|
588 Kern::Printf("%S write key test, key JUST written", |
|
589 &KDRpmbTestBanner); |
|
590 Kern::Printf("%S write key test PASS", &KDRpmbTestBanner); |
|
591 return KErrNone; |
|
592 } |
|
593 else |
|
594 { |
|
595 Kern::Printf("%S write key test unexpected result = %d error", |
|
596 &KDRpmbTestBanner, result); |
|
597 return KErrGeneral; |
|
598 } |
|
599 } |
|
600 } |
|
601 |
|
602 TInt DRpmbTest::ReadWriteCounter() |
|
603 { |
|
604 Kern::Printf("%S read write counter test", &KDRpmbTestBanner); |
|
605 |
|
606 // set up read write counter request packet |
|
607 memset(iRequest, 0, KRpmbOneFramePacketLength); |
|
608 * (iRequest + KRpmbRequestLsbOffset) = KRpmbRequestReadWriteCounter; |
|
609 |
|
610 // wrap up IO buffers in descriptors to pass across interface |
|
611 TPtr8 request(iRequest,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
612 TPtr8 response(iResponse,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
613 |
|
614 TInt r = iRpmb.SendAccessRequest(request, response); |
|
615 if (r!=KErrNone) |
|
616 { |
|
617 Kern::Printf("%S read write counter test, send request error = %d", |
|
618 &KDRpmbTestBanner, r); |
|
619 return r; |
|
620 } |
|
621 |
|
622 TUint resp = DecodeResponse(iResponse); |
|
623 TUint result = DecodeResult(iResponse); |
|
624 TUint32 counter = DecodeCounter(iResponse); |
|
625 |
|
626 if (resp != KRpmbResponseReadWriteCounter) |
|
627 { |
|
628 Kern::Printf("%S read write counter test, unexpected repsponse = %d error", |
|
629 &KDRpmbTestBanner, resp); |
|
630 return KErrGeneral; |
|
631 } |
|
632 |
|
633 #ifdef RPMBTESTS_TRY_TO_WRITE_KEY |
|
634 if (result == KRpmbResultOk) |
|
635 #else |
|
636 if (result == KRpmbResultOk || result == KRpmbResultKeyNotProgrammed) |
|
637 #endif |
|
638 { |
|
639 Kern::Printf("%S read write counter test write counter = %d", |
|
640 &KDRpmbTestBanner, counter); |
|
641 Kern::Printf("%S read write counter test PASS", &KDRpmbTestBanner); |
|
642 return KErrNone; |
|
643 } |
|
644 else |
|
645 { |
|
646 Kern::Printf("%S read write counter test, unexpected result = %d error", |
|
647 &KDRpmbTestBanner, result); |
|
648 return KErrGeneral; |
|
649 } |
|
650 } |
|
651 |
|
652 TInt DRpmbTest::ReadData() |
|
653 { |
|
654 Kern::Printf("%S read data test", &KDRpmbTestBanner); |
|
655 |
|
656 // set up read request packet |
|
657 memset(iRequest, 0, KRpmbOneFramePacketLength); |
|
658 * (iRequest + KRpmbRequestLsbOffset) = KRpmbRequestReadData; |
|
659 |
|
660 // wrap up IO buffers in descriptors to pass across interface |
|
661 TPtr8 request(iRequest,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
662 TPtr8 response(iResponse,KRpmbOneFramePacketLength,KRpmbOneFramePacketLength); |
|
663 |
|
664 TInt r=iRpmb.SendAccessRequest(request, response); |
|
665 if (r!=KErrNone) |
|
666 { |
|
667 Kern::Printf("%S read data test, send request error = %d", |
|
668 &KDRpmbTestBanner, r); |
|
669 return r; |
|
670 } |
|
671 |
|
672 TUint resp = DecodeResponse(iResponse); |
|
673 TUint result = DecodeResult(iResponse); |
|
674 |
|
675 if (resp != KRpmbResponseReadData) |
|
676 { |
|
677 Kern::Printf("%S read data test, unexpected repsponse = %d error", |
|
678 &KDRpmbTestBanner, resp); |
|
679 return KErrGeneral; |
|
680 } |
|
681 |
|
682 #ifdef RPMBTESTS_TRY_TO_WRITE_KEY |
|
683 if (result == KRpmbResultOk) |
|
684 #else |
|
685 if (result == KRpmbResultOk || result == KRpmbResultKeyNotProgrammed) |
|
686 #endif |
|
687 { |
|
688 DisplayReadData(iResponse); |
|
689 Kern::Printf("%S read data test PASS", &KDRpmbTestBanner); |
|
690 return KErrNone; |
|
691 } |
|
692 else |
|
693 { |
|
694 Kern::Printf("%S read data test, unexpected result = %d error", |
|
695 &KDRpmbTestBanner, result); |
|
696 return KErrGeneral; |
|
697 } |
|
698 } |
|
699 |
|
700 TUint DRpmbTest::DecodeResponse(TUint8 * aResp) |
|
701 { |
|
702 return (* (aResp + KRpmbResponseLsbOffset) + ((* (aResp + KRpmbResponseMsbOffset)) << 8)); |
|
703 } |
|
704 |
|
705 TUint DRpmbTest::DecodeResult(TUint8 * aResp) |
|
706 { |
|
707 return ((* (aResp + KRpmbResultLsbOffset) + ((* (aResp + KRpmbResultMsbOffset)) << 8)) |
|
708 & KRpmbResultCounterExpiredMask); |
|
709 } |
|
710 |
|
711 TUint32 DRpmbTest::DecodeCounter(TUint8 * aResp) |
|
712 { |
|
713 |
|
714 return ((* (aResp + KRpmbCounterByteOneOffset)) + ((* (aResp + KRpmbCounterByteTwoOffset)) << 8) |
|
715 + ((* (aResp + KRpmbCounterByteThreeOffset)) << 16) + ((* (aResp + KRpmbCounterByteFourOffset)) << 24)); |
|
716 } |
|
717 |
|
718 void DRpmbTest::DisplayReadData(TUint8 * aResp) |
|
719 { |
|
720 TUint8 * displayPtr = aResp + KRpmbDataOffset; |
|
721 Kern::Printf("%S data field:", &KDRpmbTestBanner); |
|
722 for (TInt i=0; i<8; i++) |
|
723 { |
|
724 Kern::Printf("%x%x%x%x %x%x%x%x %x%x%x%x %x%x%x%x %x%x%x%x %x%x%x%x %x%x%x%x %x%x%x%x", |
|
725 * displayPtr , * (displayPtr + 1), * (displayPtr + 2), * (displayPtr + 3), |
|
726 * (displayPtr + 4), * (displayPtr + 5), * (displayPtr + 6), * (displayPtr + 7), |
|
727 * (displayPtr + 8), * (displayPtr + 9), * (displayPtr + 10), * (displayPtr + 11), |
|
728 * (displayPtr + 12), * (displayPtr + 13), * (displayPtr + 14), * (displayPtr + 15), |
|
729 * (displayPtr + 16), * (displayPtr + 17), * (displayPtr + 18), * (displayPtr + 19), |
|
730 * (displayPtr + 20), * (displayPtr + 21), * (displayPtr + 22), * (displayPtr + 23), |
|
731 * (displayPtr + 24), * (displayPtr + 25), * (displayPtr + 26), * (displayPtr + 27), |
|
732 * (displayPtr + 28), * (displayPtr + 29), * (displayPtr + 30), * (displayPtr + 31)); |
|
733 displayPtr +=32; |
|
734 } |
|
735 } |
|
736 |
|
737 void DRpmbTest::StackCallBack(TAny * aSelf) |
|
738 // call back from MMC stack session |
|
739 { |
|
740 // dereference any pointer |
|
741 DRpmbTest& self = *static_cast<DRpmbTest*>(aSelf); |
|
742 // signal semaphore so that calling code progresses |
|
743 Kern::SemaphoreSignal(*(self.iStackSemPtr)); |
|
744 } |
|
745 |
|
746 TInt DRpmbTest::RpmbStackTests() |
|
747 // Test code verfies all four access types through a direct connection to the MMC protocol stack |
|
748 { |
|
749 TInt r = SetupForStackTests(); |
|
750 if (r == KErrNone) |
|
751 { |
|
752 r = StackBadIndex(); |
|
753 } |
|
754 if (r == KErrNone) |
|
755 { |
|
756 r = StackIsKeyProgrammed(); |
|
757 } |
|
758 // Don't want to write key 'pre production' on a real device as this will lock |
|
759 // the system out of the RPMB partition (the key should be preprogrammed as |
|
760 // part of the production process so that the system has access to the key - |
|
761 // if the key has already been written it can't be written again) |
|
762 #ifdef RPMBTESTS_TRY_TO_WRITE_KEY |
|
763 if (r == KErrNone) |
|
764 { |
|
765 r = StackWriteKey(); |
|
766 } |
|
767 #endif |
|
768 if (r == KErrNone) |
|
769 { |
|
770 r = StackReadWriteCounter(); |
|
771 } |
|
772 if (r == KErrNone) |
|
773 { |
|
774 r = StackReadData(); |
|
775 } |
|
776 return r; |
|
777 } |
|
778 |
|
779 |
|
780 TInt DRpmbTest::StackBadIndex() |
|
781 // Call MMCGetExtInterface with invalid device id |
|
782 // - don't expect params to be returned |
|
783 // - expect KErrGeneral return code |
|
784 { |
|
785 Kern::Printf("%S stack device index test", &KDRpmbTestBanner); |
|
786 |
|
787 MRpmbInfo* rpmbInterface = NULL; |
|
788 TRpmbDeviceParms parms; |
|
789 |
|
790 TInt r = MMCGetExtInterface(KInterfaceRpmb, (MMCMExtInterface*&) rpmbInterface, this); //this pointer not used in the case of Rpmb |
|
791 if (r!=KErrNone) |
|
792 { |
|
793 Kern::Printf("%S stack device index, MMCGetInterface returned error = %d", |
|
794 &KDRpmbTestBanner, r); |
|
795 return KErrGeneral; |
|
796 } |
|
797 if (rpmbInterface == NULL) |
|
798 { |
|
799 // unexpected error since MMCGetExtInterface didn't return an error |
|
800 Kern::Printf("%S stack device index, MMCGetInterface returned NULL interface pointer", |
|
801 &KDRpmbTestBanner, r); |
|
802 return KErrGeneral; |
|
803 } |
|
804 |
|
805 else |
|
806 { |
|
807 r = rpmbInterface->RpmbInfo(1, parms); |
|
808 if (r == KErrNone) |
|
809 { |
|
810 Kern::Printf("%S stack device index test, parmas returned for index 1 error", |
|
811 &KDRpmbTestBanner, r); |
|
812 return KErrGeneral; |
|
813 } |
|
814 else if (r != KErrGeneral) |
|
815 { |
|
816 Kern::Printf("%S stack device index test, unexpected rc for index 1 error", |
|
817 &KDRpmbTestBanner, r); |
|
818 return KErrGeneral; |
|
819 } |
|
820 } |
|
821 Kern::Printf("%S stack device index test PASS", &KDRpmbTestBanner); |
|
822 return KErrNone; |
|
823 } |
|
824 |
|
825 |
|
826 void DRpmbTest::BusCallBack(TAny* aPtr, TInt aReason, TAny* a1, TAny* a2) |
|
827 { |
|
828 DRpmbTest* lddPtr = (DRpmbTest*)aPtr; |
|
829 TPBusState busState = (TPBusState) (TInt) a1; |
|
830 TInt busError = (TInt) a2; |
|
831 |
|
832 if(aReason == TPBusCallBack::EPBusStateChange |
|
833 && busState == EPBusOn && busError == KErrNone) |
|
834 { |
|
835 Kern::SemaphoreSignal(*(lddPtr->iPowerSemPtr)); |
|
836 } |
|
837 } |
|
838 |
|
839 TInt DRpmbTest::SetupForStackTests() |
|
840 { |
|
841 Kern::Printf("%S setup for stack tests", &KDRpmbTestBanner); |
|
842 |
|
843 TRpmbDeviceParms parms; |
|
844 |
|
845 parms.iCardNumber = 0; |
|
846 parms.iSocketPtr = NULL; |
|
847 |
|
848 DMMCStack* stack = NULL; |
|
849 TUint cardNumber = 0; |
|
850 MRpmbInfo* rpmbInterface = NULL; |
|
851 |
|
852 TInt r = MMCGetExtInterface(KInterfaceRpmb, (MMCMExtInterface*&) rpmbInterface, this); //this pointer not used in the case of Rpmb |
|
853 if (r!=KErrNone) |
|
854 { |
|
855 Kern::Printf("%S setup for stack tests, MMCGetInterface returned error = %d", |
|
856 &KDRpmbTestBanner, r); |
|
857 return KErrGeneral; |
|
858 } |
|
859 if (rpmbInterface == NULL) |
|
860 { |
|
861 // unexpected error since MMCGetExtInterface didn't return an error |
|
862 return KErrGeneral; |
|
863 } |
|
864 |
|
865 else |
|
866 { |
|
867 r = rpmbInterface->RpmbInfo(0, parms); |
|
868 if (r != KErrNone) |
|
869 { |
|
870 // requested index non zero or bseport not configured with RPMB capable MMC device |
|
871 return r; |
|
872 } |
|
873 |
|
874 cardNumber = parms.iCardNumber; |
|
875 iSocket = parms.iSocketPtr; |
|
876 if(iSocket == NULL) |
|
877 { |
|
878 Kern::Printf("%S setup for stack tests, socket pointer is NULL", |
|
879 &KDRpmbTestBanner); |
|
880 return KErrNoMemory; |
|
881 } |
|
882 |
|
883 // set up to be informed of changes on bus |
|
884 iBusCallBack.iFunction = BusCallBack; |
|
885 iBusCallBack.iPtr=this; |
|
886 iBusCallBack.SetSocket(iSocket->iSocketNumber); |
|
887 iBusCallBack.Add(); |
|
888 |
|
889 // power up the stack |
|
890 // media drivers don't have to do this at this stage because already done |
|
891 NKern::ThreadEnterCS(); |
|
892 |
|
893 r = Kern::SemaphoreCreate(iPowerSemPtr,_L("DpmbPowerSem"), 0); |
|
894 |
|
895 if (r!=KErrNone) |
|
896 { |
|
897 NKern::ThreadLeaveCS(); |
|
898 Kern::Printf("%S sese you below thentup for stack tests, SemaphoreCreate returned %d", |
|
899 &KDRpmbTestBanner, r); |
|
900 return KErrGeneral; |
|
901 } |
|
902 |
|
903 r = iSocket->PowerUp(); |
|
904 |
|
905 if (r!=KErrNone && r!= KErrCompletion) |
|
906 { |
|
907 NKern::ThreadLeaveCS(); |
|
908 Kern::Printf("%S setup for stack tests, PowerUp returned %d", |
|
909 &KDRpmbTestBanner, r); |
|
910 return KErrGeneral; |
|
911 } |
|
912 |
|
913 if (r == KErrNone) |
|
914 { |
|
915 // wait for socket to power up |
|
916 Kern::SemaphoreWait(*iPowerSemPtr); |
|
917 } |
|
918 |
|
919 NKern::ThreadLeaveCS(); |
|
920 |
|
921 stack = iSocket->Stack(0); |
|
922 if (stack == NULL) |
|
923 { |
|
924 // baseport poorly configured |
|
925 Kern::Printf("%S setup for stack tests, stack pointer is NULL", |
|
926 &KDRpmbTestBanner); |
|
927 return KErrGeneral; |
|
928 } |
|
929 } |
|
930 |
|
931 TMMCard* card = stack->CardP(cardNumber); |
|
932 |
|
933 if (card == NULL) |
|
934 { |
|
935 // baseport poorly configured |
|
936 Kern::Printf("%S setup for stack tests, card pointer is NULL", |
|
937 &KDRpmbTestBanner); |
|
938 return KErrGeneral; |
|
939 } |
|
940 |
|
941 NKern::ThreadEnterCS(); |
|
942 |
|
943 iSession = stack->AllocSession(iSessionEndCallBack); |
|
944 |
|
945 NKern::ThreadLeaveCS(); |
|
946 |
|
947 if (iSession == NULL) |
|
948 { |
|
949 Kern::Printf("%S setup for stack tests, session pointer is NULL", |
|
950 &KDRpmbTestBanner); |
|
951 return(KErrNoMemory); |
|
952 } |
|
953 |
|
954 iSession->SetStack(stack); |
|
955 |
|
956 iSession->SetCard(card); |
|
957 |
|
958 TUint32 revision = 0; |
|
959 |
|
960 // loop until extended csd becomes available in case earlier pause wasn't long enough |
|
961 // this shouldn't need to be done |
|
962 // a reliable method not depending on delays and or polling is required |
|
963 do { |
|
964 stack = iSocket->Stack(0); |
|
965 if (stack) |
|
966 { |
|
967 card = stack->CardP(cardNumber); |
|
968 if (card) |
|
969 { |
|
970 revision = card->ExtendedCSD().ExtendedCSDRev(); |
|
971 } |
|
972 } |
|
973 } while (revision==0); |
|
974 |
|
975 TUint size = card->ExtendedCSD().RpmbSize(); |
|
976 |
|
977 if(revision < 5 || size == 0) |
|
978 { |
|
979 Kern::Printf("%S setup for stack test, rpmb partition NOT detected", &KDRpmbTestBanner); |
|
980 return KErrNotSupported; |
|
981 } |
|
982 |
|
983 // use memory from stack |
|
984 TInt bufLen, minorBufLen; |
|
985 stack->BufferInfo(iBufPtr, bufLen, minorBufLen); |
|
986 // mmc media driver reserved the first KRpmbOneFramePacketLength bytes of the |
|
987 // PSL buffer to be used for RPMB requests / responses |
|
988 iBufPtr += minorBufLen; |
|
989 |
|
990 return KErrNone; |
|
991 } |
|
992 |
|
993 |
|
994 TInt DRpmbTest::StackIsKeyProgrammed() |
|
995 // Write Data to block 0 without MACing |
|
996 // - expect not MACed error if key set |
|
997 // - expect key not prgrammed error if key not programmed |
|
998 { |
|
999 |
|
1000 Kern::Printf("%S write data stack test", &KDRpmbTestBanner); |
|
1001 |
|
1002 // set up write request packet in stack memory |
|
1003 memset(iBufPtr,0,KRpmbOneFramePacketLength); |
|
1004 * (iBufPtr + KRpmbRequestLsbOffset) = KRpmbRequestWriteData; |
|
1005 |
|
1006 TInt r = SendToStackAndWait(); |
|
1007 if (r != KErrNone) |
|
1008 { |
|
1009 return r; |
|
1010 } |
|
1011 |
|
1012 TUint response = DecodeResponse(iBufPtr); |
|
1013 TUint result = DecodeResult(iBufPtr); |
|
1014 |
|
1015 if (response == KRpmbResponseWriteData) |
|
1016 { |
|
1017 if (result == KRpmbResultAuthenticationFailure) |
|
1018 { |
|
1019 Kern::Printf("%S write data stack test, key IS written", |
|
1020 &KDRpmbTestBanner); |
|
1021 Kern::Printf("%S write data stack test PASS", &KDRpmbTestBanner); |
|
1022 iKeySet = ETrue; |
|
1023 return KErrNone; |
|
1024 } |
|
1025 else if (result == KRpmbResultKeyNotProgrammed) |
|
1026 { |
|
1027 Kern::Printf("%S write data stack test, key NOT written", |
|
1028 &KDRpmbTestBanner); |
|
1029 Kern::Printf("%S write data stack test PASS",&KDRpmbTestBanner); |
|
1030 iKeySet = EFalse; |
|
1031 return KErrNone; |
|
1032 } |
|
1033 } |
|
1034 Kern::Printf("%S write data stack test FAILED, response = %d, result = %d", |
|
1035 &KDRpmbTestBanner, response, result); |
|
1036 return KErrGeneral; |
|
1037 } |
|
1038 |
|
1039 TInt DRpmbTest::StackWriteKey() |
|
1040 // Write key |
|
1041 // - expect no error if key not programmed |
|
1042 // - expect general error if key already programmed |
|
1043 { |
|
1044 Kern::Printf("%S write key stack test", &KDRpmbTestBanner); |
|
1045 |
|
1046 // set up write key request packet in stack memory |
|
1047 memset(iBufPtr,0,KRpmbOneFramePacketLength); |
|
1048 * (iBufPtr + KRpmbRequestLsbOffset) = KRpmbRequestWriteKey; |
|
1049 |
|
1050 TInt r = SendToStackAndWait(); |
|
1051 if (r != KErrNone) |
|
1052 { |
|
1053 return r; |
|
1054 } |
|
1055 |
|
1056 TUint response = DecodeResponse(iBufPtr); |
|
1057 TUint result = DecodeResult(iBufPtr); |
|
1058 |
|
1059 if (response == KRpmbResponseWriteKey) |
|
1060 { |
|
1061 if (iKeySet && result == KRpmbResultGeneralFailure) |
|
1062 { |
|
1063 Kern::Printf("%S write key stack test, key ALREADY written", |
|
1064 &KDRpmbTestBanner); |
|
1065 Kern::Printf("%S write key stack test PASS", &KDRpmbTestBanner); |
|
1066 return KErrNone; |
|
1067 } |
|
1068 else if (!iKeySet && result == KRpmbResultOk) |
|
1069 { |
|
1070 Kern::Printf("%S write key stack test, key JUST written", |
|
1071 &KDRpmbTestBanner); |
|
1072 Kern::Printf("%S write key stack test PASS", &KDRpmbTestBanner); |
|
1073 return KErrNone; |
|
1074 } |
|
1075 } |
|
1076 Kern::Printf("%S write key stack test FAILED, response = %d, result = %d", |
|
1077 &KDRpmbTestBanner, response, result); |
|
1078 return KErrGeneral; |
|
1079 } |
|
1080 |
|
1081 TInt DRpmbTest::StackReadWriteCounter() |
|
1082 // Read Data Counter |
|
1083 // - expect no error |
|
1084 { |
|
1085 Kern::Printf("%S read write counter stack test", &KDRpmbTestBanner); |
|
1086 |
|
1087 // set up write key request packet in stack memory |
|
1088 memset(iBufPtr,0,KRpmbOneFramePacketLength); |
|
1089 * (iBufPtr + KRpmbRequestLsbOffset) = KRpmbRequestReadWriteCounter; |
|
1090 |
|
1091 TInt r = SendToStackAndWait(); |
|
1092 if (r != KErrNone) |
|
1093 { |
|
1094 return r; |
|
1095 } |
|
1096 |
|
1097 TUint response = DecodeResponse(iBufPtr); |
|
1098 TUint result = DecodeResult(iBufPtr); |
|
1099 TUint32 counter = DecodeCounter(iBufPtr); |
|
1100 |
|
1101 #ifdef RPMBTESTS_TRY_TO_WRITE_KEY |
|
1102 if ((response == KRpmbResponseReadWriteCounter) && (result == KRpmbResultOk)) |
|
1103 #else |
|
1104 if ((response == KRpmbResponseReadWriteCounter) |
|
1105 && (result == KRpmbResultOk || result == KRpmbResultKeyNotProgrammed)) |
|
1106 #endif |
|
1107 { |
|
1108 Kern::Printf("%S read write counter stack test, counter = %d", |
|
1109 &KDRpmbTestBanner, counter); |
|
1110 Kern::Printf("%S read write counter stack test PASS", |
|
1111 &KDRpmbTestBanner); |
|
1112 return KErrNone; |
|
1113 } |
|
1114 Kern::Printf("%S read write counrter stack test FAILED, response = %d, result = %d", |
|
1115 &KDRpmbTestBanner, response, result); |
|
1116 return KErrGeneral; |
|
1117 } |
|
1118 |
|
1119 |
|
1120 TInt DRpmbTest::StackReadData() |
|
1121 // Read Data from block 0 |
|
1122 // - expect no error |
|
1123 { |
|
1124 Kern::Printf("%S read data stack test", &KDRpmbTestBanner); |
|
1125 |
|
1126 // set up write key request packet in stack memory |
|
1127 memset(iBufPtr,0,KRpmbOneFramePacketLength); |
|
1128 * (iBufPtr + KRpmbRequestLsbOffset) = KRpmbRequestReadData; |
|
1129 |
|
1130 TInt r = SendToStackAndWait(); |
|
1131 if (r != KErrNone) |
|
1132 { |
|
1133 return r; |
|
1134 } |
|
1135 |
|
1136 TUint response = DecodeResponse(iBufPtr); |
|
1137 TUint result = DecodeResult(iBufPtr); |
|
1138 |
|
1139 #ifdef RPMBTESTS_TRY_TO_WRITE_KEY |
|
1140 if ((response == KRpmbResponseReadData) && (result == KRpmbResultOk)) |
|
1141 #else |
|
1142 if ((response == KRpmbResponseReadData) |
|
1143 && (result == KRpmbResultOk || result == KRpmbResultKeyNotProgrammed)) |
|
1144 #endif |
|
1145 { |
|
1146 DisplayReadData(iBufPtr); |
|
1147 Kern::Printf("%S read data stack test PASS", &KDRpmbTestBanner); |
|
1148 return KErrNone; |
|
1149 } |
|
1150 Kern::Printf("%S read data stack test FAILED, response = %d, result = %d", |
|
1151 &KDRpmbTestBanner, response, result); |
|
1152 return KErrGeneral; |
|
1153 } |
|
1154 |
|
1155 TInt DRpmbTest::SendToStackAndWait() |
|
1156 { |
|
1157 // comment out to get timings with RPMB -> RPMB switches in place of User |
|
1158 // Area -> RPMB switces |
|
1159 #define RPMBSTACKTEST_FIRST_SWITCH_TO_USER_AREA |
|
1160 #ifdef RPMBSTACKTEST_FIRST_SWITCH_TO_USER_AREA |
|
1161 // in normal operation it may be necessary to switch to RPMB partition |
|
1162 // prior to access |
|
1163 // so force the switch to occur by pre switching to the user area |
|
1164 iSession->SetPartition(TExtendedCSD::ESelectUserArea); |
|
1165 #endif |
|
1166 |
|
1167 TInt start, postswitch, end; |
|
1168 |
|
1169 start = NKern::TickCount(); |
|
1170 |
|
1171 // lock stack |
|
1172 TInt r = iSocket->InCritical(); |
|
1173 if (r != KErrNone) |
|
1174 { |
|
1175 Kern::Printf("%S DRpmbTest::SendToStackAndWait, error=%d", |
|
1176 &KDRpmbTestBanner, r); |
|
1177 iSocket->EndInCritical(); |
|
1178 return KErrGeneral; |
|
1179 } |
|
1180 |
|
1181 // switch to RPMB partition |
|
1182 iSession->SetPartition(TExtendedCSD::ESelectRPMB); |
|
1183 |
|
1184 postswitch = NKern::TickCount(); |
|
1185 |
|
1186 // set up for write exchange |
|
1187 iSession->ResetCommandStack(); |
|
1188 iSession->FillCommandArgs(0, KRpmbOneFramePacketLength, iBufPtr, KRpmbOneFramePacketLength); |
|
1189 iSession->iSessionID = ECIMRpmbAccess; |
|
1190 iSession->Engage(); |
|
1191 |
|
1192 // wait for stack call to complete |
|
1193 r = Kern::SemaphoreWait(*iStackSemPtr); |
|
1194 |
|
1195 end = NKern::TickCount(); |
|
1196 |
|
1197 Kern::Printf("%S switch to RPMB took %d %d uS timer ticks", |
|
1198 &KDRpmbTestBanner, start - postswitch, NKern::TickPeriod()); |
|
1199 Kern::Printf("%S RPMB ECIMRpmbAccess took %d %d uS timer ticks", |
|
1200 &KDRpmbTestBanner, end - postswitch, NKern::TickPeriod()); |
|
1201 |
|
1202 if (r != KErrNone) |
|
1203 { |
|
1204 Kern::Printf("%S DRpmbTest::SendToStackAndWait, SemaphoreWait return code = %d", |
|
1205 &KDRpmbTestBanner, r); |
|
1206 iSocket->EndInCritical(); |
|
1207 return KErrGeneral; |
|
1208 } |
|
1209 |
|
1210 // check stack epoc return code |
|
1211 r = iSession->EpocErrorCode(); |
|
1212 if (r != KErrNone) |
|
1213 { |
|
1214 Kern::Printf("%S DRpmbTest::stack epoc return code = %d", |
|
1215 &KDRpmbTestBanner, r); |
|
1216 iSocket->EndInCritical(); |
|
1217 return KErrGeneral; |
|
1218 } |
|
1219 |
|
1220 // unlock stack |
|
1221 iSocket->EndInCritical(); |
|
1222 |
|
1223 return KErrNone; |
|
1224 } |
|
1225 |