mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-01 18:30:56 +00:00
feat(ble): support setting device name from trezor
[no changelog]
This commit is contained in:
parent
0a6b434a02
commit
f747f5964c
@ -35,7 +35,8 @@ CONFIG_POWEROFF=y
|
|||||||
|
|
||||||
CONFIG_BT=y
|
CONFIG_BT=y
|
||||||
CONFIG_BT_PERIPHERAL=y
|
CONFIG_BT_PERIPHERAL=y
|
||||||
CONFIG_BT_DEVICE_NAME="Trezor T3W1"
|
CONFIG_BT_DEVICE_NAME="Trezor BLE"
|
||||||
|
CONFIG_BT_DEVICE_NAME_DYNAMIC=y
|
||||||
CONFIG_BT_DEVICE_APPEARANCE=833
|
CONFIG_BT_DEVICE_APPEARANCE=833
|
||||||
CONFIG_BT_MAX_CONN=1
|
CONFIG_BT_MAX_CONN=1
|
||||||
CONFIG_BT_MAX_PAIRED=8
|
CONFIG_BT_MAX_PAIRED=8
|
||||||
|
@ -37,10 +37,7 @@ bool advertising_wl = false;
|
|||||||
|
|
||||||
uint8_t manufacturer_data[8] = {0xff, 0xff, 0, 3, 'T', '3', 'W', '1'};
|
uint8_t manufacturer_data[8] = {0xff, 0xff, 0, 3, 'T', '3', 'W', '1'};
|
||||||
|
|
||||||
static const struct bt_data advertising_data[] = {
|
static struct bt_data advertising_data[2];
|
||||||
BT_DATA_BYTES(BT_DATA_FLAGS, (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR)),
|
|
||||||
BT_DATA(BT_DATA_NAME_COMPLETE, DEVICE_NAME, DEVICE_NAME_LEN),
|
|
||||||
};
|
|
||||||
|
|
||||||
static const struct bt_data scan_response_data[] = {
|
static const struct bt_data scan_response_data[] = {
|
||||||
BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_TRZ_VAL),
|
BT_DATA_BYTES(BT_DATA_UUID128_ALL, BT_UUID_TRZ_VAL),
|
||||||
@ -64,22 +61,29 @@ void advertising_setup_wl(void) {
|
|||||||
bt_foreach_bond(BT_ID_DEFAULT, add_to_whitelist, NULL);
|
bt_foreach_bond(BT_ID_DEFAULT, add_to_whitelist, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
void advertising_start(bool wl) {
|
void advertising_start(bool wl, uint8_t color, char *name, int name_len) {
|
||||||
if (advertising) {
|
if (advertising) {
|
||||||
if (wl != advertising_wl) {
|
|
||||||
LOG_WRN("Restarting advertising");
|
LOG_WRN("Restarting advertising");
|
||||||
bt_le_adv_stop();
|
bt_le_adv_stop();
|
||||||
} else {
|
|
||||||
LOG_WRN("Already advertising");
|
|
||||||
|
|
||||||
management_send_status_event();
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
manufacturer_data[3] = 0x03; // todo color
|
manufacturer_data[3] = color;
|
||||||
|
|
||||||
|
advertising_data[0].type = BT_DATA_FLAGS;
|
||||||
|
advertising_data[0].data_len = 1;
|
||||||
|
static const uint8_t flags = (BT_LE_AD_GENERAL | BT_LE_AD_NO_BREDR);
|
||||||
|
advertising_data[0].data = &flags;
|
||||||
|
|
||||||
|
/* Fill second element for the name */
|
||||||
|
advertising_data[1].type = BT_DATA_NAME_COMPLETE;
|
||||||
|
advertising_data[1].data_len = name_len;
|
||||||
|
advertising_data[1].data = (const uint8_t *)name;
|
||||||
|
|
||||||
|
char gap_name[21] = {0};
|
||||||
|
memcpy(gap_name, name, name_len);
|
||||||
|
|
||||||
|
bt_set_name(gap_name);
|
||||||
|
|
||||||
if (wl) {
|
if (wl) {
|
||||||
advertising_setup_wl();
|
advertising_setup_wl();
|
||||||
|
@ -73,8 +73,6 @@ bool ble_init(void) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bt_set_name("TrezorGAP");
|
|
||||||
|
|
||||||
advertising_init();
|
advertising_init();
|
||||||
management_init();
|
management_init();
|
||||||
|
|
||||||
|
@ -106,7 +106,7 @@ bool bonds_erase_current(void);
|
|||||||
// Initialization
|
// Initialization
|
||||||
void advertising_init(void);
|
void advertising_init(void);
|
||||||
// Start advertising, with or without whitelist
|
// Start advertising, with or without whitelist
|
||||||
void advertising_start(bool wl);
|
void advertising_start(bool wl, uint8_t color, char *name, int name_len);
|
||||||
// Stop advertising
|
// Stop advertising
|
||||||
void advertising_stop(void);
|
void advertising_stop(void);
|
||||||
// Check if advertising is active
|
// Check if advertising is active
|
||||||
|
@ -63,14 +63,14 @@ void management_send_status_event(void) {
|
|||||||
void management_send_success_event(void) {
|
void management_send_success_event(void) {
|
||||||
uint8_t tx_data[] = {
|
uint8_t tx_data[] = {
|
||||||
INTERNAL_EVENT_SUCCESS,
|
INTERNAL_EVENT_SUCCESS,
|
||||||
};
|
};
|
||||||
trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data));
|
trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
void management_send_failure_event(void) {
|
void management_send_failure_event(void) {
|
||||||
uint8_t tx_data[] = {
|
uint8_t tx_data[] = {
|
||||||
INTERNAL_EVENT_FAILURE,
|
INTERNAL_EVENT_FAILURE,
|
||||||
};
|
};
|
||||||
trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data));
|
trz_comm_send_msg(NRF_SERVICE_BLE_MANAGER, tx_data, sizeof(tx_data));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -105,9 +105,12 @@ static void process_command(uint8_t *data, uint16_t len) {
|
|||||||
send_respons = false;
|
send_respons = false;
|
||||||
management_send_status_event();
|
management_send_status_event();
|
||||||
break;
|
break;
|
||||||
case INTERNAL_CMD_ADVERTISING_ON:
|
case INTERNAL_CMD_ADVERTISING_ON: {
|
||||||
advertising_start(data[1] != 0);
|
uint8_t color = data[2];
|
||||||
break;
|
char *name = &data[3];
|
||||||
|
int name_len = strnlen(name, 20);
|
||||||
|
advertising_start(data[1] != 0, color, name, name_len);
|
||||||
|
} break;
|
||||||
case INTERNAL_CMD_ADVERTISING_OFF:
|
case INTERNAL_CMD_ADVERTISING_OFF:
|
||||||
advertising_stop();
|
advertising_stop();
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user