1 | /* $Id: DrvIfsTrace-tpm.cpp 104894 2024-06-12 13:53:43Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox interface callback tracing driver.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2020-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * SPDX-License-Identifier: GPL-3.0-only
|
---|
26 | */
|
---|
27 |
|
---|
28 |
|
---|
29 | /*********************************************************************************************************************************
|
---|
30 | * Header Files *
|
---|
31 | *********************************************************************************************************************************/
|
---|
32 | #define LOG_GROUP LOG_GROUP_MISC
|
---|
33 | #include <VBox/log.h>
|
---|
34 | #include <VBox/version.h>
|
---|
35 |
|
---|
36 | #include <iprt/errcore.h>
|
---|
37 | #include <iprt/tracelog.h>
|
---|
38 |
|
---|
39 | #include "DrvIfsTraceInternal.h"
|
---|
40 |
|
---|
41 |
|
---|
42 | /*
|
---|
43 | *
|
---|
44 | * ITpmConnector Implementation.
|
---|
45 | *
|
---|
46 | */
|
---|
47 | static const RTTRACELOGEVTITEMDESC g_ITpmConnectorGetVersionEvtItems[] =
|
---|
48 | {
|
---|
49 | {"enmTpmVersion", "TPM version (TPMVERSION enum) reported by the lower driver", RTTRACELOGTYPE_UINT32, 0}
|
---|
50 | };
|
---|
51 |
|
---|
52 | static const RTTRACELOGEVTDESC g_ITpmConnectorGetVersionEvtDesc =
|
---|
53 | {
|
---|
54 | "ITpmConnector.GetVersion",
|
---|
55 | "",
|
---|
56 | RTTRACELOGEVTSEVERITY_DEBUG,
|
---|
57 | RT_ELEMENTS(g_ITpmConnectorGetVersionEvtItems),
|
---|
58 | g_ITpmConnectorGetVersionEvtItems
|
---|
59 | };
|
---|
60 |
|
---|
61 | /**
|
---|
62 | * @interface_method_impl{PDMITPMCONNECTOR,pfnGetVersion}
|
---|
63 | */
|
---|
64 | static DECLCALLBACK(TPMVERSION) drvIfTraceITpmConnector_GetVersion(PPDMITPMCONNECTOR pInterface)
|
---|
65 | {
|
---|
66 | PDRVIFTRACE pThis = RT_FROM_MEMBER(pInterface, DRVIFTRACE, ITpmConnector);
|
---|
67 | TPMVERSION enmTpmVersion = pThis->pITpmConBelow->pfnGetVersion(pThis->pITpmConBelow);
|
---|
68 |
|
---|
69 | int rcTraceLog = RTTraceLogWrEvtAddL(pThis->hTraceLog, &g_ITpmConnectorGetVersionEvtDesc, 0, 0, 0, (uint32_t)enmTpmVersion);
|
---|
70 | if (RT_FAILURE(rcTraceLog))
|
---|
71 | LogRelMax(10, ("DrvIfTrace#%d: Failed to add event to trace log %Rrc\n", pThis->pDrvIns->iInstance, rcTraceLog));
|
---|
72 |
|
---|
73 | return enmTpmVersion;
|
---|
74 | }
|
---|
75 |
|
---|
76 |
|
---|
77 | static const RTTRACELOGEVTITEMDESC g_ITpmConnectorGetLocalityMaxEvtItems[] =
|
---|
78 | {
|
---|
79 | {"u32LocMax", "Maximum locality supported returned by the lower driver", RTTRACELOGTYPE_UINT32, 0}
|
---|
80 | };
|
---|
81 |
|
---|
82 | static const RTTRACELOGEVTDESC g_ITpmConnectorGetLocalityMaxEvtDesc =
|
---|
83 | {
|
---|
84 | "ITpmConnector.GetLocalityMax",
|
---|
85 | "",
|
---|
86 | RTTRACELOGEVTSEVERITY_DEBUG,
|
---|
87 | RT_ELEMENTS(g_ITpmConnectorGetLocalityMaxEvtItems),
|
---|
88 | g_ITpmConnectorGetLocalityMaxEvtItems
|
---|
89 | };
|
---|
90 |
|
---|
91 | /**
|
---|
92 | * @interface_method_impl{PDMITPMCONNECTOR,pfnGetLocalityMax}
|
---|
93 | */
|
---|
94 | static DECLCALLBACK(uint32_t) drvIfTraceITpmConnector_GetLocalityMax(PPDMITPMCONNECTOR pInterface)
|
---|
95 | {
|
---|
96 | PDRVIFTRACE pThis = RT_FROM_MEMBER(pInterface, DRVIFTRACE, ITpmConnector);
|
---|
97 | uint32_t u32LocMax = pThis->pITpmConBelow->pfnGetLocalityMax(pThis->pITpmConBelow);
|
---|
98 |
|
---|
99 | int rcTraceLog = RTTraceLogWrEvtAddL(pThis->hTraceLog, &g_ITpmConnectorGetLocalityMaxEvtDesc, 0, 0, 0, u32LocMax);
|
---|
100 | if (RT_FAILURE(rcTraceLog))
|
---|
101 | LogRelMax(10, ("DrvIfTrace#%d: Failed to add event to trace log %Rrc\n", pThis->pDrvIns->iInstance, rcTraceLog));
|
---|
102 |
|
---|
103 | return u32LocMax;
|
---|
104 | }
|
---|
105 |
|
---|
106 |
|
---|
107 | static const RTTRACELOGEVTITEMDESC g_ITpmConnectorGetBufferSizeEvtItems[] =
|
---|
108 | {
|
---|
109 | {"cbBuffer", "Buffer size in bytes returned by the lower driver", RTTRACELOGTYPE_UINT32, 0}
|
---|
110 | };
|
---|
111 |
|
---|
112 | static const RTTRACELOGEVTDESC g_ITpmConnectorGetBufferSizeEvtDesc =
|
---|
113 | {
|
---|
114 | "ITpmConnector.GetBufferSize",
|
---|
115 | "",
|
---|
116 | RTTRACELOGEVTSEVERITY_DEBUG,
|
---|
117 | RT_ELEMENTS(g_ITpmConnectorGetBufferSizeEvtItems),
|
---|
118 | g_ITpmConnectorGetBufferSizeEvtItems
|
---|
119 | };
|
---|
120 |
|
---|
121 | /**
|
---|
122 | * @interface_method_impl{PDMITPMCONNECTOR,pfnGetBufferSize}
|
---|
123 | */
|
---|
124 | static DECLCALLBACK(uint32_t) drvIfTraceITpmConnector_GetBufferSize(PPDMITPMCONNECTOR pInterface)
|
---|
125 | {
|
---|
126 | PDRVIFTRACE pThis = RT_FROM_MEMBER(pInterface, DRVIFTRACE, ITpmConnector);
|
---|
127 | uint32_t cbBuffer = pThis->pITpmConBelow->pfnGetBufferSize(pThis->pITpmConBelow);
|
---|
128 |
|
---|
129 | int rcTraceLog = RTTraceLogWrEvtAddL(pThis->hTraceLog, &g_ITpmConnectorGetBufferSizeEvtDesc, 0, 0, 0, cbBuffer);
|
---|
130 | if (RT_FAILURE(rcTraceLog))
|
---|
131 | LogRelMax(10, ("DrvIfTrace#%d: Failed to add event to trace log %Rrc\n", pThis->pDrvIns->iInstance, rcTraceLog));
|
---|
132 |
|
---|
133 | return cbBuffer;
|
---|
134 | }
|
---|
135 |
|
---|
136 |
|
---|
137 | static const RTTRACELOGEVTITEMDESC g_ITpmConnectorGetEstablishedFlagEvtItems[] =
|
---|
138 | {
|
---|
139 | {"fEstablished", "Established flag status returned by the lower driver", RTTRACELOGTYPE_BOOL, 0}
|
---|
140 | };
|
---|
141 |
|
---|
142 | static const RTTRACELOGEVTDESC g_ITpmConnectorGetEstablishedFlagEvtDesc =
|
---|
143 | {
|
---|
144 | "ITpmConnector.GetEstablishedFlag",
|
---|
145 | "",
|
---|
146 | RTTRACELOGEVTSEVERITY_DEBUG,
|
---|
147 | RT_ELEMENTS(g_ITpmConnectorGetEstablishedFlagEvtItems),
|
---|
148 | g_ITpmConnectorGetEstablishedFlagEvtItems
|
---|
149 | };
|
---|
150 |
|
---|
151 | /**
|
---|
152 | * @interface_method_impl{PDMITPMCONNECTOR,pfnGetEstablishedFlag}
|
---|
153 | */
|
---|
154 | static DECLCALLBACK(bool) drvIfTraceITpmConnector_GetEstablishedFlag(PPDMITPMCONNECTOR pInterface)
|
---|
155 | {
|
---|
156 | PDRVIFTRACE pThis = RT_FROM_MEMBER(pInterface, DRVIFTRACE, ITpmConnector);
|
---|
157 | bool fEstablished = pThis->pITpmConBelow->pfnGetEstablishedFlag(pThis->pITpmConBelow);
|
---|
158 |
|
---|
159 | int rcTraceLog = RTTraceLogWrEvtAddL(pThis->hTraceLog, &g_ITpmConnectorGetEstablishedFlagEvtDesc, 0, 0, 0, fEstablished);
|
---|
160 | if (RT_FAILURE(rcTraceLog))
|
---|
161 | LogRelMax(10, ("DrvIfTrace#%d: Failed to add event to trace log %Rrc\n", pThis->pDrvIns->iInstance, rcTraceLog));
|
---|
162 |
|
---|
163 | return fEstablished;
|
---|
164 | }
|
---|
165 |
|
---|
166 |
|
---|
167 | static const RTTRACELOGEVTITEMDESC g_ITpmConnectorResetEstablishedFlagEvtItems[] =
|
---|
168 | {
|
---|
169 | {"bLoc", "Locality to reset the flag for", RTTRACELOGTYPE_UINT8, 0},
|
---|
170 | {"rc", "Status code returned by the lower driver", RTTRACELOGTYPE_INT32, 0}
|
---|
171 | };
|
---|
172 |
|
---|
173 | static const RTTRACELOGEVTDESC g_ITpmConnectorResetEstablishedFlagEvtDesc =
|
---|
174 | {
|
---|
175 | "ITpmConnector.ResetEstablishedFlag",
|
---|
176 | "",
|
---|
177 | RTTRACELOGEVTSEVERITY_DEBUG,
|
---|
178 | RT_ELEMENTS(g_ITpmConnectorResetEstablishedFlagEvtItems),
|
---|
179 | g_ITpmConnectorResetEstablishedFlagEvtItems
|
---|
180 | };
|
---|
181 |
|
---|
182 | /**
|
---|
183 | * @interface_method_impl{PDMITPMCONNECTOR,pfnResetEstablishedFlag}
|
---|
184 | */
|
---|
185 | static DECLCALLBACK(int) drvIfTraceITpmConnector_ResetEstablishedFlag(PPDMITPMCONNECTOR pInterface, uint8_t bLoc)
|
---|
186 | {
|
---|
187 | PDRVIFTRACE pThis = RT_FROM_MEMBER(pInterface, DRVIFTRACE, ITpmConnector);
|
---|
188 | int rc = pThis->pITpmConBelow->pfnResetEstablishedFlag(pThis->pITpmConBelow, bLoc);
|
---|
189 |
|
---|
190 | int rcTraceLog = RTTraceLogWrEvtAddL(pThis->hTraceLog, &g_ITpmConnectorResetEstablishedFlagEvtDesc, 0, 0, 0, bLoc, rc);
|
---|
191 | if (RT_FAILURE(rcTraceLog))
|
---|
192 | LogRelMax(10, ("DrvIfTrace#%d: Failed to add event to trace log %Rrc\n", pThis->pDrvIns->iInstance, rcTraceLog));
|
---|
193 |
|
---|
194 | return rc;
|
---|
195 | }
|
---|
196 |
|
---|
197 |
|
---|
198 | static const RTTRACELOGEVTITEMDESC g_ITpmConnectorCmdExecReqEvtItems[] =
|
---|
199 | {
|
---|
200 | {"bLoc", "Locality in which the request is executed", RTTRACELOGTYPE_UINT8, 0},
|
---|
201 | {"pvCmd", "The raw command data", RTTRACELOGTYPE_RAWDATA, 4096},
|
---|
202 | {"cbCmd", "Size of the command in bytes", RTTRACELOGTYPE_SIZE, 0}
|
---|
203 | };
|
---|
204 |
|
---|
205 | static const RTTRACELOGEVTDESC g_ITpmConnectorCmdExecReqEvtDesc =
|
---|
206 | {
|
---|
207 | "ITpmConnector.CmdExecReq",
|
---|
208 | "",
|
---|
209 | RTTRACELOGEVTSEVERITY_DEBUG,
|
---|
210 | RT_ELEMENTS(g_ITpmConnectorCmdExecReqEvtItems),
|
---|
211 | g_ITpmConnectorCmdExecReqEvtItems
|
---|
212 | };
|
---|
213 |
|
---|
214 |
|
---|
215 | static const RTTRACELOGEVTITEMDESC g_ITpmConnectorCmdExecRespEvtItems[] =
|
---|
216 | {
|
---|
217 | {"rc", "Status code returned by the lower driver", RTTRACELOGTYPE_INT32, 0},
|
---|
218 | {"pvResp", "TPM response data", RTTRACELOGTYPE_RAWDATA, 4096},
|
---|
219 | {"cbResp", "Size of the response in bytes", RTTRACELOGTYPE_SIZE, 0},
|
---|
220 | };
|
---|
221 |
|
---|
222 | static const RTTRACELOGEVTDESC g_ITpmConnectorCmdExecRespEvtDesc =
|
---|
223 | {
|
---|
224 | "ITpmConnector.CmdExecResp",
|
---|
225 | "",
|
---|
226 | RTTRACELOGEVTSEVERITY_DEBUG,
|
---|
227 | RT_ELEMENTS(g_ITpmConnectorCmdExecRespEvtItems),
|
---|
228 | g_ITpmConnectorCmdExecRespEvtItems
|
---|
229 | };
|
---|
230 |
|
---|
231 |
|
---|
232 | /**
|
---|
233 | * @interface_method_impl{PDMITPMCONNECTOR,pfnCmdExec}
|
---|
234 | */
|
---|
235 | static DECLCALLBACK(int) drvIfTraceITpmConnector_CmdExec(PPDMITPMCONNECTOR pInterface, uint8_t bLoc, const void *pvCmd, size_t cbCmd, void *pvResp, size_t cbResp)
|
---|
236 | {
|
---|
237 | PDRVIFTRACE pThis = RT_FROM_MEMBER(pInterface, DRVIFTRACE, ITpmConnector);
|
---|
238 |
|
---|
239 | int rcTraceLog = RTTraceLogWrEvtAddL(pThis->hTraceLog, &g_ITpmConnectorCmdExecReqEvtDesc, 0, 0, 0, bLoc, pvCmd, cbCmd);
|
---|
240 | if (RT_FAILURE(rcTraceLog))
|
---|
241 | LogRelMax(10, ("DrvIfTrace#%d: Failed to add event to trace log %Rrc\n", pThis->pDrvIns->iInstance, rcTraceLog));
|
---|
242 |
|
---|
243 | int rc = pThis->pITpmConBelow->pfnCmdExec(pThis->pITpmConBelow, bLoc, pvCmd, cbCmd, pvResp, cbResp);
|
---|
244 |
|
---|
245 |
|
---|
246 | rcTraceLog = RTTraceLogWrEvtAddL(pThis->hTraceLog, &g_ITpmConnectorCmdExecRespEvtDesc, 0, 0, 0, rc, pvResp, cbResp);
|
---|
247 | if (RT_FAILURE(rcTraceLog))
|
---|
248 | LogRelMax(10, ("DrvIfTrace#%d: Failed to add event to trace log %Rrc\n", pThis->pDrvIns->iInstance, rcTraceLog));
|
---|
249 |
|
---|
250 | return rc;
|
---|
251 | }
|
---|
252 |
|
---|
253 |
|
---|
254 | static const RTTRACELOGEVTITEMDESC g_ITpmConnectorCmdCancelEvtItems[] =
|
---|
255 | {
|
---|
256 | {"rc", "Status code returned by the lower driver", RTTRACELOGTYPE_INT32, 0}
|
---|
257 | };
|
---|
258 |
|
---|
259 | static const RTTRACELOGEVTDESC g_ITpmConnectorCmdCancelEvtDesc =
|
---|
260 | {
|
---|
261 | "ITpmConnector.CmdCancel",
|
---|
262 | "",
|
---|
263 | RTTRACELOGEVTSEVERITY_DEBUG,
|
---|
264 | RT_ELEMENTS(g_ITpmConnectorCmdCancelEvtItems),
|
---|
265 | g_ITpmConnectorCmdCancelEvtItems
|
---|
266 | };
|
---|
267 |
|
---|
268 | /**
|
---|
269 | * @callback_method_impl{PDMITPMCONNECTOR,pfnCmdCancel}
|
---|
270 | */
|
---|
271 | static DECLCALLBACK(int) drvIfTraceITpmConnector_CmdCancel(PPDMITPMCONNECTOR pInterface)
|
---|
272 | {
|
---|
273 | PDRVIFTRACE pThis = RT_FROM_MEMBER(pInterface, DRVIFTRACE, ITpmConnector);
|
---|
274 | int rc = pThis->pITpmConBelow->pfnCmdCancel(pThis->pITpmConBelow);
|
---|
275 |
|
---|
276 | int rcTraceLog = RTTraceLogWrEvtAddL(pThis->hTraceLog, &g_ITpmConnectorCmdCancelEvtDesc, 0, 0, 0, rc);
|
---|
277 | if (RT_FAILURE(rcTraceLog))
|
---|
278 | LogRelMax(10, ("DrvIfTrace#%d: Failed to add event to trace log %Rrc\n", pThis->pDrvIns->iInstance, rcTraceLog));
|
---|
279 |
|
---|
280 | return rc;
|
---|
281 | }
|
---|
282 |
|
---|
283 |
|
---|
284 | /**
|
---|
285 | * Initializes TPM related interfaces.
|
---|
286 | *
|
---|
287 | * @param pThis The interface callback trace driver instance.
|
---|
288 | */
|
---|
289 | DECLHIDDEN(void) drvIfsTrace_TpmIfInit(PDRVIFTRACE pThis)
|
---|
290 | {
|
---|
291 | pThis->ITpmConnector.pfnGetVersion = drvIfTraceITpmConnector_GetVersion;
|
---|
292 | pThis->ITpmConnector.pfnGetLocalityMax = drvIfTraceITpmConnector_GetLocalityMax;
|
---|
293 | pThis->ITpmConnector.pfnGetBufferSize = drvIfTraceITpmConnector_GetBufferSize;
|
---|
294 | pThis->ITpmConnector.pfnGetEstablishedFlag = drvIfTraceITpmConnector_GetEstablishedFlag;
|
---|
295 | pThis->ITpmConnector.pfnResetEstablishedFlag = drvIfTraceITpmConnector_ResetEstablishedFlag;
|
---|
296 | pThis->ITpmConnector.pfnCmdExec = drvIfTraceITpmConnector_CmdExec;
|
---|
297 | pThis->ITpmConnector.pfnCmdCancel = drvIfTraceITpmConnector_CmdCancel;
|
---|
298 | }
|
---|
299 |
|
---|