![]() |
coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
|
#include <commonlib/iobuf.h>
#include <console/console.h>
#include <string.h>
#include "tss_marshaling.h"
#include <security/tpm/tss/vendor/cr50/cr50.h>
#include <security/tpm/tss.h>
Go to the source code of this file.
Macros | |
#define | unmarshal_TPM_CAP(a, b) ibuf_read_be32(a, b) |
#define | unmarshal_TPM_CC(a, b) ibuf_read_be32(a, b) |
#define | unmarshal_TPM_PT(a, b) ibuf_read_be32(a, b) |
#define | unmarshal_TPM_HANDLE(a, b) ibuf_read_be32(a, b) |
#define | marshal_TPM_HANDLE(a, b) obuf_write_be32(a, b) |
#define | marshal_TPMI_ALG_HASH(a, b) obuf_write_be16(a, b) |
Functions | |
static int | marshal_startup (struct obuf *ob, const struct tpm2_startup *cmd_body) |
static int | marshal_shutdown (struct obuf *ob, const struct tpm2_shutdown *cmd_body) |
static int | marshal_get_capability (struct obuf *ob, const struct tpm2_get_capability *cmd_body) |
static int | marshal_TPM2B (struct obuf *ob, const TPM2B *data) |
static int | marshal_TPMA_NV (struct obuf *ob, const TPMA_NV *nv) |
static int | marshal_TPMS_NV_PUBLIC (struct obuf *ob, const TPMS_NV_PUBLIC *nvpub) |
static int | marshal_TPMT_HA (struct obuf *ob, const TPMT_HA *tpmtha) |
static int | marshal_TPML_DIGEST_VALUES (struct obuf *ob, const TPML_DIGEST_VALUES *dvalues) |
static int | marshal_session_header (struct obuf *ob, const struct tpm2_session_header *session_header) |
static int | marshal_common_session_header (struct obuf *ob, const uint32_t *handles, size_t handle_count) |
static int | marshal_nv_define_space (struct obuf *ob, const struct tpm2_nv_define_space_cmd *nvd_in) |
static int | marshal_nv_setbits (struct obuf *ob, const struct tpm2_nv_setbits_cmd *command_body) |
static int | marshal_nv_write (struct obuf *ob, const struct tpm2_nv_write_cmd *command_body) |
static int | marshal_nv_write_lock (struct obuf *ob, const struct tpm2_nv_write_lock_cmd *command_body) |
static int | marshal_pcr_extend (struct obuf *ob, const struct tpm2_pcr_extend_cmd *command_body) |
static int | marshal_nv_read (struct obuf *ob, const struct tpm2_nv_read_cmd *command_body) |
static int | marshal_clear (struct obuf *ob) |
static int | marshal_selftest (struct obuf *ob, const struct tpm2_self_test *command_body) |
static int | marshal_hierarchy_control (struct obuf *ob, const struct tpm2_hierarchy_control_cmd *command_body) |
static int | marshal_clear_control (struct obuf *ob, const struct tpm2_clear_control_cmd *command_body) |
static int | marshal_cr50_vendor_command (struct obuf *ob, const void *command_body) |
int | tpm_marshal_command (TPM_CC command, const void *tpm_command_body, struct obuf *ob) |
tpm_marshal_command More... | |
static int | unmarshal_get_capability (struct ibuf *ib, struct get_cap_response *gcr) |
static int | unmarshal_TPM2B_MAX_NV_BUFFER (struct ibuf *ib, TPM2B_MAX_NV_BUFFER *nv_buffer) |
static int | unmarshal_nv_read (struct ibuf *ib, struct nv_read_response *nvr) |
static int | unmarshal_vendor_command (struct ibuf *ib, struct vendor_command_response *vcr) |
struct tpm2_response * | tpm_unmarshal_response (TPM_CC command, struct ibuf *ib) |
tpm_unmarshal_response More... | |
Variables | |
static uint16_t | tpm_tag |
#define marshal_TPM_HANDLE | ( | a, | |
b | |||
) | obuf_write_be32(a, b) |
Definition at line 18 of file tss_marshaling.c.
#define marshal_TPMI_ALG_HASH | ( | a, | |
b | |||
) | obuf_write_be16(a, b) |
Definition at line 19 of file tss_marshaling.c.
#define unmarshal_TPM_CAP | ( | a, | |
b | |||
) | ibuf_read_be32(a, b) |
Definition at line 13 of file tss_marshaling.c.
#define unmarshal_TPM_CC | ( | a, | |
b | |||
) | ibuf_read_be32(a, b) |
Definition at line 14 of file tss_marshaling.c.
#define unmarshal_TPM_HANDLE | ( | a, | |
b | |||
) | ibuf_read_be32(a, b) |
Definition at line 16 of file tss_marshaling.c.
#define unmarshal_TPM_PT | ( | a, | |
b | |||
) | ibuf_read_be32(a, b) |
Definition at line 15 of file tss_marshaling.c.
|
static |
Definition at line 259 of file tss_marshaling.c.
References ARRAY_SIZE, marshal_common_session_header(), and TPM_RH_PLATFORM.
Referenced by tpm_marshal_command().
|
static |
Definition at line 291 of file tss_marshaling.c.
References tpm2_clear_control_cmd::disable, marshal_session_header(), marshal_TPM_HANDLE, memset(), obuf_write_be8(), tpm2_session_header::session_handle, TPM_RH_PLATFORM, TPM_RS_PW, TPM_ST_SESSIONS, and tpm_tag.
Referenced by tpm_marshal_command().
|
static |
Definition at line 153 of file tss_marshaling.c.
References marshal_session_header(), marshal_TPM_HANDLE, memset(), tpm2_session_header::session_handle, TPM_RS_PW, TPM_ST_SESSIONS, and tpm_tag.
Referenced by marshal_clear(), marshal_nv_define_space(), marshal_nv_read(), marshal_nv_setbits(), marshal_nv_write(), marshal_nv_write_lock(), and marshal_pcr_extend().
Definition at line 309 of file tss_marshaling.c.
References BIOS_WARNING, obuf_write_be16(), printk, TPM2_CR50_SUB_CMD_GET_BOOT_MODE, TPM2_CR50_SUB_CMD_GET_REC_BTN, TPM2_CR50_SUB_CMD_IMMEDIATE_RESET, TPM2_CR50_SUB_CMD_NVMEM_ENABLE_COMMITS, TPM2_CR50_SUB_CMD_RESET_EC, TPM2_CR50_SUB_CMD_TPM_MODE, and TPM2_CR50_SUB_CMD_TURN_UPDATE_ON.
Referenced by tpm_marshal_command().
|
static |
Definition at line 31 of file tss_marshaling.c.
References tpm2_get_capability::capability, obuf_write_be32(), tpm2_get_capability::property, and tpm2_get_capability::propertyCount.
Referenced by tpm_marshal_command().
|
static |
Definition at line 272 of file tss_marshaling.c.
References tpm2_hierarchy_control_cmd::enable, marshal_session_header(), marshal_TPM_HANDLE, memset(), obuf_write_be8(), tpm2_session_header::session_handle, tpm2_hierarchy_control_cmd::state, TPM_RH_PLATFORM, TPM_RS_PW, TPM_ST_SESSIONS, and tpm_tag.
Referenced by tpm_marshal_command().
|
static |
Definition at line 173 of file tss_marshaling.c.
References ARRAY_SIZE, tpm2_nv_define_space_cmd::auth, TPM2B_DIGEST::b, marshal_common_session_header(), marshal_TPM2B(), marshal_TPMS_NV_PUBLIC(), obuf_nr_written(), obuf_splice_current(), obuf_write_be16(), tpm2_nv_define_space_cmd::publicInfo, and TPM_RH_PLATFORM.
Referenced by tpm_marshal_command().
|
static |
Definition at line 245 of file tss_marshaling.c.
References ARRAY_SIZE, marshal_common_session_header(), tpm2_nv_read_cmd::nvIndex, obuf_write_be16(), tpm2_nv_read_cmd::offset, tpm2_nv_read_cmd::size, and TPM_RH_PLATFORM.
Referenced by tpm_marshal_command().
|
static |
Definition at line 200 of file tss_marshaling.c.
References ARRAY_SIZE, tpm2_nv_setbits_cmd::bits, marshal_common_session_header(), tpm2_nv_setbits_cmd::nvIndex, obuf_write_be64(), and TPM_RH_PLATFORM.
Referenced by tpm_marshal_command().
|
static |
Definition at line 212 of file tss_marshaling.c.
References ARRAY_SIZE, TPM2B_MAX_NV_BUFFER::b, tpm2_nv_write_cmd::data, marshal_common_session_header(), marshal_TPM2B(), tpm2_nv_write_cmd::nvIndex, obuf_write_be16(), tpm2_nv_write_cmd::offset, and TPM_RH_PLATFORM.
Referenced by tpm_marshal_command().
|
static |
Definition at line 225 of file tss_marshaling.c.
References ARRAY_SIZE, marshal_common_session_header(), tpm2_nv_write_lock_cmd::nvIndex, and TPM_RH_PLATFORM.
Referenced by tpm_marshal_command().
|
static |
Definition at line 233 of file tss_marshaling.c.
References ARRAY_SIZE, tpm2_pcr_extend_cmd::digests, marshal_common_session_header(), marshal_TPML_DIGEST_VALUES(), and tpm2_pcr_extend_cmd::pcrHandle.
Referenced by tpm_marshal_command().
|
static |
Definition at line 266 of file tss_marshaling.c.
References obuf_write_be8(), and tpm2_self_test::yes_no.
Referenced by tpm_marshal_command().
|
static |
Definition at line 119 of file tss_marshaling.c.
References tpm2_session_header::auth, tpm2_session_header::auth_size, tpm2_session_header::nonce, tpm2_session_header::nonce_size, obuf_nr_written(), obuf_splice_current(), obuf_write(), obuf_write_be16(), obuf_write_be32(), obuf_write_be8(), tpm2_session_header::session_attrs, and tpm2_session_header::session_handle.
Referenced by marshal_clear_control(), marshal_common_session_header(), and marshal_hierarchy_control().
|
static |
Definition at line 26 of file tss_marshaling.c.
References obuf_write_be16(), and tpm2_shutdown::shutdown_type.
Referenced by tpm_marshal_command().
|
static |
Definition at line 21 of file tss_marshaling.c.
References obuf_write_be16(), and tpm2_startup::startup_type.
Referenced by tpm_marshal_command().
Definition at line 43 of file tss_marshaling.c.
References TPM2B::buffer, obuf_write(), obuf_write_be16(), and TPM2B::size.
Referenced by marshal_nv_define_space(), marshal_nv_write(), and marshal_TPMS_NV_PUBLIC().
Definition at line 53 of file tss_marshaling.c.
References memcpy(), and obuf_write_be32().
Referenced by marshal_TPMS_NV_PUBLIC().
|
static |
Definition at line 106 of file tss_marshaling.c.
References TPML_DIGEST_VALUES::count, TPML_DIGEST_VALUES::digests, marshal_TPMT_HA(), and obuf_write_be32().
Referenced by marshal_pcr_extend().
|
static |
Definition at line 61 of file tss_marshaling.c.
References TPMS_NV_PUBLIC::attributes, TPMS_NV_PUBLIC::authPolicy, TPM2B_DIGEST::b, TPMS_NV_PUBLIC::dataSize, marshal_TPM2B(), marshal_TPM_HANDLE, marshal_TPMA_NV(), marshal_TPMI_ALG_HASH, TPMS_NV_PUBLIC::nameAlg, TPMS_NV_PUBLIC::nvIndex, and obuf_write_be16().
Referenced by marshal_nv_define_space().
Definition at line 74 of file tss_marshaling.c.
References TPMT_HA::digest, TPMT_HA::hashAlg, marshal_TPMI_ALG_HASH, obuf_write(), TPMU_HA::sha1, TPMU_HA::sha256, TPMU_HA::sha384, TPMU_HA::sha512, TPMU_HA::sm3_256, tlcl_get_hash_size_from_algo(), TPM_ALG_SHA1, TPM_ALG_SHA256, TPM_ALG_SHA384, TPM_ALG_SHA512, and TPM_ALG_SM3_256.
Referenced by marshal_TPML_DIGEST_VALUES().
tpm_marshal_command
Given a structure containing a TPM2 command, serialize the structure for sending it to the TPM.
@command: code of the TPM2 command to marshal @tpm_command_body: a pointer to the command specific structure @ob: output buffer where command is marshaled to
Returns 0 on success or -1 on error.
Definition at line 361 of file tss_marshaling.c.
References BIOS_INFO, marshal_clear(), marshal_clear_control(), marshal_cr50_vendor_command(), marshal_get_capability(), marshal_hierarchy_control(), marshal_nv_define_space(), marshal_nv_read(), marshal_nv_setbits(), marshal_nv_write(), marshal_nv_write_lock(), marshal_pcr_extend(), marshal_selftest(), marshal_shutdown(), marshal_startup(), obuf_nr_written(), obuf_splice_current(), obuf_write_be16(), obuf_write_be32(), printk, TPM2_Clear, TPM2_ClearControl, TPM2_CR50_VENDOR_COMMAND, TPM2_GetCapability, TPM2_Hierarchy_Control, TPM2_NV_DefineSpace, TPM2_NV_Read, TPM2_NV_SetBits, TPM2_NV_Write, TPM2_NV_WriteLock, TPM2_PCR_Extend, TPM2_SelfTest, TPM2_Shutdown, TPM2_Startup, TPM_ST_NO_SESSIONS, and tpm_tag.
Referenced by tpm_process_command().
struct tpm2_response* tpm_unmarshal_response | ( | TPM_CC | command, |
struct ibuf * | ib | ||
) |
tpm_unmarshal_response
Given a buffer received from the TPM in response to a certain command, deserialize the buffer into the expected response structure.
struct tpm2_response is a union of all possible responses.
@command: code of the TPM2 command for which a response is unmarshaled @ib: input buffer containing the serialized response.
Returns a pointer to the deserialized response or NULL in case of unmarshaling problems.
Definition at line 594 of file tss_marshaling.c.
References BIOS_ERR, BIOS_INFO, BIOS_WARNING, tpm2_response::gc, tpm2_response::hdr, ibuf_capacity(), ibuf_oob_drain(), ibuf_read_be16(), ibuf_read_be32(), ibuf_remaining(), NULL, tpm2_response::nvr, printk, TPM2_Clear, TPM2_ClearControl, TPM2_CR50_VENDOR_COMMAND, TPM2_GetCapability, TPM2_Hierarchy_Control, TPM2_NV_DefineSpace, TPM2_NV_Read, TPM2_NV_SetBits, TPM2_NV_Write, TPM2_NV_WriteLock, TPM2_PCR_Extend, TPM2_RC_SUCCESS, TPM2_SelfTest, TPM2_Shutdown, TPM2_Startup, tpm_header::tpm_code, tpm_header::tpm_size, tpm_header::tpm_tag, unmarshal_get_capability(), unmarshal_nv_read(), unmarshal_TPM_CC, unmarshal_vendor_command(), and tpm2_response::vcr.
Referenced by tpm_process_command().
|
static |
Definition at line 453 of file tss_marshaling.c.
References ARRAY_SIZE, TPMU_CAPABILITIES::assignedPCR, BIOS_ERR, BIOS_INFO, TPMS_CAPABILITY_DATA::capability, get_cap_response::cd, TPML_TAGGED_TPM_PROPERTY::count, TPMS_CAPABILITY_DATA::data, ibuf_read(), ibuf_read_be32(), ibuf_read_be8(), get_cap_response::more_data, printk, TPMS_TAGGED_PROPERTY::property, TPM_CAP_PCRS, TPM_CAP_TPM_PROPERTIES, TPMU_CAPABILITIES::tpmProperties, TPML_TAGGED_TPM_PROPERTY::tpmProperty, unmarshal_TPM_CAP, unmarshal_TPM_PT, and TPMS_TAGGED_PROPERTY::value.
Referenced by tpm_unmarshal_response().
|
static |
Definition at line 531 of file tss_marshaling.c.
References BIOS_ERR, nv_read_response::buffer, ibuf_oob_drain(), ibuf_read_be32(), ibuf_remaining(), nv_read_response::params_size, printk, TPM2B_MAX_NV_BUFFER::size, TPM2B_MAX_NV_BUFFER::t, and unmarshal_TPM2B_MAX_NV_BUFFER().
Referenced by tpm_unmarshal_response().
|
static |
Definition at line 512 of file tss_marshaling.c.
References BIOS_ERR, TPM2B_MAX_NV_BUFFER::buffer, ibuf_oob_drain(), ibuf_read_be16(), ibuf_remaining(), NULL, printk, TPM2B_MAX_NV_BUFFER::size, and TPM2B_MAX_NV_BUFFER::t.
Referenced by unmarshal_nv_read().
|
static |
Definition at line 563 of file tss_marshaling.c.
References BIOS_ERR, vendor_command_response::boot_mode, ibuf_read_be16(), ibuf_read_be8(), vendor_command_response::num_restored_headers, printk, vendor_command_response::recovery_button_state, TPM2_CR50_SUB_CMD_GET_BOOT_MODE, TPM2_CR50_SUB_CMD_GET_REC_BTN, TPM2_CR50_SUB_CMD_IMMEDIATE_RESET, TPM2_CR50_SUB_CMD_NVMEM_ENABLE_COMMITS, TPM2_CR50_SUB_CMD_RESET_EC, TPM2_CR50_SUB_CMD_TPM_MODE, TPM2_CR50_SUB_CMD_TURN_UPDATE_ON, vendor_command_response::tpm_mode, and vendor_command_response::vc_subcommand.
Referenced by tpm_unmarshal_response().
|
static |
Definition at line 11 of file tss_marshaling.c.
Referenced by marshal_clear_control(), marshal_common_session_header(), marshal_hierarchy_control(), and tpm_marshal_command().