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_Read_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_AUTH authHandle,TPMI_RH_NV_INDEX nvIndex,UINT16 size,UINT16 offset)15 TSS2_RC Tss2_Sys_NV_Read_Prepare(
16 TSS2_SYS_CONTEXT *sysContext,
17 TPMI_RH_NV_AUTH authHandle,
18 TPMI_RH_NV_INDEX nvIndex,
19 UINT16 size,
20 UINT16 offset)
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_NV_Read);
29 if (rval)
30 return rval;
31
32 rval = Tss2_MU_UINT32_Marshal(authHandle, ctx->cmdBuffer,
33 ctx->maxCmdSize,
34 &ctx->nextData);
35 if (rval)
36 return rval;
37
38 rval = Tss2_MU_UINT32_Marshal(nvIndex, ctx->cmdBuffer,
39 ctx->maxCmdSize,
40 &ctx->nextData);
41 if (rval)
42 return rval;
43
44 rval = Tss2_MU_UINT16_Marshal(size, ctx->cmdBuffer,
45 ctx->maxCmdSize,
46 &ctx->nextData);
47 if (rval)
48 return rval;
49
50 rval = Tss2_MU_UINT16_Marshal(offset, ctx->cmdBuffer,
51 ctx->maxCmdSize,
52 &ctx->nextData);
53 if (rval)
54 return rval;
55
56 ctx->decryptAllowed = 0;
57 ctx->encryptAllowed = 1;
58 ctx->authAllowed = 1;
59
60 return CommonPrepareEpilogue(ctx);
61 }
62
Tss2_Sys_NV_Read_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_MAX_NV_BUFFER * data)63 TSS2_RC Tss2_Sys_NV_Read_Complete(
64 TSS2_SYS_CONTEXT *sysContext,
65 TPM2B_MAX_NV_BUFFER *data)
66 {
67 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
68 TSS2_RC rval;
69
70 if (!ctx)
71 return TSS2_SYS_RC_BAD_REFERENCE;
72
73 rval = CommonComplete(ctx);
74 if (rval)
75 return rval;
76
77 return Tss2_MU_TPM2B_MAX_NV_BUFFER_Unmarshal(ctx->cmdBuffer,
78 ctx->maxCmdSize,
79 &ctx->nextData,
80 data);
81 }
82
Tss2_Sys_NV_Read(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_AUTH authHandle,TPMI_RH_NV_INDEX nvIndex,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,UINT16 size,UINT16 offset,TPM2B_MAX_NV_BUFFER * data,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)83 TSS2_RC Tss2_Sys_NV_Read(
84 TSS2_SYS_CONTEXT *sysContext,
85 TPMI_RH_NV_AUTH authHandle,
86 TPMI_RH_NV_INDEX nvIndex,
87 TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
88 UINT16 size,
89 UINT16 offset,
90 TPM2B_MAX_NV_BUFFER *data,
91 TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
92 {
93 _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
94 TSS2_RC rval;
95
96 rval = Tss2_Sys_NV_Read_Prepare(sysContext, authHandle, nvIndex, size, offset);
97 if (rval)
98 return rval;
99
100 rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
101 if (rval)
102 return rval;
103
104 return Tss2_Sys_NV_Read_Complete(sysContext, data);
105 }
106