hardware_query/
usb.rs

1use crate::Result;
2use serde::{Deserialize, Serialize};
3
4/// USB device information
5#[derive(Debug, Clone, Serialize, Deserialize)]
6pub struct USBDevice {
7    /// USB vendor ID
8    pub vendor_id: String,
9    /// USB product ID
10    pub product_id: String,
11    /// Vendor name
12    pub vendor_name: String,
13    /// Product name
14    pub product_name: String,
15    /// USB device class
16    pub device_class: String,
17    /// USB version (1.0, 1.1, 2.0, 3.0, etc.)
18    pub usb_version: String,
19    /// Serial number (if available)
20    pub serial_number: Option<String>,
21    /// Bus number
22    pub bus_number: u8,
23    /// Device address
24    pub device_address: u8,
25    /// Port path
26    pub port_path: Option<String>,
27    /// Driver name (if loaded)
28    pub driver: Option<String>,
29    /// Is device currently connected
30    pub connected: bool,
31}
32
33impl USBDevice {
34    /// Query all USB devices
35    pub fn query_all() -> Result<Vec<Self>> {
36        // Platform-specific implementation would go here
37        // For now, return empty vector
38        Ok(vec![])
39    }
40
41    /// Get vendor ID
42    pub fn vendor_id(&self) -> &str {
43        &self.vendor_id
44    }
45
46    /// Get product ID
47    pub fn product_id(&self) -> &str {
48        &self.product_id
49    }
50
51    /// Get vendor name
52    pub fn vendor_name(&self) -> &str {
53        &self.vendor_name
54    }
55
56    /// Get product name
57    pub fn product_name(&self) -> &str {
58        &self.product_name
59    }
60
61    /// Get device class
62    pub fn device_class(&self) -> &str {
63        &self.device_class
64    }
65
66    /// Get USB version
67    pub fn usb_version(&self) -> &str {
68        &self.usb_version
69    }
70
71    /// Check if device is connected
72    pub fn is_connected(&self) -> bool {
73        self.connected
74    }
75
76    /// Check if device is a storage device
77    pub fn is_storage_device(&self) -> bool {
78        self.device_class.to_lowercase().contains("mass storage")
79            || self.device_class.to_lowercase().contains("storage")
80    }
81
82    /// Check if device is an input device
83    pub fn is_input_device(&self) -> bool {
84        self.device_class.to_lowercase().contains("hid")
85            || self.device_class.to_lowercase().contains("human interface")
86            || self.device_class.to_lowercase().contains("input")
87    }
88
89    /// Check if device is an audio device
90    pub fn is_audio_device(&self) -> bool {
91        self.device_class.to_lowercase().contains("audio")
92    }
93
94    /// Check if device is a video device
95    pub fn is_video_device(&self) -> bool {
96        self.device_class.to_lowercase().contains("video")
97            || self.device_class.to_lowercase().contains("camera")
98    }
99
100    /// Check if device supports USB 3.0 or higher
101    pub fn is_high_speed(&self) -> bool {
102        self.usb_version.contains("3.")
103            || self.usb_version.contains("3")
104                && !self.usb_version.contains("2.")
105                && !self.usb_version.contains("1.")
106    }
107}