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_PP_Commands_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_PLATFORM auth,const TPML_CC * setList,const TPML_CC * clearList)15 TSS2_RC Tss2_Sys_PP_Commands_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_RH_PLATFORM auth,
18     const TPML_CC *setList,
19     const TPML_CC *clearList)
20 {
21     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
22     TSS2_RC rval;
23 
24     if (!ctx || !setList || !clearList)
25         return TSS2_SYS_RC_BAD_REFERENCE;
26 
27     rval = CommonPreparePrologue(ctx, TPM2_CC_PP_Commands);
28     if (rval)
29         return rval;
30 
31     rval = Tss2_MU_UINT32_Marshal(auth, ctx->cmdBuffer,
32                                   ctx->maxCmdSize,
33                                   &ctx->nextData);
34     if (rval)
35         return rval;
36 
37     rval = Tss2_MU_TPML_CC_Marshal(setList, ctx->cmdBuffer,
38                                    ctx->maxCmdSize,
39                                    &ctx->nextData);
40     if (rval)
41         return rval;
42 
43     rval = Tss2_MU_TPML_CC_Marshal(clearList, 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_PP_Commands_Complete(TSS2_SYS_CONTEXT * sysContext)56 TSS2_RC Tss2_Sys_PP_Commands_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_PP_Commands(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_PLATFORM auth,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,const TPML_CC * setList,const TPML_CC * clearList,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)67 TSS2_RC Tss2_Sys_PP_Commands(
68     TSS2_SYS_CONTEXT *sysContext,
69     TPMI_RH_PLATFORM auth,
70     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
71     const TPML_CC *setList,
72     const TPML_CC *clearList,
73     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
74 {
75     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
76     TSS2_RC rval;
77 
78     if (!setList || !clearList)
79         return TSS2_SYS_RC_BAD_REFERENCE;
80 
81     rval = Tss2_Sys_PP_Commands_Prepare(sysContext, auth, setList, clearList);
82     if (rval)
83         return rval;
84 
85     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
86     if (rval)
87         return rval;
88 
89     return Tss2_Sys_PP_Commands_Complete(sysContext);
90 }
91