firmware/lib/tpm2_lite/tlcl.c
/*
 * Serializes and sends the command, gets back the response and
 * parses it into the provided buffer.
 *
 * @command: command code.
 * @command_body: command-specific payload.
 * @response: pointer to the buffer to place the parsed response to.
 *
 * Returns the result of processing the command:
 *   - if an error happened at marshaling, sending, receiving or unmarshaling
 *     stages, returns the error code;
 *   - if the received response was successfully unmarshaled, returns success
 *     regardless of the received response code.
 */
Serializes and sends the command, gets back the response and
parses it into the provided buffer.

@command: command code.

Returns the result of processing the command:
- if an error happened at marshaling, sending, receiving or unmarshaling
stages, returns the error code;
- if the received response was successfully unmarshaled, returns success
regardless of the received response code.
Serializes and sends the command gets back the response and parses it into the provided buffer . @command : command code . Returns the result of processing the command : - if an error happened at marshaling sending receiving or unmarshaling stages returns the error code ; - if the received response was successfully unmarshaled returns success regardless of the received response code .
static uint32_t tpm_get_response(TPM_CC command,
				 void *command_body,
				 struct tpm2_response *response)
{
	static uint8_t cr_buffer[TPM_BUFFER_SIZE];
	int out_size;
	uint32_t res;
	uint32_t in_size;
	out_size = tpm_marshal_command(command, command_body,
				       cr_buffer, sizeof(cr_buffer));
	if (out_size < 0) {
		VB2_DEBUG("command %#x, failed to serialize\n", command);
		return TPM_E_WRITE_FAILURE;
	}
	in_size = sizeof(cr_buffer);
	res = vb2ex_tpm_send_recv(cr_buffer, out_size, cr_buffer, &in_size);
	if (res != TPM_SUCCESS) {
		VB2_DEBUG("tpm transaction failed for %#x with error %#x\n",
			  command, res);
		return res;
	}
	if (tpm_unmarshal_response(command, cr_buffer, in_size, response) < 0) {
		VB2_DEBUG("command %#x, failed to parse response\n", command);
		return TPM_E_READ_FAILURE;
	}
	VB2_DEBUG("command %#x, return code %#x\n", command,
		  response->hdr.tpm_code);
	return TPM_SUCCESS;
}
static uint32_t tpm_get_response ( TPM_CC command , void * command_body , struct tpm2_response * response ) { static uint8_t cr_buffer [ TPM_BUFFER_SIZE ] ; int out_size ; uint32_t res ; uint32_t in_size ; out_size = tpm_marshal_command ( command , command_body , cr_buffer , sizeof ( cr_buffer ) ) ; if ( out_size < 0 ) { VB2_DEBUG ( " \n " , command ) ; return TPM_E_WRITE_FAILURE ; } in_size = sizeof ( cr_buffer ) ; res = vb2ex_tpm_send_recv ( cr_buffer , out_size , cr_buffer , & in_size ) ; if ( res != TPM_SUCCESS ) { VB2_DEBUG ( " \n " , command , res ) ; return res ; } if ( tpm_unmarshal_response ( command , cr_buffer , in_size , response ) < 0 ) { VB2_DEBUG ( " \n " , command ) ; return TPM_E_READ_FAILURE ; } VB2_DEBUG ( " \n " , command , response -> hdr . tpm_code ) ; return TPM_SUCCESS ; }
Serializes and sends the command, gets back the response and
 parses it into the provided buffer.
Serializes and sends the command gets back the response and parses it into the provided buffer .
/* Command/response buffer. */