Windows: Fix libusb_get_string_descriptor for HID devices
authorchunyu.xie <xiechunyu88@126.com>
Wed, 8 Mar 2017 10:11:06 +0000 (18:11 +0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Fri, 22 Dec 2017 20:52:44 +0000 (12:52 -0800)
When querying vendor-defined string descriptors, use GetIndexedString
of the HID library.

Closes #279, Closes #280

Signed-off-by: Chris Dickens <christopher.a.dickens@gmail.com>
libusb/os/windows_winusb.c
libusb/os/windows_winusb.h
libusb/version_nano.h

index 93668f3..4b9afbf 100644 (file)
@@ -3113,9 +3113,10 @@ static int _hid_get_config_descriptor(struct hid_device_priv *dev, void *data, s
 }
 
 static int _hid_get_string_descriptor(struct hid_device_priv *dev, int _index,
-       void *data, size_t *size)
+       void *data, size_t *size, HANDLE hid_handle)
 {
        void *tmp = NULL;
+       WCHAR string[MAX_USB_STRING_LENGTH];
        size_t tmp_size = 0;
        int i;
 
@@ -3137,8 +3138,12 @@ static int _hid_get_string_descriptor(struct hid_device_priv *dev, int _index,
                        }
                }
 
-               if (i == 3) // not found
-                       return LIBUSB_ERROR_INVALID_PARAM;
+               if (i == 3) {
+                       if (!HidD_GetIndexedString(hid_handle, _index, string, sizeof(string)))
+                               return LIBUSB_ERROR_INVALID_PARAM;
+                       tmp = string;
+                       tmp_size = (_hid_wcslen(string) + 1) * sizeof(WCHAR);
+               }
        }
 
        if (!tmp_size)
@@ -3259,7 +3264,7 @@ static int _hid_get_descriptor(struct hid_device_priv *dev, HANDLE hid_handle, i
                return LIBUSB_ERROR_INVALID_PARAM;
        case LIBUSB_DT_STRING:
                usbi_dbg("LIBUSB_DT_STRING");
-               return _hid_get_string_descriptor(dev, _index, data, size);
+               return _hid_get_string_descriptor(dev, _index, data, size, hid_handle);
        case LIBUSB_DT_HID:
                usbi_dbg("LIBUSB_DT_HID");
                if (!_index)
@@ -3464,6 +3469,7 @@ static int hid_init(int sub_api, struct libusb_context *ctx)
        DLL_LOAD_FUNC(hid, HidD_GetManufacturerString, TRUE);
        DLL_LOAD_FUNC(hid, HidD_GetProductString, TRUE);
        DLL_LOAD_FUNC(hid, HidD_GetSerialNumberString, TRUE);
+       DLL_LOAD_FUNC(hid, HidD_GetIndexedString, TRUE);
        DLL_LOAD_FUNC(hid, HidP_GetCaps, TRUE);
        DLL_LOAD_FUNC(hid, HidD_SetNumInputBuffers, TRUE);
        DLL_LOAD_FUNC(hid, HidD_SetFeature, TRUE);
index 89ebc24..483425c 100644 (file)
@@ -792,6 +792,7 @@ DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_FreePreparsedData, (PHIDP_PREPARSED_DATA));
 DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_GetManufacturerString, (HANDLE, PVOID, ULONG));
 DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_GetProductString, (HANDLE, PVOID, ULONG));
 DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_GetSerialNumberString, (HANDLE, PVOID, ULONG));
+DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_GetIndexedString, (HANDLE, ULONG, PVOID, ULONG));
 DLL_DECLARE_FUNC(WINAPI, LONG, HidP_GetCaps, (PHIDP_PREPARSED_DATA, PHIDP_CAPS));
 DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_SetNumInputBuffers, (HANDLE, ULONG));
 DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_SetFeature, (HANDLE, PVOID, ULONG));
@@ -800,4 +801,4 @@ DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_GetPhysicalDescriptor, (HANDLE, PVOID, ULONG
 DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_GetInputReport, (HANDLE, PVOID, ULONG));
 DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_SetOutputReport, (HANDLE, PVOID, ULONG));
 DLL_DECLARE_FUNC(WINAPI, BOOL, HidD_FlushQueue, (HANDLE));
-DLL_DECLARE_FUNC(WINAPI, BOOL, HidP_GetValueCaps, (HIDP_REPORT_TYPE, PHIDP_VALUE_CAPS, PULONG, PHIDP_PREPARSED_DATA));
\ No newline at end of file
+DLL_DECLARE_FUNC(WINAPI, BOOL, HidP_GetValueCaps, (HIDP_REPORT_TYPE, PHIDP_VALUE_CAPS, PULONG, PHIDP_PREPARSED_DATA));
index a07841d..8ee4d42 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11221
+#define LIBUSB_NANO 11222