OLD | NEW |
(Empty) | |
| 1 /* Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 * Use of this source code is governed by a BSD-style license that can be |
| 3 * found in the LICENSE file. |
| 4 */ |
| 5 |
| 6 /* Test of recovery when we hit the NVRAM write limit for an unowned TPM. |
| 7 */ |
| 8 |
| 9 #include <stdio.h> |
| 10 #include <stdint.h> |
| 11 #include <stdlib.h> |
| 12 #include <tss/tcs.h> |
| 13 |
| 14 #include "tlcl.h" |
| 15 |
| 16 #define INDEX0 0xda70 |
| 17 #define TPM_MAX_NV_WRITES_NOOWNER 64 |
| 18 |
| 19 int main(void) { |
| 20 int i; |
| 21 uint32_t result; |
| 22 uint8_t disable, deactivated; /* the TPM specs use these exact names */ |
| 23 |
| 24 TlclLibinit(); |
| 25 |
| 26 TlclStartup(); |
| 27 TlclSelftestfull(); |
| 28 |
| 29 TlclAssertPhysicalPresence(); |
| 30 |
| 31 result = TlclGetFlags(&disable, &deactivated); |
| 32 printf("disable is %d, deactivated is %d\n", disable, deactivated); |
| 33 |
| 34 if (disable || deactivated) { |
| 35 TlclPhysicalEnable(); |
| 36 (void) TlclPhysicalSetDeactivated(0); |
| 37 printf("TPM will be active after next reboot\n"); |
| 38 exit(0); |
| 39 } |
| 40 |
| 41 for (i = 0; i < TPM_MAX_NV_WRITES_NOOWNER + 2; i++) { |
| 42 printf("writing %d\n", i); |
| 43 if ((result = TlclWrite(INDEX0, (uint8_t*)&i, sizeof(i))) != TPM_SUCCESS) { |
| 44 switch (result) { |
| 45 case TPM_E_MAXNVWRITES: |
| 46 printf("Max NV writes exceeded - forcing clear\n"); |
| 47 TlclForceClear(); |
| 48 printf("Please reboot and run this program again\n"); |
| 49 exit(0); |
| 50 default: |
| 51 error("unexpected error code %d (0x%x)\n"); |
| 52 } |
| 53 } |
| 54 } |
| 55 |
| 56 /* Done for now. |
| 57 */ |
| 58 printf("Test completed successfully\n"); |
| 59 exit(0); |
| 60 } |
OLD | NEW |