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_HierarchyControl_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_HIERARCHY authHandle,TPMI_RH_ENABLES enable,TPMI_YES_NO state)15 TSS2_RC Tss2_Sys_HierarchyControl_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_RH_HIERARCHY authHandle,
18 TPMI_RH_ENABLES enable,
19 TPMI_YES_NO state)
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 = CommonPreparePrologue(ctx, TPM2_CC_HierarchyControl);
28 if (rval)
29 return rval;
30
31 rval = Tss2_MU_UINT32_Marshal(authHandle, ctx->cmdBuffer,
32 ctx->maxCmdSize,
33 &ctx->nextData);
34 if (rval)
35 return rval;
36
37 rval = Tss2_MU_UINT32_Marshal(enable, ctx->cmdBuffer,
38 ctx->maxCmdSize,
39 &ctx->nextData);
40 if (rval)
41 return rval;
42
43 rval = Tss2_MU_UINT8_Marshal(state, ctx->cmdBuffer,
44 ctx->maxCmdSize,
45 &ctx->nextData);
46 if (rval)
47 return rval;
48
49 ctx->decryptAllowed = 0;
50 ctx->encryptAllowed = 0;
51 ctx->authAllowed = 1;
52
53 return CommonPrepareEpilogue(ctx);
54 }
55
Tss2_Sys_HierarchyControl_Complete(TSS2_SYS_CONTEXT * sysContext)56 TSS2_RC Tss2_Sys_HierarchyControl_Complete (
57 TSS2_SYS_CONTEXT *sysContext)
58 {
59 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
60
61 if (!ctx)
62 return TSS2_SYS_RC_BAD_REFERENCE;
63
64 return CommonComplete(ctx);
65 }
66
Tss2_Sys_HierarchyControl(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_HIERARCHY authHandle,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPMI_RH_ENABLES enable,TPMI_YES_NO state,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)67 TSS2_RC Tss2_Sys_HierarchyControl(
68 TSS2_SYS_CONTEXT *sysContext,
69 TPMI_RH_HIERARCHY authHandle,
70 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
71 TPMI_RH_ENABLES enable,
72 TPMI_YES_NO state,
73 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
74 {
75 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
76 TSS2_RC rval;
77
78 rval = Tss2_Sys_HierarchyControl_Prepare(sysContext, authHandle, enable, state);
79 if (rval)
80 return rval;
81
82 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
83 if (rval)
84 return rval;
85
86 return Tss2_Sys_HierarchyControl_Complete(sysContext);
87 }
88