1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-05-08 18:08:46 +00:00

feat(core): add BLE pairing complete event

[no changelog]
This commit is contained in:
tychovrahe 2025-04-10 20:10:08 +02:00
parent 844e0d11ca
commit fad6b5e563
4 changed files with 19 additions and 0 deletions

View File

@ -65,6 +65,7 @@ typedef enum {
BLE_DISCONNECTED = 2, // Disconnected from a device BLE_DISCONNECTED = 2, // Disconnected from a device
BLE_PAIRING_REQUEST = 3, // Pairing request received BLE_PAIRING_REQUEST = 3, // Pairing request received
BLE_PAIRING_CANCELLED = 4, // Pairing was cancelled by host BLE_PAIRING_CANCELLED = 4, // Pairing was cancelled by host
BLE_PAIRING_COMPLETED = 5, // Pairing was completed successfully
} ble_event_type_t; } ble_event_type_t;
typedef struct { typedef struct {

View File

@ -263,6 +263,18 @@ static void ble_process_rx_msg_pairing_cancelled(const uint8_t *data,
drv->pairing_requested = false; 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) { static void ble_process_rx_msg_mac(const uint8_t *data, uint32_t len) {
ble_driver_t *drv = &g_ble_driver; ble_driver_t *drv = &g_ble_driver;
if (!drv->initialized) { if (!drv->initialized) {
@ -290,6 +302,9 @@ static void ble_process_rx_msg(const uint8_t *data, uint32_t len) {
break; break;
case INTERNAL_EVENT_MAC: case INTERNAL_EVENT_MAC:
ble_process_rx_msg_mac(data, len); ble_process_rx_msg_mac(data, len);
break;
case INTERNAL_EVENT_PAIRING_COMPLETED:
ble_process_rx_msg_pairing_completed(data, len);
default: default:
break; break;
} }

View File

@ -48,6 +48,7 @@ typedef enum {
INTERNAL_EVENT_PAIRING_REQUEST = 0x04, INTERNAL_EVENT_PAIRING_REQUEST = 0x04,
INTERNAL_EVENT_PAIRING_CANCELLED = 0x05, INTERNAL_EVENT_PAIRING_CANCELLED = 0x05,
INTERNAL_EVENT_MAC = 0x06, INTERNAL_EVENT_MAC = 0x06,
INTERNAL_EVENT_PAIRING_COMPLETED = 0x07,
} internal_event_t; } internal_event_t;
typedef enum { typedef enum {

View File

@ -7,6 +7,7 @@ pub enum BLEEvent {
Disconnected, Disconnected,
PairingRequest(u32), PairingRequest(u32),
PairingCanceled, PairingCanceled,
PairingCompleted,
} }
impl BLEEvent { impl BLEEvent {
@ -16,6 +17,7 @@ impl BLEEvent {
(2, None) => Self::Disconnected, (2, None) => Self::Disconnected,
(3, Some(code)) => Self::PairingRequest(code), (3, Some(code)) => Self::PairingRequest(code),
(4, None) => Self::PairingCanceled, (4, None) => Self::PairingCanceled,
(5, None) => Self::PairingCompleted,
_ => return Err(Error::ValueError(c"Invalid BLE event")), _ => return Err(Error::ValueError(c"Invalid BLE event")),
}; };
Ok(result) Ok(result)