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