OPTIGA Trust M  1.1.0
C++ library for Optiga Trust M Chip Security Controller
optiga_util.c File Reference

This file implements the OPTIGA utility module functionalities. More...

Include dependency graph for optiga_util.c:

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_toptiga_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...
 

Detailed Description

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

Author
Infineon Technologies AG

Function Documentation

◆ optiga_cmd_set_shielded_connection_option()

void optiga_cmd_set_shielded_connection_option ( optiga_cmd_t me,
uint8_t  value,
uint8_t  shielded_connection_option 
)

◆ optiga_util_close_application()

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.

  • Initiate close application command to optiga.
  • Perform manage context secure session save operations.
  • De-Initializes the OPTIGA and closes the communication channel.
  • Power downs the OPTIGA after closing the application on optiga.
Precondition
Note


Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]perform_hibernateHibernate the application on OPTIGA. The values must be as defined below.
  • TRUE (1) - Performs application hibernate.
  • FALSE (0) - De-Initializes application context.
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTInput arguments are NULL
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
main_xmc4800_sample.c

Here is the call graph for this function:

◆ optiga_util_create()

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.

  • Stores the callers context and callback handler.
  • Allocate memory for optiga_util_t.
Precondition
  • None
Note
Parameters
[in]optiga_instance_idIndicates the OPTIGA instance to be associated with optiga_util_t. Value should be defined as below
[in]handlerValid pointer to callback function
[in]caller_contextPointer to upper layer context, contains user context data
Return values
optiga_util_tOn success function will return pointer of optiga_util_t
NULLInput arguments are NULL.
Low layer function fails.
OPTIGA_CMD_MAX_REGISTRATIONS number of instances are already created.

Example
main_xmc4800_sample.c

Here is the call graph for this function:

◆ optiga_util_destroy()

optiga_lib_status_t optiga_util_destroy ( optiga_util_t me)

De-Initializes the OPTIGA util instance.

De-Initializes the optiga_util_t instance.

Precondition
  • None
Note
  • User must take care to nullify the instance pointer.
  • Invoke this API only after all the asynchronous process is completed otherwise the behavior of software stack is not defined.
Parameters
[in]meValid instance of optiga_util_t
Return values
OPTIGA_LIB_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete

Example
main_xmc4800_sample.c

Here is the call graph for this function:

◆ optiga_util_generic_event_handler()

_STATIC_H void optiga_util_generic_event_handler ( void *  me,
optiga_lib_status_t  event 
)

◆ optiga_util_open_application()

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.

  • Sets up optiga comms channel.
  • Initiate open application command to optiga.
  • Perform manage context , session restore operations and application restore.
Precondition
Note
  • For protected I2C communication, Refer OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL
  • Error codes from lower layer will be returned as it is.
  • If error in lower layer occurs while restoring OPTIGA application, then initialize a clean OPTIGA application context.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]perform_restoreRestore application on OPTIGA from a previous hibernate state. The values must be as defined below
  • TRUE (1) - Performs application restore.
  • FALSE (0) - Initialize a clean application context.
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
main_xmc4800_sample.c

Here is the call graph for this function:

◆ optiga_util_protected_update()

_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 
)
Here is the call graph for this function:

◆ optiga_util_protected_update_continue()

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.

Precondition
Note
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]fragmentValid pointer to the buffer which contains fragment
  • It must be a valid fragment, otherwise OPTIGA returns an error.
[in]fragment_lengthLength of fragment to be written
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_protected_update.c

Here is the call graph for this function:

◆ optiga_util_protected_update_final()

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.

Precondition
Note
  • The protected I2C communication value set in optiga_util_protected_update_start will be used in this API.
  • Error codes from lower layers will be returned as it is.
  • The strict sequence is terminated in case of an error from lower layer.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]fragmentValid pointer to the buffer which contains the last fragment.
  • If NULL, only strict sequence is released and no APDU is sent to OPTIGA
[in]fragment_lengthLength of fragment to be written
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_protected_update.c

Here is the call graph for this function:

◆ optiga_util_protected_update_start()

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.

  • It marks the beginning of a strict sequence. None of the service layer API will be processed until the strict sequence is terminated.
  • Invokes optiga_cmd_set_object_protected API, based on the input arguments to send manifest to OPTIGA.
Precondition
Note
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]manifest_versionVersion of manifest to be written
[in]manifestValid pointer to the buffer which contains manifest
  • It should be a valid manifest, otherwise OPTIGA returns an error.
[in]manifest_lengthLength of manifest to be written
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_protected_update.c

Here is the call graph for this function:

◆ optiga_util_read_data()

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.

Precondition
Note
  • For protected I2C communication, Refer OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL
  • Error codes from lower layers will be returned as it is.
  • The maximum value of the *length parameter must be the size of buffer buffer. In case the value is greater than buffer size, memory corruption can occur.
  • If any errors occur while retrieving the data, *length parameter is set to 0.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]optiga_oidOID of data object
  • It should be a valid data object, otherwise OPTIGA returns an error.
[in]offsetOffset from within data object
  • It must be valid offset from within data object, otherwise OPTIGA returns an error.
[in,out]bufferValid pointer to the buffer to which data is read
[in,out]lengthValid pointer to the length of data to be read from data object
  • When the data is successfully retrieved, it is updated with actual data length retrieved
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_read_data.c

Here is the call graph for this function:

◆ optiga_util_read_metadata()

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.

Precondition
Note
  • For protected I2C communication, Refer OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL
  • Error codes from lower layers will be returned as it is.
  • The metadata returned will be in TLV format.
  • The maximum value of the *length parameter must be the size of buffer. In case the value is greater than buffer size, memory corruption can occur.
  • If any errors occur while retrieving the data, *length parameter is set to 0.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]optiga_oidOID of data object
  • It should be a valid data object, otherwise OPTIGA returns an error.
[in,out]bufferValid pointer to the buffer to which metadata is read
[in,out]lengthValid pointer to the length of metadata to be read from data object
  • When the metadata is successfully retrieved, it is updated with actual metadata length retrieved
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_read_data.c

Here is the call graph for this function:

◆ optiga_util_reset_protection_level()

_STATIC_H void optiga_util_reset_protection_level ( optiga_util_t me)

◆ optiga_util_set_comms_params()

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.

Precondition
  • None
Note
  • None
Parameters
[in,out]meValid instance of optiga_util_t
[in]configuration_typeConfiguration Type Possible Types are OPTIGA_COMMS_PROTECTION_LEVEL OPTIGA_COMMS_PROTOCOL_VERSION
[in]valueValue part for the respective configuration

Example

◆ optiga_util_update_count()

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.

Precondition
Note
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]optiga_counter_oidOID of counter data object
  • It should be a valid data object, otherwise OPTIGA returns an error.
[in]countCounter value to be updated
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_update_count.c

Here is the call graph for this function:

◆ optiga_util_write_data()

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.

Precondition
Note
  • For protected I2C communication, Refer OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL
  • Error codes from lower layers will be returned as it is.
  • The maximum value of the length parameter is size of buffer. In case the value is greater than buffer size, incorrect values can get written into the data object in OPTIGA.
  • In case the write_type provided is other than erase and write(0x00) or write only(0x40), the function returns OPTIGA_UTIL_ERROR_INVALID_INPUT.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]optiga_oidOID of data object
  • It should be a valid data object, otherwise OPTIGA returns an error.
[in]write_typeType of write must be either OPTIGA_UTIL_WRITE_ONLY or OPTIGA_UTIL_ERASE_AND_WRITE.
[in]offsetOffset from within data object
  • It must be valid offset from within data object, otherwise OPTIGA returns an error.
[in]bufferValid pointer to the buffer with user data to write
[in]lengthLength of data to be written
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_write_data.c

Here is the call graph for this function:

◆ optiga_util_write_data_wrapper()

_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 
)
Here is the call graph for this function:

◆ optiga_util_write_metadata()

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.

Precondition
Note
  • For protected I2C communication, Refer OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL
  • Error codes from lower layers will be returned as it is.
  • The maximum value of the length parameter is size of buffer. In case the value is greater than buffer size, incorrect values can get written into the meta data of the data object in OPTIGA.
  • The metadata to be written must be in TLV format.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]optiga_oidOID of data object
  • It should be a valid data object, otherwise OPTIGA returns an error.
[in]bufferValid pointer to the buffer with metadata to write
[in]lengthLength of metadata to be written
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code.

Example
example_optiga_util_write_data.c

Here is the call graph for this function: