mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-23 15:08:19 +00:00
fix merge issues
This commit is contained in:
parent
28eaa8552d
commit
564965d2d6
@ -29,14 +29,14 @@ workflow.start_default()
|
|||||||
|
|
||||||
|
|
||||||
# initialize the wire codec
|
# initialize the wire codec
|
||||||
wire.setup(usb.iface_wire, WIRE_BUFFER)
|
wire.setup(usb.iface_wire)
|
||||||
|
|
||||||
if utils.USE_BLE:
|
if utils.USE_BLE:
|
||||||
import bluetooth
|
import bluetooth
|
||||||
|
|
||||||
BLE_BUFFER = bytearray(_PROTOBUF_BUFFER_SIZE)
|
BLE_BUFFER = bytearray(_PROTOBUF_BUFFER_SIZE)
|
||||||
|
|
||||||
wire.setup(bluetooth.iface_ble, BLE_BUFFER)
|
wire.setup(bluetooth.iface_ble)
|
||||||
|
|
||||||
|
|
||||||
# start the event loop
|
# start the event loop
|
||||||
|
@ -23,6 +23,7 @@ reads the message's header. When the message type is known the first handler is
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from micropython import const
|
||||||
from typing import TYPE_CHECKING
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from trezor import log, loop, protobuf, utils
|
from trezor import log, loop, protobuf, utils
|
||||||
@ -52,9 +53,9 @@ if TYPE_CHECKING:
|
|||||||
LoadedMessageType = TypeVar("LoadedMessageType", bound=protobuf.MessageType)
|
LoadedMessageType = TypeVar("LoadedMessageType", bound=protobuf.MessageType)
|
||||||
|
|
||||||
|
|
||||||
def setup(iface: WireInterface, buffer: bytearray) -> None:
|
def setup(iface: WireInterface) -> None:
|
||||||
"""Initialize the wire stack on the provided WireInterface."""
|
"""Initialize the wire stack on the provided WireInterface."""
|
||||||
loop.schedule(handle_session(iface, buffer))
|
loop.schedule(handle_session(iface))
|
||||||
|
|
||||||
|
|
||||||
if utils.USE_THP:
|
if utils.USE_THP:
|
||||||
|
@ -1,45 +1,43 @@
|
|||||||
import typing as t
|
import typing as t
|
||||||
|
|
||||||
from .. import messages
|
from .. import messages
|
||||||
from ..tools import session
|
|
||||||
|
|
||||||
if t.TYPE_CHECKING:
|
if t.TYPE_CHECKING:
|
||||||
from ..client import TrezorClient
|
from ..transport.session import Session
|
||||||
|
|
||||||
|
|
||||||
@session
|
|
||||||
def update(
|
def update(
|
||||||
client: "TrezorClient",
|
session: "Session",
|
||||||
datfile: bytes,
|
datfile: bytes,
|
||||||
binfile: bytes,
|
binfile: bytes,
|
||||||
progress_update: t.Callable[[int], t.Any] = lambda _: None,
|
progress_update: t.Callable[[int], t.Any] = lambda _: None,
|
||||||
):
|
):
|
||||||
chunk_len = 4096
|
raise NotImplementedError()
|
||||||
offset = 0
|
# chunk_len = 4096
|
||||||
|
# offset = 0
|
||||||
|
|
||||||
resp = client.call(
|
# resp = session.call(
|
||||||
messages.UploadBLEFirmwareInit(init_data=datfile, binsize=len(binfile))
|
# messages.UploadBLEFirmwareInit(init_data=datfile, binsize=len(binfile))
|
||||||
)
|
# )
|
||||||
|
|
||||||
while isinstance(resp, messages.UploadBLEFirmwareNextChunk):
|
# while isinstance(resp, messages.UploadBLEFirmwareNextChunk):
|
||||||
|
|
||||||
payload = binfile[offset : offset + chunk_len]
|
# payload = binfile[offset : offset + chunk_len]
|
||||||
resp = client.call(messages.UploadBLEFirmwareChunk(data=payload))
|
# resp = session.call(messages.UploadBLEFirmwareChunk(data=payload))
|
||||||
progress_update(chunk_len)
|
# progress_update(chunk_len)
|
||||||
offset += chunk_len
|
# offset += chunk_len
|
||||||
|
|
||||||
if isinstance(resp, messages.Success):
|
# if isinstance(resp, messages.Success):
|
||||||
return
|
# return
|
||||||
else:
|
# else:
|
||||||
raise RuntimeError(f"Unexpected message {resp}")
|
# raise RuntimeError(f"Unexpected message {resp}")
|
||||||
|
|
||||||
|
|
||||||
@session
|
|
||||||
def erase_bonds(
|
def erase_bonds(
|
||||||
client: "TrezorClient",
|
session: "Session",
|
||||||
):
|
):
|
||||||
|
|
||||||
resp = client.call(messages.EraseBonds())
|
resp = session.call(messages.EraseBonds())
|
||||||
|
|
||||||
if isinstance(resp, messages.Success):
|
if isinstance(resp, messages.Success):
|
||||||
return
|
return
|
||||||
@ -47,12 +45,11 @@ def erase_bonds(
|
|||||||
raise RuntimeError(f"Unexpected message {resp}")
|
raise RuntimeError(f"Unexpected message {resp}")
|
||||||
|
|
||||||
|
|
||||||
@session
|
|
||||||
def unpair(
|
def unpair(
|
||||||
client: "TrezorClient",
|
session: "Session",
|
||||||
):
|
):
|
||||||
|
|
||||||
resp = client.call(messages.Unpair())
|
resp = session.call(messages.Unpair())
|
||||||
|
|
||||||
if isinstance(resp, messages.Success):
|
if isinstance(resp, messages.Success):
|
||||||
return
|
return
|
||||||
@ -60,11 +57,10 @@ def unpair(
|
|||||||
raise RuntimeError(f"Unexpected message {resp}")
|
raise RuntimeError(f"Unexpected message {resp}")
|
||||||
|
|
||||||
|
|
||||||
@session
|
|
||||||
def disconnect(
|
def disconnect(
|
||||||
client: "TrezorClient",
|
session: "Session",
|
||||||
):
|
):
|
||||||
resp = client.call(messages.Disconnect())
|
resp = session.call(messages.Disconnect())
|
||||||
|
|
||||||
if isinstance(resp, messages.Success):
|
if isinstance(resp, messages.Success):
|
||||||
return
|
return
|
||||||
|
@ -23,10 +23,10 @@ import click
|
|||||||
|
|
||||||
from .. import ble, exceptions
|
from .. import ble, exceptions
|
||||||
from ..transport.ble import BleProxy
|
from ..transport.ble import BleProxy
|
||||||
from . import with_client
|
from . import with_session
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..client import TrezorClient
|
from ..transport.session import Session
|
||||||
|
|
||||||
|
|
||||||
@click.group(name="ble")
|
@click.group(name="ble")
|
||||||
@ -38,9 +38,9 @@ def cli() -> None:
|
|||||||
# fmt: off
|
# fmt: off
|
||||||
@click.argument("package", type=click.File("rb"))
|
@click.argument("package", type=click.File("rb"))
|
||||||
# fmt: on
|
# fmt: on
|
||||||
@with_client
|
@with_session
|
||||||
def update(
|
def update(
|
||||||
client: "TrezorClient",
|
session: "Session",
|
||||||
package: BinaryIO,
|
package: BinaryIO,
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Upload new BLE firmware to device."""
|
"""Upload new BLE firmware to device."""
|
||||||
@ -60,7 +60,7 @@ def update(
|
|||||||
with click.progressbar(
|
with click.progressbar(
|
||||||
label="Uploading", length=len(binfile), show_eta=False
|
label="Uploading", length=len(binfile), show_eta=False
|
||||||
) as bar:
|
) as bar:
|
||||||
ble.update(client, datfile, binfile, bar.update)
|
ble.update(session, datfile, binfile, bar.update)
|
||||||
click.echo("Update successful.")
|
click.echo("Update successful.")
|
||||||
except exceptions.Cancelled:
|
except exceptions.Cancelled:
|
||||||
click.echo("Update aborted on device.")
|
click.echo("Update aborted on device.")
|
||||||
@ -94,11 +94,10 @@ def connect() -> None:
|
|||||||
click.echo("Connected")
|
click.echo("Connected")
|
||||||
|
|
||||||
|
|
||||||
@with_client
|
def disconnect_device(session: "Session") -> None:
|
||||||
def disconnect_device(client: "TrezorClient") -> None:
|
|
||||||
"""Disconnect from device side."""
|
"""Disconnect from device side."""
|
||||||
try:
|
try:
|
||||||
ble.disconnect(client)
|
ble.disconnect(session)
|
||||||
except exceptions.Cancelled:
|
except exceptions.Cancelled:
|
||||||
click.echo("Disconnect aborted on device.")
|
click.echo("Disconnect aborted on device.")
|
||||||
except exceptions.TrezorException as e:
|
except exceptions.TrezorException as e:
|
||||||
@ -108,10 +107,11 @@ def disconnect_device(client: "TrezorClient") -> None:
|
|||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@click.option("--device", is_flag=True, help="Disconnect from device side.")
|
@click.option("--device", is_flag=True, help="Disconnect from device side.")
|
||||||
def disconnect(device: bool) -> None:
|
@with_session
|
||||||
|
def disconnect(session: "Session", device: bool) -> None:
|
||||||
|
|
||||||
if device:
|
if device:
|
||||||
disconnect_device()
|
disconnect_device(session)
|
||||||
else:
|
else:
|
||||||
ble_proxy = BleProxy()
|
ble_proxy = BleProxy()
|
||||||
devices = [d for d in ble_proxy.lookup() if d.connected]
|
devices = [d for d in ble_proxy.lookup() if d.connected]
|
||||||
@ -123,14 +123,14 @@ def disconnect(device: bool) -> None:
|
|||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@with_client
|
@with_session
|
||||||
def erase_bonds(
|
def erase_bonds(
|
||||||
client: "TrezorClient",
|
session: "Session",
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Erase BLE bonds on device."""
|
"""Erase BLE bonds on device."""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ble.erase_bonds(client)
|
ble.erase_bonds(session)
|
||||||
click.echo("Erase successful.")
|
click.echo("Erase successful.")
|
||||||
except exceptions.Cancelled:
|
except exceptions.Cancelled:
|
||||||
click.echo("Erase aborted on device.")
|
click.echo("Erase aborted on device.")
|
||||||
@ -140,14 +140,14 @@ def erase_bonds(
|
|||||||
|
|
||||||
|
|
||||||
@cli.command()
|
@cli.command()
|
||||||
@with_client
|
@with_session
|
||||||
def unpair(
|
def unpair(
|
||||||
client: "TrezorClient",
|
session: "Session",
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Erase bond of currently connected device. (on device side)"""
|
"""Erase bond of currently connected device. (on device side)"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
ble.unpair(client)
|
ble.unpair(session)
|
||||||
click.echo("Unpair successful.")
|
click.echo("Unpair successful.")
|
||||||
except exceptions.Cancelled:
|
except exceptions.Cancelled:
|
||||||
click.echo("Unapair aborted on device.")
|
click.echo("Unapair aborted on device.")
|
||||||
|
@ -92,6 +92,7 @@ class Transport:
|
|||||||
|
|
||||||
|
|
||||||
def all_transports() -> t.Iterable[t.Type["Transport"]]:
|
def all_transports() -> t.Iterable[t.Type["Transport"]]:
|
||||||
|
from .ble import BleTransport
|
||||||
from .bridge import BridgeTransport
|
from .bridge import BridgeTransport
|
||||||
from .hid import HidTransport
|
from .hid import HidTransport
|
||||||
from .udp import UdpTransport
|
from .udp import UdpTransport
|
||||||
|
@ -20,8 +20,7 @@ from multiprocessing import Pipe, Process
|
|||||||
from multiprocessing.connection import Connection
|
from multiprocessing.connection import Connection
|
||||||
from typing import TYPE_CHECKING, Any, Iterable, List, Optional
|
from typing import TYPE_CHECKING, Any, Iterable, List, Optional
|
||||||
|
|
||||||
from . import TransportException
|
from . import Transport, TransportException
|
||||||
from .protocol import ProtocolBasedTransport, ProtocolV1
|
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from ..models import TrezorModel
|
from ..models import TrezorModel
|
||||||
@ -40,15 +39,16 @@ class Device:
|
|||||||
connected: bool
|
connected: bool
|
||||||
|
|
||||||
|
|
||||||
class BleTransport(ProtocolBasedTransport):
|
class BleTransport(Transport):
|
||||||
ENABLED = True
|
|
||||||
PATH_PREFIX = "ble"
|
PATH_PREFIX = "ble"
|
||||||
|
ENABLED = True
|
||||||
|
CHUNK_SIZE = 244
|
||||||
|
|
||||||
_ble = None
|
_ble = None
|
||||||
|
|
||||||
def __init__(self, mac_addr: str) -> None:
|
def __init__(self, mac_addr: str) -> None:
|
||||||
self.device = mac_addr
|
self.device = mac_addr
|
||||||
super().__init__(protocol=ProtocolV1(self, replen=244))
|
super().__init__()
|
||||||
|
|
||||||
def get_path(self) -> str:
|
def get_path(self) -> str:
|
||||||
return "{}:{}".format(self.PATH_PREFIX, self.device)
|
return "{}:{}".format(self.PATH_PREFIX, self.device)
|
||||||
|
Loading…
Reference in New Issue
Block a user