Skip to content

Commit

Permalink
chore: Adds manufactoror on linux
Browse files Browse the repository at this point in the history
  • Loading branch information
dilawar committed Jul 8, 2024
1 parent 9bc62a0 commit 17b2121
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ pub struct UsbDevice {
pub serial_number: Option<String>,
/// Class (bDeviceBaseClass) of device.
pub base_class: Option<DeviceBaseClass>,
/// Class as string
pub class: Option<String>,
/// Manufacturer
pub manufacturer: Option<String>,
}

/// See <https://www.usb.org/defined-class-codes>
#[repr(u8)]
#[derive(Hash, Eq, Debug, Clone, PartialEq, TryFromPrimitive)]
#[allow(dead_code)]
pub enum DeviceBaseClass {
UseClassCodeFromInterfaceDescriptors = 0x00,
Audio = 0x01,
Expand Down
16 changes: 16 additions & 0 deletions src/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,13 +67,29 @@ pub fn enumerate_platform(vid: Option<u16>, pid: Option<u16>) -> Vec<UsbDevice>
.attribute_value("bDeviceClass")
.and_then(|x| x.to_str()?.parse::<u8>().ok());

let friendly_name = device
.property_value("ID_MODEL_FROM_DATABASE")
.and_then(|s| s.to_str())
.map(|x| x.to_string());
let manufacturer = device
.property_value("ID_VENDOR_FROM_DATABASE")
.and_then(|s| s.to_str())
.map(|x| x.to_string());
let class = device
.property_value("ID_PCI_CLASS_FROM_DATABASE")
.and_then(|s| s.to_str())
.map(|x| x.to_string());

output.push(UsbDevice {
id,
vendor_id,
product_id,
description,
serial_number,
base_class: bclass.and_then(|bc| DeviceBaseClass::try_from(bc).ok()),
class,
friendly_name,
manufacturer,
});

Ok(())
Expand Down

0 comments on commit 17b2121

Please sign in to comment.