Skip to content

Commit

Permalink
Merge pull request #32 from kevinmehall/win-mfg
Browse files Browse the repository at this point in the history
windows: Stop returning manufacturer string
  • Loading branch information
kevinmehall authored Jan 15, 2024
2 parents c1232a6 + 462edbe commit cfbfee0
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 24 deletions.
16 changes: 11 additions & 5 deletions src/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
24 changes: 5 additions & 19 deletions src/platform/windows_winusb/enumeration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
};
Expand Down Expand Up @@ -42,23 +42,9 @@ pub fn probe_device(devinst: DevInst) -> Option<DeviceInfo> {
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::<OsString>(DEVPKEY_Device_BusReportedDeviceDesc)
.and_then(|s| s.into_string().ok())
} else {
None
};

let manufacturer_string = if info.DeviceDescriptor.iProduct != 0 {
devinst
.get_property::<OsString>(DEVPKEY_Device_Manufacturer)
.and_then(|s| s.into_string().ok())
} else {
None
};
let product_string = devinst
.get_property::<OsString>(DEVPKEY_Device_BusReportedDeviceDesc)
.and_then(|s| s.into_string().ok());

let serial_number = if info.DeviceDescriptor.iSerialNumber != 0 {
(&instance_id)
Expand Down Expand Up @@ -116,7 +102,7 @@ pub fn probe_device(devinst: DevInst) -> Option<DeviceInfo> {
subclass: info.DeviceDescriptor.bDeviceSubClass,
protocol: info.DeviceDescriptor.bDeviceProtocol,
speed: map_speed(info.Speed),
manufacturer_string,
manufacturer_string: None,
product_string,
serial_number,
interfaces,
Expand Down

0 comments on commit cfbfee0

Please sign in to comment.