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_PolicyCounterTimer_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,const TPM2B_OPERAND * operandB,UINT16 offset,TPM2_EO operation)15 TSS2_RC Tss2_Sys_PolicyCounterTimer_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_SH_POLICY policySession,
18 const TPM2B_OPERAND *operandB,
19 UINT16 offset,
20 TPM2_EO operation)
21 {
22 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
23 TSS2_RC rval;
24
25 if (!ctx)
26 return TSS2_SYS_RC_BAD_REFERENCE;
27
28 rval = CommonPreparePrologue(ctx, TPM2_CC_PolicyCounterTimer);
29 if (rval)
30 return rval;
31
32 rval = Tss2_MU_UINT32_Marshal(policySession, ctx->cmdBuffer,
33 ctx->maxCmdSize,
34 &ctx->nextData);
35 if (rval)
36 return rval;
37
38 if (!operandB) {
39 ctx->decryptNull = 1;
40
41 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
42 ctx->maxCmdSize,
43 &ctx->nextData);
44 } else {
45
46 rval = Tss2_MU_TPM2B_OPERAND_Marshal(operandB, ctx->cmdBuffer,
47 ctx->maxCmdSize,
48 &ctx->nextData);
49 }
50
51 if (rval)
52 return rval;
53
54 rval = Tss2_MU_UINT16_Marshal(offset, ctx->cmdBuffer,
55 ctx->maxCmdSize,
56 &ctx->nextData);
57 if (rval)
58 return rval;
59
60 rval = Tss2_MU_UINT16_Marshal(operation, ctx->cmdBuffer,
61 ctx->maxCmdSize,
62 &ctx->nextData);
63 if (rval)
64 return rval;
65
66 ctx->decryptAllowed = 1;
67 ctx->encryptAllowed = 0;
68 ctx->authAllowed = 1;
69
70 return CommonPrepareEpilogue(ctx);
71 }
72
Tss2_Sys_PolicyCounterTimer_Complete(TSS2_SYS_CONTEXT * sysContext)73 TSS2_RC Tss2_Sys_PolicyCounterTimer_Complete (
74 TSS2_SYS_CONTEXT *sysContext)
75 {
76 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
77
78 if (!ctx)
79 return TSS2_SYS_RC_BAD_REFERENCE;
80
81 return CommonComplete(ctx);
82 }
83
Tss2_Sys_PolicyCounterTimer(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPM2B_OPERAND * operandB,UINT16 offset,TPM2_EO operation,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)84 TSS2_RC Tss2_Sys_PolicyCounterTimer(
85 TSS2_SYS_CONTEXT *sysContext,
86 TPMI_SH_POLICY policySession,
87 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
88 const TPM2B_OPERAND *operandB,
89 UINT16 offset,
90 TPM2_EO operation,
91 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
92 {
93 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
94 TSS2_RC rval;
95
96 rval = Tss2_Sys_PolicyCounterTimer_Prepare(sysContext, policySession,
97 operandB, offset, operation);
98 if (rval)
99 return rval;
100
101 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
102 if (rval)
103 return rval;
104
105 return Tss2_Sys_PolicyCounterTimer_Complete(sysContext);
106 }
107