CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
t1_state.h
Go to the documentation of this file.
1
17
18#pragma once
20
21#ifdef __cplusplus
22extern "C" {
23#endif
24
26#ifndef T1_MAX_APDU_LEN
27#define T1_MAX_APDU_LEN 4096
28#endif
29
31#ifndef T1_MAX_RESPONSE_LEN
32#define T1_MAX_RESPONSE_LEN 4096
33#endif
34
42
44typedef struct {
45 /* Sequence-number bookkeeping. */
46 uint8_t ns_send;
47 uint8_t ns_expected;
48
49 /* Negotiated frame sizes. */
50 uint16_t ifsc;
51 uint16_t ifsd;
52
53 /* EDC selection (driven by ATR / protocol parameters). */
54 bool use_crc;
55
56 /* Reassembly buffer for incoming chained APDU. */
58 size_t apdu_len;
60
61 /* Outgoing response chunking. */
63 size_t resp_len;
64 size_t resp_sent;
66
67 /* Pending control reply (R / S block) — drained before resp_buf chunks. */
68 uint8_t control_block[T1_INF_MAX + 5]; /* worst case: NAD+PCB+LEN + INF + 2-byte CRC */
71
77void t1_state_init(t1_state_t *state, bool use_crc);
78
87t1_feed_t t1_state_feed(t1_state_t *state, const t1_block_t *block);
88
96bool t1_state_queue_response(t1_state_t *state, const uint8_t *resp, size_t resp_len);
97
105size_t t1_state_next_outbound(t1_state_t *state, uint8_t *out, size_t out_cap);
106
107#ifdef __cplusplus
108}
109#endif
110
Decoded block. INF points into the buffer supplied to t1_block_decode.
Definition t1_block.h:69
Card-side T=1 state. Embedded entirely in caller-provided storage.
Definition t1_state.h:44
size_t control_len
Definition t1_state.h:69
size_t apdu_len
Definition t1_state.h:58
uint16_t ifsc
Definition t1_state.h:50
bool apdu_in_progress
Definition t1_state.h:59
uint8_t apdu_buf[4096]
Definition t1_state.h:57
size_t resp_sent
Definition t1_state.h:64
uint8_t resp_buf[4096]
Definition t1_state.h:62
uint8_t control_block[254+5]
Definition t1_state.h:68
uint8_t ns_send
Definition t1_state.h:46
bool use_crc
Definition t1_state.h:54
size_t resp_len
Definition t1_state.h:63
uint8_t ns_expected
Definition t1_state.h:47
uint16_t ifsd
Definition t1_state.h:51
bool resp_pending
Definition t1_state.h:65
#define T1_INF_MAX
ISO 7816-3 T=1 block-format encoder / decoder.
Definition t1_block.h:34
size_t t1_state_next_outbound(t1_state_t *state, uint8_t *out, size_t out_cap)
Emit the next outbound block (control reply or response chunk).
Definition t1_state.cpp:167
bool t1_state_queue_response(t1_state_t *state, const uint8_t *resp, size_t resp_len)
Register the application's APDU response so the state machine can chunk it into I-blocks.
Definition t1_state.cpp:155
#define T1_MAX_RESPONSE_LEN
Maximum response size that can be chunked back.
Definition t1_state.h:32
#define T1_MAX_APDU_LEN
ISO 7816-3 T=1 transport state machine (card side).
Definition t1_state.h:27
t1_feed_t
Outcome of feeding a block to the state machine.
Definition t1_state.h:36
@ T1_FEED_WAIT_MORE
Definition t1_state.h:39
@ T1_FEED_NEED_OUT
Definition t1_state.h:37
@ T1_FEED_IGNORED
Definition t1_state.h:40
@ T1_FEED_APDU_READY
Definition t1_state.h:38
t1_feed_t t1_state_feed(t1_state_t *state, const t1_block_t *block)
Feed an incoming decoded block to the state machine.
Definition t1_state.cpp:142
void t1_state_init(t1_state_t *state, bool use_crc)
Initialise the state machine. Sets sequence numbers to 0, IFSC/IFSD to defaults.
Definition t1_state.cpp:36