1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-03-12 14:16:06 +00:00

feat(core): add unpair command to BLE

[no changelog]
This commit is contained in:
tychovrahe 2025-01-31 10:19:00 +01:00 committed by M1nd3r
parent ad34dc9ae6
commit bf01294cc9
5 changed files with 31 additions and 0 deletions

View File

@ -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 {

View File

@ -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;
}

View File

@ -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;

View File

@ -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),

View File

@ -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:
"""