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_NV_ReadPublic_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_INDEX nvIndex)15 TSS2_RC Tss2_Sys_NV_ReadPublic_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_RH_NV_INDEX nvIndex)
18 {
19     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
20     TSS2_RC rval;
21 
22     if (!ctx)
23         return TSS2_SYS_RC_BAD_REFERENCE;
24 
25     rval = CommonPreparePrologue(ctx, TPM2_CC_NV_ReadPublic);
26     if (rval)
27         return rval;
28 
29     rval = Tss2_MU_UINT32_Marshal(nvIndex, ctx->cmdBuffer,
30                                   ctx->maxCmdSize,
31                                   &ctx->nextData);
32     if (rval)
33         return rval;
34 
35     ctx->decryptAllowed = 0;
36     ctx->encryptAllowed = 1;
37     ctx->authAllowed = 1;
38 
39     return CommonPrepareEpilogue(ctx);
40 }
41 
Tss2_Sys_NV_ReadPublic_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_NV_PUBLIC * nvPublic,TPM2B_NAME * nvName)42 TSS2_RC Tss2_Sys_NV_ReadPublic_Complete(
43     TSS2_SYS_CONTEXT *sysContext,
44     TPM2B_NV_PUBLIC *nvPublic,
45     TPM2B_NAME *nvName)
46 {
47     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
48     TSS2_RC rval;
49 
50     if (!ctx)
51         return TSS2_SYS_RC_BAD_REFERENCE;
52 
53     rval = CommonComplete(ctx);
54     if (rval)
55         return rval;
56 
57     rval = Tss2_MU_TPM2B_NV_PUBLIC_Unmarshal(ctx->cmdBuffer,
58                                              ctx->maxCmdSize,
59                                              &ctx->nextData,
60                                              nvPublic);
61     if (rval)
62         return rval;
63 
64     return Tss2_MU_TPM2B_NAME_Unmarshal(ctx->cmdBuffer,
65                                         ctx->maxCmdSize,
66                                         &ctx->nextData,
67                                         nvName);
68 }
69 
Tss2_Sys_NV_ReadPublic(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_INDEX nvIndex,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPM2B_NV_PUBLIC * nvPublic,TPM2B_NAME * nvName,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)70 TSS2_RC Tss2_Sys_NV_ReadPublic(
71     TSS2_SYS_CONTEXT *sysContext,
72     TPMI_RH_NV_INDEX nvIndex,
73     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
74     TPM2B_NV_PUBLIC *nvPublic,
75     TPM2B_NAME *nvName,
76     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
77 {
78     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
79     TSS2_RC rval;
80 
81     rval = Tss2_Sys_NV_ReadPublic_Prepare(sysContext, nvIndex);
82     if (rval)
83         return rval;
84 
85     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
86     if (rval)
87         return rval;
88 
89     return Tss2_Sys_NV_ReadPublic_Complete(sysContext, nvPublic, nvName);
90 }
91