1 /* SPDX-License-Identifier: BSD-3-Clause */ 2 3 #ifndef TCG2_TSS_MARSHALING_H_ 4 #define TCG2_TSS_MARSHALING_H_ 5 6 #include <commonlib/iobuf.h> 7 #include "tss_structures.h" 8 9 /* The below functions are used to serialize/deserialize TPM2 commands. */ 10 11 /** 12 * tpm_marshal_command 13 * 14 * Given a structure containing a TPM2 command, serialize the structure for 15 * sending it to the TPM. 16 * 17 * @command: code of the TPM2 command to marshal 18 * @tpm_command_body: a pointer to the command specific structure 19 * @ob: output buffer where command is marshaled to 20 * 21 * Returns 0 on success or -1 on error. 22 * 23 */ 24 int tpm_marshal_command(TPM_CC command, const void *tpm_command_body, 25 struct obuf *ob); 26 27 /** 28 * tpm_unmarshal_response 29 * 30 * Given a buffer received from the TPM in response to a certain command, 31 * deserialize the buffer into the expected response structure. 32 * 33 * struct tpm2_response is a union of all possible responses. 34 * 35 * @command: code of the TPM2 command for which a response is unmarshaled 36 * @ib: input buffer containing the serialized response. 37 * 38 * Returns a pointer to the deserialized response or NULL in case of 39 * unmarshaling problems. 40 */ 41 struct tpm2_response *tpm_unmarshal_response(TPM_CC command, struct ibuf *ib); 42 43 #endif // TCG2_TSS_MARSHALING_H_ 44