InitDeviceTcti man page

InitDeviceTcti — Initialization function for the device TCTI library.


#include <tcti/tcti_device.h>

typedef int (*TCTI_LOG_CALLBACK)( void *data, printf_typetype, const char *format, ...");

typedef struct {
    const char *device_path;
    TCTI_LOG_CALLBACK logCallback;
    void *logData;

TSS2_RC InitDeviceTcti (TSS2_TCTI_CONTEXT *tctiContext, size_t *contextSize, const TCTI_DEVICE_CONF *config);

The InitDeviceTcti() function initializes a TCTI context used to communicate with the TPM device driver.


InitDeviceTcti() attempts to initialize a caller allocated tcti_context of size size . Since the tcti_context must be a caller allocated buffer, the caller needs to know the size required by the TCTI library. The minimum size of this context can be discovered by providing NULL for the tcti_context and a non- NULL size parameter. The initialization function will then populate the size parameter with the minimum size of the tcti_context buffer. The caller must then allocate a buffer of this size (or larger) and call InitDeviceTcti () again providing the newly allocated tcti_context and the size of this context in the size parameter. This patterm is common to all TCTI initialization functions. We provide an example of this pattern using the InitDeviceTcti() function in the section titled Example.

The config parameter is a reference to an instance of the TCTI_DEVICE_CONF structure. The device_path member of this structure is a C string that contains the path to the device node exposed by the TPM device driver.

The logCallback parameter is a pointer to a callback function that will be called by the device TCTI. This is expected to be a printf like function.

The logData member is a void pointer to user data that will be supplied to the logCallback function on each invocation.

Once initialized, the TCTI context returned exposes the Trusted Computing Group (TCG) defined API for the lowest level communication with the TPM. Using this API the caller can exchange (send / receive) TPM2 command and respons buffers with the TPM device driver. In nearly all cases however, the caller will initialize a context using this funnction before passing the context to a higher level API like the System API (SAPI), and then never touch it again.

For a more thorough discussion of the TCTI API see the “TSS System Level API and TPM Command Transmission Interface Specification” as published by the TCG:

Return Value

A successful call to InitDeviceTcti() will return TSS2_RC_SUCCESS. An unsuccessful call will produce a response code described in section Errors.


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


Logging function:

int DebugPrintfCallback( void *data, printf_type type, const char *format, ...)
    va_list args;
    int rval = 0;

    va_start( args, format );
    rval = vprintf( format, args );
    va_end (args);

    return rval;

TCTI initialization fragment:

#include <inttypes.h>
#include <stdlib.h>
#include <stdio.h>
#include <tcti/tcti_device.h>

TSS2_RC rc;
TSS2_TCTI_CONTEXT *tcti_context;
size_t size;
    .device_path = "/dev/tpm0",
    .logCallback = DebugPrintfCallback,
    .logData     = NULL,

rc = InitDeviceTcti (NULL, &size, NULL);
if (rc != TSS2_RC_SUCCESS) {
    fprintf (stderr, "Failed to get allocation size for tabrmd TCTI "
             " context: 0x%" PRIx32 "0, rc);
    exit (EXIT_FAILURE);
tcti_context = calloc (1, size);
if (tcti_context == NULL) {
    fprintf (stderr, "Allocation for TCTI context failed: %s0,
             strerror (errno));
    exit (EXIT_FAILURE);
rc = InitDeviceTcti (&tcti_context, &size, &conf);
if (rc != TSS2_RC_SUCCESS) {
    fprintf (stderr, "Failed to initialize tabrmd TCTI context: "
             "0x%" PRIx32 "0, rc);
    free (tcti_context);
    exit (EXIT_FAILURE);


Philip Tricca <>

See Also

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


This page is part of release 1.3.0 of Intel's implementation of the TCG TPM2 Software Stack (TSS2). A description of the project, information about reporting bugs, and the latest version of this page can be found at

Referenced By

InitSocketTcti(3), tcti-device(7), tcti-socket(7).

JUNE 2017 Intel TPM2 Software Stack