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 "Import_fp.h"
9 
Import_Out_Marshal(Import_Out * source,TPMI_ST_COMMAND_TAG tag,BYTE ** buffer,INT32 * size)10 UINT16 Import_Out_Marshal(Import_Out* source,
11                           TPMI_ST_COMMAND_TAG tag,
12                           BYTE** buffer,
13                           INT32* size) {
14   UINT16 total_size = 0;
15   UINT32 parameter_size = 0;
16   BYTE* parameter_size_location;
17   INT32 parameter_size_size = sizeof(UINT32);
18   UINT32 num_response_handles = 0;
19   // Add parameter_size=0 to indicate size of the parameter area. Will be
20   // replaced later by computed parameter_size.
21   if (tag == TPM_ST_SESSIONS) {
22     parameter_size_location = *buffer;
23     // Don't add to total_size, but increment *buffer and decrement *size.
24     UINT32_Marshal(&parameter_size, buffer, size);
25   }
26   // Marshal response parameters.
27   total_size += TPM2B_PRIVATE_Marshal(&source->outPrivate, buffer, size);
28   // Compute actual parameter_size. Don't add result to total_size.
29   if (tag == TPM_ST_SESSIONS) {
30     parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE);
31     UINT32_Marshal(&parameter_size, &parameter_size_location,
32                    &parameter_size_size);
33   }
34   return total_size;
35 }
36 
Import_In_Unmarshal(Import_In * target,TPM_HANDLE request_handles[],BYTE ** buffer,INT32 * size)37 TPM_RC Import_In_Unmarshal(Import_In* target,
38                            TPM_HANDLE request_handles[],
39                            BYTE** buffer,
40                            INT32* size) {
41   TPM_RC result = TPM_RC_SUCCESS;
42   // Get request handles from request_handles array.
43   target->parentHandle = request_handles[0];
44   // Unmarshal request parameters.
45   result = TPM2B_DATA_Unmarshal(&target->encryptionKey, buffer, size);
46   if (result != TPM_RC_SUCCESS) {
47     return result;
48   }
49   result = TPM2B_PUBLIC_Unmarshal(&target->objectPublic, buffer, size);
50   if (result != TPM_RC_SUCCESS) {
51     return result;
52   }
53   result = TPM2B_PRIVATE_Unmarshal(&target->duplicate, buffer, size);
54   if (result != TPM_RC_SUCCESS) {
55     return result;
56   }
57   result = TPM2B_ENCRYPTED_SECRET_Unmarshal(&target->inSymSeed, buffer, size);
58   if (result != TPM_RC_SUCCESS) {
59     return result;
60   }
61   result = TPMT_SYM_DEF_OBJECT_Unmarshal(&target->symmetricAlg, buffer, size);
62   if (result != TPM_RC_SUCCESS) {
63     return result;
64   }
65   if ((result == TPM_RC_SUCCESS) && *size) {
66     result = TPM_RC_SIZE;
67   }
68   return result;
69 }
70 
Exec_Import(TPMI_ST_COMMAND_TAG tag,BYTE ** request_parameter_buffer,INT32 * request_parameter_buffer_size,TPM_HANDLE request_handles[],UINT32 * response_handle_buffer_size,UINT32 * response_parameter_buffer_size)71 TPM_RC Exec_Import(TPMI_ST_COMMAND_TAG tag,
72                    BYTE** request_parameter_buffer,
73                    INT32* request_parameter_buffer_size,
74                    TPM_HANDLE request_handles[],
75                    UINT32* response_handle_buffer_size,
76                    UINT32* response_parameter_buffer_size) {
77   TPM_RC result = TPM_RC_SUCCESS;
78   Import_In in;
79   Import_Out out;
80 #ifdef TPM_CC_Import
81   BYTE* response_buffer;
82   INT32 response_buffer_size;
83   UINT16 bytes_marshalled;
84   UINT16 num_response_handles = 0;
85 #endif
86   *response_handle_buffer_size = 0;
87   *response_parameter_buffer_size = 0;
88   // Unmarshal request parameters to input structure.
89   result = Import_In_Unmarshal(&in, request_handles, request_parameter_buffer,
90                                request_parameter_buffer_size);
91   if (result != TPM_RC_SUCCESS) {
92     return result;
93   }
94   // Execute command.
95   result = TPM2_Import(&in, &out);
96   if (result != TPM_RC_SUCCESS) {
97     return result;
98   }
99 // Marshal output structure to global response buffer.
100 #ifdef TPM_CC_Import
101   response_buffer = MemoryGetResponseBuffer(TPM_CC_Import) + 10;
102   response_buffer_size = MAX_RESPONSE_SIZE - 10;
103   bytes_marshalled =
104       Import_Out_Marshal(&out, tag, &response_buffer, &response_buffer_size);
105   *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE);
106   *response_parameter_buffer_size =
107       bytes_marshalled - *response_handle_buffer_size;
108   return TPM_RC_SUCCESS;
109 #endif
110   return TPM_RC_COMMAND_CODE;
111 }
112