Added
Link Here
|
0 |
- |
1 |
--- src/libusbhid/HidUps.cpp.orig 2015-02-08 18:00:05 UTC |
|
|
2 |
+++ src/libusbhid/HidUps.cpp |
3 |
@@ -244,6 +244,26 @@ int HidUps::GetIntfDescr( |
4 |
(type << 8) + index, 0, (char*)buf, size, 1000); |
5 |
} |
6 |
|
7 |
+/* Get the interface descriptor's length */ |
8 |
+int HidUps::GetIntfDescrLength(unsigned char index) |
9 |
+{ |
10 |
+ /* usb_hid_descriptor */ |
11 |
+ char buf[9]; |
12 |
+ memset(buf, 0, sizeof(buf)); |
13 |
+ int ret = usb_control_msg(_fd, USB_ENDPOINT_IN | USB_RECIP_INTERFACE, |
14 |
+ USB_REQ_GET_DESCRIPTOR, |
15 |
+ (USB_DT_HID << 8) + index, 0, (char*)buf, sizeof(buf), 1000); |
16 |
+ |
17 |
+ int len = MAX_SANE_DESCRIPTOR_LEN; |
18 |
+ if (ret >= 0) { |
19 |
+ /* wDescriptorLength */ |
20 |
+ int desclen = buf[7] | (buf[8] << 8); |
21 |
+ if (desclen > 0) |
22 |
+ len = desclen; |
23 |
+ } |
24 |
+ return len; |
25 |
+} |
26 |
+ |
27 |
/* |
28 |
* Fetch the report descriptor from the device given an _fd for the |
29 |
* device's control endpoint. Descriptor length is written to the |
30 |
@@ -255,8 +275,9 @@ unsigned char *HidUps::FetchReportDescr(int *rlen) |
31 |
unsigned char *ptr; |
32 |
int rdesclen; |
33 |
|
34 |
- ptr = (unsigned char*)malloc(MAX_SANE_DESCRIPTOR_LEN); |
35 |
- rdesclen = GetIntfDescr(USB_DT_REPORT, 0, ptr, MAX_SANE_DESCRIPTOR_LEN); |
36 |
+ int desclen = GetIntfDescrLength(0); |
37 |
+ ptr = (unsigned char*)malloc(desclen); |
38 |
+ rdesclen = GetIntfDescr(USB_DT_REPORT, 0, ptr, desclen); |
39 |
if (rdesclen <= 0) { |
40 |
Dmsg(100, "Unable to get REPORT descriptor (%d).\n", rdesclen); |
41 |
free(ptr); |