From e1d52dc01726e6cfb763be632045d1319f7511f6 Mon Sep 17 00:00:00 2001 From: Quin Chou Date: Wed, 20 Aug 2025 11:53:12 +0800 Subject: [PATCH] usbhub: Print firmware version of usb hub For example on Framework Desktop: [...] USB Hub RTL5424 Firmware Version: 1.8.8 [...] --- framework_lib/src/commandline/mod.rs | 5 +++++ framework_lib/src/lib.rs | 2 ++ framework_lib/src/usbhub.rs | 26 ++++++++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 framework_lib/src/usbhub.rs diff --git a/framework_lib/src/commandline/mod.rs b/framework_lib/src/commandline/mod.rs index 06edb01..646ea8d 100644 --- a/framework_lib/src/commandline/mod.rs +++ b/framework_lib/src/commandline/mod.rs @@ -60,6 +60,8 @@ use crate::touchpad::print_touchpad_fw_ver; use crate::touchscreen; #[cfg(feature = "uefi")] use crate::uefi::enable_page_break; +#[cfg(feature = "rusb")] +use crate::usbhub::check_usbhub_version; use crate::util::{self, Config, Platform, PlatformFamily}; #[cfg(feature = "hidapi")] use hidapi::HidApi; @@ -705,6 +707,9 @@ fn print_versions(ec: &CrosEc) { #[cfg(feature = "rusb")] let _ignore_err = check_camera_version(); + #[cfg(feature = "rusb")] + let _ignore_err = check_usbhub_version(); + #[cfg(feature = "rusb")] let _ignore_err = check_inputmodule_version(); diff --git a/framework_lib/src/lib.rs b/framework_lib/src/lib.rs index 05adf8f..f205403 100644 --- a/framework_lib/src/lib.rs +++ b/framework_lib/src/lib.rs @@ -25,6 +25,8 @@ pub mod touchpad; pub mod touchscreen; #[cfg(all(feature = "hidapi", windows))] pub mod touchscreen_win; +#[cfg(feature = "rusb")] +pub mod usbhub; #[cfg(feature = "uefi")] #[macro_use] diff --git a/framework_lib/src/usbhub.rs b/framework_lib/src/usbhub.rs new file mode 100644 index 0000000..53f2557 --- /dev/null +++ b/framework_lib/src/usbhub.rs @@ -0,0 +1,26 @@ +pub const REALTEK_VID: u16 = 0x0BDA; +pub const RTL5432_PID: u16 = 0x5432; +pub const RTL5424_PID: u16 = 0x5424; + +/// Get and print the firmware version of the usbhub +pub fn check_usbhub_version() -> Result<(), rusb::Error> { + for dev in rusb::devices().unwrap().iter() { + let dev_descriptor = dev.device_descriptor().unwrap(); + if dev_descriptor.vendor_id() != REALTEK_VID + || (dev_descriptor.product_id() != RTL5432_PID + && dev_descriptor.product_id() != RTL5424_PID) + { + debug!( + "Skipping {:04X}:{:04X}", + dev_descriptor.vendor_id(), + dev_descriptor.product_id() + ); + continue; + } + + let dev_descriptor = dev.device_descriptor()?; + println!("USB Hub RTL{:04X}", dev_descriptor.product_id()); + println!(" Firmware Version: {}", dev_descriptor.device_version()); + } + Ok(()) +}