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_GetTestResult_Prepare(TSS2_SYS_CONTEXT * sysContext)15 TSS2_RC Tss2_Sys_GetTestResult_Prepare(
16     TSS2_SYS_CONTEXT *sysContext)
17 {
18     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
19     TSS2_RC rval;
20 
21     if (!ctx)
22         return TSS2_SYS_RC_BAD_REFERENCE;
23 
24     rval = CommonPreparePrologue(ctx, TPM2_CC_GetTestResult);
25     if (rval)
26         return rval;
27 
28     ctx->decryptAllowed = 0;
29     ctx->encryptAllowed = 1;
30     ctx->authAllowed = 1;
31 
32     return CommonPrepareEpilogue(ctx);
33 }
34 
Tss2_Sys_GetTestResult_Complete(TSS2_SYS_CONTEXT * sysContext,TPM2B_MAX_BUFFER * outData,TSS2_RC * testResult)35 TSS2_RC Tss2_Sys_GetTestResult_Complete(
36     TSS2_SYS_CONTEXT *sysContext,
37     TPM2B_MAX_BUFFER *outData,
38     TSS2_RC *testResult)
39 {
40     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
41     TSS2_RC rval;
42 
43     if (!ctx)
44         return TSS2_SYS_RC_BAD_REFERENCE;
45 
46     rval = CommonComplete(ctx);
47     if (rval)
48         return rval;
49 
50     rval = Tss2_MU_TPM2B_MAX_BUFFER_Unmarshal(ctx->cmdBuffer,
51                                               ctx->maxCmdSize,
52                                               &ctx->nextData,
53                                               outData);
54     if (rval)
55         return rval;
56 
57     return Tss2_MU_UINT32_Unmarshal(ctx->cmdBuffer,
58                                     ctx->maxCmdSize,
59                                     &ctx->nextData,
60                                     testResult);
61 }
62 
Tss2_Sys_GetTestResult(TSS2_SYS_CONTEXT * sysContext,TSS2L_SYS_AUTH_COMMAND const * cmdAuthsArray,TPM2B_MAX_BUFFER * outData,TSS2_RC * testResult,TSS2L_SYS_AUTH_RESPONSE * rspAuthsArray)63 TSS2_RC Tss2_Sys_GetTestResult(
64     TSS2_SYS_CONTEXT *sysContext,
65     TSS2L_SYS_AUTH_COMMAND const *cmdAuthsArray,
66     TPM2B_MAX_BUFFER *outData,
67     TSS2_RC *testResult,
68     TSS2L_SYS_AUTH_RESPONSE *rspAuthsArray)
69 {
70     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
71     TSS2_RC rval;
72 
73     rval = Tss2_Sys_GetTestResult_Prepare(sysContext);
74     if (rval)
75         return rval;
76 
77     rval = CommonOneCall(ctx, cmdAuthsArray, rspAuthsArray);
78     if (rval)
79         return rval;
80 
81     return Tss2_Sys_GetTestResult_Complete(sysContext, outData, testResult);
82 }
83