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 #include "utility.h" |
| 16 |
| 17 #define INDEX0 0xda70 |
| 18 #define TPM_MAX_NV_WRITES_NOOWNER 64 |
| 19 |
| 20 int main(int argc, char** argv) { |
| 21 int i; |
| 22 uint32_t result; |
| 23 uint8_t disable, deactivated; /* the TPM specs use these exact names */ |
| 24 |
| 25 TlclLibInit(); |
| 26 |
| 27 TlclStartup(); |
| 28 TlclSelftestfull(); |
| 29 |
| 30 TlclAssertPhysicalPresence(); |
| 31 |
| 32 result = TlclGetFlags(&disable, &deactivated); |
| 33 printf("disable is %d, deactivated is %d\n", disable, deactivated); |
| 34 |
| 35 if (disable || deactivated) { |
| 36 TlclSetEnable(); |
| 37 (void) TlclSetDeactivated(0); |
| 38 printf("TPM will be active after next reboot\n"); |
| 39 exit(0); |
| 40 } |
| 41 |
| 42 for (i = 0; i < TPM_MAX_NV_WRITES_NOOWNER + 2; i++) { |
| 43 printf("writing %d\n", i); |
| 44 if ((result = TlclWrite(INDEX0, (uint8_t*)&i, sizeof(i))) != TPM_SUCCESS) { |
| 45 switch (result) { |
| 46 case TPM_E_MAXNVWRITES: |
| 47 printf("Max NV writes exceeded - forcing clear\n"); |
| 48 TlclForceClear(); |
| 49 printf("Please reboot and run this program again\n"); |
| 50 exit(0); |
| 51 default: |
| 52 error("unexpected error code %d (0x%x)\n"); |
| 53 } |
| 54 } |
| 55 } |
| 56 |
| 57 /* Done for now. |
| 58 */ |
| 59 printf("Test completed successfully\n"); |
| 60 exit(0); |
| 61 } |
OLD | NEW |