@@ -50,10 +50,9 @@ static void usbh_hid_class_free(struct usbh_hid *hid_class)
50
50
memset (hid_class , 0 , sizeof (struct usbh_hid ));
51
51
}
52
52
53
- static int usbh_hid_get_report_descriptor (struct usbh_hid * hid_class , uint8_t * buffer )
53
+ int usbh_hid_get_report_descriptor (struct usbh_hid * hid_class , uint8_t * buffer , uint32_t buflen )
54
54
{
55
55
struct usb_setup_packet * setup ;
56
- int ret ;
57
56
58
57
if (!hid_class || !hid_class -> hport ) {
59
58
return - USB_ERR_INVAL ;
@@ -64,14 +63,9 @@ static int usbh_hid_get_report_descriptor(struct usbh_hid *hid_class, uint8_t *b
64
63
setup -> bRequest = USB_REQUEST_GET_DESCRIPTOR ;
65
64
setup -> wValue = HID_DESCRIPTOR_TYPE_HID_REPORT << 8 ;
66
65
setup -> wIndex = hid_class -> intf ;
67
- setup -> wLength = hid_class -> report_size ;
66
+ setup -> wLength = buflen ;
68
67
69
- ret = usbh_control_transfer (hid_class -> hport , setup , g_hid_buf [hid_class -> minor ]);
70
- if (ret < 8 ) {
71
- return ret ;
72
- }
73
- memcpy (buffer , g_hid_buf [hid_class -> minor ], ret - 8 );
74
- return ret ;
68
+ return usbh_control_transfer (hid_class -> hport , setup , buffer );
75
69
}
76
70
77
71
int usbh_hid_set_idle (struct usbh_hid * hid_class , uint8_t report_id , uint8_t duration )
@@ -215,11 +209,6 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
215
209
}
216
210
217
211
hid_class -> report_size = desc -> subdesc [0 ].wDescriptorLength ;
218
-
219
- if (hid_class -> report_size > sizeof (g_hid_buf [hid_class -> minor ])) {
220
- USB_LOG_ERR ("HID report descriptor too large\r\n" );
221
- return - USB_ERR_INVAL ;
222
- }
223
212
found = true;
224
213
goto found ;
225
214
}
@@ -247,7 +236,8 @@ int usbh_hid_connect(struct usbh_hubport *hport, uint8_t intf)
247
236
USB_LOG_WRN ("Do not support set idle\r\n" );
248
237
}
249
238
250
- ret = usbh_hid_get_report_descriptor (hid_class , hid_class -> report_desc );
239
+ /* We read report desc but do nothing (because of too much memory usage for parsing report desc, parsed by users) */
240
+ ret = usbh_hid_get_report_descriptor (hid_class , g_hid_buf [hid_class -> minor ], MIN (sizeof (g_hid_buf [hid_class -> minor ]), hid_class -> report_size ));
251
241
if (ret < 0 ) {
252
242
return ret ;
253
243
}
0 commit comments