hsw-nbt 1.2.0
OPTIGA Authenticate NBT Host Library for C
ifx-apdu.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_APDU_H
9#define IFX_APDU_H
10
11#include <stddef.h>
12#include <stdint.h>
13#include "infineon/ifx-error.h"
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
22#define LIB_APDU UINT8_C(0x10)
23
28#define IFX_CHECK_SW_OK(response_sw) (response_sw == 0x9000)
29
36#define IFX_APDU_LE_ANY 0x100u
37
44#define IFX_APDU_LE_ANY_EXTENDED 0x10000u
45
49#define IFX_APDU_DECODE 0x01u
50
58#define IFX_LC_MISMATCH 0x01u
59
68#define IFX_EXTENDED_LEN_MISMATCH 0x02u
69
73#define IFX_APDU_ENCODE 0x02u
74
78#define IFX_APDU_RESPONSE_DECODE 0x03u
79
83#define IFX_APDU_RESPONSE_ENCODE 0x04u
84
88typedef struct
89{
93 uint8_t cla;
94
98 uint8_t ins;
99
103 uint8_t p1;
104
108 uint8_t p2;
109
113 size_t lc;
114
118 uint8_t *data;
119
123 size_t le;
124} ifx_apdu_t;
125
129typedef struct
130{
134 uint8_t *data;
135
139 size_t len;
140
144 uint16_t sw;
146
157ifx_status_t ifx_apdu_encode(const ifx_apdu_t *apdu, uint8_t **buffer,
158 size_t *buffer_len);
159
170ifx_status_t ifx_apdu_decode(ifx_apdu_t *apdu, const uint8_t *data,
171 size_t data_len);
172
185
198 const uint8_t *data, size_t data_len);
199
211 uint8_t **buffer, size_t *buffer_len);
212
226
227#ifdef __cplusplus
228}
229#endif
230
231#endif // IFX_APDU_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
Data storage struct for APDU response information.
Definition ifx-apdu.h:130
uint16_t sw
APDU response status word.
Definition ifx-apdu.h:144
size_t len
Number of bytes in ifx_apdu_response_t.data.
Definition ifx-apdu.h:139
ifx_status_t ifx_apdu_response_decode(ifx_apdu_response_t *response, const uint8_t *data, size_t data_len)
Decodes binary data to its member representation in ifx_apdu_response_t object.
void ifx_apdu_response_destroy(ifx_apdu_response_t *response)
Frees memory associated with ifx_apdu_response_t object (but not object itself).
ifx_status_t ifx_apdu_response_encode(const ifx_apdu_response_t *response, uint8_t **buffer, size_t *buffer_len)
Encodes ifx_apdu_response_t to its binary representation.
uint8_t * data
Actual response data (might be NULL ).
Definition ifx-apdu.h:134
Data storage for APDU fields.
Definition ifx-apdu.h:89
uint8_t ins
APDU instruction code.
Definition ifx-apdu.h:98
size_t lc
Length of APDU.data.
Definition ifx-apdu.h:113
uint8_t p2
Second APDU instruction parameter byte.
Definition ifx-apdu.h:108
ifx_status_t ifx_apdu_encode(const ifx_apdu_t *apdu, uint8_t **buffer, size_t *buffer_len)
Encodes APDU to its binary representation.
ifx_status_t ifx_apdu_decode(ifx_apdu_t *apdu, const uint8_t *data, size_t data_len)
Decodes binary data to its member representation in APDU object.
uint8_t cla
APDU instruction class.
Definition ifx-apdu.h:93
uint8_t * data
Actual APDU content data (might be NULL ).
Definition ifx-apdu.h:118
size_t le
Expected number of bytes in response.
Definition ifx-apdu.h:123
void ifx_apdu_destroy(ifx_apdu_t *apdu)
Frees memory associated with APDU object (but not object itself).
uint8_t p1
First APDU instruction parameter byte.
Definition ifx-apdu.h:103