use crate::{BaseClass, Interface, SubClass};
use core::convert::TryFrom;
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum DeviceType {
Unknown,
LegacyVgaCompatible,
LegacyNotVgaCompatible,
ScsiBusController,
IdeController,
FloppyController,
IpiBusController,
RaidController,
AtaController,
SataController,
SasController,
NvmeController,
UfsController,
OtherMassStorageController,
EthernetController,
TokenRingController,
FddiController,
AtmController,
IsdnController,
WorldFipController,
PicmgController,
OtherNetworkController,
VgaCompatibleController,
XgaController,
ThreeDController,
OtherDisplayController,
VideoDevice,
AudioDevice,
TelephonyDevice,
OtherMultimediaDevice,
RamController,
FlashController,
OtherMemoryController,
HostBridge,
IsaBridge,
EisaBridge,
McaBridge,
PciPciBridge,
PcmciaBridge,
NuBusBridge,
CardBusBridge,
RacewayBridge,
SemiTransparentPciPciBridge,
InfinibandPciHostBridge,
OtherBridgeDevice,
SerialController,
ParallelPort,
MultiportSerialController,
Modem,
GpibController,
SmartCard,
OtherCommunicationsDevice,
InterruptController,
DmaController,
SystemTimer,
RtcController,
GenericPciHotPlugController,
SdHostController,
OtherSystemPeripheral,
KeyboardController,
Digitizer,
MouseController,
ScannerController,
GameportController,
OtherInputController,
GenericDockingStation,
OtherDockingStation,
Processor386,
Processor486,
ProcessorPentium,
ProcessorAlpha,
ProcessorPowerPc,
ProcessorMips,
CoProcessor,
FirewireController,
AccessBusController,
SsaBusController,
UsbController,
FibreChannelController,
SmBusController,
InfiniBandController,
IpmiController,
SercosController,
CanBusController,
IrdaController,
ConsumerIrController,
RfController,
BluetoothController,
BroadbandController,
Ethernet5GHzController,
Ethernet24GHzController,
OtherWirelessController,
IntelligentIoController,
TvSatelliteCommunicationsController,
AudioSatelliteCommunicationsController,
VoiceSatelliteCommunicationsController,
DataSatelliteCommunicationsController,
NetworkCryptionController,
EntertainmentCryptionController,
OtherCryptionController,
DpioModule,
PerformanceCounter,
CommunicationsSynchronizationController,
ManagementCard,
OtherSignalProcessingController,
}
impl From<(BaseClass, SubClass)> for DeviceType {
fn from(class: (BaseClass, SubClass)) -> Self {
match class {
(0x00, 0x00) => DeviceType::LegacyNotVgaCompatible,
(0x00, 0x01) => DeviceType::LegacyVgaCompatible,
(0x01, 0x00) => DeviceType::ScsiBusController,
(0x01, 0x01) => DeviceType::IdeController,
(0x01, 0x02) => DeviceType::FloppyController,
(0x01, 0x03) => DeviceType::IpiBusController,
(0x01, 0x04) => DeviceType::RaidController,
(0x01, 0x05) => DeviceType::AtaController,
(0x01, 0x06) => DeviceType::SataController,
(0x01, 0x07) => DeviceType::SasController,
(0x01, 0x08) => DeviceType::NvmeController,
(0x01, 0x09) => DeviceType::UfsController,
(0x01, 0x80) => DeviceType::OtherMassStorageController,
(0x02, 0x00) => DeviceType::EthernetController,
(0x02, 0x01) => DeviceType::TokenRingController,
(0x02, 0x02) => DeviceType::FddiController,
(0x02, 0x03) => DeviceType::AtmController,
(0x02, 0x04) => DeviceType::IsdnController,
(0x02, 0x06) => DeviceType::PicmgController,
(0x02, 0x80) => DeviceType::OtherNetworkController,
(0x03, 0x00) => DeviceType::VgaCompatibleController,
(0x03, 0x01) => DeviceType::XgaController,
(0x03, 0x02) => DeviceType::ThreeDController,
(0x03, 0x80) => DeviceType::OtherDisplayController,
(0x04, 0x00) => DeviceType::VideoDevice,
(0x04, 0x01) => DeviceType::AudioDevice,
(0x04, 0x02) => DeviceType::TelephonyDevice,
(0x04, 0x03) => DeviceType::OtherMultimediaDevice,
(0x05, 0x00) => DeviceType::RamController,
(0x05, 0x01) => DeviceType::FlashController,
(0x05, 0x02) => DeviceType::OtherMemoryController,
(0x06, 0x00) => DeviceType::HostBridge,
(0x06, 0x01) => DeviceType::IsaBridge,
(0x06, 0x02) => DeviceType::EisaBridge,
(0x06, 0x03) => DeviceType::McaBridge,
(0x06, 0x04) => DeviceType::PciPciBridge,
(0x06, 0x05) => DeviceType::PcmciaBridge,
(0x06, 0x06) => DeviceType::NuBusBridge,
(0x06, 0x07) => DeviceType::CardBusBridge,
(0x06, 0x08) => DeviceType::RacewayBridge,
(0x06, 0x09) => DeviceType::SemiTransparentPciPciBridge,
(0x06, 0x0a) => DeviceType::InfinibandPciHostBridge,
(0x06, 0x80) => DeviceType::OtherBridgeDevice,
(0x07, 0x00) => DeviceType::SerialController,
(0x07, 0x01) => DeviceType::ParallelPort,
(0x07, 0x02) => DeviceType::MultiportSerialController,
(0x07, 0x03) => DeviceType::Modem,
(0x07, 0x04) => DeviceType::GpibController,
(0x07, 0x05) => DeviceType::SmartCard,
(0x07, 0x80) => DeviceType::OtherCommunicationsDevice,
(0x08, 0x00) => DeviceType::InterruptController,
(0x08, 0x01) => DeviceType::DmaController,
(0x08, 0x02) => DeviceType::SystemTimer,
(0x08, 0x03) => DeviceType::RtcController,
(0x08, 0x04) => DeviceType::GenericPciHotPlugController,
(0x08, 0x05) => DeviceType::SdHostController,
(0x08, 0x80) => DeviceType::OtherSystemPeripheral,
(0x09, 0x00) => DeviceType::KeyboardController,
(0x09, 0x01) => DeviceType::Digitizer,
(0x09, 0x02) => DeviceType::MouseController,
(0x09, 0x03) => DeviceType::ScannerController,
(0x09, 0x04) => DeviceType::GameportController,
(0x09, 0x80) => DeviceType::OtherInputController,
(0x0a, 0x00) => DeviceType::GenericDockingStation,
(0x0a, 0x80) => DeviceType::OtherDockingStation,
(0x0b, 0x00) => DeviceType::Processor386,
(0x0b, 0x01) => DeviceType::Processor486,
(0x0b, 0x02) => DeviceType::ProcessorPentium,
(0x0b, 0x10) => DeviceType::ProcessorAlpha,
(0x0b, 0x20) => DeviceType::ProcessorPowerPc,
(0x0b, 0x30) => DeviceType::ProcessorMips,
(0x0b, 0x40) => DeviceType::CoProcessor,
(0x0c, 0x00) => DeviceType::FirewireController,
(0x0c, 0x01) => DeviceType::AccessBusController,
(0x0c, 0x02) => DeviceType::SsaBusController,
(0x0c, 0x03) => DeviceType::UsbController,
(0x0c, 0x04) => DeviceType::FibreChannelController,
(0x0c, 0x05) => DeviceType::SmBusController,
(0x0c, 0x06) => DeviceType::InfiniBandController,
(0x0c, 0x07) => DeviceType::IpmiController,
(0x0c, 0x08) => DeviceType::SercosController,
(0x0c, 0x09) => DeviceType::CanBusController,
(0x0d, 0x00) => DeviceType::IrdaController,
(0x0d, 0x01) => DeviceType::ConsumerIrController,
(0x0d, 0x10) => DeviceType::RfController,
(0x0d, 0x11) => DeviceType::BluetoothController,
(0x0d, 0x12) => DeviceType::BroadbandController,
(0x0d, 0x20) => DeviceType::Ethernet5GHzController,
(0x0d, 0x21) => DeviceType::Ethernet24GHzController,
(0x0d, 0x80) => DeviceType::OtherWirelessController,
(0x0e, 0x00) => DeviceType::IntelligentIoController,
(0x0f, 0x00) => DeviceType::TvSatelliteCommunicationsController,
(0x0f, 0x01) => DeviceType::AudioSatelliteCommunicationsController,
(0x0f, 0x02) => DeviceType::VoiceSatelliteCommunicationsController,
(0x0f, 0x03) => DeviceType::DataSatelliteCommunicationsController,
(0x10, 0x00) => DeviceType::NetworkCryptionController,
(0x10, 0x10) => DeviceType::EntertainmentCryptionController,
(0x10, 0x80) => DeviceType::OtherCryptionController,
(0x11, 0x00) => DeviceType::DpioModule,
(0x11, 0x01) => DeviceType::PerformanceCounter,
(0x11, 0x10) => DeviceType::CommunicationsSynchronizationController,
(0x11, 0x20) => DeviceType::ManagementCard,
(0x11, 0x80) => DeviceType::OtherSignalProcessingController,
_ => DeviceType::Unknown,
}
}
}
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum UsbType {
Uhci,
Ohci,
Ehci,
Xhci,
OtherInterface,
Device,
}
impl TryFrom<Interface> for UsbType {
type Error = ();
fn try_from(interface: Interface) -> Result<Self, Self::Error> {
match interface {
0x00 => Ok(UsbType::Uhci),
0x10 => Ok(UsbType::Ohci),
0x20 => Ok(UsbType::Ehci),
0x30 => Ok(UsbType::Xhci),
0x80 => Ok(UsbType::OtherInterface),
0xfe => Ok(UsbType::Device),
_ => Err(()),
}
}
}