CDC Badge OS
Firmware for the CDC Badge v1.0 hardware security key
Loading...
Searching...
No Matches
ctaphid.h File Reference
#include <cstdint>
#include <cstddef>

Go to the source code of this file.

Classes

struct  cdc::mod_fido2::ctaphid_channel_t

Namespaces

namespace  cdc
namespace  cdc::mod_fido2

Macros

#define CTAPHID_PACKET_SIZE   64
#define CTAPHID_INIT_DATA   57
#define CTAPHID_CONT_DATA   59
#define CTAPHID_MAX_MSG_SIZE   2048
#define CTAPHID_BROADCAST_CID   0xFFFFFFFF
#define CTAPHID_PING   0x01
#define CTAPHID_MSG   0x03
#define CTAPHID_LOCK   0x04
#define CTAPHID_INIT   0x06
#define CTAPHID_WINK   0x08
#define CTAPHID_CBOR   0x10
#define CTAPHID_CANCEL   0x11
#define CTAPHID_KEEPALIVE   0x3B
#define CTAPHID_ERROR   0x3F
#define CTAPHID_ERR_INVALID_CMD   0x01
#define CTAPHID_ERR_INVALID_PAR   0x02
#define CTAPHID_ERR_INVALID_LEN   0x03
#define CTAPHID_ERR_INVALID_SEQ   0x04
#define CTAPHID_ERR_MSG_TIMEOUT   0x05
#define CTAPHID_ERR_CHANNEL_BUSY   0x06
#define CTAPHID_ERR_LOCK_REQUIRED   0x0A
#define CTAPHID_ERR_INVALID_CHANNEL   0x0B
#define CTAPHID_ERR_OTHER   0x7F
#define CTAPHID_VENDOR_FIRST   0x40
#define CTAPHID_VENDOR_LAST   0x7F
#define CTAPHID_STATUS_PROCESSING   0x01
#define CTAPHID_STATUS_UPNEEDED   0x02
#define CTAPHID_CAP_WINK   0x01
#define CTAPHID_CAP_CBOR   0x04

Functions

bool ctaphid_init (void)
 Initializes CTAPHID transport state and synchronization primitives.
bool ctaphid_process_packet (const uint8_t *packet)
 Processes one incoming 64-byte CTAPHID packet.
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.
void ctaphid_send_keepalive (uint32_t cid, uint8_t status)
 Sends a CTAPHID KEEPALIVE packet immediately over USB.
void ctaphid_send_error (uint32_t cid, uint8_t error)
 Queues a CTAPHID ERROR response for the given channel.
void ctaphid_check_timeout (void)
 Expires active channels whose message assembly timeout elapsed.
uint32_t ctaphid_get_current_cid (void)
 Returns the channel identifier of the currently processed request.
bool ctaphid_is_busy (void)
 Reports whether any CTAPHID channel currently has an active transaction.
void ctaphid_get_cmd_counts (uint32_t *cbor_count, uint32_t *msg_count)
 Returns cumulative counters for CTAPHID CBOR and MSG commands.
void ctaphid_reset_cmd_counts (void)
 Resets CTAPHID command counters.

Macro Definition Documentation

◆ CTAPHID_BROADCAST_CID

#define CTAPHID_BROADCAST_CID   0xFFFFFFFF

Definition at line 18 of file ctaphid.h.

Referenced by allocate_cid(), ctaphid_send_error(), and handle_init().

◆ CTAPHID_CANCEL

#define CTAPHID_CANCEL   0x11

Definition at line 27 of file ctaphid.h.

Referenced by process_complete_message().

◆ CTAPHID_CAP_CBOR

#define CTAPHID_CAP_CBOR   0x04

Definition at line 52 of file ctaphid.h.

Referenced by handle_init().

◆ CTAPHID_CAP_WINK

#define CTAPHID_CAP_WINK   0x01

Definition at line 51 of file ctaphid.h.

Referenced by handle_init().

◆ CTAPHID_CBOR

#define CTAPHID_CBOR   0x10

Definition at line 26 of file ctaphid.h.

Referenced by handle_cbor(), prepare_response(), and process_complete_message().

◆ CTAPHID_CONT_DATA

#define CTAPHID_CONT_DATA   59

◆ CTAPHID_ERR_CHANNEL_BUSY

#define CTAPHID_ERR_CHANNEL_BUSY   0x06

Definition at line 37 of file ctaphid.h.

Referenced by ctaphid_process_packet().

◆ CTAPHID_ERR_INVALID_CHANNEL

#define CTAPHID_ERR_INVALID_CHANNEL   0x0B

Definition at line 39 of file ctaphid.h.

Referenced by ctaphid_process_packet(), and handle_cbor().

◆ CTAPHID_ERR_INVALID_CMD

#define CTAPHID_ERR_INVALID_CMD   0x01

Definition at line 32 of file ctaphid.h.

Referenced by process_complete_message().

◆ CTAPHID_ERR_INVALID_LEN

#define CTAPHID_ERR_INVALID_LEN   0x03

Definition at line 34 of file ctaphid.h.

Referenced by ctaphid_process_packet(), handle_cbor(), and handle_init().

◆ CTAPHID_ERR_INVALID_PAR

#define CTAPHID_ERR_INVALID_PAR   0x02

Definition at line 33 of file ctaphid.h.

◆ CTAPHID_ERR_INVALID_SEQ

#define CTAPHID_ERR_INVALID_SEQ   0x04

Definition at line 35 of file ctaphid.h.

Referenced by ctaphid_process_packet().

◆ CTAPHID_ERR_LOCK_REQUIRED

#define CTAPHID_ERR_LOCK_REQUIRED   0x0A

Definition at line 38 of file ctaphid.h.

◆ CTAPHID_ERR_MSG_TIMEOUT

#define CTAPHID_ERR_MSG_TIMEOUT   0x05

Definition at line 36 of file ctaphid.h.

Referenced by ctaphid_check_timeout().

◆ CTAPHID_ERR_OTHER

#define CTAPHID_ERR_OTHER   0x7F

Definition at line 40 of file ctaphid.h.

Referenced by handle_init().

◆ CTAPHID_ERROR

#define CTAPHID_ERROR   0x3F

Definition at line 29 of file ctaphid.h.

Referenced by ctaphid_send_error().

◆ CTAPHID_INIT

#define CTAPHID_INIT   0x06

Definition at line 24 of file ctaphid.h.

Referenced by ctaphid_process_packet(), handle_init(), and process_complete_message().

◆ CTAPHID_INIT_DATA

#define CTAPHID_INIT_DATA   57

◆ CTAPHID_KEEPALIVE

#define CTAPHID_KEEPALIVE   0x3B

Definition at line 28 of file ctaphid.h.

Referenced by ctaphid_send_keepalive().

◆ CTAPHID_LOCK

#define CTAPHID_LOCK   0x04

Definition at line 23 of file ctaphid.h.

◆ CTAPHID_MAX_MSG_SIZE

#define CTAPHID_MAX_MSG_SIZE   2048

Definition at line 16 of file ctaphid.h.

Referenced by ctaphid_process_packet(), and init_channel_slot().

◆ CTAPHID_MSG

#define CTAPHID_MSG   0x03

Definition at line 22 of file ctaphid.h.

Referenced by process_complete_message().

◆ CTAPHID_PACKET_SIZE

◆ CTAPHID_PING

#define CTAPHID_PING   0x01

Definition at line 21 of file ctaphid.h.

Referenced by handle_ping(), and process_complete_message().

◆ CTAPHID_STATUS_PROCESSING

#define CTAPHID_STATUS_PROCESSING   0x01

Definition at line 47 of file ctaphid.h.

Referenced by cdc::mod_fido2::create_credential_and_respond().

◆ CTAPHID_STATUS_UPNEEDED

#define CTAPHID_STATUS_UPNEEDED   0x02

◆ CTAPHID_VENDOR_FIRST

#define CTAPHID_VENDOR_FIRST   0x40

Definition at line 43 of file ctaphid.h.

Referenced by process_complete_message().

◆ CTAPHID_VENDOR_LAST

#define CTAPHID_VENDOR_LAST   0x7F

Definition at line 44 of file ctaphid.h.

Referenced by process_complete_message().

◆ CTAPHID_WINK

#define CTAPHID_WINK   0x08

Definition at line 25 of file ctaphid.h.

Referenced by handle_wink(), and process_complete_message().

Function Documentation

◆ ctaphid_check_timeout()

void ctaphid_check_timeout ( void )

Expires active channels whose message assembly timeout elapsed.

Definition at line 730 of file ctaphid.cpp.

References CTAPHID_ERR_MSG_TIMEOUT, CTAPHID_MAX_CHANNELS, CTAPHID_MSG_TIMEOUT_MS, ctaphid_send_error(), g_ctaphid, LOG_W, and TAG.

Referenced by fido2_task().

◆ ctaphid_get_cmd_counts()

void ctaphid_get_cmd_counts ( uint32_t * cbor_count,
uint32_t * msg_count )

Returns cumulative counters for CTAPHID CBOR and MSG commands.

Parameters
cbor_countOptional destination for CBOR command count.
msg_countOptional destination for MSG/U2F command count.

Definition at line 456 of file ctaphid.cpp.

References g_ctaphid.

◆ ctaphid_get_current_cid()

uint32_t ctaphid_get_current_cid ( void )

Returns the channel identifier of the currently processed request.

Returns
Active request channel identifier.

Definition at line 753 of file ctaphid.cpp.

References g_ctaphid.

Referenced by ctap2_send_keepalive(), cdc::mod_fido2::fido2_ui_user_presence_callback(), and wait_for_user_presence().

◆ ctaphid_get_response_packet()

bool ctaphid_get_response_packet ( uint8_t * packet)

Retrieves the next response HID packet from a per-channel response queue.

Parameters
packetDestination buffer for the response packet.
Returns
true when a packet was written, otherwise false.

Definition at line 634 of file ctaphid.cpp.

References build_cont_packet(), build_init_packet(), cancelled, ctap2_is_cancelled(), CTAPHID_CONT_DATA, CTAPHID_INIT_DATA, g_ctaphid, LOG_W, pick_next_response_channel(), and TAG.

Referenced by fido2_task().

◆ ctaphid_has_response()

bool ctaphid_has_response ( void )

Indicates whether any channel has a response queued for host retrieval.

Returns
true when at least one channel has a pending response, otherwise false.

Definition at line 607 of file ctaphid.cpp.

References CTAPHID_MAX_CHANNELS, and g_ctaphid.

Referenced by fido2_task().

◆ ctaphid_init()

bool ctaphid_init ( void )

Initializes CTAPHID transport state and synchronization primitives.

Returns
true on success, otherwise false.

Definition at line 434 of file ctaphid.cpp.

References g_ctaphid, LOG_E, LOG_I, and TAG.

Referenced by fido2_init().

◆ ctaphid_is_busy()

bool ctaphid_is_busy ( void )

Reports whether any CTAPHID channel currently has an active transaction.

Returns
true when at least one channel is active, otherwise false.

Definition at line 761 of file ctaphid.cpp.

References CTAPHID_MAX_CHANNELS, and g_ctaphid.

◆ ctaphid_process_packet()

bool ctaphid_process_packet ( const uint8_t * packet)

Processes one incoming 64-byte CTAPHID packet.

Parameters
packetHID packet buffer.
Returns
true when the packet is consumed, false on invalid preconditions.

Definition at line 474 of file ctaphid.cpp.

References CTAPHID_CONT_DATA, CTAPHID_DEBUG_PACKETS, CTAPHID_ERR_CHANNEL_BUSY, CTAPHID_ERR_INVALID_CHANNEL, CTAPHID_ERR_INVALID_LEN, CTAPHID_ERR_INVALID_SEQ, CTAPHID_INIT, CTAPHID_INIT_DATA, CTAPHID_MAX_MSG_SIZE, CTAPHID_RATE_LIMIT_MAX_CMDS, CTAPHID_RATE_LIMIT_WINDOW_MS, ctaphid_send_error(), find_channel(), g_ctaphid, LOG_D, LOG_W, process_complete_message(), and TAG.

Referenced by fido2_task().

◆ ctaphid_reset_cmd_counts()

void ctaphid_reset_cmd_counts ( void )

Resets CTAPHID command counters.

Definition at line 464 of file ctaphid.cpp.

References g_ctaphid.

◆ ctaphid_send_error()

void ctaphid_send_error ( uint32_t cid,
uint8_t error )

Queues a CTAPHID ERROR response for the given channel.

Parameters
cidChannel identifier.
errorCTAPHID error code.

Definition at line 703 of file ctaphid.cpp.

References alloc_channel(), CTAPHID_BROADCAST_CID, CTAPHID_ERROR, CTAPHID_MAX_CHANNELS, find_channel(), g_ctaphid, LOG_W, prepare_response_on(), and TAG.

Referenced by ctaphid_check_timeout(), ctaphid_process_packet(), handle_cbor(), handle_init(), and process_complete_message().

◆ ctaphid_send_keepalive()

void ctaphid_send_keepalive ( uint32_t cid,
uint8_t status )

Sends a CTAPHID KEEPALIVE packet immediately over USB.

Parameters
cidChannel identifier.
statusCTAPHID keepalive status byte.

Definition at line 689 of file ctaphid.cpp.

References build_init_packet(), CTAPHID_KEEPALIVE, CTAPHID_PACKET_SIZE, and fido2_usb_write().

Referenced by ctap2_send_keepalive(), cdc::mod_fido2::fido2_ui_user_presence_callback(), and wait_for_user_presence().