mirror of
https://github.com/trezor/trezor-firmware.git
synced 2026-03-10 09:18:29 +01:00
Instead of running 2 separate THP session handling tasks (on USB & BLE interfaces), this PR uses a single task, which will handle both - in order to allow preempting the event loop in case there is an unresponsive channel. `ThpContext` is split into interface-specific class (`InterfaceContext`) and a "global" THP receiver (`ThpContext`). Also, removing `core/tests/test_trezor.wire.thp.py` - to be reimplemented in a following PR. [no changelog]
40 lines
1.3 KiB
Python
40 lines
1.3 KiB
Python
# flake8: noqa: F403,F405
|
|
from common import * # isort:skip
|
|
|
|
if utils.USE_THP:
|
|
from typing import TYPE_CHECKING
|
|
|
|
from mock_wire_interface import MockHID
|
|
from storage import cache_thp
|
|
from trezor.wire import context
|
|
from trezor.wire.thp.channel import Channel
|
|
from trezor.wire.thp.channel_manager import create_new_channel
|
|
from trezor.wire.thp.interface_context import ThpContext
|
|
from trezor.wire.thp.memory_manager import ThpBuffer
|
|
from trezor.wire.thp.session_context import SessionContext
|
|
|
|
if TYPE_CHECKING:
|
|
from trezor.wire import WireInterface
|
|
|
|
def prepare_context() -> None:
|
|
mock_iface = MockHID()
|
|
channel = get_new_channel(mock_iface)
|
|
session_cache = cache_thp.create_or_replace_session(
|
|
channel.channel_cache, session_id=b"\x01"
|
|
)
|
|
context.CURRENT_CONTEXT = SessionContext(channel, session_cache)
|
|
|
|
def get_new_channel(iface: WireInterface) -> Channel:
|
|
channel_cache = create_new_channel(iface)
|
|
thp_ctx = ThpContext(iface)
|
|
(iface_ctx,) = thp_ctx._iface_ctxs
|
|
return Channel(channel_cache, iface_ctx, (ThpBuffer(), ThpBuffer()))
|
|
|
|
|
|
if __debug__:
|
|
# Disable log.debug
|
|
def suppress_debug_log() -> None:
|
|
from trezor import log
|
|
|
|
log._min_level = 1
|