1InitSocketTcti(3)             TPM2 Software Stack            InitSocketTcti(3)
2
3
4

NAME

6       InitSocketTcti  - Initialization function for the Microsoft TPM simula‐
7       tor TCTI library.
8

SYNOPSIS

10       #include <tcti/tcti_socket.h>
11
12       typedef int (*TCTI_LOG_CALLBACK)( void  *data,  printf_typetype,  const
13       char *format, ...");
14
15       typedef struct {
16           const char *hostname;
17           uint16_t port;
18           TCTI_LOG_CALLBACK logCallback;
19           TCTI_LOG_BUFFER_CALLBACK logBufferCallback;
20           void *logData;
21       } TCTI_SOCKET_CONF;
22
23       TSS2_RC  InitSocketTcti  (TSS2_TCTI_CONTEXT  *tctiContext, size_t *con‐
24       textSize, const TCTI_SOCKET_CONF *config, const uint8_t serverSockets);
25
26
27       The InitSocketTcti() function initializes a TCTI context used to commu‐
28       nicate with the Microsoft TPM simulator.
29

DESCRIPTION

31       InitSocketTcti() attempts to initialize a caller allocated tcti_context
32       of size size using caller provided configuration information from  con‐
33       fig  .  Since  the  tcti_context must be a caller allocated buffer, the
34       caller needs to know the size required by the TCTI library. The minimum
35       size  of  this  context  can  be  discovered  by providing NULL for the
36       tcti_context and a non- NULL size parameter. The  initialization  func‐
37       tion will then populate the size parameter with the minimum size of the
38       tcti_context buffer. The caller must then allocate  a  buffer  of  this
39       size  (or  larger) and call InitSocketTcti () again providing the newly
40       allocated tcti_context and the size of this context in the size parame‐
41       ter.  This  patterm  is common to all TCTI initialization functions. We
42       provide an example of this pattern using the InitSocketTcti()  function
43       in the section titled EXAMPLE.
44
45       The   config   parameter   is   a  reference  to  an  instance  of  the
46       TCTI_SOCKET_CONF structure. The hostname member of this structure is  a
47       C  string  that  contains the hostname or IPv4 address of the Microsoft
48       TPM simulator. The port member is an unsigned 16 bit integer containing
49       the  port number for the simulator command / response port. The simula‐
50       tor listens for “platform commands” on port+1 and so an additional con‐
51       nection  will be made to this port. The logCallback member is a pointer
52       to a callback function that will be called by the socket TCTI. This  is
53       expected  to be a printf like function. The logBufferCallback mamber is
54       a pointer to a call back function that will be invoked  by  the  socket
55       TCTI  before a command buffer is transmitted or after a resposne buffer
56       is received. This is expected to be a printf like function. The logData
57       member is a void pointer that may be used to pass user data to the log‐
58       Callback and logBufferCallback functions on each invocation.
59
60       The serverSockets parameter should always be 0 for client code.
61
62       Once initialized, the TCTI context returned exposes the Trusted Comput‐
63       ing Group (TCG) defined API for the lowest level communication with the
64       TPM.  Using this API the caller can exchange (send / receive) TPM2 com‐
65       mand  and  respons  buffers with the Microsoft TPM simulator. In nearly
66       all cases however, the caller will initialize a context using this fun‐
67       nction before passing the context to a higher level API like the System
68       API (SAPI), and then never touch it again.
69
70       For a more thorough discussion of the TCTI  API  see  the  “TSS  System
71       Level API and TPM Command Transmission Interface Specification” as pub‐
72       lished                  by                   the                   TCG:
73       https://trustedcomputinggroup.org/tss-system-level-api-tpm-command-transmission-interface-specification/
74

RETURN VALUE

76       A successful call to InitSocketTcti() will return TSS2_RC_SUCCESS.   An
77       unsuccessful  call  will  produce  a response code described in section
78       ERRORS.
79

ERRORS

81       TSS2_TCTI_RC_BAD_VALUE is returned if both  the  tcti_context  and  the
82       size parameters are NULL, or if the config parameter is NULL.
83

EXAMPLE

85       Logging functions:
86
87       int DebugPrintfCallback (void *data, printf_type type, const char *format, ...)
88       {
89           va_list args;
90           int rval = 0;
91
92           va_start( args, format );
93           rval = vprintf( format, args );
94           va_end (args);
95
96           return rval;
97       }
98       void DebugPrintBuffer (printf_type type, UINT8 *buffer, UINT32 length)
99       {
100           UINT32  i;
101
102           for( i = 0; i < length; i++ )
103           {
104               if( ( i % 16 ) == 0 ) {
105                   printf ("0);
106               }
107
108               printf ("%2.2x ", buffer[i] );
109           }
110           printf ("0);
111       }
112
113       TCTI initialization fragment:
114
115       #include <inttypes.h>
116       #include <stdlib.h>
117       #include <stdio.h>
118       #include <tcti/tcti_socket.h>
119
120       TSS2_RC rc;
121       TSS2_TCTI_CONTEXT *tcti_context;
122       size_t size;
123       TCTI_SOCKET_CONF conf = {
124           .hostname          = "127.0.0.1",
125           .port              = 2321,
126           .logCallback       = DebugPrintfCallback,
127           .logBufferCallback = DebugPrintBuffer,
128           .logData           = NULL,
129       };
130
131       rc = InitSocketTcti (NULL, &size, NULL, 0);
132       if (rc != TSS2_RC_SUCCESS) {
133           fprintf (stderr, "Failed to get allocation size for tabrmd TCTI "
134                    " context: 0x%" PRIx32 "0, rc);
135           exit (EXIT_FAILURE);
136       }
137       tcti_context = calloc (1, size);
138       if (tcti_context == NULL) {
139           fprintf (stderr, "Allocation for TCTI context failed: %s0,
140                    strerror (errno));
141           exit (EXIT_FAILURE);
142       }
143       rc = InitSocketTcti (&tcti_context, &size, &conf, 0);
144       if (rc != TSS2_RC_SUCCESS) {
145           fprintf (stderr, "Failed to initialize tabrmd TCTI context: "
146                    "0x%" PRIx32 "0, rc);
147           free (tcti_context);
148           exit (EXIT_FAILURE);
149       }
150

AUTHOR

152       Philip Tricca <philip.b.tricca@intel.com>
153

SEE ALSO

155       InitDeviceTcti(3),  InitSocketTcti(3),  tcti-device(7), tcti-socket(7),
156       tcti-tabrmd(7), tpm2-abrmd(8)
157

COLOPHON

159       This page is part of release 1.4.0 of Intel's implementation of the TCG
160       TPM2  Software  Stack (TSS2). A description of the project, information
161       about reporting bugs, and the latest version of this page can be  found
162       at https://github.com/01org/tpm2.0-tss/.
163
164
165
166Intel                              JUNE 2017                 InitSocketTcti(3)
Impressum