1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************;
3 * Copyright (c) 2015-2018, Intel Corporation
4 *
5 * Copyright 2015, Andreas Fuchs @ Fraunhofer SIT
6 *
7 * All rights reserved.
8 ***********************************************************************/
9
10 #ifdef HAVE_CONFIG_H
11 #include <config.h>
12 #endif
13
14 #include <inttypes.h>
15
16 #include "tss2_tpm2_types.h"
17 #include "tss2_mu.h"
18
19 #include "sysapi_util.h"
20 #define LOGMODULE sys
21 #include "util/log.h"
22
23 #define TSSWG_INTEROP 1
24 #define TSS_SAPI_FIRST_FAMILY 2
25 #define TSS_SAPI_FIRST_LEVEL 1
26 #define TSS_SAPI_FIRST_VERSION 108
27
Tss2_Sys_Initialize(TSS2_SYS_CONTEXT * sysContext,size_t contextSize,TSS2_TCTI_CONTEXT * tctiContext,TSS2_ABI_VERSION * abiVersion)28 TSS2_RC Tss2_Sys_Initialize(
29 TSS2_SYS_CONTEXT *sysContext,
30 size_t contextSize,
31 TSS2_TCTI_CONTEXT *tctiContext,
32 TSS2_ABI_VERSION *abiVersion)
33 {
34 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
35
36 if (!ctx || !tctiContext)
37 return TSS2_SYS_RC_BAD_REFERENCE;
38
39 if (contextSize < sizeof(_TSS2_SYS_CONTEXT_BLOB))
40 return TSS2_SYS_RC_INSUFFICIENT_CONTEXT;
41
42 if (!TSS2_TCTI_TRANSMIT (tctiContext) ||
43 !TSS2_TCTI_RECEIVE (tctiContext))
44 return TSS2_SYS_RC_BAD_TCTI_STRUCTURE;
45
46 /* Checks for ABI negotiation. */
47 if (abiVersion != NULL &&
48 (abiVersion->tssCreator != TSSWG_INTEROP ||
49 abiVersion->tssFamily != TSS_SAPI_FIRST_FAMILY ||
50 abiVersion->tssLevel != TSS_SAPI_FIRST_LEVEL ||
51 abiVersion->tssVersion != TSS_SAPI_FIRST_VERSION)) {
52 LOG_ERROR("ABI-Version of application %" PRIx32 ".%" PRIu32 ".%"
53 PRIu32 ".%" PRIu32 " differs from ABI version of SAPI %"
54 PRIx32 ".%" PRIu32 ".%" PRIu32 ".%" PRIu32,
55 abiVersion->tssCreator, abiVersion->tssFamily,
56 abiVersion->tssLevel, abiVersion->tssVersion,
57 TSSWG_INTEROP, TSS_SAPI_FIRST_FAMILY,
58 TSS_SAPI_FIRST_LEVEL, TSS_SAPI_FIRST_VERSION);
59 return TSS2_SYS_RC_ABI_MISMATCH;
60 }
61
62 ctx->tctiContext = tctiContext;
63 InitSysContextPtrs(ctx, contextSize);
64 InitSysContextFields(ctx);
65 ctx->previousStage = CMD_STAGE_INITIALIZE;
66
67 return TSS2_RC_SUCCESS;
68 }
69