blob: c4f2608603d303f103eb0ff3d30a0f15325b9cc2 [file] [log] [blame]
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -07001/* Copyright (c) 2013 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/*
7 * TPM Lightweight Command Library.
8 *
9 * A low-level library for interfacing to TPM hardware or an emulator.
10 */
11
Philipp Deppenwiesed88fb362017-10-18 20:26:18 +020012#ifndef TSS_H_
13#define TSS_H_
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010014
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070015#include <stdint.h>
Vadim Bendebury245d4572016-04-05 16:01:57 -070016#include <types.h>
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070017
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010018#include <security/tpm/tss/common/tss_common.h>
19#include <security/tpm/tss_errors.h>
20#include <security/tpm/tss/vendor/cr50/cr50.h>
21
22#if IS_ENABLED(CONFIG_TPM1)
23
24#include <security/tpm/tss/tcg-1.2/tss_structures.h>
25
26/**
27 * Define a space with permission [perm]. [index] is the index for the space,
28 * [size] the usable data size. The TPM error code is returned.
29 */
30uint32_t tlcl_define_space(uint32_t index, uint32_t perm, uint32_t size);
31
32/**
33 * Issue a PhysicalEnable. The TPM error code is returned.
34 */
35uint32_t tlcl_set_enable(void);
36
37/**
38 * Issue a SetDeactivated. Pass 0 to activate. Returns result code.
39 */
40uint32_t tlcl_set_deactivated(uint8_t flag);
41
42/**
43 * Get flags of interest. Pointers for flags you aren't interested in may
44 * be NULL. The TPM error code is returned.
45 */
46uint32_t tlcl_get_flags(uint8_t *disable, uint8_t *deactivated,
47 uint8_t *nvlocked);
48
49/**
50 * Get the entire set of permanent flags.
51 */
52uint32_t tlcl_get_permanent_flags(TPM_PERMANENT_FLAGS *pflags);
53
54#endif
55
56#if IS_ENABLED(CONFIG_TPM2)
57
58#include <security/tpm/tss/tcg-2.0/tss_structures.h>
59
60/*
61 * Define a TPM2 space. The define space command TPM command used by the tlcl
62 * layer offers the ability to use custom nv attributes and policies.
63 */
64uint32_t tlcl_define_space(uint32_t space_index, size_t space_size,
65 const TPMA_NV nv_attributes,
66 const uint8_t *nv_policy, size_t nv_policy_size);
67
68/*
69 * Makes tpm_process_command available for on top implementations of
70 * custom tpm standards like cr50
71 */
72void *tpm_process_command(TPM_CC command, void *command_body);
73
74#endif
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070075
76/*****************************************************************************/
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +010077/* Generic Functions implemented in tlcl.c */
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070078
79/**
80 * Call this first. Returns 0 if success, nonzero if error.
81 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070082uint32_t tlcl_lib_init(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070083
84/**
85 * Perform a raw TPM request/response transaction.
86 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070087uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response,
Lee Leahy708fc272017-03-07 12:18:53 -080088 int max_length);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070089
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070090/* Commands */
91
92/**
93 * Send a TPM_Startup(ST_CLEAR). The TPM error code is returned (0 for
94 * success).
95 */
Daisuke Nojiri57990972014-07-15 19:47:32 -070096uint32_t tlcl_startup(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -070097
98/**
99 * Resume by sending a TPM_Startup(ST_STATE). The TPM error code is returned
100 * (0 for success).
101 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700102uint32_t tlcl_resume(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700103
104/**
Joel Kitching2e690ee2018-11-15 16:48:53 +0800105 * Save TPM state by sending either TPM_SaveState() (TPM1.2) or
106 * TPM_Shutdown(ST_STATE) (TPM2.0). The TPM error code is returned (0 for
107 * success).
108 */
109uint32_t tlcl_save_state(void);
110
111/**
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700112 * Run the self test.
113 *
114 * Note---this is synchronous. To run this in parallel with other firmware,
115 * use ContinueSelfTest(). The TPM error code is returned.
116 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700117uint32_t tlcl_self_test_full(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700118
119/**
120 * Run the self test in the background.
121 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700122uint32_t tlcl_continue_self_test(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700123
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700124/**
125 * Write [length] bytes of [data] to space at [index]. The TPM error code is
126 * returned.
127 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700128uint32_t tlcl_write(uint32_t index, const void *data, uint32_t length);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700129
130/**
131 * Read [length] bytes from space at [index] into [data]. The TPM error code
132 * is returned.
133 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700134uint32_t tlcl_read(uint32_t index, void *data, uint32_t length);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700135
136/**
137 * Assert physical presence in software. The TPM error code is returned.
138 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700139uint32_t tlcl_assert_physical_presence(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700140
141/**
142 * Enable the physical presence command. The TPM error code is returned.
143 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700144uint32_t tlcl_physical_presence_cmd_enable(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700145
146/**
147 * Finalize the physical presence settings: sofware PP is enabled, hardware PP
148 * is disabled, and the lifetime lock is set. The TPM error code is returned.
149 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700150uint32_t tlcl_finalize_physical_presence(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700151
152/**
153 * Set the nvLocked bit. The TPM error code is returned.
154 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700155uint32_t tlcl_set_nv_locked(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700156
157/**
158 * Issue a ForceClear. The TPM error code is returned.
159 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700160uint32_t tlcl_force_clear(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700161
162/**
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700163 * Set the bGlobalLock flag, which only a reboot can clear. The TPM error
164 * code is returned.
165 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700166uint32_t tlcl_set_global_lock(void);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700167
168/**
Vadim Bendebury4c0851c2016-07-03 17:08:10 -0700169 * Make an NV Ram location read_only. The TPM error code is returned.
170 */
171uint32_t tlcl_lock_nv_write(uint32_t index);
172
173/**
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700174 * Perform a TPM_Extend.
175 */
Daisuke Nojiri57990972014-07-15 19:47:32 -0700176uint32_t tlcl_extend(int pcr_num, const uint8_t *in_digest,
Lee Leahy708fc272017-03-07 12:18:53 -0800177 uint8_t *out_digest);
Daisuke Nojiriefb5cde2014-07-02 08:37:23 -0700178
179/**
Aaron Durbinf56c7782017-01-10 17:44:42 -0600180 * Disable platform hierarchy. Specific to TPM2. The TPM error code is returned.
181 */
182uint32_t tlcl_disable_platform_hierarchy(void);
183
Philipp Deppenwiesec07f8fb2018-02-27 19:40:52 +0100184#endif /* TSS_H_ */