1 /* SPDX-License-Identifier: BSD-2-Clause */
2 /***********************************************************************;
3  * Copyright (c) 2015 - 2018, Intel Corporation
4  * All rights reserved.
5  ***********************************************************************/
6 #ifdef HAVE_CONFIG_H
7 #include <config.h>
8 #endif
9 
10 #include <string.h>
11 
12 #include "tss2_tpm2_types.h"
13 #include "tss2_mu.h"
14 #include "sysapi_util.h"
15 #include "util/tss2_endian.h"
16 
Tss2_Sys_GetCommandCode(TSS2_SYS_CONTEXT * sysContext,UINT8 * commandCode)17 TSS2_RC Tss2_Sys_GetCommandCode(
18     TSS2_SYS_CONTEXT *sysContext,
19     UINT8 *commandCode)
20 {
21     _TSS2_SYS_CONTEXT_BLOB *ctx = syscontext_cast(sysContext);
22 
23     if (!ctx || !commandCode)
24         return TSS2_SYS_RC_BAD_REFERENCE;
25 
26     if (ctx->previousStage == CMD_STAGE_INITIALIZE)
27         return TSS2_SYS_RC_BAD_SEQUENCE;
28 
29     TPM2_CC tmp = HOST_TO_BE_32(ctx->commandCode);
30     memcpy(commandCode, (void *)&tmp, sizeof(tmp));
31 
32     return TSS2_RC_SUCCESS;
33 }
34