blob: e177d0609a02649de3079785e49dd3943214de2b [file] [log] [blame]
Vadim Bendebury627afc22016-06-19 12:13:18 -07001/*
2 * Copyright 2016 The Chromium OS Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6#ifndef __SRC_LIB_TPM2_MARSHALING_H
7#define __SRC_LIB_TPM2_MARSHALING_H
8
9#include "tpm2_tlcl_structures.h"
10
11/* The below functions are used to serialize/deserialize TPM2 commands. */
12
13/**
14 * tpm_marshal_command
15 *
16 * Given a structure containing a TPM2 command, serialize the structure for
17 * sending it to the TPM.
18 *
19 * @command: code of the TPM2 command to marshal
20 * @tpm_command_body: a pointer to the command specific structure
21 * @buffer: buffer where command is marshaled to
22 * @buffer_size: size of the buffer
23 *
24 * Returns number of bytes placed in the buffer, or -1 on error.
25 *
26 */
27int tpm_marshal_command(TPM_CC command, void *tpm_command_body,
Vadim Bendeburybc927102016-07-07 10:52:46 -070028 void *buffer, size_t buffer_size);
Vadim Bendebury627afc22016-06-19 12:13:18 -070029
30/**
31 * tpm_unmarshal_response
32 *
33 * Given a buffer received from the TPM in response to a certain command,
34 * deserialize the buffer into the expeced response structure.
35 *
36 * struct tpm2_response is a union of all possible responses.
37 *
38 * @command: code of the TPM2 command for which a response is unmarshaled
39 * @response_body: buffer containing the serialized response.
40 * @response_size: number of bytes in the buffer containing response
41 *
42 * Returns a pointer to the deserialized response or NULL in case of
43 * unmarshaling problems.
44 */
45struct tpm2_response *tpm_unmarshal_response(TPM_CC command,
46 void *response_body,
Vadim Bendeburybc927102016-07-07 10:52:46 -070047 size_t response_size);
Vadim Bendebury627afc22016-06-19 12:13:18 -070048
49#endif // __SRC_LIB_TPM2_MARSHALING_H