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 "CreatePrimary_fp.h"
9 
CreatePrimary_Out_Marshal(CreatePrimary_Out * source,TPMI_ST_COMMAND_TAG tag,BYTE ** buffer,INT32 * size)10 UINT16 CreatePrimary_Out_Marshal(CreatePrimary_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 = 1;
19   // Marshal response handles.
20   total_size += TPM_HANDLE_Marshal(&source->objectHandle, buffer, size);
21   // Add parameter_size=0 to indicate size of the parameter area. Will be
22   // replaced later by computed parameter_size.
23   if (tag == TPM_ST_SESSIONS) {
24     parameter_size_location = *buffer;
25     // Don't add to total_size, but increment *buffer and decrement *size.
26     UINT32_Marshal(&parameter_size, buffer, size);
27   }
28   // Marshal response parameters.
29   total_size += TPM2B_PUBLIC_Marshal(&source->outPublic, buffer, size);
30   total_size +=
31       TPM2B_CREATION_DATA_Marshal(&source->creationData, buffer, size);
32   total_size += TPM2B_DIGEST_Marshal(&source->creationHash, buffer, size);
33   total_size += TPMT_TK_CREATION_Marshal(&source->creationTicket, buffer, size);
34   total_size += TPM2B_NAME_Marshal(&source->name, buffer, size);
35   // Compute actual parameter_size. Don't add result to total_size.
36   if (tag == TPM_ST_SESSIONS) {
37     parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE);
38     UINT32_Marshal(&parameter_size, &parameter_size_location,
39                    &parameter_size_size);
40   }
41   return total_size;
42 }
43 
CreatePrimary_In_Unmarshal(CreatePrimary_In * target,TPM_HANDLE request_handles[],BYTE ** buffer,INT32 * size)44 TPM_RC CreatePrimary_In_Unmarshal(CreatePrimary_In* target,
45                                   TPM_HANDLE request_handles[],
46                                   BYTE** buffer,
47                                   INT32* size) {
48   TPM_RC result = TPM_RC_SUCCESS;
49   // Get request handles from request_handles array.
50   target->primaryHandle = request_handles[0];
51   // Unmarshal request parameters.
52   result = TPM2B_SENSITIVE_CREATE_Unmarshal(&target->inSensitive, buffer, size);
53   if (result != TPM_RC_SUCCESS) {
54     return result;
55   }
56   result = TPM2B_PUBLIC_Unmarshal(&target->inPublic, buffer, size);
57   if (result != TPM_RC_SUCCESS) {
58     return result;
59   }
60   result = TPM2B_DATA_Unmarshal(&target->outsideInfo, buffer, size);
61   if (result != TPM_RC_SUCCESS) {
62     return result;
63   }
64   result = TPML_PCR_SELECTION_Unmarshal(&target->creationPCR, buffer, size);
65   if (result != TPM_RC_SUCCESS) {
66     return result;
67   }
68   if ((result == TPM_RC_SUCCESS) && *size) {
69     result = TPM_RC_SIZE;
70   }
71   return result;
72 }
73 
Exec_CreatePrimary(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)74 TPM_RC Exec_CreatePrimary(TPMI_ST_COMMAND_TAG tag,
75                           BYTE** request_parameter_buffer,
76                           INT32* request_parameter_buffer_size,
77                           TPM_HANDLE request_handles[],
78                           UINT32* response_handle_buffer_size,
79                           UINT32* response_parameter_buffer_size) {
80   TPM_RC result = TPM_RC_SUCCESS;
81   CreatePrimary_In in;
82   CreatePrimary_Out out;
83 #ifdef TPM_CC_CreatePrimary
84   BYTE* response_buffer;
85   INT32 response_buffer_size;
86   UINT16 bytes_marshalled;
87   UINT16 num_response_handles = 1;
88 #endif
89   *response_handle_buffer_size = 0;
90   *response_parameter_buffer_size = 0;
91   // Unmarshal request parameters to input structure.
92   result =
93       CreatePrimary_In_Unmarshal(&in, request_handles, request_parameter_buffer,
94                                  request_parameter_buffer_size);
95   if (result != TPM_RC_SUCCESS) {
96     return result;
97   }
98   // Execute command.
99   result = TPM2_CreatePrimary(&in, &out);
100   if (result != TPM_RC_SUCCESS) {
101     return result;
102   }
103 // Marshal output structure to global response buffer.
104 #ifdef TPM_CC_CreatePrimary
105   response_buffer = MemoryGetResponseBuffer(TPM_CC_CreatePrimary) + 10;
106   response_buffer_size = MAX_RESPONSE_SIZE - 10;
107   bytes_marshalled = CreatePrimary_Out_Marshal(&out, tag, &response_buffer,
108                                                &response_buffer_size);
109   *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE);
110   *response_parameter_buffer_size =
111       bytes_marshalled - *response_handle_buffer_size;
112   return TPM_RC_SUCCESS;
113 #endif
114   return TPM_RC_COMMAND_CODE;
115 }
116