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