1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************;
3 * Copyright (c) 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_Policy_AC_SendSelect_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,TPM2B_NAME * objectName,TPM2B_NAME * authHandleName,TPM2B_NAME * acName,TPMI_YES_NO includeObject)15 TSS2_RC Tss2_Sys_Policy_AC_SendSelect_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_SH_POLICY policySession,
18 TPM2B_NAME *objectName,
19 TPM2B_NAME *authHandleName,
20 TPM2B_NAME *acName,
21 TPMI_YES_NO includeObject)
22 {
23 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
24 TSS2_RC rval;
25
26 if (!ctx)
27 return TSS2_SYS_RC_BAD_REFERENCE;
28
29 rval = CommonPreparePrologue(ctx, TPM2_CC_Policy_AC_SendSelect);
30 if (rval)
31 return rval;
32
33 rval = Tss2_MU_TPM2_HANDLE_Marshal(policySession, ctx->cmdBuffer,
34 ctx->maxCmdSize,
35 &ctx->nextData);
36 if (rval)
37 return rval;
38
39 if (!objectName) {
40 ctx->decryptNull = 1;
41
42 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
43 ctx->maxCmdSize,
44 &ctx->nextData);
45 } else {
46
47 rval = Tss2_MU_TPM2B_NAME_Marshal(objectName, ctx->cmdBuffer,
48 ctx->maxCmdSize,
49 &ctx->nextData);
50 }
51 if (rval)
52 return rval;
53
54 if (!authHandleName) {
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(authHandleName, ctx->cmdBuffer,
62 ctx->maxCmdSize,
63 &ctx->nextData);
64 }
65
66 if (rval)
67 return rval;
68
69 if (!acName) {
70 rval = Tss2_MU_UINT16_Marshal(0, ctx->cmdBuffer,
71 ctx->maxCmdSize,
72 &ctx->nextData);
73
74 } else {
75
76 rval = Tss2_MU_TPM2B_NAME_Marshal(acName, ctx->cmdBuffer,
77 ctx->maxCmdSize,
78 &ctx->nextData);
79 }
80
81 if (rval)
82 return rval;
83
84 rval = Tss2_MU_UINT8_Marshal(includeObject, ctx->cmdBuffer,
85 ctx->maxCmdSize, &ctx->nextData);
86 if (rval)
87 return rval;
88
89 ctx->decryptAllowed = 1;
90 ctx->encryptAllowed = 0;
91 ctx->authAllowed = 1;
92
93 return CommonPrepareEpilogue(ctx);
94 }
95
Tss2_Sys_Policy_AC_SendSelect_Complete(TSS2_SYS_CONTEXT * sysContext)96 TSS2_RC Tss2_Sys_Policy_AC_SendSelect_Complete(
97 TSS2_SYS_CONTEXT *sysContext)
98 {
99 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
100
101 if (!ctx)
102 return TSS2_SYS_RC_BAD_REFERENCE;
103
104 return CommonComplete(ctx);
105 }
106
Tss2_Sys_Policy_AC_SendSelect(TSS2_SYS_CONTEXT * sysContext,TPMI_SH_POLICY policySession,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPM2B_NAME * objectName,TPM2B_NAME * authHandleName,TPM2B_NAME * acName,TPMI_YES_NO includeObject,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)107 TSS2_RC Tss2_Sys_Policy_AC_SendSelect(
108 TSS2_SYS_CONTEXT *sysContext,
109 TPMI_SH_POLICY policySession,
110 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
111 TPM2B_NAME *objectName,
112 TPM2B_NAME *authHandleName,
113 TPM2B_NAME *acName,
114 TPMI_YES_NO includeObject,
115 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
116 {
117 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
118 TSS2_RC rval;
119
120 rval = Tss2_Sys_Policy_AC_SendSelect_Prepare(sysContext, policySession,
121 objectName, authHandleName,
122 acName, includeObject);
123 if (rval)
124 return rval;
125
126 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
127 if (rval)
128 return rval;
129
130 return Tss2_Sys_Policy_AC_SendSelect_Complete(sysContext);
131 }
132