mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-03-05 01:36:44 +00:00

Squashed commit of the following: commit 84d3486f59bda063f06521c8b695ea4b07781ec6 Author: matejcik <ja@matejcik.cz> Date: Fri May 17 14:17:15 2019 +0200 mocks: complete commit d538133a6d0fb4af06c7c81f80b8675869fb5908 Author: matejcik <ja@matejcik.cz> Date: Fri May 17 14:12:26 2019 +0200 mocks part 3 commit 9f0b868d41dafaf487df6fc844db7f3368eabe1b Author: matejcik <ja@matejcik.cz> Date: Fri May 17 14:09:20 2019 +0200 mocks: update generated mocks commit 5d80c18a7824ed16fc11cde4cdb8ebca7ed33400 Author: matejcik <ja@matejcik.cz> Date: Thu May 16 15:49:40 2019 +0200 mocks wip 2 commit 4b576eb796136a61eb88cb0d281fa4e21eadada8 Author: matejcik <ja@matejcik.cz> Date: Tue May 7 17:02:51 2019 +0200 WIP mocks part 1 commit cf3f0d4471ab74b478d2970b0bb178feae7c86a3 Author: matejcik <ja@matejcik.cz> Date: Fri May 3 17:07:53 2019 +0200 core: add package to secp256k1_zkp for mocking commit 8a12f26c8c0d99363c8df96012426abbbb3ff6cb Author: matejcik <ja@matejcik.cz> Date: Fri May 3 17:04:05 2019 +0200 core: blackify extmod docstring quotes commit b6f239676dde8b60b001fcae4e5de80a71dbacf2 Author: matejcik <ja@matejcik.cz> Date: Fri May 3 16:52:27 2019 +0200 core: make build_mocks directory agnostic mocks: detect bad packages mocks: revert noqa in favor of setup.cfg mocks: fix broken comment formatting
224 lines
4.9 KiB
Python
224 lines
4.9 KiB
Python
from typing import *
|
|
|
|
|
|
# extmod/modtrezorio/modtrezorio-flash.h
|
|
class FlashOTP:
|
|
"""
|
|
"""
|
|
|
|
def __init__(self) -> None:
|
|
"""
|
|
"""
|
|
|
|
def write(self, block: int, offset: int, data: bytes) -> None:
|
|
"""
|
|
Writes data to OTP flash
|
|
"""
|
|
|
|
def read(self, block: int, offset: int, data: bytearray) -> None:
|
|
"""
|
|
Reads data from OTP flash
|
|
"""
|
|
|
|
def lock(self, block: int) -> None:
|
|
"""
|
|
Lock OTP flash block
|
|
"""
|
|
|
|
def is_locked(self, block: int) -> bool:
|
|
"""
|
|
Is OTP flash block locked?
|
|
"""
|
|
|
|
|
|
# extmod/modtrezorio/modtrezorio-hid.h
|
|
class HID:
|
|
"""
|
|
USB HID interface configuration.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
iface_num: int,
|
|
ep_in: int,
|
|
ep_out: int,
|
|
report_desc: bytes,
|
|
subclass: int = 0,
|
|
protocol: int = 0,
|
|
polling_interval: int = 1,
|
|
max_packet_len: int = 64,
|
|
) -> None:
|
|
"""
|
|
"""
|
|
|
|
def iface_num(self) -> int:
|
|
"""
|
|
Returns the configured number of this interface.
|
|
"""
|
|
|
|
def write(self, msg: bytes) -> int:
|
|
"""
|
|
Sends message using USB HID (device) or UDP (emulator).
|
|
"""
|
|
|
|
|
|
# extmod/modtrezorio/modtrezorio-poll.h
|
|
def poll(ifaces: Iterable[int], list_ref: List, timeout_us: int) -> bool:
|
|
"""
|
|
Wait until one of `ifaces` is ready to read or write (using masks
|
|
`list_ref`:
|
|
`list_ref[0]` - the interface number, including the mask
|
|
`list_ref[1]` - for touch event, tuple of (event_type, x_position,
|
|
y_position)
|
|
- for USB read event, received bytes
|
|
If timeout occurs, False is returned, True otherwise.
|
|
"""
|
|
|
|
|
|
# extmod/modtrezorio/modtrezorio-sbu.h
|
|
class SBU:
|
|
"""
|
|
"""
|
|
|
|
def __init__(self) -> None:
|
|
"""
|
|
"""
|
|
|
|
def set(self, sbu1: bool, sbu2: bool) -> None:
|
|
"""
|
|
Sets SBU wires to sbu1 and sbu2 values respectively
|
|
"""
|
|
|
|
|
|
# extmod/modtrezorio/modtrezorio-sdcard.h
|
|
class SDCard:
|
|
"""
|
|
"""
|
|
|
|
def __init__(self) -> None:
|
|
"""
|
|
"""
|
|
|
|
def present(self) -> bool:
|
|
"""
|
|
Returns True if SD card is detected, False otherwise.
|
|
"""
|
|
|
|
def power(self, state: bool) -> bool:
|
|
"""
|
|
Power on or power off the SD card interface.
|
|
Returns True if in case of success, False otherwise.
|
|
"""
|
|
|
|
def capacity(self) -> int:
|
|
"""
|
|
Returns capacity of the SD card in bytes, or zero if not present.
|
|
"""
|
|
|
|
def read(self, block_num: int, buf: bytearray) -> bool:
|
|
"""
|
|
Reads blocks starting with block_num from the SD card into buf.
|
|
Number of bytes read is length of buf rounded down to multiply of
|
|
SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise.
|
|
"""
|
|
|
|
def write(self, block_num: int, buf: bytes) -> bool:
|
|
"""
|
|
Writes blocks starting with block_num from buf to the SD card.
|
|
Number of bytes written is length of buf rounded down to multiply of
|
|
SDCARD_BLOCK_SIZE. Returns True if in case of success, False otherwise.
|
|
"""
|
|
|
|
|
|
# extmod/modtrezorio/modtrezorio-usb.h
|
|
class USB:
|
|
"""
|
|
USB device configuration.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
vendor_id: int,
|
|
product_id: int,
|
|
release_num: int,
|
|
device_class: int = 0,
|
|
device_subclass: int = 0,
|
|
device_protocol: int = 0,
|
|
manufacturer: str = "",
|
|
product: str = "",
|
|
serial_number: str = "",
|
|
interface: str = "",
|
|
usb21_enabled: bool = True,
|
|
usb21_landing: bool = True,
|
|
) -> None:
|
|
"""
|
|
"""
|
|
|
|
def add(self, iface: Union[HID, VCP, WebUSB]) -> None:
|
|
"""
|
|
Registers passed interface into the USB stack.
|
|
"""
|
|
|
|
def open(self) -> None:
|
|
"""
|
|
Initializes the USB stack.
|
|
"""
|
|
|
|
def close(self) -> None:
|
|
"""
|
|
Cleans up the USB stack.
|
|
"""
|
|
|
|
|
|
# extmod/modtrezorio/modtrezorio-vcp.h
|
|
class VCP:
|
|
"""
|
|
USB VCP interface configuration.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
iface_num: int,
|
|
data_iface_num: int,
|
|
ep_in: int,
|
|
ep_out: int,
|
|
ep_cmd: int,
|
|
) -> None:
|
|
"""
|
|
"""
|
|
|
|
def iface_num(self) -> int:
|
|
"""
|
|
Returns the configured number of this interface.
|
|
"""
|
|
|
|
|
|
# extmod/modtrezorio/modtrezorio-webusb.h
|
|
class WebUSB:
|
|
"""
|
|
USB WebUSB interface configuration.
|
|
"""
|
|
|
|
def __init__(
|
|
self,
|
|
iface_num: int,
|
|
ep_in: int,
|
|
ep_out: int,
|
|
subclass: int = 0,
|
|
protocol: int = 0,
|
|
polling_interval: int = 1,
|
|
max_packet_len: int = 64,
|
|
) -> None:
|
|
"""
|
|
"""
|
|
|
|
def iface_num(self) -> int:
|
|
"""
|
|
Returns the configured number of this interface.
|
|
"""
|
|
|
|
def write(self, msg: bytes) -> int:
|
|
"""
|
|
Sends message using USB WebUSB (device) or UDP (emulator).
|
|
"""
|