1 /* SPDX-License-Identifier: BSD-2-Clause */ 2 /* 3 * Copyright (c) 2017 - 2018, Intel Corporation 4 * All rights reserved. 5 */ 6 #ifndef TPM2_RESPONSE_H 7 #define TPM2_RESPONSE_H 8 9 #include <glib-object.h> 10 #include <tss2/tss2_tpm2_types.h> 11 12 #include "connection.h" 13 #include "session-entry.h" 14 #include "tpm2-header.h" 15 16 G_BEGIN_DECLS 17 18 typedef struct _Tpm2ResponseClass { 19 GObjectClass parent; 20 } Tpm2ResponseClass; 21 22 typedef struct _Tpm2Response { 23 GObject parent_instance; 24 Connection *connection; 25 guint8 *buffer; 26 size_t buffer_size; 27 TPMA_CC attributes; 28 } Tpm2Response; 29 30 #define TPM_RESPONSE_HEADER_SIZE (sizeof (TPM2_ST) + sizeof (UINT32) + sizeof (TPM2_RC)) 31 32 #define TYPE_TPM2_RESPONSE (tpm2_response_get_type ()) 33 #define TPM2_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_TPM2_RESPONSE, Tpm2Response)) 34 #define TPM2_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_TPM2_RESPONSE, Tpm2ResponseClass)) 35 #define IS_TPM2_RESPONSE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), TYPE_TPM2_RESPONSE)) 36 #define IS_TPM2_RESPONSE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), TYPE_TPM2_RESPONSE)) 37 #define TPM2_RESPONSE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), TYPE_TPM2_RESPONSE, Tpm2ResponseClass)) 38 39 GType tpm2_response_get_type (void); 40 Tpm2Response* tpm2_response_new (Connection *connection, 41 guint8 *buffer, 42 size_t buffer_size, 43 TPMA_CC attributes); 44 Tpm2Response* tpm2_response_new_rc (Connection *connection, 45 TSS2_RC rc); 46 Tpm2Response* tpm2_response_new_context_save (Connection *connection, 47 SessionEntry *entry); 48 Tpm2Response* tpm2_response_new_context_load (Connection *connection, 49 SessionEntry *entry); 50 TPMA_CC tpm2_response_get_attributes (Tpm2Response *response); 51 guint8* tpm2_response_get_buffer (Tpm2Response *response); 52 TSS2_RC tpm2_response_get_code (Tpm2Response *response); 53 TPM2_HANDLE tpm2_response_get_handle (Tpm2Response *response); 54 TPM2_HT tpm2_response_get_handle_type (Tpm2Response *response); 55 gboolean tpm2_response_has_handle (Tpm2Response *response); 56 guint32 tpm2_response_get_size (Tpm2Response *response); 57 TPM2_ST tpm2_response_get_tag (Tpm2Response *response); 58 Connection* tpm2_response_get_connection (Tpm2Response *response); 59 void tpm2_response_set_handle (Tpm2Response *response, 60 TPM2_HANDLE handle); 61 62 G_END_DECLS 63 64 void 65 response_buffer_set_rc(uint8_t buffer[TPM_HEADER_SIZE], 66 TSS2_RC rc); 67 68 #endif /* TPM2_RESPONSE_H */ 69