Skip to content

Commit

Permalink
TCTI: Add null tcti.
Browse files Browse the repository at this point in the history
A tcti module which can only used for tcti initialization is added.

Signed-off-by: Juergen Repp <[email protected]>
  • Loading branch information
JuergenReppSIT committed Jan 17, 2025
1 parent 0aa7978 commit 3647305
Show file tree
Hide file tree
Showing 8 changed files with 269 additions and 1 deletion.
19 changes: 19 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,25 @@ src_tss2_tcti_libtss2_tcti_pcap_la_SOURCES = \
endif # ENABLE_TCTI_PCAP
EXTRA_DIST += lib/tss2-tcti-pcap.map

# tcti null library
if ENABLE_TCTI_NULL
libtss2_tcti_null = src/tss2-tcti/libtss2-tcti-null.la
tss2_HEADERS += $(srcdir)/include/tss2/tss2_tcti_null.h
lib_LTLIBRARIES += $(libtss2_tcti_null)
pkgconfig_DATA += lib/tss2-tcti-null.pc

if HAVE_LD_VERSION_SCRIPT
src_tss2_tcti_libtss2_tcti_null_la_LDFLAGS = -Wl,--version-script=$(srcdir)/lib/tss2-tcti-null.map
endif # HAVE_LD_VERSION_SCRIPT
src_tss2_tcti_libtss2_tcti_null_la_LIBADD = $(libtss2_tctildr) $(libtss2_mu) $(libutil) $(libutilio)
src_tss2_tcti_libtss2_tcti_null_la_SOURCES = \
src/tss2-tcti/tcti-common.c \
src/tss2-tcti/tcti-null.c \
src/tss2-tcti/tcti-null.h
endif # ENABLE_TCTI_NULL
EXTRA_DIST += lib/tss2-tcti-null.map


# tcti libtpms library
if ENABLE_TCTI_LIBTPMS
libtss2_tcti_libtpms = src/tss2-tcti/libtss2-tcti-libtpms.la
Expand Down
8 changes: 7 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) #Backward compatible setti

AC_CONFIG_HEADERS([config.h])

AC_CONFIG_FILES([Makefile Doxyfile lib/tss2-sys.pc lib/tss2-esys.pc lib/tss2-mu.pc lib/tss2-tcti-device.pc lib/tss2-tcti-mssim.pc lib/tss2-tcti-swtpm.pc lib/tss2-tcti-pcap.pc lib/tss2-tcti-libtpms.pc lib/tss2-rc.pc lib/tss2-tctildr.pc lib/tss2-fapi.pc lib/tss2-tcti-cmd.pc lib/tss2-policy.pc lib/tss2-tcti-spi-helper.pc lib/tss2-tcti-spi-ltt2go.pc lib/tss2-tcti-spidev.pc lib/tss2-tcti-spi-ftdi.pc lib/tss2-tcti-i2c-helper.pc lib/tss2-tcti-i2c-ftdi.pc])
AC_CONFIG_FILES([Makefile Doxyfile lib/tss2-sys.pc lib/tss2-esys.pc lib/tss2-mu.pc lib/tss2-tcti-device.pc lib/tss2-tcti-mssim.pc lib/tss2-tcti-swtpm.pc lib/tss2-tcti-pcap.pc lib/tss2-tcti-null.pc lib/tss2-tcti-libtpms.pc lib/tss2-rc.pc lib/tss2-tctildr.pc lib/tss2-fapi.pc lib/tss2-tcti-cmd.pc lib/tss2-policy.pc lib/tss2-tcti-spi-helper.pc lib/tss2-tcti-spi-ltt2go.pc lib/tss2-tcti-spidev.pc lib/tss2-tcti-spi-ftdi.pc lib/tss2-tcti-i2c-helper.pc lib/tss2-tcti-i2c-ftdi.pc])

# propagate configure arguments to distcheck
AC_SUBST([DISTCHECK_CONFIGURE_FLAGS],[$ac_configure_args])
Expand Down Expand Up @@ -278,6 +278,12 @@ AC_ARG_ENABLE([tcti-pcap],
[enable_tcti_pcap=yes])
AM_CONDITIONAL([ENABLE_TCTI_PCAP], [test "x$enable_tcti_pcap" != xno])

AC_ARG_ENABLE([tcti-null],
[AS_HELP_STRING([--disable-tcti-null],
[don't build the tcti-null module])],,
[enable_tcti_null=yes])
AM_CONDITIONAL([ENABLE_TCTI_NULL], [test "x$enable_tcti_null" != xno])

AC_ARG_ENABLE([tcti-libtpms],
[AS_HELP_STRING([--disable-tcti-libtpms],
[don't build the tcti-libtpms module])],
Expand Down
24 changes: 24 additions & 0 deletions include/tss2/tss2_tcti_null.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2020 Infineon Technologies AG
* All rights reserved.
*/
#ifndef TSS2_TCTI_NULL_H
#define TSS2_TCTI_NULL_H

#include "tss2_tcti.h"

#ifdef __cplusplus
extern "C" {
#endif

TSS2_RC Tss2_Tcti_Null_Init (
TSS2_TCTI_CONTEXT *tctiContext,
size_t *size,
const char *conf);

#ifdef __cplusplus
}
#endif

#endif /* TSS2_TCTI_NULL_H */
4 changes: 4 additions & 0 deletions lib/tss2-tcti-null.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
LIBRARY tss2-tcti-null
EXPORTS
Tss2_Tcti_Info
Tss2_Tcti_Null_Init
7 changes: 7 additions & 0 deletions lib/tss2-tcti-null.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
global:
Tss2_Tcti_Info;
Tss2_Tcti_Null_Init;
local:
*;
};
12 changes: 12 additions & 0 deletions lib/tss2-tcti-null.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
prefix=@prefix@
exec_prefix=@exec_prefix@
libdir=@libdir@
includedir=@includedir@

Name: tss2-tcti-null
Description: TCTI library for debugging at the TCTI interface.
URL: https://github.com/tpm2-software/tpm2-tss
Version: @VERSION@
Requires.private: tss2-tctildr
Cflags: -I${includedir}
Libs: -ltss2-tcti-null -L${libdir}
173 changes: 173 additions & 0 deletions src/tss2-tcti/tcti-null.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2025 Juergen Repp
* All rights reserved.
*/

#ifdef HAVE_CONFIG_H
#include "config.h" // IWYU pragma: keep
#endif

#include <inttypes.h> // for PRIxPTR, uintptr_t, uint8_t, int32_t
#include <string.h> // for NULL, size_t, memset

#include "tcti-common.h" // for TSS2_TCTI_COMMON_CONTEXT, TCTI_STATE_...
#include "tss2_common.h" // for TSS2_RC_SUCCESS, TSS2_RC, TSS2_TCTI_R...
#include "tss2_tcti.h" // for TSS2_TCTI_CONTEXT, TSS2_TCTI_INFO
#include "tss2_tpm2_types.h" // for TPM2_RC_SUCCESS
#include "util/aux_util.h" // for UNUSED

#define LOGMODULE tcti
#include "tcti-null.h"
#include "tss2_tctildr.h" // for Tss2_TctiLdr_Finalize, Tss2_TctiLdr_I...
#include "util/log.h" // for LOG_WARNING, LOG_ERROR, LOGBLOB_DEBUG

/*
* This function wraps the "up-cast" of the opaque TCTI context type to the
* type for the null TCTI context. The only safeguard we have to ensure this
* operation is possible is the magic number in the null TCTI context.
* If passed a NULL context, or the magic number check fails, this function
* will return NULL.
*/
TSS2_TCTI_NULL_CONTEXT*
tcti_null_context_cast (TSS2_TCTI_CONTEXT *tcti_ctx)
{
if (tcti_ctx != NULL && TSS2_TCTI_MAGIC (tcti_ctx) == TCTI_NULL_MAGIC) {
return (TSS2_TCTI_NULL_CONTEXT*)tcti_ctx;
}
return NULL;
}

/*
* This function down-casts the null TCTI context to the common context
* defined in the tcti-common module.
*/
TSS2_TCTI_COMMON_CONTEXT*
tcti_null_down_cast (TSS2_TCTI_NULL_CONTEXT *tcti_null)
{
if (tcti_null == NULL) {
return NULL;
}
return &tcti_null->common;
}

TSS2_RC
tcti_null_transmit (
TSS2_TCTI_CONTEXT *tcti_ctx,
size_t size,
const uint8_t *cmd_buf)
{
UNUSED(tcti_ctx);
UNUSED(size);
UNUSED(cmd_buf);
return TSS2_TCTI_RC_NOT_IMPLEMENTED;
}

TSS2_RC
tcti_null_receive (
TSS2_TCTI_CONTEXT *tctiContext,
size_t *response_size,
unsigned char *response_buffer,
int32_t timeout)
{
UNUSED(tctiContext);
UNUSED(response_size);
UNUSED(response_buffer);
UNUSED(timeout);
return TSS2_TCTI_RC_NOT_IMPLEMENTED;
}

TSS2_RC
tcti_null_cancel (
TSS2_TCTI_CONTEXT *tctiContext)
{
UNUSED(tctiContext);
return TSS2_TCTI_RC_NOT_IMPLEMENTED;
}

TSS2_RC
tcti_null_set_locality (
TSS2_TCTI_CONTEXT *tctiContext,
uint8_t locality)
{
UNUSED(tctiContext);
UNUSED(locality);
return TSS2_TCTI_RC_NOT_IMPLEMENTED;
}

TSS2_RC
tcti_null_get_poll_handles (
TSS2_TCTI_CONTEXT *tctiContext,
TSS2_TCTI_POLL_HANDLE *handles,
size_t *num_handles)
{
UNUSED(tctiContext);
UNUSED(handles);
UNUSED(num_handles);
return TSS2_TCTI_RC_NOT_IMPLEMENTED;
}

void
tcti_null_finalize (
TSS2_TCTI_CONTEXT *tctiContext)
{
TSS2_TCTI_NULL_CONTEXT *tcti_null = tcti_null_context_cast (tctiContext);
TSS2_TCTI_COMMON_CONTEXT *tcti_common = tcti_null_down_cast (tcti_null);
if (tcti_null == NULL) {
return;
}

tcti_common->state = TCTI_STATE_FINAL;
}

/*
* This is an implementation of the standard TCTI initialization function for
* this module.
*/
TSS2_RC
Tss2_Tcti_Null_Init (
TSS2_TCTI_CONTEXT *tctiContext,
size_t *size,
const char *conf)
{
UNUSED(conf);
TSS2_TCTI_NULL_CONTEXT *tcti_null = (TSS2_TCTI_NULL_CONTEXT*) tctiContext;
TSS2_TCTI_COMMON_CONTEXT *tcti_common = tcti_null_down_cast (tcti_null);

if (tctiContext == NULL && size == NULL) {
return TSS2_TCTI_RC_BAD_VALUE;
} else if (tctiContext == NULL) {
*size = sizeof (TSS2_TCTI_NULL_CONTEXT);
return TSS2_RC_SUCCESS;
}

TSS2_TCTI_MAGIC (tcti_common) = TCTI_NULL_MAGIC;
TSS2_TCTI_VERSION (tcti_common) = TCTI_VERSION;
TSS2_TCTI_TRANSMIT (tcti_common) = tcti_null_transmit;
TSS2_TCTI_RECEIVE (tcti_common) = tcti_null_receive;
TSS2_TCTI_FINALIZE (tcti_common) = tcti_null_finalize;
TSS2_TCTI_CANCEL (tcti_common) = tcti_null_cancel;
TSS2_TCTI_GET_POLL_HANDLES (tcti_common) = tcti_null_get_poll_handles;
TSS2_TCTI_SET_LOCALITY (tcti_common) = tcti_null_set_locality;
TSS2_TCTI_MAKE_STICKY (tcti_common) = tcti_make_sticky_not_implemented;
tcti_common->state = TCTI_STATE_TRANSMIT;
tcti_common->locality = 3;
memset (&tcti_common->header, 0, sizeof (tcti_common->header));

return TSS2_RC_SUCCESS;
}

/* public info structure */
const TSS2_TCTI_INFO tss2_tcti_info = {
.version = TCTI_VERSION,
.name = "tcti-null",
.description = "TCTI module which only provides initialization.",
.config_help = "",
.init = Tss2_Tcti_Null_Init,
};

const TSS2_TCTI_INFO*
Tss2_Tcti_Info (void)
{
return &tss2_tcti_info;
}
23 changes: 23 additions & 0 deletions src/tss2-tcti/tcti-null.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* SPDX-License-Identifier: BSD-2-Clause */
/*
* Copyright (c) 2025 Juergen Repp
* All rights reserved.
*/

#ifndef TCTI_NULL_H
#define TCTI_NULL_H

#include "tcti-common.h"
#include "tss2_tcti.h"

#define TCTI_NULL_MAGIC 0x9af45c5d7d9d0d3fULL

typedef struct {
const char *child_tcti;
} tcti_null_conf_t;

typedef struct {
TSS2_TCTI_COMMON_CONTEXT common;
} TSS2_TCTI_NULL_CONTEXT;

#endif /* TCTI_NULL_H */

0 comments on commit 3647305

Please sign in to comment.