summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2025-05-16 10:25:28 +0200
committerGitHub <[email protected]>2025-05-16 10:25:28 +0200
commit531fb695312b0e1cdade446b68d7049053897405 (patch)
treeae5ab2802b64e4a952beadff040ade53629d7967 /src/class
parent9548d51c7ec3a2c8d42058e366561f7552cf1c1d (diff)
parenta2117d5d0fb0eea1f76fe7db25642df7a9c83324 (diff)
Merge pull request #3118 from ZakDanger/vendor_device_fix
vendor device open fix for descriptor parsing
Diffstat (limited to 'src/class')
-rw-r--r--src/class/vendor/vendor_device.c32
1 files changed, 12 insertions, 20 deletions
diff --git a/src/class/vendor/vendor_device.c b/src/class/vendor/vendor_device.c
index 2fc0ac944..0f0b0cbb2 100644
--- a/src/class/vendor/vendor_device.c
+++ b/src/class/vendor/vendor_device.c
@@ -197,7 +197,7 @@ void vendord_reset(uint8_t rhport) {
uint16_t vendord_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint16_t max_len) {
TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == desc_itf->bInterfaceClass, 0);
const uint8_t* p_desc = tu_desc_next(desc_itf);
- const uint8_t* desc_end = (uint8_t const*)desc_itf + max_len;
+ const uint8_t* desc_end = (const uint8_t*)desc_itf + max_len;
// Find available interface
vendord_interface_t* p_vendor = NULL;
@@ -210,26 +210,18 @@ uint16_t vendord_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uin
TU_VERIFY(p_vendor, 0);
p_vendor->itf_num = desc_itf->bInterfaceNumber;
- uint8_t found_ep = 0;
- while (found_ep < desc_itf->bNumEndpoints) {
- // skip non-endpoint descriptors
- while ( (TUSB_DESC_ENDPOINT != tu_desc_type(p_desc)) && (p_desc < desc_end) ) {
- p_desc = tu_desc_next(p_desc);
- }
- if (p_desc >= desc_end) {
- break;
- }
-
- const tusb_desc_endpoint_t* desc_ep = (const tusb_desc_endpoint_t*) p_desc;
- TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
- found_ep++;
+ while (TUSB_DESC_INTERFACE != tu_desc_type(p_desc) && (desc_end - p_desc > 0)) {
+ if (TUSB_DESC_ENDPOINT == tu_desc_type(p_desc)) {
+ const tusb_desc_endpoint_t* desc_ep = (const tusb_desc_endpoint_t*) p_desc;
+ TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
- if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
- tu_edpt_stream_open(&p_vendor->tx.stream, desc_ep);
- tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
- } else {
- tu_edpt_stream_open(&p_vendor->rx.stream, desc_ep);
- TU_ASSERT(tu_edpt_stream_read_xfer(rhport, &p_vendor->rx.stream) > 0, 0); // prepare for incoming data
+ if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
+ tu_edpt_stream_open(&p_vendor->tx.stream, desc_ep);
+ tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
+ } else {
+ tu_edpt_stream_open(&p_vendor->rx.stream, desc_ep);
+ TU_ASSERT(tu_edpt_stream_read_xfer(rhport, &p_vendor->rx.stream) > 0, 0); // prepare for incoming data
+ }
}
p_desc = tu_desc_next(p_desc);