coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
tss_marshaling.c File Reference
Include dependency graph for tss_marshaling.c:

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_responsetpm_unmarshal_response (TPM_CC command, struct ibuf *ib)
 tpm_unmarshal_response More...
 

Variables

static uint16_t tpm_tag
 

Macro Definition Documentation

◆ marshal_TPM_HANDLE

#define marshal_TPM_HANDLE (   a,
 
)    obuf_write_be32(a, b)

Definition at line 18 of file tss_marshaling.c.

◆ marshal_TPMI_ALG_HASH

#define marshal_TPMI_ALG_HASH (   a,
 
)    obuf_write_be16(a, b)

Definition at line 19 of file tss_marshaling.c.

◆ unmarshal_TPM_CAP

#define unmarshal_TPM_CAP (   a,
 
)    ibuf_read_be32(a, b)

Definition at line 13 of file tss_marshaling.c.

◆ unmarshal_TPM_CC

#define unmarshal_TPM_CC (   a,
 
)    ibuf_read_be32(a, b)

Definition at line 14 of file tss_marshaling.c.

◆ unmarshal_TPM_HANDLE

#define unmarshal_TPM_HANDLE (   a,
 
)    ibuf_read_be32(a, b)

Definition at line 16 of file tss_marshaling.c.

◆ unmarshal_TPM_PT

#define unmarshal_TPM_PT (   a,
 
)    ibuf_read_be32(a, b)

Definition at line 15 of file tss_marshaling.c.

Function Documentation

◆ marshal_clear()

static int marshal_clear ( struct obuf ob)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_clear_control()

static int marshal_clear_control ( struct obuf ob,
const struct tpm2_clear_control_cmd command_body 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_common_session_header()

static int marshal_common_session_header ( struct obuf ob,
const uint32_t handles,
size_t  handle_count 
)
static

◆ marshal_cr50_vendor_command()

static int marshal_cr50_vendor_command ( struct obuf ob,
const void command_body 
)
static

◆ marshal_get_capability()

static int marshal_get_capability ( struct obuf ob,
const struct tpm2_get_capability cmd_body 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_hierarchy_control()

static int marshal_hierarchy_control ( struct obuf ob,
const struct tpm2_hierarchy_control_cmd command_body 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_nv_define_space()

static int marshal_nv_define_space ( struct obuf ob,
const struct tpm2_nv_define_space_cmd nvd_in 
)
static

◆ marshal_nv_read()

static int marshal_nv_read ( struct obuf ob,
const struct tpm2_nv_read_cmd command_body 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_nv_setbits()

static int marshal_nv_setbits ( struct obuf ob,
const struct tpm2_nv_setbits_cmd command_body 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_nv_write()

static int marshal_nv_write ( struct obuf ob,
const struct tpm2_nv_write_cmd command_body 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_nv_write_lock()

static int marshal_nv_write_lock ( struct obuf ob,
const struct tpm2_nv_write_lock_cmd command_body 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_pcr_extend()

static int marshal_pcr_extend ( struct obuf ob,
const struct tpm2_pcr_extend_cmd command_body 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_selftest()

static int marshal_selftest ( struct obuf ob,
const struct tpm2_self_test command_body 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_session_header()

static int marshal_session_header ( struct obuf ob,
const struct tpm2_session_header session_header 
)
static

◆ marshal_shutdown()

static int marshal_shutdown ( struct obuf ob,
const struct tpm2_shutdown cmd_body 
)
static

Definition at line 26 of file tss_marshaling.c.

References obuf_write_be16(), and tpm2_shutdown::shutdown_type.

Referenced by tpm_marshal_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_startup()

static int marshal_startup ( struct obuf ob,
const struct tpm2_startup cmd_body 
)
static

Definition at line 21 of file tss_marshaling.c.

References obuf_write_be16(), and tpm2_startup::startup_type.

Referenced by tpm_marshal_command().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_TPM2B()

static int marshal_TPM2B ( struct obuf ob,
const TPM2B data 
)
static

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_TPMA_NV()

static int marshal_TPMA_NV ( struct obuf ob,
const TPMA_NV nv 
)
static

Definition at line 53 of file tss_marshaling.c.

References memcpy(), and obuf_write_be32().

Referenced by marshal_TPMS_NV_PUBLIC().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_TPML_DIGEST_VALUES()

static int marshal_TPML_DIGEST_VALUES ( struct obuf ob,
const TPML_DIGEST_VALUES dvalues 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ marshal_TPMS_NV_PUBLIC()

static int marshal_TPMS_NV_PUBLIC ( struct obuf ob,
const TPMS_NV_PUBLIC nvpub 
)
static

◆ marshal_TPMT_HA()

static int marshal_TPMT_HA ( struct obuf ob,
const TPMT_HA tpmtha 
)
static

◆ tpm_marshal_command()

int tpm_marshal_command ( TPM_CC  command,
const void tpm_command_body,
struct obuf ob 
)

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ tpm_unmarshal_response()

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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unmarshal_get_capability()

◆ unmarshal_nv_read()

static int unmarshal_nv_read ( struct ibuf ib,
struct nv_read_response nvr 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unmarshal_TPM2B_MAX_NV_BUFFER()

static int unmarshal_TPM2B_MAX_NV_BUFFER ( struct ibuf ib,
TPM2B_MAX_NV_BUFFER nv_buffer 
)
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().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ unmarshal_vendor_command()

Variable Documentation

◆ tpm_tag