Skip to content

Commit 531fb69

Browse files
authored
Merge pull request #3118 from ZakDanger/vendor_device_fix
vendor device open fix for descriptor parsing
2 parents 9548d51 + a2117d5 commit 531fb69

File tree

1 file changed

+13
-21
lines changed

1 file changed

+13
-21
lines changed

src/class/vendor/vendor_device.c

+13-21
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ void vendord_reset(uint8_t rhport) {
197197
uint16_t vendord_open(uint8_t rhport, const tusb_desc_interface_t* desc_itf, uint16_t max_len) {
198198
TU_VERIFY(TUSB_CLASS_VENDOR_SPECIFIC == desc_itf->bInterfaceClass, 0);
199199
const uint8_t* p_desc = tu_desc_next(desc_itf);
200-
const uint8_t* desc_end = (uint8_t const*)desc_itf + max_len;
200+
const uint8_t* desc_end = (const uint8_t*)desc_itf + max_len;
201201

202202
// Find available interface
203203
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
210210
TU_VERIFY(p_vendor, 0);
211211

212212
p_vendor->itf_num = desc_itf->bInterfaceNumber;
213-
uint8_t found_ep = 0;
214-
while (found_ep < desc_itf->bNumEndpoints) {
215-
// skip non-endpoint descriptors
216-
while ( (TUSB_DESC_ENDPOINT != tu_desc_type(p_desc)) && (p_desc < desc_end) ) {
217-
p_desc = tu_desc_next(p_desc);
218-
}
219-
if (p_desc >= desc_end) {
220-
break;
221-
}
222-
223-
const tusb_desc_endpoint_t* desc_ep = (const tusb_desc_endpoint_t*) p_desc;
224-
TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
225-
found_ep++;
226-
227-
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
228-
tu_edpt_stream_open(&p_vendor->tx.stream, desc_ep);
229-
tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
230-
} else {
231-
tu_edpt_stream_open(&p_vendor->rx.stream, desc_ep);
232-
TU_ASSERT(tu_edpt_stream_read_xfer(rhport, &p_vendor->rx.stream) > 0, 0); // prepare for incoming data
213+
while (TUSB_DESC_INTERFACE != tu_desc_type(p_desc) && (desc_end - p_desc > 0)) {
214+
if (TUSB_DESC_ENDPOINT == tu_desc_type(p_desc)) {
215+
const tusb_desc_endpoint_t* desc_ep = (const tusb_desc_endpoint_t*) p_desc;
216+
TU_ASSERT(usbd_edpt_open(rhport, desc_ep));
217+
218+
if (tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN) {
219+
tu_edpt_stream_open(&p_vendor->tx.stream, desc_ep);
220+
tud_vendor_n_write_flush((uint8_t)(p_vendor - _vendord_itf));
221+
} else {
222+
tu_edpt_stream_open(&p_vendor->rx.stream, desc_ep);
223+
TU_ASSERT(tu_edpt_stream_read_xfer(rhport, &p_vendor->rx.stream) > 0, 0); // prepare for incoming data
224+
}
233225
}
234226

235227
p_desc = tu_desc_next(p_desc);

0 commit comments

Comments
 (0)