This file implements the OPTIGA utility module functionalities. More...
#include "optiga_util.h"
#include "optiga_lib_logger.h"
#include "optiga_lib_common_internal.h"
#include "pal_os_memory.h"
Functions | |
void | optiga_cmd_set_shielded_connection_option (optiga_cmd_t *me, uint8_t value, uint8_t shielded_connection_option) |
_STATIC_H void | optiga_util_generic_event_handler (void *me, optiga_lib_status_t event) |
_STATIC_H void | optiga_util_reset_protection_level (optiga_util_t *me) |
_STATIC_H optiga_lib_status_t | optiga_util_write_data_wrapper (optiga_util_t *me, uint16_t optiga_oid, uint8_t write_type, uint16_t offset, const uint8_t *p_buffer, uint16_t length) |
void | optiga_util_set_comms_params (optiga_util_t *me, uint8_t parameter_type, uint8_t value) |
Sets/updates the OPTIGA Comms Shielded connection configuration in the respective (optiga_util) instance. More... | |
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. More... | |
optiga_lib_status_t | optiga_util_destroy (optiga_util_t *me) |
De-Initializes the OPTIGA util instance. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
_STATIC_H optiga_lib_status_t | optiga_util_protected_update (optiga_util_t *me, uint8_t manifest_version, const uint8_t *p_buffer, uint16_t buffer_length, optiga_set_obj_protected_tag_t set_obj_tag) |
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. More... | |
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. More... | |
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. More... | |
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. More... | |
This file implements the OPTIGA utility module functionalities.
Copyright (c) 2019 Infineon Technologies AG
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE
\endcopyright
void optiga_cmd_set_shielded_connection_option | ( | optiga_cmd_t * | me, |
uint8_t | value, | ||
uint8_t | shielded_connection_option | ||
) |
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.
Closes the communication with OPTIGA for the given instance.
[in] | me | Valid instance of optiga_util_t created using optiga_util_create. |
[in] | perform_hibernate | Hibernate the application on OPTIGA. The values must be as defined below.
|
OPTIGA_UTIL_SUCCESS | Successful invocation |
OPTIGA_UTIL_ERROR_INVALID_INPUT | Input arguments are NULL |
OPTIGA_UTIL_ERROR_INSTANCE_IN_USE | The previous operation with the same instance is not complete |
OPTIGA_DEVICE_ERROR | Command execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual) |
Example
main_xmc4800_sample.c
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.
Create an instance of optiga_util_t.
[in] | optiga_instance_id | Indicates the OPTIGA instance to be associated with optiga_util_t. Value should be defined as below
|
[in] | handler | Valid pointer to callback function |
[in] | caller_context | Pointer to upper layer context, contains user context data |
optiga_util_t | On success function will return pointer of optiga_util_t |
NULL | Input arguments are NULL. Low layer function fails. OPTIGA_CMD_MAX_REGISTRATIONS number of instances are already created. |
Example
main_xmc4800_sample.c
optiga_lib_status_t optiga_util_destroy | ( | optiga_util_t * | me | ) |
De-Initializes the OPTIGA util instance.
De-Initializes the optiga_util_t instance.
[in] | me | Valid instance of optiga_util_t |
OPTIGA_LIB_SUCCESS | Successful invocation |
OPTIGA_UTIL_ERROR_INVALID_INPUT | Wrong Input arguments provided |
OPTIGA_UTIL_ERROR_INSTANCE_IN_USE | The previous operation with the same instance is not complete |
Example
main_xmc4800_sample.c
_STATIC_H void optiga_util_generic_event_handler | ( | void * | me, |
optiga_lib_status_t | event | ||
) |
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.
Initializes the communication with OPTIGA for the given instance.
[in] | me | Valid instance of optiga_util_t created using optiga_util_create. |
[in] | perform_restore | Restore application on OPTIGA from a previous hibernate state. The values must be as defined below
|
OPTIGA_UTIL_SUCCESS | Successful invocation |
OPTIGA_UTIL_ERROR_INVALID_INPUT | Wrong Input arguments provided |
OPTIGA_UTIL_ERROR_INSTANCE_IN_USE | The previous operation with the same instance is not complete |
OPTIGA_DEVICE_ERROR | Command execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual) |
Example
main_xmc4800_sample.c
_STATIC_H optiga_lib_status_t optiga_util_protected_update | ( | optiga_util_t * | me, |
uint8_t | manifest_version, | ||
const uint8_t * | p_buffer, | ||
uint16_t | buffer_length, | ||
optiga_set_obj_protected_tag_t | set_obj_tag | ||
) |
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.
Sends a fragment of data to be written to OPTIGA.
[in] | me | Valid instance of optiga_util_t created using optiga_util_create. |
[in] | fragment | Valid pointer to the buffer which contains fragment
|
[in] | fragment_length | Length of fragment to be written |
OPTIGA_UTIL_SUCCESS | Successful invocation |
OPTIGA_UTIL_ERROR_INVALID_INPUT | Wrong Input arguments provided |
OPTIGA_UTIL_ERROR_INSTANCE_IN_USE | The previous operation with the same instance is not complete |
OPTIGA_DEVICE_ERROR | Command execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual) |
Example
example_optiga_util_protected_update.c
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.
Sends the last fragment to finalize the protected update of data object.
[in] | me | Valid instance of optiga_util_t created using optiga_util_create. |
[in] | fragment | Valid pointer to the buffer which contains the last fragment.
|
[in] | fragment_length | Length of fragment to be written |
OPTIGA_UTIL_SUCCESS | Successful invocation |
OPTIGA_UTIL_ERROR_INVALID_INPUT | Wrong Input arguments provided |
OPTIGA_UTIL_ERROR_INSTANCE_IN_USE | The previous operation with the same instance is not complete |
OPTIGA_DEVICE_ERROR | Command execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual) |
Example
example_optiga_util_protected_update.c
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.
Initiates the start of protected update of object.
[in] | me | Valid instance of optiga_util_t created using optiga_util_create. |
[in] | manifest_version | Version of manifest to be written |
[in] | manifest | Valid pointer to the buffer which contains manifest
|
[in] | manifest_length | Length of manifest to be written |
OPTIGA_UTIL_SUCCESS | Successful invocation |
OPTIGA_UTIL_ERROR_INVALID_INPUT | Wrong Input arguments provided |
OPTIGA_UTIL_ERROR_INSTANCE_IN_USE | The previous operation with the same instance is not complete |
OPTIGA_DEVICE_ERROR | Command execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual) |
Example
example_optiga_util_protected_update.c
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.
Retrieves the requested data that is stored in the user provided data object.
[in] | me | Valid instance of optiga_util_t created using optiga_util_create. |
[in] | optiga_oid | OID of data object
|
[in] | offset | Offset from within data object
|
[in,out] | buffer | Valid pointer to the buffer to which data is read |
[in,out] | length | Valid pointer to the length of data to be read from data object
|
OPTIGA_UTIL_SUCCESS | Successful invocation |
OPTIGA_UTIL_ERROR_INVALID_INPUT | Wrong Input arguments provided |
OPTIGA_UTIL_ERROR_INSTANCE_IN_USE | The previous operation with the same instance is not complete |
OPTIGA_DEVICE_ERROR | Command execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual) |
Example
example_optiga_util_read_data.c
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.
Reads the metadata of the user provided data object.
[in] | me | Valid instance of optiga_util_t created using optiga_util_create. |
[in] | optiga_oid | OID of data object
|
[in,out] | buffer | Valid pointer to the buffer to which metadata is read |
[in,out] | length | Valid pointer to the length of metadata to be read from data object
|
OPTIGA_UTIL_SUCCESS | Successful invocation |
OPTIGA_UTIL_ERROR_INVALID_INPUT | Wrong Input arguments provided |
OPTIGA_UTIL_ERROR_INSTANCE_IN_USE | The previous operation with the same instance is not complete |
OPTIGA_DEVICE_ERROR | Command execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual) |
Example
example_optiga_util_read_data.c
_STATIC_H void optiga_util_reset_protection_level | ( | optiga_util_t * | me | ) |
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) instance.
Sets/updates the OPTIGA Comms Shielded connection configuration in the respective (optiga_util) instance.
[in,out] | me | Valid instance of optiga_util_t |
[in] | configuration_type | Configuration Type Possible Types are OPTIGA_COMMS_PROTECTION_LEVEL OPTIGA_COMMS_PROTOCOL_VERSION |
[in] | value | Value part for the respective configuration |
Example
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.
Increments the counter object by a value specified by user.
[in] | me | Valid instance of optiga_util_t created using optiga_util_create. |
[in] | optiga_counter_oid | OID of counter data object
|
[in] | count | Counter value to be updated |
OPTIGA_UTIL_SUCCESS | Successful invocation |
OPTIGA_UTIL_ERROR_INVALID_INPUT | Wrong Input arguments provided |
OPTIGA_UTIL_ERROR_INSTANCE_IN_USE | The previous operation with the same instance is not complete |
OPTIGA_DEVICE_ERROR | Command execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual) |
Example
example_optiga_util_update_count.c
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.
Writes the data provided by the user into the specified data object.
[in] | me | Valid instance of optiga_util_t created using optiga_util_create. |
[in] | optiga_oid | OID of data object
|
[in] | write_type | Type of write must be either OPTIGA_UTIL_WRITE_ONLY or OPTIGA_UTIL_ERASE_AND_WRITE. |
[in] | offset | Offset from within data object
|
[in] | buffer | Valid pointer to the buffer with user data to write |
[in] | length | Length of data to be written |
OPTIGA_UTIL_SUCCESS | Successful invocation |
OPTIGA_UTIL_ERROR_INVALID_INPUT | Wrong Input arguments provided |
OPTIGA_UTIL_ERROR_INSTANCE_IN_USE | The previous operation with the same instance is not complete |
OPTIGA_DEVICE_ERROR | Command execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual) |
Example
example_optiga_util_write_data.c
_STATIC_H optiga_lib_status_t optiga_util_write_data_wrapper | ( | optiga_util_t * | me, |
uint16_t | optiga_oid, | ||
uint8_t | write_type, | ||
uint16_t | offset, | ||
const uint8_t * | p_buffer, | ||
uint16_t | length | ||
) |
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.
Writes metadata for the specified data object.
[in] | me | Valid instance of optiga_util_t created using optiga_util_create. |
[in] | optiga_oid | OID of data object
|
[in] | buffer | Valid pointer to the buffer with metadata to write |
[in] | length | Length of metadata to be written |
OPTIGA_UTIL_SUCCESS | Successful invocation |
OPTIGA_UTIL_ERROR_INVALID_INPUT | Wrong Input arguments provided |
OPTIGA_UTIL_ERROR_INSTANCE_IN_USE | The previous operation with the same instance is not complete |
OPTIGA_DEVICE_ERROR | Command execution failure in OPTIGA and the LSB indicates the error code. |
Example
example_optiga_util_write_data.c