xref: /aosp_15_r20/external/vboot_reference/firmware/include/tpm2_marshaling.h (revision 8617a60d3594060b7ecbd21bc622a7c14f3cf2bc)
1*8617a60dSAndroid Build Coastguard Worker /* Copyright 2016 The ChromiumOS Authors
2*8617a60dSAndroid Build Coastguard Worker  * Use of this source code is governed by a BSD-style license that can be
3*8617a60dSAndroid Build Coastguard Worker  * found in the LICENSE file.
4*8617a60dSAndroid Build Coastguard Worker  */
5*8617a60dSAndroid Build Coastguard Worker 
6*8617a60dSAndroid Build Coastguard Worker #ifndef VBOOT_REFERENCE_TPM2_MARSHALING_H_
7*8617a60dSAndroid Build Coastguard Worker #define VBOOT_REFERENCE_TPM2_MARSHALING_H_
8*8617a60dSAndroid Build Coastguard Worker 
9*8617a60dSAndroid Build Coastguard Worker #include "tss_constants.h"
10*8617a60dSAndroid Build Coastguard Worker 
11*8617a60dSAndroid Build Coastguard Worker #ifdef __cplusplus
12*8617a60dSAndroid Build Coastguard Worker extern "C" {
13*8617a60dSAndroid Build Coastguard Worker #endif  /* __cplusplus */
14*8617a60dSAndroid Build Coastguard Worker 
15*8617a60dSAndroid Build Coastguard Worker /* The below functions are used to serialize/deserialize TPM2 commands. */
16*8617a60dSAndroid Build Coastguard Worker 
17*8617a60dSAndroid Build Coastguard Worker /**
18*8617a60dSAndroid Build Coastguard Worker  * tpm_marshal_command
19*8617a60dSAndroid Build Coastguard Worker  *
20*8617a60dSAndroid Build Coastguard Worker  * Given a structure containing a TPM2 command, serialize the structure for
21*8617a60dSAndroid Build Coastguard Worker  * sending it to the TPM.
22*8617a60dSAndroid Build Coastguard Worker  *
23*8617a60dSAndroid Build Coastguard Worker  * @command: code of the TPM2 command to marshal
24*8617a60dSAndroid Build Coastguard Worker  * @tpm_command_body: a pointer to the command specific structure
25*8617a60dSAndroid Build Coastguard Worker  * @buffer: buffer where command is marshaled to
26*8617a60dSAndroid Build Coastguard Worker  * @buffer_size: size of the buffer
27*8617a60dSAndroid Build Coastguard Worker  *
28*8617a60dSAndroid Build Coastguard Worker  * Returns number of bytes placed in the buffer, or -1 on error.
29*8617a60dSAndroid Build Coastguard Worker  *
30*8617a60dSAndroid Build Coastguard Worker  */
31*8617a60dSAndroid Build Coastguard Worker int tpm_marshal_command(TPM_CC command, void *tpm_command_body,
32*8617a60dSAndroid Build Coastguard Worker 			void *buffer, int buffer_size);
33*8617a60dSAndroid Build Coastguard Worker 
34*8617a60dSAndroid Build Coastguard Worker /**
35*8617a60dSAndroid Build Coastguard Worker  * tpm_unmarshal_response
36*8617a60dSAndroid Build Coastguard Worker  *
37*8617a60dSAndroid Build Coastguard Worker  * Given a buffer received from the TPM in response to a certain command,
38*8617a60dSAndroid Build Coastguard Worker  * deserialize the buffer into the expeced response structure.
39*8617a60dSAndroid Build Coastguard Worker  *
40*8617a60dSAndroid Build Coastguard Worker  * @command: code of the TPM2 command for which a response is unmarshaled
41*8617a60dSAndroid Build Coastguard Worker  * @response_body: buffer containing the serialized response.
42*8617a60dSAndroid Build Coastguard Worker  * @response_size: number of bytes in the buffer containing response
43*8617a60dSAndroid Build Coastguard Worker  * @response: structure to be filled with deserialized response,
44*8617a60dSAndroid Build Coastguard Worker  *            struct tpm2_response is a union of all possible responses.
45*8617a60dSAndroid Build Coastguard Worker  *
46*8617a60dSAndroid Build Coastguard Worker  * Returns 0 on success, or -1 on error.
47*8617a60dSAndroid Build Coastguard Worker  */
48*8617a60dSAndroid Build Coastguard Worker int tpm_unmarshal_response(TPM_CC command,
49*8617a60dSAndroid Build Coastguard Worker 			   void *response_body,
50*8617a60dSAndroid Build Coastguard Worker 			   int response_size,
51*8617a60dSAndroid Build Coastguard Worker 			   struct tpm2_response *response);
52*8617a60dSAndroid Build Coastguard Worker 
53*8617a60dSAndroid Build Coastguard Worker /**
54*8617a60dSAndroid Build Coastguard Worker  * tpm_get_packet_size
55*8617a60dSAndroid Build Coastguard Worker  *
56*8617a60dSAndroid Build Coastguard Worker  * @packet: pointer to the start of the command or response packet.
57*8617a60dSAndroid Build Coastguard Worker  *
58*8617a60dSAndroid Build Coastguard Worker  * Returns the size of the tpm packet.
59*8617a60dSAndroid Build Coastguard Worker  */
60*8617a60dSAndroid Build Coastguard Worker uint32_t tpm_get_packet_size(const uint8_t *packet);
61*8617a60dSAndroid Build Coastguard Worker 
62*8617a60dSAndroid Build Coastguard Worker /**
63*8617a60dSAndroid Build Coastguard Worker  * tpm_get_packet_response_code
64*8617a60dSAndroid Build Coastguard Worker  *
65*8617a60dSAndroid Build Coastguard Worker  * @packet: pointer to the start of the response packet.
66*8617a60dSAndroid Build Coastguard Worker  *
67*8617a60dSAndroid Build Coastguard Worker  * Returns the response code.
68*8617a60dSAndroid Build Coastguard Worker  */
69*8617a60dSAndroid Build Coastguard Worker uint32_t tpm_get_packet_response_code(const uint8_t *packet);
70*8617a60dSAndroid Build Coastguard Worker 
71*8617a60dSAndroid Build Coastguard Worker /**
72*8617a60dSAndroid Build Coastguard Worker  * tpm_set_ph_disabled
73*8617a60dSAndroid Build Coastguard Worker  *
74*8617a60dSAndroid Build Coastguard Worker  * Sets the flag that indicates if platform hierarchy is disabled.
75*8617a60dSAndroid Build Coastguard Worker  * Certain commands, like NV_Read, may need to use different
76*8617a60dSAndroid Build Coastguard Worker  * authorization if platform hierarchy is disabled.
77*8617a60dSAndroid Build Coastguard Worker  *
78*8617a60dSAndroid Build Coastguard Worker  * @flag: 1 if platform hierarchy is disabled, 0 otherwise
79*8617a60dSAndroid Build Coastguard Worker  */
80*8617a60dSAndroid Build Coastguard Worker void tpm_set_ph_disabled(int flag);
81*8617a60dSAndroid Build Coastguard Worker 
82*8617a60dSAndroid Build Coastguard Worker /**
83*8617a60dSAndroid Build Coastguard Worker  * tpm_is_ph_disabled
84*8617a60dSAndroid Build Coastguard Worker  *
85*8617a60dSAndroid Build Coastguard Worker  * Gets the flag that indicates if platform hierarchy is disabled.
86*8617a60dSAndroid Build Coastguard Worker  * Certain commands, like NV_Read, may need to use different
87*8617a60dSAndroid Build Coastguard Worker  * authorization if platform hierarchy is disabled.
88*8617a60dSAndroid Build Coastguard Worker  *
89*8617a60dSAndroid Build Coastguard Worker  * Returns 1 if platform hierarchy is disabled, 0 otherwise
90*8617a60dSAndroid Build Coastguard Worker  */
91*8617a60dSAndroid Build Coastguard Worker int tpm_is_ph_disabled(void);
92*8617a60dSAndroid Build Coastguard Worker 
93*8617a60dSAndroid Build Coastguard Worker #ifdef __cplusplus
94*8617a60dSAndroid Build Coastguard Worker }
95*8617a60dSAndroid Build Coastguard Worker #endif  /* __cplusplus */
96*8617a60dSAndroid Build Coastguard Worker 
97*8617a60dSAndroid Build Coastguard Worker #endif  /* VBOOT_REFERENCE_TPM2_MARSHALING_H_ */
98