Expand description
Async tasks running on the firmware.
Two tasks live in this module:
usb_run_task: keeps the embassy-usb device stack alive by polling itsrunfuture forever. Spawned at boot.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 theCryptoService.
The dispatch loop also drives the crate::state state machine by
posting events on crate::channels::EVENT_CHANNEL:
Event::PinVerifiedafter a successfulverify_pin.Event::SignRequestedat the start of asignoperation, then blocks oncrate::channels::TOUCH_CONFIRMEDuntil the touch task has confirmed the user pressed the button.Event::TouchTimeoutif the wait runs out.Event::SignCompleteonce the signing call returned.Event::ErrorRaisedon 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
EmergencyResetopcode. - 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
LockCrcMismatchstatus to make triage trivial on the host side. - write_
status π - Build a response frame in
tx_bufand return its length.