mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-08-04 12:56:25 +00:00
feat(core): allow some messages only over specific interfaces
This commit is contained in:
parent
23292f143d
commit
4dbabb52e3
@ -79,6 +79,16 @@ STATIC mp_obj_t mod_trezorio_BLE_write(mp_obj_t self, mp_obj_t msg) {
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_2(mod_trezorio_BLE_write_obj,
|
||||
mod_trezorio_BLE_write);
|
||||
|
||||
/// def iface_type(self) -> int:
|
||||
/// """
|
||||
/// Internal / External distinction
|
||||
/// """
|
||||
STATIC mp_obj_t mod_trezorio_BLE_iface_type(mp_obj_t self) {
|
||||
return MP_OBJ_NEW_SMALL_INT(ble_last_internal ? 1 : 0);
|
||||
}
|
||||
STATIC MP_DEFINE_CONST_FUN_OBJ_1(mod_trezorio_BLE_iface_type_obj,
|
||||
mod_trezorio_BLE_iface_type);
|
||||
|
||||
STATIC const mp_rom_map_elem_t mod_trezorio_BLE_globals_table[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR___name__), MP_ROM_QSTR(MP_QSTR_ble)},
|
||||
{MP_ROM_QSTR(MP_QSTR_update_init),
|
||||
@ -86,6 +96,8 @@ STATIC const mp_rom_map_elem_t mod_trezorio_BLE_globals_table[] = {
|
||||
{MP_ROM_QSTR(MP_QSTR_update_chunk),
|
||||
MP_ROM_PTR(&mod_trezorio_BLE_update_chunk_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_write), MP_ROM_PTR(&mod_trezorio_BLE_write_obj)},
|
||||
{MP_ROM_QSTR(MP_QSTR_iface_type),
|
||||
MP_ROM_PTR(&mod_trezorio_BLE_iface_type_obj)},
|
||||
};
|
||||
STATIC MP_DEFINE_CONST_DICT(mod_trezorio_BLE_globals,
|
||||
mod_trezorio_BLE_globals_table);
|
||||
|
@ -13,7 +13,7 @@ def register(wire_type: int, handler: Handler[Msg]) -> None:
|
||||
workflow_handlers[wire_type] = handler
|
||||
|
||||
|
||||
def _find_message_handler_module(msg_type: int) -> str:
|
||||
def _find_message_handler_module(msg_type: int, iface: WireInterface) -> str:
|
||||
"""Statically find the appropriate workflow handler.
|
||||
|
||||
For now, new messages must be registered by hand in the if-elif manner below.
|
||||
@ -56,12 +56,16 @@ def _find_message_handler_module(msg_type: int) -> str:
|
||||
return "apps.management.sd_protect"
|
||||
|
||||
# BLE
|
||||
if msg_type == MessageType.UploadBLEFirmwareInit:
|
||||
return "apps.management.ble.upload_ble_firmware_init"
|
||||
if msg_type == MessageType.PairingRequest:
|
||||
return "apps.management.ble.pairing_request"
|
||||
if msg_type == MessageType.RepairRequest:
|
||||
return "apps.management.ble.repair_request"
|
||||
if iface.iface_num() != 16:
|
||||
# cannot update over BLE
|
||||
if msg_type == MessageType.UploadBLEFirmwareInit:
|
||||
return "apps.management.ble.upload_ble_firmware_init"
|
||||
|
||||
if iface.iface_num() == 16 and iface.iface_type() == 1:
|
||||
if msg_type == MessageType.PairingRequest:
|
||||
return "apps.management.ble.pairing_request"
|
||||
if msg_type == MessageType.RepairRequest:
|
||||
return "apps.management.ble.repair_request"
|
||||
|
||||
# bitcoin
|
||||
if msg_type == MessageType.AuthorizeCoinJoin:
|
||||
@ -200,7 +204,7 @@ def find_registered_handler(iface: WireInterface, msg_type: int) -> Handler | No
|
||||
return workflow_handlers[msg_type]
|
||||
|
||||
try:
|
||||
modname = _find_message_handler_module(msg_type)
|
||||
modname = _find_message_handler_module(msg_type, iface)
|
||||
handler_name = modname[modname.rfind(".") + 1 :]
|
||||
module = __import__(modname, None, None, (handler_name,), 0)
|
||||
return getattr(module, handler_name)
|
||||
|
@ -8,6 +8,9 @@ class BleInterface:
|
||||
def iface_num(self) -> int:
|
||||
return 16
|
||||
|
||||
def iface_type(self):
|
||||
return ble.iface_type(self)
|
||||
|
||||
def write(self, msg: bytes) -> int:
|
||||
return ble.write(self, msg)
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user