• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************
3  * Copyright (c) 2015 - 2018 Intel Corporation
4  * All rights reserved.
5  ***********************************************************************/
6 #ifndef TCTI_COMMON_H
7 #define TCTI_COMMON_H
8 
9 #include <errno.h>
10 #include <stdbool.h>
11 
12 #include "tss2_tcti.h"
13 
14 #define TCTI_VERSION 0x2
15 
16 #define TPM_HEADER_SIZE (sizeof (TPM2_ST) + sizeof (UINT32) + sizeof (UINT32))
17 
18 typedef struct {
19     TPM2_ST tag;
20     UINT32 size;
21     UINT32 code;
22 } tpm_header_t;
23 /*
24  * The elements in this enumeration represent the possible states that the
25  * TCTI can be in. The state machine is as follows:
26  * An instantiated TCTI context begins in the TRANSMIT state:
27  *   TRANSMIT:
28  *     transmit:    success transitions the state machine to RECEIVE
29  *                  failure leaves the state unchanged
30  *     receive:     produces TSS2_TCTI_RC_BAD_SEQUENCE
31  *     finalize:    transitions state machine to FINAL state
32  *     cancel:      produces TSS2_TCTI_RC_BAD_SEQUENCE
33  *     setLocality: success or failure leaves state unchanged
34  *   RECEIVE:
35  *     transmit:    produces TSS2_TCTI_RC_BAD_SEQUENCE
36  *     receive:     success transitions the state machine to TRANSMIT
37  *                  failure with the following RCs leave the state unchanged:
38  *                    TRY_AGAIN, INSUFFICIENT_BUFFER, BAD_CONTEXT,
39  *                    BAD_REFERENCE, BAD_VALUE, BAD_SEQUENCE
40  *                  all other failures transition state machine to
41  *                    TRANSMIT (not recoverable)
42  *     finalize:    transitions state machine to FINAL state
43  *     cancel:      success transitions state machine to TRANSMIT
44  *                  failure leaves state unchanged
45  *     setLocality: produces TSS2_TCTI_RC_BAD_SEQUENCE
46  *   FINAL:
47  *     all function calls produce TSS2_TCTI_RC_BAD_SEQUENCE
48  */
49 typedef enum {
50     TCTI_STATE_FINAL,
51     TCTI_STATE_TRANSMIT,
52     TCTI_STATE_RECEIVE,
53 } tcti_state_t;
54 
55 typedef struct {
56     TSS2_TCTI_CONTEXT_COMMON_V2 v2;
57     tcti_state_t state;
58     tpm_header_t header;
59     uint8_t locality;
60     bool partial;
61 } TSS2_TCTI_COMMON_CONTEXT;
62 
63 /*
64  */
65 TSS2_TCTI_COMMON_CONTEXT*
66 tcti_common_context_cast (TSS2_TCTI_CONTEXT *ctx);
67 /*
68  * This function is used to "down cast" the Intel TCTI context to the opaque
69  * context type.
70  */
71 TSS2_TCTI_CONTEXT*
72 tcti_common_down_cast (TSS2_TCTI_COMMON_CONTEXT *ctx);
73 /*
74  * This function performs checks on the common context structure passed to a
75  * TCTI 'cancel' function.
76  */
77 TSS2_RC
78 tcti_common_cancel_checks (
79     TSS2_TCTI_COMMON_CONTEXT *tcti_common);
80 /*
81  * This function performs common checks on the context structure and the
82  * buffer passed into TCTI 'transmit' functions.
83  */
84 TSS2_RC
85 tcti_common_transmit_checks (
86     TSS2_TCTI_COMMON_CONTEXT *tcti_common,
87     const uint8_t *command_buffer);
88 /*
89  * This function performs common checks on the context structure, buffer and
90  * size parameter passed to the TCTI 'receive' functions.
91  */
92 TSS2_RC
93 tcti_common_receive_checks (
94     TSS2_TCTI_COMMON_CONTEXT *tcti_common,
95     size_t *response_size);
96 /*
97  * This function performs checks on the common context structure passed to a
98  * TCTI 'set_locality' function.
99  */
100 TSS2_RC
101 tcti_common_set_locality_checks (
102     TSS2_TCTI_COMMON_CONTEXT *tcti_common);
103 /*
104  * Just a function with the right prototype that returns the not implemented
105  * RC for the TCTI layer.
106  */
107 TSS2_RC
108 tcti_make_sticky_not_implemented (
109     TSS2_TCTI_CONTEXT *tctiContext,
110     TPM2_HANDLE *handle,
111     uint8_t sticky);
112 /*
113  * Utility to function to parse the first 10 bytes of a buffer and populate
114  * the 'header' structure with the results. The provided buffer is assumed to
115  * be at least 10 bytes long.
116  */
117 TSS2_RC
118 header_unmarshal (
119     const uint8_t *buf,
120     tpm_header_t *header);
121 /*
122  */
123 TSS2_RC
124 header_marshal (
125     const tpm_header_t *header,
126     uint8_t *buf);
127 
128 #endif
129