11constexpr uint8_t kCardNad = 0x00;
13uint8_t flip(uint8_t bit) {
28 const uint8_t *inf, uint8_t inf_len) {
38 memset(state, 0,
sizeof(*state));
105 if (blk->
inf_len == 1 && blk->
inf !=
nullptr) {
156 if (!state || (resp_len > 0 && !resp))
return false;
157 if (resp_len >
sizeof(state->
resp_buf))
return false;
159 memcpy(state->
resp_buf, resp, resp_len);
168 if (!state || !out)
return 0;
173 if (n > out_cap)
return 0;
184 if (remaining == 0) {
190 const size_t chunk_len = (remaining > chunk_cap) ? chunk_cap : remaining;
191 const bool more = (chunk_len < remaining);
195 kCardNad, state->
ns_send, more,
197 state->
use_crc, out, out_cap, &encoded);
198 if (status !=
T1_OK) {
Decoded block. INF points into the buffer supplied to t1_block_decode.
Card-side T=1 state. Embedded entirely in caller-provided storage.
uint8_t control_block[254+5]
t1_status_t t1_block_encode_r(uint8_t nad, uint8_t nr, t1_r_error_t err, bool use_crc, uint8_t *out, size_t out_cap, size_t *out_len)
Encode an R-block.
t1_s_subtype_t
S-block subtype (PCB bits 5-0).
t1_r_error_t
R-block error indicator (PCB bits 1-0).
t1_status_t t1_block_encode_s(uint8_t nad, t1_s_subtype_t subtype, const uint8_t *inf, uint8_t inf_len, bool use_crc, uint8_t *out, size_t out_cap, size_t *out_len)
Encode an S-block.
t1_status_t
Result of t1_block_decode / t1_block_encode.
t1_status_t t1_block_encode_i(uint8_t nad, uint8_t ns, bool more, const uint8_t *inf, uint8_t inf_len, bool use_crc, uint8_t *out, size_t out_cap, size_t *out_len)
Encode an I-block.
#define T1_DEFAULT_IFSC
Default IFSC at protocol start (ISO 7816-3, before negotiation).
static t1_feed_t handle_sblock(t1_state_t *state, const t1_block_t *blk)
static size_t encode_sblock_response(t1_state_t *state, t1_s_subtype_t subtype, const uint8_t *inf, uint8_t inf_len)
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).
static t1_feed_t handle_iblock(t1_state_t *state, const t1_block_t *blk)
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.
static size_t encode_rblock(t1_state_t *state, uint8_t nr, t1_r_error_t err)
t1_feed_t t1_state_feed(t1_state_t *state, const t1_block_t *blk)
Feed an incoming decoded block to the state machine.
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_rblock(t1_state_t *state, const t1_block_t *blk)
t1_feed_t
Outcome of feeding a block to the state machine.