CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
t1_state.cpp File Reference
#include "mod_gpg/openpgp/t1/t1_state.h"
#include <string.h>

Go to the source code of this file.

Functions

static size_t encode_rblock (t1_state_t *state, uint8_t nr, t1_r_error_t err)
static size_t encode_sblock_response (t1_state_t *state, t1_s_subtype_t subtype, const uint8_t *inf, uint8_t inf_len)
void t1_state_init (t1_state_t *state, bool use_crc)
 Initialise the state machine. Sets sequence numbers to 0, IFSC/IFSD to defaults.
static t1_feed_t handle_iblock (t1_state_t *state, const t1_block_t *blk)
static t1_feed_t handle_rblock (t1_state_t *state, const t1_block_t *blk)
static t1_feed_t handle_sblock (t1_state_t *state, const t1_block_t *blk)
t1_feed_t t1_state_feed (t1_state_t *state, const t1_block_t *blk)
 Feed an incoming decoded block to the state machine.
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.
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).

Function Documentation

◆ encode_rblock()

size_t encode_rblock ( t1_state_t * state,
uint8_t nr,
t1_r_error_t err )
static

◆ encode_sblock_response()

size_t encode_sblock_response ( t1_state_t * state,
t1_s_subtype_t subtype,
const uint8_t * inf,
uint8_t inf_len )
static

◆ handle_iblock()

◆ handle_rblock()

◆ handle_sblock()

◆ t1_state_feed()

t1_feed_t t1_state_feed ( t1_state_t * state,
const t1_block_t * block )

Feed an incoming decoded block to the state machine.

On EDC errors or unexpected sequence numbers the function queues an R-block (control_block). Mainline I-blocks either complete an APDU (T1_FEED_APDU_READY) or ACK chained pieces (T1_FEED_WAIT_MORE). S-blocks are handled and their responses queued.

Definition at line 142 of file t1_state.cpp.

References handle_iblock(), handle_rblock(), handle_sblock(), t1_block_t::kind, T1_BLOCK_I, T1_BLOCK_R, T1_BLOCK_S, and T1_FEED_IGNORED.

◆ t1_state_init()

void t1_state_init ( t1_state_t * state,
bool use_crc )

Initialise the state machine. Sets sequence numbers to 0, IFSC/IFSD to defaults.

Parameters
stateState storage (caller-owned, will be zeroed).
use_crcEDC choice; must match what's negotiated with the reader via ATR.

Definition at line 36 of file t1_state.cpp.

References t1_state_t::ifsc, t1_state_t::ifsd, t1_state_t::ns_expected, t1_state_t::ns_send, T1_DEFAULT_IFSC, and t1_state_t::use_crc.

◆ t1_state_next_outbound()

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).

Parameters
stateState machine.
outOutput buffer.
out_capOutput buffer capacity.
Returns
Number of bytes written. Zero means nothing to send.

Definition at line 167 of file t1_state.cpp.

References t1_state_t::control_block, t1_state_t::control_len, t1_state_t::ifsd, t1_state_t::ns_send, t1_state_t::resp_buf, t1_state_t::resp_len, t1_state_t::resp_pending, t1_state_t::resp_sent, t1_block_encode_i(), T1_DEFAULT_IFSC, T1_OK, and t1_state_t::use_crc.

◆ t1_state_queue_response()

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.

Must only be called after t1_state_feed returned T1_FEED_APDU_READY.

Returns
false if resp_len > T1_MAX_RESPONSE_LEN.

Definition at line 155 of file t1_state.cpp.

References t1_state_t::resp_buf, t1_state_t::resp_len, t1_state_t::resp_pending, and t1_state_t::resp_sent.