From f966119817355bd8de171402b10aea9cc9c80812 Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Wed, 25 Jun 2025 10:27:49 +0200 Subject: [PATCH] fix(core/bootloader): close booloader BLE pairing mode dialog on disconnect [no changelog] --- core/embed/io/ble/inc/io/ble.h | 3 +++ core/embed/io/ble/stm32/ble.c | 14 ++++++++++++++ .../projects/bootloader/wire/wire_iface_ble.c | 2 ++ .../src/ui/layout_bolt/component/pairing_mode.rs | 3 +++ .../ui/layout_eckhart/bootloader/pairing_mode.rs | 3 +++ 5 files changed, 25 insertions(+) diff --git a/core/embed/io/ble/inc/io/ble.h b/core/embed/io/ble/inc/io/ble.h index bc2edaf5d0..606d99afc8 100644 --- a/core/embed/io/ble/inc/io/ble.h +++ b/core/embed/io/ble/inc/io/ble.h @@ -142,6 +142,9 @@ bool ble_issue_command(ble_command_t *command); // available. bool ble_get_event(ble_event_t *event); +// Flushes the BLE event queue +void ble_event_flush(void); + // Retrieves the current state of the BLE module // // Obtains the current operational state of the BLE module. diff --git a/core/embed/io/ble/stm32/ble.c b/core/embed/io/ble/stm32/ble.c index fc4c61a72e..78f59f37cf 100644 --- a/core/embed/io/ble/stm32/ble.c +++ b/core/embed/io/ble/stm32/ble.c @@ -712,6 +712,20 @@ bool ble_get_event(ble_event_t *event) { return result; } +void ble_event_flush(void) { + ble_driver_t *drv = &g_ble_driver; + + if (!drv->initialized) { + return; + } + + irq_key_t key = irq_lock(); + + tsqueue_reset(&drv->event_queue); + + irq_unlock(key); +} + void ble_get_state(ble_state_t *state) { const ble_driver_t *drv = &g_ble_driver; diff --git a/core/embed/projects/bootloader/wire/wire_iface_ble.c b/core/embed/projects/bootloader/wire/wire_iface_ble.c index 42072c0d9b..c975697cce 100644 --- a/core/embed/projects/bootloader/wire/wire_iface_ble.c +++ b/core/embed/projects/bootloader/wire/wire_iface_ble.c @@ -179,6 +179,8 @@ bool ble_iface_start_pairing(void) { return false; } + ble_event_flush(); + ble_command_t cmd = { .cmd_type = BLE_PAIRING_MODE, .data = {.adv_start = diff --git a/core/embed/rust/src/ui/layout_bolt/component/pairing_mode.rs b/core/embed/rust/src/ui/layout_bolt/component/pairing_mode.rs index 2103e57102..4c62fb3879 100644 --- a/core/embed/rust/src/ui/layout_bolt/component/pairing_mode.rs +++ b/core/embed/rust/src/ui/layout_bolt/component/pairing_mode.rs @@ -74,6 +74,9 @@ impl Component for PairingMode { if let Event::BLE(BLEEvent::PairingCanceled) = event { return Some(PairingMsg::Cancel); } + if let Event::BLE(BLEEvent::Disconnected) = event { + return Some(PairingMsg::Cancel); + } None } diff --git a/core/embed/rust/src/ui/layout_eckhart/bootloader/pairing_mode.rs b/core/embed/rust/src/ui/layout_eckhart/bootloader/pairing_mode.rs index f797fb6973..bac2123a1c 100644 --- a/core/embed/rust/src/ui/layout_eckhart/bootloader/pairing_mode.rs +++ b/core/embed/rust/src/ui/layout_eckhart/bootloader/pairing_mode.rs @@ -74,6 +74,9 @@ impl Component for PairingModeScreen { if let Event::BLE(BLEEvent::PairingCanceled) = event { return Some(PairingMsg::Cancel); } + if let Event::BLE(BLEEvent::Disconnected) = event { + return Some(PairingMsg::Cancel); + } None }