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