Jocelyn Bohr | a4ed3aa | 2015-07-30 10:44:16 -0700 | [diff] [blame] | 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 "Create_fp.h" |
| 9 | |
Vadim Bendebury | c3730f6 | 2019-01-15 11:59:05 -0800 | [diff] [blame] | 10 | #if IS_CC_ENABLED(Create) |
Vadim Bendebury | 56abbbf | 2018-08-28 15:34:31 -0700 | [diff] [blame] | 11 | static UINT16 Create_Out_Marshal(Create_Out* source, |
| 12 | TPMI_ST_COMMAND_TAG tag, |
| 13 | BYTE** buffer, |
| 14 | INT32* size) { |
Jocelyn Bohr | a4ed3aa | 2015-07-30 10:44:16 -0700 | [diff] [blame] | 15 | UINT16 total_size = 0; |
| 16 | UINT32 parameter_size = 0; |
| 17 | BYTE* parameter_size_location; |
| 18 | INT32 parameter_size_size = sizeof(UINT32); |
| 19 | 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 | if (tag == TPM_ST_SESSIONS) { |
| 23 | parameter_size_location = *buffer; |
| 24 | // Don't add to total_size, but increment *buffer and decrement *size. |
| 25 | UINT32_Marshal(¶meter_size, buffer, size); |
| 26 | } |
| 27 | // Marshal response parameters. |
| 28 | total_size += TPM2B_PRIVATE_Marshal(&source->outPrivate, buffer, size); |
| 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 | // Compute actual parameter_size. Don't add result to total_size. |
| 35 | if (tag == TPM_ST_SESSIONS) { |
| 36 | parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE); |
| 37 | UINT32_Marshal(¶meter_size, ¶meter_size_location, |
| 38 | ¶meter_size_size); |
| 39 | } |
| 40 | return total_size; |
| 41 | } |
Vadim Bendebury | 56abbbf | 2018-08-28 15:34:31 -0700 | [diff] [blame] | 42 | #endif |
Jocelyn Bohr | a4ed3aa | 2015-07-30 10:44:16 -0700 | [diff] [blame] | 43 | |
Vadim Bendebury | 56abbbf | 2018-08-28 15:34:31 -0700 | [diff] [blame] | 44 | static TPM_RC Create_In_Unmarshal(Create_In* target, |
| 45 | TPM_HANDLE request_handles[], |
| 46 | BYTE** buffer, |
| 47 | INT32* size) { |
Jocelyn Bohr | a4ed3aa | 2015-07-30 10:44:16 -0700 | [diff] [blame] | 48 | TPM_RC result = TPM_RC_SUCCESS; |
| 49 | // Get request handles from request_handles array. |
| 50 | target->parentHandle = 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 | } |
Vadim Bendebury | 3dfffca | 2015-10-20 17:17:54 -0700 | [diff] [blame] | 68 | if ((result == TPM_RC_SUCCESS) && *size) { |
| 69 | result = TPM_RC_SIZE; |
| 70 | } |
Jocelyn Bohr | a4ed3aa | 2015-07-30 10:44:16 -0700 | [diff] [blame] | 71 | return result; |
| 72 | } |
| 73 | |
| 74 | TPM_RC Exec_Create(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 | Create_In in; |
| 82 | Create_Out out; |
Vadim Bendebury | c3730f6 | 2019-01-15 11:59:05 -0800 | [diff] [blame] | 83 | #if IS_CC_ENABLED(Create) |
Jocelyn Bohr | a4ed3aa | 2015-07-30 10:44:16 -0700 | [diff] [blame] | 84 | BYTE* response_buffer; |
| 85 | INT32 response_buffer_size; |
| 86 | UINT16 bytes_marshalled; |
| 87 | UINT16 num_response_handles = 0; |
| 88 | #endif |
| 89 | *response_handle_buffer_size = 0; |
| 90 | *response_parameter_buffer_size = 0; |
| 91 | // Unmarshal request parameters to input structure. |
| 92 | result = Create_In_Unmarshal(&in, request_handles, request_parameter_buffer, |
| 93 | request_parameter_buffer_size); |
| 94 | if (result != TPM_RC_SUCCESS) { |
| 95 | return result; |
| 96 | } |
| 97 | // Execute command. |
| 98 | result = TPM2_Create(&in, &out); |
| 99 | if (result != TPM_RC_SUCCESS) { |
| 100 | return result; |
| 101 | } |
| 102 | // Marshal output structure to global response buffer. |
Vadim Bendebury | c3730f6 | 2019-01-15 11:59:05 -0800 | [diff] [blame] | 103 | #if IS_CC_ENABLED(Create) |
Jocelyn Bohr | a4ed3aa | 2015-07-30 10:44:16 -0700 | [diff] [blame] | 104 | response_buffer = MemoryGetResponseBuffer(TPM_CC_Create) + 10; |
| 105 | response_buffer_size = MAX_RESPONSE_SIZE - 10; |
| 106 | bytes_marshalled = |
| 107 | Create_Out_Marshal(&out, tag, &response_buffer, &response_buffer_size); |
| 108 | *response_handle_buffer_size = num_response_handles * sizeof(TPM_HANDLE); |
| 109 | *response_parameter_buffer_size = |
| 110 | bytes_marshalled - *response_handle_buffer_size; |
| 111 | return TPM_RC_SUCCESS; |
| 112 | #endif |
| 113 | return TPM_RC_COMMAND_CODE; |
| 114 | } |