VirtualBox

source: vbox/trunk/include/iprt/formats/tpm.h@ 90588

Last change on this file since 90588 was 90588, checked in by vboxsync, 3 years ago

Devices/Security: EFI can communicate with the external TPM emulator over our own TPM interface emulation, bugref:10075 [build fix]

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 5.4 KB
Line 
1/* $Id: tpm.h 90588 2021-08-10 09:44:41Z vboxsync $ */
2/** @file
3 * IPRT, TPM common definitions (this is actually a protocol and not a format).
4 */
5
6/*
7 * Copyright (C) 2021 Oracle Corporation
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.virtualbox.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * The contents of this file may alternatively be used under the terms
18 * of the Common Development and Distribution License Version 1.0
19 * (CDDL) only, as it comes in the "COPYING.CDDL" file of the
20 * VirtualBox OSE distribution, in which case the provisions of the
21 * CDDL are applicable instead of those of the GPL.
22 *
23 * You may elect to license modified versions of this file under the
24 * terms and conditions of either the GPL or the CDDL or both.
25 */
26
27#ifndef IPRT_INCLUDED_formats_tpm_h
28#define IPRT_INCLUDED_formats_tpm_h
29#ifndef RT_WITHOUT_PRAGMA_ONCE
30# pragma once
31#endif
32
33#include <iprt/asm.h>
34#include <iprt/cdefs.h>
35#include <iprt/types.h>
36#include <iprt/assertcompile.h>
37#include <iprt/string.h>
38
39#pragma pack(1)
40/**
41 * TPM request header (everything big endian).
42 */
43typedef struct TPMREQHDR
44{
45 /** The tag for this request. */
46 uint16_t u16Tag;
47 /** Size of the request in bytes. */
48 uint32_t cbReq;
49 /** The request ordinal to execute. */
50 uint32_t u32Ordinal;
51} TPMREQHDR;
52AssertCompileSize(TPMREQHDR, 2 + 4 + 4);
53/** Pointer to a TPM request header. */
54typedef TPMREQHDR *PTPMREQHDR;
55/** Pointer to a const TPM request header. */
56typedef const TPMREQHDR *PCTPMREQHDR;
57
58
59/** @name TPM request ordinals.
60 * @{ */
61/** Perform a full self test. */
62#define TPM_ORD_SELFTESTFULL UINT32_C(80)
63/** Continue the selftest. */
64#define TPM_ORD_CONTINUESELFTEST UINT32_C(83)
65/** Return the test result. */
66#define TPM_ORD_GETTESTRESULT UINT32_C(84)
67/** @} */
68
69
70/**
71 * TPM response header (everything big endian).
72 */
73typedef struct TPMRESPHDR
74{
75 /** The tag for this request. */
76 uint16_t u16Tag;
77 /** Size of the response in bytes. */
78 uint32_t cbResp;
79 /** The error code for the response. */
80 uint32_t u32ErrCode;
81} TPMRESPHDR;
82AssertCompileSize(TPMRESPHDR, 2 + 4 + 4);
83/** Pointer to a TPM response header. */
84typedef TPMRESPHDR *PTPMRESPHDR;
85/** Pointer to a const TPM response header. */
86typedef const TPMRESPHDR *PCTPMRESPHDR;
87
88
89/** @name TPM status codes.
90 * @{ */
91/** Request executed successfully. */
92#define TPM_SUCCESS UINT32_C(0)
93/** Authentication failed. */
94#define TPM_AUTHFAIL UINT32_C(1)
95/** An index is malformed. */
96#define TPM_BADINDEX UINT32_C(2)
97/** A request parameter is invalid. */
98#define TPM_BAD_PARAMETER UINT32_C(3)
99/** The TPM failed to execute the request. */
100#define TPM_FAIL UINT32_C(9)
101/** @todo Extend as need arises. */
102/** @} */
103
104
105/* Some inline helpers to account for the unaligned members of the request and response headers. */
106
107/**
108 * Returns the request tag of the given TPM request header.
109 *
110 * @returns TPM request tag in bytes.
111 * @param pTpmReqHdr Pointer to the TPM request header.
112 */
113DECLINLINE(uint16_t) RTTpmReqGetTag(PCTPMREQHDR pTpmReqHdr)
114{
115 return RT_BE2H_U16(pTpmReqHdr->u16Tag);
116}
117
118
119/**
120 * Returns the request size of the given TPM request header.
121 *
122 * @returns TPM request size in bytes.
123 * @param pTpmReqHdr Pointer to the TPM request header.
124 */
125DECLINLINE(size_t) RTTpmReqGetSz(PCTPMREQHDR pTpmReqHdr)
126{
127 uint32_t cbReq;
128 memcpy(&cbReq, &pTpmReqHdr->cbReq, sizeof(pTpmReqHdr->cbReq));
129 return RT_BE2H_U32(cbReq);
130}
131
132
133/**
134 * Returns the request ordinal of the given TPM request header.
135 *
136 * @returns TPM request ordinal in bytes.
137 * @param pTpmReqHdr Pointer to the TPM request header.
138 */
139DECLINLINE(uint32_t) RTTpmReqGetOrdinal(PCTPMREQHDR pTpmReqHdr)
140{
141 uint32_t u32Ordinal;
142 memcpy(&u32Ordinal, &pTpmReqHdr->u32Ordinal, sizeof(pTpmReqHdr->u32Ordinal));
143 return RT_BE2H_U32(u32Ordinal);
144}
145
146
147/**
148 * Returns the response tag of the given TPM response header.
149 *
150 * @returns TPM request tag in bytes.
151 * @param pTpmRespHdr Pointer to the TPM response header.
152 */
153DECLINLINE(uint16_t) RTTpmRespGetTag(PCTPMRESPHDR pTpmRespHdr)
154{
155 return RT_BE2H_U16(pTpmRespHdr->u16Tag);
156}
157
158
159/**
160 * Returns the request size of the given TPM request header.
161 *
162 * @returns TPM response size in bytes.
163 * @param pTpmRespHdr Pointer to the TPM response header.
164 */
165DECLINLINE(size_t) RTTpmRespGetSz(PCTPMRESPHDR pTpmRespHdr)
166{
167 uint32_t cbResp;
168 memcpy(&cbResp, &pTpmRespHdr->cbResp, sizeof(pTpmRespHdr->cbResp));
169 return RT_BE2H_U32(cbResp);
170}
171
172
173/**
174 * Returns the request ordinal of the given TPM request header.
175 *
176 * @returns TPM response error code.
177 * @param pTpmRespHdr Pointer to the TPM response header.
178 */
179DECLINLINE(uint32_t) RTTpmRespGetErrCode(PCTPMRESPHDR pTpmRespHdr)
180{
181 uint32_t u32ErrCode;
182 memcpy(&u32ErrCode, &pTpmRespHdr->u32ErrCode, sizeof(pTpmRespHdr->u32ErrCode));
183 return RT_BE2H_U32(u32ErrCode);
184}
185
186#pragma pack()
187
188#endif /* !IPRT_INCLUDED_formats_tpm_h */
189
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette