OPTIGA Trust M  1.1.0
C++ library for Optiga Trust M Chip Security Controller
optiga_util.h
Go to the documentation of this file.
1 
39 #ifndef _OPTIGA_UTIL_H_
40 #define _OPTIGA_UTIL_H_
41 
42 #ifdef __cplusplus
43 extern "C" {
44 #endif
45 
46 #include "optiga_cmd.h"
47 
49 #define OPTIGA_UTIL_WRITE_ONLY (0x00)
50 #define OPTIGA_UTIL_ERASE_AND_WRITE (0x40)
52 
53 
55 #define OPTIGA_UTIL_CONTEXT_NONE (0x00)
56 
58 typedef union optiga_util_params
59 {
60  // set data object params
62  // get data object params
64  // set object protected params
67 
70 {
80  uint16_t instance_state;
81 #ifdef OPTIGA_COMMS_SHIELDED_CONNECTION
82  uint8_t protection_level;
86 #endif //OPTIGA_COMMS_SHIELDED_CONNECTION
87 
88 };
90 typedef struct optiga_util optiga_util_t;
91 
92 #ifdef OPTIGA_COMMS_SHIELDED_CONNECTION
93 
120  uint8_t configuration_type,
121  uint8_t value);
122 #endif
123 
153 LIBRARY_EXPORTS optiga_util_t * optiga_util_create(uint8_t optiga_instance_id,
155  void * caller_context);
156 
181 
214  bool_t perform_restore);
215 
249  bool_t perform_hibernate);
250 
286  uint16_t optiga_oid,
287  uint16_t offset,
288  uint8_t * buffer,
289  uint16_t * length);
290 
325  uint16_t optiga_oid,
326  uint8_t * buffer,
327  uint16_t * length);
328 
364  uint16_t optiga_oid,
365  uint8_t write_type,
366  uint16_t offset,
367  const uint8_t * buffer,
368  uint16_t length);
369 
402  uint16_t optiga_oid,
403  const uint8_t * buffer,
404  uint8_t length);
405 
442  uint8_t manifest_version,
443  const uint8_t * manifest,
444  uint16_t manifest_length);
445 
480  const uint8_t * fragment,
481  uint16_t fragment_length);
482 
515  const uint8_t * fragment,
516  uint16_t fragment_length);
517 
548  uint16_t optiga_counter_oid,
549  uint8_t count);
550 
576 #ifdef OPTIGA_COMMS_SHIELDED_CONNECTION
577 #define OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL(p_instance, protection_level) \
578 { \
579  optiga_util_set_comms_params(p_instance, \
580  OPTIGA_COMMS_PROTECTION_LEVEL, \
581  protection_level); \
582 }
583 #else
584 #define OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL(p_instance, protection_level) {}
585 #endif
586 
603 #ifdef OPTIGA_COMMS_SHIELDED_CONNECTION
604 #define OPTIGA_UTIL_SET_COMMS_PROTOCOL_VERSION(p_instance, version) \
605 { \
606  optiga_util_set_comms_params(p_instance, \
607  OPTIGA_COMMS_PROTOCOL_VERSION, \
608  version);\
609 }
610 #else
611 #define OPTIGA_UTIL_SET_COMMS_PROTOCOL_VERSION(p_instance, version) {}
612 #endif
613 
614 #if defined (OPTIGA_LIB_ENABLE_LOGGING) && defined (OPTIGA_LIB_ENABLE_UTIL_LOGGING)
615 
629 #define OPTIGA_UTIL_LOG_MESSAGE(msg) \
630 {\
631  optiga_lib_print_message(msg,OPTIGA_UTIL_SERVICE,OPTIGA_UTIL_SERVICE_COLOR);\
632 }
633 
649 #define OPTIGA_UTIL_LOG_HEX_DATA(array,array_len) \
650 {\
651  optiga_lib_print_array_hex_format(array,array_len,OPTIGA_UNPROTECTED_DATA_COLOR);\
652 }
653 
668 #define OPTIGA_UTIL_LOG_STATUS(return_value) \
669 { \
670  if (OPTIGA_LIB_SUCCESS != return_value) \
671  { \
672  optiga_lib_print_status(OPTIGA_UTIL_SERVICE,OPTIGA_ERROR_COLOR,return_value); \
673  } \
674  else\
675  { \
676  optiga_lib_print_status(OPTIGA_UTIL_SERVICE,OPTIGA_UTIL_SERVICE_COLOR,return_value); \
677  } \
678 }
679 #else
680 
681 #define OPTIGA_UTIL_LOG_MESSAGE(msg) {}
682 #define OPTIGA_UTIL_LOG_HEX_DATA(array, array_len) {}
683 #define OPTIGA_UTIL_LOG_STATUS(return_value) {}
684 
685 #endif
686 
687 #ifdef __cplusplus
688 }
689 #endif
690 
691 #endif /*_OPTIGA_UTIL_H_ */
692 
union optiga_util_params optiga_util_params_t
union for OPTIGA util parameters
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_read_data(optiga_util_t *me, uint16_t optiga_oid, uint16_t offset, uint8_t *buffer, uint16_t *length)
Reads data from optiga.
Definition: optiga_util.c:311
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_write_metadata(optiga_util_t *me, uint16_t optiga_oid, const uint8_t *buffer, uint8_t length)
Writes metadata for the user provided data object.
Definition: optiga_util.c:444
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_update_count(optiga_util_t *me, uint16_t optiga_counter_oid, uint8_t count)
Increments the counter object by a value specified by user.
Definition: optiga_util.c:618
LIBRARY_EXPORTS optiga_util_t * optiga_util_create(uint8_t optiga_instance_id, callback_handler_t handler, void *caller_context)
Create an instance of optiga_util_t.
Definition: optiga_util.c:153
optiga_set_data_object_params_t optiga_set_data_object_params
Definition: optiga_util.h:61
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_protected_update_start(optiga_util_t *me, uint8_t manifest_version, const uint8_t *manifest, uint16_t manifest_length)
Initiates the start of protected update of object by writing manifest into OPTIGA object.
Definition: optiga_util.c:537
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_protected_update_final(optiga_util_t *me, const uint8_t *fragment, uint16_t fragment_length)
Sends the last fragment to finalize the protected update of data object.
Definition: optiga_util.c:592
uint8_t protection_level
To provide the encryption and decryption need for command and response.
Definition: optiga_util.h:83
optiga_cmd_t * my_cmd
pointer to optiga command instance
Definition: optiga_util.h:74
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_write_data(optiga_util_t *me, uint16_t optiga_oid, uint8_t write_type, uint16_t offset, const uint8_t *buffer, uint16_t length)
Writes data to optiga.
Definition: optiga_util.c:419
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_close_application(optiga_util_t *me, bool_t perform_hibernate)
Closes the application on OPTIGA and closes the communication with optiga.
Definition: optiga_util.c:262
optiga_get_data_object_params_t optiga_get_data_object_params
Definition: optiga_util.h:63
uint8_t protocol_version
To provide the presentation layer protocol version to be used.
Definition: optiga_util.h:85
callback_handler_t handler
Callback handler.
Definition: optiga_util.h:78
uint8_t bool_t
Typedef for a boolean.
Definition: optiga_lib_types.h:91
void * caller_context
Callback context.
Definition: optiga_util.h:76
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_read_metadata(optiga_util_t *me, uint16_t optiga_oid, uint8_t *buffer, uint16_t *length)
Reads metadata of the specified data object from optiga.
Definition: optiga_util.c:366
Specifies the data structure for data to be written to OPTIGA.
Definition: optiga_lib_common.h:274
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_open_application(optiga_util_t *me, bool_t perform_restore)
Initializes the communication with optiga and open the application on OPTIGA.
Definition: optiga_util.c:215
Specifies the data structure for data to be read from OPTIGA.
Definition: optiga_lib_common.h:251
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_destroy(optiga_util_t *me)
De-Initializes the OPTIGA util instance.
Definition: optiga_util.c:191
uint16_t instance_state
To provide the busy/free status of the util instance.
Definition: optiga_util.h:80
optiga_set_object_protected_params_t optiga_set_object_protected_params
Definition: optiga_util.h:65
Command context.
Definition: optiga_cmd.c:331
Specifies the data structure for protected update.
Definition: optiga_lib_common.h:457
void optiga_util_set_comms_params(optiga_util_t *me, uint8_t configuration_type, uint8_t value)
Sets/updates the OPTIGA Comms Shielded connection configuration in the respective (optiga_util) insta...
Definition: optiga_util.c:129
OPTIGA util instance structure.
Definition: optiga_util.h:69
This file defines APIs, types and data structures used in the Command (cmd) module implementation.
uint16_t optiga_lib_status_t
typedef for OPTIGA host library status
Definition: optiga_lib_types.h:97
void(* callback_handler_t)(void *callback_ctx, optiga_lib_status_t event)
typedef for event callback handler
Definition: optiga_lib_types.h:106
optiga_util_params_t params
Details/references (pointers) to the Application Inputs.
Definition: optiga_util.h:72
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_protected_update_continue(optiga_util_t *me, const uint8_t *fragment, uint16_t fragment_length)
Sends fragment(s) of data to be written to OPTIGA.
Definition: optiga_util.c:566
union for OPTIGA util parameters
Definition: optiga_util.h:58