trezor-firmware
trezor-firmware copied to clipboard
Prepare FW for bluetooth integration
Step one: enable communication over UART/SPI combo. @TychoVrahe has a prototype branch, so let's clean that up and get it to master -- behind some sort of feature flag, probably?
This should be done in a separate session handler (handle_session
mechanism in trezor.wire
).
Resolve any issues with cross-session interaction. Off the top of my head:
- when one session is in a workflow, the other should fast-return
ProcessError(Busy)
or maybeBusyError
as a new code? - related: implement some sort of timeout mechanism so that we're never stuck on waiting for host for too long. we will need to differentiate between waiting for host reply (5 sec timeout seems reasonable?) and waiting for user interaction (timeout = autolock)
- make sure there is no session crosstalk, i.e., cannot continue a workflow from BT when it was started from USB
- make sure the buffers are well configured for this. debuglink should still have its own buffer, but all wirelinks should be able to share the same one? (because only one wirelink at a time is allowed to actually communicate, whereas the other ones will short-circuit, read and discard the full incoming message, and return the error, without needing to write anything to the internal buffer)
- speaking of, this needs to handle this edge case: Trezor is in a USB workflow, there is an incoming Bluetooth message, but only half the message is received. first idea: respond only (and directly) to the opening packet, and just discard any continuation packets that arrive at any time
- (mmilata) consider adding message for killing workflow belonging to another session https://satoshilabs.slack.com/archives/C04HCEL0WQ2/p1698322047730889
This might be an opportunity to move incoming packet processing to Rust (cf. #2156), but the main idea was originally based on being able to block while reading the whole message, which won't work anymore (see above), so i'm unsure.
This is the main branch i use https://github.com/trezor/trezor-firmware/tree/tychovrahe/bluetooth/master
Some of the issues above i already attempted to solve, i.e.:
- when USB workflow is in progress, and message is received via another interface, device response with busy: https://github.com/trezor/trezor-firmware/commit/1288f80c3b364d3e86a133597bd53ccc0bf3c824
- conditional inclusion of BLE: https://github.com/trezor/trezor-firmware/commit/6b911305b26b677a65e187c0d465d5409160345a
Building on https://github.com/trezor/trezor-firmware/pull/2912 which should be merged first.
Some other issues that will need addressing before we can merge this:
- nRF SDK is currently in embed/sdk/nrf52. I think we should make it a submodule. Bonus points: lets make a STM32 SDK/HAL submodule too and use that separately from the one in micropython. We will have same structure for all MCUs and be less dependent on micropython
- this also contains support for STM32 discovery, but the support is not compatible with the rest of codebase, we will need to either revert this or finalize it. I solved some issues with this while working on BLE, but some still remain. (personally i think supporting the discovery is useful for development and would be worth the effort)
- trezorctl bluetooth support needs improvements: currently it always does scanning which causes annoying delays when issuing commands. and it also finds devices that are not reachable which causes malfunctions.
- some trezorctl dependencies used for bluetooth are not actually listed as dependencies
- current impl in trezorctl is linux only