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 "StartAuthSession_fp.h"
9
StartAuthSession_Out_Marshal(StartAuthSession_Out * source,TPMI_ST_COMMAND_TAG tag,BYTE ** buffer,INT32 * size)10 UINT16 StartAuthSession_Out_Marshal(StartAuthSession_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 +=
21 TPMI_SH_AUTH_SESSION_Marshal(&source->sessionHandle, 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_NONCE_Marshal(&source->nonceTPM, buffer, size);
31 // Compute actual parameter_size. Don't add result to total_size.
32 if (tag == TPM_ST_SESSIONS) {
33 parameter_size = total_size - num_response_handles * sizeof(TPM_HANDLE);
34 UINT32_Marshal(¶meter_size, ¶meter_size_location,
35 ¶meter_size_size);
36 }
37 return total_size;
38 }
39
StartAuthSession_In_Unmarshal(StartAuthSession_In * target,TPM_HANDLE request_handles[],BYTE ** buffer,INT32 * size)40 TPM_RC StartAuthSession_In_Unmarshal(StartAuthSession_In* target,
41 TPM_HANDLE request_handles[],
42 BYTE** buffer,
43 INT32* size) {
44 TPM_RC result = TPM_RC_SUCCESS;
45 // Get request handles from request_handles array.
46 target->tpmKey = request_handles[0];
47 target->bind = request_handles[1];
48 // Unmarshal request parameters.
49 result = TPM2B_NONCE_Unmarshal(&target->nonceCaller, buffer, size);
50 if (result != TPM_RC_SUCCESS) {
51 return result;
52 }
53 result =
54 TPM2B_ENCRYPTED_SECRET_Unmarshal(&target->encryptedSalt, buffer, size);
55 if (result != TPM_RC_SUCCESS) {
56 return result;
57 }
58 result = TPM_SE_Unmarshal(&target->sessionType, buffer, size);
59 if (result != TPM_RC_SUCCESS) {
60 return result;
61 }
62 result = TPMT_SYM_DEF_Unmarshal(&target->symmetric, buffer, size);
63 if (result != TPM_RC_SUCCESS) {
64 return result;
65 }
66 result = TPMI_ALG_HASH_Unmarshal(&target->authHash, buffer, size, FALSE);
67 if (result != TPM_RC_SUCCESS) {
68 return result;
69 }
70 if ((result == TPM_RC_SUCCESS) && *size) {
71 result = TPM_RC_SIZE;
72 }
73 return result;
74 }
75
Exec_StartAuthSession(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)76 TPM_RC Exec_StartAuthSession(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 StartAuthSession_In in;
84 StartAuthSession_Out out;
85 #ifdef TPM_CC_StartAuthSession
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 = StartAuthSession_In_Unmarshal(&in, request_handles,
95 request_parameter_buffer,
96 request_parameter_buffer_size);
97 if (result != TPM_RC_SUCCESS) {
98 return result;
99 }
100 // Execute command.
101 result = TPM2_StartAuthSession(&in, &out);
102 if (result != TPM_RC_SUCCESS) {
103 return result;
104 }
105 // Marshal output structure to global response buffer.
106 #ifdef TPM_CC_StartAuthSession
107 response_buffer = MemoryGetResponseBuffer(TPM_CC_StartAuthSession) + 10;
108 response_buffer_size = MAX_RESPONSE_SIZE - 10;
109 bytes_marshalled = StartAuthSession_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 }
118