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

This file implements optiga comms abstraction layer for IFX I2C Protocol. More...

#include "optiga_comms.h"
#include "optiga_lib_logger.h"
#include "ifx_i2c.h"
#include "pal_os_event.h"
Include dependency graph for optiga_comms_ifx_i2c.c:

Functions

optiga_lib_status_t optiga_comms_open (optiga_comms_t *p_ctx)
 Opens the communication channel with OPTIGA. More...
 
optiga_lib_status_t optiga_comms_reset (optiga_comms_t *p_ctx, uint8_t reset_type)
 Resets the OPTIGA. More...
 
optiga_lib_status_t optiga_comms_transceive (optiga_comms_t *p_ctx, const uint8_t *p_tx_data, uint16_t tx_data_length, uint8_t *p_rx_data, uint16_t *p_rx_data_len)
 Sends and receives the APDU. More...
 
optiga_lib_status_t optiga_comms_close (optiga_comms_t *p_ctx)
 Closes the communication channel with OPTIGA. More...
 

Detailed Description

This file implements optiga comms abstraction layer for IFX I2C Protocol.

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_comms_close()

optiga_lib_status_t optiga_comms_close ( optiga_comms_t p_ctx)

Closes the communication channel with OPTIGA.

Closes the communication with OPTIGA.

  • De-Initializes the OPTIGA and closes the communication channel.
  • Power downs the OPTIGA.
Precondition
  • None
Note
Parameters
[in,out]p_ctxValid instance of optiga_comms_t created using optiga_comms_create
Return values
OPTIGA_COMMS_SUCCESS
OPTIGA_COMMS_ERROR
Here is the call graph for this function:

◆ optiga_comms_open()

optiga_lib_status_t optiga_comms_open ( optiga_comms_t p_ctx)

Opens the communication channel with OPTIGA.

Initializes the communication with OPTIGA

  • Initializes OPTIGA and establishes the communication channel.
  • Initializes the IFX I2C protocol stack and registers the event callbacks.
  • Negotiates the frame size and bit rate with the OPTIGA.
Precondition
  • None
Note
  • The following parameters in ifx_i2c_context_t must be initialized with appropriate values
    • slave address : Address of I2C slave
    • frame_size : Frame size in bytes. Minimum supported value is 16 bytes.
      • It is recommended not to use a value greater than the slave's frame size.
      • The user specified frame size is written to I2C slave's frame size register. The frame size register is read back from I2C slave. This frame value is used by the IFX-I2C protocol even if it is not equal to the user specified value.
    • frequency : Frequency/speed of I2C master in KHz.
      • This must be lowest of the maximum frequency supported by the devices (master/slave) connected on the bus.
      • Initial negotiation starts with a frequency of 100KHz.
      • If the user specified frequency is more than 400 KHz, the I2C slave is configured to operate in "Fm+" mode, otherwise the I2C slave is configured for "SM & Fm" mode.
      • If the user specified frequency negotiation fails, the I2C master frequency remains at 100KHz
    • upper_layer_event_handler : Upper layer event handler. This is invoked when ifx_i2c_open() is asynchronously completed.
    • upper_layer_ctx : Context of upper layer.
    • p_slave_vdd_pin : GPIO pin for VDD. If not set, cold reset is not done.
    • p_slave_reset_pin : GPIO pin for Reset. If not set, warm reset is not done.
    • manage_contex_operation : Used for managing session context and the values must be as defined below. The value of the parameter is not modified by the IFX-I2C protocol stack.
  • The values of registers MAX_SCL_FREQU and DATA_REG_LEN, read from slave are not validated.
  • At present, only single instance of ifx_i2c_context_t is supported.
  • Manage context operations will start in next transceive.
Parameters
[in,out]p_ctxValid instance of optiga_comms_t created using optiga_comms_create
Return values
OPTIGA_COMMS_SUCCESS
OPTIGA_COMMS_ERROR
Here is the call graph for this function:

◆ optiga_comms_reset()

optiga_lib_status_t optiga_comms_reset ( optiga_comms_t p_ctx,
uint8_t  reset_type 
)

Resets the OPTIGA.

Resets the communication channel with OPTIGA.

  • Resets the OPTIGA device.
  • Initializes the IFX I2C protocol stack.
  • Re-Initializes and negotiates the frame size and bit rate with the OPTIGA. The values remain same as that in previous optiga_comms_open().
Precondition
  • Communication channel must be established with OPTIGA.
Note
  • This function clears the saved context.
Parameters
[in,out]p_ctxValid instance of optiga_comms_t created using optiga_comms_create
[in,out]reset_typeType of reset
  • For COLD and WARM reset type: If the GPIO(VDD and/or reset) pins are not configured,
    the API continues without returning error status
Return values
OPTIGA_COMMS_SUCCESS
OPTIGA_COMMS_ERROR
Here is the call graph for this function:

◆ optiga_comms_transceive()

optiga_lib_status_t optiga_comms_transceive ( optiga_comms_t p_ctx,
const uint8_t *  p_tx_data,
uint16_t  tx_data_length,
uint8_t *  p_rx_data,
uint16_t *  p_rx_data_len 
)

Sends and receives the APDU.

Sends a command to OPTIGA and receives a response.

  • Transmit data(Command) to OPTIGA.
  • Receive data(Response) from OPTIGA.
Precondition
  • Communication channel must be established with OPTIGA
Note
  • If Presentation Layer is enabled,
    • Additional buffer size is required to handle encryption and decryption functionality.
  • The total buffer size with the additional presentation layer overhead is explained in the figure below. Please provide the lengths and data buffers as specified below.
    • The transmit and receive data buffers need additional overhead of OPTIGA_COMMS_PRL_OVERHEAD bytes along with Tx/Rx data(payload) size.
    • Provide the command data, starting from the OPTIGA_COMMS_DATA_OFFSET location in the transmit buffer.
    • In the receive buffer, the response (received data) from the OPTIGA will be stored from the OPTIGA_COMMS_DATA_OFFSET location. Read the response from this offset.
    • Provide the length of command data (tx_data_length) with the payload length excluding the additional overhead.
    • Provide the length of response data (p_rx_data_length) in order to copy the response to the buffer provided.
optiga_comms_trancv_buffer.png
optiga_comms_transceive()
  • The actual number of bytes received is stored in p_rx_buffer_len. In case of error,p_rx_buffer_len is set to 0.
  • If the size of p_rx_data is zero or insufficient to copy the response bytes, OPTIGA_COMMS_ERROR_STACK_MEMORY error is returned.
  • If establishing a secure channel fails, OPTIGA_COMMS_ERROR_HANDSHAKE is returned.
  • If OPTIGA_COMMS_ERROR_SESSION is returned, a new session must be established.
  • If presentation layer is enabled and the command data protection is selected, the input data provided will be modified because the data will be encrypted in the same input buffer. Therefore, if required by the user a copy of the input data must be preserved by the caller of this API.
Parameters
[in,out]p_ctxValid instance of optiga_comms_t created using optiga_comms_create
[in]p_tx_dataPointer to the transmit data buffer
[in]tx_data_lengthLength of the transmit data buffer
[in,out]p_rx_dataPointer to the receive data buffer
[in,out]p_rx_data_lenPointer to the length of the receive data buffer
Return values
OPTIGA_COMMS_SUCCESS
OPTIGA_COMMS_ERROR
OPTIGA_COMMS_ERROR_STACK_MEMORY
OPTIGA_COMMS_ERROR_HANDSHAKE
OPTIGA_COMMS_ERROR_SESSION
Here is the call graph for this function: