Skip to content

disconnect BLE on bond erase #5594

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: tychovrahe/ble/bond_management
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions core/embed/projects/bootloader/workflow/wf_wipe_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,34 @@ 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;
}
#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;
}
15 changes: 15 additions & 0 deletions nordic/trezor/trezor-ble/src/ble/bonds.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Loading