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 64d3df3d94..a55f15202c 100644 --- a/core/embed/io/ble/stm32/ble.c +++ b/core/embed/io/ble/stm32/ble.c @@ -117,6 +117,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; @@ -572,6 +579,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 6ebbbb2d43..628df8dee7 100644 --- a/core/embed/upymod/modtrezorio/modtrezorio-ble.h +++ b/core/embed/upymod/modtrezorio/modtrezorio-ble.h @@ -139,6 +139,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 @@ -237,6 +248,7 @@ STATIC const mp_rom_map_elem_t mod_trezorio_BLE_globals_table[] = { {MP_ROM_QSTR(MP_QSTR_read), MP_ROM_PTR(&mod_trezorio_BLE_read_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 09df0e2dde..79388a1bca 100644 --- a/core/mocks/generated/trezorio/ble.pyi +++ b/core/mocks/generated/trezorio/ble.pyi @@ -22,6 +22,13 @@ def erase_bonds() -> bool: """ +# upymod/modtrezorio/modtrezorio-ble.h +def unpair() -> None: + """ + Erases bond for current connection, if any + """ + + # upymod/modtrezorio/modtrezorio-ble.h def start_comm() -> bool: """