1#![warn(clippy::all)]
4#![allow(unused_parens, unused_mut, unused_imports, nonstandard_style)]
5
6use bitflags::bitflags;
7use fidl::encoding::{MessageBufFor, ProxyChannelBox, ResourceDialect};
8use futures::future::{self, MaybeDone, TryFutureExt};
9use zx_status;
10
11pub type ConfigurationDescriptor = Vec<FunctionDescriptor>;
12
13pub const MAX_CONFIG_DESCRIPTORS: u32 = 5;
14
15pub const MAX_FUNCTION_DESCRIPTORS: u32 = 32;
16
17pub const MAX_STRING_DESCRIPTORS: u32 = 255;
18
19pub const MAX_STRING_LENGTH: u32 = 127;
20
21#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
24pub struct DeviceDescriptor {
25 pub bcd_usb: u16,
26 pub b_device_class: u8,
27 pub b_device_sub_class: u8,
28 pub b_device_protocol: u8,
29 pub b_max_packet_size0: u8,
30 pub id_vendor: u16,
31 pub id_product: u16,
32 pub bcd_device: u16,
33 pub manufacturer: String,
34 pub product: String,
35 pub serial: String,
36 pub b_num_configurations: u8,
37}
38
39impl fidl::Persistable for DeviceDescriptor {}
40
41#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
42pub struct DeviceSetConfigurationRequest {
43 pub device_desc: DeviceDescriptor,
44 pub config_descriptors: Vec<Vec<FunctionDescriptor>>,
45}
46
47impl fidl::Persistable for DeviceSetConfigurationRequest {}
48
49#[derive(Clone, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
50pub struct DeviceGetConfigurationResponse {
51 pub device_desc: DeviceDescriptor,
52 pub config_descriptors: Vec<Vec<FunctionDescriptor>>,
53}
54
55impl fidl::Persistable for DeviceGetConfigurationResponse {}
56
57#[derive(Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd)]
58#[repr(C)]
59pub struct FunctionDescriptor {
60 pub interface_class: u8,
61 pub interface_subclass: u8,
62 pub interface_protocol: u8,
63}
64
65impl fidl::Persistable for FunctionDescriptor {}
66
67pub mod device_ordinals {
68 pub const GET_CONFIGURATION: u64 = 0x19fe4f37c3b52e3a;
69 pub const SET_CONFIGURATION: u64 = 0x464bafee91a3d6de;
70 pub const CLEAR_FUNCTIONS: u64 = 0x67d9d8086dfab0cb;
71 pub const SET_STATE_CHANGE_LISTENER: u64 = 0x5575723c4674d1d9;
72}
73
74pub mod events_ordinals {
75 pub const FUNCTION_REGISTERED: u64 = 0x191278425c4a96e8;
76 pub const FUNCTIONS_CLEARED: u64 = 0x6feab079055dacf1;
77}
78
79mod internal {
80 use super::*;
81
82 impl fidl::encoding::ValueTypeMarker for DeviceDescriptor {
83 type Borrowed<'a> = &'a Self;
84 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
85 value
86 }
87 }
88
89 unsafe impl fidl::encoding::TypeMarker for DeviceDescriptor {
90 type Owned = Self;
91
92 #[inline(always)]
93 fn inline_align(_context: fidl::encoding::Context) -> usize {
94 8
95 }
96
97 #[inline(always)]
98 fn inline_size(_context: fidl::encoding::Context) -> usize {
99 72
100 }
101 }
102
103 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<DeviceDescriptor, D>
104 for &DeviceDescriptor
105 {
106 #[inline]
107 unsafe fn encode(
108 self,
109 encoder: &mut fidl::encoding::Encoder<'_, D>,
110 offset: usize,
111 _depth: fidl::encoding::Depth,
112 ) -> fidl::Result<()> {
113 encoder.debug_check_bounds::<DeviceDescriptor>(offset);
114 fidl::encoding::Encode::<DeviceDescriptor, D>::encode(
116 (
117 <u16 as fidl::encoding::ValueTypeMarker>::borrow(&self.bcd_usb),
118 <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.b_device_class),
119 <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.b_device_sub_class),
120 <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.b_device_protocol),
121 <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.b_max_packet_size0),
122 <u16 as fidl::encoding::ValueTypeMarker>::borrow(&self.id_vendor),
123 <u16 as fidl::encoding::ValueTypeMarker>::borrow(&self.id_product),
124 <u16 as fidl::encoding::ValueTypeMarker>::borrow(&self.bcd_device),
125 <fidl::encoding::BoundedString<127> as fidl::encoding::ValueTypeMarker>::borrow(
126 &self.manufacturer,
127 ),
128 <fidl::encoding::BoundedString<127> as fidl::encoding::ValueTypeMarker>::borrow(
129 &self.product,
130 ),
131 <fidl::encoding::BoundedString<127> as fidl::encoding::ValueTypeMarker>::borrow(
132 &self.serial,
133 ),
134 <u8 as fidl::encoding::ValueTypeMarker>::borrow(&self.b_num_configurations),
135 ),
136 encoder,
137 offset,
138 _depth,
139 )
140 }
141 }
142 unsafe impl<
143 D: fidl::encoding::ResourceDialect,
144 T0: fidl::encoding::Encode<u16, D>,
145 T1: fidl::encoding::Encode<u8, D>,
146 T2: fidl::encoding::Encode<u8, D>,
147 T3: fidl::encoding::Encode<u8, D>,
148 T4: fidl::encoding::Encode<u8, D>,
149 T5: fidl::encoding::Encode<u16, D>,
150 T6: fidl::encoding::Encode<u16, D>,
151 T7: fidl::encoding::Encode<u16, D>,
152 T8: fidl::encoding::Encode<fidl::encoding::BoundedString<127>, D>,
153 T9: fidl::encoding::Encode<fidl::encoding::BoundedString<127>, D>,
154 T10: fidl::encoding::Encode<fidl::encoding::BoundedString<127>, D>,
155 T11: fidl::encoding::Encode<u8, D>,
156 > fidl::encoding::Encode<DeviceDescriptor, D>
157 for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)
158 {
159 #[inline]
160 unsafe fn encode(
161 self,
162 encoder: &mut fidl::encoding::Encoder<'_, D>,
163 offset: usize,
164 depth: fidl::encoding::Depth,
165 ) -> fidl::Result<()> {
166 encoder.debug_check_bounds::<DeviceDescriptor>(offset);
167 unsafe {
170 let ptr = encoder.buf.as_mut_ptr().add(offset).offset(8);
171 (ptr as *mut u64).write_unaligned(0);
172 }
173 unsafe {
174 let ptr = encoder.buf.as_mut_ptr().add(offset).offset(64);
175 (ptr as *mut u64).write_unaligned(0);
176 }
177 self.0.encode(encoder, offset + 0, depth)?;
179 self.1.encode(encoder, offset + 2, depth)?;
180 self.2.encode(encoder, offset + 3, depth)?;
181 self.3.encode(encoder, offset + 4, depth)?;
182 self.4.encode(encoder, offset + 5, depth)?;
183 self.5.encode(encoder, offset + 6, depth)?;
184 self.6.encode(encoder, offset + 8, depth)?;
185 self.7.encode(encoder, offset + 10, depth)?;
186 self.8.encode(encoder, offset + 16, depth)?;
187 self.9.encode(encoder, offset + 32, depth)?;
188 self.10.encode(encoder, offset + 48, depth)?;
189 self.11.encode(encoder, offset + 64, depth)?;
190 Ok(())
191 }
192 }
193
194 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for DeviceDescriptor {
195 #[inline(always)]
196 fn new_empty() -> Self {
197 Self {
198 bcd_usb: fidl::new_empty!(u16, D),
199 b_device_class: fidl::new_empty!(u8, D),
200 b_device_sub_class: fidl::new_empty!(u8, D),
201 b_device_protocol: fidl::new_empty!(u8, D),
202 b_max_packet_size0: fidl::new_empty!(u8, D),
203 id_vendor: fidl::new_empty!(u16, D),
204 id_product: fidl::new_empty!(u16, D),
205 bcd_device: fidl::new_empty!(u16, D),
206 manufacturer: fidl::new_empty!(fidl::encoding::BoundedString<127>, D),
207 product: fidl::new_empty!(fidl::encoding::BoundedString<127>, D),
208 serial: fidl::new_empty!(fidl::encoding::BoundedString<127>, D),
209 b_num_configurations: fidl::new_empty!(u8, D),
210 }
211 }
212
213 #[inline]
214 unsafe fn decode(
215 &mut self,
216 decoder: &mut fidl::encoding::Decoder<'_, D>,
217 offset: usize,
218 _depth: fidl::encoding::Depth,
219 ) -> fidl::Result<()> {
220 decoder.debug_check_bounds::<Self>(offset);
221 let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(8) };
223 let padval = unsafe { (ptr as *const u64).read_unaligned() };
224 let mask = 0xffffffff00000000u64;
225 let maskedval = padval & mask;
226 if maskedval != 0 {
227 return Err(fidl::Error::NonZeroPadding {
228 padding_start: offset + 8 + ((mask as u64).trailing_zeros() / 8) as usize,
229 });
230 }
231 let ptr = unsafe { decoder.buf.as_ptr().add(offset).offset(64) };
232 let padval = unsafe { (ptr as *const u64).read_unaligned() };
233 let mask = 0xffffffffffffff00u64;
234 let maskedval = padval & mask;
235 if maskedval != 0 {
236 return Err(fidl::Error::NonZeroPadding {
237 padding_start: offset + 64 + ((mask as u64).trailing_zeros() / 8) as usize,
238 });
239 }
240 fidl::decode!(u16, D, &mut self.bcd_usb, decoder, offset + 0, _depth)?;
241 fidl::decode!(u8, D, &mut self.b_device_class, decoder, offset + 2, _depth)?;
242 fidl::decode!(u8, D, &mut self.b_device_sub_class, decoder, offset + 3, _depth)?;
243 fidl::decode!(u8, D, &mut self.b_device_protocol, decoder, offset + 4, _depth)?;
244 fidl::decode!(u8, D, &mut self.b_max_packet_size0, decoder, offset + 5, _depth)?;
245 fidl::decode!(u16, D, &mut self.id_vendor, decoder, offset + 6, _depth)?;
246 fidl::decode!(u16, D, &mut self.id_product, decoder, offset + 8, _depth)?;
247 fidl::decode!(u16, D, &mut self.bcd_device, decoder, offset + 10, _depth)?;
248 fidl::decode!(
249 fidl::encoding::BoundedString<127>,
250 D,
251 &mut self.manufacturer,
252 decoder,
253 offset + 16,
254 _depth
255 )?;
256 fidl::decode!(
257 fidl::encoding::BoundedString<127>,
258 D,
259 &mut self.product,
260 decoder,
261 offset + 32,
262 _depth
263 )?;
264 fidl::decode!(
265 fidl::encoding::BoundedString<127>,
266 D,
267 &mut self.serial,
268 decoder,
269 offset + 48,
270 _depth
271 )?;
272 fidl::decode!(u8, D, &mut self.b_num_configurations, decoder, offset + 64, _depth)?;
273 Ok(())
274 }
275 }
276
277 impl fidl::encoding::ValueTypeMarker for DeviceSetConfigurationRequest {
278 type Borrowed<'a> = &'a Self;
279 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
280 value
281 }
282 }
283
284 unsafe impl fidl::encoding::TypeMarker for DeviceSetConfigurationRequest {
285 type Owned = Self;
286
287 #[inline(always)]
288 fn inline_align(_context: fidl::encoding::Context) -> usize {
289 8
290 }
291
292 #[inline(always)]
293 fn inline_size(_context: fidl::encoding::Context) -> usize {
294 88
295 }
296 }
297
298 unsafe impl<D: fidl::encoding::ResourceDialect>
299 fidl::encoding::Encode<DeviceSetConfigurationRequest, D>
300 for &DeviceSetConfigurationRequest
301 {
302 #[inline]
303 unsafe fn encode(
304 self,
305 encoder: &mut fidl::encoding::Encoder<'_, D>,
306 offset: usize,
307 _depth: fidl::encoding::Depth,
308 ) -> fidl::Result<()> {
309 encoder.debug_check_bounds::<DeviceSetConfigurationRequest>(offset);
310 fidl::encoding::Encode::<DeviceSetConfigurationRequest, D>::encode(
312 (
313 <DeviceDescriptor as fidl::encoding::ValueTypeMarker>::borrow(&self.device_desc),
314 <fidl::encoding::Vector<fidl::encoding::Vector<FunctionDescriptor, 32>, 5> as fidl::encoding::ValueTypeMarker>::borrow(&self.config_descriptors),
315 ),
316 encoder, offset, _depth
317 )
318 }
319 }
320 unsafe impl<
321 D: fidl::encoding::ResourceDialect,
322 T0: fidl::encoding::Encode<DeviceDescriptor, D>,
323 T1: fidl::encoding::Encode<
324 fidl::encoding::Vector<fidl::encoding::Vector<FunctionDescriptor, 32>, 5>,
325 D,
326 >,
327 > fidl::encoding::Encode<DeviceSetConfigurationRequest, D> for (T0, T1)
328 {
329 #[inline]
330 unsafe fn encode(
331 self,
332 encoder: &mut fidl::encoding::Encoder<'_, D>,
333 offset: usize,
334 depth: fidl::encoding::Depth,
335 ) -> fidl::Result<()> {
336 encoder.debug_check_bounds::<DeviceSetConfigurationRequest>(offset);
337 self.0.encode(encoder, offset + 0, depth)?;
341 self.1.encode(encoder, offset + 72, depth)?;
342 Ok(())
343 }
344 }
345
346 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
347 for DeviceSetConfigurationRequest
348 {
349 #[inline(always)]
350 fn new_empty() -> Self {
351 Self {
352 device_desc: fidl::new_empty!(DeviceDescriptor, D),
353 config_descriptors: fidl::new_empty!(
354 fidl::encoding::Vector<fidl::encoding::Vector<FunctionDescriptor, 32>, 5>,
355 D
356 ),
357 }
358 }
359
360 #[inline]
361 unsafe fn decode(
362 &mut self,
363 decoder: &mut fidl::encoding::Decoder<'_, D>,
364 offset: usize,
365 _depth: fidl::encoding::Depth,
366 ) -> fidl::Result<()> {
367 decoder.debug_check_bounds::<Self>(offset);
368 fidl::decode!(DeviceDescriptor, D, &mut self.device_desc, decoder, offset + 0, _depth)?;
370 fidl::decode!(
371 fidl::encoding::Vector<fidl::encoding::Vector<FunctionDescriptor, 32>, 5>,
372 D,
373 &mut self.config_descriptors,
374 decoder,
375 offset + 72,
376 _depth
377 )?;
378 Ok(())
379 }
380 }
381
382 impl fidl::encoding::ValueTypeMarker for DeviceGetConfigurationResponse {
383 type Borrowed<'a> = &'a Self;
384 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
385 value
386 }
387 }
388
389 unsafe impl fidl::encoding::TypeMarker for DeviceGetConfigurationResponse {
390 type Owned = Self;
391
392 #[inline(always)]
393 fn inline_align(_context: fidl::encoding::Context) -> usize {
394 8
395 }
396
397 #[inline(always)]
398 fn inline_size(_context: fidl::encoding::Context) -> usize {
399 88
400 }
401 }
402
403 unsafe impl<D: fidl::encoding::ResourceDialect>
404 fidl::encoding::Encode<DeviceGetConfigurationResponse, D>
405 for &DeviceGetConfigurationResponse
406 {
407 #[inline]
408 unsafe fn encode(
409 self,
410 encoder: &mut fidl::encoding::Encoder<'_, D>,
411 offset: usize,
412 _depth: fidl::encoding::Depth,
413 ) -> fidl::Result<()> {
414 encoder.debug_check_bounds::<DeviceGetConfigurationResponse>(offset);
415 fidl::encoding::Encode::<DeviceGetConfigurationResponse, D>::encode(
417 (
418 <DeviceDescriptor as fidl::encoding::ValueTypeMarker>::borrow(&self.device_desc),
419 <fidl::encoding::Vector<fidl::encoding::Vector<FunctionDescriptor, 32>, 5> as fidl::encoding::ValueTypeMarker>::borrow(&self.config_descriptors),
420 ),
421 encoder, offset, _depth
422 )
423 }
424 }
425 unsafe impl<
426 D: fidl::encoding::ResourceDialect,
427 T0: fidl::encoding::Encode<DeviceDescriptor, D>,
428 T1: fidl::encoding::Encode<
429 fidl::encoding::Vector<fidl::encoding::Vector<FunctionDescriptor, 32>, 5>,
430 D,
431 >,
432 > fidl::encoding::Encode<DeviceGetConfigurationResponse, D> for (T0, T1)
433 {
434 #[inline]
435 unsafe fn encode(
436 self,
437 encoder: &mut fidl::encoding::Encoder<'_, D>,
438 offset: usize,
439 depth: fidl::encoding::Depth,
440 ) -> fidl::Result<()> {
441 encoder.debug_check_bounds::<DeviceGetConfigurationResponse>(offset);
442 self.0.encode(encoder, offset + 0, depth)?;
446 self.1.encode(encoder, offset + 72, depth)?;
447 Ok(())
448 }
449 }
450
451 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D>
452 for DeviceGetConfigurationResponse
453 {
454 #[inline(always)]
455 fn new_empty() -> Self {
456 Self {
457 device_desc: fidl::new_empty!(DeviceDescriptor, D),
458 config_descriptors: fidl::new_empty!(
459 fidl::encoding::Vector<fidl::encoding::Vector<FunctionDescriptor, 32>, 5>,
460 D
461 ),
462 }
463 }
464
465 #[inline]
466 unsafe fn decode(
467 &mut self,
468 decoder: &mut fidl::encoding::Decoder<'_, D>,
469 offset: usize,
470 _depth: fidl::encoding::Depth,
471 ) -> fidl::Result<()> {
472 decoder.debug_check_bounds::<Self>(offset);
473 fidl::decode!(DeviceDescriptor, D, &mut self.device_desc, decoder, offset + 0, _depth)?;
475 fidl::decode!(
476 fidl::encoding::Vector<fidl::encoding::Vector<FunctionDescriptor, 32>, 5>,
477 D,
478 &mut self.config_descriptors,
479 decoder,
480 offset + 72,
481 _depth
482 )?;
483 Ok(())
484 }
485 }
486
487 impl fidl::encoding::ValueTypeMarker for FunctionDescriptor {
488 type Borrowed<'a> = &'a Self;
489 fn borrow(value: &<Self as fidl::encoding::TypeMarker>::Owned) -> Self::Borrowed<'_> {
490 value
491 }
492 }
493
494 unsafe impl fidl::encoding::TypeMarker for FunctionDescriptor {
495 type Owned = Self;
496
497 #[inline(always)]
498 fn inline_align(_context: fidl::encoding::Context) -> usize {
499 1
500 }
501
502 #[inline(always)]
503 fn inline_size(_context: fidl::encoding::Context) -> usize {
504 3
505 }
506 #[inline(always)]
507 fn encode_is_copy() -> bool {
508 true
509 }
510
511 #[inline(always)]
512 fn decode_is_copy() -> bool {
513 true
514 }
515 }
516
517 unsafe impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Encode<FunctionDescriptor, D>
518 for &FunctionDescriptor
519 {
520 #[inline]
521 unsafe fn encode(
522 self,
523 encoder: &mut fidl::encoding::Encoder<'_, D>,
524 offset: usize,
525 _depth: fidl::encoding::Depth,
526 ) -> fidl::Result<()> {
527 encoder.debug_check_bounds::<FunctionDescriptor>(offset);
528 unsafe {
529 let buf_ptr = encoder.buf.as_mut_ptr().add(offset);
531 (buf_ptr as *mut FunctionDescriptor)
532 .write_unaligned((self as *const FunctionDescriptor).read());
533 }
536 Ok(())
537 }
538 }
539 unsafe impl<
540 D: fidl::encoding::ResourceDialect,
541 T0: fidl::encoding::Encode<u8, D>,
542 T1: fidl::encoding::Encode<u8, D>,
543 T2: fidl::encoding::Encode<u8, D>,
544 > fidl::encoding::Encode<FunctionDescriptor, D> for (T0, T1, T2)
545 {
546 #[inline]
547 unsafe fn encode(
548 self,
549 encoder: &mut fidl::encoding::Encoder<'_, D>,
550 offset: usize,
551 depth: fidl::encoding::Depth,
552 ) -> fidl::Result<()> {
553 encoder.debug_check_bounds::<FunctionDescriptor>(offset);
554 self.0.encode(encoder, offset + 0, depth)?;
558 self.1.encode(encoder, offset + 1, depth)?;
559 self.2.encode(encoder, offset + 2, depth)?;
560 Ok(())
561 }
562 }
563
564 impl<D: fidl::encoding::ResourceDialect> fidl::encoding::Decode<Self, D> for FunctionDescriptor {
565 #[inline(always)]
566 fn new_empty() -> Self {
567 Self {
568 interface_class: fidl::new_empty!(u8, D),
569 interface_subclass: fidl::new_empty!(u8, D),
570 interface_protocol: fidl::new_empty!(u8, D),
571 }
572 }
573
574 #[inline]
575 unsafe fn decode(
576 &mut self,
577 decoder: &mut fidl::encoding::Decoder<'_, D>,
578 offset: usize,
579 _depth: fidl::encoding::Depth,
580 ) -> fidl::Result<()> {
581 decoder.debug_check_bounds::<Self>(offset);
582 let buf_ptr = unsafe { decoder.buf.as_ptr().add(offset) };
583 unsafe {
586 std::ptr::copy_nonoverlapping(buf_ptr, self as *mut Self as *mut u8, 3);
587 }
588 Ok(())
589 }
590 }
591}