hsw-nbt 1.2.0
OPTIGA Authenticate NBT Host Library for C
Infineon Error Library

This library offers utilities to create and decode C style ifx_status_t error codes.

In complex library chains it is often difficult to track exactly where errors come from. All Infineon host software libraries therefore encode their errors according to the following schema:

Bits Information
31 Error indicator set to 1 in case of error
30-24 Library identifier (e.g. 0x01 for hsw-apdu library)
23-16 Module identifier (e.g. 0x10 for apdu-response module)
15-8 Function identifier in module (e.g. 0x03 for ifx_apdu_response_decode in hsw-apdu library)
7-0 Function-specific error reason (e.g. 0xFE out of memory). Values between 0xF0 and 0xFF are reserved for reusable error codes defined here.

A return value of 0x811003FE would therefore indicate:

  • Bit 31 is set -> error.
  • Bits 30-24 are set to 0x01 -> hsw-apdu library
  • Bits 23-16 are set to 0x10 -> apdu-response module
  • Bits 15-8 are set to 0x03 -> ifx_apdu_response_decode function
  • Bits 7-0 are set to 0xFE -> Out of memory

Example

if (ifx_error_check(error_code))
{
switch(ifx_error_get_module(error_code))
{
case LIB_APDU:
switch (ifx_error_get_function(error_code))
{
switch (ifx_error_get_reason(error_code))
{
printf("Out of memory during APDU encoding\n");
break;
default:
printf("Unknown error during APDU encoding\n");
break;
}
break;
default:
printf("Error in unknown APDU function\n");
break;
}
break;
default:
printf("Error in unknown module\n");
break;
}
}
APDU (response) en-/decoding utility.
#define LIB_APDU
IFX error encoding library identifier.
Definition ifx-apdu.h:22
#define IFX_APDU_ENCODE
IFX error encoding function identifier for ifx_apdu_encode().
Definition ifx-apdu.h:73
Infineon specific error code creation and parsing.
uint8_t ifx_error_get_reason(ifx_status_t error_code)
Extracts function specific reason from error code.
uint8_t ifx_error_get_module(ifx_status_t error_code)
Extracts module identifier from error code.
bool ifx_error_check(ifx_status_t status_code)
Checks if status code indicates error.
#define IFX_OUT_OF_MEMORY
Function independent error reason for out of memory errors.
Definition ifx-error.h:44
uint32_t ifx_status_t
Custom return code type used by all Infineon host software libraries.
Definition ifx-error.h:91
#define IFX_ERROR(module, function, reason)
Creates IFX encoded error code for given module, function and reason.
Definition ifx-error.h:83
uint8_t ifx_error_get_function(ifx_status_t error_code)
Extracts function identifier from error code.

Reusable Error Reasons

This library offers a set of reusable error reasons similar to standard exceptions in other languages.

The following table gives an overview of these values and a quick description for each.

Value Name Description
0xFF IFX_UNSPECIFIED_ERROR Error without any further information
0xFE IFX_OUT_OF_MEMORY Could not allocate memory
0xFD IFX_ILLEGAL_ARGUMENT Illegal argument given to function call
0xFC IFX_TOO_LITTLE_DATA Too little data available (e.g. in decoding functions)
0xFB IFX_INVALID_STATE Program (currently) in invalid state
0xFA IFX_PROGRAMMING_ERROR Error that should have already been caught by the programmer occurred