• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_SetBits_Prepare(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_AUTH authHandle,TPMI_RH_NV_INDEX nvIndex,UINT64 bits)15 TSS2_RC Tss2_Sys_NV_SetBits_Prepare(
16     TSS2_SYS_CONTEXT *sysContext,
17     TPMI_RH_NV_AUTH authHandle,
18     TPMI_RH_NV_INDEX nvIndex,
19     UINT64 bits)
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_NV_SetBits);
28     if (rval)
29         return rval;
30 
31     rval = Tss2_MU_UINT32_Marshal(authHandle, ctx->cmdBuffer,
32                                   ctx->maxCmdSize,
33                                   &ctx->nextData);
34     if (rval)
35         return rval;
36 
37     rval = Tss2_MU_UINT32_Marshal(nvIndex, ctx->cmdBuffer,
38                                   ctx->maxCmdSize,
39                                   &ctx->nextData);
40     if (rval)
41         return rval;
42 
43     rval = Tss2_MU_UINT64_Marshal(bits, 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_NV_SetBits_Complete(TSS2_SYS_CONTEXT * sysContext)56 TSS2_RC Tss2_Sys_NV_SetBits_Complete (
57     TSS2_SYS_CONTEXT *sysContext)
58 {
59     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
60 
61     if (!ctx)
62         return TSS2_SYS_RC_BAD_REFERENCE;
63 
64     return CommonComplete(ctx);
65 }
66 
Tss2_Sys_NV_SetBits(TSS2_SYS_CONTEXT * sysContext,TPMI_RH_NV_AUTH authHandle,TPMI_RH_NV_INDEX nvIndex,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,UINT64 bits,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)67 TSS2_RC Tss2_Sys_NV_SetBits(
68     TSS2_SYS_CONTEXT *sysContext,
69     TPMI_RH_NV_AUTH authHandle,
70     TPMI_RH_NV_INDEX nvIndex,
71     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
72     UINT64 bits,
73     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
74 {
75     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
76     TSS2_RC rval;
77 
78     rval = Tss2_Sys_NV_SetBits_Prepare(sysContext, authHandle, nvIndex, bits);
79     if (rval)
80         return rval;
81 
82     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
83     if (rval)
84         return rval;
85 
86     return Tss2_Sys_NV_SetBits_Complete(sysContext);
87 }
88