blob: 10d080247270b0dbda88dc2eaa6854e8a7122c57 [file] [log] [blame]
Gaurav Shah0df08372010-03-24 14:22:41 -07001/* 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/* TPM Lightweight Command Library.
7 *
8 * A low-level library for interfacing to TPM hardware or an emulator.
9 */
10
11#ifndef TPM_LITE_TLCL_H_
12#define TPM_LITE_TLCL_H_
13
Randall Spanglerf3029052010-06-16 13:42:58 -070014#include "sysincludes.h"
Luigi Semenzato5896b962010-08-25 07:16:03 -070015#include "tss_constants.h"
Che-Liang Chiou89678602010-11-09 08:33:36 +080016#include "tlcl_stub.h"
Randall Spangler39f66112010-07-14 09:10:23 -070017
18/*****************************************************************************/
19/* Functions implemented in tlcl.c */
20
Che-Liang Chiou5d9509c2010-12-16 14:11:17 +080021/* Call this first. Returns 0 if success, nonzero if error.
Randall Spangler39f66112010-07-14 09:10:23 -070022 */
Che-Liang Chiou5d9509c2010-12-16 14:11:17 +080023uint32_t TlclLibInit(void);
Randall Spangler39f66112010-07-14 09:10:23 -070024
Randall Spangler39f66112010-07-14 09:10:23 -070025/* Logs to stdout. Arguments like printf.
26 */
27void TlclLog(char* format, ...);
28
29/* Sets the log level. 0 is quietest.
30 */
31void TlclSetLogLevel(int level);
32
33/* Sends a TPM_Startup(ST_CLEAR). The TPM error code is returned (0
34 * for success).
Gaurav Shah0df08372010-03-24 14:22:41 -070035 */
Luigi Semenzato59204c52010-06-09 13:37:15 -070036uint32_t TlclStartup(void);
Gaurav Shah0df08372010-03-24 14:22:41 -070037
Luigi Semenzato54992f92011-03-16 10:56:48 -070038/* Save the TPM state. Normally done by the kernel before a suspend, included
39 * here for tests. The TPM error code is returned (0 for success).
40 */
41uint32_t TlclSaveState(void);
42
Luigi Semenzato3da063e2010-08-31 14:31:30 -070043/* Resumes by sending a TPM_Startup(ST_STATE). The TPM error code is returned
44 * (0 for success).
45 */
46uint32_t TlclResume(void);
47
48/* Runs the self test. Note---this is synchronous. To run this in parallel
Luigi Semenzato59204c52010-06-09 13:37:15 -070049 * with other firmware, use ContinueSelfTest. The TPM error code is returned.
Gaurav Shah0df08372010-03-24 14:22:41 -070050 */
Randall Spangler3e1081f2010-07-19 10:04:21 -070051uint32_t TlclSelfTestFull(void);
Luigi Semenzato59204c52010-06-09 13:37:15 -070052
Randall Spangler39f66112010-07-14 09:10:23 -070053/* Runs the self test in the background.
Luigi Semenzato59204c52010-06-09 13:37:15 -070054 */
55uint32_t TlclContinueSelfTest(void);
Gaurav Shah0df08372010-03-24 14:22:41 -070056
57/* Defines a space with permission [perm]. [index] is the index for the space,
Luigi Semenzato59204c52010-06-09 13:37:15 -070058 * [size] the usable data size. The TPM error code is returned.
Gaurav Shah0df08372010-03-24 14:22:41 -070059 */
Luigi Semenzato59204c52010-06-09 13:37:15 -070060uint32_t TlclDefineSpace(uint32_t index, uint32_t perm, uint32_t size);
Gaurav Shah0df08372010-03-24 14:22:41 -070061
62/* Writes [length] bytes of [data] to space at [index]. The TPM error code is
Luigi Semenzato59204c52010-06-09 13:37:15 -070063 * returned.
Gaurav Shah0df08372010-03-24 14:22:41 -070064 */
Randall Spangler4abede32010-08-12 16:40:32 -070065uint32_t TlclWrite(uint32_t index, const void* data, uint32_t length);
Gaurav Shah0df08372010-03-24 14:22:41 -070066
67/* Reads [length] bytes from space at [index] into [data]. The TPM error code
Luigi Semenzato59204c52010-06-09 13:37:15 -070068 * is returned.
Gaurav Shah0df08372010-03-24 14:22:41 -070069 */
Randall Spangler4abede32010-08-12 16:40:32 -070070uint32_t TlclRead(uint32_t index, void* data, uint32_t length);
Gaurav Shah0df08372010-03-24 14:22:41 -070071
Luigi Semenzato59204c52010-06-09 13:37:15 -070072/* Write-locks space at [index]. The TPM error code is returned.
Gaurav Shah0df08372010-03-24 14:22:41 -070073 */
Luigi Semenzato59204c52010-06-09 13:37:15 -070074uint32_t TlclWriteLock(uint32_t index);
Gaurav Shah0df08372010-03-24 14:22:41 -070075
Luigi Semenzato59204c52010-06-09 13:37:15 -070076/* Read-locks space at [index]. The TPM error code is returned.
Gaurav Shah0df08372010-03-24 14:22:41 -070077 */
Luigi Semenzato59204c52010-06-09 13:37:15 -070078uint32_t TlclReadLock(uint32_t index);
Gaurav Shah0df08372010-03-24 14:22:41 -070079
Luigi Semenzato59204c52010-06-09 13:37:15 -070080/* Asserts physical presence in software. The TPM error code is returned.
Gaurav Shah0df08372010-03-24 14:22:41 -070081 */
Luigi Semenzato59204c52010-06-09 13:37:15 -070082uint32_t TlclAssertPhysicalPresence(void);
Gaurav Shah0df08372010-03-24 14:22:41 -070083
Luigi Semenzato377557f2010-08-31 13:20:53 -070084/* Enables the physical presence command. The TPM error code is returned.
Luigi Semenzato1d83dd12010-08-30 10:23:43 -070085 */
86uint32_t TlclPhysicalPresenceCMDEnable(void);
87
Luigi Semenzato377557f2010-08-31 13:20:53 -070088/* Finalizes the physical presence settings: sofware PP is enabled, hardware PP
89 * is disabled, and the lifetime lock is set. The TPM error code is returned.
90 */
91uint32_t TlclFinalizePhysicalPresence(void);
92
Luigi Semenzato59204c52010-06-09 13:37:15 -070093/* Turns off physical presence and locks it off until next reboot. The TPM
94 * error code is returned.
Luigi Semenzato596b6402010-05-27 14:04:52 -070095 */
96uint32_t TlclLockPhysicalPresence(void);
97
Luigi Semenzato59204c52010-06-09 13:37:15 -070098/* Sets the nvLocked bit. The TPM error code is returned.
Gaurav Shah0df08372010-03-24 14:22:41 -070099 */
Luigi Semenzato59204c52010-06-09 13:37:15 -0700100uint32_t TlclSetNvLocked(void);
Gaurav Shah0df08372010-03-24 14:22:41 -0700101
102/* Returns 1 if the TPM is owned, 0 otherwise.
103 */
104int TlclIsOwned(void);
105
Luigi Semenzato59204c52010-06-09 13:37:15 -0700106/* Issues a ForceClear. The TPM error code is returned.
Gaurav Shah0df08372010-03-24 14:22:41 -0700107 */
Luigi Semenzato59204c52010-06-09 13:37:15 -0700108uint32_t TlclForceClear(void);
Gaurav Shah0df08372010-03-24 14:22:41 -0700109
Luigi Semenzato416f6812010-07-08 12:12:12 -0700110/* Issues a PhysicalEnable. The TPM error code is returned.
Gaurav Shah0df08372010-03-24 14:22:41 -0700111 */
Luigi Semenzato59204c52010-06-09 13:37:15 -0700112uint32_t TlclSetEnable(void);
Gaurav Shah0df08372010-03-24 14:22:41 -0700113
Luigi Semenzato416f6812010-07-08 12:12:12 -0700114/* Issues a PhysicalDisable. The TPM error code is returned.
115 */
116uint32_t TlclClearEnable(void);
117
Luigi Semenzato596b6402010-05-27 14:04:52 -0700118/* Issues a SetDeactivated. Pass 0 to activate. Returns result code.
Gaurav Shah0df08372010-03-24 14:22:41 -0700119 */
Luigi Semenzato59204c52010-06-09 13:37:15 -0700120uint32_t TlclSetDeactivated(uint8_t flag);
Gaurav Shah0df08372010-03-24 14:22:41 -0700121
Randall Spangler3e1081f2010-07-19 10:04:21 -0700122/* Gets flags of interest. Pointers for flags you aren't interested in may
Randall Spangler205190d2010-08-05 15:55:06 -0700123 * be NULL. The TPM error code is returned.
Gaurav Shah0df08372010-03-24 14:22:41 -0700124 */
Luigi Semenzatoa7e19cf2010-09-15 17:20:36 -0700125uint32_t TlclGetFlags(uint8_t* disable, uint8_t* deactivated,
126 uint8_t* nvlocked);
Gaurav Shah0df08372010-03-24 14:22:41 -0700127
Luigi Semenzato59204c52010-06-09 13:37:15 -0700128/* Sets the bGlobalLock flag, which only a reboot can clear. The TPM error
129 * code is returned.
Luigi Semenzato596b6402010-05-27 14:04:52 -0700130 */
131uint32_t TlclSetGlobalLock(void);
132
Randall Spangler39f66112010-07-14 09:10:23 -0700133/* Performs a TPM_Extend.
134 */
Gaurav Shahb64faaa2011-03-15 16:36:29 -0700135uint32_t TlclExtend(int pcr_num, const uint8_t* in_digest, uint8_t* out_digest);
Randall Spangler39f66112010-07-14 09:10:23 -0700136
Luigi Semenzato4f11c362010-06-10 11:01:04 -0700137/* Gets the permission bits for the NVRAM space with |index|.
138 */
139uint32_t TlclGetPermissions(uint32_t index, uint32_t* permissions);
140
Luigi Semenzato5896b962010-08-25 07:16:03 -0700141/* Gets the entire set of permanent flags.
142 */
143uint32_t TlclGetPermanentFlags(TPM_PERMANENT_FLAGS* pflags);
144
145/* Gets the entire set of volatile (ST_CLEAR) flags.
146 */
147uint32_t TlclGetSTClearFlags(TPM_STCLEAR_FLAGS* pflags);
148
Gaurav Shah0df08372010-03-24 14:22:41 -0700149#endif /* TPM_LITE_TLCL_H_ */