diff options
| author | hathach <[email protected]> | 2026-05-04 13:39:39 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2026-05-04 13:39:39 +0700 |
| commit | e954302c103b4fc6870c6914945e6da1f62f6423 (patch) | |
| tree | dfff4e77a5a122d40f48397273d672b5040646e7 /src/device | |
| parent | 2a8e659bb9422655236accd84e4d1c5e39383adc (diff) | |
fix usbd control to support wLength hack
Diffstat (limited to 'src/device')
| -rw-r--r-- | src/device/usbd.c | 17 | ||||
| -rw-r--r-- | src/device/usbd_pvt.h | 4 |
2 files changed, 8 insertions, 13 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c index f8ec51762..0e58f70bf 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -945,8 +945,7 @@ static bool invoke_class_control(uint8_t rhport, usbd_class_driver_t const * dri return driver->control_xfer_cb(rhport, CONTROL_STAGE_SETUP, request); } -// Process a standard request to the device recipient (extracted from -// process_setup_received for readability; GCC chooses to inline it). +// Process a standard request to the device recipient. static bool process_std_device_request(uint8_t rhport, tusb_control_request_t const * p_request) { switch (p_request->bRequest) { //-V2520 case TUSB_REQ_SET_ADDRESS: @@ -1068,6 +1067,8 @@ static bool process_setup_received(uint8_t rhport, tusb_control_request_t const ctrl_xfer->total_xferred = 0; ctrl_xfer->data_len = 0; ctrl_xfer->complete_cb = NULL; + + p_request = &ctrl_xfer->request; // re-direct request pointer to internal copy (modifiable for hacking) TU_ASSERT(p_request->bmRequestType_bit.type < TUSB_REQ_TYPE_INVALID); // Vendor request @@ -1289,20 +1290,18 @@ static bool process_get_descriptor(uint8_t rhport, tusb_control_request_t const case TUSB_DESC_DEVICE: { TU_LOG_USBD(" Device\r\n"); - void* desc_device = (void*) (uintptr_t) tud_descriptor_device_cb(); + void *desc_device = (void *)(uintptr_t)tud_descriptor_device_cb(); TU_ASSERT(desc_device); // Only response with exactly 1 Packet if: not addressed and host requested more data than device descriptor has. // This only happens with the very first get device descriptor and EP0 size = 8 or 16. if ((CFG_TUD_ENDPOINT0_SIZE < sizeof(tusb_desc_device_t)) && !_usbd_dev.addressed && - ((tusb_control_request_t const*) p_request)->wLength > sizeof(tusb_desc_device_t)) { + p_request->wLength > sizeof(tusb_desc_device_t)) { // Hack here: we modify the request length to prevent usbd_control response with zlp // since we are responding with 1 packet & less data than wLength. - tusb_control_request_t mod_request = *p_request; - mod_request.wLength = CFG_TUD_ENDPOINT0_SIZE; - - return tud_control_xfer(rhport, &mod_request, desc_device, CFG_TUD_ENDPOINT0_SIZE); - }else { + ((tusb_control_request_t *)(uintptr_t)p_request)->wLength = CFG_TUD_ENDPOINT0_SIZE; + return tud_control_xfer(rhport, p_request, desc_device, CFG_TUD_ENDPOINT0_SIZE); + } else { return tud_control_xfer(rhport, p_request, desc_device, sizeof(tusb_desc_device_t)); } } diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index 5f11ea481..be778f9af 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -130,10 +130,6 @@ void usbd_sof_enable(uint8_t rhport, sof_consumer_t consumer, bool en); bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in); void usbd_defer_func(osal_task_func_t func, void *param, bool in_isr); -#if CFG_TUSB_DEBUG >= CFG_TUD_LOG_LEVEL -void usbd_driver_print_control_complete_name(usbd_control_xfer_cb_t callback); -#endif - #ifdef __cplusplus } #endif |
