1
0
mirror of https://github.com/trezor/trezor-firmware.git synced 2025-04-22 10:09:04 +00:00

fixup! feat(core): add BLE to bootloader

This commit is contained in:
tychovrahe 2025-04-11 15:44:13 +02:00
parent bd584edbe5
commit 6241c0b986
3 changed files with 48 additions and 23 deletions

View File

@ -144,18 +144,39 @@ void ble_iface_deinit(void) {
memset(iface, 0, sizeof(wire_iface_t));
}
void ble_iface_start_pairing(void) {
void ble_iface_end_pairing(void) {
ble_state_t state = {0};
ble_get_state(&state);
while (state.connected) {
if (state.peer_count > 0) {
ble_command_t cmd = {.cmd_type = BLE_SWITCH_ON};
ble_issue_command(&cmd);
} else {
ble_command_t cmd = {.cmd_type = BLE_SWITCH_OFF};
ble_issue_command(&cmd);
}
}
bool ble_iface_start_pairing(void) {
ble_state_t state = {0};
ble_get_state(&state);
uint16_t retry_cnt = 0;
while (state.connected && retry_cnt < 10) {
ble_command_t cmd_disconnect = {
.cmd_type = BLE_DISCONNECT,
};
ble_issue_command(&cmd_disconnect);
systick_delay_ms(20);
ble_get_state(&state);
retry_cnt++;
}
if (state.connected) {
return false;
}
ble_command_t cmd = {
@ -165,9 +186,23 @@ void ble_iface_start_pairing(void) {
.name = "Trezor Bootloader",
.static_mac = false,
}},
.data_len = 0,
};
ble_issue_command(&cmd);
retry_cnt = 0;
ble_get_state(&state);
while (!state.pairing && retry_cnt < 10) {
systick_delay_ms(20);
ble_get_state(&state);
retry_cnt++;
}
if (!state.pairing) {
ble_iface_end_pairing();
return false;
}
return true;
}
#endif

View File

@ -25,4 +25,6 @@ wire_iface_t* ble_iface_init(void);
void ble_iface_deinit(void);
void ble_iface_start_pairing(void);
bool ble_iface_start_pairing(void);
void ble_iface_end_pairing(void);

View File

@ -39,23 +39,11 @@ static bool encode_pairing_code(uint32_t code, uint8_t *outbuf) {
return true;
}
static void end_pairing_mode(void) {
ble_state_t state = {0};
ble_get_state(&state);
if (state.peer_count > 0) {
ble_command_t cmd = {.cmd_type = BLE_SWITCH_ON};
ble_issue_command(&cmd);
} else {
ble_command_t cmd = {.cmd_type = BLE_SWITCH_OFF};
ble_issue_command(&cmd);
}
}
workflow_result_t workflow_ble_pairing_request(const vendor_header *const vhdr,
const image_header *const hdr) {
ble_iface_start_pairing();
if (!ble_iface_start_pairing()) {
return WF_OK_PAIRING_FAILED;
}
uint8_t buf[1024] = {0};
screen_pairing_mode(ui_get_initial_setup(), buf, sizeof(buf));
@ -65,12 +53,12 @@ workflow_result_t workflow_ble_pairing_request(const vendor_header *const vhdr,
workflow_host_control(vhdr, hdr, buf, sizeof(buf), &code);
if (res != WF_OK_UI_ACTION) {
end_pairing_mode();
ble_iface_end_pairing();
return res;
}
if (code == PAIRING_MODE_CANCEL) {
end_pairing_mode();
ble_iface_end_pairing();
return WF_OK_PAIRING_FAILED;
}
@ -114,13 +102,13 @@ workflow_result_t workflow_ble_pairing_request(const vendor_header *const vhdr,
pairing_mode_finalization_result_t r =
screen_pairing_mode_finalizing(ui_get_initial_setup());
if (r == PAIRING_FINALIZATION_FAILED) {
end_pairing_mode();
ble_iface_end_pairing();
return WF_OK_PAIRING_FAILED;
}
if (r == PAIRING_FINALIZATION_CANCEL) {
ble_command_t disconnect = {.cmd_type = BLE_DISCONNECT};
ble_issue_command(&disconnect);
end_pairing_mode();
ble_iface_end_pairing();
return WF_OK_PAIRING_FAILED;
}
}