1 | /* $Id: tpm.h 90587 2021-08-10 09:39:57Z 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/types.h>
|
---|
34 | #include <iprt/assertcompile.h>
|
---|
35 | #include <iprt/string.h>
|
---|
36 |
|
---|
37 | #pragma pack(1)
|
---|
38 | /**
|
---|
39 | * TPM request header (everything big endian).
|
---|
40 | */
|
---|
41 | typedef struct TPMREQHDR
|
---|
42 | {
|
---|
43 | /** The tag for this request. */
|
---|
44 | uint16_t u16Tag;
|
---|
45 | /** Size of the request in bytes. */
|
---|
46 | uint32_t cbReq;
|
---|
47 | /** The request ordinal to execute. */
|
---|
48 | uint32_t u32Ordinal;
|
---|
49 | } TPMREQHDR;
|
---|
50 | AssertCompileSize(TPMREQHDR, 2 + 4 + 4);
|
---|
51 | /** Pointer to a TPM request header. */
|
---|
52 | typedef TPMREQHDR *PTPMREQHDR;
|
---|
53 | /** Pointer to a const TPM request header. */
|
---|
54 | typedef const TPMREQHDR *PCTPMREQHDR;
|
---|
55 |
|
---|
56 |
|
---|
57 | /** @name TPM request ordinals.
|
---|
58 | * @{ */
|
---|
59 | /** Perform a full self test. */
|
---|
60 | #define TPM_ORD_SELFTESTFULL UINT32_C(80)
|
---|
61 | /** Continue the selftest. */
|
---|
62 | #define TPM_ORD_CONTINUESELFTEST UINT32_C(83)
|
---|
63 | /** Return the test result. */
|
---|
64 | #define TPM_ORD_GETTESTRESULT UINT32_C(84)
|
---|
65 | /** @} */
|
---|
66 |
|
---|
67 |
|
---|
68 | /**
|
---|
69 | * TPM response header (everything big endian).
|
---|
70 | */
|
---|
71 | typedef struct TPMRESPHDR
|
---|
72 | {
|
---|
73 | /** The tag for this request. */
|
---|
74 | uint16_t u16Tag;
|
---|
75 | /** Size of the response in bytes. */
|
---|
76 | uint32_t cbResp;
|
---|
77 | /** The error code for the response. */
|
---|
78 | uint32_t u32ErrCode;
|
---|
79 | } TPMRESPHDR;
|
---|
80 | AssertCompileSize(TPMRESPHDR, 2 + 4 + 4);
|
---|
81 | /** Pointer to a TPM response header. */
|
---|
82 | typedef TPMRESPHDR *PTPMRESPHDR;
|
---|
83 | /** Pointer to a const TPM response header. */
|
---|
84 | typedef const TPMRESPHDR *PCTPMRESPHDR;
|
---|
85 |
|
---|
86 |
|
---|
87 | /** @name TPM status codes.
|
---|
88 | * @{ */
|
---|
89 | /** Request executed successfully. */
|
---|
90 | #define TPM_SUCCESS UINT32_C(0)
|
---|
91 | /** Authentication failed. */
|
---|
92 | #define TPM_AUTHFAIL UINT32_C(1)
|
---|
93 | /** An index is malformed. */
|
---|
94 | #define TPM_BADINDEX UINT32_C(2)
|
---|
95 | /** A request parameter is invalid. */
|
---|
96 | #define TPM_BAD_PARAMETER UINT32_C(3)
|
---|
97 | /** The TPM failed to execute the request. */
|
---|
98 | #define TPM_FAIL UINT32_C(9)
|
---|
99 | /** @todo Extend as need arises. */
|
---|
100 | /** @} */
|
---|
101 |
|
---|
102 |
|
---|
103 | /* Some inline helpers to account for the unaligned members of the request and response headers. */
|
---|
104 |
|
---|
105 | /**
|
---|
106 | * Returns the request tag of the given TPM request header.
|
---|
107 | *
|
---|
108 | * @returns TPM request tag in bytes.
|
---|
109 | * @param pTpmReqHdr Pointer to the TPM request header.
|
---|
110 | */
|
---|
111 | DECLINLINE(uint16_t) RTTpmReqGetTag(PCTPMREQHDR pTpmReqHdr)
|
---|
112 | {
|
---|
113 | return RT_BE2H_U16(pTpmReqHdr->u16Tag);
|
---|
114 | }
|
---|
115 |
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * Returns the request size of the given TPM request header.
|
---|
119 | *
|
---|
120 | * @returns TPM request size in bytes.
|
---|
121 | * @param pTpmReqHdr Pointer to the TPM request header.
|
---|
122 | */
|
---|
123 | DECLINLINE(size_t) RTTpmReqGetSz(PCTPMREQHDR pTpmReqHdr)
|
---|
124 | {
|
---|
125 | uint32_t cbReq;
|
---|
126 | memcpy(&cbReq, &pTpmReqHdr->cbReq, sizeof(pTpmReqHdr->cbReq));
|
---|
127 | return RT_BE2H_U32(cbReq);
|
---|
128 | }
|
---|
129 |
|
---|
130 |
|
---|
131 | /**
|
---|
132 | * Returns the request ordinal of the given TPM request header.
|
---|
133 | *
|
---|
134 | * @returns TPM request ordinal in bytes.
|
---|
135 | * @param pTpmReqHdr Pointer to the TPM request header.
|
---|
136 | */
|
---|
137 | DECLINLINE(uint32_t) RTTpmReqGetOrdinal(PCTPMREQHDR pTpmReqHdr)
|
---|
138 | {
|
---|
139 | uint32_t u32Ordinal;
|
---|
140 | memcpy(&u32Ordinal, &pTpmReqHdr->u32Ordinal, sizeof(pTpmReqHdr->u32Ordinal));
|
---|
141 | return RT_BE2H_U32(u32Ordinal);
|
---|
142 | }
|
---|
143 |
|
---|
144 |
|
---|
145 | /**
|
---|
146 | * Returns the response tag of the given TPM response header.
|
---|
147 | *
|
---|
148 | * @returns TPM request tag in bytes.
|
---|
149 | * @param pTpmRespHdr Pointer to the TPM response header.
|
---|
150 | */
|
---|
151 | DECLINLINE(uint16_t) RTTpmRespGetTag(PCTPMRESPHDR pTpmRespHdr)
|
---|
152 | {
|
---|
153 | return RT_BE2H_U16(pTpmRespHdr->u16Tag);
|
---|
154 | }
|
---|
155 |
|
---|
156 |
|
---|
157 | /**
|
---|
158 | * Returns the request size of the given TPM request header.
|
---|
159 | *
|
---|
160 | * @returns TPM response size in bytes.
|
---|
161 | * @param pTpmRespHdr Pointer to the TPM response header.
|
---|
162 | */
|
---|
163 | DECLINLINE(size_t) RTTpmRespGetSz(PCTPMRESPHDR pTpmRespHdr)
|
---|
164 | {
|
---|
165 | uint32_t cbResp;
|
---|
166 | memcpy(&cbResp, &pTpmRespHdr->cbResp, sizeof(pTpmRespHdr->cbResp));
|
---|
167 | return RT_BE2H_U32(cbResp);
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | /**
|
---|
172 | * Returns the request ordinal of the given TPM request header.
|
---|
173 | *
|
---|
174 | * @returns TPM response error code.
|
---|
175 | * @param pTpmRespHdr Pointer to the TPM response header.
|
---|
176 | */
|
---|
177 | DECLINLINE(uint32_t) RTTpmRespGetErrCode(PCTPMRESPHDR pTpmRespHdr)
|
---|
178 | {
|
---|
179 | uint32_t u32ErrCode;
|
---|
180 | memcpy(&u32ErrCode, &pTpmRespHdr->u32ErrCode, sizeof(pTpmRespHdr->u32ErrCode));
|
---|
181 | return RT_BE2H_U32(u32ErrCode);
|
---|
182 | }
|
---|
183 |
|
---|
184 | #pragma pack()
|
---|
185 |
|
---|
186 | #endif /* !IPRT_INCLUDED_formats_tpm_h */
|
---|
187 |
|
---|