Commit Graph

154 Commits

Author SHA1 Message Date
Tomas Rezucha
b698de8890 fix(usb): USB security fixes from esp-usb
Combination of the following commits:
- c546816048
- 749af3b938
- 234ed4e9d4
- 8f7fe7308d
2026-03-27 13:56:27 +01:00
Tomas Rezucha
6a7a678e6e fix(host/usb): Fixed deadlock that prevented closing devices from high priority tasks
If in usb_host_interface_release() the underlying pipe was halted while having an URB in-flight,
usb_host_client_handle_events() may not have had a chance to process the URB yet.
Check if there are any pending URBs on the pipe before attempting to free it.

Closes https://github.com/espressif/esp-idf/issues/17707
2026-02-04 08:02:08 +01:00
morris
b6a74a4c3d Merge branch 'fix/usb_phy_pull_override_backport_v5.2' into 'release/v5.2'
fix(usb_phy): Removed pull resistors override configuration for Internal FSLS PHY (backport to v5.2)

See merge request espressif/esp-idf!39214
2025-05-20 17:21:31 +08:00
Roman Leonov
7dd375bd8c fix(usb_phy): Removed pull resistors override configuration for Internal FSLS PHY 2025-05-16 14:26:42 +02:00
Roman Leonov
b2c3c9471e refactor(ext_port): Removed ext_hub dependency 2025-05-06 15:21:07 +02:00
Roman Leonov
c391c835c2 refactor(ext_port): Changed the mechanism for hub class request
Merged all Hub Class specific request to one function.
Added a callback for the External Port Driver to break the dependency from ext_hub.h
2025-05-06 15:00:50 +02:00
Roman Leonov
9c98a17a0d feat(ext_hub): Added device error handling 2025-05-06 14:17:29 +02:00
Roman Leonov
dacb29e076 feat(usbh): Added uid presence check in USBH device object list 2025-05-06 14:17:29 +02:00
Roman Leonov
48219a59f4 fix(usb_host): Correctly initialize set pipe ep char 2025-04-23 09:51:00 +02:00
Roman Leonov
f17c71455d fix(hcd): Added delay to slow down scatter-gather dma for ls device via fs hubs 2025-04-23 09:50:26 +02:00
igor.masar
5609df4096 fix(usb_host): Fix return code and description
Changed error code from ESP_ERR_INVALID_STATE to ESP_ERR_NOT_FOUND
when the client never opened the device.
Updated function documentation to correctly reflect return values.
2025-03-31 23:44:37 +02:00
Myk Melez
a40a50998e fix(usb_host): Give semaphore on attempted close of non-opened device
If you call *usb_host_device_close()* for a device that isn't open, the function exits early,
without giving back the semaphore it took, which causes any other call that tries to take
that semaphore to hang indefinitely.

Strangely, there's redundant handling of this condition, with two checks in a row that both handle
the case where `_check_client_opened_device(client_obj, dev_addr)` returns `false`:

```c
    HOST_CHECK_FROM_CRIT(_check_client_opened_device(client_obj, dev_addr), ESP_ERR_NOT_FOUND);
    if (!_check_client_opened_device(client_obj, dev_addr)) {
        // Client never opened this device
        ret = ESP_ERR_INVALID_STATE;
        HOST_EXIT_CRITICAL();
        goto exit;
    }
…
exit:
    xSemaphoreGive(p_host_lib_obj->constant.mux_lock);
    return ret;
```

The first line is the one that exits early, as HOST_CHECK_FROM_CRIT returns its second parameter
if its first parameter is false, without giving back the semaphore (although it does exit
the critical section).

The subsequent block handles the exact same case, except that it ensures the semaphore is given
back before returning. Currently, this block is never reached.

Perhaps the first check was added, then someone noticed the issue and added the second check,
but they forgot to remove the first one.

In any case, this PR removes the first check, so the second check can properly handle this case
by giving back the semaphore before returning.

This bug appears to have been present in the initial commit of the USB Host library to the ESP-IDF
repo: accbaee57c

Of course, if you never try to close a non-opened device, then you won't encounter it!
Unfortunately, I have some code that tried to do that, which is how I found the issue.
2025-03-31 23:44:37 +02:00
Roman Leonov
44f09c470b fix(usb_host): Fixed unchecked return value in enum driver (coverity) 2025-01-29 12:56:02 +01:00
Roman Leonov
7c56120be1 feat(hub): Added notification when hubs support is disabled 2024-12-05 10:32:52 +01:00
morris
1a49691899 Merge branch 'feature/usb_host_hub_support_collective_backport_p3_v5.2' into 'release/v5.2'
feat(usb_host): Hub Support Collective backport part 3/3 (v5.2)

See merge request espressif/esp-idf!33283
2024-11-20 10:40:09 +08:00
Daniel Mangum
38e9c8dbdf fix(usb_host): return ESP_ERR_NO_MEM on failed alloc in client register
Fixes issue where ESP_ERR_NO_MEM was being silently discarded after
cleaning up after a failed malloc in usb_host_client_register.

Signed-off-by: Daniel Mangum <georgedanielmangum@gmail.com>
2024-11-13 10:03:08 +01:00
Roman Leonov
1618fd8a0f refactor(usb_host): Removed error in enum when stalled, added hcd_dwc no more free channels 2024-10-25 12:31:39 +02:00
Roman Leonov
bb23c18edd fix(ext_port): Added port recovery delay 2024-10-25 12:30:31 +02:00
Roman Leonov
d83c477422 refactor(usb_host/examples): Enabled external Hub support feature 2024-10-18 10:46:53 +02:00
Roman Leonov
e62df280e0 feat(ext_port): Added External Port driver 2024-10-18 10:46:51 +02:00
morris
dc45972144 Merge branch 'feat/usb_disconnect_api_backport_v5.2' into 'release/v5.2'
refactor(usb): Update HCD tests to use port power off for disconnections backport v5.2

See merge request espressif/esp-idf!33526
2024-10-17 17:00:59 +08:00
Peter Marcisovsky
7aece79530 fix(usb_host): Update log level and error poropagation 2024-10-10 12:51:06 +02:00
Peter Marcisovsky
f02ee8ef5d refactor(usb_host): Fixed function return values in usb_host stack:
- updated doxygen for the whole usb_host stack
    - doxygen for test_apps is not updated
    - fixed error codes propagation problems in the usb_host stack
2024-10-10 12:51:06 +02:00
Tomas Rezucha
d2a8b5e577 fix(usb/host): Correctly handle unpowered port in HUB 2024-10-09 11:16:17 +02:00
Darian Leung
62a3b50c94 refactor(usb): Remove use of usb_phy_action() from unit tests
Currently, USB Host unit tests that require a software triggered disconnection/
reconnection rely on the 'usb_phy_action()' function.

This commit replaces those calls with 'hcd_port_command()' or
'usb_host_lib_set_root_port_power()'.

Note: Also removed 'test_usb_common.h/c' as it is no longer necessary are the
function call replacements.
2024-10-09 11:16:17 +02:00
Darian Leung
dc838f6123 feat(usb): Add usb_host_lib_set_root_port_power()
This commit adds the usb_host_lib_set_root_port_power() function. This provides
a public API for users to power the root port OFF or ON at runtime, thus trigger
a disconnection or allow connections respectively.

In addition, the usb_host_config_t.root_port_unpowered install configuration is
provided to allow users to install the USB Host Library without automatically
powering ON the root port.
2024-10-09 11:16:17 +02:00
Roman Leonov
e1feca0d48 refactor(hub): Cleaned up dev_tree_node debug output, moved node freeing 2024-09-06 22:53:50 +02:00
Roman Leonov
3d2edb47bb refactor(ext_hub): Prerequisites for the Ext Port Driver 2024-09-06 10:37:01 +02:00
Roman Leonov
5b346ca9d8 fix(usb_host): The Enumeration Driver, cancellation on error 2024-09-06 10:37:01 +02:00
Roman Leonov
ec6f52a717 feat(ext_hub): Added External Hub driver 2024-09-06 10:02:38 +02:00
Roman Leonov
59be21b763 fix(usb_host): Increased address map for clients and changed the uid member type 2024-09-06 10:02:37 +02:00
Tomas Rezucha
9f0ef05192 fix(enum): Returned usb_round_up_to_mps for control request of string descriptors 2024-09-06 10:02:37 +02:00
Roman Leonov
38bb90dd9a feat(hub): Added device tree nodes list and uid calculation logic 2024-09-06 10:02:37 +02:00
Roman Leonov
c5ee01dd0b fix(enum): Fixed STALL on descriptor request, removed unused value 2024-09-06 10:02:37 +02:00
Roman Leonov
410a6a21c5 refactor(enum): Curved out Enumeration process from Hub Driver 2024-09-06 10:02:37 +02:00
Roman Leonov
284b978cb4 refactor(hub): Updated HUB api for ENUM driver 2024-09-06 10:02:37 +02:00
Roman Leonov
30681356d8 refactor(usbh): Updated USBH api for ENUM driver 2024-09-06 10:02:37 +02:00
Alexey Lapshin
3759f41b94 fix(usb): fix warnings found by GNU static analyzer 2024-08-21 14:05:31 +07:00
morris
a536949363 Merge branch 'feature/usb_host_multi_configuration_backport_v5.2' into 'release/v5.2'
feat(usb/host): multiconfiguration support backport (v5.2)

See merge request espressif/esp-idf!32055
2024-08-02 11:44:12 +08:00
Peter Marcisovsky
597451afbe refactor(usb_host): Update USB Host multiconfig public API
- previous usb_host_get_config_desc_free()
    - updated usb_host_free_config_desc()
2024-07-17 09:02:43 +02:00
Tomas Rezucha
440f3308ab fix(usb/host): Fix occasional ISOC scheduler skipping transfers 2024-07-12 08:18:42 +02:00
Peter Marcisovsky
8611a66a0f feat(usb/host): multiconfiguration support
- usb host reads device's configuration on request
    - a control transfer is sent
    - memory is allocated for a new descriptor
    - user must manually free the memory
2024-07-11 11:28:52 +02:00
Tomas Rezucha
49d9fc0250 fix(usb/host): Decode error flags in ISOC transfers 2024-07-03 09:15:53 +02:00
Darian Leung
ae9a280ca1 fix(usb): Make string descriptor checks in unit tests optional
Checking for an exact match for product or serial and string descriptors can
lead to test failures if the USB devices connected to the runner is changed. This
commit adds some kconfig options to make the string descriptor checks optional,
with the product and serial string checks being disabled by default.
2024-06-09 12:36:25 +08:00
Darian Leung
6ead402d15 refactor(usb): Split test device descriptors from mock class files
Previously, descriptors of the test devices were stored direclty in the mock
device files (e.g., "mock_[hid|msc].[h|c]"). This commit splits out the device
descriptors to separate files (e.g., "dev_[hid|msc].c") along with getter
functions.

Users that want to run the tests locally on a different device simply need to
update the "dev_[hid|msc].c" file for their device.
2024-06-09 12:19:53 +08:00
Darian Leung
edd41c24c3 refactor(usb): Rename mock class files
- Rename "test_usb_mock_..." class files to "mock_..."
- Fixed some codespell issues
- Fixed comment spacing
2024-06-09 11:30:03 +08:00
morris
f0a69d8a0c Merge branch 'feature/usb_host_hub_support_collective_backport_v5.2' into 'release/v5.2'
refactor(usb/host): Prerequisite Refactoring For Hub Collective backport (v5.2)

See merge request espressif/esp-idf!29448
2024-06-07 13:12:51 +08:00
Darian Leung
36de16d97c refactor(hal/usb): Add new USB PHY related HAL API
This commit adds/updates the USB PHY related HAL APIs. The following changes
are made:

- Updated 'usb_wrap_hal.h' API
- Added 'usb_serial_jtag_hal.h' API
2024-06-04 20:35:49 +08:00
Darian Leung
d944e85a57 feat(hal/usb): Update USB WRAP and USJ LL
- Added LL cap macros to distinguish feature differences between the LLs of
  different targets:
    - '..._LL_EXT_PHY_SUPPORTED' indicates whether the USB WRAP/USJ supports
      routing to an external FSLS PHY.
- Tidied up some RCC LL functions and their callers.
- Added 'usb_wrap_types.h' and 'usb_serial_jtag_types.h' to provide types used
  in LLs.
- Fixed some spelling/naming issues as part of code-spell pre-commit
2024-06-04 20:35:49 +08:00
Darian Leung
14a581939c refactor(hal/usb): Refactor usb_wrap_ll.h
This commit rewrite the 'usb_wrap_ll.h' API as follows:

- All APIs renamed from 'usb_fsls_phy_ll_...()' to 'usb_wrap_ll_...()'
- APIs now match their equivalent counter parts in 'usb_serial_jtag_ll.h'
2024-06-04 20:35:48 +08:00