Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 1 | /* 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 Deppenwiese | d88fb36 | 2017-10-18 20:26:18 +0200 | [diff] [blame] | 12 | #ifndef TSS_H_ |
| 13 | #define TSS_H_ |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 14 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 15 | #include <stdint.h> |
Vadim Bendebury | 245d457 | 2016-04-05 16:01:57 -0700 | [diff] [blame] | 16 | #include <types.h> |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 17 | |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 18 | #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 | */ |
| 30 | uint32_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 | */ |
| 35 | uint32_t tlcl_set_enable(void); |
| 36 | |
| 37 | /** |
| 38 | * Issue a SetDeactivated. Pass 0 to activate. Returns result code. |
| 39 | */ |
| 40 | uint32_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 | */ |
| 46 | uint32_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 | */ |
| 52 | uint32_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 | */ |
| 64 | uint32_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 | */ |
| 72 | void *tpm_process_command(TPM_CC command, void *command_body); |
| 73 | |
| 74 | #endif |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 75 | |
| 76 | /*****************************************************************************/ |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 77 | /* Generic Functions implemented in tlcl.c */ |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 78 | |
| 79 | /** |
| 80 | * Call this first. Returns 0 if success, nonzero if error. |
| 81 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 82 | uint32_t tlcl_lib_init(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * Perform a raw TPM request/response transaction. |
| 86 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 87 | uint32_t tlcl_send_receive(const uint8_t *request, uint8_t *response, |
Lee Leahy | 708fc27 | 2017-03-07 12:18:53 -0800 | [diff] [blame] | 88 | int max_length); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 89 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 90 | /* Commands */ |
| 91 | |
| 92 | /** |
| 93 | * Send a TPM_Startup(ST_CLEAR). The TPM error code is returned (0 for |
| 94 | * success). |
| 95 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 96 | uint32_t tlcl_startup(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Resume by sending a TPM_Startup(ST_STATE). The TPM error code is returned |
| 100 | * (0 for success). |
| 101 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 102 | uint32_t tlcl_resume(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
Joel Kitching | 2e690ee | 2018-11-15 16:48:53 +0800 | [diff] [blame] | 105 | * 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 | */ |
| 109 | uint32_t tlcl_save_state(void); |
| 110 | |
| 111 | /** |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 112 | * 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 Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 117 | uint32_t tlcl_self_test_full(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 118 | |
| 119 | /** |
| 120 | * Run the self test in the background. |
| 121 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 122 | uint32_t tlcl_continue_self_test(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 123 | |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 124 | /** |
| 125 | * Write [length] bytes of [data] to space at [index]. The TPM error code is |
| 126 | * returned. |
| 127 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 128 | uint32_t tlcl_write(uint32_t index, const void *data, uint32_t length); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 129 | |
| 130 | /** |
| 131 | * Read [length] bytes from space at [index] into [data]. The TPM error code |
| 132 | * is returned. |
| 133 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 134 | uint32_t tlcl_read(uint32_t index, void *data, uint32_t length); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 135 | |
| 136 | /** |
| 137 | * Assert physical presence in software. The TPM error code is returned. |
| 138 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 139 | uint32_t tlcl_assert_physical_presence(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 140 | |
| 141 | /** |
| 142 | * Enable the physical presence command. The TPM error code is returned. |
| 143 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 144 | uint32_t tlcl_physical_presence_cmd_enable(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 145 | |
| 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 Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 150 | uint32_t tlcl_finalize_physical_presence(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 151 | |
| 152 | /** |
| 153 | * Set the nvLocked bit. The TPM error code is returned. |
| 154 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 155 | uint32_t tlcl_set_nv_locked(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 156 | |
| 157 | /** |
| 158 | * Issue a ForceClear. The TPM error code is returned. |
| 159 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 160 | uint32_t tlcl_force_clear(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 161 | |
| 162 | /** |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 163 | * Set the bGlobalLock flag, which only a reboot can clear. The TPM error |
| 164 | * code is returned. |
| 165 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 166 | uint32_t tlcl_set_global_lock(void); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 167 | |
| 168 | /** |
Vadim Bendebury | 4c0851c | 2016-07-03 17:08:10 -0700 | [diff] [blame] | 169 | * Make an NV Ram location read_only. The TPM error code is returned. |
| 170 | */ |
| 171 | uint32_t tlcl_lock_nv_write(uint32_t index); |
| 172 | |
| 173 | /** |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 174 | * Perform a TPM_Extend. |
| 175 | */ |
Daisuke Nojiri | 5799097 | 2014-07-15 19:47:32 -0700 | [diff] [blame] | 176 | uint32_t tlcl_extend(int pcr_num, const uint8_t *in_digest, |
Lee Leahy | 708fc27 | 2017-03-07 12:18:53 -0800 | [diff] [blame] | 177 | uint8_t *out_digest); |
Daisuke Nojiri | efb5cde | 2014-07-02 08:37:23 -0700 | [diff] [blame] | 178 | |
| 179 | /** |
Aaron Durbin | f56c778 | 2017-01-10 17:44:42 -0600 | [diff] [blame] | 180 | * Disable platform hierarchy. Specific to TPM2. The TPM error code is returned. |
| 181 | */ |
| 182 | uint32_t tlcl_disable_platform_hierarchy(void); |
| 183 | |
Philipp Deppenwiese | c07f8fb | 2018-02-27 19:40:52 +0100 | [diff] [blame] | 184 | #endif /* TSS_H_ */ |