1#[derive(Debug, Clone, Copy)]
4pub enum Class {
5 ClassInInterface,
7 Audio,
9 Communication,
11 Hid,
13 Physical,
15 StillImaging,
17 Printer,
19 MassStorage,
21 Hub(HubSpeed),
23 CdcData,
25 SmartCard,
27 ContentSecurity,
29 Video,
31 PersonalHealthcare,
33 AudioVideo(AudioVideoType),
35 Billboard,
37 TypeCBridge,
39 BulkDisplayProtocol,
41 MctpOverUsb(MctpType),
43 I3c,
45 Diagnostic(DiagnosticType),
47 Wireless(WirelessType),
49 Miscellaneous(MiscellaneousType),
51 Application(ApplicationType),
53 Vendor,
55 Unknown {
57 class: u8,
58 subclass: u8,
59 protocol: u8,
60 },
61}
62
63#[derive(Debug, Clone, Copy)]
64pub enum HubSpeed {
65 Full,
66 HiSpeedSignalTT,
67 HiSpeedMultipleTTs,
68 Unknown,
69}
70
71#[derive(Debug, Clone, Copy)]
72pub enum AudioVideoType {
73 AvControl,
74 AvDataVideoStreaming,
75 AvDataAudioStreaming,
76}
77
78#[derive(Debug, Clone, Copy)]
79pub enum MctpType {
80 ManagementControllerEndpoint(MctpVersion),
81 HostInterfaceEndpoint(MctpVersion),
82}
83
84#[derive(Debug, Clone, Copy)]
85pub enum MctpVersion {
86 V1x,
87 V2x,
88}
89
90#[derive(Debug, Clone, Copy)]
91pub enum DiagnosticType {
92 Usb2Compliance,
93 DebugTarget(DebugProtocol),
94 Trace(TraceProtocol),
95 Dfx(DfxProtocol),
96 Unknown(u8, u8), }
98
99#[derive(Debug, Clone, Copy)]
100pub enum DebugProtocol {
101 VendorDefined,
102 GnuRemoteDebug,
103}
104
105#[derive(Debug, Clone, Copy)]
106pub enum TraceProtocol {
107 VendorDefined,
108}
109
110#[derive(Debug, Clone, Copy)]
111pub enum DfxProtocol {
112 VendorDefined,
113}
114
115#[derive(Debug, Clone, Copy)]
116pub enum WirelessType {
117 BluetoothProgramming,
118 UwbRadioControl,
119 RemoteNdis,
120 BluetoothAmp,
121 HostWireAdapter(WireAdapterInterface),
122 DeviceWireAdapter(WireAdapterInterface),
123}
124
125#[derive(Debug, Clone, Copy)]
126pub enum WireAdapterInterface {
127 ControlData,
128 Isochronous,
129}
130
131#[derive(Debug, Clone, Copy)]
132pub enum MiscellaneousType {
133 ActiveSync,
134 PalmSync,
135 InterfaceAssociation,
136 WireAdapterMultifunction,
137 CableBasedAssociation,
138 Rndis(RndisType),
139 Usb3Vision(VisionInterface),
140 Step(StepType),
141 DvbCi(DvbInterface),
142}
143
144#[derive(Debug, Clone, Copy)]
145pub enum RndisType {
146 Ethernet,
147 Wifi,
148 Wimax,
149 Wwan,
150 RawIpv4,
151 RawIpv6,
152 Gprs,
153}
154
155#[derive(Debug, Clone, Copy)]
156pub enum VisionInterface {
157 Control,
158 Event,
159 Streaming,
160}
161
162#[derive(Debug, Clone, Copy)]
163pub enum StepType {
164 Step,
165 StepRaw,
166}
167
168#[derive(Debug, Clone, Copy)]
169pub enum DvbInterface {
170 CommandInIad,
171 CommandInInterface,
172 MediaInInterface,
173}
174
175#[derive(Debug, Clone, Copy)]
176pub enum ApplicationType {
177 DeviceFirmwareUpgrade,
178 IrdaBridge,
179 TestMeasurement(TestMeasurementType),
180}
181
182#[derive(Debug, Clone, Copy)]
183pub enum TestMeasurementType {
184 Standard,
185 Usb488Subclass,
186}
187
188impl Class {
189 pub fn from_class_and_subclass(class: u8, subclass: u8, protocol: u8) -> Self {
190 match (class, subclass, protocol) {
191 (0x00, 0x00, 0x00) => Self::ClassInInterface,
193
194 (0x01, _, _) => Self::Audio,
196
197 (0x02, _, _) => Self::Communication,
199
200 (0x03, _, _) => Self::Hid,
202
203 (0x05, _, _) => Self::Physical,
205
206 (0x06, 0x01, 0x01) => Self::StillImaging,
208
209 (0x07, _, _) => Self::Printer,
211
212 (0x08, _, _) => Self::MassStorage,
214
215 (0x09, _, 0x00) => Self::Hub(HubSpeed::Full),
217 (0x09, _, 0x01) => Self::Hub(HubSpeed::HiSpeedSignalTT),
218 (0x09, _, 0x02) => Self::Hub(HubSpeed::HiSpeedMultipleTTs),
219 (0x09, _, _) => Self::Hub(HubSpeed::Unknown),
220
221 (0x0A, _, _) => Self::CdcData,
223
224 (0x0B, _, _) => Self::SmartCard,
226
227 (0x0D, _, _) => Self::ContentSecurity,
229
230 (0x0E, _, _) => Self::Video,
232
233 (0x0F, _, _) => Self::PersonalHealthcare,
235
236 (0x10, 0x01, _) => Self::AudioVideo(AudioVideoType::AvControl),
238 (0x10, 0x02, _) => Self::AudioVideo(AudioVideoType::AvDataVideoStreaming),
239 (0x10, 0x03, _) => Self::AudioVideo(AudioVideoType::AvDataAudioStreaming),
240
241 (0x11, _, _) => Self::Billboard,
243
244 (0x12, _, _) => Self::TypeCBridge,
246
247 (0x13, _, _) => Self::BulkDisplayProtocol,
249
250 (0x14, 0x00, 0x01) => {
252 Self::MctpOverUsb(MctpType::ManagementControllerEndpoint(MctpVersion::V1x))
253 }
254 (0x14, 0x00, 0x02) => {
255 Self::MctpOverUsb(MctpType::ManagementControllerEndpoint(MctpVersion::V2x))
256 }
257 (0x14, 0x01, 0x01) => {
258 Self::MctpOverUsb(MctpType::HostInterfaceEndpoint(MctpVersion::V1x))
259 }
260 (0x14, 0x01, 0x02) => {
261 Self::MctpOverUsb(MctpType::HostInterfaceEndpoint(MctpVersion::V2x))
262 }
263
264 (0x3C, _, _) => Self::I3c,
266
267 (0xDC, 0x01, 0x01) => Self::Diagnostic(DiagnosticType::Usb2Compliance),
269 (0xDC, 0x02, 0x00) => {
270 Self::Diagnostic(DiagnosticType::DebugTarget(DebugProtocol::VendorDefined))
271 }
272 (0xDC, 0x02, 0x01) => {
273 Self::Diagnostic(DiagnosticType::DebugTarget(DebugProtocol::GnuRemoteDebug))
274 }
275 (0xDC, 0x03, 0x01) => {
276 Self::Diagnostic(DiagnosticType::Trace(TraceProtocol::VendorDefined))
277 }
278 (0xDC, 0x04, 0x01) => Self::Diagnostic(DiagnosticType::Dfx(DfxProtocol::VendorDefined)),
279 (0xDC, subclass, protocol) => {
280 Self::Diagnostic(DiagnosticType::Unknown(subclass, protocol))
281 }
282
283 (0xE0, 0x01, 0x01) => Self::Wireless(WirelessType::BluetoothProgramming),
285 (0xE0, 0x01, 0x02) => Self::Wireless(WirelessType::UwbRadioControl),
286 (0xE0, 0x01, 0x03) => Self::Wireless(WirelessType::RemoteNdis),
287 (0xE0, 0x01, 0x04) => Self::Wireless(WirelessType::BluetoothAmp),
288 (0xE0, 0x02, 0x01) => Self::Wireless(WirelessType::HostWireAdapter(
289 WireAdapterInterface::ControlData,
290 )),
291 (0xE0, 0x02, 0x02) => Self::Wireless(WirelessType::DeviceWireAdapter(
292 WireAdapterInterface::ControlData,
293 )),
294 (0xE0, 0x02, 0x03) => Self::Wireless(WirelessType::DeviceWireAdapter(
295 WireAdapterInterface::Isochronous,
296 )),
297
298 (0xEF, 0x01, 0x01) => Self::Miscellaneous(MiscellaneousType::ActiveSync),
300 (0xEF, 0x01, 0x02) => Self::Miscellaneous(MiscellaneousType::PalmSync),
301 (0xEF, 0x02, 0x01) => Self::Miscellaneous(MiscellaneousType::InterfaceAssociation),
302 (0xEF, 0x02, 0x02) => Self::Miscellaneous(MiscellaneousType::WireAdapterMultifunction),
303 (0xEF, 0x03, 0x01) => Self::Miscellaneous(MiscellaneousType::CableBasedAssociation),
304 (0xEF, 0x04, 0x01) => {
305 Self::Miscellaneous(MiscellaneousType::Rndis(RndisType::Ethernet))
306 }
307 (0xEF, 0x04, 0x02) => Self::Miscellaneous(MiscellaneousType::Rndis(RndisType::Wifi)),
308 (0xEF, 0x04, 0x03) => Self::Miscellaneous(MiscellaneousType::Rndis(RndisType::Wimax)),
309 (0xEF, 0x04, 0x04) => Self::Miscellaneous(MiscellaneousType::Rndis(RndisType::Wwan)),
310 (0xEF, 0x04, 0x05) => Self::Miscellaneous(MiscellaneousType::Rndis(RndisType::RawIpv4)),
311 (0xEF, 0x04, 0x06) => Self::Miscellaneous(MiscellaneousType::Rndis(RndisType::RawIpv6)),
312 (0xEF, 0x04, 0x07) => Self::Miscellaneous(MiscellaneousType::Rndis(RndisType::Gprs)),
313 (0xEF, 0x05, 0x00) => {
314 Self::Miscellaneous(MiscellaneousType::Usb3Vision(VisionInterface::Control))
315 }
316 (0xEF, 0x05, 0x01) => {
317 Self::Miscellaneous(MiscellaneousType::Usb3Vision(VisionInterface::Event))
318 }
319 (0xEF, 0x05, 0x02) => {
320 Self::Miscellaneous(MiscellaneousType::Usb3Vision(VisionInterface::Streaming))
321 }
322 (0xEF, 0x06, 0x01) => Self::Miscellaneous(MiscellaneousType::Step(StepType::Step)),
323 (0xEF, 0x06, 0x02) => Self::Miscellaneous(MiscellaneousType::Step(StepType::StepRaw)),
324 (0xEF, 0x07, 0x01) => {
325 Self::Miscellaneous(MiscellaneousType::DvbCi(DvbInterface::CommandInIad))
326 }
327 (0xEF, 0x07, 0x02) => {
328 Self::Miscellaneous(MiscellaneousType::DvbCi(DvbInterface::CommandInInterface))
329 }
330 (0xEF, 0x07, 0x03) => {
331 Self::Miscellaneous(MiscellaneousType::DvbCi(DvbInterface::MediaInInterface))
332 }
333
334 (0xFE, 0x01, 0x01) => Self::Application(ApplicationType::DeviceFirmwareUpgrade),
336 (0xFE, 0x02, 0x00) => Self::Application(ApplicationType::IrdaBridge),
337 (0xFE, 0x03, 0x00) => Self::Application(ApplicationType::TestMeasurement(
338 TestMeasurementType::Standard,
339 )),
340 (0xFE, 0x03, 0x01) => Self::Application(ApplicationType::TestMeasurement(
341 TestMeasurementType::Usb488Subclass,
342 )),
343
344 (0xFF, _, _) => Self::Vendor,
346
347 _ => Self::Unknown {
348 class,
349 subclass,
350 protocol,
351 },
352 }
353 }
354}