1 /*
2  * Copyright (C) 2018-2022 Intel Corporation.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _TPM_INTERNAL_H_
8 #define _TPM_INTERNAL_H_
9 
10 /* TPMCommBuffer will package TPM2 command and
11  * response which are handled by TPM emulator
12  *
13  * locty: the locality TPM emulator used
14  * in & in_len: To indicate the buffer and the
15  *    size for TPM command
16  * out & out_len: To indicate the buffer and
17  *    the size for TPM response
18  */
19 typedef struct TPMCommBuffer {
20 	uint8_t locty;
21 	const uint8_t *in;
22 	uint32_t in_len;
23 	uint8_t *out;
24 	uint32_t out_len;
25 	bool selftest_done;
26 } TPMCommBuffer;
27 
28 /* APIs by tpm_emulator.c */
29 /* Create Ctrl channel and Cmd channel so as to communicate with SWTPM */
30 int init_tpm_emulator(const char *sock_path);
31 
32 /* Shutdown of SWTPM and close Ctrl channel and Cmd channel */
33 void deinit_tpm_emulator(void);
34 
35 /* Send Ctrl channel command CMD_GET_TPMESTABLISHED to SWTPM */
36 bool swtpm_get_tpm_established_flag(void);
37 
38 /* Send TPM2 command request to SWTPM by using Cmd channel */
39 int swtpm_handle_request(TPMCommBuffer *cmd);
40 
41 /* Initialization for SWTPM */
42 int swtpm_startup(size_t buffersize);
43 
44 /* Cancellation of the current TPM2 command */
45 void swtpm_cancel_cmd(void);
46 
47 /* APIs by tpm_crb.c */
48 /* Initialize TPM CRB Virtual Device */
49 int init_tpm_crb(struct vmctx *ctx);
50 
51 /* Deinitialize TPM CRB Virtual Device */
52 void deinit_tpm_crb(struct vmctx *ctx);
53 
54 #endif
55