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