mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-07-03 21:32:33 +00:00
feat(core): re-pairing request/dialog
This commit is contained in:
parent
cfd5cdadb8
commit
5808a6de20
@ -57,3 +57,14 @@ message PairingRequest {
|
||||
message AuthKey {
|
||||
required bytes key = 1;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Request: initiates repairing request
|
||||
* @start
|
||||
* @next Success
|
||||
* @next Failure
|
||||
*/
|
||||
message RepairRequest {
|
||||
}
|
||||
|
||||
|
@ -142,6 +142,7 @@ enum MessageType {
|
||||
MessageType_UploadBLEFirmwareChunk = 8002 [(bitcoin_only) = true, (wire_in) = true];
|
||||
MessageType_PairingRequest = 8003 [(bitcoin_only) = true, (wire_in) = true];
|
||||
MessageType_AuthKey = 8004 [(bitcoin_only) = true, (wire_out) = true];
|
||||
MessageType_RepairRequest = 8005 [(bitcoin_only) = true, (wire_in) = true];
|
||||
|
||||
// Bitcoin
|
||||
MessageType_GetPublicKey = 11 [(bitcoin_only) = true, (wire_in) = true];
|
||||
|
@ -451,6 +451,20 @@ static void on_adv_evt(ble_adv_evt_t ble_adv_evt) {
|
||||
}
|
||||
}
|
||||
|
||||
static void int_comm_send(uint8_t *tx_data, uint16_t len) {
|
||||
uint32_t err_code;
|
||||
|
||||
for (uint32_t i = 0; i < len; i++) {
|
||||
do {
|
||||
err_code = app_uart_put(tx_data[i]);
|
||||
if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY)) {
|
||||
NRF_LOG_ERROR("Failed sending data to STM. Error 0x%x. ", err_code);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
} while (err_code == NRF_ERROR_BUSY);
|
||||
}
|
||||
}
|
||||
|
||||
/**@brief Function for handling BLE events.
|
||||
*
|
||||
* @param[in] p_ble_evt Bluetooth stack event.
|
||||
@ -497,21 +511,19 @@ static void ble_evt_handler(ble_evt_t const *p_ble_evt, void *p_context) {
|
||||
0x55, // EOM
|
||||
};
|
||||
|
||||
for (uint32_t i = 0; i < sizeof(tx_data); i++) {
|
||||
do {
|
||||
err_code = app_uart_put(tx_data[i]);
|
||||
if ((err_code != NRF_SUCCESS) && (err_code != NRF_ERROR_BUSY)) {
|
||||
NRF_LOG_ERROR("Failed receiving NUS message. Error 0x%x. ",
|
||||
err_code);
|
||||
APP_ERROR_CHECK(err_code);
|
||||
}
|
||||
} while (err_code == NRF_ERROR_BUSY);
|
||||
}
|
||||
int_comm_send(tx_data, sizeof(tx_data));
|
||||
|
||||
uint8_t p_key[6] = {0};
|
||||
|
||||
while (!m_uart_rx_data_ready_internal)
|
||||
;
|
||||
|
||||
uint16_t message_type = (m_uart_rx_data[3] << 8) | m_uart_rx_data[4];
|
||||
|
||||
if (message_type != 8004) {
|
||||
break;
|
||||
}
|
||||
|
||||
for (int i = 0; i < 6; i++) {
|
||||
p_key[i] = m_uart_rx_data[i + 11];
|
||||
}
|
||||
@ -756,33 +768,6 @@ static void uart_init(void) {
|
||||
}
|
||||
/**@snippet [UART Initialization] */
|
||||
|
||||
/**@brief Function for initializing the Advertising functionality.
|
||||
*/
|
||||
// static void advertising_init(void) {
|
||||
// uint32_t err_code;
|
||||
// ble_advertising_init_t init;
|
||||
//
|
||||
// memset(&init, 0, sizeof(init));
|
||||
//
|
||||
// init.advdata.name_type = BLE_ADVDATA_FULL_NAME;
|
||||
// init.advdata.include_appearance = false;
|
||||
// init.advdata.flags = BLE_GAP_ADV_FLAGS_LE_ONLY_LIMITED_DISC_MODE;
|
||||
//
|
||||
// init.srdata.uuids_complete.uuid_cnt =
|
||||
// sizeof(m_adv_uuids) / sizeof(m_adv_uuids[0]);
|
||||
// init.srdata.uuids_complete.p_uuids = m_adv_uuids;
|
||||
//
|
||||
// init.config.ble_adv_fast_enabled = true;
|
||||
// init.config.ble_adv_fast_interval = APP_ADV_INTERVAL;
|
||||
// init.config.ble_adv_fast_timeout = APP_ADV_DURATION;
|
||||
// init.evt_handler = on_adv_evt;
|
||||
//
|
||||
// err_code = ble_advertising_init(&m_advertising, &init);
|
||||
// APP_ERROR_CHECK(err_code);
|
||||
//
|
||||
// ble_advertising_conn_cfg_tag_set(&m_advertising, APP_BLE_CONN_CFG_TAG);
|
||||
//}
|
||||
|
||||
static void advertising_init(void) {
|
||||
uint32_t err_code;
|
||||
uint8_t adv_flags;
|
||||
@ -953,7 +938,35 @@ static void pm_evt_handler(pm_evt_t const *p_evt) {
|
||||
whitelist_set(PM_PEER_ID_LIST_SKIP_NO_ID_ADDR);
|
||||
}
|
||||
break;
|
||||
case PM_EVT_CONN_SEC_CONFIG_REQ: {
|
||||
uint8_t tx_data[] = {
|
||||
0xA0, // internal message
|
||||
0x00, // length - HI
|
||||
0x0D, // length - LO
|
||||
0x3F, 0x23, 0x23, 0x1F, 0x45, 0x00, 0x00, 0x00, 0x00,
|
||||
0x55, // EOM
|
||||
};
|
||||
|
||||
int_comm_send(tx_data, sizeof(tx_data));
|
||||
|
||||
while (!m_uart_rx_data_ready_internal)
|
||||
;
|
||||
|
||||
uint16_t message_type = (m_uart_rx_data[3] << 8) | m_uart_rx_data[4];
|
||||
|
||||
m_uart_rx_data_ready_internal = false;
|
||||
|
||||
if (message_type == 2) {
|
||||
// Allow or reject pairing request from an already bonded peer.
|
||||
pm_conn_sec_config_t conn_sec_config = {.allow_repairing = true};
|
||||
pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config);
|
||||
} else {
|
||||
// Allow or reject pairing request from an already bonded peer.
|
||||
pm_conn_sec_config_t conn_sec_config = {.allow_repairing = false};
|
||||
pm_conn_sec_config_reply(p_evt->conn_handle, &conn_sec_config);
|
||||
}
|
||||
|
||||
} break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
@ -305,6 +305,8 @@ apps.management.backup_types
|
||||
import apps.management.backup_types
|
||||
apps.management.ble.pairing_request
|
||||
import apps.management.ble.pairing_request
|
||||
apps.management.ble.repair_request
|
||||
import apps.management.ble.repair_request
|
||||
apps.management.ble.upload_ble_firmware_init
|
||||
import apps.management.ble.upload_ble_firmware_init
|
||||
apps.management.change_pin
|
||||
|
19
core/src/apps/management/ble/repair_request.py
Normal file
19
core/src/apps/management/ble/repair_request.py
Normal file
@ -0,0 +1,19 @@
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from trezor.wire import GenericContext
|
||||
from trezor.messages import (
|
||||
Success,
|
||||
RepairRequest,
|
||||
)
|
||||
|
||||
|
||||
async def repair_request(ctx: GenericContext, _msg: RepairRequest) -> Success:
|
||||
from trezor.messages import (
|
||||
Success,
|
||||
)
|
||||
from trezor.ui.layouts import confirm_action
|
||||
|
||||
await confirm_action(ctx, None, "RE-PAIR DEVICE")
|
||||
|
||||
return Success()
|
@ -60,6 +60,8 @@ def _find_message_handler_module(msg_type: int) -> str:
|
||||
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"
|
||||
|
||||
# bitcoin
|
||||
if msg_type == MessageType.AuthorizeCoinJoin:
|
||||
|
@ -55,6 +55,7 @@ UploadBLEFirmwareNextChunk = 8001
|
||||
UploadBLEFirmwareChunk = 8002
|
||||
PairingRequest = 8003
|
||||
AuthKey = 8004
|
||||
RepairRequest = 8005
|
||||
GetPublicKey = 11
|
||||
PublicKey = 12
|
||||
SignTx = 15
|
||||
|
@ -77,6 +77,7 @@ if TYPE_CHECKING:
|
||||
UploadBLEFirmwareChunk = 8002
|
||||
PairingRequest = 8003
|
||||
AuthKey = 8004
|
||||
RepairRequest = 8005
|
||||
GetPublicKey = 11
|
||||
PublicKey = 12
|
||||
SignTx = 15
|
||||
|
@ -1241,6 +1241,12 @@ if TYPE_CHECKING:
|
||||
def is_type_of(cls, msg: Any) -> TypeGuard["AuthKey"]:
|
||||
return isinstance(msg, cls)
|
||||
|
||||
class RepairRequest(protobuf.MessageType):
|
||||
|
||||
@classmethod
|
||||
def is_type_of(cls, msg: Any) -> TypeGuard["RepairRequest"]:
|
||||
return isinstance(msg, cls)
|
||||
|
||||
class CardanoBlockchainPointerType(protobuf.MessageType):
|
||||
block_index: "int"
|
||||
tx_index: "int"
|
||||
|
@ -34,12 +34,15 @@ async def button_request(
|
||||
async def interact(
|
||||
ctx: wire.GenericContext,
|
||||
layout: LayoutType,
|
||||
br_type: str,
|
||||
br_type: str | None,
|
||||
br_code: ButtonRequestType = ButtonRequestType.Other,
|
||||
) -> Any:
|
||||
if br_type is not None:
|
||||
if hasattr(layout, "page_count") and layout.page_count() > 1: # type: ignore [Cannot access member "page_count" for type "LayoutType"]
|
||||
await button_request(ctx, br_type, br_code, pages=layout.page_count()) # type: ignore [Cannot access member "page_count" for type "LayoutType"]
|
||||
return await ctx.wait(layout)
|
||||
else:
|
||||
await button_request(ctx, br_type, br_code)
|
||||
return await ctx.wait(layout)
|
||||
else:
|
||||
return await ctx.wait(layout)
|
||||
|
@ -207,7 +207,7 @@ async def raise_if_not_confirmed(a: Awaitable[T], exc: Any = ActionCancelled) ->
|
||||
|
||||
async def confirm_action(
|
||||
ctx: GenericContext,
|
||||
br_type: str,
|
||||
br_type: str | None,
|
||||
title: str,
|
||||
action: str | None = None,
|
||||
description: str | None = None,
|
||||
|
@ -85,6 +85,7 @@ class MessageType(IntEnum):
|
||||
UploadBLEFirmwareChunk = 8002
|
||||
PairingRequest = 8003
|
||||
AuthKey = 8004
|
||||
RepairRequest = 8005
|
||||
GetPublicKey = 11
|
||||
PublicKey = 12
|
||||
SignTx = 15
|
||||
@ -2109,6 +2110,10 @@ class AuthKey(protobuf.MessageType):
|
||||
self.key = key
|
||||
|
||||
|
||||
class RepairRequest(protobuf.MessageType):
|
||||
MESSAGE_WIRE_TYPE = 8005
|
||||
|
||||
|
||||
class FirmwareErase(protobuf.MessageType):
|
||||
MESSAGE_WIRE_TYPE = 6
|
||||
FIELDS = {
|
||||
|
Loading…
Reference in New Issue
Block a user