hsw-nbt 1.2.0
OPTIGA Authenticate NBT Host Library for C
ifx-protocol.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2024-2026 Infineon Technologies AG
2// SPDX-License-Identifier: MIT
3
8#ifndef IFX_PROTOCOL_H
9#define IFX_PROTOCOL_H
10
11#include <stddef.h>
12#include <stdint.h>
13
14#include "infineon/ifx-error.h"
15#include "infineon/ifx-logger.h"
16
17#ifdef __cplusplus
18extern "C" {
19#endif
20
24#define LIB_PROTOCOL UINT8_C(0x20)
25
30#define IFX_PROTOCOL_ACTIVATE UINT8_C(0x01)
31
36#define IFX_PROTOCOL_TRANSMIT UINT8_C(0x02)
37
42#define IFX_PROTOCOL_RECEIVE UINT8_C(0x03)
43
47#define IFX_PROTOCOL_RECEIVE_LEN_UNKOWN SIZE_MAX
48
53#define IFX_PROTOCOL_LAYER_INITIALIZE UINT8_C(0x04)
54
59#define IFX_PROTOCOL_TRANSCEIVE UINT8_C(0x05)
60
65#define IFX_PROTOCOL_STACK_INVALID UINT8_C(0x01)
66
67// Forward declaration only
68typedef struct ifx_protocol ifx_protocol_t;
69
84typedef ifx_status_t (*ifx_protocol_activate_callback_t)(ifx_protocol_t *self,
85 uint8_t **response,
86 size_t *response_len);
87
103ifx_status_t ifx_protocol_activate(ifx_protocol_t *self, uint8_t **response,
104 size_t *response_len);
105
119 ifx_protocol_t *self, const uint8_t *data, size_t data_len,
120 uint8_t **response, size_t *response_len);
121
138ifx_status_t ifx_protocol_transceive(ifx_protocol_t *self, const uint8_t *data,
139 size_t data_len, uint8_t **response,
140 size_t *response_len);
141
151typedef ifx_status_t (*ifx_protocol_transmit_callback_t)(ifx_protocol_t *self,
152 const uint8_t *data,
153 size_t data_len);
154
167typedef ifx_status_t (*ifx_protocol_receive_callback_t)(ifx_protocol_t *self,
168 size_t expected_len,
169 uint8_t **response,
170 size_t *response_len);
171
180typedef void (*ifx_protocol_destroy_callback_t)(ifx_protocol_t *self);
181
194void ifx_protocol_destroy(ifx_protocol_t *self);
195
207void ifx_protocol_set_logger(ifx_protocol_t *self, ifx_logger_t *logger);
208
222
323
324#ifdef __cplusplus
325}
326#endif
327
328#endif // IFX_PROTOCOL_H
Infineon specific error code creation and parsing.
uint32_t ifx_status_t
Custom return code type used by all Infineon host software libraries.
Definition ifx-error.h:91
Generic logging API.
void(* ifx_protocol_destroy_callback_t)(ifx_protocol_t *self)
Protocol layer specific destructor.
ifx_status_t(* ifx_protocol_transmit_callback_t)(ifx_protocol_t *self, const uint8_t *data, size_t data_len)
Protocol layer specific transmit function.
ifx_status_t(* ifx_protocol_transceive_callback_t)(ifx_protocol_t *self, const uint8_t *data, size_t data_len, uint8_t **response, size_t *response_len)
Protocol layer specific transceive (send + receive) function.
ifx_status_t(* ifx_protocol_receive_callback_t)(ifx_protocol_t *self, size_t expected_len, uint8_t **response, size_t *response_len)
Protocol layer specific receive function.
ifx_status_t(* ifx_protocol_activate_callback_t)(ifx_protocol_t *self, uint8_t **response, size_t *response_len)
Protocol layer specific secure element activation function.
ifx_status_t ifx_protocol_layer_initialize(ifx_protocol_t *self)
Initializes Protocol object by setting all members to valid values.
Generic protocol struct for building ISO/OSI layer stack.
ifx_protocol_activate_callback_t _activate
Private protocol activation function for negotiating protocol specific parameters.
ifx_logger_t * _logger
Private member for optional Logger.
ifx_protocol_transceive_callback_t _transceive
Private function for sending and receiving data at once.
ifx_protocol_destroy_callback_t _destructor
Private destructor if further cleanup is necessary.
ifx_status_t ifx_protocol_activate(ifx_protocol_t *self, uint8_t **response, size_t *response_len)
Activates secure element and performs protocol negotiation.
ifx_protocol_receive_callback_t _receive
Private function for receiving data.
ifx_status_t ifx_protocol_transceive(ifx_protocol_t *self, const uint8_t *data, size_t data_len, uint8_t **response, size_t *response_len)
Sends data via Protocol and reads back response.
ifx_protocol_transmit_callback_t _transmit
Private function for sending data.
void * _properties
Private member for generic properties as void*.
ifx_protocol_t * _base
Private base layer in ISO/OSI stack.
void ifx_protocol_destroy(ifx_protocol_t *self)
Frees memory associated with Protocol object (but not object itself).
uint64_t _layer_id
Private layer identification to verify that correct protocol layer called member functions.
void ifx_protocol_set_logger(ifx_protocol_t *self, ifx_logger_t *logger)
Sets Logger to be used by Protocol.