From 77cdf4b43c8630878b8fb8ad4c362ba2a7ed5a47 Mon Sep 17 00:00:00 2001 From: Ondrej Mikle Date: Tue, 30 Aug 2022 13:56:00 +0200 Subject: [PATCH] fix(core): consider device in USB suspend connected if it was configured before [no changelog] --- core/embed/trezorhal/usb.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/embed/trezorhal/usb.c b/core/embed/trezorhal/usb.c index bae24dd88..45a66bc4c 100644 --- a/core/embed/trezorhal/usb.c +++ b/core/embed/trezorhal/usb.c @@ -153,11 +153,19 @@ void usb_start(void) { USBD_Start(&usb_dev_handle); } void usb_stop(void) { USBD_Stop(&usb_dev_handle); } secbool usb_configured(void) { - USBD_HandleTypeDef *pdev = &usb_dev_handle; + const USBD_HandleTypeDef *pdev = &usb_dev_handle; if (pdev->dev_state == USBD_STATE_CONFIGURED) { return sectrue; } + // Linux has autosuspend device after 2 seconds by default. + // So a suspended device that was seen as configured is reported as + // configured. + if (pdev->dev_state == USBD_STATE_SUSPENDED && + pdev->dev_old_state == USBD_STATE_CONFIGURED) { + return sectrue; + } + return secfalse; }