/src/tpm2/Marshal_PCR_Read.c
Line | Count | Source |
1 | | // Copyright 2015 The Chromium OS 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 | | // THIS CODE IS GENERATED - DO NOT MODIFY! |
6 | | |
7 | | #include "MemoryLib_fp.h" |
8 | | #include "PCR_Read_fp.h" |
9 | | |
10 | | #if IS_CC_ENABLED(PCR_Read) |
11 | | static UINT16 PCR_Read_Out_Marshal(PCR_Read_Out* source, |
12 | | TPMI_ST_COMMAND_TAG tag, |
13 | | BYTE** buffer, |
14 | 0 | INT32* size) { |
15 | 0 | UINT16 total_size = 0; |
16 | 0 | UINT32 parameter_size = 0; |
17 | 0 | BYTE* parameter_size_location; |
18 | 0 | INT32 parameter_size_size = sizeof(UINT32); |
19 | 0 | UINT32 num_response_handles = 0; |
20 | | // Add parameter_size=0 to indicate size of the parameter area. Will be |
21 | | // replaced later by computed parameter_size. |
22 | 0 | if (tag == TPM_ST_SESSIONS) { |
23 | 0 | parameter_size_location = *buffer; |
24 | | // Don't add to total_size, but increment *buffer and decrement *size. |
25 | 0 | UINT32_Marshal(¶meter_size, buffer, size); |
26 | 0 | } |
27 | | // Marshal response parameters. |
28 | 0 | total_size += UINT32_Marshal(&source->pcrUpdateCounter, buffer, size); |
29 | 0 | total_size += |
30 | 0 | TPML_PCR_SELECTION_Marshal(&source->pcrSelectionOut, buffer, size); |
31 | 0 | total_size += TPML_DIGEST_Marshal(&source->pcrValues, buffer, size); |
32 | | // Compute actual parameter_size. Don't add result to total_size. |
33 | 0 | if (tag == TPM_ST_SESSIONS) { |
34 | 0 | parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE); |
35 | 0 | UINT32_Marshal(¶meter_size, ¶meter_size_location, |
36 | 0 | ¶meter_size_size); |
37 | 0 | } |
38 | 0 | return total_size; |
39 | 0 | } |
40 | | #endif |
41 | | |
42 | | static TPM_RC PCR_Read_In_Unmarshal(PCR_Read_In* target, |
43 | | TPM_HANDLE request_handles[], |
44 | | BYTE** buffer, |
45 | 1 | INT32* size) { |
46 | 1 | TPM_RC result = TPM_RC_SUCCESS; |
47 | | // Unmarshal request parameters. |
48 | 1 | result = TPML_PCR_SELECTION_Unmarshal(&target->pcrSelectionIn, buffer, size); |
49 | 1 | if (result != TPM_RC_SUCCESS) { |
50 | 0 | return result; |
51 | 0 | } |
52 | 1 | if ((result == TPM_RC_SUCCESS) && *size) { |
53 | 1 | result = TPM_RC_SIZE; |
54 | 1 | } |
55 | 1 | return result; |
56 | 1 | } |
57 | | |
58 | | TPM_RC Exec_PCR_Read(TPMI_ST_COMMAND_TAG tag, |
59 | | BYTE** request_parameter_buffer, |
60 | | INT32* request_parameter_buffer_size, |
61 | | TPM_HANDLE request_handles[], |
62 | | UINT32* response_handle_buffer_size, |
63 | 1 | UINT32* response_parameter_buffer_size) { |
64 | 1 | TPM_RC result = TPM_RC_SUCCESS; |
65 | 1 | PCR_Read_In in; |
66 | 1 | PCR_Read_Out out; |
67 | 1 | #if IS_CC_ENABLED(PCR_Read) |
68 | 1 | BYTE* response_buffer; |
69 | 1 | INT32 response_buffer_size; |
70 | 1 | UINT16 bytes_marshalled; |
71 | 1 | UINT16 num_response_handles = 0; |
72 | 1 | #endif |
73 | 1 | *response_handle_buffer_size = 0; |
74 | 1 | *response_parameter_buffer_size = 0; |
75 | | // Unmarshal request parameters to input structure. |
76 | 1 | result = PCR_Read_In_Unmarshal(&in, request_handles, request_parameter_buffer, |
77 | 1 | request_parameter_buffer_size); |
78 | 1 | if (result != TPM_RC_SUCCESS) { |
79 | 1 | return result; |
80 | 1 | } |
81 | | // Execute command. |
82 | 0 | result = TPM2_PCR_Read(&in, &out); |
83 | 0 | if (result != TPM_RC_SUCCESS) { |
84 | 0 | return result; |
85 | 0 | } |
86 | | // Marshal output structure to global response buffer. |
87 | 0 | #if IS_CC_ENABLED(PCR_Read) |
88 | 0 | response_buffer = MemoryGetResponseBuffer(TPM_CC_PCR_Read) + 10; |
89 | 0 | response_buffer_size = MAX_RESPONSE_SIZE - 10; |
90 | 0 | bytes_marshalled = |
91 | 0 | PCR_Read_Out_Marshal(&out, tag, &response_buffer, &response_buffer_size); |
92 | 0 | *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE); |
93 | 0 | *response_parameter_buffer_size = |
94 | 0 | bytes_marshalled - *response_handle_buffer_size; |
95 | 0 | return TPM_RC_SUCCESS; |
96 | 0 | #endif |
97 | 0 | return TPM_RC_COMMAND_CODE; |
98 | 0 | } |