vial: allow resuming an interrupted unlock sequence

This commit is contained in:
Ilya Zhuravlev 2021-01-07 09:17:18 -05:00
parent e2447a0eea
commit cc43ad2b41
2 changed files with 10 additions and 4 deletions

View file

@ -220,9 +220,14 @@ void raw_hid_receive(uint8_t *data, uint8_t length) {
uint8_t *command_data = &(data[1]);
#ifdef VIAL_ENABLE
/* When unlock is in progress, only command we react to is unlock_poll */
if (vial_unlock_in_progress && (data[0] != id_vial_prefix || data[1] != vial_unlock_poll))
goto skip;
/* When unlock is in progress, we can only react to a subset of commands */
if (vial_unlock_in_progress) {
if (data[0] != id_vial_prefix)
goto skip;
uint8_t cmd = data[1];
if (cmd != vial_get_keyboard_id && cmd != vial_get_size && cmd != vial_get_def && cmd != vial_get_unlock_status && cmd != vial_unlock_start && cmd != vial_unlock_poll)
goto skip;
}
#endif
switch (*command_id) {

View file

@ -105,7 +105,8 @@ void vial_handle_cmd(uint8_t *msg, uint8_t length) {
memset(msg, 0xFF, length);
/* First byte of message contains the status: whether board is unlocked */
msg[0] = vial_unlocked;
msg[1] = 0;
/* Second byte is whether unlock is in progress */
msg[1] = vial_unlock_in_progress;
#ifndef VIAL_INSECURE
/* Rest of the message are keys in the matrix that should be held to unlock the board */
for (size_t i = 0; i < VIAL_UNLOCK_NUM_KEYS; ++i) {