mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-12-22 14:28:07 +00:00
feat(core): Improve Optiga transport error handling.
This commit is contained in:
parent
7d92e70cc3
commit
b3d0fb68ff
@ -281,20 +281,23 @@ static optiga_result optiga_ensure_ready(void) {
|
|||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((frame_buffer[0] & I2C_STATE_BYTE1_BUSY) == 0) {
|
if ((frame_buffer[0] & I2C_STATE_BYTE1_RESP_RDY) != 0) {
|
||||||
|
// There is a response that needs to be flushed out.
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((frame_buffer[0] & I2C_STATE_BYTE1_BUSY) == 0) {
|
||||||
|
// Not busy and no response that would need to be flushed out.
|
||||||
|
return OPTIGA_SUCCESS;
|
||||||
|
}
|
||||||
ret = OPTIGA_ERR_BUSY;
|
ret = OPTIGA_ERR_BUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ret != OPTIGA_SUCCESS) {
|
if (ret != OPTIGA_SUCCESS) {
|
||||||
|
// Optiga is busy even after maximum retries at reading the I2C state.
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((frame_buffer[0] & I2C_STATE_BYTE1_RESP_RDY) == 0) {
|
|
||||||
return OPTIGA_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Flush out the previous response.
|
// Flush out the previous response.
|
||||||
|
|
||||||
uint16_t size = (frame_buffer[2] << 8) + frame_buffer[3];
|
uint16_t size = (frame_buffer[2] << 8) + frame_buffer[3];
|
||||||
@ -404,6 +407,13 @@ static optiga_result optiga_read(void) {
|
|||||||
|
|
||||||
return OPTIGA_SUCCESS;
|
return OPTIGA_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ((frame_buffer[0] & I2C_STATE_BYTE1_BUSY) == 0) {
|
||||||
|
// Optiga has no response ready and is not busy. This shouldn't happen if
|
||||||
|
// we are expecting to read a response, but Optiga occasionally fails to
|
||||||
|
// give any response to a command.
|
||||||
|
return OPTIGA_ERR_UNEXPECTED;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return OPTIGA_ERR_TIMEOUT;
|
return OPTIGA_ERR_TIMEOUT;
|
||||||
|
Loading…
Reference in New Issue
Block a user