mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-01 18:30:56 +00:00
feat(ble): add command to erase bond belonging to currently connected device
[no changelog]
This commit is contained in:
parent
53f0a840a3
commit
69679d9f9f
@ -81,6 +81,7 @@ typedef enum {
|
||||
INTERNAL_CMD_ACK = 0x05,
|
||||
INTERNAL_CMD_ALLOW_PAIRING = 0x06,
|
||||
INTERNAL_CMD_REJECT_PAIRING = 0x07,
|
||||
INTERNAL_CMD_UNPAIR = 0x08,
|
||||
} internal_cmd_t;
|
||||
|
||||
// BLE management functions
|
||||
@ -98,6 +99,8 @@ void management_send_pairing_cancelled_event(void);
|
||||
bool bonds_erase_all(void);
|
||||
// Get number of bonded devices
|
||||
int bonds_get_count(void);
|
||||
// Erase current bond
|
||||
bool bonds_erase_current(void);
|
||||
|
||||
// Advertising functions
|
||||
// Initialization
|
||||
|
@ -21,6 +21,7 @@
|
||||
#include <zephyr/types.h>
|
||||
|
||||
#include <zephyr/bluetooth/bluetooth.h>
|
||||
#include <zephyr/bluetooth/conn.h>
|
||||
|
||||
#include <zephyr/logging/log.h>
|
||||
|
||||
@ -31,8 +32,6 @@ LOG_MODULE_REGISTER(LOG_MODULE_NAME);
|
||||
|
||||
#include "ble_internal.h"
|
||||
|
||||
|
||||
|
||||
bool bonds_erase_all(void) {
|
||||
int err = bt_unpair(BT_ID_DEFAULT, BT_ADDR_LE_ANY);
|
||||
if (err) {
|
||||
@ -57,3 +56,24 @@ int bonds_get_count(void) {
|
||||
|
||||
return bond_cnt;
|
||||
}
|
||||
|
||||
bool bonds_erase_current(void) {
|
||||
int err;
|
||||
struct bt_conn *current = connection_get_current();
|
||||
|
||||
if (current == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
struct bt_conn_info info;
|
||||
|
||||
err = bt_conn_get_info(current, &info);
|
||||
if (err) {
|
||||
LOG_ERR("Failed to get connection info (err %d)", err);
|
||||
return false;
|
||||
}
|
||||
|
||||
err = bt_unpair(BT_ID_DEFAULT, info.le.dst);
|
||||
|
||||
return err == 0;
|
||||
}
|
||||
|
@ -62,8 +62,15 @@ void management_send_status_event(void) {
|
||||
|
||||
void management_send_success_event(void) {
|
||||
uint8_t tx_data[] = {
|
||||
INTERNAL_EVENT_SUCCESS,
|
||||
};
|
||||
INTERNAL_EVENT_SUCCESS,
|
||||
};
|
||||
trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data));
|
||||
}
|
||||
|
||||
void management_send_failure_event(void) {
|
||||
uint8_t tx_data[] = {
|
||||
INTERNAL_EVENT_FAILURE,
|
||||
};
|
||||
trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data));
|
||||
}
|
||||
|
||||
@ -91,8 +98,11 @@ void management_send_pairing_request_event(uint8_t *data, uint16_t len) {
|
||||
|
||||
static void process_command(uint8_t *data, uint16_t len) {
|
||||
uint8_t cmd = data[0];
|
||||
bool success = true;
|
||||
bool send_respons = true;
|
||||
switch (cmd) {
|
||||
case INTERNAL_CMD_SEND_STATE:
|
||||
send_respons = false;
|
||||
management_send_status_event();
|
||||
break;
|
||||
case INTERNAL_CMD_ADVERTISING_ON:
|
||||
@ -103,25 +113,32 @@ static void process_command(uint8_t *data, uint16_t len) {
|
||||
break;
|
||||
case INTERNAL_CMD_ERASE_BONDS:
|
||||
bonds_erase_all();
|
||||
management_send_success_event();
|
||||
break;
|
||||
case INTERNAL_CMD_DISCONNECT:
|
||||
connection_disconnect();
|
||||
management_send_success_event();
|
||||
case INTERNAL_CMD_ACK:
|
||||
// pb_msg_ack();
|
||||
break;
|
||||
case INTERNAL_CMD_ALLOW_PAIRING:
|
||||
pairing_num_comp_reply(true);
|
||||
management_send_success_event();
|
||||
break;
|
||||
break;
|
||||
case INTERNAL_CMD_REJECT_PAIRING:
|
||||
pairing_num_comp_reply(false);
|
||||
management_send_success_event();
|
||||
break;
|
||||
break;
|
||||
case INTERNAL_CMD_UNPAIR:
|
||||
success = bonds_erase_current();
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (send_respons) {
|
||||
if (success) {
|
||||
management_send_success_event();
|
||||
} else {
|
||||
management_send_failure_event();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void management_init(void) { k_sem_give(&management_ok); }
|
||||
|
Loading…
Reference in New Issue
Block a user