From 28f86ace0ec55f0879f1f1a85074365e6281bae3 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Wed, 20 Aug 2025 08:13:11 +0200 Subject: [PATCH 1/2] fix(nordic/ble): disconnect if the corresponding bond is erased [no changelog] --- nordic/trezor/trezor-ble/src/ble/bonds.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/nordic/trezor/trezor-ble/src/ble/bonds.c b/nordic/trezor/trezor-ble/src/ble/bonds.c index 27065df4c3d..c94068e0459 100644 --- a/nordic/trezor/trezor-ble/src/ble/bonds.c +++ b/nordic/trezor/trezor-ble/src/ble/bonds.c @@ -35,6 +35,7 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME); #include "ble_internal.h" bool bonds_erase_all(void) { + connection_disconnect(); int err = bt_unpair(BT_ID_DEFAULT, BT_ADDR_LE_ANY); if (err) { LOG_INF("Cannot delete bonds (err: %d)\n", err); @@ -75,6 +76,8 @@ bool bonds_erase_current(void) { return false; } + connection_disconnect(); + err = bt_unpair(BT_ID_DEFAULT, info.le.dst); return err == 0; @@ -85,12 +88,24 @@ bool bonds_erase_device(const bt_addr_le_t *addr) { return false; } + struct bt_conn *current = connection_get_current(); + bool erased = false; bt_addr_le_t target; // Copy MAC and try both address types (ignore the input type) memcpy(target.a.val, addr->a.val, BT_ADDR_SIZE); + if (current != NULL) { + struct bt_conn_info info; + int err = bt_conn_get_info(current, &info); + if (err == 0 && + memcmp(info.le.dst->a.val, target.a.val, BT_ADDR_SIZE) == 0) { + // If the device is currently connected, disconnect it first + connection_disconnect(); + } + } + target.type = BT_ADDR_LE_PUBLIC; if (bt_unpair(BT_ID_DEFAULT, &target) == 0) { erased = true; From 8bc361c00a38afc83440c38ea09a11f31d569eae Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Wed, 20 Aug 2025 13:13:03 +0200 Subject: [PATCH 2/2] fix(core/bootloader): send response before deleting bonds in factory reset [no changelog] --- .../projects/bootloader/workflow/wf_wipe_device.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/core/embed/projects/bootloader/workflow/wf_wipe_device.c b/core/embed/projects/bootloader/workflow/wf_wipe_device.c index 08962e6f0ac..143cbec8be3 100644 --- a/core/embed/projects/bootloader/workflow/wf_wipe_device.c +++ b/core/embed/projects/bootloader/workflow/wf_wipe_device.c @@ -97,12 +97,23 @@ workflow_result_t workflow_wipe_device(protob_io_t* iface) { ui_screen_wipe(); secbool wipe_result = erase_device(ui_screen_wipe_progress); + if (sectrue != wipe_result) { + send_error_conditionally(iface, "Could not erase flash"); + } + #ifdef USE_BACKUP_RAM if (!backup_ram_erase_protected()) { return WF_ERROR; } #endif + // sending success earlier to notify host before bonds deletion causes + // disconnect + if (iface != NULL) { + send_msg_success(iface, NULL); + systick_delay_ms(100); + } + #ifdef USE_BLE if (!wipe_bonds(iface)) { return WF_ERROR; @@ -110,14 +121,10 @@ workflow_result_t workflow_wipe_device(protob_io_t* iface) { #endif if (sectrue != wipe_result) { - send_error_conditionally(iface, "Could not erase flash"); screen_wipe_fail(); return WF_ERROR; } - if (iface != NULL) { - send_msg_success(iface, NULL); - } screen_wipe_success(); return WF_OK_DEVICE_WIPED; }