Skip to main content

Module tasks

Module tasks 

Source
Expand description

Async tasks running on the firmware.

Two tasks live in this module:

  1. usb_run_task : keeps the embassy-usb device stack alive by polling its run future forever. Spawned at boot.
  2. dispatch_loop : reads incoming HID reports, dispatches the request to the [CryptoService], and writes the response back. Runs in the main task because it owns the CryptoService.

The dispatch loop also drives the crate::state state machine by posting events on crate::channels::EVENT_CHANNEL:

  • Event::PinVerified after a successful verify_pin.
  • Event::SignRequested at the start of a sign operation, then blocks on crate::channels::TOUCH_CONFIRMED until the touch task has confirmed the user pressed the button.
  • Event::TouchTimeout if the wait runs out.
  • Event::SignComplete once the signing call returned.
  • Event::ErrorRaised on any service error during signing.

Splitting the device run loop from the dispatch loop is the canonical embassy-usb pattern: the stack handles control transfers and resets transparently while the application owns its own request/response cadence.

FunctionsΒ§

dispatch_loop πŸ”’
Main request/response loop: read a HID report, dispatch on the opcode, write the response.
handle_close_session πŸ”’
Synchronous handler: closes the PIN session in the host-side state only, no chip interaction. Always succeeds (idempotent).
handle_emergency_reset πŸ”’
Handler for the EmergencyReset opcode.
handle_genkey πŸ”’
handle_get_pin_status πŸ”’
handle_get_pubkey πŸ”’
handle_info πŸ”’
handle_lock_config_zone πŸ”’
handle_lock_data_zone πŸ”’
handle_lock_slot πŸ”’
handle_one_request πŸ”’
Process one incoming report, write the response into tx_buf, return the number of bytes used.
handle_provision_initial_pin πŸ”’
handle_provision_initial_puk πŸ”’
handle_provision_io_key πŸ”’
handle_provision_slot πŸ”’
handle_read_config_slot πŸ”’
handle_read_config_zone πŸ”’
handle_read_counter πŸ”’
Read one of the chip’s monotonic counters and return its raw value.
handle_read_slot_block πŸ”’
handle_read_slot_word πŸ”’
handle_set_pin πŸ”’
handle_set_puk πŸ”’
handle_sign πŸ”’
handle_unblock_pin πŸ”’
handle_verify_pin πŸ”’
handle_write_config_zone πŸ”’
usb_run_task πŸ”’
Drive the embassy-usb device stack. Spawn this once at boot.
write_error πŸ”’
Map a [CryptoServiceError] into a status + payload and write it.
write_lock_error πŸ”’
Map a service error to a response status, with a lock-specific bias: the chip’s β€œexecution error” during a lock command almost always means the CRC fed by the host did not match the chip’s recomputed CRC. Surface that as the dedicated LockCrcMismatch status to make triage trivial on the host side.
write_status πŸ”’
Build a response frame in tx_buf and return its length.