From 462edbe4a5fa63ed48aa52e29810f3151d877aea Mon Sep 17 00:00:00 2001 From: Kevin Mehall Date: Mon, 15 Jan 2024 13:48:36 -0700 Subject: [PATCH] windows: Stop returning manufacturer string This comes from the INF used to install the driver, not the descriptor. --- src/enumeration.rs | 16 ++++++++++----- src/platform/windows_winusb/enumeration.rs | 24 +++++----------------- 2 files changed, 16 insertions(+), 24 deletions(-) diff --git a/src/enumeration.rs b/src/enumeration.rs index 59f656e..6fa8f05 100644 --- a/src/enumeration.rs +++ b/src/enumeration.rs @@ -167,23 +167,29 @@ impl DeviceInfo { self.speed } - /// Manufacturer string, if available without device IO + /// Manufacturer string, if available without device IO. /// /// ### Platform-specific notes - /// * Windows: this comes from the driver, and for some drivers - /// does not match the string returned from the device. + /// * Windows: Windows does not cache the manufacturer string, and + /// this will return `None` regardless of whether a descriptor exists. #[doc(alias = "iManufacturer")] pub fn manufacturer_string(&self) -> Option<&str> { self.manufacturer_string.as_deref() } - /// Product string, if available without device IO + /// Product string, if available without device IO. #[doc(alias = "iProduct")] pub fn product_string(&self) -> Option<&str> { self.product_string.as_deref() } - /// Serial number string, if available without device IO + /// Serial number string, if available without device IO. + /// + /// ### Platform-specific notes + /// * On Windows, this comes from a case-insensitive instance ID and may + /// have been converted to upper case from the descriptor string. It is + /// recommended to use a [case-insensitive + /// comparison][str::eq_ignore_ascii_case] when matching a device. #[doc(alias = "iSerial")] pub fn serial_number(&self) -> Option<&str> { self.serial_number.as_deref() diff --git a/src/platform/windows_winusb/enumeration.rs b/src/platform/windows_winusb/enumeration.rs index 10102f7..df85a6d 100644 --- a/src/platform/windows_winusb/enumeration.rs +++ b/src/platform/windows_winusb/enumeration.rs @@ -8,7 +8,7 @@ use windows_sys::Win32::Devices::{ Properties::{ DEVPKEY_Device_Address, DEVPKEY_Device_BusNumber, DEVPKEY_Device_BusReportedDeviceDesc, DEVPKEY_Device_CompatibleIds, DEVPKEY_Device_HardwareIds, DEVPKEY_Device_InstanceId, - DEVPKEY_Device_Manufacturer, DEVPKEY_Device_Parent, DEVPKEY_Device_Service, + DEVPKEY_Device_Parent, DEVPKEY_Device_Service, }, Usb::{GUID_DEVINTERFACE_USB_DEVICE, USB_DEVICE_SPEED}, }; @@ -42,23 +42,9 @@ pub fn probe_device(devinst: DevInst) -> Option { let hub_port = HubPort::by_child_devinst(devinst).ok()?; let info = hub_port.get_node_connection_info().ok()?; - // Windows sets some device properties from string descriptors read at enumeration, - // but if the device doesn't set the descriptor, we don't want the value Windows made up. - let product_string = if info.DeviceDescriptor.iProduct != 0 { - devinst - .get_property::(DEVPKEY_Device_BusReportedDeviceDesc) - .and_then(|s| s.into_string().ok()) - } else { - None - }; - - let manufacturer_string = if info.DeviceDescriptor.iProduct != 0 { - devinst - .get_property::(DEVPKEY_Device_Manufacturer) - .and_then(|s| s.into_string().ok()) - } else { - None - }; + let product_string = devinst + .get_property::(DEVPKEY_Device_BusReportedDeviceDesc) + .and_then(|s| s.into_string().ok()); let serial_number = if info.DeviceDescriptor.iSerialNumber != 0 { (&instance_id) @@ -116,7 +102,7 @@ pub fn probe_device(devinst: DevInst) -> Option { subclass: info.DeviceDescriptor.bDeviceSubClass, protocol: info.DeviceDescriptor.bDeviceProtocol, speed: map_speed(info.Speed), - manufacturer_string, + manufacturer_string: None, product_string, serial_number, interfaces,