1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************;
3 * Copyright (c) 2015 - 2017, Intel Corporation
4 * All rights reserved.
5 ***********************************************************************/
6
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
10
11 #include "tss2_tpm2_types.h"
12 #include "tss2_mu.h"
13 #include "sysapi_util.h"
14
Tss2_Sys_ReadClock_Prepare(TSS2_SYS_CONTEXT * sysContext)15 TSS2_RC Tss2_Sys_ReadClock_Prepare(
16 TSS2_SYS_CONTEXT *sysContext)
17 {
18 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
19 TSS2_RC rval;
20
21 if (!ctx)
22 return TSS2_SYS_RC_BAD_REFERENCE;
23
24 rval = CommonPreparePrologue(ctx, TPM2_CC_ReadClock);
25 if (rval)
26 return rval;
27
28 ctx->decryptAllowed = 0;
29 ctx->encryptAllowed = 0;
30 ctx->authAllowed = 0;
31
32 return CommonPrepareEpilogue(ctx);
33 }
34
Tss2_Sys_ReadClock_Complete(TSS2_SYS_CONTEXT * sysContext,TPMS_TIME_INFO * currentTime)35 TSS2_RC Tss2_Sys_ReadClock_Complete(
36 TSS2_SYS_CONTEXT *sysContext,
37 TPMS_TIME_INFO *currentTime)
38 {
39 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
40 TSS2_RC rval;
41
42 if (!ctx)
43 return TSS2_SYS_RC_BAD_REFERENCE;
44
45 rval = CommonComplete(ctx);
46 if (rval)
47 return rval;
48
49 return Tss2_MU_TPMS_TIME_INFO_Unmarshal(ctx->cmdBuffer,
50 ctx->maxCmdSize,
51 &ctx->nextData,
52 currentTime);
53 }
54
Tss2_Sys_ReadClock(TSS2_SYS_CONTEXT * sysContext,TPMS_TIME_INFO * currentTime)55 TSS2_RC Tss2_Sys_ReadClock(
56 TSS2_SYS_CONTEXT *sysContext,
57 TPMS_TIME_INFO *currentTime)
58 {
59 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
60 TSS2_RC rval;
61
62 rval = Tss2_Sys_ReadClock_Prepare(sysContext);
63 if (rval)
64 return rval;
65
66 rval = CommonOneCall(ctx, 0, 0);
67 if (rval)
68 return rval;
69
70 return Tss2_Sys_ReadClock_Complete(sysContext, currentTime);
71 }
72