1// Copyright 2016 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include <endian.h>
6#include "tpm-commands.h"
7
8uint32_t tpm_init_getrandom(struct tpm_getrandom_cmd *cmd, uint16_t bytes_requested) {
9    cmd->hdr.tag = htobe16(TPM_ST_NO_SESSIONS);
10    cmd->hdr.total_len = htobe32(sizeof(*cmd));
11    cmd->hdr.cmd_code = htobe32(TPM_CC_GET_RANDOM);
12    cmd->bytes_requested = htobe16(bytes_requested);
13
14    return static_cast<uint32_t>(sizeof(struct tpm_getrandom_resp)) + bytes_requested;
15}
16
17uint32_t tpm_init_shutdown(struct tpm_shutdown_cmd *cmd, uint16_t type) {
18    cmd->hdr.tag = htobe16(TPM_ST_NO_SESSIONS);
19    cmd->hdr.total_len = htobe32(sizeof(*cmd));
20    cmd->hdr.cmd_code = htobe32(TPM_CC_SHUTDOWN);
21    cmd->shutdown_type = htobe16(type);
22    return static_cast<uint32_t>(sizeof(struct tpm_shutdown_resp));
23}
24