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_PolicyCommandCode_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,TPM2_CC code)15 TSS2_RC Tss2_Sys_PolicyCommandCode_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_SH_POLICY policySession,
18 TPM2_CC code)
19 {
20 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
21 TSS2_RC rval;
22
23 if (!ctx)
24 return TSS2_SYS_RC_BAD_REFERENCE;
25
26 rval = CommonPreparePrologue(ctx, TPM2_CC_PolicyCommandCode);
27 if (rval)
28 return rval;
29
30 rval = Tss2_MU_UINT32_Marshal(policySession, ctx->cmdBuffer,
31 ctx->maxCmdSize,
32 &ctx->nextData);
33 if (rval)
34 return rval;
35
36 rval = Tss2_MU_UINT32_Marshal(code, ctx->cmdBuffer,
37 ctx->maxCmdSize,
38 &ctx->nextData);
39 if (rval)
40 return rval;
41
42 ctx->decryptAllowed = 0;
43 ctx->encryptAllowed = 0;
44 ctx->authAllowed = 1;
45
46 return CommonPrepareEpilogue(ctx);
47 }
48
Tss2_Sys_PolicyCommandCode_Complete(TSS2_SYS_CONTEXT * sysContext)49 TSS2_RC Tss2_Sys_PolicyCommandCode_Complete (
50 TSS2_SYS_CONTEXT *sysContext)
51 {
52 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
53
54 if (!ctx)
55 return TSS2_SYS_RC_BAD_REFERENCE;
56
57 return CommonComplete(ctx);
58 }
59
Tss2_Sys_PolicyCommandCode(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPM2_CC code,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)60 TSS2_RC Tss2_Sys_PolicyCommandCode(
61 TSS2_SYS_CONTEXT *sysContext,
62 TPMI_SH_POLICY policySession,
63 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
64 TPM2_CC code,
65 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
66 {
67 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
68 TSS2_RC rval;
69
70 rval = Tss2_Sys_PolicyCommandCode_Prepare(sysContext, policySession, code);
71 if (rval)
72 return rval;
73
74 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
75 if (rval)
76 return rval;
77
78 return Tss2_Sys_PolicyCommandCode_Complete(sysContext);
79 }
80