Skip to content

Commit 7a54979

Browse files
committed
windows: Allow the library to operate on devices where the hardware IDs are not fully capitalized.
1 parent 5b074f9 commit 7a54979

File tree

1 file changed

+14
-4
lines changed

1 file changed

+14
-4
lines changed

src/windows/device_windows.c

+14-4
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ static libusbp_error * device_allocate(libusbp_device ** device)
2222

2323
// Gets the hardware IDs of the device, in ASCII REG_MULTI_SZ format. If there
2424
// is no error, the returned IDs must be freed with libusbp_string_free.
25+
// This function converts the IDs to uppercase before returning them.
2526
static libusbp_error * device_get_hardware_ids(
2627
HDEVINFO list, PSP_DEVINFO_DATA info, char ** ids)
2728
{
@@ -78,6 +79,19 @@ static libusbp_error * device_get_hardware_ids(
7879
error = error_create("Hardware IDs are empty or not terminated correctly.");
7980
}
8081

82+
// Capitalize the hardware IDs because some drivers create USB IDs with the
83+
// wrong capitalization (i.e. "Vid" instead of "VID").
84+
if (error == NULL)
85+
{
86+
for (DWORD i = 0; i < size; i++)
87+
{
88+
if (new_ids[i] >= 'a' && new_ids[i] <= 'z')
89+
{
90+
new_ids[i] -= 'a' - 'A';
91+
}
92+
}
93+
}
94+
8195
// Pass the IDs to the caller.
8296
if (error == NULL)
8397
{
@@ -117,10 +131,6 @@ static libusbp_error * device_take_info_from_hardware_ids(
117131
}
118132
}
119133

120-
// The format of this device's hardware IDs are not recognized. For
121-
// example, this can happen if VirtualBox is capturing a USB device, because
122-
// it makes a node with hardware IDs that have different capitalization,
123-
// like "USB\Vid_80EE&Pid_CAFE".
124134
return error_create("Device has no hardware ID with the correct format.");
125135
}
126136

0 commit comments

Comments
 (0)