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