/src/tpm2/Marshal_ReadPublic.c
Line | Count | Source (jump to first uncovered line) |
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 "ReadPublic_fp.h" |
9 | | |
10 | | #if IS_CC_ENABLED(ReadPublic) |
11 | | static UINT16 ReadPublic_Out_Marshal(ReadPublic_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 += TPM2B_PUBLIC_Marshal(&source->outPublic, buffer, size); |
29 | 0 | total_size += TPM2B_NAME_Marshal(&source->name, buffer, size); |
30 | 0 | total_size += TPM2B_NAME_Marshal(&source->qualifiedName, buffer, size); |
31 | | // Compute actual parameter_size. Don't add result to total_size. |
32 | 0 | if (tag == TPM_ST_SESSIONS) { |
33 | 0 | parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE); |
34 | 0 | UINT32_Marshal(¶meter_size, ¶meter_size_location, |
35 | 0 | ¶meter_size_size); |
36 | 0 | } |
37 | 0 | return total_size; |
38 | 0 | } |
39 | | #endif |
40 | | |
41 | | static TPM_RC ReadPublic_In_Unmarshal(ReadPublic_In* target, |
42 | | TPM_HANDLE request_handles[], |
43 | | BYTE** buffer, |
44 | 0 | INT32* size) { |
45 | 0 | TPM_RC result = TPM_RC_SUCCESS; |
46 | | // Get request handles from request_handles array. |
47 | 0 | target->objectHandle = request_handles[0]; |
48 | 0 | if ((result == TPM_RC_SUCCESS) && *size) { |
49 | 0 | result = TPM_RC_SIZE; |
50 | 0 | } |
51 | 0 | return result; |
52 | 0 | } |
53 | | |
54 | | TPM_RC Exec_ReadPublic(TPMI_ST_COMMAND_TAG tag, |
55 | | BYTE** request_parameter_buffer, |
56 | | INT32* request_parameter_buffer_size, |
57 | | TPM_HANDLE request_handles[], |
58 | | UINT32* response_handle_buffer_size, |
59 | 0 | UINT32* response_parameter_buffer_size) { |
60 | 0 | TPM_RC result = TPM_RC_SUCCESS; |
61 | 0 | ReadPublic_In in; |
62 | 0 | ReadPublic_Out out; |
63 | 0 | #if IS_CC_ENABLED(ReadPublic) |
64 | 0 | BYTE* response_buffer; |
65 | 0 | INT32 response_buffer_size; |
66 | 0 | UINT16 bytes_marshalled; |
67 | 0 | UINT16 num_response_handles = 0; |
68 | 0 | #endif |
69 | 0 | *response_handle_buffer_size = 0; |
70 | 0 | *response_parameter_buffer_size = 0; |
71 | | // Unmarshal request parameters to input structure. |
72 | 0 | result = |
73 | 0 | ReadPublic_In_Unmarshal(&in, request_handles, request_parameter_buffer, |
74 | 0 | request_parameter_buffer_size); |
75 | 0 | if (result != TPM_RC_SUCCESS) { |
76 | 0 | return result; |
77 | 0 | } |
78 | | // Execute command. |
79 | 0 | result = TPM2_ReadPublic(&in, &out); |
80 | 0 | if (result != TPM_RC_SUCCESS) { |
81 | 0 | return result; |
82 | 0 | } |
83 | | // Marshal output structure to global response buffer. |
84 | 0 | #if IS_CC_ENABLED(ReadPublic) |
85 | 0 | response_buffer = MemoryGetResponseBuffer(TPM_CC_ReadPublic) + 10; |
86 | 0 | response_buffer_size = MAX_RESPONSE_SIZE - 10; |
87 | 0 | bytes_marshalled = ReadPublic_Out_Marshal(&out, tag, &response_buffer, |
88 | 0 | &response_buffer_size); |
89 | 0 | *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE); |
90 | 0 | *response_parameter_buffer_size = |
91 | 0 | bytes_marshalled - *response_handle_buffer_size; |
92 | 0 | return TPM_RC_SUCCESS; |
93 | 0 | #endif |
94 | 0 | return TPM_RC_COMMAND_CODE; |
95 | 0 | } |