xref: /aosp_15_r20/external/vboot_reference/tests/tpm_lite/tpmtest_fastenable.c (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1 /* Copyright 2011 The ChromiumOS Authors
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 /* Testing: ForceClear and behavior of disable and permanent deactivated flags.
7  *
8  * ForceClear sets the permanent disable and deactivated flags to their default
9  * value of TRUE.  The specs say nothing about STCLEAR flags, so they should be
10  * left alone.  This test checks that both flags may be reset without a reboot,
11  * resulting in a fully enabled and activated TPM.  (We know that because
12  * ForceClear requires that the TPM be enabled and activated to run.)
13  */
14 
15 #include <stdio.h>
16 
17 #include "host_common.h"
18 #include "common/tests.h"
19 #include "tlcl.h"
20 #include "tlcl_tests.h"
21 
main(int argc,char ** argv)22 int main(int argc, char** argv) {
23 	uint8_t disable, deactivated;
24 	int i;
25 
26 	TlclLibInit();
27 	TPM_CHECK(TlclStartupIfNeeded());
28 	TPM_CHECK(TlclSelfTestFull());
29 	TPM_CHECK(TlclAssertPhysicalPresence());
30 	TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
31 	printf("disable is %d, deactivated is %d\n", disable, deactivated);
32 
33 	for (i = 0; i < 2; i++) {
34 		TPM_CHECK(TlclForceClear());
35 		TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
36 		printf("disable is %d, deactivated is %d\n", disable, deactivated);
37 		TEST_EQ(disable, 1, "after ForceClear, disable");
38 		TEST_EQ(deactivated, 1, "after ForceClear, deactivated");
39 		TPM_CHECK(TlclSetEnable());
40 		TPM_CHECK(TlclSetDeactivated(0));
41 		TPM_CHECK(TlclGetFlags(&disable, &deactivated, NULL));
42 		printf("disable is %d, deactivated is %d\n", disable, deactivated);
43 		TEST_EQ(disable, 0, "after SetEnable, enabled");
44 		TEST_EQ(deactivated, 0, "after SetDeactivated(0), activated");
45 	}
46 
47 	printf("TEST SUCCEEDED\n");
48 	return 0;
49 }
50