/src/tpm2/Marshal_LoadExternal.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 "LoadExternal_fp.h" |
9 | | |
10 | | #if IS_CC_ENABLED(LoadExternal) |
11 | | static UINT16 LoadExternal_Out_Marshal(LoadExternal_Out* source, |
12 | | TPMI_ST_COMMAND_TAG tag, |
13 | | BYTE** buffer, |
14 | 1 | INT32* size) { |
15 | 1 | UINT16 total_size = 0; |
16 | 1 | UINT32 parameter_size = 0; |
17 | 1 | BYTE* parameter_size_location; |
18 | 1 | INT32 parameter_size_size = sizeof(UINT32); |
19 | 1 | UINT32 num_response_handles = 1; |
20 | | // Marshal response handles. |
21 | 1 | total_size += TPM_HANDLE_Marshal(&source->objectHandle, buffer, size); |
22 | | // Add parameter_size=0 to indicate size of the parameter area. Will be |
23 | | // replaced later by computed parameter_size. |
24 | 1 | if (tag == TPM_ST_SESSIONS) { |
25 | 0 | parameter_size_location = *buffer; |
26 | | // Don't add to total_size, but increment *buffer and decrement *size. |
27 | 0 | UINT32_Marshal(¶meter_size, buffer, size); |
28 | 0 | } |
29 | | // Marshal response parameters. |
30 | 1 | total_size += TPM2B_NAME_Marshal(&source->name, buffer, size); |
31 | | // Compute actual parameter_size. Don't add result to total_size. |
32 | 1 | 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 | 1 | return total_size; |
38 | 1 | } |
39 | | #endif |
40 | | |
41 | | static TPM_RC LoadExternal_In_Unmarshal(LoadExternal_In* target, |
42 | | TPM_HANDLE request_handles[], |
43 | | BYTE** buffer, |
44 | 116 | INT32* size) { |
45 | 116 | TPM_RC result = TPM_RC_SUCCESS; |
46 | | // Unmarshal request parameters. |
47 | 116 | result = TPM2B_SENSITIVE_Unmarshal(&target->inPrivate, buffer, size); |
48 | 116 | if (result != TPM_RC_SUCCESS) { |
49 | 5 | return result; |
50 | 5 | } |
51 | 111 | result = TPM2B_PUBLIC_Unmarshal(&target->inPublic, buffer, size); |
52 | 111 | if (result != TPM_RC_SUCCESS) { |
53 | 51 | return result; |
54 | 51 | } |
55 | 60 | result = TPMI_RH_HIERARCHY_Unmarshal(&target->hierarchy, buffer, size, TRUE); |
56 | 60 | if (result != TPM_RC_SUCCESS) { |
57 | 3 | return result; |
58 | 3 | } |
59 | 57 | if ((result == TPM_RC_SUCCESS) && *size) { |
60 | 2 | result = TPM_RC_SIZE; |
61 | 2 | } |
62 | 57 | return result; |
63 | 60 | } |
64 | | |
65 | | TPM_RC Exec_LoadExternal(TPMI_ST_COMMAND_TAG tag, |
66 | | BYTE** request_parameter_buffer, |
67 | | INT32* request_parameter_buffer_size, |
68 | | TPM_HANDLE request_handles[], |
69 | | UINT32* response_handle_buffer_size, |
70 | 116 | UINT32* response_parameter_buffer_size) { |
71 | 116 | TPM_RC result = TPM_RC_SUCCESS; |
72 | 116 | LoadExternal_In in; |
73 | 116 | LoadExternal_Out out; |
74 | 116 | #if IS_CC_ENABLED(LoadExternal) |
75 | 116 | BYTE* response_buffer; |
76 | 116 | INT32 response_buffer_size; |
77 | 116 | UINT16 bytes_marshalled; |
78 | 116 | UINT16 num_response_handles = 1; |
79 | 116 | #endif |
80 | 116 | *response_handle_buffer_size = 0; |
81 | 116 | *response_parameter_buffer_size = 0; |
82 | | // Unmarshal request parameters to input structure. |
83 | 116 | result = |
84 | 116 | LoadExternal_In_Unmarshal(&in, request_handles, request_parameter_buffer, |
85 | 116 | request_parameter_buffer_size); |
86 | 116 | if (result != TPM_RC_SUCCESS) { |
87 | 61 | return result; |
88 | 61 | } |
89 | | // Execute command. |
90 | 55 | result = TPM2_LoadExternal(&in, &out); |
91 | 55 | if (result != TPM_RC_SUCCESS) { |
92 | 54 | return result; |
93 | 54 | } |
94 | | // Marshal output structure to global response buffer. |
95 | 1 | #if IS_CC_ENABLED(LoadExternal) |
96 | 1 | response_buffer = MemoryGetResponseBuffer(TPM_CC_LoadExternal) + 10; |
97 | 1 | response_buffer_size = MAX_RESPONSE_SIZE - 10; |
98 | 1 | bytes_marshalled = LoadExternal_Out_Marshal(&out, tag, &response_buffer, |
99 | 1 | &response_buffer_size); |
100 | 1 | *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE); |
101 | 1 | *response_parameter_buffer_size = |
102 | 1 | bytes_marshalled - *response_handle_buffer_size; |
103 | 1 | return TPM_RC_SUCCESS; |
104 | 0 | #endif |
105 | 0 | return TPM_RC_COMMAND_CODE; |
106 | 55 | } |