diff --git a/core/embed/io/ble/inc/io/ble.h b/core/embed/io/ble/inc/io/ble.h index c5ed59c975..7b0f76d17c 100644 --- a/core/embed/io/ble/inc/io/ble.h +++ b/core/embed/io/ble/inc/io/ble.h @@ -39,6 +39,7 @@ typedef enum { BLE_ERASE_BONDS = 4, // Erase all bonding information BLE_ALLOW_PAIRING = 5, // Accept pairing request BLE_REJECT_PAIRING = 6, // Reject pairing request + BLE_UNPAIR = 7, // Erase bond for currently connected device } ble_command_type_t; typedef struct { diff --git a/core/embed/io/ble/stm32/ble.c b/core/embed/io/ble/stm32/ble.c index 667ac97565..77488b4bc5 100644 --- a/core/embed/io/ble/stm32/ble.c +++ b/core/embed/io/ble/stm32/ble.c @@ -121,6 +121,13 @@ static bool ble_send_erase_bonds(ble_driver_t *drv) { 0; } +static bool ble_send_unpair(ble_driver_t *drv) { + (void)drv; + uint8_t cmd = INTERNAL_CMD_UNPAIR; + return nrf_send_msg(NRF_SERVICE_BLE_MANAGER, &cmd, sizeof(cmd), NULL, NULL) >= + 0; +} + static bool ble_send_disconnect(ble_driver_t *drv) { (void)drv; uint8_t cmd = INTERNAL_CMD_DISCONNECT; @@ -587,6 +594,9 @@ bool ble_issue_command(ble_command_t *command) { case BLE_REJECT_PAIRING: result = ble_send_pairing_reject(drv); break; + case BLE_UNPAIR: + result = ble_send_unpair(drv); + break; 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 4efd3ab521..2a062b376e 100644 --- a/core/embed/io/ble/stm32/ble_comm_defs.h +++ b/core/embed/io/ble/stm32/ble_comm_defs.h @@ -57,6 +57,7 @@ typedef enum { INTERNAL_CMD_ACK = 0x05, INTERNAL_CMD_ALLOW_PAIRING = 0x06, INTERNAL_CMD_REJECT_PAIRING = 0x07, + INTERNAL_CMD_UNPAIR = 0x08, INTERNAL_CMD_MAC_REQUEST = 0x09, } internal_cmd_t; diff --git a/core/embed/upymod/modtrezorio/modtrezorio-ble.h b/core/embed/upymod/modtrezorio/modtrezorio-ble.h index c9e658bf13..61fe3f9ddf 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-ble.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-ble.h @@ -87,6 +87,17 @@ STATIC mp_obj_t mod_trezorio_BLE_erase_bonds(void) { STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_BLE_erase_bonds_obj, mod_trezorio_BLE_erase_bonds); +/// def unpair() -> bool: +/// """ +/// Erases bond for current connection, if any +/// """ +STATIC mp_obj_t mod_trezorio_BLE_unpair(void) { + ble_command_t cmd = {.cmd_type = BLE_UNPAIR, .data_len = 0}; + return mp_obj_new_bool(ble_issue_command(&cmd)); +} +STATIC MP_DEFINE_CONST_FUN_OBJ_0(mod_trezorio_BLE_unpair_obj, + mod_trezorio_BLE_unpair); + /// def start_comm() -> bool: /// """ /// Start communication with BLE chip @@ -331,6 +342,7 @@ STATIC const mp_rom_map_elem_t mod_trezorio_BLE_globals_table[] = { // MP_ROM_PTR(&mod_trezorio_BLE_update_chunk_obj)}, {MP_ROM_QSTR(MP_QSTR_erase_bonds), MP_ROM_PTR(&mod_trezorio_BLE_erase_bonds_obj)}, + {MP_ROM_QSTR(MP_QSTR_unpair), MP_ROM_PTR(&mod_trezorio_BLE_unpair_obj)}, {MP_ROM_QSTR(MP_QSTR_start_comm), MP_ROM_PTR(&mod_trezorio_BLE_start_comm_obj)}, {MP_ROM_QSTR(MP_QSTR_start_advertising), diff --git a/core/mocks/generated/trezorio/ble.pyi b/core/mocks/generated/trezorio/ble.pyi index 66ac7de011..c7cfbd6fa7 100644 --- a/core/mocks/generated/trezorio/ble.pyi +++ b/core/mocks/generated/trezorio/ble.pyi @@ -9,6 +9,13 @@ def erase_bonds() -> bool: """ +# upymod/modtrezorio/modtrezorio-ble.h +def unpair() -> bool: + """ + Erases bond for current connection, if any + """ + + # upymod/modtrezorio/modtrezorio-ble.h def start_comm() -> bool: """