From fad6b5e563ab1e66a974875b17635906d1614d9f Mon Sep 17 00:00:00 2001 From: tychovrahe Date: Thu, 10 Apr 2025 20:10:08 +0200 Subject: [PATCH] feat(core): add BLE pairing complete event [no changelog] --- core/embed/io/ble/inc/io/ble.h | 1 + core/embed/io/ble/stm32/ble.c | 15 +++++++++++++++ core/embed/io/ble/stm32/ble_comm_defs.h | 1 + core/embed/rust/src/ui/event/ble.rs | 2 ++ 4 files changed, 19 insertions(+) diff --git a/core/embed/io/ble/inc/io/ble.h b/core/embed/io/ble/inc/io/ble.h index 6879375417..e52bc3dff1 100644 --- a/core/embed/io/ble/inc/io/ble.h +++ b/core/embed/io/ble/inc/io/ble.h @@ -65,6 +65,7 @@ typedef enum { BLE_DISCONNECTED = 2, // Disconnected from a device BLE_PAIRING_REQUEST = 3, // Pairing request received BLE_PAIRING_CANCELLED = 4, // Pairing was cancelled by host + BLE_PAIRING_COMPLETED = 5, // Pairing was completed successfully } ble_event_type_t; typedef struct { diff --git a/core/embed/io/ble/stm32/ble.c b/core/embed/io/ble/stm32/ble.c index d13938aa19..afd64f24d5 100644 --- a/core/embed/io/ble/stm32/ble.c +++ b/core/embed/io/ble/stm32/ble.c @@ -263,6 +263,18 @@ static void ble_process_rx_msg_pairing_cancelled(const uint8_t *data, drv->pairing_requested = false; } +static void ble_process_rx_msg_pairing_completed(const uint8_t *data, + uint32_t len) { + ble_driver_t *drv = &g_ble_driver; + if (!drv->initialized) { + return; + } + + ble_event_t event = {.type = BLE_PAIRING_COMPLETED, .data_len = 0}; + tsqueue_enqueue(&drv->event_queue, (uint8_t *)&event, sizeof(event), NULL); + drv->pairing_requested = false; +} + static void ble_process_rx_msg_mac(const uint8_t *data, uint32_t len) { ble_driver_t *drv = &g_ble_driver; if (!drv->initialized) { @@ -290,6 +302,9 @@ static void ble_process_rx_msg(const uint8_t *data, uint32_t len) { break; case INTERNAL_EVENT_MAC: ble_process_rx_msg_mac(data, len); + break; + case INTERNAL_EVENT_PAIRING_COMPLETED: + ble_process_rx_msg_pairing_completed(data, len); default: break; } diff --git a/core/embed/io/ble/stm32/ble_comm_defs.h b/core/embed/io/ble/stm32/ble_comm_defs.h index e2065df968..ba4b607b28 100644 --- a/core/embed/io/ble/stm32/ble_comm_defs.h +++ b/core/embed/io/ble/stm32/ble_comm_defs.h @@ -48,6 +48,7 @@ typedef enum { INTERNAL_EVENT_PAIRING_REQUEST = 0x04, INTERNAL_EVENT_PAIRING_CANCELLED = 0x05, INTERNAL_EVENT_MAC = 0x06, + INTERNAL_EVENT_PAIRING_COMPLETED = 0x07, } internal_event_t; typedef enum { diff --git a/core/embed/rust/src/ui/event/ble.rs b/core/embed/rust/src/ui/event/ble.rs index b5ee2f9ee0..1ad5245d1e 100644 --- a/core/embed/rust/src/ui/event/ble.rs +++ b/core/embed/rust/src/ui/event/ble.rs @@ -7,6 +7,7 @@ pub enum BLEEvent { Disconnected, PairingRequest(u32), PairingCanceled, + PairingCompleted, } impl BLEEvent { @@ -16,6 +17,7 @@ impl BLEEvent { (2, None) => Self::Disconnected, (3, Some(code)) => Self::PairingRequest(code), (4, None) => Self::PairingCanceled, + (5, None) => Self::PairingCompleted, _ => return Err(Error::ValueError(c"Invalid BLE event")), }; Ok(result)