1 // Copyright 2016 The Fuchsia 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 #pragma once 6 7 #include <zircon/compiler.h> 8 9 #define TPM_TAG_RSP_COMMAND 196 10 11 #define TPM_ST_NO_SESSIONS 0x8001 12 #define TPM_CC_SHUTDOWN 0x00000145 13 #define TPM_CC_GET_RANDOM 0x0000017B 14 15 // All TPM fields are big-endian. 16 // The init functions that return uint32_t return the number of bytes needed 17 // for the response structure. 18 19 #define TPM_FIXED_LEN_CMD_INIT(cmd, cmd_code) { \ 20 .tag = TPM_TAG_RQU_COMMAND, \ 21 .total_len = sizeof(cmd), \ 22 .cmd_code = cmd_code } 23 24 struct tpm_cmd_header { 25 uint16_t tag; 26 uint32_t total_len; 27 uint32_t cmd_code; 28 } __PACKED; 29 30 struct tpm_resp_header { 31 uint16_t tag; 32 uint32_t total_len; 33 uint32_t return_code; 34 } __PACKED; 35 36 struct tpm_getrandom_cmd { 37 struct tpm_cmd_header hdr; 38 uint16_t bytes_requested; 39 } __PACKED; 40 struct tpm_getrandom_resp { 41 struct tpm_resp_header hdr; 42 uint16_t bytes_returned; 43 uint8_t bytes[]; 44 } __PACKED; 45 uint32_t tpm_init_getrandom(struct tpm_getrandom_cmd *cmd, uint16_t bytes_requested); 46 47 // Shutdown types 48 #define TPM_SU_CLEAR 0 49 #define TPM_SU_STATE 1 50 51 struct tpm_shutdown_cmd { 52 struct tpm_cmd_header hdr; 53 uint16_t shutdown_type; 54 } __PACKED; 55 struct tpm_shutdown_resp { 56 struct tpm_resp_header hdr; 57 } __PACKED; 58 uint32_t tpm_init_shutdown(struct tpm_shutdown_cmd *cmd, uint16_t type); 59