mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-03 12:28:13 +00:00
feat(core): BLE pairing flow
This commit is contained in:
parent
a533bf898c
commit
4f2efd8dc7
@ -1,4 +1,5 @@
|
|||||||
import storage.device
|
import storage.device
|
||||||
|
import trezorble as ble
|
||||||
import trezorui_api
|
import trezorui_api
|
||||||
from trezor import utils
|
from trezor import utils
|
||||||
from trezor.ui.layouts import raise_if_not_confirmed
|
from trezor.ui.layouts import raise_if_not_confirmed
|
||||||
@ -8,7 +9,7 @@ async def handle_device_menu() -> None:
|
|||||||
# MOCK DATA
|
# MOCK DATA
|
||||||
failed_backup = True
|
failed_backup = True
|
||||||
battery_percentage = 22
|
battery_percentage = 22
|
||||||
paired_devices = ["Trezor Suite"]
|
paired_devices = ["Trezor Suite"] if ble.is_connected() else []
|
||||||
# ###
|
# ###
|
||||||
firmware_version = ".".join(map(str, utils.VERSION))
|
firmware_version = ".".join(map(str, utils.VERSION))
|
||||||
device_name = storage.device.get_label() or "Trezor"
|
device_name = storage.device.get_label() or "Trezor"
|
||||||
@ -27,5 +28,11 @@ async def handle_device_menu() -> None:
|
|||||||
from apps.management.ble.pair_new_device import pair_new_device
|
from apps.management.ble.pair_new_device import pair_new_device
|
||||||
|
|
||||||
await pair_new_device()
|
await pair_new_device()
|
||||||
|
elif menu_result == "DeviceDisconnect":
|
||||||
|
from trezor.messages import BleUnpair
|
||||||
|
|
||||||
|
from apps.management.ble.unpair import unpair
|
||||||
|
|
||||||
|
await unpair(BleUnpair(all=False))
|
||||||
else:
|
else:
|
||||||
raise RuntimeError(f"Unknown menu {menu_result}")
|
raise RuntimeError(f"Unknown menu {menu_result}")
|
||||||
|
@ -1,17 +1,39 @@
|
|||||||
|
import trezorble as ble
|
||||||
import trezorui_api
|
import trezorui_api
|
||||||
from trezor.ui.layouts import interact
|
from storage import device as storage_device
|
||||||
|
from trezor.ui.layouts import CONFIRMED, raise_if_not_confirmed
|
||||||
|
from trezor.wire import ActionCancelled
|
||||||
|
|
||||||
|
|
||||||
|
def _end_pairing() -> None:
|
||||||
|
if ble.peer_count() > 0:
|
||||||
|
ble.start_advertising(True, storage_device.get_label())
|
||||||
|
else:
|
||||||
|
ble.stop_advertising()
|
||||||
|
|
||||||
|
|
||||||
async def pair_new_device() -> None:
|
async def pair_new_device() -> None:
|
||||||
label = "Trezor T3W1"
|
label = storage_device.get_label() or "Trezor T3W1"
|
||||||
await interact(
|
ble.start_advertising(False, label)
|
||||||
trezorui_api.show_pairing_device_name(device_name=label),
|
try:
|
||||||
|
code = await raise_if_not_confirmed(
|
||||||
|
trezorui_api.show_pairing_device_name(
|
||||||
|
device_name=label,
|
||||||
|
),
|
||||||
None,
|
None,
|
||||||
raise_on_cancel=None, # for UI testing
|
|
||||||
)
|
)
|
||||||
|
if not isinstance(code, int):
|
||||||
|
raise ActionCancelled
|
||||||
|
|
||||||
code = 12345
|
result = await raise_if_not_confirmed(
|
||||||
await interact(
|
trezorui_api.show_pairing_code(
|
||||||
trezorui_api.show_pairing_code(code=f"{code:0>6}"),
|
code=f"{code:0>6}",
|
||||||
|
),
|
||||||
None,
|
None,
|
||||||
)
|
)
|
||||||
|
if result is CONFIRMED:
|
||||||
|
ble.allow_pairing(code)
|
||||||
|
else:
|
||||||
|
ble.reject_pairing()
|
||||||
|
finally:
|
||||||
|
_end_pairing()
|
||||||
|
Loading…
Reference in New Issue
Block a user