1 //**********************************************************************;
2 // Copyright (c) 2017, Intel Corporation
3 // All rights reserved.
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are met:
8 // 1. Redistributions of source code must retain the above copyright notice,
9 // this list of conditions and the following disclaimer.
11 // 2. Redistributions in binary form must reproduce the above copyright notice,
12 // this list of conditions and the following disclaimer in the documentation
13 // and/or other materials provided with the distribution.
15 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
16 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
19 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
25 // THE POSSIBILITY OF SUCH DAMAGE.
26 //**********************************************************************;
29 // The context for TCTI implementations is on opaque
30 // structure. There shall never be a definition of its content.
31 // Implementation provide the size information to
32 // applications via the initialize call.
33 // This makes use of a compiler trick that allows type
34 // checking of the pointer even though the type isn't
37 // The first field of a Context must be the common part
39 #ifndef TSS2_TCTI_UTIL_H
40 #define TSS2_TCTI_UTIL_H
42 #if defined linux || defined unix
43 #include <sys/socket.h>
47 #include <tcti/common.h>
49 #define TCTI_MAGIC 0x7e18e9defa8bc9e2
50 #define TCTI_VERSION 0x1
52 #define TCTI_LOG_CALLBACK(ctx) ((TSS2_TCTI_CONTEXT_INTEL*)ctx)->logCallback
53 #define TCTI_LOG_DATA(ctx) ((TSS2_TCTI_CONTEXT_INTEL*)ctx)->logData
54 #define TCTI_LOG_BUFFER_CALLBACK(ctx) ((TSS2_TCTI_CONTEXT_INTEL*)ctx)->logBufferCallback
56 typedef TSS2_RC (*TCTI_TRANSMIT_PTR)( TSS2_TCTI_CONTEXT *tctiContext, size_t size, uint8_t *command);
57 typedef TSS2_RC (*TCTI_RECEIVE_PTR) (TSS2_TCTI_CONTEXT *tctiContext, size_t *size, uint8_t *response, int32_t timeout);
59 enum tctiStates { TCTI_STAGE_INITIALIZE, TCTI_STAGE_SEND_COMMAND, TCTI_STAGE_RECEIVE_RESPONSE };
61 /* current Intel version */
65 TCTI_TRANSMIT_PTR transmit;
66 TCTI_RECEIVE_PTR receive;
67 TSS2_RC (*finalize) (TSS2_TCTI_CONTEXT *tctiContext);
68 TSS2_RC (*cancel) (TSS2_TCTI_CONTEXT *tctiContext);
69 TSS2_RC (*getPollHandles) (TSS2_TCTI_CONTEXT *tctiContext,
70 TSS2_TCTI_POLL_HANDLE *handles, size_t *num_handles);
71 TSS2_RC (*setLocality) (TSS2_TCTI_CONTEXT *tctiContext, uint8_t locality);
73 UINT32 debugMsgEnabled: 1;
75 UINT32 commandSent: 1;
76 UINT32 rmDebugPrefix: 1; // Used to add a prefix to RM debug messages. This is ONLY used
77 // for TPM commands and responses as a way to differentiate
78 // RM generated TPM commands from application generated ones.
80 // Following two fields used to save partial response status in case receive buffer's too small.
81 UINT32 tagReceived: 1;
82 UINT32 responseSizeReceived: 1;
83 UINT32 protocolResponseSizeReceived: 1;
86 // Following two fields used to save partial response in case receive buffer's too small.
90 TSS2_TCTI_CONTEXT *currentTctiContext;
92 // Sockets if socket interface is being used.
95 SOCKET currentConnectSock;
97 // File descriptor for device file if real TPM is being used.
99 UINT8 previousStage; // Used to check for sequencing errors.
100 unsigned char responseBuffer[4096];
101 TCTI_LOG_CALLBACK logCallback;
102 TCTI_LOG_BUFFER_CALLBACK logBufferCallback;
104 } TSS2_TCTI_CONTEXT_INTEL;
106 #define TCTI_CONTEXT ( (TSS2_TCTI_CONTEXT_COMMON_CURRENT *)(SYS_CONTEXT->tctiContext) )
107 #define TCTI_CONTEXT_INTEL ( (TSS2_TCTI_CONTEXT_INTEL *)tctiContext )