12#include <freertos/FreeRTOS.h>
13#include <freertos/task.h>
26static const char*
TAG =
"FIDO2";
45 LOG_I(
TAG,
"Processing task started");
71 vTaskDelay(pdMS_TO_TICKS(1));
75 if (inner_retry > 10) {
76 LOG_D(
TAG,
"USB not ready, deferring to outer loop");
79 vTaskDelay(pdMS_TO_TICKS(5));
96 LOG_W(
TAG,
"USB FIDO write failed (outer)");
99 LOG_D(
TAG,
"Sent response packet (outer)");
101 vTaskDelay(pdMS_TO_TICKS(1));
106 if (retry_count > 100) {
107 LOG_W(
TAG,
"USB not ready timeout, aborting response");
110 vTaskDelay(pdMS_TO_TICKS(10));
118 vTaskDelay(pdMS_TO_TICKS(10));
149 LOG_W(
TAG,
"U2F attestation init failed (non-fatal)");
154 xTaskCreate(
fido2_task,
"fido2", 6144,
nullptr,
155 configMAX_PRIORITIES - 2, &
g_fido2.task_handle);
182 if (
g_fido2.user_presence_cb) {
186 LOG_W(
TAG,
"No user presence callback - auto-approving");
195 g_fido2.pin_verified = verified;
197 LOG_I(
TAG,
"PIN verified via ClientPIN - device PIN will be skipped");
224 if (!info)
return false;
230 if (found == index) {
248 uint8_t *out_indices, uint8_t max_indices) {
266 LOG_W(
TAG,
"Factory reset requested");
275 LOG_I(
TAG,
"Factory reset complete");
309 if (ecc_end < ecc_start)
return 0;
310 uint16_t total =
static_cast<uint16_t
>(ecc_end - ecc_start + 1);
312 return (total > used) ?
static_cast<uint8_t
>(total - used) : 0;
CDC Log: logging over TinyUSB CDC and UART.
#define LOG_W(tag, fmt,...)
#define LOG_D(tag, fmt,...)
#define LOG_I(tag, fmt,...)
#define LOG_E(tag, fmt,...)
bool ctap2_init(void)
Initializes CTAP2 runtime state.
bool ctaphid_init(void)
Initializes CTAPHID transport state and synchronization primitives.
void ctaphid_check_timeout(void)
Expires active channels whose message assembly timeout elapsed.
bool ctaphid_has_response(void)
Indicates whether any channel has a response queued for host retrieval.
bool ctaphid_get_response_packet(uint8_t *packet)
Retrieves the next response HID packet from a per-channel response queue.
bool ctaphid_process_packet(const uint8_t *packet)
Processes one incoming 64-byte CTAPHID packet.
uint8_t fido2_find_credentials_by_rp(const uint8_t *rp_id_hash, uint8_t *out_indices, uint8_t max_indices)
Finds credential slots matching RP ID hash.
uint32_t fido2_get_auth_counter(void)
Returns global authentication counter.
void fido2_set_pin_verified(bool verified)
Stores whether PIN verification was completed via ClientPIN.
bool fido2_is_initialized(void)
Indicates whether FIDO2 subsystem is initialized.
fido2_user_presence_cb_t user_presence_cb
bool fido2_get_credential_info(uint8_t index, fido2_credential_info_t *info)
Retrieves credential metadata by visible index.
bool fido2_init(void)
Initializes storage, CTAP layers, and starts the processing task.
void fido2_set_user_presence_callback(fido2_user_presence_cb_t cb)
Sets callback used to request user presence for CTAP operations.
static void fido2_task(void *arg)
Background task that receives CTAPHID packets and sends responses.
bool fido2_delete_credential(uint8_t slot)
Deletes credential in given slot.
uint8_t fido2_get_available_slots(void)
Returns number of free credential slots.
void fido2_increment_auth_counter(void)
Increments global authentication counter.
fido2_user_presence_result_t fido2_request_user_presence(const char *rp_id, fido2_action_t action, const char *user_name)
Requests user presence from host/application callback.
static struct @140260313112121147203143015136154100311031123103 g_fido2
Global FIDO2 runtime state.
bool fido2_factory_reset(void)
Removes all credentials and resets FIDO2 data.
bool fido2_is_pin_verified(void)
Returns current PIN-verified state.
uint8_t fido2_get_credential_count(void)
Returns number of stored credentials.
#define FIDO2_MAX_CREDENTIALS
fido2_user_presence_result_t
fido2_user_presence_result_t(* fido2_user_presence_cb_t)(const char *rp_id, fido2_action_t action, const char *user_name)
char rp_id[FIDO2_RP_ID_MAX_LEN]
char user_name[FIDO2_USER_NAME_MAX_LEN]
uint8_t fido2_storage_ecc_end(void)
Returns configured ECC end slot.
uint8_t fido2_storage_count(void)
Credential lookup operations using in-memory cache only.
uint32_t fido2_storage_counter_get(void)
Returns current global authentication counter.
uint8_t fido2_storage_ecc_start(void)
Returns configured ECC start slot.
bool fido2_storage_get_credential(uint8_t slot, fido2_credential_info_t *info)
Credential create/read/delete operations.
bool fido2_storage_delete_credential(uint8_t slot)
Deletes credential and associated slot data.
bool fido2_storage_counter_increment(void)
Increments and persists global authentication counter.
uint8_t fido2_storage_find_by_rp(const uint8_t *rp_id_hash, uint8_t *out_slots, uint8_t max_slots)
Finds credentials matching RP hash.
bool fido2_storage_slot_used(uint8_t slot)
Checks whether logical slot is occupied.
uint8_t fido2_storage_init(void)
Initialization and cache rebuild routines.
bool fido2_usb_available()
Indicates whether at least one USB HID packet is queued for FIDO2.
bool fido2_usb_ready()
Reports whether USB HID endpoint is ready for transmission.
uint16_t fido2_usb_read(uint8_t *buffer)
Reads one queued CTAPHID packet from USB RX queue.
bool fido2_usb_write(const uint8_t *buffer)
Sends one CTAPHID packet over USB HID.
bool u2f_init_attestation(void)
Initializes attestation key material and builds self-signed attestation certificate.