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_GetCapability_Prepare(TSS2_SYS_CONTEXT * sysContext,TPM2_CAP capability,UINT32 property,UINT32 propertyCount)15 TSS2_RC Tss2_Sys_GetCapability_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPM2_CAP capability,
18 UINT32 property,
19 UINT32 propertyCount)
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_GetCapability);
28 if (rval)
29 return rval;
30
31 rval = Tss2_MU_UINT32_Marshal(capability, ctx->cmdBuffer,
32 ctx->maxCmdSize,
33 &ctx->nextData);
34 if (rval)
35 return rval;
36
37 rval = Tss2_MU_UINT32_Marshal(property, ctx->cmdBuffer,
38 ctx->maxCmdSize,
39 &ctx->nextData);
40 if (rval)
41 return rval;
42
43 rval = Tss2_MU_UINT32_Marshal(propertyCount, 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_GetCapability_Complete(TSS2_SYS_CONTEXT * sysContext,TPMI_YES_NO * moreData,TPMS_CAPABILITY_DATA * capabilityData)56 TSS2_RC Tss2_Sys_GetCapability_Complete(
57 TSS2_SYS_CONTEXT *sysContext,
58 TPMI_YES_NO *moreData,
59 TPMS_CAPABILITY_DATA *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_TPMS_CAPABILITY_DATA_Unmarshal(ctx->cmdBuffer,
79 ctx->maxCmdSize,
80 &ctx->nextData,
81 capabilityData);
82 }
83
Tss2_Sys_GetCapability(TSS2_SYS_CONTEXT * sysContext,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPM2_CAP capability,UINT32 property,UINT32 propertyCount,TPMI_YES_NO * moreData,TPMS_CAPABILITY_DATA * capabilityData,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)84 TSS2_RC Tss2_Sys_GetCapability(
85 TSS2_SYS_CONTEXT *sysContext,
86 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
87 TPM2_CAP capability,
88 UINT32 property,
89 UINT32 propertyCount,
90 TPMI_YES_NO *moreData,
91 TPMS_CAPABILITY_DATA *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_GetCapability_Prepare(sysContext, capability, property,
98 propertyCount);
99 if (rval)
100 return rval;
101
102 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
103 if (rval)
104 return rval;
105
106 return Tss2_Sys_GetCapability_Complete(sysContext, moreData, capabilityData);
107 }
108