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_AC_GetCapability_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_AC ac,TPM_AT capability,UINT32 count)15 TSS2_RC Tss2_Sys_AC_GetCapability_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_RH_AC ac,
18     TPM_AT capability,
19     UINT32 count)
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_AC_GetCapability);
28     if (rval)
29         return rval;
30 
31     rval = Tss2_MU_TPM2_HANDLE_Marshal(ac, ctx->cmdBuffer,
32                                        ctx->maxCmdSize,
33                                        &ctx->nextData);
34     if (rval)
35         return rval;
36 
37     rval = Tss2_MU_UINT32_Marshal(capability, ctx->cmdBuffer,
38                                   ctx->maxCmdSize,
39                                   &ctx->nextData);
40     if (rval)
41         return rval;
42 
43     rval = Tss2_MU_UINT32_Marshal(count, 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_AC_GetCapability_Complete(TSS2_SYS_CONTEXT * sysContext,TPMI_YES_NO * moreData,TPML_AC_CAPABILITIES * capabilityData)56 TSS2_RC Tss2_Sys_AC_GetCapability_Complete(
57     TSS2_SYS_CONTEXT *sysContext,
58     TPMI_YES_NO *moreData,
59     TPML_AC_CAPABILITIES *capabilityData)
60 {
61     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
62     TSS2_RC rval;
63 
64     if (!ctx)
65         return TSS2_SYS_RC_BAD_REFERENCE;
66 
67     rval = CommonComplete(ctx);
68     if (rval)
69         return rval;
70 
71     rval = Tss2_MU_UINT8_Unmarshal(ctx->cmdBuffer,
72                                    ctx->maxCmdSize,
73                                    &ctx->nextData,
74                                    moreData);
75     if (rval)
76         return rval;
77 
78     return Tss2_MU_TPML_AC_CAPABILITIES_Unmarshal(ctx->cmdBuffer,
79                                                   ctx->maxCmdSize,
80                                                   &ctx->nextData,
81                                                   capabilityData);
82 }
83 
Tss2_Sys_AC_GetCapability(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_AC ac,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPM_AT capability,UINT32 count,TPMI_YES_NO * moreData,TPML_AC_CAPABILITIES * capabilityData,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)84 TSS2_RC Tss2_Sys_AC_GetCapability(
85     TSS2_SYS_CONTEXT *sysContext,
86     TPMI_RH_AC ac,
87     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
88     TPM_AT capability,
89     UINT32 count,
90     TPMI_YES_NO *moreData,
91     TPML_AC_CAPABILITIES *capabilityData,
92     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
93 {
94     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
95     TSS2_RC rval;
96 
97     rval = Tss2_Sys_AC_GetCapability_Prepare(sysContext, ac, capability, count);
98     if (rval)
99         return rval;
100 
101     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
102     if (rval)
103         return rval;
104 
105     return Tss2_Sys_AC_GetCapability_Complete(sysContext, moreData,
106                                               capabilityData);
107 }
108